Class: PDF::Reader::WidthCalculator::Composite

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/width_calculator/composite.rb

Overview

CIDFontType0 or CIDFontType2 use DW (integer) and W (array) to determine codepoint widths, note that CIDFontType2 will contain a true type font program which could be used to calculate width, however, a conforming writer is supposed to convert the widths for the codepoints used into the W array so that it can be used. see Section 9.7.4.1, PDF 32000-1:2008, pp 269-270

Instance Method Summary collapse

Constructor Details

#initialize(font) ⇒ Composite

Returns a new instance of Composite.



13
14
15
16
17
# File 'lib/pdf/reader/width_calculator/composite.rb', line 13

def initialize(font)
  @font = font
  parse_cid_widths(@font.cid_default_width, @font.cid_widths)
  parse_cid_heights_and_positions(@font.cid_default_height, @font.cid_heights)
end

Instance Method Details

#glyph_height(code_point) ⇒ Object

NOTE: heights are negative when the text goes top to bottom



28
29
30
31
32
33
34
# File 'lib/pdf/reader/width_calculator/composite.rb', line 28

def glyph_height(code_point)
  return 0 if code_point.nil? || code_point < 0

  h = @heights[code_point]
  # 0 is a valid height
  return h.to_f unless h.nil?
end

#glyph_position(code_point) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pdf/reader/width_calculator/composite.rb', line 36

def glyph_position(code_point)
  return [0,0] if code_point.nil? || code_point < 0

  p = @positions[code_point]
  if not h.nil?
    return h.to_f
  else
    w = glyph_width(code_point)
    return [w/2, @default_position_y] unless w.nil?
  end
end

#glyph_width(code_point) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/pdf/reader/width_calculator/composite.rb', line 19

def glyph_width(code_point)
  return 0 if code_point.nil? || code_point < 0

  w = @widths[code_point]
  # 0 is a valid width
  return w.to_f unless w.nil?
end