prawn-templates 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/pdf/core/page.rb +25 -5
- data/lib/prawn/document/internals.rb +6 -0
- data/lib/prawn/templates.rb +0 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 7f3296b580f0225c618f9a1dce52ae6a5eee1b1b3f6629bb9681f2df39cb0e9b
         | 
| 4 | 
            +
              data.tar.gz: 060c30df02ead5cf014dc794092ef59ae1af77d8335da3829f8047a6dce181f1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 45937095668db1620f1483fffafc0a07b0f83f2bbb31203bedda29b55b54411a8f4aedfccea4934a680ab634da73bc86df106777aa94cd4e6aa722d54272148c
         | 
| 7 | 
            +
              data.tar.gz: 9a7b8c9897b741bc65560e908f63709fd40b4d0a502eed20ad7a2d0f36ccb7f5867d677daafb81be8b6335eaa5c4cd5320f9741e44070e4a2621588debc8095b
         | 
    
        data/lib/pdf/core/page.rb
    CHANGED
    
    | @@ -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 | 
            -
                     | 
| 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 | 
            -
                     | 
| 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] = [ | 
| 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
         | 
    
        data/lib/prawn/templates.rb
    CHANGED
    
    
    
        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. | 
| 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:  | 
| 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. | 
| 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
         |