Class: PDF::Reader::WidthCalculator::BuiltIn
- Inherits:
-
Object
- Object
- PDF::Reader::WidthCalculator::BuiltIn
- Defined in:
- lib/pdf/reader/width_calculator/built_in.rb
Overview
Type1 fonts can be one of 14 “built in” standard fonts. In these cases, the reader is expected to have it’s own copy of the font metrics. see Section 9.6.2.2, PDF 32000-1:2008, pp 256
Instance Method Summary collapse
-
#glyph_height(code_point) ⇒ Object
TODO: no idea why my pdf is using a built-in font in vertical writing mode.
- #glyph_width(code_point) ⇒ Object
-
#initialize(font) ⇒ BuiltIn
constructor
A new instance of BuiltIn.
Constructor Details
#initialize(font) ⇒ BuiltIn
Returns a new instance of BuiltIn.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pdf/reader/width_calculator/built_in.rb', line 24 def initialize(font) @font = font @@all_metrics ||= PDF::Reader::SynchronizedCache.new metrics_path = File.join(File.dirname(__FILE__), "..","afm","#{font.basefont}.afm") if File.file?(metrics_path) @metrics = @@all_metrics[metrics_path] ||= AFM::Font.new(metrics_path) else raise ArgumentError, "No built-in metrics for #{font.basefont}" end end |
Instance Method Details
#glyph_height(code_point) ⇒ Object
TODO: no idea why my pdf is using a built-in font in vertical writing mode. Couldn’t find anything in the spec that described the desired behavior in this case.
52 53 54 |
# File 'lib/pdf/reader/width_calculator/built_in.rb', line 52 def glyph_height(code_point) return 0 end |
#glyph_width(code_point) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pdf/reader/width_calculator/built_in.rb', line 37 def glyph_width(code_point) return 0 if code_point.nil? || code_point < 0 m = @metrics.metrics_for(code_point) if m.nil? name = @font.encoding.int_to_name(code_point) m = @metrics.metrics_for_name(name) end # assume that if the code point could not be found, then glyph width = 0 m ? m[:wx] : 0 end |