SvgSurface creates an empty svg file
Closed this issue · 2 comments
EriKWDev commented
I'm trying to draw the same surface as in the high-level x11 window example using the code below.
While I can create a nice png image with
surface.write_to_png "test.png"
... I can't find a way to write it to svg. There doesn't seem to be a write_to_svg
..?
When I run the code below, however, an empty "test.svg" is written
require "cairo"
module SvgCreation
include Cairo
def self.main
surface = Cairo::SvgSurface.new "test.svg", 400, 300
# surface.restrict_to_version Cairo::SvgVersion::V_1_2
context = Cairo::Context.new surface
context.set_source_rgba 1.0, 0.0, 1.0, 1.0
context.rectangle 0.0, 0.0, 400.0, 300.0
context.fill
context.set_source_rgb 0.0, 0.0, 0.0
context.move_to 0.0, 0.0
context.line_to 400.0, 300.0
context.move_to 400.0, 0.0
context.line_to 0.0, 300.0
context.line_width = 10.0
context.stroke
context.rectangle 0.0, 0.0, 200.0, 150.0
context.set_source_rgba 1.0, 0.0, 0.0, 0.80
context.fill
context.rectangle 0.0, 150.0, 200.0, 150.0
context.set_source_rgba 0.0, 1.0, 0.0, 0.60
context.fill
context.rectangle 200.0, 0.0, 200.0, 150.0
context.set_source_rgba 0.0, 0.0, 1.0, 0.40
context.fill
# surface.write_to_png "test.png"
end
main
end
Is there a close
/destroy
/save
method or something that I'm missing?
tamas-szekeres-ecom commented
Just call surface.finish
.
Also a good idea to call GC when program exits:
at_exit do
GC.collect
end
module Program
# ...
end
EriKWDev commented
Just call
surface.finish
.
That was it xP Thanks!