     for c in text
       switch c
         when ' '
-          w += word_spacing
+          w += @size
           continue
         when '\n'
           maxWidth = w if w > maxWidth
           w = 0
-          h += line_spacing
+          h += @linesize
           continue
         when '\t'
-          w += 3 * word_spacing
+          w += @tabsize
           continue
 
-      w += size
+      char = @chars[c] || @invalid_char
+
+      w += char.w
 
     if w > 0 and maxWidth == 0
       maxWidth = w
 
     if maxWidth > 0 and h == 0
-      h = size
+      h = @size
 
     new Fz2D.Rect(0, 0, maxWidth, h)
 

  # Public: Measures text.
  #
  # text - text to measure
  # size - text size (default: font size)
  # line_spacing - desired line spacing (default: 2 * size)
  # word_spacing - desired word spacing (default: size)
  #
  # Returns a {Fz2D.Rect}.
  measureText: (text, size=@size, line_spacing=size+size, word_spacing=size) ->
    w = 0
    h = 0
    maxWidth = 0

  # text - text to measure
  # x - position on the X axis
  # y - position on the Y axis
  #
  # Returns a last position.
  drawText: (ctx, text, x, y) ->
    xx = x
    yy = y

    for c in text
      switch c
        when ' '
          xx += @size
          continue
        when '\n'
          xx = x
          yy += @linesize
          continue
        when '\t'
          xx += @tabsize
          continue
 
      char = @chars[c] || @invalid_char

      ctx.draw(@texture, char.x, char.y, char.w, char.h, xx, yy, char.w, char.h)

      xx += char.w

    xx
