class Gdsii::Text
Represents a GDSII Text element. Most methods are from Element or from the various included Access module methods.
Public Class Methods
Create a text record grouping given a layer, text type, xy coordinate, and a string.
text1 = Gdsii::Text.new(1, 0, [0,0], 'hello') text2 = Gdsii::Text.new(1, 0, [100, 0], 'world', 2, :ne)
# File lib/gdsii/text.rb, line 71 def initialize(layer=nil, texttype=nil, xy=nil, string=nil, font=nil, origin=nil) super() @records[GRT_TEXT] = Record.new(GRT_TEXT) self.layer = layer unless layer.nil? self.texttype = texttype unless texttype.nil? self.xy = xy unless xy.nil? self.string = string unless string.nil? self.font = font unless font.nil? self.origin = origin unless origin.nil? yield self if block_given? end
Public Instance Methods
Returns the font number (Fixnum in range 0-3) according to the font bits in the presentation record.
# File lib/gdsii/text.rb, line 156 def font() # clear all other bits then start at 4th bit; 2**4 == 16 pres = presentation || 0 (pres & 0x0030) / 16 end
Specifies the font to use (valid range is 0-3). Calls presentation= to change the font bits.
# File lib/gdsii/text.rb, line 141 def font=(val) if val >= 0 and val <= 3 # Be sure to clear out old value first... # start at 4th bit; 2**4 == 16 pres = presentation || 0 self.presentation = (pres & 0xFFCF) | 16*val else raise ArgumentError, "Font value must be 0-3; given: #{val}" end end
Returns the text origin as a symbol containing one of 9 possible values representing compass points:
-
:c == center (x == center; y == center)
-
:n == north (x == center; y == top)
-
:ne == northeast (x == right; y == top)
-
:e == east (x == right; y == center)
-
:se == southeast (x == right; y == bottom)
-
:s == south (x == center; y == bottom)
-
:sw == southwest (x == left; y == bottom)
-
:w == west (x == left; y == center)
-
:nw == northwest (x == left; y == top)
The presentation method is used to extract the bits related to the text origin.
# File lib/gdsii/text.rb, line 179 def origin() # origin bits: x == 0-1; y == 2-3 pres = presentation || 0 x_num = (pres & 0b0011) y_num = (pres & 0b1100) @@pres_lookup[[x_num, y_num]] end
Sets the text origin based upon one of 9 compass points (see origin for the list). The presentation= method is called to manipulate the presentation bits related to the text origin.
# File lib/gdsii/text.rb, line 192 def origin=(point) if nums = @@pres_lookup[point] # clear origin bits then set to the new value pres = presentation || 0 self.presentation = (pres & 0xFFF0) | nums[0] | nums[1] else raise "Compass point given: #{point.inspect} is not valid" end end
Set the presentation bitarray number. It is easier to not modify this number directly but to use font= and origin= instead.
-
bits 0 and 1: x origin; 00 left, 01 center, 10 right
-
bits 2 and 3: y origin; 00 top, 01, center, 10 bottom
-
bits 4 and 5: font number; 00 font 0, 01 font 1, 10 font 2, 11 font 3
-
All other bits are reserved
# File lib/gdsii/text.rb, line 133 def presentation=(val) @records.set(GRT_PRESENTATION, val); end
Get the presentation record (returns Record).
# File lib/gdsii/text.rb, line 116 def presentation_record() @records.get(GRT_PRESENTATION); end
Get the text string value (returns String).
# File lib/gdsii/text.rb, line 106 def string() @records.get_data(GRT_STRING); end
Set the text string value.
# File lib/gdsii/text.rb, line 111 def string=(val) @records.set(GRT_STRING, val); end
Get the text string record (returns Record).
# File lib/gdsii/text.rb, line 101 def string_record() @records.get(GRT_STRING); end
Get the texttype number (returns Fixnum).
# File lib/gdsii/text.rb, line 91 def texttype() @records.get_data(GRT_TEXTTYPE); end
Set the texttype number.
# File lib/gdsii/text.rb, line 96 def texttype=(val) @records.set(GRT_TEXTTYPE, val); end
Get the texttype record (returns Record).
# File lib/gdsii/text.rb, line 86 def texttype_record() @records.get(GRT_TEXTTYPE); end