-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distinguishing between CairoSVGSurface and CairoPDFSurface #316
Comments
What are you trying to do? The logic of libcairo is, that you decide the type of surface before starting to draw and to render. If you are looking for a lazy/late decision, you might look at recordingSurfaces. |
We have a visualization package that relies on Cairo: https://github.com/sisl/AutoViz.jl Now we would like users to be able to save the rendered scenes in different format using c = render([roadway, veh1, veh2], camera=CarFollowCamera(...)) # default to SVGSurface
write("scene.pdf", c) This code will run fine but the user might think they have a pdf and instead they have an svg. The correct way would have been to do: c = render([roadway, veh1, veh2], camera=CarFollowCamera(...), surface=CairoPDFSurface(...))
write("scene.pdf", c) |
I see.
b) workaround could be to look at the actual stream, as both PDF and SVG have headers (files need to start with a sequence of know bytes) c) take the information along your 'c' output (type) of the render function. |
Thanks for the tips, I will give a shot to a)! |
this worked: typ = ccall((:cairo_surface_get_type, Cairo.libcairo), Cint, (Ptr{Nothing},), c.ptr)
if typ == Cairo.CAIRO_SURFACE_TYPE_PDF
# do stuff
end Thanks! |
When trying to write a cairo surface to a file, it is not possible to distinguish whether the surface object is a pdf or svg surface.
MWE:
Is there a convenient way to enforce that the file extension matches the type of Cairo stream?
Right now both CairoSVGSurface and CairoPDFSurface outputs a CairoSurfaceIOStream which makes it not possible to dispatch between the two.
The text was updated successfully, but these errors were encountered: