surface-pattern-scale-down-extend.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright © 2010 M Joonas Pihlaja
  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: M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
  25. */
  26. #include "cairo-test.h"
  27. /* Test that we can simultaneously downscale and extend a surface
  28. * pattern. Reported by Franz Schmid to the cairo mailing list as a
  29. * regression in 1.9.6:
  30. *
  31. * http://lists.cairographics.org/archives/cairo/2010-February/019492.html
  32. */
  33. static cairo_test_status_t
  34. draw_with_extend (cairo_t *cr, int w, int h, cairo_extend_t extend)
  35. {
  36. cairo_pattern_t *pattern;
  37. cairo_set_source_rgb (cr, 1,1,1);
  38. cairo_paint (cr);
  39. cairo_save (cr);
  40. /* When the destination surface is created by cairo-test-suite to
  41. * test device-offset, it is bigger than w x h. This test expects
  42. * the group to have a size which is exactly w x h, so it must
  43. * clip to the this rectangle to guarantee that the group will
  44. * have the correct size.
  45. */
  46. cairo_rectangle (cr, 0, 0, w, h);
  47. cairo_clip (cr);
  48. cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR); {
  49. /* A two by two checkerboard with black, red and yellow
  50. * cells. */
  51. cairo_set_source_rgb (cr, 1,0,0);
  52. cairo_rectangle (cr, w/2, 0, w-w/2, h/2);
  53. cairo_fill (cr);
  54. cairo_set_source_rgb (cr, 1,1,0);
  55. cairo_rectangle (cr, 0, h/2, w/2, h-h/2);
  56. cairo_fill (cr);
  57. }
  58. pattern = cairo_pop_group (cr);
  59. cairo_pattern_set_extend(pattern, extend);
  60. cairo_restore (cr);
  61. cairo_scale (cr, 0.5, 0.5);
  62. cairo_set_source (cr, pattern);
  63. cairo_paint (cr);
  64. cairo_pattern_destroy (pattern);
  65. return CAIRO_TEST_SUCCESS;
  66. }
  67. static cairo_test_status_t
  68. draw_repeat (cairo_t *cr, int w, int h)
  69. {
  70. return draw_with_extend (cr, w, h, CAIRO_EXTEND_REPEAT);
  71. }
  72. static cairo_test_status_t
  73. draw_none (cairo_t *cr, int w, int h)
  74. {
  75. return draw_with_extend (cr, w, h, CAIRO_EXTEND_NONE);
  76. }
  77. static cairo_test_status_t
  78. draw_reflect (cairo_t *cr, int w, int h)
  79. {
  80. return draw_with_extend (cr, w, h, CAIRO_EXTEND_REFLECT);
  81. }
  82. static cairo_test_status_t
  83. draw_pad (cairo_t *cr, int w, int h)
  84. {
  85. return draw_with_extend (cr, w, h, CAIRO_EXTEND_PAD);
  86. }
  87. CAIRO_TEST (surface_pattern_scale_down_extend_repeat,
  88. "Test interaction of downscaling a surface pattern and extend-repeat",
  89. "pattern, transform, extend", /* keywords */
  90. NULL, /* requirements */
  91. 100, 100,
  92. NULL, draw_repeat)
  93. CAIRO_TEST (surface_pattern_scale_down_extend_none,
  94. "Test interaction of downscaling a surface pattern and extend-none",
  95. "pattern, transform, extend", /* keywords */
  96. NULL, /* requirements */
  97. 100, 100,
  98. NULL, draw_none)
  99. CAIRO_TEST (surface_pattern_scale_down_extend_reflect,
  100. "Test interaction of downscaling a surface pattern and extend-reflect",
  101. "pattern, transform, extend", /* keywords */
  102. NULL, /* requirements */
  103. 100, 100,
  104. NULL, draw_reflect)
  105. CAIRO_TEST (surface_pattern_scale_down_extend_pad,
  106. "Test interaction of downscaling a surface pattern and extend-pad",
  107. "pattern, transform, extend", /* keywords */
  108. NULL, /* requirements */
  109. 100, 100,
  110. NULL, draw_pad)