示例#1
0
        protected internal override void DoDraw(SvgDrawContext context)
        {
            ResourceResolver resourceResolver = context.GetResourceResolver();

            if (resourceResolver == null || this.attributesAndStyles == null)
            {
                return;
            }
            String     uri     = this.attributesAndStyles.Get(SvgConstants.Attributes.XLINK_HREF);
            PdfXObject xObject = resourceResolver.RetrieveImageExtended(uri);

            if (xObject == null)
            {
                return;
            }
            PdfCanvas currentCanvas = context.GetCurrentCanvas();
            float     x             = 0;

            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.X))
            {
                x = CssUtils.ParseAbsoluteLength(attributesAndStyles.Get(SvgConstants.Attributes.X));
            }
            float y = 0;

            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.Y))
            {
                y = CssUtils.ParseAbsoluteLength(attributesAndStyles.Get(SvgConstants.Attributes.Y));
            }
            float width = 0;

            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.WIDTH))
            {
                width = CssUtils.ParseAbsoluteLength(attributesAndStyles.Get(SvgConstants.Attributes.WIDTH));
            }
            float height = 0;

            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.HEIGHT))
            {
                height = CssUtils.ParseAbsoluteLength(attributesAndStyles.Get(SvgConstants.Attributes.HEIGHT));
            }
            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.PRESERVE_ASPECT_RATIO))
            {
            }
            // TODO RND-876
            float v = y + height;

            currentCanvas.AddXObject(xObject, width, 0, 0, -height, x, v);
        }
        protected internal override void DoDraw(SvgDrawContext context)
        {
            ResourceResolver resourceResolver = context.GetResourceResolver();

            if (resourceResolver == null || this.attributesAndStyles == null)
            {
                return;
            }
            String     uri     = this.attributesAndStyles.Get(SvgConstants.Attributes.XLINK_HREF);
            PdfXObject xObject = resourceResolver.RetrieveImageExtended(uri);

            if (xObject == null)
            {
                return;
            }
            PdfCanvas currentCanvas = context.GetCurrentCanvas();
            float     x             = 0;

            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.X))
            {
                x = CssUtils.ParseAbsoluteLength(attributesAndStyles.Get(SvgConstants.Attributes.X));
            }
            float y = 0;

            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.Y))
            {
                y = CssUtils.ParseAbsoluteLength(attributesAndStyles.Get(SvgConstants.Attributes.Y));
            }
            float width = 0;

            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.WIDTH))
            {
                width = CssUtils.ParseAbsoluteLength(attributesAndStyles.Get(SvgConstants.Attributes.WIDTH));
            }
            float height = 0;

            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.HEIGHT))
            {
                height = CssUtils.ParseAbsoluteLength(attributesAndStyles.Get(SvgConstants.Attributes.HEIGHT));
            }
            String preserveAspectRatio = "";

            if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.PRESERVE_ASPECT_RATIO))
            {
                preserveAspectRatio = attributesAndStyles.Get(SvgConstants.Attributes.PRESERVE_ASPECT_RATIO);
            }
            preserveAspectRatio = preserveAspectRatio.ToLowerInvariant();
            if (!SvgConstants.Values.NONE.Equals(preserveAspectRatio) && !(width == 0 || height == 0))
            {
                float normalizedWidth;
                float normalizedHeight;
                if (xObject.GetWidth() / width > xObject.GetHeight() / height)
                {
                    normalizedWidth  = width;
                    normalizedHeight = xObject.GetHeight() / xObject.GetWidth() * width;
                }
                else
                {
                    normalizedWidth  = xObject.GetWidth() / xObject.GetHeight() * height;
                    normalizedHeight = height;
                }
                switch (preserveAspectRatio.ToLowerInvariant())
                {
                case SvgConstants.Values.XMIN_YMIN: {
                    break;
                }

                case SvgConstants.Values.XMIN_YMID: {
                    y += Math.Abs(normalizedHeight - height) / 2;
                    break;
                }

                case SvgConstants.Values.XMIN_YMAX: {
                    y += Math.Abs(normalizedHeight - height);
                    break;
                }

                case SvgConstants.Values.XMID_YMIN: {
                    x += Math.Abs(normalizedWidth - width) / 2;
                    break;
                }

                case SvgConstants.Values.XMID_YMAX: {
                    x += Math.Abs(normalizedWidth - width) / 2;
                    y += Math.Abs(normalizedHeight - height);
                    break;
                }

                case SvgConstants.Values.XMAX_YMIN: {
                    x += Math.Abs(normalizedWidth - width);
                    break;
                }

                case SvgConstants.Values.XMAX_YMID: {
                    x += Math.Abs(normalizedWidth - width);
                    y += Math.Abs(normalizedHeight - height) / 2;
                    break;
                }

                case SvgConstants.Values.XMAX_YMAX: {
                    x += Math.Abs(normalizedWidth - width);
                    y += Math.Abs(normalizedHeight - height);
                    break;
                }

                case SvgConstants.Values.DEFAULT_ASPECT_RATIO:
                default: {
                    x += Math.Abs(normalizedWidth - width) / 2;
                    y += Math.Abs(normalizedHeight - height) / 2;
                    break;
                }
                }
                width  = normalizedWidth;
                height = normalizedHeight;
            }
            float v = y + height;

            currentCanvas.AddXObject(xObject, width, 0, 0, -height, x, v);
        }