Skip to content

Commit

Permalink
first example (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
lobingera authored May 30, 2019
1 parent 3d781a7 commit 35443c2
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
10 changes: 8 additions & 2 deletions samples/Samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Mesh patterns are tensor-product patch meshes (type 7 shadings in PDF), read mor

![mesh pattern .png](sample_meshpattern.png "mesh pattern example")

## Recording and Scripting Surfaces
### Recording and Scripting Surfaces

Example of using Recording surface, simple copy, then scaled and offset.

Expand All @@ -190,4 +190,10 @@ Example of using Recording surface, simple copy, then scaled and offset.

Example of writing to script, put script text into frame.

![sample script0.png](sample_script0.png "scrip0 example")
![sample script0.png](sample_script0.png "scrip0 example")

### current point

Example of using current point

![sample current point.png](sample_current_point.png "current point example")
66 changes: 66 additions & 0 deletions samples/sample_current_point.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Compat
using Cairo

function common_header()
## header to provide surface and context
c = CairoRGBSurface(256,256);
cr = CairoContext(c);

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

return c,cr
end

function write_out_picture(filename::AbstractString,c::CairoSurface)
## mark picture with current date
move_to(cr,0.0,12.0);
set_source_rgb(cr, 0,0,0);
show_text(cr,Libc.strftime(time()));
##
write_to_png(c,filename);
nothing
end

function example_current_point(cr)
save(cr);

x=25.6; y=128.0;
x1=102.4; y1=30.4;
x2=123.6; y2=45.6;
x3=130.4; y3=128.0;

move_to(cr, x, y);
curve_to(cr, x1, y1, x2, y2, x3, y3);

if has_current_point(cr)
x,y = get_current_point(cr);
save(cr)
move_to(cr,x,y)
set_source_rgb(cr, 0,0,1.0);
show_text(cr,"current point")
restore(cr)
end

set_line_width(cr, 10.0);
stroke(cr);


restore(cr);
save(cr);

nothing
end


c,cr = common_header();
save(cr);
example_current_point(cr);
restore(cr);
write_out_picture("sample_current_point.png",c);



Binary file added samples/sample_current_point.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/Cairo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export
# path copy
copy_path, copy_path_flat, convert_cairo_path_data,

# other path operations
get_current_point, has_current_point,

# text
text,
update_layout, show_layout, get_layout_size, layout_text,
Expand Down Expand Up @@ -807,6 +810,22 @@ function convert_cairo_path_data(p::CairoPath)
path_data
end

# other path operations

function get_current_point(ctx::CairoContext)

x = Ref{Cdouble}(0)
y = Ref{Cdouble}(0)
ccall((:cairo_get_current_point, _jl_libcairo),
Nothing, (Ptr{Nothing},Ref{Cdouble},Ref{Cdouble}),ctx.ptr,x,y)

x[],y[]
end

function has_current_point(ctx::CairoContext)
Bool(ccall((:cairo_has_current_point, _jl_libcairo),
Cint, (Ptr{Nothing},),ctx.ptr))
end

# user<->device coordinate translation

Expand Down

0 comments on commit 35443c2

Please sign in to comment.