Skip to content

Commit

Permalink
Bump Cairo compatibility (#360)
Browse files Browse the repository at this point in the history
* Set Cairo compatibility

* Address deprecated bindings

* Address deprecated bindings

* Build documentation from Julia v1.2

* Remove before install

Binary Provider should be doing all the work.

* Add unicode example

* Bump to Fontconfig that uses BinaryBuilder

Tested with https://github.com/giordano/Fontconfig.jl/tree/bb, which is yet to be merged.

* .gitignore

* Add Windows to test matrix

* Remove file I/O from the Image keyword args test set

#360 (comment)
  • Loading branch information
CiaranOMara authored and bjarthur committed Nov 2, 2019
1 parent 91e6172 commit be908fd
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
19 changes: 18 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
*~
*swp

# Documenter generated code
# System-specific files and directories generated by the BinaryProvider and BinDeps packages
# They contain absolute paths specific to the host computer, and so should not be committed
deps/deps.jl
deps/build.log
deps/downloads/
deps/usr/
deps/src/

# Build artifacts for creating documentation generated by the Documenter package
docs/build/
docs/site/

test/output

# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml

# System files generated by MacOS.
.DS_Store
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: julia
os:
- linux
- osx
- windows
sudo: required
dist: trusty
julia:
Expand All @@ -13,18 +14,13 @@ matrix:
- 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
after_success:
- julia -e 'using Pkg; cd(Pkg.dir("Compose")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())';

jobs:
include:
- stage: "Documentation"
julia: 1.0
julia: 1.2
os: linux
script:
- julia --project=docs/ -e 'using Pkg; Pkg.instantiate();
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Cairo = "0.5, 0.6"
Cairo = "0.7"
Colors = "0.9"
DataStructures = "0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17"
EzXML = "0.8, 0.9"
Fontconfig = "0.2"
Fontconfig = "0.3"
IterTools = "1"
JSON = "0.18, 0.19, 0.20, 0.21"
Measures = "0.3"
Expand Down
10 changes: 5 additions & 5 deletions src/cairo_backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,13 @@ end
function apply_property(img::Image, property::FontPrimitive)
img.font = property.family

font_desc = ccall((:pango_layout_get_font_description, Cairo._jl_libpango),
font_desc = ccall((:pango_layout_get_font_description, Cairo.libpango),
Ptr{Cvoid}, (Ptr{Cvoid},), img.ctx.layout)

if font_desc == C_NULL
size = absolute_native_units(img, default_font_size.value)
else
size = ccall((:pango_font_description_get_size, Cairo._jl_libpango),
size = ccall((:pango_font_description_get_size, Cairo.libpango),
Cint, (Ptr{Cvoid},), font_desc)
end

Expand All @@ -451,13 +451,13 @@ end
function apply_property(img::Image, property::FontSizePrimitive)
img.fontsize = property.value

font_desc = ccall((:pango_layout_get_font_description, Cairo._jl_libpango),
font_desc = ccall((:pango_layout_get_font_description, Cairo.libpango),
Ptr{Cvoid}, (Ptr{Cvoid},), img.ctx.layout)

if font_desc == C_NULL
family = "sans"
else
family = ccall((:pango_font_description_get_family, Cairo._jl_libpango),
family = ccall((:pango_font_description_get_family, Cairo.libpango),
Ptr{UInt8}, (Ptr{Cvoid},), font_desc)
family = unsafe_string(family)
end
Expand Down Expand Up @@ -492,7 +492,7 @@ apply_property(img::Image, property::SVGAttributePrimitive) = nothing
function current_point(img::Image)
x = Array{Float64}(undef, 1)
y = Array{Float64}(undef, 1)
ccall((:cairo_get_current_point, Cairo._jl_libcairo), Cvoid,
ccall((:cairo_get_current_point, Cairo.libcairo), Cvoid,
(Ptr{Cvoid}, Ptr{Float64}, Ptr{Float64}), img.ctx.ptr, x, y)
return ((x[1] / img.ppmm)*mm, (x[2] / img.ppmm)*mm)
end
Expand Down
6 changes: 3 additions & 3 deletions src/pango.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Estimation of text extents using pango.

const libpangocairo = Cairo._jl_libpangocairo
const libpango = Cairo._jl_libpango
const libgobject = Cairo._jl_libgobject
const libpangocairo = Cairo.libpangocairo
const libpango = Cairo.libpango
const libgobject = Cairo.libgobject

# Cairo text backend
const CAIRO_FONT_TYPE_TOY = 0
Expand Down
17 changes: 17 additions & 0 deletions test/examples/unicode.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env julia

# Draw some unicodes to an image.
# https://github.com/GiovineItalia/Compose.jl/pull/360#issuecomment-539283765

using Compose
import Cairo, Fontconfig

c = compose(context(), text(0.5, 0.5, "π‘Ž 𝑏 𝑐 𝑑 𝑒 𝑓", hcenter, vcenter), font("Segoe UI"), fontsize(20pt) ) # Note: the string is composed with \ita \itb etc.

imgs = [
PDF("unicode.pdf")
SVG("unicode.svg")
PNG("unicode.png")
]

draw.(imgs, [c])
3 changes: 1 addition & 2 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ end
end

@testset "Image keyword args" begin
@test typeof(PNG("foo.png", 4inch, 3inch, dpi=172)) <: Compose.Image
rm("foo.png")
@test isa(PNG(4inch, 3inch, dpi=172), Compose.Image)
end

@testset "No Global RNG contamination" begin
Expand Down

0 comments on commit be908fd

Please sign in to comment.