dash-zero-length.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright © 2006 Jeff Muizelaar
  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. * Jeff Muizelaar. not be used in advertising or publicity pertaining to
  10. * distribution of the software without specific, written prior
  11. * permission. Jeff Muizelaar. 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. * JEFF MUIZELAAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. * FITNESS, IN NO EVENT SHALL JEFF MUIZELAAR 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: Jeff Muizelaar <jeff@infidigm.net>
  24. */
  25. #include "cairo-test.h"
  26. #define IMAGE_WIDTH 19
  27. #define IMAGE_HEIGHT 61
  28. /* A test of the two extremes of dashing: a solid line
  29. * and an invisible one. Also test that capping works
  30. * on invisible lines.
  31. */
  32. static void
  33. draw_dash (cairo_t *cr, double *dash, int num_dashes)
  34. {
  35. cairo_set_dash (cr, dash, num_dashes, 0.0);
  36. cairo_move_to (cr, 1, 2);
  37. cairo_line_to (cr, 18, 2);
  38. cairo_stroke (cr);
  39. cairo_translate (cr, 0, 3);
  40. }
  41. static cairo_test_status_t
  42. draw (cairo_t *cr, int width, int height)
  43. {
  44. static double solid_line[] = { 4, 0 };
  45. static double invisible_line[] = { 0, 4 };
  46. static double dotted_line[] = { 0, 6 };
  47. static double zero_1_of_3[] = { 0, 2, 3 };
  48. static double zero_2_of_3[] = { 1, 0, 3 };
  49. static double zero_3_of_3[] = { 1, 2, 0 };
  50. static double zero_1_of_4[] = { 0, 2, 3, 4 };
  51. static double zero_2_of_4[] = { 1, 0, 3, 4 };
  52. static double zero_3_of_4[] = { 1, 2, 0, 4 };
  53. static double zero_4_of_4[] = { 1, 2, 3, 0 };
  54. static double zero_1_2_of_4[] = { 0, 0, 3, 4 };
  55. static double zero_1_3_of_4[] = { 0, 2, 0, 4 };
  56. /* Clearly it would be nice to draw this one as well, but it seems to trigger a bug in ghostscript. */
  57. #if BUG_FIXED_IN_GHOSTSCRIPT
  58. static double zero_1_4_of_4[] = { 0, 2, 3, 0 };
  59. #endif
  60. static double zero_2_3_of_4[] = { 1, 0, 0, 4 };
  61. static double zero_2_4_of_4[] = { 1, 0, 3, 0 };
  62. static double zero_3_4_of_4[] = { 1, 2, 0, 0 };
  63. static double zero_1_2_3_of_4[] = { 0, 0, 0, 4 };
  64. static double zero_1_2_4_of_4[] = { 0, 0, 3, 0 };
  65. static double zero_1_3_4_of_4[] = { 0, 2, 0, 0 };
  66. static double zero_2_3_4_of_4[] = { 1, 0, 0, 0 };
  67. cairo_set_source_rgb (cr, 1, 0, 0);
  68. cairo_set_line_width (cr, 2);
  69. draw_dash (cr, solid_line, 2);
  70. draw_dash (cr, invisible_line, 2);
  71. cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
  72. draw_dash (cr, dotted_line, 2);
  73. cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
  74. draw_dash (cr, zero_1_of_3, 3);
  75. draw_dash (cr, zero_2_of_3, 3);
  76. draw_dash (cr, zero_3_of_3, 3);
  77. draw_dash (cr, zero_1_of_4, 4);
  78. draw_dash (cr, zero_2_of_4, 4);
  79. draw_dash (cr, zero_3_of_4, 4);
  80. draw_dash (cr, zero_4_of_4, 4);
  81. draw_dash (cr, zero_1_2_of_4, 4);
  82. draw_dash (cr, zero_1_3_of_4, 4);
  83. #if BUG_FIXED_IN_GHOSTSCRIPT
  84. draw_dash (cr, zero_1_4_of_4, 4);
  85. #endif
  86. draw_dash (cr, zero_2_3_of_4, 4);
  87. draw_dash (cr, zero_2_4_of_4, 4);
  88. draw_dash (cr, zero_3_4_of_4, 4);
  89. draw_dash (cr, zero_1_2_3_of_4, 4);
  90. draw_dash (cr, zero_1_2_4_of_4, 4);
  91. draw_dash (cr, zero_1_3_4_of_4, 4);
  92. draw_dash (cr, zero_2_3_4_of_4, 4);
  93. return CAIRO_TEST_SUCCESS;
  94. }
  95. CAIRO_TEST (dash_zero_length,
  96. "Tests cairo_set_dash with zero length",
  97. "dash, stroke", /* keywords */
  98. NULL, /* requirements */
  99. IMAGE_WIDTH, IMAGE_HEIGHT,
  100. NULL, draw)