mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 03:26:58 +08:00
fix bounding boxes for type 0 truetype fonts
This commit is contained in:
@@ -13,5 +13,7 @@
|
||||
bool TryGetBoundingBox(int characterCode, Func<int, int> characterIdentifierToGlyphIndex, out PdfRectangle boundingBox);
|
||||
|
||||
bool TryGetBoundingAdvancedWidth(int characterCode, out decimal width);
|
||||
|
||||
int GetFontMatrixMultiplier();
|
||||
}
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@
|
||||
this.cidToGid = cidToGid;
|
||||
|
||||
// TODO: This should maybe take units per em into account?
|
||||
var scale = 1 / 1000m;
|
||||
var scale = 1 / (decimal)(fontProgram?.GetFontMatrixMultiplier() ?? 1000);
|
||||
FontMatrix = TransformationMatrix.FromValues(scale, 0, 0, scale, 0, 0);
|
||||
}
|
||||
|
||||
|
@@ -30,8 +30,6 @@
|
||||
|
||||
public bool IsVertical => CMap.WritingMode == WritingMode.Vertical;
|
||||
|
||||
private readonly TransformationMatrix fontMatrix = TransformationMatrix.FromValues(0.001m, 0, 0, 0.001m, 0, 0);
|
||||
|
||||
public Type0Font(NameToken baseFont, ICidFont cidFont, CMap cmap, CMap toUnicodeCMap)
|
||||
{
|
||||
BaseFont = baseFont ?? throw new ArgumentNullException(nameof(baseFont));
|
||||
@@ -73,7 +71,11 @@
|
||||
|
||||
public PdfRectangle GetBoundingBox(int characterCode)
|
||||
{
|
||||
return fontMatrix.Transform(GetBoundingBoxInGlyphSpace(characterCode));
|
||||
var matrix = GetFontMatrix();
|
||||
|
||||
var boundingBox = GetBoundingBoxInGlyphSpace(characterCode);
|
||||
|
||||
return matrix.Transform(boundingBox);
|
||||
}
|
||||
|
||||
public decimal GetWidth(int characterCode)
|
||||
|
@@ -137,7 +137,7 @@ namespace UglyToad.PdfPig.Fonts.Simple
|
||||
|
||||
if (font?.HeaderTable != null)
|
||||
{
|
||||
scale = font.HeaderTable.UnitsPerEm;
|
||||
scale = font.GetFontMatrixMultiplier();
|
||||
}
|
||||
|
||||
return TransformationMatrix.FromValues(1m / scale, 0, 0, 1m / scale, 0, 0);
|
||||
|
@@ -69,6 +69,11 @@
|
||||
return TryGetBoundingAdvancedWidthByIndex(index, out width);
|
||||
}
|
||||
|
||||
public int GetFontMatrixMultiplier()
|
||||
{
|
||||
return HeaderTable?.UnitsPerEm ?? 1000;
|
||||
}
|
||||
|
||||
private bool TryGetBoundingAdvancedWidthByIndex(int index, out decimal width)
|
||||
{
|
||||
width = TableRegister.HorizontalMetricsTable.GetAdvanceWidth(index);
|
||||
|
Reference in New Issue
Block a user