Skip to content

Instantly share code, notes, and snippets.

@jonathanBieler
Created October 4, 2017 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanBieler/5a2b7494f79a3c164a59c67ba3c5028a to your computer and use it in GitHub Desktop.
Save jonathanBieler/5a2b7494f79a3c164a59c67ba3c5028a to your computer and use it in GitHub Desktop.
## header to provide surface and context
using Cairo
c = CairoRGBSurface(256,256);
struct cairo_font_options_t end
options = ccall((:cairo_font_options_create,Cairo._jl_libcairo), Ptr{cairo_font_options_t}, ())
ccall((:cairo_font_options_set_antialias,Cairo._jl_libcairo), Void, (Ptr{cairo_font_options_t},Cint),options,Cairo.ANTIALIAS_SUBPIXEL)
set_font_options(cr,options) = ccall((:cairo_set_font_options,Cairo._jl_libcairo), Void,
(Ptr{Void},Ptr{cairo_font_options_t}),cr,options)
import Base.unsafe_convert
unsafe_convert(::Type{Ptr{Void}}, c::Cairo.CairoContext) = c.ptr
cr = CairoContext(c)
set_font_options(cr,options)
save(cr);
set_source_rgb(cr,0.8,0.8,0.8); # light gray
rectangle(cr,0.0,0.0,256.0,256.0); # background
fill(cr);
restore(cr);
save(cr);
set_font_face(cr, "Sans 16")
text(cr,16.0,40.0,"Hamburgefons")
text(cr,16.0,72.0,"sp⁰¹²³,min⁻²,αΑβΒφϕΦγΓ")
text(cr,16.0,104.0,"Text<b>Bold</b><i>Italic</i><sup>super-2</sup>",markup=true)
text(cr,40.0,224.0,"Es geht <span foreground=\"white\" background=\"blue\">aufwärts</span> !",markup=true,angle=30.0)
#using textwidth and height
set_font_face(cr, "Sans 12")
a = "A"
aheight = textheight(cr,a)
awidth = textwidth(cr,a)
atext = @sprintf("%s wd=%2.2f,ht=%2.2f",a,awidth,aheight)
text(cr,16.0,240.0,atext,markup=true)
## mark picture with current date
restore(cr);
move_to(cr,0.0,12.0);
set_source_rgb(cr, 0,0,0);
set_font_options(cr,options)
show_text(cr,Libc.strftime(time()));
Cairo.set_text(cr, "test", true)
Cairo.show_layout(cr)
write_to_png(c,"sample_pango_text.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment