svggvs 0.0.10.1 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29c1636f89126ee8986e8cf114eed283f2440e6b
4
+ data.tar.gz: 709063890719e5e75b6dbcc0ab2a010e25cc5ef8
5
+ SHA512:
6
+ metadata.gz: 76f3ddacf87dc548dfe2b89a00acd18c4b5a3448f5957d6d73a1220d4fae399bf0cc3a23d87a60aa9bf0b4ccaad92cb3869b1caebbfb3b99a3c7503e65463c68
7
+ data.tar.gz: b74974b4db359bed549423b7c5e0fdc6c19b55b3388d239bb73ee878e48915d9a085566aab05f506169da1af5bb898e56e25f298c77accd214e14810751f16e4
data/README.md CHANGED
@@ -68,6 +68,14 @@ The following Card Size and Target settings set these to the following:
68
68
  * PNG Export Width: 825
69
69
  * PDF Card Size: 750x1050
70
70
  * PDF DPI: 300
71
+ * Small Square Tile
72
+ * PNG Export Width: 600
73
+ * PDF Card Size: 675x675
74
+ * PDF DPI: 300
75
+ * Square Shard
76
+ * PNG Export Width: 225
77
+ * PDF Card Size: 300x300
78
+ * PDF DPI: 300
71
79
 
72
80
  Create a `Cardfile` in your working directory. It should look something like this:
73
81
 
@@ -84,6 +92,10 @@ Create a `Cardfile` in your working directory. It should look something like thi
84
92
  # prepend this PDF to the outputted PDF (useful for game rules)
85
93
  # c.prepend_pdf = "rules.pdf"
86
94
 
95
+ # the cards are landscape, so rotate them counterclockwise
96
+ # after rendering in Inkscape
97
+ # c.orientation = :landscape
98
+
87
99
  c.data_source = "data.ods"
88
100
  end
89
101
  ```
data/bin/svggvs CHANGED
@@ -74,69 +74,79 @@ MSG
74
74
  ensure_tmp
75
75
 
76
76
  @exported_pngs = Parallel.map(context.individual_files.each_with_index) do |svg_file, index|
77
- target = Pathname(context.session.png_files_path % index)
77
+ target = Pathname(session.png_files_path % index)
78
78
  target.parent.mkpath
79
79
 
80
- system %{inkscape --export-area-page --export-png "#{target.expand_path}" --export-width #{context.session.png_export_width} --export-background="#ffffffff" "#{svg_file.expand_path}"}
80
+ command = %{inkscape --export-area-page --export-png "#{target.expand_path}" --export-background="#ffffffff" }
81
+
82
+ case session.orientation
83
+ when :portrait
84
+ command += %{--export-width #{session.png_export_width}}
85
+ when :landscape
86
+ command += %{--export-height #{session.png_export_width}}
87
+ end
88
+ command += %{ "#{svg_file.expand_path}"}
89
+
90
+ system command
91
+
92
+ if session.orientation == :landscape
93
+ system %{convert -verbose "#{target.expand_path}" -rotate 270 "#{target.expand_path}"}
94
+ end
81
95
 
82
96
  target
83
97
  end
84
98
  end
85
99
 
86
- CARDS_PER_PAGE = 9
87
-
88
100
  desc "pdf", "Create PDF of card images"
89
101
  def pdf
90
102
  pngs
91
103
 
104
+ pdf_obj = session.pdf_class.new(card_size: session.pdf_card_size)
105
+
92
106
  trimmed_pngs = Parallel.map(@exported_pngs) do |png|
93
107
  tmp_target = tmp_target_for(png)
94
108
 
95
- system %{convert #{png} -gravity Center -crop #{context.session.pdf_card_size}+0+0 +repage #{tmp_target}}
109
+ system %{convert #{png} -gravity Center -crop #{session.pdf_card_size}+0+0 +repage #{tmp_target}}
96
110
 
97
111
  tmp_target
98
112
  end
99
113
 
100
- png_slices = trimmed_pngs.each_slice(CARDS_PER_PAGE)
114
+ png_slices = trimmed_pngs.each_slice(pdf_obj.cards_per_page)
101
115
 
102
- page_count = trimmed_pngs.length / CARDS_PER_PAGE
116
+ page_count = trimmed_pngs.length / pdf_obj.cards_per_page
103
117
 
104
118
  placeholder = tmp_target_for("placeholder.png")
105
- system %{convert -size #{context.session.pdf_card_size} xc:white #{placeholder}}
106
-
107
- pdf_obj = SVGGVS::PDF.new(card_size: context.session.pdf_card_size)
119
+ system %{convert -size #{session.pdf_card_size} xc:white #{placeholder}}
108
120
 
109
121
  pages = Parallel.map(png_slices.each_with_index) do |files, page_index|
110
- tmp_pdf_png_target = tmp_path.join("page%05d.pdf" % page_index)
111
122
  tmp_pdf_target = tmp_path.join("page%05d.pdf" % page_index)
112
123
 
113
- files += Array.new(9 - files.length, placeholder)
124
+ files += Array.new(pdf_obj.cards_per_page - files.length, placeholder)
114
125
 
115
- system %{montage -density #{context.session.pdf_dpi} -geometry +0+0 #{files.join(' ')} #{tmp_pdf_png_target}}
116
- 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 }
126
+ system %{montage -density #{session.pdf_dpi} -tile #{pdf_obj.montage_tiling} -geometry +0+0 #{files.join(' ')} #{tmp_pdf_target}}
117
127
 
118
128
  tmp_pdf_target
119
129
  end
120
130
 
121
- if context.session.card_back
122
- tmp_target = tmp_target_for(context.session.card_back)
131
+ if session.card_back
132
+ tmp_target = tmp_target_for(session.card_back)
123
133
  tmp_pdf_target = tmp_path.join("backs.pdf")
124
134
 
125
- system %{convert #{context.session.card_back} -gravity Center -crop #{context.session.pdf_card_size}+0+0 +repage #{tmp_target}}
126
- system %{montage -density #{context.session.pdf_dpi} -geometry +0+0 #{Array.new(9, tmp_target).join(' ')} #{tmp_pdf_target}}
135
+ system %{convert #{session.card_back} -gravity Center -crop #{session.pdf_card_size}+0+0 +repage #{tmp_target}}
136
+ system %{montage -density #{session.pdf_dpi} -geometry +0+0 #{Array.new(pdf_obj.cards_per_page, tmp_target).join(' ')} #{tmp_pdf_target}}
127
137
 
128
138
  pages.length.times do |page|
129
139
  pages << tmp_pdf_target
130
140
  end
131
141
  end
132
142
 
133
- Pathname(context.session.pdf_target).parent.mkpath
143
+ Pathname(session.pdf_target).parent.mkpath
134
144
 
135
- if context.session.prepend_pdf
136
- pages.unshift context.session.prepend_pdf
145
+ if session.prepend_pdf
146
+ pages.unshift session.prepend_pdf
137
147
  end
138
148
 
139
- system "gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=#{context.session.pdf_target} -dBATCH #{pages.join(" ")}"
149
+ system "gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=#{session.pdf_target} -dBATCH #{pages.join(" ")}"
140
150
  end
141
151
 
142
152
  no_tasks do
@@ -160,6 +170,10 @@ MSG
160
170
  def write_svgs
161
171
  context.write_individual_files
162
172
  end
173
+
174
+ def session
175
+ context.session
176
+ end
163
177
  end
164
178
  end
165
179
  end
@@ -0,0 +1,43 @@
1
+ module SVGGVS
2
+ module Page
3
+ class Base
4
+ def initialize(options)
5
+ @options = options
6
+ end
7
+
8
+ def cards_per_page
9
+ self.class::CARDS_X * self.class::CARDS_Y
10
+ end
11
+
12
+ def montage_tiling
13
+ [ self.class::CARDS_X, self.class::CARDS_Y ].join('x')
14
+ end
15
+
16
+ private
17
+ def card_width
18
+ card_size.first
19
+ end
20
+
21
+ def card_height
22
+ card_size.last
23
+ end
24
+
25
+ def page_height
26
+ card_height * cards_per_width
27
+ end
28
+
29
+ def page_width
30
+ card_width * cards_per_height
31
+ end
32
+
33
+ def card_size
34
+ @card_size ||= @options[:card_size].split('x').collect(&:to_i)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ require_relative './letter/poker'
41
+ require_relative './letter/small_shard'
42
+ require_relative './letter/small_square_tile'
43
+
@@ -0,0 +1,13 @@
1
+ require 'svggvs/page/base'
2
+
3
+ module SVGGVS
4
+ module Page
5
+ module Letter
6
+ class Poker < SVGGVS::Page::Base
7
+ CARDS_X = 3
8
+ CARDS_Y = 3
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,13 @@
1
+ require 'svggvs/page/base'
2
+
3
+ module SVGGVS
4
+ module Page
5
+ module Letter
6
+ class SmallShard < SVGGVS::Page::Base
7
+ CARDS_X = 11
8
+ CARDS_Y = 14
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,13 @@
1
+ require 'svggvs/page/base'
2
+
3
+ module SVGGVS
4
+ module Page
5
+ module Letter
6
+ class SmallSquareTile < SVGGVS::Page::Base
7
+ CARDS_X = 4
8
+ CARDS_Y = 5
9
+ end
10
+ end
11
+ end
12
+ end
13
+
data/lib/svggvs/pdf.rb CHANGED
@@ -1,57 +1,5 @@
1
1
  module SVGGVS
2
- CROP_MARK_SIZE = 20.freeze
3
-
4
2
  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
3
  end
56
4
  end
57
5
 
@@ -3,11 +3,12 @@ module SVGGVS
3
3
  attr_accessor :svg_source, :svg_merged_target, :individual_files_path, :on_card_finished
4
4
  attr_accessor :png_files_path, :png_export_width, :pdf_card_size, :pdf_dpi
5
5
  attr_accessor :pdf_target, :card_back, :card_size, :target, :post_read_data
6
- attr_accessor :card_sheet_identifier, :prepend_pdf
6
+ attr_accessor :card_sheet_identifier, :prepend_pdf, :orientation
7
7
 
8
8
  def initialize
9
9
  @index = 0
10
10
  @card_sheet_identifier = "Card Data"
11
+ @orientation = :portrait
11
12
  end
12
13
 
13
14
  def configure
@@ -74,6 +75,10 @@ module SVGGVS
74
75
  end
75
76
  end
76
77
 
78
+ def pdf_class
79
+ @pdf_class ||= ("SVGGVS::Page::Letter::" + @card_size.spunderscore.camelize).constantize
80
+ end
81
+
77
82
  EXPORT_DEFAULTS = {
78
83
  :poker => {
79
84
  :the_game_crafter => {
@@ -81,7 +86,21 @@ module SVGGVS
81
86
  :pdf_dpi => 300,
82
87
  :png_export_width => 825
83
88
  }
84
- }
89
+ },
90
+ :small_square_tile => {
91
+ :the_game_crafter => {
92
+ :pdf_card_size => '675x675',
93
+ :pdf_dpi => 300,
94
+ :png_export_width => 600
95
+ }
96
+ },
97
+ :square_shard => {
98
+ :the_game_crafter => {
99
+ :pdf_card_size => '300x300',
100
+ :pdf_dpi => 300,
101
+ :png_export_width => 225
102
+ }
103
+ },
85
104
  }.freeze
86
105
  end
87
106
  end
@@ -1,3 +1,3 @@
1
1
  module SVGGVS
2
- VERSION = "0.0.10.1"
2
+ VERSION = "0.0.12"
3
3
  end
data/lib/svggvs.rb CHANGED
@@ -3,7 +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
+ require_relative './svggvs/page/base'
7
7
 
8
8
  module SVGGVS
9
9
  end
data/skel/Cardfile CHANGED
@@ -10,6 +10,10 @@
10
10
  # prepend this PDF to the outputted PDF (useful for game rules)
11
11
  # c.prepend_pdf = "rules.pdf"
12
12
 
13
+ # the cards are landscape, so rotate them counterclockwise
14
+ # after rendering in Inkscape
15
+ # c.orientation = :landscape
16
+
13
17
  c.data_source = "data.ods"
14
18
  end
15
19
 
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svggvs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10.1
5
- prerelease:
4
+ version: 0.0.12
6
5
  platform: ruby
7
6
  authors:
8
7
  - John Bintz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2014-06-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: thor
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: parallel
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: roo
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: activesupport
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rspec
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: Generate sets of card game cards using Inkscape templates and Ruby
@@ -115,7 +102,7 @@ executables:
115
102
  extensions: []
116
103
  extra_rdoc_files: []
117
104
  files:
118
- - .gitignore
105
+ - ".gitignore"
119
106
  - Gemfile
120
107
  - LICENSE.txt
121
108
  - README.md
@@ -125,6 +112,10 @@ files:
125
112
  - lib/svggvs/context.rb
126
113
  - lib/svggvs/data_source.rb
127
114
  - lib/svggvs/file.rb
115
+ - lib/svggvs/page/base.rb
116
+ - lib/svggvs/page/letter/poker.rb
117
+ - lib/svggvs/page/letter/small_shard.rb
118
+ - lib/svggvs/page/letter/small_square_tile.rb
128
119
  - lib/svggvs/pdf.rb
129
120
  - lib/svggvs/session.rb
130
121
  - lib/svggvs/target.rb
@@ -136,32 +127,29 @@ files:
136
127
  - skel/images/dog.png.jpg
137
128
  - skel/template.svg
138
129
  - spec/spec_helper.rb
139
- - spec/svggvs/pdf_spec.rb
140
130
  - svggvs.gemspec
141
131
  homepage: ''
142
132
  licenses: []
133
+ metadata: {}
143
134
  post_install_message:
144
135
  rdoc_options: []
145
136
  require_paths:
146
137
  - lib
147
138
  required_ruby_version: !ruby/object:Gem::Requirement
148
- none: false
149
139
  requirements:
150
- - - ! '>='
140
+ - - ">="
151
141
  - !ruby/object:Gem::Version
152
142
  version: '0'
153
143
  required_rubygems_version: !ruby/object:Gem::Requirement
154
- none: false
155
144
  requirements:
156
- - - ! '>='
145
+ - - ">="
157
146
  - !ruby/object:Gem::Version
158
147
  version: '0'
159
148
  requirements: []
160
149
  rubyforge_project:
161
- rubygems_version: 1.8.24
150
+ rubygems_version: 2.2.1
162
151
  signing_key:
163
- specification_version: 3
152
+ specification_version: 4
164
153
  summary: Generate sets of card game cards using Inkscape templates and Ruby
165
154
  test_files:
166
155
  - spec/spec_helper.rb
167
- - spec/svggvs/pdf_spec.rb
@@ -1,46 +0,0 @@
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