From ae143d779ba5765f55754cb89af87b065d84ef04 Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Tue, 25 Mar 2008 11:17:57 -0700 Subject: [PATCH] [quartz] When stroking with an image source, use the right CTM for the image Since the CTM was modified for the stroke transform, we need to reset it before calling ConcatCTM for the source transform. --- src/cairo-quartz-surface.c | 9 +++- test/Makefile.am | 3 ++ test/stroke-image-quartz-ref.png | Bin 0 -> 1802 bytes test/stroke-image-ref.png | Bin 0 -> 1866 bytes test/stroke-image.c | 77 +++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/stroke-image-quartz-ref.png create mode 100644 test/stroke-image-ref.png create mode 100644 test/stroke-image.c diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c index 93ad82cbd..4c2e9b5b7 100644 --- a/src/cairo-quartz-surface.c +++ b/src/cairo-quartz-surface.c @@ -1728,7 +1728,7 @@ _cairo_quartz_surface_stroke (void *abstract_surface, cairo_int_status_t rv = CAIRO_STATUS_SUCCESS; cairo_quartz_action_t action; quartz_stroke_t stroke; - CGAffineTransform strokeTransform; + CGAffineTransform origCTM, strokeTransform; CGPathRef path_for_unbounded = NULL; ND((stderr, "%p _cairo_quartz_surface_stroke op %d source->type %d\n", surface, op, source->type)); @@ -1749,6 +1749,9 @@ _cairo_quartz_surface_stroke (void *abstract_surface, CGContextSetLineCap (surface->cgContext, _cairo_quartz_cairo_line_cap_to_quartz (style->line_cap)); CGContextSetLineJoin (surface->cgContext, _cairo_quartz_cairo_line_join_to_quartz (style->line_join)); CGContextSetMiterLimit (surface->cgContext, style->miter_limit); + + origCTM = CGContextGetCTM (surface->cgContext); + _cairo_quartz_cairo_matrix_to_quartz (ctm, &strokeTransform); CGContextConcatCTM (surface->cgContext, strokeTransform); @@ -1795,6 +1798,8 @@ _cairo_quartz_surface_stroke (void *abstract_surface, CGContextReplacePathWithStrokedPath (surface->cgContext); CGContextClip (surface->cgContext); + CGContextSetCTM (surface->cgContext, origCTM); + CGContextConcatCTM (surface->cgContext, surface->sourceTransform); CGContextTranslateCTM (surface->cgContext, 0, surface->sourceImageRect.size.height); CGContextScaleCTM (surface->cgContext, 1, -1); @@ -1807,6 +1812,8 @@ _cairo_quartz_surface_stroke (void *abstract_surface, CGContextReplacePathWithStrokedPath (surface->cgContext); CGContextClip (surface->cgContext); + CGContextSetCTM (surface->cgContext, origCTM); + CGContextConcatCTM (surface->cgContext, surface->sourceTransform); CGContextDrawShading (surface->cgContext, surface->sourceShading); } else if (action != DO_NOTHING) { diff --git a/test/Makefile.am b/test/Makefile.am index 069ce1e17..86b6de5ad 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -111,6 +111,7 @@ rotate-image-surface-paint$(EXEEXT) \ scale-down-source-surface-paint$(EXEEXT) \ scale-source-surface-paint$(EXEEXT) \ stroke-ctm-caps$(EXEEXT) \ +stroke-image$(EXEEXT) \ select-font-face$(EXEEXT) \ select-font-no-show-text$(EXEEXT) \ self-copy$(EXEEXT) \ @@ -567,6 +568,8 @@ REFERENCE_IMAGES = \ show-text-current-point-quartz-ref.png \ skew-extreme-ref.png \ skew-extreme-ps-ref.png \ + stroke-image-ref.png \ + stroke-image-quartz-ref.png \ source-clip-ref.png \ source-clip-scale-quartz-ref.png \ source-clip-scale-ps-argb32-ref.png \ diff --git a/test/stroke-image-quartz-ref.png b/test/stroke-image-quartz-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..db1f5a708c4b32b657de27c57552e5afe141d913 GIT binary patch literal 1802 zcmV+l2le=gP)IRJa)xA%USH zBrsHj1cr)`z)%qq7%D;nLq$kns0axRv&s%YMhCDMSO%;C?oEE~13D9%OTc;H9B>pk z2K<=(e8qFT8DN6cZVZDM-oh}3$t+`uuffE3+4(is(gT>#1sFDCIF|zfQ^{yD*8BkS z4vvt13_~7BXeL8R3}x4$bV3F&94(QEMmdtiG~)>A!tiP7&ZVCXENF5U@g!SD=* z8>N?gYPpfb+TyW3U}|+%3P%s{Ik3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y#Jzvw|H=Cl z{R)c$o!7|z)ew^GCE{lMlXVdHc}hrfJ;}jCt^B^w(OH{LI@dU+IY(oWo#?tRP0l(|(<+Q4>`>u~AipOA0Jy15iNA$9G? zaG*pY_G7p!fI0+2NL}Y+&wb_jilSz62HS$KdiAQPUD$K6Z(_KX0|D0(U+WX!W#`vK z{r%aS741yCzIy=M>SHPY{rc`R*eiI)uv@U_k?&`ejd%!|A(%;*n4>^NNMNW42@Dk> sfuSNKFjRyDhKi8DP!SRsDnbIozb-?ijZP}JQ~&?~07*qoM6N<$f&v&`dH?_b literal 0 HcmV?d00001 diff --git a/test/stroke-image-ref.png b/test/stroke-image-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..c8b9417dfe4b5bf357ac46e7116ce0b7db0fc52b GIT binary patch literal 1866 zcmV-Q2etT#P)`6pHRCt{2o!g67RTRfRKW8lGqT_G8 zjA>djTBP7D2zv;`ywFn=*^8IR5&H*>3JQb}dWdAgUV4fyFNGBYL52+p1v2O;sY#he zqnUQmCbioz?H=~|q4P7Dwa(dRpS{QP-K>|H^;?(yJ-2<%-fLF?Ly2H8uIKR*3?(6fp(G?Ql!OF^l90eq5)v3nLIOi$(E*6j0?Y*F0gHh9fT_T2pd-;a51a;m z0s4T$z$xG?aK&@HDN!NRS10Yjy}&wPJem!lbCKgLMCJADZKk{+&;w6 zRzSaaC!~U5D~931yL|LEjA2U>v&TO2_mnjS*b6N2;>{fn0&9U^{kZcpFkB0qBR(>~ zK6;-6R{C+5FCi6R7w|DL4MDF*Bk(EEjm;@%#Fr6xkYtTzZJuN2gx77@GypE2QjrIwvIW7Yk!hs6ofQj=*yV! zP7Kp?OW4}(&KP4Kd7UW^jg2GQ_+mSTi8&HcFB37mm?7TX4P8$si1#B zc!m&Pdta4m5~HT|i~S3ZTf}v@h2Me2#6t$apV*i$3-!kVZ)A6y?(|x!Je}tR za2ZM~oyuGnXY!ZwhngGt`T#mLt87x_d%!m#3l+hA5(Ns9cR^g+m3VK6%b=)An-Rbd~T z(c9Jy45wh{%}US#{3Ny<7do)t*(GQPF3L^o28PRodPf<%WPqL2{gqHx+Gh!Lggh?P zdtMhrlz2g?w@znPcgebfY!-S8cDDIgMhmi6DwlzYa;~ zT1p`&vHGOLz=6!@6Zr3U#R!F+NT@d;cOE^Yxk~#E4IxW~ zdWvW6=pkJer+D<06LN=8Z%FPudPsAXesM%Y$TXqeu-tj{kmlMkx=IalLZn9Jqnh|3 z%{7;&tP)-zC*-_P&%^qOU?9!)N4ZHkAwLWC8syHShcs8|!HkBG?}d8f<<6srG}qH| zlX5~13H7RS=h35GsMjwyDJSHxP;ZXhdGwIx`lZ~YoRE`3y$9sZqsI!N-nVj-^6w$i z_x~rb^LK9soC4+w^c3HR^7%m3N;LJUQlk~PB+$$40~NqqLcLWgt8rqDQ15NMY56pj z)xzm7M*^6tleb8hS1Xsh=`LCA$ZLL#jxa5NquP~pDDvK$ z+E0ofX%_6HUndcsXbwcL3wFS+%a*o{0d!_o=~CqDeMuV_mM8)=*oBitcWPRhr_6Ox z5rlxP-YIRDu&b|%?p&=@lh~zgcQ$|73J0`d$0nM>0e559f5(6p;5ZQ#4j2TsD)eV# zKh`v5^6Cf8zyVZqs@Os%GHS?nN>|X`;0<=ESIC#IcH~RL@@O;Ow>2@ z0lET{u3ImLdjjZ(U00&Dizco!HtT%dp#d-_FSGyU$>^>+Z*{Tsn!J{u)WisCWpuNl+FJ z2n;15fuSTMFqDJ@hLVuLP!bXtN@~07*qoM6N<$ Ef>_~&SpWb4 literal 0 HcmV?d00001 diff --git a/test/stroke-image.c b/test/stroke-image.c new file mode 100644 index 000000000..464d7af67 --- /dev/null +++ b/test/stroke-image.c @@ -0,0 +1,77 @@ +/* + * Copyright © 2006 Mozilla Corporation + * + * 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 + * Mozilla Corporation not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Mozilla Corporation makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION 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: Vladimir Vukicevic + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; + +#define PAD 10 +#define SIZE 100 +#define IMAGE_SIZE (SIZE-PAD*2) +#define LINE_WIDTH 10 + +cairo_test_t test = { + "stroke-image", + "Test stroking with an image source, with a non-identity CTM", + SIZE, SIZE, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *isurf = cairo_image_surface_create (CAIRO_FORMAT_RGB24, IMAGE_SIZE, IMAGE_SIZE); + cairo_t *cr_image = cairo_create (isurf); + + /* Create the image */ + cairo_set_source_rgb (cr_image, 0, 0, 0); + cairo_paint (cr_image); + cairo_set_source_rgb (cr_image, 0, 1, 0); + cairo_set_line_width (cr_image, LINE_WIDTH); + cairo_arc (cr_image, IMAGE_SIZE/2, IMAGE_SIZE/2, IMAGE_SIZE/2 - LINE_WIDTH/2, 0, M_PI * 2.0); + cairo_stroke (cr_image); + cairo_destroy (cr_image); + + /* Now stroke with it */ + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_paint (cr); + + cairo_translate (cr, PAD, PAD); + + cairo_set_source_surface (cr, isurf, 0, 0); + + cairo_new_path (cr); + cairo_set_line_width (cr, LINE_WIDTH); + cairo_arc (cr, IMAGE_SIZE/2, IMAGE_SIZE/2, IMAGE_SIZE/2 - LINE_WIDTH/2, 0, M_PI * 2.0); + cairo_stroke (cr); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +}