From 762b7be47265a7743fcd7178032586e6d43d6975 Mon Sep 17 00:00:00 2001 From: "femtocleaner[bot]" Date: Sat, 27 Jan 2018 21:05:30 +0000 Subject: [PATCH 1/9] Fix deprecations --- deps/build.jl | 10 +-- src/Cairo.jl | 50 ++++++------- src/constants.jl | 188 +++++++++++++++++++++++------------------------ test/runtests.jl | 11 +-- 4 files changed, 127 insertions(+), 132 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index d744a63..88ac577 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -59,7 +59,7 @@ end # System Package Managers provides(AptGet, - @compat Dict( + Dict( "libcairo2" => cairo, "libfontconfig1" => fontconfig, "libpango1.0-0" => [pango,pangocairo], @@ -71,7 +71,7 @@ provides(AptGet, # TODO: check whether these are accurate provides(Yum, - @compat Dict( + Dict( "cairo" => cairo, "fontconfig" => fontconfig, "pango" => [pango,pangocairo], @@ -81,7 +81,7 @@ provides(Yum, )) provides(Zypper, - @compat Dict( + Dict( "libcairo" => cairo, "libfontconfig" => fontconfig, "libpango-1.0" => [pango,pangocairo], @@ -94,7 +94,7 @@ provides(Zypper, const png_version = "1.5.14" provides(Sources, - @compat Dict( + Dict( URI("http://www.cairographics.org/releases/pixman-0.28.2.tar.gz") => pixman, URI("http://www.cairographics.org/releases/cairo-1.12.16.tar.xz") => cairo, URI("http://download.savannah.gnu.org/releases/freetype/freetype-2.4.11.tar.gz") => freetype, @@ -110,7 +110,7 @@ provides(Sources, xx(t...) = (is_windows() ? t[1] : (is_linux() || length(t) == 2) ? t[2] : t[3]) provides(BuildProcess, - @compat Dict( + Dict( Autotools(libtarget = "pixman/libpixman-1.la", installed_libname = xx("libpixman-1-0.","libpixman-1.","libpixman-1.0.")*Libdl.dlext) => pixman, Autotools(libtarget = xx("objs/.libs/libfreetype.la","libfreetype.la")) => freetype, Autotools(libtarget = "src/libfontconfig.la") => fontconfig, diff --git a/src/Cairo.jl b/src/Cairo.jl index cde509f..4ca5250 100644 --- a/src/Cairo.jl +++ b/src/Cairo.jl @@ -27,7 +27,7 @@ if !is_windows() unsafe_load(cglobal((:glib_micro_version, Cairo._jl_libgobject), Cuint))) end -@compat import Base.show +import Base.show include("constants.jl") @@ -137,7 +137,7 @@ Cairo function write_to_stream_callback(s::IO, buf::Ptr{UInt8}, len::UInt32) n = VERSION < v"0.5-dev+2301" ? write(s,buf,len) : unsafe_write(s,buf,len) - @compat Int32((n == len) ? 0 : 11) + Int32((n == len) ? 0 : 11) end get_stream_callback(T) = cfunction(write_to_stream_callback, Int32, (Ref{T}, Ptr{UInt8}, UInt32)) @@ -183,9 +183,9 @@ type CairoSurface{T<:Union{UInt32,RGB24,ARGB32}} <: GraphicsDevice end end -@compat (::Type{CairoSurface})(ptr, w, h) = CairoSurface{UInt32}(ptr, w, h) -@compat (::Type{CairoSurface})(ptr, w, h, data) = CairoSurface{eltype(data)}(ptr, w, h, data) -@compat (::Type{CairoSurface})(ptr) = CairoSurface{UInt32}(ptr) +(::Type{CairoSurface})(ptr, w, h) = CairoSurface{UInt32}(ptr, w, h) +(::Type{CairoSurface})(ptr, w, h, data) = CairoSurface{eltype(data)}(ptr, w, h, data) +(::Type{CairoSurface})(ptr) = CairoSurface{UInt32}(ptr) width(surface::CairoSurface) = surface.width height(surface::CairoSurface) = surface.height @@ -248,7 +248,7 @@ function CairoImageSurface(img::Array{UInt32,2}, format::Integer; flipxy::Bool = CairoSurface(ptr, w, h, img) end -function CairoImageSurface{T<:@compat(Union{RGB24,ARGB32})}(img::Matrix{T}) +function CairoImageSurface{T<:Union{RGB24,ARGB32}}(img::Matrix{T}) w,h = size(img) stride = format_stride_for_width(format(T), w) @assert stride == 4w @@ -260,7 +260,7 @@ end format(::Type{RGB24}) = FORMAT_RGB24 format(::Type{ARGB32}) = FORMAT_ARGB32 -format{T<:@compat(Union{RGB24,ARGB32})}(surf::CairoSurface{T}) = T +format{T<:Union{RGB24,ARGB32}}(surf::CairoSurface{T}) = T ## PDF ## @@ -273,7 +273,7 @@ end function CairoPDFSurface(filename::AbstractString, w_pts::Real, h_pts::Real) ptr = ccall((:cairo_pdf_surface_create,_jl_libcairo), Ptr{Void}, - (Ptr{UInt8},Float64,Float64), @compat(String(filename)), w_pts, h_pts) + (Ptr{UInt8},Float64,Float64), String(filename), w_pts, h_pts) CairoSurface(ptr, w_pts, h_pts) end @@ -290,7 +290,7 @@ end function CairoEPSSurface(filename::AbstractString, w_pts::Real, h_pts::Real) ptr = ccall((:cairo_ps_surface_create,_jl_libcairo), Ptr{Void}, - (Ptr{UInt8},Float64,Float64), @compat(String(filename)), w_pts, h_pts) + (Ptr{UInt8},Float64,Float64), String(filename), w_pts, h_pts) ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Void, (Ptr{Void},Int32), ptr, 1) CairoSurface(ptr, w_pts, h_pts) @@ -318,7 +318,7 @@ end function CairoPSSurface(filename::AbstractString, w_pts::Real, h_pts::Real) ptr = ccall((:cairo_ps_surface_create,_jl_libcairo), Ptr{Void}, - (Ptr{UInt8},Float64,Float64), @compat(String(filename)), w_pts, h_pts) + (Ptr{UInt8},Float64,Float64), String(filename), w_pts, h_pts) ccall((:cairo_ps_surface_set_eps,_jl_libcairo), Void, (Ptr{Void},Int32), ptr, 0) CairoSurface(ptr, w_pts, h_pts) @@ -364,7 +364,7 @@ end function CairoSVGSurface(filename::AbstractString, w::Real, h::Real) ptr = ccall((:cairo_svg_surface_create,_jl_libcairo), Ptr{Void}, - (Ptr{UInt8},Float64,Float64), @compat(String(filename)), w, h) + (Ptr{UInt8},Float64,Float64), String(filename), w, h) CairoSurface(ptr, w, h) end @@ -372,7 +372,7 @@ end function read_from_png(filename::AbstractString) ptr = ccall((:cairo_image_surface_create_from_png,_jl_libcairo), - Ptr{Void}, (Ptr{UInt8},), @compat(String(filename))) + Ptr{Void}, (Ptr{UInt8},), String(filename)) w = ccall((:cairo_image_surface_get_width,_jl_libcairo), Int32, (Ptr{Void},), ptr) h = ccall((:cairo_image_surface_get_height,_jl_libcairo), @@ -388,10 +388,10 @@ end function write_to_png(surface::CairoSurface, filename::AbstractString) ccall((:cairo_surface_write_to_png,_jl_libcairo), Void, - (Ptr{UInt8},Ptr{UInt8}), surface.ptr, @compat(String(filename))) + (Ptr{UInt8},Ptr{UInt8}), surface.ptr, String(filename)) end -@compat show(io::IO, ::MIME"image/png", surface::CairoSurface) = +show(io::IO, ::MIME"image/png", surface::CairoSurface) = write_to_png(surface, io) function read_from_png{T<:IO}(stream::T) @@ -430,7 +430,7 @@ type CairoScript <: GraphicsDevice function CairoScript(filename::AbstractString) ptr = ccall((:cairo_script_create,_jl_libcairo), - Ptr{Void}, (Ptr{UInt8},), @compat(String(filename))) + Ptr{Void}, (Ptr{UInt8},), String(filename)) self = new(ptr) finalizer(self, destroy) self @@ -617,7 +617,7 @@ function paint_with_alpha(ctx::CairoContext, a) end function get_operator(ctx::CairoContext) - @compat Int(ccall((:cairo_get_operator,_jl_libcairo), Int32, (Ptr{Void},), ctx.ptr)) + Int(ccall((:cairo_get_operator,_jl_libcairo), Int32, (Ptr{Void},), ctx.ptr)) end @@ -775,7 +775,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 = @compat 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) @@ -1086,7 +1086,7 @@ end function set_font_face(ctx::CairoContext, str::AbstractString) fontdesc = ccall((:pango_font_description_from_string,_jl_libpango), - Ptr{Void}, (Ptr{UInt8},), @compat(String(str))) + 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, @@ -1096,10 +1096,10 @@ 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, @compat(String(text)), -1) + (Ptr{Void},Ptr{UInt8},Int32), ctx.layout, String(text), -1) else ccall((:pango_layout_set_text,_jl_libpango), Void, - (Ptr{Void},Ptr{UInt8},Int32), ctx.layout, @compat(String(text)), -1) + (Ptr{Void},Ptr{UInt8},Int32), ctx.layout, String(text), -1) end text end @@ -1126,7 +1126,7 @@ text_extents(ctx::CairoContext,value::AbstractString) = text_extents!(ctx,value, function text_extents!(ctx::CairoContext,value::AbstractString,extents) ccall((:cairo_text_extents, _jl_libcairo), Void, (Ptr{Void}, Ptr{UInt8}, Ptr{Float64}), - ctx.ptr, @compat(String(value)), extents) + ctx.ptr, String(value), extents) extents end @@ -1148,13 +1148,13 @@ end function show_text(ctx::CairoContext,value::AbstractString) ccall((:cairo_show_text, _jl_libcairo), Void, (Ptr{Void}, Ptr{UInt8}), - ctx.ptr, @compat(String(value))) + ctx.ptr, String(value)) end function text_path(ctx::CairoContext,value::AbstractString) ccall((:cairo_text_path, _jl_libcairo), Void, (Ptr{Void}, Ptr{UInt8}), - ctx.ptr, @compat(String(value))) + ctx.ptr, String(value)) end @@ -1162,7 +1162,7 @@ function select_font_face(ctx::CairoContext,family::AbstractString,slant,weight) ccall((:cairo_select_font_face, _jl_libcairo), Void, (Ptr{Void}, Ptr{UInt8}, font_slant_t, font_weight_t), - ctx.ptr, @compat(String(family)), + ctx.ptr, String(family), slant, weight) end @@ -1218,7 +1218,7 @@ type TeXLexer token_stack::Array{String,1} function TeXLexer(str::AbstractString) - s = @compat String(str) + s = String(str) new(s, endof(s), 1, String[]) end end diff --git a/src/constants.jl b/src/constants.jl index bda930b..3aac3ad 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -17,95 +17,95 @@ export CAIRO_FORMAT_ARGB32, CAIRO_FILTER_GAUSSIAN const format_t = Int32 -const FORMAT_INVALID = @compat Int32(-1) -const FORMAT_ARGB32 = @compat Int32(0) -const FORMAT_RGB24 = @compat Int32(1) -const FORMAT_A8 = @compat Int32(2) -const FORMAT_A1 = @compat Int32(3) -const FORMAT_RGB16_565 = @compat Int32(4) -const FORMAT_RGB30 = @compat Int32(5) +const FORMAT_INVALID = Int32(-1) +const FORMAT_ARGB32 = Int32(0) +const FORMAT_RGB24 = Int32(1) +const FORMAT_A8 = Int32(2) +const FORMAT_A1 = Int32(3) +const FORMAT_RGB16_565 = Int32(4) +const FORMAT_RGB30 = Int32(5) const status_t = Int32 -const STATUS_SUCCESS = @compat Int32(0) -const STATUS_NO_MEMORY = @compat Int32(1) -const STATUS_INVALID_RESTORE = @compat Int32(2) -const STATUS_INVALID_POP_GROUP = @compat Int32(3) -const STATUS_NO_CURRENT_POINT = @compat Int32(4) -const STATUS_INVALID_MATRIX = @compat Int32(5) -const STATUS_INVALID_STATUS = @compat Int32(6) -const STATUS_NULL_POINTER = @compat Int32(7) -const STATUS_INVALID_STRING = @compat Int32(8) -const STATUS_INVALID_PATH_DATA = @compat Int32(9) -const STATUS_READ_ERROR = @compat Int32(10) -const STATUS_WRITE_ERROR = @compat Int32(11) -const STATUS_SURFACE_FINISHED = @compat Int32(12) -const STATUS_SURFACE_TYPE_MISMATCH = @compat Int32(13) -const STATUS_PATTERN_TYPE_MISMATCH = @compat Int32(14) -const STATUS_INVALID_CONTENT = @compat Int32(15) -const STATUS_INVALID_FORMAT = @compat Int32(16) -const STATUS_INVALID_VISUAL = @compat Int32(17) -const STATUS_FILE_NOT_FOUND = @compat Int32(17) -const STATUS_INVALID_DASH = @compat Int32(18) -const STATUS_INVALID_DSC_COMMENT = @compat Int32(19) -const STATUS_INVALID_INDEX = @compat Int32(20) -const STATUS_CLIP_NOT_REPRESENTABLE = @compat Int32(21) -const STATUS_TEMP_FILE_ERROR = @compat Int32(22) -const STATUS_INVALID_STRIDE = @compat Int32(23) -const STATUS_FONT_TYPE_MISMATCH = @compat Int32(24) -const STATUS_USER_FONT_IMMUTABLE = @compat Int32(25) -const STATUS_USER_FONT_ERROR = @compat Int32(26) -const STATUS_NEGATIVE_COUNT = @compat Int32(27) -const STATUS_INVALID_CLUSTERS = @compat Int32(28) -const STATUS_INVALID_SLANT = @compat Int32(29) -const STATUS_INVALID_WEIGHT = @compat Int32(30) -const STATUS_INVALID_SIZE = @compat Int32(31) -const STATUS_USER_FONT_NOT_IMPLEMENTED = @compat Int32(32) -const STATUS_DEVICE_TYPE_MISMATCH = @compat Int32(33) -const STATUS_DEVICE_ERROR = @compat Int32(34) -const STATUS_INVALID_MESH_CONSTRUCTION = @compat Int32(35) -const STATUS_DEVICE_FINISHED = @compat Int32(36) -const STATUS_LAST_STATUS = @compat Int32(37) +const STATUS_SUCCESS = Int32(0) +const STATUS_NO_MEMORY = Int32(1) +const STATUS_INVALID_RESTORE = Int32(2) +const STATUS_INVALID_POP_GROUP = Int32(3) +const STATUS_NO_CURRENT_POINT = Int32(4) +const STATUS_INVALID_MATRIX = Int32(5) +const STATUS_INVALID_STATUS = Int32(6) +const STATUS_NULL_POINTER = Int32(7) +const STATUS_INVALID_STRING = Int32(8) +const STATUS_INVALID_PATH_DATA = Int32(9) +const STATUS_READ_ERROR = Int32(10) +const STATUS_WRITE_ERROR = Int32(11) +const STATUS_SURFACE_FINISHED = Int32(12) +const STATUS_SURFACE_TYPE_MISMATCH = Int32(13) +const STATUS_PATTERN_TYPE_MISMATCH = Int32(14) +const STATUS_INVALID_CONTENT = Int32(15) +const STATUS_INVALID_FORMAT = Int32(16) +const STATUS_INVALID_VISUAL = Int32(17) +const STATUS_FILE_NOT_FOUND = Int32(17) +const STATUS_INVALID_DASH = Int32(18) +const STATUS_INVALID_DSC_COMMENT = Int32(19) +const STATUS_INVALID_INDEX = Int32(20) +const STATUS_CLIP_NOT_REPRESENTABLE = Int32(21) +const STATUS_TEMP_FILE_ERROR = Int32(22) +const STATUS_INVALID_STRIDE = Int32(23) +const STATUS_FONT_TYPE_MISMATCH = Int32(24) +const STATUS_USER_FONT_IMMUTABLE = Int32(25) +const STATUS_USER_FONT_ERROR = Int32(26) +const STATUS_NEGATIVE_COUNT = Int32(27) +const STATUS_INVALID_CLUSTERS = Int32(28) +const STATUS_INVALID_SLANT = Int32(29) +const STATUS_INVALID_WEIGHT = Int32(30) +const STATUS_INVALID_SIZE = Int32(31) +const STATUS_USER_FONT_NOT_IMPLEMENTED = Int32(32) +const STATUS_DEVICE_TYPE_MISMATCH = Int32(33) +const STATUS_DEVICE_ERROR = Int32(34) +const STATUS_INVALID_MESH_CONSTRUCTION = Int32(35) +const STATUS_DEVICE_FINISHED = Int32(36) +const STATUS_LAST_STATUS = Int32(37) const surface_t = Int32 -const CAIRO_SURFACE_TYPE_IMAGE = @compat Int32(0) -const CAIRO_SURFACE_TYPE_PDF, = @compat Int32(1) -const CAIRO_SURFACE_TYPE_PS, = @compat Int32(2) -const CAIRO_SURFACE_TYPE_XLIB, = @compat Int32(3) -const CAIRO_SURFACE_TYPE_XCB, = @compat Int32(4) -const CAIRO_SURFACE_TYPE_GLITZ, = @compat Int32(5) -const CAIRO_SURFACE_TYPE_QUARTZ, = @compat Int32(6) -const CAIRO_SURFACE_TYPE_WIN32, = @compat Int32(7) -const CAIRO_SURFACE_TYPE_BEOS, = @compat Int32(8) -const CAIRO_SURFACE_TYPE_DIRECTFB, = @compat Int32(9) -const CAIRO_SURFACE_TYPE_SVG, = @compat Int32(10) -const CAIRO_SURFACE_TYPE_OS2, = @compat Int32(11) -const CAIRO_SURFACE_TYPE_WIN32_PRINTING, = @compat Int32(12) -const CAIRO_SURFACE_TYPE_QUARTZ_IMAGE, = @compat Int32(13) -const CAIRO_SURFACE_TYPE_SCRIPT, = @compat Int32(14) -const CAIRO_SURFACE_TYPE_QT, = @compat Int32(15) -const CAIRO_SURFACE_TYPE_RECORDING, = @compat Int32(16) -const CAIRO_SURFACE_TYPE_VG, = @compat Int32(17) -const CAIRO_SURFACE_TYPE_GL, = @compat Int32(18) -const CAIRO_SURFACE_TYPE_DRM, = @compat Int32(19) -const CAIRO_SURFACE_TYPE_TEE, = @compat Int32(20) -const CAIRO_SURFACE_TYPE_XML, = @compat Int32(21) -const CAIRO_SURFACE_TYPE_SKIA, = @compat Int32(22) -const CAIRO_SURFACE_TYPE_SUBSURFACE, = @compat Int32(23) -const CAIRO_SURFACE_TYPE_COGL = @compat Int32(24) +const CAIRO_SURFACE_TYPE_IMAGE = Int32(0) +const CAIRO_SURFACE_TYPE_PDF, = Int32(1) +const CAIRO_SURFACE_TYPE_PS, = Int32(2) +const CAIRO_SURFACE_TYPE_XLIB, = Int32(3) +const CAIRO_SURFACE_TYPE_XCB, = Int32(4) +const CAIRO_SURFACE_TYPE_GLITZ, = Int32(5) +const CAIRO_SURFACE_TYPE_QUARTZ, = Int32(6) +const CAIRO_SURFACE_TYPE_WIN32, = Int32(7) +const CAIRO_SURFACE_TYPE_BEOS, = Int32(8) +const CAIRO_SURFACE_TYPE_DIRECTFB, = Int32(9) +const CAIRO_SURFACE_TYPE_SVG, = Int32(10) +const CAIRO_SURFACE_TYPE_OS2, = Int32(11) +const CAIRO_SURFACE_TYPE_WIN32_PRINTING, = Int32(12) +const CAIRO_SURFACE_TYPE_QUARTZ_IMAGE, = Int32(13) +const CAIRO_SURFACE_TYPE_SCRIPT, = Int32(14) +const CAIRO_SURFACE_TYPE_QT, = Int32(15) +const CAIRO_SURFACE_TYPE_RECORDING, = Int32(16) +const CAIRO_SURFACE_TYPE_VG, = Int32(17) +const CAIRO_SURFACE_TYPE_GL, = Int32(18) +const CAIRO_SURFACE_TYPE_DRM, = Int32(19) +const CAIRO_SURFACE_TYPE_TEE, = Int32(20) +const CAIRO_SURFACE_TYPE_XML, = Int32(21) +const CAIRO_SURFACE_TYPE_SKIA, = Int32(22) +const CAIRO_SURFACE_TYPE_SUBSURFACE, = Int32(23) +const CAIRO_SURFACE_TYPE_COGL = Int32(24) const font_slant_t = Int32 -const FONT_SLANT_NORMAL = @compat Int32(0) -const FONT_SLANT_ITALIC = @compat Int32(1) -const FONT_SLANT_OBLIQUE = @compat Int32(2) +const FONT_SLANT_NORMAL = Int32(0) +const FONT_SLANT_ITALIC = Int32(1) +const FONT_SLANT_OBLIQUE = Int32(2) const font_weight_t = Int32 -const FONT_WEIGHT_NORMAL = @compat Int32(0) -const FONT_WEIGHT_BOLD = @compat Int32(1) +const FONT_WEIGHT_NORMAL = Int32(0) +const FONT_WEIGHT_BOLD = Int32(1) -const CONTENT_COLOR = @compat Int32(0x1000) -const CONTENT_ALPHA = @compat Int32(0x2000) -const CONTENT_COLOR_ALPHA = @compat Int32(0x3000) +const CONTENT_COLOR = Int32(0x1000) +const CONTENT_ALPHA = Int32(0x2000) +const CONTENT_COLOR_ALPHA = Int32(0x3000) const FILTER_FAST = 0 const FILTER_GOOD = 1 @@ -150,7 +150,7 @@ const OPERATOR_LIGHTEN = 18 ## LaTex Token Dicts ## -const _common_token_dict = @compat Dict( +const _common_token_dict = Dict( "\\{" => "{", "\\}" => "}", "\\_" => "_", @@ -162,7 +162,7 @@ const _common_token_dict = @compat Dict( "}" => "" ) -const _text_token_dict = @compat Dict( +const _text_token_dict = Dict( ## non-math symbols (p438) "\\S" => "\ua7", "\\P" => "\ub6", @@ -170,7 +170,7 @@ const _text_token_dict = @compat Dict( "\\ddag" => "\u2021" ) -const _math_token_dict = @compat Dict( +const _math_token_dict = Dict( "-" => "\u2212", # minus sign @@ -423,16 +423,16 @@ const _math_token_dict = @compat Dict( "\\arcsec" => "\u2033" ) -const CAIRO_FILL_RULE_WINDING = @compat Int32(0); -const CAIRO_FILL_RULE_EVEN_ODD = @compat Int32(1); +const CAIRO_FILL_RULE_WINDING = Int32(0); +const CAIRO_FILL_RULE_EVEN_ODD = Int32(1); -const CAIRO_LINE_CAP_BUTT = @compat Int32(0); -const CAIRO_LINE_CAP_ROUND = @compat Int32(1); -const CAIRO_LINE_CAP_SQUARE = @compat Int32(2); +const CAIRO_LINE_CAP_BUTT = Int32(0); +const CAIRO_LINE_CAP_ROUND = Int32(1); +const CAIRO_LINE_CAP_SQUARE = Int32(2); -const CAIRO_LINE_JOIN_MITER = @compat Int32(0); -const CAIRO_LINE_JOIN_ROUND = @compat Int32(1); -const CAIRO_LINE_JOIN_BEVEL = @compat Int32(2); +const CAIRO_LINE_JOIN_MITER = Int32(0); +const CAIRO_LINE_JOIN_ROUND = Int32(1); +const CAIRO_LINE_JOIN_BEVEL = Int32(2); #typedef enum _cairo_path_data_type { # CAIRO_PATH_MOVE_TO, @@ -441,9 +441,9 @@ const CAIRO_LINE_JOIN_BEVEL = @compat Int32(2); # CAIRO_PATH_CLOSE_PATH #} cairo_path_data_type_t; -const CAIRO_PATH_MOVE_TO = @compat Int32(0); -const CAIRO_PATH_LINE_TO = @compat Int32(1); -const CAIRO_PATH_CURVE_TO = @compat Int32(2); -const CAIRO_PATH_CLOSE_PATH = @compat Int32(3); +const CAIRO_PATH_MOVE_TO = Int32(0); +const CAIRO_PATH_LINE_TO = Int32(1); +const CAIRO_PATH_CURVE_TO = Int32(2); +const CAIRO_PATH_CLOSE_PATH = Int32(3); diff --git a/test/runtests.jl b/test/runtests.jl index 4c230ec..cd25f5c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,14 +2,9 @@ using Cairo using Compat, Colors import Compat.String -@compat import Base.show +import Base.show -if VERSION >= v"0.5.0-dev+7720" - using Base.Test -else - using BaseTestNext - const Test = BaseTestNext -end +using Base.Test # Image Surface @@ -25,7 +20,7 @@ end surf = CairoImageSurface(fill(RGB24(0), 10, 10)) @test Cairo.format(surf) == RGB24 io = IOBuffer() - @compat show(io, MIME("image/png"), surf) + show(io, MIME("image/png"), surf) seek(io,0) str_data = Vector{UInt8}(read(io)) From d3ee1dfb2297d10308e6f374f699ae923c9a0649 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Thu, 1 Feb 2018 13:03:45 +0100 Subject: [PATCH 2/9] Bump to Julia 0.6 --- .travis.yml | 18 +++++++++++------- REQUIRE | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7258e8a..40afe0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,27 @@ matrix: include: - language: julia - julia: 0.5 + julia: 0.6 os: linux dist: trusty - sudo: false + sudo: false - language: julia - julia: 0.6 + julia: master os: linux dist: trusty - sudo: false + sudo: false - language: julia - julia: 0.5 + julia: 0.6 os: linux - language: julia - julia: 0.5 + julia: master + os: linux + + - language: julia + julia: 0.6 os: osx - language: julia - julia: 0.6 + julia: master os: osx notifications: email: false diff --git a/REQUIRE b/REQUIRE index 3be482f..1c14d2f 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.5 +julia 0.6 Compat 0.39.0 Colors BinDeps 0.3.21 From 7837a2880cfe06bc2732bed875eeca53d354fa3b Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Thu, 1 Feb 2018 14:48:58 +0100 Subject: [PATCH 3/9] Update to Julia 0.7 --- deps/build.jl | 15 +- samples/sample_alpha_paint.jl | 37 +-- samples/sample_arc.jl | 7 +- samples/sample_arc_negative.jl | 6 +- samples/sample_copy_path.jl | 2 +- samples/sample_copy_path_flat.jl | 45 ++-- samples/sample_pango_text.jl | 4 +- src/Cairo.jl | 423 ++++++++++++++++--------------- test/REQUIRE | 1 - test/runtests.jl | 138 +++++----- test/shape_functions.jl | 2 +- test/test_painting.jl | 18 +- test/test_stream.jl | 29 ++- test/tex.jl | 4 +- 14 files changed, 377 insertions(+), 354 deletions(-) delete mode 100644 test/REQUIRE 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]" From 21362c3b5f33f007c227db9a00d03073fc37d2d1 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Fri, 2 Feb 2018 10:13:01 +0100 Subject: [PATCH 4/9] In .travis.yml use nightly instead of master Adjust appveyor.yml --- .travis.yml | 6 +++--- appveyor.yml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 40afe0f..da39075 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ matrix: dist: trusty sudo: false - language: julia - julia: master + julia: nightly os: linux dist: trusty sudo: false @@ -14,14 +14,14 @@ matrix: julia: 0.6 os: linux - language: julia - julia: master + julia: nightly os: linux - language: julia julia: 0.6 os: osx - language: julia - julia: master + julia: nightly os: osx notifications: email: false diff --git a/appveyor.yml b/appveyor.yml index 8e2409a..3bf37ef 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,11 +3,11 @@ environment: # - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe" # - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe" # - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" + # - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" # - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" + # - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" branches: only: From 25e112de2c1f36e7f27618200d82d941c6bf1330 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Fri, 2 Feb 2018 10:15:23 +0100 Subject: [PATCH 5/9] Fix use of Compat.Pkg --- deps/build.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index dba8192..7d93002 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -3,12 +3,10 @@ using BinDeps using Compat import Compat.Libdl import Compat.Sys -using Pkg +import Compat.Pkg @BinDeps.setup -using Compat - # check for cairo version function validate_cairo_version(name,handle) f = Libdl.dlsym_e(handle, "cairo_version") From e7a80b72fbac46a6e4e910a28cc0f3202186c7cd Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Fri, 2 Feb 2018 10:21:45 +0100 Subject: [PATCH 6/9] Fix Compat uses on 0.6 --- test/shape_functions.jl | 3 ++- test/tex.jl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/shape_functions.jl b/test/shape_functions.jl index cb26a34..23e2749 100644 --- a/test/shape_functions.jl +++ b/test/shape_functions.jl @@ -1,4 +1,5 @@ -using Cairo, Compat, Random +using Cairo +using Compat.Random # shape functions, diff --git a/test/tex.jl b/test/tex.jl index adbfdf3..a425c83 100644 --- a/test/tex.jl +++ b/test/tex.jl @@ -1,5 +1,5 @@ using Cairo: tex2pango -using Compat, Test +using Compat.Test fsize = 1.618034 @test tex2pango("ƒ_{Nyquist} [\\mu K]",fsize) == "ƒNyquist [μK]" From 34cd5d876dfa13afda23a7433005c85b419e8f71 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Fri, 2 Feb 2018 10:31:22 +0100 Subject: [PATCH 7/9] Use Compat.Printf correctly --- samples/sample_pango_text.jl | 4 +++- test/runtests.jl | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/samples/sample_pango_text.jl b/samples/sample_pango_text.jl index cb2e101..ea23436 100644 --- a/samples/sample_pango_text.jl +++ b/samples/sample_pango_text.jl @@ -1,5 +1,7 @@ ## header to provide surface and context -using Cairo, Compat, Printf +using Cairo +using Compat.Printf + c = CairoRGBSurface(256,256); cr = CairoContext(c); diff --git a/test/runtests.jl b/test/runtests.jl index 6f93402..6fa4cc0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -77,14 +77,13 @@ end samples_files = setdiff(samples_files, files_to_exclude) end - sc = asyncmap(samples_files, ntasks=4) do test_file_name - b = success(`$(Base.julia_cmd()) $(joinpath(samples_dir_path, test_file_name))`) + @testset "sample: $test_file_name" for test_file_name in samples_files + mod = Module(Symbol(test_file_name)) + @eval mod include($(joinpath(samples_dir_path, test_file_name))) output_png_name = replace(test_file_name,".jl",".png") - b &= isfile(output_png_name) + @test isfile(output_png_name) rm(output_png_name) - return b end - @test all(sc) end # Run some painting, check the colored pixels by counting them From d40dd8be077aaf9833bc25153a8ebd54d4587944 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Fri, 2 Feb 2018 14:22:29 +0100 Subject: [PATCH 8/9] Make include trick work on 0.7 --- samples/sample_copy_path_flat.jl | 4 ++-- samples/sample_script0.jl | 2 +- test/runtests.jl | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/samples/sample_copy_path_flat.jl b/samples/sample_copy_path_flat.jl index f053cf8..a95769b 100644 --- a/samples/sample_copy_path_flat.jl +++ b/samples/sample_copy_path_flat.jl @@ -40,7 +40,7 @@ for x in opath end s1 = repr(x.points) move_to(cr,10.0,16.0+(14.0*l)) - l += 1 + global l += 1 show_text(cr,s0*s1) end @@ -59,7 +59,7 @@ for x in fpath end s1 = repr(x.points) move_to(cr,10.0,50.0+(14.0*l)) - l += 1 + global l += 1 show_text(cr,s0*s1) end diff --git a/samples/sample_script0.jl b/samples/sample_script0.jl index 079c663..4993be1 100644 --- a/samples/sample_script0.jl +++ b/samples/sample_script0.jl @@ -48,7 +48,7 @@ t1 = 24.0 for x in r1 move_to(cr,0.0,t1) show_text(cr,x) - t1 += 12.0 + global t1 += 12.0 end diff --git a/test/runtests.jl b/test/runtests.jl index 6fa4cc0..51f6039 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -78,8 +78,11 @@ end end @testset "sample: $test_file_name" for test_file_name in samples_files - mod = Module(Symbol(test_file_name)) + # Run each sample script in a separate module to avoid pollution + s = Symbol(test_file_name) + mod = @eval(Main, module $s end) @eval mod include($(joinpath(samples_dir_path, test_file_name))) + output_png_name = replace(test_file_name,".jl",".png") @test isfile(output_png_name) rm(output_png_name) From bc7b3749aac6d86ccc9479cd1375cb1e55594f0c Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Fri, 2 Feb 2018 14:24:05 +0100 Subject: [PATCH 9/9] Bump Compat version --- REQUIRE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/REQUIRE b/REQUIRE index 1c14d2f..9a78195 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,5 +1,5 @@ julia 0.6 -Compat 0.39.0 +Compat 0.50.0 Colors BinDeps 0.3.21 Graphics 0.1