@@ -688,6 +688,8 @@ void HOCRPdfExporter::printChildren(PDFPainter& painter, const HOCRItem* item, c
688688 QString itemClass = item->itemClass ();
689689 QRect itemRect = item->bbox ();
690690 int childCount = item->children ().size ();
691+ bool prevSpacedWord, currentSpacedWord;
692+ prevSpacedWord = currentSpacedWord = false ;
691693 if (itemClass == " ocr_par" && pdfSettings.uniformizeLineSpacing ) {
692694 double yInc = double (itemRect.height ()) / childCount;
693695 double y = itemRect.top () + yInc;
@@ -706,15 +708,24 @@ void HOCRPdfExporter::printChildren(PDFPainter& painter, const HOCRItem* item, c
706708 if (pdfSettings.fontSize == -1 ) {
707709 painter.setFontSize (wordItem->fontSize () * pdfSettings.detectedFontScaling );
708710 }
711+
712+ prevWordRight = wordRect.right ();
713+ QString text = wordItem->text ();
714+ currentSpacedWord = Utils::spacedWord (text, false );
709715 // If distance from previous word is large, keep the space
710716 if (wordRect.x () - prevWordRight > pdfSettings.preserveSpaceWidth * painter.getAverageCharWidth () / px2pu) {
711717 x = wordRect.x ();
718+ } else {
719+ // need space
720+ if (currentSpacedWord && prevSpacedWord ) {
721+ x += painter.getTextWidth (" " ) / px2pu;
722+ }
712723 }
713- prevWordRight = wordRect.right ();
714- QString text = wordItem->text ();
724+
715725 double wordBaseline = (x - itemRect.x ()) * baseline.first + baseline.second ;
716726 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 );
718729 }
719730 }
720731 } else if (itemClass == " ocr_line" && !pdfSettings.uniformizeLineSpacing ) {
0 commit comments