class PDF::Writer::TagUline

A callback to support underlining.

Constants

DEFAULT_STYLE

The default underline style.

Attributes

style[RW]

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.

Public Class Methods

[](pdf, info) click to toggle source
     # File lib/pdf/writer.rb
2604 def [](pdf, info)
2605   @style ||= DEFAULT_STYLE.dup
2606 
2607   case info[:status]
2608   when :start, :start_line
2609     @links ||= {}
2610 
2611     @links[info[:cbid]] = {
2612       :x         => info[:x],
2613       :y         => info[:y],
2614       :angle     => info[:angle],
2615       :descender => info[:descender],
2616       :height    => info[:height],
2617       :uri       => nil
2618     }
2619 
2620     pdf.save_state
2621     pdf.stroke_color  @style[:color] if @style[:color]
2622     sz = info[:height] * @style[:factor]
2623     pdf.stroke_style! StrokeStyle.new(sz, @style[:line_style])
2624   when :end, :end_line
2625     start = @links[info[:cbid]]
2626     theta = PDF::Math.deg2rad(start[:angle] - 90.0)
2627     drop  = start[:height] * @style[:factor] * 1.5
2628     drop_x = Math.cos(theta) * drop
2629     drop_y = -Math.sin(theta) * drop
2630     pdf.move_to(start[:x] - drop_x, start[:y] - drop_y)
2631     pdf.line_to(info[:x] - drop_x, info[:y] - drop_y).stroke
2632     pdf.restore_state
2633   end
2634 end