63 #include <sys/types.h>
68 #if defined(GL2PS_HAVE_ZLIB)
72 #if defined(GL2PS_HAVE_LIBPNG)
85 #define GL2PS_EPSILON 5.0e-3F
86 #define GL2PS_ZSCALE 1000.0F
87 #define GL2PS_ZOFFSET 5.0e-2F
88 #define GL2PS_ZOFFSET_LARGE 20.0F
89 #define GL2PS_ZERO(arg) (fabs(arg) < 1.e-20)
93 #define GL2PS_NO_TYPE -1
97 #define GL2PS_QUADRANGLE 4
98 #define GL2PS_TRIANGLE 5
99 #define GL2PS_PIXMAP 6
100 #define GL2PS_IMAGEMAP 7
101 #define GL2PS_IMAGEMAP_WRITTEN 8
102 #define GL2PS_IMAGEMAP_VISIBLE 9
103 #define GL2PS_SPECIAL 10
107 #define GL2PS_COINCIDENT 1
108 #define GL2PS_IN_FRONT_OF 2
109 #define GL2PS_IN_BACK_OF 3
110 #define GL2PS_SPANNING 4
114 #define GL2PS_POINT_COINCIDENT 0
115 #define GL2PS_POINT_INFRONT 1
116 #define GL2PS_POINT_BACK 2
120 #define GL2PS_BEGIN_OFFSET_TOKEN 1
121 #define GL2PS_END_OFFSET_TOKEN 2
122 #define GL2PS_BEGIN_BOUNDARY_TOKEN 3
123 #define GL2PS_END_BOUNDARY_TOKEN 4
124 #define GL2PS_BEGIN_STIPPLE_TOKEN 5
125 #define GL2PS_END_STIPPLE_TOKEN 6
126 #define GL2PS_POINT_SIZE_TOKEN 7
127 #define GL2PS_LINE_WIDTH_TOKEN 8
128 #define GL2PS_BEGIN_BLEND_TOKEN 9
129 #define GL2PS_END_BLEND_TOKEN 10
130 #define GL2PS_SRC_BLEND_TOKEN 11
131 #define GL2PS_DST_BLEND_TOKEN 12
132 #define GL2PS_IMAGEMAP_TOKEN 13
133 #define GL2PS_DRAW_PIXELS_TOKEN 14
134 #define GL2PS_TEXT_TOKEN 15
150 struct _GL2PSbsptree2d {
156 GLint nmax, size, incr,
n;
162 struct _GL2PSbsptree {
164 GL2PSlist *primitives;
174 GL2PSvertex vertex[3];
180 char *str, *fontname;
188 GLsizei width, height;
198 struct _GL2PSimagemap {
204 GLshort
type, numverts;
206 char boundary,
offset, culled;
217 #if defined(GL2PS_HAVE_ZLIB)
219 uLongf destLen, srcLen;
227 int gsno, fontno, imno, shno, maskshno, trgroupno;
228 int gsobjno, fontobjno, imobjno, shobjno, maskshobjno, trgroupobjno;
233 GLint
format, sort, options, colorsize, colormode, buffersize;
235 GLboolean boundary, blending;
236 GLfloat *feedback,
offset[2], lastlinewidth;
237 GLint viewport[4], blendfunc[2], lastfactor;
238 GL2PSrgba *colormap, lastrgba, threshold, bgcolor;
239 GLushort lastpattern;
240 GL2PSvertex lastvertex;
241 GL2PSlist *primitives, *auxprimitives;
243 GL2PScompress *compress;
250 GLboolean zerosurfacearea;
252 GL2PSprimitive *primitivetoadd;
256 GL2PSlist *pdfprimlist, *pdfgrouplist;
262 int trgroupobjects_stack;
274 void (*beginViewport)(GLint viewport[4]);
275 GLint (*endViewport)(
void);
276 void (*printPrimitive)(
void *data);
278 const char *file_extension;
279 const char *description;
297 static void gl2psMsg(GLint level,
const char *fmt, ...)
303 case GL2PS_INFO : fprintf(stderr,
"GL2PS info: ");
break;
304 case GL2PS_WARNING : fprintf(stderr,
"GL2PS warning: ");
break;
305 case GL2PS_ERROR : fprintf(stderr,
"GL2PS error: ");
break;
308 vfprintf(stderr, fmt, args);
310 fprintf(stderr,
"\n");
319 if(!size)
return(
NULL);
330 if(!size)
return(
NULL);
331 ptr = realloc(ptr, size);
348 size_t size =
sizeof(
unsigned long);
349 for(i = 1; i <= bytes; ++i){
350 fputc(0xff & (data >> (size-i) * 8), gl2ps->stream);
357 #if defined(GL2PS_HAVE_ZLIB)
359 static void gl2psSetupCompress(
void)
361 gl2ps->compress = (GL2PScompress*)
gl2psMalloc(
sizeof(GL2PScompress));
362 gl2ps->compress->src =
NULL;
363 gl2ps->compress->start =
NULL;
364 gl2ps->compress->dest =
NULL;
365 gl2ps->compress->srcLen = 0;
366 gl2ps->compress->destLen = 0;
369 static void gl2psFreeCompress(
void)
375 gl2ps->compress->src =
NULL;
376 gl2ps->compress->start =
NULL;
377 gl2ps->compress->dest =
NULL;
378 gl2ps->compress->srcLen = 0;
379 gl2ps->compress->destLen = 0;
382 static int gl2psAllocCompress(
unsigned int srcsize)
386 if(!gl2ps->compress || !srcsize)
389 gl2ps->compress->srcLen = srcsize;
390 gl2ps->compress->destLen = (int)
ceil(1.001 * gl2ps->compress->srcLen + 12);
391 gl2ps->compress->src = (Bytef*)
gl2psMalloc(gl2ps->compress->srcLen);
392 gl2ps->compress->start = gl2ps->compress->src;
393 gl2ps->compress->dest = (Bytef*)
gl2psMalloc(gl2ps->compress->destLen);
398 static void *gl2psReallocCompress(
unsigned int srcsize)
400 if(!gl2ps->compress || !srcsize)
403 if(srcsize < gl2ps->compress->srcLen)
404 return gl2ps->compress->start;
406 gl2ps->compress->srcLen = srcsize;
407 gl2ps->compress->destLen = (int)
ceil(1.001 * gl2ps->compress->srcLen + 12);
408 gl2ps->compress->src = (Bytef*)
gl2psRealloc(gl2ps->compress->src,
409 gl2ps->compress->srcLen);
410 gl2ps->compress->start = gl2ps->compress->src;
411 gl2ps->compress->dest = (Bytef*)
gl2psRealloc(gl2ps->compress->dest,
412 gl2ps->compress->destLen);
414 return gl2ps->compress->start;
417 static size_t gl2psWriteBigEndianCompress(
unsigned long data,
size_t bytes)
420 size_t size =
sizeof(
unsigned long);
421 for(i = 1; i <= bytes; ++i){
422 *gl2ps->compress->src = (Bytef)(0xff & (data >> (size-i) * 8));
423 ++gl2ps->compress->src;
428 static int gl2psDeflate(
void)
432 return compress(gl2ps->compress->dest, &gl2ps->compress->destLen,
433 gl2ps->compress->start, gl2ps->compress->srcLen);
443 #if defined(GL2PS_HAVE_ZLIB)
444 unsigned int oldsize = 0;
445 static char buf[1000];
448 ret = vsprintf(buf, fmt, args);
450 oldsize = gl2ps->compress->srcLen;
451 gl2ps->compress->start = (Bytef*)gl2psReallocCompress(oldsize + ret);
452 memcpy(gl2ps->compress->start+oldsize, buf, ret);
458 ret = vfprintf(gl2ps->stream, fmt, args);
460 #if defined(GL2PS_HAVE_ZLIB)
468 #if defined(GL2PS_HAVE_ZLIB)
469 char tmp[10] = {
'\x1f',
'\x8b',
477 gl2psSetupCompress();
479 fwrite(tmp, 10, 1, gl2ps->stream);
486 #if defined(GL2PS_HAVE_ZLIB)
492 if(Z_OK != gl2psDeflate()){
498 if(gl2ps->compress->dest[1] & (1<<5)){
502 fwrite(gl2ps->compress->dest+n, gl2ps->compress->destLen-(n+4),
505 crc = crc32(0
L, gl2ps->compress->start, gl2ps->compress->srcLen);
506 for(n = 0; n < 4; ++
n){
507 tmp[
n] = (char)(crc & 0xff);
510 len = gl2ps->compress->srcLen;
511 for(n = 4; n < 8; ++
n){
512 tmp[
n] = (char)(len & 0xff);
515 fwrite(tmp, 8, 1, gl2ps->stream);
519 gl2ps->compress =
NULL;
535 list->array = (
char*)
gl2psMalloc(list->nmax * list->size);
539 list->nmax = ((n - 1) / list->incr + 1) * list->incr;
541 list->nmax * list->size);
551 if(incr <= 0) incr = 1;
583 memcpy(&list->array[(list->n - 1) * list->size], data, list->size);
599 if((index < 0) || (index >= list->n)){
603 return(&list->array[index * list->size]);
607 int (*fcmp)(
const void *
a,
const void *b))
611 qsort(list->array, list->n, list->size, fcmp);
632 #if defined(GL2PS_HAVE_LIBPNG)
634 static void gl2psListRead(GL2PSlist *list,
int index,
void *data)
636 if((index < 0) || (index >= list->n))
638 memcpy(data, &list->array[index * list->size], list->size);
641 static void gl2psEncodeBase64Block(
unsigned char in[3],
unsigned char out[4],
int len)
643 static const char cb64[] =
644 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
646 out[0] = cb64[ in[0] >> 2 ];
647 out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
648 out[2] = (len > 1) ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] :
'=';
649 out[3] = (len > 2) ? cb64[ in[2] & 0x3f ] :
'=';
652 static void gl2psListEncodeBase64(GL2PSlist *list)
654 unsigned char *
buffer, in[3], out[4];
655 int i,
n, index, len;
657 n = list->n * list->size;
658 buffer = (
unsigned char*)
gl2psMalloc(n *
sizeof(
unsigned char));
659 memcpy(buffer, list->array, n *
sizeof(
unsigned char));
665 for(i = 0; i < 3; i++) {
667 in[i] = buffer[index];
676 gl2psEncodeBase64Block(in, out, len);
677 for(i = 0; i < 4; i++)
701 for(i = 1; i < prim->numverts; i++){
714 if(n < 2)
return GL_TRUE;
716 for(i = 1; i <
n; i++){
717 if(
fabs(rgba[0][0] - rgba[i][0]) > threshold[0] ||
718 fabs(rgba[0][1] - rgba[i][1]) > threshold[1] ||
719 fabs(rgba[0][2] - rgba[i][2]) > threshold[2])
729 for(i = 0; i < 3; ++i){
730 gl2ps->lastrgba[i] = rgba[i];
735 GLfloat *red, GLfloat *green, GLfloat *blue)
738 GLsizei width = im->width;
739 GLsizei height = im->height;
740 GLfloat *pixels = im->pixels;
746 pimag = pixels + 4 * (width * (height - 1 -
y) + x);
750 pimag = pixels + 3 * (width * (height - 1 -
y) + x);
753 *red = *pimag; pimag++;
754 *green = *pimag; pimag++;
755 *blue = *pimag; pimag++;
757 return (im->format == GL_RGBA) ? *pimag : 1.0F;
767 image->width = im->width;
768 image->height = im->height;
769 image->format = im->format;
770 image->type = im->type;
772 switch(image->format){
774 size = image->height * image->width * 4 *
sizeof(GLfloat);
778 size = image->height * image->width * 3 *
sizeof(GLfloat);
783 memcpy(image->pixels, im->pixels, size);
796 #if defined(GL2PS_HAVE_LIBPNG)
798 #if !defined(png_jmpbuf)
799 # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
802 static void gl2psUserWritePNG(png_structp png_ptr, png_bytep data, png_size_t length)
805 GL2PSlist *png = (GL2PSlist*)png_get_io_ptr(png_ptr);
806 for(i = 0; i <
length; i++)
810 static void gl2psUserFlushPNG(png_structp png_ptr)
814 static void gl2psConvertPixmapToPNG(GL2PSimage *pixmap, GL2PSlist *png)
818 unsigned char *row_data;
822 if(!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL)))
825 if(!(info_ptr = png_create_info_struct(png_ptr))){
826 png_destroy_write_struct(&png_ptr,
NULL);
830 if(setjmp(png_jmpbuf(png_ptr))) {
831 png_destroy_write_struct(&png_ptr, &info_ptr);
835 png_set_write_fn(png_ptr, (
void *)png, gl2psUserWritePNG, gl2psUserFlushPNG);
836 png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
837 png_set_IHDR(png_ptr, info_ptr, pixmap->width, pixmap->height, 8,
838 PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
839 PNG_FILTER_TYPE_BASE);
840 png_write_info(png_ptr, info_ptr);
842 row_data = (
unsigned char*)
gl2psMalloc(3 * pixmap->width *
sizeof(
unsigned char));
843 for(row = 0; row < pixmap->height; row++){
844 for(col = 0; col < pixmap->width; col++){
846 row_data[3*col] = (
unsigned char)(255. * dr);
847 row_data[3*col+1] = (
unsigned char)(255. * dg);
848 row_data[3*col+2] = (
unsigned char)(255. * db);
850 png_write_row(png_ptr, (png_bytep)row_data);
854 png_write_end(png_ptr, info_ptr);
855 png_destroy_write_struct(&png_ptr, &info_ptr);
863 GLshort fontsize, GLint
alignment, GLfloat angle)
866 GL2PSprimitive *prim;
873 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
876 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
878 prim = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
882 prim->verts = (GL2PSvertex*)
gl2psMalloc(
sizeof(GL2PSvertex));
883 prim->verts[0].xyz[0] = pos[0];
884 prim->verts[0].xyz[1] = pos[1];
885 prim->verts[0].xyz[2] = pos[2];
891 glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba);
892 prim->data.text = (GL2PSstring*)
gl2psMalloc(
sizeof(GL2PSstring));
893 prim->data.text->str = (
char*)
gl2psMalloc((strlen(str)+1)*
sizeof(
char));
894 strcpy(prim->data.text->str, str);
895 prim->data.text->fontname = (
char*)
gl2psMalloc((strlen(fontname)+1)*
sizeof(char));
896 strcpy(prim->data.text->fontname, fontname);
897 prim->data.text->fontsize = fontsize;
899 prim->data.text->angle = angle;
910 text->str = (
char*)
gl2psMalloc((strlen(t->str)+1)*
sizeof(
char));
911 strcpy(text->str, t->str);
912 text->fontname = (
char*)
gl2psMalloc((strlen(t->fontname)+1)*
sizeof(char));
913 strcpy(text->fontname, t->fontname);
914 text->fontsize = t->fontsize;
915 text->alignment = t->alignment;
916 text->angle = t->angle;
937 if( (sfactor == GL_SRC_ALPHA && dfactor == GL_ONE_MINUS_SRC_ALPHA) ||
938 (sfactor == GL_ONE && dfactor == GL_ZERO) )
958 switch(gl2ps->blendfunc[0]){
988 if(!
GL2PS_ZERO(t->vertex[0].rgba[3] - t->vertex[1].rgba[3]) ||
989 !
GL2PS_ZERO(t->vertex[1].rgba[3] - t->vertex[2].rgba[3])){
993 if(t->vertex[0].rgba[3] < 1)
1001 GLboolean assignprops)
1003 t->vertex[0] = p->verts[0];
1004 t->vertex[1] = p->verts[1];
1005 t->vertex[2] = p->verts[2];
1006 if(GL_TRUE == assignprops)
1013 GL2PSvertex vertex = { {-1.0F, -1.0F, -1.0F}, {-1.0F, -1.0F, -1.0F, -1.0F} };
1014 for(i = 0; i < 3; i++)
1015 t->vertex[i] = vertex;
1023 GL2PSprimitive *prim;
1030 prim = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1032 prim->type = p->type;
1033 prim->numverts = p->numverts;
1034 prim->boundary = p->boundary;
1035 prim->offset = p->offset;
1036 prim->pattern = p->pattern;
1037 prim->factor = p->factor;
1038 prim->culled = p->culled;
1039 prim->width = p->width;
1040 prim->verts = (GL2PSvertex*)
gl2psMalloc(p->numverts*
sizeof(GL2PSvertex));
1041 memcpy(prim->verts, p->verts, p->numverts *
sizeof(GL2PSvertex));
1075 return(plane[0] * point[0] +
1076 plane[1] * point[1] +
1077 plane[2] * point[2] +
1083 return(a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);
1088 c[0] = a[1]*b[2] - a[2]*b[1];
1089 c[1] = a[2]*b[0] - a[0]*b[2];
1090 c[2] = a[0]*b[1] - a[1]*b[0];
1095 return (GLfloat)
sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
1119 GL2PSxyz
v = {0.0F, 0.0F, 0.0F},
w = {0.0F, 0.0F, 0.0F};
1124 v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0];
1125 v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1];
1126 v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2];
1127 w[0] = prim->verts[2].xyz[0] - prim->verts[0].xyz[0];
1128 w[1] = prim->verts[2].xyz[1] - prim->verts[0].xyz[1];
1129 w[2] = prim->verts[2].xyz[2] - prim->verts[0].xyz[2];
1132 plane[0] = plane[1] = 0.0F;
1134 plane[3] = -prim->verts[0].xyz[2];
1139 - plane[0] * prim->verts[0].xyz[0]
1140 - plane[1] * prim->verts[0].xyz[1]
1141 - plane[2] * prim->verts[0].xyz[2];
1145 v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0];
1146 v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1];
1147 v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2];
1149 plane[0] = plane[1] = 0.0F;
1151 plane[3] = -prim->verts[0].xyz[2];
1159 - plane[0] * prim->verts[0].xyz[0]
1160 - plane[1] * prim->verts[0].xyz[1]
1161 - plane[2] * prim->verts[0].xyz[2];
1169 plane[0] = plane[1] = 0.0F;
1171 plane[3] = -prim->verts[0].xyz[2];
1175 plane[0] = plane[1] = plane[3] = 0.0F;
1187 v[0] = b->xyz[0] - a->xyz[0];
1188 v[1] = b->xyz[1] - a->xyz[1];
1189 v[2] = b->xyz[2] - a->xyz[2];
1196 c->xyz[0] = a->xyz[0] + v[0] * sect;
1197 c->xyz[1] = a->xyz[1] + v[1] * sect;
1198 c->xyz[2] = a->xyz[2] + v[2] * sect;
1200 c->rgba[0] = (1 - sect) * a->rgba[0] + sect * b->rgba[0];
1201 c->rgba[1] = (1 - sect) * a->rgba[1] + sect * b->rgba[1];
1202 c->rgba[2] = (1 - sect) * a->rgba[2] + sect * b->rgba[2];
1203 c->rgba[3] = (1 - sect) * a->rgba[3] + sect * b->rgba[3];
1207 GL2PSprimitive *child, GLshort numverts,
1208 GLshort *index0, GLshort *index1)
1214 child->data.image = parent->data.image;
1230 child->boundary = 0;
1231 child->culled = parent->culled;
1232 child->offset = parent->offset;
1233 child->pattern = parent->pattern;
1234 child->factor = parent->factor;
1235 child->width = parent->width;
1236 child->numverts = numverts;
1237 child->verts = (GL2PSvertex*)
gl2psMalloc(numverts *
sizeof(GL2PSvertex));
1239 for(i = 0; i < numverts; i++){
1241 child->verts[i] = parent->verts[index0[i]];
1244 gl2psCutEdge(&parent->verts[index0[i]], &parent->verts[index1[i]],
1245 plane, &child->verts[i]);
1251 GLshort i, GLshort j)
1255 for(k = 0; k < *nb; k++){
1256 if((index0[k] == i && index1[k] == j) ||
1257 (index1[k] == i && index0[k] == j))
return;
1266 return (i < num - 1) ? i + 1 : 0;
1275 for(i = 0; i < prim->numverts; i++){
1279 if(prim->numverts < 2){
1283 for(i = 0; i < prim->numverts; i++){
1301 GL2PSprimitive **front, GL2PSprimitive **back)
1303 GLshort i, j, in = 0, out = 0;
1304 GLshort in0[5] = {0}, in1[5] = {0}, out0[5] = {0}, out1[5] = {0};
1310 for(i = 0; i < prim->numverts; i++){
1321 for(i = 0; i < prim->numverts; i++){
1352 *back = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1353 *front = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1362 GL2PSprimitive **
t1, GL2PSprimitive **
t2)
1364 *t1 = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1365 *t2 = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1367 (*t1)->numverts = (*t2)->numverts = 3;
1368 (*t1)->culled = (*t2)->culled = quad->culled;
1369 (*t1)->offset = (*t2)->offset = quad->offset;
1370 (*t1)->pattern = (*t2)->pattern = quad->pattern;
1371 (*t1)->factor = (*t2)->factor = quad->factor;
1372 (*t1)->width = (*t2)->width = quad->width;
1373 (*t1)->verts = (GL2PSvertex*)
gl2psMalloc(3 *
sizeof(GL2PSvertex));
1374 (*t2)->verts = (GL2PSvertex*)
gl2psMalloc(3 *
sizeof(GL2PSvertex));
1375 (*t1)->verts[0] = quad->verts[0];
1376 (*t1)->verts[1] = quad->verts[1];
1377 (*t1)->verts[2] = quad->verts[2];
1378 (*t1)->boundary = ((quad->boundary & 1) ? 1 : 0) | ((quad->boundary & 2) ? 2 : 0);
1379 (*t2)->verts[0] = quad->verts[0];
1380 (*t2)->verts[1] = quad->verts[2];
1381 (*t2)->verts[2] = quad->verts[3];
1382 (*t2)->boundary = ((quad->boundary & 4) ? 2 : 0) | ((quad->boundary & 4) ? 2 : 0);
1387 GL2PSprimitive *
q, *
w;
1388 GLfloat dq = 0.0F, dw = 0.0F, diff;
1391 q = *(GL2PSprimitive**)a;
1392 w = *(GL2PSprimitive**)b;
1394 for(i = 0; i < q->numverts; i++){
1395 dq += q->verts[i].xyz[2];
1397 dq /= (GLfloat)q->numverts;
1399 for(i = 0; i < w->numverts; i++){
1400 dw += w->verts[i].xyz[2];
1402 dw /= (GLfloat)w->numverts;
1418 GL2PSprimitive *
q, *
w;
1420 q = *(GL2PSprimitive**)a;
1421 w = *(GL2PSprimitive**)b;
1422 return(q->type < w->type ? 1 : -1);
1427 GLint i, j, count, best = 1000000, index = 0;
1428 GL2PSprimitive *prim1, *prim2;
1441 if(maxp > gl2ps->maxbestroot){
1442 maxp = gl2ps->maxbestroot;
1444 for(i = 0; i < maxp; i++){
1453 if(count > best)
break;
1459 if(!count)
return index;
1472 while(list !=
NULL){
1485 q = *(GL2PSprimitive**)data;
1498 GL2PSprimitive *
t1, *
t2;
1516 if((*tree)->primitives){
1528 if(f1 > f2)
return GL_TRUE;
1529 else return GL_FALSE;
1534 if(f1 < f2)
return GL_TRUE;
1535 else return GL_FALSE;
1540 GL2PSprimitive *prim, *frontprim =
NULL, *backprim =
NULL;
1541 GL2PSlist *frontlist, *backlist;
1602 GLboolean (*
compare)(GLfloat f1, GLfloat f2),
1603 void (*action)(
void *data),
int inverse)
1611 if(GL_TRUE ==
compare(result, epsilon)){
1621 else if(GL_TRUE ==
compare(-epsilon, result)){
1639 GL2PSprimitive *prim;
1640 GLfloat minZ, maxZ, rangeZ, scaleZ;
1641 GLfloat factor, units, area, dZ, dZdX, dZdY, maxdZ;
1649 minZ = maxZ = prim->verts[0].xyz[2];
1650 for(i = 1; i < prim->numverts; i++){
1651 if(prim->verts[i].xyz[2] < minZ) minZ = prim->verts[i].xyz[2];
1652 if(prim->verts[i].xyz[2] > maxZ) maxZ = prim->verts[i].xyz[2];
1656 for(j = 0; j < prim->numverts; j++){
1657 if(prim->verts[j].xyz[2] < minZ) minZ = prim->verts[j].xyz[2];
1658 if(prim->verts[j].xyz[2] > maxZ) maxZ = prim->verts[j].xyz[2];
1661 rangeZ = (maxZ - minZ);
1667 if(scaleZ > 100000.
F) scaleZ = 100000.F;
1672 for(j = 0; j < prim->numverts; j++){
1673 prim->verts[j].xyz[2] = (prim->verts[j].xyz[2] - minZ) * scaleZ;
1687 factor = gl2ps->offset[0];
1688 units = gl2ps->offset[1];
1690 (prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) *
1691 (prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) -
1692 (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) *
1693 (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]);
1696 ((prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) *
1697 (prim->verts[1].xyz[2] - prim->verts[0].xyz[2]) -
1698 (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]) *
1699 (prim->verts[2].xyz[2] - prim->verts[1].xyz[2])) / area;
1701 ((prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) *
1702 (prim->verts[2].xyz[2] - prim->verts[1].xyz[2]) -
1703 (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) *
1704 (prim->verts[1].xyz[2] - prim->verts[0].xyz[2])) / area;
1705 maxdZ = (GLfloat)
sqrt(dZdX * dZdX + dZdY * dZdY);
1710 dZ = factor * maxdZ + units;
1711 prim->verts[0].xyz[2] += dZ;
1712 prim->verts[1].xyz[2] += dZ;
1713 prim->verts[2].xyz[2] += dZ;
1728 plane[0] = b[1] - a[1];
1729 plane[1] = a[0] - b[0];
1730 n = (GLfloat)
sqrt(plane[0]*plane[0] + plane[1]*plane[1]);
1735 plane[3] = -plane[0]*a[0]-plane[1]*a[1];
1774 if((*tree ==
NULL) && (prim->numverts > 2)){
1780 for(i = 0; i < prim->numverts-1; i++){
1782 prim->verts[i+1].xyz,
1784 if(prim->numverts-i > 3){
1798 for(i = 2+offset; i < prim->numverts; i++){
1805 for(i = 1+offset; i < prim->numverts-1; i++){
1806 if(cur->front ==
NULL){
1810 prim->verts[i+1].xyz,
1811 cur->front->plane)){
1817 if(cur->front ==
NULL){
1821 prim->verts[offset].xyz,
1822 cur->front->plane)){
1823 cur->front->front =
NULL;
1824 cur->front->back =
NULL;
1832 for(i = 0; i < 4; i++){
1833 head->plane[i] = -head->plane[i];
1836 for(i = 1+offset; i < prim->numverts-1; i++){
1837 if(cur->front ==
NULL){
1842 cur->front->plane)){
1848 if(cur->front ==
NULL){
1853 cur->front->plane)){
1854 cur->front->front =
NULL;
1855 cur->front->back =
NULL;
1876 for(i = 1; i < prim->numverts; i++){
1890 GL2PSprimitive *child = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1894 child->data.image = parent->data.image;
1905 child->boundary = 0;
1906 child->culled = parent->culled;
1907 child->offset = parent->offset;
1908 child->pattern = parent->pattern;
1909 child->factor = parent->factor;
1910 child->width = parent->width;
1911 child->numverts = numverts;
1912 child->verts = (GL2PSvertex*)
gl2psMalloc(numverts *
sizeof(GL2PSvertex));
1913 for(i = 0; i < numverts; i++){
1914 child->verts[i] = vertx[i];
1921 GL2PSprimitive **front,
1922 GL2PSprimitive **back)
1929 GLint cur = -1, prev = -1, i,
v1 = 0, v2 = 0, flag = 1, prev0 = -1;
1932 GL2PSvertex *front_list =
NULL, *back_list =
NULL;
1935 GLshort front_count = 0, back_count = 0;
1937 for(i = 0; i <= prim->numverts; i++){
1939 if(v1 == prim->numverts){
1940 if(prim->numverts < 3)
break;
1942 v2 = prim->numverts - 1;
1951 if(((prev == -1) || (prev == cur) || (prev == 0) || (cur == 0)) &&
1952 (i < prim->numverts)){
1956 sizeof(GL2PSvertex)*front_count);
1957 front_list[front_count-1] = prim->verts[
v1];
1962 sizeof(GL2PSvertex)*back_count);
1963 back_list[back_count-1] = prim->verts[
v1];
1968 sizeof(GL2PSvertex)*front_count);
1969 front_list[front_count-1] = prim->verts[
v1];
1972 sizeof(GL2PSvertex)*back_count);
1973 back_list[back_count-1] = prim->verts[
v1];
1977 else if((prev != cur) && (cur != 0) && (prev != 0)){
1984 sizeof(GL2PSvertex)*front_count);
1986 plane, &front_list[front_count-1]);
1989 sizeof(GL2PSvertex)*back_count);
1990 back_list[back_count-1] = front_list[front_count-1];
2004 GL2PSprimitive *frontprim =
NULL, *backprim =
NULL;
2016 if((prim->type !=
GL2PS_IMAGEMAP) && (GL_FALSE == gl2ps->zerosurfacearea)){
2030 if((*tree)->front !=
NULL){
2041 if((*tree)->back !=
NULL){
2042 gl2ps->zerosurfacearea = GL_TRUE;
2044 gl2ps->zerosurfacearea = GL_FALSE;
2047 if((*tree)->front !=
NULL){
2048 gl2ps->zerosurfacearea = GL_TRUE;
2050 gl2ps->zerosurfacearea = GL_FALSE;
2062 GL2PSprimitive *prim = *(GL2PSprimitive **)data;
2063 gl2ps->primitivetoadd = prim;
2083 c[0] = c[1] = c[2] = 0.0F;
2084 for(i = 0; i < prim->numverts; i++){
2085 c[0] += prim->verts[i].xyz[0];
2086 c[1] += prim->verts[i].xyz[1];
2088 c[0] /= prim->numverts;
2089 c[1] /= prim->numverts;
2091 for(i = 0; i < prim->numverts; i++){
2092 if(prim->boundary & (GLint)
pow(2., i)){
2093 b = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
2095 b->offset = prim->offset;
2096 b->pattern = prim->pattern;
2097 b->factor = prim->factor;
2098 b->culled = prim->culled;
2099 b->width = prim->width;
2102 b->verts = (GL2PSvertex*)
gl2psMalloc(2 *
sizeof(GL2PSvertex));
2105 v[0] = c[0] - prim->verts[i].xyz[0];
2106 v[1] = c[1] - prim->verts[i].xyz[1];
2111 b->verts[0].xyz[0] = prim->verts[i].xyz[0] +0.1*
v[0];
2112 b->verts[0].xyz[1] = prim->verts[i].xyz[1] +0.1*
v[1];
2113 b->verts[0].xyz[2] = prim->verts[i].xyz[2];
2114 v[0] = c[0] - prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[0];
2115 v[1] = c[1] - prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[1];
2119 b->verts[1].xyz[0] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[0] +0.1*
v[0];
2120 b->verts[1].xyz[1] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[1] +0.1*
v[1];
2121 b->verts[1].xyz[2] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[2];
2123 b->verts[0].xyz[0] = prim->verts[i].xyz[0];
2124 b->verts[0].xyz[1] = prim->verts[i].xyz[1];
2125 b->verts[0].xyz[2] = prim->verts[i].xyz[2];
2126 b->verts[1].xyz[0] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[0];
2127 b->verts[1].xyz[1] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[1];
2128 b->verts[1].xyz[2] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[2];
2131 b->verts[0].rgba[0] = 0.0F;
2132 b->verts[0].rgba[1] = 0.0F;
2133 b->verts[0].rgba[2] = 0.0F;
2134 b->verts[0].rgba[3] = 0.0F;
2135 b->verts[1].rgba[0] = 0.0F;
2136 b->verts[1].rgba[1] = 0.0F;
2137 b->verts[1].rgba[2] = 0.0F;
2138 b->verts[1].rgba[3] = 0.0F;
2148 GL2PSprimitive *prim;
2166 GL2PSvertex *verts, GLint
offset,
2167 GLushort
pattern, GLint factor,
2168 GLfloat width,
char boundary)
2170 GL2PSprimitive *prim;
2172 prim = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
2174 prim->numverts = numverts;
2175 prim->verts = (GL2PSvertex*)
gl2psMalloc(numverts *
sizeof(GL2PSvertex));
2176 memcpy(prim->verts, verts, numverts *
sizeof(GL2PSvertex));
2177 prim->boundary = boundary;
2180 prim->factor = factor;
2181 prim->width = width;
2198 if(gl2ps->colormode == GL_COLOR_INDEX && gl2ps->colorsize > 0){
2199 i = (GLint)(p[3] + 0.5);
2200 v->rgba[0] = gl2ps->colormap[i][0];
2201 v->rgba[1] = gl2ps->colormap[i][1];
2202 v->rgba[2] = gl2ps->colormap[i][2];
2203 v->rgba[3] = gl2ps->colormap[i][3];
2220 GLint i, sizeoffloat, count,
v, vtot,
offset = 0, factor = 0, auxindex = 0;
2221 GLfloat lwidth = 1.0F, psize = 1.0F;
2223 GL2PSvertex vertices[3];
2224 GL2PSprimitive *prim;
2227 current = gl2ps->feedback;
2228 boundary = gl2ps->boundary = GL_FALSE;
2232 if(GL_TRUE == boundary) gl2ps->boundary = GL_TRUE;
2234 switch((GLint)*current){
2235 case GL_POINT_TOKEN :
2242 pattern, factor, psize, 0);
2244 case GL_LINE_TOKEN :
2245 case GL_LINE_RESET_TOKEN :
2255 pattern, factor, lwidth, 0);
2257 case GL_POLYGON_TOKEN :
2258 count = (GLint)current[1];
2262 while(count > 0 && used > 0){
2270 if(GL_TRUE == boundary){
2271 if(!count && vtot == 2) flag = 1|2|4;
2272 else if(!count) flag = 2|4;
2273 else if(vtot == 2) flag = 1|2;
2279 pattern, factor, 1, flag);
2280 vertices[1] = vertices[2];
2286 case GL_BITMAP_TOKEN :
2287 case GL_DRAW_PIXEL_TOKEN :
2288 case GL_COPY_PIXEL_TOKEN :
2295 case GL_PASS_THROUGH_TOKEN :
2296 switch((GLint)current[1]){
2307 pattern = (GLushort)current[1];
2310 factor = (GLint)current[1];
2315 gl2ps->blendfunc[0] = (GLint)current[1];
2320 gl2ps->blendfunc[1] = (GLint)current[1];
2330 lwidth = current[1];
2333 prim = (GL2PSprimitive *)
gl2psMalloc(
sizeof(GL2PSprimitive));
2337 prim->verts = (GL2PSvertex *)
gl2psMalloc(4 *
sizeof(GL2PSvertex));
2345 node->image = (GL2PSimage*)
gl2psMalloc(
sizeof(GL2PSimage));
2346 node->image->type = 0;
2347 node->image->format = 0;
2350 if(gl2ps->imagemap_head ==
NULL)
2351 gl2ps->imagemap_head = node;
2353 gl2ps->imagemap_tail->next = node;
2354 gl2ps->imagemap_tail = node;
2355 prim->data.image = node->image;
2357 current += 2; used -= 2;
2359 current += i; used -= i;
2361 node->image->width = (GLint)current[2];
2362 current += 2; used -= 2;
2363 node->image->height = (GLint)current[2];
2364 prim->verts[0].xyz[0] = prim->verts[0].xyz[0] - (int)(node->image->width / 2) + 0.5;
2365 prim->verts[0].xyz[1] = prim->verts[0].xyz[1] - (int)(node->image->height / 2) + 0.5;
2366 for(i = 1; i < 4; i++){
2367 for(v = 0; v < 3; v++){
2368 prim->verts[i].xyz[
v] = prim->verts[0].xyz[
v];
2369 prim->verts[i].rgba[
v] = prim->verts[0].rgba[
v];
2371 prim->verts[i].rgba[
v] = prim->verts[0].rgba[
v];
2373 prim->verts[1].xyz[0] = prim->verts[1].xyz[0] + node->image->width;
2374 prim->verts[2].xyz[0] = prim->verts[1].xyz[0];
2375 prim->verts[2].xyz[1] = prim->verts[2].xyz[1] + node->image->height;
2376 prim->verts[3].xyz[1] = prim->verts[2].xyz[1];
2378 sizeoffloat =
sizeof(GLfloat);
2379 v = 2 * sizeoffloat;
2380 vtot = node->image->height + node->image->height *
2381 ((node->image->width - 1) / 8);
2382 node->image->pixels = (GLfloat*)
gl2psMalloc(v + vtot);
2383 node->image->pixels[0] = prim->verts[0].xyz[0];
2384 node->image->pixels[1] = prim->verts[0].xyz[1];
2386 for(i = 0; i < vtot; i += sizeoffloat){
2387 current += 2; used -= 2;
2389 memcpy(&(((
char*)(node->image->pixels))[i +
v]), &(current[2]), sizeoffloat);
2391 memcpy(&(((
char*)(node->image->pixels))[i + v]), &(current[2]), vtot - i);
2427 unsigned char h = byte / 16;
2428 unsigned char l = byte % 16;
2434 GLuint nbhex, nbyte, nrgb, nbits;
2435 GLuint
row, col, ibyte, icase;
2436 GLfloat
dr, dg = 0.f, db = 0.f, fgrey;
2437 unsigned char red = 0, green = 0, blue = 0, b, grey;
2438 GLuint width = (GLuint)im->width;
2439 GLuint height = (GLuint)im->height;
2446 if((width <= 0) || (height <= 0))
return;
2455 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2456 gl2psPrintf(
"{ currentfile picstr readhexstring pop }\n");
2458 for(row = 0; row < height; row++){
2459 for(col = 0; col < width; col++){
2461 fgrey = (0.30 * dr + 0.59 * dg + 0.11 * db);
2462 grey = (
unsigned char)(255. * fgrey);
2467 nbhex = width * height * 2;
2472 nbits = nrgb * nbit;
2474 if((nbyte * 8) != nbits) nbyte++;
2477 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2478 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2481 for(row = 0; row < height; row++){
2485 for(ibyte = 0; ibyte < nbyte; ibyte++){
2494 red = (
unsigned char)(3. * dr);
2495 green = (
unsigned char)(3. * dg);
2496 blue = (
unsigned char)(3. * db);
2507 red = (
unsigned char)(3. * dr);
2508 green = (
unsigned char)(3. * dg);
2509 blue = (
unsigned char)(3. * db);
2515 else if(icase == 2) {
2525 red = (
unsigned char)(3. * dr);
2526 green = (
unsigned char)(3. * dg);
2527 blue = (
unsigned char)(3. * db);
2534 else if(icase == 3) {
2543 red = (
unsigned char)(3. * dr);
2544 green = (
unsigned char)(3. * dg);
2545 blue = (
unsigned char)(3. * db);
2559 nbits = nrgb * nbit;
2561 if((nbyte * 8) != nbits) nbyte++;
2564 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2565 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2568 for(row = 0; row < height; row++){
2571 for(ibyte = 0; ibyte < nbyte; ibyte++){
2580 red = (
unsigned char)(15. * dr);
2581 green = (
unsigned char)(15. * dg);
2585 else if(icase == 2) {
2586 blue = (
unsigned char)(15. * db);
2594 red = (
unsigned char)(15. * dr);
2598 else if(icase == 3) {
2599 green = (
unsigned char)(15. * dg);
2600 blue = (
unsigned char)(15. * db);
2612 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2613 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2616 for(row = 0; row < height; row++){
2617 for(col = 0; col < width; col++){
2619 red = (
unsigned char)(255. * dr);
2621 green = (
unsigned char)(255. * dg);
2623 blue = (
unsigned char)(255. * db);
2634 GLsizei width, GLsizei height,
2635 const unsigned char *imagemap){
2638 if((width <= 0) || (height <= 0))
return;
2640 size = height + height * (width - 1) / 8;
2644 gl2psPrintf(
"%d %d scale\n%d %d\ntrue\n", width, height,width, height);
2645 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ] {<", width, height);
2646 for(i = 0; i < size; i++){
2672 "%%%%Creator: GL2PS %d.%d.%d%s, %s\n"
2674 "%%%%CreationDate: %s"
2675 "%%%%LanguageLevel: 3\n"
2676 "%%%%DocumentData: Clean7Bit\n"
2680 gl2ps->producer, ctime(&now));
2684 "%%%%DocumentMedia: Default %d %d 0 () ()\n",
2687 (
int)gl2ps->viewport[2],
2689 (
int)gl2ps->viewport[3]);
2693 "%%%%EndComments\n",
2695 (
int)gl2ps->viewport[0],
2697 (
int)gl2ps->viewport[1],
2699 (
int)gl2ps->viewport[2],
2701 (
int)gl2ps->viewport[3]);
2717 "/gl2psdict 64 dict def gl2psdict begin\n"
2718 "0 setlinecap 0 setlinejoin\n"
2719 "/tryPS3shading %s def %% set to false to force subdivision\n"
2720 "/rThreshold %g def %% red component subdivision threshold\n"
2721 "/gThreshold %g def %% green component subdivision threshold\n"
2722 "/bThreshold %g def %% blue component subdivision threshold\n",
2724 gl2ps->threshold[0], gl2ps->threshold[1], gl2ps->threshold[2]);
2727 "/C { setrgbcolor } BD\n"
2728 "/G { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add setgray } BD\n"
2729 "/W { setlinewidth } BD\n");
2731 gl2psPrintf(
"/FC { findfont exch /SH exch def SH scalefont setfont } BD\n"
2732 "/SW { dup stringwidth pop } BD\n"
2733 "/S { FC moveto show } BD\n"
2734 "/SBC{ FC moveto SW -2 div 0 rmoveto show } BD\n"
2735 "/SBR{ FC moveto SW neg 0 rmoveto show } BD\n"
2736 "/SCL{ FC moveto 0 SH -2 div rmoveto show } BD\n"
2737 "/SCC{ FC moveto SW -2 div SH -2 div rmoveto show } BD\n"
2738 "/SCR{ FC moveto SW neg SH -2 div rmoveto show } BD\n"
2739 "/STL{ FC moveto 0 SH neg rmoveto show } BD\n"
2740 "/STC{ FC moveto SW -2 div SH neg rmoveto show } BD\n"
2741 "/STR{ FC moveto SW neg SH neg rmoveto show } BD\n");
2746 "/SR { gsave FCT moveto rotate show grestore } BD\n"
2747 "/SBCR{ gsave FCT moveto rotate SW -2 div 0 rmoveto show grestore } BD\n"
2748 "/SBRR{ gsave FCT moveto rotate SW neg 0 rmoveto show grestore } BD\n"
2749 "/SCLR{ gsave FCT moveto rotate 0 SH -2 div rmoveto show grestore} BD\n");
2750 gl2psPrintf(
"/SCCR{ gsave FCT moveto rotate SW -2 div SH -2 div rmoveto show grestore} BD\n"
2751 "/SCRR{ gsave FCT moveto rotate SW neg SH -2 div rmoveto show grestore} BD\n"
2752 "/STLR{ gsave FCT moveto rotate 0 SH neg rmoveto show grestore } BD\n"
2753 "/STCR{ gsave FCT moveto rotate SW -2 div SH neg rmoveto show grestore } BD\n"
2754 "/STRR{ gsave FCT moveto rotate SW neg SH neg rmoveto show grestore } BD\n");
2756 gl2psPrintf(
"/P { newpath 0.0 360.0 arc closepath fill } BD\n"
2757 "/LS { newpath moveto } BD\n"
2758 "/L { lineto } BD\n"
2759 "/LE { lineto stroke } BD\n"
2760 "/T { newpath moveto lineto lineto closepath fill } BD\n");
2766 " /b1 exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n"
2767 " /b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n"
2768 " /b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n"
2769 " gsave << /ShadingType 4 /ColorSpace [/DeviceRGB]\n"
2770 " /DataSource [ 0 x1 y1 r1 g1 b1 0 x2 y2 r2 g2 b2 0 x3 y3 r3 g3 b3 ] >>\n"
2771 " shfill grestore } BD\n");
2777 "/Tm { 3 -1 roll 8 -1 roll 13 -1 roll add add 3 div\n"
2779 " 3 -1 roll 7 -1 roll 11 -1 roll add add 3 div\n"
2781 " 3 -1 roll 6 -1 roll 9 -1 roll add add 3 div"
2791 " 4 index 15 index add 0.5 mul\n"
2792 " 4 index 15 index add 0.5 mul\n"
2793 " 4 index 15 index add 0.5 mul\n"
2794 " 4 index 15 index add 0.5 mul\n"
2795 " 4 index 15 index add 0.5 mul\n"
2796 " 5 copy 5 copy 25 15 roll\n");
2801 " 9 index 30 index add 0.5 mul\n"
2802 " 9 index 30 index add 0.5 mul\n"
2803 " 9 index 30 index add 0.5 mul\n"
2804 " 9 index 30 index add 0.5 mul\n"
2805 " 5 copy 5 copy 35 5 roll 25 5 roll 15 5 roll\n");
2810 " 4 index 10 index add 0.5 mul\n"
2811 " 4 index 10 index add 0.5 mul\n"
2812 " 4 index 10 index add 0.5 mul\n"
2813 " 4 index 10 index add 0.5 mul\n"
2814 " 5 copy 5 copy 40 5 roll 25 5 roll 15 5 roll 25 5 roll\n");
2818 gl2psPrintf(
" STnoshfill STnoshfill STnoshfill STnoshfill } BD\n");
2825 " 2 index 8 index sub abs rThreshold gt\n"
2827 " { 1 index 7 index sub abs gThreshold gt\n"
2829 " { dup 6 index sub abs bThreshold gt\n"
2831 " { 2 index 13 index sub abs rThreshold gt\n"
2833 " { 1 index 12 index sub abs gThreshold gt\n"
2835 " { dup 11 index sub abs bThreshold gt\n"
2837 " { 7 index 13 index sub abs rThreshold gt\n");
2839 " { 6 index 12 index sub abs gThreshold gt\n"
2841 " { 5 index 11 index sub abs bThreshold gt\n"
2856 " { /ST { STshfill } BD }\n"
2857 " { /ST { STnoshfill } BD }\n"
2859 "{ /ST { STnoshfill } BD }\n"
2865 "/DeviceRGB setcolorspace\n"
2869 "%%%%BeginPageSetup\n");
2873 (
int)gl2ps->viewport[3]);
2883 "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
2885 gl2ps->bgcolor[0], gl2ps->bgcolor[1], gl2ps->bgcolor[2],
2886 (
int)gl2ps->viewport[0], (
int)gl2ps->viewport[1], (
int)gl2ps->viewport[2],
2887 (
int)gl2ps->viewport[1], (
int)gl2ps->viewport[2], (
int)gl2ps->viewport[3],
2888 (
int)gl2ps->viewport[0], (
int)gl2ps->viewport[3]);
2896 gl2psPrintf(
"%g %g %g C\n", rgba[0], rgba[1], rgba[2]);
2902 gl2ps->lastrgba[0] = gl2ps->lastrgba[1] = gl2ps->lastrgba[2] = -1.;
2908 if(gl2ps->lastvertex.rgba[0] >= 0.){
2909 gl2psPrintf(
"%g %g LE\n", gl2ps->lastvertex.xyz[0], gl2ps->lastvertex.xyz[1]);
2910 for(i = 0; i < 3; i++)
2911 gl2ps->lastvertex.xyz[i] = -1.;
2912 for(i = 0; i < 4; i++)
2913 gl2ps->lastvertex.rgba[i] = -1.;
2918 int *nb,
int array[10])
2921 int on[8] = {0, 0, 0, 0, 0, 0, 0, 0};
2922 int off[8] = {0, 0, 0, 0, 0, 0, 0, 0};
2926 for(n = 15; n >= 0; n--){
2927 tmp[
n] = (char)(pattern & 0x01);
2932 for(i = 0; i < 8; i++){
2933 while(n < 16 && !tmp[n]){ off[i]++; n++; }
2934 while(n < 16 && tmp[n]){ on[i]++; n++; }
2935 if(n >= 15){ i++;
break; }
2944 for(n = i - 1; n >= 0; n--){
2945 array[(*nb)++] = factor * on[
n];
2946 array[(*nb)++] = factor * off[
n];
2947 if(*nb == 10)
break;
2953 int len = 0, i,
n, array[10];
2955 if(pattern == gl2ps->lastpattern && factor == gl2ps->lastfactor)
2959 gl2ps->lastfactor = factor;
2961 if(!pattern || !factor){
2968 for(i = 0; i <
n; i++){
2981 GL2PSprimitive *prim;
2983 prim = *(GL2PSprimitive**)data;
2998 prim->verts[0].xyz[0], prim->verts[0].xyz[1], 0.5 * prim->width);
3003 gl2ps->lastlinewidth != prim->width ||
3004 gl2ps->lastpattern != prim->pattern ||
3005 gl2ps->lastfactor != prim->factor){
3018 if(gl2ps->lastlinewidth != prim->width){
3019 gl2ps->lastlinewidth = prim->width;
3024 gl2psPrintf(
"%g %g %s\n", prim->verts[0].xyz[0], prim->verts[0].xyz[1],
3025 newline ?
"LS" :
"L");
3026 gl2ps->lastvertex = prim->verts[1];
3031 gl2psPrintf(
"%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ST\n",
3032 prim->verts[2].xyz[0], prim->verts[2].xyz[1],
3033 prim->verts[2].rgba[0], prim->verts[2].rgba[1],
3034 prim->verts[2].rgba[2], prim->verts[1].xyz[0],
3035 prim->verts[1].xyz[1], prim->verts[1].rgba[0],
3036 prim->verts[1].rgba[1], prim->verts[1].rgba[2],
3037 prim->verts[0].xyz[0], prim->verts[0].xyz[1],
3038 prim->verts[0].rgba[0], prim->verts[0].rgba[1],
3039 prim->verts[0].rgba[2]);
3044 prim->verts[2].xyz[0], prim->verts[2].xyz[1],
3045 prim->verts[1].xyz[0], prim->verts[1].xyz[1],
3046 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3060 prim->data.image->pixels[1],
3061 prim->data.image->width, prim->data.image->height,
3062 (
const unsigned char*)(&(prim->data.image->pixels[2])));
3069 if(prim->data.text->angle)
3072 prim->verts[0].xyz[0], prim->verts[0].xyz[1],
3073 prim->data.text->fontsize, prim->data.text->fontname);
3074 switch(prim->data.text->alignment){
3076 gl2psPrintf(prim->data.text->angle ?
"SCCR\n" :
"SCC\n");
3079 gl2psPrintf(prim->data.text->angle ?
"SCLR\n" :
"SCL\n");
3082 gl2psPrintf(prim->data.text->angle ?
"SCRR\n" :
"SCR\n");
3085 gl2psPrintf(prim->data.text->angle ?
"SBCR\n" :
"SBC\n");
3088 gl2psPrintf(prim->data.text->angle ?
"SBRR\n" :
"SBR\n");
3091 gl2psPrintf(prim->data.text->angle ?
"STCR\n" :
"STC\n");
3094 gl2psPrintf(prim->data.text->angle ?
"STLR\n" :
"STL\n");
3097 gl2psPrintf(prim->data.text->angle ?
"STRR\n" :
"STR\n");
3101 gl2psPrintf(prim->data.text->angle ?
"SR\n" :
"S\n");
3108 if(prim->data.text->alignment ==
GL2PS_PS ||
3109 prim->data.text->alignment ==
GL2PS_EPS)
3134 int x = viewport[0],
y = viewport[1],
w = viewport[2],
h = viewport[3];
3136 glRenderMode(GL_FEEDBACK);
3140 gl2ps->header = GL_FALSE;
3147 if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){
3148 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
3151 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &index);
3152 rgba[0] = gl2ps->colormap[index][0];
3153 rgba[1] = gl2ps->colormap[index][1];
3154 rgba[2] = gl2ps->colormap[index][2];
3158 "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3160 rgba[0], rgba[1], rgba[2],
3161 x, y, x+w, y, x+w, y+h, x, y+h);
3164 gl2psPrintf(
"newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3166 x, y, x+w, y, x+w, y+h, x, y+h);
3187 static GL2PSbackend gl2psPS = {
3198 static GL2PSbackend gl2psEPS = {
3206 "Encapsulated Postscript"
3221 if(gl2ps->filename && strlen(gl2ps->filename) < 256){
3222 for(i = strlen(gl2ps->filename)-1; i >= 0; i--){
3223 if(gl2ps->filename[i] ==
'.'){
3224 strncpy(name, gl2ps->filename, i);
3229 if(i <= 0) strcpy(name, gl2ps->filename);
3232 strcpy(name,
"untitled");
3237 fprintf(gl2ps->stream,
3239 "%% Creator: GL2PS %d.%d.%d%s, %s\n"
3241 "%% CreationDate: %s",
3244 gl2ps->producer, ctime(&now));
3246 fprintf(gl2ps->stream,
3247 "\\setlength{\\unitlength}{1pt}\n"
3248 "\\begin{picture}(0,0)\n"
3249 "\\includegraphics{%s}\n"
3250 "\\end{picture}%%\n"
3251 "%s\\begin{picture}(%d,%d)(0,0)\n",
3253 (
int)gl2ps->viewport[2], (
int)gl2ps->viewport[3]);
3258 GL2PSprimitive *prim;
3260 prim = *(GL2PSprimitive**)data;
3264 fprintf(gl2ps->stream,
"\\fontsize{%d}{0}\n\\selectfont",
3265 prim->data.text->fontsize);
3266 fprintf(gl2ps->stream,
"\\put(%g,%g){\\makebox(0,0)",
3267 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3268 switch(prim->data.text->alignment){
3270 fprintf(gl2ps->stream,
"{");
3273 fprintf(gl2ps->stream,
"[l]{");
3276 fprintf(gl2ps->stream,
"[r]{");
3279 fprintf(gl2ps->stream,
"[b]{");
3282 fprintf(gl2ps->stream,
"[br]{");
3285 fprintf(gl2ps->stream,
"[t]{");
3288 fprintf(gl2ps->stream,
"[tl]{");
3291 fprintf(gl2ps->stream,
"[tr]{");
3295 fprintf(gl2ps->stream,
"[bl]{");
3298 if(prim->data.text->angle)
3299 fprintf(gl2ps->stream,
"\\rotatebox{%g}{", prim->data.text->angle);
3300 fprintf(gl2ps->stream,
"\\textcolor[rgb]{%g,%g,%g}{{%s}}",
3301 prim->verts[0].rgba[0], prim->verts[0].rgba[1], prim->verts[0].rgba[2],
3302 prim->data.text->str);
3303 if(prim->data.text->angle)
3304 fprintf(gl2ps->stream,
"}");
3305 fprintf(gl2ps->stream,
"}}\n");
3310 if (prim->data.text->alignment ==
GL2PS_TEX)
3311 fprintf(gl2ps->stream,
"%s\n", prim->data.text->str);
3320 fprintf(gl2ps->stream,
"\\end{picture}%s\n",
3326 glRenderMode(GL_FEEDBACK);
3330 gl2ps->header = GL_FALSE;
3345 static GL2PSbackend gl2psTEX = {
3364 #if defined(GL2PS_HAVE_ZLIB)
3366 return fprintf(gl2ps->stream,
"/Filter [/FlateDecode]\n");
3377 for(i = 0; i < 3; ++i){
3380 else if(rgba[i] < 1e-4 || rgba[i] > 1e6)
3393 for(i = 0; i < 3; ++i){
3396 else if(rgba[i] < 1e-4 || rgba[i] > 1e6)
3409 else if(lw < 1e-4 || lw > 1e6)
3417 gl2ps->streamlength +=
3423 cnt, text->fontsize, x, y, text->str);
3428 gl2ps->streamlength +=
3430 "%d 0 0 %d %f %f cm\n"
3433 (
int)image->width, (
int)image->height, x, y, cnt);
3438 gl2ps->objects_stack = 7 + 1;
3439 gl2ps->extgs_stack = 0;
3440 gl2ps->font_stack = 0;
3441 gl2ps->im_stack = 0;
3442 gl2ps->trgroupobjects_stack = 0;
3443 gl2ps->shader_stack = 0;
3444 gl2ps->mshader_stack = 0;
3452 gro->ptrlist =
NULL;
3453 gro->fontno = gro->gsno = gro->imno = gro->maskshno = gro->shno
3454 = gro->trgroupno = gro->fontobjno = gro->imobjno = gro->shobjno
3455 = gro->maskshobjno = gro->gsobjno = gro->trgroupobjno = -1;
3463 GL2PSprimitive *p =
NULL;
3466 GL2PSrgba lastrgba = {-1.0F, -1.0F, -1.0F, -1.0F};
3467 GLushort lastpattern = 0;
3468 GLint lastfactor = 0;
3469 GLfloat lastwidth = 1;
3470 GL2PStriangle lastt, tmpt;
3471 int lastTriangleWasNotSimpleWithSameColor = 0;
3473 if(!gl2ps->pdfprimlist)
3476 gl2ps->pdfgrouplist =
gl2psListCreate(500, 500,
sizeof(GL2PSpdfgroup));
3485 gro.imno = gl2ps->im_stack++;
3492 gro.fontno = gl2ps->font_stack++;
3497 if(lasttype != p->type || lastwidth != p->width ||
3498 lastpattern != p->pattern || lastfactor != p->factor ||
3508 lastpattern = p->pattern;
3509 lastfactor = p->factor;
3510 lastwidth = p->width;
3511 lastrgba[0] = p->verts[0].rgba[0];
3512 lastrgba[1] = p->verts[0].rgba[1];
3513 lastrgba[2] = p->verts[0].rgba[2];
3516 if(lasttype != p->type || lastwidth != p->width ||
3526 lastwidth = p->width;
3527 lastrgba[0] = p->verts[0].rgba[0];
3528 lastrgba[1] = p->verts[0].rgba[1];
3529 lastrgba[2] = p->verts[0].rgba[2];
3533 lastTriangleWasNotSimpleWithSameColor =
3536 if(lasttype == p->type && tmpt.prop == lastt.prop &&
3537 lastTriangleWasNotSimpleWithSameColor){
3559 GL2PSprimitive *prim =
NULL;
3575 gro->gsno = gl2ps->extgs_stack++;
3576 gro->gsobjno = gl2ps->objects_stack ++;
3579 gro->gsno = gl2ps->extgs_stack++;
3580 gro->gsobjno = gl2ps->objects_stack++;
3581 gro->trgroupno = gl2ps->trgroupobjects_stack++;
3582 gro->trgroupobjno = gl2ps->objects_stack++;
3583 gro->maskshno = gl2ps->mshader_stack++;
3584 gro->maskshobjno = gl2ps->objects_stack++;
3587 gro->shno = gl2ps->shader_stack++;
3588 gro->shobjno = gl2ps->objects_stack++;
3591 gro->gsno = gl2ps->extgs_stack++;
3592 gro->gsobjno = gl2ps->objects_stack++;
3593 gro->shno = gl2ps->shader_stack++;
3594 gro->shobjno = gl2ps->objects_stack++;
3597 gro->gsno = gl2ps->extgs_stack++;
3598 gro->gsobjno = gl2ps->objects_stack++;
3599 gro->shno = gl2ps->shader_stack++;
3600 gro->shobjno = gl2ps->objects_stack++;
3601 gro->trgroupno = gl2ps->trgroupobjects_stack++;
3602 gro->trgroupobjno = gl2ps->objects_stack++;
3603 gro->maskshno = gl2ps->mshader_stack++;
3604 gro->maskshobjno = gl2ps->objects_stack++;
3613 GL2PSprimitive *prim =
NULL, *prev =
NULL;
3617 if(!gl2ps->pdfgrouplist)
3620 for(i = 0; i <
gl2psListNbr(gl2ps->pdfgrouplist); ++i){
3634 for(j = 0; j <= lastel; ++j){
3636 gl2ps->streamlength +=
3638 prim->verts[0].xyz[0], prim->verts[0].xyz[1],
3639 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3652 gl2ps->streamlength +=
3654 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3656 for(j = 1; j <= lastel; ++j){
3663 gl2ps->streamlength +=
3665 prev->verts[1].xyz[0], prev->verts[1].xyz[1]);
3666 gl2ps->streamlength +=
3668 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3673 gl2ps->streamlength +=
3675 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3679 gl2ps->streamlength +=
3681 prim->verts[1].xyz[0], prim->verts[1].xyz[1]);
3691 for(j = 0; j <= lastel; ++j){
3699 t.vertex[0].xyz[0], t.vertex[0].xyz[1],
3700 t.vertex[1].xyz[0], t.vertex[1].xyz[1],
3701 t.vertex[2].xyz[0], t.vertex[2].xyz[1]);
3711 for(j = 0; j <= lastel; ++j){
3719 t.vertex[0].xyz[0], t.vertex[0].xyz[1],
3720 t.vertex[1].xyz[0], t.vertex[1].xyz[1],
3721 t.vertex[2].xyz[0], t.vertex[2].xyz[1]);
3732 gro->gsno, gro->trgroupno);
3734 for(j = 0; j <= lastel; ++j){
3742 t.vertex[0].xyz[0], t.vertex[0].xyz[1],
3743 t.vertex[1].xyz[0], t.vertex[1].xyz[1],
3744 t.vertex[2].xyz[0], t.vertex[2].xyz[1]);
3751 gl2ps->streamlength +=
gl2psPrintf(
"/Sh%d sh\n", gro->shno);
3761 gro->gsno, gro->shno);
3772 gro->gsno, gro->trgroupno, gro->shno);
3776 for(j = 0; j <= lastel; ++j){
3779 prim->verts[0].xyz[1]);
3783 for(j = 0; j <= lastel; ++j){
3787 prim->verts[0].xyz[1]);
3804 offs += fprintf(gl2ps->stream,
3808 for(i = 0; i <
gl2psListNbr(gl2ps->pdfgrouplist); ++i){
3811 offs += fprintf(gl2ps->stream,
"/GS%d %d 0 R\n", gro->gsno, gro->gsobjno);
3813 offs += fprintf(gl2ps->stream,
">>\n");
3825 offs += fprintf(gl2ps->stream,
3828 for(i = 0; i <
gl2psListNbr(gl2ps->pdfgrouplist); ++i){
3831 offs += fprintf(gl2ps->stream,
"/Sh%d %d 0 R\n", gro->shno, gro->shobjno);
3832 if(gro->maskshno >= 0)
3833 offs += fprintf(gl2ps->stream,
"/TrSh%d %d 0 R\n", gro->maskshno, gro->maskshobjno);
3835 offs += fprintf(gl2ps->stream,
">>\n");
3844 GL2PSprimitive *p =
NULL;
3848 offs += fprintf(gl2ps->stream,
3852 for(i = 0; i <
gl2psListNbr(gl2ps->pdfgrouplist); ++i){
3859 gro->imobjno = gl2ps->objects_stack++;
3860 if(GL_RGBA == p->data.image->format)
3861 gl2ps->objects_stack++;
3862 offs += fprintf(gl2ps->stream,
"/Im%d %d 0 R\n", gro->imno, gro->imobjno);
3864 if(gro->trgroupno >=0)
3865 offs += fprintf(gl2ps->stream,
"/TrG%d %d 0 R\n", gro->trgroupno, gro->trgroupobjno);
3871 offs += fprintf(gl2ps->stream,
">>\n");
3883 offs += fprintf(gl2ps->stream,
"/Font\n<<\n");
3885 for(i = 0; i <
gl2psListNbr(gl2ps->pdfgrouplist); ++i){
3889 gro->fontobjno = gl2ps->objects_stack++;
3890 offs += fprintf(gl2ps->stream,
"/F%d %d 0 R\n", gro->fontno, gro->fontobjno);
3892 offs += fprintf(gl2ps->stream,
">>\n");
3900 GL2PSpdfgroup *gro =
NULL;
3902 if(!gl2ps->pdfgrouplist)
3905 for(i = 0; i <
gl2psListNbr(gl2ps->pdfgrouplist); ++i){
3911 gl2ps->pdfgrouplist =
NULL;
3923 newtime = gmtime(&now);
3925 offs = fprintf(gl2ps->stream,
3929 "/Creator (GL2PS %d.%d.%d%s, %s)\n"
3936 offs += fprintf(gl2ps->stream,
3942 offs += fprintf(gl2ps->stream,
3943 "/CreationDate (D:%d%02d%02d%02d%02d%02d)\n"
3946 newtime->tm_year+1900,
3959 return fprintf(gl2ps->stream,
3970 return fprintf(gl2ps->stream,
3986 offs += fprintf(gl2ps->stream,
3989 "/Length 5 0 R\n" );
3991 offs += fprintf(gl2ps->stream,
4008 (
int)gl2ps->viewport[0], (
int)gl2ps->viewport[1],
4009 (
int)gl2ps->viewport[2], (
int)gl2ps->viewport[3]);
4020 gl2ps->pdfprimlist =
gl2psListCreate(500, 500,
sizeof(GL2PSprimitive*));
4023 gl2ps->xreflist = (
int*)
gl2psMalloc(
sizeof(
int) * gl2ps->objects_stack);
4025 #if defined(GL2PS_HAVE_ZLIB)
4027 gl2psSetupCompress();
4030 gl2ps->xreflist[0] = 0;
4031 offs += fprintf(gl2ps->stream,
"%%PDF-1.4\n");
4032 gl2ps->xreflist[1] = offs;
4035 gl2ps->xreflist[2] = offs;
4038 gl2ps->xreflist[3] = offs;
4041 gl2ps->xreflist[4] = offs;
4044 gl2ps->xreflist[5] = offs;
4052 GL2PSprimitive *prim = *(GL2PSprimitive**)data;
4067 #if defined(GL2PS_HAVE_ZLIB)
4069 if(Z_OK != gl2psDeflate())
4072 fwrite(gl2ps->compress->dest, gl2ps->compress->destLen, 1, gl2ps->stream);
4073 gl2ps->streamlength += gl2ps->compress->destLen;
4075 offs += gl2ps->streamlength;
4076 gl2psFreeCompress();
4080 offs += fprintf(gl2ps->stream,
4090 return fprintf(gl2ps->stream,
4104 offs = fprintf(gl2ps->stream,
4109 "/MediaBox [%d %d %d %d]\n",
4110 (
int)gl2ps->viewport[0], (
int)gl2ps->viewport[1],
4111 (
int)gl2ps->viewport[2], (
int)gl2ps->viewport[3]);
4114 offs += fprintf(gl2ps->stream,
"/Rotate -90\n");
4116 offs += fprintf(gl2ps->stream,
4120 "/ProcSet [/PDF /Text /ImageB /ImageC] %%/ImageI\n");
4144 offs += fprintf(gl2ps->stream,
4155 return fprintf(gl2ps->stream,
4158 "/Type /ExtGState\n"
4174 size_t (*action)(
unsigned long data,
4176 GLfloat dx, GLfloat dy,
4177 GLfloat xmin, GLfloat ymin)
4186 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4188 offs += (*action)(edgeflag, 1);
4194 offs += (*action)(0, 4);
4195 offs += (*action)(0, 4);
4198 diff = (vertex->xyz[0] -
xmin) / dx;
4203 imap = (
unsigned long)(diff * dmax);
4204 offs += (*action)(imap, 4);
4206 diff = (vertex->xyz[1] -
ymin) / dy;
4211 imap = (
unsigned long)(diff * dmax);
4212 offs += (*action)(imap, 4);
4221 size_t (*action)(
unsigned long data,
4229 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4231 imap = (
unsigned long)((vertex->rgba[0]) * dmax);
4232 offs += (*action)(imap, 1);
4234 imap = (
unsigned long)((vertex->rgba[1]) * dmax);
4235 offs += (*action)(imap, 1);
4237 imap = (
unsigned long)((vertex->rgba[2]) * dmax);
4238 offs += (*action)(imap, 1);
4246 size_t (*action)(
unsigned long data,
4255 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4257 if(sigbyte != 8 && sigbyte != 16)
4262 imap = (
unsigned long)((vertex->rgba[3]) * dmax);
4264 offs += (*action)(imap, sigbyte);
4272 GLfloat dx, GLfloat dy,
4273 GLfloat xmin, GLfloat ymin,
4274 size_t (*action)(
unsigned long data,
4281 if(gray && gray != 8 && gray != 16)
4284 for(i = 0; i < 3; ++i){
4286 dx, dy, xmin, ymin);
4288 v = triangle->vertex[i];
4300 GLfloat *ymin, GLfloat *
ymax,
4301 GL2PStriangle *triangles,
int cnt)
4305 *xmin = triangles[0].vertex[0].xyz[0];
4306 *xmax = triangles[0].vertex[0].xyz[0];
4307 *ymin = triangles[0].vertex[0].xyz[1];
4308 *ymax = triangles[0].vertex[0].xyz[1];
4310 for(i = 0; i <
cnt; ++i){
4311 for(j = 0; j < 3; ++j){
4312 if(*xmin > triangles[i].vertex[j].xyz[0])
4313 *xmin = triangles[i].vertex[j].xyz[0];
4314 if(*xmax < triangles[i].vertex[j].xyz[0])
4315 *xmax = triangles[i].vertex[j].xyz[0];
4316 if(*ymin > triangles[i].vertex[j].xyz[1])
4317 *ymin = triangles[i].vertex[j].xyz[1];
4318 if(*ymax < triangles[i].vertex[j].xyz[1])
4319 *ymax = triangles[i].vertex[j].xyz[1];
4332 int i, offs = 0, vertexbytes, done = 0;
4337 vertexbytes = 1+4+4+1+1+1;
4340 vertexbytes = 1+4+4+1;
4343 vertexbytes = 1+4+4+2;
4347 vertexbytes = 1+4+4+1;
4353 offs += fprintf(gl2ps->stream,
4358 "/BitsPerCoordinate 32 "
4359 "/BitsPerComponent %d "
4361 "/Decode [%f %f %f %f 0 1 %s] ",
4363 (gray) ?
"/DeviceGray" :
"/DeviceRGB",
4365 xmin, xmax, ymin, ymax,
4366 (gray) ?
"" :
"0 1 0 1");
4368 #if defined(GL2PS_HAVE_ZLIB)
4370 gl2psAllocCompress(vertexbytes * size * 3);
4372 for(i = 0; i < size; ++i)
4374 xmax-xmin, ymax-ymin, xmin, ymin,
4375 gl2psWriteBigEndianCompress, gray);
4377 if(Z_OK == gl2psDeflate() && 23 + gl2ps->compress->destLen < gl2ps->compress->srcLen){
4379 offs += fprintf(gl2ps->stream,
4383 (
int)gl2ps->compress->destLen);
4384 offs += gl2ps->compress->destLen * fwrite(gl2ps->compress->dest,
4385 gl2ps->compress->destLen,
4389 gl2psFreeCompress();
4396 offs += fprintf(gl2ps->stream,
4400 vertexbytes * 3 * size);
4401 for(i = 0; i < size; ++i)
4403 xmax-xmin, ymax-ymin, xmin, ymin,
4407 offs += fprintf(gl2ps->stream,
4420 offs += fprintf(gl2ps->stream,
4425 "/BBox [ %d %d %d %d ]\n"
4426 "/Group \n<<\n/S /Transparency /CS /DeviceRGB\n"
4429 (
int)gl2ps->viewport[0], (
int)gl2ps->viewport[1],
4430 (
int)gl2ps->viewport[2], (
int)gl2ps->viewport[3]);
4433 ? strlen(
"/TrSh sh\n") + (int)
log10((
double)childobj)+1
4434 : strlen(
"/TrSh0 sh\n");
4436 offs += fprintf(gl2ps->stream,
4441 offs += fprintf(gl2ps->stream,
4444 offs += fprintf(gl2ps->stream,
4459 offs += fprintf(gl2ps->stream,
4464 offs += fprintf(gl2ps->stream,
4465 "/SMask << /S /Alpha /G %d 0 R >> ",
4468 offs += fprintf(gl2ps->stream,
4480 offs += fprintf(gl2ps->stream,
4493 size_t (*action)(
unsigned long data,
4500 if(im->format != GL_RGBA && gray)
4503 if(gray && gray !=8 && gray != 16)
4508 for(y = 0; y < im->height; ++
y){
4509 for(x = 0; x < im->width; ++
x){
4511 if(im->format == GL_RGBA && gray){
4512 (*action)((
unsigned long)(a*255) << 24, gray);
4515 (*action)((
unsigned long)(r*255) << 24, 1);
4516 (*action)((
unsigned long)(g*255) << 24, 1);
4517 (*action)((
unsigned long)(b*255) << 24, 1);
4523 case 0:
return 3 * im->width * im->height;
4524 case 1:
return im->width * im->height;
4525 case 2:
return 2 * im->width * im->height;
4526 default:
return 3 * im->width * im->height;
4532 int offs = 0, done = 0, sigbytes = 3;
4534 if(gray && gray !=8 && gray != 16)
4538 sigbytes = gray / 8;
4540 offs += fprintf(gl2ps->stream,
4548 "/BitsPerComponent 8\n",
4550 (
int)im->width, (
int)im->height,
4551 (gray) ?
"/DeviceGray" :
"/DeviceRGB" );
4552 if(GL_RGBA == im->format && gray == 0){
4553 offs += fprintf(gl2ps->stream,
4558 #if defined(GL2PS_HAVE_ZLIB)
4560 gl2psAllocCompress((
int)(im->width * im->height * sigbytes));
4564 if(Z_OK == gl2psDeflate() && 23 + gl2ps->compress->destLen < gl2ps->compress->srcLen){
4566 offs += fprintf(gl2ps->stream,
4570 (
int)gl2ps->compress->destLen);
4571 offs += gl2ps->compress->destLen * fwrite(gl2ps->compress->dest, gl2ps->compress->destLen,
4575 gl2psFreeCompress();
4582 offs += fprintf(gl2ps->stream,
4586 (
int)(im->width * im->height * sigbytes));
4590 offs += fprintf(gl2ps->stream,
4601 offs += fprintf(gl2ps->stream,
4608 "/Encoding /MacRomanEncoding\n"
4611 obj, fontnumber, s->fontname);
4620 GL2PSprimitive *p =
NULL;
4622 int offs = entryoffs;
4623 GL2PStriangle *triangles;
4626 if(!gl2ps->pdfgrouplist)
4629 for(i = 0; i <
gl2psListNbr(gl2ps->pdfgrouplist); ++i){
4641 triangles = (GL2PStriangle*)
gl2psMalloc(
sizeof(GL2PStriangle) * size);
4642 for(j = 0; j < size; ++j){
4647 gl2ps->xreflist[gro->shobjno] = offs;
4651 gl2ps->xreflist[gro->gsobjno] = offs;
4655 gl2ps->xreflist[gro->gsobjno] = offs;
4657 gl2ps->xreflist[gro->trgroupobjno] = offs;
4659 gl2ps->xreflist[gro->maskshobjno] = offs;
4665 gl2ps->xreflist[gro->imobjno] = offs;
4667 if(p->data.image->format == GL_RGBA){
4668 gl2ps->xreflist[gro->imobjno+1] = offs;
4673 gl2ps->xreflist[gro->fontobjno] = offs;
4679 if(p->data.text->alignment ==
GL2PS_PDF)
4680 offs += fprintf(gl2ps->stream,
"%s\n", p->data.text->str);
4700 offs = gl2ps->xreflist[5] + gl2ps->streamlength;
4702 gl2ps->xreflist[5] = offs;
4705 gl2ps->xreflist[6] = offs;
4706 gl2ps->streamlength = 0;
4711 sizeof(
int) * (gl2ps->objects_stack + 1));
4712 gl2ps->xreflist[7] = offs;
4715 gl2ps->xreflist[8] = offs;
4717 gl2ps->xreflist[gl2ps->objects_stack] =
4722 fprintf(gl2ps->stream,
4725 "%010d 65535 f \n", gl2ps->objects_stack, 0);
4727 for(i = 1; i < gl2ps->objects_stack; ++i)
4728 fprintf(gl2ps->stream,
"%010d 00000 n \n", gl2ps->xreflist[i]);
4730 fprintf(gl2ps->stream,
4739 gl2ps->objects_stack, gl2ps->xreflist[gl2ps->objects_stack]);
4747 #if defined(GL2PS_HAVE_ZLIB)
4749 gl2psFreeCompress();
4751 gl2ps->compress =
NULL;
4763 int x = viewport[0],
y = viewport[1],
w = viewport[2],
h = viewport[3];
4765 glRenderMode(GL_FEEDBACK);
4769 gl2ps->header = GL_FALSE;
4775 if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){
4776 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
4779 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &index);
4780 rgba[0] = gl2ps->colormap[index][0];
4781 rgba[1] = gl2ps->colormap[index][1];
4782 rgba[2] = gl2ps->colormap[index][2];
4798 gl2ps->streamlength += offs;
4816 static GL2PSbackend gl2psPDF = {
4824 "Portable Document Format"
4838 for(i = 0; i <
n; i++){
4839 xyz[i][0] = verts[i].xyz[0];
4840 xyz[i][1] = gl2ps->viewport[3] - verts[i].xyz[1];
4842 for(j = 0; j < 4; j++)
4843 rgba[i][j] = verts[i].rgba[j];
4849 int r = (int)(255. * rgba[0]);
4850 int g = (int)(255. * rgba[1]);
4851 int b = (int)(255. * rgba[2]);
4852 int rc = (r < 0) ? 0 : (r > 255) ? 255 : r;
4853 int gc = (g < 0) ? 0 : (g > 255) ? 255 : g;
4854 int bc = (b < 0) ? 0 : (b > 255) ? 255 : b;
4855 sprintf(str,
"#%2.2x%2.2x%2.2x", rc, gc, bc);
4860 int x,
y, width, height;
4867 x = (int)gl2ps->viewport[1];
4868 y = (
int)gl2ps->viewport[0];
4869 width = (int)gl2ps->viewport[3];
4870 height = (
int)gl2ps->viewport[2];
4873 x = (int)gl2ps->viewport[0];
4874 y = (
int)gl2ps->viewport[1];
4875 width = (int)gl2ps->viewport[2];
4876 height = (
int)gl2ps->viewport[3];
4882 gl2psPrintf(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
4883 gl2psPrintf(
"<svg xmlns=\"http://www.w3.org/2000/svg\"\n");
4884 gl2psPrintf(
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
4885 " width=\"%dpx\" height=\"%dpx\" viewBox=\"%d %d %d %d\">\n",
4886 width, height, x, y, width, height);
4900 gl2psPrintf(
"<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", col,
4901 (
int)gl2ps->viewport[0], (
int)gl2ps->viewport[1],
4902 (
int)gl2ps->viewport[2], (
int)gl2ps->viewport[1],
4903 (
int)gl2ps->viewport[2], (
int)gl2ps->viewport[3],
4904 (
int)gl2ps->viewport[0], (
int)gl2ps->viewport[3]);
4908 gl2psPrintf(
"<g shape-rendering=\"crispEdges\">\n");
4925 if(rgba[0][3] < 1.0
F)
gl2psPrintf(
"fill-opacity=\"%g\" ", rgba[0][3]);
4926 gl2psPrintf(
"points=\"%g,%g %g,%g %g,%g\"/>\n", xyz[0][0], xyz[0][1],
4927 xyz[1][0], xyz[1][1], xyz[2][0], xyz[2][1]);
4931 for(i = 0; i < 3; i++){
4932 xyz2[0][i] = xyz[0][i];
4933 xyz2[1][i] = 0.5 * (xyz[0][i] + xyz[1][i]);
4934 xyz2[2][i] = 0.5 * (xyz[0][i] + xyz[2][i]);
4936 for(i = 0; i < 4; i++){
4937 rgba2[0][i] = rgba[0][i];
4938 rgba2[1][i] = 0.5 * (rgba[0][i] + rgba[1][i]);
4939 rgba2[2][i] = 0.5 * (rgba[0][i] + rgba[2][i]);
4942 for(i = 0; i < 3; i++){
4943 xyz2[0][i] = 0.5 * (xyz[0][i] + xyz[1][i]);
4944 xyz2[1][i] = xyz[1][i];
4945 xyz2[2][i] = 0.5 * (xyz[1][i] + xyz[2][i]);
4947 for(i = 0; i < 4; i++){
4948 rgba2[0][i] = 0.5 * (rgba[0][i] + rgba[1][i]);
4949 rgba2[1][i] = rgba[1][i];
4950 rgba2[2][i] = 0.5 * (rgba[1][i] + rgba[2][i]);
4953 for(i = 0; i < 3; i++){
4954 xyz2[0][i] = 0.5 * (xyz[0][i] + xyz[2][i]);
4955 xyz2[1][i] = xyz[2][i];
4956 xyz2[2][i] = 0.5 * (xyz[1][i] + xyz[2][i]);
4958 for(i = 0; i < 4; i++){
4959 rgba2[0][i] = 0.5 * (rgba[0][i] + rgba[2][i]);
4960 rgba2[1][i] = rgba[2][i];
4961 rgba2[2][i] = 0.5 * (rgba[1][i] + rgba[2][i]);
4964 for(i = 0; i < 3; i++){
4965 xyz2[0][i] = 0.5 * (xyz[0][i] + xyz[1][i]);
4966 xyz2[1][i] = 0.5 * (xyz[1][i] + xyz[2][i]);
4967 xyz2[2][i] = 0.5 * (xyz[0][i] + xyz[2][i]);
4969 for(i = 0; i < 4; i++){
4970 rgba2[0][i] = 0.5 * (rgba[0][i] + rgba[1][i]);
4971 rgba2[1][i] = 0.5 * (rgba[1][i] + rgba[2][i]);
4972 rgba2[2][i] = 0.5 * (rgba[0][i] + rgba[2][i]);
4980 int i,
n, array[10];
4982 if(!pattern || !factor)
return;
4986 for(i = 0; i <
n; i++){
4996 if(gl2ps->lastvertex.rgba[0] >= 0.){
4997 gl2psPrintf(
"%g,%g\"/>\n", gl2ps->lastvertex.xyz[0],
4998 gl2ps->viewport[3] - gl2ps->lastvertex.xyz[1]);
4999 for(i = 0; i < 3; i++)
5000 gl2ps->lastvertex.xyz[i] = -1.;
5001 for(i = 0; i < 4; i++)
5002 gl2ps->lastvertex.rgba[i] = -1.;
5008 #if defined(GL2PS_HAVE_LIBPNG)
5020 sizeof(
unsigned char));
5021 gl2psConvertPixmapToPNG(pixmap, png);
5022 gl2psListEncodeBase64(png);
5023 gl2psPrintf(
"<image x=\"%g\" y=\"%g\" width=\"%d\" height=\"%d\"\n",
5024 x,
y - pixmap->height, pixmap->width, pixmap->height);
5025 gl2psPrintf(
"xlink:href=\"data:image/png;base64,");
5027 gl2psListRead(png, i, &c);
5034 "order to embed images in SVG streams");
5040 GL2PSprimitive *prim;
5046 prim = *(GL2PSprimitive**)data;
5061 if(rgba[0][3] < 1.0
F)
gl2psPrintf(
"fill-opacity=\"%g\" ", rgba[0][3]);
5063 xyz[0][0], xyz[0][1], 0.5 * prim->width);
5068 gl2ps->lastlinewidth != prim->width ||
5069 gl2ps->lastpattern != prim->pattern ||
5070 gl2ps->lastfactor != prim->factor){
5081 gl2ps->lastvertex = prim->verts[1];
5083 gl2ps->lastlinewidth = prim->width;
5084 gl2ps->lastpattern = prim->pattern;
5085 gl2ps->lastfactor = prim->factor;
5088 gl2psPrintf(
"<polyline fill=\"none\" stroke=\"%s\" stroke-width=\"%g\" ",
5090 if(rgba[0][3] < 1.0
F)
gl2psPrintf(
"stroke-opacity=\"%g\" ", rgba[0][3]);
5092 gl2psPrintf(
"points=\"%g,%g ", xyz[0][0], xyz[0][1]);
5109 gl2psPrintf(
"<text fill=\"%s\" x=\"%g\" y=\"%g\" font-size=\"%d\" ",
5110 col, xyz[0][0], xyz[0][1], prim->data.text->fontsize);
5111 if(!strcmp(prim->data.text->fontname,
"Times-Roman"))
5113 else if(!strcmp(prim->data.text->fontname,
"Times-Bold"))
5114 gl2psPrintf(
"font-family=\"Times\" font-weight=\"bold\">");
5115 else if(!strcmp(prim->data.text->fontname,
"Times-Italic"))
5116 gl2psPrintf(
"font-family=\"Times\" font-style=\"italic\">");
5117 else if(!strcmp(prim->data.text->fontname,
"Times-BoldItalic"))
5118 gl2psPrintf(
"font-family=\"Times\" font-style=\"italic\" font-weight=\"bold\">");
5119 else if(!strcmp(prim->data.text->fontname,
"Helvetica-Bold"))
5120 gl2psPrintf(
"font-family=\"Helvetica\" font-weight=\"bold\">");
5121 else if(!strcmp(prim->data.text->fontname,
"Helvetica-Oblique"))
5122 gl2psPrintf(
"font-family=\"Helvetica\" font-style=\"oblique\">");
5123 else if(!strcmp(prim->data.text->fontname,
"Helvetica-BoldOblique"))
5124 gl2psPrintf(
"font-family=\"Helvetica\" font-style=\"oblique\" font-weight=\"bold\">");
5125 else if(!strcmp(prim->data.text->fontname,
"Courier-Bold"))
5126 gl2psPrintf(
"font-family=\"Courier\" font-weight=\"bold\">");
5127 else if(!strcmp(prim->data.text->fontname,
"Courier-Oblique"))
5128 gl2psPrintf(
"font-family=\"Courier\" font-style=\"oblique\">");
5129 else if(!strcmp(prim->data.text->fontname,
"Courier-BoldOblique"))
5130 gl2psPrintf(
"font-family=\"Courier\" font-style=\"oblique\" font-weight=\"bold\">");
5132 gl2psPrintf(
"font-family=\"%s\">", prim->data.text->fontname);
5138 if(prim->data.text->alignment ==
GL2PS_SVG)
5159 int x = viewport[0],
y = viewport[1],
w = viewport[2],
h = viewport[3];
5161 glRenderMode(GL_FEEDBACK);
5165 gl2ps->header = GL_FALSE;
5169 if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){
5170 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
5173 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &index);
5174 rgba[0] = gl2ps->colormap[index][0];
5175 rgba[1] = gl2ps->colormap[index][1];
5176 rgba[2] = gl2ps->colormap[index][2];
5180 gl2psPrintf(
"<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", col,
5181 x, gl2ps->viewport[3] - y,
5182 x + w, gl2ps->viewport[3] - y,
5183 x + w, gl2ps->viewport[3] - (y + h),
5184 x, gl2ps->viewport[3] - (y + h));
5187 gl2psPrintf(
"<clipPath id=\"cp%d%d%d%d\">\n", x, y, w, h);
5188 gl2psPrintf(
" <polygon points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n",
5189 x, gl2ps->viewport[3] - y,
5190 x + w, gl2ps->viewport[3] - y,
5191 x + w, gl2ps->viewport[3] - (y + h),
5192 x, gl2ps->viewport[3] - (y + h));
5194 gl2psPrintf(
"<g clip-path=\"url(#cp%d%d%d%d)\">\n", x, y, w, h);
5214 static GL2PSbackend gl2psSVG = {
5222 "Scalable Vector Graphics"
5235 fprintf(gl2ps->stream,
"\\color[rgb]{%f,%f,%f}\n", rgba[0], rgba[1], rgba[2]);
5245 fprintf(gl2ps->stream,
5247 "%% Creator: GL2PS %d.%d.%d%s, %s\n"
5249 "%% CreationDate: %s",
5252 gl2ps->producer, ctime(&now));
5254 fprintf(gl2ps->stream,
"\\begin{pgfpicture}\n");
5257 fprintf(gl2ps->stream,
5258 "\\pgfpathrectanglecorners{"
5259 "\\pgfpoint{%dpt}{%dpt}}{\\pgfpoint{%dpt}{%dpt}}\n"
5260 "\\pgfusepath{fill}\n",
5261 (
int)gl2ps->viewport[0], (
int)gl2ps->viewport[1],
5262 (
int)gl2ps->viewport[2], (
int)gl2ps->viewport[3]);
5268 int i,
n, array[10];
5270 if(pattern == gl2ps->lastpattern && factor == gl2ps->lastfactor)
5274 gl2ps->lastfactor = factor;
5276 if(!pattern || !factor){
5278 fprintf(gl2ps->stream,
"\\pgfsetdash{}{0pt}\n");
5282 fprintf(gl2ps->stream,
"\\pgfsetdash{");
5283 for(i = 0; i <
n; i++) fprintf(gl2ps->stream,
"{%dpt}", array[i]);
5284 fprintf(gl2ps->stream,
"}{0pt}\n");
5300 default :
return "south west";
5306 GL2PSprimitive *prim;
5308 prim = *(GL2PSprimitive**)data;
5314 fprintf(gl2ps->stream,
5315 "\\pgfpathrectangle{\\pgfpoint{%fpt}{%fpt}}"
5316 "{\\pgfpoint{%fpt}{%fpt}}\n\\pgfusepath{fill}\n",
5317 prim->verts[0].xyz[0]-0.5*prim->width,
5318 prim->verts[0].xyz[1]-0.5*prim->width,
5319 prim->width,prim->width);
5323 if(gl2ps->lastlinewidth != prim->width){
5324 gl2ps->lastlinewidth = prim->width;
5325 fprintf(gl2ps->stream,
"\\pgfsetlinewidth{%fpt}\n", gl2ps->lastlinewidth);
5328 fprintf(gl2ps->stream,
5329 "\\pgfpathmoveto{\\pgfpoint{%fpt}{%fpt}}\n"
5330 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5331 "\\pgfusepath{stroke}\n",
5332 prim->verts[1].xyz[0], prim->verts[1].xyz[1],
5333 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
5336 if(gl2ps->lastlinewidth != 0){
5337 gl2ps->lastlinewidth = 0;
5338 fprintf(gl2ps->stream,
"\\pgfsetlinewidth{0.01pt}\n");
5341 fprintf(gl2ps->stream,
5342 "\\pgfpathmoveto{\\pgfpoint{%fpt}{%fpt}}\n"
5343 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5344 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5346 "\\pgfusepath{fill,stroke}\n",
5347 prim->verts[2].xyz[0], prim->verts[2].xyz[1],
5348 prim->verts[1].xyz[0], prim->verts[1].xyz[1],
5349 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
5352 fprintf(gl2ps->stream,
"{\n\\pgftransformshift{\\pgfpoint{%fpt}{%fpt}}\n",
5353 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
5355 if(prim->data.text->angle)
5356 fprintf(gl2ps->stream,
"\\pgftransformrotate{%f}{", prim->data.text->angle);
5358 fprintf(gl2ps->stream,
"\\pgfnode{rectangle}{%s}{\\fontsize{%d}{0}\\selectfont",
5360 prim->data.text->fontsize);
5362 fprintf(gl2ps->stream,
"\\textcolor[rgb]{%g,%g,%g}{{%s}}",
5363 prim->verts[0].rgba[0], prim->verts[0].rgba[1],
5364 prim->verts[0].rgba[2], prim->data.text->str);
5366 fprintf(gl2ps->stream,
"}{}{\\pgfusepath{discard}}}\n");
5371 if (prim->data.text->alignment ==
GL2PS_PGF)
5372 fprintf(gl2ps->stream,
"%s\n", prim->data.text->str);
5381 fprintf(gl2ps->stream,
"\\end{pgfpicture}\n");
5388 int x = viewport[0],
y = viewport[1],
w = viewport[2],
h = viewport[3];
5390 glRenderMode(GL_FEEDBACK);
5394 gl2ps->header = GL_FALSE;
5397 fprintf(gl2ps->stream,
"\\begin{pgfscope}\n");
5399 if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){
5400 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
5403 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &index);
5404 rgba[0] = gl2ps->colormap[index][0];
5405 rgba[1] = gl2ps->colormap[index][1];
5406 rgba[2] = gl2ps->colormap[index][2];
5410 fprintf(gl2ps->stream,
5411 "\\pgfpathrectangle{\\pgfpoint{%dpt}{%dpt}}"
5412 "{\\pgfpoint{%dpt}{%dpt}}\n"
5413 "\\pgfusepath{fill}\n",
5417 fprintf(gl2ps->stream,
5418 "\\pgfpathrectangle{\\pgfpoint{%dpt}{%dpt}}"
5419 "{\\pgfpoint{%dpt}{%dpt}}\n"
5420 "\\pgfusepath{clip}\n",
5428 fprintf(gl2ps->stream,
"\\end{pgfscope}\n");
5438 static GL2PSbackend gl2psPGF = {
5446 "PGF Latex Graphics"
5458 static GL2PSbackend *gl2psbackends[] = {
5469 GL2PSprimitive *prim;
5472 prim = *(GL2PSprimitive**)data;
5474 for(i = 0; i < prim->numverts; i++){
5475 if(prim->verts[i].xyz[0] < gl2ps->viewport[0])
5476 gl2ps->viewport[0] = (GLint)prim->verts[i].xyz[0];
5477 if(prim->verts[i].xyz[0] > gl2ps->viewport[2])
5478 gl2ps->viewport[2] = (GLint)(prim->verts[i].xyz[0] + 0.5F);
5479 if(prim->verts[i].xyz[1] < gl2ps->viewport[1])
5480 gl2ps->viewport[1] = (GLint)prim->verts[i].xyz[1];
5481 if(prim->verts[i].xyz[1] > gl2ps->viewport[3])
5482 gl2ps->viewport[3] = (GLint)(prim->verts[i].xyz[1] + 0.5F);
5492 used = glRenderMode(GL_RENDER);
5507 gl2ps->viewport[0] = gl2ps->viewport[1] = 100000;
5508 gl2ps->viewport[2] = gl2ps->viewport[3] = -100000;
5511 (gl2psbackends[gl2ps->format]->printHeader)();
5512 gl2ps->header = GL_FALSE;
5520 switch(gl2ps->sort){
5522 gl2psListAction(gl2ps->primitives, gl2psbackends[gl2ps->format]->printPrimitive);
5533 gl2psListAction(gl2ps->primitives, gl2psbackends[gl2ps->format]->printPrimitive);
5548 gl2psbackends[gl2ps->format]->printPrimitive, 0);
5552 gl2ps->primitives =
gl2psListCreate(500, 500,
sizeof(GL2PSprimitive*));
5555 gl2psbackends[gl2ps->format]->printFinalPrimitive();
5567 GLint viewport[4], GLint
format, GLint sort,
5568 GLint options, GLint colormode,
5570 GLint nr, GLint ng, GLint nb, GLint buffersize,
5571 FILE *stream,
const char *
filename)
5581 gl2ps = (GL2PScontext*)
gl2psMalloc(
sizeof(GL2PScontext));
5583 if(format >= 0 && format < (GLint)(
sizeof(
gl2psbackends) /
sizeof(gl2psbackends[0]))){
5607 gl2ps->stream = stream;
5616 gl2ps->header = GL_TRUE;
5617 gl2ps->maxbestroot = 10;
5618 gl2ps->options = options;
5619 gl2ps->compress =
NULL;
5620 gl2ps->imagemap_head =
NULL;
5621 gl2ps->imagemap_tail =
NULL;
5624 glGetIntegerv(GL_VIEWPORT, gl2ps->viewport);
5627 for(i = 0; i < 4; i++){
5628 gl2ps->viewport[i] = viewport[i];
5632 if(!gl2ps->viewport[2] || !gl2ps->viewport[3]){
5634 gl2ps->viewport[0], gl2ps->viewport[1],
5635 gl2ps->viewport[2], gl2ps->viewport[3]);
5641 gl2ps->threshold[0] = nr ? 1.0F / (GLfloat)nr : 0.064
F;
5642 gl2ps->threshold[1] = ng ? 1.0F / (GLfloat)ng : 0.034
F;
5643 gl2ps->threshold[2] = nb ? 1.0F / (GLfloat)nb : 0.100
F;
5644 gl2ps->colormode = colormode;
5645 gl2ps->buffersize = buffersize > 0 ? buffersize : 2048 * 2048;
5646 for(i = 0; i < 3; i++){
5647 gl2ps->lastvertex.xyz[i] = -1.0F;
5649 for(i = 0; i < 4; i++){
5650 gl2ps->lastvertex.rgba[i] = -1.0F;
5651 gl2ps->lastrgba[i] = -1.0F;
5653 gl2ps->lastlinewidth = -1.0F;
5654 gl2ps->lastpattern = 0;
5655 gl2ps->lastfactor = 0;
5656 gl2ps->imagetree =
NULL;
5657 gl2ps->primitivetoadd =
NULL;
5658 gl2ps->zerosurfacearea = GL_FALSE;
5659 gl2ps->pdfprimlist =
NULL;
5660 gl2ps->pdfgrouplist =
NULL;
5661 gl2ps->xreflist =
NULL;
5665 gl2ps->blending = (gl2ps->format ==
GL2PS_SVG) ? GL_TRUE : glIsEnabled(GL_BLEND);
5666 glGetIntegerv(GL_BLEND_SRC, &gl2ps->blendfunc[0]);
5667 glGetIntegerv(GL_BLEND_DST, &gl2ps->blendfunc[1]);
5669 if(gl2ps->colormode == GL_RGBA){
5670 gl2ps->colorsize = 0;
5671 gl2ps->colormap =
NULL;
5672 glGetFloatv(GL_COLOR_CLEAR_VALUE, gl2ps->bgcolor);
5674 else if(gl2ps->colormode == GL_COLOR_INDEX){
5675 if(!colorsize || !colormap){
5681 gl2ps->colorsize = colorsize;
5683 memcpy(gl2ps->colormap, colormap, gl2ps->colorsize *
sizeof(
GL2PSrgba));
5684 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &index);
5685 gl2ps->bgcolor[0] = gl2ps->colormap[index][0];
5686 gl2ps->bgcolor[1] = gl2ps->colormap[index][1];
5687 gl2ps->bgcolor[2] = gl2ps->colormap[index][2];
5688 gl2ps->bgcolor[3] = 1.0F;
5699 gl2ps->title[0] =
'\0';
5702 gl2ps->title = (
char*)
gl2psMalloc((strlen(title)+1)*
sizeof(
char));
5703 strcpy(gl2ps->title, title);
5707 gl2ps->producer = (
char*)
gl2psMalloc(
sizeof(
char));
5708 gl2ps->producer[0] =
'\0';
5711 gl2ps->producer = (
char*)
gl2psMalloc((strlen(producer)+1)*
sizeof(
char));
5712 strcpy(gl2ps->producer, producer);
5716 gl2ps->filename = (
char*)
gl2psMalloc(
sizeof(
char));
5717 gl2ps->filename[0] =
'\0';
5720 gl2ps->filename = (
char*)
gl2psMalloc((strlen(filename)+1)*
sizeof(
char));
5721 strcpy(gl2ps->filename, filename);
5724 gl2ps->primitives =
gl2psListCreate(500, 500,
sizeof(GL2PSprimitive*));
5725 gl2ps->auxprimitives =
gl2psListCreate(100, 100,
sizeof(GL2PSprimitive*));
5726 gl2ps->feedback = (GLfloat*)
gl2psMalloc(gl2ps->buffersize *
sizeof(GLfloat));
5727 glFeedbackBuffer(gl2ps->buffersize, GL_3D_COLOR, gl2ps->feedback);
5728 glRenderMode(GL_FEEDBACK);
5742 (gl2psbackends[gl2ps->format]->printFooter)();
5744 fflush(gl2ps->stream);
5764 (gl2psbackends[gl2ps->format]->beginViewport)(viewport);
5775 res = (gl2psbackends[gl2ps->format]->endViewport)();
5778 gl2ps->lastlinewidth = -1.0F;
5784 GLshort fontsize, GLint
alignment, GLfloat angle)
5800 GLint xorig, GLint yorig,
5805 GLfloat pos[4], *piv;
5806 GL2PSprimitive *prim;
5811 if((width <= 0) || (height <= 0))
return GL2PS_ERROR;
5815 if((format != GL_RGB && format != GL_RGBA) || type != GL_FLOAT){
5817 "GL_RGB/GL_RGBA, GL_FLOAT pixels");
5821 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
5824 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
5826 prim = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
5830 prim->verts = (GL2PSvertex*)
gl2psMalloc(
sizeof(GL2PSvertex));
5831 prim->verts[0].xyz[0] = pos[0] + xorig;
5832 prim->verts[0].xyz[1] = pos[1] + yorig;
5833 prim->verts[0].xyz[2] = pos[2];
5839 glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba);
5840 prim->data.image = (GL2PSimage*)
gl2psMalloc(
sizeof(GL2PSimage));
5841 prim->data.image->width = width;
5842 prim->data.image->height = height;
5843 prim->data.image->format =
format;
5844 prim->data.image->type =
type;
5850 prim->data.image->format = GL_RGB;
5851 size = height * width * 3;
5852 prim->data.image->pixels = (GLfloat*)
gl2psMalloc(size *
sizeof(GLfloat));
5853 piv = (GLfloat*)pixels;
5854 for(i = 0; i < size; ++i, ++piv){
5855 prim->data.image->pixels[i] = *piv;
5861 size = height * width * 4;
5862 prim->data.image->pixels = (GLfloat*)
gl2psMalloc(size *
sizeof(GLfloat));
5863 memcpy(prim->data.image->pixels, pixels, size *
sizeof(GLfloat));
5868 size = height * width * 3;
5869 prim->data.image->pixels = (GLfloat*)
gl2psMalloc(size *
sizeof(GLfloat));
5870 memcpy(prim->data.image->pixels, pixels, size *
sizeof(GLfloat));
5881 const GLfloat position[3],
5882 const unsigned char *imagemap){
5884 int sizeoffloat =
sizeof(GLfloat);
5888 if((width <= 0) || (height <= 0))
return GL2PS_ERROR;
5890 size = height + height * ((width - 1) / 8);
5893 glVertex3f(position[0], position[1],position[2]);
5895 glPassThrough((GLfloat)width);
5896 glPassThrough((GLfloat)height);
5897 for(i = 0; i < size; i += sizeoffloat){
5898 float *
value = (
float*)imagemap;
5899 glPassThrough(*value);
5900 imagemap += sizeoffloat;
5914 glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &gl2ps->offset[0]);
5915 glGetFloatv(GL_POLYGON_OFFSET_UNITS, &gl2ps->offset[1]);
5922 glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &tmp);
5923 glPassThrough((GLfloat)tmp);
5924 glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &tmp);
5925 glPassThrough((GLfloat)tmp);
5968 glPassThrough(value);
5978 glPassThrough(value);
5991 glPassThrough((GLfloat)sfactor);
5993 glPassThrough((GLfloat)dfactor);
6002 gl2ps->options = options;
6014 *options = gl2ps->options;
6021 if(format >= 0 && format < (GLint)(
sizeof(gl2psbackends) /
sizeof(gl2psbackends[0])))
6022 return gl2psbackends[
format]->file_extension;
6024 return "Unknown format";
6029 if(format >= 0 && format < (GLint)(
sizeof(gl2psbackends) /
sizeof(gl2psbackends[0])))
6030 return gl2psbackends[
format]->description;
6032 return "Unknown format";
GL2PSDLL_API GLint gl2psPointSize(GLfloat value)
#define GL2PS_POINT_COINCIDENT
static int gl2psPrintPDFShaderStreamDataAlpha(GL2PSvertex *vertex, size_t(*action)(unsigned long data, size_t size), int sigbyte)
GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4])
static void gl2psPutPDFText(GL2PSstring *text, int cnt, GLfloat x, GLfloat y)
#define GL2PS_LINE_WIDTH_TOKEN
#define GL2PS_ZOFFSET_LARGE
static int gl2psClosePDFDataStream(void)
static void gl2psWriteByte(unsigned char byte)
static void gl2psPrintSVGSmoothTriangle(GL2PSxyz xyz[3], GL2PSrgba rgba[3])
static int gl2psPrintPDFShader(int obj, GL2PStriangle *triangles, int size, int gray)
static int gl2psPrintPDFLineWidth(GLfloat lw)
static void gl2psPrintTeXFinalPrimitive(void)
static GLboolean gl2psLess(GLfloat f1, GLfloat f2)
#define GL2PS_IMAGEMAP_VISIBLE
GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, GLint viewport[4], GLint format, GLint sort, GLint options, GLint colormode, GLint colorsize, GL2PSrgba *colormap, GLint nr, GLint ng, GLint nb, GLint buffersize, FILE *stream, const char *filename)
static GLint gl2psFindRoot(GL2PSlist *primitives, GL2PSprimitive **root)
static int gl2psPrintPDFCatalog(void)
static GL2PSbackend gl2psEPS
static GLint gl2psAddText(GLint type, const char *str, const char *fontname, GLshort fontsize, GLint alignment, GLfloat angle)
GL2PSDLL_API GLint gl2psEndPage(void)
static void gl2psFreeText(GL2PSstring *text)
static GL2PSprimitive * gl2psCopyPrimitive(GL2PSprimitive *p)
static void gl2psFillTriangleFromPrimitive(GL2PStriangle *t, GL2PSprimitive *p, GLboolean assignprops)
static int gl2psPDFgroupListWriteGStateResources(void)
static const char * gl2psPGFTextAlignment(int align)
GL2PSDLL_API GLint gl2psLineWidth(GLfloat value)
static GLint gl2psCheckPrimitive(GL2PSprimitive *prim, GL2PSplane plane)
static void gl2psSetLastColor(GL2PSrgba rgba)
static int gl2psPrintPDFCompressorType(void)
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
static int gl2psPDFgroupListWriteShaderResources(void)
RooArgList L(const RooAbsArg &v1)
static int gl2psPDFgroupListWriteXObjectResources(void)
static void * gl2psRealloc(void *ptr, size_t size)
static void gl2psPDFgroupListInit(void)
GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize)
static void gl2psPrintSVGBeginViewport(GLint viewport[4])
#define GL2PS_IN_FRONT_OF
static GLshort gl2psGetIndex(GLshort i, GLshort num)
static GL2PSprimitive * gl2psCreateSplitPrimitive2D(GL2PSprimitive *parent, GLshort numverts, GL2PSvertex *vertx)
#define GL2PS_DST_BLEND_TOKEN
static void gl2psAddPrimitiveInList(GL2PSprimitive *prim, GL2PSlist *list)
static GL2PSstring * gl2psCopyText(GL2PSstring *t)
#define GL2PS_POINT_INFRONT
static void gl2psPrintPostScriptFinalPrimitive(void)
static GLint gl2psGetVertex(GL2PSvertex *v, GLfloat *p)
static void gl2psGetPlane(GL2PSprimitive *prim, GL2PSplane plane)
static void gl2psFreePrimitive(void *data)
static void gl2psPrintGzipHeader()
int compare(double v1, double v2, const std::string &name="", double scale=1.0)
static void gl2psPrintPostScriptHeader(void)
static const char * filename()
static GLfloat gl2psGetRGB(GL2PSimage *im, GLuint x, GLuint y, GLfloat *red, GLfloat *green, GLfloat *blue)
static void gl2psAdaptVertexForBlending(GL2PSvertex *v)
static void gl2psPrintSVGPrimitive(void *data)
#define GL2PS_DRAW_BACKGROUND
static int gl2psPrintPDFInfo(void)
#define GL2PS_EXTRA_VERSION
static int gl2psCompareDepth(const void *a, const void *b)
GL2PSDLL_API GLint gl2psBlendFunc(GLenum sfactor, GLenum dfactor)
static void gl2psPrintPDFFinalPrimitive(void)
GL2PSDLL_API GLint gl2psSetOptions(GLint options)
static void gl2psPrintPostScriptPrimitive(void *data)
static void gl2psPrintPDFBeginViewport(GLint viewport[4])
static std::string format(double x, double y, int digits, int width)
static GLfloat gl2psPsca(GLfloat *a, GLfloat *b)
#define GL2PS_MAJOR_VERSION
static void gl2psListAdd(GL2PSlist *list, void *data)
#define GL2PS_OCCLUSION_CULL
static void gl2psAddBoundaryInList(GL2PSprimitive *prim, GL2PSlist *list)
static void gl2psPrintPDFFooter(void)
static void gl2psPrintPGFBeginViewport(GLint viewport[4])
#define GL2PS_LINE_STIPPLE
static void gl2psPrintGzipFooter()
static GLint gl2psPrintPDFEndViewport(void)
static int gl2psPrintPDFShaderExtGS(int obj, int childobj)
static void gl2psPrintSVGFinalPrimitive(void)
static void gl2psParseStipplePattern(GLushort pattern, GLint factor, int *nb, int array[10])
static void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon, GLboolean(*compare)(GLfloat f1, GLfloat f2), void(*action)(void *data), int inverse)
static void gl2psFree(void *ptr)
static void gl2psComputeTightBoundingBox(void *data)
static void gl2psBuildPolygonBoundary(GL2PSbsptree *tree)
static void gl2psEndPostScriptLine(void)
static int gl2psPDFgroupListWriteVariableResources(void)
static double p2(double t, double a, double b, double c)
static int gl2psOpenPDFDataStreamWritePreface(void)
double pow(double, double)
static int gl2psPrintPDFGSObject(void)
static int gl2psPrintPDFShaderSimpleExtGS(int obj, GLfloat alpha)
static GLint gl2psTestSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane)
#define GL2PS_BEGIN_OFFSET_TOKEN
GL2PSDLL_API GLint gl2psEndViewport(void)
static int gl2psPrintPDFPages(void)
#define GL2PS_POLYGON_BOUNDARY
static void gl2psPrintPGFHeader(void)
static void gl2psListReset(GL2PSlist *list)
static int gl2psPrintPDFPixmapStreamData(GL2PSimage *im, size_t(*action)(unsigned long data, size_t size), int gray)
static void * gl2psListPointer(GL2PSlist *list, GLint index)
static GLint gl2psPrintPrimitives(void)
static GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree)
static void gl2psPrintPostScriptImagemap(GLfloat x, GLfloat y, GLsizei width, GLsizei height, const unsigned char *imagemap)
static void gl2psSortOutTrianglePDFgroup(GL2PSpdfgroup *gro)
#define GL2PS_UNINITIALIZED
static void gl2psListDelete(GL2PSlist *list)
#define GL2PS_BEGIN_STIPPLE_TOKEN
GL2PSDLL_API GLint gl2psTextOpt(const char *str, const char *fontname, GLshort fontsize, GLint alignment, GLfloat angle)
static int gl2psPrintPDFOpenPage(void)
static void gl2psPrintPGFFinalPrimitive(void)
static void gl2psPrintPGFPrimitive(void *data)
static void gl2psAddIndex(GLshort *index0, GLshort *index1, GLshort *nb, GLshort i, GLshort j)
static GL2PSimage * gl2psCopyPixmap(GL2PSimage *im)
static GLboolean gl2psSamePosition(GL2PSxyz p1, GL2PSxyz p2)
#define GL2PS_PATCH_VERSION
static void gl2psSVGGetCoordsAndColors(int n, GL2PSvertex *verts, GL2PSxyz *xyz, GL2PSrgba *rgba)
#define GL2PS_USE_CURRENT_VIEWPORT
static GLfloat gl2psNorm(GLfloat *a)
static void gl2psGetNormal(GLfloat *a, GLfloat *b, GLfloat *c)
static GLint gl2psPrintPostScriptEndViewport(void)
static int gl2psPrintPDFShaderMask(int obj, int childobj)
static void gl2psPrintTeXBeginViewport(GLint[4])
static void gl2psPrintSVGHeader(void)
GL2PSDLL_API const char * gl2psGetFormatDescription(GLint format)
#define GL2PS_TIGHT_BOUNDING_BOX
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
static void gl2psResetPostScriptColor(void)
static int gl2psPrintPDFDataStreamLength(int val)
static void gl2psListAction(GL2PSlist *list, void(*action)(void *data))
Double_t length(const TVector2 &v)
static void gl2psPrintSVGDash(GLushort pattern, GLint factor)
static int gl2psPDFgroupListWriteFontResources(void)
static GLfloat gl2psComparePointPlane(GL2PSxyz point, GL2PSplane plane)
#define GL2PS_BEGIN_BOUNDARY_TOKEN
static void * gl2psMalloc(size_t size)
static int gl2psPrintPDFStrokeColor(GL2PSrgba rgba)
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
static void gl2psPrintPGFColor(GL2PSrgba rgba)
static int gl2psListNbr(GL2PSlist *list)
static GL2PSbackend * gl2psbackends[]
static void gl2psListRealloc(GL2PSlist *list, GLint n)
static int gl2psPrintPDFPixmap(int obj, int childobj, GL2PSimage *im, int gray)
#define GL2PS_POINT_SIZE_TOKEN
static void gl2psSplitPrimitive2D(GL2PSprimitive *prim, GL2PSplane plane, GL2PSprimitive **front, GL2PSprimitive **back)
static GL2PScontext * gl2ps
static int gl2psPrintPDFShaderStreamDataCoord(GL2PSvertex *vertex, size_t(*action)(unsigned long data, size_t size), GLfloat dx, GLfloat dy, GLfloat xmin, GLfloat ymin)
static void gl2psPutPDFImage(GL2PSimage *image, int cnt, GLfloat x, GLfloat y)
#define GL2PS_MINOR_VERSION
static GLboolean gl2psSameColorThreshold(int n, GL2PSrgba rgba[], GL2PSrgba threshold)
static void gl2psPrintPGFFooter(void)
static int gl2psTrianglesFirst(const void *a, const void *b)
#define GL2PS_SIMPLE_SORT
static double p1(double t, double a, double b)
static GLboolean gl2psSameColor(GL2PSrgba rgba1, GL2PSrgba rgba2)
static void gl2psListSort(GL2PSlist *list, int(*fcmp)(const void *a, const void *b))
static void gl2psInitTriangle(GL2PStriangle *t)
GL2PSDLL_API const char * gl2psGetFileExtension(GLint format)
static void gl2psPrintTeXFooter(void)
static void gl2psFreeBspTree(GL2PSbsptree **tree)
struct _GL2PSimagemap GL2PSimagemap
static GL2PSbackend gl2psSVG
static void gl2psPrintSVGFooter(void)
static void gl2psParseFeedbackBuffer(GLint used)
static void gl2psPrintTeXHeader(void)
static GLboolean gl2psGreater(GLfloat f1, GLfloat f2)
#define GL2PS_END_BOUNDARY_TOKEN
GL2PSDLL_API GLint gl2psDrawImageMap(GLsizei width, GLsizei height, const GLfloat position[3], const unsigned char *imagemap)
static void gl2psSVGGetColorString(GL2PSrgba rgba, char str[32])
static int gl2psOpenPDFDataStream(void)
static GLboolean gl2psSupportedBlendMode(GLenum sfactor, GLenum dfactor)
static void gl2psAddPolyPrimitive(GLshort type, GLshort numverts, GL2PSvertex *verts, GLint offset, GLushort pattern, GLint factor, GLfloat width, char boundary)
#define GL2PS_END_STIPPLE_TOKEN
static void gl2psCreateSplitPrimitive(GL2PSprimitive *parent, GL2PSplane plane, GL2PSprimitive *child, GLshort numverts, GLshort *index0, GLshort *index1)
static void gl2psFreePixmap(GL2PSimage *im)
GL2PSDLL_API GLint gl2psGetOptions(GLint *options)
static void gl2psFreeImagemap(GL2PSimagemap *list)
static void gl2psPrintPostScriptBeginViewport(GLint viewport[4])
#define GL2PS_END_OFFSET_TOKEN
static void gl2psPrintPostScriptFooter(void)
static void gl2psPrintPGFDash(GLushort pattern, GLint factor)
GL2PSDLL_API GLint gl2psEnable(GLint mode)
struct _GL2PSbsptree2d GL2PSbsptree2d
static GLint gl2psGetPlaneFromPoints(GL2PSxyz a, GL2PSxyz b, GL2PSplane plane)
static RooMathCoreReg dummy
#define GL2PS_BEGIN_BLEND_TOKEN
static void gl2psPrintPostScriptColor(GL2PSrgba rgba)
static void gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives)
static void gl2psListActionInverse(GL2PSlist *list, void(*action)(void *data))
static GL2PSbackend gl2psPDF
static int gl2psPrintPDFFillColor(GL2PSrgba rgba)
#define GL2PS_NO_FEEDBACK
static GLint gl2psPrintSVGEndViewport(void)
static void gl2psPrintPDFHeader(void)
#define GL2PS_POLYGON_OFFSET_FILL
#define GL2PS_SRC_BLEND_TOKEN
static void gl2psRescaleAndOffset()
static GL2PSbackend gl2psPS
#define GL2PS_IMAGEMAP_WRITTEN
#define GL2PS_IMAGEMAP_TOKEN
GL2PSDLL_API GLint gl2psDisable(GLint mode)
typedef void((*Func_t)())
static int gl2psPrintPDFText(int obj, GL2PSstring *s, int fontnumber)
static GLint gl2psPrintPGFEndViewport(void)
static GLboolean gl2psVertsSameColor(const GL2PSprimitive *prim)
static void gl2psAddInImageTree(void *data)
static void gl2psPrintPDFPrimitive(void *data)
static void gl2psCutEdge(GL2PSvertex *a, GL2PSvertex *b, GL2PSplane plane, GL2PSvertex *c)
static void gl2psMsg(GLint level, const char *fmt,...)
static int gl2psPrintPDFShaderStreamDataRGB(GL2PSvertex *vertex, size_t(*action)(unsigned long data, size_t size))
static void gl2psPDFstacksInit(void)
static GLint gl2psPrintTeXEndViewport(void)
#define GL2PS_END_BLEND_TOKEN
#define dest(otri, vertexptr)
#define GL2PS_DRAW_PIXELS_TOKEN
static void gl2psPDFgroupObjectInit(GL2PSpdfgroup *gro)
static void gl2psAddPlanesInBspTreeImage(GL2PSprimitive *prim, GL2PSbsptree2d **tree)
GL2PSDLL_API GLint gl2psSpecial(GLint format, const char *str)
static void gl2psPvec(GLfloat *a, GLfloat *b, GLfloat *c)
static void gl2psPDFgroupListDelete(void)
static int gl2psPrintPostScriptDash(GLushort pattern, GLint factor, const char *str)
static void gl2psPDFgroupListWriteMainStream(void)
static void gl2psFreeBspImageTree(GL2PSbsptree2d **tree)
static GL2PSbackend gl2psTEX
static GLint gl2psSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane, GL2PSprimitive **front, GL2PSprimitive **back)
static void gl2psPrintTeXPrimitive(void *data)
#define GL2PS_NO_BLENDING
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
double norm(double *x, double *p)
#define GL2PS_NO_PS3_SHADING
static void gl2psEndSVGLine(void)
static int gl2psPDFgroupListWriteObjects(int entryoffs)
static int gl2psPrintPDFShaderStreamData(GL2PStriangle *triangle, GLfloat dx, GLfloat dy, GLfloat xmin, GLfloat ymin, size_t(*action)(unsigned long data, size_t size), int gray)
struct _GL2PSbsptree GL2PSbsptree
static void gl2psDivideQuad(GL2PSprimitive *quad, GL2PSprimitive **t1, GL2PSprimitive **t2)
GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, GLint xorig, GLint yorig, GLenum format, GLenum type, const void *pixels)
static void gl2psPrintSVGPixmap(GLfloat, GLfloat, GL2PSimage *)
static size_t gl2psWriteBigEndian(unsigned long data, size_t bytes)
static GL2PSlist * gl2psListCreate(GLint n, GLint incr, GLint size)
static int gl2psPrintf(const char *fmt,...)
static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im)
static void gl2psAssignTriangleProperties(GL2PStriangle *t)
const char Int_t const char * image
static void gl2psPDFRectHull(GLfloat *xmin, GLfloat *xmax, GLfloat *ymin, GLfloat *ymax, GL2PStriangle *triangles, int cnt)
static GLint gl2psCheckPoint(GL2PSxyz point, GL2PSplane plane)
#define GL2PS_SIMPLE_LINE_OFFSET