Class: DYI::Shape::Text

Inherits:
Base show all
Defined in:
lib/ironruby.rb,
lib/dyi/shape/base.rb

Overview

Since:

  • 0.0.0

Constant Summary collapse

BASELINE_VALUES =

Since:

  • 0.0.0

['baseline', 'top', 'middle', 'bottom']
DEFAULT_LINE_HEIGHT =

Since:

  • 0.0.0

1.0

Constants inherited from GraphicalElement

GraphicalElement::CLASS_REGEXP

Constants inherited from Element

Element::ID_REGEXP

Instance Attribute Summary collapse

Attributes inherited from Base

#anchor_href, #anchor_target, #attributes, #clipping, #parent

Attributes inherited from GraphicalElement

#css_class

Attributes inherited from Element

#description, #title

Instance Method Summary collapse

Methods inherited from Base

#add_animation, #add_painting_animation, #add_transform_animation, #animate?, #animations, #clear_clipping, #draw_on, #has_marker?, #has_uri_reference?, #root_element?, #root_node?, #rotate, #scale, #set_clipping, #set_clipping_shapes, #set_event, #skew_x, #skew_y, #transform, #translate

Methods inherited from GraphicalElement

#add_css_class, #add_event_listener, #css_classes, #event_listeners, #event_target?, #remove_css_class, #remove_event_listener, #set_event, #to_reused_source

Methods inherited from Element

#canvas, #child_elements, #has_uri_reference?, #id, #id=, #include_external_file?, #inner_id

Constructor Details

#initialize(point, text = nil, options = {}) ⇒ Text

Returns a new instance of Text.

Parameters:

  • point (Coordinate)

    a start coordinate of the text

  • text (String) (defaults to: nil)

    a text that is displayed

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :painting (Painting)

    painting status of the shape

  • :font (Font)

    font status of the text

  • :description (String)

    the description of this shape

  • :title (String)

    the title of this shape

Since:

  • 0.0.0



785
786
787
788
789
# File 'lib/dyi/shape/base.rb', line 785

def initialize(point, text=nil, options={})
  @point = Coordinate.new(point || [0,0])
  @text = text
  @attributes = init_attributes(options)
end

Instance Attribute Details

#formatObject

Since:

  • 0.0.0



777
778
779
# File 'lib/dyi/shape/base.rb', line 777

def format
  @format
end

#line_heightObject

Since:

  • 0.0.0



775
776
777
# File 'lib/dyi/shape/base.rb', line 775

def line_height
  @line_height
end

#textObject

Since:

  • 0.0.0



776
777
778
# File 'lib/dyi/shape/base.rb', line 776

def text
  @text
end

Instance Method Details

#dyObject

Since:

  • 0.0.0



799
800
801
# File 'lib/dyi/shape/base.rb', line 799

def dy
  font_height * (line_height || DEFAULT_LINE_HEIGHT)
end

#font_heightObject

Since:

  • 0.0.0



795
796
797
# File 'lib/dyi/shape/base.rb', line 795

def font_height
  font.draw_size
end

#formated_textObject

Since:

  • 0.0.0



803
804
805
806
807
808
809
810
811
812
813
814
815
# File 'lib/dyi/shape/base.rb', line 803

def formated_text
  if @format
    if @text.kind_of?(Numeric)
      @text.strfnum(@format)
    elsif @text.respond_to?(:strftime)
      @text.strftime(@format)
    else
      @text.to_s
    end
  else
    @text.to_s
  end
end

#string_formatObject

Since:

  • 0.0.0



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ironruby.rb', line 138

def string_format
  format = System::Drawing::StringFormat.new
  format.alignment =
    case attributes[:text_anchor]
      when 'start' then System::Drawing::StringAlignment.near
      when 'middle' then System::Drawing::StringAlignment.center
      when 'end' then System::Drawing::StringAlignment.far
      else System::Drawing::StringAlignment.near
    end
  format.line_alignment =
    case attributes[:alignment_baseline]
      when 'baseline' then System::Drawing::StringAlignment.far
      when 'top' then System::Drawing::StringAlignment.near
      when 'middle' then System::Drawing::StringAlignment.center
      when 'bottom' then System::Drawing::StringAlignment.far
      else System::Drawing::StringAlignment.far
    end
  format
end

#write_as(formatter, io = $>) ⇒ Object

Since:

  • 0.0.0



817
818
819
# File 'lib/dyi/shape/base.rb', line 817

def write_as(formatter, io=$>)
  formatter.write_text(self, io, &(block_given? ? Proc.new : nil))
end