Use correct font matrix when transforming the width in Type 0 font and fix #1156

This commit is contained in:
BobLd
2025-09-14 08:13:22 +01:00
parent 07df6fd740
commit 304d7dde5a
2 changed files with 32 additions and 3 deletions

View File

@@ -7,6 +7,36 @@
public class GithubIssuesTests
{
[Fact]
public void Issue1156()
{
var path = IntegrationHelpers.GetDocumentPath("felltypes-test.pdf");
using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = true }))
{
var page = document.GetPage(1);
var letters = page.Letters;
var words = NearestNeighbourWordExtractor.Instance.GetWords(letters).ToArray();
var wordThe = words[0];
Assert.Equal("THE", wordThe.Text);
Assert.Equal(wordThe.BoundingBox.BottomLeft, new PdfPoint(x: 242.9877, y: 684.7435));
Assert.Equal(wordThe.BoundingBox.BottomRight, new PdfPoint(x: 323.93999999999994, y: 684.7435));
var wordBook = words[2];
Assert.Equal("BOOK:", wordBook.Text);
Assert.Equal(wordBook.BoundingBox.BottomLeft, new PdfPoint(x: 280.4371, y: 652.0399));
Assert.Equal(wordBook.BoundingBox.BottomRight, new PdfPoint(x: 405.65439999999995, y: 652.0399));
var wordPremeffa = words[35];
Assert.Equal("preme\ue009a.", wordPremeffa.Text); // The 'ff' glyph is not properly parsed
Assert.Equal(wordPremeffa.BoundingBox.BottomLeft, new PdfPoint(x: 331.16020000000003, y: 515.2256999999998));
Assert.Equal(wordPremeffa.BoundingBox.BottomRight, new PdfPoint(x: 374.2954000000001, y: 515.2256999999998));
}
}
[Fact]
public void Issue1148()
{

View File

@@ -126,12 +126,11 @@
// Get the bounding box in glyph space
var boundingBox = CidFont.GetBoundingBox(characterIdentifier);
var fontMatrix = CidFont.GetFontMatrix(characterIdentifier);
boundingBox = fontMatrix.Transform(boundingBox);
boundingBox = CidFont.GetFontMatrix(characterIdentifier).Transform(boundingBox);
var width = CidFont.GetWidthFromFont(characterIdentifier);
var advanceWidth = fontMatrix.TransformX(width);
var advanceWidth = GetFontMatrix().TransformX(width);
var result = new CharacterBoundingBox(boundingBox, advanceWidth);