Exemplo n.º 1
0
        private int printDiary(DateTime when, System.Drawing.Printing.PrintPageEventArgs e, int curpg, int pgtotal)
        {
            PlanetaryHours pHours   = new PlanetaryHours(when, where, conf);
            Font           hdfont   = new Font(Font.Name, 15.0F, FontStyle.Bold);
            Font           sfont    = new Font(Font.Name, 11.0F);
            Font           hrfont   = new Font(Font.Name, 10.0F);
            Font           hrhdfont = new Font(Font.Name, 11.0F, FontStyle.Bold);

            float x, y;  bool hdrPrinted = false;

            if (printHr == 0)
            {
                displayHr  = 0;
                hdrPrinted = true;
                float picx = e.MarginBounds.Left;
                Image im   = Image.FromStream(conf.Fx.GlyphGif(pHours.EnglishDay()));
                x = picx + im.Width + 11;
                y = e.MarginBounds.Top;

                e.Graphics.DrawString(pHours.DayString(), hdfont, Brushes.Black, x, y, StringFormat.GenericDefault);
                y += e.Graphics.MeasureString(pHours.DayString(), hdfont, new PointF(x, y), StringFormat.GenericDefault).Height;

                string whenwhere = when.ToLongDateString() + " - " + where.Name;
                e.Graphics.DrawString(whenwhere, sfont, Brushes.Black, x + 1, y, StringFormat.GenericDefault);
                y += e.Graphics.MeasureString(whenwhere, sfont, new PointF(x, y), StringFormat.GenericDefault).Height + 2;

                string risetext, settext;
                if (!pHours.RS.SunRises)
                {
                    risetext = String.Format(conf.Res.GetString("Calendar.NoSunRiseSet"),
                                             conf.Res.GetString("Rise"), when.ToShortDateString(), where.Name);
                }
                else
                {
                    risetext = String.Format(conf.Res.GetString("Calendar.labelSunrise"),
                                             conf.FormatTime(pHours.Hours[0].StartTime),
                                             where.UseSystemTime ? "" : (" " + where.ZoneAbbreviation));
                }
                if (!pHours.RS.SunSets)
                {
                    settext = String.Format(conf.Res.GetString("Calendar.NoSunRiseSet"),
                                            conf.Res.GetString("Set"), when.ToShortDateString(), where.Name);
                }
                else
                {
                    settext = String.Format(conf.Res.GetString("Calendar.labelSunset"),
                                            conf.FormatTime(pHours.Hours[12].StartTime),
                                            where.UseSystemTime ? "": (" " + where.ZoneAbbreviation));
                }

                string riseset = risetext + " - " + settext;
                e.Graphics.DrawString(riseset, sfont, Brushes.Black, x + 1, y, StringFormat.GenericDefault);
                y += e.Graphics.MeasureString(riseset, sfont, new PointF(x, y), StringFormat.GenericDefault).Height + 2;

                float picy = e.MarginBounds.Top + (((y - e.MarginBounds.Top) - im.Height) / 2);
                if (y < (e.MarginBounds.Top + im.Height))
                {
                    y = picy + im.Height + 5;
                }

                e.Graphics.DrawImage(im, picx, picy);

                x = e.MarginBounds.Left;  y += 11;
                e.Graphics.DrawLine(Pens.Gray, x, y, x + e.MarginBounds.Width, y);
                y += 33;
            }
            else
            {
                x = e.MarginBounds.Left;
                y = e.MarginBounds.Top;
                string str = String.Format("{0} - {1} - {2}", pHours.DayString(), when.ToLongDateString(), where.Name);
                e.Graphics.DrawString(str, hrhdfont, Brushes.Black, x, y, StringFormat.GenericDefault);
                y += e.Graphics.MeasureString(str, hrhdfont, new PointF(x, y), StringFormat.GenericDefault).Height + 22;
            }

            float ght = hrfont.Height * 4;

            if (!hdrPrinted)
            {
                ght += hrfont.Height / 2;
            }
            TimeSpan os = new TimeSpan(0, 0, 1);

            while ((y + ght) <= e.MarginBounds.Bottom && printHr != 24)
            {
                if (inBounds(pHours.Hours[printHr].StartTime))
                {
                    displayHr++;
                    PlanetaryHours.Planet pl = pHours.Hours[printHr].Hour;
                    string displaystr        = pHours.HourString(pl) + " (";
                    if (printHr == 0)
                    {
                        displaystr += conf.GetString("Sunrise") + ", ";
                    }
                    else if (printHr == 12)
                    {
                        displaystr += conf.GetString("Sunset") + ", ";
                    }
                    displaystr += conf.FormatTime(pHours.Hours[printHr].StartTime) + " - " +
                                  conf.FormatTime(pHours.Hours[printHr + 1].StartTime.Subtract(os)) + ")";
                    e.Graphics.DrawString(displaystr, hrfont, Brushes.Black, x, y, StringFormat.GenericDefault);
                    float incr = e.Graphics.MeasureString(pHours.PlanetName(pl), hrfont, new PointF(x, y), StringFormat.GenericDefault).Height;
                    y += (incr * 2);
                    if (conf.PrintGlyphs)
                    {
                        RectangleF rf = new RectangleF(x, y + 1, 16, 16);
                        Image      im = Image.FromStream(conf.Fx.GlyphIconAsStream(Color.Black, pHours.EnglishName(pl)));
                        e.Graphics.DrawImage(im, rf);
                        e.Graphics.DrawLine(Pens.Gray, x + im.Width + 7, y, x + e.MarginBounds.Width, y);
                        y += incr;
                        e.Graphics.DrawLine(Pens.Gray, x + im.Width + 7, y, x + e.MarginBounds.Width, y);
                        y += incr;
                    }
                    else
                    {
                        e.Graphics.DrawLine(Pens.Gray, x, y, x + e.MarginBounds.Width, y);
                        y += incr;
                        e.Graphics.DrawLine(Pens.Gray, x, y, x + e.MarginBounds.Width, y);
                        y += incr;
                    }
                    // The first page has a long header; if not printing the first page, compensate for the absense of this header
                    if (hdrPrinted)
                    {
                        y += incr / 2;
                    }
                }
                printHr++;
            }

            string ver = Config.FormatVersion();
            SizeF  vsz = e.Graphics.MeasureString(ver, hrfont, e.MarginBounds.Width, StringFormat.GenericDefault);

            e.Graphics.DrawString(ver, hrfont, Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Bottom - vsz.Height,
                                  StringFormat.GenericDefault);

            // Try to calculate the number of pages.  A better way to do this would instead be, before printing, creating an array of Graphics surfaces
            // with each page.  When the page number is known, go back and write the "Page __ of __" to each surface.  Then, BitBlt() the appropriate
            // Graphics surface to e.Graphics.  I don't envision this algorithm will be innaccurate, but I think it might be possible, especially with the "wrong"
            // size paper.
            int pgs, hrs = 0;

            foreach (PlanetaryHours.PlanetaryHour ph in pHours.Hours)
            {
                if (inBounds(ph.StartTime))
                {
                    hrs++;
                }
            }
            if (pgtotal == 0)
            {
                if (printHr == 24)
                {
                    pgs = pageNo;
                }
                else if (radioButtonPrintAll.Checked)
                {
                    pgs = 24 / (printHr / pageNo);
                    if ((printHr * pgs) < 24)
                    {
                        pgs++;
                    }
                }
                else
                {
                    if (hrs > 9)
                    {
                        pgs = (hrs - 9) / 11;
                        if ((displayHr * pgs) + 9 < hrs)
                        {
                            pgs++;
                        }
                        pgs++;
                    }
                    else
                    {
                        pgs = 1;
                    }
                }
            }
            else
            {
                pgs = pgtotal;
            }
            string pg   = String.Format(conf.GetString("Print.PageOf"), pageNo, pgs);
            SizeF  tdsz = e.Graphics.MeasureString(pg, hrfont, e.MarginBounds.Width, StringFormat.GenericDefault);

            e.Graphics.DrawString(pg, hrfont, Brushes.Black, e.MarginBounds.Right - tdsz.Width, e.MarginBounds.Bottom - tdsz.Height, StringFormat.GenericDefault);

            if (pageNo != pageTotal)
            {
                e.HasMorePages = true;
            }

            if (printHr == 24 || hrs == displayHr)
            {
                printHr = 0;
                dayNo++;
            }

            return(pgs);
        }
Exemplo n.º 2
0
        private void printNormal(DateTime when, System.Drawing.Printing.PrintPageEventArgs e, int curpg, int pgtotal)
        {
            PlanetaryHours pHours   = new PlanetaryHours(when, where, conf);
            Font           hdfont   = new Font(Font.Name, 15.0F, FontStyle.Bold);
            Font           sfont    = new Font(Font.Name, 11.0F);
            Font           hrfont   = new Font(Font.Name, 10.0F);
            Font           hrhdfont = new Font(Font.Name, 11.0F, FontStyle.Bold);

            float picx = e.MarginBounds.Left;
            Image dyim = Image.FromStream(conf.Fx.GlyphGif(pHours.EnglishDay()));
            float x    = picx + dyim.Width + 11;
            float y    = e.MarginBounds.Top;

            // Previously we used no StringFormat in DrawString and MeasureString, which made text (mainly at the lower-left margin) not formatted correctly.
            // Thanks to a microsoft.public.dotnet.languages.csharp posting by Ron Allen, we now use StringFormat.GenericDefault
            e.Graphics.DrawString(pHours.DayString(), hdfont, Brushes.Black, x, y, StringFormat.GenericDefault);
            y += e.Graphics.MeasureString(pHours.DayString(), hdfont, new PointF(x, y), StringFormat.GenericDefault).Height;

            string whenwhere = when.ToLongDateString() + " - " + where.Name;

            e.Graphics.DrawString(whenwhere, sfont, Brushes.Black, x + 1, y, StringFormat.GenericDefault);
            y += e.Graphics.MeasureString(whenwhere, sfont, new PointF(x, y), StringFormat.GenericDefault).Height + 2;

            string risetext, settext;

            if (!pHours.RS.SunRises)            //(!pHours.RiseSet.SunRises)
            {
                risetext = String.Format(conf.Res.GetString("Calendar.NoSunRiseSet"),
                                         conf.Res.GetString("Rise"), when.ToShortDateString(), where.Name);
            }
            else
            {
                risetext = String.Format(conf.Res.GetString("Calendar.labelSunrise"),
                                         conf.FormatTime(pHours.Hours[0].StartTime),
                                         where.UseSystemTime ? "" : (" " + where.ZoneAbbreviation));
            }
            if (!pHours.RS.SunSets)
            {
                settext = String.Format(conf.Res.GetString("Calendar.NoSunRiseSet"),
                                        conf.Res.GetString("Set"), when.ToShortDateString(), where.Name);
            }
            else
            {
                settext = String.Format(conf.Res.GetString("Calendar.labelSunset"),
                                        conf.FormatTime(pHours.Hours[12].StartTime),
                                        where.UseSystemTime ? "": (" " + where.ZoneAbbreviation));
            }

            string riseset = risetext + " - " + settext;

            e.Graphics.DrawString(riseset, sfont, Brushes.Black, x + 1, y, StringFormat.GenericDefault);
            y += e.Graphics.MeasureString(riseset, sfont, new PointF(x, y), StringFormat.GenericDefault).Height + 2;

            float picy = e.MarginBounds.Top + (((y - e.MarginBounds.Top) - dyim.Height) / 2);

            if (y < (e.MarginBounds.Top + dyim.Height))
            {
                y = picy + dyim.Height + 5;
            }

            e.Graphics.DrawImage(dyim, picx, picy);

            x = e.MarginBounds.Left;  y += 11;
            e.Graphics.DrawLine(Pens.Gray, x, y, x + e.MarginBounds.Width, y);
            y += 22;

            e.Graphics.DrawString(conf.Res.GetString("Calendar.DayHours"), hrhdfont, Brushes.Black, x, y, StringFormat.GenericDefault);
            e.Graphics.DrawString(conf.Res.GetString("Calendar.NightHours"), hrhdfont, Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width / 2), y, StringFormat.GenericDefault);
            y += e.Graphics.MeasureString(conf.Res.GetString("Calendar.DayHours"), hrhdfont, new PointF(x, y), StringFormat.GenericDefault).Height + 9;
            float savey = y;

            for (int hr = 0; hr < 24; hr++)
            {
                if (hr == 12)
                {
                    y = savey;
                    x = e.MarginBounds.Left + (e.MarginBounds.Width / 2);
                }
                PlanetaryHours.Planet pl = pHours.Hours[hr].Hour;
                RectangleF            rf = new RectangleF(x, y, 16, 16);
                Image im;
                if (conf.PrintGlyphs)
                {
                    im = Image.FromStream(conf.Fx.GlyphIconAsStream(Color.Black, pHours.EnglishName(pl)));
                    e.Graphics.DrawImage(im, rf);
                }
                else
                {
                    im = new Bitmap(1, 1);
                }
                e.Graphics.DrawString(pHours.PlanetName(pl), hrfont, Brushes.Black, x + (conf.PrintGlyphs ? im.Width + 5 : 0), y, StringFormat.GenericDefault);
                e.Graphics.DrawString(conf.FormatTime(pHours.Hours[hr].StartTime), hrfont, Brushes.Black, x + 112, y, StringFormat.GenericDefault);
                if (conf.PrintGlyphs)
                {
                    y += im.Height + 5;
                }
                else
                {
                    y += e.Graphics.MeasureString(pHours.PlanetName(pl), hrfont, new PointF(x, y), StringFormat.GenericDefault).Height;
                }
            }

            string ver = Config.FormatVersion();
            SizeF  vsz = e.Graphics.MeasureString(ver, hrfont, e.MarginBounds.Width, StringFormat.GenericDefault);

            e.Graphics.DrawString(ver, hrfont, Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Bottom - vsz.Height,
                                  StringFormat.GenericDefault);
            string pg   = String.Format(conf.GetString("Print.PageOf"), curpg, pgtotal);
            SizeF  tdsz = e.Graphics.MeasureString(pg, hrfont, e.MarginBounds.Width, StringFormat.GenericDefault);

            e.Graphics.DrawString(pg, hrfont, Brushes.Black, e.MarginBounds.Right - tdsz.Width, e.MarginBounds.Bottom - tdsz.Height, StringFormat.GenericDefault);

            if (curpg != pgtotal)
            {
                e.HasMorePages = true;
            }
            dayNo++;
        }