Merge pull request #229 from BobLd/fix-point-size

Fix Letter's PointSize computation
This commit is contained in:
Eliot Jones
2020-10-13 09:27:40 +01:00
committed by GitHub
3 changed files with 24 additions and 16 deletions

View File

@@ -0,0 +1,22 @@
namespace UglyToad.PdfPig.Tests.Fonts
{
using UglyToad.PdfPig.Tests.Dla;
using Xunit;
public class PointSizeTests
{
[Fact]
public void RotatedText()
{
using (var document = PdfDocument.Open(DlaHelper.GetDocumentPath("complex rotated")))
{
var page = document.GetPage(1);
foreach (var letter in page.Letters)
{
Assert.Equal(12, letter.PointSize);
}
}
}
}
}

View File

@@ -68,7 +68,6 @@
/// <summary> /// <summary>
/// The size of the font in points. /// The size of the font in points.
/// <para>This is considered experimental because the calculated value is incorrect for some documents at present.</para>
/// </summary> /// </summary>
public double PointSize { get; } public double PointSize { get; }

View File

@@ -241,20 +241,7 @@
var renderingMatrix = var renderingMatrix =
TransformationMatrix.FromValues(fontSize * horizontalScaling, 0, 0, fontSize, 0, rise); TransformationMatrix.FromValues(fontSize * horizontalScaling, 0, 0, fontSize, 0, rise);
// TODO: this does not seem correct, produces the correct result for now but we need to revisit. var pointSize = Math.Round(transformationMatrix.Multiply(TextMatrices.TextMatrix).Transform(new PdfRectangle(0, 0, 1, fontSize)).Height, 2);
// see: https://stackoverflow.com/questions/48010235/pdf-specification-get-font-size-in-points
var fontSizeMatrix = transformationMatrix.Multiply(TextMatrices.TextMatrix).Multiply(fontSize);
var pointSize = Math.Round(fontSizeMatrix.A, 2);
// Assume a rotated letter
if (pointSize == 0)
{
pointSize = Math.Round(fontSizeMatrix.B, 2);
}
if (pointSize < 0)
{
pointSize *= -1;
}
while (bytes.MoveNext()) while (bytes.MoveNext())
{ {