text_line_width (PDF::Writer)

          # File lib/pdf/writer.rb, line 1552
    1552:   def text_line_width(text, size = nil)
    1553:     if text.kind_of?(Numeric) and size.kind_of?(String)
    1554:       text, size = size, text
    1555:       warn PDF::Writer::Lang[:text_width_parameters_reversed] % caller[0]
    1556:     end
    1557:
    1558:     if size.nil? or size <= 0
    1559:       size = @font_size
    1560:     end
    1561:
    1562:       # This function should not change any of the settings, though it will
    1563:       # need to track any tag which change during calculation, so copy them
    1564:       # at the start and put them back at the end.
    1565:     t_CTS = @current_text_state.dup
    1566:
    1567:     select_font("Helvetica") if @fonts.empty?
    1568:       # converts a number or a float to a string so it can get the width
    1569:     tt = text.to_s
    1570:       # hmm, this is where it all starts to get tricky - use the font
    1571:       # information to calculate the width of each character, add them up
    1572:       # and convert to user units
    1573:     width = 0
    1574:     font = @current_font
    1575:
    1576:     pos = -1
    1577:     loop do
    1578:       pos += 1
    1579:       break if pos == tt.size
    1580:       font_change = true
    1581:       tag_size, text, font_change = quick_text_tags(text, pos, font_change)
    1582:       if tag_size != 0
    1583:         if font_change
    1584:           current_font!
    1585:           font = @current_font
    1586:         end
    1587:         pos += tag_size - 1
    1588:       else
    1589:         if "&lt;" == tt[pos, 4]
    1590:           width += char_width(font, '<')
    1591:           pos += 3
    1592:         elsif "&gt;" == tt[pos, 4]
    1593:           width += char_width(font, '>')
    1594:           pos += 3
    1595:         elsif "&amp;" == tt[pos, 5]
    1596:           width += char_width(font, '&')
    1597:           pos += 4
    1598:         else
    1599:           width += char_width(font, tt[pos, 1])
    1600:         end
    1601:       end
    1602:     end
    1603:
    1604:     @current_text_state = t_CTS.dup
    1605:     current_font!
    1606:
    1607:     (width * size / 1000.0)
    1608:   end