Class: Fontisan::Type1::FontDictionary

Inherits:
Object
  • Object
show all
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.

Examples:

Parse font dictionary from decrypted font data

dict = Fontisan::Type1::FontDictionary.parse(decrypted_data)
puts dict.font_name
puts dict.font_info.full_name
puts dict.font_b_box

See Also:

Defined Under Namespace

Classes: Encoding, FontInfo

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFontDictionary

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

#encodingEncoding (readonly)

Returns Font encoding.

Returns:



30
31
32
# File 'lib/fontisan/type1/font_dictionary.rb', line 30

def encoding
  @encoding
end

#font_b_boxHash (readonly) Also known as: font_bbox

Returns Font bounding box [x_min, y_min, x_max, y_max].

Returns:

  • (Hash)

    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_infoFontInfo (readonly)

Returns Font information.

Returns:



24
25
26
# File 'lib/fontisan/type1/font_dictionary.rb', line 24

def font_info
  @font_info
end

#font_matrixArray<Float> (readonly)

Returns Font matrix [xx, xy, yx, yy, tx, ty].

Returns:

  • (Array<Float>)

    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_nameString (readonly)

Returns Font name.

Returns:

  • (String)

    Font name



27
28
29
# File 'lib/fontisan/type1/font_dictionary.rb', line 27

def font_name
  @font_name
end

#font_typeInteger (readonly)

Returns Font type (always 1 for Type 1).

Returns:

  • (Integer)

    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_typeInteger (readonly)

Returns Paint type (0=symbol, 1=character).

Returns:

  • (Integer)

    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_dataHash (readonly)

Returns Raw dictionary data.

Returns:

  • (Hash)

    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

Examples:

Parse from decrypted font data

dict = Fontisan::Type1::FontDictionary.parse(decrypted_data)

Parameters:

  • data (String)

    Decrypted Type 1 font data

Returns:

Raises:



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

Parameters:

  • key (String)

    Dictionary key

Returns:

  • (Object, nil)

    Value or nil if not found



136
137
138
# File 'lib/fontisan/type1/font_dictionary.rb', line 136

def [](key)
  @raw_data[key]
end

Get copyright from FontInfo

Returns:

  • (String, nil)

    Copyright notice



114
115
116
# File 'lib/fontisan/type1/font_dictionary.rb', line 114

def copyright
  @font_info&.copyright
end

#family_nameString?

Get family name from FontInfo

Returns:

  • (String, nil)

    Family name



100
101
102
# File 'lib/fontisan/type1/font_dictionary.rb', line 100

def family_name
  @font_info&.family_name
end

#full_nameString?

Get full name from FontInfo

Returns:

  • (String, nil)

    Full font name



93
94
95
# File 'lib/fontisan/type1/font_dictionary.rb', line 93

def full_name
  @font_info&.full_name
end

#noticeString?

Get notice from FontInfo

Returns:

  • (String, nil)

    Notice string



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

Parameters:

  • data (String)

    Decrypted Type 1 font data

Returns:



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

Returns:

  • (Boolean)

    True if dictionary has been parsed



86
87
88
# File 'lib/fontisan/type1/font_dictionary.rb', line 86

def parsed?
  @parsed
end

#to_type1_formatString

Convert FontDictionary to Type 1 text format

Generates the PostScript code for the Font Dictionary section of a Type 1 font.

Examples:

Generate Type 1 format

dict = FontDictionary.new
puts dict.to_type1_format

Returns:

  • (String)

    Type 1 Font Dictionary text



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

#versionString?

Get version from FontInfo

Returns:

  • (String, nil)

    Font version



107
108
109
# File 'lib/fontisan/type1/font_dictionary.rb', line 107

def version
  @font_info&.version
end

#weightString?

Get weight from FontInfo

Returns:

  • (String, nil)

    Font weight (Thin, Light, Regular, Bold, etc.)



128
129
130
# File 'lib/fontisan/type1/font_dictionary.rb', line 128

def weight
  @font_info&.weight
end