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
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fontisan/tables/cff2.rb', line 98 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 require_relative "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
121 122 123 124 125 126 127 |
# File 'lib/fontisan/tables/cff2.rb', line 121 def charstrings return [] unless @charstrings_index @charstrings_index.count.times.map 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
67 68 69 70 71 |
# File 'lib/fontisan/tables/cff2.rb', line 67 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)
76 77 78 |
# File 'lib/fontisan/tables/cff2.rb', line 76 def glyph_count=(count) @glyph_count = count end |
#header ⇒ Cff2Header
Get the CFF2 header
57 58 59 60 |
# File 'lib/fontisan/tables/cff2.rb', line 57 def header parse unless @parsed @header end |
#num_axes ⇒ Integer
Get number of variation axes
90 91 92 |
# File 'lib/fontisan/tables/cff2.rb', line 90 def num_axes @num_axes || 0 end |
#num_axes=(count) ⇒ Object
Set number of variation axes (from fvar table)
83 84 85 |
# File 'lib/fontisan/tables/cff2.rb', line 83 def num_axes=(count) @num_axes = count end |
#parse ⇒ self
Parse the CFF2 table
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fontisan/tables/cff2.rb', line 42 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
132 133 134 |
# File 'lib/fontisan/tables/cff2.rb', line 132 def valid? header.valid? end |