def dimensions_of(text, fonts, size = 1000)
      fonts = [fonts] unless fonts.is_a? Array
      merged_metrics = {}
      # merge the metrics last to first (so that important fonts override secondary fonts)
      fonts.length.downto(1).each do |i|
        f = get_original_font(fonts[i - 1])
        if f && f.metrics
          merged_metrics.update(get_original_font(fonts[i - 1]).metrics)
        else
          warn 'metrics of font not found!'
        end
      end

      metrics_array = []
      text.each_char do |c|
        metrics_array << (merged_metrics[c] || { wx: 0, boundingbox: [0, 0, 0, 0] })
      end
      height = metrics_array.map { |m| m ? m[:boundingbox][3] : 0 } .max
      height -= (metrics_array.map { |m| m ? m[:boundingbox][1] : 0 }).min
      width = 0.0
      metrics_array.each do |m|
        width += (m[:wx] || m[:wy])
      end
      return [height.to_f / 1000 * size, width.to_f / 1000 * size] if metrics_array[0][:wy]
      [width.to_f / 1000 * size, height.to_f / 1000 * size]
    end
def dimensions_of(text, fonts, size = 1000)
      fonts = [fonts] unless fonts.is_a? Array
      merged_metrics = {}
      # merge the metrics last to first (so that important fonts override secondary fonts)
      fonts.length.downto(1).each do |i|
        f = get_original_font(fonts[i - 1])
        if f && f.metrics
          merged_metrics.update(get_original_font(fonts[i - 1]).metrics)
        else
          warn 'metrics of font not found!'
        end
      end

      metrics_array = []
      text.each_char do |c|
        metrics_array << (merged_metrics[c] || { wx: 0, boundingbox: [0, 0, 0, 0] })
      end
      height = metrics_array.map { |m| m ? m[:boundingbox][3] : 0 } .max
      height -= (metrics_array.map { |m| m ? m[:boundingbox][1] : 0 }).min
      width = 0.0
      metrics_array.each do |m|
        width += (m[:wx] || m[:wy])
      end
      return [height.to_f / 1000 * size, width.to_f / 1000 * size] if metrics_array[0][:wy]
      [width.to_f / 1000 * size, height.to_f / 1000 * size]
    end
gets the dimentions (width and height) of the text, as it will be printed in the PDF.

 text:: the text to measure
 fonts:: a font name or an Array of font names. Font names should be registered fonts. The 14 standard fonts are pre regitered with the font library.
 size:: the size of the font (defaults to 1000 points).