Class: GlyphImager::FontRecord

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

Constant Summary collapse

@@metadata_ids =
%w[
  copyright
  font_family
  font_subfamily
  unique_subfamily
  font_name
  version
  trademark
  manufacturer
  designer
  description
  vendor_url
  designer_url
  license
  license_url
  preferred_family
  preferred_subfamily
  compatible_full
  sample_text
]

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FontRecord

Returns a new instance of FontRecord.



51
52
53
# File 'lib/glyph_imager.rb', line 51

def initialize(filename)
  @font = TTFunk::File.open(filename)
end

Instance Method Details

#control_character_pointsObject



68
69
70
71
72
73
# File 'lib/glyph_imager.rb', line 68

def control_character_points
  return @control_character_points if @control_character_points
  @control_character_points = 0.upto(31).collect {|i| ("%04x" % i).upcase }
  @control_character_points << "007F"
  @control_character_points += 128.upto(159).collect { |i| ("%04x" % i).upcase }
end

#fontObject



55
56
57
# File 'lib/glyph_imager.rb', line 55

def font
  @font
end

#has_glyph_for_unicode_char?(code_point) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
# File 'lib/glyph_imager.rb', line 59

def has_glyph_for_unicode_char?(code_point)
  return false if control_character_points.include?(code_point) 
  if format12 = font.cmap.unicode.detect { |t| t.format == 12 }
    format12[code_point.hex] != 0
  elsif format4 = font.cmap.unicode.detect { |t| t.format == 4 }
    format4[code_point.hex] != 0
  end
end