More exploration spikes

* Playing with PDF support
* Added background
* Added rectangle
* Split save to save_pdf and save_images since PDFs are way different
* Working on text rendering (non-pango for now, but that'll change)
This commit is contained in:
Andy Meneely
2014-07-13 01:10:24 -04:00
parent 6fd2ab8684
commit e036d36737
7 changed files with 97 additions and 11 deletions
+17
View File
@@ -0,0 +1,17 @@
module Squib
module Graphics
class Background
def initialize(card, color)
@card=card; @color=color
end
def execute
cc = @card.cairo_context
cc.set_source_rgb(*@color)
cc.paint
end
end
end
end
+21
View File
@@ -0,0 +1,21 @@
module Squib
module Graphics
class Rectangle
def initialize(card, x, y, width, height, x_radius, y_radius)
@card=card; @x=x; @y=y; @width=width; @height=height
@x_radius=x_radius; @y_radius=y_radius
end
def execute
cc = @card.cairo_context
cc.set_source_rgb(0.0,0.0,0.0)
cc.rounded_rectangle(@x, @y, @width, @height, @x_radius, @y_radius)
cc.stroke
end
end
end
end
+27
View File
@@ -0,0 +1,27 @@
module Squib
module Graphics
class SaveDoc
def initialize(format)
@format = format
end
def execute
#paper is 8.5x11
# PDF points are 1/72 of an inch
width = 8.5 * 72
height = 11 * 72
cc = Cairo::Context.new(Cairo::PDFSurface.new('_img/deck.pdf', width, height))
x = 10
y = 10
Squib.the_deck.each_with_index do |card, i|
cc.move_to(x,y)
x += 825*i
cc.set_source(card.cairo_surface, 0, 300)
cc.paint
end
end
end
end
end
@@ -1,13 +1,12 @@
module Squib
module Graphics
class Save
class SaveImages
def initialize(format)
@format = format
end
def execute
puts "Here!"
Squib.the_deck.each_with_index do |card, i|
card.cairo_context.target.write_to_png("_img/img_#{i}.png")
end
+1 -1
View File
@@ -14,7 +14,7 @@ module Squib
cc.set_source_rgb(0.0,0.0,0.0)
cc.select_font_face ("Helvetica");
cc.set_font_size(36)
cc.move_to(@x,@y)
cc.move_to(@x,@y + cc.text_extents(@str.to_s).height)
cc.show_text(@str.to_s)
end
end