class HexaPDF::Font::Type1::Font
Represents a Type1
font.
This class abstracts from the specifics of the Type1
font and allows working with it in a standardized way.
The following method calls are forwarded to the contained FontMetrics
object:
-
font_name
-
full_name
-
family_name
-
weight
-
weight_class
-
font_bbox
-
italic_angle
-
ascender
-
descender
-
cap_height
-
x_height
-
horizontal_dominant_width
-
vertical_dominant_width
Attributes
The associated FontMetrics
object.
Public Class Methods
Creates a Type1
font object from an AFM source.
# File lib/hexapdf/font/type1/font.rb, line 70 def self.from_afm(source) new(AFMParser.parse(source)) end
Creates a new Type1
font object with the given font metrics.
# File lib/hexapdf/font/type1/font.rb, line 84 def initialize(metrics) @metrics = metrics end
Public Instance Methods
Returns the built-in encoding of the font.
# File lib/hexapdf/font/type1/font.rb, line 89 def encoding @encoding ||= begin if @metrics.encoding_scheme == 'AdobeStandardEncoding' Encoding.for_name(:StandardEncoding) elsif font_name == 'ZapfDingbats' || font_name == 'Symbol' Encoding.for_name((font_name + "Encoding").to_sym) else encoding = Encoding::Base.new @metrics.character_metrics.each do |key, char_metric| next unless key.kind_of?(Integer) && key >= 0 encoding.code_to_name[key] = char_metric.name end encoding end end end
Returns a set of features this font supports.
For Type1
fonts, the features that may be available :kern and :liga.
# File lib/hexapdf/font/type1/font.rb, line 127 def features @features ||= Set.new.tap do |set| set << :kern unless metrics.kerning_pairs.empty? set << :liga unless metrics.ligature_pairs.empty? end end
Returns the name/id of the missing glyph, i.e. .notdef.
# File lib/hexapdf/font/type1/font.rb, line 120 def missing_glyph_id :'.notdef' end
Returns the distance from the baseline to the top of the strikeout line.
# File lib/hexapdf/font/type1/font.rb, line 140 def strikeout_position # We use the suggested value from the OpenType spec. 225 end
Returns the thickness of the strikeout line.
# File lib/hexapdf/font/type1/font.rb, line 146 def strikeout_thickness # The OpenType spec suggests the width of an em-dash or 50, so we use that as # approximation since the AFM files don't contain this information. if (bbox = @metrics.character_metrics[:emdash]&.bbox) bbox[3] - bbox[1] else 50 end end
Returns the distance from the baseline to the top of the underline.
# File lib/hexapdf/font/type1/font.rb, line 135 def underline_position @metrics.underline_position + @metrics.underline_thickness / 2.0 end
Returns the width of the glyph which can either be specified by glyph name or by an integer that is interpreted according to the built-in encoding.
If there is no glyph found for the name or code, nil
is returned.
# File lib/hexapdf/font/type1/font.rb, line 115 def width(glyph) (metric = @metrics.character_metrics[glyph]) && metric.width end