Module: Fontisan::OpenTypeFontExtensions
- Included in:
- OpenTypeFont
- Defined in:
- lib/fontisan/open_type_font_extensions.rb
Overview
Extension module for OpenTypeFont providing table-based construction.
Extended into OpenTypeFont from open_type_font.rb so that
OpenTypeFont.from_tables(...) is available whenever the class
itself is loaded.
Instance Method Summary collapse
-
#from_tables(tables) ⇒ OpenTypeFont
Create font from hash of tables.
Instance Method Details
#from_tables(tables) ⇒ OpenTypeFont
Create font from hash of tables
This is used during font conversion when we have tables but not a file.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fontisan/open_type_font_extensions.rb', line 16 def from_tables(tables) font = new font.initialize_storage font.loading_mode = LoadingModes::FULL font.table_data = tables num_tables = tables.size max_power = 0 n = num_tables while n > 1 n >>= 1 max_power += 1 end search_range = (1 << max_power) * 16 entry_selector = max_power range_shift = (num_tables * 16) - search_range font.header.sfnt_version = 0x4F54544F # 'OTTO' for OpenType/CFF font.header.num_tables = num_tables font.header.search_range = search_range font.header.entry_selector = entry_selector font.header.range_shift = range_shift font.tables.clear tables.each_key do |tag| entry = TableDirectory.new entry.tag = tag entry.checksum = 0 entry.offset = 0 entry.table_length = tables[tag].bytesize font.tables << entry end font end |