Class: Fontisan::Type1::CharStrings
- Inherits:
-
Object
- Object
- Fontisan::Type1::CharStrings
- Defined in:
- lib/fontisan/type1/charstrings.rb
Overview
Type 1 CharStrings parser
CharStrings parses and stores
the CharStrings dictionary from a Type 1 font, which contains
glyph outline descriptions.
CharStrings in Type 1 fonts use a stack-based language with commands for drawing curves, lines, and composite glyphs (via the seac operator).
Defined Under Namespace
Classes: CharStringParser
Instance Attribute Summary collapse
-
#charstrings ⇒ Hash
readonly
Glyph name to CharString data mapping.
-
#private_dict ⇒ PrivateDict
readonly
Private dictionary for decryption.
Class Method Summary collapse
-
.parse(data, private_dict = nil) ⇒ CharStrings
Parse CharStrings dictionary from decrypted Type 1 font data.
Instance Method Summary collapse
-
#[](glyph_name) ⇒ String?
Get CharString data for glyph.
-
#charstring(glyph_name) ⇒ String?
Alias for #[].
-
#components_for(glyph_name) ⇒ Hash?
Get components for composite glyph.
-
#composite?(glyph_name) ⇒ Boolean
Check if glyph is composite (uses seac).
-
#count ⇒ Integer
Get the number of charstrings.
-
#each_charstring {|glyph_name, charstring_data| ... } ⇒ Enumerator
Iterate over all charstrings.
-
#encoding ⇒ Hash
Get encoding map.
-
#glyph_names ⇒ Array<String>
Get list of glyph names.
-
#has_glyph?(glyph_name) ⇒ Boolean
Check if glyph exists.
-
#initialize(private_dict = nil) ⇒ CharStrings
constructor
Initialize a new CharStrings parser.
-
#outline_for(glyph_name) ⇒ Array
Get outline for glyph by name.
-
#parse(data) ⇒ CharStrings
Parse CharStrings dictionary from decrypted Type 1 font data.
Constructor Details
#initialize(private_dict = nil) ⇒ CharStrings
Initialize a new CharStrings parser
42 43 44 45 |
# File 'lib/fontisan/type1/charstrings.rb', line 42 def initialize(private_dict = nil) @private_dict = private_dict || PrivateDict.new @charstrings = {} end |
Instance Attribute Details
#charstrings ⇒ Hash (readonly)
Returns Glyph name to CharString data mapping.
21 22 23 |
# File 'lib/fontisan/type1/charstrings.rb', line 21 def charstrings @charstrings end |
#private_dict ⇒ PrivateDict (readonly)
Returns Private dictionary for decryption.
24 25 26 |
# File 'lib/fontisan/type1/charstrings.rb', line 24 def private_dict @private_dict end |
Class Method Details
.parse(data, private_dict = nil) ⇒ CharStrings
Parse CharStrings dictionary from decrypted Type 1 font data
35 36 37 |
# File 'lib/fontisan/type1/charstrings.rb', line 35 def self.parse(data, private_dict = nil) new(private_dict).parse(data) end |
Instance Method Details
#[](glyph_name) ⇒ String?
Get CharString data for glyph
100 101 102 |
# File 'lib/fontisan/type1/charstrings.rb', line 100 def [](glyph_name) @charstrings[glyph_name] end |
#charstring(glyph_name) ⇒ String?
Alias for #[]
108 109 110 |
# File 'lib/fontisan/type1/charstrings.rb', line 108 def charstring(glyph_name) @charstrings[glyph_name] end |
#components_for(glyph_name) ⇒ Hash?
Get components for composite glyph
141 142 143 144 145 146 147 148 149 |
# File 'lib/fontisan/type1/charstrings.rb', line 141 def components_for(glyph_name) return nil unless composite?(glyph_name) charstring = @charstrings[glyph_name] parser = CharStringParser.new(@private_dict) parser.parse(charstring) parser.seac_components end |
#composite?(glyph_name) ⇒ Boolean
Check if glyph is composite (uses seac)
130 131 132 133 134 135 |
# File 'lib/fontisan/type1/charstrings.rb', line 130 def composite?(glyph_name) charstring = @charstrings[glyph_name] return false if charstring.nil? charstring.include?(SEAC_OPCODE) end |
#count ⇒ Integer
Get the number of charstrings
67 68 69 |
# File 'lib/fontisan/type1/charstrings.rb', line 67 def count @charstrings.size end |
#each_charstring {|glyph_name, charstring_data| ... } ⇒ Enumerator
Iterate over all charstrings
82 83 84 85 86 |
# File 'lib/fontisan/type1/charstrings.rb', line 82 def each_charstring(&) return enum_for(:each_charstring) unless block_given? @charstrings.each(&) end |
#encoding ⇒ Hash
Get encoding map
74 75 76 |
# File 'lib/fontisan/type1/charstrings.rb', line 74 def encoding @encoding ||= build_standard_encoding end |
#glyph_names ⇒ Array<String>
Get list of glyph names
60 61 62 |
# File 'lib/fontisan/type1/charstrings.rb', line 60 def glyph_names @charstrings.keys end |
#has_glyph?(glyph_name) ⇒ Boolean
Check if glyph exists
92 93 94 |
# File 'lib/fontisan/type1/charstrings.rb', line 92 def has_glyph?(glyph_name) @charstrings.key?(glyph_name) end |
#outline_for(glyph_name) ⇒ Array
Get outline for glyph by name
Parses the CharString and returns outline commands.
118 119 120 121 122 123 124 |
# File 'lib/fontisan/type1/charstrings.rb', line 118 def outline_for(glyph_name) charstring = @charstrings[glyph_name] return nil if charstring.nil? parser = CharStringParser.new(@private_dict) parser.parse(charstring) end |
#parse(data) ⇒ CharStrings
Parse CharStrings dictionary from decrypted Type 1 font data
51 52 53 54 55 |
# File 'lib/fontisan/type1/charstrings.rb', line 51 def parse(data) extract_charstrings(data) decrypt_charstrings self end |