Class: Idml::TextEngine::Shaper
- Inherits:
-
Object
- Object
- Idml::TextEngine::Shaper
- Defined in:
- lib/idml/text_engine/shaper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(font, size) ⇒ Shaper
constructor
A new instance of Shaper.
- #measure(glyphs) ⇒ Object
- #shape(text) ⇒ Object
Constructor Details
#initialize(font, size) ⇒ Shaper
Returns a new instance of Shaper.
14 15 16 17 18 |
# File 'lib/idml/text_engine/shaper.rb', line 14 def initialize(font, size) @font = font @size = size @scale = size.to_f / font.units_per_em end |
Class Method Details
.shape(text:, font:, size:) ⇒ Object
10 11 12 |
# File 'lib/idml/text_engine/shaper.rb', line 10 def self.shape(text:, font:, size:) new(font, size).shape(text) end |
Instance Method Details
#measure(glyphs) ⇒ Object
30 31 32 |
# File 'lib/idml/text_engine/shaper.rb', line 30 def measure(glyphs) glyphs.sum(&:width) end |
#shape(text) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/idml/text_engine/shaper.rb', line 20 def shape(text) glyphs = [] text.each_codepoint do |cp| raw_width = @font.glyph_width(cp) width = raw_width * @scale glyphs << ShapedGlyph.new(cp, width, cp == 32) end glyphs end |