Class: Fontisan::Woff2::TableTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/woff2/table_transformer.rb

Overview

Table transformer for WOFF2 encoding

Woff2::TableTransformer handles table transformations that improve compression in WOFF2. The WOFF2 spec defines transformations for glyf/loca and hmtx tables.

Transformations implemented:

  • glyf/loca: Combined stream format with specialized encoding
  • hmtx: Delta encoding with 255UInt16 compression

Reference: https://www.w3.org/TR/WOFF2/#table_tranforms

Examples:

Transform tables for WOFF2

transformer = TableTransformer.new(font)
glyf_data = transformer.transform_table("glyf")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(font) ⇒ TableTransformer

Initialize transformer with font

Parameters:



27
28
29
# File 'lib/fontisan/woff2/table_transformer.rb', line 27

def initialize(font)
  @font = font
end

Instance Attribute Details

#fontObject (readonly)

Returns Font object with table access.

Returns:

  • (Object)

    Font object with table access



22
23
24
# File 'lib/fontisan/woff2/table_transformer.rb', line 22

def font
  @font
end

Instance Method Details

#transform_table(tag) ⇒ String?

Transform a table for WOFF2 encoding

Parameters:

  • tag (String)

    Table tag

Returns:

  • (String, nil)

    Transformed table data



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fontisan/woff2/table_transformer.rb', line 35

def transform_table(tag)
  case tag
  when "glyf"
    transform_glyf
  when "loca"
    transform_loca
  when "hmtx"
    transform_hmtx
  else
    # No transformation, return original data
    get_table_data(tag)
  end
end

#transformable?(tag) ⇒ Boolean

Check if a table can be transformed

Parameters:

  • tag (String)

    Table tag

Returns:

  • (Boolean)

    True if table supports transformation



53
54
55
# File 'lib/fontisan/woff2/table_transformer.rb', line 53

def transformable?(tag)
  %w[glyf loca hmtx].include?(tag)
end

#transformation_version(tag) ⇒ Integer

Determine transformation version for a table

Parameters:

  • tag (String)

    Table tag

Returns:

  • (Integer)

    Transformation version



61
62
63
64
65
66
67
68
69
70
# File 'lib/fontisan/woff2/table_transformer.rb', line 61

def transformation_version(tag)
  case tag
  when "glyf", "loca"
    Directory::TRANSFORM_GLYF_LOCA
  when "hmtx"
    Directory::TRANSFORM_HMTX
  else
    Directory::TRANSFORM_NONE
  end
end