prawn-templates 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 854ad9427cb3c48e39e1bfd05e87bf27f3acf2be
4
- data.tar.gz: 5d1ce54e939337e8e1940ad23d2687b723d5a602
3
+ metadata.gz: a07d63a03e5331fe73c2df7df5cb23b9fc1c42a2
4
+ data.tar.gz: 252d06574afa170bc89c6c3560de1933bd2b2195
5
5
  SHA512:
6
- metadata.gz: de7b977b63ba27bfe0a560c18b89f08ea56e37367eb881fc96f7d2d69636cafcd35ee091e351363a9273e5ed70f50f37b5f2196dd76402167f707621fadd9e3f
7
- data.tar.gz: 1fe9ad6fa76e278d23c1de1371ff0a5be0934bfe01e87845cdda6831aeffe591d7da58cc774cf9151b2b32fc83c747846d27c1d6d1eb2d02f75ac3e81eca6ff4
6
+ metadata.gz: 7640f9e16b2ea3a256e550cf459f510a49be182788c3de6b763e2f78cf12d1bbf999b79a2c858b25751337a7b13d616b372e26f4c4a2829724e2de190ae5fd9c
7
+ data.tar.gz: 13cd410a9d90943de5d6162e38a64fa1d41fc560a885c9d20c3c0a2b895d57e0c13f391ddea592076e370c1a4bd959b1dce3af35a02d931cac2efc093681f28b
@@ -0,0 +1,35 @@
1
+ module PDF
2
+ module Core
3
+ class DocumentState #:nodoc:
4
+ def initialize(options)
5
+ normalize_metadata(options)
6
+
7
+ if options[:template]
8
+ if options[:print_scaling]
9
+ @store = PDF::Core::ObjectStore.new(:template => options[:template], :print_scaling => options[:print_scaling])
10
+ else
11
+ @store = PDF::Core::ObjectStore.new(:template => options[:template])
12
+ end
13
+ @store.info.data.merge!(options[:info]) if options[:info]
14
+ else
15
+ if options[:print_scaling]
16
+ @store = PDF::Core::ObjectStore.new(:info => options[:info], :print_scaling => options[:print_scaling])
17
+ else
18
+ @store = PDF::Core::ObjectStore.new(:info => options[:info])
19
+ end
20
+ end
21
+
22
+ @version = 1.3
23
+ @pages = []
24
+ @page = nil
25
+ @trailer = options.fetch(:trailer, {})
26
+ @compress = options.fetch(:compress, false)
27
+ @encrypt = options.fetch(:encrypt, false)
28
+ @encryption_key = options[:encryption_key]
29
+ @skip_encoding = options.fetch(:skip_encoding, false)
30
+ @before_render_callbacks = []
31
+ @on_page_create_callback = nil
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ module PDF
2
+ module Core
3
+ module Errors
4
+ # This error is raised when object store fails to load a template file
5
+ TemplateError = Class.new(StandardError)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ module PDF
2
+ module Core
3
+ class ObjectStore #:nodoc:
4
+ def initialize(opts = {})
5
+ @objects = {}
6
+ @identifiers = []
7
+
8
+ load_file(opts[:template]) if opts[:template]
9
+
10
+ @info ||= ref(opts[:info] || {}).identifier
11
+ @root ||= ref(:Type => :Catalog).identifier
12
+ if opts[:print_scaling] == :none
13
+ root.data[:ViewerPreferences] = { :PrintScaling => :None }
14
+ end
15
+ if pages.nil?
16
+ root.data[:Pages] = ref(:Type => :Pages, :Count => 0, :Kids => [])
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ module PDF
2
+ module Core
3
+ class Page #:nodoc:
4
+ # As per the PDF spec, each page can have multiple content streams. This will
5
+ # add a fresh, empty content stream this the page, mainly for use in loading
6
+ # template files.
7
+ #
8
+ def new_content_stream
9
+ return if in_stamp_stream?
10
+
11
+ unless dictionary.data[:Contents].is_a?(Array)
12
+ dictionary.data[:Contents] = [content]
13
+ end
14
+ @content = document.ref({})
15
+ dictionary.data[:Contents] << document.state.store[@content]
16
+ document.open_graphics_state
17
+ end
18
+
19
+ def init_from_object(options)
20
+ @dictionary = options[:object_id].to_i
21
+ dictionary.data[:Parent] = document.state.store.pages if options[:page_template]
22
+
23
+ unless dictionary.data[:Contents].is_a?(Array) # content only on leafs
24
+ @content = dictionary.data[:Contents].identifier
25
+ end
26
+
27
+ @stamp_stream = nil
28
+ @stamp_dictionary = nil
29
+ @imported_page = true
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module Prawn
2
+ class Document
3
+ module Internals
4
+ delegate [ :open_graphics_state ] => :renderer
5
+
6
+ # adds a new, empty content stream to each page. Used in templating so
7
+ # that imported content streams can be left pristine
8
+ #
9
+ def fresh_content_streams(options = {})
10
+ (1..page_count).each do |i|
11
+ go_to_page i
12
+ state.page.new_content_stream
13
+ apply_margin_options(options)
14
+ generate_margin_box
15
+ use_graphic_settings(options[:template])
16
+ forget_text_rendering_mode!
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,14 @@
1
1
  # This is free software. See LICENSE and COPYING files for details.
2
2
  require 'pdf/reader'
3
+ require 'pdf/core'
4
+ require 'prawn/text'
5
+
6
+ require_relative "../pdf/core/document_state"
7
+ require_relative "../pdf/core/errors"
8
+ require_relative "../pdf/core/object_store"
9
+ require_relative "../pdf/core/page"
10
+ require_relative "text"
11
+ require_relative "document/internals"
3
12
 
4
13
  module Prawn
5
14
  # @private
@@ -10,27 +19,30 @@ module Prawn
10
19
  fresh_content_streams(options)
11
20
  go_to_page(1)
12
21
  end
13
-
22
+
14
23
  ## FIXME: This is going to be terribly brittle because
15
24
  # it copy-pastes the start_new_page method. But at least
16
25
  # it should only run when templates are used.
17
-
18
26
  def start_new_page(options = {})
19
27
  return super unless options[:template]
20
28
 
21
29
  if last_page = state.page
22
30
  last_page_size = last_page.size
23
31
  last_page_layout = last_page.layout
24
- last_page_margins = last_page.margins
32
+ last_page_margins = last_page.margins.dup
25
33
  end
26
34
 
27
- page_options = {:size => options[:size] || last_page_size,
28
- :layout => options[:layout] || last_page_layout,
29
- :margins => last_page_margins}
35
+ page_options = {
36
+ :size => options[:size] || last_page_size,
37
+ :layout => options[:layout] || last_page_layout,
38
+ :margins => last_page_margins
39
+ }
30
40
  if last_page
31
41
  new_graphic_state = last_page.graphic_state.dup if last_page.graphic_state
32
- #erase the color space so that it gets reset on new page for fussy pdf-readers
42
+
43
+ # erase the color space so that it gets reset on new page for fussy pdf-readers
33
44
  new_graphic_state.color_space = {} if new_graphic_state
45
+
34
46
  page_options.merge!(:graphic_state => new_graphic_state)
35
47
  end
36
48
 
@@ -93,13 +105,9 @@ module Prawn
93
105
  elsif File.file?(input.to_s)
94
106
  StringIO.new(File.binread(input.to_s))
95
107
  else
96
- raise ArgumentError, "input must be an IO-like object or a filename"
108
+ fail ArgumentError, "input must be an IO-like object or a filename"
97
109
  end
98
110
 
99
- # unless File.file?(filename)
100
- # raise ArgumentError, "#{filename} does not exist"
101
- # end
102
-
103
111
  hash = indexed_hash(input, io)
104
112
  ref = hash.page_references[page_num - 1]
105
113
 
@@ -174,7 +182,7 @@ module Prawn
174
182
  def load_file(template)
175
183
  unless (template.respond_to?(:seek) && template.respond_to?(:read)) ||
176
184
  File.file?(template)
177
- raise ArgumentError, "#{template} does not exist"
185
+ fail ArgumentError, "#{template} does not exist"
178
186
  end
179
187
 
180
188
  hash = PDF::Reader::ObjectHash.new(template)
@@ -184,7 +192,7 @@ module Prawn
184
192
 
185
193
  if hash.trailer[:Encrypt]
186
194
  msg = "Template file is an encrypted PDF, it can't be used as a template"
187
- raise PDF::Core::Errors::TemplateError, msg
195
+ fail PDF::Core::Errors::TemplateError, msg
188
196
  end
189
197
 
190
198
  if src_info
@@ -212,12 +220,12 @@ module Prawn
212
220
  @loaded_objects ||= {}
213
221
  case object
214
222
  when ::Hash then
215
- object.each { |key,value| object[key] = load_object_graph(hash, value) }
223
+ object.each { |key, value| object[key] = load_object_graph(hash, value) }
216
224
  object
217
225
  when Array then
218
- object.map { |item| load_object_graph(hash, item)}
226
+ object.map { |item| load_object_graph(hash, item) }
219
227
  when PDF::Reader::Reference then
220
- unless @loaded_objects.has_key?(object.id)
228
+ unless @loaded_objects.key?(object.id)
221
229
  @loaded_objects[object.id] = ref(nil)
222
230
  new_obj = load_object_graph(hash, hash[object])
223
231
  if new_obj.kind_of?(PDF::Reader::Stream)
@@ -0,0 +1,25 @@
1
+ module Prawn
2
+ module Text #:nodoc:
3
+ def text_rendering_mode(mode = nil)
4
+ return (defined?(@text_rendering_mode) && @text_rendering_mode || :fill) if mode.nil?
5
+ unless MODES.key?(mode)
6
+ fail ArgumentError, "mode must be between one of #{MODES.keys.join(', ')} (#{mode})"
7
+ end
8
+ original_mode = self.text_rendering_mode
9
+ if original_mode == :unknown
10
+ original_mode = :fill
11
+ add_content "\n#{MODES[:fill]} Tr"
12
+ end
13
+
14
+ if original_mode == mode
15
+ yield
16
+ else
17
+ @text_rendering_mode = mode
18
+ add_content "\n#{MODES[mode]} Tr"
19
+ yield
20
+ add_content "\n#{MODES[original_mode]} Tr"
21
+ @text_rendering_mode = original_mode
22
+ end
23
+ end
24
+ end
25
+ end
@@ -3,19 +3,21 @@ Gem::Specification.new do |spec|
3
3
  spec.version = File.read(File.expand_path('VERSION', File.dirname(__FILE__))).strip
4
4
  spec.platform = Gem::Platform::RUBY
5
5
  spec.summary = "Prawn::Templates allows using PDFs as templates in Prawn"
6
- spec.files = Dir.glob("{lib}/**/**/*") +
7
- ["prawn-templates.gemspec"]
6
+ spec.files = Dir.glob("{lib}/**/**/*") + ["prawn-templates.gemspec"]
8
7
  spec.require_path = "lib"
9
8
  spec.required_ruby_version = '>= 1.9.3'
10
9
  spec.required_rubygems_version = ">= 1.3.6"
10
+ spec.licenses = %w(PRAWN GPL-2.0 GPL-3.0)
11
11
 
12
- spec.authors = ["Gregory Brown","Brad Ediger","Daniel Nelson","Jonathan Greenberg","James Healy"]
13
- spec.email = ["gregory.t.brown@gmail.com","brad@bradediger.com","dnelson@bluejade.com","greenberg@entryway.net","jimmy@deefa.com"]
12
+ spec.authors = ["Gregory Brown", "Brad Ediger", "Daniel Nelson", "Jonathan Greenberg", "James Healy", "Burkhard Vogel"]
13
+ spec.email = ["gregory.t.brown@gmail.com", "brad@bradediger.com", "dnelson@bluejade.com", "greenberg@entryway.net", "jimmy@deefa.com", "b.vogel@buddyandselly.com"]
14
14
  spec.add_dependency('pdf-reader', '~>1.3')
15
- spec.add_dependency('prawn', '>= 0.15.0')
16
- spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
15
+ spec.add_dependency('prawn', '>= 2.1.0')
16
+ spec.add_dependency('pdf-core', '>= 0.5.0')
17
+ spec.add_development_dependency('pdf-inspector', '~> 1.2.0')
17
18
  spec.add_development_dependency('rspec')
18
19
  spec.add_development_dependency('rake')
19
- spec.homepage = "http://prawn.majesticseacreature.com"
20
+ spec.add_development_dependency('rubocop', '0.30.1')
21
+ spec.homepage = "https://github.com/prawnpdf/prawn-templates"
20
22
  spec.description = "Prawn::Templates allows using PDFs as templates in Prawn"
21
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Brown
@@ -9,10 +9,11 @@ authors:
9
9
  - Daniel Nelson
10
10
  - Jonathan Greenberg
11
11
  - James Healy
12
+ - Burkhard Vogel
12
13
  autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
- date: 2014-02-21 00:00:00.000000000 Z
16
+ date: 2016-04-03 00:00:00.000000000 Z
16
17
  dependencies:
17
18
  - !ruby/object:Gem::Dependency
18
19
  name: pdf-reader
@@ -34,28 +35,42 @@ dependencies:
34
35
  requirements:
35
36
  - - ">="
36
37
  - !ruby/object:Gem::Version
37
- version: 0.15.0
38
+ version: 2.1.0
38
39
  type: :runtime
39
40
  prerelease: false
40
41
  version_requirements: !ruby/object:Gem::Requirement
41
42
  requirements:
42
43
  - - ">="
43
44
  - !ruby/object:Gem::Version
44
- version: 0.15.0
45
+ version: 2.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: pdf-core
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.5.0
53
+ type: :runtime
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.5.0
45
60
  - !ruby/object:Gem::Dependency
46
61
  name: pdf-inspector
47
62
  requirement: !ruby/object:Gem::Requirement
48
63
  requirements:
49
64
  - - "~>"
50
65
  - !ruby/object:Gem::Version
51
- version: 1.1.0
66
+ version: 1.2.0
52
67
  type: :development
53
68
  prerelease: false
54
69
  version_requirements: !ruby/object:Gem::Requirement
55
70
  requirements:
56
71
  - - "~>"
57
72
  - !ruby/object:Gem::Version
58
- version: 1.1.0
73
+ version: 1.2.0
59
74
  - !ruby/object:Gem::Dependency
60
75
  name: rspec
61
76
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +99,20 @@ dependencies:
84
99
  - - ">="
85
100
  - !ruby/object:Gem::Version
86
101
  version: '0'
102
+ - !ruby/object:Gem::Dependency
103
+ name: rubocop
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '='
107
+ - !ruby/object:Gem::Version
108
+ version: 0.30.1
109
+ type: :development
110
+ prerelease: false
111
+ version_requirements: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '='
114
+ - !ruby/object:Gem::Version
115
+ version: 0.30.1
87
116
  description: Prawn::Templates allows using PDFs as templates in Prawn
88
117
  email:
89
118
  - gregory.t.brown@gmail.com
@@ -91,14 +120,24 @@ email:
91
120
  - dnelson@bluejade.com
92
121
  - greenberg@entryway.net
93
122
  - jimmy@deefa.com
123
+ - b.vogel@buddyandselly.com
94
124
  executables: []
95
125
  extensions: []
96
126
  extra_rdoc_files: []
97
127
  files:
128
+ - lib/pdf/core/document_state.rb
129
+ - lib/pdf/core/errors.rb
130
+ - lib/pdf/core/object_store.rb
131
+ - lib/pdf/core/page.rb
132
+ - lib/prawn/document/internals.rb
98
133
  - lib/prawn/templates.rb
134
+ - lib/prawn/text.rb
99
135
  - prawn-templates.gemspec
100
- homepage: http://prawn.majesticseacreature.com
101
- licenses: []
136
+ homepage: https://github.com/prawnpdf/prawn-templates
137
+ licenses:
138
+ - PRAWN
139
+ - GPL-2.0
140
+ - GPL-3.0
102
141
  metadata: {}
103
142
  post_install_message:
104
143
  rdoc_options: []
@@ -116,9 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
155
  version: 1.3.6
117
156
  requirements: []
118
157
  rubyforge_project:
119
- rubygems_version: 2.2.0
158
+ rubygems_version: 2.5.1
120
159
  signing_key:
121
160
  specification_version: 4
122
161
  summary: Prawn::Templates allows using PDFs as templates in Prawn
123
162
  test_files: []
124
- has_rdoc: