class DYI::Drawing::Pen

Pen object holds a {Painting} object and a {Font} object. Using these object, Pen object creates instances of concrete subclass of {Shape::Base}; a created instance has a painting attribute and a font attribute that Pen object holds.

Pen class has been optimized to draw a line or a outline of the shape. Synonym methods of attributes stroke_xxx has been defined in this class: color(synonym of stroke), dashoffset(synonym of stroke_dashoffset), linecap(synonym of stroke_linecap), linejoin(synonym of stroke_linejoin), miterlimit(synonym of stroke_miterlimit) and width(synonym of stroke_width).

This class has shortcut contractors: color_name_pen, which a line color is specified in.

@example

pen = DYI::Drawing::Pen.red_pen(:wdith => 3)
# the followings is the same processing
# pen = DYI::Drawing::Pen.new(:color => 'red', :wdith => 3)
# pen = DYI::Drawing::Pen.new(:stroke => 'red', :stroke_wdith => 3)

canvas = DYI::Canvas.new(100, 50)
pen.draw_line(canvas, [10, 20], [90, 40])

@since 0.0.0

Constants

ALIAS_ATTRIBUTES

@private

Public Class Methods

method_missing(method_name, *args, &block) click to toggle source
Calls superclass method
# File lib/dyi/drawing/pen.rb, line 640
def method_missing(method_name, *args, &block)
  if method_name.to_s =~ /^([a-z]+)_pen$/
    if options = args.first
      self.new(options.merge(:stroke => $1))
    else
      self.new(:stroke => $1)
    end
  else
    super
  end
end
new(options={}) click to toggle source

(see PenBase#initialize) @option options [Color, write_as] :color the value of attribute {#color

color}

@option options [Array<Length>, String] :dasharray the value of

attribute {#dasharray dasharray}

@option options [Length] :dashoffset the value of attribute {#dashoffset

dashoffset}

@option options [String] :linecap the value of attribute {#linecap

linecap}

@option options [String] :linejoin the value of attribute {#linejoin

linejoin}

@option options [#to_f] :miterlimit the value of attribute {#miterlimit

mitterlimit}

@option options [Lengthf] :width the value of attribute {#width width}

Calls superclass method DYI::Drawing::PenBase::new
# File lib/dyi/drawing/pen.rb, line 584
def initialize(options={})
  options = options.clone
  ALIAS_ATTRIBUTES.each do |key, value|
    options[value] = options.delete(key) if options.key?(key) && !options.key?(value)
  end
  options[:stroke] = 'black' unless options.key?(:stroke)
  super
end

Public Instance Methods

draw_text(canvas, point, text, options={}) click to toggle source

(see PenBase#draw_text)

Calls superclass method DYI::Drawing::PenBase#draw_text
# File lib/dyi/drawing/pen.rb, line 626
def draw_text(canvas, point, text, options={})
  painting = @painting
  text_painting = Painting.new(painting)
  text_painting.fill = painting.stroke
  text_painting.fill_opacity = painting.stroke_opacity
  text_painting.stroke = nil
  text_painting.stroke_width = nil
  @painting = text_painting
  shape = super
  @painting = painting
  shape
end