Class: Fontisan::Type1::PrivateDict
- Inherits:
-
Object
- Object
- Fontisan::Type1::PrivateDict
- Defined in:
- lib/fontisan/type1/private_dict.rb
Overview
Type 1 Private Dictionary model
[‘PrivateDict`](lib/fontisan/type1/private_dict.rb) parses and stores the private dictionary from a Type 1 font, which contains hinting and spacing information used by the CharString interpreter.
The private dictionary includes:
-
BlueValues and OtherBlues (alignment zones for optical consistency)
-
StdHW and StdVW (standard stem widths)
-
StemSnapH and StemSnapV (stem snap arrays)
-
Subrs (local subroutines)
-
lenIV (CharString encryption IV length)
Instance Attribute Summary collapse
-
#blue_fuzz ⇒ Integer
BlueFuzz.
-
#blue_scale ⇒ Float
BlueScale.
-
#blue_shift ⇒ Integer
BlueShift.
-
#blue_values ⇒ Array<Integer>
BlueValues alignment zones.
-
#expansion_factor ⇒ Float
ExpansionFactor for counter widening.
-
#family_blues ⇒ Array<Integer>
FamilyBlues alignment zones.
-
#family_other_blues ⇒ Array<Integer>
FamilyOtherBlues alignment zones.
-
#force_bold ⇒ Boolean
ForceBold flag.
-
#initial_random_seed ⇒ Integer
InitialRandomSeed for randomization.
-
#language_group ⇒ Integer
LanguageGroup (0 for Latin, 1 for Japanese, etc.).
-
#len_iv ⇒ Integer
LenIV (CharString encryption IV length).
-
#other_blues ⇒ Array<Integer>
OtherBlues alignment zones.
-
#raw_data ⇒ Hash
readonly
Raw dictionary data.
-
#std_hw ⇒ Array<Float>
StdHW (standard horizontal width).
-
#std_vw ⇒ Array<Float>
StdVW (standard vertical width).
-
#stem_snap_h ⇒ Array<Float>
StemSnapH (horizontal stem snap array).
-
#stem_snap_v ⇒ Array<Float>
StemSnapV (vertical stem snap array).
-
#subrs ⇒ Array<String>
Subrs (local subroutines).
Class Method Summary collapse
-
.parse(data) ⇒ PrivateDict
Parse private dictionary from decrypted Type 1 font data.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Get raw value from dictionary.
-
#array_to_type1(name, value) ⇒ String
Format an array value for Type 1 output.
-
#boolean_to_type1(name, value) ⇒ String
Format a boolean value for Type 1 output.
-
#effective_blue_values ⇒ Array<Float>
Get effective BlueValues for hinting.
-
#has_blues? ⇒ Boolean
Check if font has blues.
-
#has_stem_hints? ⇒ Boolean
Check if font has stem hints.
-
#initialize ⇒ PrivateDict
constructor
Initialize a new PrivateDict.
-
#parse(data) ⇒ PrivateDict
Parse private dictionary from decrypted Type 1 font data.
-
#parsed? ⇒ Boolean
Check if dictionary was successfully parsed.
-
#scalar_to_type1(name, value) ⇒ String
Format a scalar value for Type 1 output.
-
#to_type1_format ⇒ String
Convert PrivateDict to Type 1 text format.
Constructor Details
#initialize ⇒ PrivateDict
Initialize a new PrivateDict
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/fontisan/type1/private_dict.rb', line 92 def initialize @blue_values = [] @other_blues = [] @family_blues = [] @family_other_blues = [] @blue_scale = 0.039625 @blue_shift = 7 @blue_fuzz = 1 @std_hw = [] @std_vw = [] @stem_snap_h = [] @stem_snap_v = [] @force_bold = false @len_iv = 4 @subrs = [] @language_group = 0 @expansion_factor = 0.06 @initial_random_seed = 0 @raw_data = {} @parsed = false end |
Instance Attribute Details
#blue_fuzz ⇒ Integer
Returns BlueFuzz.
44 45 46 |
# File 'lib/fontisan/type1/private_dict.rb', line 44 def blue_fuzz @blue_fuzz end |
#blue_scale ⇒ Float
Returns BlueScale.
38 39 40 |
# File 'lib/fontisan/type1/private_dict.rb', line 38 def blue_scale @blue_scale end |
#blue_shift ⇒ Integer
Returns BlueShift.
41 42 43 |
# File 'lib/fontisan/type1/private_dict.rb', line 41 def blue_shift @blue_shift end |
#blue_values ⇒ Array<Integer>
Returns BlueValues alignment zones.
26 27 28 |
# File 'lib/fontisan/type1/private_dict.rb', line 26 def blue_values @blue_values end |
#expansion_factor ⇒ Float
Returns ExpansionFactor for counter widening.
71 72 73 |
# File 'lib/fontisan/type1/private_dict.rb', line 71 def expansion_factor @expansion_factor end |
#family_blues ⇒ Array<Integer>
Returns FamilyBlues alignment zones.
32 33 34 |
# File 'lib/fontisan/type1/private_dict.rb', line 32 def family_blues @family_blues end |
#family_other_blues ⇒ Array<Integer>
Returns FamilyOtherBlues alignment zones.
35 36 37 |
# File 'lib/fontisan/type1/private_dict.rb', line 35 def family_other_blues @family_other_blues end |
#force_bold ⇒ Boolean
Returns ForceBold flag.
59 60 61 |
# File 'lib/fontisan/type1/private_dict.rb', line 59 def force_bold @force_bold end |
#initial_random_seed ⇒ Integer
Returns InitialRandomSeed for randomization.
74 75 76 |
# File 'lib/fontisan/type1/private_dict.rb', line 74 def initial_random_seed @initial_random_seed end |
#language_group ⇒ Integer
Returns LanguageGroup (0 for Latin, 1 for Japanese, etc.).
68 69 70 |
# File 'lib/fontisan/type1/private_dict.rb', line 68 def language_group @language_group end |
#len_iv ⇒ Integer
Returns lenIV (CharString encryption IV length).
62 63 64 |
# File 'lib/fontisan/type1/private_dict.rb', line 62 def len_iv @len_iv end |
#other_blues ⇒ Array<Integer>
Returns OtherBlues alignment zones.
29 30 31 |
# File 'lib/fontisan/type1/private_dict.rb', line 29 def other_blues @other_blues end |
#raw_data ⇒ Hash (readonly)
Returns Raw dictionary data.
77 78 79 |
# File 'lib/fontisan/type1/private_dict.rb', line 77 def raw_data @raw_data end |
#std_hw ⇒ Array<Float>
Returns StdHW (standard horizontal width).
47 48 49 |
# File 'lib/fontisan/type1/private_dict.rb', line 47 def std_hw @std_hw end |
#std_vw ⇒ Array<Float>
Returns StdVW (standard vertical width).
50 51 52 |
# File 'lib/fontisan/type1/private_dict.rb', line 50 def std_vw @std_vw end |
#stem_snap_h ⇒ Array<Float>
Returns StemSnapH (horizontal stem snap array).
53 54 55 |
# File 'lib/fontisan/type1/private_dict.rb', line 53 def stem_snap_h @stem_snap_h end |
#stem_snap_v ⇒ Array<Float>
Returns StemSnapV (vertical stem snap array).
56 57 58 |
# File 'lib/fontisan/type1/private_dict.rb', line 56 def stem_snap_v @stem_snap_v end |
#subrs ⇒ Array<String>
Returns Subrs (local subroutines).
65 66 67 |
# File 'lib/fontisan/type1/private_dict.rb', line 65 def subrs @subrs end |
Class Method Details
.parse(data) ⇒ PrivateDict
Parse private dictionary from decrypted Type 1 font data
87 88 89 |
# File 'lib/fontisan/type1/private_dict.rb', line 87 def self.parse(data) new.parse(data) end |
Instance Method Details
#[](key) ⇒ Object?
Get raw value from dictionary
136 137 138 |
# File 'lib/fontisan/type1/private_dict.rb', line 136 def [](key) @raw_data[key] end |
#array_to_type1(name, value) ⇒ String
Format an array value for Type 1 output
222 223 224 |
# File 'lib/fontisan/type1/private_dict.rb', line 222 def array_to_type1(name, value) "/#{name} [#{value.join(' ')}] def" end |
#boolean_to_type1(name, value) ⇒ String
Format a boolean value for Type 1 output
240 241 242 |
# File 'lib/fontisan/type1/private_dict.rb', line 240 def boolean_to_type1(name, value) "/#{name} #{value} def" end |
#effective_blue_values ⇒ Array<Float>
Get effective BlueValues for hinting
Returns BlueValues adjusted by BlueScale.
145 146 147 148 149 |
# File 'lib/fontisan/type1/private_dict.rb', line 145 def effective_blue_values return [] if @blue_values.empty? @blue_values.map { |v| v * @blue_scale } end |
#has_blues? ⇒ Boolean
Check if font has blues
154 155 156 |
# File 'lib/fontisan/type1/private_dict.rb', line 154 def has_blues? !@blue_values.empty? || !@other_blues.empty? end |
#has_stem_hints? ⇒ Boolean
Check if font has stem hints
161 162 163 164 |
# File 'lib/fontisan/type1/private_dict.rb', line 161 def has_stem_hints? !@std_hw.empty? || !@std_vw.empty? || !@stem_snap_h.empty? || !@stem_snap_v.empty? end |
#parse(data) ⇒ PrivateDict
Parse private dictionary from decrypted Type 1 font data
118 119 120 121 122 123 |
# File 'lib/fontisan/type1/private_dict.rb', line 118 def parse(data) extract_private_dict(data) extract_properties @parsed = true self end |
#parsed? ⇒ Boolean
Check if dictionary was successfully parsed
128 129 130 |
# File 'lib/fontisan/type1/private_dict.rb', line 128 def parsed? @parsed end |
#scalar_to_type1(name, value) ⇒ String
Format a scalar value for Type 1 output
231 232 233 |
# File 'lib/fontisan/type1/private_dict.rb', line 231 def scalar_to_type1(name, value) "/#{name} #{value} def" end |
#to_type1_format ⇒ String
Convert PrivateDict to Type 1 text format
Generates the PostScript code for the Private dictionary section of a Type 1 font.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/fontisan/type1/private_dict.rb', line 177 def to_type1_format result = [] unless @blue_values.empty? result << array_to_type1(:BlueValues, @blue_values) end unless @other_blues.empty? result << array_to_type1(:OtherBlues, @other_blues) end unless @family_blues.empty? result << array_to_type1(:FamilyBlues, @family_blues) end unless @family_other_blues.empty? result << array_to_type1(:FamilyOtherBlues, @family_other_blues) end result << scalar_to_type1(:BlueScale, @blue_scale) result << scalar_to_type1(:BlueShift, @blue_shift) result << scalar_to_type1(:BlueFuzz, @blue_fuzz) result << array_to_type1(:StdHW, @std_hw) unless @std_hw.empty? result << array_to_type1(:StdVW, @std_vw) unless @std_vw.empty? unless @stem_snap_h.empty? result << array_to_type1(:StemSnapH, @stem_snap_h) end unless @stem_snap_v.empty? result << array_to_type1(:StemSnapV, @stem_snap_v) end unless @force_bold == false result << boolean_to_type1(:ForceBold, @force_bold) end result << scalar_to_type1(:lenIV, @len_iv) result.join("\n") end |