From a74db7e7bc092533d244123ea2ae272edf3f5d8f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 4 Apr 2008 12:34:40 +0100 Subject: [PATCH] [test] Exercise "soft" masks. PDF has a concept of "soft" masks, for which it is able to construct a mask out of PDF drawing operations. These tests exercise constructing various masks using the high level drawing operations. --- test/.gitignore | 7 ++ test/Makefile.am | 14 ++++ test/smask-fill-ref.png | Bin 0 -> 1223 bytes test/smask-fill.c | 83 ++++++++++++++++++++++ test/smask-image-mask-ref.png | Bin 0 -> 643 bytes test/smask-image-mask.c | 92 ++++++++++++++++++++++++ test/smask-mask-ref.png | Bin 0 -> 2523 bytes test/smask-mask.c | 107 ++++++++++++++++++++++++++++ test/smask-paint-ref.png | Bin 0 -> 2639 bytes test/smask-paint.c | 90 +++++++++++++++++++++++ test/smask-ref.png | Bin 0 -> 3587 bytes test/smask-stroke-ref.png | Bin 0 -> 1845 bytes test/smask-stroke.c | 83 ++++++++++++++++++++++ test/smask-text-ref.png | Bin 0 -> 1796 bytes test/smask-text.c | 92 ++++++++++++++++++++++++ test/smask.c | 130 ++++++++++++++++++++++++++++++++++ 16 files changed, 698 insertions(+) create mode 100644 test/smask-fill-ref.png create mode 100644 test/smask-fill.c create mode 100644 test/smask-image-mask-ref.png create mode 100644 test/smask-image-mask.c create mode 100644 test/smask-mask-ref.png create mode 100644 test/smask-mask.c create mode 100644 test/smask-paint-ref.png create mode 100644 test/smask-paint.c create mode 100644 test/smask-ref.png create mode 100644 test/smask-stroke-ref.png create mode 100644 test/smask-stroke.c create mode 100644 test/smask-text-ref.png create mode 100644 test/smask-text.c create mode 100644 test/smask.c diff --git a/test/.gitignore b/test/.gitignore index 268afcaa1..689ecf0f2 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -162,6 +162,13 @@ set-source show-glyphs-many show-text-current-point skew-extreme +smask +smask-fill +smask-image-mask +smask-mask +smask-paint +smask-stroke +smask-text solid-pattern-cache-stress source-clip source-clip-scale diff --git a/test/Makefile.am b/test/Makefile.am index 2dce2310d..b73df2362 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -120,6 +120,13 @@ self-intersecting$(EXEEXT) \ set-source$(EXEEXT) \ show-text-current-point$(EXEEXT) \ skew-extreme$(EXEEXT) \ +smask$(EXEEXT) \ +smask-fill$(EXEEXT) \ +smask-image-mask$(EXEEXT) \ +smask-mask$(EXEEXT) \ +smask-paint$(EXEEXT) \ +smask-stroke$(EXEEXT) \ +smask-text$(EXEEXT) \ solid-pattern-cache-stress$(EXEEXT) \ source-clip$(EXEEXT) \ source-clip-scale$(EXEEXT) \ @@ -579,6 +586,13 @@ REFERENCE_IMAGES = \ show-text-current-point-quartz-ref.png \ skew-extreme-ref.png \ skew-extreme-ps-ref.png \ + smask-ref.png \ + smask-fill-ref.png \ + smask-image-mask-ref.png \ + smask-mask-ref.png \ + smask-paint-ref.png \ + smask-stroke-ref.png \ + smask-text-ref.png \ stroke-image-ref.png \ stroke-image-pdf-ref.png \ stroke-image-ps-ref.png \ diff --git a/test/smask-fill-ref.png b/test/smask-fill-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..c778a7911a957da39681dfd39bf3e74719b5fdfa GIT binary patch literal 1223 zcmV;&1UUPNP)%k@HGmCj`9 zK->^>t*9Jr^<4M#A|Bh?bLX?U&F8ruIB>t0%jJBy=Wq_^d~bqu+D%l7Zgc}?yWDi( zV5VMNWJHy2D;-g-%QB}dbiu7Io9l0(z#ncipj4j|il=6&EY|(6yo~y{I zVE-TYsj$yR?dqi@Z!9<=ZH>dWdPk++G05q_j;@!KYt^Vj-F1EODT5cfV29mSI64kF z-PqChPI^GIE&7$s9{34gc+DFY_;psXnRw8Atr~r2`OJb7(za-}$=CZ?Ms{O$y;n7l$7$6&n)-d^??_dhNM^i;UQ!xnQxGy3xL@V|g67R;R_z7Bn^~rBbg49ltjCIUf}~ zHglbAF;X-(7_rX5SYQL8)xI3pt;c|?bWeF(Cf~4u&|QAENKZ7lPDgC8nfogojRw~^ z5i4vUw8WWc@cn*_7519o3VpG{CZ*i#d^EVkP^_?l&>en@2G8?XtgwO5?S3Bv9&^+Z z3KSWM4K@%eG7|lTe|LMVut_Pyilf25S`aI2AT*>T8r-WgR@gwOS7kK#ti`dy212JS ziw2*zG*;NZ%+sYh8hp$nvBC~3)}e0VEZGkM-=(WBO|BeX3r2USQw%q83dvlbANT zJnVa$?J?ir4Z#j5wad<&#_Y6!p-jIfEvj|R`aHYa4nMhjD$TzB^x--kHrcD(r5VMZ zbDy_un{ZJv9N95OPsOTS@$~cPQSR#ACmsvB){xd7c6wjGF_@2vC?Tv l3*#q`LMS)ge@izV_#dfElh%d8_vrut002ovPDHLkV1ih0VcY-! literal 0 HcmV?d00001 diff --git a/test/smask-fill.c b/test/smask-fill.c new file mode 100644 index 000000000..980018e4c --- /dev/null +++ b/test/smask-fill.c @@ -0,0 +1,83 @@ +/* + * Copyright © 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; + +cairo_test_t test = { + "smask-fill", + "Test the support of \"soft\" masks with fills", + 60, 60, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *mask; + cairo_pattern_t *pattern; + cairo_t *cr2; + + mask = cairo_surface_create_similar (cairo_get_group_target (cr), + CAIRO_CONTENT_ALPHA, + width, height); + cr2 = cairo_create (mask); + + cairo_save (cr2); { + cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr2); + } cairo_restore (cr2); + + pattern = cairo_pattern_create_linear (0, 0, width, height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5); + cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.); + cairo_set_source (cr2, pattern); + cairo_pattern_destroy (pattern); + + cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.45 * height, 0, 2 * M_PI); + cairo_fill (cr2); + cairo_destroy (cr2); + + + cairo_set_source_rgb (cr, 0, 0, 1.0); + cairo_paint (cr); + + cairo_set_source_rgb (cr, 1.0, 0, 0); + cairo_mask_surface (cr, mask, 0, 0); + cairo_surface_destroy (mask); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +} + diff --git a/test/smask-image-mask-ref.png b/test/smask-image-mask-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..858b2094e988bbb959ede8e901a827a5a453e4ff GIT binary patch literal 643 zcmeAS@N?(olHy`uVBq!ia0vp^HXzKw1|+Ti+$;i8Y)RhkE)4%caKYZ?lYt`aC7!;n z>^E3gxP_#*%@1D9z`&&H>EalY(fIV%#ysg1iPneD|1U9`ur&6NgQSMDcGpBzXA$kG z+T0*g*?Z@y4vnxb=M~-}&IKG>J6<*2YBUO9+qA`7;?xJ@Cr10cE3OsaD>{3d%Ukd7 z^I5O&{kXn+T5QGJw%KtzH@tDK|8@I!UiHJJ(Nbb@JJzP=Elj++a_6+)eP_3P_3O1d}a!BqaP2J1Z>N+)c@_dQH?&`KReQty8)()VeWOHnHznb33wjmGZLS)*3jf3I8)w5s#`l)lHa zSgVg0PvqQvA>iH5g=q)xefspu_DoalyS_``g3mVnJrEC6$S<#{T?cf*`=8HOeLT@r z`*hi*PfOAc#(j57ITRNWHmh!J#BxIa a@E_bSFTHZR`*UC#V(@hJb6Mw<&;$U)i!w|A literal 0 HcmV?d00001 diff --git a/test/smask-image-mask.c b/test/smask-image-mask.c new file mode 100644 index 000000000..5c805e1cd --- /dev/null +++ b/test/smask-image-mask.c @@ -0,0 +1,92 @@ +/* + * Copyright © 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; + +cairo_test_t test = { + "smask-image-mask", + "Test the support of \"soft\" masks with a secondary image mask", + 60, 60, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + static uint32_t data[] = { + 0xaa000000, 0x55000000, + 0x55000000, 0xaa000000, + }; + + cairo_surface_t *mask, *mask2; + cairo_pattern_t *pattern; + cairo_t *cr2; + + mask = cairo_surface_create_similar (cairo_get_group_target (cr), + CAIRO_CONTENT_ALPHA, + width, height); + cr2 = cairo_create (mask); + + cairo_save (cr2); { + cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr2); + } cairo_restore (cr2); + + pattern = cairo_pattern_create_linear (0, 0, width, height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5); + cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.); + cairo_set_source (cr2, pattern); + cairo_pattern_destroy (pattern); + + mask2 = cairo_image_surface_create_for_data ((unsigned char *) data, + CAIRO_FORMAT_ARGB32, 2, 2, 8); + pattern = cairo_pattern_create_for_surface (mask2); + cairo_surface_destroy (mask2); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); + cairo_mask (cr2, pattern); + cairo_pattern_destroy (pattern); + cairo_destroy (cr2); + + cairo_set_source_rgb (cr, 0, 0, 1.0); + cairo_paint (cr); + + cairo_set_source_rgb (cr, 1.0, 0, 0); + cairo_mask_surface (cr, mask, 0, 0); + cairo_surface_destroy (mask); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +} + diff --git a/test/smask-mask-ref.png b/test/smask-mask-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..eabd2d6b3ed5832f0074aead7c7e6d6be63765ef GIT binary patch literal 2523 zcmV<12_*K3P)%TN2z`R~F`Iec85%KI>+D zW=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EM8=iUN z3tw5XDcQmo-v@sV>Q6;#;1bdotIW4IbHOEKJ%q&V^vW4F8Q_tk2zPLP-Fnr zC@K|I53a^Vg^`!cCnmpuUD2EuXHlUjt7DB~a!#eXSgX8Z-5U<*o1~yV>z$aFxjIuz zsWv)yQtb-U#@Zr#1;udaKR0^^m}oR4UW^>4MJF z(bD)#*rA7%by!as>VSMwkzJ2B0*ch0a(uAoF&8>{zGB+;~IP_ znz>ORTNVXYDa$*W3~UMPO^VdrG4J`PK(k=+nBxoUuC`_I3)llx`ftsQee-HcY07)h zoM*|LU3Fgw`E5tbl*1LA&h=Wm=M+v8)<$2Dw*QD93l{p1KirIKrsYpJd@U*t2HykIGCyy!p}*y``I@kQvLnqP zY}JST+@bTQK|`>9oRbSzHb*o9)^EcUv}#sXGh;7FhhPVNICFFUG)T&&st!B^Tb&hG z0+woHby`_2Ch#M$H+@*U-&DfXfNKlmLF(3Y(c8URJuswf78iFFz6YDnd27+PX2!CD zd>SwWD^pg`bY&A<(6<6qzV?70{=G5BDxAQEa;~6rq*@!xcs{@9vmb%&H4l%%`aYC) z{Jm6n$afo#1y)+z|`J;;Q;Y91bi^>cyT%D1&4xyGzMN*(HFJp~8(~9KN^K^!S;Oke}T>Y9&A4T@Ma)kKdR_0*rM>Cgsoj8iwqrW lrky3Ds-=%Y-hn literal 0 HcmV?d00001 diff --git a/test/smask-mask.c b/test/smask-mask.c new file mode 100644 index 000000000..3d8cb0566 --- /dev/null +++ b/test/smask-mask.c @@ -0,0 +1,107 @@ +/* + * Copyright © 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; + +cairo_test_t test = { + "smask-mask", + "Test the support of \"soft\" masks with a secondary mask", + 60, 60, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *mask, *mask2; + cairo_pattern_t *pattern; + cairo_t *cr2; + + mask = cairo_surface_create_similar (cairo_get_group_target (cr), + CAIRO_CONTENT_ALPHA, + width, height); + + mask2 = cairo_surface_create_similar (mask, + CAIRO_CONTENT_ALPHA, + width, height); + cr2 = cairo_create (mask2); + + cairo_save (cr2); { + cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr2); + } cairo_restore (cr2); + + pattern = cairo_pattern_create_linear (0, 0, width, height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5); + cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.); + cairo_set_source (cr2, pattern); + cairo_pattern_destroy (pattern); + cairo_paint (cr2); + cairo_destroy (cr2); + + + cr2 = cairo_create (mask); + + cairo_save (cr2); { + cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr2); + } cairo_restore (cr2); + + pattern = cairo_pattern_create_radial ( + 0.5 * width, 0.5 * height, 0, + 0.5 * width, 0.5 * height, 0.5 *height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 1., 1., 1., 1.); + cairo_set_source (cr2, pattern); + cairo_pattern_destroy (pattern); + + cairo_mask_surface (cr2, mask2, 0, 0); + cairo_surface_destroy (mask2); + cairo_destroy (cr2); + + + cairo_set_source_rgb (cr, 0, 0, 1.0); + cairo_paint (cr); + + cairo_set_source_rgb (cr, 1.0, 0, 0); + cairo_mask_surface (cr, mask, 0, 0); + cairo_surface_destroy (mask); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +} + diff --git a/test/smask-paint-ref.png b/test/smask-paint-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..438120964015140b517afde55d205dd7c8f9d193 GIT binary patch literal 2639 zcmV-V3b6HwP) zsc6`8prYZ#k|QNYN=_`(sn?E_bgV93U-O=LUH%ua6%8dvmYe`6=vgqZU|?Xuo*f;l zGtd)DdJ1}q^!#VSE;&*DEZ7Zof?O~p$bz1M1;7N>m7RkfSY+XU7?$IYDICppMMpt@ z1}n&%veBFcc4C=8bq=F_==w)tS9GseI4W9lOiPQfI(iEB>}XjhNC$Qm9WnyzwSh(Y zj90qr@P54>@^B2FnL1I zGTmq0jC%?iDq7abZ{6gis-EY}ICtu^1s;{|DK5jl&n5;L# z&iZf+Py$s7a_E6YDlQIeso5k`c6Ak4V&3%>q{X|kbFlt5!D{oDobs?ah4owkDi@8t zg3@C>W@q=^oWeQZ%|+k2qo>nqo{c`cV3@$db5wTNoWe0e$3o+hvN5Oo zv8GMy(Ba@0eb_6gXufgx{7YoUf{hACU=<6|lpWmDTddmVV57>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@BKakj0S1g@mIb-f;4(0LjvN}mZk z^qjH|>nWp29nkZnB6dCA2t4(}(=_ITJs5m|JrcP7~HrUl48o8b1~+OmBa<8RtyP?{4^Jx*HrR z&mes&sz+a|0#ppX9ji1yFJnW0$!FtZgmtx)vT`k+s~=TSG!~r9IQ|GO!sa$spVzWZ zW9HH$X)b8Fspt#*(Cv>)X7AIIcsD|aDk$Yy_g7a~&~vb{G?wosg&nwKbr#a&qc1Yv z>&e09W>4C*v*z4#sm|!LaU>N3tShU?>~}d!hxOo<%V&P5NzX-V2aT|~DMc&~m1=SU z$}PzObIK~ppDCQXX&qtxxo$>B1#{{?_r}woCgyt9STV(@>}DKcW7p?_YNGJmZxwSz zhr>oweaVdDNXEx9xwbCm-Ak}>h@q4gVY5D*%gZ|T1Clw|T*Ds6sBti!YuE)U@VN1A z!ZDQ{DQ97`KJ3>H9e)}$2kXz{Vq9RNVIJYq#q%KVtz1_>z19Qs8;^IYxUxJPI zd2`V>XU4LE+)b?;^PGP>fal4%)$w5F6XA3SxiT&xv`Ar^Ot<~ zHL#QB;aXTf=hBY9Hg~Tl`fkZF!Rp9$Jw6qA2{OW-H4oRq`n5nV<=fnlTw_)rrOx%U zo`Q~)XXWCxuxHJ~YhnG`0TraKiOhoa^p>lQuZ_Z&U?)EOZ(!s35^TKv;mtsVeXXLG xV3Wc>6E^o5x%)tZ&6SL*mR<|_66}F3{{W5Ep++%feE + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; + +cairo_test_t test = { + "smask-paint", + "Test the support of \"soft\" masks with paints", + 60, 60, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *mask; + cairo_pattern_t *pattern; + cairo_t *cr2; + + mask = cairo_surface_create_similar (cairo_get_group_target (cr), + CAIRO_CONTENT_ALPHA, + width, height); + cr2 = cairo_create (mask); + + cairo_save (cr2); { + cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr2); + } cairo_restore (cr2); + + pattern = cairo_pattern_create_linear (0, 0, width, height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5); + cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.); + cairo_set_source (cr2, pattern); + cairo_pattern_destroy (pattern); + + cairo_paint (cr2); + cairo_destroy (cr2); + + cairo_set_source_rgb (cr, 0, 0, 1.0); + cairo_paint (cr); + + pattern = cairo_pattern_create_radial ( + 0.5 * width, 0.5 * height, 0, + 0.5 * width, 0.5 * height, 0.5 *height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 0., 0., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 0., 0., .5); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 1., 0., 0., 1.); + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + + cairo_mask_surface (cr, mask, 0, 0); + cairo_surface_destroy (mask); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +} + diff --git a/test/smask-ref.png b/test/smask-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..2d98e4337377593cf99aacdb1e7a9f7afe706060 GIT binary patch literal 3587 zcmV+e4*cX!OSHY9yco$lLxZ*_g^_dHKMRdutPR$kLq(^l6KuJ82oR?n(B>RPHg#l2jn zqpGVSm-U=O3D37G+kGc}Ui<%mt!b<1%H&X-!_iXjX-EtlN?8Z|SlEj0E#UtP*s4xZ zb=K4LTd=vTfNiVwz~sp<%I@8%`em>cU9}$z8$dI8kE&%ys%#8argZ42^!kUw77G7R zvyK(*2b;<5cgfwpH)YnSC3P)b6|06U7=lO!3=+t?0`3xs?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ilY~$~9GE()eRu5wEH)xt~I*p587{53i z0W^Tez;Q!Pc*HY4w%;WOo$ncrLYw~E-}H>RY3HW?T-LcMd@b}~Ji(5Wgz&|1E(48U zI$~Ka+oW*XkdCT9dD?x>*zb~Y3mTeQ>Mq&uuO4*Mjv~;-CY>rAMr`!7IgUReIA;Ii zpYzn&V`bAHhd`0`a9P$9NADOqtutg;aouHLW$y{YPrPW5{;xAGwea8OcsxrRQ}#LZ zdf8Z*Hmc05oG%lx_Dz3uL2i+1E?FW#!>@AO#=9vV~DQR$*y+4YZo_CK#1ySs#)=Y0SG002ov JPDHLkV1j8s9Yp{D literal 0 HcmV?d00001 diff --git a/test/smask-stroke-ref.png b/test/smask-stroke-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..0d3f7feaeb7d9a027e99361551db81fd34d3d145 GIT binary patch literal 1845 zcmV-52g>+~P)_N;Gh;V zA0b0UGlwV-MJjI42TGyz+<5PmWOL`V=d|Y*BYu-B?aB4OuKs@a|IVFr|F3`Zh$3eZ z=bUK)Up3zv{-$%*84lvye3(NjHMr7S#@b_~M#YZm@1#(m%^-&jvDX;8jq|R{Y%|#r zgJaW_m+Pl=nPxY6-a;$<(Cbd=Cn+HmoE|-We$S;|a-Gd)Xjha=dATz@+CGadGv8_@ zS{3N@i4k6LwKq)hp^NM@TC*}83c*0fm1uRogGSruVjsB7yNVqZ3Y;*&CNn+j7KaSW zh0MMiF45|K54qhcg*qf9JmXd?E%0~W@710c`B0U5(`}KE)Ft0$Gpu#n>5J7{`egW8 zFZ+XEE7#NPi5FHhtH7pqgPOMX^+WMz1u;h8RD@0MtRDjjBoFZziB<-LDOt?RI&M1 zpE0x0tW2G1oeF%{Ki%ksjMrvl_*yTkQ46Zo*=tPil;)6TWuCIg=gu+R78C8rbZHcI zH%hcb+x;Lqs63i)RkyKcVoddF^k+Yd9`TE)(6Juld(7~C9#*c&CNr%zzi(-Yf!9p6 z(*&hj%<*(4OVVGBQT9cRDxyXeQMrR>Je%ppV27j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1,83 @@ +/* + * Copyright © 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; + +cairo_test_t test = { + "smask-stroke", + "Test the support of \"soft\" masks with strokes", + 60, 60, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *mask; + cairo_pattern_t *pattern; + cairo_t *cr2; + + mask = cairo_surface_create_similar (cairo_get_group_target (cr), + CAIRO_CONTENT_ALPHA, + width, height); + cr2 = cairo_create (mask); + + cairo_save (cr2); { + cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr2); + } cairo_restore (cr2); + + pattern = cairo_pattern_create_linear (0, 0, width, height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5); + cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.); + cairo_set_source (cr2, pattern); + cairo_pattern_destroy (pattern); + + cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.4 * height, 0, 2 * M_PI); + cairo_stroke (cr2); + cairo_destroy (cr2); + + + cairo_set_source_rgb (cr, 0, 0, 1.0); + cairo_paint (cr); + + cairo_set_source_rgb (cr, 1.0, 0, 0); + cairo_mask_surface (cr, mask, 0, 0); + cairo_surface_destroy (mask); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +} + diff --git a/test/smask-text-ref.png b/test/smask-text-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..e5ca43f1a54c09f11ebd8971a0bd15524f06596e GIT binary patch literal 1796 zcmbW230D$`7RQ~*w1KC+u_6_5nVwVbTcM`UjtaR1%yU5#MICWNbIE-nn|zg-TLqRR zs3W4OV7Opl*%?!D0~}>=0k>?@!ZkD%ow3I|?|p&y&OP`3&b{Z}bM86!oc}HS2g*YO zpbJn@QPJ@7g!w9&rF7?GYRbrD<~>tFE#is?Oy$eJt){zysH~``c_HEIQ>v;!P1CQS zntWwXy%)^YKZ~*^$u0I5Lw@-*%3p<=vCOS}vVQ{FY<5tv*7EyYH_&xKYU$#3V0dQ2hz&69PGvDo60euWYH}7qd{a+bY@IU z%yhb^h+u!4@nNl^qe9f>7+!OHHkRqt{%xQ$1~>xx%C-p=ig zrj!h?P4)+|z4gZD4-$7yUrGykzLOpfHhH!HK!(oPqe^?92!E;NqS90IcH4?`9PlJ&-eOta+ZO?qIY_^{$~UxykMdQ@>ym&|YD95Bp=z87|qsku^ADxC@y}JQ%{N z9@XhNlK@;Nnjzx@TWrNVX?O*;OgQXJt)HWy=Z)uvDP z9nLZxag!CRfq52|QMVxqYO<5by@k+Hb!=Cd0=`TR?{);4`OaUvFq`&sImnM;8DGUW z;jraaSaLgZmI{a{`%r1OQ}dPU`dsPz%<;84!+fy*6-hhy(m1p%%SF3U!KfES1f@oy zdbq>yd`m$7%>E^J_iI-YR$>9)?EwRif_0BTSR*XxGH2e5liaE&9#~m#4deQCHKV^X zxdnvmF$Piq!kuSC<|{hTkZ9K>TcuQVymyzSwas>mzTRT(xEJc(k%iNO6uk*6?Z7Sb^L$I=xPCgR z5jq^8%zo(!*yv#*$Cy|ZG6M={+uGo<)K6{dh!=0fE`bb`frp^8Z=Mj=sB42)ip5NE zXZj-Cmv#EkeO1{N^0qnp;8*1CW1^PevI0AIzE{p@B@c9JC)|egw4VLDm|<~qQxyI@ ztF&J*9F`u&s-D@t;|AqP|N5$CaHb%!D-&B6ijW-tLkwPjy(heO|q z5B(>yRRWpIsLa%8^{{U+Hug8$DqOi{H?H=sQj9Fj71DT;NJ`26#oDV>UHailB@~Qn z_9?Oa>2duOA+t?>ihl=Ld{a?splC0g;LZ&U`#U`+{yEIF8}n@^ylr}wnxQ&&v&{{) jT~_+wzq0#(;fuQWD6v`^dGxsQiK%$OQLq-b@ce%P4ZneT literal 0 HcmV?d00001 diff --git a/test/smask-text.c b/test/smask-text.c new file mode 100644 index 000000000..589c71df7 --- /dev/null +++ b/test/smask-text.c @@ -0,0 +1,92 @@ +/* + * Copyright © 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; + +cairo_test_t test = { + "smask-text", + "Test the support of \"soft\" masks with text", + 120, 60, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *mask; + cairo_pattern_t *pattern; + cairo_t *cr2; + cairo_text_extents_t extents; + + mask = cairo_surface_create_similar (cairo_get_group_target (cr), + CAIRO_CONTENT_ALPHA, + width, height); + cr2 = cairo_create (mask); + + cairo_save (cr2); { + cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr2); + } cairo_restore (cr2); + + pattern = cairo_pattern_create_linear (0, 0, width, height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5); + cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.); + cairo_set_source (cr2, pattern); + cairo_pattern_destroy (pattern); + + cairo_select_font_face (cr2, + "Bitstream Vera Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size (cr2, 0.5 * height); + + cairo_text_extents (cr2, "cairo", &extents); + cairo_move_to (cr2, + floor ((width - extents.width) / 2 + 0.5) - extents.x_bearing, + floor ((height - extents.height) / 2 - 0.5) - extents.y_bearing); + cairo_show_text (cr2, "cairo"); + cairo_destroy (cr2); + + cairo_set_source_rgb (cr, 0, 0, 1.0); + cairo_paint (cr); + + cairo_set_source_rgb (cr, 1.0, 0, 0); + cairo_mask_surface (cr, mask, 0, 0); + cairo_surface_destroy (mask); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +} + diff --git a/test/smask.c b/test/smask.c new file mode 100644 index 000000000..28eaed061 --- /dev/null +++ b/test/smask.c @@ -0,0 +1,130 @@ +/* + * Copyright © 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; + +cairo_test_t test = { + "smask", + "Test the support of \"soft\" masks", + 60, 60, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + static uint32_t data[] = { + 0x80000000, 0x80000000, + 0x80000000, 0x80000000, + }; + + cairo_surface_t *mask, *mask2; + cairo_pattern_t *pattern; + cairo_t *cr2; + cairo_text_extents_t extents; + + mask = cairo_surface_create_similar (cairo_get_group_target (cr), + CAIRO_CONTENT_ALPHA, + width, height); + cr2 = cairo_create (mask); + + cairo_save (cr2); { + cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr2); + } cairo_restore (cr2); + + pattern = cairo_pattern_create_linear (0, 0, 0, height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.0); + cairo_pattern_add_color_stop_rgba (pattern, 0.80, 0., 0., 0., 0.0); + cairo_pattern_add_color_stop_rgba (pattern, 0.90, 1., 1., 1., 0.25); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 1., 1., 1., 1.0); + cairo_set_source (cr2, pattern); + cairo_pattern_destroy (pattern); + + cairo_paint (cr2); + + pattern = cairo_pattern_create_linear (0, 0, width, height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5); + cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.); + cairo_set_source (cr2, pattern); + cairo_pattern_destroy (pattern); + + mask2 = cairo_image_surface_create_for_data ((unsigned char *) data, + CAIRO_FORMAT_ARGB32, 2, 2, 8); + pattern = cairo_pattern_create_for_surface (mask2); + cairo_surface_destroy (mask2); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); + cairo_mask (cr2, pattern); + cairo_pattern_destroy (pattern); + + cairo_arc (cr2, 0.5 * width, 0.5 * height - 10, 0.2 * height, 0, 2 * M_PI); + cairo_fill (cr2); + + cairo_arc (cr2, 0.5 * width, 0.5 * height - 10, 0.25 * height, 0, 2 * M_PI); + cairo_stroke (cr2); + + cairo_select_font_face (cr2, + "Bitstream Vera Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size (cr2, 0.3 * height); + + cairo_text_extents (cr2, "FG", &extents); + cairo_move_to (cr2, + floor ((width - extents.width) / 2 + 0.5) - extents.x_bearing, + floor (height - extents.height - 0.5) - extents.y_bearing - 5); + cairo_show_text (cr2, "FG"); + cairo_destroy (cr2); + + cairo_set_source_rgb (cr, 0, 0, 1.0); + cairo_paint (cr); + + pattern = cairo_pattern_create_radial ( + 0.5 * width, 0.5 * height, 0, + 0.5 * width, 0.5 * height, 0.5 *height); + cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.); + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 0., 0., 1.); + cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 0., 0., .5); + cairo_pattern_add_color_stop_rgba (pattern, 1.00, 1., 0., 0., 1.); + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + + cairo_mask_surface (cr, mask, 0, 0); + cairo_surface_destroy (mask); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +} +