joins-loop.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright © 2011 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * Author: Chris Wilson <chris@chris-wilson.co.uk>
  25. */
  26. #include "cairo-test.h"
  27. #define LINE_WIDTH 10.
  28. #define SIZE (8 * LINE_WIDTH)
  29. #define PAD (1 * LINE_WIDTH)
  30. static void
  31. make_path (cairo_t *cr)
  32. {
  33. cairo_move_to (cr, 0, 0);
  34. cairo_rel_curve_to (cr,
  35. SIZE, 0,
  36. 0, SIZE,
  37. SIZE, SIZE);
  38. cairo_rel_line_to (cr, -SIZE, 0);
  39. cairo_rel_curve_to (cr,
  40. SIZE, 0,
  41. 0, -SIZE,
  42. SIZE, -SIZE);
  43. cairo_close_path (cr);
  44. }
  45. static void
  46. draw_joins (cairo_t *cr)
  47. {
  48. cairo_save (cr);
  49. cairo_translate (cr, PAD, PAD);
  50. make_path (cr);
  51. cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
  52. cairo_stroke (cr);
  53. cairo_translate (cr, SIZE + PAD, 0.);
  54. make_path (cr);
  55. cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
  56. cairo_stroke (cr);
  57. cairo_translate (cr, SIZE + PAD, 0.);
  58. make_path (cr);
  59. cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
  60. cairo_stroke (cr);
  61. cairo_translate (cr, SIZE + PAD, 0.);
  62. cairo_restore (cr);
  63. }
  64. static cairo_test_status_t
  65. draw (cairo_t *cr, int width, int height)
  66. {
  67. cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
  68. cairo_paint (cr);
  69. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  70. cairo_set_line_width (cr, LINE_WIDTH);
  71. draw_joins (cr);
  72. /* and reflect to generate the opposite vertex ordering */
  73. cairo_translate (cr, 0, height);
  74. cairo_scale (cr, 1, -1);
  75. draw_joins (cr);
  76. return CAIRO_TEST_SUCCESS;
  77. }
  78. CAIRO_TEST (joins_loop,
  79. "A loopy concave shape",
  80. "stroke", /* keywords */
  81. NULL, /* requirements */
  82. 3*(SIZE+PAD)+PAD, 2*(SIZE+PAD)+2*PAD,
  83. NULL, draw)