diff --git a/src/UglyToad.PdfPig.Tests/Integration/Documents/capas.pdf b/src/UglyToad.PdfPig.Tests/Integration/Documents/capas.pdf new file mode 100644 index 000000000..a57167ca5 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Integration/Documents/capas.pdf differ diff --git a/src/UglyToad.PdfPig.Tests/Integration/ZapfDingbatsTests.cs b/src/UglyToad.PdfPig.Tests/Integration/ZapfDingbatsTests.cs index 86a7c9b1c..c478ecf7b 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/ZapfDingbatsTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/ZapfDingbatsTests.cs @@ -4,6 +4,17 @@ public class ZapfDingbatsTests { + [Fact] + public void TrueTypeSimpleFont1() + { + using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("capas"))) + { + var page = document.GetPage(18); + // ZapfDingbats characters are spaces + Assert.Contains(" ", page.Letters.Select(l => l.Value)); + } + } + [Fact] public void Type1Standard14Font1() { @@ -17,7 +28,6 @@ public void Type1Standard14Font1() [Fact] public void Type1Standard14Font2() { - // This document does not actually contain circular references using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("MOZILLA-LINK-5251-1"))) { var page = document.GetPage(1); @@ -33,7 +43,6 @@ public void Type1Standard14Font2() [Fact] public void Type1FontSimple1() { - // This document does not actually contain circular references using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("MOZILLA-2775-1"))) { var page = document.GetPage(11); @@ -44,7 +53,6 @@ public void Type1FontSimple1() [Fact] public void Type1FontSimple2() { - // This document does not actually contain circular references using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("PDFBOX-492-4.jar-8"))) { var page = document.GetPage(1); diff --git a/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs b/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs index d23beba69..e16f89ee3 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs @@ -31,6 +31,8 @@ internal sealed class TrueTypeSimpleFont : IFont private readonly double[] widths; + private readonly bool isZapfDingbats; + #nullable disable public NameToken Name { get; } #nullable enable @@ -63,8 +65,7 @@ public TrueTypeSimpleFont( Details = descriptor?.ToDetails(Name?.Data) ?? FontDetails.GetDefault(Name?.Data); - // Assumption is ZapfDingbats is not possible here. We need to change the behaviour if not the case - System.Diagnostics.Debug.Assert(!(encoding is ZapfDingbatsEncoding || Details.Name.Contains("ZapfDingbats"))); + isZapfDingbats = encoding is ZapfDingbatsEncoding || Details.Name.Contains("ZapfDingbats"); } public int ReadCharacterCode(IInputBytes bytes, out int codeLength) @@ -100,12 +101,22 @@ public bool TryGetUnicode(int characterCode, [NotNullWhen(true)] out string? val // If the font is a simple font that uses one of the predefined encodings MacRomanEncoding, MacExpertEncoding, or WinAnsiEncoding... // Map the character code to a character name. - var encodedCharacterName = encoding.GetName(characterCode); + var name = encoding.GetName(characterCode); // Look up the character name in the Adobe Glyph List or additional Glyph List. try { - value = GlyphList.AdobeGlyphList.NameToUnicode(encodedCharacterName); + if (isZapfDingbats) + { + value = GlyphList.ZapfDingbats.NameToUnicode(name); + + if (value is not null) + { + return true; + } + } + + value = GlyphList.AdobeGlyphList.NameToUnicode(name); } catch {