class FreeType::API::Outline

Public Class Methods

new(outline) click to toggle source
# File lib/freetype/api.rb, line 181
def initialize(outline)
  @outline = outline
end

Public Instance Methods

[](key) click to toggle source
# File lib/freetype/api.rb, line 185
def [](key)
  @outline[key]
end
contours() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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
tags() click to toggle source
# 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