1/*********************************************************************** 2 * * 3 * $Id: hpgs.h 381 2007-02-20 09:06:38Z softadm $ 4 * * 5 * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * 6 * API for rendering a scene and thus renders to a variety of * 7 * devices and fileformats. * 8 * * 9 * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * 10 * * 11 * Author: Wolfgang Glas * 12 * * 13 * hpgs is free software; you can redistribute it and/or * 14 * modify it under the terms of the GNU Lesser General Public * 15 * License as published by the Free Software Foundation; either * 16 * version 2.1 of the License, or (at your option) any later version. * 17 * * 18 * hpgs 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 GNU * 21 * Lesser General Public License for more details. * 22 * * 23 * You should have received a copy of the GNU Lesser General Public * 24 * License along with this library; if not, write to the * 25 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * 26 * Boston, MA 02111-1307 USA * 27 * * 28 *********************************************************************** 29 * * 30 * The public interfaces, which have to be known to all components. * 31 * * 32 ***********************************************************************/ 33 34#ifndef __HPGS_H 35#define __HPGS_H 36 37#include<stdio.h> 38#include<stdarg.h> 39#include<stdlib.h> 40 41#ifdef __cplusplus 42extern "C" { 43#endif 44 45#ifndef __GNUC__ 46#ifdef _MSC_VER 47#define __inline__ __inline 48#else 49#define __inline__ inline 50#endif 51#endif 52 53/* All this is needed in order to set the right attributes for functions. 54 This allows us to build fully compliant dlls under Windows and to 55 hide functions needed for the implementation of the API in 56 ELF modules. Additionally, we make use of the 'format' attribute of 57 gcc in order to get the most out of -Wall. 58 */ 59#ifdef HPGS_SHARED 60# ifdef WIN32 61# ifdef __GNUC__ 62# ifdef HPGS_BUILD_SLIB 63# define HPGS_API __attribute__((dllexport)) 64# define HPGS_PRINTF_API(i) __attribute__((dllexport,format(printf,i,i+1))) 65# define HPGS_I18N_API __attribute__((dllexport,format_arg (1))) 66# define HPGS_I18N_N_API __attribute__((dllexport,format_arg (1),format_arg (2))) 67# else 68# define HPGS_API __attribute__((dllimport)) 69# define HPGS_PRINTF_API(i) __attribute__((dllimport,format(printf,i,i+1))) 70# define HPGS_I18N_API __attribute__((dllimport,format_arg (1))) 71# define HPGS_I18N_N_API __attribute__((dllimport,format_arg (1),format_arg (2))) 72# endif 73# define HPGS_INTERNAL_PRINTF_API(i) __attribute__((format(printf,i,i+1))) 74# else 75# ifdef HPGS_BUILD_SLIB 76# define HPGS_API __declspec(dllexport) 77# else 78# define HPGS_API __declspec(dllimport) 79# endif 80# endif 81# else 82# ifdef __GNUC__ 83# define HPGS_PRINTF_API(i) __attribute__((format(printf,i,i+1))) 84# define HPGS_I18N_API __attribute__((format_arg (1))) 85# define HPGS_I18N_N_API __attribute__((format_arg (1),format_arg (2))) 86# define HPGS_INTERNAL_API __attribute__((visibility("hidden"))) 87# define HPGS_INTERNAL_PRINTF_API(i) __attribute__((visibility("hidden"),format(printf,i,i+1))) 88# endif 89# endif 90#endif 91 92#ifndef HPGS_API 93#define HPGS_API 94#endif 95#ifndef HPGS_PRINTF_API 96#define HPGS_PRINTF_API(i) HPGS_API 97#endif 98#ifndef HPGS_I18N_API 99#define HPGS_I18N_API HPGS_API 100#endif 101#ifndef HPGS_I18N_N_API 102#define HPGS_I18N_N_API HPGS_API 103#endif 104#ifndef HPGS_INTERNAL_API 105#define HPGS_INTERNAL_API 106#endif 107#ifndef HPGS_INTERNAL_PRINTF_API 108#define HPGS_INTERNAL_PRINTF_API(i) HPGS_INTERNAL_API 109#endif 110 111/* These defines are used in order to allow better doxygen integration 112 of the printf API functions. */ 113#define HPGS_PRINTF1_API HPGS_PRINTF_API(1) 114#define HPGS_PRINTF2_API HPGS_PRINTF_API(2) 115#define HPGS_INTERNAL_PRINTF1_API HPGS_INTERNAL_PRINTF_API(1) 116#define HPGS_INTERNAL_PRINTF2_API HPGS_INTERNAL_PRINTF_API(2) 117 118#ifdef WIN32 119#define HPGS_SIZE_T_FMT "%lu" 120#else 121#define HPGS_SIZE_T_FMT "%zu" 122#endif 123 124/*! \file hpgs.h 125 126 \brief The public interfaces. 127 128 A header file, which declares the public structures and functions 129 provided by the hpgs library. The API declared in this header file 130 remains stable across the whole series of release with the same 131 major ans minor number. 132*/ 133 134#define HPGS_STRINGIFYIFY(i) #i 135#define HPGS_STRINGIFY(i) HPGS_STRINGIFYIFY(i) 136 137#define HPGS_MAJOR_VERSION 1 138#define HPGS_MINOR_VERSION 1 139#define HPGS_PATCH_VERSION 0 140#define HPGS_EXTRA_VERSION 141 142// a string for displaying the version. 143#define HPGS_VERSION HPGS_STRINGIFY(HPGS_MAJOR_VERSION) "." HPGS_STRINGIFY(HPGS_MINOR_VERSION) "." HPGS_STRINGIFY(HPGS_PATCH_VERSION) HPGS_STRINGIFY(HPGS_EXTRA_VERSION) 144 145#define HPGS_ESC '\033' 146 147#define HPGS_MAX_LABEL_SIZE 256 148 149#define hpgs_alloca(sz) alloca(sz) 150 151/*! @addtogroup base 152 * @{ 153 */ 154typedef int hpgs_bool; 155 156#define HPGS_TRUE 1 157#define HPGS_FALSE 0 158 159HPGS_API int hpgs_array_safe_resize (size_t itemsz, void **pptr, size_t *psz, size_t nsz); 160 161#define HPGS_MIN(a,b) ((a)<(b)?(a):(b)) 162#define HPGS_MAX(a,b) ((a)>(b)?(a):(b)) 163 164#define HPGS_INIT_ARRAY(st,type,pmemb,nmemb,szmemb,insz) \ 165(st->szmemb=insz,st->nmemb=0,(st->pmemb=(type*)malloc(sizeof(type)*insz))?0:-1) 166 167#define HPGS_GROW_ARRAY_FOR_PUSH(st,type,pmemb,nmemb,szmemb) \ 168((st->nmemb >= st->szmemb)?hpgs_array_safe_resize(sizeof(type),(void **)(&st->pmemb),&st->szmemb,st->szmemb*2):(0)) 169 170#define HPGS_GROW_ARRAY_MIN_SIZE(st,type,pmemb,nmemb,szmemb,msz) \ 171((st->nmemb>=st->szmemb||st->szmemb<msz)?hpgs_array_safe_resize(sizeof(type),(void **)(&st->pmemb),&st->szmemb,HPGS_MAX(st->szmemb*2,msz)):(0)) 172 173#ifdef WIN32 174#define HPGS_PATH_SEPARATOR '\\' 175#else 176#define HPGS_PATH_SEPARATOR '/' 177#endif 178 179HPGS_API void hpgs_init (const char *prefix); 180HPGS_API const char *hpgs_get_prefix(); 181HPGS_API void hpgs_cleanup (void); 182HPGS_API char *hpgs_share_filename(const char *rel_filename); 183 184HPGS_API char *hpgs_vsprintf_malloc(const char *fmt, va_list ap); 185HPGS_PRINTF1_API char *hpgs_sprintf_malloc(const char *fmt, ...); 186 187HPGS_PRINTF1_API int hpgs_set_error(const char *fmt, ...); 188HPGS_PRINTF1_API int hpgs_error_ctxt(const char *fmt, ...); 189HPGS_API int hpgs_set_verror(const char *fmt, va_list ap); 190HPGS_API int hpgs_verror_ctxt(const char *fmt, va_list ap); 191HPGS_API const char *hpgs_get_error(); 192HPGS_API hpgs_bool hpgs_have_error(); 193HPGS_API void hpgs_clear_error(); 194 195HPGS_API int hpgs_next_utf8(const char **p); 196HPGS_API int hpgs_utf8_strlen(const char *p, int n); 197 198HPGS_I18N_API const char *hpgs_i18n(const char *msg); 199HPGS_I18N_N_API const char *hpgs_i18n_n(const char *msg, 200 const char *msg_plural, 201 unsigned long n); 202 203typedef void (*hpgs_logger_func_t) (const char *fmt, va_list ap); 204HPGS_API void hpgs_set_logger(hpgs_logger_func_t func); 205HPGS_PRINTF1_API void hpgs_log(const char *fmt, ...); 206HPGS_API void hpgs_vlog(const char *fmt, va_list ap); 207 208HPGS_API hpgs_bool hpgs_get_arg_value(const char *opt, const char *argv[], 209 const char **value, int *narg); 210 211/*! \brief A 2D point. 212 213 This structure has a public alias \c hpgs_point and 214 represents a point consisting of double precision 215 x and y coordinates. 216 */ 217typedef struct hpgs_point_st { 218 double x, y; 219} hpgs_point; 220 221/*! \brief An application level RGB color. 222 223 This structure has a public alias \c hpgs_color and 224 represents an application level RGB color consisting 225 of double precision r,g and b color values in the range 226 from 0.0 to 1.0. 227 */ 228typedef struct hpgs_color_st { 229 double r, g, b; 230} hpgs_color; 231 232typedef struct hpgs_palette_color_st hpgs_palette_color; 233 234/*! \brief A screen RGB color as stored in a palette. 235 236 This structure has a public alias \c hpgs_palette_color and 237 represents a screen RGB color consisting of single byte 238 r,g and b color values in the range 0 to 255. 239 */ 240struct hpgs_palette_color_st 241{ 242 unsigned char r; 243 unsigned char g; 244 unsigned char b; 245}; 246 247typedef void (*hpgs_rop3_func_t) (unsigned char *, unsigned char, unsigned char); 248 249HPGS_API hpgs_rop3_func_t hpgs_rop3_func(int rop3, 250 hpgs_bool src_transparency, 251 hpgs_bool pattern_transparency); 252 253typedef unsigned (*hpgs_xrop3_func_t) (unsigned char, unsigned char); 254 255HPGS_API hpgs_xrop3_func_t hpgs_xrop3_func(int rop3, 256 hpgs_bool src_transparency, 257 hpgs_bool pattern_transparency); 258 259typedef struct hpgs_paint_color_st hpgs_paint_color; 260 261/*! \brief An image RGB color with an optional palette index. 262 263 This structure has a public alias \c hpgs_paint_color and 264 represents an image RGB color with an optional palette index 265 consisting of single byte 266 r,g and b color values in the range 0 to 255 as well as of 267 a single byte palette index. 268 269 For calculating a suitable palette index for a given 270 \c hpgs_image consider calling \c hpgs_image_define_color. 271 */ 272struct hpgs_paint_color_st 273{ 274 unsigned char r; 275 unsigned char g; 276 unsigned char b; 277 unsigned char index; 278}; 279 280typedef struct hpgs_bbox_st hpgs_bbox; 281 282/*! \brief A bounding box. 283 284 This structure hold a bounding box used in several contexts. 285 */ 286struct hpgs_bbox_st 287{ 288 double llx; 289 double lly; 290 double urx; 291 double ury; 292}; 293 294HPGS_API hpgs_bool hpgs_bbox_isequal(const hpgs_bbox *bb1, const hpgs_bbox *bb2); 295HPGS_API hpgs_bool hpgs_bbox_isnull (const hpgs_bbox *bb); 296HPGS_API hpgs_bool hpgs_bbox_isempty (const hpgs_bbox *bb); 297HPGS_API void hpgs_bbox_distance (hpgs_point *d, const hpgs_bbox *bb1, const hpgs_bbox *bb2); 298HPGS_API void hpgs_bbox_null (hpgs_bbox *bb); 299HPGS_API void hpgs_bbox_expand (hpgs_bbox *bb1, const hpgs_bbox *bb2); 300HPGS_API void hpgs_bbox_intersect (hpgs_bbox *bb1, const hpgs_bbox *bb2); 301/*! Expands the bounding box \c bb in all directions by the amount of \c border. */ 302static void hpgs_bbox_addborder (hpgs_bbox *bb, double border); 303/*! Expands the bounding box \c bb in order to comprise the smallest bounding box 304 containing both \c bb and \cp. */ 305static void hpgs_bbox_add (hpgs_bbox *bb, const hpgs_point *p); 306 307__inline__ void hpgs_bbox_addborder (hpgs_bbox *bb, double border) 308{ 309 bb->llx -= border; 310 bb->urx += border; 311 bb->lly -= border; 312 bb->ury += border; 313} 314 315__inline__ void hpgs_bbox_add (hpgs_bbox *bb, const hpgs_point *p) 316{ 317 if (p->x < bb->llx) bb->llx = p->x; 318 if (p->x > bb->urx) bb->urx = p->x; 319 if (p->y < bb->lly) bb->lly = p->y; 320 if (p->y > bb->ury) bb->ury = p->y; 321} 322 323typedef struct hpgs_matrix_st hpgs_matrix; 324 325/*! \brief A transformation matrix for 2D points. 326 327 This structure holds an affine transformation matrix consisting of a 328 translation vector and a 2x2 matrix for rotation and or scaling. 329 */ 330struct hpgs_matrix_st 331{ 332 double dx; 333 double dy; 334 double mxx; 335 double mxy; 336 double myx; 337 double myy; 338}; 339 340HPGS_API void hpgs_matrix_set_identity(hpgs_matrix *m); 341 342HPGS_API void hpgs_matrix_xform(hpgs_point *res, 343 const hpgs_matrix *m, const hpgs_point *p); 344HPGS_API void hpgs_matrix_ixform(hpgs_point *res, 345 const hpgs_point *p, const hpgs_matrix *m); 346HPGS_API void hpgs_matrix_scale(hpgs_point *res, 347 const hpgs_matrix *m, const hpgs_point *p); 348HPGS_API void hpgs_matrix_iscale(hpgs_point *res, 349 const hpgs_point *p, const hpgs_matrix *m); 350HPGS_API void hpgs_matrix_concat(hpgs_matrix *res, 351 const hpgs_matrix *a, const hpgs_matrix *b); 352HPGS_API void hpgs_matrix_invert(hpgs_matrix *res, const hpgs_matrix *m); 353 354HPGS_API void hpgs_matrix_xform_bbox(hpgs_bbox *res, 355 const hpgs_matrix *m, const hpgs_bbox *bb); 356HPGS_API void hpgs_matrix_ixform_bbox(hpgs_bbox *res, 357 const hpgs_bbox *bb, const hpgs_matrix *m); 358 359/*! Defines the supported line cap styles. */ 360typedef enum { 361 hpgs_cap_butt = 0, //!< Butt line cap. 362 hpgs_cap_round = 1, //!< Round line cap. 363 hpgs_cap_square = 2 //!< Square line cap. 364} hpgs_line_cap; 365 366/*! Defines the supported line join styles. */ 367typedef enum { 368 hpgs_join_miter = 0, //!< Miter line join. 369 hpgs_join_round = 1, //!< Round line join. 370 hpgs_join_bevel = 2 //!< Bevel line join. 371} hpgs_line_join; 372 373// input stream 374typedef struct hpgs_istream_st hpgs_istream; 375typedef struct hpgs_istream_vtable_st hpgs_istream_vtable; 376 377typedef int (*hpgs_istream_getc_func_t)(void *); 378typedef int (*hpgs_istream_ungetc_func_t)(int ,void *); 379typedef int (*hpgs_istream_close_func_t)(void *); 380typedef int (*hpgs_istream_iseof_func_t)(void *); 381typedef int (*hpgs_istream_iserror_func_t)(void *); 382typedef int (*hpgs_istream_seek_func_t)(void *, size_t); 383typedef int (*hpgs_istream_tell_func_t)(void *, size_t*); 384typedef size_t (*hpgs_istream_read_func_t)(void *, size_t, size_t, void *); 385typedef int (*hpgs_istream_seekend_func_t)(void *, size_t); 386 387/*! \brief A table of virtual function implementing \c hpgs_istream. 388 389 This structure has a public alias \c hpgs_istream_vtable and 390 represents a table of functions for a specific implementation 391 of \c hpgs_istream. 392 393 The function names are deliberately similar to the corresponding 394 ANSI C functions. 395 */ 396struct hpgs_istream_vtable_st 397{ 398 hpgs_istream_getc_func_t getc_func; 399 hpgs_istream_ungetc_func_t ungetc_func; 400 hpgs_istream_close_func_t close_func; 401 hpgs_istream_iseof_func_t iseof_func; 402 hpgs_istream_iserror_func_t iserror_func; 403 hpgs_istream_seek_func_t seek_func; 404 hpgs_istream_tell_func_t tell_func; 405 hpgs_istream_read_func_t read_func; 406 hpgs_istream_seekend_func_t seekend_func; 407}; 408 409/*! \brief A virtual input stream for the HPGL reader. 410 411 This structure has a public alias \c hpgs_istream and 412 represents an abstract input stream consisting of 413 a stream pointer and a pointer to a table of virtual functions 414 implementing the stream. 415 */ 416struct hpgs_istream_st 417{ 418 hpgs_istream_vtable *vtable; 419 420 void *stream; 421}; 422 423HPGS_API hpgs_istream *hpgs_new_file_istream (const char *fn); 424HPGS_API hpgs_istream *hpgs_new_mem_istream (const unsigned char *data, 425 size_t data_size, 426 hpgs_bool dup); 427 428 429/*! The counterpart of ANSI getc for \c hpgs_istream. */ 430static int hpgs_getc (hpgs_istream *_this); 431/*! The counterpart of ANSI ungetc for \c hpgs_istream. */ 432static int hpgs_ungetc (int c, hpgs_istream *_this); 433/*! The counterpart of ANSI fclose for \c hpgs_istream. 434 After calling this function, all allocated resources of the stream are freed. */ 435static int hpgs_istream_close (hpgs_istream *_this); 436/*! The counterpart of ANSI feof for \c hpgs_istream. */ 437static int hpgs_istream_iseof (hpgs_istream *_this); 438/*! The counterpart of ANSI ferror for \c hpgs_istream. */ 439static int hpgs_istream_iserror(hpgs_istream *_this); 440/*! The counterpart of ANSI fseek for \c hpgs_istream. */ 441static int hpgs_istream_seek (hpgs_istream *_this, size_t pos); 442/*! The counterpart of ANSI fseek(SEEK_END) for \c hpgs_istream. */ 443static int hpgs_istream_seekend (hpgs_istream *_this, size_t pos); 444/*! The counterpart of ANSI ftell for \c hpgs_istream. */ 445static int hpgs_istream_tell (hpgs_istream *_this, size_t *pos); 446/*! The counterpart of ANSI fread for \c hpgs_istream. */ 447static size_t hpgs_istream_read (void *ptr, size_t size, size_t nmemb, hpgs_istream *_this); 448 449__inline__ int hpgs_getc (hpgs_istream *_this) 450{ return _this->vtable->getc_func(_this->stream); } 451 452__inline__ int hpgs_ungetc (int c, hpgs_istream *_this) 453{ return _this->vtable->ungetc_func(c,_this->stream); } 454 455__inline__ int hpgs_istream_close (hpgs_istream *_this) 456{ int ret = _this->vtable->close_func(_this->stream); free(_this); return ret; } 457 458__inline__ int hpgs_istream_iseof (hpgs_istream *_this) 459{ return _this->vtable->iseof_func(_this->stream); } 460 461__inline__ int hpgs_istream_iserror (hpgs_istream *_this) 462{ return _this->vtable->iserror_func(_this->stream); } 463 464__inline__ int hpgs_istream_seek (hpgs_istream *_this, size_t pos) 465{ return _this->vtable->seek_func(_this->stream,pos); } 466 467__inline__ int hpgs_istream_seekend (hpgs_istream *_this, size_t pos) 468{ return _this->vtable->seekend_func(_this->stream,pos); } 469 470__inline__ int hpgs_istream_tell (hpgs_istream *_this, size_t *pos) 471{ return _this->vtable->tell_func(_this->stream,pos); } 472 473__inline__ size_t hpgs_istream_read (void *ptr, size_t size, size_t nmemb, hpgs_istream *_this) 474{ return _this->vtable->read_func(ptr,size,nmemb,_this->stream); } 475 476// output stream 477typedef struct hpgs_ostream_st hpgs_ostream; 478typedef struct hpgs_ostream_vtable_st hpgs_ostream_vtable; 479 480typedef int (*hpgs_ostream_putc_func_t)(int, void *); 481typedef size_t (*hpgs_ostream_write_func_t)(const void *, size_t, size_t, void *); 482typedef int (*hpgs_ostream_vprintf_func_t)(void *, const char *, va_list); 483typedef int (*hpgs_ostream_flush_func_t)(void *); 484typedef int (*hpgs_ostream_close_func_t)(void *); 485typedef int (*hpgs_ostream_iserror_func_t)(void *); 486typedef hpgs_istream *(*hpgs_ostream_getbuf_func_t)(void *); 487typedef int (*hpgs_ostream_tell_func_t)(void *, int layer, size_t *); 488typedef int (*hpgs_ostream_seek_func_t)(void *, size_t); 489 490/*! \brief A table of virtual function implementing \c hpgs_istream. 491 492 This structure has a public alias \c hpgs_istream_vtable and 493 represents a table of functions for a specific implementation 494 of \c hpgs_istream. 495 496 The function names are deliberately similar to the corresponding 497 ANSI C functions. 498 */ 499struct hpgs_ostream_vtable_st 500{ 501 hpgs_ostream_putc_func_t putc_func; 502 hpgs_ostream_write_func_t write_func; 503 hpgs_ostream_vprintf_func_t vprintf_func; 504 hpgs_ostream_flush_func_t flush_func; 505 hpgs_ostream_close_func_t close_func; 506 hpgs_ostream_iserror_func_t iserror_func; 507 hpgs_ostream_getbuf_func_t getbuf_func; 508 hpgs_ostream_tell_func_t tell_func; 509 hpgs_ostream_seek_func_t seek_func; 510}; 511 512/*! \brief A virtual output stream for the HPGL reader. 513 514 This structure has a public alias \c hpgs_ostream and 515 represents an abstract onput stream consisting of 516 a stream pointer and a pointer to a table of virtual functions 517 implementing the stream. 518 */ 519struct hpgs_ostream_st 520{ 521 hpgs_ostream_vtable *vtable; 522 523 void *stream; 524}; 525 526HPGS_API hpgs_ostream *hpgs_new_file_ostream (const char *fn); 527HPGS_API hpgs_ostream *hpgs_new_mem_ostream (size_t data_reserve); 528HPGS_API hpgs_ostream *hpgs_new_z_ostream (hpgs_ostream *base, int compression, hpgs_bool take_base); 529 530HPGS_API int hpgs_copy_streams (hpgs_ostream *out, hpgs_istream *in); 531 532HPGS_PRINTF2_API int hpgs_ostream_printf (hpgs_ostream *_this, const char *msg, ...); 533HPGS_API int hpgs_ostream_vprintf (hpgs_ostream *_this, const char *msg, va_list ap); 534 535/*! The counterpart of ANSI putc for \c hpgs_ostream. */ 536static int hpgs_ostream_putc (int c, hpgs_ostream *_this); 537/*! The counterpart of ANSI fwrite for \c hpgs_ostream. */ 538static size_t hpgs_ostream_write (const void *ptr, size_t size, size_t nmemb, hpgs_ostream *_this); 539/*! The counterpart of ANSI fflush for \c hpgs_ostream. */ 540static int hpgs_ostream_flush (hpgs_ostream *_this); 541/*! The counterpart of ANSI fclose for \c hpgs_ostream. 542 After calling this function, all allocated resources of the stream are freed. */ 543static int hpgs_ostream_close (hpgs_ostream *_this); 544/*! The counterpart of ANSI ferror for \c hpgs_ostream. */ 545static int hpgs_ostream_iserror(hpgs_ostream *_this); 546/*! Get the buffer of a \c hpgs_ostream. This function should only be called 547 after \c hpgs_ostream_flush. */ 548static hpgs_istream *hpgs_ostream_getbuf(hpgs_ostream *_this); 549/*! The counterpart of ANSI ftell for \c hpgs_ostream. */ 550static int hpgs_ostream_tell(hpgs_ostream *_this, int layer, size_t *pos); 551/*! The counterpart of ANSI fseek for \c hpgs_ostream. */ 552static int hpgs_ostream_seek (hpgs_ostream *_this, size_t pos); 553 554__inline__ int hpgs_ostream_putc (int c, hpgs_ostream *_this) 555{ return _this->vtable->putc_func(c,_this->stream); } 556 557__inline__ size_t hpgs_ostream_write (const void *ptr, size_t size, size_t nmemb, hpgs_ostream *_this) 558{ return _this->vtable->write_func(ptr,size,nmemb,_this->stream); } 559 560__inline__ int hpgs_ostream_flush (hpgs_ostream *_this) 561{ return _this->vtable->flush_func ? _this->vtable->flush_func(_this->stream) : 0; } 562 563__inline__ int hpgs_ostream_close (hpgs_ostream *_this) 564{ int ret = _this->vtable->close_func(_this->stream); free(_this); return ret; } 565 566__inline__ int hpgs_ostream_iserror (hpgs_ostream *_this) 567{ return _this->vtable->iserror_func(_this->stream); } 568 569__inline__ hpgs_istream *hpgs_ostream_getbuf (hpgs_ostream *_this) 570{ return _this->vtable->getbuf_func ? _this->vtable->getbuf_func(_this->stream) : 0; } 571 572__inline__ int hpgs_ostream_tell(hpgs_ostream *_this, int layer, size_t *pos) 573{ return _this->vtable->tell_func ? _this->vtable->tell_func(_this->stream,layer,pos) : -1; } 574 575__inline__ int hpgs_ostream_seek (hpgs_ostream *_this, size_t pos) 576{ return _this->vtable->seek_func ? _this->vtable->seek_func(_this->stream,pos) : -1; } 577 578HPGS_API int hpgs_parse_papersize(const char *str, double *pt_width, double *pt_height); 579HPGS_API int hpgs_parse_length(const char *str, double *pt_length); 580 581/*! @} */ /* end of group base */ 582 583/*! @addtogroup device 584 * @{ 585 */ 586typedef struct hpgs_device_st hpgs_device; 587typedef struct hpgs_plotsize_device_st hpgs_plotsize_device; 588typedef struct hpgs_eps_device_st hpgs_eps_device; 589typedef struct hpgs_gs_device_st hpgs_gs_device; 590typedef struct hpgs_device_vtable_st hpgs_device_vtable; 591typedef struct hpgs_image_st hpgs_image; 592typedef struct hpgs_image_vtable_st hpgs_image_vtable; 593typedef struct hpgs_png_image_st hpgs_png_image; 594typedef struct hpgs_paint_device_st hpgs_paint_device; 595typedef struct hpgs_gstate_st hpgs_gstate; 596typedef struct hpgs_font_st hpgs_font; 597 598/*! \brief The vector graphics state. 599 600 This structure has a public alias \c hpgs_gstate and holds 601 the line attributes of a graphics state. 602 */ 603struct hpgs_gstate_st 604{ 605 hpgs_line_cap line_cap; 606 hpgs_line_join line_join; 607 hpgs_color color; 608 double miterlimit; 609 double linewidth; 610 611 int rop3; 612 hpgs_bool src_transparency; 613 hpgs_bool pattern_transparency; 614 615 hpgs_color pattern_color; 616 617 int n_dashes; 618 float *dash_lengths; 619 double dash_offset; 620}; 621 622HPGS_API hpgs_gstate *hpgs_new_gstate(void); 623HPGS_API void hpgs_gstate_destroy(hpgs_gstate *gstate); 624HPGS_API int hpgs_gstate_setdash(hpgs_gstate *gstate, 625 const float *, unsigned, double); 626 627 628#define HPGS_DEVICE_CAP_RASTER (1<<0) //!< This device is a raster device. 629#define HPGS_DEVICE_CAP_ANTIALIAS (1<<1) //!< This device supports anitaliasing. 630#define HPGS_DEVICE_CAP_VECTOR (1<<2) //!< This device is a true vector device. 631#define HPGS_DEVICE_CAP_MULTIPAGE (1<<3) //!< This device supports multiple pages. 632#define HPGS_DEVICE_CAP_PAGECOLLATION (1<<4) //!< This device is able to write multiple pages to a single file. 633#define HPGS_DEVICE_CAP_MULTISIZE (1<<5) //!< This device is able to cope with distinct sizes per page. 634#define HPGS_DEVICE_CAP_DRAWIMAGE (1<<6) //!< The device may draw an image. 635#define HPGS_DEVICE_CAP_NULLIMAGE (1<<7) //!< The device accepts a null image in drawimage. 636#define HPGS_DEVICE_CAP_PLOTSIZE (1<<8) //!< This device is a plotsize device. 637#define HPGS_DEVICE_CAP_ROP3 (1<<9) //!< This device supports rop3 operations. 638 639/*! \brief A table of virtual function implementing \c hpgs_device. 640 641 This structure has a public alias \c hpgs_device_vtable and 642 represents a table of functions for a specific implementation 643 of \c hpgs_device. 644 645 The function names are deliberately similar to the corresponding 646 functions of the PostScript programming language. 647 */ 648struct hpgs_device_vtable_st { 649 const char * rtti; 650 int (*moveto) (hpgs_device *_this, const hpgs_point *p); 651 int (*lineto) (hpgs_device *_this, const hpgs_point *p); 652 int (*curveto) (hpgs_device *_this, const hpgs_point *p1, 653 const hpgs_point *p2, const hpgs_point *p3 ); 654 int (*newpath) (hpgs_device *_this); 655 int (*closepath) (hpgs_device *_this); 656 int (*stroke) (hpgs_device *_this); 657 int (*fill) (hpgs_device *_this, hpgs_bool winding); 658 int (*clip) (hpgs_device *_this, hpgs_bool winding); 659 int (*clipsave) (hpgs_device *_this); 660 int (*cliprestore) (hpgs_device *_this); 661 int (*setrgbcolor) (hpgs_device *_this, const hpgs_color *rgb); 662 int (*setdash) (hpgs_device *_this, const float *, unsigned, double); 663 int (*setlinewidth)(hpgs_device *_this, double); 664 int (*setlinecap) (hpgs_device *_this, hpgs_line_cap); 665 int (*setlinejoin) (hpgs_device *_this, hpgs_line_join); 666 int (*setmiterlimit) (hpgs_device *_this, double l); 667 int (*setrop3) (hpgs_device *_this, int rop, 668 hpgs_bool src_transparency, hpgs_bool pattern_transparency); 669 int (*setpatcol) (hpgs_device *_this, const hpgs_color *rgb); 670 int (*drawimage) (hpgs_device *_this, const hpgs_image *img, 671 const hpgs_point *ll, const hpgs_point *lr, 672 const hpgs_point *ur); 673 int (*setplotsize) (hpgs_device *_this, const hpgs_bbox *bb); 674 int (*getplotsize) (hpgs_device *_this, int i, hpgs_bbox *bb); 675 int (*showpage) (hpgs_device *_this, int i); 676 int (*finish) (hpgs_device *_this); 677 int (*capabilities)(hpgs_device *_this); 678 void (*destroy) (hpgs_device *_this); 679}; 680 681/*! \brief A virtual vector graphics device for the HPGL reader. 682 683 This structure has a public alias \c hpgs_device and 684 represents an abstract vector drawing device consisting of 685 a pointer to a table of virtual functions 686 implementing the device. 687 688 */ 689struct hpgs_device_st { 690 hpgs_device_vtable *vtable; 691}; 692 693#define HPGS_BASE_CLASS(d) (&(d->inherited)) 694 695HPGS_API hpgs_plotsize_device *hpgs_new_plotsize_device(hpgs_bool ignore_ps, 696 hpgs_bool do_linewidth); 697 698HPGS_API hpgs_eps_device *hpgs_new_eps_device(const char *filename, 699 const hpgs_bbox *bb, 700 hpgs_bool do_rop3 ); 701 702HPGS_API hpgs_eps_device *hpgs_new_ps_device(const char *filename, 703 const hpgs_bbox *bb, 704 hpgs_bool do_rop3); 705 706typedef int (*hpgs_reader_asset_func_t)(void *, hpgs_device *, 707 const hpgs_matrix *, 708 const hpgs_matrix *, 709 const hpgs_bbox *, int); 710 711HPGS_API int hpgs_new_plugin_device( hpgs_device **device, 712 void **page_asset_ctxt, 713 hpgs_reader_asset_func_t *page_asset_func, 714 void **frame_asset_ctxt, 715 hpgs_reader_asset_func_t *frame_asset_func, 716 const char *dev_name, 717 const char *filename, 718 const hpgs_bbox *bb, 719 double xres, double yres, 720 hpgs_bool do_rop3, 721 int argc, const char *argv[]); 722 723HPGS_API const char *hpgs_device_rtti(hpgs_device *_this); 724 725/*! PostScript moveto on the device. */ 726static int hpgs_moveto (hpgs_device *_this, const hpgs_point *p); 727/*! PostScript lineto on the device. */ 728static int hpgs_lineto (hpgs_device *_this, const hpgs_point *p); 729/*! PostScript curveto on the device. */ 730static int hpgs_curveto (hpgs_device *_this, const hpgs_point *p1, 731 const hpgs_point *p2, const hpgs_point *p3 ); 732/*! PostScript closepath on the device. */ 733static int hpgs_closepath (hpgs_device *_this); 734/*! PostScript newpath on the device. */ 735static int hpgs_newpath (hpgs_device *_this); 736/*! PostScript stroke on the device. */ 737static int hpgs_stroke (hpgs_device *_this); 738/*! PostScript fill/eofill on the device. 739 If \c winding is \c HPGS_TRUE we issue \c fill, otherwise \c eofill. */ 740static int hpgs_fill (hpgs_device *_this, hpgs_bool winding); 741/*! PostScript clip/eoclip on the device. 742 If \c winding is \c HPGS_TRUE we issue \c clip, otherwise \c eoclip. */ 743static int hpgs_clip (hpgs_device *_this, hpgs_bool winding); 744/*! Save the clip state onto the clip stack. Unlike PostScripts \c gsave 745 the line attributes and colors of the graphics state are not saved. */ 746static int hpgs_clipsave (hpgs_device *_this); 747/*! Restores the last clip state from the clip stack. */ 748static int hpgs_cliprestore (hpgs_device *_this); 749/*! PostScript setrgbcolor on the device. */ 750static int hpgs_setrgbcolor (hpgs_device *_this, const hpgs_color *rgb); 751/*! PostScript setdash on the device. */ 752static int hpgs_setdash (hpgs_device *_this, const float *d, 753 unsigned nd, double s); 754/*! PostScript setlinewidth on the device. */ 755static int hpgs_setlinewidth(hpgs_device *_this, double w); 756/*! PostScript setlinecap on the device. */ 757static int hpgs_setlinecap (hpgs_device *_this, hpgs_line_cap c); 758/*! PostScript setlinejoin on the device. */ 759static int hpgs_setlinejoin (hpgs_device *_this, hpgs_line_join j); 760/*! PostScript setmiterlimit on the device. */ 761static int hpgs_setmiterlimit (hpgs_device *_this, double l); 762/*! Get the device capabilities. */ 763static int hpgs_device_capabilities (hpgs_device *_this); 764 765HPGS_API int hpgs_setrop3 (hpgs_device *_this, int rop, 766 hpgs_bool src_transparency, hpgs_bool pattern_transparency); 767HPGS_API int hpgs_setpatcol (hpgs_device *_this, const hpgs_color *rgb); 768 769HPGS_API int hpgs_drawimage(hpgs_device *_this, const hpgs_image *img, 770 const hpgs_point *ll, const hpgs_point *lr, 771 const hpgs_point *ur); 772 773HPGS_API int hpgs_setplotsize (hpgs_device *_this, const hpgs_bbox *bb); 774HPGS_API int hpgs_getplotsize (hpgs_device *_this, int i, hpgs_bbox *bb); 775HPGS_API int hpgs_showpage (hpgs_device *_this, int i); 776HPGS_API int hpgs_device_finish (hpgs_device *_this); 777HPGS_API void hpgs_device_destroy (hpgs_device *_this); 778 779__inline__ int hpgs_moveto (hpgs_device *_this, const hpgs_point *p) 780{ return _this->vtable->moveto(_this,p); } 781 782__inline__ int hpgs_lineto (hpgs_device *_this, const hpgs_point *p) 783{ return _this->vtable->lineto(_this,p); } 784 785__inline__ int hpgs_curveto (hpgs_device *_this, const hpgs_point *p1, 786 const hpgs_point *p2, const hpgs_point *p3 ) 787{ return _this->vtable->curveto(_this,p1,p2,p3); } 788 789__inline__ int hpgs_closepath (hpgs_device *_this) 790{ return _this->vtable->closepath(_this); } 791 792__inline__ int hpgs_newpath (hpgs_device *_this) 793{ return _this->vtable->newpath(_this); } 794 795__inline__ int hpgs_stroke (hpgs_device *_this) 796{ return _this->vtable->stroke(_this); } 797 798__inline__ int hpgs_fill (hpgs_device *_this, hpgs_bool winding) 799{ return _this->vtable->fill(_this,winding); } 800 801__inline__ int hpgs_clip (hpgs_device *_this, hpgs_bool winding) 802{ return _this->vtable->clip(_this,winding); } 803 804__inline__ int hpgs_clipsave (hpgs_device *_this) 805{ return _this->vtable->clipsave(_this); } 806 807__inline__ int hpgs_cliprestore (hpgs_device *_this) 808{ return _this->vtable->cliprestore(_this); } 809 810__inline__ int hpgs_setrgbcolor (hpgs_device *_this, const hpgs_color *rgb) 811{ return _this->vtable->setrgbcolor ? _this->vtable->setrgbcolor(_this,rgb) : 0; } 812 813__inline__ int hpgs_setdash (hpgs_device *_this, const float *d, 814 unsigned nd, double s) 815{ return _this->vtable->setdash ? _this->vtable->setdash(_this,d,nd,s) : 0; } 816 817__inline__ int hpgs_setlinewidth(hpgs_device *_this, double w) 818{ return _this->vtable->setlinewidth ? _this->vtable->setlinewidth(_this,w) : 0; } 819 820__inline__ int hpgs_setlinecap (hpgs_device *_this, hpgs_line_cap c) 821{ return _this->vtable->setlinecap ? _this->vtable->setlinecap(_this,c) : 0; } 822 823__inline__ int hpgs_setlinejoin (hpgs_device *_this, hpgs_line_join j) 824{ return _this->vtable->setlinejoin ? _this->vtable->setlinejoin(_this,j) : 0; } 825 826__inline__ int hpgs_setmiterlimit (hpgs_device *_this, double l) 827{ return _this->vtable->setmiterlimit ? _this->vtable->setmiterlimit(_this,l) : 0; } 828 829__inline__ int hpgs_device_capabilities (hpgs_device *_this) 830{ return _this->vtable->capabilities(_this); } 831 832/*! @} */ /* end of group device */ 833 834/*! @addtogroup reader 835 * @{ 836 */ 837typedef struct hpgs_reader_st hpgs_reader; 838 839HPGS_API hpgs_reader *hpgs_new_reader(hpgs_istream *in, hpgs_device *dev, 840 hpgs_bool multipage, int v); 841 842HPGS_API void hpgs_reader_set_lw_factor(hpgs_reader *reader, double lw_factor); 843 844HPGS_API void hpgs_reader_set_fixed_page(hpgs_reader *reader, 845 hpgs_bbox *bbox, 846 double page_width, 847 double page_height, 848 double border, 849 double angle ); 850 851HPGS_API void hpgs_reader_set_dynamic_page(hpgs_reader *reader, 852 hpgs_bbox *bbox, 853 double max_page_width, 854 double max_page_height, 855 double border, 856 double angle ); 857 858HPGS_API void hpgs_reader_set_page_asset_func(hpgs_reader *reader, 859 void * ctxt, 860 hpgs_reader_asset_func_t func); 861 862HPGS_API void hpgs_reader_set_frame_asset_func(hpgs_reader *reader, 863 void * ctxt, 864 hpgs_reader_asset_func_t func); 865 866HPGS_API void hpgs_reader_interrupt(hpgs_reader *reader); 867HPGS_API int hpgs_reader_get_current_pen(hpgs_reader *reader); 868 869HPGS_API int hpgs_reader_imbue(hpgs_reader *reader, hpgs_device *dev); 870HPGS_API int hpgs_reader_attach(hpgs_reader *reader, hpgs_istream *in); 871HPGS_API int hpgs_reader_stamp(hpgs_reader *reader, 872 const hpgs_bbox *bb, 873 const char *stamp, const char *encoding, 874 double stamp_size); 875 876HPGS_API int hpgs_device_stamp(hpgs_device *dev, 877 const hpgs_bbox *bb, 878 const char *stamp, const char *encoding, 879 double stamp_size); 880 881HPGS_API int hpgs_reader_set_png_dump(hpgs_reader *reader, const char *filename); 882HPGS_API int hpgs_read(hpgs_reader *reader, hpgs_bool finish); 883HPGS_API void hpgs_destroy_reader(hpgs_reader *reader); 884 885/*! @} */ /* end of group reader */ 886 887/*! @addtogroup font 888 * @{ 889 */ 890 891HPGS_API hpgs_font *hpgs_find_font(const char *name); 892HPGS_API void hpgs_destroy_font(hpgs_font *font); 893HPGS_API double hpgs_font_get_ascent(hpgs_font *font); 894HPGS_API double hpgs_font_get_descent(hpgs_font *font); 895HPGS_API double hpgs_font_get_line_gap(hpgs_font *font); 896HPGS_API double hpgs_font_get_cap_height(hpgs_font *font); 897HPGS_API unsigned hpgs_font_get_glyph_count(hpgs_font *font); 898HPGS_API unsigned hpgs_font_get_glyph_id(hpgs_font *font, int uc); 899HPGS_API const char *hpgs_font_get_glyph_name(hpgs_font *font, unsigned gid); 900HPGS_API int hpgs_font_get_glyph_bbox(hpgs_font *font, hpgs_bbox *bb, unsigned gid); 901HPGS_API int hpgs_font_get_glyph_metrics(hpgs_font *font, hpgs_point *m, unsigned gid); 902HPGS_API int hpgs_font_get_kern_metrics(hpgs_font *font, hpgs_point *m, unsigned gid_l, unsigned gid_r); 903HPGS_API int hpgs_font_get_utf8_metrics(hpgs_font *font, hpgs_point *m, const char *str, int strlen); 904 905typedef int (*hpgs_moveto_func_t) (void *ctxt, const hpgs_point *p); 906typedef int (*hpgs_lineto_func_t) (void *ctxt, const hpgs_point *p); 907typedef int (*hpgs_curveto_func_t) (void *ctxt, const hpgs_point *p1, const hpgs_point *p2, const hpgs_point *p3); 908typedef int (*hpgs_fill_func_t) (void *ctxt, hpgs_bool winding); 909 910HPGS_API int hpgs_font_decompose_glyph(hpgs_font *font, 911 void *ctxt, 912 hpgs_moveto_func_t moveto_func, 913 hpgs_lineto_func_t lineto_func, 914 hpgs_curveto_func_t curveto_func, 915 const hpgs_matrix *m, 916 unsigned gid); 917 918HPGS_API int hpgs_font_draw_glyph(hpgs_font *font, 919 hpgs_device *device, 920 const hpgs_matrix *m, 921 unsigned gid); 922 923HPGS_API int hpgs_font_decompose_utf8(hpgs_font *font, 924 void *ctxt, 925 hpgs_moveto_func_t moveto_func, 926 hpgs_lineto_func_t lineto_func, 927 hpgs_curveto_func_t curveto_func, 928 hpgs_fill_func_t fill_func, 929 const hpgs_matrix *m, 930 const char *str, int strlen); 931 932HPGS_API int hpgs_font_draw_utf8(hpgs_font *font, 933 hpgs_device *device, 934 const hpgs_matrix *m, 935 const char *str, int strlen); 936 937/*! @} */ /* end of group font */ 938 939/*! @addtogroup image 940 * @{ 941 */ 942 943/*! \brief A table of virtual function implementing \c hpgs_image. 944 945 This structure has a public alias \c hpgs_image_vtable and 946 represents a table of functions for a specific implementation 947 of \c hpgs_image. 948 */ 949struct hpgs_image_vtable_st { 950 int (*get_pixel) (const hpgs_image *_this, 951 int x, int y, hpgs_paint_color *c, double *alpha); 952 int (*put_pixel) (hpgs_image *_this, 953 int x, int y, const hpgs_paint_color *c, double alpha); 954 int (*put_chunk) (hpgs_image *_this, 955 int x1, int x2, int y, const hpgs_paint_color *c); 956 int (*rop3_pixel) (hpgs_image *_this, 957 int x, int y, const hpgs_paint_color *c, double alpha); 958 int (*rop3_chunk) (hpgs_image *_this, 959 int x1, int x2, int y, const hpgs_paint_color *c); 960 int (*setrop3) (hpgs_image *_this, hpgs_rop3_func_t rop3); 961 int (*setpatcol) (hpgs_image *_this, const hpgs_palette_color *p); 962 int (*resize) (hpgs_image *_this, int w, int h); 963 int (*set_resolution)(hpgs_image *pim, double x_dpi, double y_dpi); 964 int (*clear) (hpgs_image *_this); 965 int (*write) (hpgs_image *_this, const char *filename); 966 int (*get_data) (hpgs_image *_this, unsigned char **data, int *stride, int *depth); 967 void (*destroy) (hpgs_image *_this); 968}; 969 970/*! \brief An abstract pixel image. 971 972 This structure has a public alias \c hpgs_image and 973 represents a rectangular pixel container, which tradiationally 974 is called an image. 975 976 Nevertheless, implementations for drawing to a window system 977 may be provided in the future. 978 */ 979struct hpgs_image_st { 980 hpgs_image_vtable *vtable; //!< The virtual table. 981 int width; //!< The number of pixel columns. 982 int height; //!< The number of pixel rows. 983 984 hpgs_palette_color *palette; //!< The palette for indexed images. 985 unsigned *palette_idx; //!< a compacted rgb color index. 986 int palette_ncolors; //!< The number of colors in the palette. 987}; 988 989HPGS_API int hpgs_image_define_color_func (hpgs_image *image, hpgs_paint_color *c); 990 991static int hpgs_image_define_color (hpgs_image *image, hpgs_paint_color *c); 992 993/*! Enter the supplied rgb value to the palette of an indexed image. 994 Set the index member of \c c to the palette index of the 995 RGB triplet. 996 997 If the palette is exhausted, -1 is returned. 998 */ 999__inline__ int hpgs_image_define_color (hpgs_image *image, hpgs_paint_color *c) 1000{ 1001 if (image->palette) return hpgs_image_define_color_func (image,c); else return 0; 1002} 1003 1004HPGS_API int hpgs_image_set_palette (hpgs_image *image, 1005 hpgs_palette_color *p, int np); 1006 1007HPGS_API hpgs_png_image *hpgs_new_png_image(int width, int height, 1008 int depth, hpgs_bool palette, 1009 hpgs_bool do_rop3); 1010 1011HPGS_API int hpgs_png_image_set_compression(hpgs_png_image *pim, int compression); 1012 1013HPGS_API int hpgs_image_set_resolution(hpgs_image *pim, double x_dpi, double y_dpi); 1014 1015HPGS_API int hpgs_image_get_data(hpgs_image *_this, 1016 unsigned char **data, int *stride, 1017 int *depth); 1018 1019/*! Retrieves the color and alpha value of the pixel 1020 in column \c x and row \c y. */ 1021static int hpgs_image_get_pixel (const hpgs_image *_this, 1022 int x, int y, 1023 hpgs_paint_color *c, double *alpha); 1024/*! Sets the color and alpha value of the pixel 1025 in column \c x and row \c y. */ 1026static int hpgs_image_put_pixel (hpgs_image *_this, 1027 int x, int y, 1028 const hpgs_paint_color *c, double alpha); 1029/*! Sets the color of all pixels 1030 in the columns \c x1 up to \c x2 in row \c y. 1031 The alpha value is set to 1. */ 1032static int hpgs_image_put_chunk (hpgs_image *_this, 1033 int x1, int x2, int y, const hpgs_paint_color *c); 1034 1035/*! Sets the color and alpha value of the pixel 1036 in column \c x and row \c y. This function applies a ROP3 1037 operation, if supported by the image. 1038 */ 1039static int hpgs_image_rop3_pixel (hpgs_image *_this, 1040 int x, int y, 1041 const hpgs_paint_color *c, double alpha); 1042/*! Sets the color of all pixels 1043 in the columns \c x1 up to \c x2 in row \c y. 1044 The alpha value is set to 1. This function applies a ROP3 1045 operation, if supported by the image. 1046 */ 1047static int hpgs_image_rop3_chunk (hpgs_image *_this, 1048 int x1, int x2, int y, const hpgs_paint_color *c); 1049 1050HPGS_API int hpgs_image_resize (hpgs_image *_this, int w, int h); 1051HPGS_API int hpgs_image_clear (hpgs_image *_this); 1052HPGS_API int hpgs_image_write (hpgs_image *_this, const char *filename); 1053HPGS_API int hpgs_image_setrop3 (hpgs_image *_this, hpgs_rop3_func_t rop3); 1054HPGS_API int hpgs_image_setpatcol (hpgs_image *_this, const hpgs_palette_color *p); 1055 1056HPGS_API void hpgs_image_destroy (hpgs_image *_this); 1057 1058__inline__ int hpgs_image_get_pixel (const hpgs_image *_this, 1059 int x, int y, 1060 hpgs_paint_color *c, double *alpha) 1061{ return _this->vtable->get_pixel(_this,x,y,c,alpha); } 1062 1063__inline__ int hpgs_image_put_pixel (hpgs_image *_this, 1064 int x, int y, 1065 const hpgs_paint_color *c, double alpha) 1066{ return _this->vtable->put_pixel(_this,x,y,c,alpha); } 1067 1068__inline__ int hpgs_image_put_chunk (hpgs_image *_this, 1069 int x1, int x2, int y, const hpgs_paint_color *c) 1070{ return _this->vtable->put_chunk(_this,x1,x2,y,c); } 1071 1072__inline__ int hpgs_image_rop3_pixel (hpgs_image *_this, 1073 int x, int y, 1074 const hpgs_paint_color *c, double alpha) 1075{ return _this->vtable->rop3_pixel(_this,x,y,c,alpha); } 1076 1077__inline__ int hpgs_image_rop3_chunk (hpgs_image *_this, 1078 int x1, int x2, int y, const hpgs_paint_color *c) 1079{ return _this->vtable->rop3_chunk(_this,x1,x2,y,c); } 1080 1081HPGS_API int hpgs_image_rop3_clip(hpgs_device *device, 1082 hpgs_palette_color *data, 1083 const hpgs_image *img, 1084 const hpgs_point *ll, const hpgs_point *lr, 1085 const hpgs_point *ur, 1086 const hpgs_palette_color *p, 1087 hpgs_xrop3_func_t xrop3); 1088 1089/*! @} */ /* end of group image */ 1090 1091/*! @addtogroup path 1092 * @{ 1093 */ 1094 1095typedef struct hpgs_path_point_st hpgs_path_point; 1096typedef struct hpgs_paint_path_st hpgs_paint_path; 1097 1098#define HPGS_POINT_ROLE_MASK 0xF //!< A mask for retrieving the role of a point in the path 1099#define HPGS_POINT_UNDEFINED 0x0 //!< point is undefined 1100#define HPGS_POINT_LINE 0x1 //!< start of line 1101#define HPGS_POINT_BEZIER 0x2 //!< start of bezier curve 1102#define HPGS_POINT_CONTROL 0x3 //!< bezier control point 1103#define HPGS_POINT_FILL_LINE 0x4 //!< line fill only (implicit closepath) 1104#define HPGS_POINT_DOT 0x8 //!< indicates a moveto/lineto with the same coordinates at the start of a subpath. 1105 1106#define HPGS_POINT_SUBPATH_START 0x10 //!< a subpath starts at this point 1107#define HPGS_POINT_SUBPATH_END 0x20 //!< a subpath ends at this point 1108#define HPGS_POINT_SUBPATH_CLOSE 0x40 //!< indicates an explicit closepath at the end of a subpath 1109 1110/*! \brief A point in a stored path. 1111 1112 This structure has a public alias \c hpgs_path_point and 1113 represents a point of a polygonal path. 1114 */ 1115struct hpgs_path_point_st 1116{ 1117 hpgs_point p; /*!< Coordinates of this path point. */ 1118 int flags; /*!< Flags for this path point. */ 1119}; 1120 1121/*! \brief A stored vector path. 1122 1123 This structure has a public alias \c hpgs_paint_path and 1124 represents a polygonal path, which is stores the path topology 1125 together with cached informations about bezier splines. 1126 */ 1127struct hpgs_paint_path_st 1128{ 1129 /*@{ */ 1130 /*! A stack of path points. 1131 \c last_start indicates the index of the last start of a subpolygon. 1132 This is information is needed during path construction. 1133 */ 1134 hpgs_path_point *points; 1135 int n_points; 1136 int last_start; 1137 int points_malloc_size; 1138 /*@} */ 1139 1140 hpgs_bbox bb; /*! The bounding box of this path. */ 1141}; 1142 1143HPGS_API hpgs_paint_path *hpgs_new_paint_path(void); 1144HPGS_API void hpgs_paint_path_destroy(hpgs_paint_path *_this); 1145HPGS_API void hpgs_paint_path_truncate(hpgs_paint_path *_this); 1146 1147HPGS_API int hpgs_paint_path_moveto(hpgs_paint_path *_this, 1148 const hpgs_point *p ); 1149 1150HPGS_API int hpgs_paint_path_lineto(hpgs_paint_path *_this, 1151 const hpgs_point *p ); 1152 1153HPGS_API int hpgs_paint_path_curveto(hpgs_paint_path *_this, 1154 const hpgs_point *p1, 1155 const hpgs_point *p2, 1156 const hpgs_point *p3 ); 1157 1158HPGS_API int hpgs_paint_path_closepath(hpgs_paint_path *_this); 1159 1160HPGS_API int hpgs_paint_path_buldgeto(hpgs_paint_path *_this, 1161 const hpgs_point *p, 1162 double buldge); 1163 1164HPGS_API hpgs_paint_path *hpgs_paint_path_stroke_path(const hpgs_paint_path *_this, 1165 const hpgs_gstate *gstate); 1166 1167HPGS_API hpgs_paint_path *hpgs_paint_path_decompose_dashes(const hpgs_paint_path *_this, 1168 const hpgs_gstate *gstate); 1169 1170HPGS_API double hpgs_bezier_path_x (const hpgs_paint_path *path, int i, double t); 1171HPGS_API double hpgs_bezier_path_y (const hpgs_paint_path *path, int i, double t); 1172HPGS_API double hpgs_bezier_path_delta_x (const hpgs_paint_path *path, int i, double t); 1173HPGS_API double hpgs_bezier_path_delta_y (const hpgs_paint_path *path, int i, double t); 1174 1175HPGS_API double hpgs_bezier_path_xmin (const hpgs_paint_path *path, int i); 1176HPGS_API double hpgs_bezier_path_xmax (const hpgs_paint_path *path, int i); 1177HPGS_API double hpgs_bezier_path_ymin (const hpgs_paint_path *path, int i); 1178HPGS_API double hpgs_bezier_path_ymax (const hpgs_paint_path *path, int i); 1179 1180HPGS_API void hpgs_bezier_path_point(const hpgs_paint_path *path, int i, 1181 double t, hpgs_point *p); 1182 1183HPGS_API void hpgs_bezier_path_delta(const hpgs_paint_path *path, int i, 1184 double t, hpgs_point *p); 1185 1186HPGS_API void hpgs_bezier_path_tangent(const hpgs_paint_path *path, int i, 1187 double t, int orientation, 1188 double ytol, 1189 hpgs_point *p); 1190 1191HPGS_API void hpgs_bezier_path_singularities(const hpgs_paint_path *path, int i, 1192 double t0, double t1, 1193 int *nx, double *tx); 1194 1195HPGS_API void hpgs_bezier_path_to_quadratic(const hpgs_paint_path *path, int i, 1196 double t0, double t1, 1197 int *nx, hpgs_point *points); 1198 1199/*! @} */ /* end of group path */ 1200 1201/*! @addtogroup paint_device 1202 * @{ 1203 */ 1204HPGS_API hpgs_paint_device *hpgs_new_paint_device(hpgs_image *image, 1205 const char *filename, 1206 const hpgs_bbox *bb, 1207 hpgs_bool antialias); 1208 1209HPGS_API void hpgs_paint_device_set_image_interpolation (hpgs_paint_device *pdv, int i); 1210HPGS_API void hpgs_paint_device_set_thin_alpha (hpgs_paint_device *pdv, double a); 1211 1212/*! @} */ /* end of group paint_device */ 1213 1214#ifdef __cplusplus 1215} // end of extern "C" 1216#endif 1217 1218#endif /* ! __HPGS_H */ 1219