support adding card backs to PnP pdfs and speed up rendering by removing hidden layers
This commit is contained in:
parent
7cd12544c0
commit
e9b60b622f
20
bin/svggvs
20
bin/svggvs
@ -36,12 +36,18 @@ module SVGGVS
|
|||||||
end
|
end
|
||||||
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"
|
desc "pdf", "Create PDF of card images"
|
||||||
def pdf
|
def pdf
|
||||||
pngs
|
pngs
|
||||||
|
|
||||||
trimmed_pngs = @exported_pngs.collect do |png|
|
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}}
|
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
|
tmp_pdf_target
|
||||||
end
|
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(" ")}"
|
system "gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=#{context.session.pdf_target} -dBATCH #{pages.join(" ")}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,7 +77,16 @@ module SVGGVS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def save(file)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@ module SVGGVS
|
|||||||
class Session
|
class Session
|
||||||
attr_accessor :svg_source, :svg_merged_target, :individual_files_path, :on_card_finished
|
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 :png_files_path, :png_export_width, :pdf_card_size, :pdf_dpi
|
||||||
attr_accessor :pdf_target
|
attr_accessor :pdf_target, :card_back
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@index = 0
|
@index = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user