Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
                     }
                 }
             }
         }
     }
 }