Class: Autocad::Text
Overview
Single-line text annotation element in AutoCAD
Represents a simple text entity with a single line of content. Provides methods for reading, writing, and manipulating text properties.
Instance Attribute Summary
Attributes inherited from Element
#acad_type, #app, #ole_obj, #original
Instance Method Summary collapse
-
#=~(reg) ⇒ Integer?
Regex pattern matching against text content.
-
#bounds ⇒ BoundingBox
Experimental bounding box calculation.
-
#highlight(flag = true) ⇒ void
Toggle text highlighting in the drawing.
-
#method_missing(meth) ⇒ Object
Delegate uppercase methods to OLE object, lowercase to string methods.
-
#read_ole(_ole) ⇒ String
Read text content from OLE object.
-
#text? ⇒ Boolean
Confirm this is a text element (always true).
-
#to_regexp ⇒ Regexp
Convert text content to regex pattern.
-
#to_s ⇒ String
Get text content as string.
-
#write_ole(text) ⇒ void
Update text content in AutoCAD.
Methods inherited from Element
#[], #app_ole_obj, #clone, convert_item, #delete, #do_update, #each_complex, #get_property_handler, #in_cell?, #initialize, #move, #move_ole, #move_x, #move_y, #ole_cell, ole_object?, #property_handler, #redraw, #update, #updated?
Methods included from ElementTrait
#autocad_type, #block_reference?, #cell?, #def, #drawing, #explode, #graphical?, #has_tags?, #id_from_record, #inspect, #line?, #model, #parent, #pviewport?, #select, #to_ole, #visible?
Constructor Details
This class inherits a constructor from Autocad::Element
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object
Delegate uppercase methods to OLE object, lowercase to string methods
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/autocad/text.rb', line 111 def method_missing(meth, *, &) if /^[A-Z]/.match?(meth) ole_obj.send(meth, *) else dup = @original.dup result = dup.send(meth, *, &) update(result) result end end |
Instance Method Details
#=~(reg) ⇒ Integer?
Regex pattern matching against text content
67 68 69 |
# File 'lib/autocad/text.rb', line 67 def =~(reg) @original =~ reg end |
#bounds ⇒ BoundingBox
Contains debug code - use with caution
Experimental bounding box calculation
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/autocad/text.rb', line 84 def bounds binding.break rotation = ole_obj.Rotation begin app_ole_obj.Matrix3dInverse(rotation) rescue binding.irb end transform = app_ole_obj.Transform3dFromMatrix3dandFixedPoint3d(app_ole_obj.Matrix3dInverse(rotation), ole_obj.origin) ole_obj.transform transform 0.upto(4) do |i| points[i] = ole_obj.Boundary.Low end points[2] = self.Boundary.High points[1].X = points[2].x points[3].y = points[2].Y end |
#highlight(flag = true) ⇒ void
This method returns an undefined value.
Toggle text highlighting in the drawing
57 58 59 60 |
# File 'lib/autocad/text.rb', line 57 def highlight(flag = true) ole_obj.Highlight(flag) ole_obj.Update end |
#read_ole(_ole) ⇒ String
Read text content from OLE object
21 22 23 |
# File 'lib/autocad/text.rb', line 21 def read_ole(_ole) ole_obj.TextString end |
#text? ⇒ Boolean
Confirm this is a text element (always true)
29 30 31 |
# File 'lib/autocad/text.rb', line 29 def text? true end |
#to_regexp ⇒ Regexp
Convert text content to regex pattern
46 47 48 |
# File 'lib/autocad/text.rb', line 46 def to_regexp Regexp.new(read_ole.to_s) end |
#to_s ⇒ String
Get text content as string
75 76 77 |
# File 'lib/autocad/text.rb', line 75 def to_s original.to_s end |
#write_ole(text) ⇒ void
This method returns an undefined value.
Update text content in AutoCAD
38 39 40 |
# File 'lib/autocad/text.rb', line 38 def write_ole(text) ole_obj.TextString = text end |