示例#1
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);
                     }
                 }
             }
         }
     }
 }