示例#1
0
        protected override void OnDraw(Xwt.Drawing.Context ctx, Xwt.Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            if (pages == null)
            {
                return;
            }
            ctx.Save();

            //Xwt.Rectangle rep_r = new Xwt.Rectangle(1, 1, width - 1, height - 1);

            //RenderXwt render = new RenderXwt(ctx, Scale);
            //render.RunPage(pages);
            //ctx.Stroke();

            if (_defaultBackend == Backend.PureXwt)
            {
                RenderXwt render = new RenderXwt(ctx, this, 1f);
                render.RunPage(pages);
            }
            else
            {
                // Page Drawing using System.Drawing converted to Xwt Context
                PageDrawing render = new PageDrawing(ctx, 1f, Convert.ToInt32(this.MinWidth), Convert.ToInt32(this.MinHeight));
                render.RunPage(pages);
            }
            ctx.Stroke();
            ctx.Save();
        }
示例#2
0
        protected override void OnDraw(Xwt.Drawing.Context ctx, Xwt.Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            if (pages == null)
            {
                return;
            }
            ctx.Font = this.Font;
            ctx.Save();

            int width  = (int)(report.PageWidthPoints * Scale);
            int height = (int)(report.PageHeightPoints * Scale);
            //Xwt.Rectangle rep_r = new Xwt.Rectangle(1, 1, width - 1, height - 1);

            //RenderXwt render = new RenderXwt(ctx, Scale);
            //render.RunPage(pages);
            //ctx.Stroke();


            // Page Drawing using System.Drawing converted to Xwt Context
            PageDrawing render = new PageDrawing(ctx, 1f);

            render.RunPage(pages);
            ctx.Stroke();
            ctx.Save();
        }
        private void DrawImage(PageImage pi, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream(pi.ImageData);
            Xwt.Drawing.Image      im = null;
            try
            {
                // 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.Drawing.Image img = System.Drawing.Image.FromStream(ms);

                string fileName = System.IO.Path.GetTempFileName();
                img.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);

                //im = Xwt.Drawing.Image.FromStream(ms);
                im = Xwt.Drawing.Image.FromFile(fileName);
                DrawImageSized(pi, im, g, r);

                im.Dispose();
                System.IO.File.Delete(fileName);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
            }
            finally
            {
                if (im != null)
                {
                    im.Dispose();
                }
            }
        }
示例#4
0
        static void DrawIcon(TextEditor editor, Xwt.Drawing.Context cr, DocumentLine lineSegment, double x, double y, double width, double height)
        {
            if (lineSegment.IsBookmarked)
            {
                var color1 = editor.ColorStyle.Bookmarks.Color;
                var color2 = editor.ColorStyle.Bookmarks.SecondColor;

                DrawRoundRectangle(cr, x + 1, y + 1, 8, width - 4, height - 4);
                using (var pat = new Xwt.Drawing.LinearGradient(x + width / 4, y, x + width / 2, y + height - 4))
                {
                    pat.AddColorStop(0, color1);
                    pat.AddColorStop(1, color2);
                    cr.Pattern = pat;
                    cr.FillPreserve();
                }

                using (var pat = new Xwt.Drawing.LinearGradient(x, y + height, x + width, y))
                {
                    pat.AddColorStop(0, color2);
                    //pat.AddColorStop (1, color1);
                    cr.Pattern = pat;
                    cr.Stroke();
                }
            }
        }
示例#5
0
        static void DrawRoundRectangle(Xwt.Drawing.Context cr, double x, double y, double r, double w, double h)
        {
            const double ARC_TO_BEZIER = 0.55228475;
            double       radius_x      = r;
            double       radius_y      = r / 4;

            if (radius_x > w - radius_x)
            {
                radius_x = w / 2;
            }

            if (radius_y > h - radius_y)
            {
                radius_y = h / 2;
            }

            double c1 = ARC_TO_BEZIER * radius_x;
            double c2 = ARC_TO_BEZIER * radius_y;

            cr.NewPath();
            cr.MoveTo(x + radius_x, y);
            cr.RelLineTo(w - 2 * radius_x, 0.0);
            cr.RelCurveTo(c1, 0.0,
                          radius_x, c2,
                          radius_x, radius_y);
            cr.RelLineTo(0, h - 2 * radius_y);
            cr.RelCurveTo(0.0, c2, c1 - radius_x, radius_y, -radius_x, radius_y);
            cr.RelLineTo(-w + 2 * radius_x, 0);
            cr.RelCurveTo(-c1, 0, -radius_x, -c2, -radius_x, -radius_y);
            cr.RelLineTo(0, -h + 2 * radius_y);
            cr.RelCurveTo(0.0, -c2, radius_x - c1, -radius_y, radius_x, -radius_y);
            cr.ClosePath();
        }
示例#6
0
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            var p = new ReferencePainter();

            p.All(ctx);
        }
示例#7
0
        public RenderXwt(Xwt.Drawing.Context g, float scale)
        {
            this.g = g;
            this.layout = new Xwt.Drawing.TextLayout(this.g );

            dpiX *= scale;
            dpiY *= scale;
        }
示例#8
0
        public RenderXwt(Xwt.Drawing.Context g, float scale)
        {
            this.g      = g;
            this.layout = new Xwt.Drawing.TextLayout(this.g);

            dpiX *= scale;
            dpiY *= scale;
        }
示例#9
0
        public RenderXwt(Xwt.Drawing.Context g, Xwt.Canvas c, float scale)
		{
            this.cxt = g;
            this.cvs = c;
            this.layout = new Xwt.Drawing.TextLayout(this.cvs);
			
			dpiX *= scale;
			dpiY *= scale;
		}
        public RenderXwt(Xwt.Drawing.Context g, Xwt.Canvas c, float scale)
        {
            this.cxt    = g;
            this.cvs    = c;
            this.layout = new Xwt.Drawing.TextLayout(this.cvs);

            dpiX *= scale;
            dpiY *= scale;
        }
示例#11
0
        public PageDrawing(Xwt.Drawing.Context g, float scale)
        {
            DpiX *= scale;
            DpiY *= scale;

            this.xwtContext = g;

            System.Drawing.Bitmap bm = new Bitmap(600,600);
            gImg= (Image)bm;
            this.g = Graphics.FromImage(gImg);
        }
示例#12
0
        public PageDrawing(Xwt.Drawing.Context g, float scale, int width, int height)
        {
            DpiX *= scale;
            DpiY *= scale;

            this.xwtContext = g;

            System.Drawing.Bitmap bm = new Bitmap(width, height);
            gImg   = (Image)bm;
            this.g = Graphics.FromImage(gImg);
        }
示例#13
0
        public PageDrawing(Xwt.Drawing.Context g, float scale)
        {
            DpiX *= scale;
            DpiY *= scale;

            this.xwtContext = g;

            System.Drawing.Bitmap bm = new Bitmap(600, 600);
            gImg   = (Image)bm;
            this.g = Graphics.FromImage(gImg);
        }
示例#14
0
 void DrawMarginBackground(Xwt.Drawing.Context cr, int line, double x, double y, double lineHeight)
 {
     if (editor.Caret.Line == line)
     {
         editor.TextViewMargin.DrawCaretLineMarker(cr, x, y, Width, lineHeight);
         return;
     }
     cr.Rectangle(x, y, Width, lineHeight);
     cr.SetSourceColor(editor.ColorStyle.LineNumbers.Background);
     cr.Fill();
 }
示例#15
0
        public PageDrawing(Xwt.Drawing.Context g, float scale, int width, int height)
        {
            DpiX *= scale;
            DpiY *= scale;

            this.xwtContext = g;

            System.Drawing.Bitmap bm = new Bitmap(width, height);
            gImg= (Image)bm;
            this.g = Graphics.FromImage(gImg);
        }
示例#16
0
        private void ProcessPage(Xwt.Drawing.Context 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;

                    Xwt.Drawing.Color bcolorleft = XwtColor.SystemColorToXwtColor(pl.SI.BColorLeft);

                    DrawLine(bcolorleft, pl.SI.BStyleLeft, pl.SI.BWidthLeft,
                             g, PixelsX(pl.X), PixelsY(pl.Y), PixelsX(pl.X2), PixelsY(pl.Y2)
                             );
                    continue;
                }

                Xwt.Rectangle rect = new Xwt.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;
                    DrawImage(i, g, rect);
                    continue;
                }

                if (pi is PageText)
                {
                    PageText pt = pi as PageText;
                    DrawString(pt, g, rect);
                }

                if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;
                    DrawImage(i, g, rect);
                }

                if (pi is PageRectangle)
                {
                    //DrawBackground(g, rect, pi.SI);
                }

                DrawBorder(pi, g, rect);
            }
        }
示例#17
0
 private void DrawImage(PageImage pi, Xwt.Drawing.Context g, Xwt.Rectangle r)
 {
     System.IO.MemoryStream ms = new System.IO.MemoryStream(pi.ImageData);
     Xwt.Drawing.Image      im = null;
     try
     {
         im = Xwt.Drawing.Image.FromStream(ms);
         DrawImageSized(pi, im, g, r);
     }
     finally
     {
         if (im != null)
         {
             im.Dispose();
         }
     }
 }
示例#18
0
 protected override void OnDraw(Xwt.Drawing.Context ctx, Xwt.Rectangle dirtyRect)
 {
     base.OnDraw(ctx, dirtyRect);
     if (image != null)
     {
         ctx.DrawImage(image, 0, 0);
         if (filler != null)
         {
             int    fillCount = (int)Math.Ceiling((Bounds.Width - image.Width) / filler.Width);
             double x         = image.Width;
             while ((fillCount--) > 0)
             {
                 ctx.DrawImage(filler, x, 0);
                 x += filler.Width;
             }
         }
     }
 }
示例#19
0
        private void DrawBorder(PageItem pi, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            if (r.Height <= 0 || r.Width <= 0)      // no bounding box to use
            {
                return;
            }

            double    right  = r.X + r.Width;
            double    bottom = r.Y + r.Height;
            StyleInfo si     = pi.SI;


            Xwt.Drawing.Color ec = XwtColor.SystemColorToXwtColor(si.BackgroundGradientEndColor);

            DrawLine(XwtColor.SystemColorToXwtColor(si.BColorTop), si.BStyleTop, si.BWidthTop, g, r.X, r.Y, right, r.Y);
            DrawLine(XwtColor.SystemColorToXwtColor(si.BColorRight), si.BStyleRight, si.BWidthRight, g, right, r.Y, right, bottom);
            DrawLine(XwtColor.SystemColorToXwtColor(si.BColorLeft), si.BStyleLeft, si.BWidthLeft, g, r.X, r.Y, r.X, bottom);
            DrawLine(XwtColor.SystemColorToXwtColor(si.BColorBottom), si.BStyleBottom, si.BWidthBottom, g, r.X, bottom, right, bottom);
        }
示例#20
0
        private void DrawLine(Xwt.Drawing.Color c, BorderStyleEnum bs, float w, Xwt.Drawing.Context g, double x, double y, double x2, double y2)
        {
            if (bs == BorderStyleEnum.None || //|| c.IsEmpty
                w <= 0)      // nothing to draw
            {
                return;
            }

            g.Save();
            //          Pen p = null;
            //          p = new Pen(c, w);
            g.SetColor(c);
            g.SetLineWidth(w);
            switch (bs)
            {
            case BorderStyleEnum.Dashed:
                //	                p.DashStyle = DashStyle.Dash;
                g.SetLineDash(0.0, new double[] { 2, 1 });
                break;

            case BorderStyleEnum.Dotted:
                //                        p.DashStyle = DashStyle.Dot;
                g.SetLineDash(0.0, new double[] { 1 });
                break;

            case BorderStyleEnum.Double:
            case BorderStyleEnum.Groove:
            case BorderStyleEnum.Inset:
            case BorderStyleEnum.Solid:
            case BorderStyleEnum.Outset:
            case BorderStyleEnum.Ridge:
            case BorderStyleEnum.WindowInset:
            default:
                g.SetLineDash(0.0, new double[] { });
                break;
            }

            g.MoveTo(x, y);
            g.LineTo(x2, y2);
            g.Stroke();

            g.Restore();
        }
示例#21
0
        internal protected override void Draw(Xwt.Drawing.Context cr, Xwt.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            var  marker         = lineSegment != null ? (MarginMarker)lineSegment.Markers.FirstOrDefault(m => m is MarginMarker && ((MarginMarker)m).CanDraw(this)) : null;
            bool drawBackground = true;

            if (marker != null && marker.CanDrawBackground(this))
            {
                drawBackground = !marker.DrawBackground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
            }

            if (drawBackground)
            {
                DrawMarginBackground(cr, line, x, y, lineHeight);
            }

            if (marker != null && marker.CanDrawForeground(this))
            {
                marker.DrawForeground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
            }
        }
示例#22
0
        private void DrawBackground(Xwt.Drawing.Context g, Xwt.Rectangle rect, StyleInfo si)
        {
            //            LinearGradientBrush linGrBrush = null;
            //            SolidBrush sb = null;
            if (si.BackgroundColor.IsEmpty)
            {
                return;
            }

            g.Save();

            Xwt.Drawing.Color c = XwtColor.SystemColorToXwtColor(si.BackgroundColor);

            Xwt.Drawing.Gradient gradient = null;

            if (si.BackgroundGradientType != BackgroundGradientTypeEnum.None &&
                !si.BackgroundGradientEndColor.IsEmpty)
            {
                Xwt.Drawing.Color ec = XwtColor.SystemColorToXwtColor(si.BackgroundGradientEndColor);

                switch (si.BackgroundGradientType)
                {
                case BackgroundGradientTypeEnum.LeftRight:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                    gradient = new Xwt.Drawing.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y);
                    break;

                case BackgroundGradientTypeEnum.TopBottom:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                    gradient = new Xwt.Drawing.LinearGradient(rect.X, rect.Y, rect.X, rect.Y + rect.Height);
                    break;

                case BackgroundGradientTypeEnum.Center:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                    throw new NotSupportedException();

                //                            break;
                case BackgroundGradientTypeEnum.DiagonalLeft:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.ForwardDiagonal);
                    gradient = new Xwt.Drawing.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height);
                    break;

                case BackgroundGradientTypeEnum.DiagonalRight:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.BackwardDiagonal);
                    gradient = new Xwt.Drawing.LinearGradient(rect.X + rect.Width, rect.Y + rect.Height, rect.X, rect.Y);
                    break;

                case BackgroundGradientTypeEnum.HorizontalCenter:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                    throw new NotSupportedException();

                //							break;
                case BackgroundGradientTypeEnum.VerticalCenter:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                    throw new NotSupportedException();

                //							break;
                default:
                    break;
                }

                gradient.AddColorStop(0, c);
                gradient.AddColorStop(1, ec);
            }

            if (gradient != null)
            {
                // TODO: Fix
                //g.FillRectangle(rect, gradient);
            }
            else if (!si.BackgroundColor.IsEmpty)
            {
                // TODO: Fix
                //g.FillRectangle(rect, c);
            }
            g.Restore();
        }
示例#23
0
 public abstract void Draw(Xwt.Drawing.Context cr, Rectangle erea);
 public object Create(Xwt.Drawing.Context context)
 {
     return(new LayoutInfo());
 }
 protected internal override void DrawBackground(Xwt.Drawing.Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
 {
 }
示例#26
0
 public override void DrawForeground(TextEditor editor, Xwt.Drawing.Context cr, MarginDrawMetrics metrics)
 {
     DrawBookmarkFunc(editor, cr, LineSegment, metrics.X, metrics.Y, metrics.Width, metrics.Height);
 }
示例#27
0
 private void ProcessHtml(PageTextHtml pth, Xwt.Drawing.Context g)
 {
     //            pth.Build(g);            // Builds the subobjects that make up the html
     this.ProcessPage(g, pth);
 }
示例#28
0
 internal protected abstract void Draw(Xwt.Drawing.Context cr, Rectangle area, DocumentLine line, int lineNumber, double x, double y, double lineHeight);
示例#29
0
 public RenderXwt(Xwt.Drawing.Context g) : this(g, 1.0f)
 {
 }
示例#30
0
 public PageDrawing(Xwt.Drawing.Context g)
     : this(g, 1.0f)
 {
 }
示例#31
0
        private void DrawString(PageText pt, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            StyleInfo si = pt.SI;
            string    s  = pt.Text;

            g.Save();
            layout      = new Xwt.Drawing.TextLayout(g);
            layout.Font = g.Font;


            float fontsize = (si.FontSize * 72 / 96);

            layout.Font.WithFamily(si.GetFontFamily().Name);
            layout.Font.WithPixelSize(fontsize * PixelsX(1));

            if (si.FontStyle == FontStyleEnum.Italic)
            {
                layout.Font.WithStyle(Xwt.Drawing.FontStyle.Italic);
            }

            switch (si.FontWeight)
            {
            case FontWeightEnum.Bold:
            case FontWeightEnum.Bolder:
            case FontWeightEnum.W500:
            case FontWeightEnum.W600:
            case FontWeightEnum.W700:
            case FontWeightEnum.W800:
            case FontWeightEnum.W900:
                layout.Font.WithWeight(Xwt.Drawing.FontWeight.Bold);
                break;
            }

            // TODO: Fix Alignment
            //switch (si.TextAlign)
            //{
            //    case TextAlignEnum.Right:
            //        layout.Alignment = Pango.Alignment.Right;
            //        break;
            //    case TextAlignEnum.Center:
            //        layout.Alignment = Pango.Alignment.Center;
            //        break;
            //    case TextAlignEnum.Left:
            //    default:
            //        layout.Alignment = Pango.Alignment.Left;
            //        break;
            //}

            // TODO: Fix with
            //layout.Width = Pango.Units.FromPixels((int)(r.Width - si.PaddingLeft - si.PaddingRight - 2));

            layout.Text = s;



            //Xwt.Rectangle logical;
            // Xwt.Rectangle ink;

            // TODO: Fix
            //layout.GetExtents(out ink, out logical);
            double height = 12; // logical.Height / Pango.Scale.PangoScale;

            double y = 0;

            switch (si.VerticalAlign)
            {
            case VerticalAlignEnum.Top:
                y = r.Y + si.PaddingTop;
                break;

            case VerticalAlignEnum.Middle:
                y = r.Y + (r.Height - height) / 2;
                break;

            case VerticalAlignEnum.Bottom:
                y = r.Y + (r.Height - height) - si.PaddingBottom;
                break;
            }

            // draw the background
            DrawBackground(g, r, si);

            Xwt.Rectangle box = new Xwt.Rectangle(
                r.X + si.PaddingLeft + 1,
                y,
                r.Width,
                r.Height);

            Xwt.Drawing.Color sicolor = XwtColor.SystemColorToXwtColor(si.Color);
            g.SetColor(sicolor);

            g.MoveTo(box.X, box.Y);
            g.DrawTextLayout(layout, box.X, box.Y);
            g.Restore();
        }
示例#32
0
        private void DrawImageSized(PageImage pi, Xwt.Drawing.Image im, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            double    height, width;   // some work variables
            StyleInfo si = pi.SI;

            Xwt.Rectangle r2 = new Xwt.Rectangle(r.X + PixelsX(si.PaddingLeft),
                                                 r.Y + PixelsY(si.PaddingTop),
                                                 r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                                 r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            Xwt.Rectangle ir;   // int work rectangle
            switch (pi.Sizing)
            {
            case ImageSizingEnum.AutoSize:

                float imwidth  = PixelsX((float)im.Size.Width);
                float imheight = PixelsX((float)im.Size.Height);
                ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                       imwidth, imheight);

                im.Scale((int)r2.Width, (int)r2.Height);
                g.DrawImage(im, ir);

                break;

            case ImageSizingEnum.Clip:
                g.Save();
                g.Rectangle(r2);
                g.Clip();


                ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                       im.Size.Width, im.Size.Height);

                g.DrawImage(im, ir);
                g.Restore();
                break;

            case ImageSizingEnum.FitProportional:
                double ratioIm = (float)im.Size.Height / (float)im.Size.Width;
                double 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 ractangle height must be corrected
                    height = width * ratioIm;
                }
                r2 = new Xwt.Rectangle(r2.X, r2.Y, width, height);
                g.DrawImage(im, r2);
                break;

            case ImageSizingEnum.Fit:
            default:
                g.DrawImage(im, r2);
                break;
            }
        }
 public RenderXwt(Xwt.Drawing.Context g, Xwt.Canvas c) : this(g, c, 1.0f)
 {
 }