From 4d911fb9d16a23bddb34acab614c7b4c021ca639 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Fri, 28 Feb 2020 15:15:16 +0000 Subject: [PATCH] use transform x for widths to improve performance when transforming the advance width inside a font, we transform only the x coordinate rather than making a new point to transform. --- src/UglyToad.PdfPig/PdfFonts/Composite/Type0Font.cs | 2 +- src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs | 4 ++-- src/UglyToad.PdfPig/PdfFonts/Simple/Type3Font.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/UglyToad.PdfPig/PdfFonts/Composite/Type0Font.cs b/src/UglyToad.PdfPig/PdfFonts/Composite/Type0Font.cs index 92ca3976..a4ba68fe 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Composite/Type0Font.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Composite/Type0Font.cs @@ -94,7 +94,7 @@ var width = CidFont.GetWidthFromFont(characterIdentifier); - var advanceWidth = matrix.Transform(new PdfPoint(width, 0)).X; + var advanceWidth = matrix.TransformX(width); return new CharacterBoundingBox(boundingBox, advanceWidth); } diff --git a/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs b/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs index edf87ef9..fd9fb3a0 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs @@ -159,11 +159,11 @@ if (fromFont) { - width = fontMatrix.Transform(new PdfPoint(width, 0)).X; + width = fontMatrix.TransformX(width); } else { - width = DefaultTransformation.Transform(new PdfPoint(width, 0)).X; + width = DefaultTransformation.TransformX(width); } var result = new CharacterBoundingBox(boundingBox, width); diff --git a/src/UglyToad.PdfPig/PdfFonts/Simple/Type3Font.cs b/src/UglyToad.PdfPig/PdfFonts/Simple/Type3Font.cs index 989fc86d..b2906833 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Simple/Type3Font.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Simple/Type3Font.cs @@ -67,7 +67,7 @@ characterBoundingBox = fontMatrix.Transform(characterBoundingBox); - var width = fontMatrix.Transform(new PdfPoint(widths[characterCode - firstChar], 0)).X; + var width = fontMatrix.TransformX(widths[characterCode - firstChar]); return new CharacterBoundingBox(characterBoundingBox, width); } @@ -79,7 +79,7 @@ throw new InvalidFontFormatException($"The character code was not contained in the widths array: {characterCode}."); } - return new PdfRectangle(0, 0, widths[characterCode - firstChar], 0); ; + return new PdfRectangle(0, 0, widths[characterCode - firstChar], 0); } public TransformationMatrix GetFontMatrix()