mi_api.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* This file is part of the GNU libxmi package. Copyright (C) 1998, 1999,
  2. 2000, 2005, Free Software Foundation, Inc.
  3. The GNU libxmi package is free software. You may redistribute it
  4. and/or modify it under the terms of the GNU General Public License as
  5. published by the Free Software foundation; either version 2, or (at your
  6. option) any later version.
  7. The GNU libxmi package is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with the GNU plotutils package; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  14. Boston, MA 02110-1301, USA. */
  15. /* This file defines the core libxmi API, consisting of:
  16. 1. miDrawPoints, miDrawLines, miFillPolygon.
  17. 2. miDrawRectangles, miFillRectangles.
  18. 3. miDrawArcs, miFillArcs. Also the reentrant miDrawArcs_r.
  19. Each of these is a wrapper around an internal function that takes as first
  20. argument a (miPaintedSet *). A miPaintedSet struct is a structure that is
  21. used by Joel McCormack's span-merging module to implement the
  22. `touch-each-pixel-once' rule. See mi_spans.c and mi_spans.h. */
  23. #include "sys-defines.h"
  24. #include "extern.h"
  25. #include "xmi.h"
  26. #include "mi_spans.h"
  27. #include "mi_gc.h"
  28. #include "mi_api.h"
  29. #define MI_SETUP_PAINTED_SET(paintedSet, pGC) \
  30. {\
  31. }
  32. #define MI_TEAR_DOWN_PAINTED_SET(paintedSet) \
  33. {\
  34. miUniquifyPaintedSet (paintedSet); \
  35. }
  36. /* ARGS: mode = Origin or Previous */
  37. void
  38. miDrawPoints (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npt, const miPoint *pPts)
  39. {
  40. MI_SETUP_PAINTED_SET(paintedSet, pGC)
  41. miDrawPoints_internal (paintedSet, pGC, mode, npt, pPts);
  42. MI_TEAR_DOWN_PAINTED_SET(paintedSet)
  43. }
  44. /* ARGS: mode = Origin or Previous */
  45. void
  46. miDrawLines (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npt, const miPoint *pPts)
  47. {
  48. MI_SETUP_PAINTED_SET(paintedSet, pGC)
  49. miDrawLines_internal (paintedSet, pGC, mode, npt, pPts);
  50. MI_TEAR_DOWN_PAINTED_SET(paintedSet)
  51. }
  52. /* ARGS: mode = Origin or Previous */
  53. void
  54. miFillPolygon (miPaintedSet *paintedSet, const miGC *pGC, miPolygonShape shape, miCoordMode mode, int count, const miPoint *pPts)
  55. {
  56. MI_SETUP_PAINTED_SET(paintedSet, pGC)
  57. miFillPolygon_internal (paintedSet, pGC, shape, mode, count, pPts);
  58. MI_TEAR_DOWN_PAINTED_SET(paintedSet)
  59. }
  60. void
  61. miDrawRectangles (miPaintedSet *paintedSet, const miGC *pGC, int nrects, const miRectangle *prectInit)
  62. {
  63. MI_SETUP_PAINTED_SET(paintedSet, pGC);
  64. miDrawRectangles_internal (paintedSet, pGC, nrects, prectInit);
  65. MI_TEAR_DOWN_PAINTED_SET(paintedSet)
  66. }
  67. void
  68. miFillRectangles (miPaintedSet *paintedSet, const miGC *pGC, int nrectFill, const miRectangle *prectInit)
  69. {
  70. fprintf (stderr, "miFillRectangles()\n");
  71. MI_SETUP_PAINTED_SET(paintedSet, pGC);
  72. miFillRectangles_internal (paintedSet, pGC, nrectFill, prectInit);
  73. MI_TEAR_DOWN_PAINTED_SET(paintedSet)
  74. }
  75. #ifndef NO_NONREENTRANT_POLYARC_SUPPORT
  76. void
  77. miDrawArcs (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs)
  78. {
  79. MI_SETUP_PAINTED_SET(paintedSet, pGC)
  80. miDrawArcs_internal (paintedSet, pGC, narcs, parcs);
  81. MI_TEAR_DOWN_PAINTED_SET(paintedSet)
  82. }
  83. #endif /* not NO_NONREENTRANT_POLYARC_SUPPORT */
  84. void
  85. miFillArcs (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs)
  86. {
  87. MI_SETUP_PAINTED_SET(paintedSet, pGC)
  88. miFillArcs_internal (paintedSet, pGC, narcs, parcs);
  89. MI_TEAR_DOWN_PAINTED_SET(paintedSet)
  90. }
  91. /* ARGS: ellipseCache = pointer to ellipse data cache */
  92. void
  93. miDrawArcs_r (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs, miEllipseCache *ellipseCache)
  94. {
  95. MI_SETUP_PAINTED_SET(paintedSet, pGC)
  96. miDrawArcs_r_internal (paintedSet, pGC, narcs, parcs, ellipseCache);
  97. MI_TEAR_DOWN_PAINTED_SET(paintedSet)
  98. }
  99. /**********************************************************************/
  100. /* Further wrappers that should really be moved to other file(s). */
  101. /**********************************************************************/
  102. /* ARGS: ellipseCache = pointer to ellipse data cache */
  103. void
  104. miDrawArcs_r_internal (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs, miEllipseCache *ellipseCache)
  105. {
  106. if (pGC->lineWidth == 0)
  107. /* use Bresenham algorithm */
  108. miZeroPolyArc_r (paintedSet, pGC, narcs, parcs, ellipseCache);
  109. else
  110. miPolyArc_r (paintedSet, pGC, narcs, parcs, ellipseCache);
  111. }
  112. #ifndef NO_NONREENTRANT_POLYARC_SUPPORT
  113. void
  114. miDrawArcs_internal (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs)
  115. {
  116. if (pGC->lineWidth == 0)
  117. /* use Bresenham algorithm */
  118. miZeroPolyArc (paintedSet, pGC, narcs, parcs);
  119. else
  120. miPolyArc (paintedSet, pGC, narcs, parcs);
  121. }
  122. #endif /* not NO_NONREENTRANT_POLYARC_SUPPORT */
  123. /* ARGS: mode = Origin or Previous */
  124. void
  125. miDrawLines_internal (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npt, const miPoint *pPts)
  126. {
  127. if (pGC->lineWidth == 0)
  128. {
  129. /* use Bresenham algorithm */
  130. if (pGC->lineStyle == (int)MI_LINE_SOLID)
  131. miZeroLine (paintedSet, pGC, mode, npt, pPts);
  132. else
  133. miZeroDash (paintedSet, pGC, mode, npt, pPts);
  134. }
  135. else
  136. {
  137. if (pGC->lineStyle == (int)MI_LINE_SOLID)
  138. miWideLine (paintedSet, pGC, mode, npt, pPts);
  139. else
  140. miWideDash (paintedSet, pGC, mode, npt, pPts);
  141. }
  142. }
  143. void
  144. miDrawRectangles_internal (miPaintedSet *paintedSet, const miGC *pGC, int nrects, const miRectangle *prectInit)
  145. {
  146. const miRectangle *pR = prectInit;
  147. miPoint rect[5];
  148. int i;
  149. fprintf (stderr, "miDrawRectangles_internal()\n");
  150. for (i = 0; i < nrects; i++)
  151. {
  152. rect[0].x = pR->x;
  153. rect[0].y = pR->y;
  154. rect[1].x = pR->x + (int) pR->width;
  155. rect[1].y = rect[0].y;
  156. rect[2].x = rect[1].x;
  157. rect[2].y = pR->y + (int) pR->height;
  158. rect[3].x = rect[0].x;
  159. rect[3].y = rect[2].y;
  160. /* close the polyline */
  161. rect[4].x = rect[0].x;
  162. rect[4].y = rect[0].y;
  163. miDrawLines_internal (paintedSet, pGC, MI_COORD_MODE_ORIGIN, 5, rect);
  164. pR++;
  165. }
  166. }