You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2026/08/10 11:39:04 UTC

svn commit: r1937033 - in pdfbox/trunk/pdfbox-layout-awt/src/test: java/org/apache/pdfbox/glyphlayout/awt resources/pdf

Author: tilman
Date: Mon Aug 10 11:39:04 2026
New Revision: 1937033

Log:
PDFBOX-4951: add width test

Modified:
   pdfbox/trunk/pdfbox-layout-awt/src/test/java/org/apache/pdfbox/glyphlayout/awt/GlyphLayoutLigaturesAndKerningTest.java
   pdfbox/trunk/pdfbox-layout-awt/src/test/resources/pdf/GlyphLayoutLigaturesAndKerning.pdf

Modified: pdfbox/trunk/pdfbox-layout-awt/src/test/java/org/apache/pdfbox/glyphlayout/awt/GlyphLayoutLigaturesAndKerningTest.java
==============================================================================
--- pdfbox/trunk/pdfbox-layout-awt/src/test/java/org/apache/pdfbox/glyphlayout/awt/GlyphLayoutLigaturesAndKerningTest.java	Mon Aug 10 11:35:25 2026	(r1937032)
+++ pdfbox/trunk/pdfbox-layout-awt/src/test/java/org/apache/pdfbox/glyphlayout/awt/GlyphLayoutLigaturesAndKerningTest.java	Mon Aug 10 11:39:04 2026	(r1937033)
@@ -23,6 +23,7 @@ import java.net.URISyntaxException;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import org.junit.jupiter.api.Test;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
@@ -144,6 +145,26 @@ class GlyphLayoutLigaturesAndKerningTest
                 cs.showText(" ");
                 cs.showText(BENGALI_STRING2);
                 cs.endText();
+
+                // Test code for the string widths - the widths be different due to kerning
+                float f1 = dejavuFont.getStringWidth(DEJAVU_STRING) * dejavuFont.getFontMatrix().getScaleX() * fontSize;
+                float f2 = dejavuLigKernFont.getStringWidth(DEJAVU_STRING) * dejavuLigKernFont.getFontMatrix().getScaleX() * fontSize;
+                float f3 = glyphLayoutProcessor.getStringWidth(dejavuFont, fontSize, DEJAVU_STRING);
+                float f4 = glyphLayoutProcessor.getStringWidth(dejavuLigKernFont, fontSize, DEJAVU_STRING);
+
+                // equality is expected here, but this shows that the ordinary getStringWidth() isn't helpful
+                assertEquals(f1, f2);
+
+                // kerning output is obviously smaller
+                assertTrue(f4 < f1);
+                assertTrue(f4 < f3);
+
+                cs.moveTo(x, 737);
+                cs.lineTo(x + f3, 737);
+                cs.stroke();
+                cs.moveTo(x, 676);
+                cs.lineTo(x + f4, 676);
+                cs.stroke();
             }
             doc.save(outputFilename);
         }

Modified: pdfbox/trunk/pdfbox-layout-awt/src/test/resources/pdf/GlyphLayoutLigaturesAndKerning.pdf
==============================================================================
Binary file (source and/or target). No diff available.