/// <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> /// 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); }