mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Encode text as hex to avoid an escaping issue when using font subsets. Fixes #33.
This commit is contained in:
parent
3ab7a74369
commit
513fef78e1
BIN
demo/out.pdf
BIN
demo/out.pdf
Binary file not shown.
@ -81,15 +81,6 @@ module.exports =
|
||||
|
||||
@x = x
|
||||
@fill()
|
||||
|
||||
_escape: (text) ->
|
||||
('' + text)
|
||||
.replace(/\\/g, '\\\\\\\\')
|
||||
.replace(/\(/g, '\\(')
|
||||
.replace(/\)/g, '\\)')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/&/g, '&')
|
||||
|
||||
_line: (text, options) ->
|
||||
wrap = @_wrapState
|
||||
@ -147,9 +138,10 @@ module.exports =
|
||||
# tell the font subset to use the characters
|
||||
@_font.use text
|
||||
|
||||
# encode and escape the text for inclusion in PDF
|
||||
# encode the text based on the font subset,
|
||||
# and then convert it to hex
|
||||
text = @_font.encode text
|
||||
text = @_escape text
|
||||
text = (text.charCodeAt(i).toString(16) for i in [0...text.length]).join('')
|
||||
|
||||
# begin the text object
|
||||
@addContent "BT"
|
||||
@ -171,7 +163,7 @@ module.exports =
|
||||
@addContent characterSpacing + ' Tc' unless characterSpacing is state.characterSpacing
|
||||
|
||||
# add the actual text
|
||||
@addContent "(#{text}) Tj"
|
||||
@addContent "<#{text}> Tj"
|
||||
|
||||
# end the text object
|
||||
@addContent "ET"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user