Ejemplo n.º 1
0
 /// <summary>
 /// Removes any previously applied transforms from the specified <see cref="ISvgRenderer"/>.
 /// </summary>
 /// <param name="renderer">The <see cref="ISvgRenderer"/> that should have transforms removed.</param>
 protected internal virtual void PopTransforms(ISvgRenderer renderer)
 {
     renderer.Transform = _graphicsTransform;
     _graphicsTransform.Dispose();
     _graphicsTransform = null;
     renderer.SetClip(_graphicsClip);
     _graphicsClip = null;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Common code for rendering a marker once the orientation angle has been calculated
        /// </summary>
        /// <param name="fAngle"></param>
        /// <param name="pRenderer"></param>
        /// <param name="pOwner"></param>
        /// <param name="pMarkerPoint"></param>
        private void RenderPart2(float fAngle, SvgRenderer pRenderer, SvgPath pOwner, PointF pMarkerPoint)
        {
            Pen pRenderPen = CreatePen(pOwner, pRenderer);

            GraphicsPath markerPath = GetClone(pOwner);

            Matrix transMatrix = new Matrix();

            transMatrix.Translate(pMarkerPoint.X, pMarkerPoint.Y);
            if (Orient.IsAuto)
            {
                transMatrix.Rotate(fAngle);
            }
            else
            {
                transMatrix.Rotate(Orient.Angle);
            }
            switch (MarkerUnits)
            {
            case SvgMarkerUnits.strokeWidth:
                transMatrix.Translate(AdjustForViewBoxWidth(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this) *
                                                            pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this)),
                                      AdjustForViewBoxHeight(-RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this) *
                                                             pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this)));
                break;

            case SvgMarkerUnits.userSpaceOnUse:
                transMatrix.Translate(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this),
                                      -RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this));
                break;
            }
            markerPath.Transform(transMatrix);
            pRenderer.DrawPath(pRenderPen, markerPath);

            SvgPaintServer pFill     = Fill;
            SvgFillRule    pFillRule = FillRule;                                                        // TODO: What do we use the fill rule for?
            float          fOpacity  = FillOpacity;

            if (pFill != null)
            {
                Brush pBrush = pFill.GetBrush(this, pRenderer, fOpacity);
                pRenderer.FillPath(pBrush, markerPath);
                pBrush.Dispose();
            }
            pRenderPen.Dispose();
            markerPath.Dispose();
            transMatrix.Dispose();
        }
Ejemplo n.º 3
0
        private GraphicsPath GetPath(ISvgRenderer renderer, string text, IList <RectangleF> ranges, bool measureSpaces)
        {
            EnsureDictionaries();

            RectangleF   bounds;
            SvgGlyph     glyph;
            SvgKern      kern;
            GraphicsPath path;
            SvgGlyph     prevGlyph = null;
            Matrix       scaleMatrix;
            float        xPos = 0;

            var ascent = Ascent(renderer);

            var result = new GraphicsPath();

            if (string.IsNullOrEmpty(text))
            {
                return(result);
            }

            for (int i = 0; i < text.Length; i++)
            {
                if (!_glyphs.TryGetValue(text.Substring(i, 1), out glyph))
                {
                    glyph = _font.Descendants().OfType <SvgMissingGlyph>().First();
                }
                if (prevGlyph != null && _kerning.TryGetValue(prevGlyph.GlyphName + "|" + glyph.GlyphName, out kern))
                {
                    xPos -= kern.Kerning * _emScale;
                }
                path        = (GraphicsPath)glyph.Path(renderer).Clone();
                scaleMatrix = new Matrix();
                scaleMatrix.Scale(_emScale, -1 * _emScale, MatrixOrder.Append);
                scaleMatrix.Translate(xPos, ascent, MatrixOrder.Append);
                path.Transform(scaleMatrix);
                scaleMatrix.Dispose();

                bounds = path.GetBounds();
                if (ranges != null)
                {
                    if (measureSpaces && bounds == RectangleF.Empty)
                    {
                        ranges.Add(new RectangleF(xPos, 0, glyph.HorizAdvX * _emScale, ascent));
                    }
                    else
                    {
                        ranges.Add(bounds);
                    }
                }
                if (path.PointCount > 0)
                {
                    result.AddPath(path, false);
                }

                xPos     += glyph.HorizAdvX * _emScale;
                prevGlyph = glyph;
            }

            return(result);
        }