private bool DrawInClipPath(SvgDrawContext context)
 {
     if (attributesAndStyles.ContainsKey(SvgConstants.Attributes.CLIP_PATH))
     {
         String           clipPathName = attributesAndStyles.Get(SvgConstants.Attributes.CLIP_PATH);
         ISvgNodeRenderer template     = context.GetNamedObject(NormalizeLocalUrlName(clipPathName));
         //Clone template to avoid muddying the state
         if (template is ClipPathSvgNodeRenderer)
         {
             ClipPathSvgNodeRenderer clipPath = (ClipPathSvgNodeRenderer)template.CreateDeepCopy();
             clipPath.SetClippedRenderer(this);
             clipPath.Draw(context);
             return(!clipPath.GetChildren().IsEmpty());
         }
     }
     return(false);
 }
        private TransparentColor GetColorFromAttributeValue(SvgDrawContext context, String rawColorValue, float objectBoundingBoxMargin
                                                            , float parentOpacity)
        {
            if (rawColorValue == null)
            {
                return(null);
            }
            CssDeclarationValueTokenizer tokenizer = new CssDeclarationValueTokenizer(rawColorValue);

            CssDeclarationValueTokenizer.Token token = tokenizer.GetNextValidToken();
            if (token == null)
            {
                return(null);
            }
            String tokenValue = token.GetValue();

            if (tokenValue.StartsWith("url(#") && tokenValue.EndsWith(")"))
            {
                Color            resolvedColor   = null;
                float            resolvedOpacity = 1;
                String           normalizedName  = tokenValue.JSubstring(5, tokenValue.Length - 1).Trim();
                ISvgNodeRenderer colorRenderer   = context.GetNamedObject(normalizedName);
                if (colorRenderer is AbstractGradientSvgNodeRenderer)
                {
                    resolvedColor = ((AbstractGradientSvgNodeRenderer)colorRenderer).CreateColor(context, GetObjectBoundingBox
                                                                                                     (context), objectBoundingBoxMargin, parentOpacity);
                }
                if (resolvedColor != null)
                {
                    return(new TransparentColor(resolvedColor, resolvedOpacity));
                }
                token = tokenizer.GetNextValidToken();
            }
            // may become null after function parsing and reading the 2nd token
            if (token != null)
            {
                String value = token.GetValue();
                if (!SvgConstants.Values.NONE.EqualsIgnoreCase(value))
                {
                    return(new TransparentColor(WebColors.GetRGBColor(value), parentOpacity * GetAlphaFromRGBA(value)));
                }
            }
            return(null);
        }
Пример #3
0
        internal static void DrawMarker(SvgDrawContext context, String moveX, String moveY, MarkerVertexType markerToUse
                                        , AbstractSvgNodeRenderer parent)
        {
            String           elementToReUse = parent.attributesAndStyles.Get(markerToUse.ToString());
            String           normalizedName = SvgTextUtil.FilterReferenceValue(elementToReUse);
            ISvgNodeRenderer template       = context.GetNamedObject(normalizedName);
            //Clone template
            ISvgNodeRenderer namedObject = template == null ? null : template.CreateDeepCopy();

            if (namedObject is MarkerSvgNodeRenderer &&
                // Having markerWidth or markerHeight with negative or zero value disables rendering of the element .
                MarkerWidthHeightAreCorrect((MarkerSvgNodeRenderer)namedObject))
            {
                // setting the parent of the referenced element to this instance
                namedObject.SetParent(parent);
                namedObject.SetAttribute(SvgConstants.Tags.MARKER, markerToUse.ToString());
                namedObject.SetAttribute(SvgConstants.Attributes.X, moveX);
                namedObject.SetAttribute(SvgConstants.Attributes.Y, moveY);
                namedObject.Draw(context);
                // unsetting the parent of the referenced element
                namedObject.SetParent(null);
            }
        }
Пример #4
0
 protected internal override void DoDraw(SvgDrawContext context)
 {
     if (this.attributesAndStyles != null)
     {
         String elementToReUse = this.attributesAndStyles.Get(SvgConstants.Attributes.XLINK_HREF);
         if (elementToReUse == null)
         {
             elementToReUse = this.attributesAndStyles.Get(SvgConstants.Attributes.HREF);
         }
         if (elementToReUse != null && !String.IsNullOrEmpty(elementToReUse) && IsValidHref(elementToReUse))
         {
             String normalizedName = SvgTextUtil.FilterReferenceValue(elementToReUse);
             if (!context.IsIdUsedByUseTagBefore(normalizedName))
             {
                 ISvgNodeRenderer template = context.GetNamedObject(normalizedName);
                 //Clone template
                 ISvgNodeRenderer namedObject = template == null ? null : template.CreateDeepCopy();
                 //Resolve parent inheritance
                 SvgNodeRendererInheritanceResolver iresolver = new SvgNodeRendererInheritanceResolver();
                 iresolver.ApplyInheritanceToSubTree(this, namedObject);
                 if (namedObject != null)
                 {
                     if (namedObject is AbstractSvgNodeRenderer)
                     {
                         ((AbstractSvgNodeRenderer)namedObject).SetPartOfClipPath(partOfClipPath);
                     }
                     PdfCanvas currentCanvas = context.GetCurrentCanvas();
                     float     x             = 0f;
                     float     y             = 0f;
                     if (this.attributesAndStyles.ContainsKey(SvgConstants.Attributes.X))
                     {
                         x = CssUtils.ParseAbsoluteLength(this.attributesAndStyles.Get(SvgConstants.Attributes.X));
                     }
                     if (this.attributesAndStyles.ContainsKey(SvgConstants.Attributes.Y))
                     {
                         y = CssUtils.ParseAbsoluteLength(this.attributesAndStyles.Get(SvgConstants.Attributes.Y));
                     }
                     AffineTransform inverseMatrix = null;
                     if (!CssUtils.CompareFloats(x, 0) || !CssUtils.CompareFloats(y, 0))
                     {
                         AffineTransform translation = AffineTransform.GetTranslateInstance(x, y);
                         currentCanvas.ConcatMatrix(translation);
                         if (partOfClipPath)
                         {
                             try {
                                 inverseMatrix = translation.CreateInverse();
                             }
                             catch (NoninvertibleTransformException ex) {
                                 LogManager.GetLogger(typeof(UseSvgNodeRenderer)).Warn(SvgLogMessageConstant.NONINVERTIBLE_TRANSFORMATION_MATRIX_USED_IN_CLIP_PATH
                                                                                       , ex);
                             }
                         }
                     }
                     // setting the parent of the referenced element to this instance
                     namedObject.SetParent(this);
                     namedObject.Draw(context);
                     // unsetting the parent of the referenced element
                     namedObject.SetParent(null);
                     if (inverseMatrix != null)
                     {
                         currentCanvas.ConcatMatrix(inverseMatrix);
                     }
                 }
             }
         }
     }
 }