mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-04-05 20:55:01 +08:00
Properly handle ZapfDingbats font for TrueTypeSimpleFont and add tests
This commit is contained in:
parent
4430a01e43
commit
53cf4f2ced
BIN
src/UglyToad.PdfPig.Tests/Integration/Documents/capas.pdf
Normal file
BIN
src/UglyToad.PdfPig.Tests/Integration/Documents/capas.pdf
Normal file
Binary file not shown.
@ -4,6 +4,17 @@
|
|||||||
|
|
||||||
public class ZapfDingbatsTests
|
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]
|
[Fact]
|
||||||
public void Type1Standard14Font1()
|
public void Type1Standard14Font1()
|
||||||
{
|
{
|
||||||
@ -17,7 +28,6 @@
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Type1Standard14Font2()
|
public void Type1Standard14Font2()
|
||||||
{
|
{
|
||||||
// This document does not actually contain circular references
|
|
||||||
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("MOZILLA-LINK-5251-1")))
|
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("MOZILLA-LINK-5251-1")))
|
||||||
{
|
{
|
||||||
var page = document.GetPage(1);
|
var page = document.GetPage(1);
|
||||||
@ -33,7 +43,6 @@
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Type1FontSimple1()
|
public void Type1FontSimple1()
|
||||||
{
|
{
|
||||||
// This document does not actually contain circular references
|
|
||||||
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("MOZILLA-2775-1")))
|
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("MOZILLA-2775-1")))
|
||||||
{
|
{
|
||||||
var page = document.GetPage(11);
|
var page = document.GetPage(11);
|
||||||
@ -44,7 +53,6 @@
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Type1FontSimple2()
|
public void Type1FontSimple2()
|
||||||
{
|
{
|
||||||
// This document does not actually contain circular references
|
|
||||||
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("PDFBOX-492-4.jar-8")))
|
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("PDFBOX-492-4.jar-8")))
|
||||||
{
|
{
|
||||||
var page = document.GetPage(1);
|
var page = document.GetPage(1);
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
private readonly double[] widths;
|
private readonly double[] widths;
|
||||||
|
|
||||||
|
private readonly bool isZapfDingbats;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
public NameToken Name { get; }
|
public NameToken Name { get; }
|
||||||
#nullable enable
|
#nullable enable
|
||||||
@ -63,8 +65,7 @@
|
|||||||
Details = descriptor?.ToDetails(Name?.Data)
|
Details = descriptor?.ToDetails(Name?.Data)
|
||||||
?? FontDetails.GetDefault(Name?.Data);
|
?? FontDetails.GetDefault(Name?.Data);
|
||||||
|
|
||||||
// Assumption is ZapfDingbats is not possible here. We need to change the behaviour if not the case
|
isZapfDingbats = encoding is ZapfDingbatsEncoding || Details.Name.Contains("ZapfDingbats");
|
||||||
System.Diagnostics.Debug.Assert(!(encoding is ZapfDingbatsEncoding || Details.Name.Contains("ZapfDingbats")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ReadCharacterCode(IInputBytes bytes, out int codeLength)
|
public int ReadCharacterCode(IInputBytes bytes, out int codeLength)
|
||||||
@ -100,12 +101,22 @@
|
|||||||
// If the font is a simple font that uses one of the predefined encodings MacRomanEncoding, MacExpertEncoding, or WinAnsiEncoding...
|
// 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.
|
// 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.
|
// Look up the character name in the Adobe Glyph List or additional Glyph List.
|
||||||
try
|
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
|
catch
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user