Class: PDF::Writer::TagUline
- Inherits:
-
Object
- Object
- PDF::Writer::TagUline
- Defined in:
- lib/pdf/writer.rb
Overview
A callback to support underlining.
Constant Summary collapse
- DEFAULT_STYLE =
The default underline style.
{ :color => nil, :line_style => { :dash => PDF::Writer::StrokeStyle::SOLID_LINE }, :factor => 0.05 }
Class Attribute Summary collapse
-
.style ⇒ Object
Sets the style for <c:uline> callback underlines that follow.
Class Method Summary collapse
Class Attribute Details
.style ⇒ Object
Sets the style for <c:uline> callback underlines that follow. This is expected to be a hash with the following keys:
:factor
-
The size of the line, as a multiple of the text height. Default is 0.05.
Set this to nil
to get the default style.
2622 2623 2624 |
# File 'lib/pdf/writer.rb', line 2622 def style @style end |
Class Method Details
.[](pdf, info) ⇒ Object
2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 |
# File 'lib/pdf/writer.rb', line 2624 def [](pdf, info) @style ||= DEFAULT_STYLE.dup case info[:status] when :start, :start_line @links ||= {} @links[info[:cbid]] = { :x => info[:x], :y => info[:y], :angle => info[:angle], :descender => info[:descender], :height => info[:height], :uri => nil } pdf.save_state pdf.stroke_color @style[:color] if @style[:color] sz = info[:height] * @style[:factor] pdf.stroke_style! StrokeStyle.new(sz, @style[:line_style]) when :end, :end_line start = @links[info[:cbid]] theta = PDF::Math.deg2rad(start[:angle] - 90.0) drop = start[:height] * @style[:factor] * 1.5 drop_x = Math.cos(theta) * drop drop_y = -Math.sin(theta) * drop pdf.move_to(start[:x] - drop_x, start[:y] - drop_y) pdf.line_to(info[:x] - drop_x, info[:y] - drop_y).stroke pdf.restore_state end end |