#141 fix two's complement in adobe type 2 charstring

the byte value of 28 indicates the next 2 bytes are a 16 bit two's complement number rather than just a short. this changes the calculation to generate the two's complement value correctly.
This commit is contained in:
Eliot Jones
2020-02-25 13:19:47 +00:00
parent d6d3869fe2
commit f7c6de4118

View File

@@ -767,7 +767,11 @@ namespace UglyToad.PdfPig.Fonts.CompactFontFormat.CharStrings
{ {
if (b == 28) if (b == 28)
{ {
return bytes[++i] << 8 | bytes[++i]; var num = bytes[++i] << 8 | bytes[++i];
// Next 2 bytes are a 16-bit two's complement number.
// The twos complement of a number N in a B-bit system is 2^B - N. For 16 bits the result is 2^16 - num.
// A shortcut is to invert the bits of the number and add 1.
return (short) (~(num) + 1);
} }
if (b >= 32 && b <= 246) if (b >= 32 && b <= 246)