     @_fontSizeCache[key] = size
     size
 
-  # allow chopping up the string
+  # Given a target width and height, return the optimal string and font-size
+  # that fits
+  #
+  # Allowed operations
+  #
+  # * reduce font size
+  # * chop text
+  #
   @fit: (text="", width, height, minfont, opts={}, el) ->
     optsize = @fontSize text, width, height, opts
     nchar = text.length

  # @return integer of font point size
  @fontSize: (text, width, height, opts, el) ->
    css =
       color: "white"
       "font-family": "arial"
    _.extend css, opts
    _.extend css,
       left: -100000
       position: "absolute"

    # check the cache
    key = "#{text.length}--#{width}--#{height}--#{JSON.stringify(css)}"

    

    body = document.getElementsByTagName("body")[0]
    div = document.createElement("span")
    div.textContent = text
    $(div)
      .css(css)
      .attr(css)

    el = body unless el?
    el.appendChild div

    dim = {w: width, h: height}
    size = 10
    n = 0
    while n < 30
      n += 1
      if util.Textsize.larger text, size, dim, div
         if size > 50
           size /= 2
         else
           size -= 1
      else
         if util.Textsize.larger text, size + 1, dim, div
           break
         size += 5

