Class PDF::Writer::TagAlink
In: lib/pdf/writer.rb
Parent: Object
Transaction::Simple SimpleTable TechBook Complex Action Procset FontDescriptor FontEncoding Destination Info Catalog Encryption Contents Pages Outline Outlines Annotation Page Font ViewerPreferences Image Hash OHash QuickRef FontMetrics ARC4 StrokeStyle PolygonPoint ImageInfo StdDev lib/pdf/simpletable.rb lib/pdf/techbook.rb lib/pdf/writer.rb lib/pdf/quickref.rb Math lib/pdf/writer/fontmetrics.rb lib/pdf/writer/ohash.rb lib/pdf/writer/arc4.rb lib/pdf/writer/strokestyle.rb lib/pdf/writer/graphics.rb lib/pdf/writer/object.rb lib/pdf/writer/object/image.rb External EN Lang OffsetReader lib/pdf/writer/graphics/imageinfo.rb Graphics lib/pdf/writer/object/outlines.rb lib/pdf/writer/object/destination.rb lib/pdf/writer/object/viewerpreferences.rb lib/pdf/writer/object/fontencoding.rb lib/pdf/writer/object/page.rb lib/pdf/writer/object/contents.rb lib/pdf/writer/object/procset.rb lib/pdf/writer/object/pages.rb lib/pdf/writer/object/info.rb lib/pdf/writer/object/encryption.rb lib/pdf/writer/object/catalog.rb lib/pdf/writer/object/outline.rb lib/pdf/writer/object/fontdescriptor.rb lib/pdf/writer/object/action.rb lib/pdf/writer/object/font.rb lib/pdf/writer/object/annotation.rb Object Writer lib/pdf/charts/stddev.rb Charts 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 2527
2527:       def [](pdf, info)
2528:         @style ||= DEFAULT_STYLE.dup
2529: 
2530:         case info[:status]
2531:         when :start, :start_line
2532:             # The beginning of the link. This should contain the URI for the
2533:             # link as the :params entry, and will also contain the value of
2534:             # :cbid.
2535:           @links ||= {}
2536: 
2537:           @links[info[:cbid]] = {
2538:             :x         => info[:x],
2539:             :y         => info[:y],
2540:             :angle     => info[:angle],
2541:             :descender => info[:descender],
2542:             :height    => info[:height],
2543:             :uri       => info[:params]["uri"]
2544:           }
2545: 
2546:           pdf.save_state
2547:           pdf.fill_color @style[:text_color] if @style[:text_color]
2548:           if @style[:draw_line]
2549:             pdf.stroke_color  @style[:color] if @style[:color]
2550:             sz = info[:height] * @style[:factor]
2551:             pdf.stroke_style! StrokeStyle.new(sz, @style[:line_style])
2552:           end
2553:         when :end, :end_line
2554:             # The end of the link. Assume that it is the most recent opening
2555:             # which has closed.
2556:           start = @links[info[:cbid]]
2557:             # Add underlining.
2558:           theta = PDF::Math.deg2rad(start[:angle] - 90.0)
2559:           if @style[:draw_line]
2560:             drop  = start[:height] * @style[:factor] * 1.5
2561:             drop_x = Math.cos(theta) * drop
2562:             drop_y = -Math.sin(theta) * drop
2563:             pdf.move_to(start[:x] - drop_x, start[:y] - drop_y)
2564:             pdf.line_to(info[:x] - drop_x, info[:y] - drop_y).stroke
2565:           end
2566:           pdf.add_link(start[:uri], start[:x], start[:y] +
2567:                        start[:descender], info[:x], start[:y] +
2568:                        start[:descender] + start[:height])
2569:           pdf.restore_state
2570:         end
2571:       end

[Validate]