mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
LibPDF: Improve Type2 hint counting
There were two issues with how we counted hints with Type2 CharString commands: the first was that we assumed a single hint per command, even though there are commands that accept multiple hints thanks to taking a variable number of operands; and secondly, the hintmask/ctrlmask commands can also take operands (i.e., hints) themselves in certain situations. This commit fixes these two issues by correctly counting hints in both cases. This in turn fixes cases when there were more than 8 hints in total, therefore a hintmask/ctrlmask command needed to read more than one byte past the operator itself.
This commit is contained in:
parent
bf61f94413
commit
de5e7b487c
1 changed files with 4 additions and 2 deletions
|
@ -271,7 +271,7 @@ PDFErrorOr<Type1FontProgram::Glyph> Type1FontProgram::parse_glyph(ReadonlyBytes
|
||||||
|
|
||||||
// hints operators
|
// hints operators
|
||||||
case HStemHM:
|
case HStemHM:
|
||||||
state.n_hints++;
|
state.n_hints += state.sp / 2;
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case HStem:
|
case HStem:
|
||||||
maybe_read_width(Odd);
|
maybe_read_width(Odd);
|
||||||
|
@ -279,7 +279,7 @@ PDFErrorOr<Type1FontProgram::Glyph> Type1FontProgram::parse_glyph(ReadonlyBytes
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VStemHM:
|
case VStemHM:
|
||||||
state.n_hints++;
|
state.n_hints += state.sp / 2;
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case VStem:
|
case VStem:
|
||||||
maybe_read_width(Odd);
|
maybe_read_width(Odd);
|
||||||
|
@ -289,9 +289,11 @@ PDFErrorOr<Type1FontProgram::Glyph> Type1FontProgram::parse_glyph(ReadonlyBytes
|
||||||
case Hintmask:
|
case Hintmask:
|
||||||
case Cntrmask: {
|
case Cntrmask: {
|
||||||
maybe_read_width(Odd);
|
maybe_read_width(Odd);
|
||||||
|
state.n_hints += state.sp / 2;
|
||||||
auto hint_bytes = (state.n_hints + 8 - 1) / 8;
|
auto hint_bytes = (state.n_hints + 8 - 1) / 8;
|
||||||
TRY(require(hint_bytes));
|
TRY(require(hint_bytes));
|
||||||
i += hint_bytes;
|
i += hint_bytes;
|
||||||
|
state.sp = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue