Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected CompactFontFormatCharset(ReadOnlySpan<(int glyphId, int stringId, stri

public virtual string GetNameByGlyphId(int glyphId)
{
return GlyphIdToStringIdAndName.TryGetValue(glyphId, out var strings) ? strings.name : ".notdef";
return GlyphIdToStringIdAndName.TryGetValue(glyphId, out var strings) ? strings.name : null;
}

public virtual string GetNameByStringId(int stringId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ internal CompactFontFormatFont(CompactFontFormatTopLevelDictionary topDictionary
/// </summary>
public string GetCharacterName(int characterCode, bool isCid)
{
if (Encoding is not null)
{
return Encoding.GetName(characterCode);
}

if (Charset.IsCidCharset)
{
return Charset.GetNameByStringId(characterCode);
}

if (isCid)
{
if (this is not CompactFontFormatCidFont && !Charset.IsCidCharset)
Expand All @@ -75,6 +65,16 @@ public string GetCharacterName(int characterCode, bool isCid)
return Charset.GetNameByStringId(characterCode);
}

if (Encoding is not null)
{
return Encoding.GetName(characterCode);
}

if (Charset.IsCidCharset)
{
return Charset.GetNameByStringId(characterCode);
}

string characterName = GlyphList.AdobeGlyphList.UnicodeCodePointToName(characterCode);

if (characterName.Equals(GlyphList.NotDefined, StringComparison.OrdinalIgnoreCase))
Expand Down
22 changes: 8 additions & 14 deletions src/UglyToad.PdfPig.Fonts/TrueType/TrueTypeFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,15 @@ public bool TryGetBoundingBox(int characterCode, Func<int, int?> characterCodeTo
* This is to fix P2P-33713919.pdf
* See https://github.com/BobLd/PdfPig.Rendering.Skia/issues/46
*
* A CFF that carries its own encoding selects glyphs from the character code
* directly. Without an encoding (e.g. an OpenType/CFF embedded as a CIDFont) the
* CID must first be mapped to a glyph index via the CIDToGIDMap (Identity when none),
* then looked up by glyph id in the charset.
* When used as a CIDFont the CID is first mapped to a glyph index via the supplied
* mapping (the CIDToGIDMap, or Identity when none), then resolved by glyph id in the
* embedded CFF (see CompactFontFormatFont.GetCharacterName).
*
* See https://github.com/UglyToad/PdfPig/issues/1320
*/

var cffFont = cffFontCollection.FirstFont;
int cffGlyphId = cffFont.Encoding is null
? (characterCodeToGlyphId?.Invoke(characterCode) ?? characterCode)
: characterCode;
int cffGlyphId = characterCodeToGlyphId?.Invoke(characterCode) ?? characterCode;
var name = cffFont.GetCharacterName(cffGlyphId, true);
if (string.IsNullOrEmpty(name))
{
Expand Down Expand Up @@ -212,18 +209,15 @@ public bool TryGetPath(int characterCode, Func<int, int?> characterCodeToGlyphId
* This is to fix P2P-33713919.pdf
* See https://github.com/BobLd/PdfPig.Rendering.Skia/issues/46
*
* A CFF that carries its own encoding selects glyphs from the character code
* directly. Without an encoding (e.g. an OpenType/CFF embedded as a CIDFont) the
* CID must first be mapped to a glyph index via the CIDToGIDMap (Identity when none),
* then looked up by glyph id in the charset.
* When used as a CIDFont the CID is first mapped to a glyph index via the supplied
* mapping (the CIDToGIDMap, or Identity when none), then resolved by glyph id in the
* embedded CFF (see CompactFontFormatFont.GetCharacterName).
*
* See https://github.com/UglyToad/PdfPig/issues/1320
*/

var cffFont = cffFontCollection.FirstFont;
int cffGlyphId = cffFont.Encoding is null
? (characterCodeToGlyphId?.Invoke(characterCode) ?? characterCode)
: characterCode;
int cffGlyphId = characterCodeToGlyphId?.Invoke(characterCode) ?? characterCode;
var name = cffFont.GetCharacterName(cffGlyphId, true);
if (string.IsNullOrEmpty(name))
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ SKPoint GetPoint(PdfPoint p)
graphics.DrawPoint(GetPoint(point), pen);
}

[Fact]
public void issues_1176_1()
{
Run("issues-1176-1.pdf");
}

[Fact]
public void P2P_33713919()
{
Expand Down
Loading