mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
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:
@@ -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);
|
||||
|
||||
|
||||
@@ -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 =>
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user