Class: Autocad::MText
Overview
Multi-line formatted text container in AutoCAD
Represents a rich text entity with multiple lines and formatting. Supports Liquid templates, table cell awareness, and line-by-line operations.
Instance Attribute Summary collapse
-
#ole_obj ⇒ Object
readonly
Returns the value of attribute ole_obj.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
Attributes inherited from Element
Instance Method Summary collapse
-
#=~(reg) ⇒ Integer?
Regex pattern matching against text content.
-
#empty? ⇒ Boolean
Check for empty content.
-
#method_missing(meth) ⇒ Object
Delegate uppercase methods to OLE object, lowercase to string methods.
-
#mtext? ⇒ Boolean
Type check for multi-line text (always true).
-
#read_ole(ole) ⇒ String
Read content from OLE object.
-
#render(h = {}) ⇒ self
Render Liquid template with provided context.
-
#size ⇒ Integer
Get number of text lines.
-
#template? ⇒ Boolean
Check for Liquid template placeholders.
-
#text? ⇒ Boolean
Override text type check (always false).
-
#to_regexp ⇒ Regexp
Convert content to regex pattern.
-
#to_s ⇒ String
Get content as string.
-
#update_ole!(text) ⇒ void
Full content rewrite with line-by-line updates.
-
#write_ole(text) ⇒ void
Update text content with cell awareness.
-
#write_ole_in_cell(text) ⇒ void
Update text content for MText in table cell.
-
#write_ole_regular(text) ⇒ void
Update text content for regular MText.
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?, #bounds, #cell?, #def, #drawing, #explode, #graphical?, #has_tags?, #highlight, #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
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/autocad/mtext.rb', line 167 def method_missing(meth, *, &) if /^[A-Z]/.match?(meth) ole_obj.send(meth, *) else copy = @original.dup result = copy.send(meth, *, &) update(result) unless copy == @original result end end |
Instance Attribute Details
#ole_obj ⇒ Object (readonly)
Returns the value of attribute ole_obj.
15 16 17 |
# File 'lib/autocad/mtext.rb', line 15 def ole_obj @ole_obj end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
15 16 17 |
# File 'lib/autocad/mtext.rb', line 15 def original @original end |
Instance Method Details
#=~(reg) ⇒ Integer?
Regex pattern matching against text content
132 133 134 |
# File 'lib/autocad/mtext.rb', line 132 def =~(reg) @original =~ reg end |
#empty? ⇒ Boolean
Check for empty content
29 30 31 |
# File 'lib/autocad/mtext.rb', line 29 def empty? ole_obj.TextLinesCount == 0 end |
#mtext? ⇒ Boolean
Type check for multi-line text (always true)
37 38 39 |
# File 'lib/autocad/mtext.rb', line 37 def mtext? true end |
#read_ole(ole) ⇒ String
Read content from OLE object
62 63 64 |
# File 'lib/autocad/mtext.rb', line 62 def read_ole(ole) ole.TextString end |
#render(h = {}) ⇒ self
Render Liquid template with provided context
151 152 153 154 155 156 157 158 |
# File 'lib/autocad/mtext.rb', line 151 def render(h = {}) return self unless template? template = Liquid::Template.parse(to_s) result = template.render(h) update(result) unless result == @original self end |
#size ⇒ Integer
Get number of text lines
53 54 55 |
# File 'lib/autocad/mtext.rb', line 53 def size ole_obj.TextLinesCount end |
#template? ⇒ Boolean
Check for Liquid template placeholders
140 141 142 |
# File 'lib/autocad/mtext.rb', line 140 def template? !!(@original =~ /{{.+}}/) end |
#text? ⇒ Boolean
Override text type check (always false)
45 46 47 |
# File 'lib/autocad/mtext.rb', line 45 def text? false end |
#to_regexp ⇒ Regexp
Convert content to regex pattern
21 22 23 |
# File 'lib/autocad/mtext.rb', line 21 def to_regexp Regexp.new(original.to_s) end |
#to_s ⇒ String
Get content as string
123 124 125 |
# File 'lib/autocad/mtext.rb', line 123 def to_s @original.to_s end |
#update_ole!(text) ⇒ void
This method returns an undefined value.
Full content rewrite with line-by-line updates
110 111 112 113 114 115 116 117 |
# File 'lib/autocad/mtext.rb', line 110 def update_ole!(text) ole_obj.DeleteAllTextLines text.each_line do |line| ole_obj.AddTextLine(line) end ole_obj.Redraw Autocad::MSD::MsdDrawingModeNormal ole_obj.Rewrite end |
#write_ole(text) ⇒ void
This method returns an undefined value.
Update text content with cell awareness
71 72 73 74 75 76 77 |
# File 'lib/autocad/mtext.rb', line 71 def write_ole(text) if in_cell? write_ole_in_cell(text) else write_ole_regular(text) end end |
#write_ole_in_cell(text) ⇒ void
This method returns an undefined value.
Update text content for MText in table cell
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/autocad/mtext.rb', line 93 def write_ole_in_cell(text) orig_ole = ole_obj new_text_ole = ole_obj.Clone new_text_ole.DeleteAllTextLines text.each_line do |line| new_text_ole.AddTextLine(line) end @ole_obj = new_text_ole rescue @ole_obj = orig_ole end |
#write_ole_regular(text) ⇒ void
This method returns an undefined value.
Update text content for regular MText
84 85 86 |
# File 'lib/autocad/mtext.rb', line 84 def write_ole_regular(text) ole_obj.TextString = text end |