@@ -211,10 +211,11 @@ module.exports =
211
211
@ stroke ()
212
212
@ restore ()
213
213
214
+ _addGlyphs : (glyphs , positions , x , y , options = {}) ->
214
215
# flip coordinate system
215
216
@ save ()
216
217
@ transform 1 , 0 , 0 , - 1 , 0 , @page .height
217
- y = @page .height - y - (@_font .ascender / 1000 * @_fontSize )
218
+ y = @page .height - y# - (@_font.ascender / 1000 * @_fontSize)
218
219
219
220
# add current font to page if necessary
220
221
@page .fonts [@_font .id ] ?= @_font .ref ()
@@ -233,33 +234,10 @@ module.exports =
233
234
@ addContent " #{ mode} Tr" if mode
234
235
235
236
# Character spacing
236
- @ addContent " #{ number (characterSpacing)} Tc" if characterSpacing
237
+ # @addContent "#{number(characterSpacing)} Tc" if characterSpacing
237
238
238
239
# Add the actual text
239
- # If we have a word spacing value, we need to encode each word separately
240
- # since the normal Tw operator only works on character code 32, which isn't
241
- # used for embedded fonts.
242
- if wordSpacing
243
- words = text .trim ().split (/ \s + / )
244
- wordSpacing += @ widthOfString (' ' ) + characterSpacing
245
- wordSpacing *= 1000 / @_fontSize
246
-
247
- encoded = []
248
- positions = []
249
- for word in words
250
- [encodedWord , positionsWord ] = @_font .encode (word, options .features )
251
- encoded .push encodedWord...
252
- positions .push positionsWord...
253
-
254
- # add the word spacing to the end of the word
255
- # clone object because of cache
256
- space = {}
257
- space[key] = val for key, val of positions[positions .length - 1 ]
258
- space .xAdvance += wordSpacing
259
- positions[positions .length - 1 ] = space
260
- else
261
- [encoded , positions ] = @_font .encode (text, options .features )
262
-
240
+ encoded = @_font .encode2 (glyphs)
263
241
scale = @_fontSize / 1000
264
242
commands = []
265
243
last = 0
@@ -269,7 +247,7 @@ module.exports =
269
247
addSegment = (cur ) =>
270
248
if last < cur
271
249
hex = encoded .slice (last, cur).join ' '
272
- advance = positions[cur - 1 ].xAdvance - positions [cur - 1 ].advanceWidth
250
+ advance = positions[cur - 1 ].xAdvance * ( 1000 / @_fontSize) - glyphs [cur - 1] . advanceWidth * (1000 / @_font . font . unitsPerEm)
273
251
commands. push "<#{hex}> #{number(-advance)}"
274
252
275
253
last = cur
@@ -301,10 +279,10 @@ module.exports =
301
279
hadOffset = no
302
280
303
281
# Group segments that don't have any advance adjustments
304
- unless pos .xAdvance - pos .advanceWidth is 0
282
+ unless pos. xAdvance - glyphs [i] . advanceWidth * (@_fontSize / @_font . font . unitsPerEm) is 0
305
283
addSegment i + 1
306
284
307
- x += pos .xAdvance * scale
285
+ x + = pos. xAdvance
308
286
309
287
# Flush any remaining commands
310
288
flush i
0 commit comments