svggvs 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/bin/svggvs CHANGED
@@ -46,6 +46,8 @@ module SVGGVS
46
46
  end
47
47
  end
48
48
 
49
+ CARDS_PER_PAGE = 9
50
+
49
51
  desc "pdf", "Create PDF of card images"
50
52
  def pdf
51
53
  pngs
@@ -58,19 +60,23 @@ module SVGGVS
58
60
  tmp_target
59
61
  end
60
62
 
61
- png_slices = trimmed_pngs.each_slice(9)
63
+ png_slices = trimmed_pngs.each_slice(CARDS_PER_PAGE)
62
64
 
63
- page_count = trimmed_pngs.length / 9
65
+ page_count = trimmed_pngs.length / CARDS_PER_PAGE
64
66
 
65
67
  placeholder = tmp_target_for("placeholder.png")
66
68
  system %{convert -size #{context.session.pdf_card_size} xc:white #{placeholder}}
67
69
 
70
+ pdf_obj = SVGGVS::PDF.new(card_size: context.session.pdf_card_size)
71
+
68
72
  pages = Parallel.map(png_slices.each_with_index) do |files, page_index|
73
+ tmp_pdf_png_target = tmp_path.join("page%05d.pdf" % page_index)
69
74
  tmp_pdf_target = tmp_path.join("page%05d.pdf" % page_index)
70
75
 
71
76
  files += Array.new(9 - files.length, placeholder)
72
77
 
73
- system %{montage -density #{context.session.pdf_dpi} -geometry +0+0 #{files.join(' ')} #{tmp_pdf_target}}
78
+ system %{montage -density #{context.session.pdf_dpi} -geometry +0+0 #{files.join(' ')} #{tmp_pdf_png_target}}
79
+ 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 }
74
80
 
75
81
  tmp_pdf_target
76
82
  end
data/lib/svggvs/pdf.rb ADDED
@@ -0,0 +1,57 @@
1
+ module SVGGVS
2
+ CROP_MARK_SIZE = 20.freeze
3
+
4
+ class PDF
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def self.border_size
10
+ ([ CROP_MARK_SIZE ] * 2).join('x')
11
+ end
12
+
13
+ def page_size_with_crop_marks
14
+ [ card_width * 3, card_height * 3 ].collect { |size| size + CROP_MARK_SIZE * 2 }.join('x')
15
+ end
16
+
17
+ def generate_crop_mark_directives
18
+ (0..3).collect { |index|
19
+ pos_x = CROP_MARK_SIZE + index * card_width
20
+ pos_y = CROP_MARK_SIZE + index * card_height
21
+
22
+ [ [ 0 ], [ CROP_MARK_SIZE + page_height ] ].collect { |size|
23
+ [ pos_x ] + size + [ pos_x, size.first + CROP_MARK_SIZE ]
24
+ } +
25
+ [ [ 0 ], [ CROP_MARK_SIZE + page_width ] ].collect { |size|
26
+ size + [ pos_y ] + [ size.first + CROP_MARK_SIZE, pos_y ]
27
+ }
28
+ }.flatten(1).collect { |sx, sy, ex, ey| "#{sx},#{sy} #{ex},#{ey}" }
29
+ end
30
+
31
+ def generate_crop_mark_draws
32
+ generate_crop_mark_directives.collect { |coords| %{-stroke black -strokewidth 3 -draw "line #{coords}"} }
33
+ end
34
+
35
+ private
36
+ def card_width
37
+ card_size.first
38
+ end
39
+
40
+ def card_height
41
+ card_size.last
42
+ end
43
+
44
+ def page_height
45
+ card_height * 3
46
+ end
47
+
48
+ def page_width
49
+ card_width * 3
50
+ end
51
+
52
+ def card_size
53
+ @card_size ||= @options[:card_size].split('x').collect(&:to_i)
54
+ end
55
+ end
56
+ end
57
+
@@ -1,3 +1,3 @@
1
1
  module SVGGVS
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/svggvs.rb CHANGED
@@ -3,6 +3,7 @@ require_relative './svggvs/target'
3
3
  require_relative './svggvs/context'
4
4
  require_relative './svggvs/session'
5
5
  require_relative './svggvs/data_source'
6
+ require_relative './svggvs/pdf'
6
7
 
7
8
  module SVGGVS
8
9
  end
@@ -0,0 +1,2 @@
1
+ $: << File.expand_path('../lib', __FILE__)
2
+
@@ -0,0 +1,46 @@
1
+ require_relative '../spec_helper'
2
+ require 'svggvs/pdf'
3
+ require 'digest/md5'
4
+
5
+ describe SVGGVS::PDF do
6
+ subject { SVGGVS::PDF.new(options) }
7
+
8
+ let(:options) {
9
+ { card_size: '100x100' }
10
+ }
11
+
12
+ describe '#page_size_with_crop_marks' do
13
+ it "should have the right size" do
14
+ subject.page_size_with_crop_marks.should be == "340x340"
15
+ end
16
+ end
17
+
18
+ describe '#generate_crop_mark_directives' do
19
+ let(:result) {
20
+ [
21
+ "20,0 20,20",
22
+ "20,320 20,340",
23
+ "120,0 120,20",
24
+ "120,320 120,340",
25
+ "220,0 220,20",
26
+ "220,320 220,340",
27
+ "320,0 320,20",
28
+ "320,20 340,20",
29
+ "320,120 340,120",
30
+ "320,220 340,220",
31
+ "320,320 320,340",
32
+ "320,320 340,320",
33
+ "0,20 20,20",
34
+ "0,120 20,120",
35
+ "0,220 20,220",
36
+ "0,320 20,320",
37
+ ]
38
+ }
39
+
40
+ it 'should create correct definitions' do
41
+ subject.generate_crop_mark_directives.each { |coords|
42
+ result.should include(coords)
43
+ }
44
+ end
45
+ end
46
+ end
data/svggvs.gemspec CHANGED
@@ -22,4 +22,6 @@ Gem::Specification.new do |gem|
22
22
  gem.add_dependency 'parallel'
23
23
  gem.add_dependency 'roo'
24
24
  gem.add_dependency 'activesupport'
25
+
26
+ gem.add_development_dependency 'rspec'
25
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svggvs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &85515200 !ruby/object:Gem::Requirement
17
+ requirement: &77132620 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *85515200
25
+ version_requirements: *77132620
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: thor
28
- requirement: &85514990 !ruby/object:Gem::Requirement
28
+ requirement: &77132410 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *85514990
36
+ version_requirements: *77132410
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: parallel
39
- requirement: &85514780 !ruby/object:Gem::Requirement
39
+ requirement: &77132200 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *85514780
47
+ version_requirements: *77132200
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: roo
50
- requirement: &85514570 !ruby/object:Gem::Requirement
50
+ requirement: &77131990 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *85514570
58
+ version_requirements: *77131990
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: activesupport
61
- requirement: &85514360 !ruby/object:Gem::Requirement
61
+ requirement: &77131780 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,18 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *85514360
69
+ version_requirements: *77131780
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: &77131570 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *77131570
70
81
  description: Generate sets of card game cards using Inkscape templates and Ruby
71
82
  email:
72
83
  - john@coswellproductions.com
@@ -85,6 +96,7 @@ files:
85
96
  - lib/svggvs/context.rb
86
97
  - lib/svggvs/data_source.rb
87
98
  - lib/svggvs/file.rb
99
+ - lib/svggvs/pdf.rb
88
100
  - lib/svggvs/session.rb
89
101
  - lib/svggvs/target.rb
90
102
  - lib/svggvs/version.rb
@@ -94,6 +106,8 @@ files:
94
106
  - skel/images/cat.png.jpg
95
107
  - skel/images/dog.png.jpg
96
108
  - skel/template.svg
109
+ - spec/spec_helper.rb
110
+ - spec/svggvs/pdf_spec.rb
97
111
  - svggvs.gemspec
98
112
  has_rdoc: true
99
113
  homepage: ''
@@ -120,4 +134,6 @@ rubygems_version: 1.6.2
120
134
  signing_key:
121
135
  specification_version: 3
122
136
  summary: Generate sets of card game cards using Inkscape templates and Ruby
123
- test_files: []
137
+ test_files:
138
+ - spec/spec_helper.rb
139
+ - spec/svggvs/pdf_spec.rb