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:
Eliot Jones
2020-01-28 16:05:53 +00:00
parent 6292fc256d
commit 29061b1fd2
2 changed files with 36 additions and 2 deletions

View File

@@ -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'.");

View File

@@ -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();