1 #ifndef _Graphics_h_
2 #define _Graphics_h_
3 /* Graphics.h
4 *
5 * Copyright (C) 1992-2005,2007-2020 Paul Boersma
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 "Thing.h"
22 #include "../kar/longchar.h"
23
24 #include "Graphics_enums.h"
25
26 typedef struct { double x1NDC, x2NDC, y1NDC, y2NDC; } Graphics_Viewport;
27
28 Thing_declare (GuiDrawingArea);
29
30 typedef struct {
31 unsigned char link, rightToLeft;
32 short style, size, baseline;
33 double size_real;
34 uint32 code;
35 char32 kar;
36 Longchar_Info karInfo;
37 double width;
38 union { integer integer_; const char *string; void *pointer; } font;
39 int cell, line, run;
40 } _Graphics_widechar;
41
Thing_define(Graphics,Thing)42 Thing_define (Graphics, Thing) {
43 /* Device constants. */
44 bool screen;
45 /* A boolean for whether we are a graphic screen (which may include a non-PostScript printer. */
46 bool postScript;
47 /* A boolean for whether we are a PostScript device. */
48 bool printer;
49 /* A boolean for whether we are a printer. */
50 bool metafile;
51 /* A boolean for whether we are a high-resolution metafile or clipboard. */
52 bool yIsZeroAtTheTop;
53 /* A boolean for whether vertical cooordinates increase from top to bottom (as on most screens, but not PostScript). */
54 GuiDrawingArea d_drawingArea;
55 /* Also used as a boolean. */
56 int resolution;
57 /* Dots per inch. */
58 enum kGraphics_resolution resolutionNumber;
59 integer d_x1DCmin, d_x2DCmax, d_y1DCmin, d_y2DCmax;
60 /* Maximum dimensions of the output device. */
61 /* x1DCmin < x2DCmax; y1DCmin < y2DCmax; */
62 /* The point (x1DCmin, y1DCmin) can be either in the top left */
63 /* or in the bottom left, depending on the yIsZeroAtTheTop flag. */
64 /* Device variables. */
65 integer d_x1DC, d_x2DC, d_y1DC, d_y2DC;
66 /* Current dimensions of the output device, or: */
67 /* device coordinates of the viewport rectangle. */
68 /* x1DCmin <= x1DC < x2DC <= x2DCmax; */
69 /* y1DCmin <= y1DC < y2DC <= y2DCmax; */
70 /* Graphics_create_xxxxxx sets these coordinates to */
71 /* x1DCmin, x2DCmax, y1DCmin, and y2DCmax. */
72 /* They can be changed by Graphics_setWsViewport. */
73 double d_x1wNDC, d_x2wNDC, d_y1wNDC, d_y2wNDC;
74 /* Normalized device coordinates of */
75 /* the device viewport rectangle. */
76 /* The point (x1wNDC, y1wNDC) is always in the bottom left. */
77 /* Graphics_create_xxxxxx sets these coordinates to */
78 /* 0.0, 1.0, 0.0, and 1.0. */
79 /* They can be changed by Graphics_setWsWindow. */
80 double d_x1NDC, d_x2NDC, d_y1NDC, d_y2NDC;
81 /* Normalized device coordinates of the user output viewport, */
82 /* which is a part of the device viewport rectangle. */
83 /* x1wNDC <= x1NDC < x2NDC <= x2wNDC; */
84 /* y1wNDC <= y1NDC < y2NDC <= y2wNDC; */
85 /* Graphics_create_xxxxxx sets these coordinates to */
86 /* 0.0, 1.0, 0.0, and 1.0. */
87 /* They can be changed by Graphics_setViewport. */
88 double d_x1WC, d_x2WC, d_y1WC, d_y2WC;
89 /* World coordinates of the user output viewport rectangle. */
90 /* They bear a relation to the "real" world, */
91 /* and are used in the drawing routines. */
92 /* Graphics_create_xxxxxx sets these coordinates to */
93 /* 0.0, 1.0, 0.0, and 1.0. */
94 /* They can be changed by Graphics_setWindow. */
95 double deltaX, deltaY, scaleX, scaleY;
96 /* Current coordinate transformation. */
97 /* Graphics state. */
98 int lineType;
99 MelderColour colour;
100 double lineWidth, arrowSize, speckleSize;
101 kGraphics_colourScale colourScale;
102 int horizontalTextAlignment, verticalTextAlignment;
103 double textRotation, wrapWidth, secondIndent, textX, textY;
104 kGraphics_font font;
105 double fontSize;
106 int fontStyle;
107 bool percentSignIsItalic, numberSignIsBold, circumflexIsSuperscript, underscoreIsSubscript;
108 bool dollarSignIsCode, atSignIsLink;
109 bool recording, duringXor;
110 integer irecord, nrecord;
111 double *record;
112 Graphics_Viewport outerViewport; // for Graphics_(un)setInner ()
113 double horTick, vertTick; // for Graphics_mark(s)XXX ()
114 double paperWidth, paperHeight;
115
116 void v_destroy () noexcept
117 override;
118
119 virtual void v_polyline (integer /* numberOfPoints */, double * /* xyDC */, bool /* close */) { }
120 virtual void v_fillArea (integer /* numberOfPoints */, double * /* xyDC */) { }
121 virtual void v_rectangle (double /* x1DC */, double /* x2DC */, double /* y1DC */, double /* y2DC */) { }
122 virtual void v_fillRectangle (double /* x1DC */, double /* x2DC */, double /* y1DC */, double /* y2DC */) { }
123 virtual void v_circle (double /* xDC */, double /* yDC */, double /* rDC */) { }
124 virtual void v_ellipse (double /* x1DC */, double /* x2DC */, double /* y1DC */, double /* y2DC */) { }
125 virtual void v_arc (double /* xDC */, double /* yDC */, double /* rDC */, double /* fromAngle */, double /* toAngle */) { }
126 virtual void v_fillCircle (double /* xDC */, double /* yDC */, double /* rDC */) { }
127 virtual void v_fillEllipse (double /* x1DC */, double /* x2DC */, double /* y1DC */, double /* y2DC */) { }
128 virtual void v_button (double a_x1DC, double a_x2DC, double a_y1DC, double a_y2DC)
129 {
130 v_rectangle (a_x1DC, a_x2DC, a_y1DC, a_y2DC); // the simplest implementation
131 }
132 virtual void v_roundedRectangle (double x1DC, double x2DC, double y1DC, double y2DC, double r);
133 virtual void v_fillRoundedRectangle (double x1DC, double x2DC, double y1DC, double y2DC, double r);
134 virtual void v_arrowHead (double xDC, double yDC, double angle);
135 virtual void v_clearWs () { }
136 virtual void v_updateWs () { }
137 };
138
139 autoGraphics Graphics_create (int resolution);
140 autoGraphics Graphics_create_postscriptjob (MelderFile file, int resolution, kGraphicsPostscript_spots spots,
141 kGraphicsPostscript_paperSize paperSize, kGraphicsPostscript_orientation rotation, double magnification);
142 autoGraphics Graphics_create_epsfile (MelderFile file, int resolution, enum kGraphicsPostscript_spots spots,
143 double xmin, double xmax, double ymin, double ymax, bool includeFonts, bool useSilipaPS);
144 autoGraphics Graphics_create_pdffile (MelderFile file, int resolution,
145 double x1inches, double x2inches, double y1inches, double y2inches);
146 autoGraphics Graphics_create_pdf (void *context, int resolution,
147 double x1inches, double x2inches, double y1inches, double y2inches);
148 autoGraphics Graphics_create_pngfile (MelderFile file, int resolution,
149 double x1inches, double x2inches, double y1inches, double y2inches);
150 autoGraphics Graphics_create_postscriptprinter (void);
151 autoGraphics Graphics_create_screenPrinter (void *display, void *window);
152 autoGraphics Graphics_create_screen (void *display, void *window, int resolution);
153 autoGraphics Graphics_create_xmdrawingarea (GuiDrawingArea drawingArea);
154
155 int Graphics_getResolution (Graphics me);
156
157 void Graphics_setWsViewport (Graphics me, integer x1DC, integer x2DC, integer y1DC, integer y2DC);
158 void Graphics_resetWsViewport (Graphics me, integer x1DC, integer x2DC, integer y1DC, integer y2DC);
159 void Graphics_setWsWindow (Graphics me, double x1NDC, double x2NDC, double y1NDC, double y2NDC);
160 void Graphics_inqWsViewport (Graphics me, integer *x1DC, integer *x2DC, integer *y1DC, integer *y2DC);
161 void Graphics_inqWsWindow (Graphics me, double *x1NDC, double *x2NDC, double *y1NDC, double *y2NDC);
162 void Graphics_clearWs (Graphics me);
163 void Graphics_updateWs (Graphics me);
164 void Graphics_beginMovieFrame (Graphics me, MelderColour *colour);
165 void Graphics_endMovieFrame (Graphics me, double frameDuration);
166 void Graphics_DCtoWC (Graphics me, integer xDC, integer yDC, double *xWC, double *yWC);
167 void Graphics_WCtoDC (Graphics me, double xWC, double yWC, integer *xDC, integer *yDC);
168
169 void Graphics_setViewport (Graphics me, double x1NDC, double x2NDC, double y1NDC, double y2NDC);
170 Graphics_Viewport Graphics_insetViewport (Graphics me, double x1rel, double x2rel, double y1rel, double y2rel);
171 void Graphics_resetViewport (Graphics me, Graphics_Viewport viewport);
172 void Graphics_setWindow (Graphics me, double x1, double x2, double y1, double y2);
173
174 void Graphics_polyline (Graphics me, integer numberOfPoints, const double *x, const double *y);
175 void Graphics_polyline_closed (Graphics me, integer numberOfPoints, const double *x, const double *y);
176
177 void Graphics_text (Graphics me, double xWC, double yWC, conststring32 txt);
178 template <typename... Args>
Graphics_text(Graphics me,double xWC,double yWC,const MelderArg & first,Args...rest)179 void Graphics_text (Graphics me, double xWC, double yWC, const MelderArg& first, Args... rest) {
180 Graphics_text (me, xWC, yWC, Melder_cat (first, rest...));
181 }
182
183 void Graphics_textRect (Graphics me, double x1, double x2, double y1, double y2, conststring32 text /* cattable */);
184 double Graphics_textWidth (Graphics me, conststring32 text /* cattable */);
185 double Graphics_textWidth_ps (Graphics me, conststring32 text /* cattable */, bool useSilipaPS);
186 double Graphics_textWidth_ps_mm (Graphics me, conststring32 text /* cattable */, bool useSilipaPS);
187 void Graphics_fillArea (Graphics me, integer numberOfPoints, double const *x, double const *y);
188 void Graphics_cellArray (Graphics me, constMATVU const& z,
189 double x1, double x2, double y1, double y2, double minimum, double maximum);
190 void Graphics_cellArray_colour (Graphics me, constmatrixview <MelderColour> const& z,
191 double x1, double x2, double y1, double y2, double minimum, double maximum);
192 void Graphics_cellArray8 (Graphics me, constmatrixview <unsigned char> const& z,
193 double x1, double x2, double y1, double y2, unsigned char minimum, unsigned char maximum);
194 void Graphics_image (Graphics me, constMATVU const& z,
195 double x1, double x2, double y1, double y2, double minimum, double maximum);
196 void Graphics_image_colour (Graphics me, constmatrixview <MelderColour> const& z,
197 double x1, double x2, double y1, double y2, double minimum, double maximum);
198 void Graphics_image8 (Graphics me, constmatrixview <unsigned char> const& z,
199 double x1, double x2, double y1, double y2, uint8 minimum, uint8 maximum);
200 void Graphics_imageFromFile (Graphics me, conststring32 relativeFileName, double x1, double x2, double y1, double y2);
201 void Graphics_line (Graphics me, double x1, double y1, double x2, double y2);
202 void Graphics_rectangle (Graphics me, double x1, double x2, double y1, double y2);
203 void Graphics_fillRectangle (Graphics me, double x1, double x2, double y1, double y2);
204 void Graphics_roundedRectangle (Graphics me, double x1, double x2, double y1, double y2, double r_mm);
205 void Graphics_fillRoundedRectangle (Graphics me, double x1, double x2, double y1, double y2, double r_mm);
206 void Graphics_function (Graphics me, const double y [], integer ix1, integer ix2, double x1, double x2); // y [ix1..ix2]
207 void Graphics_function16 (Graphics me, const int16 y [], integer stride, integer ix1, integer ix2, double x1, double x2); // y [ix1..ix2] or y [ix1*2..ix2*2]
208 void Graphics_circle (Graphics me, double x, double y, double r);
209 void Graphics_fillCircle (Graphics me, double x, double y, double r);
210 void Graphics_circle_mm (Graphics me, double x, double y, double d);
211 void Graphics_fillCircle_mm (Graphics me, double x, double y, double d);
212 void Graphics_speckle (Graphics me, double x, double y);
213 void Graphics_rectangle_mm (Graphics me, double x, double y, double horizontalSide_mm, double verticalSide_mm);
214 void Graphics_fillRectangle_mm (Graphics me, double x, double y, double horizontalSide_mm, double verticalSide_mm);
215 void Graphics_arc (Graphics me, double x, double y, double r, double fromAngle, double toAngle);
216 void Graphics_fillArc (Graphics me, double x, double y, double r, double fromAngle, double toAngle);
217 void Graphics_ellipse (Graphics me, double x1, double x2, double y1, double y2);
218 void Graphics_fillEllipse (Graphics me, double x1, double x2, double y1, double y2);
219 void Graphics_arrow (Graphics me, double x1, double y1, double x2, double y2);
220 void Graphics_doubleArrow (Graphics me, double x1, double y1, double x2, double y2);
221 void Graphics_arcArrow (Graphics me, double x, double y, double r, double fromAngle, double toAngle, int arrowAtStart, int arrowAtEnd);
222 void Graphics_mark (Graphics me, double x, double y, double size_mm, conststring32 markString /* cattable */);
223 void Graphics_button (Graphics me, double x1, double x2, double y1, double y2);
224 void Graphics_innerRectangle (Graphics me, double x1, double x2, double y1, double y2);
225
226 void Graphics_setColour (Graphics me, MelderColour colour);
227 void Graphics_setGrey (Graphics me, double grey);
228
229 void Graphics_xorOn (Graphics me, MelderColour colour);
230 void Graphics_xorOff (Graphics me);
231 void Graphics_highlight (Graphics me, double x1, double x2, double y1, double y2);
232 void Graphics_highlight2 (Graphics me, double x1, double x2, double y1, double y2,
233 double innerX1, double innerX2, double innerY1, double innerY2);
234
235 #define Graphics_NOCHANGE -1
236 #define Graphics_LEFT kGraphics_horizontalAlignment::LEFT
237 #define Graphics_CENTRE kGraphics_horizontalAlignment::CENTRE
238 #define Graphics_RIGHT kGraphics_horizontalAlignment::RIGHT
239 #define Graphics_BOTTOM 0
240 #define Graphics_HALF 1
241 #define Graphics_TOP 2
242 #define Graphics_BASELINE 3
243 void Graphics_setTextAlignment (Graphics me, enum kGraphics_horizontalAlignment horizontal, int vertical);
244
245 void Graphics_setFont (Graphics me, enum kGraphics_font font);
246 void Graphics_setFontSize (Graphics me, double height);
247
248 #define Graphics_NORMAL 0
249 #define Graphics_BOLD 1
250 #define Graphics_ITALIC 2
251 #define Graphics_BOLD_ITALIC 3
252 #define Graphics_CODE 4
253 void Graphics_setFontStyle (Graphics me, int style);
254
255 void Graphics_setItalic (Graphics me, bool onoff);
256 void Graphics_setBold (Graphics me, bool onoff);
257 void Graphics_setCode (Graphics me, bool onoff);
258 void Graphics_setTextRotation (Graphics me, double angle);
259 void Graphics_setTextRotation_vector (Graphics me, double dx, double dy);
260 void Graphics_setWrapWidth (Graphics me, double wrapWidth);
261 void Graphics_setSecondIndent (Graphics me, double indent);
262 double Graphics_inqTextX (Graphics me);
263 double Graphics_inqTextY (Graphics me);
264 typedef struct { double x1, x2, y1, y2; char32 *name; } Graphics_Link;
265 int Graphics_getLinks (Graphics_Link **plinks);
266 void Graphics_setNumberSignIsBold (Graphics me, bool isBold);
267 void Graphics_setPercentSignIsItalic (Graphics me, bool isItalic);
268 void Graphics_setCircumflexIsSuperscript (Graphics me, bool isSuperscript);
269 void Graphics_setUnderscoreIsSubscript (Graphics me, bool isSubscript);
270 void Graphics_setDollarSignIsCode (Graphics me, bool isCode);
271 void Graphics_setAtSignIsLink (Graphics me, bool isLink);
272
273 #define Graphics_DRAWN 0
274 #define Graphics_DOTTED 1
275 #define Graphics_DASHED 2
276 #define Graphics_DASHED_DOTTED 3
277 void Graphics_setLineType (Graphics me, int lineType);
278
279 void Graphics_setLineWidth (Graphics me, double lineWidth);
280 void Graphics_setArrowSize (Graphics me, double arrowSize);
281 void Graphics_setSpeckleSize (Graphics me, double speckleSize);
282
283 void Graphics_setColourScale (Graphics me, enum kGraphics_colourScale colourScale);
284
285 void Graphics_inqViewport (Graphics me, double *x1NDC, double *x2NDC, double *y1NDC, double *y2NDC);
286 void Graphics_inqWindow (Graphics me, double *x1WC, double *x2WC, double *y1WC, double *y2WC);
287 enum kGraphics_font Graphics_inqFont (Graphics me);
288 double Graphics_inqFontSize (Graphics me);
289 int Graphics_inqFontStyle (Graphics me);
290 int Graphics_inqLineType (Graphics me);
291 double Graphics_inqLineWidth (Graphics me);
292 double Graphics_inqArrowSize (Graphics me);
293 double Graphics_inqSpeckleSize (Graphics me);
294 MelderColour Graphics_inqColour (Graphics me);
295 enum kGraphics_colourScale Graphics_inqColourScale (Graphics me);
296
297 void Graphics_contour (Graphics me, constMATVU const& z,
298 double x1WC, double x2WC, double y1WC, double y2WC, double height);
299 void Graphics_altitude (Graphics me, constMATVU const& z,
300 double x1WC, double x2WC, double y1WC, double y2WC, int numberOfBorders, double borders []);
301 void Graphics_grey (Graphics me, constMATVU const& z,
302 double x1WC, double x2WC, double y1WC, double y2WC, int numberOfBorders, double borders []);
303 #define Graphics_gray Graphics_grey
304 void Graphics_surface (Graphics me, constMATVU const& z,
305 double x1WC, double x2WC, double y1WC, double y2WC,
306 double minimum, double maximum, double elevation, double azimuth
307 );
308
309 void Graphics_setInner (Graphics me);
310 void Graphics_unsetInner (Graphics me);
311 void Graphics_drawInnerBox (Graphics me);
312 void Graphics_textLeft (Graphics me, bool farr, conststring32 text /* cattable */);
313 void Graphics_textRight (Graphics me, bool farr, conststring32 text /* cattable */);
314 void Graphics_textBottom (Graphics me, bool farr, conststring32 text /* cattable */);
315 void Graphics_textTop (Graphics me, bool farr, conststring32 text /* cattable */);
316 void Graphics_marksLeft (Graphics me, int numberOfMarks, bool haveNumbers, bool haveTicks, bool haveDottedLines);
317 void Graphics_marksRight (Graphics me, int numberOfMarks, bool haveNumbers, bool haveTicks, bool haveDottedLines);
318 void Graphics_marksBottom (Graphics me, int numberOfMarks, bool haveNumbers, bool haveTicks, bool haveDottedLines);
319 void Graphics_marksTop (Graphics me, int numberOfMarks, bool haveNumbers, bool haveTicks, bool haveDottedLines);
320 void Graphics_marksLeftLogarithmic (Graphics me, int numberOfMarksPerDecade, bool haveNumbers, bool haveTicks, bool haveDottedLines);
321 void Graphics_marksRightLogarithmic (Graphics me, int numberOfMarksPerDecade, bool haveNumbers, bool haveTicks, bool haveDottedLines);
322 void Graphics_marksBottomLogarithmic (Graphics me, int numberOfMarksPerDecade, bool haveNumbers, bool haveTicks, bool haveDottedLines);
323 void Graphics_marksTopLogarithmic (Graphics me, int numberOfMarksPerDecade, bool haveNumbers, bool haveTicks, bool haveDottedLines);
324 void Graphics_markLeft (Graphics me, double yWC, bool hasNumber, bool hasTick, bool hasDottedLine, conststring32 text /* cattable */);
325 void Graphics_markRight (Graphics me, double yWC, bool hasNumber, bool hasTick, bool hasDottedLine, conststring32 text /* cattable */);
326 void Graphics_markBottom (Graphics me, double xWC, bool hasNumber, bool hasTick, bool hasDottedLine, conststring32 text /* cattable */);
327 void Graphics_markTop (Graphics me, double xWC, bool hasNumber, bool hasTick, bool hasDottedLine, conststring32 text /* cattable */);
328 void Graphics_markLeftLogarithmic (Graphics me, double y, bool hasNumber, bool hasTick, bool hasDottedLine, conststring32 text /* cattable */); // y > 0
329 void Graphics_markRightLogarithmic (Graphics me, double y, bool hasNumber, bool hasTick, bool hasDottedLine, conststring32 text /* cattable */);
330 void Graphics_markBottomLogarithmic (Graphics me, double x, bool hasNumber, bool hasTick, bool hasDottedLine, conststring32 text /* cattable */);
331 void Graphics_markTopLogarithmic (Graphics me, double x, bool hasNumber, bool hasTick, bool hasDottedLine, conststring32 text /* cattable */);
332 void Graphics_marksLeftEvery (Graphics me, double units, double distance, bool haveNumbers, bool haveTicks, bool haveDottedLines);
333 void Graphics_marksRightEvery (Graphics me, double units, double distance, bool haveNumbers, bool haveTicks, bool haveDottedLines);
334 void Graphics_marksBottomEvery (Graphics me, double units, double distance, bool haveNumbers, bool haveTicks, bool haveDottedLines);
335 void Graphics_marksTopEvery (Graphics me, double units, double distance, bool haveNumbers, bool haveTicks, bool haveDottedLines);
336
337 bool Graphics_startRecording (Graphics me);
338 bool Graphics_stopRecording (Graphics me);
339 void Graphics_clearRecording (Graphics me);
340 void Graphics_play (Graphics from, Graphics to);
341 void Graphics_writeRecordings (Graphics me, FILE *f);
342 void Graphics_readRecordings (Graphics me, FILE *f);
343 void Graphics_markGroup (Graphics me);
344 void Graphics_undoGroup (Graphics me);
345
346 double Graphics_dxMMtoWC (Graphics me, double dx_mm);
347 double Graphics_dyMMtoWC (Graphics me, double dy_mm);
348 double Graphics_distanceWCtoMM (Graphics me, double x1WC, double y1WC, double x2WC, double y2WC);
349 double Graphics_dxWCtoMM (Graphics me, double dxWC);
350 double Graphics_dyWCtoMM (Graphics me, double dyWC);
351
352 void Graphics_nextSheetOfPaper (Graphics me);
353
354 void Graphics_prefs ();
355
356 /* End of file Graphics.h */
357 #endif
358