/// <summary>A copy constructor.</summary> /// <param name="tagPointer"> /// the /// <c>TagTreePointer</c> /// from which current position and page are copied. /// </param> public TagTreePointer(iText.Kernel.Pdf.Tagutils.TagTreePointer tagPointer) { this.tagStructureContext = tagPointer.tagStructureContext; SetCurrentStructElem(tagPointer.GetCurrentStructElem()); this.currentPage = tagPointer.currentPage; this.contentStream = tagPointer.contentStream; }
/// <summary> /// Moves kid of the current tag to the tag at which given /// <c>TagTreePointer</c> /// points. /// This method doesn't change neither this instance nor pointerToNewParent position. /// </summary> /// <param name="kidIndex">zero-based index of the current tag's kid to be relocated.</param> /// <param name="pointerToNewParent"> /// the /// <c>TagTreePointer</c> /// which is positioned at the tag which will become kid's new parent. /// </param> /// <returns> /// this /// <see cref="TagTreePointer"/> /// instance. /// </returns> public virtual iText.Kernel.Pdf.Tagutils.TagTreePointer RelocateKid(int kidIndex, iText.Kernel.Pdf.Tagutils.TagTreePointer pointerToNewParent) { if (GetDocument() != pointerToNewParent.GetDocument()) { throw new PdfException(PdfException.TagCannotBeMovedToTheAnotherDocumentsTagStructure); } if (GetCurrentStructElem().IsFlushed()) { throw new PdfException(PdfException.CannotRelocateTagWhichParentIsAlreadyFlushed); } if (IsPointingToSameTag(pointerToNewParent)) { if (kidIndex == pointerToNewParent.nextNewKidIndex) { return(this); } else { if (kidIndex < pointerToNewParent.nextNewKidIndex) { pointerToNewParent.SetNextNewKidIndex(pointerToNewParent.nextNewKidIndex - 1); } } } if (GetCurrentStructElem().GetKids()[kidIndex] == null) { throw new PdfException(PdfException.CannotRelocateTagWhichIsAlreadyFlushed); } IStructureNode removedKid = GetCurrentStructElem().RemoveKid(kidIndex, true); if (removedKid is PdfStructElem) { pointerToNewParent.AddNewKid((PdfStructElem)removedKid); } else { if (removedKid is PdfMcr) { PdfMcr mcrKid = PrepareMcrForMovingToNewParent((PdfMcr)removedKid, pointerToNewParent.GetCurrentStructElem ()); pointerToNewParent.AddNewKid(mcrKid); } } return(this); }
/// <summary> /// Checks if this /// <see cref="TagTreePointer"/> /// is pointing at the same tag as the giving /// <see cref="TagTreePointer"/> /// . /// </summary> /// <param name="otherPointer"> /// a /// <see cref="TagTreePointer"/> /// which is checked against this instance on whether they point /// at the same tag. /// </param> /// <returns> /// true if both /// <see cref="TagTreePointer"/> /// instances point at the same tag, false otherwise. /// </returns> public virtual bool IsPointingToSameTag(iText.Kernel.Pdf.Tagutils.TagTreePointer otherPointer) { return(GetCurrentStructElem().GetPdfObject().Equals(otherPointer.GetCurrentStructElem().GetPdfObject())); }
/// <summary> /// Moves kid of the current tag to the tag at which given /// <c>TagTreePointer</c> /// points. /// This method doesn't change pointerToNewParent position. /// </summary> /// <param name="kidIndex">zero-based index of the current tag's kid to be relocated.</param> /// <param name="pointerToNewParent"> /// the /// <c>TagTreePointer</c> /// which is positioned at the tag which will become kid's new parent. /// </param> /// <returns> /// this /// <see cref="TagStructureContext"/> /// instance. /// </returns> public virtual iText.Kernel.Pdf.Tagutils.TagTreePointer RelocateKid(int kidIndex, iText.Kernel.Pdf.Tagutils.TagTreePointer pointerToNewParent) { if (GetDocument() != pointerToNewParent.GetDocument()) { throw new PdfException(PdfException.TagCannotBeMovedToTheAnotherDocumentsTagStructure); } IPdfStructElem removedKid = GetCurrentStructElem().RemoveKid(kidIndex); if (removedKid is PdfStructElem) { pointerToNewParent.AddNewKid((PdfStructElem)removedKid); } else { if (removedKid is PdfMcr) { PdfMcr mcrKid = PrepareMcrForMovingToNewParent((PdfMcr)removedKid, pointerToNewParent.GetCurrentStructElem ()); pointerToNewParent.AddNewKid(mcrKid); } } return(this); }