Пример #1
0
        public Pen GetPen(GraphicsPath gp)
        {
            float strokeWidth = GetStrokeWidth();
            if (strokeWidth == 0) return null;

            GdiSvgPaint stroke;
            if (PaintType == SvgPaintType.None)
            {
                return null;
            }
            else if (PaintType == SvgPaintType.CurrentColor)
            {
                stroke = new GdiSvgPaint(_element, "color");
            }
            else
            {
                stroke = this;
            }

            Pen pen = new Pen(stroke.GetBrush(gp, "stroke"), strokeWidth);

            pen.StartCap   = pen.EndCap = GetLineCap();
            pen.LineJoin   = GetLineJoin();
            pen.MiterLimit = GetMiterLimit();

            float[] fDashArray = GetDashArray(strokeWidth);
            if (fDashArray != null)
            {
                // Do not draw if dash array had a zero value in it

                for (int i = 0; i < fDashArray.Length; i++)
                {
                    if (fDashArray[i] == 0)
                        return null;
                }

                pen.DashPattern = fDashArray;
            }

            pen.DashOffset = GetDashOffset(strokeWidth);

            return pen;
        }
Пример #2
0
 private Pen GetPen(GraphicsPath gp)
 {
     GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "stroke");
     return paint.GetPen(gp);
 }
Пример #3
0
 private Brush GetBrush(GraphicsPath gp)
 {
     GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "fill");
     return paint.GetBrush(gp);
 }
Пример #4
0
        private void AddGraphicsPath(SvgTextContentElement element, ref PointF ctp, string text)
        {
            if (text.Length == 0)
                return;

            float emSize      = GetComputedFontSize(element);
            FontFamily family = GetGDIFontFamily(element, emSize);
            int style         = GetGDIFontStyle(element);
            StringFormat sf   = GetGDIStringFormat(element);

            GraphicsPath textGeometry = new GraphicsPath();

            float xCorrection = 0;
            if (sf.Alignment == StringAlignment.Near)
                xCorrection = emSize * 1 / 6;
            else if (sf.Alignment == StringAlignment.Far)
                xCorrection = -emSize * 1 / 6;

            float yCorrection = (float)(family.GetCellAscent(FontStyle.Regular)) / (float)(family.GetEmHeight(FontStyle.Regular)) * emSize;

            // TODO: font property
            PointF p = new PointF(ctp.X - xCorrection, ctp.Y - yCorrection);

            textGeometry.AddString(text, family, style, emSize, p, sf);
            if (!textGeometry.GetBounds().IsEmpty)
            {
                float bboxWidth = textGeometry.GetBounds().Width;
                if (sf.Alignment == StringAlignment.Center)
                    bboxWidth /= 2;
                else if (sf.Alignment == StringAlignment.Far)
                    bboxWidth = 0;

                ctp.X += bboxWidth + emSize / 4;
            }

            GdiSvgPaint fillPaint = new GdiSvgPaint(element, "fill");
            Brush brush = fillPaint.GetBrush(textGeometry);

            GdiSvgPaint strokePaint = new GdiSvgPaint(element, "stroke");
            Pen pen = strokePaint.GetPen(textGeometry);

            if (brush != null)
            {
                if (brush is PathGradientBrush)
                {
                    GdiGradientFill gps = fillPaint.PaintFill as GdiGradientFill;

                    _graphics.SetClip(gps.GetRadialGradientRegion(textGeometry.GetBounds()), CombineMode.Exclude);

                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)brush).InterpolationColors.Colors[0]);
                    _graphics.FillPath(this, tempBrush, textGeometry);
                    tempBrush.Dispose();
                    _graphics.ResetClip();
                }

                _graphics.FillPath(this, brush, textGeometry);
                brush.Dispose();
            }

            if (pen != null)
            {
                if (pen.Brush is PathGradientBrush)
                {
                    GdiGradientFill gps = strokePaint.PaintFill as GdiGradientFill;
                    GdiGraphicsContainer container = _graphics.BeginContainer();

                    _graphics.SetClip(gps.GetRadialGradientRegion(textGeometry.GetBounds()), CombineMode.Exclude);

                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)pen.Brush).InterpolationColors.Colors[0]);
                    Pen tempPen = new Pen(tempBrush, pen.Width);
                    _graphics.DrawPath(this, tempPen, textGeometry);
                    tempPen.Dispose();
                    tempBrush.Dispose();

                    _graphics.EndContainer(container);
                }

                _graphics.DrawPath(this, pen, textGeometry);
                pen.Dispose();
            }

            textGeometry.Dispose();
        }
Пример #5
0
        public override void Render(GdiGraphicsRenderer renderer)
        {
            GdiGraphicsWrapper graphics = renderer.GraphicsWrapper;

            SvgRenderingHint hint = element.RenderingHint;
            if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping)
            {
                return;
            }
            if (element.ParentNode is SvgClipPathElement)
            {
                return;
            }

            SvgStyleableElement styleElm = (SvgStyleableElement)element;

            string sVisibility = styleElm.GetPropertyValue("visibility");
            string sDisplay    = styleElm.GetPropertyValue("display");
            if (String.Equals(sVisibility, "hidden") || String.Equals(sDisplay, "none"))
            {
                return;
            }

            GraphicsPath gp = CreatePath(element);

            if (gp != null)
            {
                Clip(graphics);

                GdiSvgPaint fillPaint = new GdiSvgPaint(styleElm, "fill");
                Brush brush = fillPaint.GetBrush(gp);

                GdiSvgPaint strokePaint = new GdiSvgPaint(styleElm, "stroke");
                Pen pen = strokePaint.GetPen(gp);

                if (brush != null)
                {
                    if (brush is PathGradientBrush)
                    {
                        GdiGradientFill gps = fillPaint.PaintFill as GdiGradientFill;

                        graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);

                        SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)brush).InterpolationColors.Colors[0]);
                        graphics.FillPath(this, tempBrush,gp);
                        tempBrush.Dispose();
                        graphics.ResetClip();
                    }

                    graphics.FillPath(this, brush, gp);
                    brush.Dispose();
                    brush = null;
                }

                if (pen != null)
                {
                    if (pen.Brush is PathGradientBrush)
                    {
                        GdiGradientFill gps = strokePaint.PaintFill as GdiGradientFill;
                        GdiGraphicsContainer container = graphics.BeginContainer();

                        graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);

                        SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)pen.Brush).InterpolationColors.Colors[0]);
                        Pen tempPen = new Pen(tempBrush, pen.Width);
                        graphics.DrawPath(this, tempPen,gp);
                        tempPen.Dispose();
                        tempBrush.Dispose();

                        graphics.EndContainer(container);
                    }

                    graphics.DrawPath(this, pen, gp);
                    pen.Dispose();
                    pen = null;
                }

                gp.Dispose();
                gp = null;
            }

            PaintMarkers(renderer, styleElm, graphics);
        }
Пример #6
0
        private void AddGraphicsPath(SvgTextContentElement element, ref PointF ctp, string text)
        {
            if (text.Length == 0)
            {
                return;
            }

            float        emSize = GetComputedFontSize(element);
            FontFamily   family = GetGDIFontFamily(element, emSize);
            int          style  = GetGDIFontStyle(element);
            StringFormat sf     = GetGDIStringFormat(element);

            GraphicsPath textGeometry = new GraphicsPath();

            float xCorrection = 0;

            if (sf.Alignment == StringAlignment.Near)
            {
                xCorrection = emSize * 1 / 6;
            }
            else if (sf.Alignment == StringAlignment.Far)
            {
                xCorrection = -emSize * 1 / 6;
            }

            float yCorrection = (float)(family.GetCellAscent(FontStyle.Regular)) / (float)(family.GetEmHeight(FontStyle.Regular)) * emSize;

            // TODO: font property
            PointF p = new PointF(ctp.X - xCorrection, ctp.Y - yCorrection);

            textGeometry.AddString(text, family, style, emSize, p, sf);
            if (!textGeometry.GetBounds().IsEmpty)
            {
                float bboxWidth = textGeometry.GetBounds().Width;
                if (sf.Alignment == StringAlignment.Center)
                {
                    bboxWidth /= 2;
                }
                else if (sf.Alignment == StringAlignment.Far)
                {
                    bboxWidth = 0;
                }

                ctp.X += bboxWidth + emSize / 4;
            }

            GdiSvgPaint fillPaint = new GdiSvgPaint(element, "fill");
            Brush       brush     = fillPaint.GetBrush(textGeometry);

            GdiSvgPaint strokePaint = new GdiSvgPaint(element, "stroke");
            Pen         pen         = strokePaint.GetPen(textGeometry);

            if (brush != null)
            {
                if (brush is PathGradientBrush)
                {
                    GdiGradientFill gps = fillPaint.PaintFill as GdiGradientFill;

                    _graphics.SetClip(gps.GetRadialGradientRegion(textGeometry.GetBounds()), CombineMode.Exclude);

                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)brush).InterpolationColors.Colors[0]);
                    _graphics.FillPath(this, tempBrush, textGeometry);
                    tempBrush.Dispose();
                    _graphics.ResetClip();
                }

                _graphics.FillPath(this, brush, textGeometry);
                brush.Dispose();
            }

            if (pen != null)
            {
                if (pen.Brush is PathGradientBrush)
                {
                    GdiGradientFill      gps       = strokePaint.PaintFill as GdiGradientFill;
                    GdiGraphicsContainer container = _graphics.BeginContainer();

                    _graphics.SetClip(gps.GetRadialGradientRegion(textGeometry.GetBounds()), CombineMode.Exclude);

                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)pen.Brush).InterpolationColors.Colors[0]);
                    Pen        tempPen   = new Pen(tempBrush, pen.Width);
                    _graphics.DrawPath(this, tempPen, textGeometry);
                    tempPen.Dispose();
                    tempBrush.Dispose();

                    _graphics.EndContainer(container);
                }

                _graphics.DrawPath(this, pen, textGeometry);
                pen.Dispose();
            }

            textGeometry.Dispose();
        }
Пример #7
0
        private Pen GetPen(GraphicsPath gp)
        {
            GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "stroke");

            return(paint.GetPen(gp));
        }
Пример #8
0
        private Brush GetBrush(GraphicsPath gp)
        {
            GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "fill");

            return(paint.GetBrush(gp));
        }
        public override void Render(GdiGraphicsRenderer renderer)
        {
            GdiGraphicsWrapper graphics = renderer.GraphicsWrapper;

            SvgRenderingHint hint = element.RenderingHint;

            if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping)
            {
                return;
            }
            if (element.ParentNode is SvgClipPathElement)
            {
                return;
            }

            SvgStyleableElement styleElm = (SvgStyleableElement)element;

            string sVisibility = styleElm.GetPropertyValue("visibility");
            string sDisplay    = styleElm.GetPropertyValue("display");

            if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none"))
            {
                return;
            }

            GraphicsPath gp = CreatePath(element);

            if (gp != null)
            {
                Clip(graphics);

                GdiSvgPaint fillPaint = new GdiSvgPaint(styleElm, "fill");
                Brush       brush     = fillPaint.GetBrush(gp);

                GdiSvgPaint strokePaint = new GdiSvgPaint(styleElm, "stroke");
                Pen         pen         = strokePaint.GetPen(gp);

                if (brush != null)
                {
                    if (brush is PathGradientBrush)
                    {
                        GdiGradientFill gps = fillPaint.PaintFill as GdiGradientFill;

                        graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);

                        SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)brush).InterpolationColors.Colors[0]);
                        graphics.FillPath(this, tempBrush, gp);
                        tempBrush.Dispose();
                        graphics.ResetClip();
                    }

                    graphics.FillPath(this, brush, gp);
                    brush.Dispose();
                    brush = null;
                }

                if (pen != null)
                {
                    if (pen.Brush is PathGradientBrush)
                    {
                        GdiGradientFill      gps       = strokePaint.PaintFill as GdiGradientFill;
                        GdiGraphicsContainer container = graphics.BeginContainer();

                        graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);

                        SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)pen.Brush).InterpolationColors.Colors[0]);
                        Pen        tempPen   = new Pen(tempBrush, pen.Width);
                        graphics.DrawPath(this, tempPen, gp);
                        tempPen.Dispose();
                        tempBrush.Dispose();

                        graphics.EndContainer(container);
                    }

                    graphics.DrawPath(this, pen, gp);
                    pen.Dispose();
                    pen = null;
                }

                gp.Dispose();
                gp = null;
            }

            PaintMarkers(renderer, styleElm, graphics);
        }
Пример #10
0
        private Brush GetBrush(GraphicsPath gp, string propPrefix)
        {
            SvgPaint     painter;
            SvgPaintType curPaintType = this.PaintType;

            if (curPaintType == SvgPaintType.None)
            {
                return(null);
            }
            else if (curPaintType == SvgPaintType.CurrentColor)
            {
                painter = new GdiSvgPaint(_element, "color");
            }
            else
            {
                painter = this;
            }

            SvgPaintType paintType = painter.PaintType;

            if (paintType == SvgPaintType.Uri || paintType == SvgPaintType.UriCurrentColor ||
                paintType == SvgPaintType.UriNone || paintType == SvgPaintType.UriRgbColor ||
                paintType == SvgPaintType.UriRgbColorIccColor)
            {
                _paintFill = GetPaintFill(painter.Uri);
                if (_paintFill != null)
                {
                    Brush br = _paintFill.GetBrush(gp.GetBounds());

                    LinearGradientBrush lgb = br as LinearGradientBrush;
                    if (lgb != null)
                    {
                        int opacityl = GetOpacity(propPrefix);
                        for (int i = 0; i < lgb.InterpolationColors.Colors.Length; i++)
                        {
                            lgb.InterpolationColors.Colors[i] =
                                Color.FromArgb(opacityl, lgb.InterpolationColors.Colors[i]);
                        }
                        for (int i = 0; i < lgb.LinearColors.Length; i++)
                        {
                            lgb.LinearColors[i] = Color.FromArgb(opacityl, lgb.LinearColors[i]);
                        }

                        return(br);
                    }

                    PathGradientBrush pgb = br as PathGradientBrush;
                    if (pgb != null)
                    {
                        int opacityl = GetOpacity(propPrefix);
                        for (int i = 0; i < pgb.InterpolationColors.Colors.Length; i++)
                        {
                            pgb.InterpolationColors.Colors[i] =
                                Color.FromArgb(opacityl, pgb.InterpolationColors.Colors[i]);
                        }
                        for (int i = 0; i < pgb.SurroundColors.Length; i++)
                        {
                            pgb.SurroundColors[i] = Color.FromArgb(opacityl, pgb.SurroundColors[i]);
                        }

                        return(br);
                    }
                }
                else
                {
                    if (curPaintType == SvgPaintType.UriNone ||
                        curPaintType == SvgPaintType.Uri)
                    {
                        return(null);
                    }
                    else if (curPaintType == SvgPaintType.UriCurrentColor)
                    {
                        painter = new GdiSvgPaint(_element, "color");
                    }
                    else
                    {
                        painter = this;
                    }
                }
            }

            if (painter == null || painter.RgbColor == null)
            {
                return(null);
            }

            SolidBrush brush   = new SolidBrush(GdiConverter.ToColor(painter.RgbColor));
            int        opacity = GetOpacity(propPrefix);

            brush.Color = Color.FromArgb(opacity, brush.Color);
            return(brush);
        }
Пример #11
0
        public override void Render(GdiGraphicsRenderer renderer)
        {
            var graphics = renderer.GdiGraphics;

            SvgRenderingHint hint = _svgElement.RenderingHint;

            if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping)
            {
                return;
            }
            if (_svgElement.ParentNode is SvgClipPathElement)
            {
                return;
            }
            var comparer = StringComparison.OrdinalIgnoreCase;

            SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement;

            string sVisibility = styleElm.GetPropertyValue(CssConstants.PropVisibility);
            string sDisplay    = styleElm.GetPropertyValue(CssConstants.PropDisplay);

            if (string.Equals(sVisibility, CssConstants.ValHidden, comparer) ||
                string.Equals(sDisplay, CssConstants.ValNone, comparer))
            {
                return;
            }

            GraphicsPath gp = CreatePath(_svgElement);

            if (gp == null)
            {
                return;
            }

            SetClip(graphics);

            GdiSvgPaint fillPaint = new GdiSvgPaint(styleElm, "fill");
            Brush       brush     = fillPaint.GetBrush(gp);

            GdiSvgPaint strokePaint = new GdiSvgPaint(styleElm, "stroke");
            Pen         pen         = strokePaint.GetPen(gp);

            if (brush != null)
            {
                if (brush is PathGradientBrush)
                {
                    var gps = fillPaint.PaintFill as GdiRadialGradientFill;

                    graphics.SetClip(gps.GetRadialRegion(gp.GetBounds()), CombineMode.Exclude);

                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)brush).InterpolationColors.Colors[0]);
                    graphics.FillPath(this, tempBrush, gp);
                    tempBrush.Dispose();
                    graphics.ResetClip();
                }

                graphics.FillPath(this, brush, gp);
                brush.Dispose();
                brush = null;
            }

            if (pen != null)
            {
                if (pen.Brush is PathGradientBrush)
                {
                    var gps = strokePaint.PaintFill as GdiRadialGradientFill;
                    GdiGraphicsContainer container = graphics.BeginContainer();

                    graphics.SetClip(gps.GetRadialRegion(gp.GetBounds()), CombineMode.Exclude);

                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)pen.Brush).InterpolationColors.Colors[0]);
                    Pen        tempPen   = new Pen(tempBrush, pen.Width);
                    graphics.DrawPath(this, tempPen, gp);
                    tempPen.Dispose();
                    tempBrush.Dispose();

                    graphics.EndContainer(container);
                }

                graphics.DrawPath(this, pen, gp);
                pen.Dispose();
                pen = null;
            }

            gp.Dispose();
            gp = null;

            PaintMarkers(renderer, styleElm, graphics);
        }
Пример #12
0
        private Brush GetBrush(GraphicsPath gp, string propPrefix)
        {
            SvgPaint painter;
            SvgPaintType curPaintType = this.PaintType;
            if (curPaintType == SvgPaintType.None)
            {
                return null;
            }
            else if (curPaintType == SvgPaintType.CurrentColor)
            {
                painter = new GdiSvgPaint(_element, "color");
            }
            else
            {
                painter = this;
            }

            SvgPaintType paintType = painter.PaintType;
            if (paintType == SvgPaintType.Uri     || paintType == SvgPaintType.UriCurrentColor ||
                paintType == SvgPaintType.UriNone || paintType == SvgPaintType.UriRgbColor     ||
                paintType == SvgPaintType.UriRgbColorIccColor)
            {
                _paintFill = GetPaintFill(painter.Uri);
                if (_paintFill != null)
                {
                    Brush br = _paintFill.GetBrush(gp.GetBounds());

                    LinearGradientBrush lgb = br as LinearGradientBrush;
                    if (lgb != null)
                    {
                        int opacityl = GetOpacity(propPrefix);
                        for (int i = 0; i < lgb.InterpolationColors.Colors.Length; i++)
                        {
                            lgb.InterpolationColors.Colors[i] =
                                Color.FromArgb(opacityl, lgb.InterpolationColors.Colors[i]);
                        }
                        for (int i = 0; i < lgb.LinearColors.Length; i++)
                        {
                            lgb.LinearColors[i] = Color.FromArgb(opacityl, lgb.LinearColors[i]);
                        }

                        return br;
                    }

                    PathGradientBrush pgb = br as PathGradientBrush;
                    if (pgb != null)
                    {
                        int opacityl = GetOpacity(propPrefix);
                        for (int i = 0; i < pgb.InterpolationColors.Colors.Length; i++)
                        {
                            pgb.InterpolationColors.Colors[i] =
                                Color.FromArgb(opacityl, pgb.InterpolationColors.Colors[i]);
                        }
                        for (int i = 0; i < pgb.SurroundColors.Length; i++)
                        {
                            pgb.SurroundColors[i] = Color.FromArgb(opacityl, pgb.SurroundColors[i]);
                        }

                        return br;
                    }
                }
                else
                {
                    if (curPaintType == SvgPaintType.UriNone ||
                        curPaintType == SvgPaintType.Uri)
                    {
                        return null;
                    }
                    else if (curPaintType == SvgPaintType.UriCurrentColor)
                    {
                        painter = new GdiSvgPaint(_element, "color");
                    }
                    else
                    {
                        painter = this;
                    }
                }
            }

            if (painter == null || painter.RgbColor == null)
            {
                return null;
            }

            SolidBrush brush = new SolidBrush(GdiConverter.ToColor(painter.RgbColor));
            int opacity = GetOpacity(propPrefix);
            brush.Color = Color.FromArgb(opacity, brush.Color);
            return brush;
        }