38 #include <sys/types.h>
43 #if defined(GL2PS_HAVE_ZLIB)
47 #if defined(GL2PS_HAVE_LIBPNG)
60 #define GL2PS_EPSILON 5.0e-3F
61 #define GL2PS_ZSCALE 1000.0F
62 #define GL2PS_ZOFFSET 5.0e-2F
63 #define GL2PS_ZOFFSET_LARGE 20.0F
64 #define GL2PS_ZERO(arg) (fabs(arg) < 1.e-20)
68 #define GL2PS_COINCIDENT 1
69 #define GL2PS_IN_FRONT_OF 2
70 #define GL2PS_IN_BACK_OF 3
71 #define GL2PS_SPANNING 4
75 #define GL2PS_POINT_COINCIDENT 0
76 #define GL2PS_POINT_INFRONT 1
77 #define GL2PS_POINT_BACK 2
81 #define GL2PS_BEGIN_OFFSET_TOKEN 1
82 #define GL2PS_END_OFFSET_TOKEN 2
83 #define GL2PS_BEGIN_BOUNDARY_TOKEN 3
84 #define GL2PS_END_BOUNDARY_TOKEN 4
85 #define GL2PS_BEGIN_STIPPLE_TOKEN 5
86 #define GL2PS_END_STIPPLE_TOKEN 6
87 #define GL2PS_POINT_SIZE_TOKEN 7
88 #define GL2PS_LINE_CAP_TOKEN 8
89 #define GL2PS_LINE_JOIN_TOKEN 9
90 #define GL2PS_LINE_WIDTH_TOKEN 10
91 #define GL2PS_BEGIN_BLEND_TOKEN 11
92 #define GL2PS_END_BLEND_TOKEN 12
93 #define GL2PS_SRC_BLEND_TOKEN 13
94 #define GL2PS_DST_BLEND_TOKEN 14
95 #define GL2PS_IMAGEMAP_TOKEN 15
96 #define GL2PS_DRAW_PIXELS_TOKEN 16
97 #define GL2PS_TEXT_TOKEN 17
175 #if defined(GL2PS_HAVE_ZLIB)
176 Bytef *dest, *src, *start;
177 uLongf destLen, srcLen;
191 GLint format,
sort, options, colorsize, colormode, buffersize;
196 GLint viewport[4], blendfunc[2], lastfactor;
236 void (*printHeader)(void);
237 void (*printFooter)(void);
238 void (*beginViewport)(GLint viewport[4]);
239 GLint (*endViewport)(void);
240 void (*printPrimitive)(
void *data);
241 void (*printFinalPrimitive)(void);
261 static void gl2psMsg(GLint level,
const char *fmt, ...)
267 case GL2PS_INFO : fprintf(stderr,
"GL2PS info: ");
break;
268 case GL2PS_WARNING : fprintf(stderr,
"GL2PS warning: ");
break;
269 case GL2PS_ERROR : fprintf(stderr,
"GL2PS error: ");
break;
272 vfprintf(stderr, fmt, args);
274 fprintf(stderr,
"\n");
283 if(!size)
return NULL;
295 if(!size)
return NULL;
296 ptr = realloc(orig, size);
314 int size =
sizeof(
unsigned long);
315 for(i = 1; i <= bytes; ++i){
316 fputc(0xff & (data >> (size - i) * 8),
gl2ps->
stream);
323 #if defined(GL2PS_HAVE_ZLIB)
325 static void gl2psSetupCompress(
void)
335 static void gl2psFreeCompress(
void)
348 static int gl2psAllocCompress(
unsigned int srcsize)
364 static void *gl2psReallocCompress(
unsigned int srcsize)
369 if(srcsize < gl2ps->
compress->srcLen)
383 static int gl2psWriteBigEndianCompress(
unsigned long data,
int bytes)
386 int size =
sizeof(
unsigned long);
387 for(i = 1; i <= bytes; ++i){
388 *
gl2ps->
compress->src = (Bytef)(0xff & (data >> (size-i) * 8));
394 static int gl2psDeflate(
void)
409 #if defined(GL2PS_HAVE_ZLIB)
410 static char buf[1024];
412 GLboolean freebuf = GL_FALSE;
413 unsigned int oldsize = 0;
414 #if !defined(GL2PS_HAVE_NO_VSNPRINTF)
417 int bufsize =
sizeof(buf);
421 #if defined(GL2PS_HAVE_NO_VSNPRINTF)
422 ret = vsprintf(buf, fmt, args);
424 ret = vsnprintf(bufptr, bufsize, fmt, args);
427 #if !defined(GL2PS_HAVE_NO_VSNPRINTF)
428 while(ret >= (bufsize - 1) || ret < 0){
431 if(freebuf == GL_TRUE)
gl2psFree(bufptr);
435 ret = vsnprintf(bufptr, bufsize, fmt, args);
440 gl2ps->
compress->start = (Bytef*)gl2psReallocCompress(oldsize + ret);
442 if(freebuf == GL_TRUE)
gl2psFree(bufptr);
450 #if defined(GL2PS_HAVE_ZLIB)
458 #if defined(GL2PS_HAVE_ZLIB)
459 char tmp[10] = {
'\x1f',
'\x8b',
467 gl2psSetupCompress();
476 #if defined(GL2PS_HAVE_ZLIB)
482 if(Z_OK != gl2psDeflate()){
496 for(n = 0; n < 4; ++n){
497 tmp[n] = (char)(crc & 0xff);
501 for(n = 4; n < 8; ++n){
502 tmp[n] = (char)(len & 0xff);
541 if(incr <= 0) incr = 1;
573 memcpy(&list->
array[(list->
n - 1) * list->
size], data, list->
size);
589 if((idx < 0) || (idx >= list->
n)){
597 int (*fcmp)(
const void *a,
const void *b))
601 qsort(list->
array, list->
n, list->
size, fcmp);
631 #if defined(GL2PS_HAVE_LIBPNG)
633 static void gl2psListRead(
GL2PSlist *list,
int index,
void *data)
635 if((index < 0) || (index >= list->
n))
640 static void gl2psEncodeBase64Block(
unsigned char in[3],
unsigned char out[4],
int len)
642 static const char cb64[] =
643 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
645 out[0] = cb64[ in[0] >> 2 ];
646 out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
647 out[2] = (len > 1) ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] :
'=';
648 out[3] = (len > 2) ? cb64[ in[2] & 0x3f ] :
'=';
651 static void gl2psListEncodeBase64(
GL2PSlist *list)
653 unsigned char *buffer, in[3], out[4];
654 int i, n, index, len;
656 n = list->
n * list->
size;
657 buffer = (
unsigned char*)
gl2psMalloc(n *
sizeof(
unsigned char));
658 memcpy(buffer, list->
array, n *
sizeof(
unsigned char));
664 for(i = 0; i < 3; i++) {
666 in[i] = buffer[index];
675 gl2psEncodeBase64Block(in, out, len);
676 for(i = 0; i < 4; i++)
700 for(i = 1; i < prim->
numverts; i++){
713 if(n < 2)
return GL_TRUE;
715 for(i = 1; i < n; i++){
716 if(fabs(rgba[0][0] - rgba[i][0]) > threshold[0] ||
717 fabs(rgba[0][1] - rgba[i][1]) > threshold[1] ||
718 fabs(rgba[0][2] - rgba[i][2]) > threshold[2])
728 for(i = 0; i < 3; ++i){
734 GLfloat *red, GLfloat *green, GLfloat *blue)
737 GLsizei width = im->
width;
738 GLsizei height = im->
height;
739 GLfloat *pixels = im->
pixels;
745 pimag = pixels + 4 * (width * (height - 1 - y) + x);
749 pimag = pixels + 3 * (width * (height - 1 - y) + x);
752 *red = *pimag; pimag++;
753 *green = *pimag; pimag++;
754 *blue = *pimag; pimag++;
756 return (im->
format == GL_RGBA) ? *pimag : 1.0F;
775 size = image->
height * image->
width * 4 *
sizeof(GLfloat);
779 size = image->
height * image->
width * 3 *
sizeof(GLfloat);
797 #if defined(GL2PS_HAVE_LIBPNG)
799 #if !defined(png_jmpbuf)
800 # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
803 static void gl2psUserWritePNG(png_structp png_ptr, png_bytep data, png_size_t
length)
807 for(i = 0; i <
length; i++)
811 static void gl2psUserFlushPNG(png_structp png_ptr)
820 unsigned char *row_data;
824 if(!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
827 if(!(info_ptr = png_create_info_struct(png_ptr))){
828 png_destroy_write_struct(&png_ptr, NULL);
832 if(setjmp(png_jmpbuf(png_ptr))) {
833 png_destroy_write_struct(&png_ptr, &info_ptr);
837 png_set_write_fn(png_ptr, (
void *)png, gl2psUserWritePNG, gl2psUserFlushPNG);
838 png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
839 png_set_IHDR(png_ptr, info_ptr, pixmap->
width, pixmap->
height, 8,
840 PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
841 PNG_FILTER_TYPE_BASE);
842 png_write_info(png_ptr, info_ptr);
844 row_data = (
unsigned char*)
gl2psMalloc(3 * pixmap->
width *
sizeof(
unsigned char));
845 for(row = 0; row < pixmap->
height; row++){
846 for(col = 0; col < pixmap->
width; col++){
848 row_data[3*col] = (
unsigned char)(255. * dr);
849 row_data[3*col+1] = (
unsigned char)(255. * dg);
850 row_data[3*col+2] = (
unsigned char)(255. * db);
852 png_write_row(png_ptr, (png_bytep)row_data);
856 png_write_end(png_ptr, info_ptr);
857 png_destroy_write_struct(&png_ptr, &info_ptr);
864 static GLint
gl2psAddText(GLint type,
const char *str,
const char *fontname,
865 GLshort fontsize, GLint alignment, GLfloat
angle,
867 GLfloat blx, GLfloat bly)
884 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
886 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
890 prim->
type = (GLshort)type;
913 memcpy(prim->
verts[0].
rgba, color, 4 *
sizeof(
float));
923 glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->
verts[0].
rgba);
953 strcpy(text->
str, t->
str);
979 if( (sfactor == GL_SRC_ALPHA && dfactor == GL_ONE_MINUS_SRC_ALPHA) ||
980 (sfactor == GL_ONE && dfactor == GL_ZERO) )
1043 GLboolean assignprops)
1048 if(GL_TRUE == assignprops)
1055 GL2PSvertex vertex = { {-1.0F, -1.0F, -1.0F}, {-1.0F, -1.0F, -1.0F, -1.0F} };
1056 for(i = 0; i < 3; i++)
1127 return (plane[0] * point[0] +
1128 plane[1] * point[1] +
1129 plane[2] * point[2] +
1135 return (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);
1140 c[0] = a[1]*b[2] - a[2]*b[1];
1141 c[1] = a[2]*b[0] - a[0]*b[2];
1142 c[2] = a[0]*b[1] - a[1]*b[0];
1147 return (GLfloat)sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
1171 GL2PSxyz v = {0.0F, 0.0F, 0.0F}, w = {0.0F, 0.0F, 0.0F};
1184 plane[0] = plane[1] = 0.0F;
1193 - plane[2] * prim->
verts[0].
xyz[2];
1201 plane[0] = plane[1] = 0.0F;
1213 - plane[2] * prim->
verts[0].
xyz[2];
1221 plane[0] = plane[1] = 0.0F;
1227 plane[0] = plane[1] = plane[3] = 0.0F;
1239 v[0] = b->
xyz[0] - a->
xyz[0];
1240 v[1] = b->
xyz[1] - a->
xyz[1];
1241 v[2] = b->
xyz[2] - a->
xyz[2];
1248 c->xyz[0] = a->
xyz[0] + v[0] * sect;
1249 c->xyz[1] = a->
xyz[1] + v[1] * sect;
1250 c->xyz[2] = a->
xyz[2] + v[2] * sect;
1252 c->rgba[0] = (1 - sect) * a->
rgba[0] + sect * b->
rgba[0];
1253 c->rgba[1] = (1 - sect) * a->
rgba[1] + sect * b->
rgba[1];
1254 c->rgba[2] = (1 - sect) * a->
rgba[2] + sect * b->
rgba[2];
1255 c->rgba[3] = (1 - sect) * a->
rgba[3] + sect * b->
rgba[3];
1260 GLshort *index0, GLshort *index1)
1295 for(i = 0; i < numverts; i++){
1301 plane, &child->
verts[i]);
1307 GLshort i, GLshort j)
1311 for(k = 0; k < *nb; k++){
1312 if((index0[k] == i && index1[k] == j) ||
1313 (index1[k] == i && index0[k] == j))
return;
1322 return (i < num - 1) ? i + 1 : 0;
1331 for(i = 0; i < prim->
numverts; i++){
1339 for(i = 0; i < prim->
numverts; i++){
1359 GLshort i, j, in = 0, out = 0, in0[5], in1[5], out0[5], out1[5];
1365 for(i = 0; i < prim->
numverts; i++){
1376 for(i = 0; i < prim->
numverts; i++){
1422 (*t1)->numverts = (*t2)->numverts = 3;
1423 (*t1)->culled = (*t2)->culled = quad->
culled;
1424 (*t1)->offset = (*t2)->offset = quad->
offset;
1425 (*t1)->ofactor = (*t2)->ofactor = quad->
ofactor;
1426 (*t1)->ounits = (*t2)->ounits = quad->
ounits;
1427 (*t1)->pattern = (*t2)->pattern = quad->
pattern;
1428 (*t1)->factor = (*t2)->factor = quad->
factor;
1429 (*t1)->width = (*t2)->width = quad->
width;
1430 (*t1)->linecap = (*t2)->linecap = quad->
linecap;
1431 (*t1)->linejoin = (*t2)->linejoin = quad->
linejoin;
1434 (*t1)->verts[0] = quad->
verts[0];
1435 (*t1)->verts[1] = quad->
verts[1];
1436 (*t1)->verts[2] = quad->
verts[2];
1437 (*t1)->boundary = ((quad->
boundary & 1) ? 1 : 0) | ((quad->
boundary & 2) ? 2 : 0);
1438 (*t2)->verts[0] = quad->
verts[0];
1439 (*t2)->verts[1] = quad->
verts[2];
1440 (*t2)->verts[2] = quad->
verts[3];
1441 (*t2)->boundary = ((quad->
boundary & 4) ? 2 : 0) | ((quad->
boundary & 8) ? 4 : 0);
1447 GLfloat dq = 0.0F, dw = 0.0F, diff;
1458 for(i = 0; i < w->numverts; i++){
1482 return (q->
type < w->
type ? 1 : -1);
1487 GLint i, j, count, best = 1000000, idx = 0;
1504 for(i = 0; i < maxp; i++){
1513 if(count > best)
break;
1519 if(!count)
return idx;
1533 while(list != NULL){
1577 if((*tree)->primitives){
1589 if(f1 > f2)
return GL_TRUE;
1590 else return GL_FALSE;
1595 if(f1 < f2)
return GL_TRUE;
1596 else return GL_FALSE;
1663 GLboolean (*
compare)(GLfloat f1, GLfloat f2),
1664 void (*action)(
void *data),
int inverse)
1701 GLfloat minZ, maxZ, rangeZ, scaleZ;
1702 GLfloat factor, units, area, dZ, dZdX, dZdY, maxdZ;
1710 minZ = maxZ = prim->
verts[0].
xyz[2];
1711 for(i = 1; i < prim->
numverts; i++){
1717 for(j = 0; j < prim->
numverts; j++){
1722 rangeZ = (maxZ - minZ);
1728 if(scaleZ > 100000.
F) scaleZ = 100000.F;
1733 for(j = 0; j < prim->
numverts; j++){
1766 maxdZ = (GLfloat)sqrt(dZdX * dZdX + dZdY * dZdY);
1771 dZ = factor * maxdZ + units;
1789 plane[0] = b[1] - a[1];
1790 plane[1] = a[0] - b[0];
1791 n = (GLfloat)sqrt(plane[0]*plane[0] + plane[1]*plane[1]);
1796 plane[3] = -plane[0]*a[0]-plane[1]*a[1];
1835 if((*tree == NULL) && (prim->
numverts > 2)){
1841 for(i = 0; i < prim->
numverts-1; i++){
1859 for(i = 2+offset; i < prim->
numverts; i++){
1866 for(i = 1+offset; i < prim->
numverts-1; i++){
1867 if(cur->front == NULL){
1872 cur->front->plane)){
1878 if(cur->front == NULL){
1883 cur->front->plane)){
1884 cur->front->front = NULL;
1885 cur->front->back = NULL;
1893 for(i = 0; i < 4; i++){
1897 for(i = 1+offset; i < prim->
numverts-1; i++){
1898 if(cur->front == NULL){
1903 cur->front->plane)){
1909 if(cur->front == NULL){
1914 cur->front->plane)){
1915 cur->front->front = NULL;
1916 cur->front->back = NULL;
1937 for(i = 1; i < prim->
numverts; i++){
1978 for(i = 0; i < numverts; i++){
1979 child->
verts[i] = vertx[i];
1994 GLint cur = -1, prev = -1, i, v1 = 0, v2 = 0, flag = 1, prev0 = -1;
1997 GL2PSvertex *front_list = NULL, *back_list = NULL;
2000 GLshort front_count = 0, back_count = 0;
2002 for(i = 0; i <= prim->
numverts; i++){
2016 if(((prev == -1) || (prev == cur) || (prev == 0) || (cur == 0)) &&
2017 (i < prim->numverts)){
2022 front_list[front_count-1] = prim->
verts[v1];
2028 back_list[back_count-1] = prim->
verts[v1];
2034 front_list[front_count-1] = prim->
verts[v1];
2038 back_list[back_count-1] = prim->
verts[v1];
2042 else if((prev != cur) && (cur != 0) && (prev != 0)){
2051 plane, &front_list[front_count-1]);
2055 back_list[back_count-1] = front_list[front_count-1];
2095 if((*tree)->front != NULL){
2106 if((*tree)->back != NULL){
2112 if((*tree)->front != NULL){
2148 c[0] =
c[1] =
c[2] = 0.0F;
2149 for(i = 0; i < prim->
numverts; i++){
2156 for(i = 0; i < prim->
numverts; i++){
2157 if(prim->
boundary & (GLint)pow(2., i)){
2236 GLfloat ofactor, GLfloat ounits,
2237 GLushort pattern, GLint factor,
2238 GLfloat width, GLint linecap,
2239 GLint linejoin,
char boundary)
2249 prim->
offset = (char)offset;
2254 prim->
width = width;
2274 i = (GLint)(p[3] + 0.5);
2293 GLushort pattern = 0;
2295 GLint i, sizeoffloat, count, v, vtot, offset = 0, factor = 0, auxindex = 0;
2296 GLint lcap = 0, ljoin = 0;
2297 GLfloat lwidth = 1.0F, psize = 1.0F, ofactor = 0.0F, ounits = 0.0F;
2310 switch((GLint)*current){
2311 case GL_POINT_TOKEN :
2318 pattern, factor, psize, lcap, ljoin, 0);
2320 case GL_LINE_TOKEN :
2321 case GL_LINE_RESET_TOKEN :
2331 pattern, factor, lwidth, lcap, ljoin, 0);
2333 case GL_POLYGON_TOKEN :
2334 count = (GLint)current[1];
2338 while(count > 0 && used > 0){
2346 if(GL_TRUE == boundary){
2347 if(!count && vtot == 2) flag = 1|2|4;
2348 else if(!count) flag = 2|4;
2349 else if(vtot == 2) flag = 1|2;
2355 ounits, pattern, factor, 1, lcap, ljoin,
2357 vertices[1] = vertices[2];
2363 case GL_BITMAP_TOKEN :
2364 case GL_DRAW_PIXEL_TOKEN :
2365 case GL_COPY_PIXEL_TOKEN :
2372 case GL_PASS_THROUGH_TOKEN :
2373 switch((GLint)current[1]){
2378 ofactor = current[1];
2381 ounits = current[1];
2396 pattern = (GLushort)current[1];
2399 factor = (GLint)current[1];
2419 lcap = (GLint)current[1];
2424 ljoin = (GLint)current[1];
2429 lwidth = current[1];
2460 current += 2; used -= 2;
2462 current += i; used -= i;
2465 current += 2; used -= 2;
2469 for(i = 1; i < 4; i++){
2470 for(v = 0; v < 3; v++){
2481 sizeoffloat =
sizeof(GLfloat);
2482 v = 2 * sizeoffloat;
2489 for(i = 0; i < vtot; i += sizeoffloat){
2490 current += 2; used -= 2;
2492 memcpy(&(((
char*)(node->
image->
pixels))[i + v]), &(current[2]), sizeoffloat);
2494 memcpy(&(((
char*)(node->
image->
pixels))[i + v]), &(current[2]), vtot - i);
2530 unsigned char h =
byte / 16;
2531 unsigned char l =
byte % 16;
2537 GLuint nbhex, nbyte, nrgb, nbits;
2538 GLuint row, col, ibyte, icase;
2539 GLfloat dr = 0., dg = 0., db = 0., fgrey;
2540 unsigned char red = 0, green = 0, blue = 0, b, grey;
2541 GLuint width = (GLuint)im->
width;
2542 GLuint height = (GLuint)im->
height;
2549 if((width <= 0) || (height <= 0))
return;
2558 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2559 gl2psPrintf(
"{ currentfile picstr readhexstring pop }\n");
2561 for(row = 0; row < height; row++){
2562 for(col = 0; col < width; col++){
2564 fgrey = (0.30F * dr + 0.59F * dg + 0.11F * db);
2565 grey = (
unsigned char)(255. * fgrey);
2570 nbhex = width * height * 2;
2575 nbits = nrgb * nbit;
2577 if((nbyte * 8) != nbits) nbyte++;
2580 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2581 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2584 for(row = 0; row < height; row++){
2588 for(ibyte = 0; ibyte < nbyte; ibyte++){
2597 red = (
unsigned char)(3. * dr);
2598 green = (
unsigned char)(3. * dg);
2599 blue = (
unsigned char)(3. * db);
2610 red = (
unsigned char)(3. * dr);
2611 green = (
unsigned char)(3. * dg);
2612 blue = (
unsigned char)(3. * db);
2618 else if(icase == 2) {
2628 red = (
unsigned char)(3. * dr);
2629 green = (
unsigned char)(3. * dg);
2630 blue = (
unsigned char)(3. * db);
2637 else if(icase == 3) {
2646 red = (
unsigned char)(3. * dr);
2647 green = (
unsigned char)(3. * dg);
2648 blue = (
unsigned char)(3. * db);
2662 nbits = nrgb * nbit;
2664 if((nbyte * 8) != nbits) nbyte++;
2667 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2668 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2671 for(row = 0; row < height; row++){
2674 for(ibyte = 0; ibyte < nbyte; ibyte++){
2683 red = (
unsigned char)(15. * dr);
2684 green = (
unsigned char)(15. * dg);
2688 else if(icase == 2) {
2689 blue = (
unsigned char)(15. * db);
2697 red = (
unsigned char)(15. * dr);
2701 else if(icase == 3) {
2702 green = (
unsigned char)(15. * dg);
2703 blue = (
unsigned char)(15. * db);
2715 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2716 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2719 for(row = 0; row < height; row++){
2720 for(col = 0; col < width; col++){
2722 red = (
unsigned char)(255. * dr);
2724 green = (
unsigned char)(255. * dg);
2726 blue = (
unsigned char)(255. * db);
2737 GLsizei width, GLsizei height,
2738 const unsigned char *imagemap){
2741 if((width <= 0) || (height <= 0))
return;
2743 size = height + height * (width - 1) / 8;
2747 gl2psPrintf(
"%d %d scale\n%d %d\ntrue\n", width, height,width, height);
2748 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ] {<", width, height);
2749 for(i = 0; i < size; i++){
2775 "%%%%Creator: GL2PS %d.%d.%d%s, %s\n"
2777 "%%%%CreationDate: %s"
2778 "%%%%LanguageLevel: 3\n"
2779 "%%%%DocumentData: Clean7Bit\n"
2787 "%%%%DocumentMedia: Default %d %d 0 () ()\n",
2796 "%%%%EndComments\n",
2820 "/gl2psdict 64 dict def gl2psdict begin\n"
2821 "/tryPS3shading %s def %% set to false to force subdivision\n"
2822 "/rThreshold %g def %% red component subdivision threshold\n"
2823 "/gThreshold %g def %% green component subdivision threshold\n"
2824 "/bThreshold %g def %% blue component subdivision threshold\n",
2829 "/C { setrgbcolor } BD\n"
2830 "/G { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add setgray } BD\n"
2831 "/W { setlinewidth } BD\n"
2832 "/LC { setlinecap } BD\n"
2833 "/LJ { setlinejoin } BD\n");
2835 gl2psPrintf(
"/FC { findfont exch /SH exch def SH scalefont setfont } BD\n"
2836 "/SW { dup stringwidth pop } BD\n"
2837 "/S { FC moveto show } BD\n"
2838 "/SBC{ FC moveto SW -2 div 0 rmoveto show } BD\n"
2839 "/SBR{ FC moveto SW neg 0 rmoveto show } BD\n"
2840 "/SCL{ FC moveto 0 SH -2 div rmoveto show } BD\n"
2841 "/SCC{ FC moveto SW -2 div SH -2 div rmoveto show } BD\n"
2842 "/SCR{ FC moveto SW neg SH -2 div rmoveto show } BD\n"
2843 "/STL{ FC moveto 0 SH neg rmoveto show } BD\n"
2844 "/STC{ FC moveto SW -2 div SH neg rmoveto show } BD\n"
2845 "/STR{ FC moveto SW neg SH neg rmoveto show } BD\n");
2850 "/SR { gsave FCT moveto rotate show grestore } BD\n"
2851 "/SBCR{ gsave FCT moveto rotate SW -2 div 0 rmoveto show grestore } BD\n"
2852 "/SBRR{ gsave FCT moveto rotate SW neg 0 rmoveto show grestore } BD\n"
2853 "/SCLR{ gsave FCT moveto rotate 0 SH -2 div rmoveto show grestore} BD\n");
2854 gl2psPrintf(
"/SCCR{ gsave FCT moveto rotate SW -2 div SH -2 div rmoveto show grestore} BD\n"
2855 "/SCRR{ gsave FCT moveto rotate SW neg SH -2 div rmoveto show grestore} BD\n"
2856 "/STLR{ gsave FCT moveto rotate 0 SH neg rmoveto show grestore } BD\n"
2857 "/STCR{ gsave FCT moveto rotate SW -2 div SH neg rmoveto show grestore } BD\n"
2858 "/STRR{ gsave FCT moveto rotate SW neg SH neg rmoveto show grestore } BD\n");
2860 gl2psPrintf(
"/P { newpath 0.0 360.0 arc closepath fill } BD\n"
2861 "/R { newpath moveto lineto lineto lineto closepath fill } BD\n"
2862 "/LS { newpath moveto } BD\n"
2863 "/L { lineto } BD\n"
2864 "/LE { lineto stroke } BD\n"
2865 "/T { newpath moveto lineto lineto closepath fill } BD\n");
2871 " /b1 exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n"
2872 " /b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n"
2873 " /b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n"
2874 " gsave << /ShadingType 4 /ColorSpace [/DeviceRGB]\n"
2875 " /DataSource [ 0 x1 y1 r1 g1 b1 0 x2 y2 r2 g2 b2 0 x3 y3 r3 g3 b3 ] >>\n"
2876 " shfill grestore } BD\n");
2882 "/Tm { 3 -1 roll 8 -1 roll 13 -1 roll add add 3 div\n"
2884 " 3 -1 roll 7 -1 roll 11 -1 roll add add 3 div\n"
2886 " 3 -1 roll 6 -1 roll 9 -1 roll add add 3 div"
2896 " 4 index 15 index add 0.5 mul\n"
2897 " 4 index 15 index add 0.5 mul\n"
2898 " 4 index 15 index add 0.5 mul\n"
2899 " 4 index 15 index add 0.5 mul\n"
2900 " 4 index 15 index add 0.5 mul\n"
2901 " 5 copy 5 copy 25 15 roll\n");
2906 " 9 index 30 index add 0.5 mul\n"
2907 " 9 index 30 index add 0.5 mul\n"
2908 " 9 index 30 index add 0.5 mul\n"
2909 " 9 index 30 index add 0.5 mul\n"
2910 " 5 copy 5 copy 35 5 roll 25 5 roll 15 5 roll\n");
2915 " 4 index 10 index add 0.5 mul\n"
2916 " 4 index 10 index add 0.5 mul\n"
2917 " 4 index 10 index add 0.5 mul\n"
2918 " 4 index 10 index add 0.5 mul\n"
2919 " 5 copy 5 copy 40 5 roll 25 5 roll 15 5 roll 25 5 roll\n");
2923 gl2psPrintf(
" STnoshfill STnoshfill STnoshfill STnoshfill } BD\n");
2930 " 2 index 8 index sub abs rThreshold gt\n"
2932 " { 1 index 7 index sub abs gThreshold gt\n"
2934 " { dup 6 index sub abs bThreshold gt\n"
2936 " { 2 index 13 index sub abs rThreshold gt\n"
2938 " { 1 index 12 index sub abs gThreshold gt\n"
2940 " { dup 11 index sub abs bThreshold gt\n"
2942 " { 7 index 13 index sub abs rThreshold gt\n");
2944 " { 6 index 12 index sub abs gThreshold gt\n"
2946 " { 5 index 11 index sub abs bThreshold gt\n"
2961 " { /ST { STshfill } BD }\n"
2962 " { /ST { STnoshfill } BD }\n"
2964 "{ /ST { STnoshfill } BD }\n"
2970 "/DeviceRGB setcolorspace\n"
2974 "%%%%BeginPageSetup\n");
2988 "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3001 gl2psPrintf(
"%g %g %g C\n", rgba[0], rgba[1], rgba[2]);
3015 for(i = 0; i < 3; i++)
3017 for(i = 0; i < 4; i++)
3023 int *nb,
int array[10])
3026 int on[8] = {0, 0, 0, 0, 0, 0, 0, 0};
3027 int off[8] = {0, 0, 0, 0, 0, 0, 0, 0};
3031 for(n = 15; n >= 0; n--){
3032 tmp[n] = (char)(pattern & 0x01);
3037 for(i = 0; i < 8; i++){
3038 while(n < 16 && !tmp[n]){ off[i]++; n++; }
3039 while(n < 16 && tmp[n]){ on[i]++; n++; }
3040 if(n >= 15){ i++;
break; }
3049 for(n = i - 1; n >= 0; n--){
3050 array[(*nb)++] = factor * on[n];
3051 array[(*nb)++] = factor * off[n];
3052 if(*nb == 10)
break;
3058 int len = 0, i, n,
array[10];
3066 if(!pattern || !factor){
3073 for(i = 0; i < n; i++){
3154 newline ?
"LS" :
"L");
3160 gl2psPrintf(
"%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ST\n",
3263 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
3265 glRenderMode(GL_FEEDBACK);
3280 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
3283 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
3290 "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3292 rgba[0], rgba[1], rgba[2],
3293 x, y, x+w, y, x+w, y+h, x, y+h);
3296 gl2psPrintf(
"newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3298 x, y, x+w, y, x+w, y+h, x, y+h);
3338 "Encapsulated Postscript"
3365 strcpy(name,
"untitled");
3372 "%% Creator: GL2PS %d.%d.%d%s, %s\n"
3374 "%% CreationDate: %s",
3382 "\\setlength{\\unitlength}{%gpt}\n"
3383 "\\begin{picture}(0,0)\n"
3384 "\\includegraphics[scale=%g]{%s}\n"
3385 "\\end{picture}%%\n"
3386 "%s\\begin{picture}(%d,%d)(0,0)\n",
3401 fprintf(
gl2ps->
stream,
"\\fontsize{%d}{0}\\selectfont",
3439 fprintf(
gl2ps->
stream,
"\\textcolor[rgb]{%g,%g,%g}{{%s}}",
3466 glRenderMode(GL_FEEDBACK);
3506 #if defined(GL2PS_HAVE_ZLIB)
3508 return fprintf(
gl2ps->
stream,
"/Filter [/FlateDecode]\n");
3519 for(i = 0; i < 3; ++i){
3522 else if(rgba[i] < 1e-4 || rgba[i] > 1e6)
3535 for(i = 0; i < 3; ++i){
3538 else if(rgba[i] < 1e-4 || rgba[i] > 1e6)
3551 else if(lw < 1e-4 || lw > 1e6)
3575 GLfloat rad, crad, srad;
3577 if(text->
angle == 0.0F){
3587 rad = (GLfloat)(3.141593
F * text->
angle / 180.0F);
3588 srad = (GLfloat)sin(rad);
3589 crad = (GLfloat)cos(rad);
3593 "%f %f %f %f %f %f Tm\n"
3596 cnt, text->
fontsize, crad, srad, -srad, crad, x, y, text->
str);
3605 GLfloat xbl, GLfloat ybl)
3607 if(text->
angle == 0.0F){
3618 GLfloat pi = 3.141593F;
3619 GLfloat i = atan2(y - ybl, x - xbl);
3620 GLfloat r = sqrt((y - ybl) * (y - ybl) + (x - xbl) * (x - xbl));
3622 a = (GLfloat)(pi * text->
angle / 180.0F);
3623 sa = (GLfloat)sin(a);
3624 ca = (GLfloat)cos(a);
3628 "%f %f %f %f %f %f Tm\n"
3633 xbl + r * (cos(i) - cos(i + a)), ybl + r * (sin(i) - sin(i+a)), text->
str);
3647 "%d 0 0 %d %f %f cm\n"
3684 GL2PSrgba lastrgba = {-1.0F, -1.0F, -1.0F, -1.0F};
3685 GLushort lastpattern = 0;
3686 GLint lastfactor = 0;
3687 GLfloat lastwidth = 1;
3688 GLint lastlinecap = 0;
3689 GLint lastlinejoin = 0;
3691 int lastTriangleWasNotSimpleWithSameColor = 0;
3717 if(lasttype != p->
type || lastwidth != p->
width ||
3731 lastwidth = p->
width;
3739 if(lasttype != p->
type || lastwidth != p->
width ||
3749 lastwidth = p->
width;
3756 lastTriangleWasNotSimpleWithSameColor =
3760 lastTriangleWasNotSimpleWithSameColor){
3841 int i, j, lastel, count;
3851 for(i = 0; i < count; ++i){
3865 for(j = 0; j <= lastel; ++j){
3894 for(j = 1; j <= lastel; ++j){
3903 prev->verts[1].xyz[0], prev->verts[1].xyz[1]);
3929 for(j = 0; j <= lastel; ++j){
3949 for(j = 0; j <= lastel; ++j){
3972 for(j = 0; j <= lastel; ++j){
4014 for(j = 0; j <= lastel; ++j){
4021 for(j = 0; j <= lastel; ++j){
4041 for(j = 0; j <= lastel; ++j){
4177 newtime = gmtime(&now);
4183 "/Creator (GL2PS %d.%d.%d%s, %s)\n"
4197 "/CreationDate (D:%d%02d%02d%02d%02d%02d)\n"
4200 newtime->tm_year+1900,
4243 "/Length 5 0 R\n" );
4279 #if defined(GL2PS_HAVE_ZLIB)
4281 gl2psSetupCompress();
4321 #if defined(GL2PS_HAVE_ZLIB)
4323 if(Z_OK != gl2psDeflate())
4330 gl2psFreeCompress();
4363 "/MediaBox [%d %d %d %d]\n",
4374 "/ProcSet [/PDF /Text /ImageB /ImageC] %%/ImageI\n");
4412 "/Type /ExtGState\n"
4428 int (*action)(
unsigned long data,
int size),
4429 GLfloat dx, GLfloat dy,
4430 GLfloat xmin, GLfloat ymin)
4439 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4441 offs += (*action)(edgeflag, 1);
4447 offs += (*action)(0, 4);
4448 offs += (*action)(0, 4);
4451 diff = (vertex->
xyz[0] - xmin) / dx;
4456 imap = (
unsigned long)(diff * dmax);
4457 offs += (*action)(imap, 4);
4459 diff = (vertex->
xyz[1] - ymin) / dy;
4464 imap = (
unsigned long)(diff * dmax);
4465 offs += (*action)(imap, 4);
4474 int (*action)(
unsigned long data,
int size))
4482 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4484 tmp = vertex->
rgba[0];
4489 imap = (
unsigned long)(tmp * dmax);
4490 offs += (*action)(imap, 1);
4492 tmp = vertex->
rgba[1];
4497 imap = (
unsigned long)(tmp * dmax);
4498 offs += (*action)(imap, 1);
4500 tmp = vertex->
rgba[2];
4505 imap = (
unsigned long)(tmp * dmax);
4506 offs += (*action)(imap, 1);
4514 int (*action)(
unsigned long data,
int size),
4523 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4525 if(sigbyte != 8 && sigbyte != 16)
4530 tmp = vertex->
rgba[3];
4535 imap = (
unsigned long)(tmp * dmax);
4537 offs += (*action)(imap, sigbyte);
4545 GLfloat dx, GLfloat dy,
4546 GLfloat xmin, GLfloat ymin,
4547 int (*action)(
unsigned long data,
int size),
4556 for(i = 0; i < 3; ++i){
4558 dx, dy, xmin, ymin);
4572 GLfloat *ymin, GLfloat *ymax,
4582 for(i = 0; i < cnt; ++i){
4583 for(j = 0; j < 3; ++j){
4584 if(*xmin > triangles[i].vertex[j].xyz[0])
4586 if(*xmax < triangles[i].vertex[j].xyz[0])
4588 if(*ymin > triangles[i].vertex[j].xyz[1])
4590 if(*ymax < triangles[i].vertex[j].xyz[1])
4604 int i, offs = 0, vertexbytes, done = 0;
4605 GLfloat xmin, xmax, ymin, ymax;
4609 vertexbytes = 1+4+4+1+1+1;
4612 vertexbytes = 1+4+4+1;
4615 vertexbytes = 1+4+4+2;
4619 vertexbytes = 1+4+4+1;
4630 "/BitsPerCoordinate 32 "
4631 "/BitsPerComponent %d "
4633 "/Decode [%f %f %f %f 0 1 %s] ",
4635 (
gray) ?
"/DeviceGray" :
"/DeviceRGB",
4637 xmin, xmax, ymin, ymax,
4638 (
gray) ?
"" :
"0 1 0 1");
4640 #if defined(GL2PS_HAVE_ZLIB)
4642 gl2psAllocCompress(vertexbytes * size * 3);
4644 for(i = 0; i < size; ++i)
4646 xmax-xmin, ymax-ymin, xmin, ymin,
4647 gl2psWriteBigEndianCompress,
gray);
4661 gl2psFreeCompress();
4672 vertexbytes * 3 * size);
4673 for(i = 0; i < size; ++i)
4675 xmax-xmin, ymax-ymin, xmin, ymin,
4697 "/BBox [ %d %d %d %d ]\n"
4698 "/Group \n<<\n/S /Transparency /CS /DeviceRGB\n"
4705 ? (
int)strlen(
"/TrSh sh\n") + (int)log10((
double)childobj)+1
4706 : (
int)strlen(
"/TrSh0 sh\n");
4737 "/SMask << /S /Alpha /G %d 0 R >> ",
4765 int (*action)(
unsigned long data,
int size),
4779 shift = (
sizeof(
unsigned long) - 1) * 8;
4781 for(y = 0; y < im->
height; ++y){
4782 for(x = 0; x < im->
width; ++x){
4785 (*action)((
unsigned long)(a * 255) << shift,
gray);
4788 (*action)((
unsigned long)(r * 255) << shift, 1);
4789 (*action)((
unsigned long)(g * 255) << shift, 1);
4790 (*action)((
unsigned long)(b * 255) << shift, 1);
4805 int offs = 0, done = 0, sigbytes = 3;
4811 sigbytes =
gray / 8;
4821 "/BitsPerComponent 8\n",
4824 (
gray) ?
"/DeviceGray" :
"/DeviceRGB" );
4831 #if defined(GL2PS_HAVE_ZLIB)
4833 gl2psAllocCompress((
int)(im->
width * im->
height * sigbytes));
4848 gl2psFreeCompress();
4881 "/Encoding /MacRomanEncoding\n"
4895 int offs = entryoffs;
4915 for(j = 0; j < size; ++j){
5020 #if defined(GL2PS_HAVE_ZLIB)
5022 gl2psFreeCompress();
5036 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
5038 glRenderMode(GL_FEEDBACK);
5051 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
5054 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
5099 "Portable Document Format"
5113 for(i = 0; i < n; i++){
5114 xyz[i][0] = verts[i].
xyz[0];
5117 for(j = 0; j < 4; j++)
5118 rgba[i][j] = verts[i].rgba[j];
5124 int r = (int)(255. * rgba[0]);
5125 int g = (int)(255. * rgba[1]);
5126 int b = (int)(255. * rgba[2]);
5127 int rc = (r < 0) ? 0 : (r > 255) ? 255 : r;
5128 int gc = (g < 0) ? 0 : (g > 255) ? 255 : g;
5129 int bc = (b < 0) ? 0 : (b > 255) ? 255 : b;
5130 sprintf(str,
"#%2.2x%2.2x%2.2x", rc, gc, bc);
5135 int x, y, width, height;
5157 gl2psPrintf(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
5158 gl2psPrintf(
"<svg xmlns=\"http://www.w3.org/2000/svg\"\n");
5159 gl2psPrintf(
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
5160 " width=\"%dpt\" height=\"%dpt\" viewBox=\"%d %d %d %d\">\n",
5161 width, height, x, y, width, height);
5175 gl2psPrintf(
"<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", col,
5200 if(rgba[0][3] < 1.0
F)
gl2psPrintf(
"fill-opacity=\"%g\" ", rgba[0][3]);
5202 gl2psPrintf(
"points=\"%g,%g %g,%g %g,%g\"/>\n", xyz[0][0], xyz[0][1],
5203 xyz[1][0], xyz[1][1], xyz[2][0], xyz[2][1]);
5207 for(i = 0; i < 3; i++){
5208 xyz2[0][i] = xyz[0][i];
5209 xyz2[1][i] = 0.5F * (xyz[0][i] + xyz[1][i]);
5210 xyz2[2][i] = 0.5F * (xyz[0][i] + xyz[2][i]);
5212 for(i = 0; i < 4; i++){
5213 rgba2[0][i] = rgba[0][i];
5214 rgba2[1][i] = 0.5F * (rgba[0][i] + rgba[1][i]);
5215 rgba2[2][i] = 0.5F * (rgba[0][i] + rgba[2][i]);
5218 for(i = 0; i < 3; i++){
5219 xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[1][i]);
5220 xyz2[1][i] = xyz[1][i];
5221 xyz2[2][i] = 0.5F * (xyz[1][i] + xyz[2][i]);
5223 for(i = 0; i < 4; i++){
5224 rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[1][i]);
5225 rgba2[1][i] = rgba[1][i];
5226 rgba2[2][i] = 0.5F * (rgba[1][i] + rgba[2][i]);
5229 for(i = 0; i < 3; i++){
5230 xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[2][i]);
5231 xyz2[1][i] = xyz[2][i];
5232 xyz2[2][i] = 0.5F * (xyz[1][i] + xyz[2][i]);
5234 for(i = 0; i < 4; i++){
5235 rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[2][i]);
5236 rgba2[1][i] = rgba[2][i];
5237 rgba2[2][i] = 0.5F * (rgba[1][i] + rgba[2][i]);
5240 for(i = 0; i < 3; i++){
5241 xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[1][i]);
5242 xyz2[1][i] = 0.5F * (xyz[1][i] + xyz[2][i]);
5243 xyz2[2][i] = 0.5F * (xyz[0][i] + xyz[2][i]);
5245 for(i = 0; i < 4; i++){
5246 rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[1][i]);
5247 rgba2[1][i] = 0.5F * (rgba[1][i] + rgba[2][i]);
5248 rgba2[2][i] = 0.5F * (rgba[0][i] + rgba[2][i]);
5256 int i, n,
array[10];
5258 if(!pattern || !factor)
return;
5262 for(i = 0; i < n; i++){
5275 for(i = 0; i < 3; i++)
5277 for(i = 0; i < 4; i++)
5284 #if defined(GL2PS_HAVE_LIBPNG)
5296 sizeof(
unsigned char));
5297 gl2psConvertPixmapToPNG(pixmap, png);
5298 gl2psListEncodeBase64(png);
5303 gl2psPrintf(
"<image x=\"%g\" y=\"%g\" width=\"%d\" height=\"%d\"\n",
5305 gl2psPrintf(
"transform=\"matrix(%g,0,0,%g,%g,%g)\"\n",
5307 gl2psPrintf(
"xlink:href=\"data:image/png;base64,");
5309 gl2psListRead(png, i, &
c);
5315 (void) x; (void) y; (void) pixmap;
5317 "order to embed images in SVG streams");
5327 char lcap[7], ljoin[7];
5346 if (rgba[0][3] < 1.0
F)
gl2psPrintf(
"fill-opacity=\"%g\" ", rgba[0][3]);
5347 gl2psPrintf(
"x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"/>\n",
5348 xyz[0][0] - 0.5*prim->
width, xyz[0][1] - 0.5*prim->
width,
5353 if (rgba[0][3] < 1.0
F)
gl2psPrintf(
"fill-opacity=\"%g\" ", rgba[0][3]);
5355 xyz[0][0], xyz[0][1], 0.5 * prim->
width);
5385 gl2psPrintf(
"<polyline fill=\"none\" stroke=\"%s\" stroke-width=\"%g\" ",
5389 sprintf (lcap,
"%s",
"butt");
5392 sprintf (lcap,
"%s",
"round");
5395 sprintf (lcap,
"%s",
"square");
5400 sprintf (ljoin,
"%s",
"miter");
5403 sprintf (ljoin,
"%s",
"round");
5406 sprintf (ljoin,
"%s",
"bevel");
5409 gl2psPrintf(
"stroke-linecap=\"%s\" stroke-linejoin=\"%s\" ",
5411 if(rgba[0][3] < 1.0
F)
gl2psPrintf(
"stroke-opacity=\"%g\" ", rgba[0][3]);
5413 gl2psPrintf(
"points=\"%g,%g ", xyz[0][0], xyz[0][1]);
5430 gl2psPrintf(
"<text fill=\"%s\" x=\"%g\" y=\"%g\" font-size=\"%d\" ",
5474 gl2psPrintf(
"font-family=\"Times\" font-weight=\"bold\">");
5476 gl2psPrintf(
"font-family=\"Times\" font-style=\"italic\">");
5478 gl2psPrintf(
"font-family=\"Times\" font-style=\"italic\" font-weight=\"bold\">");
5480 gl2psPrintf(
"font-family=\"Helvetica\" font-weight=\"bold\">");
5482 gl2psPrintf(
"font-family=\"Helvetica\" font-style=\"oblique\">");
5484 gl2psPrintf(
"font-family=\"Helvetica\" font-style=\"oblique\" font-weight=\"bold\">");
5486 gl2psPrintf(
"font-family=\"Courier\" font-weight=\"bold\">");
5488 gl2psPrintf(
"font-family=\"Courier\" font-style=\"oblique\">");
5490 gl2psPrintf(
"font-family=\"Courier\" font-style=\"oblique\" font-weight=\"bold\">");
5519 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
5521 glRenderMode(GL_FEEDBACK);
5532 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
5535 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
5542 gl2psPrintf(
"<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\" ", col,
5547 gl2psPrintf(
"shape-rendering=\"crispEdges\"/>\n");
5550 gl2psPrintf(
"<clipPath id=\"cp%d%d%d%d\">\n", x, y, w, h);
5551 gl2psPrintf(
" <polygon points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n",
5557 gl2psPrintf(
"<g clip-path=\"url(#cp%d%d%d%d)\">\n", x, y, w, h);
5585 "Scalable Vector Graphics"
5598 fprintf(
gl2ps->
stream,
"\\color[rgb]{%f,%f,%f}\n", rgba[0], rgba[1], rgba[2]);
5610 "%% Creator: GL2PS %d.%d.%d%s, %s\n"
5612 "%% CreationDate: %s",
5621 "\\pgfpathrectanglecorners{"
5622 "\\pgfpoint{%dpt}{%dpt}}{\\pgfpoint{%dpt}{%dpt}}\n"
5623 "\\pgfusepath{fill}\n",
5631 int i, n,
array[10];
5639 if(!pattern || !factor){
5663 default :
return "south west";
5678 fprintf(
gl2ps->
stream,
"\\pgfpathrectangle{\\pgfpoint{%fpt}{%fpt}}"
5679 "{\\pgfpoint{%fpt}{%fpt}}\n\\pgfusepath{fill}\n",
5684 fprintf(
gl2ps->
stream,
"\\pgfpathcircle{\\pgfpoint{%fpt}{%fpt}}"
5685 "{%fpt}\n\\pgfusepath{fill}\n",
5698 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"buttcap");
5701 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"roundcap");
5704 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"rectcap");
5712 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"miterjoin");
5715 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"roundjoin");
5718 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"beveljoin");
5724 "\\pgfpathmoveto{\\pgfpoint{%fpt}{%fpt}}\n"
5725 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5726 "\\pgfusepath{stroke}\n",
5733 fprintf(
gl2ps->
stream,
"\\pgfsetlinewidth{0.01pt}\n");
5739 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"buttcap");
5742 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"roundcap");
5745 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"rectcap");
5753 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"miterjoin");
5756 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"roundjoin");
5759 fprintf(
gl2ps->
stream,
"\\pgfset%s\n",
"beveljoin");
5765 "\\pgfpathmoveto{\\pgfpoint{%fpt}{%fpt}}\n"
5766 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5767 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5769 "\\pgfusepath{fill,stroke}\n",
5775 fprintf(
gl2ps->
stream,
"{\n\\pgftransformshift{\\pgfpoint{%fpt}{%fpt}}\n",
5781 fprintf(
gl2ps->
stream,
"\\pgfnode{rectangle}{%s}{\\fontsize{%d}{0}\\selectfont",
5785 fprintf(
gl2ps->
stream,
"\\textcolor[rgb]{%g,%g,%g}{{%s}}",
5789 fprintf(
gl2ps->
stream,
"}{}{\\pgfusepath{discard}}");
5816 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
5818 glRenderMode(GL_FEEDBACK);
5830 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
5833 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
5841 "\\pgfpathrectangle{\\pgfpoint{%dpt}{%dpt}}"
5842 "{\\pgfpoint{%dpt}{%dpt}}\n"
5843 "\\pgfusepath{fill}\n",
5848 "\\pgfpathrectangle{\\pgfpoint{%dpt}{%dpt}}"
5849 "{\\pgfpoint{%dpt}{%dpt}}\n"
5850 "\\pgfusepath{clip}\n",
5876 "PGF Latex Graphics"
5904 for(i = 0; i < prim->
numverts; i++){
5923 used = glRenderMode(GL_RENDER);
5998 "GL2PS_DRAW_BACKGROUND are incompatible.");
6003 "GL2PS_USE_CURRENT_VIEWPORT are incompatible.");
6008 "option GL2PS_NO_BLENDING.");
6011 if (colormode != GL_RGBA) {
6028 GLint viewport[4], GLint format, GLint sort,
6029 GLint options, GLint colormode,
6031 GLint nr, GLint ng, GLint nb, GLint buffersize,
6032 FILE *stream,
const char *filename)
6096 for(i = 0; i < 4; i++){
6115 for(i = 0; i < 3; i++){
6118 for(i = 0; i < 4; i++){
6138 : glIsEnabled(GL_BLEND);
6154 if(!colorsize || !colormap){
6163 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
6209 glRenderMode(GL_FEEDBACK);
6295 GLshort fontsize, GLint alignment, GLfloat
angle,
6299 color, GL_FALSE, 0, 0);
6308 GLshort fontsize, GLint alignment, GLfloat
angle,
6309 GL2PSrgba color, GLfloat blx, GLfloat bly)
6312 color, GL_TRUE, blx, bly);
6316 GLshort fontsize, GLint alignment, GLfloat
angle)
6324 NULL, GL_FALSE, 0, 0);
6338 GLint xorig, GLint yorig,
6339 GLenum format, GLenum type,
6344 GLfloat pos[4], zoom_x, zoom_y;
6350 if((width <= 0) || (height <= 0))
return GL2PS_ERROR;
6354 if((format != GL_RGB && format != GL_RGBA) || type != GL_FLOAT){
6356 "GL_RGB/GL_RGBA, GL_FLOAT pixels");
6370 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
6372 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
6373 glGetFloatv(GL_ZOOM_X, &zoom_x);
6374 glGetFloatv(GL_ZOOM_Y, &zoom_y);
6382 prim->
verts[0].
xyz[0] = pos[0] + xorig;
6383 prim->
verts[0].
xyz[1] = pos[1] + yorig;
6399 glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->
verts[0].
rgba);
6416 size = height * width * 3;
6418 piv = (
const GLfloat*)pixels;
6419 for(i = 0; i < size; ++i, ++piv){
6426 size = height * width * 4;
6433 size = height * width * 3;
6452 const GLfloat position[3],
6453 const unsigned char *imagemap){
6455 int sizeoffloat =
sizeof(GLfloat);
6459 if((width <= 0) || (height <= 0))
return GL2PS_ERROR;
6461 size = height + height * ((width - 1) / 8);
6464 glVertex3f(position[0], position[1],position[2]);
6466 glPassThrough((GLfloat)width);
6467 glPassThrough((GLfloat)height);
6468 for(i = 0; i < size; i += sizeoffloat){
6469 const float *value = (
const float*)imagemap;
6470 glPassThrough(*value);
6471 imagemap += sizeoffloat;
6486 glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &tmp2);
6487 glPassThrough(tmp2);
6488 glGetFloatv(GL_POLYGON_OFFSET_UNITS, &tmp2);
6489 glPassThrough(tmp2);
6496 glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &tmp);
6497 glPassThrough((GLfloat)tmp);
6498 glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &tmp);
6499 glPassThrough((GLfloat)tmp);
6542 glPassThrough(value);
6552 glPassThrough(value);
6562 glPassThrough(value);
6572 glPassThrough(value);
6585 glPassThrough((GLfloat)sfactor);
6587 glPassThrough((GLfloat)dfactor);
6622 return "Unknown format";
6630 return "Unknown format";