File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -22,18 +22,30 @@ def initialize(document, options = {})
2222 end
2323 end
2424
25+ # If :Contents is a reference to an array, returns the resolved reference.
26+ # Otherwise, makes sure :Contents is an array.
27+ def ensure_contents_array
28+ contents = dictionary . data [ :Contents ]
29+ if contents . is_a? ( PDF ::Core ::Reference ) && contents . data . is_a? ( Array )
30+ contents = contents . data
31+ else
32+ # Ensure contents is an array.
33+ contents = Array ( contents )
34+ dictionary . data [ :Contents ] = contents
35+ end
36+ contents
37+ end
38+
2539 # As per the PDF spec, each page can have multiple content streams. This
2640 # will add a fresh, empty content stream this the page, mainly for use in
2741 # loading template files.
2842 #
2943 def new_content_stream
3044 return if in_stamp_stream?
3145
32- unless dictionary . data [ :Contents ] . is_a? ( Array )
33- dictionary . data [ :Contents ] = [ content ]
34- end
3546 @content = document . ref ( { } )
36- dictionary . data [ :Contents ] << document . state . store [ @content ]
47+ contents = ensure_contents_array
48+ contents << document . state . store [ @content ]
3749 document . open_graphics_state
3850 end
3951
You can’t perform that action at this time.
0 commit comments