Class: JennCad::Primitives::Text

Inherits:
Primitive show all
Defined in:
lib/jenncad/primitives/text.rb

Instance Attribute Summary collapse

Attributes inherited from Primitive

#dimensions

Attributes inherited from Thing

#anchors, #angle, #calc_h, #calc_x, #calc_y, #calc_z, #csize, #diameter, #name, #opts, #parent, #parts, #pos, #shape, #sits_on, #transformations, #x, #y

Instance Method Summary collapse

Methods inherited from Primitive

#feed_opts, #handle_diameter, #handle_margins

Methods inherited from Thing

#anchor, #at, #auto_color, #auto_color!, #auto_extrude, #calculate_center_rotation, #calculated_h, #children_list, #color, #color_or_fallback, #color_parse, #copy_anchor, #copy_anchors, #cut_to, #dbg, #debug?, #find_calculated_h, #fixate, #flip, #flipc, #get_children, #get_contents, #ghost, #has_explicit_color?, #hide, #hl, #inherit_color, #init, #is_2d?, #is_3d?, #mhx, #mhy, #mhz, #mirror, #mix, #miy, #miz, #modify_values, #modify_values!, #move, #movea, #moveai, #moveh, #movei, #multmatrix, #mx, #my, #mz, #on_top_of, #only, #only_color?, #openscad, #openscad_modifier, #option, #parse_xyz_shortcuts, #radians, #referenced_z, #reset, #reset_last_move, #rotate, #rotate_around, #rx, #ry, #rz, #scale, #set_anchor, #set_anchor_from, #set_auto_color, #set_auto_color_for_children, #set_flag, #set_heights_for_auto_extrude, #set_option, #set_parent, #skew, #to_mod, #top_of, #transform, #unset_flag, #z, #z=, #z_margin

Constructor Details

#initialize(args) ⇒ Text

Returns a new instance of Text.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jenncad/primitives/text.rb', line 5

def initialize(args)
  @text = args[:text]
  @size = args[:size]
  @font = args[:font]
  @valign = args[:valign]
  @halign = args[:halign]
  @spacing = args[:spacing]
  @script = args[:script]
  @direction = parse_dir(args[:dir] || args[:direction])
  case @direction
    when "btt", "ttb"
      @valign ||= :top
      @halign ||= :left
  end

  @language = args[:language]
  @fn = args[:fn]

  init(args)
end

Instance Attribute Details

#directionObject

Returns the value of attribute direction.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def direction
  @direction
end

#fnObject

Returns the value of attribute fn.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def fn
  @fn
end

#fontObject

Returns the value of attribute font.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def font
  @font
end

#halignObject

Returns the value of attribute halign.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def halign
  @halign
end

#languageObject

Returns the value of attribute language.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def language
  @language
end

#scriptObject

Returns the value of attribute script.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def script
  @script
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def size
  @size
end

#spacingObject

Returns the value of attribute spacing.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def spacing
  @spacing
end

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def text
  @text
end

#valignObject

Returns the value of attribute valign.



3
4
5
# File 'lib/jenncad/primitives/text.rb', line 3

def valign
  @valign
end

Instance Method Details

#openscad_paramsObject



41
42
43
44
45
46
47
# File 'lib/jenncad/primitives/text.rb', line 41

def openscad_params
  res = {}
  [:text, :font, :valign, :halign, :size, :spacing, :script, :direction, :language, :fn].each do |n|
    res[n] = self.send n
  end
  res
end

#parse_dir(dir) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jenncad/primitives/text.rb', line 26

def parse_dir(dir)
  case dir.to_s
    when "x", "ltr"
      "ltr"
    when "-x", "xn", "nx", "xi", "rtl"
      "rtl"
    when "y", "btt"
      "btt"
    when "-y", "yn", "ny", "yi", "ttb"
      "ttb"
    else
      nil
  end
end