caps.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright © 2008 Chris Wilson
  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. * Chris Wilson not be used in advertising or publicity pertaining to
  10. * distribution of the software without specific, written prior
  11. * permission. Chris Wilson 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. * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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. * Author: Chris Wilson <chris@chris-wilson.co.uk>
  24. */
  25. #include "cairo-test.h"
  26. #define LINE_WIDTH 10.
  27. #define SIZE (5 * LINE_WIDTH)
  28. #define PAD (2 * LINE_WIDTH)
  29. static void
  30. make_path (cairo_t *cr)
  31. {
  32. int i;
  33. cairo_save (cr);
  34. for (i = 0; i <= 3; i++) {
  35. cairo_new_sub_path (cr);
  36. cairo_move_to (cr, -SIZE / 2, 0.);
  37. cairo_line_to (cr, SIZE / 2, 0.);
  38. cairo_rotate (cr, M_PI / 4.);
  39. }
  40. cairo_restore (cr);
  41. }
  42. static cairo_test_status_t
  43. draw (cairo_t *cr)
  44. {
  45. cairo_save (cr);
  46. cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
  47. cairo_paint (cr);
  48. cairo_restore (cr);
  49. cairo_translate (cr, PAD + SIZE / 2., PAD + SIZE / 2.);
  50. cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
  51. cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
  52. make_path (cr);
  53. cairo_stroke (cr);
  54. cairo_translate (cr, 0, SIZE + PAD);
  55. cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
  56. cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
  57. make_path (cr);
  58. cairo_stroke (cr);
  59. cairo_translate (cr, 0, SIZE + PAD);
  60. cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
  61. cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
  62. make_path (cr);
  63. cairo_stroke (cr);
  64. return CAIRO_TEST_SUCCESS;
  65. }
  66. static cairo_test_status_t
  67. draw_10 (cairo_t *cr, int width, int height)
  68. {
  69. cairo_set_line_width (cr, LINE_WIDTH);
  70. return draw (cr);
  71. }
  72. static cairo_test_status_t
  73. draw_2 (cairo_t *cr, int width, int height)
  74. {
  75. cairo_set_line_width (cr, 2);
  76. return draw (cr);
  77. }
  78. static cairo_test_status_t
  79. draw_1 (cairo_t *cr, int width, int height)
  80. {
  81. cairo_set_line_width (cr, 1);
  82. return draw (cr);
  83. }
  84. static cairo_test_status_t
  85. draw_05 (cairo_t *cr, int width, int height)
  86. {
  87. cairo_set_line_width (cr, 0.5);
  88. return draw (cr);
  89. }
  90. CAIRO_TEST (caps,
  91. "Test caps",
  92. "stroke, caps", /* keywords */
  93. NULL, /* requirements */
  94. PAD + SIZE + PAD,
  95. 3 * (PAD + SIZE) + PAD,
  96. NULL, draw_10)
  97. CAIRO_TEST (caps_2,
  98. "Test normal caps",
  99. "stroke, caps", /* keywords */
  100. NULL, /* requirements */
  101. PAD + SIZE + PAD,
  102. 3 * (PAD + SIZE) + PAD,
  103. NULL, draw_2)
  104. CAIRO_TEST (caps_1,
  105. "Test hairline caps",
  106. "stroke, caps", /* keywords */
  107. NULL, /* requirements */
  108. PAD + SIZE + PAD,
  109. 3 * (PAD + SIZE) + PAD,
  110. NULL, draw_1)
  111. CAIRO_TEST (caps_05,
  112. "Test fine caps",
  113. "stroke, caps", /* keywords */
  114. NULL, /* requirements */
  115. PAD + SIZE + PAD,
  116. 3 * (PAD + SIZE) + PAD,
  117. NULL, draw_05)