mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-19 10:47:56 +08:00
handle extraneous def token in some dictionaries and skip returning glyph bounds if not in font
This commit is contained in:
@@ -63,7 +63,7 @@
|
||||
var builder = new StringBuilder("<!DOCTYPE html><html><head></head><body>");
|
||||
foreach (var charString in result.CharStrings.CharStrings)
|
||||
{
|
||||
var path = result.CharStrings.Generate(charString.Key);
|
||||
Assert.True(result.CharStrings.TryGenerate(charString.Key, out var path));
|
||||
builder.AppendLine(path.ToFullSvg());
|
||||
}
|
||||
|
||||
|
@@ -25,27 +25,27 @@
|
||||
Subroutines = subroutines ?? throw new ArgumentNullException(nameof(subroutines));
|
||||
}
|
||||
|
||||
public PdfPath Generate(string name)
|
||||
public bool TryGenerate(string name, out PdfPath path)
|
||||
{
|
||||
PdfPath glyph;
|
||||
path = default(PdfPath);
|
||||
lock (locker)
|
||||
{
|
||||
if (glyphs.TryGetValue(name, out var result))
|
||||
if (glyphs.TryGetValue(name, out path))
|
||||
{
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!CharStrings.TryGetValue(name, out var sequence))
|
||||
{
|
||||
throw new InvalidOperationException($"No charstring sequence with the name /{name} in this font.");
|
||||
return false;
|
||||
}
|
||||
|
||||
glyph = Run(sequence);
|
||||
path = Run(sequence);
|
||||
|
||||
glyphs[name] = glyph;
|
||||
glyphs[name] = path;
|
||||
}
|
||||
|
||||
return glyph;
|
||||
return true;
|
||||
}
|
||||
|
||||
private PdfPath Run(CommandSequence sequence)
|
||||
|
@@ -2,7 +2,6 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using CharStrings;
|
||||
using Core;
|
||||
using Geometry;
|
||||
@@ -62,7 +61,11 @@
|
||||
|
||||
public PdfRectangle? GetCharacterBoundingBox(string characterName)
|
||||
{
|
||||
var glyph = CharStrings.Generate(characterName);
|
||||
if (!CharStrings.TryGenerate(characterName, out var glyph))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var bbox = glyph.GetBoundingRectangle();
|
||||
|
||||
return bbox;
|
||||
@@ -77,7 +80,7 @@
|
||||
{
|
||||
if (FontMatrix == null || FontMatrix.Data.Count != 6)
|
||||
{
|
||||
return TransformationMatrix.FromValues(0.001m, 0, 0, 0.001m, 0, 0);;
|
||||
return TransformationMatrix.FromValues(0.001m, 0, 0, 0.001m, 0, 0);
|
||||
}
|
||||
|
||||
var a = ((NumericToken) FontMatrix.Data[0]).Data;
|
||||
|
@@ -94,6 +94,12 @@
|
||||
result[key] = token;
|
||||
}
|
||||
|
||||
// skip def.
|
||||
if (PeekNext(tokens, i) == OperatorToken.Def)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
key = null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user