[
https://issues.apache.org/jira/browse/PDFBOX-4951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18101046#comment-18101046
]
Tilman Hausherr commented on PDFBOX-4951:
-----------------------------------------
I was thinking again about {{PDFont.getStringWidth()}}, that it would not
return the correct result, and yes it didn't. Try this in
GlyphLayoutLigaturesAndKerningTest:
{code:java}
float f1 = dejavuFont.getStringWidth(DEJAVU_STRING) *
dejavuFont.getFontMatrix().getScaleX() * fontSize;
float f2 = dejavuLigKernFont.getStringWidth(DEJAVU_STRING) *
dejavuLigKernFont.getFontMatrix().getScaleX() * fontSize;
System.out.println("widths: " + f1 + " " + f2);
{code}
output:
widths: 291.144 291.144
the two numbers should be different.
So I added this to the awt processor:
{code:java}
public float getStringWidth(PDType0Font font, float fontSize, String text)
{
FontRenderContext fontRenderContext = new FontRenderContext(new
AffineTransform(), false, true);
// use fractional metrics
Font awtFont =
glyphLayoutFontLoaderAwt.getAwtFont(font).deriveFont(fontSize);
checkMissingGlyphs(text, awtFont);
Rectangle2D rect = awtFont.getStringBounds(text, fontRenderContext);
return (float) rect.getWidth();
}
{code}
and changed the test code to
{code:java}
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);
System.out.println("widths: " + f1 + " " + f2);
System.out.println("widths: " + f3 + " " + f4);
{code}
and the output is now:
widths: 291.144 291.144
widths: 291.10547 287.1621
I also added this code to the test to visualize the lengths:
{code:java}
cs.setStrokingColor(0);
cs.moveTo(x, 734);
cs.lineTo(x + f1, 734);
cs.stroke();
cs.moveTo(x, 674);
cs.lineTo(x + f2, 674);
cs.stroke();
cs.moveTo(x, 676);
cs.lineTo(x + f4, 676);
cs.stroke();
{code}
Should we add this? Btw no bidi stuff involved, I didn't find anything in the
awt font API.
> Sequences of DIN SPEC 91379 with combining letters are rendered incorrectly
> ---------------------------------------------------------------------------
>
> Key: PDFBOX-4951
> URL: https://issues.apache.org/jira/browse/PDFBOX-4951
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.21
> Reporter: Volker Kunert
> Assignee: Tilman Hausherr
> Priority: Major
> Fix For: 3.0.9 PDFBox, 4.0.0
>
> Attachments: Bildschirmfoto_2026-07-07_08-38-04.png,
> DIN_SPEC_91379_Sequences-aa.pdf, DIN_SPEC_91379_Sequences-ab.pdf,
> DIN_SPEC_91379_Sequences-ac.pdf, DIN_SPEC_91379_Sequences.txt,
> DefaultScriptProcessor.java, DejaVuSans.ttf, DoGlyphLayoutBidi.pdf,
> DoGlyphLayoutDinSpec91379.pdf, DoGlyphLayoutDinSpec91379Form.pdf,
> DoGlyphPositionBengali.pdf, ExamplePdfboxFopPos-By-Tilman.pdf,
> ExamplePdfboxFopPos.java, ExamplePdfboxFopPos.pdf,
> ExamplePdfboxFopPosForm.java, ExamplePdfboxFopPosForm.pdf,
> FiraCode-Regular.ttf, FontForge-Lohit-Bengali.png, TestPdfbox.java,
> TestPdfboxFop2.java, TestPdfboxFop2.pdf, TestPdfboxJava2D.java,
> TestPdfboxJava2D.pdf, bengali.fo, bengali.pdf, bidi-1.png, bidi-2.png,
> bidi.fo, bidi.pdf, bidi.png, config.xml, dejavu-sequences.png,
> example-PDFBOX-3147-NotoSansThaiLooped-Regular.png,
> image-2026-05-23-16-16-53-442.png, image-2026-05-23-16-17-28-172.png,
> image-2026-05-26-16-49-45-529.png, image-2026-07-04-21-37-03-606.png,
> image-2026-07-04-21-37-35-370.png, kerning.fo, kerning.pdf,
> ligatures-kerning.png, patch-2020-10-02.txt, pdfbox.patch, pdfbox.pdf,
> screenshot-1.png, screenshot-2.png, screenshot-3.png
>
>
> Accented Letters composed of Unicode base letter and combining accent are
> rendered wrong. E.g. with 0041 030B LATIN CAPITAL LETTER A WITH COMBINING
> DOUBLE ACUTE ACCENT the accent appears at the right hand side of the letter
> A, not above the letter A.
> The position is wrong for most of the sequences defined in the following spec:
> DIN SPEC 91379: Characters in Unicode for the electronic processing of names
> and data
> exchange in Europe; with digital attachment
> [https://www.xoev.de/downloads-2316#StringLatin]
> [https://www.din.de/de/wdc-beuth:din21:301228458]
>
> The correct rendering should look like the output of hb-view 2.6.8, see files
> DIN_SPEC_91379_Sequences*.pdf.
> The output of PDFBox is appended in pdfbox.pdf, which is created by running
> TestPdfbox.java. The sequences are read from file
> DIN_SPEC_91379_Sequences.txt.
>
> Font used for testing: NotoSansMono-Regular.ttf, see
> [https://www.google.com/get/noto/]
> download:
> [https://noto-website-2.storage.googleapis.com/pkgs/NotoSansMono-hinted.zip]
> See also FOP-2969
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]