default height from font matrix for type 0 fonts when height missing #287

This commit is contained in:
Eliot Jones 2021-02-28 13:48:23 -04:00
parent 13247a5218
commit 6a1fa544d2
2 changed files with 10 additions and 7 deletions

View File

@ -10,7 +10,7 @@
{ {
var names = Standard14.GetNames().Count; var names = Standard14.GetNames().Count;
Assert.Equal(38, names); Assert.Equal(39, names);
} }
} }
} }

View File

@ -16,6 +16,7 @@
private readonly ICidFontProgram fontProgram; private readonly ICidFontProgram fontProgram;
private readonly VerticalWritingMetrics verticalWritingMetrics; private readonly VerticalWritingMetrics verticalWritingMetrics;
private readonly double? defaultWidth; private readonly double? defaultWidth;
private readonly double scale;
public NameToken Type { get; } public NameToken Type { get; }
@ -46,11 +47,13 @@
this.fontProgram = fontProgram; this.fontProgram = fontProgram;
this.verticalWritingMetrics = verticalWritingMetrics; this.verticalWritingMetrics = verticalWritingMetrics;
this.defaultWidth = defaultWidth; this.defaultWidth = defaultWidth;
scale = 1 / (double)(fontProgram?.GetFontMatrixMultiplier() ?? 1000);
Type = type; Type = type;
SubType = subType; SubType = subType;
BaseFont = baseFont; BaseFont = baseFont;
SystemInfo = systemInfo; SystemInfo = systemInfo;
var scale = 1 / (double)(fontProgram?.GetFontMatrixMultiplier() ?? 1000);
FontMatrix = TransformationMatrix.FromValues(scale, 0, 0, scale, 0, 0); FontMatrix = TransformationMatrix.FromValues(scale, 0, 0, scale, 0, 0);
Descriptor = descriptor; Descriptor = descriptor;
Widths = widths; Widths = widths;
@ -96,7 +99,7 @@
if (fontProgram == null) if (fontProgram == null)
{ {
return Descriptor?.BoundingBox ?? new PdfRectangle(0, 0, 1000, 0); return Descriptor?.BoundingBox ?? new PdfRectangle(0, 0, 1000, 1.0 / scale);
} }
if (fontProgram.TryGetBoundingBox(characterIdentifier, out var boundingBox)) if (fontProgram.TryGetBoundingBox(characterIdentifier, out var boundingBox))
@ -106,15 +109,15 @@
if (Widths.TryGetValue(characterIdentifier, out var width)) if (Widths.TryGetValue(characterIdentifier, out var width))
{ {
return new PdfRectangle(0, 0, width, 0); return new PdfRectangle(0, 0, width, 1.0 / scale);
} }
if (defaultWidth.HasValue) if (defaultWidth.HasValue)
{ {
return new PdfRectangle(0, 0, defaultWidth.Value, 0); return new PdfRectangle(0, 0, defaultWidth.Value, 1.0 / scale);
} }
return new PdfRectangle(0, 0, 1000, 0); return new PdfRectangle(0, 0, 1000, 1.0 / scale);
} }
public PdfVector GetPositionVector(int characterIdentifier) public PdfVector GetPositionVector(int characterIdentifier)