Class: FreeType::API::Outline
- Inherits:
-
Object
- Object
- FreeType::API::Outline
show all
- Includes:
- C
- Defined in:
- lib/freetype/api.rb
Constant Summary
Constants included
from C
C::FT_ENC_TAG, C::FT_Encoding, C::FT_Glyph_Format, C::FT_IMAGE_TAG, C::FT_Kerning_Mode, C::FT_LOAD_COLOR, C::FT_LOAD_COMPUTE_METRICS, C::FT_LOAD_CROP_BITMAP, C::FT_LOAD_DEFAULT, C::FT_LOAD_FORCE_AUTOHINT, C::FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH, C::FT_LOAD_IGNORE_TRANSFORM, C::FT_LOAD_LINEAR_DESIGN, C::FT_LOAD_MONOCHROME, C::FT_LOAD_NO_AUTOHINT, C::FT_LOAD_NO_BITMAP, C::FT_LOAD_NO_HINTING, C::FT_LOAD_NO_RECURSE, C::FT_LOAD_NO_SCALE, C::FT_LOAD_PEDANTIC, C::FT_LOAD_RENDER, C::FT_LOAD_VERTICAL_LAYOUT
Instance Method Summary
collapse
#attach_function
Constructor Details
#initialize(outline) ⇒ Outline
Returns a new instance of Outline.
181
182
183
|
# File 'lib/freetype/api.rb', line 181
def initialize(outline)
@outline = outline
end
|
Instance Method Details
#[](key) ⇒ Object
185
186
187
|
# File 'lib/freetype/api.rb', line 185
def [](key)
@outline[key]
end
|
#contours ⇒ Object
198
199
200
201
|
# File 'lib/freetype/api.rb', line 198
def contours
return [] if @outline[:n_contours] == 0
@outline[:contours].get_array_of_short(0, @outline[:n_contours])
end
|
#points ⇒ Object
189
190
191
192
193
194
195
196
|
# File 'lib/freetype/api.rb', line 189
def points
points = @outline[:n_points].times.map do |i|
FT_Vector.new(@outline[:points] + i * FT_Vector.size)
end
points.zip(tags).map do |(point, tag)|
Point.new(tag, point[:x], point[:y])
end
end
|
#svg_path_data ⇒ Object
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/freetype/api.rb', line 208
def svg_path_data
commands = []
outline_funcs = FreeType::C::FT_Outline_Funcs.new
outline_funcs[:move_to] = proc do |to|
commands << [:M, to[:x], -to[:y]]
0
end
outline_funcs[:line_to] = proc do |to|
commands << [:L, to[:x], -to[:y]]
0
end
outline_funcs[:conic_to] = proc do |ctrl, to|
commands << [:Q, ctrl[:x], -ctrl[:y], to[:x], -to[:y]]
0
end
outline_funcs[:cubic_to] = proc do |ctrl1, ctrl2, to|
commands << [:C, ctrl1[:x], -ctrl1[:y], ctrl2[:x], -ctrl2[:y], to[:x], -to[:y]]
0
end
err = FreeType::C::FT_Outline_Decompose(@outline, outline_funcs, nil)
if err != 0
raise FreeType::Error.find(err)
end
commands << [:Z] if commands.empty?.!
commands
end
|
203
204
205
206
|
# File 'lib/freetype/api.rb', line 203
def tags
return [] if @outline[:n_points] == 0
@outline[:tags].get_array_of_char(0, @outline[:n_points])
end
|