skip postscript wrappers when parsing private dictionary for type 1 fonts. type 1 font now retrieves bounding box by name rather than character code

This commit is contained in:
Eliot Jones
2019-01-11 07:10:40 +00:00
parent d86c79da45
commit 17d4b964f7
4 changed files with 25 additions and 8 deletions

View File

@@ -132,11 +132,10 @@
if (stream.StreamDictionary.TryGet(NameToken.Subtype, out NameToken subTypeName)
&& NameToken.Type1C.Equals(subTypeName))
{
var str = OtherEncodings.BytesAsLatin1String(bytes.ToArray());
var cffFont = compactFontFormatParser.Parse(new CompactFontFormatData(bytes));
return Union<Type1FontProgram, CompactFontFormatFontProgram>.Two(cffFont);
}
var length1 = stream.StreamDictionary.Get<NumericToken>(NameToken.Length1, pdfScanner);
var length2 = stream.StreamDictionary.Get<NumericToken>(NameToken.Length2, pdfScanner);

View File

@@ -120,7 +120,7 @@
{
return box;
}
var boundingBox = GetBoundingBoxInGlyphSpace(characterCode);
var matrix = fontMatrix;
@@ -151,7 +151,8 @@
var rect = default(PdfRectangle?);
fontProgram.Match(x =>
{
rect = x.GetCharacterBoundingBox(characterCode);
var name = encoding.GetName(characterCode);
rect = x.GetCharacterBoundingBox(name);
},
x =>
{

View File

@@ -24,7 +24,7 @@
}
var decrypted = Decrypt(bytes, EexecEncryptionKey, EexecRandomBytes);
var tokenizer = new Type1Tokenizer(new ByteArrayInputBytes(decrypted));
/*
@@ -495,6 +495,24 @@
{
break;
}
// PostScript wrapper (ignored for now)
if (string.Equals(token.Text, "systemdict"))
{
ReadExpected(tokenizer, Type1Token.TokenType.Literal, "internaldict");
ReadExpected(tokenizer, Type1Token.TokenType.Name, "known");
ReadExpected(tokenizer, Type1Token.TokenType.StartProc);
// TODO: read values from the wrapper, see line 396 of Type1Parser.java
// Skips the entire contents
while ((token = tokenizer.GetNext()) != null)
{
if (token.Type == Type1Token.TokenType.Name && (token.Text == "ND" || token.Text == "def"))
{
return;
}
}
}
}
else if (!skip)
{

View File

@@ -60,10 +60,9 @@
CharStrings = charStrings ?? throw new ArgumentNullException(nameof(charStrings));
}
public PdfRectangle? GetCharacterBoundingBox(int characterCode)
public PdfRectangle? GetCharacterBoundingBox(string characterName)
{
var b = Encoding[characterCode];
var glyph = CharStrings.Generate(b);
var glyph = CharStrings.Generate(characterName);
var bbox = glyph.GetBoundingRectangle();
return bbox;