Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper for cairo_recording_surface_ink_extents() #356

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions samples/Samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ Example of using Recording surface, simple copy, then scaled and offset.
![sample record0.png](sample_record0.png "record0 example")
![sample record1.png](sample_record1.png "record1 example")

Example of using Recording surface, find the `ink_extents` of drawing operations,
draw an encompassing rectangle, scale and offset.

![sample record inkextents.png](sample_record_inkextents.png "record inkextents example")

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

![sample script0.png](sample_script0.png "scrip0 example")
Expand Down
53 changes: 53 additions & 0 deletions samples/sample_record_inkextents.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## header to provide surface and context
using Cairo
c = CairoARGBSurface(256,256);
cr = CairoContext(c);

save(cr);
set_source_rgba(cr,0.0,0.0,0.0,0.0); # transparent black
rectangle(cr,0.0,0.0,256.0,256.0); # background
fill(cr);
restore(cr);
save(cr);

## paint the following to a Recording Surface
s1 = CairoRecordingSurface()
c1 = CairoContext(s1)

move_to(c1, 128.0, 25.6);
line_to(c1, 230.4, 230.4);
rel_line_to(c1, -102.4, 0.0);
curve_to(c1, 51.2, 230.4, 51.2, 128.0, 128.0, 128.0);
close_path(c1);

move_to(c1, 64.0, 25.6);
rel_line_to(c1, 51.2, 51.2);
rel_line_to(c1, -51.2, 51.2);
rel_line_to(c1, -51.2, -51.2);
close_path(c1);

set_line_width(c1, 10.0);
set_source_rgb(c1, 0, 0, 1);
fill_preserve(c1);
set_source_rgb(c1, 0, 0, 0);
stroke(c1);

## find ink extents and mark with a rectangle
x0, y0, width, height = recording_surface_ink_extents(s1);
rectangle(c1, x0, y0, width, height)
stroke(c1);

## play back on transform coord
scale(cr,0.5,0.5)
set_source(cr, s1, 128.0, 128.0)

paint(cr)


## mark picture with current date
restore(cr);
move_to(cr,0.0,12.0);
set_source_rgb(cr, 0,0,0);
show_text(cr,Libc.strftime(time()));
write_to_png(c,"sample_record_inkextents.png");

Binary file added samples/sample_record_inkextents.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion src/Cairo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export
set_source_rgb, set_source_rgba, set_source_surface, set_line_type,
set_line_cap, set_line_join,
set_operator, get_operator, set_source,
CairoMatrix,
CairoMatrix, recording_surface_ink_extents,

# coordinate systems
reset_transform, rotate, scale, translate, user_to_device!,
Expand Down Expand Up @@ -563,6 +563,16 @@ function script_from_recording_surface(s::CairoScript,r::CairoSurface)
ccall((:cairo_script_from_recording_surface,libcairo), Int32,
(Ptr{Nothing},Ptr{Nothing}),s.ptr, r.ptr)
end
function recording_surface_ink_extents(r::CairoSurface)
x0 = Ref{Cdouble}(0)
y0 = Ref{Cdouble}(0)
width = Ref{Cdouble}(0)
height = Ref{Cdouble}(0)
ccall((:cairo_recording_surface_ink_extents,libcairo), Nothing,
(Ptr{Nothing}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}),
r.ptr, x0, y0, width, height)
x0[], y0[], width[], height[]
end
# -----------------------------------------------------------------------------

mutable struct CairoContext <: GraphicsContext
Expand Down