Class: Gdsii::Text

Inherits:
Element
  • Object
show all
Includes:
Access::ELFlags, Access::Layer, Access::PathType, Access::Plex, Access::StransGroup, Access::Width, Access::XY
Defined in:
lib/gdsii/text.rb

Overview

Represents a GDSII Text element. Most methods are from Element or from the various included Access module methods.

Constant Summary collapse

@@pres_lookup =

Create a simple hash to store compass points and their respective presentation values and vice-versa. This is used in manipulating and querying the text’s PRESENTATION record.

{
  # * bits 0 and 1: x origin; 00 left, 01 center, 10 right
  # * bits 2 and 3: y origin; 00 top, 01, center, 10 bottom
  [0b0000, 0b0000] => :nw,
  [0b0000, 0b0100] => :w,
  [0b0000, 0b1000] => :sw,
  [0b0001, 0b0000] => :n,
  [0b0001, 0b0100] => :c,
  [0b0001, 0b1000] => :s,
  [0b0010, 0b0000] => :ne,
  [0b0010, 0b0100] => :e,
  [0b0010, 0b1000] => :se
}

Instance Method Summary collapse

Methods included from Access::StransGroup

#strans, #strans=

Methods included from Access::Plex

#plex, #plex=, #plex_record

Methods included from Access::ELFlags

#elflags, #elflags=, #elflags_record

Methods included from Access::Width

#width, #width=, #width_record

Methods included from Access::PathType

#pathtype, #pathtype=, #pathtype_record

Methods included from Access::XY

#xy, #xy=, #xy_record

Methods included from Access::Layer

#layer, #layer=, #layer_record

Constructor Details

#initialize(layer = nil, texttype = nil, xy = nil, string = nil, font = nil, origin = nil) {|_self| ... } ⇒ Text

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)

Yields:

  • (_self)

Yield Parameters:

  • _self (Gdsii::Text)

    the object that the method was called on



71
72
73
74
75
76
77
78
79
80
81
# 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

Instance Method Details

#fontObject

Returns the font number (Fixnum in range 0-3) according to the font bits in the #presentation record.



156
157
158
159
160
# 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

#font=(val) ⇒ Object

Specifies the font to use (valid range is 0-3). Calls #presentation= to change the font bits.



141
142
143
144
145
146
147
148
149
150
# 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

#originObject

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.



179
180
181
182
183
184
185
# 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

#origin=(point) ⇒ Object

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.



192
193
194
195
196
197
198
199
200
# 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

#presentationObject

Get the presentation bitarray number (returns Fixnum). It is probably easier to use #font and #origin instead.



122
# File 'lib/gdsii/text.rb', line 122

def presentation() @records.get_data(GRT_PRESENTATION); end

#presentation=(val) ⇒ Object

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



133
134
135
# File 'lib/gdsii/text.rb', line 133

def presentation=(val)
  @records.set(GRT_PRESENTATION, val);
end

#presentation_recordObject

Get the presentation record (returns Record).



116
# File 'lib/gdsii/text.rb', line 116

def presentation_record() @records.get(GRT_PRESENTATION); end

#stringObject

Get the text string value (returns String).



106
# File 'lib/gdsii/text.rb', line 106

def string() @records.get_data(GRT_STRING); end

#string=(val) ⇒ Object

Set the text string value.



111
# File 'lib/gdsii/text.rb', line 111

def string=(val) @records.set(GRT_STRING, val); end

#string_recordObject

Get the text string record (returns Record).



101
# File 'lib/gdsii/text.rb', line 101

def string_record() @records.get(GRT_STRING); end

#texttypeObject

Get the texttype number (returns Fixnum).



91
# File 'lib/gdsii/text.rb', line 91

def texttype() @records.get_data(GRT_TEXTTYPE); end

#texttype=(val) ⇒ Object

Set the texttype number.



96
# File 'lib/gdsii/text.rb', line 96

def texttype=(val) @records.set(GRT_TEXTTYPE, val); end

#texttype_recordObject

Get the texttype record (returns Record).



86
# File 'lib/gdsii/text.rb', line 86

def texttype_record() @records.get(GRT_TEXTTYPE); end