public virtual int ReplaceKidHint(TaggingHintKey kidHintKey, ICollection <TaggingHintKey> newKidsHintKeys) { TaggingHintKey parentKey = GetParentHint(kidHintKey); if (parentKey == null) { return(-1); } if (kidHintKey.IsFinished()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Tagging.LayoutTaggingHelper)); logger.Error(iText.IO.LogMessageConstant.CANNOT_REPLACE_FINISHED_HINT); // If kidHintKey is finished you won't be able to add it anywhere after replacing is ended. // If kidHintKey might be finished, use moveKidHint instead. // replaceKidHint should be used when parent might be finished. return(-1); } int kidIndex = RemoveParentHint(kidHintKey); IList <TaggingHintKey> kidsToBeAdded = new List <TaggingHintKey>(); foreach (TaggingHintKey newKidKey in newKidsHintKeys) { int i = RemoveParentHint(newKidKey); if (i == RETVAL_PARENT_AND_KID_FINISHED || i == RETVAL_NO_PARENT && newKidKey.IsFinished()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Tagging.LayoutTaggingHelper)); logger.Error(iText.IO.LogMessageConstant.CANNOT_MOVE_FINISHED_HINT); continue; } kidsToBeAdded.Add(newKidKey); } AddKidsHint(parentKey, kidsToBeAdded, kidIndex, true); return(kidIndex); }
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); }
public virtual TaggingHintKey GetAccessibleParentHint(TaggingHintKey hintKey) { do { hintKey = GetParentHint(hintKey); }while (hintKey != null && IsNonAccessibleHint(hintKey)); return(hintKey); }
public virtual TaggingHintKey GetParentHint(IPropertyContainer hintOwner) { TaggingHintKey hintKey = GetHintKey(hintOwner); if (hintKey == null) { return(null); } return(GetParentHint(hintKey)); }
public virtual IList <TaggingHintKey> GetKidsHint(TaggingHintKey parent) { IList <TaggingHintKey> kidsHint = kidsHints.Get(parent); if (kidsHint == null) { return(JavaCollectionsUtil.EmptyList <TaggingHintKey>()); } return(JavaCollectionsUtil.UnmodifiableList <TaggingHintKey>(kidsHint)); }
private void ReleaseHint(TaggingHintKey hint, ICollection <TaggingHintKey> hintsToBeHeld, bool checkContextIsFinished ) { TaggingHintKey parentHint = parentHints.Get(hint); IList <TaggingHintKey> kidsHint = kidsHints.Get(hint); if (checkContextIsFinished && parentHint != null) { if (IsSomeParentNotFinished(parentHint)) { return; } } if (checkContextIsFinished && kidsHint != null) { if (IsSomeKidNotFinished(hint)) { return; } } if (checkContextIsFinished && hintsToBeHeld != null) { if (hintsToBeHeld.Contains(hint)) { return; } } if (parentHint != null) { RemoveParentHint(hint, parentHint); } if (kidsHint != null) { foreach (TaggingHintKey kidHint in kidsHint) { parentHints.JRemove(kidHint); } kidsHints.JRemove(hint); } TagTreePointer tagPointer = new TagTreePointer(document); if (context.GetWaitingTagsManager().TryMovePointerToWaitingTag(tagPointer, hint)) { context.GetWaitingTagsManager().RemoveWaitingState(hint); if (immediateFlush) { tagPointer.FlushParentsIfAllKidsFlushed(); } } else { context.GetWaitingTagsManager().RemoveWaitingState(hint); } }
private bool IsSomeKidNotFinished(TaggingHintKey hint) { foreach (TaggingHintKey kidHint in GetKidsHint(hint)) { if (!kidHint.IsFinished()) { return(true); } if (IsNonAccessibleHint(kidHint) && IsSomeKidNotFinished(kidHint)) { return(true); } } return(false); }
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); }
private int RemoveParentHint(TaggingHintKey hintKey) { TaggingHintKey parentHint = parentHints.Get(hintKey); if (parentHint == null) { return(RETVAL_NO_PARENT); } TaggingHintKey accessibleParentHint = GetAccessibleParentHint(hintKey); if (hintKey.IsFinished() && parentHint.IsFinished() && (accessibleParentHint == null || accessibleParentHint .IsFinished())) { return(RETVAL_PARENT_AND_KID_FINISHED); } return(RemoveParentHint(hintKey, parentHint)); }
private void RemoveTagUnavailableInPriorToOneDotFivePdf(TaggingHintKey taggingHintKey, LayoutTaggingHelper taggingHelper) { taggingHelper.ReplaceKidHint(taggingHintKey, taggingHelper.GetAccessibleKidsHint(taggingHintKey)); PdfDocument pdfDocument = taggingHelper.GetPdfDocument(); WaitingTagsManager waitingTagsManager = pdfDocument.GetTagStructureContext().GetWaitingTagsManager(); TagTreePointer tagPointer = new TagTreePointer(pdfDocument); if (waitingTagsManager.TryMovePointerToWaitingTag(tagPointer, taggingHintKey)) { waitingTagsManager.RemoveWaitingState(taggingHintKey); tagPointer.RemoveTag(); } if (finishForbidden.Remove(taggingHintKey)) { taggingHintKey.SetFinished(); } }
public virtual bool CreateTag(IRenderer renderer, TagTreePointer tagPointer) { TaggingHintKey hintKey = GetHintKey(renderer); bool noHint = hintKey == null; if (noHint) { hintKey = GetOrCreateHintKey(renderer, false); } bool created = CreateTag(hintKey, tagPointer); if (noHint) { hintKey.SetFinished(); context.GetWaitingTagsManager().RemoveWaitingState(hintKey); } return(created); }
public virtual void AddKidsHint <_T0>(IPropertyContainer parent, IEnumerable <_T0> newKids, int insertIndex) where _T0 : IPropertyContainer { if (parent is AreaBreakRenderer) { return; } TaggingHintKey parentKey = GetOrCreateHintKey(parent); IList <TaggingHintKey> newKidsKeys = new List <TaggingHintKey>(); foreach (IPropertyContainer kid in newKids) { if (kid is AreaBreakRenderer) { return; } newKidsKeys.Add(GetOrCreateHintKey(kid)); } AddKidsHint(parentKey, newKidsKeys, insertIndex); }
private bool IsSomeParentNotFinished(TaggingHintKey parentHint) { TaggingHintKey hintKey = parentHint; while (true) { if (hintKey == null) { return(false); } if (!hintKey.IsFinished()) { return(true); } if (!IsNonAccessibleHint(hintKey)) { return(false); } hintKey = GetParentHint(hintKey); } }
public virtual bool CreateTag(TaggingHintKey hintKey, TagTreePointer tagPointer) { if (hintKey.IsArtifact()) { return(false); } bool created = CreateSingleTag(hintKey, tagPointer); if (created) { IList <TaggingHintKey> kidsHint = GetAccessibleKidsHint(hintKey); foreach (TaggingHintKey hint in kidsHint) { if (hint.GetAccessibleElement() is TaggingDummyElement) { CreateTag(hint, new TagTreePointer(document)); } } } return(created); }
private int RemoveParentHint(TaggingHintKey hintKey, TaggingHintKey parentHint) { parentHints.JRemove(hintKey); IList <TaggingHintKey> kidsHint = kidsHints.Get(parentHint); int i; int size = kidsHint.Count; for (i = 0; i < size; ++i) { if (kidsHint[i] == hintKey) { kidsHint.JRemoveAt(i); break; } } System.Diagnostics.Debug.Assert(i < size); if (kidsHint.IsEmpty()) { kidsHints.JRemove(parentHint); } return(i); }
public virtual int MoveKidHint(TaggingHintKey hintKeyOfKidToMove, TaggingHintKey newParent, int insertIndex ) { if (newParent.IsFinished()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Tagging.LayoutTaggingHelper)); logger.Error(iText.IO.LogMessageConstant.CANNOT_MOVE_HINT_TO_FINISHED_PARENT); return(-1); } int removeRes = RemoveParentHint(hintKeyOfKidToMove); if (removeRes == RETVAL_PARENT_AND_KID_FINISHED || removeRes == RETVAL_NO_PARENT && hintKeyOfKidToMove.IsFinished ()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Tagging.LayoutTaggingHelper)); logger.Error(iText.IO.LogMessageConstant.CANNOT_MOVE_FINISHED_HINT); return(-1); } AddKidsHint(newParent, JavaCollectionsUtil.SingletonList <TaggingHintKey>(hintKeyOfKidToMove), insertIndex, true); return(removeRes); }
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); }
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(); }
private void MoveKidTagIfCreated(TaggingHintKey parentKey, TaggingHintKey kidKey) { // both arguments shall be accessible, non-accessible are not handled inside this method TagTreePointer kidPointer = new TagTreePointer(document); WaitingTagsManager waitingTagsManager = context.GetWaitingTagsManager(); if (!waitingTagsManager.TryMovePointerToWaitingTag(kidPointer, kidKey)) { return; } TagTreePointer parentPointer = new TagTreePointer(document); if (!waitingTagsManager.TryMovePointerToWaitingTag(parentPointer, parentKey)) { return; } int kidIndInParentKidsHint = GetAccessibleKidsHint(parentKey).IndexOf(kidKey); int ind = GetNearestNextSiblingTagIndex(waitingTagsManager, parentPointer, GetAccessibleKidsHint(parentKey ), kidIndInParentKidsHint); parentPointer.SetNextNewKidIndex(ind); kidPointer.Relocate(parentPointer); }
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); }
public virtual IList <TaggingHintKey> GetAccessibleKidsHint(TaggingHintKey parent) { IList <TaggingHintKey> kidsHint = kidsHints.Get(parent); if (kidsHint == null) { return(JavaCollectionsUtil.EmptyList <TaggingHintKey>()); } IList <TaggingHintKey> accessibleKids = new List <TaggingHintKey>(); foreach (TaggingHintKey kid in kidsHint) { if (IsNonAccessibleHint(kid)) { accessibleKids.AddAll(GetAccessibleKidsHint(kid)); } else { accessibleKids.Add(kid); } } return(accessibleKids); }
public virtual void MarkArtifactHint(TaggingHintKey hintKey) { hintKey.SetArtifact(); hintKey.SetFinished(); TagTreePointer existingArtifactTag = new TagTreePointer(document); if (context.GetWaitingTagsManager().TryMovePointerToWaitingTag(existingArtifactTag, hintKey)) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Tagging.LayoutTaggingHelper)); logger.Error(iText.IO.LogMessageConstant.ALREADY_TAGGED_HINT_MARKED_ARTIFACT); context.GetWaitingTagsManager().RemoveWaitingState(hintKey); if (immediateFlush) { existingArtifactTag.FlushParentsIfAllKidsFlushed(); } } IList <TaggingHintKey> kidsHint = GetKidsHint(hintKey); foreach (TaggingHintKey kidKey in kidsHint) { MarkArtifactHint(kidKey); } RemoveParentHint(hintKey); }
private bool IsTagAlreadyExistsForHint(TaggingHintKey tagHint) { return(context.GetWaitingTagsManager().IsObjectAssociatedWithWaitingTag(tagHint)); }
private static bool IsNonAccessibleHint(TaggingHintKey hintKey) { return(hintKey.GetAccessibleElement() == null || hintKey.GetAccessibleElement().GetAccessibilityProperties ().GetRole() == null); }
private void AddKidsHint(TaggingHintKey parentKey, ICollection <TaggingHintKey> newKidsKeys, int insertIndex , bool skipFinishedChecks) { if (newKidsKeys.IsEmpty()) { return; } if (parentKey.IsArtifact()) { foreach (TaggingHintKey kid in newKidsKeys) { MarkArtifactHint(kid); } return; } if (!skipFinishedChecks && parentKey.IsFinished()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Tagging.LayoutTaggingHelper)); logger.Error(iText.IO.LogMessageConstant.CANNOT_ADD_HINTS_TO_FINISHED_PARENT); return; } IList <TaggingHintKey> kidsHint = kidsHints.Get(parentKey); if (kidsHint == null) { kidsHint = new List <TaggingHintKey>(); } TaggingHintKey parentTagHint = IsNonAccessibleHint(parentKey) ? GetAccessibleParentHint(parentKey) : parentKey; bool parentTagAlreadyCreated = parentTagHint != null && IsTagAlreadyExistsForHint(parentTagHint); foreach (TaggingHintKey kidKey in newKidsKeys) { if (kidKey.IsArtifact()) { continue; } TaggingHintKey prevParent = GetParentHint(kidKey); if (prevParent != null) { // TODO seems to be a legit use case to re-add hints to just ensure that hints are added // Logger logger = LoggerFactory.getLogger(LayoutTaggingHelper.class); // logger.error(LogMessageConstant.CANNOT_ADD_KID_HINT_WHICH_IS_ALREADY_ADDED_TO_ANOTHER_PARENT); continue; } if (!skipFinishedChecks && kidKey.IsFinished()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Tagging.LayoutTaggingHelper)); logger.Error(iText.IO.LogMessageConstant.CANNOT_ADD_FINISHED_HINT_AS_A_NEW_KID_HINT); continue; } if (insertIndex > -1) { kidsHint.Add(insertIndex++, kidKey); } else { kidsHint.Add(kidKey); } parentHints.Put(kidKey, parentKey); if (parentTagAlreadyCreated) { if (kidKey.GetAccessibleElement() is TaggingDummyElement) { CreateTag(kidKey, new TagTreePointer(document)); } if (IsNonAccessibleHint(kidKey)) { foreach (TaggingHintKey nestedKid in GetAccessibleKidsHint(kidKey)) { if (nestedKid.GetAccessibleElement() is TaggingDummyElement) { CreateTag(nestedKid, new TagTreePointer(document)); } MoveKidTagIfCreated(parentTagHint, nestedKid); } } else { MoveKidTagIfCreated(parentTagHint, kidKey); } } } if (!kidsHint.IsEmpty()) { kidsHints.Put(parentKey, kidsHint); } }
public virtual void AddKidsHint(TaggingHintKey parentKey, ICollection <TaggingHintKey> newKidsKeys, int insertIndex ) { AddKidsHint(parentKey, newKidsKeys, insertIndex, false); }
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); }
public virtual void MarkArtifactHint(IPropertyContainer hintOwner) { TaggingHintKey hintKey = GetOrCreateHintKey(hintOwner); MarkArtifactHint(hintKey); }
public virtual int MoveKidHint(TaggingHintKey hintKeyOfKidToMove, TaggingHintKey newParent) { return(MoveKidHint(hintKeyOfKidToMove, newParent, -1)); }
public virtual TaggingHintKey GetParentHint(TaggingHintKey hintKey) { return(parentHints.Get(hintKey)); }