inc/psGfx.h File Reference

#include "psPoly.h"

Include dependency graph for psGfx.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  psGfx

Functions

psGfxpsOpen (char *fileName, double userWidth, double userHeight, double ptWidth, double ptHeight, double ptMargin)
void psClose (struct psGfx **pPs)
void psTranslate (struct psGfx *ps, double xTrans, double yTrans)
void psClipRect (struct psGfx *ps, double x, double y, double width, double height)
void psDrawBox (struct psGfx *ps, double x, double y, double width, double height)
void psDrawLine (struct psGfx *ps, double x1, double y1, double x2, double y2)
void psFillUnder (struct psGfx *ps, double x1, double y1, double x2, double y2, double bottom)
void psXyOut (struct psGfx *ps, double x, double y)
void psWhOut (struct psGfx *ps, double width, double height)
void psMoveTo (struct psGfx *ps, double x, double y)
void psTextAt (struct psGfx *ps, double x, double y, char *text)
void psTextDown (struct psGfx *ps, double x, double y, char *text)
void psTextRight (struct psGfx *mg, double x, double y, double width, double height, char *text)
void psTextCentered (struct psGfx *mg, double x, double y, double width, double height, char *text)
void psTimesFont (struct psGfx *ps, double size)
void psSetColor (struct psGfx *ps, int r, int g, int b)
void psSetGray (struct psGfx *ps, double grayVal)
void psPushG (struct psGfx *ps)
void psPopG (struct psGfx *ps)
void psDrawPoly (struct psGfx *ps, struct psPoly *poly, boolean filled)
void psFillEllipse (struct psGfx *ps, double x, double y, double xrad, double yrad)
void psDrawEllipse (struct psGfx *ps, double x, double y, double xrad, double yrad, double startAngle, double endAngle)
char * convertEpsToPdf (char *epsFile)


Function Documentation

char* convertEpsToPdf ( char *  epsFile  ) 

Definition at line 346 of file psGfx.c.

References addSuffix(), chopLine, chopSuffix(), cloneString(), freez(), lineFileClose(), lineFileNext(), lineFileOpen(), round, safef(), and TRUE.

00348 {
00349 char *pdfTmpName = NULL, *pdfName=NULL;
00350 char cmdBuffer[2048];
00351 int sysVal = 0;
00352 struct lineFile *lf = NULL;
00353 char *line;
00354 int lineSize=0;
00355 float width=0, height=0;
00356 pdfTmpName = cloneString(epsFile);
00357 
00358 /* Get the dimensions of bounding box. */
00359 lf = lineFileOpen(epsFile, TRUE);
00360 while(lineFileNext(lf, &line, &lineSize)) 
00361     {
00362     if(strstr( line, "BoundingBox:")) 
00363         {
00364         char *words[5];
00365         chopLine(line, words);
00366         width = atof(words[3]);
00367         height = atof(words[4]);
00368         break;
00369         }
00370     }
00371 lineFileClose(&lf);
00372         
00373 /* Do conversion. */
00374 chopSuffix(pdfTmpName);
00375 pdfName = addSuffix(pdfTmpName, ".pdf");
00376 safef(cmdBuffer, sizeof(cmdBuffer), "ps2pdf -dDEVICEWIDTHPOINTS=%d -dDEVICEHEIGHTPOINTS=%d %s %s", 
00377       round(width), round(height), epsFile, pdfName);
00378 sysVal = system(cmdBuffer);
00379 if(sysVal != 0)
00380     freez(&pdfName);
00381 freez(&pdfTmpName);
00382 return pdfName;
00383 }

Here is the call graph for this function:

void psClipRect ( struct psGfx ps,
double  x,
double  y,
double  width,
double  height 
)

Definition at line 24 of file psGfx.c.

References psGfx::f, psWhOut(), and psXyOut().

Referenced by pscmSetClip(), pscmUnclip(), and psOpen().

00027 {
00028 FILE *f = ps->f;
00029 fprintf(f, "cliprestore ");
00030 psXyOut(ps, x, y+height); 
00031 psWhOut(ps, width, height);       
00032 fprintf(f, "rectclip\n");
00033 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psClose ( struct psGfx **  pPs  ) 

Definition at line 105 of file psGfx.c.

References carefulClose(), psGfx::f, and freez().

Referenced by pscmClose().

00107 {
00108 struct psGfx *ps = *pPs;
00109 if (ps != NULL)
00110     {
00111     carefulClose(&ps->f);
00112     freez(pPs);
00113     }
00114 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psDrawBox ( struct psGfx ps,
double  x,
double  y,
double  width,
double  height 
)

Definition at line 147 of file psGfx.c.

References psGfx::f, psWhOut(), and psXyOut().

Referenced by pscmBoxToPs(), pscmDot(), pscmLine(), and pscmVerticalSmear().

00150 {
00151 if (width > 0 && height > 0)
00152     {
00153     psWhOut(ps, width, height);
00154     psXyOut(ps, x, y+height); 
00155     fprintf(ps->f, "fillBox\n");
00156     }
00157 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psDrawEllipse ( struct psGfx ps,
double  x,
double  y,
double  xrad,
double  yrad,
double  startAngle,
double  endAngle 
)

Definition at line 332 of file psGfx.c.

References psGfx::f, psFloatOut(), psWhOut(), and psXyOut().

00334 {
00335 FILE *f = ps->f;
00336 fprintf(f, "newpath\n");
00337 psXyOut(ps, x, y);
00338 psWhOut(ps, xrad, yrad);
00339 psFloatOut(f, startAngle);
00340 psFloatOut(f, endAngle);
00341 fprintf(f, "ellipse\n");
00342 fprintf(f, "closepath\n");
00343 fprintf(f, "stroke\n");
00344 }

Here is the call graph for this function:

void psDrawLine ( struct psGfx ps,
double  x1,
double  y1,
double  x2,
double  y2 
)

Definition at line 159 of file psGfx.c.

References psGfx::f, psMoveTo(), and psXyOut().

Referenced by pscmLine().

00161 {
00162 FILE *f = ps->f;
00163 fprintf(f, "newpath\n");
00164 psMoveTo(ps, x1, y1);
00165 psXyOut(ps, x2, y2);
00166 fprintf(ps->f, "lineto\n");
00167 fprintf(f, "stroke\n");
00168 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psDrawPoly ( struct psGfx ps,
struct psPoly poly,
boolean  filled 
)

Definition at line 295 of file psGfx.c.

References psGfx::f, psPoint::next, psLineTo(), psMoveTo(), psPoly::ptList, psPoint::x, and psPoint::y.

Referenced by pscmDrawPoly().

00297 {
00298 FILE *f = ps->f;
00299 struct psPoint *p = poly->ptList;
00300 fprintf(f, "newpath\n");
00301 psMoveTo(ps, p->x, p->y);
00302 for (;;)
00303     {
00304     p = p->next;
00305     psLineTo(ps, p->x, p->y);
00306     if (p == poly->ptList)
00307         break;
00308     }
00309 if (filled)
00310     {
00311     fprintf(f, "fill\n");
00312     }
00313 else
00314     {
00315     fprintf(f, "closepath\n");
00316     fprintf(f, "stroke\n");
00317     }
00318 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psFillEllipse ( struct psGfx ps,
double  x,
double  y,
double  xrad,
double  yrad 
)

Definition at line 321 of file psGfx.c.

References psGfx::f, psWhOut(), and psXyOut().

00322 {
00323 FILE *f = ps->f;
00324 fprintf(f, "newpath\n");
00325 psXyOut(ps, x, y);
00326 psWhOut(ps, xrad, yrad);
00327 fprintf(f, "%d %d ellipse\n",   0, 360);
00328 fprintf(f, "closepath\n");
00329 fprintf(f, "fill\n");
00330 }

Here is the call graph for this function:

void psFillUnder ( struct psGfx ps,
double  x1,
double  y1,
double  x2,
double  y2,
double  bottom 
)

Definition at line 170 of file psGfx.c.

References psGfx::f, psLineTo(), and psMoveTo().

Referenced by pscmFillUnder().

00176 {
00177 FILE *f = ps->f;
00178 fprintf(f, "newpath\n");
00179 psMoveTo(ps, x1, y1);
00180 psLineTo(ps, x2, y2);
00181 psLineTo(ps, x2, bottom);
00182 psLineTo(ps, x1, bottom);
00183 fprintf(f, "closepath\n");
00184 fprintf(f, "fill\n");
00185 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psMoveTo ( struct psGfx ps,
double  x,
double  y 
)

Definition at line 132 of file psGfx.c.

References psGfx::f, and psXyOut().

Referenced by psDrawLine(), psDrawPoly(), psFillUnder(), psTextAt(), psTextCentered(), psTextDown(), and psTextRight().

00134 {
00135 psXyOut(ps, x, y);
00136 fprintf(ps->f, "moveto\n");
00137 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct psGfx* psOpen ( char *  fileName,
double  userWidth,
double  userHeight,
double  ptWidth,
double  ptHeight,
double  ptMargin 
) [read]

Definition at line 49 of file psGfx.c.

References AllocVar, psGfx::f, psGfx::fontHeight, mustOpen(), psClipRect(), psWriteHeader(), psGfx::ptHeight, psGfx::ptWidth, psGfx::userHeight, psGfx::userWidth, psGfx::xOff, psGfx::xScale, psGfx::yOff, and psGfx::yScale.

Referenced by pscmOpen().

00055 {
00056 struct psGfx *ps;
00057 
00058 /* Allocate structure and open file. */
00059 AllocVar(ps);
00060 ps->f = mustOpen(fileName, "w");
00061 
00062 /* Save page dimensions and calculate scaling factors. */
00063 ps->userWidth = userWidth;
00064 ps->userHeight = userHeight;
00065 ps->ptWidth = ptWidth;
00066 ps->xScale = (ptWidth - 2*ptMargin)/userWidth;
00067 if (ptHeight != 0.0)
00068    {
00069    ps->ptHeight = ptHeight;
00070    ps->yScale = (ptHeight - 2*ptMargin) / userHeight;
00071    }
00072 else
00073    {
00074    ps->yScale = ps->xScale;
00075    ptHeight = ps->ptHeight = userHeight * ps->yScale + 2*ptMargin;
00076    }
00077 /* 0.5, 0.5 is the center of the pixel in upper-left corner which corresponds to (0,0) */
00078 ps->xOff = ptMargin;
00079 ps->yOff = ptMargin;
00080 ps->fontHeight = 10;
00081 
00082 /* Cope with fact y coordinates are bottom to top rather
00083  * than top to bottom. */
00084 ps->yScale = -ps->yScale;
00085 ps->yOff = ps->ptHeight - ps->yOff;
00086 
00087 psWriteHeader(ps->f, ptWidth, ptHeight);
00088 
00089 /* Set initial clipping rectangle. */
00090 psClipRect(ps, 0, 0, ps->userWidth, ps->userHeight);
00091 
00092 /* Set line width to a single pixel. */
00093 fprintf(ps->f, "%f setlinewidth\n", ps->xScale);
00094 
00095 return ps;
00096 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psPopG ( struct psGfx ps  ) 

Definition at line 289 of file psGfx.c.

References psGfx::f.

00291 {
00292 fprintf(ps->f, "grestore\n");
00293 }

void psPushG ( struct psGfx ps  ) 

Definition at line 283 of file psGfx.c.

References psGfx::f.

00285 {
00286 fprintf(ps->f, "gsave\n");
00287 }

void psSetColor ( struct psGfx ps,
int  r,
int  g,
int  b 
)

Definition at line 254 of file psGfx.c.

References psGfx::f, and psFloatOut().

Referenced by pscmSetColor().

00256 {
00257 FILE *f = ps->f;
00258 double scale = 1.0/255;
00259 if (r == g && g == b)
00260     {
00261     psFloatOut(f, scale * r);
00262     fprintf(f, "setgray\n");
00263     }
00264 else
00265     {
00266     psFloatOut(f, scale * r);
00267     psFloatOut(f, scale * g);
00268     psFloatOut(f, scale * b);
00269     fprintf(f, "setrgbcolor\n");
00270     }
00271 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psSetGray ( struct psGfx ps,
double  grayVal 
)

Definition at line 273 of file psGfx.c.

References psGfx::f, and psFloatOut().

00275 {
00276 FILE *f = ps->f;
00277 if (grayVal < 0) grayVal = 0;
00278 if (grayVal > 1) grayVal = 1;
00279 psFloatOut(f, grayVal);
00280 fprintf(f, "setgray\n");
00281 }

Here is the call graph for this function:

void psTextAt ( struct psGfx ps,
double  x,
double  y,
char *  text 
)

Definition at line 201 of file psGfx.c.

References psGfx::f, psGfx::fontHeight, and psMoveTo().

Referenced by pscmText().

00203 {
00204 char c;
00205 psMoveTo(ps, x, y + ps->fontHeight);
00206 fprintf(ps->f, "(");
00207 while ((c = *text++) != 0)
00208     {
00209     if (c == ')' || c == '(')
00210         fprintf(ps->f, "\\");
00211     fprintf(ps->f, "%c", c);
00212     }
00213 fprintf(ps->f, ") show\n");
00214 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psTextCentered ( struct psGfx mg,
double  x,
double  y,
double  width,
double  height,
char *  text 
)

Definition at line 226 of file psGfx.c.

References psGfx::f, psGfx::fontHeight, and psMoveTo().

Referenced by pscmTextCentered().

00230 {
00231 char c;
00232 y += (height - ps->fontHeight)/2;
00233 psMoveTo(ps, x+width/2, y + ps->fontHeight);
00234 fprintf(ps->f, "(");
00235 while ((c = *text++) != 0)
00236     {
00237     if (c == ')' || c == '(')
00238         fprintf(ps->f, "\\");
00239     fprintf(ps->f, "%c", c);
00240     }
00241 fprintf(ps->f, ") showMiddle\n");
00242 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psTextDown ( struct psGfx ps,
double  x,
double  y,
char *  text 
)

Definition at line 244 of file psGfx.c.

References psGfx::f, and psMoveTo().

00246 {
00247 psMoveTo(ps, x, y);
00248 fprintf(ps->f, "gsave\n");
00249 fprintf(ps->f, "-90 rotate\n");
00250 fprintf(ps->f, "(%s) show\n", text);
00251 fprintf(ps->f, "grestore\n");
00252 }

Here is the call graph for this function:

void psTextRight ( struct psGfx mg,
double  x,
double  y,
double  width,
double  height,
char *  text 
)

Definition at line 216 of file psGfx.c.

References psGfx::f, psGfx::fontHeight, and psMoveTo().

Referenced by pscmTextRight().

00220 {
00221 y += (height - ps->fontHeight)/2;
00222 psMoveTo(ps, x+width, y + ps->fontHeight);
00223 fprintf(ps->f, "(%s) showBefore\n", text);
00224 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psTimesFont ( struct psGfx ps,
double  size 
)

Definition at line 187 of file psGfx.c.

References psGfx::f, psGfx::fontHeight, and psGfx::yScale.

Referenced by pscmSetFont().

00189 {
00190 FILE *f = ps->f;
00191 fprintf(f, "/Helvetica findfont ");
00192 
00193 /* Note the 1.2 and the 1.0 below seem to get it to 
00194  * position about where the stuff developed for pixel
00195  * based systems expects it.  It is all a kludge though! */
00196 fprintf(f, "%f scalefont setfont\n", -size*ps->yScale*1.2);
00197 ps->fontHeight = size*0.8;
00198 }

Here is the caller graph for this function:

void psTranslate ( struct psGfx ps,
double  xTrans,
double  yTrans 
)

Definition at line 98 of file psGfx.c.

References psGfx::xOff, psGfx::xScale, psGfx::yOff, and psGfx::yScale.

Referenced by pscmOpen().

00100 {
00101 ps->xOff += xTrans*ps->xScale;   
00102 ps->yOff += yTrans*ps->yScale;
00103 }

Here is the caller graph for this function:

void psWhOut ( struct psGfx ps,
double  width,
double  height 
)

Definition at line 124 of file psGfx.c.

References psGfx::f, psFloatOut(), psGfx::xScale, and psGfx::yScale.

Referenced by psClipRect(), psDrawBox(), psDrawEllipse(), and psFillEllipse().

00126 {
00127 FILE *f = ps->f;
00128 psFloatOut(f, width * ps->xScale);
00129 psFloatOut(f, height * -ps->yScale);
00130 }

Here is the call graph for this function:

Here is the caller graph for this function:

void psXyOut ( struct psGfx ps,
double  x,
double  y 
)

Definition at line 116 of file psGfx.c.

References psGfx::f, psFloatOut(), psGfx::xOff, psGfx::xScale, psGfx::yOff, and psGfx::yScale.

Referenced by psClipRect(), psDrawBox(), psDrawEllipse(), psDrawLine(), psFillEllipse(), psLineTo(), and psMoveTo().

00118 {
00119 FILE *f = ps->f;
00120 psFloatOut(f, x * ps->xScale + ps->xOff);
00121 psFloatOut(f, y * ps->yScale + ps->yOff);
00122 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Tue Dec 25 19:11:49 2007 for blat by  doxygen 1.5.2