-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxdevice.cpp
executable file
·1502 lines (1316 loc) · 45 KB
/
xdevice.cpp
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Astrolog (Version 6.40) File: xdevice.cpp
**
** IMPORTANT NOTICE: Astrolog and all chart display routines and anything
** not enumerated below used in this program are Copyright (C) 1991-2018 by
** Walter D. Pullen (Astara@msn.com, http://www.astrolog.org/astrolog.htm).
** Permission is granted to freely use, modify, and distribute these
** routines provided these credits and notices remain unmodified with any
** altered or distributed versions of the program.
**
** The main ephemeris databases and calculation routines are from the
** library SWISS EPHEMERIS and are programmed and copyright 1997-2008 by
** Astrodienst AG. The use of that source code is subject to the license for
** Swiss Ephemeris Free Edition, available at http://www.astro.com/swisseph.
** This copyright notice must not be changed or removed by any user of this
** program.
**
** Additional 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@astro.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.
**
** The original planetary calculation routines used in this program have
** been copyrighted and the initial core of this program was mostly a
** conversion to C of the routines created by James Neely as listed in
** 'Manual of Computer Programming for Astrologers', by Michael Erlewine,
** available from Matrix Software.
**
** The PostScript code within the core graphics routines are programmed
** and Copyright (C) 1992-1993 by Brian D. Willoughby (brianw@sounds.wa.com).
**
** More formally: 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. This program is
** distributed in the hope that it will be useful and inspiring, 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, a copy of which is in the
** LICENSE.HTM file included with Astrolog, and at http://www.gnu.org
**
** Initial programming 8/28-30/1991.
** X Window graphics initially programmed 10/23-29/1991.
** PostScript graphics initially programmed 11/29-30/1992.
** Last code change made 7/22/2018.
*/
#include "astrolog.h"
#ifdef GRAPH
/*
******************************************************************************
** 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(FILE *file, CONST char *name, char mode)
{
int x, y, i, temp = 0;
uint value;
char szT[cchSzDef], *pchStart, *pchEnd;
/* Determine variable name from filename. */
sprintf(szT, "%s", name);
for (pchEnd = szT; *pchEnd != chNull; pchEnd++)
;
for (pchStart = pchEnd; pchStart > szT &&
*(pchStart-1) != '/' && *(pchStart-1) != '\\'; pchStart--)
;
for (pchEnd = pchStart; *pchEnd != chNull && *pchEnd != '.'; pchEnd++)
;
*pchEnd = chNull;
/* Output file header. */
fprintf(file, "#define %s_width %d\n" , pchStart, gs.xWin);
fprintf(file, "#define %s_height %d\n", pchStart, gs.yWin);
fprintf(file, "static %s %s_bits[] = {",
mode != 'V' ? "char" : "short", pchStart);
for (y = 0; y < gs.yWin; y++) {
x = 0;
do {
/* Process each row, eight columns at a time. */
if (y + x > 0)
fprintf(file, ",");
if (temp == 0)
fprintf(file, "\n%s",
mode == 'N' ? " " : (mode == 'C' ? " " : ""));
value = 0;
for (i = (mode != 'V' ? 7 : 15); i >= 0; i--)
value = (value << 1) + (!(FBmGet(gi.bm, x+i, y)^
(gs.fInverse*15))^gs.fInverse && (x + i < gs.xWin));
if (mode == 'N')
putc(' ', file);
fprintf(file, "0x");
if (mode == 'V')
fprintf(file, "%c%c",
ChHex(value >> 12), ChHex((value >> 8) & 15));
fprintf(file, "%c%c",
ChHex((value >> 4) & 15), ChHex(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 < gs.xWin);
}
fprintf(file, "};\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(FILE *file)
{
int x, y, i;
for (y = 0; y < gs.yWin; y++) {
for (x = 0; x < gs.xWin; x++) {
i = FBmGet(gi.bm, x, y);
if (gs.fColor)
putc(ChHex(i), file);
else
putc(i ? '-' : '#', file);
}
putc('\n', file);
}
}
/* 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 a small header, and one bit per pixel */
/* for monochrome graphics, or four bits per pixel for full color. */
void WriteBmp(FILE *file)
{
int x, y;
dword value;
/* BitmapFileHeader */
PutByte('B'); PutByte('M');
PutLong(14+40 + (gs.fColor ? 64 : 8) +
(long)4*gs.yWin*(((gs.xWin-1) >> (gs.fColor ? 3 : 5))+1));
PutWord(0); PutWord(0);
PutLong(14+40 + (gs.fColor ? 64 : 8));
/* BitmapInfo / BitmapInfoHeader */
PutLong(40);
PutLong(gs.xWin); PutLong(gs.yWin);
PutWord(1); PutWord(gs.fColor ? 4 : 1);
PutLong(0 /*BI_RGB*/); PutLong(0);
PutLong(0); PutLong(0);
PutLong(0); PutLong(0);
/* RgbQuad */
if (gs.fColor)
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 = gs.yWin-1; y >= 0; y--) {
value = 0;
for (x = 0; x < gs.xWin; x++) {
if ((x & (gs.fColor ? 7 : 31)) == 0 && x > 0) {
PutLong(value);
value = 0;
}
if (gs.fColor)
value |= (dword)FBmGet(gi.bm, x, y) << ((x & 7 ^ 1) << 2);
else
if (FBmGet(gi.bm, x, y))
value |= (dword)1 << (x & 31 ^ 7);
}
PutLong(value);
}
}
/* Begin the work of creating a graphics file. Prompt for a filename if */
/* need be, and if valid, create the file and open it for writing. */
void BeginFileX()
{
#ifndef WIN
char line[cchSzDef];
#endif
if (us.fNoWrite)
return;
#ifdef WIN
if (gi.szFileOut == NULL)
return;
#endif
#ifndef WIN
if (gi.szFileOut == NULL && (
#ifdef PS
gi.fEps ||
#endif
gs.fMeta || (gs.fBitmap && gs.chBmpMode == 'B'))) {
sprintf(line, "(It is recommended to specify an extension of '.%s'.)\n",
gs.fBitmap ? "bmp" :
#ifdef PS
(gi.fEps ? "eps" : "wmf")
#else
"wmf"
#endif
);
PrintSzScreen(line);
}
#endif /* WIN */
loop {
#ifndef WIN
if (gi.szFileOut == NULL) {
sprintf(line, "Enter name of file to write %s to",
gs.fBitmap ? "bitmap" : (gs.fPS ? "PostScript" :
(gs.fMeta ? "metafile" : "wireframe")));
InputString(line, line);
gi.szFileOut = SzPersist(line);
}
#else
/* If autosaving in potentially rapid succession, ensure the file isn't */
/* being opened by some other application before saving over it again. */
if (wi.fAutoSave) {
if (wi.hMutex == NULL)
wi.hMutex = CreateMutex(NULL, fFalse, szAppName);
if (wi.hMutex != NULL)
WaitForSingleObject(wi.hMutex, 1000);
}
#endif
gi.file = fopen(gi.szFileOut, (gs.fBitmap && gs.chBmpMode != 'B') ||
gs.fPS || gs.fWire ? "w" : "wb");
if (gi.file != NULL)
break;
#ifdef WIN
if (wi.fAutoSave)
break;
#endif
PrintWarning("Couldn't create output file.");
gi.szFileOut = NULL;
#ifdef WIN
break;
#endif
}
}
/* Finish up the work of creating a graphics file. This basically consists */
/* of just calling the appropriate routine to actually write the data in */
/* memory to a file for bitmaps and metafiles, although for PostScript we */
/* just close file as we were already writing while creating the chart. */
void EndFileX()
{
if (gs.fBitmap && gi.file != NULL) {
PrintNotice("Writing chart bitmap to file.");
if (gs.chBmpMode == 'B')
WriteBmp(gi.file);
else if (gs.chBmpMode == 'A')
WriteAscii(gi.file);
else
WriteXBitmap(gi.file, gi.szFileOut, gs.chBmpMode);
}
#ifdef PS
else if (gs.fPS)
PsEnd();
#endif
#ifdef META
else if (gs.fMeta) {
PrintNotice("Writing metafile to file.");
WriteMeta(gi.file);
}
#endif
#ifdef WIRE
else if (gs.fWire) {
PrintNotice("Writing wireframe to file.");
WriteWire(gi.file);
}
#endif
if (gi.file != NULL)
fclose(gi.file);
#ifdef WIN
if (wi.fAutoSave && wi.hMutex != NULL)
ReleaseMutex(wi.hMutex);
if (wi.wCmd == cmdSaveWallTile || wi.wCmd == cmdSaveWallCenter ||
wi.wCmd == cmdSaveWallStretch || wi.wCmd == cmdSaveWallFit ||
wi.wCmd == cmdSaveWallFill) {
WriteProfileString("Desktop", "TileWallpaper",
wi.wCmd == cmdSaveWallTile ? "1" : "0");
WriteProfileString("Desktop", "WallpaperStyle",
wi.wCmd == cmdSaveWallStretch ? "2" : (wi.wCmd == cmdSaveWallFit ? "6" :
(wi.wCmd == cmdSaveWallFill ? "10" : "0")));
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, gi.szFileOut,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
wi.wCmd = 0;
}
#endif
}
#ifdef PS
/*
******************************************************************************
** PostScript File Routines.
******************************************************************************
*/
/* Table of PostScript header alias lines used by the program. */
CONST char szPsFunctions[] =
"/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 LLx add neg URy LLy sub 0.5 mul LLy add neg"
" 0 0 moveto rmoveto"
" show grestore end}bind def\n"
"/center load 0 4 dict put\n"
"/c{setrgbcolor}bind def\n"
"/d{moveto 0 0 rlineto}bind def\n"
"/l{4 2 roll moveto lineto}bind def\n"
"/t{lineto}bind def\n"
"/el{newpath matrix currentmatrix 5 1 roll translate scale"
" 0 0 1 0 360 arc setmatrix stroke}bind def\n";
/* Write a command to flush the PostScript buffer. */
void PsStrokeForce()
{
if (gi.cStroke > 0) { /* render any existing path */
fprintf(gi.file, "stroke\n");
gi.cStroke = 0;
gi.xPen = -1; /* Invalidate PolyLine cache */
}
}
/* Indicate that a certain number of PostScript commands have been done. */
void PsStroke(int n)
{
gi.cStroke += n;
if (gi.cStroke > 2000) /* Whenever we reach a certain limit, flush. */
PsStrokeForce();
}
/* Set the type of line end to be used by PostScript commands. If linecap */
/* is true, then the line ends are rounded, otherwise they are squared. */
void PsLineCap(flag fLineCap)
{
if (fLineCap != gi.fLineCap) {
PsStrokeForce();
fprintf(gi.file, "%d setlinecap\n", fLineCap);
gi.fLineCap = fLineCap;
}
}
/* Set the dash length to be used by PostScript line commands. */
void PsDash(int dashoff)
{
if (dashoff != gi.nDash) {
PsStrokeForce();
if (dashoff)
fprintf(gi.file, "[%d %d", PSMUL, dashoff * PSMUL);
else
fprintf(gi.file, "[");
fprintf(gi.file, "]0 setdash\n");
gi.nDash = dashoff;
}
}
/* Set a linewidth size to be used by PostScript figure primitive commands. */
void PsLineWidth(int linewidth)
{
if ((real)linewidth != gi.rLineWid) {
PsStrokeForce();
fprintf(gi.file, "%d setlinewidth\n", linewidth);
gi.rLineWid = (real)linewidth;
}
}
/* Set a system font and size to be used by PostScript text commands. */
void PsFont(int psfont)
{
int z;
if (psfont != gi.nFont && gs.fFont) {
if (psfont <= 2) {
z = psfont == 1 ? 32*PSMUL : 23*PSMUL;
fprintf(gi.file, "/Astro[%d 0 0 -%d 0 0]sf\n", z, z);
} else if (psfont == 3) {
z = 26*PSMUL;
fprintf(gi.file, "/Times-Roman[%d 0 0 -%d 0 0]sf\n", z, z);
} else {
z = 10*PSMUL;
fprintf(gi.file, "/Courier[%d 0 0 -%d 0 0]sf\n", z, z);
}
gi.nFont = psfont;
}
}
/* Prompt the user for the name of a file to write the PostScript file to */
/* (if not already specified), open it, and write out file header info. */
void PsBegin()
{
fprintf(gi.file, "%%!PS-Adobe-2.0");
if (gi.fEps)
fprintf(gi.file, " EPSF-2.0");
fprintf(gi.file, "\n%%%%Title: %s\n", gi.szFileOut);
fprintf(gi.file, "%%%%Creator: %s %s\n", szAppName, szVersionCore);
fprintf(gi.file, "%%%%CreationDate: %s\n", szDateCore);
if (gi.fEps) {
fprintf(gi.file, "%%%%BoundingBox: 0 0 %d %d\n", gs.xWin, gs.yWin);
fprintf(gi.file, "%%%%EndComments\n");
fprintf(gi.file, "%%%%BeginSetup\n");
fprintf(gi.file, szPsFunctions, 6 * PSMUL, 6 * PSMUL);
fprintf(gi.file, "%%%%EndSetup\n");
fprintf(gi.file, "0 0 %d %d rc\n", gs.xWin, gs.yWin);
} else {
fprintf(gi.file, "%%%%Pages: 1 1\n");
fprintf(gi.file, "%%%%DocumentFonts: (atend)\n");
fprintf(gi.file, "%%%%BoundingBox: %d %d %d %d\n", PSGUTTER, PSGUTTER,
(int)(gs.xInch*72.0+rRound)-PSGUTTER,
(int)(gs.yInch*72.0+rRound)-PSGUTTER);
fprintf(gi.file, "%%%%EndComments\n");
fprintf(gi.file, "%%%%BeginProcSet: common\n");
fprintf(gi.file, szPsFunctions, 6 * PSMUL, 6 * PSMUL);
fprintf(gi.file, "%%%%EndProcSet\n");
fprintf(gi.file, "%%%%Page: 1 1\n");
}
PsFont(2);
fprintf(gi.file, "gsave\n");
PsLineWidth(gi.nPenWid/2);
gi.xPen = -1;
PrintNotice("Creating PostScript chart file.");
}
/* Write out trailing information to the PostScript file. */
void PsEnd()
{
PsStrokeForce();
if (gi.fEps)
fprintf(gi.file, "%%%%EOF\n");
else {
fprintf(gi.file, "showpage\n");
fprintf(gi.file, "%%%%PageTrailer\n");
fprintf(gi.file, "%%%%Trailer\n");
fprintf(gi.file, "%%%%DocumentFonts: Times-Roman\n");
if (gs.fFont) {
fprintf(gi.file, "%%%%+ Courier\n");
fprintf(gi.file, "%%%%+ Astro\n");
}
}
}
#endif /* PS */
#ifdef META
/*
******************************************************************************
** Metafile Routines.
******************************************************************************
*/
/* Output one 16 bit or 32 bit value into the metafile buffer stream. */
void MetaWord(word w)
{
char sz[cchSzDef];
if ((lpbyte)gi.pwMetaCur - gi.bm >= gi.cbMeta) {
sprintf(sz, "Metafile would be more than %ld bytes.", gi.cbMeta);
PrintError(sz);
Terminate(tcFatal);
}
*gi.pwMetaCur = w;
gi.pwMetaCur++;
}
void MetaLong(long l)
{
MetaWord(WLo(l));
MetaWord(WHi(l));
}
/* Output any necessary metafile records to make the current actual */
/* settings of line color, fill color, etc, be those that we know are */
/* desired. This is generally called by the primitives routines before */
/* any figure record is actually written into a metafile. We wait until */
/* the last moment before changing any settings to ensure that we don't */
/* output any unnecessary records, e.g. two select colors in a row. */
void MetaSelect()
{
if (gi.kiLineDes != gi.kiLineAct) {
MetaSelectObject(gi.kiLineDes);
gi.kiLineAct = gi.kiLineDes;
}
if (gi.kiFillDes != gi.kiFillAct) {
MetaSelectObject(16*4 + gi.kiFillDes);
gi.kiFillAct = gi.kiFillDes;
}
if (gi.nFontDes != gi.nFontAct) {
MetaSelectObject(16*5 + gi.nFontDes);
gi.nFontAct = gi.nFontDes;
}
if (gi.kiTextDes != gi.kiTextAct) {
MetaTextColor(rgbbmp[gi.kiTextDes]);
gi.kiTextAct = gi.kiTextDes;
}
if (gi.nAlignDes != gi.nAlignAct) {
MetaTextAlign(gi.nAlignDes);
gi.nAlignAct = gi.nAlignDes;
}
gi.xPen = -1; /* Invalidate PolyLine cache */
}
/* Output initial metafile header information into our metafile buffer. */
/* We also setup and create all pen, brush, and font objects that may */
/* possibly be used in the generation and playing of the picture. */
void MetaInit()
{
int i, j, k;
gi.pwMetaCur = (word *)gi.bm;
/* Placeable Metaheader */
MetaLong(0x9AC6CDD7L);
MetaWord(0); /* Not used */
MetaWord(0); MetaWord(0);
MetaWord(gs.xWin); MetaWord(gs.yWin);
MetaWord(gs.xWin/6); /* Units per inch */
MetaLong(0L); /* Not used */
MetaWord(0x9AC6 ^ 0xCDD7 ^ gs.xWin ^ gs.yWin ^ gs.xWin/6); /* Checksum */
/* Metaheader */
MetaWord(1); /* Metafile type */
MetaWord(9); /* Size of header in words */
MetaWord(0x300); /* Windows version */
MetaLong(0L); /* Size of entire metafile in words */
MetaWord(16*5+1+(gs.fFont>0)*4); /* Number of objects in metafile */
MetaLong(17L); /* Size of largest record in words */
MetaWord(0); /* Not used */
/* Setup */
MetaEscape(17);
MetaLong(LFromBB('A', 's', 't', 'r')); /* "Astr" */
MetaWord(4); /* Creator */
MetaLong(14L); /* Bytes in string */
MetaLong(LFromBB('A', 's', 't', 'r')); /* "Astr" */
MetaLong(LFromBB('o', 'l', 'o', 'g')); /* "olog" */
MetaLong(LFromBB(' ', '6', '.', '4')); /* " 6.4" */
MetaWord(WFromBB('0', 0)); /* "0" */
MetaSaveDc();
MetaWindowOrg(0, 0);
MetaWindowExt(gs.xWin, gs.yWin);
MetaBkMode(1 /* Transparent */);
/* Colors */
for (j = 1; j <= 4; j++)
for (i = 0; i < 16; i++) {
k = j <= 1 ? gi.nPenWid : 0;
MetaCreatePen(j <= 2 ? 0 : j-2 /* PS_SOLID; PS_DASH; PS_DOT */,
k, rgbbmp[i]);
}
for (i = 0; i < 16; i++) {
MetaCreateBrush(0 /* BS_SOLID */, rgbbmp[i]);
}
MetaCreateBrush(1 /* BS_NULL */, 0L);
/* Fonts */
if (gs.fFont) {
MetaCreateFont(5, 0, -8*gi.nScale, 2 /* Symbol Charset */);
MetaWord(WFromBB(1 /* Draft */, 1 | 0x10 /* Fixed | Roman */));
MetaLong(LFromBB('W', 'i', 'n', 'g'));
MetaLong(LFromBB('d', 'i', 'n', 'g'));
MetaWord(WFromBB('s', 0));
MetaCreateFont(8, 0, -6*gi.nScale, 0 /* Ansi Charset */);
MetaWord(WFromBB(0 /* Default */, 2 | 0x10 /* Variable | Roman */));
MetaLong(LFromBB('T', 'i', 'm', 'e'));
MetaLong(LFromBB('s', ' ', 'N', 'e'));
MetaLong(LFromBB('w', ' ', 'R', 'o'));
MetaLong(LFromBB('m', 'a', 'n', 0));
MetaCreateFont(6, 6*METAMUL, 10*METAMUL, 0 /* Ansi Charset */);
MetaWord(WFromBB(1 /* Draft */, 1 | 0x30 /* Fixed | Modern */));
MetaLong(LFromBB('C', 'o', 'u', 'r'));
MetaLong(LFromBB('i', 'e', 'r', ' '));
MetaLong(LFromBB('N', 'e', 'w', 0));
MetaCreateFont(8, 0, -11*gi.nScale, 0 /* Ansi Charset */);
MetaWord(WFromBB(0 /* Default */, 2 | 0 /* Variable | Don't Care */));
MetaLong(LFromBB('A', 's', 't', 'r'));
MetaLong(LFromBB('o', '-', 'S', 'e'));
MetaLong(LFromBB('m', 'i', 'B', 'o'));
MetaLong(LFromBB('l', 'd', 0, 0));
}
}
/* Output trailing records to indicate the end of the metafile and then */
/* actually write out the entire buffer to the specifed file. */
void WriteMeta(FILE *file)
{
word *w;
#if FALSE
int i;
for (i = 16*5+1+(gs.fFont>0)*4; i >= 0; i--) {
MetaDeleteObject(i);
}
#endif
MetaRestoreDc();
MetaRecord(3, 0); /* End record */
*(long *)(gi.bm + 22 + 6) =
((long)((lpbyte)gi.pwMetaCur - gi.bm) - 22) / 2;
for (w = (word *)gi.bm; w < gi.pwMetaCur; w++) {
PutWord(*w);
}
}
#endif /* META */
#ifdef WIRE
/*
******************************************************************************
** Daedalus Wireframe File Routines.
******************************************************************************
*/
/* Write the wireframe file in memory to a previously opened file in the */
/* Daedalus wireframe format. This usually consists of coordinates for each */
/* line segment, but can also include changes to the default color. */
void WriteWire(FILE *file)
{
word *pw = (word *)gi.bm;
int x1, y1, z1, x2, y2, z2, n;
if (file == NULL)
return;
fprintf(file, "DW#\n%d\n", gi.cWire);
while (pw < gi.pwWireCur) {
if (*pw != 32768) {
/* Output one line segment. */
x1 = (short)pw[0]; y1 = (short)pw[1]; z1 = (short)pw[2];
x2 = (short)pw[3]; y2 = (short)pw[4]; z2 = (short)pw[5];
fprintf(file, "%d %d %d %d %d %d\n", x1, y1, z1, x2, y2, z2);
pw += 6;
} else {
/* Output a color change. */
if (gs.fColor) {
n = pw[1];
if (n < cColor) {
if (n != kOrange)
fprintf(file, "%s\n", szColor[n]);
else
fprintf(file, "Maize\n");
} else {
if (gs.fInverse)
n = 255 - n;
fprintf(file, "GrayN %d\n", n);
}
}
pw += 2;
}
}
}
/* Add a single 16 bit number to the current wireframe file. */
void WireNum(int n)
{
char sz[cchSzDef];
if ((lpbyte)gi.pwWireCur - gi.bm >= gi.cbWire) {
sprintf(sz, "Wireframe would be more than %ld bytes.", gi.cbWire);
PrintError(sz);
Terminate(tcFatal);
}
*gi.pwWireCur = (word)n;
gi.pwWireCur++;
}
/* Add a solid line to current wireframe file, specified by its endpoints. */
void WireLine(int x1, int y1, int z1, int x2, int y2, int z2)
{
if (gi.kiInFile != gi.kiCur) {
gi.kiInFile = gi.kiCur;
WireNum(32768);
WireNum(gi.kiCur);
}
WireNum(x1); WireNum(y1); WireNum(z1);
WireNum(x2); WireNum(y2); WireNum(z2);
gi.cWire++;
}
/* Add an octahedron of a given radius to the current wireframe file. These */
/* shapes are used to mark the exact locations of planets in the scene. */
void WireOctahedron(int x, int y, int z, int r)
{
int rgx[4], rgy[4], i;
rgx[0] = rgx[3] = x-r; rgx[1] = rgx[2] = x+r;
rgy[0] = rgy[1] = y-r; rgy[2] = rgy[3] = y+r;
for (i = 0; i < 4; i++) {
WireLine(rgx[i], rgy[i], z, x, y, z-r);
WireLine(rgx[i], rgy[i], z, x, y, z+r);
WireLine(rgx[i], rgy[i], z, rgx[i+1 & 3], rgy[i+1 & 3], z);
}
}
/* Add a fixed star to the current wireframe file. */
void WireStar(int x, int y, int z, real mag)
{
int n;
n = 255 - (int)((mag + 1.46) / 7.0 * 224.0);
n = Min(n, 255); n = Max(n, 32);
DrawColor(n);
WireLine(x-1, y, z, x+1, y, z);
WireLine(x, y-1, z, x, y+1, z);
WireLine(x, y, z-1, x, y, z+1);
}
/* Given longitude and latitude values on a globe, return the 3D pixel */
/* coordinates corresponding to them. In other words, project the globe in */
/* the 3D environment, and return where our coordinates got projected to. */
/* Like FGlobeCalc() except for 3D wireframe format. */
void WireGlobeCalc(real x1, real y1, int *u, int *v, int *w, int rz, real deg)
{
real lonMC, latMC;
/* Compute coordinates for a general globe invoked with -XG switch. */
if (gi.nMode == gSphere) {
/* Chart sphere coordinates are relative to the local horizon. */
lonMC = Tropical(is.MC); latMC = 0.0;
EclToEqu(&lonMC, &latMC);
x1 = Mod(rDegMax - (x1 + lonMC) + rDegQuad);
y1 = rDegQuad - y1;
EquToLocal(&x1, &y1, rDegQuad - Lat);
y1 = rDegQuad - y1;
}
x1 = Mod(x1+deg); /* Shift by current globe rotation value. */
if (gs.rTilt != 0.0) {
/* Do another coordinate shift if the globe's equator is tilted any. */
y1 = rDegQuad - y1;
CoorXform(&x1, &y1, gs.rTilt);
x1 = Mod(x1); y1 = rDegQuad - y1;
}
*u = (int)((real)rz*RSinD(y1)*RSinD(x1)-rRound);
*v = (int)((real)rz*RSinD(y1)*RCosD(x1)-rRound);
*w = (int)((real)rz*RCosD(y1)-rRound);
}
/* Given longitude and latitude values, return the 3D pixel coordinates */
/* corresponding to them. Like FMapCalc() except for 3D wireframe format. */
void WireMapCalc(real x1, real y1, int *xp, int *yp, int *zp, flag fSky,
real lonMC, real rT, int rz, real deg)
{
if (!fSky)
x1 = lonMC - x1;
if (x1 < 0.0)
x1 += rDegMax;
if (x1 > rDegHalf)
x1 -= rDegMax;
x1 = Mod(rDegHalf - rT - x1);
y1 = rDegQuad - y1;
WireGlobeCalc(x1, y1, xp, yp, zp, rz, deg);
}
/* Draw a globe, for either the world or the constellations. We shift the */
/* chart by specified rotational and tilt values, and may plot on the */
/* chart each planet at its zenith position on Earth or location in */
/* constellations. Like DrawMap() except for 3D wireframe format. */
void WireDrawGlobe(flag fSky, real deg)
{
char *nam, *loc, *lin, chCmd;
int X[objMax], Y[objMax], Z[objMax], M[objMax], N[objMax], O[objMax],
rz, lon, lat, unit = 12*gi.nScale,
x, y, z, xold, yold, m, n, o, u, v, w, i, j, k, l, nScl = gi.nScale;
flag fNext = fTrue;
real planet1[objMax], planet2[objMax], x1, y1, rT;
#ifdef CONSTEL
CONST char *pch;
flag fBlank;
int isz = 0, nC, xT, yT, xDelta, yDelta, xLo, xHi, yLo, yHi;
#endif
#ifdef SWISS
real magS;
#endif
/* Set up some variables. */
rz = Min(gs.xWin/2, gs.yWin/2);
if (gi.nMode == gSphere)
rz -= 7*gi.nScale;
loop {
/* Get the next chunk of data to process. Get the starting position, */
/* map it to the screen, and set the drawing color appropriately. */
if (fNext) {
fNext = fFalse;
/* For constellations, get data for the next constellation shape. */
if (fSky) {
#ifdef CONSTEL
isz++;
if (isz > cCnstl)
break;
DrawColor(gi.nMode == gSphere ? kRainbowB[7] :
(gs.fAlt ? kMainB[7] : kRainbowB[6]));
pch = szDrawConstel[isz];
lon = nDegMax -
(((pch[2]-'0')*10+(pch[3]-'0'))*15+(pch[4]-'0')*10+(pch[5]-'0'));
lat = 90-((pch[6] == '-' ? -1 : 1)*((pch[7]-'0')*10+(pch[8]-'0')));
pch += 9;
xLo = xHi = xT = xold = x = lon;
yLo = yHi = yT = yold = y = lat;
nC = 0;
WireGlobeCalc((real)x, (real)y, &m, &n, &o, rz, rDegMax - deg);
k = l = fTrue;
#else
;
#endif
/* For world maps, get data for the next coastline piece. */
} else {
if (!FReadWorldData(&nam, &loc, &lin))
break;
i = nam[0]-'0';
DrawColor(gs.fAlt && !gs.fColorHouse ? gi.kiGray :
(i ? kRainbowB[i] : kMainB[7]));
lon = (loc[0] == '+' ? 1 : -1)*
((loc[1]-'0')*100 + (loc[2]-'0')*10 + (loc[3]-'0'));
lat = (loc[4] == '+' ? 1 : -1)*((loc[5]-'0')*10 + (loc[6]-'0'));
x = 180-lon;
y = 90-lat;
WireGlobeCalc((real)x, (real)y, &m, &n, &o, rz, deg);
k = l = fTrue;
}
}
/* Get the next unit from the string to draw on the screen as a line. */
if (fSky) {
/* For constellations we have a cache of how long we should keep */
/* going in the previous direction, as say "u5" for up five should */
/* move our pointer up five times without advancing string pointer. */
#ifdef CONSTEL
if (nC <= 0) {
if (!(chCmd = *pch)) {
fNext = fTrue;
if (gs.fText) {
/* If we've reached the end of current constellation, compute */
/* the center location in it based on lower and upper bounds */
/* we've maintained, and print the name of the constel there. */
xT = xLo + (xHi - xLo)*(szDrawConstel[isz][0]-'1')/8;
yT = yLo + (yHi - yLo)*(szDrawConstel[isz][1]-'1')/8;
if (xT < 0)
xT += nDegMax;
else if (xT > nDegMax)
xT -= nDegMax;
WireGlobeCalc((real)xT, (real)yT, &x, &y, &z, rz, deg);
DrawColor(gi.nMode == gSphere || gs.fAlt ? gi.kiGray : kMainB[5]);
gi.zDefault = z;
DrawSz(szCnstlAbbrev[isz], x, y, dtCent);
}
continue;
}
pch++;
/* Get the next direction and distance from constellation string. */
if (fBlank = (chCmd == 'b'))
chCmd = *pch++;
xDelta = yDelta = 0;
switch (chCmd) {
case 'u': yDelta = -1; break; /* Up */
case 'd': yDelta = 1; break; /* Down */
case 'l': xDelta = -1; break; /* Left */
case 'r': xDelta = 1; break; /* Right */
case 'U': yDelta = -1; nC = (yT-1)%10+1; break; /* Up until */
case 'D': yDelta = 1; nC = 10-yT%10; break; /* Down until */
case 'L': xDelta = -1; nC = (xT+599)%15+1; break; /* Left until */
case 'R': xDelta = 1; nC = 15-(xT+600)%15; break; /* Right until */
default: PrintError("Bad draw."); /* Shouldn't happen. */
}
if (chCmd >= 'a')
nC = NFromPch(&pch); /* Figure out how far to draw. */
}
nC--;
xT += xDelta; x += xDelta;
yT += yDelta; y += yDelta;
if (fBlank) {
xold = x; yold = y; /* We occasionally want to move the pointer */
l = fFalse; /* without drawing the line on the screen. */
continue;
}
if (xT < xLo) /* Maintain our bounding rectangle for this */
xLo = xT; /* constellation if we crossed over it any. */
else if (xT > xHi)
xHi = xT;
if (yT < yLo)
yLo = yT;
else if (yT > yHi)
yHi = yT;
#else
;
#endif
} else {
/* Get the next unit from the much simpler world map strings. */
if (!(chCmd = *lin)) {
fNext = fTrue;
continue;
}
lin++;
/* Each unit is exactly one character in the coastline string. */
if (chCmd == 'L' || chCmd == 'H' || chCmd == 'G')
x--;
else if (chCmd == 'R' || chCmd == 'E' || chCmd == 'F')
x++;
if (chCmd == 'U' || chCmd == 'H' || chCmd == 'E')
y--;
else if (chCmd == 'D' || chCmd == 'G' || chCmd == 'F')
y++;