Class: Fontisan::Tables::Cff2
- Inherits:
-
Binary::BaseRecord
- Object
- BinData::Record
- Binary::BaseRecord
- Fontisan::Tables::Cff2
- 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
Defined Under Namespace
Classes: BlendOperator, Cff2Header, CharstringParser, OperandStack, PrivateDictBlendHandler, RegionMatcher, TableBuilder, TableReader, VariationDataExtractor
Instance Method Summary collapse
-
#charstring_for_glyph(glyph_id) ⇒ CharstringParser?
Get CharString for a specific glyph.
-
#charstrings ⇒ Array<CharstringParser>
Get all CharStrings.
-
#glyph_count ⇒ Integer
Get glyph count from font's maxp table.
-
#glyph_count=(count) ⇒ Object
Set glyph count (from maxp table).
-
#header ⇒ Cff2Header
Get the CFF2 header.
-
#num_axes ⇒ Integer
Get number of variation axes.
-
#num_axes=(count) ⇒ Object
Set number of variation axes (from fvar table).
-
#parse ⇒ self
Parse the CFF2 table.
-
#valid? ⇒ Boolean
Check if table is valid.
Methods inherited from Binary::BaseRecord
Instance Method Details
#charstring_for_glyph(glyph_id) ⇒ CharstringParser?
Get CharString for a specific glyph
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 |
#charstrings ⇒ Array<CharstringParser>
Get all CharStrings
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_count ⇒ Integer
Get glyph count from font's maxp table
CFF2 doesn't store glyph count internally - it relies on the maxp table
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)
88 89 90 |
# File 'lib/fontisan/tables/cff2.rb', line 88 def glyph_count=(count) @glyph_count = count end |
#header ⇒ Cff2Header
Get the CFF2 header
69 70 71 72 |
# File 'lib/fontisan/tables/cff2.rb', line 69 def header parse unless @parsed @header end |
#num_axes ⇒ Integer
Get number of variation 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)
95 96 97 |
# File 'lib/fontisan/tables/cff2.rb', line 95 def num_axes=(count) @num_axes = count end |
#parse ⇒ self
Parse the CFF2 table
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
143 144 145 |
# File 'lib/fontisan/tables/cff2.rb', line 143 def valid? header.valid? end |