/// <summary>Clears the document of all it's content, including scripts and styles.</summary>
        public override void clear()
        {
            svg = null;

            // Gracefully clear the innerHTML:
            base.clear();
        }
Beispiel #2
0
        public RenderContext(SVGSVGElement drawing)
        {
            Drawing = drawing;

            // Create the tex too:
            Filter = new Loonim.SurfaceTexture();

            // Create the draw surface:
            DrawInfo = new Loonim.DrawInfo();
        }
Beispiel #3
0
        public void AddViewBoxTransform(BoxRegion region, AspectRatio aspectRatio, SVGSVGElement frag)
        {
            // Get the tags computed style:
            Css.ComputedStyle tagStyle = (frag == null) ? null : frag.Style.Computed;

            float x = (tagStyle == null ? 0 : tagStyle.OffsetLeft);
            float y = (tagStyle == null ? 0 : tagStyle.OffsetTop);

            if (region.IsEmpty)
            {
                PushMatrix(TranslateMatrix(x, y));
                return;
            }

            float width  = (tagStyle == null ? region.Width : tagStyle.PixelWidth);
            float height = (tagStyle == null ? region.Height : tagStyle.PixelHeight);

            float fScaleX = width / region.Width;
            float fScaleY = height / region.Height;             //(this.MinY < 0 ? -1 : 1) *
            float fMinX   = -region.X * fScaleX;
            float fMinY   = -region.Y * fScaleY;

            if (aspectRatio == null)
            {
                aspectRatio = new AspectRatio(SVGPreserveAspectRatio.xMidYMid, false);
            }

            if (aspectRatio.Align != SVGPreserveAspectRatio.none)
            {
                if (aspectRatio.Slice)
                {
                    fScaleX = (float)Math.Max(fScaleX, fScaleY);
                    fScaleY = (float)Math.Max(fScaleX, fScaleY);
                }
                else
                {
                    fScaleX = (float)Math.Min(fScaleX, fScaleY);
                    fScaleY = (float)Math.Min(fScaleX, fScaleY);
                }

                float fViewMidX = (region.Width / 2) * fScaleX;
                float fViewMidY = (region.Height / 2) * fScaleY;
                float fMidX     = width / 2;
                float fMidY     = height / 2;
                fMinX = -region.X * fScaleX;
                fMinY = -region.Y * fScaleY;

                switch (aspectRatio.Align)
                {
                case SVGPreserveAspectRatio.xMinYMin:
                    break;

                case SVGPreserveAspectRatio.xMidYMin:
                    fMinX += fMidX - fViewMidX;
                    break;

                case SVGPreserveAspectRatio.xMaxYMin:
                    fMinX += width - region.Width * fScaleX;
                    break;

                case SVGPreserveAspectRatio.xMinYMid:
                    fMinY += fMidY - fViewMidY;
                    break;

                case SVGPreserveAspectRatio.xMidYMid:
                    fMinX += fMidX - fViewMidX;
                    fMinY += fMidY - fViewMidY;
                    break;

                case SVGPreserveAspectRatio.xMaxYMid:
                    fMinX += width - region.Width * fScaleX;
                    fMinY += fMidY - fViewMidY;
                    break;

                case SVGPreserveAspectRatio.xMinYMax:
                    fMinY += height - region.Height * fScaleY;
                    break;

                case SVGPreserveAspectRatio.xMidYMax:
                    fMinX += fMidX - fViewMidX;
                    fMinY += height - region.Height * fScaleY;
                    break;

                case SVGPreserveAspectRatio.xMaxYMax:
                    fMinX += width - region.Width * fScaleX;
                    fMinY += height - region.Height * fScaleY;
                    break;

                default:
                    break;
                }
            }

            // Clip now:
            SetClip(new BoxRegion(x, y, width, height), false);

            Matrix4x4 matrix = ScaleMatrix(fScaleX, fScaleY);

            matrix *= TranslateMatrix(x, y);
            matrix *= TranslateMatrix(fMinX, fMinY);

            // Push it:
            PushMatrix(matrix);
        }