From 5cb5ba8595f97cf75c41867ef21d8e1413cbf811 Mon Sep 17 00:00:00 2001 From: hustf Date: Sat, 20 Aug 2022 12:16:11 +0200 Subject: [PATCH] modified: samples/Samples.md Include sample_record_inkextents new file: samples/sample_record_inkextents.jl new file: samples/sample_record_inkextents.png modified: src/Cairo.jl Add ink_extents --- samples/Samples.md | 5 +++ samples/sample_record_inkextents.jl | 53 +++++++++++++++++++++++++++ samples/sample_record_inkextents.png | Bin 0 -> 3428 bytes src/Cairo.jl | 12 +++++- 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 samples/sample_record_inkextents.jl create mode 100644 samples/sample_record_inkextents.png diff --git a/samples/Samples.md b/samples/Samples.md index 930aa28..abc2880 100644 --- a/samples/Samples.md +++ b/samples/Samples.md @@ -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") diff --git a/samples/sample_record_inkextents.jl b/samples/sample_record_inkextents.jl new file mode 100644 index 0000000..b41851f --- /dev/null +++ b/samples/sample_record_inkextents.jl @@ -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"); + diff --git a/samples/sample_record_inkextents.png b/samples/sample_record_inkextents.png new file mode 100644 index 0000000000000000000000000000000000000000..7e7ff9ef01e9b38eb7a72ea3b7a0f6bb4a575a6c GIT binary patch literal 3428 zcmbtXdpJ~U7vFo#Fk@WeWK>M~L{x*$(UH4dhltZqks&mNqg=`n5;8L>PC7*{LnqUq za>;FsVhp(!hsph(+zuJXEq7Cx`NlZk^L+n(e|*p0&-?D@_pJ3>YrSi&cfap_JG`Z| zVaO6&6TGMIb4GF?CY$T4~R^jOgJ zpz(rY#DE6X2On4|2o}6*Bc7_;8d@{Eh(Mw z$>z6ou2wxgUbE*(@N;|bZXRu>vAm;muD;iAIItmN?H$ipxY(qR5mPTPYJEV8e##$QY5n=C26@C_I|!ba*NHxxszTQ(>k?BlKT zv&Y6to1c=csrv~h8_f*edM(n3V_(XBTag4HF>jh!mh!OC%vq*mu#S>3!84ni>~m!R znoh|z9f=#RibAX}n(!qyq_v-pHA^6F& zOpyrMF-syno03S5sOy||)K2LJ7pitOEX~7DoRfH1(67Gn{4PlveLRaM)TsD}<~&19 zjbz|rr~|X8D>`X2d{M-scgHhoy!9+RCTa|4BSI`BILeK~x8yYUJSxJuk`YiNW;gDF z6(2A3i6Ph~E6FB0L5nxf3)ODx{G$fv9I#z6(fw&Lmg?1np{wFvt$%9oLM$(IQ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wk+Zt1Ah8q6Y$$h-E!`HWw)J?4wZ zxgWwn?~94K@4a%D^wV8ty~HNwU>T|BR-i;;|M6Kmg7hy)e!^wqn@x= z3`Lb9tlqi(Q%bvVif7jiK+8mbFS3W!Fv8q8OY)F6BmBw7GOSyzEKJRPQd?!pzyUfF z>4|00zI{!aPrr0x9N$!sT-d!yQocMkj5IgNlGF@f_)0_^cb5yffvS>yc{{1YoZqFh$h}bMYeK$G-1!ZP}&Daz0{5Oshlbf25;+U zNoLsA1W5bG<=i97<8h<=)i++;wGH{EU#UYmeZ7I^c56U00J2C5}P AT>t<8 literal 0 HcmV?d00001 diff --git a/src/Cairo.jl b/src/Cairo.jl index a269c81..9b93150 100644 --- a/src/Cairo.jl +++ b/src/Cairo.jl @@ -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!, @@ -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