Class: Phew::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/phew/font.rb

Overview

Font family. Handles coverage, among other things.

Instance Method Summary collapse

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.

Parameters:

  • context (Pango::Context)

    Pango context to retrieve font from.

  • text_description (String)

    Description of the font to create.



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.

Returns:

  • A hash with keys :none, :fallback, :approximate, :exact, and values indicating the number of characters in the text that have that coverage.



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