Class: DYI::Shape::Text
- Inherits:
-
Base
show all
- Defined in:
- lib/ironruby.rb,
lib/dyi/shape/base.rb
Overview
Constant Summary
collapse
- BASELINE_VALUES =
['baseline', 'top', 'middle', 'bottom']
- DEFAULT_LINE_HEIGHT =
1.0
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
#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
#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.
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
777
778
779
|
# File 'lib/dyi/shape/base.rb', line 777
def format
@format
end
|
#line_height ⇒ Object
775
776
777
|
# File 'lib/dyi/shape/base.rb', line 775
def line_height
@line_height
end
|
#text ⇒ Object
776
777
778
|
# File 'lib/dyi/shape/base.rb', line 776
def text
@text
end
|
Instance Method Details
#dy ⇒ Object
799
800
801
|
# File 'lib/dyi/shape/base.rb', line 799
def dy
font_height * (line_height || DEFAULT_LINE_HEIGHT)
end
|
#font_height ⇒ Object
795
796
797
|
# File 'lib/dyi/shape/base.rb', line 795
def font_height
font.draw_size
end
|
#formated_text ⇒ Object
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
|
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
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
|