Exemplo n.º 1
0
        /// <summary>Applies an opacity value to a Loonim node.</summary>
        private void ApplyOpacity(float opacity, Loonim.Property prop, ref Loonim.TextureNode fill)
        {
            opacity = (float)Math.Min(Math.Max(opacity * Opacity, 0), 1);

            if (opacity == 1f)
            {
                return;
            }

            // If the value is simply a property, apply opacity straight to that:

            if (prop == null)
            {
                // Must create a multiply by..
                Color mult = new Color(1f, 1f, 1f, opacity);

                fill = new Loonim.Multiply(
                    fill,
                    new Loonim.Property(mult)
                    );
            }
            else
            {
                // Must overwrite (because this can be called multiple times):
                prop.Colour.a = opacity;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders the fill of the <see cref="SvgVisualElement"/> to the specified <see cref="RenderContext"/>
        /// </summary>
        protected internal virtual void BuildFill(VectorPath path, RenderContext renderer)
        {
            // Get the fill:
            Loonim.TextureNode fill = Fill;

            if (fill == null)
            {
                // Fill isn't active.
                return;
            }

            // Get as a property:
            Loonim.Property prop = (fill as Loonim.Property);

            if (prop != null)
            {
                // Check if it's transparent:
                if (prop.Colour.a == 0f)
                {
                    return;
                }
            }

            ApplyOpacity(FillOpacity, prop, ref fill);

            // Fill now!
            renderer.FillPath(fill, path, (FillRule == "evenodd"));
        }
Exemplo n.º 3
0
        public void FillPath(Loonim.TextureNode fill, VectorPath transformedPath, bool evenOddFillMethod)
        {
            // Create Loonim node:
            Loonim.ClippingPath path = new Loonim.ClippingPath(fill, transformedPath);

            // Add to draw stack:
            if (DrawStack == null)
            {
                DrawStack            = new Loonim.Stack(1);
                DrawStack.Sources[0] = path;
            }
            else
            {
                // Add a path to the draw stack:
                DrawStack.Add(path);
            }
        }
Exemplo n.º 4
0
        public TextureNodeValue(Css.Value val)
        {
            // Value could be a set but not a colour. If that's the case, use the last one.
            // E.g. "red device-cmyk(0.1,....)"
            RawValue = val;

            Color result;

            if (val.IsColour)
            {
                result = val.GetColour(null, null);
            }
            else
            {
                result = val[val.Count - 1].GetColour(null, null);
            }

            // Assume solid col for now:
            TextureNode = new Loonim.Property(result);
        }
Exemplo n.º 5
0
        private bool BuildDefaultStroke(VectorPath path, RenderContext renderer)
        {
            Loonim.TextureNode stroke = Stroke;

            if (stroke == null || path.FirstPathNode == null)
            {
                return(false);
            }

            // Get as a property:
            Loonim.Property prop = (stroke as Loonim.Property);

            if (prop != null)
            {
                // Check if it's transparent:
                if (prop.Colour.a == 0f)
                {
                    return(false);
                }
            }

            float strokeWidth = StrokeWidth;

            if (strokeWidth <= 0)
            {
                return(false);
            }

            ApplyOpacity(StrokeOpacity, prop, ref stroke);

            if (path.Width == 0f)
            {
                path.RecalculateBounds();
            }

            // Stroke now!
            renderer.StrokePath(stroke, path, strokeWidth, this);

            // Ok:
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>Computes a stroke path now and adds it.</summary>
        public void StrokePath(Loonim.TextureNode stroke, VectorPath transformedPath, float width, SVGElement settings)
        {
            if (StrokeHelper == null)
            {
                StrokeHelper = new Loonim.StrokePathMesh();
            }

            // Get other settings:
            StrokeHelper.LineCapMode = settings.StrokeLineCap;
            // Css.Value dashArray=settings.StrokeDashArray;
            StrokeHelper.LineJoinMode = settings.StrokeLineJoin;
            StrokeHelper.MiterLimit   = settings.StrokeMiterLimit;
            StrokeHelper.Accuracy     = Loonim.ClippingPath.DefaultAccuracy;
            StrokeHelper.Width        = width;

            // Generate now!
            List <Mesh> meshes = StrokeHelper.GenerateMeshes(transformedPath);

            foreach (Mesh mesh in meshes)
            {
                // Create Loonim node for each mesh:
                Loonim.ClippingPath path = new Loonim.ClippingPath(stroke, mesh);

                // Add to draw stack:
                if (DrawStack == null)
                {
                    DrawStack            = new Loonim.Stack(1);
                    DrawStack.Sources[0] = path;
                }
                else
                {
                    // Add a path to the draw stack:
                    DrawStack.Add(path);
                }
            }
        }