| 1 |
#ifndef _GraphicsP_h_ |
| 2 |
#define _GraphicsP_h_ |
| 3 |
/* GraphicsP.h |
| 4 |
* |
| 5 |
* Copyright (C) 1992-2020,2022,2023 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 |
|
| 21 |
#include "Graphics.h" |
| 22 |
#include "Gui.h" |
| 23 |
|
| 24 |
#if defined (_WIN32) |
| 25 |
#include <windowsx.h> |
| 26 |
#include <gdiplus.h> |
| 27 |
#endif |
| 28 |
|
| 29 |
void Graphics_init (Graphics me, int resolution); |
| 30 |
/* |
| 31 |
Postconditions: |
| 32 |
my font == Graphics_FONT_HELVETICA; |
| 33 |
my fontSize == 9; |
| 34 |
my fontStyle == Graphics_NORMAL; |
| 35 |
*/ |
| 36 |
|
| 37 |
#define kGraphics_font_SYMBOL ((int) kGraphics_font::MAX + 1) |
| 38 |
#define kGraphics_font_IPATIMES ((int) kGraphics_font::MAX + 2) |
| 39 |
#define kGraphics_font_IPAPALATINO ((int) kGraphics_font::MAX + 3) |
| 40 |
#define kGraphics_font_CHEROKEE ((int) kGraphics_font::MAX + 4) |
| 41 |
#define kGraphics_font_DINGBATS ((int) kGraphics_font::MAX + 5) |
| 42 |
#define kGraphics_font_CHINESE ((int) kGraphics_font::MAX + 6) |
| 43 |
#define kGraphics_font_JAPANESE ((int) kGraphics_font::MAX + 7) |
| 44 |
|
| 45 |
/* |
| 46 |
Honour the NO_GRAPHICS compiler switch. |
| 47 |
*/ |
| 48 |
#if defined (NO_GRAPHICS) |
| 49 |
#define cairo 0 |
| 50 |
#define gdi 0 |
| 51 |
#define direct2d 0 |
| 52 |
#define quartz 0 |
| 53 |
#elif defined (UNIX) /* include graphics even if there is no GUI, in order to be able to save PNG files */ |
| 54 |
#define cairo 1 /* Cairo, including Pango */ |
| 55 |
#define gdi 0 |
| 56 |
#define direct2d 0 |
| 57 |
#define quartz 0 |
| 58 |
#elif motif |
| 59 |
#define cairo 0 |
| 60 |
#define gdi 1 /* to be discontinued when we no longer have to support Windows XP */ |
| 61 |
#define direct2d 0 /* for the future: Direct2D, including DirectWrite */ |
| 62 |
#define quartz 0 |
| 63 |
#elif cocoa |
| 64 |
#define cairo 0 |
| 65 |
#define gdi 0 |
| 66 |
#define direct2d 0 |
| 67 |
#define quartz 1 /* Quartz, including CoreText */ |
| 68 |
#else |
| 69 |
/* |
| 70 |
Unknown platforms have no graphics. |
| 71 |
*/ |
| 72 |
#define cairo 0 |
| 73 |
#define gdi 0 |
| 74 |
#define direct2d 0 |
| 75 |
#define quartz 0 |
| 76 |
#endif |
| 77 |
|
| 78 |
Thing_define (GraphicsScreen, Graphics) { |
| 79 |
bool d_isPng; |
| 80 |
structMelderFile d_file; |
| 81 |
#if defined (NO_GRAPHICS) |
| 82 |
#elif cairo |
| 83 |
#if gtk |
| 84 |
GdkDisplay *d_display; |
| 85 |
GdkWindow *d_window; |
| 86 |
#endif |
| 87 |
cairo_surface_t *d_cairoSurface; |
| 88 |
cairo_t *d_cairoGraphicsContext; |
| 89 |
#elif gdi |
| 90 |
HWND d_winWindow; |
| 91 |
HDC d_gdiGraphicsContext; |
| 92 |
COLORREF d_winForegroundColour; |
| 93 |
HPEN d_winPen; |
| 94 |
HBRUSH d_winBrush; |
| 95 |
HDC d_savedDC; |
| 96 |
bool d_useGdiplus; |
| 97 |
HBITMAP d_gdiBitmap; |
| 98 |
Gdiplus::Bitmap *d_gdiplusBitmap; |
| 99 |
#elif quartz |
| 100 |
NSView *d_macView; |
| 101 |
int d_macFont, d_macStyle; |
| 102 |
int d_depth; |
| 103 |
uint8 *d_bits; |
| 104 |
CGContextRef d_macGraphicsContext; |
| 105 |
#endif |
| 106 |
|
| 107 |
void v9_destroy () noexcept |
| 108 |
override; |
| 109 |
void v_polyline (integer numberOfPoints, double *xyDC, bool close) |
| 110 |
override; |
| 111 |
void v_fillArea (integer numberOfPoints, double *xyDC) |
| 112 |
override; |
| 113 |
void v_rectangle (double x1DC, double x2DC, double y1DC, double y2DC) |
| 114 |
override; |
| 115 |
void v_fillRectangle (double x1DC, double x2DC, double y1DC, double y2DC) |
| 116 |
override; |
| 117 |
void v_circle (double xDC, double yDC, double rDC) |
| 118 |
override; |
| 119 |
void v_ellipse (double x1DC, double x2DC, double y1DC, double y2DC) |
| 120 |
override; |
| 121 |
void v_arc (double xDC, double yDC, double rDC, double fromAngle, double toAngle) |
| 122 |
override; |
| 123 |
void v_fillCircle (double xDC, double yDC, double rDC) |
| 124 |
override; |
| 125 |
void v_fillEllipse (double x1DC, double x2DC, double y1DC, double y2DC) |
| 126 |
override; |
| 127 |
void v_button (double x1DC, double x2DC, double y1DC, double y2DC) |
| 128 |
override; |
| 129 |
void v_roundedRectangle (double x1DC, double x2DC, double y1DC, double y2DC, double r) |
| 130 |
override; |
| 131 |
void v_arrowHead (double xDC, double yDC, double angle) |
| 132 |
override; |
| 133 |
void v_clearWs () |
| 134 |
override; |
| 135 |
void v_updateWs () |
| 136 |
override; |
| 137 |
}; |
| 138 |
|
| 139 |
Thing_define (GraphicsPostscript, Graphics) { |
| 140 |
FILE *d_file; |
| 141 |
int (*d_printf) (void *stream, const char *format, ...); |
| 142 |
int languageLevel; |
| 143 |
int photocopyable, spotsDensity, spotsAngle; |
| 144 |
bool loadedXipa, useSilipaPS, landscape, includeFonts; |
| 145 |
double magnification; |
| 146 |
char *fontInfos [1 + kGraphics_font_DINGBATS] [1 + Graphics_BOLD_ITALIC]; |
| 147 |
const char *lastFid; |
| 148 |
int pageNumber, lastSize; |
| 149 |
bool job, eps; |
| 150 |
|
| 151 |
void v9_destroy () noexcept |
| 152 |
override; |
| 153 |
void v_polyline (integer numberOfPoints, double *xyDC, bool close) |
| 154 |
override; |
| 155 |
void v_fillArea (integer numberOfPoints, double *xyDC) |
| 156 |
override; |
| 157 |
void v_rectangle (double x1DC, double x2DC, double y1DC, double y2DC) |
| 158 |
override; |
| 159 |
void v_fillRectangle (double x1DC, double x2DC, double y1DC, double y2DC) |
| 160 |
override; |
| 161 |
void v_circle (double xDC, double yDC, double rDC) |
| 162 |
override; |
| 163 |
void v_ellipse (double x1DC, double x2DC, double y1DC, double y2DC) |
| 164 |
override; |
| 165 |
void v_arc (double xDC, double yDC, double rDC, double fromAngle, double toAngle) |
| 166 |
override; |
| 167 |
void v_fillCircle (double xDC, double yDC, double rDC) |
| 168 |
override; |
| 169 |
void v_fillEllipse (double x1DC, double x2DC, double y1DC, double y2DC) |
| 170 |
override; |
| 171 |
void v_arrowHead (double xDC, double yDC, double angle) |
| 172 |
override; |
| 173 |
}; |
| 174 |
|
| 175 |
/* Opcodes for recording. */ |
| 176 |
|
| 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) { const 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 |
|
| 183 |
/* When adding opcodes in the following list, add them at the end. */ |
| 184 |
/* Otherwise, old picture files will become incompatible with the current Graphics. */ |
| 185 |
enum opcode { SET_VIEWPORT = 101, SET_INNER, UNSET_INNER, SET_WINDOW, |
| 186 |
/* 105 */ TEXT, POLYLINE, LINE, ARROW, FILL_AREA, FUNCTION, RECTANGLE, FILL_RECTANGLE, |
| 187 |
/* 113 */ CIRCLE, FILL_CIRCLE, ARC, ARC_ARROW, HIGHLIGHT, CELL_ARRAY, |
| 188 |
/* 119 */ SET_FONT, SET_FONT_SIZE, SET_FONT_STYLE, |
| 189 |
/* 122 */ SET_TEXT_ALIGNMENT, SET_TEXT_ROTATION, |
| 190 |
/* 124 */ SET_LINE_TYPE, SET_LINE_WIDTH, |
| 191 |
/* 126 */ SET_STANDARD_COLOUR, SET_GREY, |
| 192 |
/* 128 */ MARK_GROUP, ELLIPSE, FILL_ELLIPSE, CIRCLE_MM, FILL_CIRCLE_MM, IMAGE8, |
| 193 |
/* 134 */ UNHIGHLIGHT, XOR_ON, XOR_OFF, RECTANGLE_MM, FILL_RECTANGLE_MM, |
| 194 |
/* 139 */ SET_WS_WINDOW, SET_WRAP_WIDTH, SET_SECOND_INDENT, |
| 195 |
/* 142 */ SET_PERCENT_SIGN_IS_ITALIC, SET_NUMBER_SIGN_IS_BOLD, |
| 196 |
/* 144 */ SET_CIRCUMFLEX_IS_SUPERSCRIPT, SET_UNDERSCORE_IS_SUBSCRIPT, |
| 197 |
/* 146 */ SET_DOLLAR_SIGN_IS_CODE, SET_AT_SIGN_IS_LINK, |
| 198 |
/* 148 */ BUTTON, ROUNDED_RECTANGLE, FILL_ROUNDED_RECTANGLE, FILL_ARC, |
| 199 |
/* 152 */ INNER_RECTANGLE, CELL_ARRAY8, IMAGE, HIGHLIGHT2, UNHIGHLIGHT2, |
| 200 |
/* 157 */ SET_ARROW_SIZE, DOUBLE_ARROW, SET_RGB_COLOUR, IMAGE_FROM_FILE, |
| 201 |
/* 161 */ POLYLINE_CLOSED, CELL_ARRAY_COLOUR, IMAGE_COLOUR, SET_COLOUR_SCALE, |
| 202 |
/* 165 */ SET_SPECKLE_SIZE, SPECKLE, CLEAR_WS, SET_BACKQUOTE_IS_VERBATIM, |
| 203 |
/* 169 */ RECTANGLE_TEXT_WRAP_AND_TRUNCATE, RECTANGLE_TEXT_MAXIMAL_FIT |
| 204 |
}; |
| 205 |
|
| 206 |
void _GraphicsScreen_text_init (GraphicsScreen me); |
| 207 |
void _Graphics_fillRectangle (Graphics me, integer x1DC, integer x2DC, integer y1DC, integer y2DC); |
| 208 |
void _Graphics_setColour (Graphics me, MelderColour colour); |
| 209 |
void _Graphics_setGrey (Graphics me, double grey); |
| 210 |
void _Graphics_colour_init (Graphics me); |
| 211 |
bool _GraphicsMac_tryToInitializeFonts (); |
| 212 |
bool _GraphicsLin_tryToInitializeFonts (); |
| 213 |
|
| 214 |
extern enum kGraphics_cjkFontStyle theGraphicsCjkFontStyle; |
| 215 |
|
| 216 |
/* End of file GraphicsP.h */ |
| 217 |
#endif |