Class PDF::Writer::TagAlink
In: lib/pdf/writer.rb
Parent: Object
TechBook Transaction::Simple SimpleTable Complex Action FontDescriptor Procset Catalog FontEncoding Pages Destination Info Encryption Annotation Contents Outline Page Outlines Font ViewerPreferences Image Hash OHash QuickRef StdDev FontMetrics StrokeStyle ARC4 PolygonPoint ImageInfo lib/pdf/simpletable.rb lib/pdf/writer.rb lib/pdf/techbook.rb lib/pdf/quickref.rb lib/pdf/charts/stddev.rb Charts Math lib/pdf/writer/ohash.rb lib/pdf/writer/fontmetrics.rb lib/pdf/writer/strokestyle.rb lib/pdf/writer/arc4.rb lib/pdf/writer/graphics.rb lib/pdf/writer/object.rb lib/pdf/writer/object/image.rb External lib/pdf/writer/object/font.rb lib/pdf/writer/object/outlines.rb lib/pdf/writer/object/contents.rb lib/pdf/writer/object/annotation.rb lib/pdf/writer/object/destination.rb lib/pdf/writer/object/viewerpreferences.rb lib/pdf/writer/object/info.rb lib/pdf/writer/object/fontencoding.rb lib/pdf/writer/object/page.rb lib/pdf/writer/object/catalog.rb lib/pdf/writer/object/outline.rb lib/pdf/writer/object/encryption.rb lib/pdf/writer/object/procset.rb lib/pdf/writer/object/action.rb lib/pdf/writer/object/pages.rb lib/pdf/writer/object/fontdescriptor.rb Object OffsetReader EN Lang lib/pdf/writer/graphics/imageinfo.rb Graphics Writer PDF dot/m_33_0.png

A callback to support the formation of clickable links to external locations.

Methods

[]  

Constants

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.

Attributes

style  [RW]  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.

Public Class methods

[Source]

      # File lib/pdf/writer.rb, line 2498
2498:       def [](pdf, info)
2499:         @style ||= DEFAULT_STYLE.dup
2500: 
2501:         case info[:status]
2502:         when :start, :start_line
2503:             # The beginning of the link. This should contain the URI for the
2504:             # link as the :params entry, and will also contain the value of
2505:             # :cbid.
2506:           @links ||= {}
2507: 
2508:           @links[info[:cbid]] = {
2509:             :x         => info[:x],
2510:             :y         => info[:y],
2511:             :angle     => info[:angle],
2512:             :descender => info[:descender],
2513:             :height    => info[:height],
2514:             :uri       => info[:params]["uri"]
2515:           }
2516: 
2517:           pdf.save_state
2518:           pdf.fill_color @style[:text_color] if @style[:text_color]
2519:           if @style[:draw_line]
2520:             pdf.stroke_color  @style[:color] if @style[:color]
2521:             sz = info[:height] * @style[:factor]
2522:             pdf.stroke_style! StrokeStyle.new(sz, @style[:line_style])
2523:           end
2524:         when :end, :end_line
2525:             # The end of the link. Assume that it is the most recent opening
2526:             # which has closed.
2527:           start = @links[info[:cbid]]
2528:             # Add underlining.
2529:           theta = PDF::Math.deg2rad(start[:angle] - 90.0)
2530:           if @style[:draw_line]
2531:             drop  = start[:height] * @style[:factor] * 1.5
2532:             drop_x = Math.cos(theta) * drop
2533:             drop_y = -Math.sin(theta) * drop
2534:             pdf.move_to(start[:x] - drop_x, start[:y] - drop_y)
2535:             pdf.line_to(info[:x] - drop_x, info[:y] - drop_y).stroke
2536:           end
2537:           pdf.add_link(start[:uri], start[:x], start[:y] +
2538:                        start[:descender], info[:x], start[:y] +
2539:                        start[:descender] + start[:height])
2540:           pdf.restore_state
2541:         end
2542:       end

[Validate]