GraphicsP.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #ifndef _GraphicsP_h_
  2. #define _GraphicsP_h_
  3. /* GraphicsP.h
  4. *
  5. * Copyright (C) 1992-2018 Paul Boersma, 2013 Tom Naughton
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "Graphics.h"
  21. #include "Gui.h"
  22. #if defined (_WIN32)
  23. #include <windowsx.h>
  24. #include <gdiplus.h>
  25. #endif
  26. void Graphics_init (Graphics me, int resolution);
  27. /*
  28. Postconditions:
  29. my font == Graphics_FONT_HELVETICA;
  30. my fontSize == 9;
  31. my fontStyle == Graphics_NORMAL;
  32. */
  33. #define kGraphics_font_SYMBOL ((int) kGraphics_font::MAX + 1)
  34. #define kGraphics_font_IPATIMES ((int) kGraphics_font::MAX + 2)
  35. #define kGraphics_font_IPAPALATINO ((int) kGraphics_font::MAX + 3)
  36. #define kGraphics_font_DINGBATS ((int) kGraphics_font::MAX + 4)
  37. #define kGraphics_font_CHINESE ((int) kGraphics_font::MAX + 5)
  38. #define kGraphics_font_JAPANESE ((int) kGraphics_font::MAX + 6)
  39. /*
  40. Honour the NO_GRAPHICS compiler switch.
  41. */
  42. #if defined (NO_GRAPHICS)
  43. #define cairo 0
  44. #define gdi 0
  45. #define direct2d 0
  46. #define quartz 0
  47. #elif defined (UNIX) /* include graphics even if there is no GUI, in order to be able to save PNG files */
  48. #define cairo 1 /* Cairo, including Pango */
  49. #define gdi 0
  50. #define direct2d 0
  51. #define quartz 0
  52. #elif motif
  53. #define cairo 0
  54. #define gdi 1 /* to be discontinued when we no longer have to support Windows XP */
  55. #define direct2d 0 /* for the future: Direct2D, including DirectWrite */
  56. #define quartz 0
  57. #elif cocoa
  58. #define cairo 0
  59. #define gdi 0
  60. #define direct2d 0
  61. #define quartz 1 /* Quartz, including CoreText */
  62. #else
  63. /*
  64. Unknown platforms have no graphics.
  65. */
  66. #define cairo 0
  67. #define gdi 0
  68. #define direct2d 0
  69. #define quartz 0
  70. #endif
  71. Thing_define (GraphicsScreen, Graphics) {
  72. bool d_isPng;
  73. structMelderFile d_file;
  74. #if defined (NO_GRAPHICS)
  75. #elif cairo
  76. #if gtk
  77. GdkDisplay *d_display;
  78. #if ALLOW_GDK_DRAWING
  79. GdkDrawable *d_window;
  80. GdkGC *d_gdkGraphicsContext;
  81. #else
  82. GdkWindow *d_window;
  83. #endif
  84. #endif
  85. cairo_surface_t *d_cairoSurface;
  86. cairo_t *d_cairoGraphicsContext;
  87. #elif gdi
  88. HWND d_winWindow;
  89. HDC d_gdiGraphicsContext;
  90. COLORREF d_winForegroundColour;
  91. HPEN d_winPen;
  92. HBRUSH d_winBrush;
  93. bool d_fatNonSolid;
  94. bool d_useGdiplus;
  95. HBITMAP d_gdiBitmap;
  96. Gdiplus::Bitmap *d_gdiplusBitmap;
  97. #elif quartz
  98. NSView *d_macView;
  99. int d_macFont, d_macStyle;
  100. int d_depth;
  101. RGBColor d_macColour;
  102. uint8 *d_bits;
  103. CGContextRef d_macGraphicsContext;
  104. #endif
  105. void v_destroy () noexcept
  106. override;
  107. void v_polyline (integer numberOfPoints, double *xyDC, bool close)
  108. override;
  109. void v_fillArea (integer numberOfPoints, double *xyDC)
  110. override;
  111. void v_rectangle (double x1DC, double x2DC, double y1DC, double y2DC)
  112. override;
  113. void v_fillRectangle (double x1DC, double x2DC, double y1DC, double y2DC)
  114. override;
  115. void v_circle (double xDC, double yDC, double rDC)
  116. override;
  117. void v_ellipse (double x1DC, double x2DC, double y1DC, double y2DC)
  118. override;
  119. void v_arc (double xDC, double yDC, double rDC, double fromAngle, double toAngle)
  120. override;
  121. void v_fillCircle (double xDC, double yDC, double rDC)
  122. override;
  123. void v_fillEllipse (double x1DC, double x2DC, double y1DC, double y2DC)
  124. override;
  125. void v_button (double x1DC, double x2DC, double y1DC, double y2DC)
  126. override;
  127. void v_roundedRectangle (double x1DC, double x2DC, double y1DC, double y2DC, double r)
  128. override;
  129. void v_arrowHead (double xDC, double yDC, double angle)
  130. override;
  131. bool v_mouseStillDown ()
  132. override;
  133. void v_getMouseLocation (double *xWC, double *yWC)
  134. override;
  135. void v_flushWs ()
  136. override;
  137. void v_clearWs ()
  138. override;
  139. void v_updateWs ()
  140. override;
  141. };
  142. Thing_define (GraphicsPostscript, Graphics) {
  143. FILE *d_file;
  144. int (*d_printf) (void *stream, const char *format, ...);
  145. int languageLevel;
  146. int photocopyable, spotsDensity, spotsAngle;
  147. bool loadedXipa, useSilipaPS, landscape, includeFonts;
  148. double magnification;
  149. char *fontInfos [1 + kGraphics_font_DINGBATS] [1 + Graphics_BOLD_ITALIC];
  150. const char *lastFid;
  151. int pageNumber, lastSize;
  152. bool job, eps;
  153. void v_destroy () noexcept
  154. override;
  155. void v_polyline (integer numberOfPoints, double *xyDC, bool close)
  156. override;
  157. void v_fillArea (integer numberOfPoints, double *xyDC)
  158. override;
  159. void v_rectangle (double x1DC, double x2DC, double y1DC, double y2DC)
  160. override;
  161. void v_fillRectangle (double x1DC, double x2DC, double y1DC, double y2DC)
  162. override;
  163. void v_circle (double xDC, double yDC, double rDC)
  164. override;
  165. void v_ellipse (double x1DC, double x2DC, double y1DC, double y2DC)
  166. override;
  167. void v_arc (double xDC, double yDC, double rDC, double fromAngle, double toAngle)
  168. override;
  169. void v_fillCircle (double xDC, double yDC, double rDC)
  170. override;
  171. void v_fillEllipse (double x1DC, double x2DC, double y1DC, double y2DC)
  172. override;
  173. void v_arrowHead (double xDC, double yDC, double angle)
  174. override;
  175. };
  176. /* Opcodes for recording. */
  177. double * _Graphics_check (Graphics me, integer number);
  178. #define put(f) * ++ p = (double) (f)
  179. #define op(opcode,number) double *p = _Graphics_check (me, number); if (! p) return; put (opcode); put (number)
  180. #define mput(n,a) { double *f = a; for (integer l = 0; l < n; l ++) put (f [l]); }
  181. #define sput(s,l) { put (l); strcpy ((char *) (p + 1), s); p += l; }
  182. /* When adding opcodes in the following list, add them at the end. */
  183. /* Otherwise, old picture files will become incompatible with the current Graphics. */
  184. enum opcode { SET_VIEWPORT = 101, SET_INNER, UNSET_INNER, SET_WINDOW,
  185. /* 105 */ TEXT, POLYLINE, LINE, ARROW, FILL_AREA, FUNCTION, RECTANGLE, FILL_RECTANGLE,
  186. /* 113 */ CIRCLE, FILL_CIRCLE, ARC, ARC_ARROW, HIGHLIGHT, CELL_ARRAY,
  187. /* 119 */ SET_FONT, SET_FONT_SIZE, SET_FONT_STYLE,
  188. /* 122 */ SET_TEXT_ALIGNMENT, SET_TEXT_ROTATION,
  189. /* 124 */ SET_LINE_TYPE, SET_LINE_WIDTH,
  190. /* 126 */ SET_STANDARD_COLOUR, SET_GREY,
  191. /* 128 */ MARK_GROUP, ELLIPSE, FILL_ELLIPSE, CIRCLE_MM, FILL_CIRCLE_MM, IMAGE8,
  192. /* 134 */ UNHIGHLIGHT, XOR_ON, XOR_OFF, RECTANGLE_MM, FILL_RECTANGLE_MM,
  193. /* 139 */ SET_WS_WINDOW, SET_WRAP_WIDTH, SET_SECOND_INDENT,
  194. /* 142 */ SET_PERCENT_SIGN_IS_ITALIC, SET_NUMBER_SIGN_IS_BOLD,
  195. /* 144 */ SET_CIRCUMFLEX_IS_SUPERSCRIPT, SET_UNDERSCORE_IS_SUBSCRIPT,
  196. /* 146 */ SET_DOLLAR_SIGN_IS_CODE, SET_AT_SIGN_IS_LINK,
  197. /* 148 */ BUTTON, ROUNDED_RECTANGLE, FILL_ROUNDED_RECTANGLE, FILL_ARC,
  198. /* 152 */ INNER_RECTANGLE, CELL_ARRAY8, IMAGE, HIGHLIGHT2, UNHIGHLIGHT2,
  199. /* 157 */ SET_ARROW_SIZE, DOUBLE_ARROW, SET_RGB_COLOUR, IMAGE_FROM_FILE,
  200. /* 161 */ POLYLINE_CLOSED, CELL_ARRAY_COLOUR, IMAGE_COLOUR, SET_COLOUR_SCALE,
  201. /* 165 */ SET_SPECKLE_SIZE, SPECKLE
  202. };
  203. void _GraphicsScreen_text_init (GraphicsScreen me);
  204. void _Graphics_fillRectangle (Graphics me, integer x1DC, integer x2DC, integer y1DC, integer y2DC);
  205. void _Graphics_setColour (Graphics me, Graphics_Colour colour);
  206. void _Graphics_setGrey (Graphics me, double grey);
  207. void _Graphics_colour_init (Graphics me);
  208. bool _GraphicsMac_tryToInitializeFonts ();
  209. bool _GraphicsLin_tryToInitializeFonts ();
  210. #if quartz
  211. void GraphicsQuartz_initDraw (GraphicsScreen me);
  212. void GraphicsQuartz_exitDraw (GraphicsScreen me);
  213. #endif
  214. extern enum kGraphics_cjkFontStyle theGraphicsCjkFontStyle;
  215. /* End of file GraphicsP.h */
  216. #endif