Class | PDF::Writer::TagAlink |
In: |
lib/pdf/writer.rb
|
Parent: | Object |
A callback to support the formation of clickable links to external locations.
DEFAULT_STYLE | = | { :color => Color::RGB::Blue, :text_color => Color::RGB::Blue, :draw_line => true, :line_style => { :dash => PDF::Writer::StrokeStyle::SOLID_LINE }, :factor => 0.05 | The default anchored link style. |
style | [RW] |
Sets the style for <c:alink> callback underlines that follow. This is
expected to be a hash with the following keys:
Set this to nil to get the default style. |
# File lib/pdf/writer.rb, line 2527 2527: def [](pdf, info) 2528: @style ||= DEFAULT_STYLE.dup 2529: 2530: case info[:status] 2531: when :start, :start_line 2532: # The beginning of the link. This should contain the URI for the 2533: # link as the :params entry, and will also contain the value of 2534: # :cbid. 2535: @links ||= {} 2536: 2537: @links[info[:cbid]] = { 2538: :x => info[:x], 2539: :y => info[:y], 2540: :angle => info[:angle], 2541: :descender => info[:descender], 2542: :height => info[:height], 2543: :uri => info[:params]["uri"] 2544: } 2545: 2546: pdf.save_state 2547: pdf.fill_color @style[:text_color] if @style[:text_color] 2548: if @style[:draw_line] 2549: pdf.stroke_color @style[:color] if @style[:color] 2550: sz = info[:height] * @style[:factor] 2551: pdf.stroke_style! StrokeStyle.new(sz, @style[:line_style]) 2552: end 2553: when :end, :end_line 2554: # The end of the link. Assume that it is the most recent opening 2555: # which has closed. 2556: start = @links[info[:cbid]] 2557: # Add underlining. 2558: theta = PDF::Math.deg2rad(start[:angle] - 90.0) 2559: if @style[:draw_line] 2560: drop = start[:height] * @style[:factor] * 1.5 2561: drop_x = Math.cos(theta) * drop 2562: drop_y = -Math.sin(theta) * drop 2563: pdf.move_to(start[:x] - drop_x, start[:y] - drop_y) 2564: pdf.line_to(info[:x] - drop_x, info[:y] - drop_y).stroke 2565: end 2566: pdf.add_link(start[:uri], start[:x], start[:y] + 2567: start[:descender], info[:x], start[:y] + 2568: start[:descender] + start[:height]) 2569: pdf.restore_state 2570: end 2571: end