Skip to content

Commit

Permalink
default height from font matrix for type 0 fonts when height missing #…
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotJones committed Feb 28, 2021
1 parent 13247a5 commit 6a1fa54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig.Tests/Fonts/Standard14Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void CanCreateStandard14()
{
var names = Standard14.GetNames().Count;

Assert.Equal(38, names);
Assert.Equal(39, names);
}
}
}
15 changes: 9 additions & 6 deletions src/UglyToad.PdfPig/PdfFonts/CidFonts/Type0CidFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class Type0CidFont : ICidFont
private readonly ICidFontProgram fontProgram;
private readonly VerticalWritingMetrics verticalWritingMetrics;
private readonly double? defaultWidth;
private readonly double scale;

public NameToken Type { get; }

Expand Down Expand Up @@ -46,11 +47,13 @@ public Type0CidFont(ICidFontProgram fontProgram, NameToken type, NameToken subTy
this.fontProgram = fontProgram;
this.verticalWritingMetrics = verticalWritingMetrics;
this.defaultWidth = defaultWidth;

scale = 1 / (double)(fontProgram?.GetFontMatrixMultiplier() ?? 1000);

Type = type;
SubType = subType;
BaseFont = baseFont;
SystemInfo = systemInfo;
var scale = 1 / (double)(fontProgram?.GetFontMatrixMultiplier() ?? 1000);
FontMatrix = TransformationMatrix.FromValues(scale, 0, 0, scale, 0, 0);
Descriptor = descriptor;
Widths = widths;
Expand Down Expand Up @@ -96,25 +99,25 @@ public PdfRectangle GetBoundingBox(int characterIdentifier)

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))
{
return boundingBox;
}

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)
{
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)
Expand Down

0 comments on commit 6a1fa54

Please sign in to comment.