home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
ast40dos
/
xgeneral.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-04
|
42KB
|
1,421 lines
/*
** Astrolog (Version 4.00) File: xgeneral.c
**
** IMPORTANT NOTICE: the graphics database and chart display routines
** used in this program are Copyright (C) 1991-1993 by Walter D. Pullen
** (cruiser1@stein.u.washington.edu). Permission is granted to freely
** use and distribute these routines provided one doesn't sell,
** restrict, or profit from them in any way. Modification is allowed
** provided these notices remain with any altered or edited versions of
** the program.
**
** The main planetary calculation routines used in this program have
** been Copyrighted and the core of this program is basically a
** conversion to C of the routines created by James Neely as listed in
** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
** available from Matrix Software. The copyright gives us permission to
** use the routines for personal use but not to sell them or profit from
** them in any way.
**
** The PostScript code within the core graphics routines are programmed
** and Copyright (C) 1992-1993 by Brian D. Willoughby
** (brianw@sounds.wa.com). Conditions are identical to those above.
**
** The extended accurate ephemeris databases and formulas are from the
** calculation routines in the program "Placalc" and are programmed and
** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
** (alois@azur.ch). The use of that source code is subject to
** regulations made by Astrodienst Zurich, and the code is not in the
** public domain. This copyright notice must not be changed or removed
** by any user of this program.
**
** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
** X Window graphics initially programmed 10/23-29/1991.
** PostScript graphics initially programmed 11/29-30/1992.
** Last code change made 12/31/1993.
*/
#include "astrolog.h"
#ifdef GRAPH
int xpen, ypen;
/*
******************************************************************************
** Bitmap File Routines.
******************************************************************************
*/
/* Write the bitmap array to a previously opened file in a format that */
/* can be read in by the Unix X commands bitmap and xsetroot. The 'mode' */
/* parameter defines how much white space is put in the file. */
void WriteXBitmap(data, name, mode)
FILE *data;
char *name, mode;
{
int x, y, i, temp = 0;
uint value;
fprintf(data, "#define %s_width %d\n" , name, chartx);
fprintf(data, "#define %s_height %d\n", name, charty);
fprintf(data, "static %s %s_bits[] = {",
mode != 'V' ? "char" : "short", name);
for (y = 0; y < charty; y++) {
x = 0;
do {
/* Process each row, eight columns at a time. */
if (y + x > 0)
fprintf(data, ",");
if (temp == 0)
fprintf(data, "\n%s",
mode == 'N' ? " " : (mode == 'C' ? " " : ""));
value = 0;
for (i = (mode != 'V' ? 7 : 15); i >= 0; i--)
value = (value << 1) +
(!(PGET(bm, x+i, y)^(xreverse*15))^xreverse && (x + i < chartx));
if (mode == 'N')
putc(' ', data);
fprintf(data, "0x");
if (mode == 'V')
fprintf(data, "%c%c",
INTTOHEX(value >> 12), INTTOHEX((value >> 8) & 15));
fprintf(data, "%c%c",
INTTOHEX((value >> 4) & 15), INTTOHEX(value & 15));
temp++;
/* Is it time to skip to the next line while writing the file yet? */
if ((mode == 'N' && temp >= 12) ||
(mode == 'C' && temp >= 15) ||
(mode == 'V' && temp >= 11))
temp = 0;
x += (mode != 'V' ? 8 : 16);
} while (x < chartx);
}
fprintf(data, "};\n");
}
/* Write the bitmap array to a previously opened file in a simple boolean */
/* Ascii rectangle, one char per pixel, where '#' represents an off bit and */
/* '-' an on bit. The output format is identical to the format generated by */
/* the Unix bmtoa command, and it can be converted into a bitmap with atobm. */
void WriteAscii(data)
FILE *data;
{
int x, y, i;
for (y = 0; y < charty; y++) {
for (x = 0; x < chartx; x++) {
i = PGET(bm, x, y);
if (xcolor)
putc(INTTOHEX(i), data);
else
putc(i ? '-' : '#', data);
}
putc('\n', data);
}
}
/* Write the bitmap array to a previously opened file in the bitmap format */
/* used in Microsoft Windows for its .bmp extension files. This is a pretty */
/* efficient format, only requiring one bit per pixel and a small header. */
void WriteBmp(data)
FILE *data;
{
int x, y;
dword value;
/* BitmapFileHeader */
PutByte('B'); PutByte('M');
PutLong(14+40 + (xcolor ? 64 : 8) +
(long)4*charty*((chartx-1 >> (xcolor ? 3 : 5))+1));
PutWord(0); PutWord(0);
PutLong(14+40 + (xcolor ? 64 : 8));
/* BitmapInfo / BitmapInfoHeader */
PutLong(40);
PutLong(chartx); PutLong(charty);
PutWord(1); PutWord(xcolor ? 4 : 1);
PutLong(0 /*BI_RGB*/); PutLong(0);
PutLong(0); PutLong(0);
PutLong(0); PutLong(0);
/* RgbQuad */
if (xcolor)
for (x = 0; x < 16; x++) {
PutByte(RGBB(rgbbmp[x])); PutByte(RGBG(rgbbmp[x]));
PutByte(RGBR(rgbbmp[x])); PutByte(0);
}
else {
PutLong(0);
PutByte(255); PutByte(255); PutByte(255); PutByte(0);
}
/* Data */
for (y = charty-1; y >= 0; y--) {
value = 0;
for (x = 0; x < chartx; x++) {
if ((x & (xcolor ? 7 : 31)) == 0 && x > 0) {
PutLong(value);
value = 0;
}
if (xcolor)
value |= (dword)PGET(bm, x, y) << ((x & 7 ^ 1) << 2);
else
if (PGET(bm, x, y))
value |= (dword)1 << (x & 31 ^ 7);
}
PutLong(value);
}
}
/* Output the bitmap in memory to a file. This basically consists of just */
/* calling some routine to actually write a bitmap to a file, although we */
/* need to prompt the user for a filename if it wasn't specified beforehand. */
void WriteFile()
{
char line[STRING];
FILE *data;
#ifdef PS
if (psfile) {
PSend();
return;
}
#endif
if (outputfile == NULL && (metafile || (xbitmap && bitmapmode == 'B')))
fprintf(stdout, "(It is recommended to specify an extension of '.%s'.)\n",
xbitmap ? "bmp" : "wmf");
loop {
if (outputfile == NULL) {
sprintf(line, "Enter name of file to write %s to",
xbitmap ? "bitmap" : "metafile");
InputString(line, line);
outputfile = line;
}
data = fopen(outputfile, "wb");
if (data != NULL)
break;
else {
PrintWarning("Couldn't create output file.");
outputfile = NULL;
}
}
if (xbitmap) {
if (bitmapmode == 'B')
WriteBmp(data);
else if (bitmapmode == 'A')
WriteAscii(data);
else
WriteXBitmap(data, outputfile, bitmapmode);
}
#ifdef META
else
WriteMeta(data);
#endif
fclose(data);
}
/*
******************************************************************************
** PostScript File Routines.
******************************************************************************
*/
#ifdef PS
/* Global variables used by the PostScript generator. */
FILE *psdata;
int strokecount = 0, currentlinecap = 0, currentdash = 0, currentfont = 0;
real currentlinewidth = 1.0;
/* Table of PostScript header alias lines used by the program. */
char PSfunctions[] =
"/languagelevel where{pop languagelevel}{1}ifelse\
2 lt{\n\
/sf{exch findfont exch\
dup type/arraytype eq{makefont}{scalefont}ifelse setfont}bind def\n\
/rf{gsave newpath\n\
4 -2 roll moveto\
dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto closepath\n\
fill grestore}bind def\n\
/rc{newpath\n\
4 -2 roll moveto\
dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto closepath\n\
clip newpath}bind def\n\
}{/sf/selectfont load def/rf/rectfill load def\
/rc/rectclip load def}ifelse\n\
/center{0 begin gsave dup 4 2 roll\
translate newpath 0 0 moveto\
false charpath flattenpath pathbbox\
/URy exch def/URx exch def/LLy exch def/LLx exch def\
URx LLx sub 0.5 mul