1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
/*
* This file is part of XForms.
*
* XForms is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1, or
* (at your option) any later version.
*
* XForms 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with XForms. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file fd2ps.c
*
* This file is part of XForms package
* Copyright (c) 1997-2000 by T.C. Zhao
* All rights reserved.
*
* Read in a form defination file (.fd) and write an EPS output
* for inclusion in a document
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <stdlib.h>
#include "include/forms.h"
#include "fd2ps.h"
#include "global.h"
static int parse_command_line( int argc, char * argv[ ] );
static void usage( const char *, int );
static void fd2ps_init( void );
static char *helpmsg[ ] =
{
"-h this help",
"-dpi f specifies the pixel/length conversion",
"-gray requests grayscale output",
"-l requests landscape output",
"-p requests portrait output",
"-bw n sets object border width",
"-eps requests Encapsulated PostScript",
"-G f specifies gamma",
"-verbose specifies verbose output",
"-version prints version info and exits",
"-paper s specifies paper name (A4 etc). Use all for a list",
"-pw f specifies paper width (in inches)",
"-ph f specifies paper height (in inches)",
0
};
/***************************************
***************************************/
static void
usage( const char * cmd,
int die )
{
char **q = helpmsg;
fprintf( stderr, "Usage: %s [options] infile.[fd] [outfile]\n", cmd );
fprintf( stderr, " where options are\n" );
for ( ; *q; q++ )
fprintf( stderr, " %s\n", *q );
fprintf( stderr, " -rgb file specifies the path to rgb.txt. "
"Default is %s\n", psinfo.rgbfile );
if ( die )
exit( 1 );
}
/***************************************
***************************************/
int
main( int argc,
char * argv[ ] )
{
int n;
char outname[ 512 ],
inname[ 512 ],
*p;
FILE *fp;
fd2ps_init( );
n = parse_command_line( argc, argv );
strcpy( inname, argv[ n ] );
if ( ! strstr( inname, ".fd" ) )
strcat( inname, ".fd" );
if ( n < argc - 1 )
strcpy( outname, argv[ ++n ] );
else
{
strcpy( outname, inname );
if ( ( p = strrchr( outname, '.' ) ) )
*p = '\0';
strcat( outname, psinfo.eps ? ".eps" : ".ps" );
}
/* before opening the output file, check the existence of input */
if ( ! ( fp = fopen( inname, "r" ) ) )
{
perror( inname );
exit( 1 );
}
fclose( fp );
if ( strcmp( outname, "-" ) == 0 )
flps->fp = stdout;
else if ( ! ( flps->fp = fopen( outname, "w" ) ) )
{
fprintf( stderr, "Can't open %s for output\n", outname );
exit( 1 );
}
load_form_definition( inname );
return 0;
}
/***************************************
* Overall default configuration
***************************************/
static void
fd2ps_init( void )
{
char *env;
psinfo.xdpi = psinfo.ydpi = 85;
psinfo.paper_name = "Letter";
get_paper_size( psinfo.paper_name, &psinfo.paper_w, &psinfo.paper_h );
psinfo.bw = 2; /* Should be 1 but then output looks shitty JTT */
psinfo.verbose = 0;
psinfo.colorps = 1;
psinfo.eps = 0;
psinfo.gamma = 1.0;
psinfo.page = 1;
psinfo.xscale = psinfo.yscale = 1.0;
psinfo.pack = 1;
psinfo.landscape = -1; /* auto */
psinfo.fp = stdout;
psinfo.rgbfile = "/usr/lib/X11/rgb.txt";
psinfo.xpmtops_direct = 1;
flps = &psinfo;
/* check if enviornment variable paper is defined */
if ( ( env = getenv( "PAPER" ) ) )
{
get_paper_size( env, &psinfo.paper_w, &psinfo.paper_h );
psinfo.paper_name = env;
}
if ( ( env = getenv( "RGBFile" ) ) )
psinfo.rgbfile = env;
}
/***************************************
***************************************/
static int
parse_command_line( int argc,
char * argv[ ] )
{
int i;
float ftmp;
for ( i = 1; i < argc && *argv[ i ] == '-'; i++ )
{
if ( strcmp( argv[ i ], "-bw" ) == 0 && i + 1 < argc )
psinfo.user_bw = atoi( argv[ ++i ] );
else if ( strcmp( argv[ i ], "-dpi" ) == 0 && i + 1 < argc )
{
ftmp = atof( argv[ ++i ] );
psinfo.xdpi = psinfo.ydpi = ftmp;
}
else if ( strncmp( argv[ i ], "-verb", 5 ) == 0 )
psinfo.verbose = 1;
else if ( strcmp(argv[ i ], "-eps" ) == 0 )
psinfo.eps = 1;
else if ( strncmp( argv[ i ], "-vers", 5 ) == 0 )
print_version( 1 );
else if (strncmp( argv[ i ], "-h", 2 ) == 0 )
usage( argv[ 0 ], 1 );
else if ( strcmp( argv[ i ], "-pw" ) == 0 && i + 1 < argc )
{
psinfo.paper_w = atof( argv[ ++i ] );
psinfo.paper_name = 0;
}
else if ( strcmp(argv[ i ], "-ph" ) == 0 && i + 1 < argc )
{
psinfo.paper_h = atof( argv[ ++i ] );
psinfo.paper_name = 0;
}
else if ( strcmp( argv[ i ], "-G" ) == 0 && i + 1 < argc )
psinfo.gamma = atof( argv[ ++i ] );
else if (strcmp( argv[ i ], "-l" ) == 0 )
psinfo.landscape = 1;
else if ( strcmp( argv[ i ], "-p" ) == 0 )
psinfo.landscape = 0;
else if ( strcmp( argv[ i ], "-color" ) == 0 )
psinfo.colorps = 1;
else if ( strcmp( argv[ i ], "-pack" ) == 0 )
psinfo.pack = !psinfo.pack;
else if ( strcmp( argv[ i ], "-gray" ) == 0
|| strcmp( argv[ i ], "-grey" ) == 0 )
psinfo.colorps = 0;
else if ( strcmp( argv[ i ], "-rgb" ) == 0 && i + 1 < argc )
psinfo.rgbfile = fl_strdup( argv[ ++i ] );
else if ( strcmp( argv[ i ], "-paper" ) == 0 && i + 1 < argc )
{
if ( strcmp( argv[ ++i ], "all" ) == 0 )
{
fprintf( stderr, " The following paper names are known\n" );
list_papers( "\t" );
exit( 0 );
}
get_paper_size( argv[ i ], &psinfo.paper_w, &psinfo.paper_h );
psinfo.paper_name = argv[ i ];
}
else
{
usage( argv[ 0 ], 0 );
fprintf( stderr, "Unknown Option %s\n", argv[ i ] );
exit( 1 );
}
}
if ( i == argc )
usage( argv[ 0 ], 1 );
/* limited validation */
if ( psinfo.paper_h <= 1 || psinfo.paper_w <= 1 )
{
fprintf( stderr, "%s: incorrect paper size (%.1fX%.1f)\n",
argv[ 0 ], psinfo.paper_w, psinfo.paper_h );
exit( 0 );
}
if ( psinfo.xdpi < 50 || psinfo.xdpi > 300 )
{
fprintf( stderr, "%s: unusual DPI value %.1f\n",
argv[ 0 ], psinfo.xdpi );
}
if ( psinfo.gamma != 1.0 )
apply_gamma( psinfo.gamma );
return i;
}
/*
* Local variables:
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
|