Skip to content

Commit

Permalink
Fix #807 (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobLd authored Mar 23, 2024
1 parent 69e2b7b commit e789691
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
Binary file not shown.
24 changes: 24 additions & 0 deletions src/UglyToad.PdfPig.Tests/Integration/Type1FontSimpleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace UglyToad.PdfPig.Tests.Integration
{
using System.Linq;

public class Type1FontSimpleTests
{
[Fact]
public void Issue807()
{
var file = IntegrationHelpers.GetDocumentPath("Diacritics_export.pdf");

using (var document = PdfDocument.Open(file))
{
var page = document.GetPage(1);
var words = page.GetWords().ToArray();

Assert.Equal(3, words.Length);
Assert.Equal("Espinosa", words[0].Text);
Assert.Equal("Spínola", words[1].Text);
Assert.Equal("Moraña,", words[2].Text);
}
}
}
}
11 changes: 5 additions & 6 deletions src/UglyToad.PdfPig/PdfFonts/Simple/Type1FontSimple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,13 @@ public int ReadCharacterCode(IInputBytes bytes, out int codeLength)

public bool TryGetUnicode(int characterCode, [NotNullWhen(true)] out string? value)
{
if (toUnicodeCMap.CanMapToUnicode)
value = null;
if (toUnicodeCMap.CanMapToUnicode && toUnicodeCMap.TryGet(characterCode, out value))
{
return toUnicodeCMap.TryGet(characterCode, out value);
return true;
}

value = null;

if (encoding == null)
if (encoding is null)
{
try
{
Expand Down Expand Up @@ -132,7 +131,7 @@ public bool TryGetUnicode(int characterCode, [NotNullWhen(true)] out string? val
return false;
}

return true;
return value is not null;
}

public CharacterBoundingBox GetBoundingBox(int characterCode)
Expand Down
23 changes: 18 additions & 5 deletions src/UglyToad.PdfPig/PdfFonts/Simple/Type3Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,29 @@ public int ReadCharacterCode(IInputBytes bytes, out int codeLength)

public bool TryGetUnicode(int characterCode, [NotNullWhen(true)] out string? value)
{
if (toUnicodeCMap.CanMapToUnicode)
value = null;

if (toUnicodeCMap.CanMapToUnicode && toUnicodeCMap.TryGet(characterCode, out value))
{
return toUnicodeCMap.TryGet(characterCode, out value);
return true;
}

var name = encoding.GetName(characterCode);
if (encoding is null)
{
return false;
}

value = GlyphList.AdobeGlyphList.NameToUnicode(name);
try
{
var name = encoding.GetName(characterCode);
value = GlyphList.AdobeGlyphList.NameToUnicode(name);
}
catch
{
return false;
}

return true;
return value is not null;
}

public CharacterBoundingBox GetBoundingBox(int characterCode)
Expand Down

0 comments on commit e789691

Please sign in to comment.