Skip to content

Commit

Permalink
Fix checkstylre ssues (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckorzen authored May 26, 2023
1 parent 8ea00e2 commit ec3849f
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 87 deletions.
6 changes: 4 additions & 2 deletions src/DiacriticalMarksMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "./DiacriticalMarksMerger.h"

using ppp::math_utils::equal;
using ppp::math_utils::larger;
using std::endl;
using std::max;
using std::min;
Expand Down Expand Up @@ -143,15 +145,15 @@ void DiacriticalMarksMerger::process() const {
_log->debug(p) << "xOverlapRatio current/next char: " << nextXOverlapRatio << endl;

// Skip the character if both overlap ratios are equal to zero.
if (ppp::math_utils::equal(prevXOverlapRatio, 0) && ppp::math_utils::equal(nextXOverlapRatio, 0)) {
if (equal(prevXOverlapRatio, 0) && equal(nextXOverlapRatio, 0)) {
_log->debug(p) << BOLD << "Skipping char (both overlaps == 0)." << OFF << endl;
continue;
}

// Consider the character that yields the larger overlap ratio to be the base character.
PdfCharacter* mark = currChar;
PdfCharacter* base;
if (ppp::math_utils::larger(prevXOverlapRatio, nextXOverlapRatio)) {
if (larger(prevXOverlapRatio, nextXOverlapRatio)) {
_log->debug(p) << BOLD << "Merge diacritic with previous character." << OFF << endl;
base = prevChar;
} else {
Expand Down
8 changes: 5 additions & 3 deletions src/SubSuperScriptsDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "./PdfDocument.h"
#include "./SubSuperScriptsDetector.h"

using ppp::math_utils::larger;
using ppp::math_utils::smaller;
using std::endl;
using std::max;
using std::min;
Expand Down Expand Up @@ -63,15 +65,15 @@ void SubSuperScriptsDetector::process() const {
_log->debug(p) << " └─ line.base: " << line->base << endl;
_log->debug(p) << " └─ tolerance base-line: " << config::BASE_EQUAL_TOLERANCE << endl;

if (ppp::math_utils::smaller(character->fontSize, _doc->mostFreqFontSize,
if (smaller(character->fontSize, _doc->mostFreqFontSize,
config::FSIZE_EQUAL_TOLERANCE)) {
if (ppp::math_utils::smaller(character->base, line->base, config::BASE_EQUAL_TOLERANCE)) {
if (smaller(character->base, line->base, config::BASE_EQUAL_TOLERANCE)) {
_log->debug(p) << BOLD << " superscript (char.base < line.base)" << OFF << endl;
character->isSuperscript = true;
continue;
}

if (ppp::math_utils::larger(character->base, line->base, config::BASE_EQUAL_TOLERANCE)) {
if (larger(character->base, line->base, config::BASE_EQUAL_TOLERANCE)) {
_log->debug(p) << BOLD << " subscript (char.base > line.base)" << OFF << endl;
character->isSubscript = true;
continue;
Expand Down
57 changes: 32 additions & 25 deletions src/TextBlocksDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ using std::endl;
using std::string;
using std::vector;

using ppp::math_utils::between;
using ppp::math_utils::equal;
using ppp::math_utils::equalOrLarger;
using ppp::math_utils::equalOrSmaller;
using ppp::math_utils::larger;
using ppp::math_utils::round;
using ppp::math_utils::smaller;
using ppp::string_utils::shorten;

namespace config = text_blocks_detector::config;
Expand Down Expand Up @@ -387,8 +394,8 @@ Trool TextBlocksDetector::startsBlock_fontSize(const PdfTextLine* line) const {
// parts is likely to have a larger font size than the rest of the caption). The second condition
// exists to not split text lines with many small characters (which is particularly often the
// case when the text line contains an inline formula).
bool isEqualFontSize = ppp::math_utils::equal(prevLine->fontSize, line->fontSize, tolerance);
bool isEqualMaxFontSize = ppp::math_utils::equal(prevLine->maxFontSize, line->maxFontSize, tolerance);
bool isEqualFontSize = equal(prevLine->fontSize, line->fontSize, tolerance);
bool isEqualMaxFontSize = equal(prevLine->maxFontSize, line->maxFontSize, tolerance);
if (!isEqualFontSize && !isEqualMaxFontSize) {
_log->debug(p) << _q << BLUE << BOLD << " yes → starts block" << OFF << endl;
return Trool::True;
Expand All @@ -406,7 +413,7 @@ Trool TextBlocksDetector::startsBlock_lineDistance(const PdfTextLine* line) cons
const PdfTextLine* prevLine = line->prevLine;

// Compute the expected line distance.
double fontSize = ppp::math_utils::round(line->fontSize, config::FONT_SIZE_PREC);
double fontSize = round(line->fontSize, config::FONT_SIZE_PREC);
double expectedLineDistance = 0;
if (_doc->mostFreqLineDistancePerFontSize.count(fontSize) > 0) {
double eld = _doc->mostFreqLineDistancePerFontSize.at(fontSize);
Expand All @@ -416,7 +423,7 @@ Trool TextBlocksDetector::startsBlock_lineDistance(const PdfTextLine* line) cons

// Compute the actual line distance.
double actualLineDistance = element_utils::computeVerticalGap(prevLine, line);
actualLineDistance = ppp::math_utils::round(actualLineDistance, config::LINE_DIST_PREC);
actualLineDistance = round(actualLineDistance, config::LINE_DIST_PREC);

double lineDistanceDiff = actualLineDistance - expectedLineDistance;

Expand All @@ -430,14 +437,14 @@ Trool TextBlocksDetector::startsBlock_lineDistance(const PdfTextLine* line) cons
_log->debug(p) << _q << " └─ threshold: " << threshold << endl;

// The line does *not* start a new block if the actual line distance is negative.
if (ppp::math_utils::equalOrSmaller(actualLineDistance, 0)) {
if (equalOrSmaller(actualLineDistance, 0)) {
_log->debug(p) << _q << BLUE << BOLD << " no, distance < 0 → continues block" << OFF << endl;
return Trool::False;
}

// The line starts a new block if the actual line distance is larger than the expected line
// distance, under consideration of the computed tolerance.
if (ppp::math_utils::larger(actualLineDistance, expectedLineDistance, threshold)) {
if (larger(actualLineDistance, expectedLineDistance, threshold)) {
_log->debug(p) << _q << BLUE << BOLD << " yes → starts block" << OFF << endl;
return Trool::True;
}
Expand All @@ -460,11 +467,11 @@ Trool TextBlocksDetector::startsBlock_increasedLineDistance(const PdfTextLine* l

// Compute the distance between the previous but one line and the previous line.
double prevDistance = element_utils::computeVerticalGap(prevPrevLine, prevLine);
prevDistance = ppp::math_utils::round(prevDistance, config::LINE_DIST_PREC);
prevDistance = round(prevDistance, config::LINE_DIST_PREC);

// Compute the distance between the previous line and the current line.
double distance = element_utils::computeVerticalGap(prevLine, line);
distance = ppp::math_utils::round(distance, config::LINE_DIST_PREC);
distance = round(distance, config::LINE_DIST_PREC);

// Compute the tolerance.
double threshold = config::getPrevCurrNextLineDistanceTolerance(_doc);
Expand All @@ -476,7 +483,7 @@ Trool TextBlocksDetector::startsBlock_increasedLineDistance(const PdfTextLine* l

// The line starts a block if the curr+prev line distance is larger than the prev+prevPrev line
// distance, under consideration of the computed tolerance.
if (ppp::math_utils::larger(distance, prevDistance, threshold)) {
if (larger(distance, prevDistance, threshold)) {
_log->debug(p) << _q << BLUE << BOLD << " yes → starts block" << OFF << endl;
return Trool::True;
}
Expand Down Expand Up @@ -576,7 +583,7 @@ Trool TextBlocksDetector::startsBlock_item(const PdfTextBlock* pBlock, const Pdf
if (isPrevContLine) {
// The line does *not* start a block if the line and the previous line are a continuation
// of an item, and the leftX-offset between the lines is in the given tolerance.
if (ppp::math_utils::between(leftXOffset, leftXOffsetToleranceLow, leftXOffsetToleranceHigh)) {
if (between(leftXOffset, leftXOffsetToleranceLow, leftXOffsetToleranceHigh)) {
_log->debug(p) << _q << BLUE << BOLD << " + prev line is continuation of item "
<< "+ leftX-offset in tolerance → continues block" << OFF << endl;
return Trool::False;
Expand Down Expand Up @@ -665,12 +672,12 @@ Trool TextBlocksDetector::startsBlock_hangingIndent(const PdfTextBlock* pBlock,
double hangingIndent = pBlock->hangingIndent;
double prevLeftMargin = prevLine->leftMargin;
double currLeftMargin = line->leftMargin;
bool isPrevNotIndented = ppp::math_utils::smaller(prevLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isCurrNotIndented = ppp::math_utils::smaller(currLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isPrevIndented = ppp::math_utils::equal(prevLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isCurrIndented = ppp::math_utils::equal(currLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isPrevMoreIndented = ppp::math_utils::larger(prevLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isCurrMoreIndented = ppp::math_utils::larger(currLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isPrevNotIndented = smaller(prevLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isCurrNotIndented = smaller(currLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isPrevIndented = equal(prevLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isCurrIndented = equal(currLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isPrevMoreIndented = larger(prevLeftMargin, hangingIndent, _doc->avgCharWidth);
bool isCurrMoreIndented = larger(currLeftMargin, hangingIndent, _doc->avgCharWidth);
double leftXOffset = element_utils::computeLeftXOffset(prevLine, line);
bool hasPrevLineCapacity = text_lines_utils::computeHasPrevLineCapacity(line);
pair<double, double> leftXOffsetTolInterval = config::getLeftXOffsetToleranceInterval(_doc);
Expand All @@ -693,7 +700,7 @@ Trool TextBlocksDetector::startsBlock_hangingIndent(const PdfTextBlock* pBlock,
_log->debug(p) << _q << " └─ leftXOffsetToleranceHigh: " << leftXOffsetToleranceHigh << endl;

// Do nothing if the block is not in hanging indent format.
if (ppp::math_utils::equalOrSmaller(hangingIndent, 0.0)) {
if (equalOrSmaller(hangingIndent, 0.0)) {
return Trool::None;
}

Expand All @@ -711,7 +718,7 @@ Trool TextBlocksDetector::startsBlock_hangingIndent(const PdfTextBlock* pBlock,

// The line does *not* start a block if it is indented, the prev. line is more indented
// than the tolerance, and the leftX-offset between both lines is in the given tolerance.
if (ppp::math_utils::between(leftXOffset, leftXOffsetToleranceLow, leftXOffsetToleranceHigh)) {
if (between(leftXOffset, leftXOffsetToleranceLow, leftXOffsetToleranceHigh)) {
_log->debug(p) << _q << BLUE << BOLD << " + x-offset is in tolerance → continues block"
<< OFF << endl;
return Trool::False;
Expand Down Expand Up @@ -742,7 +749,7 @@ Trool TextBlocksDetector::startsBlock_hangingIndent(const PdfTextBlock* pBlock,

// The line does *not* start a block if the current and previous line are more indented
// than the tolerance, and the leftX-offset between both lines is in the given tolerance.
if (ppp::math_utils::between(leftXOffset, leftXOffsetToleranceLow, leftXOffsetToleranceHigh)) {
if (between(leftXOffset, leftXOffsetToleranceLow, leftXOffsetToleranceHigh)) {
_log->debug(p) << _q << BLUE << BOLD << " + x-offset is in tolerance → continues block"
<< OFF << endl;
return Trool::False;
Expand Down Expand Up @@ -776,10 +783,10 @@ Trool TextBlocksDetector::startsBlock_indent(const PdfTextLine* line) const {
pair<double, double> indentToleranceInterval = config::getIndentToleranceInterval(_doc);
double indentTolLow = indentToleranceInterval.first;
double indentTolHigh = indentToleranceInterval.second;
bool isPrevIndented = ppp::math_utils::between(prevLeftMargin, indentTolLow, indentTolHigh);
bool isCurrIndented = ppp::math_utils::between(currLeftMargin, indentTolLow, indentTolHigh);
bool isPrevMoreIndented = ppp::math_utils::larger(prevLeftMargin, indentTolHigh);
bool isCurrMoreIndented = ppp::math_utils::larger(currLeftMargin, indentTolHigh);
bool isPrevIndented = between(prevLeftMargin, indentTolLow, indentTolHigh);
bool isCurrIndented = between(currLeftMargin, indentTolLow, indentTolHigh);
bool isPrevMoreIndented = larger(prevLeftMargin, indentTolHigh);
bool isCurrMoreIndented = larger(currLeftMargin, indentTolHigh);
double absLeftXOffset = abs(element_utils::computeLeftXOffset(prevLine, line));
bool hasPrevLineCapacity = text_lines_utils::computeHasPrevLineCapacity(line);

Expand All @@ -801,7 +808,7 @@ Trool TextBlocksDetector::startsBlock_indent(const PdfTextLine* line) const {

// The line does *not* start a block if it is more indented than the given tolerance and
// its leftX offset is equal to zero (under consideration of a small threshold).
if (ppp::math_utils::equal(absLeftXOffset, 0, _doc->avgCharWidth)) {
if (equal(absLeftXOffset, 0, _doc->avgCharWidth)) {
_log->debug(p) << _q << BLUE << BOLD << " + leftXOffset ≈ 0 → continues block" << OFF << endl;
return Trool::False;
}
Expand All @@ -818,7 +825,7 @@ Trool TextBlocksDetector::startsBlock_indent(const PdfTextLine* line) const {
// The line starts a block if the current and previous line are more indented
// than the tolerance, and the leftX-offset between both lines is equal to 0 (under
// consideration of a small threshold).
if (ppp::math_utils::equal(absLeftXOffset, 0, _doc->avgCharWidth)) {
if (equal(absLeftXOffset, 0, _doc->avgCharWidth)) {
_log->debug(p) << _q << BLUE << BOLD << " + leftXOffset ≈ 0 → continues block" << OFF << endl;
return Trool::False;
}
Expand Down
8 changes: 5 additions & 3 deletions src/TextOutputDev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ using global_config::COORDS_EQUAL_TOLERANCE;
using global_config::FONT_SIZE_PREC;
using global_config::ID_LENGTH;

using ppp::math_utils::larger;
using ppp::math_utils::smaller;
using std::endl;
using std::get;
using std::max;
Expand Down Expand Up @@ -236,10 +238,10 @@ void TextOutputDev::drawChar(GfxState* state, double x, double y, double dx, dou
m[2] = m2[2];
m[3] = m2[3];
}
if (ppp::math_utils::larger(fabs(m[0] * m[3]), fabs(m[1] * m[2]))) {
ch->pos->rotation = (ppp::math_utils::larger(m[0], 0) || ppp::math_utils::smaller(m[3], 0)) ? 0 : 2;
if (larger(fabs(m[0] * m[3]), fabs(m[1] * m[2]))) {
ch->pos->rotation = (larger(m[0], 0) || smaller(m[3], 0)) ? 0 : 2;
} else {
ch->pos->rotation = (ppp::math_utils::larger(m[2], 0)) ? 1 : 3;
ch->pos->rotation = (larger(m[2], 0)) ? 1 : 3;
}
// In vertical writing mode, the lines are effectively rotated by 90 degrees.
if (gfxFont && gfxFont->getWMode()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ string getSemanticRolesStr(const string& separator) {
return resultStr;
}

} // namespace ppp::types
} // namespace ppp::types
8 changes: 4 additions & 4 deletions src/Validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace po = boost::program_options;
namespace ppp::types {

// _________________________________________________________________________________________________
void validate(boost::any& v, const vector<string>& vals, SerializationFormat* f, int) {
void validate(boost::any& v, const vector<string>& vals, SerializationFormat* f, int) { // NOLINT
// Make sure no previous assignment to the option was made.
po::validators::check_first_occurrence(v);

Expand All @@ -41,7 +41,7 @@ void validate(boost::any& v, const vector<string>& vals, SerializationFormat* f,
}

// _________________________________________________________________________________________________
void validate(boost::any& v, const vector<string>& vals, SemanticRole* r, int) {
void validate(boost::any& v, const vector<string>& vals, SemanticRole* r, int) { // NOLINT
// Make sure no previous assignment to the option was made.
po::validators::check_first_occurrence(v);

Expand All @@ -60,7 +60,7 @@ void validate(boost::any& v, const vector<string>& vals, SemanticRole* r, int) {
}

// _________________________________________________________________________________________________
void validate(boost::any& v, const vector<string>& vals, DocumentUnit* u, int) {
void validate(boost::any& v, const vector<string>& vals, DocumentUnit* u, int) { // NOLINT
// Make sure no previous assignment to the option was made.
po::validators::check_first_occurrence(v);

Expand All @@ -78,4 +78,4 @@ void validate(boost::any& v, const vector<string>& vals, DocumentUnit* u, int) {
throw po::invalid_option_value(token);
}

} // namespace ppp::types
} // namespace ppp::types
18 changes: 11 additions & 7 deletions src/WordsDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

using global_config::ID_LENGTH;

using ppp::math_utils::equal;
using ppp::math_utils::equalOrLarger;
using ppp::math_utils::larger;
using ppp::math_utils::smaller;
using std::endl;
using std::max;
using std::min;
Expand Down Expand Up @@ -213,7 +217,7 @@ bool WordsDetector::startsWord(const PdfCharacter* currChar) const {
<< "word smaller than a threshold?" << endl;
_log->debug(p) << " └─ maxYRatio: " << maxYOverlapRatio << endl;
_log->debug(p) << " └─ threshold: " << config::Y_OVERLAP_RATIO_THRESHOLD << endl;
if (ppp::math_utils::smaller(maxYOverlapRatio, config::Y_OVERLAP_RATIO_THRESHOLD)) {
if (smaller(maxYOverlapRatio, config::Y_OVERLAP_RATIO_THRESHOLD)) {
_log->debug(p) << BLUE << BOLD << " yes → starts word" << OFF << endl;
return true;
}
Expand All @@ -232,11 +236,11 @@ bool WordsDetector::startsWord(const PdfCharacter* currChar) const {
_log->debug(p) << " └─ hGapRight: " << hGapRight << endl;
_log->debug(p) << " └─ threshold: " << hGapThreshold << endl;

if (ppp::math_utils::larger(hGapLeft, hGapThreshold)) {
if (larger(hGapLeft, hGapThreshold)) {
_log->debug(p) << BLUE << BOLD << " yes (hGapLeft) → starts word" << OFF << endl;
return true;
}
if (ppp::math_utils::larger(hGapRight, hGapThreshold)) {
if (larger(hGapRight, hGapThreshold)) {
_log->debug(p) << BLUE << BOLD << " yes (hGapRight) → starts word" << OFF << endl;
return true;
}
Expand Down Expand Up @@ -316,7 +320,7 @@ void WordsDetector::mergeStackedMathSymbols(const PdfPage* page) const {
double maxXOverlapRatio = element_utils::computeMaxXOverlapRatio(word, prevWord);
_log->debug(p) << " └─ maxXOverlapRatio: " << maxXOverlapRatio << endl;
_log->debug(p) << " └─ xOverlapRatioThreshold: " << xOverlapRatioThreshold << endl;
if (ppp::math_utils::smaller(maxXOverlapRatio, xOverlapRatioThreshold)) {
if (smaller(maxXOverlapRatio, xOverlapRatioThreshold)) {
_log->debug(p) << BOLD << "is *not* part of the stacked math symbol "
<< "(maxXOverlapRatio < threshold)." << OFF << endl;
break;
Expand All @@ -326,7 +330,7 @@ void WordsDetector::mergeStackedMathSymbols(const PdfPage* page) const {
// smaller than the font size of the base word.
_log->debug(p) << " └─ prevWord.fontSize: " << prevWord->fontSize << endl;
_log->debug(p) << " └─ word.fontSize: " << word->fontSize << endl;
if (!ppp::math_utils::smaller(prevWord->fontSize, word->fontSize, config::FSIZE_EQUAL_TOLERANCE)) {
if (!smaller(prevWord->fontSize, word->fontSize, config::FSIZE_EQUAL_TOLERANCE)) {
_log->debug(p) << BOLD << "is *not* part of the stacked math symbol "
<< "(prevWord.fontSize >= word.fontSize)." << OFF << endl;
break;
Expand Down Expand Up @@ -358,7 +362,7 @@ void WordsDetector::mergeStackedMathSymbols(const PdfPage* page) const {
double maxXOverlapRatio = element_utils::computeMaxXOverlapRatio(word, nextWord);
_log->debug(p) << " └─ maxXOverlapRatio: " << maxXOverlapRatio << endl;
_log->debug(p) << " └─ minXOverlapRatioThreshold: " << xOverlapRatioThreshold << endl;
if (ppp::math_utils::smaller(maxXOverlapRatio, xOverlapRatioThreshold)) {
if (smaller(maxXOverlapRatio, xOverlapRatioThreshold)) {
_log->debug(p) << BOLD << "is *not* part of the stacked math symbol "
<< "(maxXOverlapRatio < threshold)." << OFF << endl;
break;
Expand All @@ -368,7 +372,7 @@ void WordsDetector::mergeStackedMathSymbols(const PdfPage* page) const {
// smaller than the font size of the base word.
_log->debug(p) << " └─ nextWord.fontSize: " << nextWord->fontSize << endl;
_log->debug(p) << " └─ word.fontSize: " << word->fontSize << endl;
if (!ppp::math_utils::smaller(nextWord->fontSize, word->fontSize, config::FSIZE_EQUAL_TOLERANCE)) {
if (!smaller(nextWord->fontSize, word->fontSize, config::FSIZE_EQUAL_TOLERANCE)) {
_log->debug(p) << BOLD << "is *not* part of the stacked math symbol "
<< "(nextWord.fontSize >= word.fontSize)." << OFF << endl;
break;
Expand Down
Loading

0 comments on commit ec3849f

Please sign in to comment.