From: Michael G. <gof...@us...> - 2007-08-23 13:05:46
|
Update of /cvsroot/octave/octave-forge/extra/jhandles/src In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv23236/src Modified Files: gl2ps.c gl2ps.h gl2ps_java.c Log Message: handle box around text in PS output Index: gl2ps_java.c =================================================================== RCS file: /cvsroot/octave/octave-forge/extra/jhandles/src/gl2ps_java.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- gl2ps_java.c 22 Aug 2007 14:58:35 -0000 1.4 +++ gl2ps_java.c 23 Aug 2007 13:05:46 -0000 1.5 @@ -19,6 +19,11 @@ #define WITH_JINTARRAY(s, code) \ JINTARRAY(s); do { code } while (0); END_JINTARRAY(s); +#define JFLOATARRAY(s) jfloat* s = (_ ## s ? (*env)->GetFloatArrayElements(env, _ ## s, NULL) : NULL) +#define END_JFLOATARRAY(s) if (s) (*env)->ReleaseFloatArrayElements(env, _ ## s, s, 0) +#define WITH_JFLOATARRAY(s, code) \ + JFLOATARRAY(s); do { code } while (0); END_JFLOATARRAY(s); + JNIEXPORT jint JNICALL Java_org_octave_graphics_GL2PS_gl2psBeginPage (JNIEnv *env, jclass cls, jstring _title, jstring _producer, @@ -97,14 +102,18 @@ (JNIEnv *env, jclass cls, jstring _string, jstring _fontname, jint fontsize, jint align, jfloat angle, jfloat margin, - jboolean offsetmargin) + jboolean offsetmargin, jfloat linewidth, jfloatArray _linecolor, + jshort linepattern, jint linefactor, jfloatArray _fillcolor) { GLint result; WITH_JSTRING(string, WITH_JSTRING(fontname, - result = gl2psTextOpt(string, fontname, fontsize, align, angle, margin, offsetmargin); - )) + WITH_JFLOATARRAY(linecolor, + WITH_JFLOATARRAY(fillcolor, + result = gl2psTextOpt(string, fontname, fontsize, align, angle, margin, offsetmargin, + linewidth, linecolor, linepattern, linefactor, fillcolor); + )))) return result; } Index: gl2ps.c =================================================================== RCS file: /cvsroot/octave/octave-forge/extra/jhandles/src/gl2ps.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- gl2ps.c 22 Aug 2007 15:00:55 -0000 1.5 +++ gl2ps.c 23 Aug 2007 13:05:46 -0000 1.6 @@ -189,6 +189,7 @@ GLushort linepattern; GLint linefactor; GL2PSrgba fillcolor; + GLboolean depthtest; } GL2PSstring; typedef struct { @@ -909,22 +910,27 @@ prim->data.text->margin = margin; prim->data.text->offsetmargin = offsetmargin; prim->data.text->linewidth = lwidth; - if (lwidth > 0) + if (lwidth > 0 && lc != NULL) { prim->data.text->linecolor[0] = lc[0]; prim->data.text->linecolor[1] = lc[1]; prim->data.text->linecolor[2] = lc[2]; prim->data.text->linecolor[3] = lc[3]; } + else + prim->data.text->linecolor[0] = -1.0F; prim->data.text->linepattern = lpattern; prim->data.text->linefactor = lfactor; - if (fc) + if (fc != NULL) { prim->data.text->fillcolor[0] = fc[0]; prim->data.text->fillcolor[1] = fc[1]; prim->data.text->fillcolor[2] = fc[2]; prim->data.text->fillcolor[3] = fc[3]; } + else + prim->data.text->fillcolor[0] = -1.0F; + glGetBooleanv(GL_DEPTH_TEST, &(prim->data.text->depthtest)); gl2psListAdd(gl2ps->auxprimitives, &prim); glPassThrough(GL2PS_TEXT_TOKEN); @@ -955,6 +961,7 @@ text->fillcolor[1] = t->fillcolor[1]; text->fillcolor[2] = t->fillcolor[2]; text->fillcolor[3] = t->fillcolor[3]; + text->depthtest = t->depthtest; return text; } @@ -1416,7 +1423,7 @@ (*t2)->verts[0] = quad->verts[0]; (*t2)->verts[1] = quad->verts[2]; (*t2)->verts[2] = quad->verts[3]; - (*t1)->boundary = ((quad->boundary & 4) ? 2 : 0) | ((quad->boundary & 4) ? 2 : 0); + (*t2)->boundary = ((quad->boundary & 4) ? 2 : 0) | ((quad->boundary & 4) ? 2 : 0); } static int gl2psCompareDepth(const void *a, const void *b) @@ -1591,6 +1598,10 @@ for(i = 0; i < gl2psListNbr(primitives); i++){ if(i != index){ prim = *(GL2PSprimitive**)gl2psListPointer(primitives,i); + if (prim->type == GL2PS_TEXT && prim->data.text->depthtest == GL_FALSE) { + gl2psAddPrimitiveInList(prim, backlist); + continue; + } switch(gl2psSplitPrimitive(prim, tree->plane, &frontprim, &backprim)){ case GL2PS_COINCIDENT: gl2psAddPrimitiveInList(prim, tree->primitives); @@ -2760,7 +2771,7 @@ /* text decoration (border and fill) */ - gl2psPrintf("/TB { gsave 4 1 roll setrgbcolor fillState not { exch W 3 1 roll setdash } if\n" + gl2psPrintf("/TB { gsave 4 1 roll setrgbcolor fillState not { exch W } if\n" " SM neg dup SD add rmoveto currentpoint newpath moveto\n" " SW SM 2 mul add 0 rlineto\n" " 0 SH SM 2 mul add rlineto\n" @@ -3115,7 +3126,27 @@ break; case GL2PS_TEXT : gl2psPrintPostScriptColor(prim->verts[0].rgba); - gl2psPrintf("0 (%s) ", prim->data.text->str); + if (prim->data.text->linecolor[0] >= 0 || prim->data.text->fillcolor[0] >= 0) + { + int boxFlag = 0; + if (prim->data.text->linecolor[0] >= 0) + { + gl2psPrintPostScriptDash(prim->data.text->linepattern, prim->data.text->linefactor, "setdash"); + gl2psPrintf("%g %g %g %g ", prim->data.text->linewidth, prim->data.text->linecolor[0], + prim->data.text->linecolor[1], prim->data.text->linecolor[2]); + boxFlag |= 2; + } + if (prim->data.text->fillcolor[0] >= 0) + { + gl2psPrintf("%g %g %g ", prim->data.text->fillcolor[0], prim->data.text->fillcolor[1], + prim->data.text->fillcolor[2]); + boxFlag |= 1; + } + gl2psPrintf("%d ", boxFlag); + } + else + gl2psPrintf("0 "); + gl2psPrintf("(%s) ", prim->data.text->str); if(prim->data.text->angle) gl2psPrintf("%g ", prim->data.text->angle); gl2psPrintf("%g %g %d /%s %g %s ", @@ -5824,7 +5855,7 @@ GLushort lpattern, GLint lfactor, GL2PSrgba fc) { return gl2psAddText(GL2PS_TEXT, str, fontname, fontsize, alignment, angle, margin, offsetmargin, - 0, NULL, 0xFFFF, 1, NULL); + lwidth, lc, lpattern, lfactor, fc); } GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize) Index: gl2ps.h =================================================================== RCS file: /cvsroot/octave/octave-forge/extra/jhandles/src/gl2ps.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- gl2ps.h 22 Aug 2007 14:58:35 -0000 1.3 +++ gl2ps.h 23 Aug 2007 13:05:46 -0000 1.4 @@ -176,7 +176,8 @@ GLshort fontsize); GL2PSDLL_API GLint gl2psTextOpt(const char *str, const char *fontname, GLshort fontsize, GLint align, GLfloat angle, GLfloat margin, - GLboolean offsetmargin); + GLboolean offsetmargin, GLfloat linewidth, GL2PSrgba linecolor, + GLushort linepattern, GLint linefactor, GL2PSrgba fillcolor); GL2PSDLL_API GLint gl2psSpecial(GLint format, const char *str); GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, GLint xorig, GLint yorig, |