/// ------------------------------------------------------------------------------------ /// <summary> /// Finds all ORCs in the given text and notes any orphaned footnotes or pictures. /// </summary> /// <param name="text">The text.</param> /// <param name="textLocationInfo">Additional information about the location of the /// text that can help the user find it.</param> /// <param name="startRef">Caller should pass in the initial reference to use as the /// basis for any references found in the course of parsing the text. Returned value /// will be the final reference found, which can be used as the basis for the subsequent /// text</param> /// <param name="endRef">Same as startRef, except in the case of verse bridges or /// section headings</param> /// <param name="footnotes">List of footnotes owned by the book that owns the /// given text. As footnotes are found, their locations will be set.</param> /// <param name="parasWithOrcs">List of paragraphs and ORC positions (excluding known /// picture ORCs).</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private static bool FindOrcsWithoutPropsInText(IStText text, string textLocationInfo, ref BCVRef startRef, ref BCVRef endRef, List <FootnoteOrcLocation> footnotes, List <OrcLocation> parasWithOrcs) { bool foundOrphan = false; foreach (IStTxtPara para in text.ParagraphsOS) { ITsString tssContents = para.Contents; string sContents = tssContents.Text; if (sContents == null) { continue; } int nRun = tssContents.RunCount; for (int i = 0; i < nRun; i++) { TsRunInfo runInfo; ITsTextProps tprops = tssContents.FetchRunInfo(i, out runInfo); string styleName = tprops.GetStrPropValue( (int)FwTextPropType.ktptNamedStyle); // When a verse number is encountered, save the number into // the reference. if (styleName == ScrStyleNames.VerseNumber) { string sVerseNum = sContents.Substring(runInfo.ichMin, runInfo.ichLim - runInfo.ichMin); int nVerseStart, nVerseEnd; ScrReference.VerseToInt(sVerseNum, out nVerseStart, out nVerseEnd); startRef.Verse = nVerseStart; endRef.Verse = nVerseEnd; } // If a chapter number is encountered then save the number into // the reference and start the verse number back at 1. else if (styleName == ScrStyleNames.ChapterNumber) { try { string sChapterNum = sContents.Substring(runInfo.ichMin, runInfo.ichLim - runInfo.ichMin); startRef.Chapter = endRef.Chapter = ScrReference.ChapterToInt(sChapterNum); startRef.Verse = endRef.Verse = 1; } catch (ArgumentException) { // ignore runs with invalid Chapter numbers } } else { // search contents for ORCs for (int ich = runInfo.ichMin; ich < runInfo.ichLim; ich++) { if (sContents[ich] != StringUtils.kChObject) { continue; } OrcLocation orcLocation = new OrcLocation(para, ich, startRef, endRef, textLocationInfo); ITsTextProps props = tssContents.get_PropertiesAt(ich); string objData = props.GetStrPropValue((int)FwTextPropType.ktptObjData); if (objData == null) { foundOrphan = true; } else { // first char. of strData is type code - GUID will follow it. Guid objGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1)); ICmObject obj; if (!text.Cache.ServiceLocator.ObjectRepository.TryGetObject(objGuid, out obj)) { foundOrphan = true; } else if (obj.ClassID == ScrFootnoteTags.kClassId) { foreach (FootnoteOrcLocation footnote in footnotes) { if (footnote.footnote.Guid == objGuid) { orcLocation.Footnote = footnote.footnote; footnote.location = orcLocation; break; } } } else { Debug.Assert(obj.ClassID == CmPictureTags.kClassId, "Unknown class id in embedded object: " + obj.ClassID); continue; } } parasWithOrcs.Add(orcLocation); } } } } return(foundOrphan); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finds all ORCs in the given text and notes any orphaned footnotes or pictures. /// </summary> /// <param name="text">The text.</param> /// <param name="textLocationInfo">Additional information about the location of the /// text that can help the user find it.</param> /// <param name="startRef">Caller should pass in the initial reference to use as the /// basis for any references found in the course of parsing the text. Returned value /// will be the final reference found, which can be used as the basis for the subsequent /// text</param> /// <param name="endRef">Same as startRef, except in the case of verse bridges or /// section headings</param> /// <param name="footnotes">List of footnotes owned by the book that owns the /// given text. As footnotes are found, their locations will be set.</param> /// <param name="parasWithOrcs">List of paragraphs and ORC positions.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private static bool FindOrcsWithoutPropsInText(IStText text, string textLocationInfo, ref BCVRef startRef, ref BCVRef endRef, List<FootnoteOrcLocation> footnotes, List<OrcLocation> parasWithOrcs) { bool foundOrphan = false; foreach (IStTxtPara para in text.ParagraphsOS) { ITsString tssContents = para.Contents.UnderlyingTsString; string sContents = tssContents.Text; if (sContents == null) continue; int nRun = tssContents.RunCount; for (int i = 0; i < nRun; i++) { TsRunInfo runInfo; ITsTextProps tprops = tssContents.FetchRunInfo(i, out runInfo); string styleName = tprops.GetStrPropValue( (int)FwTextPropType.ktptNamedStyle); // When a verse number is encountered, save the number into // the reference. if (styleName == ScrStyleNames.VerseNumber) { string sVerseNum = sContents.Substring(runInfo.ichMin, runInfo.ichLim - runInfo.ichMin); int nVerseStart, nVerseEnd; ScrReference.VerseToInt(sVerseNum, out nVerseStart, out nVerseEnd); startRef.Verse = nVerseStart; endRef.Verse = nVerseEnd; } // If a chapter number is encountered then save the number into // the reference and start the verse number back at 1. else if (styleName == ScrStyleNames.ChapterNumber) { try { string sChapterNum = sContents.Substring(runInfo.ichMin, runInfo.ichLim - runInfo.ichMin); startRef.Chapter = endRef.Chapter = ScrReference.ChapterToInt(sChapterNum); startRef.Verse = endRef.Verse = 1; } catch (ArgumentException) { // ignore runs with invalid Chapter numbers } } else { // search contents for ORCs for (int ich = runInfo.ichMin; ich < runInfo.ichLim; ich++) { if (sContents[ich] != StringUtils.kchObject) continue; OrcLocation orcLocation = new OrcLocation(para, ich, startRef, endRef, textLocationInfo); parasWithOrcs.Add(orcLocation); ITsTextProps props = tssContents.get_PropertiesAt(ich); string objData = props.GetStrPropValue((int)FwTextPropType.ktptObjData); if (objData == null) foundOrphan = true; else { // first char. of strData is type code - GUID will follow it. Guid objGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1)); int hvo = text.Cache.GetIdFromGuid(objGuid); int classId = (hvo == 0) ? 0 : text.Cache.GetClassOfObject(hvo); if (classId == StFootnote.kClassId) { foreach (FootnoteOrcLocation footnote in footnotes) { if (footnote.footnote.Hvo == hvo) { orcLocation.Object = footnote.footnote; footnote.location = orcLocation; break; } } } else if (classId == 0) { foundOrphan = true; } else { Debug.Assert(classId == CmPicture.kClassId, "Unknown class id in embedded object: " + classId); orcLocation.Object = classId; } } } } } } return foundOrphan; }