diff --git a/deps/build.jl b/deps/build.jl
index 88ac577..dba8192 100644
--- a/deps/build.jl
+++ b/deps/build.jl
@@ -1,14 +1,19 @@
using BinDeps
+using Compat
+import Compat.Libdl
+import Compat.Sys
+using Pkg
+
@BinDeps.setup
using Compat
-# check for cairo version
+# check for cairo version
function validate_cairo_version(name,handle)
f = Libdl.dlsym_e(handle, "cairo_version")
f == C_NULL && return false
- v = ccall(f, Int32,())
+ v = ccall(f, Int32,())
return v > 10800
end
@@ -28,7 +33,7 @@ deps = [
zlib = library_dependency("zlib", aliases = ["libzlib","zlib1"], os = :Windows, group = group)
]
-if is_windows()
+if Sys.iswindows()
using WinRPM
provides(WinRPM.RPM,"libpango-1_0-0",[pango,pangocairo],os = :Windows)
provides(WinRPM.RPM,["glib2", "libgobject-2_0-0"],gobject,os = :Windows)
@@ -79,7 +84,7 @@ provides(Yum,
"libpng" => libpng,
"gettext-libs" => gettext
))
-
+
provides(Zypper,
Dict(
"libcairo" => cairo,
@@ -107,7 +112,7 @@ provides(Sources,
URI("http://zlib.net/zlib-1.2.7.tar.gz") => zlib
))
-xx(t...) = (is_windows() ? t[1] : (is_linux() || length(t) == 2) ? t[2] : t[3])
+xx(t...) = (Sys.iswindows() ? t[1] : (is_linux() || length(t) == 2) ? t[2] : t[3])
provides(BuildProcess,
Dict(
diff --git a/samples/sample_alpha_paint.jl b/samples/sample_alpha_paint.jl
index c97463e..a6a0be9 100644
--- a/samples/sample_alpha_paint.jl
+++ b/samples/sample_alpha_paint.jl
@@ -1,13 +1,14 @@
## header to provide surface and context
using Cairo
using Colors
+using Compat
-c = CairoRGBSurface(256,256);
-cr = CairoContext(c);
+c = CairoRGBSurface(256,256)
+cr = CairoContext(c)
-save(cr);
+save(cr)
-z = Array{RGB24}(2,2)
+z = Array{RGB24}(uninitialized, 2, 2)
c1 = convert(RGB24,colorant"grey20")
c2 = convert(RGB24,colorant"grey80")
z[1,1] = c1
@@ -16,18 +17,18 @@ z[2,1] = c2
z[2,2] = c1
img = CairoImageSurface(z)
-pattern = CairoPattern(img);
-pattern_set_extend(pattern, Cairo.EXTEND_REPEAT);
-pattern_set_filter(pattern, Cairo.FILTER_BILINEAR);
+pattern = CairoPattern(img)
+pattern_set_extend(pattern, Cairo.EXTEND_REPEAT)
+pattern_set_filter(pattern, Cairo.FILTER_BILINEAR)
-m = CairoMatrix(1/8.0,0,0,1/8.0,0,0);
+m = CairoMatrix(1/8.0,0,0,1/8.0,0,0)
-set_matrix(pattern, m);
-set_source(cr, pattern);
-paint(cr);
-restore(cr);
+set_matrix(pattern, m)
+set_source(cr, pattern)
+paint(cr)
+restore(cr)
-save(cr);
+save(cr)
# 5 uses of set_source
@@ -75,8 +76,8 @@ restore(cr)
## mark picture with current date
-restore(cr);
-move_to(cr,0.0,12.0);
-set_source_rgb(cr, 0,0,0);
-show_text(cr,Libc.strftime(time()));
-write_to_png(c,"sample_alpha_paint.png");
+restore(cr)
+move_to(cr,0.0,12.0)
+set_source_rgb(cr, 0,0,0)
+show_text(cr,Libc.strftime(time()))
+write_to_png(c,"sample_alpha_paint.png")
diff --git a/samples/sample_arc.jl b/samples/sample_arc.jl
index be5da1d..4e61924 100644
--- a/samples/sample_arc.jl
+++ b/samples/sample_arc.jl
@@ -1,5 +1,6 @@
## header to provide surface and context
using Cairo
+
c = CairoRGBSurface(256,256);
cr = CairoContext(c);
@@ -13,14 +14,14 @@ restore(cr);
xc = 128.0;
yc = 128.0;
radius = 100.0;
-angle1 = 45.0 * (pi/180.0); # angles are specified
-angle2 = 180.0 * (pi/180.0); # in radians
+angle1 = 45.0 * (pi/180.0); # angles are specified
+angle2 = 180.0 * (pi/180.0); # in radians
set_line_width(cr, 10.0);
arc(cr, xc, yc, radius, angle1, angle2);
stroke(cr);
-# draw helping lines
+# draw helping lines
set_source_rgba(cr, 1, 0.2, 0.2, 0.6);
set_line_width(cr, 6.0);
diff --git a/samples/sample_arc_negative.jl b/samples/sample_arc_negative.jl
index 938b3f3..ba14d8e 100644
--- a/samples/sample_arc_negative.jl
+++ b/samples/sample_arc_negative.jl
@@ -13,14 +13,14 @@ restore(cr);
xc = 128.0;
yc = 128.0;
radius = 100.0;
-angle1 = 45.0 * (pi/180.0); # angles are specified
-angle2 = 180.0 * (pi/180.0); # in radians
+angle1 = 45.0 * (pi/180.0); # angles are specified
+angle2 = 180.0 * (pi/180.0); # in radians
set_line_width(cr, 10.0);
arc_negative(cr, xc, yc, radius, angle1, angle2);
stroke(cr);
-# draw helping lines
+# draw helping lines
set_source_rgba(cr, 1, 0.2, 0.2, 0.6);
set_line_width(cr, 6.0);
diff --git a/samples/sample_copy_path.jl b/samples/sample_copy_path.jl
index 234ee2c..a3a9288 100644
--- a/samples/sample_copy_path.jl
+++ b/samples/sample_copy_path.jl
@@ -57,7 +57,7 @@ function example_copy_path(cr)
s1 = repr(x.points)
move_to(cr,100.0,14.0*l)
l += 1
- show_text(cr,s0*s1); #
+ show_text(cr,s0*s1)
end
nothing
end
diff --git a/samples/sample_copy_path_flat.jl b/samples/sample_copy_path_flat.jl
index 5163543..f053cf8 100644
--- a/samples/sample_copy_path_flat.jl
+++ b/samples/sample_copy_path_flat.jl
@@ -1,28 +1,29 @@
## header to provide surface and context
using Cairo
-c = CairoRGBSurface(256,256);
-cr = CairoContext(c);
-save(cr);
-set_source_rgb(cr,0.8,0.8,0.8); # light gray
-rectangle(cr,0.0,0.0,256.0,256.0); # background
-fill(cr);
-restore(cr);
+c = CairoRGBSurface(256,256)
+cr = CairoContext(c)
-save(cr);
+save(cr)
+set_source_rgb(cr,0.8,0.8,0.8) # light gray
+rectangle(cr,0.0,0.0,256.0,256.0) # background
+fill(cr)
+restore(cr)
+
+save(cr)
## original example, following here
-move_to(cr, 16.0, 32.0);
-curve_to(cr, 16.0, 16.0, 16.0, 16.0, 32.0, 16.0);
+move_to(cr, 16.0, 32.0)
+curve_to(cr, 16.0, 16.0, 16.0, 16.0, 32.0, 16.0)
-opath = Cairo.convert_cairo_path_data(Cairo.copy_path(cr));
-dx,dy,ex,ey = path_extents(cr);
+opath = Cairo.convert_cairo_path_data(Cairo.copy_path(cr))
+dx,dy,ex,ey = path_extents(cr)
-fpath = Cairo.convert_cairo_path_data(Cairo.copy_path_flat(cr));
+fpath = Cairo.convert_cairo_path_data(Cairo.copy_path_flat(cr))
-stroke(cr);
+stroke(cr)
-restore(cr);
+restore(cr)
l = 2 # something like a line counter
@@ -40,7 +41,7 @@ for x in opath
s1 = repr(x.points)
move_to(cr,10.0,16.0+(14.0*l))
l += 1
- show_text(cr,s0*s1); #
+ show_text(cr,s0*s1)
end
l = 2 # something like a line counter
@@ -59,15 +60,15 @@ for x in fpath
s1 = repr(x.points)
move_to(cr,10.0,50.0+(14.0*l))
l += 1
- show_text(cr,s0*s1); #
+ show_text(cr,s0*s1)
end
## mark picture with current date
-restore(cr);
+restore(cr)
-move_to(cr,0.0,12.0);
-set_source_rgb(cr, 0,0,0);
-show_text(cr,Libc.strftime(time()));
+move_to(cr,0.0,12.0)
+set_source_rgb(cr, 0,0,0)
+show_text(cr,Libc.strftime(time()))
-write_to_png(c,"sample_copy_path_flat.png");
+write_to_png(c,"sample_copy_path_flat.png")
diff --git a/samples/sample_pango_text.jl b/samples/sample_pango_text.jl
index d5ce36d..cb2e101 100644
--- a/samples/sample_pango_text.jl
+++ b/samples/sample_pango_text.jl
@@ -1,5 +1,5 @@
## header to provide surface and context
-using Cairo
+using Cairo, Compat, Printf
c = CairoRGBSurface(256,256);
cr = CairoContext(c);
@@ -19,7 +19,7 @@ text(cr,16.0,104.0,"TextBoldItalicsuper-2",markup=true)
text(cr,40.0,224.0,"Es geht aufwärts !",markup=true,angle=30.0)
-#using textwidth and height
+#using textwidth and height
set_font_face(cr, "Sans 12")
diff --git a/src/Cairo.jl b/src/Cairo.jl
index 4ca5250..85d50b5 100644
--- a/src/Cairo.jl
+++ b/src/Cairo.jl
@@ -2,8 +2,8 @@ __precompile__()
module Cairo
-using Compat; import Compat: String, textwidth
-
+using Compat
+import Compat.Sys
depsjl = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
isfile(depsjl) ? include(depsjl) : error("Cairo not properly ",
@@ -11,14 +11,16 @@ isfile(depsjl) ? include(depsjl) : error("Cairo not properly ",
using Colors
-importall Graphics
-import Base: copy
+import Graphics
+using Graphics: BoundingBox, GraphicsContext, GraphicsDevice
+import Graphics: arc, clip, close_path, creategc, fill_preserve, height, line_to, move_to, new_path, new_sub_path, paint, rectangle, rel_line_to, reset_clip, restore, rotate, save, scale, set_dash, set_line_width, set_source, set_source_rgb, set_source_rgba, stroke, stroke_preserve, textwidth, translate, width
+import Base: copy, fill
libcairo_version = VersionNumber(unsafe_string(
ccall((:cairo_version_string,Cairo._jl_libcairo),Cstring,()) ))
libpango_version = VersionNumber(unsafe_string(
ccall((:pango_version_string,Cairo._jl_libpango),Cstring,()) ))
-if !is_windows()
+if !Sys.iswindows()
libpangocairo_version = VersionNumber(unsafe_string(
ccall((:pango_version_string,Cairo._jl_libpangocairo),Cstring,()) ))
libgobject_version = VersionNumber(
@@ -43,7 +45,7 @@ export
# surface and context management
finish, destroy, status, get_source,
- creategc, getgc, save, restore, show_page, width, height,
+ creategc, save, restore, show_page, width, height,
# pattern
pattern_create_radial, pattern_create_linear,
@@ -113,7 +115,7 @@ Surfaces, the canvas you are painting on
Context, the handle to coordinate transformation, paint+Color
CairoContext, finish, destroy, status, get_source,
- creategc, getgc, save, restore, show_page, width, height
+ creategc, save, restore, show_page, width, height
Path creation API
@@ -130,7 +132,7 @@ Stroking and painting API
stroke_preserve, stroke_transformed, stroke_transformed_preserve
CairoContext, finish, destroy, status, get_source,
- creategc, getgc, save, restore, show_page, width, height
+ creategc, save, restore, show_page, width, height
"
Cairo
@@ -140,7 +142,7 @@ function write_to_stream_callback(s::IO, buf::Ptr{UInt8}, len::UInt32)
Int32((n == len) ? 0 : 11)
end
-get_stream_callback(T) = cfunction(write_to_stream_callback, Int32, (Ref{T}, Ptr{UInt8}, UInt32))
+get_stream_callback(T) = cfunction(write_to_stream_callback, Int32, Tuple{Ref{T}, Ptr{UInt8}, UInt32})
function read_from_stream_callback(s::IO, buf::Ptr{UInt8}, len::UInt32)
@@ -154,31 +156,31 @@ function read_from_stream_callback(s::IO, buf::Ptr{UInt8}, len::UInt32)
(nb == len) ? STATUS_SUCCESS : STATUS_READ_ERROR
end
-get_readstream_callback(T) = cfunction(read_from_stream_callback, Int32, (Ref{T}, Ptr{UInt8}, UInt32))
+get_readstream_callback(T) = cfunction(read_from_stream_callback, Int32, Tuple{Ref{T}, Ptr{UInt8}, UInt32})
-type CairoSurface{T<:Union{UInt32,RGB24,ARGB32}} <: GraphicsDevice
- ptr::Ptr{Void}
+mutable struct CairoSurface{T<:Union{UInt32,RGB24,ARGB32}} <: GraphicsDevice
+ ptr::Ptr{Nothing}
width::Float64
height::Float64
data::Matrix{T}
- @compat function (::Type{CairoSurface{T}}){T}(ptr::Ptr{Void}, w, h)
+ function (::Type{CairoSurface{T}})(ptr::Ptr{Nothing}, w, h) where {T}
self = new{T}(ptr, w, h)
- finalizer(destroy, self)
+ @compat finalizer(destroy, self)
self
end
- @compat function (::Type{CairoSurface{T}}){T}(ptr::Ptr{Void}, w, h, data::Matrix{T})
+ function (::Type{CairoSurface{T}})(ptr::Ptr{Nothing}, w, h, data::Matrix{T}) where {T}
self = new{T}(ptr, w, h, data)
- finalizer(destroy, self)
+ @compat finalizer(destroy, self)
self
end
- @compat function (::Type{CairoSurface{T}}){T}(ptr::Ptr{Void})
+ function (::Type{CairoSurface{T}})(ptr::Ptr{Nothing}) where {T}
ccall(
(:cairo_surface_reference,_jl_libcairo),
- Ptr{Void}, (Ptr{Void}, ), ptr)
+ Ptr{Nothing}, (Ptr{Nothing}, ), ptr)
self = new{T}(ptr)
- finalizer(destroy, self)
+ @compat finalizer(destroy, self)
self
end
end
@@ -194,7 +196,7 @@ function destroy(surface::CairoSurface)
if surface.ptr == C_NULL
return
end
- ccall((:cairo_surface_destroy,_jl_libcairo), Void, (Ptr{Void},), surface.ptr)
+ ccall((:cairo_surface_destroy,_jl_libcairo), Nothing, (Ptr{Nothing},), surface.ptr)
surface.ptr = C_NULL
nothing
end
@@ -215,18 +217,18 @@ for name in (:finish,:flush,:mark_dirty)
@eval begin
$name(surface::CairoSurface) =
ccall(($(string("cairo_surface_",name)),_jl_libcairo),
- Void, (Ptr{Void},), surface.ptr)
+ Nothing, (Ptr{Nothing},), surface.ptr)
end
end
function status(surface::CairoSurface)
ccall((:cairo_surface_status,_jl_libcairo),
- Int32, (Ptr{Void},), surface.ptr)
+ Int32, (Ptr{Nothing},), surface.ptr)
end
function CairoImageSurface(w::Real, h::Real, format::Integer)
ptr = ccall((:cairo_image_surface_create,_jl_libcairo),
- Ptr{Void}, (Int32,Int32,Int32), format, w, h)
+ Ptr{Nothing}, (Int32,Int32,Int32), format, w, h)
CairoSurface(ptr, w, h)
end
@@ -237,111 +239,111 @@ CairoRGBSurface(img) = CairoImageSurface(img, FORMAT_RGB24)
function CairoImageSurface(img::Array{UInt32,2}, format::Integer; flipxy::Bool = true)
if flipxy
- img = img'
+ img = permutedims(img, (2,1))
end
w,h = size(img)
stride = format_stride_for_width(format, w)
@assert stride == 4w
ptr = ccall((:cairo_image_surface_create_for_data,_jl_libcairo),
- Ptr{Void}, (Ptr{Void},Int32,Int32,Int32,Int32),
+ Ptr{Nothing}, (Ptr{Nothing},Int32,Int32,Int32,Int32),
img, format, w, h, stride)
CairoSurface(ptr, w, h, img)
end
-function CairoImageSurface{T<:Union{RGB24,ARGB32}}(img::Matrix{T})
+function CairoImageSurface(img::Matrix{T}) where {T<:Union{RGB24,ARGB32}}
w,h = size(img)
stride = format_stride_for_width(format(T), w)
@assert stride == 4w
ptr = ccall((:cairo_image_surface_create_for_data,_jl_libcairo),
- Ptr{Void}, (Ptr{Void},Int32,Int32,Int32,Int32),
+ Ptr{Nothing}, (Ptr{Nothing},Int32,Int32,Int32,Int32),
img, format(T), w, h, stride)
CairoSurface(ptr, w, h, img)
end
format(::Type{RGB24}) = FORMAT_RGB24
format(::Type{ARGB32}) = FORMAT_ARGB32
-format{T<:Union{RGB24,ARGB32}}(surf::CairoSurface{T}) = T
+format(surf::CairoSurface{T}) where {T<:Union{RGB24,ARGB32}} = T
## PDF ##
-function CairoPDFSurface{T<:IO}(stream::T, w::Real, h::Real)
+function CairoPDFSurface(stream::T, w::Real, h::Real) where {T<:IO}
callback = get_stream_callback(T)
- ptr = ccall((:cairo_pdf_surface_create_for_stream,_jl_libcairo), Ptr{Void},
- (Ptr{Void}, Any, Float64, Float64), callback, stream, w, h)
+ ptr = ccall((:cairo_pdf_surface_create_for_stream,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing}, Any, Float64, Float64), callback, stream, w, h)
CairoSurface(ptr, w, h)
end
function CairoPDFSurface(filename::AbstractString, w_pts::Real, h_pts::Real)
- ptr = ccall((:cairo_pdf_surface_create,_jl_libcairo), Ptr{Void},
+ ptr = ccall((:cairo_pdf_surface_create,_jl_libcairo), Ptr{Nothing},
(Ptr{UInt8},Float64,Float64), String(filename), w_pts, h_pts)
CairoSurface(ptr, w_pts, h_pts)
end
## EPS ##
-function CairoEPSSurface{T<:IO}(stream::T, w::Real, h::Real)
+function CairoEPSSurface(stream::T, w::Real, h::Real) where {T<:IO}
callback = get_stream_callback(T)
- ptr = ccall((:cairo_ps_surface_create_for_stream,_jl_libcairo), Ptr{Void},
- (Ptr{Void}, Any, Float64, Float64), callback, stream, w, h)
- ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Void,
- (Ptr{Void},Int32), ptr, 1)
+ ptr = ccall((:cairo_ps_surface_create_for_stream,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing}, Any, Float64, Float64), callback, stream, w, h)
+ ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Int32), ptr, 1)
CairoSurface(ptr, w, h)
end
function CairoEPSSurface(filename::AbstractString, w_pts::Real, h_pts::Real)
- ptr = ccall((:cairo_ps_surface_create,_jl_libcairo), Ptr{Void},
+ ptr = ccall((:cairo_ps_surface_create,_jl_libcairo), Ptr{Nothing},
(Ptr{UInt8},Float64,Float64), String(filename), w_pts, h_pts)
- ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Void,
- (Ptr{Void},Int32), ptr, 1)
+ ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Int32), ptr, 1)
CairoSurface(ptr, w_pts, h_pts)
end
## PS ##
function CairoPSSurface(stream::IOStream, w::Real, h::Real)
- callback = cfunction(write_to_ios_callback, Int32, (Ptr{Void},Ptr{UInt8},UInt32))
- ptr = ccall((:cairo_ps_surface_create_for_stream,_jl_libcairo), Ptr{Void},
- (Ptr{Void}, Ptr{Void}, Float64, Float64), callback, stream, w, h)
- ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Void,
- (Ptr{Void},Int32), ptr, 0)
+ callback = cfunction(write_to_ios_callback, Int32, Tuple{Ptr{Nothing},Ptr{UInt8},UInt32})
+ ptr = ccall((:cairo_ps_surface_create_for_stream,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing}, Ptr{Nothing}, Float64, Float64), callback, stream, w, h)
+ ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Int32), ptr, 0)
CairoSurface(ptr, w, h)
end
-function CairoPSSurface{T<:IO}(stream::T, w::Real, h::Real)
+function CairoPSSurface(stream::T, w::Real, h::Real) where {T<:IO}
callback = get_stream_callback(T)
- ptr = ccall((:cairo_ps_surface_create_for_stream,_jl_libcairo), Ptr{Void},
- (Ptr{Void}, Any, Float64, Float64), callback, stream, w, h)
- ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Void,
- (Ptr{Void},Int32), ptr, 0)
+ ptr = ccall((:cairo_ps_surface_create_for_stream,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing}, Any, Float64, Float64), callback, stream, w, h)
+ ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Int32), ptr, 0)
CairoSurface(ptr, w, h)
end
function CairoPSSurface(filename::AbstractString, w_pts::Real, h_pts::Real)
- ptr = ccall((:cairo_ps_surface_create,_jl_libcairo), Ptr{Void},
+ ptr = ccall((:cairo_ps_surface_create,_jl_libcairo), Ptr{Nothing},
(Ptr{UInt8},Float64,Float64), String(filename), w_pts, h_pts)
- ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Void,
- (Ptr{Void},Int32), ptr, 0)
+ ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Int32), ptr, 0)
CairoSurface(ptr, w_pts, h_pts)
end
## Xlib ##
function CairoXlibSurface(display, drawable, visual, w, h)
- ptr = ccall((:cairo_xlib_surface_create,_jl_libcairo), Ptr{Void},
- (Ptr{Void}, Int, Ptr{Void}, Int32, Int32),
+ ptr = ccall((:cairo_xlib_surface_create,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing}, Int, Ptr{Nothing}, Int32, Int32),
display, drawable, visual, w, h)
CairoSurface(ptr, w, h)
end
CairoXlibSurfaceSetSize(surface, w, h) =
- ccall((:cairo_xlib_surface_set_size,_jl_libcairo), Void,
- (Ptr{Void}, Int32, Int32),
+ ccall((:cairo_xlib_surface_set_size,_jl_libcairo), Nothing,
+ (Ptr{Nothing}, Int32, Int32),
surface, w, h)
## Quartz ##
function CairoQuartzSurface(context, w, h)
ptr = ccall((:cairo_quartz_surface_create_for_cg_context,_jl_libcairo),
- Ptr{Void}, (Ptr{Void}, UInt32, UInt32), context, w, h)
+ Ptr{Nothing}, (Ptr{Nothing}, UInt32, UInt32), context, w, h)
CairoSurface(ptr, w, h)
end
@@ -349,21 +351,21 @@ end
function CairoWin32Surface(hdc,w,h)
ptr = ccall((:cairo_win32_surface_create, _jl_libcairo),
- Ptr{Void}, (Ptr{Void},), hdc)
+ Ptr{Nothing}, (Ptr{Nothing},), hdc)
CairoSurface(ptr,w,h)
end
## SVG ##
-function CairoSVGSurface{T<:IO}(stream::T, w::Real, h::Real)
+function CairoSVGSurface(stream::T, w::Real, h::Real) where {T<:IO}
callback = get_stream_callback(T)
- ptr = ccall((:cairo_svg_surface_create_for_stream,_jl_libcairo), Ptr{Void},
- (Ptr{Void}, Any, Float64, Float64), callback, stream, w, h)
+ ptr = ccall((:cairo_svg_surface_create_for_stream,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing}, Any, Float64, Float64), callback, stream, w, h)
CairoSurface(ptr, w, h)
end
function CairoSVGSurface(filename::AbstractString, w::Real, h::Real)
- ptr = ccall((:cairo_svg_surface_create,_jl_libcairo), Ptr{Void},
+ ptr = ccall((:cairo_svg_surface_create,_jl_libcairo), Ptr{Nothing},
(Ptr{UInt8},Float64,Float64), String(filename), w, h)
CairoSurface(ptr, w, h)
end
@@ -372,36 +374,36 @@ end
function read_from_png(filename::AbstractString)
ptr = ccall((:cairo_image_surface_create_from_png,_jl_libcairo),
- Ptr{Void}, (Ptr{UInt8},), String(filename))
+ Ptr{Nothing}, (Ptr{UInt8},), String(filename))
w = ccall((:cairo_image_surface_get_width,_jl_libcairo),
- Int32, (Ptr{Void},), ptr)
+ Int32, (Ptr{Nothing},), ptr)
h = ccall((:cairo_image_surface_get_height,_jl_libcairo),
- Int32, (Ptr{Void},), ptr)
+ Int32, (Ptr{Nothing},), ptr)
CairoSurface(ptr, w, h)
end
-function write_to_png{T<:IO}(surface::CairoSurface, stream::T)
+function write_to_png(surface::CairoSurface, stream::T) where {T<:IO}
callback = get_stream_callback(T)
- ccall((:cairo_surface_write_to_png_stream,_jl_libcairo), Void,
- (Ptr{UInt8},Ptr{Void},Any), surface.ptr, callback, stream)
+ ccall((:cairo_surface_write_to_png_stream,_jl_libcairo), Nothing,
+ (Ptr{UInt8},Ptr{Nothing},Any), surface.ptr, callback, stream)
end
function write_to_png(surface::CairoSurface, filename::AbstractString)
- ccall((:cairo_surface_write_to_png,_jl_libcairo), Void,
+ ccall((:cairo_surface_write_to_png,_jl_libcairo), Nothing,
(Ptr{UInt8},Ptr{UInt8}), surface.ptr, String(filename))
end
show(io::IO, ::MIME"image/png", surface::CairoSurface) =
write_to_png(surface, io)
-function read_from_png{T<:IO}(stream::T)
+function read_from_png(stream::T) where {T<:IO}
callback = get_readstream_callback(T)
ptr = ccall((:cairo_image_surface_create_from_png_stream, Cairo._jl_libcairo),
- Ptr{Void}, (Ptr{Void},Ref{IO}), callback, stream)
+ Ptr{Nothing}, (Ptr{Nothing},Ref{IO}), callback, stream)
w = ccall((:cairo_image_surface_get_width,Cairo._jl_libcairo),
- Int32, (Ptr{Void},), ptr)
+ Int32, (Ptr{Nothing},), ptr)
h = ccall((:cairo_image_surface_get_height,Cairo._jl_libcairo),
- Int32, (Ptr{Void},), ptr)
+ Int32, (Ptr{Nothing},), ptr)
Cairo.CairoSurface(ptr, w, h)
end
@@ -409,8 +411,8 @@ end
## Generic ##
function surface_create_similar(s::CairoSurface, w = width(s), h = height(s))
- ptr = ccall((:cairo_surface_create_similar,_jl_libcairo), Ptr{Void},
- (Ptr{Void}, Int32, Int32, Int32),
+ ptr = ccall((:cairo_surface_create_similar,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing}, Int32, Int32, Int32),
s.ptr, CONTENT_COLOR_ALPHA, w, h)
CairoSurface(ptr, w, h)
end
@@ -425,23 +427,23 @@ end
## Scripting
-type CairoScript <: GraphicsDevice
- ptr::Ptr{Void}
+mutable struct CairoScript <: GraphicsDevice
+ ptr::Ptr{Nothing}
function CairoScript(filename::AbstractString)
ptr = ccall((:cairo_script_create,_jl_libcairo),
- Ptr{Void}, (Ptr{UInt8},), String(filename))
+ Ptr{Nothing}, (Ptr{UInt8},), String(filename))
self = new(ptr)
- finalizer(self, destroy)
+ @compat finalizer(destroy, self)
self
end
- function CairoScript{T<:IO}(stream::T)
+ function CairoScript(stream::T) where {T<:IO}
callback = get_stream_callback(T)
- ptr = ccall((:cairo_script_create_for_stream,_jl_libcairo), Ptr{Void},
- (Ptr{Void}, Any), callback, stream)
+ ptr = ccall((:cairo_script_create_for_stream,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing}, Any), callback, stream)
self = new(ptr)
- finalizer(self, destroy)
+ @compat finalizer(destroy, self)
self
end
end
@@ -450,34 +452,34 @@ function destroy(s::CairoScript)
if s.ptr == C_NULL
return
end
- ccall((:cairo_device_destroy,_jl_libcairo), Void, (Ptr{Void},), s.ptr)
+ ccall((:cairo_device_destroy,_jl_libcairo), Nothing, (Ptr{Nothing},), s.ptr)
s.ptr = C_NULL
nothing
end
function CairoScriptSurface(filename::AbstractString, w::Real, h::Real)
s = CairoScript(filename)
- ptr = ccall((:cairo_script_surface_create,_jl_libcairo), Ptr{Void},
- (Ptr{Void},Int32,Float64,Float64),s.ptr ,CONTENT_COLOR_ALPHA, w, h)
+ ptr = ccall((:cairo_script_surface_create,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing},Int32,Float64,Float64),s.ptr ,CONTENT_COLOR_ALPHA, w, h)
CairoSurface(ptr, w, h)
end
function CairoScriptSurface(filename::AbstractString,sc::CairoSurface)
s = CairoScript(filename)
- ptr = ccall((:cairo_script_surface_create_for_target,_jl_libcairo), Ptr{Void},
- (Ptr{Void},Ptr{Void}),s.ptr, sc.ptr)
+ ptr = ccall((:cairo_script_surface_create_for_target,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing},Ptr{Nothing}),s.ptr, sc.ptr)
CairoSurface(ptr, sc.width, sc.height)
end
-function CairoScriptSurface{T<:IO}(stream::T, w::Real, h::Real)
+function CairoScriptSurface(stream::IO, w::Real, h::Real)
s = CairoScript(stream)
- ptr = ccall((:cairo_script_surface_create,_jl_libcairo), Ptr{Void},
- (Ptr{Void},Int32,Float64,Float64),s.ptr ,CONTENT_COLOR_ALPHA, w, h)
+ ptr = ccall((:cairo_script_surface_create,_jl_libcairo), Ptr{Nothing},
+ (Ptr{Nothing},Int32,Float64,Float64),s.ptr ,CONTENT_COLOR_ALPHA, w, h)
CairoSurface(ptr, w, h)
end
-type CairoRectangle
+mutable struct CairoRectangle
x0::Float64
y0::Float64
x1::Float64
@@ -487,13 +489,13 @@ end
CairoRectangle() = CairoRectangle(0.0, 0.0, 0.0, 0.0)
function CairoRecordingSurface(content::Int32,extents::CairoRectangle)
- ptr = ccall((:cairo_recording_surface_create,_jl_libcairo), Ptr{Void},
- (Int32,Ptr{Void}),content, Ref(extents))
+ ptr = ccall((:cairo_recording_surface_create,_jl_libcairo), Ptr{Nothing},
+ (Int32,Ptr{Nothing}),content, Ref(extents))
CairoSurface(ptr)
end
function CairoRecordingSurface(content::Int32)
- ptr = ccall((:cairo_recording_surface_create,_jl_libcairo), Ptr{Void},
- (Int32,Ptr{Void}),content, C_NULL)
+ ptr = ccall((:cairo_recording_surface_create,_jl_libcairo), Ptr{Nothing},
+ (Int32,Ptr{Nothing}),content, C_NULL)
CairoSurface(ptr)
end
@@ -502,34 +504,34 @@ CairoRecordingSurface() = CairoRecordingSurface(CONTENT_COLOR_ALPHA)
function script_from_recording_surface(s::CairoScript,r::CairoSurface)
ccall((:cairo_script_from_recording_surface,_jl_libcairo), Int32,
- (Ptr{Void},Ptr{Void}),s.ptr, r.ptr)
+ (Ptr{Nothing},Ptr{Nothing}),s.ptr, r.ptr)
end
# -----------------------------------------------------------------------------
-type CairoContext <: GraphicsContext
- ptr::Ptr{Void}
+mutable struct CairoContext <: GraphicsContext
+ ptr::Ptr{Nothing}
surface::CairoSurface
- layout::Ptr{Void} # cache PangoLayout
+ layout::Ptr{Nothing} # cache PangoLayout
function CairoContext(surface::CairoSurface)
ptr = ccall((:cairo_create,_jl_libcairo),
- Ptr{Void}, (Ptr{Void},), surface.ptr)
+ Ptr{Nothing}, (Ptr{Nothing},), surface.ptr)
layout = ccall((:pango_cairo_create_layout,_jl_libpangocairo),
- Ptr{Void}, (Ptr{Void},), ptr)
+ Ptr{Nothing}, (Ptr{Nothing},), ptr)
self = new(ptr, surface, layout)
- finalizer(self, destroy)
+ @compat finalizer(destroy, self)
self
end
- function CairoContext(ptr::Ptr{Void})
+ function CairoContext(ptr::Ptr{Nothing})
ccall((:cairo_reference,_jl_libcairo),
- Ptr{Void}, (Ptr{Void},), ptr)
+ Ptr{Nothing}, (Ptr{Nothing},), ptr)
surface_p = ccall((:cairo_get_target,_jl_libcairo),
- Ptr{Void}, (Ptr{Void},), ptr)
+ Ptr{Nothing}, (Ptr{Nothing},), ptr)
surface = CairoSurface(surface_p)
layout = ccall((:pango_cairo_create_layout,_jl_libpangocairo),
- Ptr{Void}, (Ptr{Void},), ptr)
+ Ptr{Nothing}, (Ptr{Nothing},), ptr)
self = new(ptr,surface,layout)
- finalizer(self, destroy)
+ @compat finalizer(destroy, self)
self
end
@@ -542,7 +544,7 @@ function destroy(ctx::CairoContext)
if ctx.ptr == C_NULL
return
end
- ccall((:g_object_unref,_jl_libgobject), Void, (Ptr{Void},), ctx.layout)
+ ccall((:g_object_unref,_jl_libgobject), Nothing, (Ptr{Nothing},), ctx.layout)
_destroy(ctx)
ctx.ptr = C_NULL
nothing
@@ -592,7 +594,7 @@ for (NAME, FUNCTION) in Any[(:_destroy, :cairo_destroy),
@eval begin
$NAME(ctx::CairoContext) =
ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
- Void, (Ptr{Void},), ctx.ptr)
+ Nothing, (Ptr{Nothing},), ctx.ptr)
end
end
@@ -600,24 +602,24 @@ function stroke(ctx::CairoContext)
save(ctx)
# use uniform scale for stroking
reset_transform(ctx)
- ccall((:cairo_stroke, _jl_libcairo), Void, (Ptr{Void},), ctx.ptr)
+ ccall((:cairo_stroke, _jl_libcairo), Nothing, (Ptr{Nothing},), ctx.ptr)
restore(ctx)
end
function stroke_preserve(ctx::CairoContext)
save(ctx)
reset_transform(ctx)
- ccall((:cairo_stroke_preserve, _jl_libcairo), Void, (Ptr{Void},), ctx.ptr)
+ ccall((:cairo_stroke_preserve, _jl_libcairo), Nothing, (Ptr{Nothing},), ctx.ptr)
restore(ctx)
end
function paint_with_alpha(ctx::CairoContext, a)
ccall((:cairo_paint_with_alpha, _jl_libcairo),
- Void, (Ptr{Void}, Float64), ctx.ptr, a)
+ Nothing, (Ptr{Nothing}, Float64), ctx.ptr, a)
end
function get_operator(ctx::CairoContext)
- Int(ccall((:cairo_get_operator,_jl_libcairo), Int32, (Ptr{Void},), ctx.ptr))
+ Int(ccall((:cairo_get_operator,_jl_libcairo), Int32, (Ptr{Nothing},), ctx.ptr))
end
@@ -628,7 +630,7 @@ for (NAME, FUNCTION) in Any[(:set_fill_type, :cairo_set_fill_rule),
@eval begin
$NAME(ctx::CairoContext, i0::Integer) =
ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
- Void, (Ptr{Void},Int32), ctx.ptr, i0)
+ Nothing, (Ptr{Nothing},Int32), ctx.ptr, i0)
end
end
@@ -638,7 +640,7 @@ for (NAME, FUNCTION) in Any[(:set_line_width, :cairo_set_line_width),
@eval begin
$NAME(ctx::CairoContext, d0::Real) =
ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
- Void, (Ptr{Void},Float64), ctx.ptr, d0)
+ Nothing, (Ptr{Nothing},Float64), ctx.ptr, d0)
end
end
@@ -651,7 +653,7 @@ for (NAME, FUNCTION) in Any[(:line_to, :cairo_line_to),
@eval begin
$NAME(ctx::CairoContext, d0::Real, d1::Real) =
ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
- Void, (Ptr{Void},Float64,Float64), ctx.ptr, d0, d1)
+ Nothing, (Ptr{Nothing},Float64,Float64), ctx.ptr, d0, d1)
end
end
@@ -660,7 +662,7 @@ for (NAME, FUNCTION) in Any[(:curve_to, :cairo_curve_to),
@eval begin
$NAME(ctx::CairoContext, d0::Real, d1::Real, d2::Real, d3::Real, d4::Real, d5::Real) =
ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
- Void, (Ptr{Void},Float64,Float64,Float64,Float64,Float64,Float64), ctx.ptr, d0, d1, d2, d3, d4, d5)
+ Nothing, (Ptr{Nothing},Float64,Float64,Float64,Float64,Float64,Float64), ctx.ptr, d0, d1, d2, d3, d4, d5)
end
end
@@ -669,7 +671,7 @@ for (NAME, FUNCTION) in Any[(:arc, :cairo_arc),
@eval begin
$NAME(ctx::CairoContext, xc::Real, yc::Real, radius::Real, angle1::Real, angle2::Real) =
ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
- Void, (Ptr{Void},Float64,Float64,Float64,Float64,Float64),
+ Nothing, (Ptr{Nothing},Float64,Float64,Float64,Float64,Float64),
ctx.ptr, xc, yc, radius, angle1, angle2)
end
end
@@ -677,11 +679,11 @@ end
set_source_rgb(ctx::CairoContext, r::Real, g::Real, b::Real) =
ccall((:cairo_set_source_rgb,_jl_libcairo),
- Void, (Ptr{Void},Float64,Float64,Float64), ctx.ptr, r, g, b)
+ Nothing, (Ptr{Nothing},Float64,Float64,Float64), ctx.ptr, r, g, b)
set_source_rgba(ctx::CairoContext, r::Real, g::Real, b::Real, a::Real) =
- ccall((:cairo_set_source_rgba,_jl_libcairo), Void,
- (Ptr{Void},Float64,Float64,Float64,Float64),
+ ccall((:cairo_set_source_rgba,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Float64,Float64,Float64,Float64),
ctx.ptr, r, g, b, a)
function set_source(ctx::CairoContext, c::Color)
@@ -699,18 +701,18 @@ set_source(dest::CairoContext, src::CairoContext) = set_source_surface(dest, src
set_source(dest::CairoContext, src::CairoSurface) = set_source_surface(dest, src)
rectangle(ctx::CairoContext, x::Real, y::Real, w::Real, h::Real) =
- ccall((:cairo_rectangle,_jl_libcairo), Void,
- (Ptr{Void},Float64,Float64,Float64,Float64),
+ ccall((:cairo_rectangle,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Float64,Float64,Float64,Float64),
ctx.ptr, x, y, w, h)
function set_dash(ctx::CairoContext, dashes::Vector{Float64}, offset::Real = 0.0)
- ccall((:cairo_set_dash,_jl_libcairo), Void,
- (Ptr{Void},Ptr{Float64},Int32,Float64), ctx.ptr, dashes, length(dashes), offset)
+ ccall((:cairo_set_dash,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Ptr{Float64},Int32,Float64), ctx.ptr, dashes, length(dashes), offset)
end
function set_source_surface(ctx::CairoContext, s::CairoSurface, x::Real = 0.0, y::Real = 0.0)
- ccall((:cairo_set_source_surface,_jl_libcairo), Void,
- (Ptr{Void},Ptr{Void},Float64,Float64), ctx.ptr, s.ptr, x, y)
+ ccall((:cairo_set_source_surface,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Ptr{Nothing},Float64,Float64), ctx.ptr, s.ptr, x, y)
end
function set_source(ctx::CairoContext, s::CairoSurface, x::Real, y::Real)
@@ -720,24 +722,24 @@ end
# cairo_path data and functions
-type CairoPath_t
+mutable struct CairoPath_t
status::Cairo.status_t
data::Ptr{Float64}
num_data::UInt32
end
-type CairoPath <: GraphicsDevice
+mutable struct CairoPath <: GraphicsDevice
ptr::Ptr{CairoPath_t}
- function CairoPath(ptr::Ptr{Void})
+ function CairoPath(ptr::Ptr{Nothing})
self = new(ptr)
- finalizer(self, destroy)
+ @compat finalizer(destroy, self)
self
end
end
# Abstract, contains type (moveto,lineto,curveto,closepath) and points
-type CairoPathEntry
+mutable struct CairoPathEntry
element_type::UInt32
points::Array{Float64,1}
end
@@ -747,24 +749,24 @@ function destroy(path::CairoPath)
if path.ptr == C_NULL
return
end
- ccall((:cairo_path_destroy,_jl_libcairo), Void, (Ptr{Void},), path.ptr)
+ ccall((:cairo_path_destroy,_jl_libcairo), Nothing, (Ptr{Nothing},), path.ptr)
path.ptr = C_NULL
nothing
end
function copy_path(ctx::CairoContext)
ptr = ccall((:cairo_copy_path, _jl_libcairo),
- Ptr{Void}, (Ptr{Void},),ctx.ptr)
+ Ptr{Nothing}, (Ptr{Nothing},),ctx.ptr)
path = CairoPath(ptr)
- finalizer(path, destroy)
+ @compat finalizer(destroy, path)
path
end
function copy_path_flat(ctx::CairoContext)
ptr = ccall((:cairo_copy_path_flat, _jl_libcairo),
- Ptr{Void}, (Ptr{Void},),ctx.ptr)
+ Ptr{Nothing}, (Ptr{Nothing},),ctx.ptr)
path = CairoPath(ptr)
- finalizer(path, destroy)
+ @compat finalizer(destroy, path)
path
end
@@ -775,7 +777,7 @@ function convert_cairo_path_data(p::CairoPath)
# define here by Float64 (most data is) and reinterpret in the header.
path_data = CairoPathEntry[]
- c_data = unsafe_wrap(Array,c.data,(Int(c.num_data*2),1),false)
+ c_data = unsafe_wrap(Array, c.data, (Int(c.num_data*2), 1), false)
data_index = 1
while data_index <= ((c.num_data)*2)
@@ -785,7 +787,7 @@ function convert_cairo_path_data(p::CairoPath)
element_type = reinterpret(UInt64,c_data[data_index]) & 0xffffffff
# copy points x,y
- points = Vector{Float64}((element_length - 1) * 2)
+ points = Vector{Float64}(uninitialized, (element_length - 1) * 2)
for i=1:(element_length-1)*2
points[i] = c_data[data_index+i+1]
end
@@ -810,7 +812,7 @@ for (fname,cname) in ((:user_to_device!,:cairo_user_to_device),
@eval begin
function ($fname)(ctx::CairoContext, p::Vector{Float64})
ccall(($(Expr(:quote,cname)),_jl_libcairo),
- Void, (Ptr{Void}, Ptr{Float64}, Ptr{Float64}),
+ Nothing, (Ptr{Nothing}, Ptr{Float64}, Ptr{Float64}),
ctx.ptr, pointer(p,1), pointer(p,2))
p
end
@@ -841,7 +843,7 @@ function push_group(ctx::CairoContext)
if ctx.ptr == C_NULL
return
end
- ccall((:cairo_push_group, _jl_libcairo), Void, (Ptr{Void},),ctx.ptr)
+ ccall((:cairo_push_group, _jl_libcairo), Nothing, (Ptr{Nothing},),ctx.ptr)
nothing
end
@@ -849,99 +851,99 @@ function pop_group(ctx::CairoContext)
if ctx.ptr == C_NULL
return
end
- ptr = ccall((:cairo_pop_group, _jl_libcairo), Ptr{Void}, (Ptr{Void},),ctx.ptr)
+ ptr = ccall((:cairo_pop_group, _jl_libcairo), Ptr{Nothing}, (Ptr{Nothing},),ctx.ptr)
pattern = CairoPattern(ptr)
- finalizer(pattern, destroy)
+ @compat finalizer(destroy, pattern)
pattern
end
# -----------------------------------------------------------------------------
-type CairoPattern
- ptr::Ptr{Void}
+mutable struct CairoPattern
+ ptr::Ptr{Nothing}
end
function CairoPattern(s::CairoSurface)
ptr = ccall((:cairo_pattern_create_for_surface, _jl_libcairo),
- Ptr{Void}, (Ptr{Void},), s.ptr)
+ Ptr{Nothing}, (Ptr{Nothing},), s.ptr)
# Ideally we'd check the status, but at least for certain releases of the library
# the return value seems not to be set properly (random values are returned)
# status = ccall((:cairo_pattern_status, _jl_libcairo),
-# Cint, (Ptr{Void},), s.ptr)
+# Cint, (Ptr{Nothing},), s.ptr)
# if status != 0
# error("Error creating Cairo pattern: ", bytestring(
# ccall((:cairo_status_to_string, _jl_libcairo),
# Ptr{UInt8}, (Cint,), status)))
# end
pattern = CairoPattern(ptr)
- finalizer(pattern, destroy)
+ @compat finalizer(destroy, pattern)
pattern
end
set_source(dest::CairoContext, src::CairoPattern) =
ccall((:cairo_set_source, _jl_libcairo),
- Void, (Ptr{Void}, Ptr{Void}), dest.ptr, src.ptr)
+ Nothing, (Ptr{Nothing}, Ptr{Nothing}), dest.ptr, src.ptr)
function get_source(ctx::CairoContext)
CairoPattern(ccall((:cairo_get_source,_jl_libcairo),
- Ptr{Void}, (Ptr{Void},), ctx.ptr))
+ Ptr{Nothing}, (Ptr{Nothing},), ctx.ptr))
end
function pattern_set_filter(p::CairoPattern, f)
- ccall((:cairo_pattern_set_filter,_jl_libcairo), Void,
- (Ptr{Void},Int32), p.ptr, f)
+ ccall((:cairo_pattern_set_filter,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Int32), p.ptr, f)
end
function pattern_set_extend(p::CairoPattern, val)
- ccall((:cairo_pattern_set_extend,_jl_libcairo), Void,
- (Ptr{Void},Int32), p.ptr, val)
+ ccall((:cairo_pattern_set_extend,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Int32), p.ptr, val)
end
function pattern_create_radial(cx0::Real, cy0::Real, radius0::Real, cx1::Real, cy1::Real, radius1::Real)
ptr = ccall((:cairo_pattern_create_radial, _jl_libcairo),
- Ptr{Void}, (Float64,Float64,Float64,Float64,Float64,Float64),cx0,cy0,radius0,cx1,cy1,radius1)
+ Ptr{Nothing}, (Float64,Float64,Float64,Float64,Float64,Float64),cx0,cy0,radius0,cx1,cy1,radius1)
pattern = CairoPattern(ptr)
- finalizer(pattern, destroy)
+ @compat finalizer(destroy, pattern)
pattern
end
function pattern_create_linear(x0::Real, y0::Real, x1::Real, y1::Real)
ptr = ccall((:cairo_pattern_create_linear, _jl_libcairo),
- Ptr{Void}, (Float64,Float64,Float64,Float64),x0,y0,x1,y1)
+ Ptr{Nothing}, (Float64,Float64,Float64,Float64),x0,y0,x1,y1)
pattern = CairoPattern(ptr)
- finalizer(pattern, destroy)
+ @compat finalizer(destroy, pattern)
pattern
end
function pattern_add_color_stop_rgb(pat::CairoPattern, offset::Real, red::Real, green::Real, blue::Real)
ccall((:cairo_pattern_add_color_stop_rgb, _jl_libcairo),
- Void, (Ptr{Void},Float64,Float64,Float64,Float64),pat.ptr,offset,red,green,blue)
+ Nothing, (Ptr{Nothing},Float64,Float64,Float64,Float64),pat.ptr,offset,red,green,blue)
end
function pattern_add_color_stop_rgba(pat::CairoPattern, offset::Real, red::Real, green::Real, blue::Real, alpha::Real)
ccall((:cairo_pattern_add_color_stop_rgba, _jl_libcairo),
- Void, (Ptr{Void},Float64,Float64,Float64,Float64,Float64),pat.ptr,offset,red,green,blue,alpha)
+ Nothing, (Ptr{Nothing},Float64,Float64,Float64,Float64,Float64),pat.ptr,offset,red,green,blue,alpha)
end
function pattern_get_surface(pat::CairoPattern)
- ptrref = Ref{Ptr{Void}}()
+ ptrref = Ref{Ptr{Nothing}}()
status = ccall((:cairo_pattern_get_surface, _jl_libcairo), Cint,
- (Ptr{Void}, Ref{Ptr{Void}}), pat.ptr, ptrref)
+ (Ptr{Nothing}, Ref{Ptr{Nothing}}), pat.ptr, ptrref)
if status == STATUS_PATTERN_TYPE_MISMATCH
error("Cannot get surface from a non-surface pattern.")
end
ptr = ptrref.x
- ccall((:cairo_surface_reference, _jl_libcairo), Ptr{Void}, (Ptr{Void},), ptr)
- typ = ccall((:cairo_surface_get_type, _jl_libcairo), Cint, (Ptr{Void},), ptr)
+ ccall((:cairo_surface_reference, _jl_libcairo), Ptr{Nothing}, (Ptr{Nothing},), ptr)
+ typ = ccall((:cairo_surface_get_type, _jl_libcairo), Cint, (Ptr{Nothing},), ptr)
w = 0.0
h = 0.0
if typ == CAIRO_SURFACE_TYPE_IMAGE
w = ccall((:cairo_image_surface_get_width, _jl_libcairo),
- Int32, (Ptr{Void},), ptr)
+ Int32, (Ptr{Nothing},), ptr)
h = ccall((:cairo_image_surface_get_height, _jl_libcairo),
- Int32, (Ptr{Void},), ptr)
+ Int32, (Ptr{Nothing},), ptr)
end
return CairoSurface(ptr, w, h)
end
@@ -950,7 +952,7 @@ function destroy(pat::CairoPattern)
if pat.ptr == C_NULL
return
end
- ccall((:cairo_pattern_destroy,_jl_libcairo), Void, (Ptr{Void},), pat.ptr)
+ ccall((:cairo_pattern_destroy,_jl_libcairo), Nothing, (Ptr{Nothing},), pat.ptr)
pat.ptr = C_NULL
nothing
end
@@ -960,16 +962,16 @@ end
# create mesh pattern
function CairoPatternMesh()
ptr = ccall((:cairo_pattern_create_mesh, _jl_libcairo),
- Ptr{Void}, ())
+ Ptr{Nothing}, ())
pattern = CairoPattern(ptr)
#status = ccall((:cairo_pattern_status, _jl_libcairo),
- # Cint, (Ptr{Void},), pattern.ptr)
+ # Cint, (Ptr{Nothing},), pattern.ptr)
#if status != 0
# error("Error creating Cairo pattern: ", bytestring(
# ccall((:cairo_status_to_string, _jl_libcairo),
# Ptr{Uint8}, (Cint,), status)))
#end
- finalizer(pattern, destroy)
+ @compat finalizer(destroy, pattern)
pattern
end
@@ -979,7 +981,7 @@ end
# @eval begin
# $NAME(ctx::CairoContext, d0::Real) =
# ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
-# Void, (Ptr{Void},Float64), ctx.ptr, d0)
+# Nothing, (Ptr{Nothing},Float64), ctx.ptr, d0)
# end
#end
@@ -988,7 +990,7 @@ for (NAME, FUNCTION) in Any[(:mesh_pattern_begin_patch, :cairo_mesh_pattern_begi
@eval begin
$NAME(pattern::CairoPattern) =
ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
- Void, (Ptr{Void},), pattern.ptr)
+ Nothing, (Ptr{Nothing},), pattern.ptr)
end
end
@@ -997,7 +999,7 @@ for (NAME, FUNCTION) in Any[(:mesh_pattern_line_to, :cairo_mesh_pattern_line_to)
@eval begin
$NAME(pattern::CairoPattern, d0::Real, d1::Real) =
ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
- Void, (Ptr{Void},Float64,Float64), pattern.ptr, d0, d1)
+ Nothing, (Ptr{Nothing},Float64,Float64), pattern.ptr, d0, d1)
end
end
@@ -1006,34 +1008,34 @@ for (NAME, FUNCTION) in Any[(:mesh_pattern_curve_to, :cairo_mesh_pattern_curve_t
@eval begin
$NAME(pattern::CairoPattern, d0::Real, d1::Real, d2::Real, d3::Real, d4::Real, d5::Real) =
ccall(($(Expr(:quote,FUNCTION)),_jl_libcairo),
- Void, (Ptr{Void},Float64,Float64,Float64,Float64,Float64,Float64), pattern.ptr, d0, d1, d2, d3, d4, d5)
+ Nothing, (Ptr{Nothing},Float64,Float64,Float64,Float64,Float64,Float64), pattern.ptr, d0, d1, d2, d3, d4, d5)
end
end
function mesh_pattern_set_corner_color_rgb(pat::CairoPattern, corner_num::Real, red::Real, green::Real, blue::Real)
ccall((:cairo_mesh_pattern_set_corner_color_rgb, _jl_libcairo),
- Void, (Ptr{Void},Int32,Float64,Float64,Float64),pat.ptr,corner_num,red,green,blue)
+ Nothing, (Ptr{Nothing},Int32,Float64,Float64,Float64),pat.ptr,corner_num,red,green,blue)
end
function mesh_pattern_set_corner_color_rgba(pat::CairoPattern, corner_num::Real, red::Real, green::Real, blue::Real, alpha::Real)
ccall((:cairo_mesh_pattern_set_corner_color_rgba, _jl_libcairo),
- Void, (Ptr{Void},Int32,Float64,Float64,Float64,Float64),pat.ptr,corner_num,red,green,blue,alpha)
+ Nothing, (Ptr{Nothing},Int32,Float64,Float64,Float64,Float64),pat.ptr,corner_num,red,green,blue,alpha)
end
# ----
set_antialias(ctx::CairoContext, a) =
- ccall((:cairo_set_antialias,_jl_libcairo), Void,
- (Ptr{Void},Cint), ctx.ptr, a)
+ ccall((:cairo_set_antialias,_jl_libcairo), Nothing,
+ (Ptr{Nothing},Cint), ctx.ptr, a)
get_antialias(ctx::CairoContext) =
ccall((:cairo_get_antialias,_jl_libcairo), Cint,
- (Ptr{Void},), ctx.ptr)
+ (Ptr{Nothing},), ctx.ptr)
# -----------------------------------------------------------------------------
-immutable CairoMatrix
+struct CairoMatrix
xx::Float64
yx::Float64
xy::Float64
@@ -1046,16 +1048,16 @@ CairoMatrix() = CairoMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
function get_matrix(ctx::CairoContext)
m = [CairoMatrix()]
- ccall((:cairo_get_matrix, _jl_libcairo), Void, (Ptr{Void}, Ptr{Void}), ctx.ptr, m)
+ ccall((:cairo_get_matrix, _jl_libcairo), Nothing, (Ptr{Nothing}, Ptr{Nothing}), ctx.ptr, m)
m[1]
end
function set_matrix(ctx::CairoContext, m::CairoMatrix)
- ccall((:cairo_set_matrix, _jl_libcairo), Void, (Ptr{Void}, Ptr{Void}), ctx.ptr, [m])
+ ccall((:cairo_set_matrix, _jl_libcairo), Nothing, (Ptr{Nothing}, Ptr{Nothing}), ctx.ptr, [m])
end
function set_matrix(p::CairoPattern, m::CairoMatrix)
- ccall((:cairo_pattern_set_matrix, _jl_libcairo), Void, (Ptr{Void}, Ptr{Void}), p.ptr, [m])
+ ccall((:cairo_pattern_set_matrix, _jl_libcairo), Nothing, (Ptr{Nothing}, Ptr{Nothing}), p.ptr, [m])
end
@@ -1086,46 +1088,47 @@ end
function set_font_face(ctx::CairoContext, str::AbstractString)
fontdesc = ccall((:pango_font_description_from_string,_jl_libpango),
- Ptr{Void}, (Ptr{UInt8},), String(str))
- ccall((:pango_layout_set_font_description,_jl_libpango), Void,
- (Ptr{Void},Ptr{Void}), ctx.layout, fontdesc)
- ccall((:pango_font_description_free,_jl_libpango), Void,
- (Ptr{Void},), fontdesc)
+ Ptr{Nothing}, (Ptr{UInt8},), String(str))
+ ccall((:pango_layout_set_font_description,_jl_libpango), Nothing,
+ (Ptr{Nothing},Ptr{Nothing}), ctx.layout, fontdesc)
+ ccall((:pango_font_description_free,_jl_libpango), Nothing,
+ (Ptr{Nothing},), fontdesc)
end
function set_text(ctx::CairoContext, text::AbstractString, markup::Bool = false)
if markup
- ccall((:pango_layout_set_markup,_jl_libpango), Void,
- (Ptr{Void},Ptr{UInt8},Int32), ctx.layout, String(text), -1)
+ ccall((:pango_layout_set_markup,_jl_libpango), Nothing,
+ (Ptr{Nothing},Ptr{UInt8},Int32), ctx.layout, String(text), -1)
else
- ccall((:pango_layout_set_text,_jl_libpango), Void,
- (Ptr{Void},Ptr{UInt8},Int32), ctx.layout, String(text), -1)
+ ccall((:pango_layout_set_text,_jl_libpango), Nothing,
+ (Ptr{Nothing},Ptr{UInt8},Int32), ctx.layout, String(text), -1)
end
text
end
function get_layout_size(ctx::CairoContext)
- w = Vector{Int32}(2)
- ccall((:pango_layout_get_pixel_size,_jl_libpango), Void,
- (Ptr{Void},Ptr{Int32},Ptr{Int32}), ctx.layout, pointer(w,1), pointer(w,2))
+ w = Vector{Int32}(uninitialized, 2)
+ ccall((:pango_layout_get_pixel_size,_jl_libpango), Nothing,
+ (Ptr{Nothing},Ptr{Int32},Ptr{Int32}), ctx.layout, pointer(w,1), pointer(w,2))
w
end
function update_layout(ctx::CairoContext)
- ccall((:pango_cairo_update_layout,_jl_libpangocairo), Void,
- (Ptr{Void},Ptr{Void}), ctx.ptr, ctx.layout)
+ ccall((:pango_cairo_update_layout,_jl_libpangocairo), Nothing,
+ (Ptr{Nothing},Ptr{Nothing}), ctx.ptr, ctx.layout)
end
function show_layout(ctx::CairoContext)
- ccall((:pango_cairo_show_layout,_jl_libpangocairo), Void,
- (Ptr{Void},Ptr{Void}), ctx.ptr, ctx.layout)
+ ccall((:pango_cairo_show_layout,_jl_libpangocairo), Nothing,
+ (Ptr{Nothing},Ptr{Nothing}), ctx.ptr, ctx.layout)
end
-text_extents(ctx::CairoContext,value::AbstractString) = text_extents!(ctx,value, Matrix{Float64}(6, 1))
+text_extents(ctx::CairoContext,value::AbstractString) =
+ text_extents!(ctx,value, Matrix{Float64}(uninitialized, 6, 1))
function text_extents!(ctx::CairoContext,value::AbstractString,extents)
ccall((:cairo_text_extents, _jl_libcairo),
- Void, (Ptr{Void}, Ptr{UInt8}, Ptr{Float64}),
+ Nothing, (Ptr{Nothing}, Ptr{UInt8}, Ptr{Float64}),
ctx.ptr, String(value), extents)
extents
end
@@ -1137,7 +1140,7 @@ function path_extents(ctx::CairoContext)
dy2 = Cdouble[0]
ccall((:cairo_path_extents, _jl_libcairo),
- Void, (Ptr{Void}, Ptr{Cdouble}, Ptr{Cdouble},
+ Nothing, (Ptr{Nothing}, Ptr{Cdouble}, Ptr{Cdouble},
Ptr{Cdouble}, Ptr{Cdouble}),
ctx.ptr, dx1, dy1, dx2, dy2)
@@ -1147,20 +1150,20 @@ end
function show_text(ctx::CairoContext,value::AbstractString)
ccall((:cairo_show_text, _jl_libcairo),
- Void, (Ptr{Void}, Ptr{UInt8}),
+ Nothing, (Ptr{Nothing}, Ptr{UInt8}),
ctx.ptr, String(value))
end
function text_path(ctx::CairoContext,value::AbstractString)
ccall((:cairo_text_path, _jl_libcairo),
- Void, (Ptr{Void}, Ptr{UInt8}),
+ Nothing, (Ptr{Nothing}, Ptr{UInt8}),
ctx.ptr, String(value))
end
function select_font_face(ctx::CairoContext,family::AbstractString,slant,weight)
ccall((:cairo_select_font_face, _jl_libcairo),
- Void, (Ptr{Void}, Ptr{UInt8},
+ Nothing, (Ptr{Nothing}, Ptr{UInt8},
font_slant_t, font_weight_t),
ctx.ptr, String(family),
slant, weight)
@@ -1211,7 +1214,7 @@ end
set_latex(ctx::CairoContext, str::AbstractString, fontsize::Real) = set_text(ctx, tex2pango(str, fontsize), true)
-type TeXLexer
+mutable struct TeXLexer
str::String
len::Int
pos::Int
@@ -1219,7 +1222,7 @@ type TeXLexer
function TeXLexer(str::AbstractString)
s = String(str)
- new(s, endof(s), 1, String[])
+ new(s, lastindex(s), 1, String[])
end
end
@@ -1363,7 +1366,7 @@ end
@deprecate layout_text(ctx::CairoContext, str::AbstractString, fontsize::Real) set_latex(ctx, str, fontsize)
@deprecate textwidth(ctx::CairoContext, str::AbstractString, fontsize::Real) textwidth(ctx, tex2pango(str, fontsize), true)
@deprecate textheight(ctx::CairoContext, str::AbstractString, fontsize::Real) textheight(ctx, tex2pango(str, fontsize), true)
-@deprecate cairo_write_to_ios_callback(s::Ptr{Void}, buf::Ptr{UInt8}, len::UInt32) write_to_ios_callback(s, buf, len)
+@deprecate cairo_write_to_ios_callback(s::Ptr{Nothing}, buf::Ptr{UInt8}, len::UInt32) write_to_ios_callback(s, buf, len)
@deprecate cairo_write_to_stream_callback(s::IO, buf::Ptr{UInt8}, len::UInt32) write_to_stream_callback(s, buf, len)
@deprecate text_extents(ctx::CairoContext,value::AbstractString,extents) text_extents!(ctx,value,extents)
diff --git a/test/REQUIRE b/test/REQUIRE
deleted file mode 100644
index 94e516f..0000000
--- a/test/REQUIRE
+++ /dev/null
@@ -1 +0,0 @@
-BaseTestNext
diff --git a/test/runtests.jl b/test/runtests.jl
index cd25f5c..6f93402 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -1,10 +1,10 @@
using Cairo
using Compat, Colors
-import Compat.String
+import Compat.Sys
import Base.show
-using Base.Test
+using Compat.Test
# Image Surface
@@ -55,9 +55,9 @@ end
# Test creating a CairoContext from a cairo_t pointer
surf = CairoImageSurface(fill(ARGB32(0), 10, 10))
- ctx_ptr = ccall((:cairo_create, Cairo._jl_libcairo),Ptr{Void}, (Ptr{Void}, ), surf.ptr)
+ ctx_ptr = ccall((:cairo_create, Cairo._jl_libcairo),Ptr{Nothing}, (Ptr{Nothing}, ), surf.ptr)
ctx = CairoContext(ctx_ptr)
- ccall((:cairo_destroy,Cairo._jl_libcairo),Void, (Ptr{Void}, ), ctx_ptr)
+ ccall((:cairo_destroy,Cairo._jl_libcairo),Nothing, (Ptr{Nothing}, ), ctx_ptr)
@test isa(ctx, CairoContext)
end
@@ -77,13 +77,15 @@ end
samples_files = setdiff(samples_files, files_to_exclude)
end
- for test_file_name in samples_files
- include(joinpath(samples_dir_path, test_file_name))
+ sc = asyncmap(samples_files, ntasks=4) do test_file_name
+ b = success(`$(Base.julia_cmd()) $(joinpath(samples_dir_path, test_file_name))`)
output_png_name = replace(test_file_name,".jl",".png")
- @test isfile(output_png_name)
+ b &= isfile(output_png_name)
rm(output_png_name)
+ return b
end
-end
+ @test all(sc)
+end
# Run some painting, check the colored pixels by counting them
@testset "Bitmap Painting" begin
@@ -93,37 +95,37 @@ end
# fill all
z = zeros(UInt32,512,512);
surf = CairoImageSurface(z, Cairo.FORMAT_ARGB32)
- # fills a 512x512 pixel area with blue,0.5 by using a hilbert curve of
+ # fills a 512x512 pixel area with blue,0.5 by using a hilbert curve of
# dimension 64 (scaled by 8 -> 512) and a linewidth of 8
- hdraw(surf,64,8,8)
+ hdraw(surf,64,8,8)
d = simple_hist(surf.data)
- @test length(d) == 1
+ @test length(d) == 1
@test collect(keys(d))[1] == 0x80000080
# fill 1/4 (upper quarter)
z = zeros(UInt32,512,512);
surf = CairoImageSurface(z, Cairo.FORMAT_ARGB32)
- # fills a 256x256 pixel area with blue,0.5 by using a hilbert curve of
+ # fills a 256x256 pixel area with blue,0.5 by using a hilbert curve of
# dimension 32 (scaled by 8 -> 256) and a linewidth of 8
- hdraw(surf,32,8,8)
+ hdraw(surf,32,8,8)
d = simple_hist(surf.data)
- @test length(d) == 2
+ @test length(d) == 2
@test d[0x80000080] == 256*256
- # fill ~1/2 full,
+ # fill ~1/2 full,
z = zeros(UInt32,512,512);
surf = CairoImageSurface(z, Cairo.FORMAT_ARGB32)
- # fills a 512x512 pixel area with blue,0.5 by using a hilbert curve of
+ # fills a 512x512 pixel area with blue,0.5 by using a hilbert curve of
# dimension 64 (scaled by 8 -> 512) and a linewidth of 4 -> 1/4 of pixels -16
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
d = simple_hist(surf.data)
- @test length(d) == 2
+ @test length(d) == 2
@test d[0x80000080] == ((512*256)-16)
end
@@ -132,7 +134,7 @@ end
output_file_name = "a.svg"
surf = CairoSVGSurface(output_file_name,512,512)
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
finish(surf)
@test isfile(output_file_name)
@@ -140,9 +142,9 @@ end
io = IOBuffer()
surf = CairoSVGSurface(io,512,512)
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
finish(surf)
-
+
seek(io,0)
str_data = Vector{UInt8}(read(io))
@@ -150,7 +152,7 @@ end
output_file_name = "a.pdf"
surf = CairoPDFSurface(output_file_name,512,512)
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
finish(surf)
@test isfile(output_file_name)
@@ -158,7 +160,7 @@ end
io = IOBuffer()
surf = CairoPDFSurface(io,512,512)
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
finish(surf)
seek(io,0)
@@ -168,7 +170,7 @@ end
output_file_name = "a.eps"
surf = CairoEPSSurface(output_file_name,512,512)
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
finish(surf)
@test isfile(output_file_name)
@@ -176,17 +178,17 @@ end
io = IOBuffer()
surf = CairoEPSSurface(io,512,512)
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
finish(surf)
-
+
seek(io,0)
str_data = Vector{UInt8}(read(io))
-
+
@test length(str_data) > 3000 && str_data[1:10] == [0x25,0x21,0x50,0x53,0x2d,0x41,0x64,0x6f,0x62,0x65]
output_file_name = "a.ps"
surf = CairoPSSurface(output_file_name,512,512)
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
finish(surf)
@test isfile(output_file_name)
@@ -194,62 +196,70 @@ end
io = IOBuffer()
surf = CairoPSSurface(io,512,512)
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
finish(surf)
-
+
seek(io,0)
str_data = Vector{UInt8}(read(io))
-
+
@test length(str_data) > 3000 && str_data[1:10] == [0x25,0x21,0x50,0x53,0x2d,0x41,0x64,0x6f,0x62,0x65]
-
if Cairo.libcairo_version >= v"1.12.0"
- if ~is_windows()
-
- output_file_name = "a.cs"
- surf = CairoScriptSurface(output_file_name,512,512)
- hdraw(surf,64,8,4)
- destroy(surf)
+ # FixMe! I'm not sure has anything to do with Windows. See comment below.
+ if !Sys.iswindows()
- @test isfile(output_file_name)
+ output_file_name = "a.cs"
+ surf = CairoScriptSurface(output_file_name,512,512)
+ hdraw(surf,64,8,4)
+ # FixMe! The use of gc here is not a real solution but makes the tests pass for now. The issue here is
+ # that Cairo only writes to the file when the CairoScript handle is finalized. Either Cairo.jl should
+ # stop supporting this API or handle should be explicitly closed instead of using finalizers.
+ destroy(surf);GC.gc()
- str_data = read(output_file_name)
- @test length(str_data) > 3000 && str_data[1:10] == [0x25,0x21,0x43,0x61,0x69,0x72,0x6f,0x53,0x63,0x72]
- rm(output_file_name)
+ @test isfile(output_file_name)
+
+ str_data = read(output_file_name)
+ @test length(str_data) > 3000
+ @test str_data[1:10] == [0x25,0x21,0x43,0x61,0x69,0x72,0x6f,0x53,0x63,0x72]
+ rm(output_file_name)
end
io = IOBuffer()
surf = CairoScriptSurface(io,512,512)
- hdraw(surf,64,8,4)
+ hdraw(surf,64,8,4)
finish(surf)
-
+
seek(io,0)
str_data = Vector{UInt8}(read(io))
-
+
@test length(str_data) > 3000 && str_data[1:10] == [0x25,0x21,0x43,0x61,0x69,0x72,0x6f,0x53,0x63,0x72]
- if ~is_windows()
- # _create_for_target
- z = zeros(UInt32,512,512);
- surf = CairoImageSurface(z, Cairo.FORMAT_ARGB32)
+ # FixMe! I'm not sure has anything to do with Windows. See comment below.
+ if !Sys.iswindows()
+ # _create_for_target
+ z = zeros(UInt32,512,512);
+ surf = CairoImageSurface(z, Cairo.FORMAT_ARGB32)
- output_file_name = "a.cs"
- scsurf = CairoScriptSurface(output_file_name,surf)
- hdraw(scsurf,64,8,8)
- finish(surf)
- destroy(scsurf)
- @test isfile(output_file_name)
+ output_file_name = "a.cs"
+ scsurf = CairoScriptSurface(output_file_name,surf)
+ hdraw(scsurf,64,8,8)
+ finish(surf)
+ # FixMe! The use of gc here is not a real solution but makes the tests pass for now. The issue here is
+ # that Cairo only writes to the file when the CairoScript handle is finalized. Either Cairo.jl should
+ # stop supporting this API or handle should be explicitly closed instead of using finalizers.
+ destroy(scsurf);GC.gc()
+ @test isfile(output_file_name)
- str_data = read(output_file_name)
- @test length(str_data) > 3000 && str_data[1:10] == [0x25,0x21,0x43,0x61,0x69,0x72,0x6f,0x53,0x63,0x72]
- rm(output_file_name)
+ str_data = read(output_file_name)
+ @test length(str_data) > 3000 && str_data[1:10] == [0x25,0x21,0x43,0x61,0x69,0x72,0x6f,0x53,0x63,0x72]
+ rm(output_file_name)
- d = simple_hist(surf.data)
+ d = simple_hist(surf.data)
- @test length(d) == 1
- @test collect(keys(d))[1] == 0x80000080
+ @test length(d) == 1
+ @test collect(keys(d))[1] == 0x80000080
end
end
@@ -258,7 +268,7 @@ end
# pixel/bitmap surfaces
@testset "Bitmap Surfaces" begin
- z = zeros(UInt32,512,512);
+ z = zeros(UInt32,512,512)
surf = CairoImageSurface(z, Cairo.FORMAT_ARGB32)
hilbert_colored(surf)
@@ -293,11 +303,11 @@ end
pa = surf.ptr
surf.ptr = C_NULL
-
+
@test destroy(surf) == nothing
surf.ptr = pa
- cr = Cairo.CairoContext(surf)
+ cr = Cairo.CairoContext(surf)
pa = cr.ptr
cr.ptr = C_NULL
diff --git a/test/shape_functions.jl b/test/shape_functions.jl
index d43627d..cb26a34 100644
--- a/test/shape_functions.jl
+++ b/test/shape_functions.jl
@@ -1,4 +1,4 @@
-using Cairo
+using Cairo, Compat, Random
# shape functions,
diff --git a/test/test_painting.jl b/test/test_painting.jl
index 2ecbd72..f160a51 100644
--- a/test/test_painting.jl
+++ b/test/test_painting.jl
@@ -39,16 +39,16 @@ end
function hilbert_colored(surf)
-
+
zscale = 8;
n1 = 8;
cr = CairoContext(surf)
-
+
c = Float64[]
hilbert_curve(c,0,0,64,0,0)
move_to(cr,0,0)
-
+
translate(cr,zscale/2,zscale/2)
scale(cr,zscale,zscale)
set_line_width(cr,zscale/2)
@@ -62,13 +62,13 @@ function hilbert_colored(surf)
set_source_rgb(cr,c1[1]/float(n1-1),c1[2]/float(n1-1),c1[3]/float(n1-1))
stroke(cr)
- end
+ end
end
""" function hdraw(s,dim,zscale,linewidth)
draws a hilbert curve with dimension dim (power of 2) and scales the drawing with
-zscale.
+zscale.
"""
function hdraw(s,dim,zscale,linewidth)
@@ -79,12 +79,12 @@ function hdraw(s,dim,zscale,linewidth)
set_line_width(cr,linewidth)
set_line_cap(cr,Cairo.CAIRO_LINE_CAP_SQUARE)
translate(cr,zscale/2,zscale/2)
-
+
save(cr)
c = Float64[]
hilbert_curve(c,0,0,dim,0,0)
-
+
scale(cr,zscale,zscale)
move_to(cr,0,0)
@@ -93,7 +93,7 @@ function hdraw(s,dim,zscale,linewidth)
end
stroke(cr)
- restore(cr)
+ restore(cr)
end
"""
@@ -118,7 +118,7 @@ end
"""
function matrix_read(surface)
paint the input surface into a matrix image of the same size to access
- the pixels.
+ the pixels.
"""
function matrix_read(surface)
w = Int(surface.width)
diff --git a/test/test_stream.jl b/test/test_stream.jl
index 346e4cf..6102b16 100644
--- a/test/test_stream.jl
+++ b/test/test_stream.jl
@@ -1,21 +1,24 @@
# So that this test can be run independently
-using Cairo
+using Cairo, Compat
+using Compat.Base64
+
if !isdefined(:ddots4)
include("shape_functions.jl")
end
-# Test that writing images to a Julia IO object works
-c = CairoRGBSurface(256,256);
-cr = CairoContext(c);
-ddots4(cr,256,246,1.0,3000)
-buf = IOBuffer()
-pipe = Base64EncodePipe(buf)
-write_to_png(c,pipe)
-close(pipe)
+@testset "Test that writing images to a Julia IO object works" begin
+ c = CairoRGBSurface(256,256)
+ cr = CairoContext(c)
+ ddots4(cr,256,246,1.0,3000)
+ buf = IOBuffer()
+ pipe = Base64EncodePipe(buf)
+ write_to_png(c,pipe)
+ close(pipe)
-# Catch short writes
+ # Catch short writes
-str = String(take!(buf))
-str_data = Vector{UInt8}(str)
+ str = String(take!(buf))
+ str_data = codeunits(str)
-@assert length(str_data) > 200
+ @test length(str_data) > 200
+end
diff --git a/test/tex.jl b/test/tex.jl
index 09995f4..adbfdf3 100644
--- a/test/tex.jl
+++ b/test/tex.jl
@@ -1,5 +1,5 @@
-using Cairo.tex2pango
-using Base.Test
+using Cairo: tex2pango
+using Compat, Test
fsize = 1.618034
@test tex2pango("ƒ_{Nyquist} [\\mu K]",fsize) == "ƒNyquist [μK]"