Class: Fontisan::Type1::FontDictionary
- Inherits:
-
Object
- Object
- Fontisan::Type1::FontDictionary
- Defined in:
- lib/fontisan/type1/font_dictionary.rb
Overview
Type 1 Font Dictionary model
FontDictionary parses and stores
the font dictionary from a Type 1 font, which contains metadata about
the font including FontInfo, FontName, Encoding, and other properties.
The font dictionary is the top-level PostScript dictionary that defines the font's properties and contains references to the Private dictionary and CharStrings.
Defined Under Namespace
Instance Attribute Summary collapse
-
#encoding ⇒ Encoding
readonly
Font encoding.
-
#font_b_box ⇒ Hash
(also: #font_bbox)
readonly
Font bounding box [x_min, y_min, x_max, y_max].
-
#font_info ⇒ FontInfo
readonly
Font information.
-
#font_matrix ⇒ Array<Float>
readonly
Font matrix [xx, xy, yx, yy, tx, ty].
-
#font_name ⇒ String
readonly
Font name.
-
#font_type ⇒ Integer
readonly
Font type (always 1 for Type 1).
-
#paint_type ⇒ Integer
readonly
Paint type (0=symbol, 1=character).
-
#raw_data ⇒ Hash
readonly
Raw dictionary data.
Class Method Summary collapse
-
.parse(data) ⇒ FontDictionary
Parse font dictionary from decrypted Type 1 font data.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Get raw value from dictionary.
-
#copyright ⇒ String?
Get copyright from FontInfo.
-
#family_name ⇒ String?
Get family name from FontInfo.
-
#full_name ⇒ String?
Get full name from FontInfo.
-
#initialize ⇒ FontDictionary
constructor
Initialize a new FontDictionary.
-
#notice ⇒ String?
Get notice from FontInfo.
-
#parse(data) ⇒ FontDictionary
Parse font dictionary from decrypted Type 1 font data.
-
#parsed? ⇒ Boolean
Check if dictionary was successfully parsed.
-
#to_type1_format ⇒ String
Convert FontDictionary to Type 1 text format.
-
#version ⇒ String?
Get version from FontInfo.
-
#weight ⇒ String?
Get weight from FontInfo.
Constructor Details
#initialize ⇒ FontDictionary
Initialize a new FontDictionary
63 64 65 66 67 68 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 63 def initialize @font_info = FontInfo.new @encoding = Encoding.new @raw_data = {} @parsed = false end |
Instance Attribute Details
#encoding ⇒ Encoding (readonly)
Returns Font encoding.
30 31 32 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 30 def encoding @encoding end |
#font_b_box ⇒ Hash (readonly) Also known as: font_bbox
Returns Font bounding box [x_min, y_min, x_max, y_max].
33 34 35 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 33 def font_b_box @font_b_box end |
#font_info ⇒ FontInfo (readonly)
Returns Font information.
24 25 26 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 24 def font_info @font_info end |
#font_matrix ⇒ Array<Float> (readonly)
Returns Font matrix [xx, xy, yx, yy, tx, ty].
39 40 41 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 39 def font_matrix @font_matrix end |
#font_name ⇒ String (readonly)
Returns Font name.
27 28 29 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 27 def font_name @font_name end |
#font_type ⇒ Integer (readonly)
Returns Font type (always 1 for Type 1).
45 46 47 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 45 def font_type @font_type end |
#paint_type ⇒ Integer (readonly)
Returns Paint type (0=symbol, 1=character).
42 43 44 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 42 def paint_type @paint_type end |
#raw_data ⇒ Hash (readonly)
Returns Raw dictionary data.
48 49 50 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 48 def raw_data @raw_data end |
Class Method Details
.parse(data) ⇒ FontDictionary
Parse font dictionary from decrypted Type 1 font data
58 59 60 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 58 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/font_dictionary.rb', line 136 def [](key) @raw_data[key] end |
#copyright ⇒ String?
Get copyright from FontInfo
114 115 116 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 114 def copyright @font_info&.copyright end |
#family_name ⇒ String?
Get family name from FontInfo
100 101 102 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 100 def family_name @font_info&.family_name end |
#full_name ⇒ String?
Get full name from FontInfo
93 94 95 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 93 def full_name @font_info&.full_name end |
#notice ⇒ String?
Get notice from FontInfo
121 122 123 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 121 def notice @font_info&.notice end |
#parse(data) ⇒ FontDictionary
Parse font dictionary from decrypted Type 1 font data
74 75 76 77 78 79 80 81 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 74 def parse(data) extract_font_dictionary(data) extract_font_info extract_encoding extract_properties @parsed = true self end |
#parsed? ⇒ Boolean
Check if dictionary was successfully parsed
86 87 88 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 86 def parsed? @parsed end |
#to_type1_format ⇒ String
Convert FontDictionary to Type 1 text format
Generates the PostScript code for the Font Dictionary section of a Type 1 font.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 150 def to_type1_format result = [] result << "% Type 1 Font Dictionary" result << "12 dict begin" result << "" result << "/FontType 1 def" result << "/PaintType #{@paint_type} def" result << font_matrix_to_type1 result << font_bbox_to_type1 result << "" result << font_info_to_type1 result << "" result << "currentdict end" result << "/FontName #{@font_name} def" result.join("\n") end |
#version ⇒ String?
Get version from FontInfo
107 108 109 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 107 def version @font_info&.version end |
#weight ⇒ String?
Get weight from FontInfo
128 129 130 |
# File 'lib/fontisan/type1/font_dictionary.rb', line 128 def weight @font_info&.weight end |