2 * Grace - GRaphing, Advanced Computation and Exploration of data
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
6 * Copyright (c) 1996-2003 Grace Development Team
8 * Maintained by Evgeny Stambulchik
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include "grace/base.h"
33 /* bpp that Grace uses internally ( = 256 colors) */
35 #define MAXCOLORS (0x01 << GRACE_BPP)
37 /* polyline drawing modes */
38 #define POLYLINE_OPEN 0
39 #define POLYLINE_CLOSED 1
41 /* polygon fill type */
42 #define FILLRULE_WINDING 0
43 #define FILLRULE_EVENODD 1
46 #define ARCFILL_CHORD 0
47 #define ARCFILL_PIESLICE 1
49 /* pixmap transparency types */
50 #define PIXMAP_TRANSPARENT 0
51 #define PIXMAP_OPAQUE 1
53 /* line cap parameter */
54 #define LINECAP_BUTT 0
55 #define LINECAP_ROUND 1
56 #define LINECAP_PROJ 2
59 #define LINEJOIN_MITER 0
60 #define LINEJOIN_ROUND 1
61 #define LINEJOIN_BEVEL 2
63 /* Text string justifications */
73 #define JUST_MIDDLE 12
75 #define BAD_FONT_ID -1
78 #define TEXT_ADVANCING_LR 0
79 #define TEXT_ADVANCING_RL 1
81 #define STRING_DIRECTION_LR 0
82 #define STRING_DIRECTION_RL 1
86 #define MARK_CR MAX_MARKS
88 #define UNIT_TM {1.0, 0.0, 0.0, 1.0}
90 #define MM_PER_INCH 25.4
91 #define CM_PER_INCH (MM_PER_INCH/10)
93 /* hardcopy or terminal device */
94 /* device output can be redirected to file/printer(both) */
97 #define DEVICE_PRINT 2
99 /* Page orientation */
100 #define PAGE_ORIENT_LANDSCAPE 0
101 #define PAGE_ORIENT_PORTRAIT 1
103 #define INTENSITY(r, g, b) ((299*r + 587*g + 114*b)/1000)
105 #define COLOR_TRANS_NONE 0
106 #define COLOR_TRANS_GREYSCALE 1
107 #define COLOR_TRANS_BW 2
108 #define COLOR_TRANS_NEGATIVE 3
109 #define COLOR_TRANS_REVERSE 4
110 #define COLOR_TRANS_SRGB 5
114 #define BBOX_TYPE_GLOB 0
115 #define BBOX_TYPE_TEMP 1
117 /* The default max drawing path limit */
118 #define MAX_DRAWING_PATH 20000
121 /* A point in viewport coordinates */
129 double xv1
, xv2
, yv1
, yv2
;
135 /* int transparency; */
213 CStringSegment
*segs
;
214 struct _CSGlyphCache
*cglyphs
;
219 char chars_used
[256];
223 unsigned int ncolors
;
224 unsigned int *colors
;
225 unsigned int npatterns
;
226 unsigned int *patterns
;
227 unsigned int nlinestyles
;
228 unsigned int *linestyles
;
243 typedef struct _Canvas Canvas
;
245 typedef void (*DevFreeDataProc
)(void *data
);
247 /* function to initialize device */
248 typedef int (*DevInitProc
)(const Canvas
*canvas
, void *data
,
249 const CanvasStats
*cstats
);
250 /* function to parse device-specific commands */
251 typedef int (*DevParserProc
)(const Canvas
*canvas
, void *data
, const char *s
);
252 /* function (GUI interface) to setup device */
253 typedef void (*DevSetupProc
)(const Canvas
*canvas
, void *data
);
254 /* update color map */
255 typedef void (*DevUpdateCmapProc
)(const Canvas
*canvas
, void *data
);
257 typedef void (*DevLeaveGraphicsProc
)(const Canvas
*canvas
, void *data
,
258 const CanvasStats
*cstats
);
261 /* device pixel routine */
262 typedef void (*DevDrawPixelProc
)(const Canvas
*canvas
, void *data
,
264 /* device polyline routine */
265 typedef void (*DevDrawPolyLineProc
)(const Canvas
*canvas
, void *data
,
266 const VPoint
*vps
, int n
, int mode
);
267 /* device polygon routine */
268 typedef void (*DevFillPolygonProc
)(const Canvas
*canvas
, void *data
,
269 const VPoint
*vps
, int nc
);
270 /* device arc routine */
271 typedef void (*DevDrawArcProc
)(const Canvas
*canvas
, void *data
,
272 const VPoint
*vp1
, const VPoint
*vp2
, double a1
, double a2
);
273 /* device fill arc routine */
274 typedef void (*DevFillArcProc
)(const Canvas
*canvas
, void *data
,
275 const VPoint
*vp1
, const VPoint
*vp2
, double a1
, double a2
, int mode
);
276 /* device pixmap drawing */
277 typedef void (*DevPutPixmapProc
)(const Canvas
*canvas
, void *data
,
278 const VPoint
*vp
, const CPixmap
*pm
);
279 /* device text typesetting */
280 typedef void (*DevPutTextProc
)(const Canvas
*canvas
, void *data
,
281 const VPoint
*vp
, const char *s
, int len
, int font
, const TextMatrix
*tm
,
282 int underline
, int overline
, int kerning
);
284 /* drawing procedure */
285 typedef void (*CanvasDrawProc
)(Canvas
*canvas
, void *data
);
287 typedef int (*CanvasCSParseProc
)(const Canvas
*canvas
,
288 const char *s
, CompositeString
*cstring
);
290 typedef int (*CanvasFMapProc
)(const Canvas
*canvas
, int);
296 RGB devrgb
; /* Converted RGB - for the current device */
320 /* Standard formats */
323 PAGE_FORMAT_USLETTER
,
327 /* Font rasterizing types */
338 unsigned long height
;
344 char *name
; /* name of device */
345 char *fext
; /* filename extension */
346 FontRaster fontrast
; /* font rasterizing */
347 Page_geometry pg
; /* device defaults */
349 int twopass
; /* two-pass mode */
350 int autocrop
; /* resize canvas to tight BBox */
352 int color_trans
; /* color transformation type */
354 /* low-level device routines */
355 DevInitProc initgraphics
;
356 DevLeaveGraphicsProc leavegraphics
;
357 DevParserProc parser
;
359 DevUpdateCmapProc updatecmap
;
360 DevDrawPixelProc drawpixel
;
361 DevDrawPolyLineProc drawpolyline
;
362 DevFillPolygonProc fillpolygon
;
363 DevDrawArcProc drawarc
;
364 DevFillArcProc fillarc
;
365 DevPutPixmapProc putpixmap
;
366 DevPutTextProc puttext
;
368 void *data
; /* device private data */
369 DevFreeDataProc freedata
; /* freeing private data */
372 char *canvas_get_username(const Canvas
*canvas
);
373 char *canvas_get_docname(const Canvas
*canvas
);
374 char *canvas_get_description(const Canvas
*canvas
);
376 void getpen(const Canvas
*canvas
, Pen
*pen
);
377 int getcolor(const Canvas
*canvas
);
378 int getbgcolor(const Canvas
*canvas
);
379 int getpattern(const Canvas
*canvas
);
380 int getlinestyle(const Canvas
*canvas
);
381 int getlinecap(const Canvas
*canvas
);
382 int getlinejoin(const Canvas
*canvas
);
383 int getfillrule(const Canvas
*canvas
);
384 double getlinewidth(const Canvas
*canvas
);
385 double getcharsize(const Canvas
*canvas
);
386 int getfont(const Canvas
*canvas
);
389 void canvas_set_prstream(Canvas
*canvas
, FILE *prstream
);
390 FILE *canvas_get_prstream(const Canvas
*canvas
);
392 void set_max_path_limit(Canvas
*canvas
, int limit
);
393 int get_max_path_limit(const Canvas
*canvas
);
395 unsigned int number_of_colors(const Canvas
*canvas
);
396 double get_rgb_intensity(const RGB
*rgb
);
398 unsigned int number_of_fonts(const Canvas
*canvas
);
399 char *get_fontname(const Canvas
*canvas
, int font
);
400 char *get_fontfullname(const Canvas
*canvas
, int font
);
401 char *get_fontfamilyname(const Canvas
*canvas
, int font
);
402 char *get_fontweight(const Canvas
*canvas
, int font
);
403 char *get_fontfilename(const Canvas
*canvas
, int font
, int abspath
);
404 char *get_afmfilename(const Canvas
*canvas
, int font
, int abspath
);
405 char *get_fontalias(const Canvas
*canvas
, int font
);
406 char *get_encodingscheme(const Canvas
*canvas
, int font
);
407 char **get_default_encoding(const Canvas
*canvas
);
408 double get_textline_width(const Canvas
*canvas
, int font
);
409 double get_underline_pos(const Canvas
*canvas
, int font
);
410 double get_overline_pos(const Canvas
*canvas
, int font
);
411 double get_italic_angle(const Canvas
*canvas
, int font
);
413 unsigned int number_of_patterns(const Canvas
*canvas
);
414 Pattern
*canvas_get_pattern(const Canvas
*canvas
, unsigned int n
);
416 unsigned int number_of_linestyles(const Canvas
*canvas
);
417 LineStyle
*canvas_get_linestyle(const Canvas
*canvas
, unsigned int n
);
419 #if !defined(CANVAS_BACKEND_API) || defined(__CANVASP_H_)
421 Canvas
*canvas_new(void);
422 void canvas_free(Canvas
*canvas
);
424 void canvas_set_udata(Canvas
*canvas
, void *data
);
425 void *canvas_get_udata(const Canvas
*canvas
);
427 void canvas_set_username(Canvas
*canvas
, const char *s
);
428 void canvas_set_docname(Canvas
*canvas
, const char *s
);
429 void canvas_set_description(Canvas
*canvas
, const char *s
);
431 void canvas_set_fmap_proc(Canvas
*canvas
, CanvasFMapProc fmap_proc
);
432 void canvas_set_csparse_proc(Canvas
*canvas
, CanvasCSParseProc csparse_proc
);
433 void canvas_set_fontsize_scale(Canvas
*canvas
, double fscale
);
434 void canvas_set_linewidth_scale(Canvas
*canvas
, double lscale
);
436 void canvas_set_pagefill(Canvas
*canvas
, int flag
);
438 void setclipping(Canvas
*canvas
, int flag
);
439 int canvas_set_clipview(Canvas
*canvas
, const view
*v
);
441 void setbgcolor(Canvas
*canvas
, int bgcolor
);
442 void setpen(Canvas
*canvas
, const Pen
*pen
);
443 void setline(Canvas
*canvas
, const Line
*line
);
444 void setcolor(Canvas
*canvas
, int color
);
445 void setlinestyle(Canvas
*canvas
, int lines
);
446 void setlinewidth(Canvas
*canvas
, double linew
);
447 void setpattern(Canvas
*canvas
, int pattern
);
448 void setcharsize(Canvas
*canvas
, double charsize
);
449 void setfont(Canvas
*canvas
, int font
);
450 void setfillrule(Canvas
*canvas
, int rule
);
451 void setlinecap(Canvas
*canvas
, int type
);
452 void setlinejoin(Canvas
*canvas
, int type
);
454 void DrawPixel(Canvas
*canvas
, const VPoint
*vp
);
455 void DrawPolyline(Canvas
*canvas
, const VPoint
*vps
, int n
, int mode
);
456 void DrawPolygon(Canvas
*canvas
, const VPoint
*vps
, int n
);
457 void DrawArc(Canvas
*canvas
, const VPoint
*vp1
, const VPoint
*vp2
,
458 double angle1
, double angle2
);
459 void DrawFilledArc(Canvas
*canvas
, const VPoint
*vp1
, const VPoint
*vp2
,
460 double angle1
, double angle2
, int mode
);
461 void WriteString(Canvas
*canvas
,
462 const VPoint
*vp
, double angle
, int just
, const char *s
);
464 void DrawRect(Canvas
*canvas
, const VPoint
*vp1
, const VPoint
*vp2
);
465 void FillRect(Canvas
*canvas
, const VPoint
*vp1
, const VPoint
*vp2
);
466 void DrawLine(Canvas
*canvas
, const VPoint
*vp1
, const VPoint
*vp2
);
467 void DrawEllipse(Canvas
*canvas
, const VPoint
*vp1
, const VPoint
*vp2
);
468 void DrawFilledEllipse(Canvas
*canvas
, const VPoint
*vp1
, const VPoint
*vp2
);
469 void DrawCircle(Canvas
*canvas
, const VPoint
*vp
, double radius
);
470 void DrawFilledCircle(Canvas
*canvas
, const VPoint
*vp
, double radius
);
472 CStringSegment
*cstring_seg_new(CompositeString
*cstring
);
473 double tm_size(const TextMatrix
*tm
);
474 int tm_scale(TextMatrix
*tm
, double s
);
475 int tm_rotate(TextMatrix
*tm
, double angle
);
476 int tm_slant(TextMatrix
*tm
, double slant
);
477 int tm_product(TextMatrix
*tm
, const TextMatrix
*p
);
479 void set_draw_mode(Canvas
*canvas
, int mode
);
480 int get_draw_mode(const Canvas
*canvas
);
482 int is_validVPoint(const Canvas
*canvas
, const VPoint
*vp
);
484 void reset_bbox(Canvas
*canvas
, int type
);
485 void freeze_bbox(Canvas
*canvas
, int type
);
486 int get_bbox(const Canvas
*canvas
, int type
, view
*v
);
487 void update_bbox(Canvas
*canvas
, int type
, const VPoint
*vp
);
488 int melt_bbox(Canvas
*canvas
, int type
);
489 void activate_bbox(Canvas
*canvas
, int type
, int status
);
491 int view_extend(view
*v
, double w
);
492 int merge_bboxes(const view
*v1
, const view
*v2
, view
*v
);
493 void vpswap(VPoint
*vp1
, VPoint
*vp2
);
494 int VPoints2bbox(const VPoint
*vp1
, const VPoint
*vp2
, view
*bb
);
496 int is_vpoint_inside(const view
*v
, const VPoint
*vp
, double epsilon
);
498 int canvas_cmap_reset(Canvas
*canvas
);
499 int canvas_store_color(Canvas
*canvas
, unsigned int n
, const RGB
*rgb
);
501 int canvas_set_encoding(Canvas
*canvas
, char *encfile
);
502 int canvas_add_font(Canvas
*canvas
, char *ffile
, const char *alias
);
504 int canvas_get_font_by_name(const Canvas
*canvas
, const char *fname
);
506 int select_device(Canvas
*canvas
, unsigned int dindex
);
508 Device_entry
*get_device_props(const Canvas
*canvas
, int device
);
510 char *get_device_name(const Canvas
*canvas
, int device
);
512 int is_valid_page_geometry(const Page_geometry
*pg
);
513 int set_page_geometry(Canvas
*canvas
, const Page_geometry
*pg
);
515 int get_device_page_dimensions(const Canvas
*canvas
,
516 unsigned int dindex
, int *wpp
, int *hpp
);
518 int get_device_by_name(const Canvas
*canvas
, const char *dname
);
520 int parse_device_options(Canvas
*canvas
, unsigned int dindex
, char *options
);
522 int number_of_devices(const Canvas
*canvas
);
524 int terminal_device(const Canvas
*canvas
);
526 PageFormat
get_page_format(const Canvas
*canvas
, int device
);
528 int canvas_draw(Canvas
*canvas
, CanvasDrawProc dproc
, void *data
);
530 int get_string_bbox(Canvas
*canvas
,
531 const VPoint
*vp
, double angle
, int just
, const char *s
, view
*bbox
);
533 CPixmap
*canvas_raster_char(int font
, char c
, float size
, int *vshift
, int *hshift
);
534 void canvas_cpixmap_free(CPixmap
*pm
);
536 int isvalid_viewport(const view
*v
);
540 #if defined(CANVAS_BACKEND_API) || defined(__CANVASP_H_)
542 /* Some useful macros */
543 #define page_dpi(canvas) ((get_page_geometry(canvas))->dpi)
545 #define page_width(canvas) ((get_page_geometry(canvas))->width)
546 #define page_height(canvas) ((get_page_geometry(canvas))->height)
548 #define page_width_in(canvas) ((double) page_width(canvas)/page_dpi(canvas))
549 #define page_height_in(canvas) ((double) page_height(canvas)/page_dpi(canvas))
551 #define page_width_mm(canvas) (MM_PER_INCH*page_width_in(canvas))
552 #define page_height_mm(canvas) (MM_PER_INCH*page_height_in(canvas))
554 #define page_width_cm(canvas) (CM_PER_INCH*page_width_in(canvas))
555 #define page_height_cm(canvas) (CM_PER_INCH*page_height_in(canvas))
557 #define page_width_pp(canvas) (72*page_width_in(canvas))
558 #define page_height_pp(canvas) (72*page_height_in(canvas))
563 unsigned int **matrix
;
566 typedef int (*XrstDumpProc
)(const Canvas
*canvas
, void *data
,
567 unsigned int ncolors
, unsigned int *colors
, Xrst_pixmap
*pm
);
569 typedef struct _XrstDevice_entry
{
574 DevParserProc parser
;
579 void *data
; /* device private data */
580 DevFreeDataProc freedata
; /* freeing private data */
584 Device_entry
*device_new(const char *name
, int type
, int twopass
,
585 void *data
, DevFreeDataProc freedata
);
586 void device_free(Device_entry
*d
);
587 int device_set_procs(Device_entry
*d
,
588 DevInitProc initgraphics
,
589 DevLeaveGraphicsProc leavegraphics
,
590 DevParserProc parser
,
592 DevUpdateCmapProc updatecmap
,
593 DevDrawPixelProc drawpixel
,
594 DevDrawPolyLineProc drawpolyline
,
595 DevFillPolygonProc fillpolygon
,
596 DevDrawArcProc drawarc
,
597 DevFillArcProc fillarc
,
598 DevPutPixmapProc putpixmap
,
599 DevPutTextProc puttext
);
600 int device_set_fext(Device_entry
*d
, const char *fext
);
601 int device_set_autocrop(Device_entry
*d
, int autocrop
);
602 int device_set_fontrast(Device_entry
*d
, FontRaster fontrast
);
603 int device_set_dpi(Device_entry
*d
, float dpi
);
605 Page_geometry
*get_page_geometry(const Canvas
*canvas
);
607 int register_device(Canvas
*canvas
, Device_entry
*d
);
609 int register_xrst_device(Canvas
*canvas
, const XrstDevice_entry
*xdev
);
611 int get_rgb(const Canvas
*canvas
, unsigned int cindex
, RGB
*rgb
);
612 int get_frgb(const Canvas
*canvas
, unsigned int cindex
, fRGB
*frgb
);
614 double get_colorintensity(const Canvas
*canvas
, int cindex
);
616 int get_cmy(const Canvas
*canvas
, unsigned int cindex
, CMY
*cmy
);
617 int get_cmyk(const Canvas
*canvas
, unsigned int cindex
, CMYK
*cmyk
);
618 int get_fcmyk(const Canvas
*canvas
, unsigned int cindex
, fCMYK
*fcmyk
);
620 char *font_subset(const Canvas
*canvas
,
621 int font
, char *mask
, unsigned long *datalen
);
623 double *get_kerning_vector(const Canvas
*canvas
,
624 const char *str
, int len
, int font
);
628 #endif /* __CANVAS_H_ */