public virtual bool OnTagFinish(LayoutTaggingHelper taggingHelper, TaggingHintKey taggingHintKey)
 {
     if (taggingHintKey.GetAccessibleElement() != null)
     {
         String role = taggingHintKey.GetAccessibleElement().GetAccessibilityProperties().GetRole();
         if (StandardRoles.THEAD.Equals(role) || StandardRoles.TFOOT.Equals(role))
         {
             finishForbidden.Add(taggingHintKey);
             return(false);
         }
     }
     foreach (TaggingHintKey hint in taggingHelper.GetAccessibleKidsHint(taggingHintKey))
     {
         String role = hint.GetAccessibleElement().GetAccessibilityProperties().GetRole();
         if (StandardRoles.TBODY.Equals(role) || StandardRoles.THEAD.Equals(role) || StandardRoles.TFOOT.Equals(role
                                                                                                                ))
         {
             // THead and TFoot are not finished thanks to this rule logic, TBody not finished because it's dummy and Table itself not finished
             RemoveTagUnavailableInPriorToOneDotFivePdf(hint, taggingHelper);
         }
     }
     return(true);
 }
Exemplo n.º 2
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.º 3
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.º 4
0
        public virtual bool OnTagFinish(LayoutTaggingHelper taggingHelper, TaggingHintKey tableHintKey)
        {
            IList <TaggingHintKey> kidKeys = taggingHelper.GetAccessibleKidsHint(tableHintKey);
            IDictionary <int, SortedDictionary <int, TaggingHintKey> > tableTags = new SortedDictionary <int, SortedDictionary
                                                                                                         <int, TaggingHintKey> >();
            IList <TaggingHintKey> tableCellTagsUnindexed = new List <TaggingHintKey>();
            IList <TaggingHintKey> nonCellKids            = new List <TaggingHintKey>();

            foreach (TaggingHintKey kidKey in kidKeys)
            {
                if (StandardRoles.TD.Equals(kidKey.GetAccessibleElement().GetAccessibilityProperties().GetRole()) || StandardRoles
                    .TH.Equals(kidKey.GetAccessibleElement().GetAccessibilityProperties().GetRole()))
                {
                    if (kidKey.GetAccessibleElement() is Cell)
                    {
                        Cell cell   = (Cell)kidKey.GetAccessibleElement();
                        int  rowInd = cell.GetRow();
                        int  colInd = cell.GetCol();
                        SortedDictionary <int, TaggingHintKey> rowTags = tableTags.Get(rowInd);
                        if (rowTags == null)
                        {
                            rowTags = new SortedDictionary <int, TaggingHintKey>();
                            tableTags.Put(rowInd, rowTags);
                        }
                        rowTags.Put(colInd, kidKey);
                    }
                    else
                    {
                        tableCellTagsUnindexed.Add(kidKey);
                    }
                }
                else
                {
                    nonCellKids.Add(kidKey);
                }
            }
            bool createTBody = true;

            if (tableHintKey.GetAccessibleElement() is Table)
            {
                Table modelElement = (Table)tableHintKey.GetAccessibleElement();
                createTBody = modelElement.GetHeader() != null && !modelElement.IsSkipFirstHeader() || modelElement.GetFooter
                                  () != null && !modelElement.IsSkipLastFooter();
            }
            TaggingDummyElement tbodyTag = null;

            tbodyTag = new TaggingDummyElement(createTBody ? StandardRoles.TBODY : null);
            foreach (TaggingHintKey nonCellKid in nonCellKids)
            {
                String kidRole = nonCellKid.GetAccessibleElement().GetAccessibilityProperties().GetRole();
                if (!StandardRoles.THEAD.Equals(kidRole) && !StandardRoles.TFOOT.Equals(kidRole))
                {
                    taggingHelper.MoveKidHint(nonCellKid, tableHintKey);
                }
            }
            foreach (TaggingHintKey nonCellKid in nonCellKids)
            {
                String kidRole = nonCellKid.GetAccessibleElement().GetAccessibilityProperties().GetRole();
                if (StandardRoles.THEAD.Equals(kidRole))
                {
                    taggingHelper.MoveKidHint(nonCellKid, tableHintKey);
                }
            }
            taggingHelper.AddKidsHint(tableHintKey, JavaCollectionsUtil.SingletonList <TaggingHintKey>(LayoutTaggingHelper
                                                                                                       .GetOrCreateHintKey(tbodyTag)), -1);
            foreach (TaggingHintKey nonCellKid in nonCellKids)
            {
                String kidRole = nonCellKid.GetAccessibleElement().GetAccessibilityProperties().GetRole();
                if (StandardRoles.TFOOT.Equals(kidRole))
                {
                    taggingHelper.MoveKidHint(nonCellKid, tableHintKey);
                }
            }
            foreach (SortedDictionary <int, TaggingHintKey> rowTags in tableTags.Values)
            {
                TaggingDummyElement row        = new TaggingDummyElement(StandardRoles.TR);
                TaggingHintKey      rowTagHint = LayoutTaggingHelper.GetOrCreateHintKey(row);
                foreach (TaggingHintKey cellTagHint in rowTags.Values)
                {
                    taggingHelper.MoveKidHint(cellTagHint, rowTagHint);
                }
                if (tableCellTagsUnindexed != null)
                {
                    foreach (TaggingHintKey cellTagHint in tableCellTagsUnindexed)
                    {
                        taggingHelper.MoveKidHint(cellTagHint, rowTagHint);
                    }
                    tableCellTagsUnindexed = null;
                }
                taggingHelper.AddKidsHint(tbodyTag, JavaCollectionsUtil.SingletonList <TaggingDummyElement>(row), -1);
            }
            return(true);
        }
Exemplo n.º 5
0
 private static bool IsNonAccessibleHint(TaggingHintKey hintKey)
 {
     return(hintKey.GetAccessibleElement() == null || hintKey.GetAccessibleElement().GetAccessibilityProperties
                ().GetRole() == null);
 }