1425: def add_text(x, y, text, size = nil, angle = 0, word_space_adjust = 0)
1426: if text.kind_of?(Numeric) and size.kind_of?(String)
1427: text, size = size, text
1428: warn PDF::Writer::Lang[:add_text_parameters_reversed] % caller[0]
1429: end
1430:
1431: if size.nil? or size <= 0
1432: size = @font_size
1433: end
1434:
1435: select_font("Helvetica") if @fonts.empty?
1436:
1437: text = text.to_s
1438:
1439:
1440:
1441: @callbacks.reverse_each do |ii|
1442: info = ii.dup
1443: info[:x] = x
1444: info[:y] = y
1445: info[:angle] = angle
1446: info[:status] = :start_line
1447:
1448: info[:tag][self, info]
1449: end
1450: if angle == 0
1451: add_content("\nBT %.3f %.3f Td" % [x, y])
1452: else
1453: rad = PDF::Math.deg2rad(angle)
1454: tt = "\nBT %.3f %.3f %.3f %.3f %.3f %.3f Tm"
1455: tt = tt % [ Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), x, y ]
1456: add_content(tt)
1457: end
1458:
1459: if (word_space_adjust != 0) or not ((@word_space_adjust.nil?) and (@word_space_adjust != word_space_adjust))
1460: @word_space_adjust = word_space_adjust
1461: add_content(" %.3f Tw" % word_space_adjust)
1462: end
1463:
1464: pos = -1
1465: start = 0
1466: loop do
1467: pos += 1
1468: break if pos == text.size
1469: font_change = true
1470: tag_size, text, font_change = quick_text_tags(text, pos, font_change)
1471:
1472: if tag_size != 0
1473: if pos > start
1474: part = text[start, pos - start]
1475: tt = " /F#{find_font(@current_font).font_id}"
1476: tt << " %.1f Tf %d Tr" % [ size, @current_text_render_style ]
1477: tt << " (#{PDF::Writer.escape(part)}) Tj"
1478: add_content(tt)
1479: end
1480:
1481: if font_change
1482: current_font!
1483: else
1484: add_content(" ET")
1485: xp = x
1486: yp = y
1487: tag_size, text, font_change, xp, yp = text_tags(text, pos, font_change, true, xp, yp, size, angle, word_space_adjust)
1488:
1489:
1490: if angle.zero?
1491: add_content("\nBT %.3f %.3f Td" % [xp, yp])
1492: else
1493: rad = PDF::Math.deg2rad(angle)
1494: tt = "\nBT %.3f %.3f %.3f %.3f %.3f %.3f Tm"
1495: tt = tt % [ Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), xp, yp ]
1496: add_content(tt)
1497: end
1498:
1499: if (word_space_adjust != 0) or (word_space_adjust != @word_space_adjust)
1500: @word_space_adjust = word_space_adjust
1501: add_content(" %.3f Tw" % [word_space_adjust])
1502: end
1503: end
1504:
1505: pos += tag_size - 1
1506: start = pos + 1
1507: end
1508: end
1509:
1510: if start < text.size
1511: part = text[start..-1]
1512:
1513: tt = " /F#{find_font(@current_font).font_id}"
1514: tt << " %.1f Tf %d Tr" % [ size, @current_text_render_style ]
1515: tt << " (#{PDF::Writer.escape(part)}) Tj"
1516: add_content(tt)
1517: end
1518: add_content(" ET")
1519:
1520:
1521: @callbacks.reverse_each do |ii|
1522: info = ii.dup
1523: info[:x] = x
1524: info[:y] = y
1525: info[:angle] = angle
1526: info[:status] = :end_line
1527: info[:tag][self, info]
1528: end
1529: end