Skip to content

Commit

Permalink
Naive fiddle
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Oct 8, 2019
1 parent f796e4a commit b7c7f5c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
10 changes: 8 additions & 2 deletions src/Compose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export compose, compose!, Context, UnitBox, AbsoluteBoundingBox,
Rotation, Mirror, Shear,
ParentDrawContext, context, ctxpromise, table, set_units!, minwidth, minheight,
text_extents, max_text_extents, polygon, ngon, star, xgon,
line, rectangle, circle, arc, sector, ellipse, text, curve, bitmap,
line, rectangle, circle, arc, sector, ellipse, text, curve, bitmap,
stroke, fill, strokedash, strokelinecap, arrow,
strokelinejoin, linewidth, visible, fillopacity, strokeopacity, clip,
font, fontsize, svgid, svgclass, svgattribute, jsinclude, jscall, Measure,
Expand Down Expand Up @@ -171,7 +171,13 @@ function link_cairo()
end

function __init__()
@require Cairo="159f3aea-2a34-519c-b102-8c37f9878175" link_cairo()
@require Cairo="159f3aea-2a34-519c-b102-8c37f9878175" begin
const libpangocairo = Cairo.libpangocairo
const libpango = Cairo.libpango
const libgobject = Cairo.libgobject

link_cairo()
end
@require Fontconfig="186bb1d3-e1f7-5a2c-a377-96d770f13627" begin
include("pango.jl")
link_fontconfig()
Expand Down
18 changes: 7 additions & 11 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.libpango),
font_desc = ccall((:pango_layout_get_font_description, 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.libpango),
size = ccall((:pango_font_description_get_size, 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.libpango),
font_desc = ccall((:pango_layout_get_font_description, libpango),
Ptr{Cvoid}, (Ptr{Cvoid},), img.ctx.layout)

if font_desc == C_NULL
family = "sans"
else
family = ccall((:pango_font_description_get_family, Cairo.libpango),
family = ccall((:pango_font_description_get_family, libpango),
Ptr{UInt8}, (Ptr{Cvoid},), font_desc)
family = unsafe_string(family)
end
Expand Down Expand Up @@ -823,15 +823,15 @@ end

# Arrows

apply_property(img::Image, p::ArrowPrimitive) =
apply_property(img::Image, p::ArrowPrimitive) =
img.arrow = p.value


function arrow(img::Image, points::Vector{<:Vec})
xmax, ymax = points[end]
dxy = points[end] .- points[end-1]
dx, dy = dxy[1].value, dxy[2].value
vl, θ = 0.225*hypot(dy,dx), atan(dy, dx)
dx, dy = dxy[1].value, dxy[2].value
vl, θ = 0.225*hypot(dy,dx), atan(dy, dx)
arrowhead(img, (xmax,ymax), vl, θ)
end

Expand All @@ -851,7 +851,3 @@ function arrowhead(img::Image, point::Vec, vl::Float64, θ::Float64)
line_to(img, (xmax, ymax))
line_to(img, (xmax+xr[2], ymax+yr[2]))
end




4 changes: 0 additions & 4 deletions src/pango.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Estimation of text extents using pango.

const libpangocairo = Cairo.libpangocairo
const libpango = Cairo.libpango
const libgobject = Cairo.libgobject

# Cairo text backend
const CAIRO_FONT_TYPE_TOY = 0
const CAIRO_FONT_TYPE_FT = 1
Expand Down

0 comments on commit b7c7f5c

Please sign in to comment.