class Phew::Font

Font family. Handles coverage, among other things.

Public Class Methods

new(context, text_description) click to toggle source

Initialize the font from a text description. The text description should be in the format accepted by Pango::FontDescription.from_string.

@param [Pango::Context] context Pango context to retrieve font from. @param [String] text_description Description of the font to create.

# 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

Public Instance Methods

coverage_summary(text) click to toggle source

Summarize coverage of the given text by the glyphs in the font.

@return A hash with keys :none, :fallback, :approximate, :exact, and values

indicating the number of characters in the text that have that coverage.
# 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 }
  Hash[
    Pango::CoverageLevel::Enum.symbols.map { |lvl| [lvl, text_cov.count(lvl)] }]
end