Exemplo n.º 1
0
        private void DrawPie(PagePie pp, Graphics g, RectangleF r)
        {
            StyleInfo si = pp.SI;

            if (!si.BackgroundColor.IsEmpty)
            {
                g.FillPie(new SolidBrush(si.BackgroundColor), (int)r.X, (int)r.Y, (int)r.Width, (int)r.Height, (float)pp.StartAngle, (float)pp.SweepAngle);
            }

            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.DrawPie(p, r, pp.StartAngle, pp.SweepAngle);
            }
        }
Exemplo n.º 2
0
        // render all the objects in a page (or any composite object
        private void ProcessPage(System.Drawing.Graphics g, IEnumerable p)
        {
            // TODO: (Peter) Support can grow and can shrink
            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 + _left - _hScroll), PixelsY(pl.Y + _top - _vScroll),
                             PixelsX(pl.X2 + _left - _hScroll), PixelsY(pl.Y2 + _top - _vScroll));
                    continue;
                }


                RectangleF rect = new RectangleF(PixelsX(pi.X + _left - _hScroll), PixelsY(pi.Y + _top - _vScroll),
                                                 PixelsX(pi.W), PixelsY(pi.H));


                if ((pi is PagePolygon) || (pi is PageCurve))
                { // intentionally empty; polygon's rectangles aren't calculated
                }

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

                if (pi is PageText)
                {
                    // TODO: enable can shrink, can grow
                    // 2005 spec file, page 9, in the text box has
                    // CanGrow and CanShrink
                    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);
            }

            // TO: convert System.Drawing.Graphics to Xwt.Drawing.Context and draw it to this.g

            Bitmap bm = new Bitmap(600, 600);

            g.DrawImage(bm, 600, 600);

            System.IO.MemoryStream s = new System.IO.MemoryStream();
            gImg.Save(s, System.Drawing.Imaging.ImageFormat.Png);
            gImg.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
            // Xwt.Drawing.Image img = Xwt.Drawing.Image.FromStream(s);
            Xwt.Drawing.Image img = Xwt.Drawing.Image.FromFile("test.png");

            xwtContext.DrawImage(img, new Xwt.Rectangle(0, 0, 600, 600), new Xwt.Rectangle(0, 0, 600, 600));
            //Xwt.Drawing.TextLayout layout = new Xwt.Drawing.TextLayout(xwtContext);
            //layout.Font = xwtContext.Font;
            //layout.Text = "Test";
            //xwtContext.DrawTextLayout(layout, 2, 4);
        }
        // render all the objects in a page (or any composite object
        private void ProcessPage(StringBuilder sb, IEnumerable p, Rectangle offset)
        {
            foreach (PageItem pi in p)
            {
                if (pi is PageTextHtml)
                {       // PageTextHtml is actually a composite object (just like a page)
                    ProcessHtml(pi as PageTextHtml, sb, new Rectangle(PixelsX(pi.X), PixelsY(pi.Y), PixelsX(pi.W), PixelsY(pi.H)));
                    continue;
                }

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

                Rectangle rect = new Rectangle(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;
                    DrawImageBackground(i, pi.SI, sb, rect);
                }

                if (pi is PageText)
                {
                    PageText pt = pi as PageText;
                    DrawString(pt, sb, rect);
                }
                else if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;
                    DrawImage(i, sb, rect);
                }
                else if (pi is PageRectangle)
                {
                    this.DrawRectangle(pi as PageRectangle, sb, rect);
                }
                else if (pi is PageEllipse)
                {
                    PageEllipse pe = pi as PageEllipse;
                    DrawEllipse(pe, sb, 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;
                    DrawPolygon(ppo, sb);
                }

                DrawBorder(pi, sb, rect);
            }
        }
Exemplo n.º 4
0
        // render all the objects in a page (or any composite object
        private void ProcessPage(Graphics g, IEnumerable p, RectangleF clipRect, bool bHitList)
        {
            // TODO: (Peter) Support can grow and can shrink
            foreach (PageItem pi in p)
            {
                //if (pi is PageTextHtml)
                //{	// PageTextHtml is actually a composite object (just like a page)
                //    if (SelectTool && bHitList)
                //    {
                //        RectangleF hr = new RectangleF(PixelsX(pi.X + _left - _hScroll), PixelsY(pi.Y + _top - _vScroll),
                //                                                            PixelsX(pi.W), PixelsY(pi.H));
                //        _HitList.Add(new HitListEntry(hr, pi));
                //    }
                //    ProcessHtml(pi as PageTextHtml, g, clipRect, bHitList);
                //    continue;
                //}

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


                RectangleF rect = new RectangleF(PixelsX(pi.X + _left - _hScroll), PixelsY(pi.Y + _top - _vScroll),
                                                 PixelsX(pi.W), PixelsY(pi.H));

                // Maintain the hit list
                //if (bHitList)
                //{
                //    if (SelectTool)
                //    {   // we need all PageText and PageImage items that have been displayed
                //        if (pi is PageText || pi is PageImage)
                //        {
                //            _HitList.Add(new HitListEntry(rect, pi));
                //        }
                //    }
                //    // Only care about items with links and tips
                //    else if (pi.HyperLink != null || pi.BookmarkLink != null || pi.Tooltip != null)
                //    {
                //        HitListEntry hle;
                //        if (pi is PagePolygon)
                //            hle = new HitListEntry(pi as PagePolygon, _left - _hScroll, _top - _vScroll, this);
                //        else
                //            hle = new HitListEntry(rect, pi);
                //        _HitList.Add(hle);
                //    }
                //}

                if ((pi is PagePolygon) || (pi is PageCurve))
                { // intentionally empty; polygon's rectangles aren't calculated
                }
                else if (!rect.IntersectsWith(clipRect))
                {
                    continue;
                }

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

                if (pi is PageText)
                {
                    // TODO: enable can shrink, can grow
                    // 2005 spec file, page 9, in the text box has
                    // CanGrow and CanShrink
                    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);
            }
        }
        /// <summary>
        /// Renders all the objects in a Page or composite object.
        /// </summary>
        private static void ProcessPage(Graphics g, IEnumerable p, RectangleF clipRect, bool bHitList, CanvasProperties cp, ref PageItemManager cpim)
        {
            foreach (PageItem pi in p)
            {
                if (pi is PageTextHtml)
                {       // PageTextHtml is actually a composite object (just like a page)
                    if (cpim.SelectToolEnabled && bHitList)
                    {
                        RectangleF hr = new RectangleF(
                            Measurement.PixelsFromPoints(pi.X + cp.Left - cp.Scroll.X, cp.Dpi.X),
                            Measurement.PixelsFromPoints(pi.Y + cp.Scroll.X - cp.Scroll.Y, cp.Dpi.Y),
                            Measurement.PixelsFromPoints(pi.W, cp.Dpi.X),
                            Measurement.PixelsFromPoints(pi.H, cp.Dpi.Y));

                        cpim.HitList.Add(new HitListEntry(hr, pi));
                    }
                    ProcessHtml(pi as PageTextHtml, g, clipRect, bHitList, cp, ref cpim);
                    continue;
                }

                if (pi is PageLine)
                {
                    PageLine pl = pi as PageLine;
                    CanvasPainter.DrawLine(
                        pl.SI.BColorLeft,
                        pl.SI.BStyleLeft,
                        pl.SI.BWidthLeft,
                        g,
                        Measurement.PixelsFromPoints(pl.X + cp.Left - cp.Scroll.X, cp.Dpi.X),
                        Measurement.PixelsFromPoints(pl.Y + cp.Top - cp.Scroll.Y, cp.Dpi.Y),
                        Measurement.PixelsFromPoints(pl.X2 + cp.Left - cp.Scroll.X, cp.Dpi.X),
                        Measurement.PixelsFromPoints(pl.Y2 + cp.Top - cp.Scroll.Y, cp.Dpi.Y));
                    continue;
                }


                RectangleF rect = new RectangleF(
                    Measurement.PixelsFromPoints(pi.X + cp.Left - cp.Scroll.X, cp.Dpi.X),
                    Measurement.PixelsFromPoints(pi.Y + cp.Top - cp.Scroll.Y, cp.Dpi.Y),
                    Measurement.PixelsFromPoints(pi.W, cp.Dpi.X),
                    Measurement.PixelsFromPoints(pi.H, cp.Dpi.Y));

                // Maintain the hit list
                if (bHitList)
                {
                    if (cpim.SelectToolEnabled)
                    {   // we need all PageText and PageImage items that have been displayed
                        if (pi is PageText || pi is PageImage)
                        {
                            cpim.HitList.Add(new HitListEntry(rect, pi));
                        }
                    }
                    // Only care about items with links and tips
                    else if (pi.HyperLink != null || pi.BookmarkLink != null || pi.Tooltip != null)
                    {
                        HitListEntry hle;
                        if (pi is PagePolygon)
                        {
                            hle = new HitListEntry(pi as PagePolygon, cp.Left - cp.Scroll.X, cp.Top - cp.Scroll.Y, ((Canvas)cp.Parent));
                        }
                        else
                        {
                            hle = new HitListEntry(rect, pi);
                        }
                        cpim.HitList.Add(hle);
                    }
                }

                if ((pi is PagePolygon) || (pi is PageCurve))
                { // intentionally empty; polygon's rectangles aren't calculated
                }
                else if (!rect.IntersectsWith(clipRect))
                {
                    continue;
                }

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

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


                CanvasPainter.DrawBorder(pi, g, rect);
            }
        }
Exemplo n.º 6
0
        // render all the objects in a page (or any composite object
        private void ProcessPage(System.Drawing.Graphics g, IEnumerable p)
        {
            // TODO: (Peter) Support can grow and can shrink
            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 + _left - _hScroll), PixelsY(pl.Y + _top - _vScroll),
                             PixelsX(pl.X2 + _left - _hScroll), PixelsY(pl.Y2 + _top - _vScroll));
                    continue;
                }


                RectangleF rect = new RectangleF(PixelsX(pi.X + _left - _hScroll), PixelsY(pi.Y + _top - _vScroll),
                                                 PixelsX(pi.W), PixelsY(pi.H));


                if ((pi is PagePolygon) || (pi is PageCurve))
                { // intentionally empty; polygon's rectangles aren't calculated
                }

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

                if (pi is PageText)
                {
                    // TODO: enable can shrink, can grow
                    // 2005 spec file, page 9, in the text box has
                    // CanGrow and CanShrink
                    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);
            }

            // TO: convert System.Drawing.Graphics to Xwt.Drawing.Context and draw it to this.g

            Bitmap bm = new Bitmap(gImg.Width, gImg.Height);

            g.DrawImage(bm, gImg.Width, gImg.Height);


            // Xwt.Drawing.Image.FromStream does not work.  It crashes with both wpf and gtk
            // As a work around save the image to a temporary file and load it into xwt using the
            // FromFile method.

            System.IO.MemoryStream s = new System.IO.MemoryStream();
            gImg.Save(s, System.Drawing.Imaging.ImageFormat.Png);
            string fileName = System.IO.Path.GetTempFileName();

            gImg.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);

            // Xwt.Drawing.Image img = Xwt.Drawing.Image.FromStream(s);

            Xwt.Drawing.Image img = Xwt.Drawing.Image.FromFile(fileName);
            xwtContext.DrawImage(img, new Xwt.Rectangle(0, 0, gImg.Width, gImg.Height), new Xwt.Rectangle(0, 0, gImg.Width, gImg.Height));
            img.Dispose();
            System.IO.File.Delete(fileName);
        }