Skip to content

Distinguishing between CairoSVGSurface and CairoPDFSurfaceΒ #316

@MaximeBouton

Description

@MaximeBouton

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:

using Cairo 

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
end

c = CairoSVGSurface(IOBuffer(), 1000, 600);
write("output.svg", c) # this works fine 
write("output.pdf", c) # this would also have worked but the output file would not really be a pdf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions