Class: PDF::Writer::TagAlink
- Defined in:
- lib/extensions/pdf-writer/pdf/writer.rb
Overview
A callback to support the formation of clickable links to external locations.
Constant Summary collapse
- DEFAULT_STYLE =
The default anchored link style.
{ :color => Color::RGB::Blue, :text_color => Color::RGB::Blue, :draw_line => true, :line_style => { :dash => PDF::Writer::StrokeStyle::SOLID_LINE }, :factor => 0.05 }
Class Attribute Summary collapse
-
.style ⇒ Object
Sets the style for <c:alink> callback underlines that follow.
Class Method Summary collapse
Class Attribute Details
.style ⇒ Object
Sets the style for <c:alink> callback underlines that follow. This is expected to be a hash with the following keys:
:color
-
The colour to be applied to the link underline. Default is Color::RGB::Blue.
:text_color
-
The colour to be applied to the link text. Default is Color::RGB::Blue.
:factor
-
The size of the line, as a multiple of the text height. Default is 0.05.
:draw_line
-
Whether to draw the underline as part of the link or not. Default is
true
. :line_style
-
The style modification hash supplied to PDF::Writer::StrokeStyle.new. The default is a solid line with normal cap, join, and miter limit values.
Set this to nil
to get the default style.
2496 2497 2498 |
# File 'lib/extensions/pdf-writer/pdf/writer.rb', line 2496 def style @style end |
Class Method Details
.[](pdf, info) ⇒ Object
2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 |
# File 'lib/extensions/pdf-writer/pdf/writer.rb', line 2498 def [](pdf, info) @style ||= DEFAULT_STYLE.dup case info[:status] when :start, :start_line # The beginning of the link. This should contain the URI for the # link as the :params entry, and will also contain the value of # :cbid. @links ||= {} @links[info[:cbid]] = { :x => info[:x], :y => info[:y], :angle => info[:angle], :descender => info[:descender], :height => info[:height], :uri => info[:params]["uri"] } pdf.save_state pdf.fill_color @style[:text_color] if @style[:text_color] if @style[:draw_line] pdf.stroke_color @style[:color] if @style[:color] sz = info[:height] * @style[:factor] pdf.stroke_style! StrokeStyle.new(sz, @style[:line_style]) end when :end, :end_line # The end of the link. Assume that it is the most recent opening # which has closed. start = @links[info[:cbid]] # Add underlining. theta = PDF::Math.deg2rad(start[:angle] - 90.0) if @style[:draw_line] 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 end pdf.add_link(start[:uri], start[:x], start[:y] + start[:descender], info[:x], start[:y] + start[:descender] + start[:height]) pdf.restore_state end end |