pdf-inspector 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ v1.0.0 (13 August 2011)
2
+ * initial release as a standalone gem
data/README ADDED
@@ -0,0 +1,39 @@
1
+ PDF::Inspector : A tool for analyzing PDF output
2
+
3
+ This library provides a number of PDF::Reader[0] based tools for use in testing
4
+ PDF output. Presently, the primary purpose of this tool is to support the
5
+ tests found in Prawn[1], a pure Ruby PDF generation library.
6
+
7
+ However, it may be useful to others, so we have made it available as a gem in
8
+ its own right.
9
+
10
+ = Installation
11
+
12
+ The recommended installation method is via Rubygems.
13
+
14
+ gem install pdf-inspector
15
+
16
+ = Maintainers
17
+
18
+ - Brad Ediger
19
+ - Daniel Nelson
20
+ - Jonathan Greenberg
21
+ - James Healy
22
+
23
+ = Licensing
24
+
25
+ Matz’s terms for Ruby, GPLv2, or GPLv3. See LICENSING for details.
26
+
27
+ = Mailing List
28
+
29
+ pdf-inspector is maintaiend as a dependency of prawn, the ruby PDF generation
30
+ library.
31
+
32
+ Any questions or feedback should be sent to the Prawn google group.
33
+
34
+ http://groups.google.com/group/prawn-ruby
35
+
36
+ = References
37
+
38
+ [0] http://github.com/yob/pdf-reader
39
+ [1] http://github.com/sandal/prawn
@@ -0,0 +1,26 @@
1
+ require "rubygems"
2
+ require "pdf/reader"
3
+ require "pdf/inspector/text"
4
+ require "pdf/inspector/xobject"
5
+ require "pdf/inspector/extgstate"
6
+ require "pdf/inspector/graphics"
7
+ require "pdf/inspector/page"
8
+
9
+ module PDF
10
+ class Inspector
11
+ def self.analyze(output,*args,&block)
12
+ obs = self.new(*args, &block)
13
+ PDF::Reader.string(output,obs)
14
+ obs
15
+ end
16
+
17
+ def self.analyze_file(filename,*args,&block)
18
+ analyze(File.open(filename, "rb") { |f| f.read },*args,&block)
19
+ end
20
+
21
+ def self.parse(obj)
22
+ PDF::Reader::Parser.new(
23
+ PDF::Reader::Buffer.new(StringIO.new(obj)), nil).parse_token
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ module PDF
2
+ class Inspector
3
+ class ExtGState < Inspector
4
+ attr_accessor :extgstates
5
+
6
+ def initialize
7
+ @extgstates = []
8
+ end
9
+
10
+ def resource_extgstate(*params)
11
+ @extgstates << {
12
+ :opacity => params[1][:ca],
13
+ :stroke_opacity => params[1][:CA]
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,168 @@
1
+ module PDF
2
+ class Inspector
3
+ module Graphics
4
+ class Line < Inspector
5
+ attr_accessor :points, :widths
6
+
7
+ def initialize
8
+ @points = []
9
+ @widths = []
10
+ end
11
+
12
+ def append_line(*params)
13
+ @points << params
14
+ end
15
+
16
+ def begin_new_subpath(*params)
17
+ @points << params
18
+ end
19
+
20
+ def set_line_width(params)
21
+ @widths << params
22
+ end
23
+
24
+ end
25
+
26
+ class Rectangle < Inspector
27
+ attr_reader :rectangles
28
+
29
+ def initialize
30
+ @rectangles = []
31
+ end
32
+
33
+ def append_rectangle(*params)
34
+ @rectangles << { :point => params[0..1],
35
+ :width => params[2],
36
+ :height => params[3] }
37
+ end
38
+ end
39
+
40
+ class Curve < Inspector
41
+
42
+ attr_reader :coords
43
+
44
+ def initialize
45
+ @coords = []
46
+ end
47
+
48
+ def begin_new_subpath(*params)
49
+ @coords += params
50
+ end
51
+
52
+ def append_curved_segment(*params)
53
+ @coords += params
54
+ end
55
+
56
+ end
57
+
58
+ class Color < Inspector
59
+ attr_reader :stroke_color, :fill_color, :stroke_color_count,
60
+ :fill_color_count, :stroke_color_space_count, :color_space
61
+
62
+ def initialize
63
+ @stroke_color_count = 0
64
+ @fill_color_count = 0
65
+ @stroke_color_space_count = {:DeviceCMYK => 0, :DeviceRGB => 0}
66
+ end
67
+
68
+ def set_color_for_stroking_and_special(*params)
69
+ @stroke_color_count += 1
70
+ @stroke_color = params
71
+ end
72
+
73
+ def set_color_for_nonstroking_and_special(*params)
74
+ @fill_color_count += 1
75
+ @fill_color = params
76
+ end
77
+
78
+ def set_stroke_color_space(*params)
79
+ @stroke_color_space_count[params[0]] += 1
80
+ @color_space = params[0]
81
+ end
82
+
83
+ end
84
+
85
+ class Dash < Inspector
86
+ attr_reader :stroke_dash, :stroke_dash_count
87
+
88
+ def initialize
89
+ @stroke_dash_count = 0
90
+ end
91
+
92
+ def set_line_dash(*params)
93
+ @stroke_dash_count += 1
94
+ @stroke_dash = params
95
+ end
96
+ end
97
+
98
+ class CapStyle < Inspector
99
+ attr_reader :cap_style, :cap_style_count
100
+
101
+ def initialize
102
+ @cap_style_count = 0
103
+ end
104
+
105
+ def set_line_cap_style(*params)
106
+ @cap_style_count += 1
107
+ @cap_style = params[0]
108
+ end
109
+ end
110
+
111
+ class JoinStyle < Inspector
112
+ attr_reader :join_style, :join_style_count
113
+
114
+ def initialize
115
+ @join_style_count = 0
116
+ end
117
+
118
+ def set_line_join_style(*params)
119
+ @join_style_count += 1
120
+ @join_style = params[0]
121
+ end
122
+ end
123
+
124
+ class Matrix < Inspector
125
+ attr_reader :matrices
126
+
127
+ def initialize
128
+ @matrices = []
129
+ end
130
+
131
+ def concatenate_matrix(*values)
132
+ @matrices << values
133
+ end
134
+ end
135
+
136
+ class State < Inspector
137
+ attr_reader :save_graphics_state_count, :restore_graphics_state_count
138
+
139
+ def initialize
140
+ @save_graphics_state_count = 0
141
+ @restore_graphics_state_count = 0
142
+ end
143
+
144
+ def save_graphics_state(*values)
145
+ @save_graphics_state_count += 1
146
+ end
147
+
148
+ def restore_graphics_state(*values)
149
+ @restore_graphics_state_count += 1
150
+ end
151
+ end
152
+
153
+ class Pattern < Inspector
154
+ attr_reader :patterns
155
+
156
+ def initialize
157
+ super
158
+ @patterns = {}
159
+ end
160
+
161
+ def resource_pattern(name, dict)
162
+ @patterns[name] = dict
163
+ end
164
+ end
165
+
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,25 @@
1
+ module PDF
2
+ class Inspector
3
+ class Page < Inspector
4
+ attr_reader :pages
5
+
6
+ def initialize
7
+ @pages = []
8
+ end
9
+
10
+ def begin_page(params)
11
+ @pages << {:size => params[:MediaBox][-2..-1], :strings => []}
12
+ end
13
+
14
+ def show_text(*params)
15
+ @pages.last[:strings] << params[0]
16
+ end
17
+
18
+ def show_text_with_positioning(*params)
19
+ # ignore kerning information
20
+ @pages.last[:strings] << params[0].reject { |e| Numeric === e }.join
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,51 @@
1
+ module PDF
2
+ class Inspector
3
+ class Text < Inspector
4
+ attr_accessor :font_settings, :size, :strings
5
+ attr_accessor :character_spacing, :word_spacing
6
+ attr_accessor :kerned, :text_rendering_mode
7
+
8
+ def initialize
9
+ @font_settings = []
10
+ @fonts = {}
11
+ @strings = []
12
+ @character_spacing = []
13
+ @word_spacing = []
14
+ @kerned = []
15
+ @text_rendering_mode = []
16
+ end
17
+
18
+ def resource_font(*params)
19
+ @fonts[params[0]] = params[1].basefont
20
+ end
21
+
22
+ def set_text_font_and_size(*params)
23
+ @font_settings << { :name => @fonts[params[0]], :size => params[1] }
24
+ end
25
+
26
+ def show_text(*params)
27
+ @kerned << false
28
+ @strings << params[0]
29
+ end
30
+
31
+ def show_text_with_positioning(*params)
32
+ @kerned << true
33
+ # ignore kerning information
34
+ @strings << params[0].reject { |e| Numeric === e }.join
35
+ end
36
+
37
+ def set_text_rendering_mode(*params)
38
+ @text_rendering_mode << params[0]
39
+ end
40
+
41
+ def set_character_spacing(*params)
42
+ @character_spacing << params[0]
43
+ end
44
+
45
+ def set_word_spacing(*params)
46
+ @word_spacing << params[0]
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,25 @@
1
+ module PDF
2
+ class Inspector
3
+ class XObject < Inspector
4
+ attr_accessor :page_xobjects, :xobject_streams
5
+
6
+ def initialize
7
+ @page_xobjects = []
8
+ @xobject_streams = {}
9
+ end
10
+
11
+ def resource_xobject(*params)
12
+ @page_xobjects.last << params.first
13
+ store_streams(params.first, params.last)
14
+ end
15
+
16
+ def begin_page(*params)
17
+ @page_xobjects << []
18
+ end
19
+
20
+ def store_streams(resource_name, stream)
21
+ @xobject_streams[resource_name] = stream
22
+ end
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdf-inspector
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gregory Brown
9
+ - Brad Ediger
10
+ - Daniel Nelson
11
+ - Jonathan Greenberg
12
+ - James Healy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+ date: 2011-08-13 00:00:00.000000000 -05:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: pdf-reader
21
+ requirement: &9952680 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ type: :runtime
28
+ prerelease: false
29
+ version_requirements: *9952680
30
+ description: ! 'This library provides a number of PDF::Reader[0] based tools for use
31
+ in testing
32
+
33
+ PDF output. Presently, the primary purpose of this tool is to support the
34
+
35
+ tests found in Prawn[1], a pure Ruby PDF generation library.
36
+
37
+
38
+ However, it may be useful to others, so we have made it available as a gem in
39
+
40
+ its own right.
41
+
42
+
43
+ [0] https://github.com/yob/pdf-reader
44
+
45
+ [1] https://github.com/sandal/prawn
46
+
47
+ '
48
+ email:
49
+ - gregory.t.brown@gmail.com
50
+ - brad@bradediger.com
51
+ - dnelson77@gmail.com
52
+ - greenberg@entryway.net
53
+ - jimmy@deefa.com
54
+ executables: []
55
+ extensions: []
56
+ extra_rdoc_files:
57
+ - CHANGELOG
58
+ - README
59
+ files:
60
+ - lib/pdf/inspector.rb
61
+ - lib/pdf/inspector/graphics.rb
62
+ - lib/pdf/inspector/extgstate.rb
63
+ - lib/pdf/inspector/page.rb
64
+ - lib/pdf/inspector/text.rb
65
+ - lib/pdf/inspector/xobject.rb
66
+ - CHANGELOG
67
+ - README
68
+ has_rdoc: true
69
+ homepage: https://github.com/sandal/pdf-inspector
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --title
74
+ - PDF::Inspector
75
+ - --main
76
+ - README
77
+ - -q
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.6.2
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: A tool for analyzing PDF output
98
+ test_files: []