Class: Pdfrb::Font::Type1::FontMetrics

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

Overview

Type1 font metrics wrapper. Delegates to AFMParser for the 14 standard fonts; provides glyph-width lookup.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(font_name, metrics) ⇒ FontMetrics

Returns a new instance of FontMetrics.



11
12
13
14
# File 'lib/pdfrb/font/type1/font_metrics.rb', line 11

def initialize(font_name, metrics)
  @font_name = font_name
  @metrics = metrics
end

Instance Attribute Details

#font_nameObject (readonly)

Returns the value of attribute font_name.



9
10
11
# File 'lib/pdfrb/font/type1/font_metrics.rb', line 9

def font_name
  @font_name
end

#metricsObject (readonly)

Returns the value of attribute metrics.



9
10
11
# File 'lib/pdfrb/font/type1/font_metrics.rb', line 9

def metrics
  @metrics
end

Class Method Details

.for_standard_font(name) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/pdfrb/font/type1/font_metrics.rb', line 16

def self.for_standard_font(name)
  afm_path = File.join(Pdfrb::DataDir.root, "afm", "#{name}.afm")
  return nil unless File.exist?(afm_path)

  metrics = AFMParser.from_file(afm_path)
  new(name, metrics)
end

Instance Method Details

#ascenderObject



32
33
34
# File 'lib/pdfrb/font/type1/font_metrics.rb', line 32

def ascender
  @metrics.ascender
end

#bboxObject



28
29
30
# File 'lib/pdfrb/font/type1/font_metrics.rb', line 28

def bbox
  @metrics.bbox
end

#cap_heightObject



40
41
42
# File 'lib/pdfrb/font/type1/font_metrics.rb', line 40

def cap_height
  @metrics.cap_height
end

#descenderObject



36
37
38
# File 'lib/pdfrb/font/type1/font_metrics.rb', line 36

def descender
  @metrics.descender
end

#width_for(glyph_name) ⇒ Object



24
25
26
# File 'lib/pdfrb/font/type1/font_metrics.rb', line 24

def width_for(glyph_name)
  @metrics.width_for(glyph_name)
end