@@ -30,6 +30,7 @@ def run(argv)
3030 opts . on ( "--background COLOR" ) { |value | options [ :background ] = value }
3131 opts . on ( "--static" ) { options [ :static ] = true }
3232 opts . on ( "--quality N" , Integer ) { |value | options [ :quality ] = value }
33+ opts . on ( "--print-template" ) { options [ :print_template ] = true }
3334 opts . on ( "--render-timeout SECONDS" , Float ) { |value | options [ :render_timeout ] = value }
3435 opts . on ( "--force" ) { options [ :force ] = true }
3536 opts . on ( "-v" , "--version" ) { puts "bkrender #{ VERSION } " ; return 0 }
@@ -42,6 +43,10 @@ def run(argv)
4243 raise ArgumentError , "--diff requires OLD and NEW inputs" if options [ :diff ] && !second_input
4344 raise ArgumentError , "unexpected arguments: #{ argv . join ( ' ' ) } " unless argv . empty?
4445 format = output_format ( options )
46+ if options [ :print_template ]
47+ raise ArgumentError , "--print-template requires PDF output" unless format == "pdf"
48+ options . merge! ( theme : "print" , crop : "none" , scale : 1.0 , static : true )
49+ end
4550 raise ArgumentError , "--background is only supported for JPEG" if options [ :background ] && format != "jpeg"
4651 raise ArgumentError , "cannot write binary image data to a terminal; use -o PATH" if !%w[ svg html ] . include? ( format ) && !options [ :output ] && $stdout. tty?
4752 return render_diff ( input , second_input , options , format ) if options [ :diff ]
@@ -61,6 +66,7 @@ def run(argv)
6166 state : state , active_layer : options [ :layer ] , focus : options [ :focus ] ,
6267 highlight_net : options [ :highlight_net ] }
6368 svg = SvgRenderer . new . render ( circuit , **render_options )
69+ svg = print_dimensions ( svg ) if options [ :print_template ]
6470 output = case format
6571 when "svg" then svg
6672 when "html" then html_viewer ( svg , theme : options [ :theme ] , circuit : circuit , render_options : render_options )
@@ -81,6 +87,12 @@ def run(argv)
8187
8288 private
8389
90+ def print_dimensions ( svg )
91+ svg . sub ( /(<svg\b [^>]*?\b width=")([\d .]+)(" height=")([\d .]+)(")/ ) do
92+ "#{ $1} #{ format ( '%.2f' , $2. to_f * 0.254 ) } mm#{ $3} #{ format ( '%.2f' , $4. to_f * 0.254 ) } mm#{ $5} "
93+ end
94+ end
95+
8496 def output_format ( options )
8597 extension = File . extname ( options [ :output ] . to_s ) . downcase
8698 from_path = { ".svg" => "svg" , ".html" => "html" , ".png" => "png" , ".jpg" => "jpeg" , ".jpeg" => "jpeg" ,
0 commit comments