Module: PixelFontTrieOCR::FontMetadata
- Included in:
- PixelFontTrieOCR
- Defined in:
- lib/pixel_font_trie_ocr/font_metadata.rb
Constant Summary collapse
- DEFAULT_FONT_NAME =
"hex-synergy_font.ttf"
Instance Attribute Summary collapse
Instance Method Summary collapse
- #alphanumeric ⇒ Object
- #ascent ⇒ Object
- #ascent_ratio ⇒ Object
- #character_count ⇒ Object
- #characters ⇒ Object
- #code_map ⇒ Object
- #descent ⇒ Object
- #digits ⇒ Object
- #family ⇒ Object
- #font ⇒ Object
- #font_dir ⇒ Object
- #font_dir=(value) ⇒ Object
- #font_map ⇒ Object
- #font_path ⇒ Object
- #height ⇒ Object
- #lowercase ⇒ Object
- #postscript_name ⇒ Object
- #subfamily ⇒ Object
- #symbols ⇒ Object
- #units_per_em ⇒ Object
- #uppercase ⇒ Object
- #whitespace ⇒ Object
Instance Attribute Details
#font_name ⇒ Object
10 11 12 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 10 def font_name @font_name ||= DEFAULT_FONT_NAME end |
#font_size ⇒ Object
26 27 28 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 26 def font_size @font_size ||= 8 end |
Instance Method Details
#alphanumeric ⇒ Object
98 99 100 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 98 def alphanumeric @alphanumeric ||= uppercase | lowercase | digits end |
#ascent ⇒ Object
66 67 68 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 66 def ascent @ascent ||= font.os2.ascent end |
#ascent_ratio ⇒ Object
78 79 80 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 78 def ascent_ratio @ascent_ratio ||= ascent / units_per_em.to_f end |
#character_count ⇒ Object
62 63 64 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 62 def character_count @character_count ||= characters.size end |
#characters ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 42 def characters @characters ||= Set.new( code_map.filter_map do |key, value| value.positive? && key > 31 && [key].pack("U") end ) end |
#code_map ⇒ Object
38 39 40 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 38 def code_map @code_map ||= font_map.respond_to?(:code_map) ? font_map.code_map : {} end |
#descent ⇒ Object
70 71 72 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 70 def descent @descent ||= font.os2.descent end |
#digits ⇒ Object
94 95 96 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 94 def digits @digits ||= Set.new("0".."9") end |
#family ⇒ Object
50 51 52 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 50 def family @family ||= font.name.font_name end |
#font ⇒ Object
30 31 32 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 30 def font @font ||= TTFunk::File.open(font_path) end |
#font_dir ⇒ Object
18 19 20 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 18 def font_dir @font_dir ||= Pathname.new(__dir__).join("fonts") end |
#font_dir=(value) ⇒ Object
14 15 16 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 14 def font_dir=(value) @font_dir = Pathname.new(value) end |
#font_map ⇒ Object
34 35 36 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 34 def font_map @font_map ||= font.cmap.unicode.first end |
#font_path ⇒ Object
22 23 24 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 22 def font_path @font_path ||= font_dir.join(font_name).to_s end |
#height ⇒ Object
82 83 84 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 82 def height @height ||= (ascent_ratio * font_size).ceil end |
#lowercase ⇒ Object
90 91 92 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 90 def lowercase @lowercase ||= Set.new("a".."z") end |
#postscript_name ⇒ Object
58 59 60 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 58 def postscript_name @postscript_name ||= font.name.postscript_name end |
#subfamily ⇒ Object
54 55 56 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 54 def subfamily @subfamily ||= font.name.font_subfamily end |
#symbols ⇒ Object
106 107 108 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 106 def symbols @symbols ||= characters - alphanumeric - whitespace end |
#units_per_em ⇒ Object
74 75 76 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 74 def units_per_em @units_per_em ||= font.header.units_per_em end |
#uppercase ⇒ Object
86 87 88 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 86 def uppercase @uppercase ||= Set.new("A".."Z") end |
#whitespace ⇒ Object
102 103 104 |
# File 'lib/pixel_font_trie_ocr/font_metadata.rb', line 102 def whitespace Set.new([" ", "\r", "\n", "\t"]) end |