mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-18 18:27:55 +08:00
handle unexpected adobe type 1 format
an encoding array in an adobe type 1 font may be missing its declaration ending in 'for', if we encounter 'dup' while looking for the 'for' token we have a special case to go straight into reading the encoding. also handles a case where the page content stream contains a path-closing operator without any path being active.
This commit is contained in:
@@ -316,18 +316,42 @@
|
||||
return (new ArrayToken(result), null);
|
||||
}
|
||||
|
||||
var stoppedOnDup = false;
|
||||
|
||||
while (scanner.MoveNext() && (!(scanner.CurrentToken is OperatorToken forOperator) || forOperator.Data != "for"))
|
||||
{
|
||||
if (!(scanner.CurrentToken is OperatorToken operatorToken))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(operatorToken.Data, "for", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (string.Equals(operatorToken.Data, OperatorToken.Dup.Data, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
stoppedOnDup = true;
|
||||
break;
|
||||
}
|
||||
// skip these operators for now, they're probably important...
|
||||
}
|
||||
|
||||
if (scanner.CurrentToken != OperatorToken.For)
|
||||
if (scanner.CurrentToken != OperatorToken.For && !stoppedOnDup)
|
||||
{
|
||||
return (new ArrayToken(result), null);
|
||||
}
|
||||
|
||||
while (scanner.MoveNext() && scanner.CurrentToken != OperatorToken.Def && scanner.CurrentToken != OperatorToken.Readonly)
|
||||
bool IsDefOrReadonly()
|
||||
{
|
||||
return scanner.CurrentToken == OperatorToken.Def
|
||||
|| scanner.CurrentToken == OperatorToken.Readonly;
|
||||
}
|
||||
|
||||
while ((stoppedOnDup || scanner.MoveNext()) && !IsDefOrReadonly())
|
||||
{
|
||||
stoppedOnDup = false;
|
||||
if (scanner.CurrentToken != OperatorToken.Dup)
|
||||
{
|
||||
throw new InvalidFontFormatException("Expected the array for encoding to begin with 'dup'.");
|
||||
|
@@ -413,6 +413,11 @@
|
||||
|
||||
public void StrokePath(bool close)
|
||||
{
|
||||
if (CurrentPath == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (close)
|
||||
{
|
||||
ClosePath();
|
||||
@@ -427,6 +432,11 @@
|
||||
|
||||
public void FillPath(bool close)
|
||||
{
|
||||
if (CurrentPath == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (close)
|
||||
{
|
||||
ClosePath();
|
||||
|
Reference in New Issue
Block a user