device-offset-scale.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright © 2008 Mozilla Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software
  5. * and its documentation for any purpose is hereby granted without
  6. * fee, provided that the above copyright notice appear in all copies
  7. * and that both that copyright notice and this permission notice
  8. * appear in supporting documentation, and that the name of
  9. * Mozilla Corporation not be used in advertising or publicity pertaining to
  10. * distribution of the software without specific, written prior
  11. * permission. Mozilla Corporation makes no representations about the
  12. * suitability of this software for any purpose. It is provided "as
  13. * is" without express or implied warranty.
  14. *
  15. * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL,
  18. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  19. * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  21. * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. *
  23. * Authors: Michael Ventnor, Jeff Muizelaar
  24. */
  25. #include "cairo-test.h"
  26. #define WIDTH 20
  27. #define HEIGHT 20
  28. static cairo_test_status_t
  29. draw (cairo_t *cr, int width, int height)
  30. {
  31. cairo_surface_t *second;
  32. cairo_t *second_cr;
  33. /* fill with black so we don't need an rgb test case */
  34. cairo_set_source_rgb (cr, 0, 0, 0);
  35. cairo_paint (cr);
  36. cairo_scale (cr, 0.5, 0.5);
  37. /* draw the first rectangle */
  38. cairo_set_source_rgb (cr, 0, 0, 0.4);
  39. cairo_rectangle (cr, 6, 6, 10, 10);
  40. cairo_fill (cr);
  41. /* adjust the offset so that the second rectangle will fit on the surface */
  42. second = cairo_image_surface_create (CAIRO_FORMAT_A8, 10, 10);
  43. cairo_surface_set_device_offset (second, -6, -6);
  44. /* draw the second rectangle:
  45. * this rectangle should end up in the same place as the rectangle above
  46. * independent of the device offset of the surface it is painted on*/
  47. second_cr = cairo_create (second);
  48. cairo_surface_destroy (second);
  49. cairo_rectangle (second_cr, 6, 6, 10, 10);
  50. cairo_fill (second_cr);
  51. /* paint the second rectangle on top of the first rectangle */
  52. cairo_set_source_rgb (cr, 0.5, 0.5, 0);
  53. cairo_mask_surface (cr, cairo_get_target (second_cr), 0, 0);
  54. cairo_destroy (second_cr);
  55. return CAIRO_TEST_SUCCESS;
  56. }
  57. /*
  58. * XFAIL: complication of pre-multiplying device_offset into the pattern_matrix
  59. * and then requiring further manipulation for SVG
  60. */
  61. CAIRO_TEST (device_offset_scale,
  62. "Test that the device-offset transform is transformed by the ctm.",
  63. "device-offset", /* keywords */
  64. NULL, /* requirements */
  65. WIDTH, HEIGHT,
  66. NULL, draw)