Class: Text

Inherits:
Object
  • Object
show all
Includes:
Magick
Defined in:
lib/openscad-text/text.rb

Overview

Represents a Text with a font

Constant Summary collapse

FONT_DIRECTORIES =
["/usr/share/fonts"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#drawObject (readonly)

Returns the value of attribute draw.



7
8
9
# File 'lib/openscad-text/text.rb', line 7

def draw
  @draw
end

Class Method Details

.available_fontsObject

def debug_output

  out = @paths.map.with_index do |chain,i|
    s = ""
    s << '# ' if i != 0

    chain.each { |p_i| s << "translate(#{@points[p_i].to_s}) cube(1);\n" }
    s
  end

  out.each { |o| puts o, "/"*30 }
  exit
end


184
185
186
187
188
# File 'lib/openscad-text/text.rb', line 184

def self.available_fonts
  FONT_DIRECTORIES.map do |dir|
    Dir[dir + "/**/*.ttf"]
  end.flatten!
end

Instance Method Details

#to_openscadObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/openscad-text/text.rb', line 149

def to_openscad
  @points = []
  @paths  = []

  # draw an image of the text and create a matrix from its pixels
  @matrix = create_image.pixel_matrix

  # go through each point aka pixel to make sure it gets used once
  # and try to retrace the letters
  @matrix.each_with_index do |_,x,y|
    create_pixel_chain(Vector[x,y])
  end

  # align them!
  align_points

  # finished woop woop
  "polygon(points=#{@points.map(&:to_a).to_s}, paths=#{@paths.to_s});"
end