Skip to content

Commit c4f442c

Browse files
committed
Properly fix #1148 by always parsing optional tables in TrueTypeFontParser and remove Type 0 font hack
1 parent 0ef120d commit c4f442c

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

src/UglyToad.PdfPig.Fonts/TrueType/Parser/TrueTypeFontParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ private static TrueTypeFont ParseTables(float version, IReadOnlyDictionary<strin
121121

122122
// glyf
123123
builder.GlyphDataTable = GlyphDataTable.Load(data, glyphHeaderTable, builder);
124-
125-
OptionallyParseTables(tables, data, builder);
126124
}
127125

126+
OptionallyParseTables(tables, data, builder);
127+
128128
return new TrueTypeFont(version, tables, builder.Build());
129129
}
130130

src/UglyToad.PdfPig/PdfFonts/Composite/Type0Font.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,7 @@ public CharacterBoundingBox GetBoundingBox(int characterCode)
131131

132132
var width = CidFont.GetWidthFromFont(characterIdentifier);
133133

134-
double scale = fontMatrix.A;
135-
if (Math.Abs(scale - 0.001) < 0.0001)
136-
{
137-
// BobLD: The value of scale is close enough to 0.001 to be able to use 0.001.
138-
// Still not sure what is the correct logic, but this hack fixes issue #1148 (while not breaking "Old Gutnish Internet Explorer.pdf")
139-
//
140-
// Based on https://martin.hoppenheit.info/blog/2018/pdfa-validation-and-inconsistent-glyph-width-information/
141-
// which quotes: section 6.2.11.5 of ISO 19005-2:2011 (PDF/A-2) clarifies this issue: “For ISO 19005, consistent is defined to be a difference of no more than 1/1000 unit.”
142-
scale = 0.001;
143-
}
144-
145-
var advanceWidth = scale * width;
134+
var advanceWidth = fontMatrix.TransformX(width);
146135

147136
var result = new CharacterBoundingBox(boundingBox, advanceWidth);
148137

0 commit comments

Comments
 (0)