Skip to content

Commit

Permalink
write to file, fix #42
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeBouton committed Feb 22, 2020
1 parent f4fa235 commit 18563ec
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/renderable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ isrenderable(t::Type) = hasmethod(add_renderable!, Tuple{RenderModel, t})

isrenderable(t::Type{Roadway}) = true

function Base.write(filename::String, c::CairoSurface)
write_to_png(c, filename)
end

"""
write_to_svg(surface::CairoSurface, filename::AbstractString)
Write a cairo svg surface to a file. The surface object is destroyed after.
"""
function write_to_svg(surface::CairoSurface, filename::AbstractString)
function Base.write(filename::String, surface::Cairo.CairoSurfaceIOStream)
finish(surface)
seek(surface.stream, 0)
open(filename, "w") do io
write(io, read(surface.stream, String))
end
return
return
end


Expand Down
Binary file added test/out.pdf
Binary file not shown.
Binary file added test/out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@ end
c = render([rw, car, car2], camera=SceneFollowCamera(zoom=10.))
end

@testset "write SVG" begin
@testset "write SVG, PDF, PNG" begin
roadway = gen_stadium_roadway(4)
c = @test_deprecated render(roadway)
write_to_svg(c, "out.svg")
write("out.svg", c)
@test isfile("out.svg")

# write pdf
camera = StaticCamera(position=(50,30), zoom=6.)
c = render([roadway], camera=camera,
surface=AutoViz.CairoPDFSurface(IOBuffer(), AutoViz.canvas_width(camera), AutoViz.canvas_height(camera)))
write("out.pdf", c)

# write png
c = render([roadway], camera=camera,
surface=AutoViz.CairoRGBSurface(AutoViz.canvas_width(camera), AutoViz.canvas_height(camera)))
write("out.png", c)
end

@testset "vehicle rendering" begin
Expand Down

0 comments on commit 18563ec

Please sign in to comment.