Class: Fontisan::Export::TableSerializer
- Inherits:
-
Object
- Object
- Fontisan::Export::TableSerializer
- Defined in:
- lib/fontisan/export/table_serializer.rb
Overview
TableSerializer handles serialization of individual font tables
Uses strategy pattern to serialize different table types:
-
Fully parsed tables: Use Lutaml::Model serialization
-
Binary tables: Encode as hex or base64
-
Special tables: Custom serialization logic
Constant Summary collapse
- FULLY_PARSED_TABLES =
Tables that have full Lutaml::Model parsing support
%w[ head hhea maxp post OS/2 name fvar HVAR VVAR MVAR cvar gvar ].freeze
- BINARY_ONLY_TABLES =
Tables that should be stored as binary
%w[ cvt fpgm prep gasp DSIG GDEF GPOS GSUB ].freeze
Instance Method Summary collapse
-
#initialize(binary_format: :hex) ⇒ TableSerializer
constructor
Initialize table serializer.
-
#serialize(table, tag) ⇒ Hash
Serialize a table to exportable format.
-
#serialize_binary(data, tag) ⇒ Hash
Serialize a binary-only table.
-
#serialize_mixed(table, tag) ⇒ Hash
Serialize tables with mixed content (summary + binary).
-
#serialize_parsed(table, tag) ⇒ Hash
Serialize a parsed table.
Constructor Details
#initialize(binary_format: :hex) ⇒ TableSerializer
Initialize table serializer
36 37 38 39 |
# File 'lib/fontisan/export/table_serializer.rb', line 36 def initialize(binary_format: :hex) @binary_format = binary_format validate_binary_format! end |
Instance Method Details
#serialize(table, tag) ⇒ Hash
Serialize a table to exportable format
46 47 48 49 50 51 52 53 54 |
# File 'lib/fontisan/export/table_serializer.rb', line 46 def serialize(table, tag) if fully_parsed?(tag) serialize_parsed(table, tag) elsif binary_only?(tag) serialize_binary(table.to_binary_s, tag) else serialize_mixed(table, tag) end end |
#serialize_binary(data, tag) ⇒ Hash
Serialize a binary-only table
76 77 78 79 80 81 82 83 84 |
# File 'lib/fontisan/export/table_serializer.rb', line 76 def serialize_binary(data, tag) encoded = encode_binary(data) { tag: tag, parsed: false, data: encoded, fields: nil, } end |
#serialize_mixed(table, tag) ⇒ Hash
Serialize tables with mixed content (summary + binary)
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/fontisan/export/table_serializer.rb', line 91 def serialize_mixed(table, tag) summary = create_summary(table, tag) binary = table.respond_to?(:to_binary_s) ? table.to_binary_s : "" { tag: tag, parsed: true, fields: summary.to_json, data: encode_binary(binary), } end |
#serialize_parsed(table, tag) ⇒ Hash
Serialize a parsed table
61 62 63 64 65 66 67 68 69 |
# File 'lib/fontisan/export/table_serializer.rb', line 61 def serialize_parsed(table, tag) fields = extract_fields(table) { tag: tag, parsed: true, fields: fields.to_json, data: nil, } end |