Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/cairo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ end

const julia_cairo_engine = Ref{gvdevice_engine_t}()
const julia_cairo_features = Ref{gvdevice_features_t}(gvdevice_features_t(Int32(0),0.,0.,0.,0.,96.,96.))
const julia_cairo_name = Vector{UInt8}("julia:cairo")
const julia_cairo_libname = Vector{UInt8}("julia:cairo")
const julia_cairo_name = vcat(Vector{UInt8}("julia:cairo"), UInt8(0))
const julia_cairo_libname = vcat(Vector{UInt8}("julia:cairo"), UInt8(0))
const julia_cairo_device = Ref{NTuple{2, gvplugin_installed_t}}()
const julia_cairo_api = Ref{NTuple{2, gvplugin_api_t}}()

format_placeholder = Vector{UInt8}()

function init_cairo_structs!()
julia_cairo_engine[] = gvdevice_engine_t(@cfunction(cairo_initialize,Cvoid,(Ptr{Cvoid},)),@cfunction(cairo_format,Cvoid,(Ptr{Cvoid},)),@cfunction(cairo_finalize,Cvoid,(Ptr{Cvoid},)))
julia_cairo_device[] = (
Expand Down Expand Up @@ -80,12 +82,21 @@ function render(c::CairoContext,g::GraphViz.Graph; context = default_context[],
end

function cairo_render(g::GraphViz.Graph; context = default_context[], format="julia:cairo")
global last_surface
global last_surface, format_placeholder
GraphViz.add_julia_cairo!(context)
if !g.didlayout
error("Must call layout before calling render!")
end
ccall((:gvRenderContext,libgvc),Cint,(Ptr{Cvoid},Ptr{Cvoid},Ptr{UInt8},Ptr{Cvoid}),context.handle,g.handle,format,C_NULL)

empty!(format_placeholder)
append!(format_placeholder, format)
push!(format_placeholder, UInt8(0))
format_cstring = pointer(format_placeholder)

ret = ccall((:gvRenderContext,libgvc),Cint,(Ptr{Cvoid},Ptr{Cvoid},Ptr{UInt8},Ptr{Cvoid}),context.handle,g.handle,format_cstring,C_NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all not gc-safe. Just declare this as Cstring rather than Ptr{UInt8} and let julia worry about the string conversion.

if ret != 0
error("gvRenderContext failed with return code: $ret")
end
surface = last_surface
last_surface = nothing
return surface
Expand Down