Sha256: a8c6351d7b03e8c53b67f7003c50525d91c459e0778ebd7d10f919101f6cebb3

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

module SVGGVS
  CROP_MARK_SIZE = 20.freeze

  class PDF
    def initialize(options)
      @options = options
    end

    def self.border_size
      ([ CROP_MARK_SIZE ] * 2).join('x')
    end

    def page_size_with_crop_marks
      [ card_width * 3, card_height * 3 ].collect { |size| size + CROP_MARK_SIZE * 2 }.join('x')
    end

    def generate_crop_mark_directives
      (0..3).collect { |index|
        pos_x = CROP_MARK_SIZE + index * card_width
        pos_y = CROP_MARK_SIZE + index * card_height

        [ [ 0 ], [ CROP_MARK_SIZE + page_height ] ].collect { |size|
          [ pos_x ] + size + [ pos_x, size.first + CROP_MARK_SIZE ]
        } +
        [ [ 0 ], [ CROP_MARK_SIZE + page_width ] ].collect { |size|
          size + [ pos_y ] + [ size.first + CROP_MARK_SIZE, pos_y ]
        }
      }.flatten(1).collect { |sx, sy, ex, ey| "#{sx},#{sy} #{ex},#{ey}" }
    end

    def generate_crop_mark_draws
      generate_crop_mark_directives.collect { |coords| %{-stroke black -strokewidth 3 -draw "line #{coords}"} }
    end

    private
    def card_width
      card_size.first
    end

    def card_height
      card_size.last
    end

    def page_height
      card_height * 3
    end

    def page_width
      card_width * 3
    end

    def card_size
      @card_size ||= @options[:card_size].split('x').collect(&:to_i)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
svggvs-0.0.10.1 lib/svggvs/pdf.rb
svggvs-0.0.10 lib/svggvs/pdf.rb
svggvs-0.0.9 lib/svggvs/pdf.rb
svggvs-0.0.8 lib/svggvs/pdf.rb
svggvs-0.0.7 lib/svggvs/pdf.rb
svggvs-0.0.6 lib/svggvs/pdf.rb