Class: Okab::Font
- Inherits:
-
Object
- Object
- Okab::Font
- Defined in:
- lib/okab/font.rb,
sig/okab.rbs
Instance Attribute Summary collapse
-
#face ⇒ Alhena::Font
readonly
Returns the value of attribute face.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(face) ⇒ Font
constructor
A new instance of Font.
- #measure(text, size:) ⇒ Float
Constructor Details
#initialize(face) ⇒ Font
Returns a new instance of Font.
12 13 14 15 16 |
# File 'lib/okab/font.rb', line 12 def initialize(face) raise ArgumentError, "expected an Alhena::Font" unless face.is_a?(Alhena::Font) @face = face end |
Instance Attribute Details
#face ⇒ Alhena::Font (readonly)
Returns the value of attribute face.
7 8 9 |
# File 'lib/okab/font.rb', line 7 def face @face end |
Class Method Details
.embed(document, font, subset: true) ⇒ EmbeddedFont
10 |
# File 'lib/okab/font.rb', line 10 def self.(document, font, subset: true) = document.(font, subset: subset) |
.load(path) ⇒ Font
9 |
# File 'lib/okab/font.rb', line 9 def self.load(path) = new(Alhena::Font.open(path)) |
Instance Method Details
#measure(text, size:) ⇒ Float
18 19 20 21 22 23 |
# File 'lib/okab/font.rb', line 18 def measure(text, size:) raise ArgumentError, "text must be valid UTF-8" unless text.is_a?(String) && text.encoding == Encoding::UTF_8 && text.valid_encoding? raise ArgumentError, "size must be finite and positive" unless size.is_a?(Numeric) && size.finite? && size.positive? @face.glyph_ids(text).sum { |glyph| @face.advance_width(glyph) } * size.to_f / @face.units_per_em end |