prawn-templates 0.1.1 → 0.1.2

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
- SHA1:
3
- metadata.gz: 4675a2da68897899907ad2cd9ca41f965795c529
4
- data.tar.gz: dad0a841287c217ba076dcdf054d8f406a5921b2
2
+ SHA256:
3
+ metadata.gz: 7f3296b580f0225c618f9a1dce52ae6a5eee1b1b3f6629bb9681f2df39cb0e9b
4
+ data.tar.gz: 060c30df02ead5cf014dc794092ef59ae1af77d8335da3829f8047a6dce181f1
5
5
  SHA512:
6
- metadata.gz: 3f26464256ebf5e75af2744dac364cc02299f81953a3f2edd8298987d9ec8e81abadc15b97bc838dad6feade30572aa9b7f9f21fa1cc7434ed86113777c38dc3
7
- data.tar.gz: 52fa48e4bdc6371d89fbf2a5ddebfbad0867465f65eae7458f0021e8e140c659c47fe673454482eb25a521d8be32b9f5b169e03f91ee61cff705140bb77eaee9
6
+ metadata.gz: 45937095668db1620f1483fffafc0a07b0f83f2bbb31203bedda29b55b54411a8f4aedfccea4934a680ab634da73bc86df106777aa94cd4e6aa722d54272148c
7
+ data.tar.gz: 9a7b8c9897b741bc65560e908f63709fd40b4d0a502eed20ad7a2d0f36ccb7f5867d677daafb81be8b6335eaa5c4cd5320f9741e44070e4a2621588debc8095b
@@ -22,6 +22,24 @@ module PDF
22
22
  end
23
23
  end
24
24
 
25
+ # Prepend a content stream containing 'q',
26
+ # and append a content stream containing 'Q'.
27
+ # This ensures that prawn has a pristine graphics state
28
+ # before it starts adding content.
29
+ def wrap_graphics_state
30
+ dictionary.data[:Contents] = Array(dictionary.data[:Contents])
31
+
32
+ # Save graphics context
33
+ @content = document.ref({})
34
+ dictionary.data[:Contents].unshift(document.state.store[@content])
35
+ document.add_content 'q'
36
+
37
+ # Restore graphics context
38
+ @content = document.ref({})
39
+ dictionary.data[:Contents] << document.state.store[@content]
40
+ document.add_content 'Q'
41
+ end
42
+
25
43
  # As per the PDF spec, each page can have multiple content streams. This
26
44
  # will add a fresh, empty content stream this the page, mainly for use in
27
45
  # loading template files.
@@ -29,9 +47,7 @@ module PDF
29
47
  def new_content_stream
30
48
  return if in_stamp_stream?
31
49
 
32
- unless dictionary.data[:Contents].is_a?(Array)
33
- dictionary.data[:Contents] = [content]
34
- end
50
+ dictionary.data[:Contents] = Array(dictionary.data[:Contents])
35
51
  @content = document.ref({})
36
52
  dictionary.data[:Contents] << document.state.store[@content]
37
53
  document.open_graphics_state
@@ -45,7 +61,11 @@ module PDF
45
61
 
46
62
  alias __dimensions dimensions if method_defined? :dimensions
47
63
  def dimensions
48
- return inherited_dictionary_value(:MediaBox) if imported_page?
64
+ if imported_page?
65
+ media_box = inherited_dictionary_value(:MediaBox)
66
+ return media_box.data if media_box.is_a?(PDF::Core::Reference)
67
+ return media_box
68
+ end
49
69
 
50
70
  coords = PDF::Core::PageGeometry::SIZES[size] || size
51
71
  [0, 0] +
@@ -100,7 +120,7 @@ module PDF
100
120
  Contents: content
101
121
  )
102
122
 
103
- resources[:ProcSet] = [:PDF, :Text, :ImageB, :ImageC, :ImageI]
123
+ resources[:ProcSet] = %i[PDF Text ImageB ImageC ImageI]
104
124
  end
105
125
  end
106
126
  end
@@ -3,12 +3,18 @@ module Prawn
3
3
  module Internals
4
4
  delegate [:open_graphics_state] => :renderer
5
5
 
6
+ # wraps existing content streams with two new streams
7
+ # containing just 'q' and 'Q'. This ensures that prawn
8
+ # has a pristine graphics context before it starts adding content.
9
+ #
6
10
  # adds a new, empty content stream to each page. Used in templating so
7
11
  # that imported content streams can be left pristine
8
12
  #
9
13
  def fresh_content_streams(options = {})
10
14
  (1..page_count).each do |i|
11
15
  go_to_page i
16
+
17
+ state.page.wrap_graphics_state
12
18
  state.page.new_content_stream
13
19
  apply_margin_options(options)
14
20
  generate_margin_box
@@ -130,7 +130,6 @@ module Prawn
130
130
  load_object_graph(hash, ref).identifier
131
131
  )
132
132
  end
133
-
134
133
  rescue PDF::Reader::MalformedPDFError,
135
134
  PDF::Reader::InvalidObjectError => e
136
135
  msg = 'Error reading template file. If you are sure it\'s a valid PDF,'\
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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Brown
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-03-24 00:00:00.000000000 Z
16
+ date: 2019-11-21 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: pdf-reader
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: 1.3.6
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 2.6.10
163
+ rubygems_version: 2.7.9
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: Prawn::Templates allows using PDFs as templates in Prawn