Class: Phew::Font
- Inherits:
-
Object
- Object
- Phew::Font
- Defined in:
- lib/phew/font.rb
Overview
Font family. Handles coverage, among other things.
Instance Method Summary collapse
-
#coverage_summary(text) ⇒ Object
Summarize coverage of the given text by the glyphs in the font.
-
#initialize(context, text_description) ⇒ Font
constructor
Initialize the font from a text description.
Constructor Details
#initialize(context, text_description) ⇒ Font
Initialize the font from a text description. The text description should be in the format accepted by Pango::FontDescription.from_string.
13 14 15 16 17 18 |
# File 'lib/phew/font.rb', line 13 def initialize(context, text_description) fd = Pango::FontDescription.from_string text_description fd.size = 10 fontmap = context.get_font_map @font = fontmap.load_font context, fd end |
Instance Method Details
#coverage_summary(text) ⇒ Object
Summarize coverage of the given text by the glyphs in the font.
24 25 26 27 28 29 |
# File 'lib/phew/font.rb', line 24 def coverage_summary(text) lang = Pango::Language.new cov = @font.get_coverage lang text_cov = text.each_codepoint.map { |cp| cov.get cp } Pango::CoverageLevel::Enum.symbols.to_h { |lvl| [lvl, text_cov.count(lvl)] } end |