path-append.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright © 2009 Jeff Muizelaar
  3. * Copyright © 2009 Chris Wilson
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and its
  6. * documentation for any purpose is hereby granted without fee, provided that
  7. * the above copyright notice appear in all copies and that both that copyright
  8. * notice and this permission notice appear in supporting documentation, and
  9. * that the name of the copyright holders not be used in advertising or
  10. * publicity pertaining to distribution of the software without specific,
  11. * written prior permission. The copyright holders make no representations
  12. * about the suitability of this software for any purpose. It is provided "as
  13. * is" without express or implied warranty.
  14. *
  15. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  16. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  17. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  18. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  20. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  21. * OF THIS SOFTWARE.
  22. */
  23. #include "cairo-test.h"
  24. #include <stdlib.h>
  25. static cairo_test_status_t
  26. draw (cairo_t *cr, int width, int height)
  27. {
  28. cairo_matrix_t m;
  29. int xoffset = 50;
  30. int yoffset = 50;
  31. cairo_surface_t *shadow;
  32. cairo_t *shadow_cr;
  33. cairo_path_t *path;
  34. cairo_set_source_rgb (cr, 1, 1, 1);
  35. cairo_paint (cr);
  36. cairo_translate (cr, 130, 130);
  37. cairo_rotate (cr, .5);//2*M_PI*angle/360);
  38. cairo_rectangle (cr, 0, 0, 50, 100);
  39. cairo_get_matrix (cr, &m);
  40. shadow = cairo_surface_create_similar (cairo_get_target (cr),
  41. CAIRO_CONTENT_COLOR_ALPHA,
  42. 600 - xoffset,
  43. 600 - yoffset);
  44. cairo_surface_set_device_offset (shadow, xoffset, yoffset);
  45. shadow_cr = cairo_create (shadow);
  46. cairo_surface_destroy (shadow);
  47. cairo_set_source_rgb (shadow_cr, 0, 1, 0);
  48. cairo_set_matrix (shadow_cr, &m);
  49. path = cairo_copy_path (cr);
  50. cairo_new_path (shadow_cr);
  51. cairo_append_path (shadow_cr, path);
  52. cairo_fill (shadow_cr);
  53. cairo_path_destroy (path);
  54. cairo_identity_matrix (cr);
  55. cairo_translate (cr, 10, 50);
  56. cairo_set_source_surface (cr, cairo_get_target (shadow_cr), 0, 0);
  57. cairo_paint (cr);
  58. cairo_set_matrix (cr, &m);
  59. cairo_set_source_rgb (cr, 1, 0, 0);
  60. cairo_fill (cr);
  61. cairo_destroy (shadow_cr);
  62. return CAIRO_TEST_SUCCESS;
  63. }
  64. CAIRO_TEST (path_append,
  65. "Test appending path to a context, in particular to exercise a regression in 005436",
  66. "path", /* keywords */
  67. NULL, /* requirements */
  68. 600, 600,
  69. NULL, draw)