private ParaChangeInfo EnsureParaInfo(int hvoFake, int hvoTargetPara) { var hvoPara = GetTargetObject(hvoFake); if (hvoTargetPara != 0 && hvoPara != hvoTargetPara) return null; ParaChangeInfo info; if (!m_changedParas.TryGetValue(hvoPara, out info)) { int flid = FlidOfTarget(hvoPara); int ws = 0; if (flid == CmPictureTags.kflidCaption) ws = m_cache.DefaultVernWs; Debug.Assert(flid != 0); info = new ParaChangeInfo(this, hvoPara, flid, ws); m_changedParas[hvoPara] = info; } return info; }
/// <summary> /// Update offsets for the given paragraph /// </summary> private void UpdateOffsets(int hvoPara, ParaChangeInfo info) { int ichange = 0; // index into info.Changes; int delta = 0; // amount to add to offsets of later words. if (m_cache.GetClassOfObject(hvoPara) == StTxtPara.kclsidStTxtPara) { // Adjust segment-by-segment so as to keep track of how far each segment boundary is // moved by the replacements within it. IStTxtPara para = StTxtPara.CreateFromDBObject(m_cache, hvoPara); List<int> segIds = para.Segments; foreach (int currentSegmentId in segIds) { AdjustOffset(currentSegmentId, delta, kflidBeginOffset); List<int> xficIds = para.SegmentForms(currentSegmentId); AdjustXficOffsets(info, xficIds, ref delta, ref ichange); AdjustOffset(currentSegmentId, delta, kflidEndOffset); } } else { // Not a paragraph, so there won't be segments, and we can't make an IStTxtPara object. // Just adjust all the wfics. AdjustXficOffsets(info, info.Changes, ref delta, ref ichange); } }
/// <summary> /// Adjust the offsets of the xfics (wfics or pfics, wordform-in-context or punct-in-context) given /// in xficIds, which are a (sub)range of the ids in info.changes. Both input and output are the /// total change in length and the index of the place we are up to in info.Changes. /// </summary> /// <param name="info"></param> /// <param name="xficIds"></param> /// <param name="delta"></param> /// <param name="ichange"></param> private void AdjustXficOffsets(ParaChangeInfo info, List<int> xficIds, ref int delta, ref int ichange) { foreach (int xfic in xficIds) { int beginTarget = BeginOffset(xfic); for (; ichange < info.Changes.Count; ichange++) { int hvoChange = info.Changes[ichange]; int beginChange = BeginOffset(hvoChange); if (beginChange >= beginTarget) break; ITsString tssOld = OldOccurrence(hvoChange); string replacement = Replacement(tssOld); delta += replacement.Length - tssOld.Length; } AdjustOffset(xfic, delta, kflidBeginOffset); if (ichange < info.Changes.Count && info.Changes[ichange] == xfic) { // Adjusting the target itself...it's end needs a different adjustment. // Pass delta to account for the fact that the begin offset of xfic has // already been adjusted. ITsString tssOld = OldOccurrence(xfic, delta); string replacement = Replacement(tssOld); delta += replacement.Length - tssOld.Length; ichange++; } AdjustOffset(xfic, delta, kflidEndOffset); } }
private ParaChangeInfo EnsureParaInfo(int hvoCba, int hvoTargetPara) { int hvoPara = GetTargetObject(hvoCba); if (hvoTargetPara != 0 && hvoPara != hvoTargetPara) return null; ParaChangeInfo info; if (!m_changedParas.TryGetValue(hvoPara, out info)) { int flid = m_cache.GetIntProperty(hvoCba, kflidFlid); int ws = 0; if (IsMultilingual(flid)) ws = m_cache.GetObjProperty(hvoCba, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidWritingSystem); info = new ParaChangeInfo(hvoPara, flid, ws); m_changedParas[hvoPara] = info; } return info; }