Simplify the code

TextPagePrivate::correctTextOrder was running makeAndSortLines + calculateStatisticalInformation to calculate the tcx, tcy
to pass it to XYCutForBoundingBoxes and then in XYCutForBoundingBoxes we were doing the same but just for when countLoop was not 0, thus
if we remove the first code and remove the check for countLoop being not 0 we end up with the same behaviour
remotes/origin/KDE/4.8
Albert Astals Cid 14 years ago
parent d49894b9d2
commit b055d659b0
  1. 50
      core/textpage.cpp
  2. 2
      core/textpage_p.h

@ -1512,7 +1512,7 @@ void TextPagePrivate::calculateStatisticalInformation(const SortedTextList &line
/**
* Implements the XY Cut algorithm for textpage segmentation
*/
RegionTextList TextPagePrivate::XYCutForBoundingBoxes(int tcx, int tcy)
RegionTextList TextPagePrivate::XYCutForBoundingBoxes()
{
const int pageWidth = m_page->m_page->width();
const int pageHeight = m_page->m_page->height();
@ -1525,7 +1525,6 @@ RegionTextList TextPagePrivate::XYCutForBoundingBoxes(int tcx, int tcy)
tree.push_back(root);
int i = 0, j, k;
int countLoop = 0;
// while traversing the tree has not been ended
while(i < tree.length())
@ -1549,23 +1548,20 @@ RegionTextList TextPagePrivate::XYCutForBoundingBoxes(int tcx, int tcy)
const TextList list = node.text();
// Calculate tcx and tcy locally for each new region
if(countLoop++)
{
SortedTextList lines;
LineRect line_rects;
int word_spacing, line_spacing, column_spacing;
SortedTextList lines;
LineRect line_rects;
int word_spacing, line_spacing, column_spacing;
makeAndSortLines(list, &lines, &line_rects);
calculateStatisticalInformation(lines, line_rects, &word_spacing, &line_spacing, &column_spacing);
for(int i = 0 ; i < lines.length() ; i++)
{
qDeleteAll(lines.at(i));
}
lines.clear();
makeAndSortLines(list, &lines, &line_rects);
calculateStatisticalInformation(lines, line_rects, &word_spacing, &line_spacing, &column_spacing);
for(j = 0 ; j < lines.length() ; j++)
{
qDeleteAll(lines.at(j));
}
lines.clear();
tcx = word_spacing * 2;
tcy = line_spacing * 2;
}
const int tcx = word_spacing * 2;
const int tcy = line_spacing * 2;
int maxX = 0 , maxY = 0;
int avgX = 0 ;
@ -1927,28 +1923,10 @@ void TextPagePrivate::correctTextOrder()
*/
const QHash<QRect, RegionText> word_chars_map = makeWordFromCharacters();
SortedTextList lines;
LineRect line_rects;
/**
* Create arbitrary lines from words and sort them according to X and Y position
*/
makeAndSortLines(m_words, &lines, &line_rects);
/**
* Calculate statistical information which will be needed later for algorithm implementation
*/
int word_spacing, line_spacing, col_spacing;
calculateStatisticalInformation(lines, line_rects, &word_spacing, &line_spacing, &col_spacing);
for(int i = 0 ; i < lines.length() ; i++)
{
qDeleteAll(lines.at(i));
}
lines.clear();
/**
* Make a XY Cut tree for segmentation of the texts
*/
const RegionTextList tree = XYCutForBoundingBoxes(word_spacing * 2, line_spacing * 2);
const RegionTextList tree = XYCutForBoundingBoxes();
/**
* Add spaces to the word

@ -98,7 +98,7 @@ class TextPagePrivate
* Functions necessary for document file segmentation into text regions for document layout
* analysis.
*/
RegionTextList XYCutForBoundingBoxes(int tcx, int tcy);
RegionTextList XYCutForBoundingBoxes();
/**
* Add additional spaces between words, if necessary, which can make the words valuable

Loading…
Cancel
Save