# File lib/pdf/writer.rb, line 1489
1489:   def text_line_width(text, size = nil)
1490:     if text.kind_of?(Numeric) and size.kind_of?(String)
1491:       text, size = size, text
1492:       warn PDF::Writer::Lang[:text_width_parameters_reversed] % caller[0]
1493:     end
1494: 
1495:     if size.nil? or size <= 0
1496:       size = @font_size
1497:     end
1498: 
1499:       # This function should not change any of the settings, though it will
1500:       # need to track any tag which change during calculation, so copy them
1501:       # at the start and put them back at the end.
1502:     t_CTS = @current_text_state.dup
1503: 
1504:     select_font("Helvetica") if @fonts.empty?
1505:       # converts a number or a float to a string so it can get the width
1506:     tt = text.to_s
1507:       # hmm, this is where it all starts to get tricky - use the font
1508:       # information to calculate the width of each character, add them up
1509:       # and convert to user units
1510:     width = 0
1511:     font = @current_font
1512: 
1513:     pos = -1
1514:     loop do
1515:       pos += 1
1516:       break if pos == tt.size
1517:       font_change = true
1518:       tag_size, text, font_change = quick_text_tags(text, pos, font_change)
1519:       if tag_size != 0
1520:         if font_change
1521:           current_font!
1522:           font = @current_font
1523:         end
1524:         pos += tag_size - 1
1525:       else
1526:         if "&lt;" == tt[pos, 4]
1527:           width += char_width(font, '<')
1528:           pos += 3
1529:         elsif "&gt;" == tt[pos, 4]
1530:           width += char_width(font, '>')
1531:           pos += 3
1532:         elsif "&amp;" == tt[pos, 5]
1533:           width += char_width(font, '&')
1534:           pos += 4
1535:         else
1536:           width += char_width(font, tt[pos, 1])
1537:         end
1538:       end
1539:     end
1540: 
1541:     @current_text_state = t_CTS.dup
1542:     current_font!
1543: 
1544:     (width * size / 1000.0)
1545:   end