Class: Fontisan::Type1::SeacExpander
- Inherits:
-
Object
- Object
- Fontisan::Type1::SeacExpander
- Defined in:
- lib/fontisan/type1/seac_expander.rb
Overview
Expands Type 1 seac composite glyphs into base + accent outlines
SeacExpander handles the
decomposition of Type 1 composite glyphs that use the seac operator.
The seac operator combines two glyphs (a base character and an accent)
with a positioning offset, which must be decomposed for CFF conversion.
The seac operator format is:
seac asb adx ady bchar achar
Where:
asb: Accent side bearing (not used in decomposition)adx: X offset for accent placementady: Y offset for accent placementbchar: Character code of base glyphachar: Character code of accent glyph
Instance Attribute Summary collapse
-
#charstrings ⇒ CharStrings
readonly
Type 1 CharStrings dictionary.
-
#private_dict ⇒ PrivateDict
readonly
Private dictionary for hinting.
Instance Method Summary collapse
-
#composite?(glyph_name) ⇒ Boolean
Check if a glyph is a seac composite.
-
#composite_glyphs ⇒ Array<String>
Get all seac composite glyphs in the font.
-
#decompose(glyph_name) ⇒ String?
Decompose a seac composite glyph into base + accent outlines.
-
#initialize(charstrings, private_dict) ⇒ SeacExpander
constructor
Initialize a new SeacExpander.
Constructor Details
#initialize(charstrings, private_dict) ⇒ SeacExpander
Initialize a new SeacExpander
41 42 43 44 |
# File 'lib/fontisan/type1/seac_expander.rb', line 41 def initialize(charstrings, private_dict) @charstrings = charstrings @private_dict = private_dict end |
Instance Attribute Details
#charstrings ⇒ CharStrings (readonly)
Returns Type 1 CharStrings dictionary.
32 33 34 |
# File 'lib/fontisan/type1/seac_expander.rb', line 32 def charstrings @charstrings end |
#private_dict ⇒ PrivateDict (readonly)
Returns Private dictionary for hinting.
35 36 37 |
# File 'lib/fontisan/type1/seac_expander.rb', line 35 def private_dict @private_dict end |
Instance Method Details
#composite?(glyph_name) ⇒ Boolean
Check if a glyph is a seac composite
113 114 115 |
# File 'lib/fontisan/type1/seac_expander.rb', line 113 def composite?(glyph_name) @charstrings.composite?(glyph_name) end |
#composite_glyphs ⇒ Array<String>
Get all seac composite glyphs in the font
120 121 122 |
# File 'lib/fontisan/type1/seac_expander.rb', line 120 def composite_glyphs @charstrings.glyph_names.select { |name| composite?(name) } end |
#decompose(glyph_name) ⇒ String?
Decompose a seac composite glyph into base + accent outlines
This method:
- Parses the seac operator to extract components
- Gets CharStrings for base and accent glyphs
- Parses both CharStrings into outline commands
- Transforms the accent by (adx, ady) offset
- Merges base and accent outlines into a single path
- Returns the decomposed CharString data
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fontisan/type1/seac_expander.rb', line 62 def decompose(glyph_name) components = @charstrings.components_for(glyph_name) return nil unless components # Use the encoding map to lookup glyph names from character codes base_glyph_name = @charstrings.encoding[components[:base]] accent_glyph_name = @charstrings.encoding[components[:accent]] if base_glyph_name.nil? raise Fontisan::Error, "Base glyph for char code #{components[:base]} not found" end if accent_glyph_name.nil? raise Fontisan::Error, "Accent glyph for char code #{components[:accent]} not found" end # Get CharStrings for base and accent base_charstring = @charstrings[base_glyph_name] accent_charstring = @charstrings[accent_glyph_name] if base_charstring.nil? raise Fontisan::Error, "CharString not found for base glyph #{base_glyph_name}" end if accent_charstring.nil? raise Fontisan::Error, "CharString not found for accent glyph #{accent_glyph_name}" end # Parse both CharStrings into command sequences base_commands = parse_charstring_to_commands(base_charstring) accent_commands = parse_charstring_to_commands(accent_charstring) # Transform accent by (adx, ady) offset accent_commands = transform_commands(accent_commands, components[:adx], components[:ady]) # Merge base and accent commands merged_commands = merge_outline_commands(base_commands, accent_commands) # Convert merged commands back to CharString bytecode generate_charstring(merged_commands) end |