Class: Fontisan::Tables::Cff2

Inherits:
Binary::BaseRecord show all
Defined in:
lib/fontisan/tables/cff2.rb,
lib/fontisan/tables/cff2/table_reader.rb,
lib/fontisan/tables/cff2/operand_stack.rb,
lib/fontisan/tables/cff2/table_builder.rb,
lib/fontisan/tables/cff2/blend_operator.rb,
lib/fontisan/tables/cff2/region_matcher.rb,
lib/fontisan/tables/cff2/charstring_parser.rb,
lib/fontisan/tables/cff2/variation_data_extractor.rb,
lib/fontisan/tables/cff2/private_dict_blend_handler.rb

Overview

Parser for the 'CFF2' (Compact Font Format 2) table

CFF2 is used primarily in variable fonts with PostScript outlines. Key differences from CFF:

  • No Name INDEX (font names come from name table)
  • No Encoding or Charset (use cmap table instead)
  • Support for blend operators in CharStrings for variations
  • Different default values in DICTs

Reference: Adobe Technical Note #5177

Examples:

Reading a CFF2 table

data = font.table_data("CFF2")
cff2 = Fontisan::Tables::Cff2.read(data)
num_glyphs = cff2.glyph_count

Defined Under Namespace

Classes: BlendOperator, Cff2Header, CharstringParser, OperandStack, PrivateDictBlendHandler, RegionMatcher, TableBuilder, TableReader, VariationDataExtractor

Instance Method Summary collapse

Methods inherited from Binary::BaseRecord

#raw_data, read

Instance Method Details

#charstring_for_glyph(glyph_id) ⇒ CharstringParser?

Get CharString for a specific glyph

Parameters:

  • glyph_id (Integer)

    Glyph ID

Returns:



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/fontisan/tables/cff2.rb', line 110

def charstring_for_glyph(glyph_id)
  parse unless @parsed
  return nil if @charstrings_index.nil?
  return nil if glyph_id >= @charstrings_index.count

  # Get CharString data from INDEX
  charstring_data = @charstrings_index[glyph_id]
  return nil if charstring_data.nil?

  # Parse with CFF2 CharString parser
  CharstringParser.new(
    charstring_data,
    @num_axes,
    @global_subr_index,
    nil, # local subrs (CFF2 may not have them)
    0, # vsindex
  ).parse
end

#charstringsArray<CharstringParser>

Get all CharStrings

Returns:



132
133
134
135
136
137
138
# File 'lib/fontisan/tables/cff2.rb', line 132

def charstrings
  return [] unless @charstrings_index

  Array.new(@charstrings_index.count) do |glyph_id|
    charstring_for_glyph(glyph_id)
  end.compact
end

#glyph_countInteger

Get glyph count from font's maxp table

CFF2 doesn't store glyph count internally - it relies on the maxp table

Returns:

  • (Integer)

    Number of glyphs (requires access to font's maxp)



79
80
81
82
83
# File 'lib/fontisan/tables/cff2.rb', line 79

def glyph_count
  # This needs to be set externally or retrieved from maxp table
  # For now, return a default that indicates it needs to be set
  @glyph_count || 0
end

#glyph_count=(count) ⇒ Object

Set glyph count (from maxp table)

Parameters:

  • count (Integer)

    Number of glyphs



88
89
90
# File 'lib/fontisan/tables/cff2.rb', line 88

def glyph_count=(count)
  @glyph_count = count
end

#headerCff2Header

Get the CFF2 header

Returns:



69
70
71
72
# File 'lib/fontisan/tables/cff2.rb', line 69

def header
  parse unless @parsed
  @header
end

#num_axesInteger

Get number of variation axes

Returns:

  • (Integer)

    Number of axes



102
103
104
# File 'lib/fontisan/tables/cff2.rb', line 102

def num_axes
  @num_axes || 0
end

#num_axes=(count) ⇒ Object

Set number of variation axes (from fvar table)

Parameters:

  • count (Integer)

    Number of axes



95
96
97
# File 'lib/fontisan/tables/cff2.rb', line 95

def num_axes=(count)
  @num_axes = count
end

#parseself

Parse the CFF2 table

Returns:

  • (self)


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fontisan/tables/cff2.rb', line 54

def parse
  return self if @parsed

  @header = parse_header
  @global_subr_index = parse_global_subr_index
  @top_dict = parse_top_dict
  @charstrings_index = parse_charstrings_index

  @parsed = true
  self
end

#valid?Boolean

Check if table is valid

Returns:

  • (Boolean)

    True if valid CFF2 table



143
144
145
# File 'lib/fontisan/tables/cff2.rb', line 143

def valid?
  header.valid?
end