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_"); }
/// <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); } } }
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)); }
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 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); } }
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); } } }
public static void TrySetLangAttribute(IAccessibleElement accessibleElement, String lang) { if (lang != null) { AccessibilityProperties properties = accessibleElement.GetAccessibilityProperties(); if (properties.GetLanguage() == null) { properties.SetLanguage(lang); } } }
/// <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)); } }
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 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(); }