-
Notifications
You must be signed in to change notification settings - Fork 7
/
PanchangaPrintDocument.cs
411 lines (347 loc) · 13 KB
/
PanchangaPrintDocument.cs
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
/******
Copyright (C) 2005 Ajit Krishnan (http://www.mudgala.com)
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,
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******/
using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
namespace mhora
{
/// <summary>
/// Summary description for PanchangaPrintDocument.
/// </summary>
public class PanchangaPrintDocument : PrintDocument
{
private PanchangaGlobalMoments globals = null;
private ArrayList locals = null;
private Horoscope h = null;
private PanchangaControl.UserOptions opts = null;
public bool bPrintPanchanga = true;
public bool bPrintLagna = false;
public PanchangaPrintDocument(
PanchangaControl.UserOptions _opts,
Horoscope _h, PanchangaGlobalMoments _globals, ArrayList _locals)
{
h = _h;
opts = _opts;
globals = _globals;
locals = _locals;
if (locals.Count > 0 &&
((PanchangaLocalMoments)locals[0]).lagnas_ut.Count > 1)
bPrintLagna = true;
}
Font f = MhoraGlobalOptions.Instance.GeneralFont;
Font f_u = new Font(MhoraGlobalOptions.Instance.GeneralFont.FontFamily,
MhoraGlobalOptions.Instance.GeneralFont.SizeInPoints, FontStyle.Underline);
int local_index = 0;
protected override void OnBeginPrint(PrintEventArgs e)
{
base.OnBeginPrint (e);
divisional_chart_size = 250;
time_width = 43;
day_width = 65;
wday_width = 25;
sunrise_width = time_width;
sunset_width = time_width;
tithi_name_width = 75;
tithi_time_width = time_width;
karana_name_width = 85;
karana_time_width = time_width;
nak_name_width = 70;
nak_time_width = time_width;
sm_name_width = 80;
sm_time_width = time_width;
rahu_kala_width = time_width * 2 + 10;
day_offset = 0;
wday_offset = day_width;
sunrise_offset = wday_offset + wday_width;
sunset_offset = sunrise_offset + sunrise_width;
nak_name_offset = sunset_offset + sunset_width;
nak_time_offset = nak_name_offset + nak_name_width;
tithi_name_offset = nak_time_offset + nak_time_width;
tithi_time_offset = tithi_name_offset + tithi_name_width;
karana_name_1_offset = tithi_time_offset + tithi_time_width;
karana_time_1_offset = karana_name_1_offset + karana_name_width;
karana_name_2_offset = karana_time_1_offset + karana_time_width;
karana_time_2_offset = karana_name_2_offset + karana_name_width;
sm_name_offset = karana_time_2_offset + karana_time_width;
sm_time_offset = sm_name_offset + sm_name_width;
rahu_kala_offset = sm_time_offset + sm_time_width;
}
protected override void OnEndPrint(PrintEventArgs e)
{
base.OnEndPrint (e);
}
private void checkForMorePages (PrintPageEventArgs e)
{
e.HasMorePages = true;
if (this.bPrintLagna == false &&
this.bPrintPanchanga == false)
e.HasMorePages = false;
}
protected override void OnPrintPage(PrintPageEventArgs e)
{
if (this.bPrintPanchanga)
{
PrintFirstPage(e);
}
else if (this.bPrintLagna)
{
PrintLagna(e);
}
this.checkForMorePages(e);
}
int margin_offset = 30;
int header_offset = 30;
Brush b = Brushes.Black;
Pen p = Pens.Black;
int time_width;
int day_offset;
int day_width;
int wday_offset;
int wday_width;
int sunrise_offset;
int sunrise_width;
int sunset_offset;
int sunset_width;
int tithi_name_offset;
int tithi_name_width;
int tithi_time_offset;
int tithi_time_width;
int karana_name_1_offset;
int karana_name_width;
int karana_time_1_offset;
int karana_time_width;
int karana_name_2_offset;
int karana_time_2_offset;
int nak_name_offset;
int nak_name_width;
int nak_time_offset;
int nak_time_width;
int sm_name_offset;
int sm_name_width;
int sm_time_offset;
int sm_time_width;
int rahu_kala_offset;
int rahu_kala_width;
int divisional_chart_size;
private Moment utToMoment (double found_ut)
{
// turn into horoscope
int year=0, month=0, day=0;
double hour =0;
found_ut += (h.info.tz.toDouble() / 24.0);
sweph.swe_revjul(found_ut, ref year, ref month, ref day, ref hour);
Moment m = new Moment(year, month, day, hour);
return m;
}
private string utTimeToString (double ut_event, double ut_sr, double sunrise)
{
Moment m = this.utToMoment(ut_event);
HMSInfo hms = new HMSInfo(m.time);
if (ut_event >= (ut_sr - (sunrise/24.0) + 1.0))
{
if (false == opts.LargeHours)
return string.Format ("*{0}:{1:00}", hms.degree, hms.minute);
else
return string.Format ("{0:00}:{1:00}", hms.degree+24, hms.minute);
}
return string.Format ("{0:00}:{1:00}", hms.degree, hms.minute);
}
private void PrintLagna (PrintPageEventArgs e)
{
e.HasMorePages = true;
Graphics g = e.Graphics;
g.ResetTransform();
g.TranslateTransform(100, header_offset);
for (int j=1; j<=12; j++)
{
ZodiacHouse zh = new ZodiacHouse((ZodiacHouse.Name)j);
g.DrawString(zh.value.ToString(), f, b,
day_offset+100+(int)zh.value*time_width, 0);
}
g.TranslateTransform(0, f.Height);
int i = local_index;
while (i < locals.Count)
{
PanchangaLocalMoments local = (PanchangaLocalMoments)locals[i];
Moment m_sunrise = new Moment(local.sunrise_ut, h);
g.DrawString(m_sunrise.ToString(), f, b, day_offset, 0);
for (int j=0; j<local.lagnas_ut.Count; j++)
{
PanchangaMomentInfo pmi = (PanchangaMomentInfo)local.lagnas_ut[j];
//Moment m_lagna = new Moment(pmi.ut, h);
ZodiacHouse zh = new ZodiacHouse((ZodiacHouse.Name)pmi.info);
zh = zh.add(12);
Font _f = f;
if (local.lagna_zh == zh.value)
_f = this.f_u;
g.DrawString(
this.utTimeToString(pmi.ut, local.sunrise_ut, local.sunrise),
_f, b,
day_offset + 100 + (int)zh.value * time_width, 0);
}
local_index = ++i;
g.TranslateTransform(0, f.Height);
if (g.Transform.OffsetY > e.PageBounds.Height - this.header_offset)
return;
}
this.bPrintLagna = false;
e.HasMorePages = false;
}
private void PrintTitle (Graphics g, int left, int right, string s)
{
SizeF sz = g.MeasureString(s, f);
g.DrawString(s, f, b, left+(((right-left)-sz.Width)/2), 0);
}
private void PrintFirstPage (PrintPageEventArgs e)
{
e.HasMorePages = true;
Graphics g = e.Graphics;
g.ResetTransform();
g.TranslateTransform(margin_offset, header_offset);
PrintTitle(g, 0, this.wday_offset+this.wday_width, "Date/Day");
PrintTitle(g, this.sunrise_offset, this.sunset_offset+this.sunset_width, "Sunrise/set");
PrintTitle(g, this.nak_name_offset, this.nak_time_offset+this.nak_time_width, "Nakshatra");
PrintTitle(g, this.tithi_name_offset, this.tithi_time_offset+this.tithi_time_width, "Tithi");
PrintTitle(g, this.karana_name_1_offset, this.karana_time_2_offset+this.karana_time_width, "Karana");
PrintTitle(g, this.sm_name_offset, this.sm_time_offset+this.sm_time_width, "SM-Yoga");
g.TranslateTransform(0, (float)(f.Height*1.5));
int iStart = local_index;
int i = local_index;
while (i < locals.Count)
{
int numLines = 1;
PanchangaLocalMoments local = (PanchangaLocalMoments)locals[i];
Moment m_sunrise = new Moment(local.sunrise_ut, h);
Moment m_sunset = new Moment(0, 0, 0, local.sunset);
g.DrawString(m_sunrise.ToShortDateString(), f, b, day_offset, 0);
g.DrawString(Basics.weekdayToShortString(local.wday), f, b, wday_offset, 0);
if (opts.ShowSunriset)
{
g.DrawString(m_sunrise.ToTimeString(), f, b, sunrise_offset, 0);
g.DrawString(m_sunset.ToTimeString(), f, b, sunset_offset, 0);
}
int numTithis = local.tithi_index_end - local.tithi_index_start;
int numNaks = local.nakshatra_index_end - local.nakshatra_index_start;
int numSMYogas = local.smyoga_index_end - local.smyoga_index_start;
int numKaranas = local.karana_index_end - local.karana_index_start;
if (opts.CalcTithiCusps)
{
numLines = Math.Max(numLines, numTithis);
for (int j = 0; j < numTithis; j++)
{
PanchangaMomentInfo pmi = (PanchangaMomentInfo)globals.tithis_ut[local.tithi_index_start+1+j];
Tithi t = new Tithi((Tithi.Name)pmi.info);
Moment mTithi = new Moment(pmi.ut, h);
g.DrawString(t.ToUnqualifiedString(), f, b, tithi_name_offset, j*f.Height);
g.DrawString(this.utTimeToString(pmi.ut, local.sunrise_ut, local.sunrise),
f, b, tithi_time_offset, j * f.Height);
}
}
if (opts.CalcKaranaCusps)
{
numLines = Math.Max(numLines, (int)Math.Ceiling(numKaranas/2.0));
for (int j = 0; j < numKaranas; j++)
{
PanchangaMomentInfo pmi = (PanchangaMomentInfo)globals.karanas_ut[local.karana_index_start+1+j];
Karana k = new Karana((Karana.Name)pmi.info);
Moment mKarana = new Moment(pmi.ut, h);
int jRow = (int)Math.Floor((decimal)j/2);
int name_offset = karana_name_1_offset;
int time_offset = karana_time_1_offset;
if (j%2 == 1)
{
name_offset = karana_name_2_offset;
time_offset = karana_time_2_offset;
}
g.DrawString(k.value.ToString(), f, b, name_offset, jRow*f.Height);
g.DrawString(this.utTimeToString(pmi.ut, local.sunrise_ut, local.sunrise),
f, b, time_offset, jRow * f.Height);
}
}
if (opts.CalcNakCusps)
{
numLines = Math.Max(numLines, numNaks);
for (int j=0; j< numNaks; j++)
{
PanchangaMomentInfo pmi = (PanchangaMomentInfo)globals.nakshatras_ut[local.nakshatra_index_start+1+j];
Nakshatra n = new Nakshatra((Nakshatra.Name)pmi.info);
Moment mNak = new Moment(pmi.ut, h);
g.DrawString(n.ToString(), f, b, nak_name_offset, j*f.Height);
g.DrawString(this.utTimeToString(pmi.ut, local.sunrise_ut, local.sunrise),
f, b, nak_time_offset, j*f.Height);
}
}
if (opts.CalcSMYogaCusps)
{
numLines = Math.Max(numLines, numSMYogas);
for (int j=0; j<numSMYogas; j++)
{
PanchangaMomentInfo pmi = (PanchangaMomentInfo)globals.smyogas_ut[local.smyoga_index_start+1+j];
SunMoonYoga sm = new SunMoonYoga((SunMoonYoga.Name)pmi.info);
Moment mSMYoga = new Moment(pmi.ut, h);
g.DrawString(sm.value.ToString(), f, b, sm_name_offset, j*f.Height);
g.DrawString(this.utTimeToString(pmi.ut, local.sunrise_ut, local.sunrise),
f, b, sm_time_offset, j*f.Height);
}
}
#if DND
string s_rahu_kala = string.Format("{0} - {1}",
this.utTimeToString(local.kalas_ut[local.rahu_kala_index], local.sunrise_ut, local.sunrise),
this.utTimeToString(local.kalas_ut[local.rahu_kala_index+1], local.sunrise_ut, local.sunrise));
g.DrawString(s_rahu_kala, f, b, rahu_kala_offset, 0);
#endif
g.TranslateTransform(0, f.Height * numLines);
local_index = ++i;
if (g.Transform.OffsetY > e.PageBounds.Height - this.header_offset-divisional_chart_size)
goto first_done;
}
this.bPrintPanchanga = false;
this.local_index = 0;
first_done:
float offsetY = g.Transform.OffsetY;
float offsetX = margin_offset+sm_time_offset+sm_time_width;
Moment mCurr = new Moment(((PanchangaLocalMoments)locals[iStart]).sunrise_ut, h);
HoraInfo hiCurr = new HoraInfo(mCurr, h.info.lat, h.info.lon, h.info.tz);
Horoscope hCurr = new Horoscope(hiCurr, h.options);
DivisionalChart dc = new DivisionalChart(hCurr);
dc.PrintMode = true;
dc.options.ViewStyle = DivisionalChart.UserOptions.EViewStyle.Panchanga;
dc.SetOptions(dc.options);
dc.DrawChart(g, divisional_chart_size, divisional_chart_size);
g.ResetTransform();
// horizontal top & bottom
g.DrawLine(p, margin_offset-5, header_offset-5, margin_offset+sm_time_offset+sm_time_width+5, header_offset-5);
g.DrawLine(p, margin_offset-5, header_offset-5+f.Height*(float)1.5, margin_offset+sm_time_offset+sm_time_width+5, header_offset-5+f.Height*(float)1.5);
g.DrawLine(p, margin_offset-5, offsetY+5, offsetX+5, offsetY+5);
// vertical left and right
g.DrawLine(p, margin_offset-5, header_offset-5, margin_offset-5, offsetY+5);
g.DrawLine(p, offsetX+5, header_offset-5, offsetX+5, offsetY+5);
g.DrawLine(p,
margin_offset+sunset_offset+sunset_width-2, header_offset-5,
margin_offset+sunset_offset+sunset_width-2, offsetY+5);
g.DrawLine(p,
margin_offset+tithi_time_offset+tithi_time_width-2, header_offset-5,
margin_offset+tithi_time_offset+tithi_time_width-2, offsetY+5);
g.DrawLine(p,
margin_offset+nak_time_offset+nak_time_width-2, header_offset-5,
margin_offset+nak_time_offset+nak_time_width-2, offsetY+5);
g.DrawLine(p,
margin_offset+karana_time_2_offset+karana_time_width-2, header_offset-5,
margin_offset+karana_time_2_offset+karana_time_width-2, offsetY+5);
}
}
}