Skip to content

Commit

Permalink
Benchmarking, small bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andymeneely committed Feb 4, 2015
1 parent 7f8cc85 commit a1bf90b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -29,4 +29,6 @@ samples/_output/*.pdf
samples/_output/foo
rubocop.txt
benchmarks/_output/*.png
benchmarks/_output/*.pdf
benchmarks/_output/*.pdf
benchmarks/_output/
samples/_output/*.svg
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -26,6 +26,7 @@ YARD::Rake::YardocTask.new(:yarddoc) do |t|
end

task benchmark: [:install] do
require 'squib'
Squib::logger.level = Logger::ERROR #silence warnings
Dir.chdir('benchmarks') do
Benchmark.bm(15) do |bm|
Expand Down
14 changes: 14 additions & 0 deletions benchmarks/backend-memory.rb
@@ -0,0 +1,14 @@
require 'squib'

Squib::Deck.new(cards: 200) do
background color: :white
text str: "Hello, world!", y: 500, width: 825, font: 'Sans bold 72', align: :center
rect x: 10, y: 10, width: 20, height: 20
circle x: 40, y: 40, radius: 25
triangle x1: 50, y1: 15, x2: 60, y2: 25, x3: 75, y3: 25
line x1: 100, y1: 620, x2: 720, y2: 620, stroke_width: 15.0
svg file: 'spanner.svg', x: 100, y: 20
png file: 'shiny-purse.png', x: 250, y: 20
save_png prefix: 'rasterized_'
save_pdf file: 'backend.pdf'
end
14 changes: 14 additions & 0 deletions benchmarks/backend-svg.rb
@@ -0,0 +1,14 @@
require 'squib'

Squib::Deck.new(cards: 200, config: 'backend-svg.yml') do
background color: :white
text str: "Hello, world!", y: 500, width: 825, font: 'Sans bold 72', align: :center
rect x: 10, y: 10, width: 20, height: 20
circle x: 40, y: 40, radius: 25
triangle x1: 50, y1: 15, x2: 60, y2: 25, x3: 75, y3: 25
line x1: 100, y1: 620, x2: 720, y2: 620, stroke_width: 15.0
svg file: 'spanner.svg', x: 100, y: 20
png file: 'shiny-purse.png', x: 250, y: 20
save_png prefix: 'rasterized_'
save_pdf file: 'backend.pdf'
end
4 changes: 4 additions & 0 deletions benchmarks/backend-svg.yml
@@ -0,0 +1,4 @@
backend: svg
prefix: vector_backend_
count_format: '%02d'
dir: _output
1 change: 1 addition & 0 deletions lib/squib/card.rb
Expand Up @@ -25,6 +25,7 @@ def initialize(deck, width, height, backend=:memory, index=-1)
when :memory
Cairo::ImageSurface.new(width, height)
when :svg
Dir.mkdir deck.dir unless Dir.exists?(deck.dir)
Cairo::SVGSurface.new("#{deck.dir}/#{deck.prefix}#{deck.count_format % index}.svg", width, height)
else
Squib.logger.fatal "Back end not recognized: '#{backend}'"
Expand Down
2 changes: 1 addition & 1 deletion lib/squib/deck.rb
Expand Up @@ -67,7 +67,7 @@ def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml
@img_dir = '.'
@progress_bar = Progress.new(false)
@text_hint = :off
@backend = 'memory'
@backend = :memory
@dir = SYSTEM_DEFAULTS[:dir]
@prefix = SYSTEM_DEFAULTS[:prefix]
@count_format = SYSTEM_DEFAULTS[:count_format]
Expand Down
1 change: 0 additions & 1 deletion lib/squib/graphics/save_doc.rb
Expand Up @@ -20,7 +20,6 @@ def save_pdf(opts = {})
p = needs(opts, [:range, :paper_width, :paper_height, :file_to_save, :creatable_dir, :margin, :gap, :trim])
cc = Cairo::Context.new(Cairo::PDFSurface.new("#{p[:dir]}/#{p[:file]}", p[:width], p[:height]))
file = "#{p[:dir]}/#{p[:file]}"
puts file
cc = Cairo::Context.new(Cairo::PDFSurface.new(file, width, height))
x = p[:margin]
y = p[:margin]
Expand Down

0 comments on commit a1bf90b

Please sign in to comment.