From 729234477a7b8547bdb2db2a41cbd320093c2aa7 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sat, 4 Apr 2020 17:30:06 +0100 Subject: [PATCH] fix issue with null encodings for cid fonts --- .../PdfFonts/CidFonts/PdfCidCompactFontFormatFont.cs | 8 +++++++- .../PdfFonts/Parser/Parts/CidFontFactory.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/UglyToad.PdfPig/PdfFonts/CidFonts/PdfCidCompactFontFormatFont.cs b/src/UglyToad.PdfPig/PdfFonts/CidFonts/PdfCidCompactFontFormatFont.cs index 2e0db0fb..6059ecf4 100644 --- a/src/UglyToad.PdfPig/PdfFonts/CidFonts/PdfCidCompactFontFormatFont.cs +++ b/src/UglyToad.PdfPig/PdfFonts/CidFonts/PdfCidCompactFontFormatFont.cs @@ -1,7 +1,6 @@ namespace UglyToad.PdfPig.PdfFonts.CidFonts { using System; - using System.Linq; using Core; using Fonts.CompactFontFormat; @@ -20,8 +19,15 @@ public bool TryGetBoundingBox(int characterIdentifier, out PdfRectangle boundingBox) { + boundingBox = new PdfRectangle(0, 0, 500, 0); + var font = GetFont(); + if (font.Encoding == null) + { + return false; + } + var characterName = GetCharacterName(characterIdentifier); boundingBox = font.GetCharacterBoundingBox(characterName) ?? new PdfRectangle(0, 0, 500, 0); diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs index 632fb149..e5241086 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs @@ -157,7 +157,7 @@ { var widths = new Dictionary(); - if (!dict.TryGet(NameToken.W, out var widthsItem) || !(widthsItem is ArrayToken widthArray)) + if (!dict.TryGet(NameToken.W, pdfScanner, out ArrayToken widthArray)) { return widths; }