-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Julia v1.0 #282
Changes from 6 commits
235b2c9
999a688
0a051ac
2c2c0c5
909f22f
b731974
658a980
a2c07d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
julia 0.6 | ||
julia 0.7 | ||
Colors | ||
Compat 0.52.0 | ||
DataStructures | ||
IterTools | ||
JSON | ||
Measures | ||
Requires |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
VERSION >= v"0.4.0-dev+6521" && __precompile__() | ||
|
||
module Compose | ||
|
||
using Colors | ||
using IterTools | ||
using DataStructures | ||
using Compat | ||
using Measures | ||
using Requires | ||
using Dates | ||
using Printf | ||
using Base.Iterators | ||
import JSON | ||
|
||
import Base: length, start, next, done, isempty, getindex, setindex!, | ||
display, show, showcompact, convert, zero, isless, max, fill, size, copy, | ||
import Base: length, isempty, getindex, setindex!, | ||
display, show, convert, zero, isless, max, fill, size, copy, | ||
min, max, abs, +, -, *, /, == | ||
|
||
using Compat.Dates | ||
using Compat.Printf | ||
using Compat.Pkg | ||
|
||
import Measures: resolve, w, h | ||
|
||
export compose, compose!, Context, UnitBox, AbsoluteBoundingBox, Rotation, Mirror, | ||
|
@@ -31,25 +27,6 @@ export compose, compose!, Context, UnitBox, AbsoluteBoundingBox, Rotation, Mirro | |
CAIROSURFACE, introspect, set_default_graphic_size, set_default_jsmode, | ||
boundingbox, Patchable | ||
|
||
function isinstalled(pkg, ge=v"0.0.0-") | ||
try | ||
# Pkg.installed might throw an error, | ||
# we need to account for it to be able to precompile | ||
ver = Pkg.installed(pkg) | ||
ver == nothing && try | ||
# Assume the version is new enough if the package is in LOAD_PATH | ||
ex = Expr(:import, Symbol(pkg)) | ||
@eval $ex | ||
return true | ||
catch | ||
return false | ||
end | ||
return ver >= ge | ||
catch | ||
return false | ||
end | ||
end | ||
|
||
abstract type Backend end | ||
|
||
""" | ||
|
@@ -146,51 +123,49 @@ default_fill_color = colorant"black" | |
# Use cairo for the PNG, PS, PDF if it's installed. | ||
macro missing_cairo_error(backend) | ||
msg1 = """ | ||
Cairo and Fontconfig are necessary for the $(backend) backend. Run: | ||
Pkg.add("Cairo") | ||
Pkg.add("Fontconfig") | ||
The Cairo and Fontconfig packages are necessary for the $(backend) backend. | ||
Add them with the package manager if necessary, then run: | ||
import Cairo, Fontconfig | ||
before invoking $(backend). | ||
""" | ||
msg2 = """ | ||
You also have to delete $(joinpath(Base.LOAD_CACHE_PATH[1], "Compose.ji")) | ||
and restart your REPL session afterwards. | ||
""" | ||
string(msg1, msg2) | ||
string(msg1) | ||
end | ||
|
||
if isinstalled("Cairo") | ||
include("cairo_backends.jl") | ||
include("immerse_backend.jl") | ||
else | ||
global PNG | ||
global PS | ||
global PDF | ||
|
||
PNG(args...) = error(@missing_cairo_error "PNG") | ||
PS(args...) = error(@missing_cairo_error "PS") | ||
PDF(args...) = error(@missing_cairo_error "PDF") | ||
end | ||
#global PDF | ||
PNG(::Any, args...) = error(@missing_cairo_error "PNG") | ||
PS(::Any, args...) = error(@missing_cairo_error "PS") | ||
PDF(::Any, args...) = error(@missing_cairo_error "PDF") | ||
|
||
include("svg.jl") | ||
include("pgf_backend.jl") | ||
|
||
# If available, pango and fontconfig are used to compute text extents and match | ||
# fonts. Otherwise a simplistic pure-julia fallback is used. | ||
|
||
if isinstalled("Fontconfig") | ||
include("fontfallback.jl") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to the extent that fontfallback.jl mimics pango well, we should really hype up the fact that Gadfly can generate SVG with pure julia. maybe add a comment in the Compose README or docs. |
||
|
||
function link_fontconfig() | ||
@info "Loading Fontconfig backend into Compose.jl" | ||
pango_cairo_ctx = C_NULL | ||
include("pango.jl") | ||
|
||
function __init__() | ||
global pango_cairo_ctx | ||
global pangolayout | ||
ccall((:g_type_init, Cairo._jl_libgobject), Void, ()) | ||
pango_cairo_fm = ccall((:pango_cairo_font_map_new, libpangocairo), | ||
Ptr{Void}, ()) | ||
pango_cairo_ctx = ccall((:pango_font_map_create_context, libpango), | ||
Ptr{Void}, (Ptr{Void},), pango_cairo_fm) | ||
pangolayout = PangoLayout() | ||
end | ||
else | ||
include("fontfallback.jl") | ||
ccall((:g_type_init, libgobject), Cvoid, ()) | ||
pango_cairo_fm = ccall((:pango_cairo_font_map_new, libpangocairo), | ||
Ptr{Cvoid}, ()) | ||
pango_cairo_ctx = ccall((:pango_font_map_create_context, libpango), | ||
Ptr{Cvoid}, (Ptr{Cvoid},), pango_cairo_fm) | ||
pangolayout = PangoLayout() | ||
end | ||
|
||
function link_cairo() | ||
@info "Loading Cairo backend into Compose.jl" | ||
include("cairo_backends.jl") | ||
include("immerse_backend.jl") | ||
end | ||
|
||
function __init__() | ||
@require Cairo="159f3aea-2a34-519c-b102-8c37f9878175" link_cairo() | ||
@require Fontconfig="186bb1d3-e1f7-5a2c-a377-96d770f13627" link_fontconfig() | ||
end | ||
|
||
show(io::IO, m::MIME"text/html", ctx::Context) = | ||
|
@@ -204,6 +179,7 @@ try | |
getfield(Compose, :Cairo) # throws if Cairo isn't being used | ||
show(io::IO, ::MIME"image/png", ctx::Context) = | ||
draw(PNG(io, default_graphic_width, default_graphic_height), ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could these three lines be added to cairo_backends.jl? seems better to conditionally include them via Requires.jl instead of a try/catch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. I'll move it. |
||
catch | ||
end | ||
|
||
function pad_outer(c::Context, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could these three lines be simplified to
PNG = error...
? none of the input args are actually used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I had tried that originally and I was getting illegal constant redefinitions.