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.
Source Code
19 | def initialize |
20 | @commands = [] |
21 | @number_of_contours = 0 |
22 | end
|
Instance Attribute Details
#commands ⇒ Array (readonly)
Commands in this path.
Source Code
13 | def commands |
14 | @commands
|
15 | end
|
#number_of_contours ⇒ Integer (readonly)
Number of contours in this path.
Source Code
17 | def number_of_contours |
18 | @number_of_contours
|
19 | end
|
Instance Method Details
#close_path ⇒ void
This method returns an undefined value.
Close current contour.
Source Code
60 | def close_path |
61 | @commands << CLOSE_PATH_CMD |
62 | @number_of_contours += 1 |
63 | 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.
Source Code
53 | def curve_to(x1, y1, x2, y2, x, y) # rubocop: disable Metrics/ParameterLists,Style/CommentedKeyword |
54 | @commands << [:curve, x1, y1, x2, y2, x, y] |
55 | end
|
#line_to(x, y) ⇒ void
This method returns an undefined value.
Add a line to coordinates.
Source Code
38 | def line_to(x, y) |
39 | @commands << [:line, x, y] |
40 | end
|
#move_to(x, y) ⇒ void
This method returns an undefined value.
Move implicit cursor to coordinates.
Source Code
29 | def move_to(x, y) |
30 | @commands << [:move, x, y] |
31 | end
|
#render(x: 0, y: 0, font_size: 72, units_per_em: 1000) ⇒ TTFunk::Table::Cff::Path
Reposition and scale path.
Source Code
72 | def render(x: 0, y: 0, font_size: 72, units_per_em: 1000) |
73 | new_path = self.class.new |
74 | scale = 1.0 / units_per_em * font_size |
75 | |
76 | commands.each do |cmd| |
77 | case cmd[:type] |
78 | when :move |
79 | new_path.move_to(x + (cmd[1] * scale), y + (-cmd[2] * scale)) |
80 | when :line |
81 | new_path.line_to(x + (cmd[1] * scale), y + (-cmd[2] * scale)) |
82 | when :curve |
83 | new_path.curve_to( |
84 | x + (cmd[1] * scale), |
85 | y + (-cmd[2] * scale), |
86 | x + (cmd[3] * scale), |
87 | y + (-cmd[4] * scale), |
88 | x + (cmd[5] * scale), |
89 | y + (-cmd[6] * scale), |
90 | )
|
91 | when :close |
92 | new_path.close_path |
93 | end
|
94 | end
|
95 | |
96 | new_path
|
97 | end
|