Exemplo n.º 1
0
        public static void ApplyTableAttributes(AbstractRenderer renderer)
        {
            if (!(renderer.GetModelElement() is IAccessibleElement))
            {
                return;
            }
            IAccessibleElement accessibleElement = (IAccessibleElement)renderer.GetModelElement();
            PdfDictionary      attributes        = new PdfDictionary();
            PdfName            attributesType    = PdfName.Table;

            attributes.Put(PdfName.O, attributesType);
            if (accessibleElement is Cell)
            {
                Cell cell = (Cell)accessibleElement;
                if (cell.GetRowspan() != 1)
                {
                    attributes.Put(PdfName.RowSpan, new PdfNumber(cell.GetRowspan()));
                }
                if (cell.GetColspan() != 1)
                {
                    attributes.Put(PdfName.ColSpan, new PdfNumber(cell.GetColspan()));
                }
            }
            if (attributes.Size() > 1)
            {
                AccessibilityProperties properties = accessibleElement.GetAccessibilityProperties();
                RemoveSameAttributesTypeIfPresent(properties, attributesType);
                properties.AddAttributes(attributes);
            }
        }
Exemplo n.º 2
0
        public virtual void TagStructureRemovingTest03()
        {
            PdfWriter writer = new PdfWriter(destinationFolder + "tagStructureRemovingTest03.pdf");

            writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION);
            PdfDocument document = new PdfDocument(writer);

            document.SetTagged();
            PdfPage        page       = document.AddNewPage();
            TagTreePointer tagPointer = new TagTreePointer(document);

            tagPointer.SetPageForTagging(page);
            PdfCanvas canvas = new PdfCanvas(page);

            tagPointer.AddTag(PdfName.P);
            IAccessibleElement paragraphElement = tagPointer.GetConnectedElement(true);
            PdfFont            standardFont     = PdfFontFactory.CreateFont(FontConstants.COURIER);

            canvas.BeginText().SetFontAndSize(standardFont, 24).SetTextMatrix(1, 0, 0, 1, 32, 512);
            tagPointer.AddTag(PdfName.Span);
            canvas.OpenTag(tagPointer.GetTagReference()).ShowText("Hello ").CloseTag();
            canvas.SetFontAndSize(standardFont, 30).OpenTag(tagPointer.GetTagReference()).ShowText("World").CloseTag()
            .EndText();
            tagPointer.MoveToParent().MoveToParent();
            document.RemovePage(1);
            PdfPage newPage = document.AddNewPage();

            canvas = new PdfCanvas(newPage);
            tagPointer.SetPageForTagging(newPage);
            tagPointer.MoveToTag(paragraphElement).AddTag(PdfName.Span);
            canvas.OpenTag(tagPointer.GetTagReference()).BeginText().SetFontAndSize(standardFont, 24).SetTextMatrix(1,
                                                                                                                    0, 0, 1, 32, 512).ShowText("Hello.").EndText().CloseTag();
            document.Close();
            CompareResult("tagStructureRemovingTest03.pdf", "cmp_tagStructureRemovingTest03.pdf", "diffRemoving03_");
        }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
        public virtual void TagTreePointerTest06()
        {
            PdfReader reader = new PdfReader(sourceFolder + "taggedDocument.pdf");
            PdfWriter writer = new PdfWriter(destinationFolder + "tagTreePointerTest06.pdf");

            writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION);
            PdfDocument    document   = new PdfDocument(reader, writer);
            TagTreePointer tagPointer = new TagTreePointer(document);

            tagPointer.SetRole(PdfName.Part);
            NUnit.Framework.Assert.AreEqual(tagPointer.GetRole().GetValue(), "Part");
            tagPointer.MoveToKid(PdfName.Table).GetProperties().SetLanguage("en-US");
            tagPointer.MoveToKid(PdfName.TR).MoveToKid(PdfName.TD).MoveToKid(PdfName.P);
            String actualText1 = "Some looong latin text";

            tagPointer.GetProperties().SetActualText(actualText1);
            NUnit.Framework.Assert.IsNull(tagPointer.GetConnectedElement(false));
            IAccessibleElement connectedElement = tagPointer.GetConnectedElement(true);

            tagPointer.MoveToRoot().MoveToKid(PdfName.Table).MoveToKid(1, PdfName.TR).GetProperties().SetActualText("More latin text"
                                                                                                                    );
            connectedElement.SetRole(PdfName.Div);
            connectedElement.GetAccessibilityProperties().SetLanguage("en-Us");
            NUnit.Framework.Assert.AreEqual(connectedElement.GetAccessibilityProperties().GetActualText(), actualText1
                                            );
            document.Close();
            CompareResult("tagTreePointerTest06.pdf", "cmp_tagTreePointerTest06.pdf", "diff06_");
        }
Exemplo n.º 5
0
        public virtual bool IsArtifact(IPropertyContainer hintOwner)
        {
            TaggingHintKey key = GetHintKey(hintOwner);

            if (key != null)
            {
                return(key.IsArtifact());
            }
            else
            {
                IAccessibleElement aElem = null;
                if (hintOwner is IRenderer && ((IRenderer)hintOwner).GetModelElement() is IAccessibleElement)
                {
                    aElem = (IAccessibleElement)((IRenderer)hintOwner).GetModelElement();
                }
                else
                {
                    if (hintOwner is IAccessibleElement)
                    {
                        aElem = (IAccessibleElement)hintOwner;
                    }
                }
                if (aElem != null)
                {
                    return(StandardRoles.ARTIFACT.Equals(aElem.GetAccessibilityProperties().GetRole()));
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public virtual void TagStructureFlushingTest05()
        {
            PdfWriter writer = new PdfWriter(destinationFolder + "tagStructureFlushingTest05.pdf");

            writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION);
            PdfDocument document = new PdfDocument(writer);

            document.SetTagged();
            PdfPage        page1      = document.AddNewPage();
            TagTreePointer tagPointer = new TagTreePointer(document);

            tagPointer.SetPageForTagging(page1);
            PdfCanvas canvas = new PdfCanvas(page1);

            tagPointer.AddTag(PdfName.Div);
            tagPointer.AddTag(PdfName.P);
            IAccessibleElement paragraphElement = tagPointer.GetConnectedElement(true);

            canvas.BeginText();
            PdfFont standardFont = PdfFontFactory.CreateFont(FontConstants.COURIER);

            canvas.SetFontAndSize(standardFont, 24).SetTextMatrix(1, 0, 0, 1, 32, 512);
            tagPointer.AddTag(PdfName.Span);
            canvas.OpenTag(tagPointer.GetTagReference()).ShowText("Hello ").CloseTag();
            canvas.SetFontAndSize(standardFont, 30).OpenTag(tagPointer.GetTagReference()).ShowText("World").CloseTag();
            tagPointer.MoveToParent().MoveToParent();
            // Flushing /Div tag and it's children. /P tag shall not be flushed, as it is has connected paragraphElement
            // object. On removing connection between paragraphElement and /P tag, /P tag shall be flushed.
            // When tag is flushed, tagPointer begins to point to tag's parent. If parent is also flushed - to the root.
            tagPointer.FlushTag();
            tagPointer.MoveToTag(paragraphElement);
            tagPointer.AddTag(PdfName.Span);
            canvas.OpenTag(tagPointer.GetTagReference()).ShowText("Hello ").CloseTag();
            canvas.SetFontAndSize(standardFont, 30).OpenTag(tagPointer.GetTagReference()).ShowText("again").CloseTag();
            tagPointer.RemoveElementConnectionToTag(paragraphElement);
            tagPointer.MoveToRoot();
            canvas.EndText().Release();
            PdfPage page2 = document.AddNewPage();

            tagPointer.SetPageForTagging(page2);
            canvas = new PdfCanvas(page2);
            tagPointer.AddTag(PdfName.P);
            canvas.BeginText().SetFontAndSize(PdfFontFactory.CreateFont(FontConstants.HELVETICA), 24).SetTextMatrix(1,
                                                                                                                    0, 0, 1, 32, 512);
            tagPointer.AddTag(PdfName.Span);
            canvas.OpenTag(tagPointer.GetTagReference()).ShowText("Hello ").CloseTag();
            tagPointer.MoveToParent().AddTag(PdfName.Span);
            canvas.OpenTag(tagPointer.GetTagReference()).ShowText("World").CloseTag();
            canvas.EndText().Release();
            page1.Flush();
            page2.Flush();
            document.Close();
            CompareResult("tagStructureFlushingTest05.pdf", "cmp_tagStructureFlushingTest05.pdf", "diffFlushing05_");
        }
Exemplo n.º 7
0
 public static void TrySetLangAttribute(IAccessibleElement accessibleElement, String lang)
 {
     if (lang != null)
     {
         AccessibilityProperties properties = accessibleElement.GetAccessibilityProperties();
         if (properties.GetLanguage() == null)
         {
             properties.SetLanguage(lang);
         }
     }
 }
Exemplo n.º 8
0
        /// <returns>parent of the flushed tag</returns>
        internal virtual IPdfStructElem FlushTag(PdfStructElem tagStruct)
        {
            IAccessibleElement modelElement = connectedStructToModel.JRemove(tagStruct.GetPdfObject());

            if (modelElement != null)
            {
                connectedModelToStruct.JRemove(modelElement);
            }
            IPdfStructElem parent = tagStruct.GetParent();

            FlushStructElementAndItKids(tagStruct);
            return(parent);
        }
Exemplo n.º 9
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);
         }
     }
 }
Exemplo n.º 10
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());
            }
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
0
        /// <summary>Gets accessibility properties of the current tag.</summary>
        /// <returns>accessibility properties of the current tag.</returns>
        public virtual AccessibilityProperties GetProperties()
        {
            PdfStructElem      currElem = GetCurrentStructElem();
            IAccessibleElement model    = tagStructureContext.GetModelConnectedToStruct(currElem);

            if (model != null)
            {
                return(model.GetAccessibilityProperties());
            }
            else
            {
                return(new BackedAccessibleProperties(currElem));
            }
        }
Exemplo n.º 13
0
        /// <summary>Sets new role to the current tag.</summary>
        /// <param name="role">new role to be set.</param>
        /// <returns>
        /// this
        /// <see cref="TagStructureContext"/>
        /// instance.
        /// </returns>
        public virtual iText.Kernel.Pdf.Tagutils.TagTreePointer SetRole(PdfName role)
        {
            IAccessibleElement connectedElement = tagStructureContext.GetModelConnectedToStruct(GetCurrentStructElem()
                                                                                                );

            if (connectedElement != null)
            {
                connectedElement.SetRole(role);
            }
            else
            {
                GetCurrentStructElem().SetRole(role);
            }
            return(this);
        }
Exemplo n.º 14
0
    public string AccessibilityForType(IAccessibleElement element)
    {
        AccessModifier accessModifier = this.ActiveDTOStage ? AccessModifier.Public : element.Access;
        string         accessibility  = accessModifier.ToString().ToLowerInvariant();

//        if (element is IPropertyBase)
//        {
//            if ((element as IPropertyBase).Owner.TypeKind == PersistentTypeKind.Interface)
//            {
//                accessibility = string.Empty;
//            }
//        }

        return(accessibility);
    }
Exemplo n.º 15
0
        private bool CreateSingleTag(TaggingHintKey hintKey, TagTreePointer tagPointer)
        {
            if (hintKey.IsFinished())
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Layout.Tagging.LayoutTaggingHelper));
                logger.Error(iText.IO.LogMessageConstant.ATTEMPT_TO_CREATE_A_TAG_FOR_FINISHED_HINT);
                return(false);
            }
            if (IsNonAccessibleHint(hintKey))
            {
                // try move pointer to the nearest accessible parent in case any direct content will be
                // tagged with this tagPointer
                TaggingHintKey parentTagHint = GetAccessibleParentHint(hintKey);
                context.GetWaitingTagsManager().TryMovePointerToWaitingTag(tagPointer, parentTagHint);
                return(false);
            }
            WaitingTagsManager waitingTagsManager = context.GetWaitingTagsManager();

            if (!waitingTagsManager.TryMovePointerToWaitingTag(tagPointer, hintKey))
            {
                IAccessibleElement modelElement = hintKey.GetAccessibleElement();
                TaggingHintKey     parentHint   = GetAccessibleParentHint(hintKey);
                int ind = -1;
                if (parentHint != null)
                {
                    // if parent tag hasn't been created yet - it's ok, kid tags will be moved on it's creation
                    if (waitingTagsManager.TryMovePointerToWaitingTag(tagPointer, parentHint))
                    {
                        IList <TaggingHintKey> siblingsHint = GetAccessibleKidsHint(parentHint);
                        int i = siblingsHint.IndexOf(hintKey);
                        ind = GetNearestNextSiblingTagIndex(waitingTagsManager, tagPointer, siblingsHint, i);
                    }
                }
                tagPointer.AddTag(ind, modelElement.GetAccessibilityProperties());
                if (hintKey.GetOverriddenRole() != null)
                {
                    tagPointer.SetRole(hintKey.GetOverriddenRole());
                }
                waitingTagsManager.AssignWaitingState(tagPointer, hintKey);
                IList <TaggingHintKey> kidsHint = GetAccessibleKidsHint(hintKey);
                foreach (TaggingHintKey kidKey in kidsHint)
                {
                    MoveKidTagIfCreated(hintKey, kidKey);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 16
0
        // listener methods

        /// <summary>
        /// Adds a IDocListener to the Document.
        /// </summary>
        /// <param name="listener">the new IDocListener</param>
        public void AddDocListener(IDocListener listener)
        {
            listeners.Add(listener);
            if (listener is IAccessibleElement)
            {
                IAccessibleElement ae = (IAccessibleElement)listener;
                ae.Role = this.role;
                ae.ID   = this.id;
                if (this.accessibleAttributes != null)
                {
                    foreach (PdfName key in this.accessibleAttributes.Keys)
                    {
                        ae.SetAccessibleAttribute(key, this.accessibleAttributes[key]);
                    }
                }
            }
        }
Exemplo n.º 17
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);
         }
     }
 }
Exemplo n.º 18
0
        private static TaggingHintKey GetOrCreateHintKey(IPropertyContainer hintOwner, bool setProperty)
        {
            TaggingHintKey hintKey = hintOwner.GetProperty <TaggingHintKey>(Property.TAGGING_HINT_KEY);

            if (hintKey == null)
            {
                IAccessibleElement elem = null;
                if (hintOwner is IAccessibleElement)
                {
                    elem = (IAccessibleElement)hintOwner;
                }
                else
                {
                    if (hintOwner is IRenderer && ((IRenderer)hintOwner).GetModelElement() is IAccessibleElement)
                    {
                        elem = (IAccessibleElement)((IRenderer)hintOwner).GetModelElement();
                    }
                }
                hintKey = new TaggingHintKey(elem, hintOwner is IElement);
                if (elem != null && StandardRoles.ARTIFACT.Equals(elem.GetAccessibilityProperties().GetRole()))
                {
                    hintKey.SetArtifact();
                    hintKey.SetFinished();
                }
                if (setProperty)
                {
                    if (elem is ILargeElement && !((ILargeElement)elem).IsComplete())
                    {
                        ((ILargeElement)elem).SetProperty(Property.TAGGING_HINT_KEY, hintKey);
                    }
                    else
                    {
                        hintOwner.SetProperty(Property.TAGGING_HINT_KEY, hintKey);
                    }
                }
            }
            return(hintKey);
        }
Exemplo n.º 19
0
        public virtual void FinishTaggingHint(IPropertyContainer hintOwner)
        {
            TaggingHintKey rendererKey = GetHintKey(hintOwner);

            // artifact is always finished
            if (rendererKey == null || rendererKey.IsFinished())
            {
                return;
            }
            if (rendererKey.IsElementBasedFinishingOnly() && !(hintOwner is IElement))
            {
                // avoid auto finishing of hints created based on IElements
                return;
            }
            if (!IsNonAccessibleHint(rendererKey))
            {
                IAccessibleElement modelElement = rendererKey.GetAccessibleElement();
                String             role         = modelElement.GetAccessibilityProperties().GetRole();
                if (rendererKey.GetOverriddenRole() != null)
                {
                    role = rendererKey.GetOverriddenRole();
                }
                IList <ITaggingRule> rules = taggingRules.Get(role);
                bool ruleResult            = true;
                if (rules != null)
                {
                    foreach (ITaggingRule rule in rules)
                    {
                        ruleResult = ruleResult && rule.OnTagFinish(this, rendererKey);
                    }
                }
                if (!ruleResult)
                {
                    return;
                }
            }
            rendererKey.SetFinished();
        }
Exemplo n.º 20
0
        // constructors

        /**
         * Constructs a <CODE>PdfChunk</CODE>-object.
         *
         * @param string the content of the <CODE>PdfChunk</CODE>-object
         * @param font the <CODE>PdfFont</CODE>
         * @param attributes the metrics attributes
         * @param noStroke the non metric attributes
         */

        internal PdfChunk(string str, PdfChunk other)
        {
            thisChunk[0]       = this;
            value              = str;
            this.font          = other.font;
            this.attributes    = other.attributes;
            this.noStroke      = other.noStroke;
            this.baseFont      = other.baseFont;
            this.changeLeading = other.changeLeading;
            this.leading       = other.leading;
            Object[] obj = null;
            if (attributes.ContainsKey(Chunk.IMAGE))
            {
                obj = (Object[])attributes[Chunk.IMAGE];
            }
            if (obj == null)
            {
                image = null;
            }
            else
            {
                image         = (Image)obj[0];
                offsetX       = (float)obj[1];
                offsetY       = (float)obj[2];
                changeLeading = (bool)obj[3];
            }
            encoding = font.Font.Encoding;
            if (noStroke.ContainsKey(Chunk.SPLITCHARACTER))
            {
                splitCharacter = (ISplitCharacter)noStroke[Chunk.SPLITCHARACTER];
            }
            else
            {
                splitCharacter = DefaultSplitCharacter.DEFAULT;
            }
            accessibleElement = other.accessibleElement;
        }
 public void CloseMCBlock(IAccessibleElement element)
 {
     if (IsTagged() && element != null /*&& element.Role != null*/)
     {
         if (GetMcElements().Contains(element)) {
             CloseMCBlockInt(element);
             GetMcElements().Remove(element);
         }
     }
 }
 private void CloseMCBlockInt(IAccessibleElement element)
 {
     if (IsTagged() && element.Role != null) {
         bool inTextLocal = inText;
         if (inText)
             EndText();
         EndMarkedContentSequence();
         if (inTextLocal)
             BeginText(true);
     }
 }
Exemplo n.º 23
0
 public virtual bool NeedToBeMarkedInContent(IAccessibleElement element) {
     if ((taggingMode & markInlineElementsOnly) != 0) {
         if (element.IsInline || PdfName.ARTIFACT.Equals(element.Role)) {
             return true;
         }
         return false;
     }
     return true;
 }
        private PdfStructureElement OpenMCBlockInt(IAccessibleElement element) {
            PdfStructureElement structureElement = null;
            if (IsTagged()) {
                IAccessibleElement parent = null;
                if (GetMcElements().Count > 0)
                    parent = GetMcElements()[GetMcElements().Count - 1];
                if(parent != null && (parent.Role == null || PdfName.ARTIFACT.Equals(parent.Role)))
                    element.Role = null;
                if (element.Role != null) {
                    if(!PdfName.ARTIFACT.Equals(element.Role)) {
                        if(!pdf.structElements.TryGetValue(element.ID, out structureElement)) {
                            structureElement = new PdfStructureElement(GetParentStructureElement(), element.Role);
                            structureElement.WriteAttributes(element);
                        }
                    }
                    bool inTextLocal = inText;
                    if (inText)
                        EndText();
                    if (PdfName.ARTIFACT.Equals(element.Role)) {
                        Dictionary<PdfName, PdfObject> properties = element.GetAccessibleAttributes();
                        PdfDictionary propertiesDict = null;
                        if (properties == null || properties.Count == 0) {
                        }
                        else {
                            propertiesDict = new PdfDictionary();
                            foreach (KeyValuePair<PdfName, PdfObject> entry in properties) {
                                propertiesDict.Put(entry.Key, entry.Value);
                            }
                        }
                        BeginMarkedContentSequence(element.Role, propertiesDict, true);
                    }
                    else {
                        BeginMarkedContentSequence(structureElement);
                    }

                    if (inTextLocal)
                        BeginText(true);
                }
            }
            return structureElement;
        }
Exemplo n.º 25
0
     // constructors
 
     /**
      * Constructs a <CODE>PdfChunk</CODE>-object.
      *
      * @param string the content of the <CODE>PdfChunk</CODE>-object
      * @param font the <CODE>PdfFont</CODE>
      * @param attributes the metrics attributes
      * @param noStroke the non metric attributes
      */
 
     internal PdfChunk(string str, PdfChunk other) {
         thisChunk[0] = this;
         value = str;
         this.font = other.font;
         this.attributes = other.attributes;
         this.noStroke = other.noStroke;
         this.baseFont = other.baseFont;
         this.changeLeading = other.changeLeading;
         this.leading = other.leading;
         Object[] obj = null;
         if (attributes.ContainsKey(Chunk.IMAGE))
             obj = (Object[])attributes[Chunk.IMAGE];
         if (obj == null)
             image = null;
         else {
             image = (Image)obj[0];
             offsetX = (float)obj[1];
             offsetY = (float)obj[2];
             changeLeading = (bool)obj[3];
         }
         encoding = font.Font.Encoding;
         if (noStroke.ContainsKey(Chunk.SPLITCHARACTER))
             splitCharacter = (ISplitCharacter)noStroke[Chunk.SPLITCHARACTER];
         else
             splitCharacter = DefaultSplitCharacter.DEFAULT;
         accessibleElement = other.accessibleElement;
     }
Exemplo n.º 26
0
        /**
         * Constructs a <CODE>PdfChunk</CODE>-object.
         *
         * @param chunk the original <CODE>Chunk</CODE>-object
         * @param action the <CODE>PdfAction</CODE> if the <CODE>Chunk</CODE> comes from an <CODE>Anchor</CODE>
         */

        internal PdfChunk(Chunk chunk, PdfAction action)
        {
            value = chunk.Content;

            Font  f    = chunk.Font;
            float size = f.Size;

            if (size == iTextSharp.text.Font.UNDEFINED)
            {
                size = 12;
            }
            baseFont = f.BaseFont;
            //BaseFont bf = f.BaseFont;
            int style = f.Style;

            if (style == iTextSharp.text.Font.UNDEFINED)
            {
                style = iTextSharp.text.Font.NORMAL;
            }
            if (baseFont == null)
            {
                // translation of the font-family to a PDF font-family
                baseFont = f.GetCalculatedBaseFont(false);
            }
            else
            {
                // bold simulation
                if ((style & iTextSharp.text.Font.BOLD) != 0)
                {
                    attributes[Chunk.TEXTRENDERMODE] = new Object[] { PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, size / 30f, null }
                }
                ;
                // italic simulation
                if ((style & iTextSharp.text.Font.ITALIC) != 0)
                {
                    attributes[Chunk.SKEW] = new float[] { 0, ITALIC_ANGLE }
                }
                ;
            }
            font = new PdfFont(baseFont, size);
            // other style possibilities
            Dictionary <string, object> attr = chunk.Attributes;

            if (attr != null)
            {
                foreach (KeyValuePair <string, object> entry in attr)
                {
                    string name = entry.Key;
                    if (keysAttributes.ContainsKey(name))
                    {
                        attributes[name] = entry.Value;
                    }
                    else if (keysNoStroke.ContainsKey(name))
                    {
                        noStroke[name] = entry.Value;
                    }
                }
                if (attr.ContainsKey(Chunk.GENERICTAG) && "".Equals(attr[Chunk.GENERICTAG]))
                {
                    attributes[Chunk.GENERICTAG] = chunk.Content;
                }
            }
            if (f.IsUnderlined())
            {
                Object[]   obj  = { null, new float[] { 0, UNDERLINE_THICKNESS, 0, UNDERLINE_OFFSET, 0 } };
                Object[][] obja = null;
                if (attributes.ContainsKey(Chunk.UNDERLINE))
                {
                    obja = (Object[][])attributes[Chunk.UNDERLINE];
                }
                Object[][] unders = Utilities.AddToArray(obja, obj);
                attributes[Chunk.UNDERLINE] = unders;
            }
            if (f.IsStrikethru())
            {
                Object[]   obj  = { null, new float[] { 0, 1f / 15, 0, 1f / 3, 0 } };
                Object[][] obja = null;
                if (attributes.ContainsKey(Chunk.UNDERLINE))
                {
                    obja = (Object[][])attributes[Chunk.UNDERLINE];
                }
                Object[][] unders = Utilities.AddToArray(obja, obj);
                attributes[Chunk.UNDERLINE] = unders;
            }
            if (action != null)
            {
                attributes[Chunk.ACTION] = action;
            }
            // the color can't be stored in a PdfFont
            noStroke[Chunk.COLOR]    = f.Color;
            noStroke[Chunk.ENCODING] = font.Font.Encoding;
            Object lh;

            if (attributes.TryGetValue(Chunk.LINEHEIGHT, out lh))
            {
                changeLeading = true;
                leading       = (float)lh;
            }

            Object[] obj2 = null;
            if (attributes.ContainsKey(Chunk.IMAGE))
            {
                obj2 = (Object[])attributes[Chunk.IMAGE];
            }
            if (obj2 == null)
            {
                image = null;
            }
            else
            {
                attributes.Remove(Chunk.HSCALE); // images are scaled in other ways
                image         = (Image)obj2[0];
                offsetX       = ((float)obj2[1]);
                offsetY       = ((float)obj2[2]);
                changeLeading = (bool)obj2[3];
            }
            object hs;

            if (attributes.TryGetValue(Chunk.HSCALE, out hs))
            {
                font.HorizontalScaling = (float)hs;
            }
            encoding = font.Font.Encoding;
            if (noStroke.ContainsKey(Chunk.SPLITCHARACTER))
            {
                splitCharacter = (ISplitCharacter)noStroke[Chunk.SPLITCHARACTER];
            }
            else
            {
                splitCharacter = DefaultSplitCharacter.DEFAULT;
            }
            accessibleElement = chunk;
        }
Exemplo n.º 27
0
 internal virtual PdfStructElem GetStructConnectedToModel(IAccessibleElement element)
 {
     return(connectedModelToStruct.Get(element));
 }
Exemplo n.º 28
0
 internal TaggingHintKey(IAccessibleElement elem, bool createdElementBased)
 {
     this.elem = elem;
     this.elementBasedFinishingOnly = createdElementBased;
 }
Exemplo n.º 29
0
 internal void OpenMCBlock(IAccessibleElement element) {
     if (writer.IsTagged() && element != null/* && element.Role != null*/) {
         if (!GetMcElements().Contains(element)) {
             PdfStructureElement structureElement = OpenMCBlockInt(element);
             GetMcElements().Add(element);
             if (structureElement != null)
                 pdf.structElements[element.ID] = structureElement;
         }
     }
 }
Exemplo n.º 30
0
 internal virtual void SaveConnectionBetweenStructAndModel(IAccessibleElement element, PdfStructElem structElem
                                                           )
 {
     connectedModelToStruct[element] = structElem;
     connectedStructToModel[structElem.GetPdfObject()] = element;
 }
Exemplo n.º 31
0
        public virtual void WriteAttributes(IAccessibleElement element) {
            // I do remember that these lines were necessary to avoid creation of files which are not valid from Acrobat 10 preflight perspective.
            // Now it seems that in Acrobat 11 there's no such problem (I think Acrobat 10 behavior can be considered as a bug) and we can remove those lines.
            // if(top.Writer.GetPdfVersion().Version < PdfWriter.VERSION_1_7)
            //    return;

            if (element is ListItem)
                WriteAttributes((ListItem) element);
            else if (element is Paragraph)
                WriteAttributes((Paragraph) element);
            else if (element is Chunk)
                WriteAttributes((Chunk) element);
            else if (element is Image)
                WriteAttributes((Image) element);
            else if (element is List)
                WriteAttributes((List) element);
            else if (element is ListLabel)
                WriteAttributes((ListLabel) element);
            else if (element is ListBody)
                WriteAttributes((ListBody) element);
            else if (element is PdfPTable)
                WriteAttributes((PdfPTable) element);
            else if (element is PdfPRow)
                WriteAttributes((PdfPRow) element);
            else if (element is PdfPHeaderCell)
                WriteAttributes((PdfPHeaderCell) element);
            else if (element is PdfPCell)
                WriteAttributes((PdfPCell) element);
            else if (element is PdfPTableHeader)
                WriteAttributes((PdfPTableHeader) element);
            else if (element is PdfPTableFooter)
                WriteAttributes((PdfPTableFooter) element);
            else if (element is PdfPTableBody)
                WriteAttributes((PdfPTableBody) element);
            else if (element is PdfDiv)
                WriteAttributes((PdfDiv) element);
            else if (element is PdfTemplate)
                WriteAttributes((PdfTemplate) element);
            else if (element is Document)
                WriteAttributes((Document) element);

            if (element.GetAccessibleAttributes() != null) {
                foreach (PdfName key in element.GetAccessibleAttributes().Keys) {
                    if (key.Equals(PdfName.ID)) {
                        PdfObject attr = element.GetAccessibleAttribute(key);
                        Put(key, attr);
                        top.PutIDTree(attr.ToString(), Reference);
                    } else if (key.Equals(PdfName.LANG) || key.Equals(PdfName.ALT) || key.Equals(PdfName.ACTUALTEXT) || key.Equals(PdfName.E) || key.Equals(PdfName.T)) {
                        Put(key, element.GetAccessibleAttribute(key));
                    } else
                        SetAttribute(key, element.GetAccessibleAttribute(key));
                }
            }
        }
Exemplo n.º 32
0
 private PdfStructureElement OpenMCBlockInt(IAccessibleElement element) {
     PdfStructureElement structureElement = null;
     if (IsTagged()) {
         IAccessibleElement parent = null;
         if (GetMcElements().Count > 0)
             parent = GetMcElements()[GetMcElements().Count - 1];
         if (parent != null && parent.Role == null)
             element.Role = null;
         if (element.Role != null) {
             pdf.structElements.TryGetValue(element.ID, out structureElement);
             if (structureElement == null)
             {
                 structureElement = new PdfStructureElement(GetParentStructureElement(), element.Role);
                 structureElement.WriteAttributes(element);
             }
             bool inTextLocal = inText;
             if (inText)
                 EndText();
             BeginMarkedContentSequence(structureElement);
             if (inTextLocal)
                 BeginText(true);
         }
     }
     return structureElement;
 }
Exemplo n.º 33
0
        public void WriteAttributes(IAccessibleElement element)
        {
            if (element is ListItem)
                WriteAttributes((ListItem) element);
            else if (element is Paragraph)
                WriteAttributes((Paragraph) element);
            else if (element is Chunk)
                WriteAttributes((Chunk) element);
            else if (element is Image)
                WriteAttributes((Image) element);
            else if (element is List)
                WriteAttributes((List) element);
            else if (element is ListLabel)
                WriteAttributes((ListLabel) element);
            else if (element is ListBody)
                WriteAttributes((ListBody) element);
            else if (element is PdfPTable)
                WriteAttributes((PdfPTable) element);
            else if (element is PdfPRow)
                WriteAttributes((PdfPRow) element);
            else if (element is PdfPHeaderCell)
                WriteAttributes((PdfPHeaderCell) element);
            else if (element is PdfPCell)
                WriteAttributes((PdfPCell) element);
            else if (element is PdfPTableHeader)
                WriteAttributes((PdfPTableHeader) element);
            else if (element is PdfPTableFooter)
                WriteAttributes((PdfPTableFooter) element);
            else if (element is PdfPTableBody)
                WriteAttributes((PdfPTableBody) element);
            else if (element is PdfDiv)
                WriteAttributes((PdfDiv) element);
            else if (element is Document)
                WriteAttributes((Document) element);

            if (element.GetAccessibleAttributes() != null)
                foreach (PdfName key in element.GetAccessibleAttributes().Keys)
                {
                    if (key.Equals(PdfName.LANG) || key.Equals(PdfName.ALT) || key.Equals(PdfName.ACTUALTEXT) ||
                        key.Equals(PdfName.E))
                        Put(key, element.GetAccessibleAttribute(key));
                    else
                        SetAttribute(key, element.GetAccessibleAttribute(key));
                }
        }
Exemplo n.º 34
0
        public void WriteAttributes(IAccessibleElement element)
        {
            if (top.Writer.GetPdfVersion().Version < PdfWriter.VERSION_1_7)
            {
                return;
            }
            if (element is ListItem)
            {
                WriteAttributes((ListItem)element);
            }
            else if (element is Paragraph)
            {
                WriteAttributes((Paragraph)element);
            }
            else if (element is Chunk)
            {
                WriteAttributes((Chunk)element);
            }
            else if (element is Image)
            {
                WriteAttributes((Image)element);
            }
            else if (element is List)
            {
                WriteAttributes((List)element);
            }
            else if (element is ListLabel)
            {
                WriteAttributes((ListLabel)element);
            }
            else if (element is ListBody)
            {
                WriteAttributes((ListBody)element);
            }
            else if (element is PdfPTable)
            {
                WriteAttributes((PdfPTable)element);
            }
            else if (element is PdfPRow)
            {
                WriteAttributes((PdfPRow)element);
            }
            else if (element is PdfPHeaderCell)
            {
                WriteAttributes((PdfPHeaderCell)element);
            }
            else if (element is PdfPCell)
            {
                WriteAttributes((PdfPCell)element);
            }
            else if (element is PdfPTableHeader)
            {
                WriteAttributes((PdfPTableHeader)element);
            }
            else if (element is PdfPTableFooter)
            {
                WriteAttributes((PdfPTableFooter)element);
            }
            else if (element is PdfPTableBody)
            {
                WriteAttributes((PdfPTableBody)element);
            }
            else if (element is PdfDiv)
            {
                WriteAttributes((PdfDiv)element);
            }
            else if (element is Document)
            {
                WriteAttributes((Document)element);
            }

            if (element.GetAccessibleAttributes() != null)
            {
                foreach (PdfName key in element.GetAccessibleAttributes().Keys)
                {
                    if (key.Equals(PdfName.LANG) || key.Equals(PdfName.ALT) || key.Equals(PdfName.ACTUALTEXT) ||
                        key.Equals(PdfName.E))
                    {
                        Put(key, element.GetAccessibleAttribute(key));
                    }
                    else
                    {
                        SetAttribute(key, element.GetAccessibleAttribute(key));
                    }
                }
            }
        }
Exemplo n.º 35
0
 private void CloseMCBlockInt(IAccessibleElement element) {
     if (IsTagged() && element.Role != null) {
         PdfStructureElement structureElement = null;
         pdf.structElements.TryGetValue(element.ID, out structureElement);
         if (structureElement != null) {
             structureElement.WriteAttributes(element);
         }
         if (writer.NeedToBeMarkedInContent(element)) {
             bool inTextLocal = inText;
             if (inText)
                 EndText();
             EndMarkedContentSequence();
             if (inTextLocal)
                 BeginText(true);
         }
     }
 }
Exemplo n.º 36
0
        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();
            }
        }
Exemplo n.º 37
0
        public virtual void WriteAttributes(IAccessibleElement element)
        {
            // I do remember that these lines were necessary to avoid creation of files which are not valid from Acrobat 10 preflight perspective.
            // Now it seems that in Acrobat 11 there's no such problem (I think Acrobat 10 behavior can be considered as a bug) and we can remove those lines.
            // if(top.Writer.GetPdfVersion().Version < PdfWriter.VERSION_1_7)
            //    return;

            if (element is ListItem)
            {
                WriteAttributes((ListItem)element);
            }
            else if (element is Paragraph)
            {
                WriteAttributes((Paragraph)element);
            }
            else if (element is Chunk)
            {
                WriteAttributes((Chunk)element);
            }
            else if (element is Image)
            {
                WriteAttributes((Image)element);
            }
            else if (element is List)
            {
                WriteAttributes((List)element);
            }
            else if (element is ListLabel)
            {
                WriteAttributes((ListLabel)element);
            }
            else if (element is ListBody)
            {
                WriteAttributes((ListBody)element);
            }
            else if (element is PdfPTable)
            {
                WriteAttributes((PdfPTable)element);
            }
            else if (element is PdfPRow)
            {
                WriteAttributes((PdfPRow)element);
            }
            else if (element is PdfPHeaderCell)
            {
                WriteAttributes((PdfPHeaderCell)element);
            }
            else if (element is PdfPCell)
            {
                WriteAttributes((PdfPCell)element);
            }
            else if (element is PdfPTableHeader)
            {
                WriteAttributes((PdfPTableHeader)element);
            }
            else if (element is PdfPTableFooter)
            {
                WriteAttributes((PdfPTableFooter)element);
            }
            else if (element is PdfPTableBody)
            {
                WriteAttributes((PdfPTableBody)element);
            }
            else if (element is PdfDiv)
            {
                WriteAttributes((PdfDiv)element);
            }
            else if (element is PdfTemplate)
            {
                WriteAttributes((PdfTemplate)element);
            }
            else if (element is Document)
            {
                WriteAttributes((Document)element);
            }

            if (element.GetAccessibleAttributes() != null)
            {
                foreach (PdfName key in element.GetAccessibleAttributes().Keys)
                {
                    if (key.Equals(PdfName.ID))
                    {
                        PdfObject attr = element.GetAccessibleAttribute(key);
                        Put(key, attr);
                        top.PutIDTree(attr.ToString(), Reference);
                    }
                    else if (key.Equals(PdfName.LANG) || key.Equals(PdfName.ALT) || key.Equals(PdfName.ACTUALTEXT) || key.Equals(PdfName.E) || key.Equals(PdfName.T))
                    {
                        Put(key, element.GetAccessibleAttribute(key));
                    }
                    else
                    {
                        SetAttribute(key, element.GetAccessibleAttribute(key));
                    }
                }
            }
        }
Exemplo n.º 38
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();
            }
        }
Exemplo n.º 39
0
        /// <summary>
        /// Sets the tag, which is connected with the given accessible element, as a current tag for the given
        /// <see cref="TagTreePointer"/>
        /// . An exception will be thrown, if given accessible element is not connected to any tag.
        /// </summary>
        /// <param name="element">an element which has a connection with some tag.</param>
        /// <param name="tagPointer">
        ///
        /// <see cref="TagTreePointer"/>
        /// which will be moved to the tag connected to the given accessible element.
        /// </param>
        /// <returns>
        /// current
        /// <see cref="TagStructureContext"/>
        /// instance.
        /// </returns>
        public virtual iText.Kernel.Pdf.Tagutils.TagStructureContext MoveTagPointerToTag(IAccessibleElement element
                                                                                         , TagTreePointer tagPointer)
        {
            PdfStructElem connectedStructElem = connectedModelToStruct.Get(element);

            if (connectedStructElem == null)
            {
                throw new PdfException(PdfException.GivenAccessibleElementIsNotConnectedToAnyTag);
            }
            tagPointer.SetCurrentStructElem(connectedStructElem);
            return(this);
        }
Exemplo n.º 40
0
      /**
       * Constructs a <CODE>PdfChunk</CODE>-object.
       *
       * @param chunk the original <CODE>Chunk</CODE>-object
       * @param action the <CODE>PdfAction</CODE> if the <CODE>Chunk</CODE> comes from an <CODE>Anchor</CODE>
       */
 
      internal PdfChunk(Chunk chunk, PdfAction action) {
          thisChunk[0] = this;
          value = chunk.Content;
      
          Font f = chunk.Font;
          float size = f.Size;
          if (size == iTextSharp.text.Font.UNDEFINED)
              size = 12;
          baseFont = f.BaseFont;
          //BaseFont bf = f.BaseFont;
          int style = f.Style;
          if (style == iTextSharp.text.Font.UNDEFINED) {
              style = iTextSharp.text.Font.NORMAL;
          }
          if (baseFont == null) {
              // translation of the font-family to a PDF font-family
              baseFont = f.GetCalculatedBaseFont(false);
          }
          else{
              // bold simulation
              if ((style & iTextSharp.text.Font.BOLD) != 0)
                  attributes[Chunk.TEXTRENDERMODE] = new Object[]{PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, size / 30f, null};
              // italic simulation
              if ((style & iTextSharp.text.Font.ITALIC) != 0)
                  attributes[Chunk.SKEW] = new float[]{0, ITALIC_ANGLE};
          }
          font = new PdfFont(baseFont, size);
          // other style possibilities
          Dictionary<string,object> attr = chunk.Attributes;
          if (attr != null) {
              foreach (KeyValuePair<string,object> entry in attr) {
                  string name = entry.Key;
                  if (keysAttributes.ContainsKey(name)) {
                      attributes[name] = entry.Value;
                  }
                  else if (keysNoStroke.ContainsKey(name)) {
                      noStroke[name] = entry.Value;
                  }
              }
              if (attr.ContainsKey(Chunk.GENERICTAG) && "".Equals(attr[Chunk.GENERICTAG])) {
                  attributes[Chunk.GENERICTAG] = chunk.Content;
              }
          }
          if (f.IsUnderlined()) {
              Object[] obj = {null, new float[]{0, 1f / 15, 0, -1f / 3, 0}};
              Object[][] obja = null;
              if (attributes.ContainsKey(Chunk.UNDERLINE))
                  obja = (Object[][])attributes[Chunk.UNDERLINE];
              Object[][] unders = Utilities.AddToArray(obja, obj);
              attributes[Chunk.UNDERLINE] = unders;
          }
          if (f.IsStrikethru()) {
              Object[] obj = {null, new float[]{0, 1f / 15, 0, 1f / 3, 0}};
              Object[][] obja = null;
              if (attributes.ContainsKey(Chunk.UNDERLINE))
                  obja = (Object[][])attributes[Chunk.UNDERLINE];
              Object[][] unders = Utilities.AddToArray(obja, obj);
              attributes[Chunk.UNDERLINE] = unders;
          }
          if (action != null)
              attributes[Chunk.ACTION] = action;
          // the color can't be stored in a PdfFont
          noStroke[Chunk.COLOR] = f.Color;
          noStroke[Chunk.ENCODING] = font.Font.Encoding;
          Object lh;
          if (attributes.TryGetValue(Chunk.LINEHEIGHT, out lh)) {
              changeLeading = true;
              leading = (float)lh;
          }
      
          Object[] obj2 = null;
          if (attributes.ContainsKey(Chunk.IMAGE))
              obj2 = (Object[])attributes[Chunk.IMAGE];
          if (obj2 == null)
              image = null;
          else {
              attributes.Remove(Chunk.HSCALE); // images are scaled in other ways
              image = (Image)obj2[0];
              offsetX = ((float)obj2[1]);
              offsetY = ((float)obj2[2]);
              changeLeading = (bool)obj2[3];
          }
          object hs;
          if (attributes.TryGetValue(Chunk.HSCALE, out hs))
              font.HorizontalScaling = (float)hs;
          encoding = font.Font.Encoding;
          if (noStroke.ContainsKey(Chunk.SPLITCHARACTER))
              splitCharacter = (ISplitCharacter)noStroke[Chunk.SPLITCHARACTER];
          else
              splitCharacter = DefaultSplitCharacter.DEFAULT;
          accessibleElement = chunk;
      }
 public void OpenMCBlock(IAccessibleElement element)
 {
     if (IsTagged())
     {
         if (pdf.openMCDocument)
         {
             pdf.openMCDocument = false;
             writer.DirectContentUnder.OpenMCBlock(pdf);
         }
         if (element != null/* && element.getRole() != null*/)
         {
             if (!GetMcElements().Contains(element))
             {
                 PdfStructureElement structureElement = OpenMCBlockInt(element);
                 GetMcElements().Add(element);
                 if (structureElement != null)
                     pdf.structElements[element.ID] = structureElement;
             }
         }
     }
 }
Exemplo n.º 42
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;
        }
Exemplo n.º 43
0
 public virtual void CheckElementRole(IAccessibleElement element, IAccessibleElement parent) {
     if (parent != null && (parent.Role == null || PdfName.ARTIFACT.Equals(parent.Role)))
         element.Role = null;
     else if ((taggingMode & markInlineElementsOnly) != 0) {
         if (element.IsInline && element.Role == null && (parent == null || !parent.IsInline))
             throw new ArgumentException(MessageLocalization.GetComposedMessage("inline.elements.with.role.null.are.not.allowed"));
     }
 }