Class: DYI::Drawing::Pen
Overview
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.
Direct Known Subclasses
Constant Summary collapse
- ALIAS_ATTRIBUTES =
Painting::IMPLEMENT_ATTRIBUTES.inject({}) do |hash, key| hash[$'.empty? ? :color : $'.to_sym] = key if key.to_s =~ /^(stroke_|stroke$)/ && key != :stroke_opacity hash end
Constants inherited from PenBase
DYI::Drawing::PenBase::DROP_SHADOW_OPTIONS
Instance Attribute Summary collapse
-
#color ⇒ Color, ...
Synonym of attribute stroke.
-
#dasharray ⇒ Color, ...
Synonym of attribute stroke.
-
#dashoffset ⇒ Color, ...
Synonym of attribute stroke.
-
#linecap ⇒ Color, ...
Synonym of attribute stroke.
-
#linejoin ⇒ Color, ...
Synonym of attribute stroke.
-
#miterlimit ⇒ Color, ...
Synonym of attribute stroke.
-
#width ⇒ Color, ...
Synonym of attribute stroke.
Attributes inherited from PenBase
#display, #drop_shadow, #fill, #fill_opacity, #fill_rule, #opacity, #stroke, #stroke_dasharray, #stroke_dashoffset, #stroke_linecap, #stroke_linejoin, #stroke_miterlimit, #stroke_opacity, #stroke_width, #visibility
Class Method Summary collapse
Instance Method Summary collapse
-
#draw_text(canvas, point, text, options = {}) ⇒ Shape::Text
Draws a text.
-
#initialize(options = {}) ⇒ Pen
constructor
A new instance of Pen.
Methods inherited from PenBase
#draw_circle, #draw_closed_path, #draw_ellipse, #draw_image, #draw_line, #draw_line_on_direction, #draw_path, #draw_polygon, #draw_polyline, #draw_rectangle, #draw_rectangle_on_corner, #draw_sector, #draw_toroid, #import_image
Constructor Details
#initialize(options = {}) ⇒ Pen
Returns a new instance of Pen.
585 586 587 588 589 590 591 592 |
# File 'lib/dyi/drawing/pen.rb', line 585 def initialize(={}) = .clone ALIAS_ATTRIBUTES.each do |key, value| [value] = .delete(key) if .key?(key) && !.key?(value) end [:stroke] = 'black' unless .key?(:stroke) super end |
Instance Attribute Details
#color ⇒ Color, ...
Synonym of attribute stroke. +++ Synonym of attribute stroke_dasharray. +++ Synonym of attribute stroke_dashoffset. +++ Synonym of attribute stroke_linecap. +++ Synonym of attribute stroke_linejoin. +++ Synonym of attribute stroke_miterlimit. +++ Synonym of attribute stroke_width.
621 622 623 624 |
# File 'lib/dyi/drawing/pen.rb', line 621 ALIAS_ATTRIBUTES.each do |key, value| alias_method key, value alias_method "#{key}=", "#{value}=" end |
#dasharray ⇒ Color, ...
Synonym of attribute stroke. +++ Synonym of attribute stroke_dasharray. +++ Synonym of attribute stroke_dashoffset. +++ Synonym of attribute stroke_linecap. +++ Synonym of attribute stroke_linejoin. +++ Synonym of attribute stroke_miterlimit. +++ Synonym of attribute stroke_width.
621 622 623 624 |
# File 'lib/dyi/drawing/pen.rb', line 621 ALIAS_ATTRIBUTES.each do |key, value| alias_method key, value alias_method "#{key}=", "#{value}=" end |
#dashoffset ⇒ Color, ...
Synonym of attribute stroke. +++ Synonym of attribute stroke_dasharray. +++ Synonym of attribute stroke_dashoffset. +++ Synonym of attribute stroke_linecap. +++ Synonym of attribute stroke_linejoin. +++ Synonym of attribute stroke_miterlimit. +++ Synonym of attribute stroke_width.
621 622 623 624 |
# File 'lib/dyi/drawing/pen.rb', line 621 ALIAS_ATTRIBUTES.each do |key, value| alias_method key, value alias_method "#{key}=", "#{value}=" end |
#linecap ⇒ Color, ...
Synonym of attribute stroke. +++ Synonym of attribute stroke_dasharray. +++ Synonym of attribute stroke_dashoffset. +++ Synonym of attribute stroke_linecap. +++ Synonym of attribute stroke_linejoin. +++ Synonym of attribute stroke_miterlimit. +++ Synonym of attribute stroke_width.
621 622 623 624 |
# File 'lib/dyi/drawing/pen.rb', line 621 ALIAS_ATTRIBUTES.each do |key, value| alias_method key, value alias_method "#{key}=", "#{value}=" end |
#linejoin ⇒ Color, ...
Synonym of attribute stroke. +++ Synonym of attribute stroke_dasharray. +++ Synonym of attribute stroke_dashoffset. +++ Synonym of attribute stroke_linecap. +++ Synonym of attribute stroke_linejoin. +++ Synonym of attribute stroke_miterlimit. +++ Synonym of attribute stroke_width.
621 622 623 624 |
# File 'lib/dyi/drawing/pen.rb', line 621 ALIAS_ATTRIBUTES.each do |key, value| alias_method key, value alias_method "#{key}=", "#{value}=" end |
#miterlimit ⇒ Color, ...
Synonym of attribute stroke. +++ Synonym of attribute stroke_dasharray. +++ Synonym of attribute stroke_dashoffset. +++ Synonym of attribute stroke_linecap. +++ Synonym of attribute stroke_linejoin. +++ Synonym of attribute stroke_miterlimit. +++ Synonym of attribute stroke_width.
621 622 623 624 |
# File 'lib/dyi/drawing/pen.rb', line 621 ALIAS_ATTRIBUTES.each do |key, value| alias_method key, value alias_method "#{key}=", "#{value}=" end |
#width ⇒ Color, ...
Synonym of attribute stroke. +++ Synonym of attribute stroke_dasharray. +++ Synonym of attribute stroke_dashoffset. +++ Synonym of attribute stroke_linecap. +++ Synonym of attribute stroke_linejoin. +++ Synonym of attribute stroke_miterlimit. +++ Synonym of attribute stroke_width.
621 622 623 624 |
# File 'lib/dyi/drawing/pen.rb', line 621 ALIAS_ATTRIBUTES.each do |key, value| alias_method key, value alias_method "#{key}=", "#{value}=" end |
Class Method Details
.method_missing(method_name, *args, &block) ⇒ Object
641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/dyi/drawing/pen.rb', line 641 def method_missing(method_name, *args, &block) if method_name.to_s =~ /^([a-z]+)_pen$/ if = args.first self.new(.merge(:stroke => $1)) else self.new(:stroke => $1) end else super end end |
Instance Method Details
#draw_text(canvas, point, text, options = {}) ⇒ Shape::Text
Draws a text.
627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/dyi/drawing/pen.rb', line 627 def draw_text(canvas, point, text, ={}) 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 |