/********************************************************************
This file is part of the abs 0.907 distribution. abs is a spreadsheet
with graphical user interface.
Copyright (C) 1998-2001 André Bertin (Andre.Bertin@ping.be)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version if in the same spirit as version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Concact: abs@pi.be
http://home.pi.be/bertin/abs.shtml
*********************************************************************/
#include "print.h"
#include "worksheet.h"
#include "application.h"
#include "main.h"
#include "callback.h"
#include "fig.h"
#include "gr_interf.h"
#include <stdio.h>
PrintParam printparam;
int
printfile (PrintParam pp)
{
FILE *fp;
int i, j;
double H, W;
int PH = 29.7 * 450;
int PW = 21.0 * 450;
int x0, y0, xn, yn;
Graph *gr;
Drawing *dr;
int tofile = 0;
char paper[10];
char *spc;
int i1, i2, j1, j2;
char command[256];
int p;
strncpy (paper, pp.papertype, 8);
spc = strchr (paper, ' ');
*spc = '\0';
if (ActiveWorksheet == NULL)
return -1;
if (ActiveWorksheet->maxrow < 1)
return -1;
getselection (&i1, &j1, &i2, &j2);
if (pp.what == PWKS || pp.what == PWKB || (i1 == i2 && j1 == j2) || i1 < 1 || j1 < 1
|| i2 > ActiveWorksheet->nblin || j2 > ActiveWorksheet->nbcol)
{
i1 = 1;
j1 = 1;
i2 = ActiveWorksheet->maxrow;
j2 = ActiveWorksheet->_maxcol;
absijtoxy (i1, j1, &x0, &y0);
absijtoxy (i2 + 1, j2 + 1, &xn, &yn);
for (i = 0; i < getnumgra (); i++)
{
gr = (Graph *) getgra (i);
if (gr->x + gr->w > xn)
xn = gr->x + gr->w;
if (gr->y + gr->h > yn)
yn = gr->y + gr->h;
}
for (i = 0; i < getnumdra (); i++)
{
dr = (Drawing *) getdra (i);
if (dr->x2 > xn)
xn = dr->x2;
if (dr->y2 > yn)
yn = dr->y2;
if (dr->x1 > xn)
xn = dr->x1;
if (dr->y1 > yn)
yn = dr->y1;
}
}
else
{
absijtoxy (i1, j1, &x0, &y0);
absijtoxy (i2 + 1, j2 + 1, &xn, &yn);
}
if (pp.filename == NULL)
{
if (strstr (pp.destination, "fig"))
pp.filename = "output.fig";
else
pp.filename = "output.ps";
}
else
tofile = 1;
fp = fopen ("output.fig", "w");
if (fp == NULL)
return -1;
FIG_init (fp);
W = abs (xn - x0);
H = abs (yn - y0);
if (!strncmp (paper, "A0", 2))
{
PH = 118.9 * 450;
PW = 84.1 * 450;
}
if (!strncmp (paper, "A1", 2))
{
PH = 84.1 * 450;
PW = 59.4 * 450;
}
if (!strncmp (paper, "A2", 2))
{
PH = 59.4 * 450;
PW = 42.0 * 450;
}
if (!strncmp (paper, "A3", 2))
{
PH = 42.0 * 450;
PW = 29.7 * 450;
}
if (!strncmp (paper, "A4", 2))
{
PH = 29.7 * 450;
PW = 21.0 * 450;
}
if (!strncmp (paper, "B5", 2))
{
PH = 25.7 * 450;
PW = 18.2 * 450;
}
if (!strncmp (paper, "Ledger", 6))
{
PH = 17 * 2.54 * 450;
PW = 11 * 2.54 * 450;
}
if (!strncmp (paper, "Legal", 5))
{
PH = 14 * 2.54 * 450;
PW = 11 * 2.54 * 450;
}
if (!strncmp (paper, "Letter", 6))
{
PH = 11 * 2.54 * 450;
PW = 8.5 * 2.54 * 450;
}
if (pp.magnification == 0)
{
double Wmax, Hmax, mh = 1, mw = 1;
if (pp.orientation == PORTRAIT)
{
Wmax = (PW - (pp.lm + pp.rm) * 450) * pp.nbhpages;
Hmax = (PH - (pp.tm + pp.bm) * 450) * pp.nbvpages;
}
else
{
Hmax = (PW - (pp.lm + pp.rm) * 450) * pp.nbhpages;
Wmax = (PH - (pp.tm + pp.bm) * 450) * pp.nbvpages;
}
if (H * 15 > Hmax)
mh = Hmax / (H * 15);
if (W * 15 > Wmax)
mw = Wmax / (W * 15);
if (mw < mh)
mh = mw;
pp.magnification = mh * 100.0;
}
FIG_options (1200, pp.center, pp.orientation, paper);
i = x0 - pp.lm * 30;
j = y0 - pp.tm * 30;
setout (2, 15, 15, i, j);
for (i = i1; i <= i2; i++)
{
for (j = j1; j <= j2; j++)
{
xdrawcell (i, j, 5, 1);
}
}
for (i = 0; i < getnumgra (); i++)
{
gr = (Graph *) getgra (i);
if (gr->x >= x0 && gr->y >= y0 && gr->x + gr->w <= x0 + W
&& gr->y + gr->h <= y0 + H)
doplot (gr);
}
for (i = 0; i < getnumdra (); i++)
{
dr = (Drawing *) getdra (i);
if (
(dr->x1 >= x0 && dr->y1 >= y0 && dr->x1 <= x0 + W
&& dr->y1 <= y0 + H) || (dr->x2 >= x0 && dr->y2 >= y0
&& dr->x2 <= x0 + W && dr->y2 <= y0 + H))
redrawdr (dr);
}
setout (0, 1, 1, x0, y0);
fclose (fp);
if (!strcmp (pp.destination, "fig format file"))
return 0;
if (!strcmp (pp.destination, "xfig preview"))
{
sprintf (command, "xfig %s", pp.filename);
system (command);
return 0;
}
if (!strcmp (pp.destination, "ghostview preview") ||
!strcmp (pp.destination, "postscript format file"))
{
pp.language = "ps";
sprintf (command, "fig2dev -L%s", pp.language);
if (pp.center == CENTER)
sprintf (command, "%s -c", command);
sprintf (command, "%s -P", command);
sprintf (command, "%s -z %s", command, paper);
sprintf (command, "%s -M", command);
sprintf (command, "%s -m %f", command, pp.magnification / 100.0);
if (pp.orientation == PORTRAIT)
{
sprintf (command, "%s -p xxx", command);
}
else
{
sprintf (command, "%s -l xxx", command);
}
sprintf (command, "%s -n output.ps", command);
p = pp.xshift;
sprintf (command, "%s -x %d", command, p);
p = pp.yshift;
sprintf (command, "%s -y %d", command, p);
sprintf (command, "%s output.fig %s", command, pp.filename);
fprintf (stderr, command);
system (command);
}
if (!strcmp (pp.destination, "ghostview preview"))
{
sprintf (command, "ghostview %s", pp.filename);
system (command);
return 0;
}
return 0;
}
syntax highlighted by Code2HTML, v. 0.9.1