Class: TTFunk::Table::Cff::Path
- Inherits:
-
Object
- Object
- TTFunk::Table::Cff::Path
- Defined in:
- lib/ttfunk/table/cff/path.rb
Overview
Path. Mostly used for CFF glyph outlines.
Constant Summary collapse
- CLOSE_PATH_CMD =
Close path command.
[:close].freeze
Instance Attribute Summary collapse
-
#commands ⇒ Array
readonly
Commands in this path.
-
#number_of_contours ⇒ Integer
readonly
Number of contours in this path.
Instance Method Summary collapse
-
#close_path ⇒ void
Close current contour.
-
#curve_to(x1, y1, x2, y2, x, y) ⇒ void
Add a Bézier curve.
-
#initialize ⇒ Path
constructor
A new instance of Path.
-
#line_to(x, y) ⇒ void
Add a line to coordinates.
-
#move_to(x, y) ⇒ void
Move implicit cursor to coordinates.
-
#render(x: 0, y: 0, font_size: 72, units_per_em: 1000) ⇒ TTFunk::Table::Cff::Path
Reposition and scale path.
Constructor Details
#initialize ⇒ Path
Returns a new instance of Path.
19 20 21 22 |
# File 'lib/ttfunk/table/cff/path.rb', line 19 def initialize @commands = [] @number_of_contours = 0 end |
Instance Attribute Details
#commands ⇒ Array (readonly)
Commands in this path.
13 14 15 |
# File 'lib/ttfunk/table/cff/path.rb', line 13 def commands @commands end |
#number_of_contours ⇒ Integer (readonly)
Number of contours in this path.
17 18 19 |
# File 'lib/ttfunk/table/cff/path.rb', line 17 def number_of_contours @number_of_contours end |
Instance Method Details
#close_path ⇒ void
This method returns an undefined value.
Close current contour.
60 61 62 63 |
# File 'lib/ttfunk/table/cff/path.rb', line 60 def close_path @commands << CLOSE_PATH_CMD @number_of_contours += 1 end |
#curve_to(x1, y1, x2, y2, x, y) ⇒ void
This method returns an undefined value.
Add a Bézier curve. Current position is the first control point, (‘x1`, `y1`) is the second, (`x2`, `y2`) is the third, and (`x`, `y`) is the last control point.
53 54 55 |
# File 'lib/ttfunk/table/cff/path.rb', line 53 def curve_to(x1, y1, x2, y2, x, y) # rubocop: disable Metrics/ParameterLists @commands << [:curve, x1, y1, x2, y2, x, y] end |
#line_to(x, y) ⇒ void
This method returns an undefined value.
Add a line to coordinates.
38 39 40 |
# File 'lib/ttfunk/table/cff/path.rb', line 38 def line_to(x, y) @commands << [:line, x, y] end |
#move_to(x, y) ⇒ void
This method returns an undefined value.
Move implicit cursor to coordinates.
29 30 31 |
# File 'lib/ttfunk/table/cff/path.rb', line 29 def move_to(x, y) @commands << [:move, x, y] end |
#render(x: 0, y: 0, font_size: 72, units_per_em: 1000) ⇒ TTFunk::Table::Cff::Path
Reposition and scale path.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ttfunk/table/cff/path.rb', line 72 def render(x: 0, y: 0, font_size: 72, units_per_em: 1000) new_path = self.class.new scale = 1.0 / units_per_em * font_size commands.each do |cmd| case cmd[:type] when :move new_path.move_to(x + (cmd[1] * scale), y + (-cmd[2] * scale)) when :line new_path.line_to(x + (cmd[1] * scale), y + (-cmd[2] * scale)) when :curve new_path.curve_to( x + (cmd[1] * scale), y + (-cmd[2] * scale), x + (cmd[3] * scale), y + (-cmd[4] * scale), x + (cmd[5] * scale), y + (-cmd[6] * scale), ) when :close new_path.close_path end end new_path end |