Class | PDF::Writer::TagUline |
In: |
lib/pdf/writer.rb
|
Parent: | Object |
A callback to support underlining.
DEFAULT_STYLE | = | { :color => nil, :line_style => { :dash => PDF::Writer::StrokeStyle::SOLID_LINE }, :factor => 0.05 | The default underline style. |
style | [RW] |
Sets the style for <c:uline> 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 2622 2622: def [](pdf, info) 2623: @style ||= DEFAULT_STYLE.dup 2624: 2625: case info[:status] 2626: when :start, :start_line 2627: @links ||= {} 2628: 2629: @links[info[:cbid]] = { 2630: :x => info[:x], 2631: :y => info[:y], 2632: :angle => info[:angle], 2633: :descender => info[:descender], 2634: :height => info[:height], 2635: :uri => nil 2636: } 2637: 2638: pdf.save_state 2639: pdf.stroke_color @style[:color] if @style[:color] 2640: sz = info[:height] * @style[:factor] 2641: pdf.stroke_style! StrokeStyle.new(sz, @style[:line_style]) 2642: when :end, :end_line 2643: start = @links[info[:cbid]] 2644: theta = PDF::Math.deg2rad(start[:angle] - 90.0) 2645: drop = start[:height] * @style[:factor] * 1.5 2646: drop_x = Math.cos(theta) * drop 2647: drop_y = -Math.sin(theta) * drop 2648: pdf.move_to(start[:x] - drop_x, start[:y] - drop_y) 2649: pdf.line_to(info[:x] - drop_x, info[:y] - drop_y).stroke 2650: pdf.restore_state 2651: end 2652: end