Class: Fontisan::Tables::Cff::CFFGlyph
- Inherits:
-
Object
- Object
- Fontisan::Tables::Cff::CFFGlyph
- Defined in:
- lib/fontisan/tables/cff/cff_glyph.rb
Overview
Wrapper class for CFF glyph data
CFFGlyph provides a unified
interface for CFF glyphs that matches the API of TrueType glyphs
(SimpleGlyph and
CompoundGlyph).
This allows GlyphAccessor to work
transparently with both TrueType (glyf) and OpenType/CFF fonts.
CFF Glyph Characteristics:
- Always "simple" (no composite structure like TrueType compound glyphs)
- Outline data stored as Type 2 CharString programs
- Width information embedded in CharString
- Glyph names from Charset
Reference: docs/ttfunk-feature-analysis.md:541-575
Instance Attribute Summary collapse
-
#charstring ⇒ CharString
readonly
Interpreted CharString with path data.
-
#glyph_id ⇒ Integer
readonly
Glyph ID (GID).
Instance Method Summary collapse
-
#bounding_box ⇒ Array<Float>?
Get the bounding box for this glyph.
-
#compound? ⇒ Boolean
Check if this is a compound glyph.
-
#empty? ⇒ Boolean
Check if this glyph has no outline data.
-
#initialize(glyph_id, charstring, charset, encoding = nil) ⇒ CFFGlyph
constructor
Initialize a CFF glyph wrapper.
-
#name ⇒ String
Get the PostScript glyph name.
-
#path ⇒ Array<Hash>
Get the raw path data.
-
#simple? ⇒ Boolean
Check if this is a simple glyph.
-
#to_commands ⇒ Array<Array>
Convert the glyph outline to drawing commands.
-
#to_s ⇒ String
(also: #inspect)
String representation for debugging.
-
#width ⇒ Integer?
Get the advance width for this glyph.
Constructor Details
#initialize(glyph_id, charstring, charset, encoding = nil) ⇒ CFFGlyph
Initialize a CFF glyph wrapper
48 49 50 51 52 53 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 48 def initialize(glyph_id, charstring, charset, encoding = nil) @glyph_id = glyph_id @charstring = charstring @charset = charset @encoding = encoding end |
Instance Attribute Details
#charstring ⇒ CharString (readonly)
Returns Interpreted CharString with path data.
39 40 41 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 39 def charstring @charstring end |
#glyph_id ⇒ Integer (readonly)
Returns Glyph ID (GID).
36 37 38 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 36 def glyph_id @glyph_id end |
Instance Method Details
#bounding_box ⇒ Array<Float>?
Get the bounding box for this glyph
Returns the glyph's bounding box in font units as calculated from the CharString path.
94 95 96 97 98 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 94 def bounding_box return nil unless @charstring @charstring.bounding_box end |
#compound? ⇒ Boolean
Check if this is a compound glyph
CFF glyphs don't have components like TrueType compound glyphs.
72 73 74 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 72 def compound? false end |
#empty? ⇒ Boolean
Check if this glyph has no outline data
A glyph is empty if its CharString path is empty (e.g., space character)
82 83 84 85 86 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 82 def empty? return true unless @charstring @charstring.path.empty? end |
#name ⇒ String
Get the PostScript glyph name
Looks up the glyph name from the Charset using the glyph ID.
117 118 119 120 121 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 117 def name return ".notdef" unless @charset @charset.glyph_name(@glyph_id) || ".notdef" end |
#path ⇒ Array<Hash>
Get the raw path data
Returns the raw path array from the CharString for advanced use cases.
158 159 160 161 162 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 158 def path return [] unless @charstring @charstring.path end |
#simple? ⇒ Boolean
Check if this is a simple glyph
CFF glyphs are conceptually "simple" - they don't have the composite structure that TrueType compound glyphs have. While CFF CharStrings can call subroutines, these are code reuse mechanisms, not glyph composition.
63 64 65 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 63 def simple? true end |
#to_commands ⇒ Array<Array>
Convert the glyph outline to drawing commands
Returns an array of drawing commands that can be used to render the glyph outline.
144 145 146 147 148 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 144 def to_commands return [] unless @charstring @charstring.to_commands end |
#to_s ⇒ String Also known as: inspect
String representation for debugging
167 168 169 170 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 167 def to_s "#<#{self.class.name} gid=#{@glyph_id} name=#{name.inspect} " \ "width=#{width} bbox=#{bounding_box.inspect}>" end |
#width ⇒ Integer?
Get the advance width for this glyph
Returns the glyph's advance width from the CharString.
106 107 108 109 110 |
# File 'lib/fontisan/tables/cff/cff_glyph.rb', line 106 def width return nil unless @charstring @charstring.width end |