Class: PDF::Inspector::Text

Inherits:
PDF::Inspector show all
Defined in:
lib/pdf/inspector/text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PDF::Inspector

analyze, analyze_file, parse

Constructor Details

#initializeText

Returns a new instance of Text


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pdf/inspector/text.rb', line 9

def initialize
  @font_settings = []
  @fonts = {}
  @font_objects = {}
  @strings = []
  @character_spacing = []
  @word_spacing = []
  @kerned = []
  @text_rendering_mode = []
  @positions = []
  @horizontal_text_scaling = []
end

Instance Attribute Details

#character_spacingObject

Returns the value of attribute character_spacing


5
6
7
# File 'lib/pdf/inspector/text.rb', line 5

def character_spacing
  @character_spacing
end

#font_settingsObject

Returns the value of attribute font_settings


4
5
6
# File 'lib/pdf/inspector/text.rb', line 4

def font_settings
  @font_settings
end

#horizontal_text_scalingObject

Returns the value of attribute horizontal_text_scaling


7
8
9
# File 'lib/pdf/inspector/text.rb', line 7

def horizontal_text_scaling
  @horizontal_text_scaling
end

#kernedObject

Returns the value of attribute kerned


6
7
8
# File 'lib/pdf/inspector/text.rb', line 6

def kerned
  @kerned
end

#positionsObject

Returns the value of attribute positions


6
7
8
# File 'lib/pdf/inspector/text.rb', line 6

def positions
  @positions
end

#sizeObject

Returns the value of attribute size


4
5
6
# File 'lib/pdf/inspector/text.rb', line 4

def size
  @size
end

#stringsObject

Returns the value of attribute strings


4
5
6
# File 'lib/pdf/inspector/text.rb', line 4

def strings
  @strings
end

#text_rendering_modeObject

Returns the value of attribute text_rendering_mode


6
7
8
# File 'lib/pdf/inspector/text.rb', line 6

def text_rendering_mode
  @text_rendering_mode
end

#word_spacingObject

Returns the value of attribute word_spacing


5
6
7
# File 'lib/pdf/inspector/text.rb', line 5

def word_spacing
  @word_spacing
end

Instance Method Details

#move_text_position(tx, ty) ⇒ Object


35
36
37
# File 'lib/pdf/inspector/text.rb', line 35

def move_text_position(tx, ty)
  @positions << [tx, ty]
end

#page=(page) ⇒ Object


22
23
24
25
26
27
28
# File 'lib/pdf/inspector/text.rb', line 22

def page=(page)
  @state = PDF::Reader::PageState.new(page)
  page.fonts.each do |label, stream|
    @fonts[label]        = stream[:BaseFont]
    @font_objects[label] = PDF::Reader::Font.new(page.objects, stream)
  end
end

#set_character_spacing(spacing) ⇒ Object


57
58
59
60
# File 'lib/pdf/inspector/text.rb', line 57

def set_character_spacing(spacing)
  @state.set_character_spacing(spacing)
  @character_spacing << spacing
end

#set_horizontal_text_scaling(scaling) ⇒ Object


67
68
69
70
# File 'lib/pdf/inspector/text.rb', line 67

def set_horizontal_text_scaling(scaling)
  @state.set_horizontal_text_scaling(scaling)
  @horizontal_text_scaling << scaling
end

#set_text_font_and_size(*params) ⇒ Object


30
31
32
33
# File 'lib/pdf/inspector/text.rb', line 30

def set_text_font_and_size(*params)
  @state.set_text_font_and_size(*params)
  @font_settings << { name: @fonts[params[0]], size: params[1] }
end

#set_text_rendering_mode(*params) ⇒ Object


52
53
54
55
# File 'lib/pdf/inspector/text.rb', line 52

def set_text_rendering_mode(*params)
  @state.set_text_rendering_mode(*params)
  @text_rendering_mode << params[0]
end

#set_word_spacing(*params) ⇒ Object


62
63
64
65
# File 'lib/pdf/inspector/text.rb', line 62

def set_word_spacing(*params)
  @state.set_word_spacing(*params)
  @word_spacing << params[0]
end

#show_text(*params) ⇒ Object


39
40
41
42
# File 'lib/pdf/inspector/text.rb', line 39

def show_text(*params)
  @kerned << false
  @strings << @state.current_font.to_utf8(params[0])
end

#show_text_with_positioning(*params) ⇒ Object


44
45
46
47
48
49
50
# File 'lib/pdf/inspector/text.rb', line 44

def show_text_with_positioning(*params)
  @kerned << true
  # ignore kerning information
  show_text params[0].reject { |e|
    e.is_a? Numeric
  }.join
end