Start reworking internals to support other Game Crafter part types.

This commit is contained in:
John Bintz 2014-06-21 23:06:53 -04:00
parent 40121e6b6a
commit 8f68703e5b
10 changed files with 117 additions and 111 deletions

View File

@ -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:

View File

@ -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

View File

@ -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

43
lib/svggvs/page/base.rb Normal file
View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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