@@ -688,6 +688,8 @@ void HOCRPdfExporter::printChildren(PDFPainter& painter, const HOCRItem* item, c
688
688
QString itemClass = item->itemClass ();
689
689
QRect itemRect = item->bbox ();
690
690
int childCount = item->children ().size ();
691
+ bool prevSpacedWord, currentSpacedWord;
692
+ prevSpacedWord = currentSpacedWord = false ;
691
693
if (itemClass == " ocr_par" && pdfSettings.uniformizeLineSpacing ) {
692
694
double yInc = double (itemRect.height ()) / childCount;
693
695
double y = itemRect.top () + yInc;
@@ -706,15 +708,24 @@ void HOCRPdfExporter::printChildren(PDFPainter& painter, const HOCRItem* item, c
706
708
if (pdfSettings.fontSize == -1 ) {
707
709
painter.setFontSize (wordItem->fontSize () * pdfSettings.detectedFontScaling );
708
710
}
711
+
712
+ prevWordRight = wordRect.right ();
713
+ QString text = wordItem->text ();
714
+ currentSpacedWord = Utils::spacedWord (text, false );
709
715
// If distance from previous word is large, keep the space
710
716
if (wordRect.x () - prevWordRight > pdfSettings.preserveSpaceWidth * painter.getAverageCharWidth () / px2pu) {
711
717
x = wordRect.x ();
718
+ } else {
719
+ // need space
720
+ if (currentSpacedWord && prevSpacedWord ) {
721
+ x += painter.getTextWidth (" " ) / px2pu;
722
+ }
712
723
}
713
- prevWordRight = wordRect.right ();
714
- QString text = wordItem->text ();
724
+
715
725
double wordBaseline = (x - itemRect.x ()) * baseline.first + baseline.second ;
716
726
painter.drawText (x * px2pu, (y + wordBaseline) * px2pu, text);
717
- x += painter.getTextWidth (text + " " ) / px2pu;
727
+ x += painter.getTextWidth (text) / px2pu;
728
+ prevSpacedWord = Utils::spacedWord (text, true );
718
729
}
719
730
}
720
731
} else if (itemClass == " ocr_line" && !pdfSettings.uniformizeLineSpacing ) {
0 commit comments