world-map.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright © 2006 Red Hat, Inc.
  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: Carl D. Worth <cworth@cworth.org>
  25. */
  26. #include "cairo-test.h"
  27. #ifdef HAVE_UNISTD_H
  28. #include <unistd.h>
  29. #endif
  30. #define WIDTH 800
  31. #define HEIGHT 400
  32. typedef enum {
  33. WM_NEW_PATH,
  34. WM_MOVE_TO,
  35. WM_LINE_TO,
  36. WM_HLINE_TO,
  37. WM_VLINE_TO,
  38. WM_REL_LINE_TO,
  39. WM_END
  40. } wm_type_t;
  41. typedef struct _wm_element {
  42. wm_type_t type;
  43. double x;
  44. double y;
  45. } wm_element_t;
  46. #include "world-map.h"
  47. enum {
  48. STROKE = 1,
  49. FILL = 2,
  50. };
  51. static cairo_test_status_t
  52. draw_world_map (cairo_t *cr, int width, int height, int mode)
  53. {
  54. const wm_element_t *e;
  55. double cx, cy;
  56. cairo_set_line_width (cr, 0.2);
  57. cairo_set_source_rgb (cr, .68, .85, .90); /* lightblue */
  58. cairo_rectangle (cr, 0, 0, 800, 400);
  59. cairo_fill (cr);
  60. e = &countries[0];
  61. while (1) {
  62. switch (e->type) {
  63. case WM_NEW_PATH:
  64. case WM_END:
  65. if (mode & FILL) {
  66. cairo_set_source_rgb (cr, .75, .75, .75); /* silver */
  67. cairo_fill_preserve (cr);
  68. }
  69. if (mode & STROKE) {
  70. cairo_set_source_rgb (cr, .50, .50, .50); /* gray */
  71. cairo_stroke (cr);
  72. }
  73. cairo_new_path (cr);
  74. cairo_move_to (cr, e->x, e->y);
  75. break;
  76. case WM_MOVE_TO:
  77. cairo_close_path (cr);
  78. cairo_move_to (cr, e->x, e->y);
  79. break;
  80. case WM_LINE_TO:
  81. cairo_line_to (cr, e->x, e->y);
  82. break;
  83. case WM_HLINE_TO:
  84. cairo_get_current_point (cr, &cx, &cy);
  85. cairo_line_to (cr, e->x, cy);
  86. break;
  87. case WM_VLINE_TO:
  88. cairo_get_current_point (cr, &cx, &cy);
  89. cairo_line_to (cr, cx, e->y);
  90. break;
  91. case WM_REL_LINE_TO:
  92. cairo_rel_line_to (cr, e->x, e->y);
  93. break;
  94. }
  95. if (e->type == WM_END)
  96. break;
  97. e++;
  98. }
  99. cairo_new_path (cr);
  100. return CAIRO_TEST_SUCCESS;
  101. }
  102. static cairo_test_status_t
  103. draw_world_map_stroke (cairo_t *cr, int width, int height)
  104. {
  105. return draw_world_map (cr, width, height, STROKE);
  106. }
  107. static cairo_test_status_t
  108. draw_world_map_fill (cairo_t *cr, int width, int height)
  109. {
  110. return draw_world_map (cr, width, height, FILL);
  111. }
  112. static cairo_test_status_t
  113. draw_world_map_both (cairo_t *cr, int width, int height)
  114. {
  115. return draw_world_map (cr, width, height, FILL | STROKE);
  116. }
  117. CAIRO_TEST (world_map,
  118. "Tests a complex drawing (part of the performance suite)",
  119. "fill, stroke", /* keywords */
  120. NULL, /* requirements */
  121. WIDTH, HEIGHT,
  122. NULL, draw_world_map_both)
  123. CAIRO_TEST (world_map_stroke,
  124. "Tests a complex drawing (part of the performance suite)",
  125. "stroke", /* keywords */
  126. NULL, /* requirements */
  127. WIDTH, HEIGHT,
  128. NULL, draw_world_map_stroke)
  129. CAIRO_TEST (world_map_fill,
  130. "Tests a complex drawing (part of the performance suite)",
  131. "fill", /* keywords */
  132. NULL, /* requirements */
  133. WIDTH, HEIGHT,
  134. NULL, draw_world_map_fill)