Class: HarfBuzz::ShapingResult
- Inherits:
-
Object
- Object
- HarfBuzz::ShapingResult
- Includes:
- Enumerable
- Defined in:
- lib/harfbuzz/shaping_result.rb
Overview
Value object returned by HarfBuzz.shape_text — provides convenient access to shaped glyphs, positions, and rendering helpers.
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#font ⇒ Object
readonly
Returns the value of attribute font.
Instance Method Summary collapse
-
#each ⇒ Object
Iterates over [GlyphInfo, GlyphPosition] pairs.
-
#glyph_infos ⇒ Array<GlyphInfo>
Glyph info array.
-
#glyph_positions ⇒ Array<GlyphPosition>
Glyph position array.
-
#initialize(buffer:, font:) ⇒ ShapingResult
constructor
A new instance of ShapingResult.
- #inspect ⇒ Object
-
#length ⇒ Integer
(also: #size)
Number of glyphs.
-
#to_svg_path ⇒ String
Generates an SVG path string for all glyphs at their shaped positions.
-
#total_advance ⇒ Array<Integer>
Returns the total advance as [x_advance, y_advance].
Constructor Details
#initialize(buffer:, font:) ⇒ ShapingResult
Returns a new instance of ShapingResult.
13 14 15 16 17 18 |
# File 'lib/harfbuzz/shaping_result.rb', line 13 def initialize(buffer:, font:) @buffer = buffer @font = font @glyph_infos = buffer.glyph_infos @glyph_positions = buffer.glyph_positions end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
9 10 11 |
# File 'lib/harfbuzz/shaping_result.rb', line 9 def buffer @buffer end |
#font ⇒ Object (readonly)
Returns the value of attribute font.
9 10 11 |
# File 'lib/harfbuzz/shaping_result.rb', line 9 def font @font end |
Instance Method Details
#each ⇒ Object
Iterates over [GlyphInfo, GlyphPosition] pairs
31 32 33 |
# File 'lib/harfbuzz/shaping_result.rb', line 31 def each @glyph_infos.zip(@glyph_positions).each { |info, pos| yield info, pos } end |
#glyph_infos ⇒ Array<GlyphInfo>
Returns Glyph info array.
21 22 23 |
# File 'lib/harfbuzz/shaping_result.rb', line 21 def glyph_infos @glyph_infos end |
#glyph_positions ⇒ Array<GlyphPosition>
Returns Glyph position array.
26 27 28 |
# File 'lib/harfbuzz/shaping_result.rb', line 26 def glyph_positions @glyph_positions end |
#inspect ⇒ Object
67 68 69 |
# File 'lib/harfbuzz/shaping_result.rb', line 67 def inspect "#<HarfBuzz::ShapingResult length=#{length} total_advance=#{total_advance.inspect}>" end |
#length ⇒ Integer Also known as: size
Returns Number of glyphs.
36 37 38 |
# File 'lib/harfbuzz/shaping_result.rb', line 36 def length @glyph_infos.length end |
#to_svg_path ⇒ String
Generates an SVG path string for all glyphs at their shaped positions
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/harfbuzz/shaping_result.rb', line 52 def to_svg_path paths = [] cx = 0 cy = 0 each do |info, pos| glyph_path = extract_glyph_path(info.glyph_id) ox = cx + pos.x_offset oy = cy + pos.y_offset paths << translate_path(glyph_path, ox, oy) unless glyph_path.empty? cx += pos.x_advance cy += pos.y_advance end paths.join(" ") end |
#total_advance ⇒ Array<Integer>
Returns the total advance as [x_advance, y_advance]
44 45 46 47 48 |
# File 'lib/harfbuzz/shaping_result.rb', line 44 def total_advance @glyph_positions.inject([0, 0]) do |(x, y), pos| [x + pos.x_advance, y + pos.y_advance] end end |