Esempio n. 1
0
        private void DrawEllipse(PageEllipse pe, Graphics g, RectangleF r)
        {
            StyleInfo si = pe.SI;

            if (!si.BackgroundColor.IsEmpty)
            {
                g.FillEllipse(new SolidBrush(si.BackgroundColor), r);
            }
            if (si.BStyleTop != BorderStyleEnum.None)
            {
                Pen p = new Pen(si.BColorTop, si.BWidthTop);
                switch (si.BStyleTop)
                {
                case BorderStyleEnum.Dashed:
                    p.DashStyle = DashStyle.Dash;
                    break;

                case BorderStyleEnum.Dotted:
                    p.DashStyle = DashStyle.Dot;
                    break;

                case BorderStyleEnum.Double:
                case BorderStyleEnum.Groove:
                case BorderStyleEnum.Inset:
                case BorderStyleEnum.Solid:
                case BorderStyleEnum.Outset:
                case BorderStyleEnum.Ridge:
                case BorderStyleEnum.WindowInset:
                default:
                    p.DashStyle = DashStyle.Solid;
                    break;
                }
                g.DrawEllipse(p, r);
            }
        }
Esempio n. 2
0
        private void DoInstructions(Single Xp, Single Yp, Single Wid, Single Hgt, Brush b)
        {
            switch (b.GetType().Name)
            {
            case "SolidBrush":
                System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b;
                Color       col = theBrush.Color;
                PageEllipse pl  = new PageEllipse();
                pl.X = X + Xp * SCALEFACTOR;
                pl.Y = Y + Yp * SCALEFACTOR;
                pl.W = Wid * SCALEFACTOR;
                pl.H = Hgt * SCALEFACTOR;

                StyleInfo SI = new StyleInfo();
                SI.BackgroundColor = col;
                pl.SI = SI;
                items.Add(pl);



                //Lines.AppendFormat("\r\n"); //CrLf
                //Lines.AppendFormat("q\t"); //Push graphics state onto stack
                //Lines.AppendFormat("{0} w\t", 1 * ScaleX); //set width of path
                //Lines.AppendFormat("{0} {1} {2} RG\t", Math.Round(theBrush.Color.R / 255.0, 3), Math.Round(theBrush.Color.G / 255.0, 3), Math.Round(theBrush.Color.B / 255.0, 3)); //Set RGB colours
                //Lines.AppendFormat("{0} {1} {2} rg\t", Math.Round(theBrush.Color.R / 255.0, 3), Math.Round(theBrush.Color.G / 255.0, 3), Math.Round(theBrush.Color.B / 255.0, 3)); //Set RGB colours
                ////Need some bezier curves to  draw an ellipse.. we can't draw a circle, but we can get close.
                //Double k = 0.5522847498;
                //Double RadiusX = (Wid / 2.0) * ScaleX;
                //Double RadiusY = (Hgt / 2.0) * ScaleY;
                //Double Y4 = Y + Height - Yp * ScaleY;
                //Double X1 = Xp * ScaleX + X;
                //Double Y1 = Y4 - RadiusY;
                //Double X4 = X1 + RadiusX;
                //Lines.AppendFormat("{0} {1} m\t", X1, Y1);//FirstPoint..
                //Double kRy = k * RadiusY;
                //Double kRx = k * RadiusX;
                ////Control Point 1 will be on the same X as point 1 and be -kRy Y
                //Double X2 = X1;
                //Double Y2 = Y1 + kRy;
                //Double X3 = X4 - kRx;
                //Double Y3 = Y4;
                //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Upper Left Quadrant
                //X1 += 2 * RadiusX;
                //X2 = X1;
                //X3 += 2 * kRx;
                //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Upper Right Quadrant
                //Y2 -= 2 * kRy;
                //Y3 -= 2 * RadiusY;
                //Y4 = Y3;
                //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Lower Right Quadrant
                //X1 -= 2 * RadiusX;
                //X2 = X1;
                //X3 -= 2 * kRx;
                //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Lower Right Quadrant
                //Lines.AppendFormat("f\t");//fill path
                //Lines.AppendFormat("Q\t");//Pop graphics state from stack
                break;
            }
        }
Esempio n. 3
0
        private void ProcessPage(Graphics g, IEnumerable p)
        {
            foreach (PageItem pi in p)
            {
                if (pi is PageTextHtml)
                {   // PageTextHtml is actually a composite object (just like a page)
                    ProcessHtml(pi as PageTextHtml, g);
                    continue;
                }

                if (pi is PageLine)
                {
                    PageLine pl = pi as PageLine;
                    DrawLine(
                        pl.SI.BColorLeft, pl.SI.BStyleLeft, pl.SI.BWidthLeft,
                        g, PixelsX(pl.X), PixelsY(pl.Y), PixelsX(pl.X2), PixelsY(pl.Y2)
                        );
                    continue;
                }

                RectangleF rect = new RectangleF(PixelsX(pi.X), PixelsY(pi.Y), PixelsX(pi.W), PixelsY(pi.H));

                if (pi.SI.BackgroundImage != null)
                {   // put out any background image
                    PageImage i = pi.SI.BackgroundImage;
                    DrawImage(i, g, rect);
                }

                if (pi is PageText)
                {
                    PageText pt = pi as PageText;
                    DrawString(pt, g, rect);
                }
                else if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;
                    DrawImage(i, g, rect);
                }
                else if (pi is PageRectangle)
                {
                    this.DrawBackground(g, rect, pi.SI);
                }
                else if (pi is PageEllipse)
                {
                    PageEllipse pe = pi as PageEllipse;
                    DrawEllipse(pe, g, rect);
                }
                else if (pi is PagePie)
                {
                    PagePie pp = pi as PagePie;
                    DrawPie(pp, g, rect);
                }
                else if (pi is PagePolygon)
                {
                    PagePolygon ppo = pi as PagePolygon;
                    FillPolygon(ppo, g, rect);
                }
                else if (pi is PageCurve)
                {
                    PageCurve pc = pi as PageCurve;
                    DrawCurve(pc.SI.BColorLeft, pc.SI.BStyleLeft, pc.SI.BWidthLeft,
                              g, pc.Points, pc.Offset, pc.Tension);
                }

                DrawBorder(pi, g, rect);
            }
        }
Esempio n. 4
0
        private void DoEllipse(Pen p, Single Xp, Single Yp, Single Wid, Single Hgt)
        {
            BorderStyleEnum ls = getLineStyle(p);

            Color col = Color.Black;

            if (p.Brush.GetType().Name.Equals("SolidBrush"))
            {
                System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)p.Brush;
                col = theBrush.Color;
            }

            PageEllipse pl = new PageEllipse();

            pl.X = X + Xp * SCALEFACTOR;
            pl.Y = Y + Yp * SCALEFACTOR;
            pl.W = Wid * SCALEFACTOR;
            pl.H = Hgt * SCALEFACTOR;

            StyleInfo SI = new StyleInfo();

            SI.Color     = col;
            SI.BColorTop = col;
            SI.BStyleTop = ls;
            SI.BWidthTop = p.Width * SCALEFACTOR;
            pl.SI        = SI;
            items.Add(pl);

            //Lines.AppendFormat("\r\n"); //CrLf
            //Lines.AppendFormat("q\t"); //Push graphics state onto stack
            //Lines.AppendFormat("{0} w\t", p.Width * ScaleX); //set width of path
            //Lines.AppendFormat("{0} \t", linestyle); //line style from pen...
            //Lines.AppendFormat("{0} {1} {2} RG\t", Math.Round(R / 255.0, 3), Math.Round(G / 255.0, 3), Math.Round(B / 255.0, 3)); //Set RGB colours
            //Lines.AppendFormat("{0} {1} {2} rg\t", Math.Round(R / 255.0, 3), Math.Round(G / 255.0, 3), Math.Round(B / 255.0, 3)); //Set RGB colours
            ////Need some bezier curves to  draw an ellipse.. we can't draw a circle, but we can get close.
            //Double k = 0.5522847498;
            //Double RadiusX = (Wid / 2.0) * ScaleX;
            //Double RadiusY = (Hgt / 2.0) * ScaleY;
            //Double Y4 = Y + Height - Yp * ScaleY;
            //Double X1 = Xp * ScaleX + X;
            //Double Y1 = Y4 - RadiusY;
            //Double X4 = X1 + RadiusX;

            //Lines.AppendFormat("{0} {1} m\t", X1, Y1);//FirstPoint..

            //Double kRy = k * RadiusY;
            //Double kRx = k * RadiusX;

            ////Control Point 1 will be on the same X as point 1 and be -kRy Y
            //Double X2 = X1;
            //Double Y2 = Y1 + kRy;

            //Double X3 = X4 - kRx;
            //Double Y3 = Y4;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Upper Left Quadrant

            //X1 += 2 * RadiusX;
            //X2 = X1;
            //X3 += 2 * kRx;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Upper Right Quadrant

            //Y2 -= 2 * kRy;
            //Y3 -= 2 * RadiusY;
            //Y4 = Y3;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Lower Right Quadrant

            //X1 -= 2 * RadiusX;
            //X2 = X1;
            //X3 -= 2 * kRx;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Lower Right Quadrant

            //Lines.AppendFormat("S\t");//Stroke path
            //Lines.AppendFormat("Q\t");//Pop graphics state from stack
        }
Esempio n. 5
0
        // render all the objects in a page in PDF
        private void ProcessPage(Pages pgs, IEnumerable items)
        {
            foreach (PageItem pi in items)
            {
                if (pi.SI.BackgroundImage != null)
                {       // put out any background image
                    PageImage bgImg = pi.SI.BackgroundImage;
                    //					elements.AddImage(images, i.Name, content.objectNum, i.SI, i.ImgFormat,
                    //						pi.X, pi.Y, pi.W, pi.H, i.ImageData,i.SamplesW, i.SamplesH, null);
                    //Duc Phan modified 10 Dec, 2007 to support on background image
                    float imW     = Measurement.PointsFromPixels(bgImg.SamplesW, pgs.G.DpiX);
                    float imH     = Measurement.PointsFromPixels(bgImg.SamplesH, pgs.G.DpiY);
                    int   repeatX = 0;
                    int   repeatY = 0;
                    float itemW   = pi.W - (pi.SI.PaddingLeft + pi.SI.PaddingRight);
                    float itemH   = pi.H - (pi.SI.PaddingTop + pi.SI.PaddingBottom);
                    switch (bgImg.Repeat)
                    {
                    case ImageRepeat.Repeat:
                        repeatX = (int)Math.Floor(itemW / imW);
                        repeatY = (int)Math.Floor(itemH / imH);
                        break;

                    case ImageRepeat.RepeatX:
                        repeatX = (int)Math.Floor(itemW / imW);
                        repeatY = 1;
                        break;

                    case ImageRepeat.RepeatY:
                        repeatY = (int)Math.Floor(itemH / imH);
                        repeatX = 1;
                        break;

                    case ImageRepeat.NoRepeat:
                    default:
                        repeatX = repeatY = 1;
                        break;
                    }

                    //make sure the image is drawn at least 1 times
                    repeatX = Math.Max(repeatX, 1);
                    repeatY = Math.Max(repeatY, 1);

                    float currX  = pi.X + pi.SI.PaddingLeft;
                    float currY  = pi.Y + pi.SI.PaddingTop;
                    float startX = currX;
                    float startY = currY;
                    for (int i = 0; i < repeatX; i++)
                    {
                        for (int j = 0; j < repeatY; j++)
                        {
                            currX = startX + i * imW;
                            currY = startY + j * imH;
                            elements.AddImage(images, bgImg.Name,
                                              content.objectNum, bgImg.SI, bgImg.ImgFormat,
                                              currX, currY, imW, imH, RectangleF.Empty, bgImg.ImageData, bgImg.SamplesW, bgImg.SamplesH, null, pi.Tooltip);
                        }
                    }
                }

                if (pi is PageTextHtml)
                {
                    PageTextHtml pth = pi as PageTextHtml;
                    pth.Build(pgs.G);
                    ProcessPage(pgs, pth);
                    continue;
                }

                if (pi is PageText)
                {
                    PageText pt = pi as PageText;
                    float[]  textwidth;
                    string[] sa = MeasureString(pt, pgs.G, out textwidth);
                    elements.AddText(pt.X, pt.Y, pt.H, pt.W, sa, pt.SI,
                                     fonts, textwidth, pt.CanGrow, pt.HyperLink, pt.NoClip, pt.Tooltip);
                    if (pt.Bookmark != null)
                    {
                        outline.Bookmarks.Add(new PdfOutlineEntry(anchor, page.objectNum, pt.Bookmark, pt.X, elements.PageSize.yHeight - pt.Y));
                    }
                    continue;
                }

                if (pi is PageLine)
                {
                    PageLine pl = pi as PageLine;
                    elements.AddLine(pl.X, pl.Y, pl.X2, pl.Y2, pl.SI);
                    continue;
                }

                if (pi is PageEllipse)
                {
                    PageEllipse pe = pi as PageEllipse;
                    elements.AddEllipse(pe.X, pe.Y, pe.H, pe.W, pe.SI, pe.HyperLink);
                    continue;
                }



                if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;

                    //Duc Phan added 20 Dec, 2007 to support sized image
                    RectangleF r2 = new RectangleF(i.X + i.SI.PaddingLeft, i.Y + i.SI.PaddingTop, i.W - i.SI.PaddingLeft - i.SI.PaddingRight, i.H - i.SI.PaddingTop - i.SI.PaddingBottom);

                    RectangleF adjustedRect;   // work rectangle
                    RectangleF clipRect = RectangleF.Empty;
                    switch (i.Sizing)
                    {
                    case ImageSizingEnum.AutoSize:
                        adjustedRect = new RectangleF(r2.Left, r2.Top,
                                                      r2.Width, r2.Height);
                        break;

                    case ImageSizingEnum.Clip:
                        adjustedRect = new RectangleF(r2.Left, r2.Top,
                                                      Measurement.PointsFromPixels(i.SamplesW, pgs.G.DpiX), Measurement.PointsFromPixels(i.SamplesH, pgs.G.DpiY));
                        clipRect = new RectangleF(r2.Left, r2.Top,
                                                  r2.Width, r2.Height);
                        break;

                    case ImageSizingEnum.FitProportional:
                        float height;
                        float width;
                        float ratioIm = (float)i.SamplesH / i.SamplesW;
                        float ratioR  = r2.Height / r2.Width;
                        height = r2.Height;
                        width  = r2.Width;
                        if (ratioIm > ratioR)
                        {       // this means the rectangle width must be corrected
                            width = height * (1 / ratioIm);
                        }
                        else if (ratioIm < ratioR)
                        {       // this means the rectangle height must be corrected
                            height = width * ratioIm;
                        }
                        adjustedRect = new RectangleF(r2.X, r2.Y, width, height);
                        break;

                    case ImageSizingEnum.Fit:
                    default:
                        adjustedRect = r2;
                        break;
                    }
                    if (i.ImgFormat == System.Drawing.Imaging.ImageFormat.Wmf || i.ImgFormat == System.Drawing.Imaging.ImageFormat.Emf)
                    {
                        //We dont want to add it - its already been broken down into page items;
                    }
                    else
                    {
                        elements.AddImage(images, i.Name, content.objectNum, i.SI, i.ImgFormat,
                                          adjustedRect.X, adjustedRect.Y, adjustedRect.Width, adjustedRect.Height, clipRect, i.ImageData, i.SamplesW, i.SamplesH, i.HyperLink, i.Tooltip);
                    }
                    continue;
                }

                if (pi is PageRectangle)
                {
                    PageRectangle pr = pi as PageRectangle;
                    elements.AddRectangle(pr.X, pr.Y, pr.H, pr.W, pi.SI, pi.HyperLink, patterns, pi.Tooltip);
                    continue;
                }
                if (pi is PagePie)
                {   // TODO
                    PagePie pp = pi as PagePie;
                    // elements.AddPie(pr.X, pr.Y, pr.H, pr.W, pi.SI, pi.HyperLink, patterns, pi.Tooltip);
                    continue;
                }
                if (pi is PagePolygon)
                {
                    PagePolygon ppo = pi as PagePolygon;
                    elements.AddPolygon(ppo.Points, pi.SI, pi.HyperLink, patterns);
                    continue;
                }
                if (pi is PageCurve)
                {
                    PageCurve pc = pi as PageCurve;
                    elements.AddCurve(pc.Points, pi.SI);
                    continue;
                }
            }
        }