   # @param div a dom element selection
   # @param size font-size
   # @param dms bounding box
-  @larger: (div, size, dims) ->
-    div.style['font-size'] = "#{size}pt"
-    [sw, sh] = [div.scrollWidth, div.scrollHeight]
-    @log "larger: #{size}pt: #{[sw, sh]} vs #{dims.w}, #{dims.h}"
-    sw > dims.w or sh > dims.h
-    #sw > div[0].clientWidth or sh > div[0].clientHeight
+  # @param el dom element to update
+  @larger: (text, size, dims, el) ->
+    if el?
+      el.style['font-size'] = "#{size}pt"
+      [sw, sh] = [el.scrollWidth, el.scrollHeight]
+      if sw? and sh?
+        return sw > dims.w or sh > dims.h
+    
+    ds = @defaultSize text, "#{size}pt"
+    ds.w > dims.w or ds.h > dims.h
 
 
   # Search for the largest font size (pt) for text to be contained

    size.w = size.width
    size.h = size.height
    size

  # @param text the string to compute size of
  # @param opts css attributes

    

    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

