From 198cca13365af1144de4229151359966db3ad76e Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 7 Jul 2019 12:12:09 +0100 Subject: [PATCH] change point size calculation to use rotation #41 point size was previously only calculated based on the transformation matrix but now uses the transformation matrix, the rotation matrix and the font matrix values. the calculated value still seems unlikely to be correct so it is exposed using the page's experimental access for now, rather than as a public getter. --- src/UglyToad.PdfPig/Content/Page.cs | 9 +++++++++ src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/UglyToad.PdfPig/Content/Page.cs b/src/UglyToad.PdfPig/Content/Page.cs index bb08f029..c0458446 100644 --- a/src/UglyToad.PdfPig/Content/Page.cs +++ b/src/UglyToad.PdfPig/Content/Page.cs @@ -154,6 +154,15 @@ { return annotationProvider.GetAnnotations(); } + + /// + /// Gets the calculated letter size in points. + /// This is considered experimental because the calculated value is incorrect for some documents at present. + /// + public decimal GetPointSize(Letter letter) + { + return letter.PointSize; + } } } } \ No newline at end of file diff --git a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs index 9839c316..915f8130 100644 --- a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs @@ -126,7 +126,7 @@ // TODO: this does not seem correct, produces the correct result for now but we need to revisit. // see: https://stackoverflow.com/questions/48010235/pdf-specification-get-font-size-in-points - var pointSize = decimal.Round(fontSize * transformationMatrix.A, 2); + var pointSize = decimal.Round(rotation.Rotate(transformationMatrix).Multiply(TextMatrices.TextMatrix).Multiply(fontSize).A, 2); while (bytes.MoveNext()) {