示例#1
0
 /// <summary>Adds a new tag to the tag structure.</summary>
 /// <remarks>
 /// Adds a new tag to the tag structure.
 /// This method call moves this
 /// <c>TagTreePointer</c>
 /// to the added kid.
 /// <br/>
 /// New tag will have a role and attributes defined by the given IAccessibleElement.
 /// <br /><br />
 /// If
 ///
 /// is true then a newly created tag will retain the connection with given
 /// accessible element. See
 /// <see cref="MoveToTag(IAccessibleElement)"/>
 /// for more explanations about tag connections concept.
 /// <br/><br/>
 /// If the same accessible element is connected to the tag and is added twice to the same parent -
 /// this
 /// <c>TagTreePointer</c>
 /// instance would move to connected kid instead of creating tag twice.
 /// But if it is added to some other parent, then connection will be removed.
 /// <p>
 /// <br/><br/>
 /// This call is equivalent of calling sequentially
 /// <see cref="SetNextNewKidIndex(int)"/>
 /// and
 /// <see cref="AddTag(IAccessibleElement, bool)"/>
 /// .
 /// </remarks>
 /// <param name="index">zero-based index in kids array of parent tag at which new tag will be added.</param>
 /// <param name="element">accessible element which represents a new tag.</param>
 /// <param name="keepConnectedToTag">defines if to retain the connection between accessible element and the tag.
 ///     </param>
 /// <returns>
 /// this
 /// <see cref="TagTreePointer"/>
 /// instance.
 /// </returns>
 public virtual iText.Kernel.Pdf.Tagutils.TagTreePointer AddTag(int index, IAccessibleElement element, bool
                                                                keepConnectedToTag)
 {
     tagStructureContext.ThrowExceptionIfRoleIsInvalid(element.GetRole());
     if (!tagStructureContext.IsElementConnectedToTag(element))
     {
         SetNextNewKidIndex(index);
         SetCurrentStructElem(AddNewKid(element, keepConnectedToTag));
     }
     else
     {
         PdfStructElem connectedStruct = tagStructureContext.GetStructConnectedToModel(element);
         if (connectedStruct.GetParent() != null && GetCurrentStructElem().GetPdfObject() == ((PdfStructElem)connectedStruct
                                                                                              .GetParent()).GetPdfObject())
         {
             SetCurrentStructElem(connectedStruct);
         }
         else
         {
             tagStructureContext.RemoveElementConnectionToTag(element);
             SetNextNewKidIndex(index);
             SetCurrentStructElem(AddNewKid(element, keepConnectedToTag));
         }
     }
     return(this);
 }
示例#2
0
 /// <summary>Method for internal usages.</summary>
 /// <remarks>
 /// Method for internal usages.
 /// Essentially, all it does is just making sure that for connected tags properties are
 /// up to date with connected accessible elements properties.
 /// </remarks>
 public virtual void ActualizeTagsProperties()
 {
     foreach (KeyValuePair <IAccessibleElement, PdfStructElem> structToModel in connectedModelToStruct)
     {
         IAccessibleElement element    = structToModel.Key;
         PdfStructElem      structElem = structToModel.Value;
         structElem.SetRole(element.GetRole());
         if (element.GetAccessibilityProperties() != null)
         {
             element.GetAccessibilityProperties().SetToStructElem(structElem);
         }
     }
 }
示例#3
0
        /// <summary>Gets current tag role.</summary>
        /// <returns>current tag role.</returns>
        public virtual PdfName GetRole()
        {
            IAccessibleElement model = tagStructureContext.GetModelConnectedToStruct(GetCurrentStructElem());

            if (model != null)
            {
                return(model.GetRole());
            }
            else
            {
                return(GetCurrentStructElem().GetRole());
            }
        }
示例#4
0
        private PdfStructElem AddNewKid(IAccessibleElement element, bool keepConnectedToTag)
        {
            PdfStructElem kid = new PdfStructElem(GetDocument(), element.GetRole());

            if (keepConnectedToTag)
            {
                tagStructureContext.SaveConnectionBetweenStructAndModel(element, kid);
            }
            if (!keepConnectedToTag && element.GetAccessibilityProperties() != null)
            {
                element.GetAccessibilityProperties().SetToStructElem(kid);
            }
            return(AddNewKid(kid));
        }
示例#5
0
 private void RemoveStructToModelConnection(PdfStructElem structElem)
 {
     if (structElem != null)
     {
         IAccessibleElement element = connectedStructToModel.JRemove(structElem.GetPdfObject());
         structElem.SetRole(element.GetRole());
         if (element.GetAccessibilityProperties() != null)
         {
             element.GetAccessibilityProperties().SetToStructElem(structElem);
         }
         if (structElem.GetParent() == null)
         {
             // is flushed
             FlushStructElementAndItKids(structElem);
         }
     }
 }
示例#6
0
        public override void Draw(DrawContext drawContext)
        {
            PdfDocument document = drawContext.GetDocument();

            ApplyDestination(document);
            ApplyAction(document);
            bool               isTagged          = drawContext.IsTaggingEnabled() && GetModelElement() is IAccessibleElement;
            TagTreePointer     tagPointer        = null;
            IAccessibleElement accessibleElement = null;

            if (isTagged)
            {
                accessibleElement = (IAccessibleElement)GetModelElement();
                PdfName role = accessibleElement.GetRole();
                if (role != null && !PdfName.Artifact.Equals(role))
                {
                    tagPointer = document.GetTagStructureContext().GetAutoTaggingPointer();
                    if (!tagPointer.IsElementConnectedToTag(accessibleElement))
                    {
                        AccessibleAttributesApplier.ApplyLayoutAttributes(role, this, document);
                        if (role.Equals(PdfName.TD))
                        {
                            AccessibleAttributesApplier.ApplyTableAttributes(this);
                        }
                        if (role.Equals(PdfName.List))
                        {
                            AccessibleAttributesApplier.ApplyListAttributes(this);
                        }
                    }
                    tagPointer.AddTag(accessibleElement, true);
                }
                else
                {
                    isTagged = false;
                }
            }
            bool isRelativePosition = IsRelativePosition();

            if (isRelativePosition)
            {
                ApplyAbsolutePositioningTranslation(false);
            }
            BeginRotationIfApplied(drawContext.GetCanvas());
            DrawBackground(drawContext);
            DrawBorder(drawContext);
            DrawChildren(drawContext);
            EndRotationIfApplied(drawContext.GetCanvas());
            if (isRelativePosition)
            {
                ApplyAbsolutePositioningTranslation(true);
            }
            if (isTagged)
            {
                tagPointer.MoveToParent();
                if (isLastRendererForModelElement)
                {
                    document.GetTagStructureContext().RemoveElementConnectionToTag(accessibleElement);
                }
            }
            flushed = true;
        }
示例#7
0
        public override void Draw(DrawContext drawContext)
        {
            base.Draw(drawContext);
            PdfDocument    document   = drawContext.GetDocument();
            bool           isTagged   = drawContext.IsTaggingEnabled() && GetModelElement() is IAccessibleElement;
            bool           isArtifact = false;
            TagTreePointer tagPointer = null;

            if (isTagged)
            {
                tagPointer = document.GetTagStructureContext().GetAutoTaggingPointer();
                IAccessibleElement accessibleElement = (IAccessibleElement)GetModelElement();
                PdfName            role = accessibleElement.GetRole();
                if (role != null && !PdfName.Artifact.Equals(role))
                {
                    AccessibleAttributesApplier.ApplyLayoutAttributes(accessibleElement.GetRole(), this, document);
                    tagPointer.AddTag(accessibleElement);
                }
                else
                {
                    isTagged = false;
                    if (PdfName.Artifact.Equals(role))
                    {
                        isArtifact = true;
                    }
                }
            }
            ApplyMargins(occupiedArea.GetBBox(), false);
            bool isRelativePosition = IsRelativePosition();

            if (isRelativePosition)
            {
                ApplyAbsolutePositioningTranslation(false);
            }
            if (fixedYPosition == null)
            {
                fixedYPosition = occupiedArea.GetBBox().GetY() + pivotY;
            }
            if (fixedXPosition == null)
            {
                fixedXPosition = occupiedArea.GetBBox().GetX();
            }
            PdfCanvas canvas = drawContext.GetCanvas();

            if (isTagged)
            {
                canvas.OpenTag(tagPointer.GetTagReference());
            }
            else
            {
                if (isArtifact)
                {
                    canvas.OpenTag(new CanvasArtifact());
                }
            }
            PdfXObject xObject = ((Image)(GetModelElement())).GetXObject();

            canvas.AddXObject(xObject, matrix[0], matrix[1], matrix[2], matrix[3], (float)fixedXPosition + deltaX, (float
                                                                                                                    )fixedYPosition);
            if (true.Equals(GetPropertyAsBoolean(Property.FLUSH_ON_DRAW)))
            {
                xObject.Flush();
            }
            if (isTagged || isArtifact)
            {
                canvas.CloseTag();
            }
            if (isRelativePosition)
            {
                ApplyAbsolutePositioningTranslation(true);
            }
            ApplyMargins(occupiedArea.GetBBox(), true);
            if (isTagged)
            {
                tagPointer.MoveToParent();
            }
        }
        public override void Draw(DrawContext drawContext)
        {
            bool           isTagged   = drawContext.IsTaggingEnabled() && GetModelElement() is IAccessibleElement;
            TagTreePointer tagPointer = null;

            if (isTagged)
            {
                tagPointer = drawContext.GetDocument().GetTagStructureContext().GetAutoTaggingPointer();
                IAccessibleElement modelElement = (IAccessibleElement)GetModelElement();
                PdfName            role         = modelElement.GetRole();
                if (role != null && !PdfName.Artifact.Equals(role))
                {
                    bool lBodyTagIsCreated = tagPointer.IsElementConnectedToTag(modelElement);
                    if (!lBodyTagIsCreated)
                    {
                        tagPointer.AddTag(PdfName.LI);
                    }
                    else
                    {
                        tagPointer.MoveToTag(modelElement).MoveToParent();
                    }
                }
                else
                {
                    isTagged = false;
                }
            }
            base.Draw(drawContext);
            // It will be null in case of overflow (only the "split" part will contain symbol renderer.
            if (symbolRenderer != null)
            {
                symbolRenderer.SetParent(parent);
                float x = occupiedArea.GetBBox().GetX();
                if (childRenderers.Count > 0)
                {
                    float?yLine = ((AbstractRenderer)childRenderers[0]).GetFirstYLineRecursively();
                    if (yLine != null)
                    {
                        if (symbolRenderer is TextRenderer)
                        {
                            ((TextRenderer)symbolRenderer).MoveYLineTo((float)yLine);
                        }
                        else
                        {
                            symbolRenderer.Move(0, (float)yLine - symbolRenderer.GetOccupiedArea().GetBBox().GetY());
                        }
                    }
                    else
                    {
                        symbolRenderer.Move(0, occupiedArea.GetBBox().GetY() + occupiedArea.GetBBox().GetHeight() - (symbolRenderer
                                                                                                                     .GetOccupiedArea().GetBBox().GetY() + symbolRenderer.GetOccupiedArea().GetBBox().GetHeight()));
                    }
                }
                else
                {
                    symbolRenderer.Move(0, occupiedArea.GetBBox().GetY() + occupiedArea.GetBBox().GetHeight() - symbolRenderer
                                        .GetOccupiedArea().GetBBox().GetHeight() - symbolRenderer.GetOccupiedArea().GetBBox().GetY());
                }
                ListSymbolAlignment listSymbolAlignment = (ListSymbolAlignment)parent.GetProperty <ListSymbolAlignment?>(Property
                                                                                                                         .LIST_SYMBOL_ALIGNMENT, ListSymbolAlignment.RIGHT);
                float xPosition = x - symbolRenderer.GetOccupiedArea().GetBBox().GetX();
                if (listSymbolAlignment == ListSymbolAlignment.RIGHT)
                {
                    xPosition += symbolAreaWidth - symbolRenderer.GetOccupiedArea().GetBBox().GetWidth();
                }
                symbolRenderer.Move(xPosition, 0);
                if (isTagged)
                {
                    tagPointer.AddTag(0, PdfName.Lbl);
                }
                symbolRenderer.Draw(drawContext);
                if (isTagged)
                {
                    tagPointer.MoveToParent();
                }
            }
            if (isTagged)
            {
                tagPointer.MoveToParent();
            }
        }