Skip to content

Commit e40be42

Browse files
committed
Fix font size calculation
DEVSIX-7182
1 parent ff2b7d7 commit e40be42

27 files changed

Lines changed: 13 additions & 13 deletions

pdfocr-api/src/main/java/com/itextpdf/pdfocr/OcrPdfCreator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,7 @@ private void addTextToCanvas(
591591
.setHorizontalScaling(bboxWidthPt / lineWidth);
592592

593593
Paragraph paragraph = new Paragraph(text)
594-
.setMargin(0)
595-
.setMultipliedLeading(1.2f);
594+
.setMargin(0);
596595
paragraph.setFontFamily(fontFamily)
597596
.setFontSize(fontSize);
598597
paragraph.setWidth(bboxWidthPt * 1.5f);

pdfocr-api/src/main/java/com/itextpdf/pdfocr/PdfCreatorUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static float calculateFontSize(final Document document, final String line,
9696

9797
try {
9898
Paragraph paragraph = new Paragraph(line);
99+
paragraph.setMargin(0);
99100
paragraph.setWidth(bbox.getWidth());
100101
paragraph.setFontFamily(fontFamily);
101102

pdfocr-tesseract4/src/test/java/com/itextpdf/pdfocr/tessdata/TessDataIntegrationLibTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public void compareInvoiceFrontThaiImage() throws InterruptedException, java.io.
101101
TEST_IMAGES_DIRECTORY + filename + ".jpg", resultPdfPath,
102102
Arrays.<String>asList("tha", "eng"), Arrays.<String>asList(NOTO_SANS_THAI_FONT_PATH, NOTO_SANS_FONT_PATH), DeviceRgb.RED);
103103
boolean javaTest = new CompareTool().compareByContent(resultPdfPath, expectedPdfPathJava,
104-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
104+
getTargetDirectory(), "diff_") == null;
105105
boolean dotNetTest = new CompareTool().compareByContent(resultPdfPath, expectedPdfPathDotNet,
106-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
106+
getTargetDirectory(), "diff_") == null;
107107

108108
Assert.assertTrue(javaTest || dotNetTest);
109109
}
@@ -134,9 +134,9 @@ public void compareThaiTextImage() throws InterruptedException, java.io.IOExcept
134134
TEST_IMAGES_DIRECTORY + filename + ".jpg", resultPdfPath,
135135
Arrays.<String>asList("tha"), Arrays.<String>asList(NOTO_SANS_THAI_FONT_PATH), DeviceRgb.RED);
136136
boolean javaTest = new CompareTool().compareByContent(resultPdfPath, expectedPdfPathJava,
137-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
137+
getTargetDirectory(), "diff_") == null;
138138
boolean dotNetTest = new CompareTool().compareByContent(resultPdfPath, expectedPdfPathDotNet,
139-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
139+
getTargetDirectory(), "diff_") == null;
140140

141141
Assert.assertTrue(javaTest || dotNetTest);
142142
}

pdfocr-tesseract4/src/test/java/com/itextpdf/pdfocr/tessdata/TessDataIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public void compareMultiLangImage() throws InterruptedException, IOException {
350350
Arrays.<String>asList("eng", "deu", "spa"), DeviceCmyk.BLACK);
351351

352352
Assert.assertNull(new CompareTool().compareByContent(resultPdfPath, expectedPdfPath,
353-
TEST_DOCUMENTS_DIRECTORY, "diff_"));
353+
getTargetDirectory(), "diff_"));
354354
} finally {
355355
Assert.assertEquals(TextPositioning.BY_WORDS,
356356
tesseractReader.getTesseract4OcrEngineProperties().getTextPositioning());

pdfocr-tesseract4/src/test/java/com/itextpdf/pdfocr/tesseract4/ImageIntegrationTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ public void compareRotatedImage() throws InterruptedException, IOException {
118118
// So the goal of this test is to make text invisible and check if image is rotated.
119119
// Proper text recognition is compared in testHocrRotatedImage test by checking HOCR file.
120120
boolean javaTest = new CompareTool().compareVisually(resultPdfPath, expectedPdfPathJava,
121-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
121+
getTargetDirectory(), "diff_") == null;
122122
boolean dotNetTest = new CompareTool().compareVisually(resultPdfPath, expectedPdfPathDotNet,
123-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
123+
getTargetDirectory(), "diff_") == null;
124124
Assert.assertTrue(javaTest || dotNetTest);
125125

126126
filename = "180_degrees_rotated";
@@ -134,9 +134,9 @@ public void compareRotatedImage() throws InterruptedException, IOException {
134134

135135

136136
javaTest = new CompareTool().compareVisually(resultPdfPath, expectedPdfPathJava,
137-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
137+
getTargetDirectory(), "diff_") == null;
138138
dotNetTest = new CompareTool().compareVisually(resultPdfPath, expectedPdfPathDotNet,
139-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
139+
getTargetDirectory(), "diff_") == null;
140140

141141
Assert.assertTrue(javaTest || dotNetTest);
142142

@@ -151,9 +151,9 @@ public void compareRotatedImage() throws InterruptedException, IOException {
151151

152152

153153
javaTest = new CompareTool().compareVisually(resultPdfPath, expectedPdfPathJava,
154-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
154+
getTargetDirectory(), "diff_") == null;
155155
dotNetTest = new CompareTool().compareVisually(resultPdfPath, expectedPdfPathDotNet,
156-
TEST_DOCUMENTS_DIRECTORY, "diff_") == null;
156+
getTargetDirectory(), "diff_") == null;
157157

158158
Assert.assertTrue(javaTest || dotNetTest);
159159
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)