Class: Fontisan::Export::TableSerializer
- Inherits:
-
Object
- Object
- Fontisan::Export::TableSerializer
- Defined in:
- lib/fontisan/export/table_serializer.rb
Overview
Serializes individual font tables for export.
Tables fall into three categories:
- Fully parsed: BinData records whose
snapshothash is exported as JSON fields. - Binary-only: opaque blobs encoded as hex or base64.
- Mixed: tables with a small typed summary alongside the binary payload (glyf, loca, cmap, CFF).
All table objects are BinData::Record subclasses; we trust that interface rather than duck-typing each field.
Defined Under Namespace
Modules: CffSummary, CmapSummary, GlyphSummary, LocaSummary
Constant Summary collapse
- FULLY_PARSED_TABLES =
Tables whose BinData fields are exported as JSON.
%w[ head hhea maxp post OS/2 name fvar HVAR VVAR MVAR cvar gvar ].freeze
- BINARY_ONLY_TABLES =
Tables stored as opaque binary with no field extraction.
%w[ cvt fpgm prep gasp DSIG GDEF GPOS GSUB ].freeze
- MIXED_SUMMARIES =
Tables that ship a summary alongside the raw binary.
{ "glyf" => GlyphSummary, "loca" => LocaSummary, "cmap" => CmapSummary, "CFF" => CffSummary, }.freeze
Instance Method Summary collapse
-
#initialize(binary_format: :hex) ⇒ TableSerializer
constructor
A new instance of TableSerializer.
-
#serialize(table, tag) ⇒ Hash
Serialized payload.
- #serialize_binary(data, tag) ⇒ Hash
Constructor Details
#initialize(binary_format: :hex) ⇒ TableSerializer
Returns a new instance of TableSerializer.
40 41 42 43 |
# File 'lib/fontisan/export/table_serializer.rb', line 40 def initialize(binary_format: :hex) @binary_format = binary_format validate_binary_format! end |
Instance Method Details
#serialize(table, tag) ⇒ Hash
Returns serialized payload.
48 49 50 51 52 53 54 55 56 |
# File 'lib/fontisan/export/table_serializer.rb', line 48 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
61 62 63 |
# File 'lib/fontisan/export/table_serializer.rb', line 61 def serialize_binary(data, tag) { tag: tag, parsed: false, data: encode_binary(data), fields: nil } end |