Class: Fontisan::Subset::TableStrategy::ColorBitmapSubsetter

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/subset/table_strategy/color_bitmap_subsetter.rb

Overview

Paired CBDT + CBLC subsetter.

CBDT (Color Bitmap Data) and CBLC (Color Bitmap Location) are tightly coupled: CBLC indexes glyph IDs to CBDT byte offsets, and CBDT is just a blob of bitmap blocks. Subsetting requires walking both at once — filtering to subset GIDs, copying the retained bitmap blocks into a fresh CBDT, and rewriting CBLC's IndexSubTable offsets to match.

Both the Cbdt and Cblc strategies call into this collaborator, which performs the work once and caches both byte strings. This keeps the strategies themselves trivial and avoids forcing the TableSubsetter to know about CBDT/CBLC ordering.

The output CBLC keeps the source BitmapSize records verbatim (ppem, metrics, glyph_range) and rewrites each IndexSubTable's imageDataOffset and offset array to point into the new CBDT. Glyph IDs are remapped via the supplied [GlyphMapping] so the subset's CBLC references subset GIDs, not source GIDs.

Output IndexSubTables always use format 1 (uint32 offsets) — it has no alignment requirement, so arbitrary bitmap block sizes from the source work without padding.

Reference: OpenType CBDT/CBLC specifications.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(font:, mapping:) ⇒ ColorBitmapSubsetter

Returns a new instance of ColorBitmapSubsetter.

Parameters:



40
41
42
43
44
45
# File 'lib/fontisan/subset/table_strategy/color_bitmap_subsetter.rb', line 40

def initialize(font:, mapping:)
  @font = font
  @mapping = mapping
  @cbdt_bytes = +""
  @cblc_bytes = +""
end

Instance Attribute Details

#cbdt_bytesString (readonly)

Returns new CBDT bytes (header + retained blocks).

Returns:

  • (String)

    new CBDT bytes (header + retained blocks)



33
34
35
# File 'lib/fontisan/subset/table_strategy/color_bitmap_subsetter.rb', line 33

def cbdt_bytes
  @cbdt_bytes
end

#cblc_bytesString (readonly)

Returns new CBLC bytes (header + BitmapSize + ISTA + IST).

Returns:

  • (String)

    new CBLC bytes (header + BitmapSize + ISTA + IST)



36
37
38
# File 'lib/fontisan/subset/table_strategy/color_bitmap_subsetter.rb', line 36

def cblc_bytes
  @cblc_bytes
end

Instance Method Details

#buildself

Build the subset CBDT + CBLC bytes. Idempotent.

Returns:

  • (self)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fontisan/subset/table_strategy/color_bitmap_subsetter.rb', line 50

def build
  return self if @built

  source_cblc = @font.table_data["CBLC"]
  source_cbdt = @font.table_data["CBDT"]

  if source_cblc.nil? || source_cbdt.nil?
    @built = true
    return self
  end

  cblc = Tables::Cblc.read(source_cblc)
  cbdt = Tables::Cbdt.read(source_cbdt)

  plan = ColorBitmapSubsetPlan.new(@mapping)
  plan.collect!(cblc)

  emit_cbdt(cbdt, plan)
  emit_cblc(cblc, plan)

  @built = true
  self
end