Class PDF::Writer::StrokeStyle
In: lib/pdf/writer/strokestyle.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 class that represents a style with which lines will be drawn.

Methods

new   render  

Constants

LINE_CAPS = { :butt => 0, :round => 1, :square => 2 }
LINE_JOINS = { :miter => 0, :round => 1, :bevel => 2 }
SOLID_LINE = { :pattern => [], :phase => 0 }
DEFAULT = self.new(1, :cap => :butt, :join => :miter, :dash => SOLID_LINE)

Attributes

cap  [RW]  The type of cap to put on the line.
:butt:The stroke is squared off at the endpoint of the path. There is no projection beyond the end of the path.
:round:A semicircular arc with a diameter equal to the line width is drawn around the endpoint and filled in.
:square:The stroke continues beyond the endpoint of the path for a distance equal to half the line width and is squared off.
nil:Keeps the current line cap.
dash  [RW]  Controls the pattern of dashes and gaps used to stroke paths. This value must either be nil, or a hash with the following values:
:pattern:An array of numbers specifying the lengths (in PDF userspace units) of alternating dashes and gaps. The array is processed cyclically, so that a :pattern of [3] represents three units on, three units off, and a :pattern of
2, 1
represents two units on, one unit off.
      # - represents on, _ represents off
    ---___---___---   # pattern [3]
    --_--_--_--_--_   # pattern [2, 1]
:phase:The offset in the :pattern where the drawing of the stroke begins. Using a :phase of 1, the :pattern [3] will start offset by one phase, for two units on, three units off, three units on.
    --___---___---_   # pattern [3], phase 1
    -_--_--_--_--_-   # pattern [2, 1], phase 1

The constant SOLID_LINE may be used to restore line drawing to a solid line; this corresponds to an empty pattern with zero phase ([] 0).

Dashed lines wrap around curves and corners just as solid stroked lines do, with normal cap and join handling with no consideration of the dash pattern. A path with several subpaths treats each subpath independently; the complete dash pattern is restarted at the beginning of each subpath.

join  [RW]  How two lines join together.
:miter:The outer edges of the strokes for the two segments are extended until they meet at an angle, as in a picture frame. If the segments meet at too sharp an angle (as defined by the miter_limit), a bevel join is used instead.
:round:An arc of a circle with a diameter equal to the line width is drawn around the point where the two segments meet, connecting the outer edges of the strokes for the two segments. This pie-slice shaped figure is filled in, producing a rounded corner.
:bevel:The two segments are finished with butt caps and the the resulting notch beyond the ends of the segments is filled with a triangle, forming a flattened edge on the join.
nil:Keeps the current line join.
miter_limit  [RW]  When two line segments meet and :miter joins have been specified, the miter may extend far beyond the thickness of the line stroking the path. miter_limit imposes a maximum ratio miter length to line width at which point the join will be converted from a miter to a bevel. Adobe points out that the ratio is directly related to the angle between the segments in user space. With [p] representing the angle at which the segments meet:
    miter_length / line_width == 1 / (sin ([p] / 2))

A miter limit of 1.414 converts miters to bevels for [p] less than 90 degrees, a limit of 2.0 converts them for [p] less than 60 degrees, and a limit of 10.0 converts them for [p] less than approximately 11.5 degrees.

width  [RW]  The thickness of the line in PDF units.

Public Class methods

[Source]

    # File lib/pdf/writer/strokestyle.rb, line 17
17:   def initialize(width = 1, options = {})
18:     @width        = width
19:     @cap          = options[:cap]
20:     @join         = options[:join]
21:     @dash         = options[:dash]
22:     @miter_limit  = options[:miter_limit]
23: 
24:     yield self if block_given?
25:   end

Public Instance methods

[Source]

     # File lib/pdf/writer/strokestyle.rb, line 125
125:   def render(debug = false)
126:     s = ""
127:     s << "#{width} w" if @width > 0
128:     s << " #{LINE_CAPS[@cap]} J" if @cap
129:     s << " #{LINE_JOINS[@join]} j" if @join
130:     s << " #{@miter_limit} M" if @miter_limit
131:     if @dash
132:       s << " ["
133:       @dash[:pattern].each { |len| s << " #{len}" }
134:       s << " ] #{@dash[:phase] or 0} d"
135:     end
136:     s
137:   end

[Validate]