diff --git a/gl2ps.c b/gl2ps.c index e63b24d0baecabb36f21921a4cb011dd7391247d..cb66c91b1127d4a5dd4fe139af4d7ce829365138 100644 --- a/gl2ps.c +++ b/gl2ps.c @@ -3391,23 +3391,39 @@ static int gl2psPrintPDFLineWidth(GLfloat lw) static void gl2psPutPDFText(GL2PSstring *text, int cnt, GLfloat x, GLfloat y) { - gl2ps->streamlength += - gl2psPrintf("BT\n" - "/F%d %d Tf\n" - "%f %f Td\n" - "(%s) Tj\n" - "ET\n", - cnt, text->fontsize, x, y, text->str); + GLfloat rad, crad, srad; + + if(text->angle == 0.0F){ + gl2ps->streamlength += gl2psPrintf + ("BT\n" + "/F%d %d Tf\n" + "%f %f Td\n" + "(%s) Tj\n" + "ET\n", + cnt, text->fontsize, x, y, text->str); + } + else{ + rad = M_PI * text->angle / 180.0F; + srad = (GLfloat)sin(rad); + crad = (GLfloat)cos(rad); + gl2ps->streamlength += gl2psPrintf + ("BT\n" + "/F%d %d Tf\n" + "%f %f %f %f %f %f Tm\n" + "(%s) Tj\n" + "ET\n", + cnt, text->fontsize, crad, srad, -srad, crad, x, y, text->str); + } } static void gl2psPutPDFImage(GL2PSimage *image, int cnt, GLfloat x, GLfloat y) { - gl2ps->streamlength += - gl2psPrintf("q\n" - "%d 0 0 %d %f %f cm\n" - "/Im%d Do\n" - "Q\n", - (int)image->width, (int)image->height, x, y, cnt); + gl2ps->streamlength += gl2psPrintf + ("q\n" + "%d 0 0 %d %f %f cm\n" + "/Im%d Do\n" + "Q\n", + (int)image->width, (int)image->height, x, y, cnt); } static void gl2psPDFstacksInit(void) diff --git a/gl2ps.tex b/gl2ps.tex index 8cee26cf2739e36e779edb8291f98e22a39ffc28..2e5909af7bf2de31fee845f645cccf7b587b0731 100644 --- a/gl2ps.tex +++ b/gl2ps.tex @@ -1,4 +1,3 @@ -% $Id: gl2ps.tex,v 1.3 2009-10-11 22:07:21 geuzaine Exp $ % % GL2PS, an OpenGL to PostScript Printing Library % Copyright (C) 1999-2009 C. Geuzaine @@ -63,7 +62,7 @@ \title{GL2PS: an OpenGL to PostScript printing library} \author{Christophe Geuzaine} -\date{Version 1.3.5, October 12 2009} +\date{Version 1.3.5, October 16 2009} \maketitle @@ -873,6 +872,9 @@ in pdf code; \noemail{Sylvestre Ledru}{sylvestre.ledru@scilab.org} for SVG patches; % \noemail{Calixte Denizet}{Calixte.Denizet@ac-rennes.fr} for 64 bit patch. +% +\noemail{lion\_vasilief@yahoo.fr}{Ion Vasilief} and Paul Griffiths for +rotated text in PDF output. \section{Links} \label{sec:links} @@ -1011,8 +1013,9 @@ anymore. fixed possible divisions by zero. \item[1.3.4] (Sep 30, 2009) Added support for rotated text in SVG output; fixed MSVC warnings. -\item[1.3.5] (Oct 12, 2009) Fixed PDF image output when compiled in 64 bit - mode; added cmake build file. +\item[1.3.5] (Oct 16, 2009) Added support for rotated text in PDF output; + fixed PDF image output when compiled in 64 bit mode; added cmake + configuration. \end{description} \special{html:<p> diff --git a/gl2psTest.c b/gl2psTest.c index 1486079e62acf52e981b87f8b8ad1039f88c789f..9b39f57deaadcbd151f05e573553221e420c845d 100644 --- a/gl2psTest.c +++ b/gl2psTest.c @@ -1,4 +1,3 @@ -/* $Id: gl2psTest.c,v 1.85 2009-09-30 21:50:19 geuzaine Exp $ */ /* * GL2PS, an OpenGL to PostScript Printing Library * Copyright (C) 1999-2009 Christophe Geuzaine <geuz@geuz.org> @@ -133,7 +132,8 @@ static char *pixmap[] = { "*..............................................................*", "****************************************************************"}; -void triangles(void){ +void triangles() +{ /* two intersecting triangles */ glBegin(GL_TRIANGLES); @@ -154,7 +154,8 @@ void triangles(void){ glEnd(); } -void extras(void){ +void extras() +{ glColor3f(1., 0., 0.); glPointSize(1.); @@ -222,7 +223,8 @@ void extras(void){ gl2psLineWidth(1); } -void objects(void){ +void objects() +{ glPushMatrix(); glEnable(GL_LIGHTING); glRotatef(rotation, 2., 0., 1.); @@ -237,7 +239,8 @@ void objects(void){ glPopMatrix(); } -void printstring(char *string){ +void printstring(char *string, float angle) +{ unsigned int i; char *fonts[] = { "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic", @@ -247,38 +250,50 @@ void printstring(char *string){ /* call gl2psText before the glut function since glutBitmapCharacter changes the raster position... */ - gl2psText(string, fonts[4], 12); + gl2psTextOpt(string, fonts[4], 12, GL2PS_TEXT_BL, angle); for (i = 0; i < strlen(string); i++) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, string[i]); } -void text(void){ +void text() +{ double x = -1.25, y = -0.33, dy = 0.13; glColor3f(1., 1., 0.); - glRasterPos2d(x, y); y -= dy; - printstring("Press:"); - glRasterPos2d(x, y); y -= dy; - printstring(" p: to change the print format (PS, EPS, PDF, ...)"); - glRasterPos2d(x, y); y -= dy; - printstring(" s: to save the images"); - glRasterPos2d(x, y); y -= dy; - printstring(" t: to alternate between teapot and torus"); - glRasterPos2d(x, y); y -= dy; - printstring(" v: to alternate between single and multiple viewport modes"); - glRasterPos2d(x, y); y -= dy; - printstring(" b: to change the blending mode (transparency)"); - glRasterPos2d(x, y); y -= dy; - printstring(" q: to quit"); - glRasterPos2d(x, y); y -= dy; - printstring("Click and move the mouse to rotate the objects"); + glRasterPos2d(x, y); + printstring("Press:", 0.); + y -= dy; + glRasterPos2d(x, y); + printstring(" p: to change the print format (PS, EPS, PDF, ...)", 0.); + y -= dy; + glRasterPos2d(x, y); + printstring(" s: to save the images", 0.); + y -= dy; + glRasterPos2d(x, y); + printstring(" t: to alternate between teapot and torus", 0.); + y -= dy; + glRasterPos2d(x, y); + printstring(" v: to alternate between single and multiple viewport modes", 0.); + y -= dy; + glRasterPos2d(x, y); + printstring(" b: to change the blending mode (transparency)", 0.); + y -= dy; + glRasterPos2d(x, y); + printstring(" q: to quit", 0.), 0.; + y -= dy; + glRasterPos2d(x, y); + printstring("Click and move the mouse to rotate the objects", 0.); + + glRasterPos2d(0, 0.75); + printstring("rotated", 45.); gl2psSpecial(GL2PS_TEX, "% This should only be printed in LaTeX output!"); } -void cube(void){ +void cube() +{ glColor3d (0.0,1.0,0.); glBegin(GL_POLYGON); glVertex3d( 0.5,-0.5,-0.5); @@ -313,7 +328,8 @@ void cube(void){ glEnd(); } -void image(float x, float y, GLboolean opaque){ +void image(float x, float y, GLboolean opaque) +{ int w = 64, h = 66, row, col, pos = 0; float *pixels, r = 0., g = 0., b = 0.; @@ -366,7 +382,8 @@ void image(float x, float y, GLboolean opaque){ } /* A simple drawing function, using the default viewport */ -void draw_single(void){ +void draw_single() +{ glScissor(0, 0, window_w, window_h); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); triangles(); @@ -377,7 +394,8 @@ void draw_single(void){ } /* A more complex drawing function, using 2 separate viewports */ -void draw_multi(void){ +void draw_multi() +{ GLint viewport[4]; glScissor(0, 0, window_w, window_h); @@ -436,7 +454,8 @@ void draw_multi(void){ glFlush(); } -void display(void){ +void display() +{ GLfloat spec[4] = {0.6, 0.6, 0.6, 1.0}; glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); @@ -462,7 +481,8 @@ void display(void){ } } -void reshape(int w, int h){ +void reshape(int w, int h) +{ window_w = w; window_h = h; @@ -477,7 +497,8 @@ void reshape(int w, int h){ } void writefile(int format, int sort, int options, int nbcol, - char *filename, const char *extension){ + char *filename, const char *extension) +{ FILE *fp; char file[256]; int state = GL2PS_OVERFLOW, buffsize = 0; @@ -517,7 +538,8 @@ void writefile(int format, int sort, int options, int nbcol, fflush(stdout); } -void keyboard(unsigned char key, int x, int y){ +void keyboard(unsigned char key, int x, int y) +{ int opt; char ext[32]; static int format = GL2PS_PS; @@ -585,12 +607,14 @@ void keyboard(unsigned char key, int x, int y){ } } -void motion(int x, int y){ +void motion(int x, int y) +{ rotation += 10.; display(); } -int main(int argc, char **argv){ +int main(int argc, char **argv) +{ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_DEPTH); glutInitWindowSize(400, 600); diff --git a/gl2psTestSimple.c b/gl2psTestSimple.c index a8644c3abb9e071abdfb320029ba686f44816b00..efb9f3a17d87baa30110de12cc3dfe5a20a25db3 100644 --- a/gl2psTestSimple.c +++ b/gl2psTestSimple.c @@ -1,4 +1,3 @@ -/* $Id: gl2psTestSimple.c,v 1.17 2009-09-30 21:50:19 geuzaine Exp $ */ /* * GL2PS, an OpenGL to PostScript Printing Library * Copyright (C) 1999-2009 Christophe Geuzaine <geuz@geuz.org> @@ -51,7 +50,8 @@ #include <string.h> #include "gl2ps.h" -void display(void){ +void display() +{ unsigned int i; int N = 50; char *help = "Press 's' to save image or 'q' to quit"; @@ -91,7 +91,8 @@ void display(void){ glFlush(); } -void keyboard(unsigned char key, int x, int y){ +void keyboard(unsigned char key, int x, int y) +{ FILE *fp; int state = GL2PS_OVERFLOW, buffsize = 0; @@ -116,8 +117,9 @@ void keyboard(unsigned char key, int x, int y){ } } -int main(int argc, char **argv){ - GLfloat pos[4]={1.,1.,-1.,0.}; +int main(int argc, char **argv) +{ + GLfloat pos[4] = {1., 1., -1., 0.}; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH);