[gl2ps] Problem with linewidth and viewport

Michael Goffioul michael.goffioul at gmail.com
Tue Aug 21 13:49:11 CEST 2007


On 8/21/07, Christophe Geuzaine <cgeuzaine at ulg.ac.be> wrote:
> Hi Michael - Indeed, we cache the last used color, line width, ...,
> across viewports... but we probably shouldn't.
>
> Can you replace the "gl2psEndViewport" routine with this one and let me
> know if it fixes the problem?
>
> GL2PSDLL_API GLint gl2psEndViewport(void)
> {
>   GLint res;
>
>   if(!gl2ps) return GL2PS_UNINITIALIZED;
>
>   res = (gl2psbackends[gl2ps->format]->endViewport)();
>
>   /* reset last used line width */
>   gl2ps->lastlinewidth = -1.0F;
>
>   return res;
> }
>
>
> If it does I'll make sure to fix the bug in the next release.

It works.

While I'm at it,  I made some modifications to GL2PS in order to put some
extra space around text strings. This is controlled by the additional "margin"
argument of gl2psTextOpt. The diff's are attached. You might want to use it.

Michael.
-------------- next part --------------
--- src/gl2ps.h	2007-08-21 11:11:12.129356500 +0200
+++ /cygdrive/d/Temp/gl2ps.h	2007-08-21 13:42:56.564263500 +0200
@@ -171,7 +171,7 @@
 GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, 
                              GLshort fontsize);
 GL2PSDLL_API GLint gl2psTextOpt(const char *str, const char *fontname, 
-                                GLshort fontsize, GLint align, GLfloat angle, GLfloat margin);
+                                GLshort fontsize, GLint align, GLfloat angle);
 GL2PSDLL_API GLint gl2psSpecial(GLint format, const char *str);
 GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height,
                                    GLint xorig, GLint yorig,
-------------- next part --------------
--- src/gl2ps.c	2007-08-21 13:39:43.604076900 +0200
+++ /cygdrive/d/Temp/gl2ps.c	2007-08-21 13:48:17.449543700 +0200
@@ -182,7 +182,6 @@
      (PostScript, PDF, etc.) of the special string */
   GLint alignment;
   GLfloat angle;
-  GLfloat margin;
 } GL2PSstring;
 
 typedef struct {
@@ -299,7 +298,7 @@
 {
   va_list args;
 
-  if(1 || !(gl2ps->options & GL2PS_SILENT)){
+  if(!(gl2ps->options & GL2PS_SILENT)){
     switch(level){
     case GL2PS_INFO : fprintf(stderr, "GL2PS info: "); break;
     case GL2PS_WARNING : fprintf(stderr, "GL2PS warning: "); break;
@@ -861,7 +860,7 @@
 /* Helper routines for text strings */
 
 static GLint gl2psAddText(GLint type, const char *str, const char *fontname, 
-                          GLshort fontsize, GLint alignment, GLfloat angle, GLfloat margin)
+                          GLshort fontsize, GLint alignment, GLfloat angle)
 {
   GLfloat pos[4];
   GL2PSprimitive *prim;
@@ -898,7 +897,6 @@
   prim->data.text->fontsize = fontsize;
   prim->data.text->alignment = alignment;
   prim->data.text->angle = angle;
-  prim->data.text->margin = margin;
 
   gl2psListAdd(gl2ps->auxprimitives, &prim);
   glPassThrough(GL2PS_TEXT_TOKEN);
@@ -2719,30 +2717,30 @@
               "/G  { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add setgray } BD\n"
               "/W  { setlinewidth } BD\n");
 
-  gl2psPrintf("/FC { /SM exch def findfont exch /SH exch def SH scalefont setfont } BD\n"
+  gl2psPrintf("/FC { findfont exch /SH exch def SH scalefont setfont } BD\n"
               "/SW { dup stringwidth pop } BD\n"
-              "/S  { FC moveto SM dup rmoveto show } BD\n"
-              "/SBC{ FC moveto 0 SM rmoveto SW -2 div 0 rmoveto show } BD\n"
-              "/SBR{ FC moveto SM neg SM rmoveto SW neg 0 rmoveto show } BD\n"
-              "/SCL{ FC moveto SM 0 rmoveto 0 SH -2 div rmoveto show } BD\n"
+              "/S  { FC moveto show } BD\n"
+              "/SBC{ FC moveto SW -2 div 0 rmoveto show } BD\n"
+              "/SBR{ FC moveto SW neg 0 rmoveto show } BD\n"
+              "/SCL{ FC moveto 0 SH -2 div rmoveto show } BD\n"
               "/SCC{ FC moveto SW -2 div SH -2 div rmoveto show } BD\n"
-              "/SCR{ FC moveto SM neg 0 rmoveto SW neg SH -2 div rmoveto show } BD\n"
-              "/STL{ FC moveto SM SM neg rmoveto 0 SH neg rmoveto show } BD\n"
-              "/STC{ FC moveto 0 SM neg rmoveto SW -2 div SH neg rmoveto show } BD\n"
-              "/STR{ FC moveto SM neg dup rmoveto SW neg SH neg rmoveto show } BD\n");
+              "/SCR{ FC moveto SW neg SH -2 div rmoveto show } BD\n"
+              "/STL{ FC moveto 0 SH neg rmoveto show } BD\n"
+              "/STC{ FC moveto SW -2 div SH neg rmoveto show } BD\n"
+              "/STR{ FC moveto SW neg SH neg rmoveto show } BD\n");
 
   /* rotated text routines: same nameanem with R appended */
 
   gl2psPrintf("/FCT { FC translate 0 0 } BD\n"
-              "/SR  { gsave FCT moveto rotate SM dup rmoveto show grestore } BD\n"  
-              "/SBCR{ gsave FCT moveto rotate 0 SM rmoveto SW -2 div 0 rmoveto show grestore } BD\n"
-              "/SBRR{ gsave FCT moveto rotate SM neg SM rmoveto SW neg 0 rmoveto show grestore } BD\n"
-              "/SCLR{ gsave FCT moveto rotate SM 0 rmoveto 0 SH -2 div rmoveto show grestore} BD\n");
+              "/SR  { gsave FCT moveto rotate show grestore } BD\n"  
+              "/SBCR{ gsave FCT moveto rotate SW -2 div 0 rmoveto show grestore } BD\n"
+              "/SBRR{ gsave FCT moveto rotate SW neg 0 rmoveto show grestore } BD\n"
+              "/SCLR{ gsave FCT moveto rotate 0 SH -2 div rmoveto show grestore} BD\n");
   gl2psPrintf("/SCCR{ gsave FCT moveto rotate SW -2 div SH -2 div rmoveto show grestore} BD\n"
-              "/SCRR{ gsave FCT moveto rotate SM neg 0 rmoveto SW neg SH -2 div rmoveto show grestore} BD\n"
-              "/STLR{ gsave FCT moveto rotate SM SM neg rmoveto 0 SH neg rmoveto show grestore } BD\n"
-              "/STCR{ gsave FCT moveto rotate 0 SM neg rmoveto SW -2 div SH neg rmoveto show grestore } BD\n"
-              "/STRR{ gsave FCT moveto rotate SM neg dup rmoveto SW neg SH neg rmoveto show grestore } BD\n");
+              "/SCRR{ gsave FCT moveto rotate SW neg SH -2 div rmoveto show grestore} BD\n"
+              "/STLR{ gsave FCT moveto rotate 0 SH neg rmoveto show grestore } BD\n"
+              "/STCR{ gsave FCT moveto rotate SW -2 div SH neg rmoveto show grestore } BD\n"
+              "/STRR{ gsave FCT moveto rotate SW neg SH neg rmoveto show grestore } BD\n");
 
   gl2psPrintf("/P  { newpath 0.0 360.0 arc closepath fill } BD\n"
               "/LS { newpath moveto } BD\n"
@@ -3059,9 +3057,9 @@
     gl2psPrintf("(%s) ", prim->data.text->str);
     if(prim->data.text->angle)
       gl2psPrintf("%g ", prim->data.text->angle);
-    gl2psPrintf("%g %g %d /%s %g ",
+    gl2psPrintf("%g %g %d /%s ",
                 prim->verts[0].xyz[0], prim->verts[0].xyz[1],
-                prim->data.text->fontsize, prim->data.text->fontname, prim->data.text->margin);
+                prim->data.text->fontsize, prim->data.text->fontname);
     switch(prim->data.text->alignment){
     case GL2PS_TEXT_C:
       gl2psPrintf(prim->data.text->angle ? "SCCR\n" : "SCC\n");
@@ -5751,19 +5749,19 @@
 }
 
 GL2PSDLL_API GLint gl2psTextOpt(const char *str, const char *fontname, 
-                                GLshort fontsize, GLint alignment, GLfloat angle, GLfloat margin)
+                                GLshort fontsize, GLint alignment, GLfloat angle)
 {
-  return gl2psAddText(GL2PS_TEXT, str, fontname, fontsize, alignment, angle, margin);
+  return gl2psAddText(GL2PS_TEXT, str, fontname, fontsize, alignment, angle);
 }
 
 GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize)
 {
-  return gl2psAddText(GL2PS_TEXT, str, fontname, fontsize, GL2PS_TEXT_BL, 0.0F, 0.0F);
+  return gl2psAddText(GL2PS_TEXT, str, fontname, fontsize, GL2PS_TEXT_BL, 0.0F);
 }
 
 GL2PSDLL_API GLint gl2psSpecial(GLint format, const char *str)
 {
-  return gl2psAddText(GL2PS_SPECIAL, str, "", 0, format, 0.0F, 0.0F);
+  return gl2psAddText(GL2PS_SPECIAL, str, "", 0, format, 0.0F);
 }
 
 GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height,