From b055d659b05080d239bc30658230d3b40f29f7b2 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 30 Nov 2011 22:36:10 +0000 Subject: [PATCH] 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 --- core/textpage.cpp | 50 +++++++++++++---------------------------------- core/textpage_p.h | 2 +- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/core/textpage.cpp b/core/textpage.cpp index 211325f67..a11c79f06 100644 --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -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 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 diff --git a/core/textpage_p.h b/core/textpage_p.h index 953e9d1f0..3cdf956e8 100644 --- a/core/textpage_p.h +++ b/core/textpage_p.h @@ -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