@@ -685,6 +685,8 @@ void HOCRPdfExporter::printChildren(PDFPainter& painter, const HOCRItem* item, c
685685 QString itemClass = item->itemClass ();
686686 QRect itemRect = item->bbox ();
687687 int childCount = item->children ().size ();
688+ bool prevSpacedWord, currentSpacedWord;
689+ prevSpacedWord = currentSpacedWord = false ;
688690 if (itemClass == " ocr_par" && pdfSettings.uniformizeLineSpacing ) {
689691 double yInc = double (itemRect.height ()) / childCount;
690692 double y = itemRect.top () + yInc;
@@ -703,15 +705,24 @@ void HOCRPdfExporter::printChildren(PDFPainter& painter, const HOCRItem* item, c
703705 if (pdfSettings.fontSize == -1 ) {
704706 painter.setFontSize (wordItem->fontSize () * pdfSettings.detectedFontScaling );
705707 }
708+
709+ prevWordRight = wordRect.right ();
710+ QString text = wordItem->text ();
711+ currentSpacedWord = Utils::spacedWord (text, false );
706712 // If distance from previous word is large, keep the space
707713 if (wordRect.x () - prevWordRight > pdfSettings.preserveSpaceWidth * painter.getAverageCharWidth () / px2pu) {
708714 x = wordRect.x ();
715+ } else {
716+ // need space
717+ if (currentSpacedWord && prevSpacedWord ) {
718+ x += painter.getTextWidth (" " ) / px2pu;
719+ }
709720 }
710- prevWordRight = wordRect.right ();
711- QString text = wordItem->text ();
721+
712722 double wordBaseline = (x - itemRect.x ()) * baseline.first + baseline.second ;
713723 painter.drawText (x * px2pu, (y + wordBaseline) * px2pu, text);
714- x += painter.getTextWidth (text + " " ) / px2pu;
724+ x += painter.getTextWidth (text) / px2pu;
725+ prevSpacedWord = Utils::spacedWord (text, true );
715726 }
716727 }
717728 } else if (itemClass == " ocr_line" && !pdfSettings.uniformizeLineSpacing ) {
0 commit comments