Class: HexaPDF::Font::Type1::FontMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/font/type1/font_metrics.rb

Overview

Represents the information stored in an AFM font metrics file for a Type1 font that is needed for working with that font in context of the PDF format.

Constant Summary collapse

WEIGHT_NAME_TO_NUMBER =

:nodoc:

{'Bold' => 700, 'Medium' => 500, 'Roman' => 400}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFontMetrics

:nodoc:



113
114
115
116
117
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 113

def initialize #:nodoc:
  @character_metrics = {}
  @kerning_pairs = {}
  @ligature_pairs = {}
end

Instance Attribute Details

#ascenderObject

Ascender of the font.



78
79
80
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 78

def ascender
  @ascender
end

#bounding_boxObject

The font bounding box as array of four numbers, specifying the x- and y-coordinates of the bottom-left corner and the x- and y-coordinates of the top-right corner.



67
68
69
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 67

def bounding_box
  @bounding_box
end

#cap_heightObject

The y-value of the top of the capital H (or 0 or nil if the font doesn’t contain a capital H).



71
72
73
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 71

def cap_height
  @cap_height
end

#character_metricsObject

Mapping of character codes and names to CharacterMetrics objects.



103
104
105
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 103

def character_metrics
  @character_metrics
end

#character_setObject

A string describing the character set of the font.



57
58
59
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 57

def character_set
  @character_set
end

#descenderObject

Descender of the font.



81
82
83
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 81

def descender
  @descender
end

#dominant_horizontal_stem_widthObject

Dominant width of horizontal stems.



84
85
86
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 84

def dominant_horizontal_stem_width
  @dominant_horizontal_stem_width
end

#dominant_vertical_stem_widthObject

Dominant width of vertical stems.



87
88
89
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 87

def dominant_vertical_stem_width
  @dominant_vertical_stem_width
end

#encoding_schemeObject

A string indicating the default encoding used for the font.



60
61
62
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 60

def encoding_scheme
  @encoding_scheme
end

#family_nameObject

Name of the typeface family to which the font belongs.



54
55
56
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 54

def family_name
  @family_name
end

#font_nameObject

PostScript name of the font.



48
49
50
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 48

def font_name
  @font_name
end

#full_nameObject

Full text name of the font.



51
52
53
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 51

def full_name
  @full_name
end

#is_fixed_pitchObject

Boolean specifying if the font is a fixed pitch (monospaced) font.



100
101
102
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 100

def is_fixed_pitch
  @is_fixed_pitch
end

#italic_angleObject

Angle (in degrees counter-clockwise from the vertical) of the dominant vertical strokes of the font.



97
98
99
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 97

def italic_angle
  @italic_angle
end

#kerning_pairsObject

Nested mapping of kerning pairs, ie. each key is a character name and each value is a mapping from the second character name to the kerning amount.



107
108
109
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 107

def kerning_pairs
  @kerning_pairs
end

#ligature_pairsObject

Nested mapping of ligature pairs, ie. each key is a character name and each value is a mapping from the second character name to the ligature name.



111
112
113
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 111

def ligature_pairs
  @ligature_pairs
end

#underline_positionObject

Distance from the baseline for centering underlining strokes.



90
91
92
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 90

def underline_position
  @underline_position
end

#underline_thicknessObject

Stroke width for underlining.



93
94
95
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 93

def underline_thickness
  @underline_thickness
end

#weightObject

A string describing the weight of the font.



63
64
65
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 63

def weight
  @weight
end

#x_heightObject

The y-value of the top of the lowercase x (or 0 or nil if the font doesnt’ contain a lowercase x)



75
76
77
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 75

def x_height
  @x_height
end

Instance Method Details

#weight_classObject

Returns the weight of the font as a number.

The return value 0 is used if the weight class cannot be determined.



124
125
126
# File 'lib/hexapdf/font/type1/font_metrics.rb', line 124

def weight_class
  WEIGHT_NAME_TO_NUMBER.fetch(weight, 0)
end