コード例 #1
1
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      this.dt = DateTime.Now;

      XPen   pen   = new XPen(XColors.DarkBlue, 5);
      XBrush brush = new XSolidBrush(properties.Brush2.Brush);

      InitializeCoordinates(gfx);
      DrawFace(gfx, pen, brush);
      DrawHourHand(gfx, pen, brush);
      DrawMinuteHand(gfx, pen, brush);
      DrawSecondHand(gfx, new XPen(XColors.Red, 7));
    }
コード例 #2
0
ファイル: Acro8Bug.cs プロジェクト: DavidS/MigraDoc
    public override void RenderPage(XGraphics gfx)
    {
      //base.RenderPage(gfx);

      XFont font1 = new XFont("Arial", 9);
      XFont font2 = new XFont("Arial", 9, XFontStyle.Italic);
      XFont font3 = new XFont("Arial", 9, XFontStyle.Bold);
      XSolidBrush brush = new XSolidBrush(XColors.Black);

      gfx.DrawString("Page 5", font1, brush, 100, 100);
      gfx.DrawString("Water Sports You've Done continued", font2, brush, 100, 200);
      gfx.DrawString("Rowing", font1, brush, 100, 250);
      gfx.DrawString("Snorkeling", font1, brush, 100, 300);
      gfx.DrawString("WINTER SPORTS, SKIING, SKIING IN THE US", font3, XBrushes.Red, 100, 320);

      gfx.DrawLine(XPens.Red, 100, 100, 200, 200);

      gfx.DrawString("Resorts You've Skied in Vermont", font3, brush, 100, 400);
      gfx.DrawString("Haystack", font1, brush, 100, 420);

//      string text = "TgfÄÖÜWi9";
//      if (this.properties.Font1.Text != "")
//        text = this.properties.Font1.Text;
//      float x = 100, y = 300;
//      string familyName = properties.Font1.FamilyName;
//      XFontStyle style = this.properties.Font1.Style;
//      float emSize = this.properties.Font1.Size;
//      XFont font = CreateFont(familyName, emSize, style);
//      font = this.properties.Font1.Font;
//      XSize size = gfx.MeasureString(text, font);

//      double lineSpace = font.GetHeight(gfx);
//      int cellSpace   = font.FontFamily.GetLineSpacing(style);
//      int cellAscent  = font.FontFamily.GetCellAscent(style);
//      int cellDescent = font.FontFamily.GetCellDescent(style);
//      int cellLeading = cellSpace - cellAscent - cellDescent;

//      double ascent  = lineSpace * cellAscent / cellSpace;
//      gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent);

//      double descent = lineSpace * cellDescent / cellSpace;
//      gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent);

//      double leading = lineSpace * cellLeading / cellSpace;
//      gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading);

//      //gfx.DrawRectangle(this.properties.Brush1.Brush, x, y - size.Height, size.Width, size.Height);
//      //gfx.DrawLine(this.properties.Pen2.Pen, x, y, x + size.Width, y);
//      //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200);

//#if true_
//      XPdfFontOptions pdfOptions = new XPdfFontOptions(false, true);
//      font = new XFont("Tahoma", 8, XFontStyle.Regular, pdfOptions);
//      text = "Hallo";
//      text = chinese;
//#endif
//      gfx.DrawString(text, font, this.properties.Font1.Brush, x, y);
//      gfx.DrawLine(XPens.Red, 0, 0, 100, 100);
//      gfx.DrawString(text, font, this.properties.Font1.Brush, x, y + 20);
    }
コード例 #3
0
    internal override void InitRendering(BarCodeRenderInfo info)
    {
      base.InitRendering(info);
      CalcThinBarWidth(info);
      info.BarHeight = Size.Height;
      // HACK in ThickThinBarCode
      if (this.textLocation != TextLocation.None)
        info.BarHeight *= 4.0 / 5;

#if DEBUG_
      XColor back = XColors.LightSalmon;
      back.A = 0.3;
      XSolidBrush brush = new XSolidBrush(back);
      info.Gfx.DrawRectangle(brush, new XRect(info.Center - this.size / 2, this.size));
#endif
      switch (this.direction)
      {
        case CodeDirection.RightToLeft:
          info.Gfx.RotateAtTransform(180, info.Position);
          break;

        case CodeDirection.TopToBottom:
          info.Gfx.RotateAtTransform(90, info.Position);
          break;

        case CodeDirection.BottomToTop:
          info.Gfx.RotateAtTransform(-90, info.Position);
          break;
      }
    }
コード例 #4
0
ファイル: Card.cs プロジェクト: jeffreyabecker/CahGen
        public virtual void Render(XRect rect, XGraphics gfx, string fontName)
        {
            //gfx.DrawRectangle(XBrushes.Red, rect);
            var font = new XFont(fontName, FontSize, XFontStyle.Regular);
            var brush = new XSolidBrush(ForegroundColor);
            var textFormatter = new XTextFormatter(gfx);
            textFormatter.Alignment = XParagraphAlignment.Left;

            textFormatter.DrawString(Text, font, brush, rect);
        }
コード例 #5
0
ファイル: DoubleBar.cs プロジェクト: Nodgez/PDFReporter
        public void Draw(XPoint basePoint, XRect baseRect, XImage img)
        {
            XFont headerFont = new XFont("Arial", 16);
            XFont subfont = new XFont("Arial", 10);
            char degree = Convert.ToChar('\u00b0');
            gfx.DrawString(parameterLeft.Name.Substring(5, parameterLeft.Name.Length - 5), headerFont, XBrushes.Black, basePoint, XStringFormats.Center);
            gfx.DrawString(parameterLeft.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(-15, baseRect.Height * 0.05),XStringFormats.Center);
            gfx.DrawString(parameterRight.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(20, baseRect.Height * 0.05), XStringFormats.Center);

            XBrush brush = XBrushes.Black;

            brush = DrawingUtil.Instance.ChooseBrushColor(parameterLeft.LSI, 49, 74);

            XRect r = new XRect(basePoint + new XPoint(-baseRect.Width * 0.05, baseRect.Height * 0.075),
                new XSize(baseRect.Width * 0.1, baseRect.Height * 0.075));

            DrawingUtil.DrawOutlineRect(r, gfx, new XSize(10, 10));

            gfx.DrawRoundedRectangle(brush, r, new XSize(10,10));
            gfx.DrawString(parameterLeft.LSI.ToString("0") + "%",
                subfont,
                XBrushes.Black,
                basePoint + new XPoint(baseRect.Width * -0.025, baseRect.Height * 0.125));

            XSolidBrush blue = new XSolidBrush(XColor.FromArgb(127, 0, 0, 255));
            XSolidBrush yellow = new XSolidBrush(XColor.FromArgb(127, 255, 255, 0));

            XPoint top = new XPoint(basePoint.X - 20,Math.Ceiling( basePoint.Y + baseRect.Height * 0.2));
            XPoint bottom = new XPoint(basePoint.X - 20, Math.Ceiling(basePoint.Y + baseRect.Height * 0.8));

            XPoint leftRectPoint = Interpolate(bottom, top, -parameterLeft.Percentage);
            XRect leftBar = new XRect(leftRectPoint, new XSize(20, bottom.Y - leftRectPoint.Y  ));
            gfx.DrawRectangle(blue, leftBar);

            XPoint rigthRectPoint = Interpolate(bottom, top, -parameterRight.Percentage);
            XRect rightBar = new XRect(rigthRectPoint + new XPoint(30,0), new XSize(20, bottom.Y - rigthRectPoint.Y));
            gfx.DrawRectangle(yellow, rightBar);

            XPoint offset = new XPoint(25, 0);
            gfx.DrawLine(XPens.Green, top + offset, bottom + offset);
            gfx.DrawLine(XPens.Yellow, Interpolate(bottom, top, - parameterLeft.AmberVal) + offset, bottom + offset);
            gfx.DrawLine(XPens.Red, Interpolate(bottom, top, -parameterLeft.RedVal) + offset, bottom + offset);

            gfx.DrawString("L", subfont, XBrushes.Black, bottom + new XPoint(5, -2));
            gfx.DrawString("R", subfont, XBrushes.Black, bottom + new XPoint(35, -2));

            double wRatio = (double)img.PixelWidth / (double)img.PixelHeight;

            gfx.DrawImage(img, new XRect(new XPoint(bottom.X, bottom.Y), new XSize(wRatio * 50, 50)));
            img.Dispose();
        }
コード例 #6
0
        protected override RBrush CreateSolidBrush(RColor color)
        {
            XBrush solidBrush;
            if (color == RColor.White)
                solidBrush = XBrushes.White;
            else if (color == RColor.Black)
                solidBrush = XBrushes.Black;
            else if (color.A < 1)
                solidBrush = XBrushes.Transparent;
            else
                solidBrush = new XSolidBrush(Utils.Convert(color));

            return new BrushAdapter(solidBrush);
        }
コード例 #7
0
        public void Render(XGraphics gfx, FixedElement element)
        {
            var spec = (Backgrounded) element.Specification;

            if (spec.BackgroundColor != Colors.Transparent)
            {
                var backgroundBrush = new XSolidBrush(XColor.FromArgb(spec.BackgroundColor));
                gfx.DrawRectangle(backgroundBrush,
                                  element.InnerBox.Left.Points,
                                  element.InnerBox.Top.Points,
                                  element.InnerBox.Width.Points,
                                  element.InnerBox.Height.Points);
            }
        }
コード例 #8
0
    void DrawCodePage(XGraphics gfx, XPoint origin)
    {
      const double dx = 25;
      const double dy = 25;
      XFont labelFont = new XFont("Verdana", 10, XFontStyle.Bold);
      //XFont font = new XFont("Bauhaus", 16);
      XFont font = this.properties.Font1.Font;
      //XFont labelFont = font;
      //font = new XFont("Symbol", 16);
      Encoding encoding = Encoding.GetEncoding(1252);
      double asdf = XColors.LightGray.GS;
      //XBrush lighter = new XSolidBrush(XColor.FromGrayScale(XColor.LightGray.GS * 1.1));
      XBrush lighter = new XSolidBrush(XColor.FromGrayScale(0.9));

      XFontStyle style = font.Style;
      double lineSpace = font.GetHeight(gfx);
      int cellSpace   = font.FontFamily.GetLineSpacing(style);
      int cellAscent  = font.FontFamily.GetCellAscent(style);
      int cellDescent = font.FontFamily.GetCellDescent(style);
      int cellLeading = cellSpace - cellAscent - cellDescent;

      double ascent  = lineSpace * cellAscent / cellSpace;
      double descent = lineSpace * cellDescent / cellSpace;
      double leading = lineSpace * cellLeading / cellSpace;

      double x = origin.X + dx;
      double y = origin.Y;
      //for (int idx = 0; idx < 16; idx++)
      //  gfx.DrawString("x" + idx.ToString("X"), labelFont, XBrushes.DarkGray, x + idx * dx, y);
      for (int row = 0; row < 16; row++)
      {
        x = origin.X;
        y += dy;
        //gfx.DrawString(row.ToString("X") + "x", labelFont, XBrushes.DarkGray, x, y);
        for (int clm = 0; clm < 16; clm++)
        {
          x += dx;
          string glyph = encoding.GetString(new byte[1]{Convert.ToByte(row * 16 + clm)});
          glyph += "!";
          XSize size = gfx.MeasureString(glyph, font);
          gfx.DrawRectangle(XBrushes.LightGray, x, y - size.Height + descent, size.Width, size.Height);
          gfx.DrawRectangle(lighter, x, y - size.Height + descent, size.Width, leading);
          gfx.DrawRectangle(lighter, x, y, size.Width, descent);
          gfx.DrawString(glyph, font, XBrushes.Black, x, y);
        }
      }
    }
コード例 #9
0
ファイル: DoubleBar.cs プロジェクト: Nodgez/Redback
        public void Draw(XPoint basePoint, XRect baseRect, XImage image)
        {
            XFont headerFont = new XFont("Arial", 16);
            XFont subfont = new XFont("Arial", 10);
            char degree = Convert.ToChar('\u00b0');
            gfx.DrawString(parameterLeft.Name.Substring(5, parameterLeft.Name.Length - 5), headerFont, XBrushes.Black, basePoint, XStringFormats.Center);
            gfx.DrawString(parameterLeft.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(-25, baseRect.Height * 0.05),XStringFormats.Center);
            gfx.DrawString(parameterRight.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(25, baseRect.Height * 0.05), XStringFormats.Center);

            XBrush brush = XBrushes.Black;

            if (parameterLeft.LSI >= 75)
                brush = XBrushes.Green;
            else
                brush = XBrushes.Gold;

            gfx.DrawRoundedRectangle(brush,
                new XRect(basePoint + new XPoint(-baseRect.Width * 0.05, baseRect.Height * 0.075),
                new XSize(baseRect.Width * 0.1, baseRect.Height * 0.075)),
                new XSize(10,10));
            gfx.DrawString(parameterLeft.LSI.ToString("0") + "%",
                subfont,
                XBrushes.Black,
                basePoint + new XPoint(baseRect.Width * -0.025, baseRect.Height * 0.125));

            XSolidBrush blue = new XSolidBrush(XColor.FromArgb(127, 0, 0, 255));
            XSolidBrush yellow = new XSolidBrush(XColor.FromArgb(127, 255, 255, 0));

            XPoint top = new XPoint(basePoint.X - 20, basePoint.Y + baseRect.Height * 0.2);
            XPoint bottom = new XPoint(basePoint.X - 20, basePoint.Y + baseRect.Height * 0.8);

            XPoint leftRectPoint = Interpolate(bottom, top, -parameterLeft.Percentage);
            XRect leftBar = new XRect(leftRectPoint, new XSize(20, bottom.Y - leftRectPoint.Y  ));
            gfx.DrawRectangle(blue, leftBar);

            XPoint rigthRectPoint = Interpolate(bottom, top, -parameterRight.Percentage);
            XRect rightBar = new XRect(rigthRectPoint + new XPoint(30,0), new XSize(20, bottom.Y - rigthRectPoint.Y));
            gfx.DrawRectangle(yellow, rightBar);

            gfx.DrawString("L", subfont, XBrushes.Black, bottom + new XPoint(5, -2));
            gfx.DrawString("R", subfont, XBrushes.Black, bottom + new XPoint(35, -2));

            gfx.DrawImage(image, new XRect(bottom.X, bottom.Y, 50, 50));
            image.Dispose();
        }
コード例 #10
0
    /// <summary>
    /// Source and more infos: http://www.math.dartmouth.edu/~dlittle/java/SpiroGraph/
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      //int R =  60, r =  60, p =   60, N = 270; // Cardioid
      //int R =  60, r = -45, p = -101, N = 270; // Rounded Square
      //int R =  75, r = -25, p =   85, N = 270; // Gold fish
      //int R =  75, r = -30, p =   60, N = 270; // Star fish
      //int R = 100, r =  49, p =   66, N =   7; // String of Pearls
      //int R =  90, r =   1, p =  105, N = 105; // Rotating Triangle

      //int R =  90, r =   1, p =  105, N = 105;
      int R =  60, r =   2, p =  122, N = 490;

      int revs = Math.Abs(r) / Gcd(R, Math.Abs(r));
      XPoint[] points = new XPoint[revs * N + 1];
      for (int i = 0; i <= revs * N; i++)
      {
        double t = 4 * i * Math.PI / N;
        points[i].X = ((R+r)*Math.Cos(t) - p * Math.Cos((R+r)* t / r));
        points[i].Y = ((R+r)*Math.Sin(t) - p * Math.Sin((R+r)* t / r));
      }

#if true
      // Draw as lines
      gfx.TranslateTransform(300, 250);
      gfx.DrawLines(properties.Pen2.Pen, points);

      //gfx.DrawPolygon(properties.Pen2.Pen, properties.Brush2.Brush, points, properties.General.FillMode);

      // Draw as closed curve
      gfx.TranslateTransform(0, 400);
      gfx.DrawClosedCurve(properties.Pen2.Pen, properties.Brush2.Brush, points, properties.General.FillMode,
        properties.General.Tension);
#else
      gfx.TranslateTransform(300, 400);
      XSolidBrush dotBrush = new XSolidBrush(properties.Pen2.Pen.Color);
      float width = properties.Pen2.Width;
      for (int i = 0; i < revs * N; i++)
        gfx.DrawEllipse(dotBrush,points[i].X, points[i].Y, width, width);
#endif
    }
コード例 #11
0
ファイル: PDFSharpUtil.cs プロジェクト: HedinRakot/KVS
        /// <summary>
        /// Erstellt eine Wassserzeichen
        /// </summary>
        /// <param name="watermarkText">Text fuer das Wasserzeichen</param>
        /// <param name="source">Quelle PDF Stream</param>
        /// <param name="target">Ziel PDF Stream</param>
        public static void WriteWatermark(string watermarkText, MemoryStream source, MemoryStream target)
        {
            PdfDocument originalPdf = PdfSharp.Pdf.IO.PdfReader.Open(source, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify);
            foreach (PdfPage page in originalPdf.Pages)
            {
                var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);
                var font = new XFont("Verdana", 120);
                var size = gfx.MeasureString(watermarkText, font);
                var brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));
                gfx.TranslateTransform(page.Width.Value / 2, page.Height.Value / 2);
                gfx.RotateTransform(-Math.Atan(page.Height.Value / page.Width.Value) * 180 / Math.PI);
                gfx.TranslateTransform(-page.Width.Value / 2, -page.Height.Value / 2);
                var format = new XStringFormat();
                format.Alignment = XStringAlignment.Near;
                format.LineAlignment = XLineAlignment.Near;
                gfx.DrawString(watermarkText, font, brush, new XPoint((page.Width.Value - size.Width) / 2, (page.Height.Value - size.Height) / 2), format);
            }

            originalPdf.Save(target, false);
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: vronikp/EventRegistration
    static void Main()
    {
      const string watermark = "PDFsharp";
      const int emSize = 150;

      // Get a fresh copy of the sample PDF file
      const string filename = "Portable Document Format.pdf";
      File.Copy(Path.Combine("../../../../../PDFs/", filename),
        Path.Combine(Directory.GetCurrentDirectory(), filename), true);

      // Create the font for drawing the watermark
      XFont font = new XFont("Times New Roman", emSize, XFontStyle.BoldItalic);

      // Open an existing document for editing and loop through its pages
      PdfDocument document = PdfReader.Open(filename);

      // Set version to PDF 1.4 (Acrobat 5) because we use transparency.
      if (document.Version < 14)
        document.Version = 14;

      for (int idx = 0; idx < document.Pages.Count; idx++)
      {
        //if (idx == 1) break;
        PdfPage page = document.Pages[idx];

        switch (idx % 3)
        {
          case 0:
            {
              // Variation 1: Draw watermark as text string

              // Get an XGraphics object for drawing beneath the existing content
              XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

#if true_
            // Fill background with linear gradient color
            XRect rect = page.MediaBox.ToXRect();
            XLinearGradientBrush gbrush = new XLinearGradientBrush(rect,
              XColors.LightSalmon, XColors.WhiteSmoke, XLinearGradientMode.Vertical);
            gfx.DrawRectangle(gbrush, rect);
#endif

              // Get the size (in point) of the text
              XSize size = gfx.MeasureString(watermark, font);

              // Define a rotation transformation at the center of the page
              gfx.TranslateTransform(page.Width / 2, page.Height / 2);
              gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
              gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

              // Create a string format
              XStringFormat format = new XStringFormat();
              format.Alignment = XStringAlignment.Near;
              format.LineAlignment = XLineAlignment.Near;

              // Create a dimmed red brush
              XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));

              // Draw the string
              gfx.DrawString(watermark, font, brush,
                new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                format);
            }
            break;

          case 1:
            {
              // Variation 2: Draw watermark as outlined graphical path

              // Get an XGraphics object for drawing beneath the existing content
              XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

              // Get the size (in point) of the text
              XSize size = gfx.MeasureString(watermark, font);

              // Define a rotation transformation at the center of the page
              gfx.TranslateTransform(page.Width / 2, page.Height / 2);
              gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
              gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

              // Create a graphical path
              XGraphicsPath path = new XGraphicsPath();

              // Add the text to the path
              path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                XStringFormats.Default);

              // Create a dimmed red pen
              XPen pen = new XPen(XColor.FromArgb(128, 255, 0, 0), 2);

              // Stroke the outline of the path
              gfx.DrawPath(pen, path);
            }
            break;

          case 2:
            {
              // Variation 3: Draw watermark as transparent graphical path above text

              // Get an XGraphics object for drawing above the existing content
              XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

              // Get the size (in point) of the text
              XSize size = gfx.MeasureString(watermark, font);

              // Define a rotation transformation at the center of the page
              gfx.TranslateTransform(page.Width / 2, page.Height / 2);
              gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
              gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

              // Create a graphical path
              XGraphicsPath path = new XGraphicsPath();

              // Add the text to the path
              path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                XStringFormats.Default);

              // Create a dimmed red pen and brush
              XPen pen = new XPen(XColor.FromArgb(50, 75, 0, 130), 3);
              XBrush brush = new XSolidBrush(XColor.FromArgb(50, 106, 90, 205));

              // Stroke the outline of the path
              gfx.DrawPath(pen, brush, path);
            }
            break;
        }
      }
      // Save the document...
      document.Save(filename);
      // ...and start a viewer
      Process.Start(filename);
    }
コード例 #13
0
ファイル: PDFManager.cs プロジェクト: SDelport/propspect
        private void InitializeBrushes()
        {
            PropspectBrush = new XSolidBrush(XColor.FromCmyk(0.5424, 0.0508, 0, 0.3059));

        }
コード例 #14
0
ファイル: XSolidBrush.cs プロジェクト: mapilab/PDFsharp
 /// <summary>
 /// Initializes a new instance of the <see cref="XSolidBrush"/> class.
 /// </summary>
 public XSolidBrush(XSolidBrush brush)
 {
     _color = brush.Color;
 }
コード例 #15
0
ファイル: FlightPlanForm.cs プロジェクト: hrishi18pathak/QNP
        private void createPdfDocument()
        {
            PdfDocument document = new PdfDocument();
            int displayYOffset = 50;
            int displayXOffset = 5;
            // int height = 5;
            // int width = 5;

            PdfPage page = document.AddPage();
            page.Width = this.Width;
            XGraphics gfx = XGraphics.FromPdfPage(page);
            XFont font = new XFont("Aerial", 13, XFontStyle.Bold);
            XColor back = XColors.Transparent;
            back.A = 0.3;
            XSolidBrush BorderBrush = new XSolidBrush(back);
            XPen pen = new XPen(XColors.Gray, 1);

            drawGridOnPdfdocument(dataGridView1, gfx, displayXOffset + 5, displayYOffset + 2);

            displayYOffset = this.dataGridView1.Location.Y + this.dataGridView1.Height + 57;

            gfx.DrawString("Total Dist:", font, XBrushes.Black, lblTotalDist.Location.X + displayXOffset, displayYOffset);
            gfx.DrawString(txtTotalDist.Text, font, XBrushes.Black, txtTotalDist.Location.X + displayXOffset, displayYOffset);

            gfx.DrawString("Total Time (HR:MIN)", font, XBrushes.Black, displayXOffset + lblSpeed.Location.X, displayYOffset);
            gfx.DrawString(this.txtTotalTime.Text, font, XBrushes.Black, displayXOffset + txtTotalTime.Location.X, displayYOffset);

            gfx.DrawString("Total Fuel:", font, XBrushes.Black, displayXOffset + label14.Location.X + displayXOffset, displayYOffset);
            gfx.DrawString(this.txtTotalFuel.Text, font, XBrushes.Black, displayXOffset + txtTotalFuel.Location.X, displayYOffset);

            displayYOffset = this.dataGridView1.Location.Y + this.dataGridView1.Height + 80;

            drawGridOnPdfdocument(dataGridView2, gfx, displayXOffset + 5, displayYOffset + 35);

            gfx.DrawString("Relative Bearings", font, XBrushes.DarkBlue, displayXOffset + 7, displayYOffset + 30);
            gfx.DrawString("Additional Information", font, XBrushes.DarkBlue, displayXOffset + 568, displayYOffset + 30);

            gfx.DrawRoundedRectangle(pen, displayXOffset + 565, displayYOffset + 33, 500, 285, 10, 10);
            DrawThisControlOnPdfDocument2(this.additional_Info_richTextBox, gfx, displayXOffset - 4, displayYOffset + 17);

            displayXOffset = this.dataGridView1.Location.X + this.dataGridView1.Width + 10;
            displayYOffset = 40;

            gfx.DrawString("Date", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 30);
            DrawThisControlOnPdfDocument(this.dateTimePicker1, gfx, displayXOffset, displayYOffset);

            displayYOffset = 75;
            gfx.DrawString("Call Sign", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 30);
            DrawThisControlOnPdfDocument(this.callsignBox, gfx, displayXOffset, displayYOffset);
            displayYOffset += 35;
            gfx.DrawString("Pilot", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 30);
            DrawThisControlOnPdfDocument(this.pilotNameBox, gfx, displayXOffset, displayYOffset);
            displayYOffset += 07;
            gfx.DrawString("Co-Pilot", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 60);
            DrawThisControlOnPdfDocument(this.copilotNameBox, gfx, displayXOffset, displayYOffset);
            displayYOffset += 50;
            gfx.DrawString("Start Fuel", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 45);
            DrawThisControlOnPdfDocument(this.numericUpDn_startFuel, gfx, displayXOffset, displayYOffset);

            displayYOffset += 60;
            gfx.DrawString("Start Up", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 35);
            DrawThisControlOnPdfDocument(this.timeStartBox, gfx, displayXOffset, displayYOffset);
            displayYOffset += 10;
            gfx.DrawString("Take Off", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 60);
            DrawThisControlOnPdfDocument(this.timeTakeoffBox, gfx, displayXOffset, displayYOffset);
            displayYOffset += 10;
            gfx.DrawString("Landing", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 80);
            DrawThisControlOnPdfDocument(this.timeLandBox, gfx, displayXOffset, displayYOffset);
            displayYOffset += 10;
            gfx.DrawString("Switch Off", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 105);
            DrawThisControlOnPdfDocument(this.timeSWoffBox, gfx, displayXOffset, displayYOffset);

            displayYOffset += 123;
            gfx.DrawString("Start + Taxi + Hold", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 35);
            DrawThisControlOnPdfDocument(this.numericUpDn_StartTaxiHold, gfx, displayXOffset + 5, displayYOffset);
            displayYOffset += 07;
            gfx.DrawString("Flt Fuel", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 55);
            DrawThisControlOnPdfDocument(this.txtBox_fltFuel, gfx, displayXOffset + 5, displayYOffset);
            displayYOffset += 07;
            gfx.DrawString("Reserve", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 80);
            DrawThisControlOnPdfDocument(this.numericUpDn_Reserve, gfx, displayXOffset - 4, displayYOffset);
            gfx.DrawString("Min", font, XBrushes.Black, displayXOffset + 95, displayYOffset + 80);
            DrawThisControlOnPdfDocument(this.txtBox_Reserve, gfx, displayXOffset + 5, displayYOffset);
            displayYOffset += 07;
            gfx.DrawString("10% Contingency", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 105);
            DrawThisControlOnPdfDocument(this.txtBox_Contingency, gfx, displayXOffset + 5, displayYOffset);
            displayYOffset += 07;
            gfx.DrawString("Additional Reserve", font, XBrushes.Black, displayXOffset + 7, displayYOffset + 130);
            DrawThisControlOnPdfDocument(this.numericUpDn_AddReserve, gfx, displayXOffset + 5, displayYOffset);
            displayYOffset += 130;
            gfx.DrawString("Total Flt Fuel", font, XBrushes.DarkBlue, displayXOffset + 7, displayYOffset + 30);
            DrawThisControlOnPdfDocument(this.txtBox_Tot_FltFuel, gfx, displayXOffset + 12, displayYOffset + 10);

            //
            DrawThisControlOnPdfDocument(this.additional_Info_richTextBox, gfx, displayXOffset - 25, displayYOffset + 10);

            back.A = 0.3;
            XSolidBrush brush = new XSolidBrush(back);

            //Side Panels
            gfx.DrawRoundedRectangle(pen, 1075, 48, 190, 175, 10, 10);
            gfx.DrawRoundedRectangle(brush, 1075, 48, 190, 175, 10, 10);
            gfx.DrawRoundedRectangle(pen, 1075, 238, 190, 140, 10, 10);
            gfx.DrawRoundedRectangle(brush, 1075, 238, 190, 140, 10, 10);
            gfx.DrawRoundedRectangle(pen, 1075, 392, 195, 195, 10, 10);
            gfx.DrawRoundedRectangle(brush, 1075, 392, 195, 195, 10, 10);
            /*
            //for dataGridview1
            gfx.DrawRoundedRectangle(pen, 5, 48, 1058, 328, 10, 10);
             */

            /*
            XImage xImage = XImage.FromFile(imagePath);
            gfx.DrawImage(xImage, xPosition, yPosition, xImage.PixelWidth, xImage.PixelWidth);

            */

            // Create a font
            XFont font1 = new XFont("Aerial", 30, XFontStyle.Regular);
            XFont font2 = new XFont("Aerial", 14, XFontStyle.Italic);
            // Draw the Main Heading text and Caution Note
            //gfx.DrawRoundedRectangle(XBrushes.Navy, 570, 2, 1024, 35, 10, 10);
            string qnpPdfTitle = "QNP Nav Plan";
            string regClientName = ApplicationState.Instance.getRegisteredClientName();
            if (!string.IsNullOrWhiteSpace(regClientName))
            {
                qnpPdfTitle += "[" + regClientName + "]";
            }

            gfx.DrawString(qnpPdfTitle, font1, XBrushes.Black,
              new XRect(0, 0, page.Width, page.Height),
              XStringFormats.TopCenter);
            gfx.DrawString("Caution ", font2, XBrushes.Red, 5, 820);
            gfx.DrawString(": Check the correctness of calculated data with other resources.", font2, XBrushes.Black, 50, 820);

            // TODO DISPLAY A FILE SAVE DIALOG ALLOWING THE USER TO SET THE NAME
            // OF THE CURRENTLY GENERATED REPORT

            //save file dialog proc
            SaveFileDialog SaveFileDialog1 = new SaveFileDialog();

            //saveFileDialog1.ShowDialog();

            //Nullable<bool> result = SaveFileDialog1.ShowDialog();
            saveFileDialog1.Tag = DateTime.Now.ToString("yyyy_MM_dd_HH_mm");
            // Process save file dialog box results
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Save document
                String rawFileName = saveFileDialog1.FileName;
                String taggedFileName = AppendDate(rawFileName);
                document.Save(taggedFileName);
                Process.Start(taggedFileName);
            }
        }
コード例 #16
0
ファイル: Render.cs プロジェクト: Matt--/travellermap
        private static void DrawMicroBorders(RenderContext ctx, BorderLayer layer)
        {
            const byte FILL_ALPHA = 64;

            float[] edgex, edgey;
            PathUtil.PathType borderPathType = ctx.styles.microBorderStyle == MicroBorderStyle.Square ?
                PathUtil.PathType.Square : PathUtil.PathType.Hex;
            RenderUtil.HexEdges(borderPathType, out edgex, out edgey);

            XSolidBrush solidBrush = new XSolidBrush();
            XPen pen = new XPen(XColor.Empty);
            ctx.styles.microBorders.pen.Apply(ref pen);

            foreach (Sector sector in ctx.selector.Sectors)
            {
                XGraphicsPath sectorClipPath = null;

                using (RenderUtil.SaveState(ctx.graphics))
                {
                    // This looks craptacular for Candy style borders :(
                    if (ctx.clipOutsectorBorders &&
                        (layer == BorderLayer.Fill || ctx.styles.microBorderStyle != MicroBorderStyle.Curve))
                    {
                        Sector.ClipPath clip = sector.ComputeClipPath(borderPathType);
                        if (!ctx.tileRect.IntersectsWith(clip.bounds))
                            continue;

                        sectorClipPath = new XGraphicsPath(clip.clipPathPoints, clip.clipPathPointTypes, XFillMode.Alternate);
                        if (sectorClipPath != null)
                            ctx.graphics.IntersectClip(sectorClipPath);
                    }

                    ctx.graphics.SmoothingMode = XSmoothingMode.AntiAlias;

                    foreach (Border border in sector.Borders)
                    {
                        BorderPath borderPath = border.ComputeGraphicsPath(sector, borderPathType);

                        XGraphicsPath drawPath = borderPath.borderPathPoints.Length > 0 ? new XGraphicsPath(borderPath.borderPathPoints, borderPath.borderPathTypes, XFillMode.Alternate) : null;
                        XGraphicsPath clipPath = new XGraphicsPath(borderPath.clipPathPoints, borderPath.clipPathTypes, XFillMode.Alternate);

                        Color? borderColor = border.Color;
                        LineStyle? borderStyle = border.Style;

                        SectorStylesheet.StyleResult ssr = sector.ApplyStylesheet("border", border.Allegiance);
                        borderStyle = borderStyle ?? ssr.GetEnum<LineStyle>("style") ?? LineStyle.Solid;
                        borderColor = borderColor ?? ssr.GetColor("color") ?? ctx.styles.microBorders.pen.color;

                        if (layer == BorderLayer.Stroke && borderStyle.Value == LineStyle.None)
                            continue;

                        if (ctx.styles.grayscale ||
                            !ColorUtil.NoticeableDifference(borderColor.Value, ctx.styles.backgroundColor))
                        {
                            borderColor = ctx.styles.microBorders.pen.color; // default
                        }

                        pen.Color = borderColor.Value;
                        pen.DashStyle = LineStyleToDashStyle(borderStyle.Value);

                        if (ctx.styles.microBorderStyle != MicroBorderStyle.Curve)
                        {
                            // Clip to the path itself - this means adjacent borders don't clash
                            using (RenderUtil.SaveState(ctx.graphics))
                            {
                                ctx.graphics.IntersectClip(clipPath);
                                if (layer == BorderLayer.Fill)
                                {
                                    solidBrush.Color = Color.FromArgb(FILL_ALPHA, borderColor.Value);
                                    ctx.graphics.DrawPath(solidBrush, clipPath);
                                }

                                if (layer == BorderLayer.Stroke && drawPath != null)
                                    ctx.graphics.DrawPath(pen, drawPath);
                            }
                        }
                        else
                        {
                            if (layer == BorderLayer.Fill)
                            {
                                solidBrush.Color = Color.FromArgb(FILL_ALPHA, borderColor.Value);
                                ctx.graphics.DrawClosedCurve(solidBrush, borderPath.clipPathPoints);
                            }

                            if (layer == BorderLayer.Stroke)
                            {
                                foreach (PointF[] curve in borderPath.curvePoints)
                                {
                                    // TODO: Investigate DrawClosedCurve to handle endings
                                    // Would need to have path computer tell whether
                                    // or not the path was actually a closed loop
                                    // Can do it by clipping borders to sector, but that loses
                                    // bottom/right overlaps
                                    ctx.graphics.DrawCurve(pen, curve, 0.6f);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #17
0
ファイル: Render.cs プロジェクト: Matt--/travellermap
        private static void DrawLabels(RenderContext ctx, FontCache styleRes)
        {
            using (RenderUtil.SaveState(ctx.graphics))
            {
                XSolidBrush solidBrush = new XSolidBrush();

                ctx.graphics.SmoothingMode = XSmoothingMode.AntiAlias;

                foreach (Sector sector in ctx.selector.Sectors)
                {
                    solidBrush.Color = ctx.styles.microBorders.textColor;
                    foreach (Border border in sector.Borders.Where(border => border.ShowLabel))
                    {
                        Allegiance alleg = sector.GetAllegianceFromCode(border.Allegiance);
                        if (alleg != null || !String.IsNullOrEmpty(border.Label))
                        {
                            string text = border.Label ?? alleg.Name;
                            Point labelHex = border.LabelPosition;
                            PointF labelPos = Astrometrics.HexToCenter(Astrometrics.LocationToCoordinates(new Location(sector.Location, labelHex)));
                            // TODO: Replace these with, well, positions!
                            //labelPos.X -= 0.5f;
                            //labelPos.Y -= 0.5f;

                            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"\s+(?![a-z])");
                            if (border.WrapLabel)
                                text = r.Replace(text, "\n");

                            RenderUtil.DrawLabel(ctx.graphics, text, labelPos, ctx.styles.microBorders.Font, solidBrush, ctx.styles.microBorders.textStyle);
                        }
                    }

                    foreach (Label label in sector.Labels)
                    {
                        string text = label.Text;
                        Point labelHex = new Point(label.Hex / 100, label.Hex % 100);
                        PointF labelPos = Astrometrics.HexToCenter(Astrometrics.LocationToCoordinates(new Location(sector.Location, labelHex)));
                        // TODO: Adopt some of the tweaks from .MSEC
                        labelPos.Y -= label.OffsetY * 0.7f;

                        XFont font;
                        switch (label.Size)
                        {
                            case "small": font = ctx.styles.microBorders.SmallFont; break;
                            case "large": font = ctx.styles.microBorders.LargeFont; break;
                            default: font = ctx.styles.microBorders.Font; break;
                        }

                        if (!ctx.styles.grayscale &&
                            ColorUtil.NoticeableDifference(label.Color, ctx.styles.backgroundColor) &&
                            (label.Color != Label.DefaultColor))
                            solidBrush.Color = label.Color;
                        else
                            solidBrush.Color = ctx.styles.microBorders.textColor;
                        RenderUtil.DrawLabel(ctx.graphics, text, labelPos, font, solidBrush, ctx.styles.microBorders.textStyle);
                    }
                }
            }
        }
コード例 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XSolidBrush"/> class.
 /// </summary>
 public XSolidBrush(XSolidBrush brush)
 {
     this.color = brush.Color;
 }
コード例 #19
0
ファイル: Render.cs プロジェクト: Matt--/travellermap
        private static void DrawWorld(RenderContext ctx, FontCache styleRes, World world, WorldLayer layer)
        {
            bool isPlaceholder = world.IsPlaceholder;
            bool isCapital = world.IsCapital;
            bool isHiPop = world.IsHi;
            bool renderName = ctx.styles.worldDetails.HasFlag(WorldDetails.AllNames) ||
                (ctx.styles.worldDetails.HasFlag(WorldDetails.KeyNames) && (isCapital || isHiPop));
            bool renderUWP = ctx.styles.worldDetails.HasFlag(WorldDetails.Uwp);

            using (RenderUtil.SaveState(ctx.graphics))
            {
                XPen pen = new XPen(XColor.Empty);
                XSolidBrush solidBrush = new XSolidBrush();

                ctx.graphics.SmoothingMode = XSmoothingMode.AntiAlias;

                // Center on the parsec
                PointF center = Astrometrics.HexToCenter(world.Coordinates);

                XMatrix matrix = new XMatrix();
                matrix.TranslatePrepend(center.X, center.Y);
                matrix.ScalePrepend(ctx.styles.hexContentScale / Astrometrics.ParsecScaleX, ctx.styles.hexContentScale / Astrometrics.ParsecScaleY);
                ctx.graphics.MultiplyTransform(matrix, XMatrixOrder.Prepend);

                if (!ctx.styles.useWorldImages)
                {
                    if (layer == WorldLayer.Background)
                    {
                        #region Zone
                        if (ctx.styles.worldDetails.HasFlag(WorldDetails.Zone))
                        {
                            Stylesheet.StyleElement? maybeElem = ZoneStyle(ctx, world);
                            if (maybeElem.HasValue)
                            {
                                Stylesheet.StyleElement elem = maybeElem.Value;
                                if (!elem.fillColor.IsEmpty)
                                {
                                    solidBrush.Color = elem.fillColor;
                                    ctx.graphics.DrawEllipse(solidBrush, -0.4f, -0.4f, 0.8f, 0.8f);
                                }

                                PenInfo pi = elem.pen;
                                if (!pi.color.IsEmpty)
                                {
                                    pi.Apply(ref pen);

                                    if (renderName && ctx.styles.fillMicroBorders)
                                    {
                                        using (RenderUtil.SaveState(ctx.graphics))
                                        {
                                            ctx.graphics.IntersectClip(new RectangleF(-.5f, -.5f, 1f, renderUWP ? 0.65f : 0.75f));
                                            ctx.graphics.DrawEllipse(pen, -0.4f, -0.4f, 0.8f, 0.8f);
                                        }
                                    }
                                    else
                                    {
                                        ctx.graphics.DrawEllipse(pen, -0.4f, -0.4f, 0.8f, 0.8f);
                                    }
                                }
                            }
                        }
                        #endregion

                        #region Hex
                        if (!ctx.styles.numberAllHexes &&
                            ctx.styles.worldDetails.HasFlag(WorldDetails.Hex))
                        {
                            string hex;
                            switch (ctx.styles.hexCoordinateStyle)
                            {
                                default:
                                case Stylesheet.HexCoordinateStyle.Sector: hex = world.Hex; break;
                                case Stylesheet.HexCoordinateStyle.Subsector: hex = world.SubsectorHex; break;
                            }
                            solidBrush.Color = ctx.styles.hexNumber.textColor;
                            ctx.graphics.DrawString(hex, ctx.styles.hexNumber.Font, solidBrush, 0.0f, -0.5f, RenderUtil.StringFormatTopCenter);
                        }
                        #endregion
                    }

                    if (layer == WorldLayer.Foreground)
                    {
                        Stylesheet.StyleElement? elem = ZoneStyle(ctx, world);
                        TextBackgroundStyle worldTextBackgroundStyle = (elem.HasValue && !elem.Value.fillColor.IsEmpty)
                            ? TextBackgroundStyle.None : ctx.styles.worlds.textBackgroundStyle;

                        #region Name
                        if (renderName)
                        {
                            string name = world.Name;
                            if ((isHiPop && ctx.styles.worldDetails.HasFlag(WorldDetails.Highlight)) || ctx.styles.worlds.textStyle.Uppercase)
                                name = name.ToUpperInvariant();

                            Color textColor = (isCapital && ctx.styles.worldDetails.HasFlag(WorldDetails.Highlight))
                                ? ctx.styles.worlds.textHighlightColor : ctx.styles.worlds.textColor;
                            XFont font = ((isHiPop || isCapital) && ctx.styles.worldDetails.HasFlag(WorldDetails.Highlight))
                                ? ctx.styles.worlds.LargeFont : ctx.styles.worlds.Font;

                            DrawWorldLabel(ctx, worldTextBackgroundStyle, solidBrush, textColor, ctx.styles.worlds.textStyle.Translation, font, name);
                        }
                        #endregion

                        #region Allegiance
                        // TODO: Mask off background for allegiance
                        if (ctx.styles.worldDetails.HasFlag(WorldDetails.Allegiance))
                        {
                            string alleg = world.Allegiance;
                            if (!SecondSurvey.IsDefaultAllegiance(alleg))
                            {
                                if (!ctx.styles.t5AllegianceCodes && alleg.Length > 2)
                                    alleg = SecondSurvey.T5AllegianceCodeToLegacyCode(alleg);

                                solidBrush.Color = ctx.styles.worlds.textColor;

                                if (ctx.styles.lowerCaseAllegiance)
                                    alleg = alleg.ToLowerInvariant();

                                ctx.graphics.DrawString(alleg, ctx.styles.worlds.SmallFont, solidBrush, ctx.styles.AllegiancePosition.X, ctx.styles.AllegiancePosition.Y, RenderUtil.StringFormatCentered);
                            }
                        }
                        #endregion

                        if (!isPlaceholder)
                        {
                            #region GasGiant
                            if (ctx.styles.worldDetails.HasFlag(WorldDetails.GasGiant))
                            {
                                if (world.GasGiants > 0)
                                {
                                    solidBrush.Color = ctx.styles.worlds.textColor;
                                    RenderUtil.DrawGlyph(ctx.graphics, Glyph.Circle, styleRes, solidBrush, ctx.styles.GasGiantPosition.X, ctx.styles.GasGiantPosition.Y);
                                }
                            }
                            #endregion

                            #region Starport
                            if (ctx.styles.worldDetails.HasFlag(WorldDetails.Starport))
                            {
                                string starport = world.Starport.ToString();
                                DrawWorldLabel(ctx, worldTextBackgroundStyle, solidBrush, ctx.styles.worlds.textColor, ctx.styles.StarportPosition, styleRes.StarportFont, starport);
                            }
                            #endregion

                            #region UWP
                            if (renderUWP)
                            {
                                string uwp = world.UWP;
                                solidBrush.Color = ctx.styles.worlds.textColor;

                                ctx.graphics.DrawString(uwp, ctx.styles.hexNumber.Font, solidBrush, ctx.styles.StarportPosition.X, -ctx.styles.StarportPosition.Y, RenderUtil.StringFormatCentered);
                            }
                            #endregion

                            #region Bases
                            // TODO: Mask off background for glyphs
                            if (ctx.styles.worldDetails.HasFlag(WorldDetails.Bases))
                            {
                                string bases = world.Bases;

                                // Special case: Show Zho Naval+Military as diamond
                                if (world.BaseAllegiance == "Zh" && bases == "KM")
                                    bases = "Z";

                                // Base 1
                                bool bottomUsed = false;
                                if (bases.Length > 0)
                                {
                                    Glyph glyph = Glyph.FromBaseCode(world.BaseAllegiance, bases[0]);
                                    if (glyph.Printable)
                                    {
                                        PointF pt = ctx.styles.BaseTopPosition;
                                        if (glyph.Bias == Glyph.GlyphBias.Bottom)
                                        {
                                            pt = ctx.styles.BaseBottomPosition;
                                            bottomUsed = true;
                                        }

                                        solidBrush.Color = glyph.IsHighlighted ? ctx.styles.worlds.textHighlightColor : ctx.styles.worlds.textColor;
                                        RenderUtil.DrawGlyph(ctx.graphics, glyph, styleRes, solidBrush, pt.X, pt.Y);
                                    }
                                }

                                // Base 2
                                if (bases.Length > 1)
                                {
                                    Glyph glyph = Glyph.FromBaseCode(world.LegacyAllegiance, bases[1]);
                                    if (glyph.Printable)
                                    {
                                        PointF pt = bottomUsed ? ctx.styles.BaseTopPosition : ctx.styles.BaseBottomPosition;
                                        solidBrush.Color = glyph.IsHighlighted ? ctx.styles.worlds.textHighlightColor : ctx.styles.worlds.textColor;
                                        RenderUtil.DrawGlyph(ctx.graphics, glyph, styleRes, solidBrush, pt.X, pt.Y);
                                    }
                                }

                                // Research Stations
                                string rs;
                                if ((rs = world.ResearchStation) != null)
                                {
                                    Glyph glyph = Glyph.FromResearchCode(rs);
                                    solidBrush.Color = glyph.IsHighlighted ? ctx.styles.worlds.textHighlightColor : ctx.styles.worlds.textColor;
                                    RenderUtil.DrawGlyph(ctx.graphics, glyph, styleRes, solidBrush, ctx.styles.BaseMiddlePosition.X, ctx.styles.BaseMiddlePosition.Y);
                                }
                                else if (world.IsReserve)
                                {
                                    Glyph glyph = Glyph.Reserve;
                                    solidBrush.Color = glyph.IsHighlighted ? ctx.styles.worlds.textHighlightColor : ctx.styles.worlds.textColor;
                                    RenderUtil.DrawGlyph(ctx.graphics, glyph, styleRes, solidBrush, ctx.styles.BaseMiddlePosition.X, 0);
                                }
                                else if (world.IsPenalColony)
                                {
                                    Glyph glyph = Glyph.Prison;
                                    solidBrush.Color = glyph.IsHighlighted ? ctx.styles.worlds.textHighlightColor : ctx.styles.worlds.textColor;
                                    RenderUtil.DrawGlyph(ctx.graphics, glyph, styleRes, solidBrush, ctx.styles.BaseMiddlePosition.X, 0);
                                }
                                else if (world.IsPrisonExileCamp)
                                {
                                    Glyph glyph = Glyph.ExileCamp;
                                    solidBrush.Color = glyph.IsHighlighted ? ctx.styles.worlds.textHighlightColor : ctx.styles.worlds.textColor;
                                    RenderUtil.DrawGlyph(ctx.graphics, glyph, styleRes, solidBrush, ctx.styles.BaseMiddlePosition.X, 0);
                                }
                            }
                            #endregion
                        }

                        #region Disc
                        if (ctx.styles.worldDetails.HasFlag(WorldDetails.Type))
                        {
                            if (isPlaceholder)
                            {
                                DrawWorldLabel(ctx, ctx.styles.placeholder.textBackgroundStyle, solidBrush, ctx.styles.placeholder.textColor, ctx.styles.placeholder.position, ctx.styles.placeholder.Font, ctx.styles.placeholder.content);
                            }
                            else
                            {
                                if (world.Size <= 0)
                                {
                                    #region Asteroid-Belt
                                    if (ctx.styles.worldDetails.HasFlag(WorldDetails.Asteroids))
                                    {
                                        // Basic pattern, with probability varying per position:
                                        //   o o o
                                        //  o o o o
                                        //   o o o

                                        int[] lpx = { -2, 0, 2, -3, -1, 1, 3, -2, 0, 2 };
                                        int[] lpy = { -2, -2, -2, 0, 0, 0, 0, 2, 2, 2 };
                                        float[] lpr = { 0.5f, 0.9f, 0.5f, 0.6f, 0.9f, 0.9f, 0.6f, 0.5f, 0.9f, 0.5f };

                                        solidBrush.Color = ctx.styles.worlds.textColor;

                                        // Random generator is seeded with world location so it is always the same
                                        Random rand = new Random(world.Coordinates.X ^ world.Coordinates.Y);
                                        for (int i = 0; i < lpx.Length; ++i)
                                        {
                                            if (rand.NextDouble() < lpr[i])
                                            {
                                                float px = lpx[i] * 0.035f;
                                                float py = lpy[i] * 0.035f;

                                                float w = 0.04f + (float)rand.NextDouble() * 0.03f;
                                                float h = 0.04f + (float)rand.NextDouble() * 0.03f;

                                                // If necessary, add jitter here
                                                float dx = 0, dy = 0;

                                                ctx.graphics.DrawEllipse(solidBrush,
                                                    px + dx - w / 2, py + dy - h / 2, w, h);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // Just a glyph
                                        solidBrush.Color = ctx.styles.worlds.textColor;
                                        RenderUtil.DrawGlyph(ctx.graphics, Glyph.DiamondX, styleRes, solidBrush, 0.0f, 0.0f);
                                    }
                                    #endregion
                                }
                                else
                                {
                                    XColor penColor, brushColor;
                                    ctx.styles.WorldColors(world, out penColor, out brushColor);

                                    if (!brushColor.IsEmpty)
                                    {
                                        solidBrush.Color = brushColor;
                                        ctx.graphics.DrawEllipse(solidBrush, -0.1f, -0.1f, 0.2f, 0.2f);
                                    }

                                    if (!penColor.IsEmpty)
                                    {
                                        ctx.styles.worldWater.pen.Apply(ref pen);
                                        pen.Color = penColor;
                                        ctx.graphics.DrawEllipse(pen, -0.1f, -0.1f, 0.2f, 0.2f);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // Dotmap
                            solidBrush.Color = ctx.styles.worlds.textColor;
                            ctx.graphics.DrawEllipse(solidBrush, -0.2f, -0.2f, 0.4f, 0.4f);
                        }
                        #endregion
                    }
                }
                else // ctx.styles.useWorldImages
                {
                    float imageRadius = ((world.Size <= 0) ? 0.6f : (0.3f * (world.Size / 5.0f + 0.2f))) / 2;
                    float decorationRadius = imageRadius;

                    if (layer == WorldLayer.Background)
                    {
                        #region Disc
                        if (ctx.styles.worldDetails.HasFlag(WorldDetails.Type))
                        {
                            if (isPlaceholder)
                            {
                                DrawWorldLabel(ctx, ctx.styles.placeholder.textBackgroundStyle, solidBrush, ctx.styles.placeholder.textColor, ctx.styles.placeholder.position, ctx.styles.placeholder.Font, ctx.styles.placeholder.content);
                            }
                            else if (world.Size <= 0)
                            {
                                const float scaleX = 1.5f;
                                const float scaleY = 1.0f;
                                XImage img = s_worldImages["Belt"];

                                lock (img)
                                {
                                    ctx.graphics.DrawImage(img, -imageRadius * scaleX, -imageRadius * scaleY, imageRadius * 2 * scaleX, imageRadius * 2 * scaleY);
                                }
                            }
                            else
                            {
                                XImage img;
                                switch (world.Hydrographics)
                                {
                                    default:
                                    case 0x0: img = s_worldImages["Hyd0"]; break;
                                    case 0x1: img = s_worldImages["Hyd1"]; break;
                                    case 0x2: img = s_worldImages["Hyd2"]; break;
                                    case 0x3: img = s_worldImages["Hyd3"]; break;
                                    case 0x4: img = s_worldImages["Hyd4"]; break;
                                    case 0x5: img = s_worldImages["Hyd5"]; break;
                                    case 0x6: img = s_worldImages["Hyd6"]; break;
                                    case 0x7: img = s_worldImages["Hyd7"]; break;
                                    case 0x8: img = s_worldImages["Hyd8"]; break;
                                    case 0x9: img = s_worldImages["Hyd9"]; break;
                                    case 0xA: img = s_worldImages["HydA"]; break;
                                }
                                if (img != null)
                                {
                                    lock (img)
                                    {
                                        ctx.graphics.DrawImage(img, -imageRadius, -imageRadius, imageRadius * 2, imageRadius * 2);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // Dotmap
                            solidBrush.Color = ctx.styles.worlds.textColor;
                            ctx.graphics.DrawEllipse(solidBrush, -0.2f, -0.2f, 0.4f, 0.4f);
                        }
                        #endregion
                    }

                    if (isPlaceholder)
                        return;

                    if (layer == WorldLayer.Foreground)
                    {
                        #region Zone
                        if (ctx.styles.worldDetails.HasFlag(WorldDetails.Zone))
                        {
                            if (world.IsAmber || world.IsRed || world.IsBlue)
                            {
                                PenInfo pi =
                                    world.IsAmber ? ctx.styles.amberZone.pen :
                                    world.IsRed ? ctx.styles.redZone.pen : ctx.styles.blueZone.pen;
                                pi.Apply(ref pen);

                                // TODO: Try and accomplish this using dash pattern
                                decorationRadius += 0.1f;
                                ctx.graphics.DrawArc(pen, -decorationRadius, -decorationRadius, decorationRadius * 2, decorationRadius * 2, 5, 80);
                                ctx.graphics.DrawArc(pen, -decorationRadius, -decorationRadius, decorationRadius * 2, decorationRadius * 2, 95, 80);
                                ctx.graphics.DrawArc(pen, -decorationRadius, -decorationRadius, decorationRadius * 2, decorationRadius * 2, 185, 80);
                                ctx.graphics.DrawArc(pen, -decorationRadius, -decorationRadius, decorationRadius * 2, decorationRadius * 2, 275, 80);
                            }
                        }
                        #endregion

                        #region GasGiant
                        if (ctx.styles.worldDetails.HasFlag(WorldDetails.GasGiant))
                        {
                            if (world.GasGiants > 0)
                            {
                                decorationRadius += 0.1f;
                                const float symbolRadius = 0.05f;
                                solidBrush.Color = ctx.styles.worlds.textHighlightColor; ;
                                ctx.graphics.DrawEllipse(solidBrush, decorationRadius - symbolRadius, 0.0f - symbolRadius, symbolRadius * 2, symbolRadius * 2);
                            }
                        }
                        #endregion

                        #region UWP
                        if (renderUWP)
                        {
                            string uwp = world.UWP;
                            solidBrush.Color = ctx.styles.worlds.textColor;

                            using (RenderUtil.SaveState(ctx.graphics))
                            {
                                XMatrix uwpMatrix = new XMatrix();
                                uwpMatrix.TranslatePrepend(decorationRadius, 0.0f);
                                uwpMatrix.ScalePrepend(ctx.styles.worlds.textStyle.Scale.Width, ctx.styles.worlds.textStyle.Scale.Height);
                                uwpMatrix.Multiply(uwpMatrix, XMatrixOrder.Prepend);
                                ctx.graphics.DrawString(uwp, ctx.styles.hexNumber.Font, solidBrush, ctx.styles.StarportPosition.X, -ctx.styles.StarportPosition.Y, RenderUtil.StringFormatCenterLeft);
                            }
                        }
                        #endregion

                        #region Name
                        if (renderName)
                        {
                            string name = world.Name;
                            if (isHiPop)
                                name = name.ToUpperInvariant();

                            using (RenderUtil.SaveState(ctx.graphics))
                            {
                                Color textColor = (isCapital && ctx.styles.worldDetails.HasFlag(WorldDetails.Highlight))
                                    ? ctx.styles.worlds.textHighlightColor : ctx.styles.worlds.textColor;

                                if (ctx.styles.worlds.textStyle.Uppercase)
                                    name = name.ToUpper();

                                decorationRadius += 0.1f;
                                XMatrix imageMatrix = new XMatrix();
                                imageMatrix.TranslatePrepend(decorationRadius, 0.0f);
                                imageMatrix.ScalePrepend(ctx.styles.worlds.textStyle.Scale.Width, ctx.styles.worlds.textStyle.Scale.Height);
                                imageMatrix.TranslatePrepend(ctx.graphics.MeasureString(name, ctx.styles.worlds.Font).Width / 2, 0.0f); // Left align
                                ctx.graphics.MultiplyTransform(imageMatrix, XMatrixOrder.Prepend);

                                DrawWorldLabel(ctx, ctx.styles.worlds.textBackgroundStyle, solidBrush, textColor, ctx.styles.worlds.textStyle.Translation, ctx.styles.worlds.Font, name);
                            }
                        }
                        #endregion
                    }
                }
            }
        }
コード例 #20
0
ファイル: Render.cs プロジェクト: Matt--/travellermap
        public static void RenderTile(RenderContext ctx)
        {
            DateTime dtStart = DateTime.Now;
            List<Timer> timers = new List<Timer>();

            if (ctx.resourceManager == null)
                throw new ArgumentNullException("resourceManager");

            if (ctx.graphics == null)
                throw new ArgumentNullException("graphics");

            if (ctx.selector == null)
                throw new ArgumentNullException("selector");

            XSolidBrush solidBrush = new XSolidBrush();
            XPen pen = new XPen(XColor.Empty);

            using (var fonts = new FontCache(ctx.styles))
            {
                #region resources
                lock (s_imageInitLock)
                {
                    if (ctx.styles.useBackgroundImage && s_backgroundImage == null)
                        s_backgroundImage = XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Nebula.png"));

                    if (ctx.styles.showRifts && s_riftImage == null)
                        s_riftImage = new ImageHolder(Image.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Rifts.png")));

                    if (ctx.styles.useGalaxyImage && s_galaxyImage == null) {
                        s_galaxyImage = new ImageHolder(Image.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Galaxy.png")));
                        s_galaxyImageGray = new ImageHolder(Image.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Galaxy_Gray.png")));
                    }

                    if (ctx.styles.useWorldImages && s_worldImages == null)
                    {
                        s_worldImages = new Dictionary<string, XImage> {
                            { "Hyd0", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd0.png")) },
                            { "Hyd1", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd1.png")) },
                            { "Hyd2", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd2.png")) },
                            { "Hyd3", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd3.png")) },
                            { "Hyd4", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd4.png")) },
                            { "Hyd5", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd5.png")) },
                            { "Hyd6", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd6.png")) },
                            { "Hyd7", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd7.png")) },
                            { "Hyd8", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd8.png")) },
                            { "Hyd9", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Hyd9.png")) },
                            { "HydA", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/HydA.png")) },
                            { "Belt", XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/Candy/Belt.png")) }
                        };
                    }

                    if (ctx.silly && s_sillyImageColor == null)
                    {
                        // Happy face c/o http://bighappyfaces.com/
                        s_sillyImageColor = XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/AprilFools/Starburst.png"));
                        s_sillyImageGray = XImage.FromFile(ctx.resourceManager.Server.MapPath(@"~/res/AprilFools/Starburst_Gray.png"));
                    }
                }
                #endregion

                timers.Add(new Timer("preload"));
                //////////////////////////////////////////////////////////////
                //
                // Image-Space Rendering
                //
                //////////////////////////////////////////////////////////////

                using (Maps.Rendering.RenderUtil.SaveState(ctx.graphics))
                {
                    if (ctx.clipPath != null)
                    {
                        XMatrix m = ctx.ImageSpaceToWorldSpace;
                        ctx.graphics.MultiplyTransform(m);
                        ctx.graphics.IntersectClip(ctx.clipPath);
                        m.Invert();
                        ctx.graphics.MultiplyTransform(m);
                    }

                    // Fill
                    ctx.graphics.SmoothingMode = XSmoothingMode.HighSpeed;
                    solidBrush.Color = ctx.styles.backgroundColor;
                    ctx.graphics.DrawRectangle(solidBrush, 0, 0, ctx.tileSize.Width, ctx.tileSize.Height);

                    //// Draw tile #
                    //using( var font = new Font( FontFamily.GenericSansSerif, 10 ) )
                    //{
                    //  graphics.DrawString( String.Format( "({0},{1})", x, y ), font, foregroundBrush, 0, 0 );
                    //  graphics.DrawString( String.Format( "{0},{1}-{2}x{3}", tileRect.X, tileRect.Y, tileRect.Width, tileRect.Height ), font, foregroundBrush, 0, 20 );
                    //}

                    // Frame it
                    //graphics.DrawRectangle( Pens.Green, 0, 0, tileSize.Width-1, tileSize.Height-1 );
                }

                timers.Add(new Timer("imagespace"));
                //////////////////////////////////////////////////////////////
                //
                // World-Space Rendering
                //
                //////////////////////////////////////////////////////////////

                // Transform from image-space to world-space. Set up a reverse transform as well.
                XMatrix imageSpaceToWorldSpace = ctx.ImageSpaceToWorldSpace;

                XMatrix worldSpaceToImageSpace = imageSpaceToWorldSpace;
                worldSpaceToImageSpace.Invert();

                ctx.graphics.MultiplyTransform(imageSpaceToWorldSpace);

                using (Maps.Rendering.RenderUtil.SaveState(ctx.graphics))
                {

                    //------------------------------------------------------------
                    // Explicit Clipping
                    //------------------------------------------------------------

                    if (ctx.clipPath != null)
                        ctx.graphics.IntersectClip(ctx.clipPath);

                    //ctx.styles.showPseudoRandomStars = true;
                    //------------------------------------------------------------
                    // Backgrounds
                    //------------------------------------------------------------

                    RectangleF galacticBounds = new RectangleF(-14598.67f, -23084.26f, 29234.1133f, 25662.4746f); // TODO: Don't hardcode
                    Rectangle galaxyImageRect = new Rectangle(-18257, -26234, 36551, 32462); // Chosen to match T5 pp.416

                    // This transforms the Linehan galactic structure to the Mikesh galactic structure
                    // See http://travellermap.blogspot.com/2009/03/galaxy-scale-mismatch.html
                    Matrix xformLinehanToMikesh = new Matrix(0.9181034f, 0.0f, 0.0f, 0.855192542f, 120.672432f, 86.34569f);
                    timers.Add(new Timer("prep"));

                    //------------------------------------------------------------
                    // Local background (Nebula)
                    //------------------------------------------------------------
                    #region nebula-background

                    // NOTE: Since alpha texture brushes aren't supported without
                    // creating a new image (slow!) we render the local background
                    // first, then overlay the deep background over it, for
                    // basically the same effect since the alphas sum to 1.

                    if (ctx.styles.useBackgroundImage && galacticBounds.IntersectsWith(ctx.tileRect))
                    {
                        // Image-space rendering, so save current context
                        using (RenderUtil.SaveState(ctx.graphics))
                        {
                            // Never fill outside the galaxy
                            ctx.graphics.IntersectClip(galacticBounds);

                            // Map back to image space so it scales/tiles nicely
                            ctx.graphics.MultiplyTransform(worldSpaceToImageSpace);

                            const float backgroundImageScale = 2.0f;

                            lock (s_backgroundImage)
                            {
                                // Scaled size of the background
                                double w = s_backgroundImage.PixelWidth * backgroundImageScale;
                                double h = s_backgroundImage.PixelHeight * backgroundImageScale;

                                // Offset of the background, relative to the canvas
                                double ox = (float)(-ctx.tileRect.Left * ctx.scale * Astrometrics.ParsecScaleX) % w;
                                double oy = (float)(-ctx.tileRect.Top * ctx.scale * Astrometrics.ParsecScaleY) % h;
                                if (ox > 0) ox -= w;
                                if (oy > 0) oy -= h;

                                // Number of copies needed to cover the canvas
                                int nx = 1 + (int)Math.Floor(ctx.tileSize.Width / w);
                                int ny = 1 + (int)Math.Floor(ctx.tileSize.Height / h);
                                if (ox + nx * w < ctx.tileSize.Width) nx += 1;
                                if (oy + ny * h < ctx.tileSize.Height) ny += 1;

                                for (int x = 0; x < nx; ++x)
                                {
                                    for (int y = 0; y < ny; ++y)
                                    {
                                        ctx.graphics.DrawImage(s_backgroundImage, ox + x * w, oy + y * h, w + 1, h + 1);
                                        //ctx.graphics.DrawRectangle( XPens.Orange, ox + x * w, oy + y * h, w, h );
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                    timers.Add(new Timer("background (nebula)"));

                    //------------------------------------------------------------
                    // Deep background (Galaxy)
                    //------------------------------------------------------------
                    #region galaxy-background
                    if (ctx.styles.useGalaxyImage && ctx.styles.deepBackgroundOpacity > 0f)
                    {
                        using (RenderUtil.SaveState(ctx.graphics))
                        {
                            ctx.graphics.MultiplyTransform(xformLinehanToMikesh);
                            ImageHolder galaxyImage = ctx.styles.lightBackground ? s_galaxyImageGray : s_galaxyImage;
                            lock (galaxyImage)
                            {
                                RenderUtil.DrawImageAlpha(ctx.graphics, ctx.styles.deepBackgroundOpacity, galaxyImage, galaxyImageRect);
                            }
                        }
                    }
                    #endregion
                    timers.Add(new Timer("background (galaxy)"));

                    //------------------------------------------------------------
                    // Pseudo-Random Stars
                    //------------------------------------------------------------
                    #region pseudorandom-stars

                    if (ctx.styles.pseudoRandomStars.visible)
                    {
                        // Render pseudorandom stars based on the tile # and
                        // scale factor. Note that these are positioned in
                        // screen space, not world space.

                        //const int nStars = 75;
                        int nMinStars = ctx.tileSize.Width * ctx.tileSize.Height / 300;
                        int nStars = ctx.scale >= 1 ? nMinStars : (int)(nMinStars / ctx.scale);

                        // NOTE: For performance's sake, three different cases are considered:
                        // (1) Tile is entirely within charted space (most common) - just render
                        //     the pseudorandom stars into the tile
                        // (2) Tile intersects the galaxy bounds - render pseudorandom stars
                        //     into a texture, then fill the galaxy vector with it
                        // (3) Tile is entire outside the galaxy - don't render stars

                        using (RenderUtil.SaveState(ctx.graphics))
                        {
                            ctx.graphics.SmoothingMode = XSmoothingMode.HighQuality;
                            solidBrush.Color = ctx.styles.pseudoRandomStars.fillColor;

                            Random rand = new Random((((int)ctx.tileRect.Left) << 8) ^ (int)ctx.tileRect.Top);
                            for (int i = 0; i < nStars; i++)
                            {
                                float starX = (float)rand.NextDouble() * ctx.tileRect.Width + ctx.tileRect.X;
                                float starY = (float)rand.NextDouble() * ctx.tileRect.Height + ctx.tileRect.Y;
                                float d = (float)rand.NextDouble() * 2;

                                //ctx.graphics.DrawRectangle( fonts.foregroundBrush, starX, starY, (float)( d / ctx.scale * Astrometrics.ParsecScaleX ), (float)( d / ctx.scale * Astrometrics.ParsecScaleY ) );
                                ctx.graphics.DrawEllipse(solidBrush, starX, starY, (float)(d / ctx.scale * Astrometrics.ParsecScaleX), (float)(d / ctx.scale * Astrometrics.ParsecScaleY));
                            }
                        }
                    }
                    #endregion
                    timers.Add(new Timer("pseudorandom"));

                    //------------------------------------------------------------
                    // Rifts in Charted Space
                    //------------------------------------------------------------
                    #region rifts

                    if (ctx.styles.showRifts && ctx.styles.riftOpacity > 0f)
                    {
                        Rectangle riftImageRect;
                        riftImageRect = new Rectangle(-1374, -827, 2769, 1754); // Correct
                        lock (s_riftImage)
                        {
                            RenderUtil.DrawImageAlpha(ctx.graphics, ctx.styles.riftOpacity, s_riftImage, riftImageRect);
                        }
                    }
                    #endregion
                    timers.Add(new Timer("rifts"));

                    //------------------------------------------------------------
                    // April Fool's Day
                    //------------------------------------------------------------
                    #region april-fools

                    if (ctx.silly)
                    {
                        using (RenderUtil.SaveState(ctx.graphics))
                        {
                            // Render in image-space
                            ctx.graphics.MultiplyTransform(worldSpaceToImageSpace);

                            XImage sillyImage = ctx.styles.grayscale ? s_sillyImageGray : s_sillyImageColor;

                            lock (sillyImage)
                            {
                                ctx.graphics.DrawImage(sillyImage, 0, 0, ctx.tileSize.Width, ctx.tileSize.Height);
                            }
                        }
                        timers.Add(new Timer("silly"));
                    }

                    #endregion

                    //------------------------------------------------------------
                    // Macro: Borders object
                    //------------------------------------------------------------
                    #region macro-borders
                    if (ctx.styles.macroBorders.visible)
                    {
                        ctx.styles.macroBorders.pen.Apply(ref pen);
                        ctx.graphics.SmoothingMode = XSmoothingMode.AntiAlias;
                        foreach (var vec in borderFiles
                            .Select(file => ctx.resourceManager.GetXmlFileObject(file, typeof(VectorObject)))
                            .OfType<VectorObject>()
                            .Where(vec => (vec.MapOptions & ctx.options & MapOptions.BordersMask) != 0))
                        {
                            vec.Draw(ctx.graphics, ctx.tileRect, ctx.options, pen);
                        }

                    }
                    #endregion
                    timers.Add(new Timer("macro-borders"));

                    //------------------------------------------------------------
                    // Macro: Route object
                    //------------------------------------------------------------
                    #region macro-routes

                    if (ctx.styles.macroRoutes.visible)
                    {
                        ctx.styles.macroRoutes.pen.Apply(ref pen);
                        ctx.graphics.SmoothingMode = XSmoothingMode.AntiAlias;
                        foreach (var vec in routeFiles
                            .Select(file => ctx.resourceManager.GetXmlFileObject(file, typeof(VectorObject)))
                            .OfType<VectorObject>()
                            .Where(vec => (vec.MapOptions & ctx.options & MapOptions.BordersMask) != 0))
                        {
                            vec.Draw(ctx.graphics, ctx.tileRect, ctx.options, pen);
                        }
                    }
                    #endregion
                    timers.Add(new Timer("macro-routes"));

                    //------------------------------------------------------------
                    // Sector Grid
                    //------------------------------------------------------------
                    #region sector-grid

                    ctx.graphics.SmoothingMode = XSmoothingMode.HighSpeed;

                    if (ctx.styles.sectorGrid.visible)
                    {
                        const int gridSlop = 10;
                        ctx.styles.sectorGrid.pen.Apply(ref pen);

                        for (float h = ((float)(Math.Floor((ctx.tileRect.Left) / Astrometrics.SectorWidth) - 1) - Astrometrics.ReferenceSector.X) * Astrometrics.SectorWidth - Astrometrics.ReferenceHex.X; h <= ctx.tileRect.Right + Astrometrics.SectorWidth; h += Astrometrics.SectorWidth)
                            ctx.graphics.DrawLine(pen, h, ctx.tileRect.Top - gridSlop, h, ctx.tileRect.Bottom + gridSlop);

                        for (float v = ((float)(Math.Floor((ctx.tileRect.Top) / Astrometrics.SectorHeight) - 1) - Astrometrics.ReferenceSector.Y) * Astrometrics.SectorHeight - Astrometrics.ReferenceHex.Y; v <= ctx.tileRect.Bottom + Astrometrics.SectorHeight; v += Astrometrics.SectorHeight)
                            ctx.graphics.DrawLine(pen, ctx.tileRect.Left - gridSlop, v, ctx.tileRect.Right + gridSlop, v);
                    }

                    #endregion
                    timers.Add(new Timer("sector grid"));

                    //------------------------------------------------------------
                    // Subsector Grid
                    //------------------------------------------------------------
                    #region subsector-grid
                    ctx.graphics.SmoothingMode = XSmoothingMode.HighSpeed;
                    if (ctx.styles.subsectorGrid.visible)
                    {
                        const int gridSlop = 10;
                        ctx.styles.subsectorGrid.pen.Apply(ref pen);

                        int hmin = (int)Math.Floor(ctx.tileRect.Left / Astrometrics.SubsectorWidth) - 1 - Astrometrics.ReferenceSector.X,
                            hmax = (int)Math.Ceiling((ctx.tileRect.Right + Astrometrics.SubsectorWidth + Astrometrics.ReferenceHex.X) / Astrometrics.SubsectorWidth);
                        for (int hi = hmin; hi <= hmax; ++hi)
                        {
                            if (hi % 4 == 0) continue;
                            float h = hi * Astrometrics.SubsectorWidth - Astrometrics.ReferenceHex.X;
                            ctx.graphics.DrawLine(pen, h, ctx.tileRect.Top - gridSlop, h, ctx.tileRect.Bottom + gridSlop);
                        }

                        int vmin = (int)Math.Floor(ctx.tileRect.Top / Astrometrics.SubsectorHeight) - 1 - Astrometrics.ReferenceSector.Y,
                            vmax = (int)Math.Ceiling((ctx.tileRect.Bottom + Astrometrics.SubsectorHeight + Astrometrics.ReferenceHex.Y) / Astrometrics.SubsectorHeight);
                        for (int vi = vmin; vi <= vmax; ++vi)
                        {
                            if (vi % 4 == 0) continue;
                            float v = vi * Astrometrics.SubsectorHeight - Astrometrics.ReferenceHex.Y;
                            ctx.graphics.DrawLine(pen, ctx.tileRect.Left - gridSlop, v, ctx.tileRect.Right + gridSlop, v);
                        }
                    }
                    #endregion
                    timers.Add(new Timer("subsector grid"));

                    //------------------------------------------------------------
                    // Parsec Grid
                    //------------------------------------------------------------
                    #region parsec-grid
                    // TODO: Optimize - timers indicate this is slow
                    ctx.graphics.SmoothingMode = XSmoothingMode.HighQuality;
                    if (ctx.styles.parsecGrid.visible)
                    {
                        const int parsecSlop = 1;

                        int hx = (int)Math.Floor(ctx.tileRect.Left);
                        int hw = (int)Math.Ceiling(ctx.tileRect.Width);
                        int hy = (int)Math.Floor(ctx.tileRect.Top);
                        int hh = (int)Math.Ceiling(ctx.tileRect.Height);

                        ctx.styles.parsecGrid.pen.Apply(ref pen);

                        switch (ctx.styles.hexStyle)
                        {
                            case HexStyle.Square:
                                for (int px = hx - parsecSlop; px < hx + hw + parsecSlop; px++)
                                {
                                    float yOffset = ((px % 2) != 0) ? 0.0f : 0.5f;
                                    for (int py = hy - parsecSlop; py < hy + hh + parsecSlop; py++)
                                    {
                                        // TODO: use RenderUtil.(Square|Hex)Edges(X|Y) arrays
                                        const float inset = 0.1f;
                                        ctx.graphics.DrawRectangle(pen, px + inset, py + inset + yOffset, 1 - inset * 2, 1 - inset * 2);
                                    }
                                }
                                break;

                            case HexStyle.Hex:
                                XPoint[] points = new XPoint[4];
                                for (int px = hx - parsecSlop; px < hx + hw + parsecSlop; px++)
                                {
                                    double yOffset = ((px % 2) != 0) ? 0.0 : 0.5;
                                    for (int py = hy - parsecSlop; py < hy + hh + parsecSlop; py++)
                                    {
                                        points[0] = new XPoint(px + -RenderUtil.HEX_EDGE, py + 0.5 + yOffset);
                                        points[1] = new XPoint(px + RenderUtil.HEX_EDGE, py + 1.0 + yOffset);
                                        points[2] = new XPoint(px + 1.0 - RenderUtil.HEX_EDGE, py + 1.0 + yOffset);
                                        points[3] = new XPoint(px + 1.0 + RenderUtil.HEX_EDGE, py + 0.5 + yOffset);
                                        ctx.graphics.DrawLines(pen, points);
                                    }
                                }
                                break;
                            case HexStyle.None:
                                // none
                                break;
                        }

                        if (ctx.styles.numberAllHexes &&
                            ctx.styles.worldDetails.HasFlag(WorldDetails.Hex))
                        {
                            solidBrush.Color = ctx.styles.hexNumber.textColor;
                            for (int px = hx - parsecSlop; px < hx + hw + parsecSlop; px++)
                            {
                                double yOffset = ((px % 2) != 0) ? 0.0 : 0.5;
                                for (int py = hy - parsecSlop; py < hy + hh + parsecSlop; py++)
                                {
                                    Location loc = Astrometrics.CoordinatesToLocation(px + 1, py + 1);
                                    string hex;
                                    switch (ctx.styles.hexCoordinateStyle)
                                    {
                                        default:
                                        case Stylesheet.HexCoordinateStyle.Sector: hex = loc.HexString; break;
                                        case Stylesheet.HexCoordinateStyle.Subsector: hex = loc.SubsectorHexString; break;
                                    }
                                    using (RenderUtil.SaveState(ctx.graphics))
                                    {
                                        XMatrix matrix = new XMatrix();
                                        matrix.TranslatePrepend(px + 0.5f, py + yOffset);
                                        matrix.ScalePrepend(ctx.styles.hexContentScale / Astrometrics.ParsecScaleX, ctx.styles.hexContentScale / Astrometrics.ParsecScaleY);
                                        ctx.graphics.MultiplyTransform(matrix, XMatrixOrder.Prepend);
                                        ctx.graphics.DrawString(hex, ctx.styles.hexNumber.Font, solidBrush, 0, 0, RenderUtil.StringFormatTopCenter);
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                    timers.Add(new Timer("parsec grid"));

                    //------------------------------------------------------------
                    // Subsector Names
                    //------------------------------------------------------------
                    #region subsector-names

                    if (ctx.styles.subsectorNames.visible)
                    {
                        solidBrush.Color = ctx.styles.subsectorNames.textColor;
                        foreach (Sector sector in ctx.selector.Sectors)
                        {
                            for (int i = 0; i < 16; i++)
                            {
                                int ssx = i % 4;
                                int ssy = i / 4;

                                Subsector ss = sector[i];
                                if (ss == null || String.IsNullOrEmpty(ss.Name))
                                    continue;

                                Point center = sector.SubsectorCenter(i);
                                RenderUtil.DrawLabel(ctx.graphics, ss.Name, center, ctx.styles.subsectorNames.Font, solidBrush, ctx.styles.subsectorNames.textStyle);
                            }
                        }
                    }

                    #endregion
                    timers.Add(new Timer("subsector names"));

                    //------------------------------------------------------------
                    // Micro: Borders
                    //------------------------------------------------------------
                    #region micro-borders
                    if (ctx.styles.microBorders.visible)
                    {
                        if (ctx.styles.fillMicroBorders)
                            DrawMicroBorders(ctx, BorderLayer.Fill);
                        DrawMicroBorders(ctx, BorderLayer.Stroke);
                    }
                    #endregion
                    timers.Add(new Timer("micro-borders"));

                    //------------------------------------------------------------
                    // Micro: Routes
                    //------------------------------------------------------------
                    #region micro-routes

                    if (ctx.styles.microRoutes.visible)
                        DrawRoutes(ctx, fonts);

                    #endregion
                    timers.Add(new Timer("micro-routes"));

                    //------------------------------------------------------------
                    // Sector Names
                    //------------------------------------------------------------
                    #region sector-names

                    if (ctx.styles.showSomeSectorNames || ctx.styles.showAllSectorNames)
                    {
                        foreach (Sector sector in ctx.selector.Sectors
                            .Where(sector => ctx.styles.showAllSectorNames || (ctx.styles.showSomeSectorNames && sector.Selected))
                            .Where(sector => sector.Names.Any() || sector.Label != null))
                        {
                            solidBrush.Color = ctx.styles.sectorName.textColor;
                            string name = sector.Label ?? sector.Names[0].Text;

                            RenderUtil.DrawLabel(ctx.graphics, name, sector.Center, ctx.styles.sectorName.Font, solidBrush, ctx.styles.sectorName.textStyle);
                        }
                    }

                    #endregion
                    timers.Add(new Timer("sector names"));

                    //------------------------------------------------------------
                    // Mega: Galaxy-Scale Labels
                    //------------------------------------------------------------
                    #region mega-names
                    if (ctx.styles.megaNames.visible)
                    {
                        solidBrush.Color = ctx.styles.megaNames.textColor;
                        foreach (var label in megaLabels)
                        {
                            using (RenderUtil.SaveState(ctx.graphics))
                            {
                                XMatrix matrix = new XMatrix();
                                matrix.ScalePrepend(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY);
                                matrix.TranslatePrepend(label.position.X, label.position.Y);
                                ctx.graphics.MultiplyTransform(matrix, XMatrixOrder.Prepend);

                                XFont font = label.minor ? ctx.styles.megaNames.SmallFont : ctx.styles.megaNames.Font;
                                XSize size = ctx.graphics.MeasureString(label.text, font);
                                ctx.graphics.TranslateTransform(-size.Width / 2, -size.Height / 2); // Center the text
                                RectangleF textBounds = new RectangleF(0, 0, (float)size.Width * 1.01f, (float)size.Height * 2); // *2 or it gets cut off at high sizes
                                XTextFormatter formatter = new XTextFormatter(ctx.graphics);
                                formatter.Alignment = XParagraphAlignment.Center;
                                formatter.DrawString(label.text, font, solidBrush, textBounds);
                            }
                        }
                    }
                    #endregion
                    timers.Add(new Timer("mega names"));

                    //------------------------------------------------------------
                    // Macro: Government / Rift / Route Names
                    //------------------------------------------------------------
                    #region government-rift-names
                    if (ctx.styles.macroNames.visible)
                    {
                        foreach (var vec in borderFiles
                            .Select(file => ctx.resourceManager.GetXmlFileObject(file, typeof(VectorObject)))
                            .OfType<VectorObject>()
                            .Where(vec => (vec.MapOptions & ctx.options & MapOptions.NamesMask) != 0))
                        {
                            bool major = vec.MapOptions.HasFlag(MapOptions.NamesMajor);
                            LabelStyle labelStyle = new LabelStyle();
                            labelStyle.Uppercase = major;
                            XFont font = major ? ctx.styles.macroNames.Font : ctx.styles.macroNames.SmallFont;
                            solidBrush.Color = major ? ctx.styles.macroNames.textColor : ctx.styles.macroNames.textHighlightColor;
                            vec.DrawName(ctx.graphics, ctx.tileRect, ctx.options, font, solidBrush, labelStyle);
                        }

                        foreach (var vec in riftFiles
                            .Select(file => ctx.resourceManager.GetXmlFileObject(file, typeof(VectorObject)))
                            .OfType<VectorObject>()
                            .Where(vec => (vec.MapOptions & ctx.options & MapOptions.NamesMask) != 0))
                        {
                            bool major = vec.MapOptions.HasFlag(MapOptions.NamesMajor);
                            LabelStyle labelStyle = new LabelStyle();
                            labelStyle.Rotation = 35;
                            labelStyle.Uppercase = major;
                            XFont font = major ? ctx.styles.macroNames.Font : ctx.styles.macroNames.SmallFont;
                            solidBrush.Color = major ? ctx.styles.macroNames.textColor : ctx.styles.macroNames.textHighlightColor;
                            vec.DrawName(ctx.graphics, ctx.tileRect, ctx.options, font, solidBrush, labelStyle);
                        }

                        if (ctx.styles.macroRoutes.visible)
                        {
                            foreach (var vec in routeFiles
                                .Select(file => ctx.resourceManager.GetXmlFileObject(file, typeof(VectorObject)))
                                .OfType<VectorObject>()
                                .Where(vec => (vec.MapOptions & ctx.options & MapOptions.NamesMask) != 0))
                            {
                                bool major = vec.MapOptions.HasFlag(MapOptions.NamesMajor);
                                LabelStyle labelStyle = new LabelStyle();
                                labelStyle.Uppercase = major;
                                XFont font = major ? ctx.styles.macroNames.Font : ctx.styles.macroNames.SmallFont;
                                solidBrush.Color = major ? ctx.styles.macroRoutes.textColor : ctx.styles.macroRoutes.textHighlightColor;
                                vec.DrawName(ctx.graphics, ctx.tileRect, ctx.options, font, solidBrush, labelStyle);
                            }
                        }

                        if (ctx.options.HasFlag(MapOptions.NamesMinor))
                        {
                            XFont font = ctx.styles.macroNames.MediumFont;
                            solidBrush.Color = ctx.styles.macroRoutes.textHighlightColor;
                            foreach (var label in labels)
                            {
                                using (RenderUtil.SaveState(ctx.graphics))
                                {
                                    XMatrix matrix = new XMatrix();
                                    matrix.ScalePrepend(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY);
                                    matrix.TranslatePrepend(label.position.X, label.position.Y);
                                    ctx.graphics.MultiplyTransform(matrix, XMatrixOrder.Prepend);

                                    XSize size = ctx.graphics.MeasureString(label.text, font);
                                    ctx.graphics.TranslateTransform(-size.Width / 2, -size.Height / 2); // Center the text
                                    RectangleF textBounds = new RectangleF(0, 0, (float)size.Width, (float)size.Height * 2); // *2 or it gets cut off at high sizes
                                    XTextFormatter formatter = new XTextFormatter(ctx.graphics);
                                    formatter.Alignment = XParagraphAlignment.Center;
                                    formatter.DrawString(label.text, font, solidBrush, textBounds);
                                }
                            }

                        }
                    }

                    #endregion
                    timers.Add(new Timer("macro names"));

                    //------------------------------------------------------------
                    // Macro: Capitals & Home Worlds
                    //------------------------------------------------------------
                    #region capitals-homeworlds

                    if (ctx.styles.capitals.visible && (ctx.options & MapOptions.WorldsMask) != 0)
                    {
                        WorldObjectCollection worlds = ctx.resourceManager.GetXmlFileObject(@"~/res/Worlds.xml", typeof(WorldObjectCollection)) as WorldObjectCollection;
                        if (worlds != null)
                        {
                            solidBrush.Color = ctx.styles.capitals.textColor;
                            foreach (WorldObject world in worlds.Worlds.Where(world => (world.MapOptions & ctx.options) != 0))
                            {
                                world.Paint(ctx.graphics, ctx.tileRect, ctx.options, ctx.styles.capitals.fillColor,
                                    solidBrush, ctx.styles.macroNames.SmallFont);
                            }
                        }
                    }

                    #endregion
                    timers.Add(new Timer("macro worlds"));

                    //------------------------------------------------------------
                    // Micro: Border Labels & Explicit Labels
                    //------------------------------------------------------------
                    #region micro-border-labels

                    if (ctx.styles.showMicroNames)
                        DrawLabels(ctx, fonts);

                    #endregion
                    timers.Add(new Timer("micro-border labels"));
                }

                // End of clipping, so world names are not clipped in jumpmaps.

                //------------------------------------------------------------
                // Worlds
                //------------------------------------------------------------
                #region worlds
                if (ctx.styles.worlds.visible)
                {
                    // TODO: selector may be expensive
                    foreach (World world in ctx.selector.Worlds) { DrawWorld(ctx, fonts, world, WorldLayer.Background); }
                    foreach (World world in ctx.selector.Worlds) { DrawWorld(ctx, fonts, world, WorldLayer.Foreground); }
                }
                #endregion
                timers.Add(new Timer("worlds"));

                //------------------------------------------------------------
                // Unofficial
                //------------------------------------------------------------
                #region unofficial

                if (ctx.styles.dimUnofficialSectors && ctx.styles.worlds.visible)
                {
                    solidBrush.Color = Color.FromArgb(128, ctx.styles.backgroundColor);
                    foreach (Sector sector in ctx.selector.Sectors
                        .Where(sector => !sector.Tags.Contains("Official") && !sector.Tags.Contains("Preserve") && !sector.Tags.Contains("InReview")))
                        ctx.graphics.DrawRectangle(solidBrush, sector.Bounds);
                }

                #endregion

            #if SHOW_TIMING
                using( RenderUtil.SaveState( ctx.graphics ) )
                {
                    XFont font = new XFont( FontFamily.GenericSansSerif, 12, XFontStyle.Regular, new XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode) );
                    ctx.graphics.MultiplyTransform( worldSpaceToImageSpace );
                    double cursorX = 20.0, cursorY = 20.0;
                    DateTime last = dtStart;
                    foreach( Timer s in timers )
                    {
                        TimeSpan ts = s.dt - last;
                        last = s.dt;
                        for( int dx = -1; dx <= 1; ++dx )
                        {
                            for( int dy = -1; dy <= 1; ++dy )
                            {

                                ctx.graphics.DrawString( String.Format( "{0} {1}", Math.Round( ts.TotalMilliseconds ), s.label ), font, XBrushes.Black, cursorX + dx, cursorY + dy );
                            }
                        }
                        ctx.graphics.DrawString( String.Format("{0} {1}", Math.Round(ts.TotalMilliseconds), s.label), font, XBrushes.Yellow, cursorX, cursorY );
                        cursorY += 14;
                    }
                }
            #endif

            }
        }
コード例 #21
0
ファイル: DocumentManager.cs プロジェクト: rymbln/WPFDB
 private static void DrawText(XGraphics gfx, string text, string font, string style, double size, string color, int width, int height, int x, int y)
 {
     XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Default);
     XFont fontStyle = null;
     switch (style)
     {
         case "Bold":
             fontStyle = new XFont(font, size, XFontStyle.Bold, options);
             break;
         case "Italic":
             fontStyle = new XFont(font, size, XFontStyle.Italic, options);
             break;
         case "Regular":
             fontStyle = new XFont(font, size, XFontStyle.Regular, options);
             break;
         case "Underline":
             fontStyle = new XFont(font, size, XFontStyle.Underline, options);
             break;
         case "Strikeout":
             fontStyle = new XFont(font, size, XFontStyle.Strikeout, options);
             break;
         case "BoldItalic":
             fontStyle = new XFont(font, size, XFontStyle.BoldItalic, options);
             break;
         default:
             break;
     }
     System.Drawing.Color fontColor = ConverterManager.HexToColorConverter(color);
     XBrush fontBrush = new XSolidBrush(new XColor { R = fontColor.R, G = fontColor.G, B = fontColor.B });
     XRect fontRect = new XRect(x, y, width, height);
     XStringFormat fontFormat = new XStringFormat { Alignment = XStringAlignment.Center };
     gfx.DrawString(text, fontStyle, fontBrush, fontRect, fontFormat);
 }
コード例 #22
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="gfx"></param>
 /// <param name="brush"></param>
 /// <param name="pen"></param>
 /// <param name="isStroked"></param>
 /// <param name="isFilled"></param>
 /// <param name="rect"></param>
 private static void DrawRectangleInternal(
     XGraphics gfx,
     XSolidBrush brush,
     XPen pen,
     bool isStroked,
     bool isFilled,
     ref XRect rect)
 {
     if (isStroked && isFilled)
     {
         gfx.DrawRectangle(pen, brush, rect);
     }
     else if (isStroked && !isFilled)
     {
         gfx.DrawRectangle(pen, rect);
     }
     else if (!isStroked && isFilled)
     {
         gfx.DrawRectangle(brush, rect);
     }
 }
コード例 #23
0
ファイル: FlightPlanForm.cs プロジェクト: hrishi18pathak/QNP
        private void drawGridOnPdfdocument(DataGridView displayGrid, XGraphics gfx, int displayXOffset, int displayYOffset)
        {
            XColor back = XColors.Transparent;
            back.A = 0.1;
            XSolidBrush BorderBrush = new XSolidBrush(back);
            XPen pen = new XPen(XColors.Gray, 1);
            //Side Panels
            double height = displayGrid.Height + 5;
            double width = displayGrid.Width + 7;
            gfx.DrawRoundedRectangle(pen, BorderBrush, displayGrid.Location.X - 8, displayGrid.Location.Y - 20 + displayYOffset, width, height, 10, 10);
            gfx.DrawRoundedRectangle(pen, BorderBrush, displayGrid.Location.X - 5, displayGrid.Location.Y + 365, 1058, 28, 5, 5);
            XFont headerfont = new XFont("Aerial", 13, XFontStyle.Bold);
            XTextFormatter tf = new XTextFormatter(gfx);
            XPen newPen = new XPen(Color.Black);
            XColor fillColor = XColors.DarkOrange;
            XBrush brush = new XSolidBrush(fillColor);
            fillColor.A = 0.8;

            int headerOffset = 0;
            foreach (DataGridViewColumn colmn in displayGrid.Columns)
            {
                if (colmn.Visible)
                {
                    Rectangle header_rect = displayGrid.GetCellDisplayRectangle(colmn.Index, -1, false);
                    XRect pdf_rect = new XRect(header_rect.X + displayXOffset, header_rect.Y + displayYOffset, header_rect.Width, header_rect.Height);
                    headerOffset = header_rect.Height;
                    gfx.DrawRectangle(newPen, pdf_rect);
                    tf.Alignment = XParagraphAlignment.Center;
                    tf.DrawString(colmn.HeaderText, headerfont, XBrushes.Black, pdf_rect, XStringFormats.TopLeft);
                }

            }

            XFont font = new XFont("Aerial", 13, XFontStyle.Bold);
            foreach (DataGridViewRow dgRow in displayGrid.Rows)
                foreach (DataGridViewColumn dgCol in displayGrid.Columns)
                {
                    if (dgCol.Visible)
                    {
                        Rectangle rect = displayGrid.GetCellDisplayRectangle(dgCol.Index, dgRow.Index, true);
                        XRect pdf_rect = new XRect(rect.X + displayXOffset, rect.Y + displayYOffset, rect.Width, rect.Height);
                        gfx.DrawRectangle(newPen, pdf_rect);
                        tf.Alignment = XParagraphAlignment.Center;
                        string displayText = getCellFormatedValue(displayGrid.Rows[dgRow.Index].Cells[dgCol.Index]);
                        tf.DrawString(displayText, headerfont, XBrushes.Black, pdf_rect, XStringFormats.TopLeft);
                    }

                }
        }
コード例 #24
0
ファイル: Render.cs プロジェクト: Matt--/travellermap
        private static void DrawWorldLabel(RenderContext ctx, TextBackgroundStyle backgroundStyle, XSolidBrush brush, Color color, PointF position, XFont font, string text)
        {
            XSize size = ctx.graphics.MeasureString(text, font);

            switch (backgroundStyle)
            {
                case TextBackgroundStyle.None:
                    break;

                default:
                case TextBackgroundStyle.Rectangle:
                    if (!ctx.styles.fillMicroBorders)
                    {
                        // TODO: Implement this with a clipping region instead
                        brush.Color = ctx.styles.backgroundColor;
                        ctx.graphics.DrawRectangle(brush, position.X - size.Width / 2, position.Y - size.Height / 2, size.Width, size.Height);
                    }
                    break;

                case TextBackgroundStyle.Outline:
                case TextBackgroundStyle.Shadow:
                    {
                        // TODO: These scaling factors are constant for a render; compute once

                        // Invert the current scaling transforms
                        float sx = 1.0f / ctx.styles.hexContentScale;
                        float sy = 1.0f / ctx.styles.hexContentScale;
                        sx *= Astrometrics.ParsecScaleX;
                        sy *= Astrometrics.ParsecScaleY;
                        sx /= (float)ctx.scale * Astrometrics.ParsecScaleX;
                        sy /= (float)ctx.scale * Astrometrics.ParsecScaleY;

                        const int outlineSize = 2;
                        const int outlineSkip = 1;

                        int outlineStart = backgroundStyle == TextBackgroundStyle.Outline
                            ? -outlineSize
                            : 0;

                        brush.Color = ctx.styles.backgroundColor;

                        for (int dx = outlineStart; dx <= outlineSize; dx += outlineSkip)
                        {
                            for (int dy = outlineStart; dy <= outlineSize; dy += outlineSkip)
                            {
                                ctx.graphics.DrawString(text, font, brush, position.X + sx * dx, position.Y + sy * dy, RenderUtil.StringFormatCentered);
                            }
                        }
                        break;
                    }
            }

            brush.Color = color;
            ctx.graphics.DrawString(text, font, brush, position.X, position.Y, RenderUtil.StringFormatCentered);
        }
コード例 #25
0
ファイル: VectorObject.cs プロジェクト: Matt--/travellermap
        public void Paint(XGraphics graphics, RectangleF rect, MapOptions options, Color dotColor, XBrush labelBrush, XFont labelFont)
        {
            if (graphics == null)
                throw new ArgumentNullException("graphics");

            Point pt = Astrometrics.LocationToCoordinates(Location);

            using (RenderUtil.SaveState(graphics))
            {

                graphics.SmoothingMode = XSmoothingMode.HighSpeed;
                graphics.TranslateTransform(pt.X, pt.Y);
                graphics.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY);

                const float radius = 3;

                XBrush brush = new XSolidBrush(dotColor);
                XPen pen = new XPen(dotColor);
                graphics.DrawEllipse(brush, -radius / 2, -radius / 2, radius, radius);

                graphics.SmoothingMode = XSmoothingMode.HighQuality;
                graphics.DrawEllipse(pen, -radius / 2, -radius / 2, radius, radius);

                XStringFormat format = (LabelBiasX == -1) ? RenderUtil.StringFormatTopRight :
                    (LabelBiasX == 1) ? RenderUtil.StringFormatTopLeft : RenderUtil.StringFormatTopCenter;

                XSize size = graphics.MeasureString(Name, labelFont);
                XPoint pos = new XPoint(0, 0);

                //pos.X += ( LabelBiasX * radius / 2 ) + ( -size.Width  * ( 1 - LabelBiasX ) / 2.0f );
                pos.Y += (LabelBiasY * radius / 2) + (-size.Height * (1 - LabelBiasY) / 2.0f);
                pos.X += (LabelBiasX * radius / 2);
                //pos.Y += ( LabelBiasY * radius / 2 );

                graphics.DrawString(Name, labelFont, labelBrush, pos.X, pos.Y, format);

            }
        }
コード例 #26
0
ファイル: DrukWplaty.cs プロジェクト: fraczo/BR5
        public static bool Attach_DrukWplatyPD(SPWeb web, SPListItem item, string nazwaPliku, string odbiorca, string numerRachunku, double kwotaDoZaplaty, string zleceniodawca, string nip, string typIdentyfikatora, string okres, string symbolFormularza, string identyfikacjaZobowiazania)
        {
            const int maxLen = 27;
            odbiorca = odbiorca.ToUpper();
            zleceniodawca = zleceniodawca.ToUpper();

            //unormowanie nazwy pliku
            nazwaPliku = CleanupFileName(nazwaPliku);

            if (numerRachunku.Length != 26)
            {
                return false;
            }

            if (item.Attachments.Count > 0)
            {
                foreach (string fname in item.Attachments)
                {
                    if (fname == nazwaPliku)
                    {
                        item.Attachments.DeleteNow(fname);
                        break;
                    }
                }
            }

            string pdfFilePath = @"SiteAssets/Templates/DW-Podatek.pdf";
            int x0 = 90;
            int dx = 136;
            int y0 = 74;
            int dy = 76;
            double ofset0 = 14.3;
            int c01 = 3;
            int r01 = 7;
            int r02 = 31;
            int r03 = 55;
            int c02 = 218;
            int r04 = 81;
            int r05 = 103;
            int r06 = 127;
            int r07 = 152;
            int r08 = 176;
            int r09 = 200;


            SPFile file = web.GetFile(pdfFilePath);

            if (file.Exists)
            {
                int bufferSize = 20480;
                byte[] byteBuffer = new byte[bufferSize];
                //byteBuffer = File.ReadAllBytes(pdfFilePath);
                byteBuffer = file.OpenBinary();

                MemoryStream coverSheetContent = new MemoryStream();

                coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length);
                int t = PdfReader.TestPdfFile(coverSheetContent);
                PdfDocument document = PdfReader.Open(coverSheetContent);
                PdfPage page = document.Pages[0];

                XForm form = new XForm(document, XUnit.FromMillimeter(dx), XUnit.FromMillimeter(dy));
                XGraphics formGfx = XGraphics.FromForm(form);

                // Draw a large transparent rectangle to visualize the area the form occupies
#if DEBUG
                XColor back = XColors.Orange;
#else
                XColor back = XColors.White;
#endif

                back.A = 0.2;
                XSolidBrush brush = new XSolidBrush(back);
                formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);

                XFont font = new XFont("Verdana", 10, XFontStyle.Bold); //XFont("Verdana", 10, XFontStyle.Regular)

                string odbiorca2 = string.Empty;
                if (odbiorca.Length > maxLen)
                {
                    odbiorca2 = odbiorca.Substring(maxLen, odbiorca.Length - maxLen);
                    if (odbiorca2.Length > maxLen)
                    {
                        odbiorca2 = odbiorca2.Substring(0, maxLen);
                    }
                    odbiorca = odbiorca.Substring(0, maxLen);
                }

                PlotText(odbiorca, c01, r01, ofset0, formGfx, font);

                PlotText(odbiorca2, c01, r02, ofset0, formGfx, font);

                PlotText(numerRachunku, c01, r03, ofset0, formGfx, font);

                PlotText("X", c01 + (int)(9 * ofset0) + 2, r04 - 3, ofset0, formGfx, font);
                PlotText((string)(String.Format("{0:#0.00}", kwotaDoZaplaty) + "************").Substring(0, 12), c02, r04, ofset0, formGfx, font);

                int zlote = (int)kwotaDoZaplaty;
                int grosze = (int)(100 * kwotaDoZaplaty) % 100;
                string kwota = String.Format("{0} {1}",
                    KwotaSlownie.LiczbaSlownie(zlote),
                    grosze + "/100");

                formGfx.DrawString("*" + kwota + "*", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, c01, r05, XStringFormats.TopLeft);

                string zleceniodawca2 = string.Empty;
                if (zleceniodawca.Length > maxLen)
                {
                    zleceniodawca2 = zleceniodawca.Substring(maxLen, zleceniodawca.Length - maxLen);
                    if (zleceniodawca2.Length > maxLen)
                    {
                        zleceniodawca2 = zleceniodawca2.Substring(0, maxLen);
                    }
                    zleceniodawca = zleceniodawca.Substring(0, maxLen);
                }
                PlotText(zleceniodawca, c01, r06, ofset0, formGfx, font);
                PlotText(zleceniodawca2, c01, r07, ofset0, formGfx, font);

                PlotText(nip, c01, r08, ofset0, formGfx, font);
                PlotText(typIdentyfikatora, c01 + (int)(15 * ofset0), r08, ofset0, formGfx, font);
                PlotText(okres, c01 + (int)(19 * ofset0), r08, ofset0, formGfx, font);
                PlotText(symbolFormularza, c01, r09, ofset0, formGfx, font);
                PlotText(identyfikacjaZobowiazania, c01 + (int)(7 * ofset0), r09, ofset0, formGfx, font);


                XPen pen = XPens.LightBlue.Clone();
                pen.Width = 2.5;

                XGraphics gfx = XGraphics.FromPdfPage(page);

                // Draw the form on the page of the document in its original size
                gfx.DrawImage(form, x0, y0);
                gfx.DrawImage(form, x0, y0 + 300);

                MemoryStream ms = new MemoryStream();
                document.Save(ms);

                item.Attachments.AddNow(nazwaPliku, ms.GetBuffer());
                //item.SystemUpdate();

                return true;
            }

            else
            {
                return false;
            }


        }
コード例 #27
0
ファイル: DrukWplaty.cs プロジェクト: fraczo/BR5
        public static bool Attach_DrukWplatyZUS(SPWeb web, SPListItem item, string nazwaPliku, string numerRachunku, double kwotaDoZaplaty, string nadawca, string nip, string typIdentyfikatora, string drugiIdentyfikator, string identyfikatorDeklaracji)
        {
            const int maxLen = 27;

            nazwaPliku = CleanupFileName(nazwaPliku);

            if (numerRachunku.Length != 26)
            {
                return false;
            }
            else
            {
                numerRachunku = String.Format(@"{0}                  {1}", numerRachunku.Substring(0, 2), numerRachunku.Substring(20, 1));
            }

            if (item.Attachments.Count > 0)
            {
                foreach (string fname in item.Attachments)
                {
                    if (fname == nazwaPliku)
                    {
                        item.Attachments.DeleteNow(fname);
                        break;
                    }
                }
            }

            string pdfFilePath = @"SiteAssets/Templates/DW-ZUS.pdf";
            int x0 = 92;
            int dx = 135;
            int y0 = 76;
            int dy = 78;
            int formoffset = 304;

            double ofset0 = 14.15; //odstępo pomiędzy znakami
            double ofset1 = 24.1; //odstęp pomiędzy liniami

            int c01 = 3;
            int r01 = 58;
            int r02 = r01 + (int)(ofset1 * 1);
            int r03 = r01 + (int)(ofset1 * 2);
            int c02 = 215;
            int r04 = r01 + (int)(ofset1 * 3);
            int r05 = r01 + (int)(ofset1 * 4);
            int r06 = r01 + (int)(ofset1 * 5);
            int r07 = r01 + (int)(ofset1 * 6);



            SPFile file = web.GetFile(pdfFilePath);

            if (file.Exists)
            {
                int bufferSize = 20480;
                byte[] byteBuffer = new byte[bufferSize];
                byteBuffer = file.OpenBinary();

                MemoryStream coverSheetContent = new MemoryStream();

                coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length);
                int t = PdfReader.TestPdfFile(coverSheetContent);
                PdfDocument document = PdfReader.Open(coverSheetContent);
                PdfPage page = document.Pages[0];

                XForm form = new XForm(document, XUnit.FromMillimeter(dx), XUnit.FromMillimeter(dy));
                XGraphics formGfx = XGraphics.FromForm(form);
#if DEBUG
                XColor back = XColors.Orange;
#else
                XColor back = XColors.White;
#endif
                back.A = 0.2;
                XSolidBrush brush = new XSolidBrush(back);
                formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);

                XFont font = new XFont("Verdana", 10, XFontStyle.Bold);

                PlotText(numerRachunku, c01, r01, ofset0, formGfx, font);

                PlotText((string)(String.Format("{0:#0.00}", kwotaDoZaplaty) + "************").Substring(0, 12), c02, r02, ofset0, formGfx, font);

                int zlote = (int)kwotaDoZaplaty;
                int grosze = (int)(100 * kwotaDoZaplaty) % 100;
                string kwota = String.Format("{0} {1}",
                    KwotaSlownie.LiczbaSlownie(zlote),
                    grosze + "/100");

                formGfx.DrawString("*" + kwota + "*", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, c01, r03, XStringFormats.TopLeft);

                string nadawca2 = string.Empty;
                if (nadawca.Length > maxLen)
                {
                    nadawca2 = nadawca.Substring(maxLen, nadawca.Length - maxLen);
                    if (nadawca2.Length > maxLen)
                    {
                        nadawca2 = nadawca2.Substring(0, maxLen);
                    }
                    nadawca = nadawca.Substring(0, maxLen);
                }
                PlotText(nadawca, c01, r04, ofset0, formGfx, font);
                PlotText(nadawca2, c01, r05, ofset0, formGfx, font);

                PlotText(nip, c01, r06, ofset0, formGfx, font);
                PlotText(typIdentyfikatora, c01 + (int)(11 * ofset0), r06, ofset0, formGfx, font);
                PlotText(drugiIdentyfikator, c01 + (int)(13 * ofset0), r06, ofset0, formGfx, font);

                PlotText(identyfikatorDeklaracji, c01, r07, ofset0, formGfx, font);


                XPen pen = XPens.LightBlue.Clone();
                pen.Width = 2.5;

                XGraphics gfx = XGraphics.FromPdfPage(page);

                // Draw the form on the page of the document in its original size
                gfx.DrawImage(form, x0, y0);
                gfx.DrawImage(form, x0, y0 + formoffset);

                MemoryStream ms = new MemoryStream();
                document.Save(ms);

                item.Attachments.AddNow(nazwaPliku, ms.GetBuffer());
                //item.SystemUpdate();

                return true;
            }

            else
            {
                return false;
            }

        }
コード例 #28
0
ファイル: DrukWplaty.cs プロジェクト: fraczo/BR5
        public static bool Attach_DrukWplaty(SPWeb web, SPListItem item, string nazwaPliku, string odbiorca, string numerRachunku, double kwotaDoZaplaty, string zleceniodawca, string tytulem)
        {
            //const int maxLen = 27;
            const int maxLen = 46;
            odbiorca = odbiorca.ToUpper();
            zleceniodawca = zleceniodawca.ToUpper();
            tytulem = tytulem.ToUpper();

            //unormowanie nazwy pliku
            nazwaPliku = CleanupFileName(nazwaPliku);

            if (numerRachunku.Length != 26)
            {
                return false;
            }

            if (item.Attachments.Count > 0)
            {
                foreach (string fname in item.Attachments)
                {
                    if (fname == nazwaPliku)
                    {
                        item.Attachments.DeleteNow(fname);
                        break;
                    }
                }
            }

            string pdfFilePath = @"SiteAssets/Templates/DW-Przelew.pdf";
            int x0 = 89;
            int y0 = 76;

            //string pdfFilePath = @"SiteAssets/Templates/PolecenieWplaty-Template.pdf";
            //int x0 = 95;
            //int y0 = 115;

            //string pdfFilePath = @"SiteAssets/Templates/MyTemplate.pdf";

            SPFile file = web.GetFile(pdfFilePath);

            if (file.Exists)
            {
                int bufferSize = 20480;
                byte[] byteBuffer = new byte[bufferSize];
                //byteBuffer = File.ReadAllBytes(pdfFilePath);
                byteBuffer = file.OpenBinary();

                MemoryStream coverSheetContent = new MemoryStream();

                coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length);
                int t = PdfReader.TestPdfFile(coverSheetContent);
                PdfDocument document = PdfReader.Open(coverSheetContent);
                PdfPage page = document.Pages[0];

                // Create an empty XForm object with the specified width and height
                // A form is bound to its target document when it is created. The reason is that the form can 
                // share fonts and other objects with its target document.
                XForm form = new XForm(document, XUnit.FromMillimeter(138), XUnit.FromMillimeter(77));

                // Create an XGraphics object for drawing the contents of the form.
                XGraphics formGfx = XGraphics.FromForm(form);

                // Draw a large transparent rectangle to visualize the area the form occupies
                XColor back = XColors.Orange;
                back.A = 0.2;
                XSolidBrush brush = new XSolidBrush(back);
                formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);

                // On a form you can draw...

                // ... text

                XFont font = new XFont("Verdana", 10, XFontStyle.Bold); //XFont("Verdana", 10, XFontStyle.Regular)

                string odbiorca2 = string.Empty;
                if (odbiorca.Length > maxLen)
                {
                    odbiorca2 = odbiorca.Substring(maxLen, odbiorca.Length - maxLen);
                    if (odbiorca2.Length > maxLen)
                    {
                        odbiorca2 = odbiorca2.Substring(0, maxLen);
                    }
                    odbiorca = odbiorca.Substring(0, maxLen);
                }

                formGfx.DrawString(odbiorca, font, XBrushes.Navy, 8, 8, XStringFormats.TopLeft);
                formGfx.DrawString(odbiorca2, font, XBrushes.Navy, 8, 33, XStringFormats.TopLeft);
                //formGfx.DrawString("Numer rachunku odbiorcy przekazu pocztowego", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 8, 57, XStringFormats.TopLeft);

                int n = 0;
                formGfx.DrawString(numerRachunku.Substring(n, 2), font, XBrushes.Navy, 13, 57, XStringFormats.TopLeft); n = n + 2;

                int offset = 57;
                int targetX = 48;

                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 1 * offset, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 2 * offset, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 3 * offset, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 4 * offset, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 5 * offset, 57, XStringFormats.TopLeft);

                formGfx.DrawString("***" + String.Format("{0:#,0.00}", kwotaDoZaplaty) + "***", font, XBrushes.Navy, 220, 81, XStringFormats.TopLeft);

                int zlote = (int)kwotaDoZaplaty;
                int grosze = (int)(100 * kwotaDoZaplaty) % 100;
                string kwota = String.Format("{0} {1}",
                    KwotaSlownie.LiczbaSlownie(zlote),
                    grosze + "/100");

                formGfx.DrawString("***" + kwota + "***", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 8, 106, XStringFormats.TopLeft);

                string zleceniodawca2 = string.Empty;
                if (zleceniodawca.Length > maxLen)
                {
                    zleceniodawca2 = zleceniodawca.Substring(maxLen, zleceniodawca.Length - maxLen);
                    if (zleceniodawca2.Length > maxLen)
                    {
                        zleceniodawca2 = zleceniodawca2.Substring(0, maxLen);
                    }
                    zleceniodawca = zleceniodawca.Substring(0, maxLen);
                }
                formGfx.DrawString(zleceniodawca, font, XBrushes.Navy, 8, 130, XStringFormats.TopLeft);
                formGfx.DrawString(zleceniodawca2, font, XBrushes.Navy, 8, 154, XStringFormats.TopLeft);

                string tytulem2 = string.Empty;
                if (tytulem.Length > maxLen)
                {
                    tytulem2 = tytulem.Substring(maxLen, tytulem.Length - maxLen);
                    if (tytulem2.Length > maxLen)
                    {
                        tytulem2 = tytulem2.Substring(0, maxLen);
                    }
                    tytulem = tytulem.Substring(0, maxLen);
                }
                formGfx.DrawString(tytulem, font, XBrushes.Navy, 8, 178, XStringFormats.TopLeft);
                formGfx.DrawString(tytulem2, font, XBrushes.Navy, 8, 201, XStringFormats.TopLeft);




                XPen pen = XPens.LightBlue.Clone();
                pen.Width = 2.5;

                XGraphics gfx = XGraphics.FromPdfPage(page);

                // Draw the form on the page of the document in its original size
                gfx.DrawImage(form, x0, y0);
                gfx.DrawImage(form, x0, y0 + 300);

                MemoryStream ms = new MemoryStream();
                document.Save(ms);

                item.Attachments.AddNow(nazwaPliku, ms.GetBuffer());
                //item.SystemUpdate();

                return true;
            }

            else
            {
                return false;
            }


        }
コード例 #29
0
        private static void PrepareInvoiceTop(XGraphics formGfx, XGraphicsState state, string InvoiceNumber)
        {
            string Headline = "Service Invoice " + InvoiceNumber + "";
            string MyName = TimeConnector.Data.Variables.SelectedContractor["CmpName"];
            string Phone = TimeConnector.Data.Variables.SelectedContractorContact["ConPhone"];
            string MyPhone = "Phone (" + Phone.Substring(0, 3) + ") " + Phone.Substring(4, 3) + "-" + Phone.Substring(7, 4) + "";
            string MyEmail = "Email: " + TimeConnector.Data.Variables.SelectedContractorContact["ConEmail"] + "";
            string MyAddress = TimeConnector.Data.Variables.SelectedContractor["CmpAddress"];
            string MyCityStateZip = "" + TimeConnector.Data.Variables.SelectedContractor["CmpCity"] + ", " + TimeConnector.Data.Variables.SelectedContractor["CmpState"] + "  " + TimeConnector.Data.Variables.SelectedContractor["CmpZip"] + "";
            string WeekEnding = TimeConnector.Data.Variables.SelectedPaydate["WeekEnd"];
            string PayDate = TimeConnector.Data.Variables.SelectedPaydate["PayDate"];
            string CompanyName = TimeConnector.Data.Variables.SelectedCompany["CmpName"];
            string CompanyContact = "c/o " + TimeConnector.Data.Variables.SelectedContact["ConName"] + "";
            string CompanyContactPhone = "" + TimeConnector.Data.Variables.SelectedContact["ConPhone"] + "";
            string CompanyContactEmail = "" + TimeConnector.Data.Variables.SelectedContact["ConEmail"] + "";
            string CompanyAddress = TimeConnector.Data.Variables.SelectedCompany["CmpAddress"];
            string CompanyCityStateZip = "" + TimeConnector.Data.Variables.SelectedCompany["CmpCity"] + ", " + TimeConnector.Data.Variables.SelectedCompany["CmpState"] + "  " + TimeConnector.Data.Variables.SelectedCompany["CmpZip"] + "";

            //----- Invoice Header
            XFont HeaderFont = new XFont("Imprint MT Shadow", 30, XFontStyle.Bold);
            string HeaderText = "I N V O I C E";
            XStringFormat format = new XStringFormat();
            format.Alignment = XStringAlignment.Near;
            format.LineAlignment = XLineAlignment.Near;
            XColor color = default(XColor);
            color = XColor.FromName("SteelBlue");
            color.A = 0.5;
            XBrush brush = default(XBrush);
            brush = new XSolidBrush(color);
            XPoint point = new XPoint(410, 20);
            formGfx.DrawString(HeaderText, HeaderFont, brush, point, format);

            //..... My Company Icon
            state = formGfx.Save();
            formGfx.DrawImage(XImage.FromFile("Images\\logo.png"), 20, 20, 65, 65);
            formGfx.Restore(state);

            //..... My Company Information
            DrawText(MyName, formGfx, new XFont(PdfFontMyInfo, 15, XFontStyle.Bold), XBrushes.SteelBlue, 95, 20);
            DrawText(MyAddress, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 45);
            DrawText(MyCityStateZip, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 55);
            DrawText(MyPhone, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 65);
            DrawText(MyEmail, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 75);

            XPen pen1 = new XPen(XColors.Maroon);
            pen1.Width = 1;
            //Dim pen2 As New XPen(XColors.Maroon)
            XPen pen2 = new XPen(XColors.SteelBlue);
            pen2.Width = 2;
            //Dim pen3 As New XPen(XColors.SteelBlue)
            XPen pen3 = new XPen(XColors.Maroon);
            pen3.Width = 1;
            formGfx.DrawBeziers(pen1, XPoint.ParsePoints("20,95 80,140 190,70 250,110"));

            DrawSignature(formGfx, 531, 696, "LightGray", 1);
            DrawSignature(formGfx, 530, 695, "Black", 1.5);
            DrawSignature(formGfx, 530, 695, "SteelBlue", 1);

            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("300,100 310,110 340,90 350,100"))  'Top
            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("312,108 322,118 332,99 342,110")) 'Top Center
            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center
            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("310,130 315,140 330,120 335,130")) 'Bottom
            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center

            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("300,100 310,110 340,90 350,100"))  'Top
            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("312,108 322,118 332,99 342,110")) 'Top Center
            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center
            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("310,130 315,140 330,120 335,130")) 'Bottom
            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center

            //..... ACS Company Icon
            DrawText("B I L L   T O :", formGfx, new XFont(PdfFont, 9, XFontStyle.Bold), XBrushes.Black, 60, 95);
            state = formGfx.Save();
            formGfx.DrawImage(XImage.FromFile("Images\\ACSIcon.jpg"), 20, 115, 65, 65);
            formGfx.Restore(state);

            //..... ACS Company Information
            DrawText(CompanyName, formGfx, new XFont(PdfFontMyInfo, 15, XFontStyle.Bold), XBrushes.Green, 95, 115);
            DrawText(CompanyContact, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 135);
            DrawText(CompanyAddress, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 145);
            DrawText(CompanyCityStateZip, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 155);
            DrawText(CompanyContactPhone, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 165);
            DrawText(CompanyContactEmail, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 175);

            //..... Invoice Information
            DrawLine(formGfx, 450, 590, 80, "SteelBlue", 0.5);
            DrawText("Invoice #:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 71);
            DrawText(InvoiceNumber, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Maroon, 530, 71);
            DrawLine(formGfx, 450, 590, 90, "SteelBlue", 0.5);
            DrawText("Week Ending:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 81);
            DrawText(WeekEnding, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 81);
            DrawLine(formGfx, 450, 590, 100, "SteelBlue", 0.5);
            DrawText("Pay Date:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 91);
            DrawText(PayDate, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 91);
            DrawLine(formGfx, 450, 590, 110, "SteelBlue", 0.5);
            DrawText("Hours Worked:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 101);
            DrawText(TimeConnector.Data.Invoice.FinHour, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 101);
            DrawLine(formGfx, 450, 590, 120, "SteelBlue", 0.5);
            DrawText("Balance Due:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 111);
            DrawText(TimeConnector.Data.Invoice.FinCost, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 111);
        }
コード例 #30
0
 private static void DrawText(string text, XGraphics formGfx, XFont font, XSolidBrush color, double x, double y)
 {
     formGfx.DrawString(text, font, color, x, y, XStringFormats.TopLeft);
 }
コード例 #31
0
 private static void DrawFill(XGraphics formGfx, string Color, int Width, int Height, int Left, int Top)
 {
     XColor back = default(XColor);
     back = XColor.FromName(Color);
     back.A = 0.2;
     XSolidBrush brush = new XSolidBrush(back);
     formGfx.DrawRectangle(brush, Left, Top, Width, Height);
 }
コード例 #32
-1
        private static void RenderWord(string word, XGraphics gfx, XRect rect, int fontsize, string color = null)
        {
            XFont font = new XFont("Garamond", fontsize, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode));
            XBrush brush;
            if(string.IsNullOrEmpty(color))
                brush = XBrushes.Black;
            else
            {
                XColor xcolor = XColor.FromArgb(ColorTranslator.FromHtml("#" + color));
                brush = new XSolidBrush(xcolor);
            }

            XStringFormat format = new XStringFormat();

            format.Alignment = XStringAlignment.Center;
            format.LineAlignment = XLineAlignment.Center;
            gfx.DrawString(word.ToLower(), font, brush, rect, format);
        }