1362: def add_text(x, y, text, size = nil, angle = 0, word_space_adjust = 0)
1363: if text.kind_of?(Numeric) and size.kind_of?(String)
1364: text, size = size, text
1365: warn PDF::Writer::Lang[:add_text_parameters_reversed] % caller[0]
1366: end
1367:
1368: if size.nil? or size <= 0
1369: size = @font_size
1370: end
1371:
1372: select_font("Helvetica") if @fonts.empty?
1373:
1374: text = text.to_s
1375:
1376:
1377:
1378: @callbacks.reverse_each do |ii|
1379: info = ii.dup
1380: info[:x] = x
1381: info[:y] = y
1382: info[:angle] = angle
1383: info[:status] = :start_line
1384:
1385: info[:tag][self, info]
1386: end
1387: if angle == 0
1388: add_content("\nBT %.3f %.3f Td" % [x, y])
1389: else
1390: rad = PDF::Math.deg2rad(angle)
1391: tt = "\nBT %.3f %.3f %.3f %.3f %.3f %.3f Tm"
1392: tt = tt % [ Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), x, y ]
1393: add_content(tt)
1394: end
1395:
1396: if (word_space_adjust != 0) or not ((@word_space_adjust.nil?) and (@word_space_adjust != word_space_adjust))
1397: @word_space_adjust = word_space_adjust
1398: add_content(" %.3f Tw" % word_space_adjust)
1399: end
1400:
1401: pos = -1
1402: start = 0
1403: loop do
1404: pos += 1
1405: break if pos == text.size
1406: font_change = true
1407: tag_size, text, font_change = quick_text_tags(text, pos, font_change)
1408:
1409: if tag_size != 0
1410: if pos > start
1411: part = text[start, pos - start]
1412: tt = " /F#{find_font(@current_font).font_id}"
1413: tt << " %.1f Tf %d Tr" % [ size, @current_text_render_style ]
1414: tt << " (#{PDF::Writer.escape(part)}) Tj"
1415: add_content(tt)
1416: end
1417:
1418: if font_change
1419: current_font!
1420: else
1421: add_content(" ET")
1422: xp = x
1423: yp = y
1424: tag_size, text, font_change, xp, yp = text_tags(text, pos, font_change, true, xp, yp, size, angle, word_space_adjust)
1425:
1426:
1427: if angle.zero?
1428: add_content("\nBT %.3f %.3f Td" % [xp, yp])
1429: else
1430: rad = PDF::Math.deg2rad(angle)
1431: tt = "\nBT %.3f %.3f %.3f %.3f %.3f %.3f Tm"
1432: tt = tt % [ Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), xp, yp ]
1433: add_content(tt)
1434: end
1435:
1436: if (word_space_adjust != 0) or (word_space_adjust != @word_space_adjust)
1437: @word_space_adjust = word_space_adjust
1438: add_content(" %.3f Tw" % [word_space_adjust])
1439: end
1440: end
1441:
1442: pos += tag_size - 1
1443: start = pos + 1
1444: end
1445: end
1446:
1447: if start < text.size
1448: part = text[start..-1]
1449:
1450: tt = " /F#{find_font(@current_font).font_id}"
1451: tt << " %.1f Tf %d Tr" % [ size, @current_text_render_style ]
1452: tt << " (#{PDF::Writer.escape(part)}) Tj"
1453: add_content(tt)
1454: end
1455: add_content(" ET")
1456:
1457:
1458: @callbacks.reverse_each do |ii|
1459: info = ii.dup
1460: info[:x] = x
1461: info[:y] = y
1462: info[:angle] = angle
1463: info[:status] = :end_line
1464: info[:tag][self, info]
1465: end
1466: end