diff --git a/src/UglyToad.PdfPig/Fonts/Simple/Type1FontSimple.cs b/src/UglyToad.PdfPig/Fonts/Simple/Type1FontSimple.cs index 05b2bbca..0603d360 100644 --- a/src/UglyToad.PdfPig/Fonts/Simple/Type1FontSimple.cs +++ b/src/UglyToad.PdfPig/Fonts/Simple/Type1FontSimple.cs @@ -127,7 +127,7 @@ boundingBox = matrix.Transform(boundingBox); - var width = matrix.TransformX(widths[characterCode - firstChar]); + var width = matrix.TransformX(GetWidth(characterCode, boundingBox)); var result = new CharacterBoundingBox(boundingBox, width); @@ -135,6 +135,23 @@ return result; } + + private decimal GetWidth(int characterCode, PdfRectangle boundingBox) + { + var widthIndex = characterCode - firstChar; + + if (widthIndex >= 0 && widthIndex < widths.Length) + { + return widths[widthIndex]; + } + + if (fontDescriptor?.MissingWidth != null) + { + return fontDescriptor.MissingWidth; + } + + return boundingBox.Width; + } private PdfRectangle GetBoundingBoxInGlyphSpace(int characterCode) {