close-path-current-point.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright © 2009 Nis Martensen
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software
  5. * and its documentation for any purpose is hereby granted without fee,
  6. * provided that the above copyright notice appear in all copies and
  7. * that both that copyright notice and this permission notice appear in
  8. * supporting documentation, and that the name of the copyright holder
  9. * not be used in advertising or publicity pertaining to distribution of
  10. * the software without specific, written prior permission. The
  11. * copyright holder makes no representations about the suitability of
  12. * this software for any purpose. It is provided "as is" without
  13. * express or implied warranty.
  14. *
  15. * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  18. * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  19. * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  20. * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  21. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. *
  23. * Author: Nis Martensen <nis.martensen@web.de>
  24. */
  25. #include "cairo-test.h"
  26. #define SIZE 20
  27. static cairo_test_status_t
  28. draw (cairo_t *cr, int width, int height)
  29. {
  30. /* We draw in the default black, so paint white first. */
  31. cairo_save (cr);
  32. cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
  33. cairo_paint (cr);
  34. cairo_restore (cr);
  35. /* subpath starts with cairo_move_to */
  36. cairo_new_sub_path (cr);
  37. cairo_move_to (cr, SIZE, SIZE);
  38. cairo_rel_line_to (cr, SIZE, 0);
  39. cairo_rel_line_to (cr, 0, SIZE);
  40. cairo_close_path (cr);
  41. cairo_rel_line_to (cr, 0.5 * SIZE, SIZE);
  42. /* subpath starts with cairo_line_to */
  43. cairo_new_sub_path (cr);
  44. cairo_line_to (cr, SIZE, 3 * SIZE);
  45. cairo_rel_line_to (cr, SIZE, 0);
  46. cairo_rel_line_to (cr, 0, SIZE);
  47. cairo_close_path (cr);
  48. cairo_rel_line_to (cr, 0, SIZE);
  49. /* subpath starts with cairo_curve_to */
  50. cairo_new_sub_path (cr);
  51. cairo_curve_to (cr,
  52. SIZE, 5 * SIZE,
  53. 1.5 * SIZE, 6 * SIZE,
  54. 2 * SIZE, 5 * SIZE);
  55. cairo_rel_line_to (cr, 0, SIZE);
  56. cairo_close_path (cr);
  57. cairo_rel_line_to (cr, -0.5 * SIZE, SIZE);
  58. /* subpath starts with cairo_arc */
  59. cairo_new_sub_path (cr);
  60. cairo_arc (cr,
  61. 1.5 * SIZE, 7 * SIZE,
  62. 0.5 * SIZE,
  63. M_PI, 2 * M_PI);
  64. cairo_rel_line_to (cr, 0, SIZE);
  65. cairo_close_path (cr);
  66. cairo_rel_line_to (cr, -0.7 * SIZE, 0.7 * SIZE);
  67. /* subpath starts with cairo_arc_negative */
  68. cairo_new_sub_path (cr);
  69. cairo_arc_negative (cr,
  70. 1.5 * SIZE, 9 * SIZE,
  71. 0.5 * SIZE,
  72. M_PI, 2 * M_PI);
  73. cairo_rel_line_to (cr, 0, SIZE);
  74. cairo_close_path (cr);
  75. cairo_rel_line_to (cr, -0.8 * SIZE, 0.3 * SIZE);
  76. cairo_stroke (cr);
  77. return CAIRO_TEST_SUCCESS;
  78. }
  79. CAIRO_TEST (close_path_current_point,
  80. "Test some corner cases related to cairo path operations and the current point",
  81. "path", /* keywords */
  82. NULL, /* requirements */
  83. 3 * SIZE, 11 * SIZE,
  84. NULL, draw)