/// <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 current tag to the tag at which given /// <c>TagTreePointer</c> /// points. /// This method doesn't change either this instance or pointerToNewParent position. /// </summary> /// <param name="pointerToNewParent"> /// the /// <c>TagTreePointer</c> /// which is positioned at the tag /// which will become current tag new parent. /// </param> /// <returns> /// this /// <see cref="TagTreePointer"/> /// instance. /// </returns> public virtual iText.Kernel.Pdf.Tagutils.TagTreePointer Relocate(iText.Kernel.Pdf.Tagutils.TagTreePointer pointerToNewParent) { if (GetCurrentStructElem().GetPdfObject() == tagStructureContext.GetRootTag().GetPdfObject()) { throw new PdfException(PdfException.CannotRelocateRootTag); } if (GetCurrentStructElem().IsFlushed()) { throw new PdfException(PdfException.CannotRelocateTagWhichIsAlreadyFlushed); } int i = GetIndexInParentKidsList(); if (i < 0) { throw new PdfException(PdfException.CannotRelocateTagWhichParentIsAlreadyFlushed); } new iText.Kernel.Pdf.Tagutils.TagTreePointer(this).MoveToParent().RelocateKid(i, pointerToNewParent); return(this); }
/// <summary> /// Moves this /// <see cref="TagTreePointer"/> /// instance to the tag at which given /// <see cref="TagTreePointer"/> /// instance is pointing. /// </summary> /// <param name="tagTreePointer"> /// a /// <see cref="TagTreePointer"/> /// that points at the tag which will become the current tag /// of this instance. /// </param> /// <returns> /// this /// <see cref="TagTreePointer"/> /// instance. /// </returns> public virtual iText.Kernel.Pdf.Tagutils.TagTreePointer MoveToPointer(iText.Kernel.Pdf.Tagutils.TagTreePointer tagTreePointer) { this.currentStructElem = tagTreePointer.currentStructElem; return(this); }
/// <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); }