When using a font, but only using the ideographic space (\u3000) from that font, an exception is thrown. It seems to be an interaction between svg-to-pdfkit and fontkit, and it's not clear where the bug belongs, but I'm filing it here since this package is closest to the thrown exception.
Note that   is an "ideographic space" from the korean font, and counts as a space for JS's regexp matching (i.e., \s will match it). It's the only character used here. When run, it exits with this error:
(node:11822) UnhandledPromiseRejectionWarning: RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 255. Received -1
at writeU_Int8 (internal/buffer.js:724:11)
at Buffer.writeUInt8 (internal/buffer.js:734:10)
at EncodeStream.<computed> [as writeUInt8] (/home/arista/tmp/noteflight/bug-8729/node_modules/restructure/src/EncodeStream.js:37:29)
at NumberT.encode (/home/arista/tmp/noteflight/bug-8729/node_modules/restructure/src/Number.js:28:39)
at Struct.encode (/home/arista/tmp/noteflight/bug-8729/node_modules/restructure/src/Struct.js:110:16)
at RangeArray.ArrayT.encode (/home/arista/tmp/noteflight/bug-8729/node_modules/restructure/src/Array.js:88:19)
at VersionedStruct.encode (/home/arista/tmp/noteflight/bug-8729/node_modules/restructure/src/VersionedStruct.js:120:16)
at VersionedStruct.encode (/home/arista/tmp/noteflight/bug-8729/node_modules/restructure/src/VersionedStruct.js:126:18)
at CFFSubset.encode (/home/arista/tmp/noteflight/bug-8729/node_modules/fontkit/index.js:13585:12)
at /home/arista/tmp/noteflight/bug-8729/node_modules/fontkit/index.js:13048:13
What I think is happening:
SVGtoPDF, around source.js:2296, effectively converts the ideographic space to an ASCII space
Since that ideographic space was the only character used from the NotoSansKR font, that font ends up using no glyphs
So in CFFSubset, that font is left with glyphs=[0] (a single element)
In CFFSubset.encode, it defines a charset range in which nLeft is set to this.charstrings.length - 2. Since charStrings comes from CFFSubset.glyphs, which only has 1 element, that results in -1.
When VersionedStruct tries to encode that as a U8, it balks at the negative number
When using a font, but only using the ideographic space (\u3000) from that font, an exception is thrown. It seems to be an interaction between svg-to-pdfkit and fontkit, and it's not clear where the bug belongs, but I'm filing it here since this package is closest to the thrown exception.
Minimal node test case:
Note that
 
is an "ideographic space" from the korean font, and counts as a space for JS's regexp matching (i.e.,\s
will match it). It's the only character used here. When run, it exits with this error:What I think is happening:
nLeft
is set tothis.charstrings.length - 2
. Since charStrings comes from CFFSubset.glyphs, which only has 1 element, that results in -1.