Skip to content

Commit

Permalink
set/get_font_matrix (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikunia committed Aug 2, 2020
1 parent 0e8323f commit c6aea85
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Cairo.jl
Expand Up @@ -103,6 +103,7 @@ export
set_font_face, set_font_size, select_font_face,
textwidth, textheight, text_extents,
TeXLexer, tex2pango, show_text, text_path,
set_font_matrix, get_font_matrix,

# images
write_to_png, image, read_from_png,
Expand Down Expand Up @@ -1118,6 +1119,16 @@ function set_matrix(p::CairoPattern, m::CairoMatrix)
ccall((:cairo_pattern_set_matrix, libcairo), Nothing, (Ptr{Nothing}, Ptr{Nothing}), p.ptr, [m])
end

# -----------------------------------------------------------------------------
function get_font_matrix(ctx::CairoContext)
m = [CairoMatrix()]
ccall((:cairo_get_font_matrix, libcairo), Nothing, (Ptr{Nothing}, Ptr{Nothing}), ctx.ptr, m)
m[1]
end

function set_font_matrix(ctx::CairoContext, m::CairoMatrix)
ccall((:cairo_set_font_matrix, libcairo), Nothing, (Ptr{Nothing}, Ptr{Nothing}), ctx.ptr, [m])
end

# -----------------------------------------------------------------------------
function set_line_type(ctx::CairoContext, nick::AbstractString)
Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Expand Up @@ -333,4 +333,20 @@ end
@test destroy(cr) == nothing
end

@testset "font_matrix" begin
z = zeros(UInt32,512,512);
surf = CairoImageSurface(z, Cairo.FORMAT_ARGB32)

pa = surf.ptr
surf.ptr = C_NULL

surf.ptr = pa
cr = Cairo.CairoContext(surf)

m = CairoMatrix(1.0,2.0,2.0,1.0,0.,0.)
set_font_matrix(cr, m)
@test m == get_font_matrix(cr)
@test destroy(cr) == nothing
end

nothing

0 comments on commit c6aea85

Please sign in to comment.