diff --git a/README.md b/README.md index aac2093..9579b1b 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,14 @@ The following Card Size and Target settings set these to the following: * PNG Export Width: 825 * PDF Card Size: 750x1050 * PDF DPI: 300 + * Small Square Tile + * PNG Export Width: 600 + * PDF Card Size: 675x675 + * PDF DPI: 300 + * Square Shard + * PNG Export Width: 225 + * PDF Card Size: 300x300 + * PDF DPI: 300 Create a `Cardfile` in your working directory. It should look something like this: diff --git a/bin/svggvs b/bin/svggvs index 5db7b0d..a23cd90 100755 --- a/bin/svggvs +++ b/bin/svggvs @@ -83,12 +83,12 @@ MSG end end - CARDS_PER_PAGE = 9 - desc "pdf", "Create PDF of card images" def pdf pngs + pdf_obj = context.session.pdf_class.new(card_size: context.session.pdf_card_size) + trimmed_pngs = Parallel.map(@exported_pngs) do |png| tmp_target = tmp_target_for(png) @@ -97,23 +97,19 @@ MSG tmp_target end - png_slices = trimmed_pngs.each_slice(CARDS_PER_PAGE) + png_slices = trimmed_pngs.each_slice(pdf_obj.cards_per_page) - page_count = trimmed_pngs.length / CARDS_PER_PAGE + page_count = trimmed_pngs.length / pdf_obj.cards_per_page placeholder = tmp_target_for("placeholder.png") system %{convert -size #{context.session.pdf_card_size} xc:white #{placeholder}} - pdf_obj = SVGGVS::PDF.new(card_size: context.session.pdf_card_size) - pages = Parallel.map(png_slices.each_with_index) do |files, page_index| - tmp_pdf_png_target = tmp_path.join("page%05d.pdf" % page_index) tmp_pdf_target = tmp_path.join("page%05d.pdf" % page_index) - files += Array.new(9 - files.length, placeholder) + files += Array.new(pdf_obj.cards_per_page - files.length, placeholder) - system %{montage -density #{context.session.pdf_dpi} -geometry +0+0 #{files.join(' ')} #{tmp_pdf_png_target}} - system %{convert -density #{context.session.pdf_dpi} #{tmp_pdf_png_target} -bordercolor white -border #{SVGGVS::PDF.border_size} #{pdf_obj.generate_crop_mark_draws.join(' ')} #{tmp_pdf_target}}.tap { |o| p o } + system %{montage -density #{context.session.pdf_dpi} -tile #{pdf_obj.montage_tiling} -geometry +0+0 #{files.join(' ')} #{tmp_pdf_target}} tmp_pdf_target end @@ -123,7 +119,7 @@ MSG tmp_pdf_target = tmp_path.join("backs.pdf") system %{convert #{context.session.card_back} -gravity Center -crop #{context.session.pdf_card_size}+0+0 +repage #{tmp_target}} - system %{montage -density #{context.session.pdf_dpi} -geometry +0+0 #{Array.new(9, tmp_target).join(' ')} #{tmp_pdf_target}} + system %{montage -density #{context.session.pdf_dpi} -geometry +0+0 #{Array.new(pdf_obj.cards_per_page, tmp_target).join(' ')} #{tmp_pdf_target}} pages.length.times do |page| pages << tmp_pdf_target diff --git a/lib/svggvs.rb b/lib/svggvs.rb index f66c5b6..39962ab 100644 --- a/lib/svggvs.rb +++ b/lib/svggvs.rb @@ -3,7 +3,7 @@ require_relative './svggvs/target' require_relative './svggvs/context' require_relative './svggvs/session' require_relative './svggvs/data_source' -require_relative './svggvs/pdf' +require_relative './svggvs/page/base' module SVGGVS end diff --git a/lib/svggvs/page/base.rb b/lib/svggvs/page/base.rb new file mode 100644 index 0000000..0480d05 --- /dev/null +++ b/lib/svggvs/page/base.rb @@ -0,0 +1,43 @@ +module SVGGVS + module Page + class Base + def initialize(options) + @options = options + end + + def cards_per_page + self.class::CARDS_X * self.class::CARDS_Y + end + + def montage_tiling + [ self.class::CARDS_X, self.class::CARDS_Y ].join('x') + end + + private + def card_width + card_size.first + end + + def card_height + card_size.last + end + + def page_height + card_height * cards_per_width + end + + def page_width + card_width * cards_per_height + end + + def card_size + @card_size ||= @options[:card_size].split('x').collect(&:to_i) + end + end + end +end + +require_relative './letter/poker' +require_relative './letter/small_shard' +require_relative './letter/small_square_tile' + diff --git a/lib/svggvs/page/letter/poker.rb b/lib/svggvs/page/letter/poker.rb new file mode 100644 index 0000000..34b24ba --- /dev/null +++ b/lib/svggvs/page/letter/poker.rb @@ -0,0 +1,13 @@ +require 'svggvs/page/base' + +module SVGGVS + module Page + module Letter + class Poker < SVGGVS::Page::Base + CARDS_X = 3 + CARDS_Y = 3 + end + end + end +end + diff --git a/lib/svggvs/page/letter/small_shard.rb b/lib/svggvs/page/letter/small_shard.rb new file mode 100644 index 0000000..35f86ac --- /dev/null +++ b/lib/svggvs/page/letter/small_shard.rb @@ -0,0 +1,13 @@ +require 'svggvs/page/base' + +module SVGGVS + module Page + module Letter + class SmallShard < SVGGVS::Page::Base + CARDS_X = 11 + CARDS_Y = 14 + end + end + end +end + diff --git a/lib/svggvs/page/letter/small_square_tile.rb b/lib/svggvs/page/letter/small_square_tile.rb new file mode 100644 index 0000000..51e7dce --- /dev/null +++ b/lib/svggvs/page/letter/small_square_tile.rb @@ -0,0 +1,13 @@ +require 'svggvs/page/base' + +module SVGGVS + module Page + module Letter + class SmallSquareTile < SVGGVS::Page::Base + CARDS_X = 4 + CARDS_Y = 5 + end + end + end +end + diff --git a/lib/svggvs/pdf.rb b/lib/svggvs/pdf.rb index 6fbbff7..288d3ba 100644 --- a/lib/svggvs/pdf.rb +++ b/lib/svggvs/pdf.rb @@ -1,57 +1,5 @@ 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 diff --git a/lib/svggvs/session.rb b/lib/svggvs/session.rb index 3308b63..8d91570 100644 --- a/lib/svggvs/session.rb +++ b/lib/svggvs/session.rb @@ -74,6 +74,10 @@ module SVGGVS end end + def pdf_class + @pdf_class ||= ("SVGGVS::Page::Letter::" + @card_size.spunderscore.camelize).constantize + end + EXPORT_DEFAULTS = { :poker => { :the_game_crafter => { @@ -81,7 +85,21 @@ module SVGGVS :pdf_dpi => 300, :png_export_width => 825 } - } + }, + :small_square_tile => { + :the_game_crafter => { + :pdf_card_size => '675x675', + :pdf_dpi => 300, + :png_export_width => 600 + } + }, + :square_shard => { + :the_game_crafter => { + :pdf_card_size => '300x300', + :pdf_dpi => 300, + :png_export_width => 225 + } + }, }.freeze end end diff --git a/spec/svggvs/pdf_spec.rb b/spec/svggvs/pdf_spec.rb deleted file mode 100644 index 976dc98..0000000 --- a/spec/svggvs/pdf_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require_relative '../spec_helper' -require 'svggvs/pdf' -require 'digest/md5' - -describe SVGGVS::PDF do - subject { SVGGVS::PDF.new(options) } - - let(:options) { - { card_size: '100x100' } - } - - describe '#page_size_with_crop_marks' do - it "should have the right size" do - subject.page_size_with_crop_marks.should be == "340x340" - end - end - - describe '#generate_crop_mark_directives' do - let(:result) { - [ - "20,0 20,20", - "20,320 20,340", - "120,0 120,20", - "120,320 120,340", - "220,0 220,20", - "220,320 220,340", - "320,0 320,20", - "320,20 340,20", - "320,120 340,120", - "320,220 340,220", - "320,320 320,340", - "320,320 340,320", - "0,20 20,20", - "0,120 20,120", - "0,220 20,220", - "0,320 20,320", - ] - } - - it 'should create correct definitions' do - subject.generate_crop_mark_directives.each { |coords| - result.should include(coords) - } - end - end -end