Skip to content

Commit

Permalink
Merge pull request #282 from GiovineItalia/tn/more-v07-fixes
Browse files Browse the repository at this point in the history
Add support for Julia v1.0
  • Loading branch information
tlnagy authored Sep 7, 2018
2 parents 5a65bc4 + a2c07d2 commit 69be7b7
Show file tree
Hide file tree
Showing 24 changed files with 302 additions and 327 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ os:
sudo: required
dist: trusty
julia:
- 0.6
- 0.7
- 1.0
- nightly
matrix:
allow_failures:
- julia: nightly
notifications:
email: false
before_install:
- if [ `uname` = "Linux" ]; then
sudo apt-get update -qq -y;
sudo apt-get install -y libcairo2 libfontconfig1 libpango1.0-0 libpng12-0 libpng12-dev libpixman-1-0 gettext;
fi
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("Compose"); Pkg.test("Compose"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("Compose")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
- julia -e 'cd(Pkg.dir("Compose")); map(x -> Pkg.add(strip(x)), readlines(open(joinpath("docs", "REQUIRE")))); include(joinpath("docs", "make.jl"))'
- julia -e 'using Pkg; Pkg.add("Documenter"); include(joinpath("docs", "make.jl"))'
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Compose!

[![][docs-latest-img]][docs-latest-url] [![][pkg-0.6-img]][pkg-0.6-url] [![][pkg-1.0-img]][pkg-1.0-url] [![][travis-img]][travis-url] [![][codecov-img]][codecov-url]
[![][docs-latest-img]][docs-latest-url] [![][travis-img]][travis-url] [![][codecov-img]][codecov-url]

Compose is a vector graphics library for Julia.
It forms the basis for the statistical graphics system
Expand All @@ -24,11 +24,6 @@ consistent and powerful means of building vector graphics.
[docs-latest-img]: https://img.shields.io/badge/docs-latest-blue.svg
[docs-latest-url]: https://giovineitalia.github.io/Compose.jl/latest

[pkg-0.6-img]: http://pkg.julialang.org/badges/Compose_0.6.svg
[pkg-0.6-url]: http://pkg.julialang.org/?pkg=Compose
[pkg-1.0-img]: http://pkg.julialang.org/badges/Compose_1.0.svg
[pkg-1.0-url]: http://pkg.julialang.org/?pkg=Compose

[travis-img]: http://img.shields.io/travis/GiovineItalia/Compose.jl.svg
[travis-url]: https://travis-ci.org/GiovineItalia/Compose.jl
[codecov-img]: https://codecov.io/gh/GiovineItalia/Compose.jl/branch/master/graph/badge.svg
Expand Down
4 changes: 2 additions & 2 deletions REQUIRE
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
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ makedocs(

deploydocs(
repo = "github.com/GiovineItalia/Compose.jl.git",
julia = "0.5",
julia = "1.0",
osname = "linux",
deps = nothing,
make = nothing,
Expand Down
1 change: 1 addition & 0 deletions examples/golden_rect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Colors
using Compose
using Base.MathConstants

function golden_rect(n::Int)
if n == 0 return context() end
Expand Down
105 changes: 37 additions & 68 deletions src/Compose.jl
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,
Expand All @@ -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

"""
Expand Down Expand Up @@ -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")

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) =
Expand All @@ -200,12 +175,6 @@ show(io::IO, m::MIME"text/html", ctx::Context) =
show(io::IO, m::MIME"image/svg+xml", ctx::Context) =
draw(SVG(io, default_graphic_width, default_graphic_height, false), ctx)

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)
end

function pad_outer(c::Context,
left_padding::MeasureOrNumber,
right_padding::MeasureOrNumber,
Expand Down
11 changes: 5 additions & 6 deletions src/batch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ struct FormBatch{P <: FormPrimitive}
end

"""
Attempt to batch a form. Return a Nullable{FormBatch} which is null if the Form
could not be batched, and non-null if the original form can be replaced with teh
resulting FormBatch.
Attempt to batch a form. Return a Nothing singleton if the Form could not be
batched, and FormBatch object if the original form can be replaced.
"""
batch(form::Form{P}) where P = Nullable{FormBatch{P}}()
batch(form::Form{P}) where P = nothing

# Note: in tests using random data, this optimization wasn't worth it. I'm
# keeping it around out of hopes I find a more clever version that is
Expand Down Expand Up @@ -54,7 +53,7 @@ function batch{T <: CirclePrimitive}(form::Form{T})
r = form.primitives[1].radius
n = length(form.primitives)
for i in 2:n
form.primitives[i].radius == r || return Nullable{FormBatch{CirclePrimitive}}()
form.primitives[i].radius == r || return Nothing
end
prim = CirclePrimitive((0mm, 0mm), r)
Expand All @@ -63,7 +62,7 @@ function batch{T <: CirclePrimitive}(form::Form{T})
offsets[i] = form.primitives[i].center
end
return Nullable(FormBatch(prim, offsets))
return FormBatch(prim, offsets)
end
=#

Expand Down
Loading

0 comments on commit 69be7b7

Please sign in to comment.