diff --git a/bin/svggvs b/bin/svggvs index 2215eba..3179f5f 100755 --- a/bin/svggvs +++ b/bin/svggvs @@ -36,12 +36,18 @@ module SVGGVS end end + no_tasks do + def tmp_target_for(file) + tmp_path.join(Digest::MD5.hexdigest(file.to_s) + '.png') + end + end + desc "pdf", "Create PDF of card images" def pdf pngs trimmed_pngs = @exported_pngs.collect do |png| - tmp_target = tmp_path.join(Digest::MD5.hexdigest(png.to_s) + '.png') + tmp_target = tmp_target_for(png) system %{convert #{png} -gravity Center -crop #{context.session.pdf_card_size}+0+0 +repage #{tmp_target}} @@ -60,6 +66,18 @@ module SVGGVS tmp_pdf_target end + if context.session.card_back + tmp_target = tmp_target_for(context.session.card_back) + 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}} + + pages.length.times do |page| + pages << tmp_pdf_target + end + end + system "gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=#{context.session.pdf_target} -dBATCH #{pages.join(" ")}" end diff --git a/lib/svggvs/file.rb b/lib/svggvs/file.rb index 4c19ecc..c724274 100644 --- a/lib/svggvs/file.rb +++ b/lib/svggvs/file.rb @@ -77,7 +77,16 @@ module SVGGVS end def save(file) - ::File.open(file, 'w') { |fh| fh.print doc.to_xml } + for_save_doc = doc.dup + for_save_doc.css('g[inkscape|label]').each do |group| + if (group[:style] || '').include?('display:none') + if !(group['inkscape:label'] || '').include?('(protect)') + group.remove + end + end + end + + ::File.open(file, 'w') { |fh| fh.print for_save_doc.to_xml } end end end diff --git a/lib/svggvs/session.rb b/lib/svggvs/session.rb index 825e4b9..f5bbb53 100644 --- a/lib/svggvs/session.rb +++ b/lib/svggvs/session.rb @@ -2,7 +2,7 @@ module SVGGVS class Session attr_accessor :svg_source, :svg_merged_target, :individual_files_path, :on_card_finished attr_accessor :png_files_path, :png_export_width, :pdf_card_size, :pdf_dpi - attr_accessor :pdf_target + attr_accessor :pdf_target, :card_back def initialize @index = 0