/// ------------------------------------------------------------------------------------ /// <summary> /// Show (or hide) the footnote view. /// </summary> /// <param name="footnote">Footnote to scroll to or <c>null</c> to just display or hide /// the footnote view. If a footnote is given the footnote view will always be shown. /// </param> /// <param name="fPutInsertionPtAtEnd">if set to <c>true</c> and showing the view, /// the insertion point will be put at the end of the footnote text instead of at the /// beginning, as would be appropriate in the case of a newly inserted footnote that has /// Reference Text. This parameter is ignored if footnote is null.</param> /// ------------------------------------------------------------------------------------ internal override void ShowOrHideFootnoteView(IStFootnote footnote, bool fPutInsertionPtAtEnd) { CheckDisposed(); //toggle bool fShow = !m_grid.Rows[kFootnoteRow].Visible || footnote != null; base.ShowOrHideFootnoteView(footnote, fPutInsertionPtAtEnd); if (fShow) { // We don't want to show both draft view rows together with the footnotes m_fBothDraftViewsShowing = (m_grid.Rows[kUpperDraftRow].Visible && m_grid.Rows[kLowerDraftRow].Visible); // Determine which of the draft view to collapse (if both are open) if (m_fBothDraftViewsShowing) { if (FocusedRootSite == GetControl(kUpperDraftRow, kDraftViewColumn)) { m_grid.Rows[kLowerDraftRow].Visible = false; } else { m_grid.Rows[kUpperDraftRow].Visible = false; } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies that all footnotes correspond to exactly one ORC in the vernacular /// Scripture and that they are in the same order as they occur in Scripture. /// </summary> /// ------------------------------------------------------------------------------------ private void VerifyNoOrphanedFootnotes() { ScrChecksDataSource scrData = new ScrChecksDataSource(Cache); foreach (IScrBook book in m_scr.ScriptureBooksOS) { IEnumerator <IStFootnote> footnotes = book.FootnotesOS.GetEnumerator(); IStFootnote currentFootnote = (footnotes.MoveNext() ? footnotes.Current : null); scrData.GetText(book.CanonicalNum, 0); foreach (ITextToken tok in scrData.TextTokens()) { if (tok.TextType == TextType.Note) { if (tok.IsNoteStart) { Assert.IsNotNull(currentFootnote, "No more footnotes were expected in " + book.BestUIName); Assert.IsTrue(((IStTxtPara)currentFootnote.ParagraphsOS[0]).Contents.Text.StartsWith(tok.Text), "Footnote ORC does not match next footnote in sequence (mismatched text)"); Assert.AreEqual(currentFootnote.ParagraphsOS[0].StyleName, tok.ParaStyleName, "Footnote ORC does not match next footnote in sequence (mismatched style)"); currentFootnote = (footnotes.MoveNext() ? footnotes.Current : null); } } else { Assert.IsFalse(tok.Text.Contains(StringUtils.kszObject)); } } Assert.IsNull(currentFootnote); } }
public void ExportFootnote_Missing() { int markerStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.FootnoteMarker).IndexInOwner + 1; int footnoteStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.NormalFootnoteParagraph).IndexInOwner + 1; ITsStrFactory stringFactory = TsStrFactoryClass.Create(); // Create a book with a section that has a paragraph with some text and a footnote! AddRunToMockedPara(m_para, "My text for footnotes", string.Empty); IStFootnote testFootnote = AddFootnote(m_book, m_para, m_para.Contents.Length, string.Empty); m_exporter = new DummyExportRtf(m_fileName, Cache, m_styleSheet); m_exporter.CallExportParagraph(m_para); // Verify the contents of the temp file m_exporter.CloseOutputFile(); using (TextReader file = FileUtils.OpenFileForRead(m_fileName, Encoding.ASCII)) { string line = file.ReadLine(); // the line is the paragraph without the footnote marker. Assert.AreEqual(@"\pard\plain\s2\f1\fs20{My text for footnotes}", line); } }
public void UpdateAllFootnotesWhenValuesChangeInScripture() { IScrBook james = (IScrBook)m_scr.ScriptureBooksOS[0]; m_scr.DisplayFootnoteReference = false; m_scr.FootnoteMarkerSymbol = "*"; m_scr.FootnoteMarkerType = FootnoteMarkerTypes.SymbolicFootnoteMarker; m_footnoteView.RefreshDisplay(); for (int i = james.FootnotesOS.Count - 2; i < james.FootnotesOS.Count; i++) { IStFootnote fNote = (IStFootnote)james.FootnotesOS[i]; // Assert.AreEqual(m_footnoteView.m_updatedDisplayMarker, // fNote.DisplayFootnoteMarker); // Assert.AreEqual(m_footnoteView.m_updatedDisplayReference, // fNote.DisplayFootnoteReference); Assert.AreEqual(m_footnoteView.m_updatedFootnoteMarker, fNote.FootnoteMarker.Text); } for (int i = 0; i <= 2; i++) { IStFootnote fNote = (IStFootnote)m_Jude.FootnotesOS[i]; // Assert.AreEqual(m_footnoteView.m_updatedDisplayMarker, // fNote.DisplayFootnoteMarker); // Assert.AreEqual(m_footnoteView.m_updatedDisplayReference, // fNote.DisplayFootnoteReference); Assert.AreEqual(m_footnoteView.m_updatedFootnoteMarker, fNote.FootnoteMarker.Text); } }
/// ------------------------------------------------------------------------------------- /// <summary> /// This method gets called whenever the focused reference in the error pane changes. /// We respond by telling the draft view to scroll to and select the text of the new /// verse. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// ------------------------------------------------------------------------------------- private void OnRefInGridChanged(object sender, CheckingError e) { // TE-6691 -- Not fully initialized yet so return if (EditingHelper == null || EditingHelper.EditedRootBox == null) { return; } if (e != null && e != CheckingError.Empty) { EditingHelper.EditedRootBox.DestroySelection(); IStTxtPara para = e.MyNote.BeginObjectRA as IStTxtPara; if (para != null && para.Owner is IStFootnote) { // Checking error is for text in a footnote. Make sure the footnote pane is open. IStFootnote footnote = para.Owner as IStFootnote; ((IViewFootnotes)DraftView).ShowFootnoteView(footnote); } else { ((IViewFootnotes)DraftView).FootnoteViewFocused = false; } // Note: EditingHelper is actually the active editing helper, so the above // code can change its value. EditingHelper.GoToScrScriptureNoteRef(e.MyNote); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares the given footnote with the values in m_footnote. /// </summary> /// <param name="footnote">The footnote to compare</param> /// ------------------------------------------------------------------------------------ private void CompareFootnote(IStFootnote footnote) { Assert.AreEqual(m_footnote.MarkerType, footnote.MarkerType); if (footnote.MarkerType == FootnoteMarkerTypes.SymbolicFootnoteMarker) { AssertEx.AreTsStringsEqual(m_footnote.FootnoteMarker, footnote.FootnoteMarker); } Assert.AreEqual(m_footnote.ParagraphsOS.Count, footnote.ParagraphsOS.Count, "Footnote paragraph count did not match"); string diff = string.Empty; for (int i = 0; i < m_footnote.ParagraphsOS.Count; i++) { IStTxtPara expectedPara = (IStTxtPara)m_footnote.ParagraphsOS[i]; IStTxtPara actualPara = (IStTxtPara)footnote.ParagraphsOS[i]; bool result = TsTextPropsHelper.PropsAreEqual(expectedPara.StyleRules, actualPara.StyleRules, out diff); Assert.IsTrue(result, "paragraph " + i + " stylerules differed in: " + diff); result = TsStringHelper.TsStringsAreEqual(expectedPara.Contents, actualPara.Contents, out diff); Assert.IsTrue(result, "paragraph " + i + " differed in: " + diff); CompareFootnoteTrans(expectedPara.GetBT(), actualPara); } }
public void FindNextMissingBtFootnoteMarker_BtSectionHeadToContent() { IScrSection section = m_exodus.SectionsOS[1]; ITsStrFactory strfact = TsStrFactoryClass.Create(); IStTxtPara contentPara = section.ContentOA[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); IStFootnote foot = m_exodus.InsertFootnoteAt(0, strBldr, 7); contentPara.Contents = strBldr.GetString(); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs); ICmTranslation trans = contentPara.GetOrCreateBT(); m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0); m_draftView.CallNextMissingBtFootnoteMarker(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(2, helper.IchAnchor, "IP should be after chapter and verse number."); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidContent, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation); }
public void CreateFromStringRep_BT_withBrackets() { SetupBackTrans(); // Setup expected results for the footnote ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_vernWs); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); ITsStrBldr bldr = TsStringUtils.MakeStrBldr(); bldr.Replace(0, 0, "Text in <brackets>", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); m_footnotePara.Contents = bldr.GetString(); // ... and now set up the expected results for the back translations of the footnote. AddRunToMockedTrans(m_trans, m_wsEs, "Spanish BT in <brackets>", null); AddRunToMockedTrans(m_trans, m_wsDe, "German BT in <brackets>", null); // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Text in <brackets></RUN>" + @"<TRANS WS='de'><RUN WS='de'>German BT in <brackets></RUN></TRANS>" + @"<TRANS WS='es'><RUN WS='es'>Spanish BT in <brackets></RUN></TRANS></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void CreateFromStringRep_twoParas() { ITsStrBldr bldr = m_footnotePara.Contents.GetBldr(); bldr.Replace(0, 0, "Paragraph One", null); m_footnotePara.Contents = bldr.GetString(); ReflectionHelper.SetField(typeof(ScrFootnote), "s_maxAllowedParagraphs", 2); // create second para IStTxtPara para = m_footnote.AddNewTextPara("Note Exegesis Paragraph"); bldr = TsStringUtils.MakeStrBldr(); bldr.Replace(0, 0, "Paragraph Two", StyleUtils.CharStyleTextProps("Foreign", m_wsUr)); para.Contents = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Paragraph One</RUN></P><P><PS>Note Exegesis Paragraph</PS>" + @"<RUN WS='ur' CS='Foreign'>Paragraph Two</RUN></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void FindNextMissingBtFootnoteMarker_BtSectionHeadToNowhere() { IScrSection section = m_exodus.SectionsOS[1]; ITsStrFactory strfact = TsStrFactoryClass.Create(); IStTxtPara contentPara = section.ContentOA[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); IStFootnote foot = m_exodus.InsertFootnoteAt(0, strBldr, 7); contentPara.Contents = strBldr.GetString(); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs); ICmTranslation trans = contentPara.GetOrCreateBT(); ITsStrBldr bldr = trans.Translation.get_String(Cache.DefaultAnalWs).GetBldr(); TsStringUtils.InsertOrcIntoPara(foot.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, 2, 2, Cache.DefaultAnalWs); trans.Translation.set_String(Cache.DefaultAnalWs, bldr.GetString()); m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0); m_draftView.CallNextMissingBtFootnoteMarker(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(0, helper.IchAnchor); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidHeading, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation); }
public void FindNextMissingBtFootnoteMarker_BtSectionHeadToContent() { IScrSection section = m_exodus.SectionsOS[1]; ITsStrFactory strfact = TsStrFactoryClass.Create(); IStTxtPara contentPara = section.ContentOA[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); IStFootnote foot = m_exodus.InsertFootnoteAt(0, strBldr, 7); contentPara.Contents = strBldr.GetString(); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs); m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidHeading, 0, 1, 0, 0, true, true, false, VwScrollSelOpts.kssoDefault); m_draftView.CallNextMissingBtFootnoteMarker(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.IsFalse(helper.IsRange); Assert.AreEqual(1, helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor)[0].ihvo, "IP should be in first non-label segment."); Assert.AreEqual(0, helper.IchAnchor, "IP should be at start of segment."); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidContent, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation); }
public void CreateFromStringRep_twoCharStylePara() { ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_vernWs); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Emphasis"); ITsStrBldr bldr = TsStringUtils.MakeStrBldr(); bldr.Replace(0, 0, "Test Text", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); bldr.Replace(bldr.Length, bldr.Length, "No char style", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Quoted Text"); bldr.Replace(bldr.Length, bldr.Length, "Ahh!!!!!!", propsBldr.GetTextProps()); m_footnotePara.Contents = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr' CS='Emphasis'>Test Text</RUN><RUN WS='fr'>No char style</RUN>" + "<RUN WS='fr' CS='Quoted Text'>Ahh!!!!!!</RUN></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void MakeLabelFromText_AnnotationOnFootnote() { IScrScriptureNote note = Cache.ServiceLocator.GetInstance <IScrScriptureNoteFactory>().Create(); m_scr.BookAnnotationsOS[0].NotesOS.Add(note); note.BeginRef = 01001011; note.EndRef = 01001011; IStFootnote footnote = AddFootnote(m_gen, (IStTxtPara)m_gen.SectionsOS[1].ContentOA.ParagraphsOS[0], 0); note.BeginObjectRA = AddParaToMockedText(footnote, "Whatever"); ITsString tss = m_vc.CallMakeLabelFromText("GEN 1:11", "WhoCares", note); Assert.AreEqual(3, tss.RunCount); #if __MonoCS__ const string fontname = "OpenSymbol"; const string symbol = "\u2042"; #else const string fontname = "Marlett"; const string symbol = "\u0032"; #endif Assert.AreEqual(symbol, tss.get_RunText(0)); Assert.AreEqual("GEN 1:11", tss.get_RunText(1)); Assert.AreEqual(fontname, tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptFontFamily)); Assert.AreEqual("WhoCares", tss.get_Properties(1).GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); CheckFinalSpaceInReferenceLabel(tss); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Checks if the current selection contains only a footnote reference, or is an IP /// associated with only a footnote reference. /// </summary> /// <param name="vwsel">selection to get info from</param> /// <returns>the footnote object, if current selection is on a footnote; /// otherwise null</returns> /// ------------------------------------------------------------------------------------ public IStFootnote GetFootnoteFromMarkerSelection(IVwSelection vwsel) { CheckDisposed(); IStFootnote footnote = null; // if we find a single run with the correct props, we are on an ORC hot link string sGuid = GetOrcHotLinkStrProp(vwsel); if (sGuid == null) { return(null); // not a footnote } // Get the underlying object for the guid. Guid guid = MiscUtils.GetGuidFromObjData(sGuid.Substring(1)); int hvoObj = Cache.GetIdFromGuid(guid); if (hvoObj != 0) { try { ICmObject obj = CmObject.CreateFromDBObject(Cache, hvoObj); footnote = obj as IStFootnote; } catch (NullReferenceException) { return(null); } } return(footnote); }
public void GetBookHvoWithFootnotes() { IScripture scr = Cache.LangProject.TranslatedScriptureOA; IScrBook genesis = scr.ScriptureBooksOS[0]; // Add a footnote in the first book, first section, first paragraph IScrSection section = genesis.SectionsOS[0]; IStFootnote footnote = AddFootnote(genesis, (IStTxtPara)section.ContentOA.ParagraphsOS[0], 2, "A footnote"); m_ScrPubCtrl.CallRefreshDisplay(); m_ScrPubCtrl.CreatePages(); m_ScrPubCtrl.PrepareToDrawPages(0, m_ScrPubCtrl.AutoScrollMinSize.Height * 2); // Simulate setting the IP at the beginning of the footnote bool fFoundPageWithFootnotes = false; foreach (DummyPage page in m_ScrPubCtrl.Pages) { if (page.DependentObjectsRootStream != null) { fFoundPageWithFootnotes = true; ((IVwRootBox)page.DependentObjectsRootStream).MakeSimpleSel(true, true, false, true); m_ScrPubCtrl.FocusedStream = page.DependentObjectsRootStream; break; } } Assert.IsTrue(fFoundPageWithFootnotes, "Can't run this test without finding any footnotes"); SelectionHelper selHelper = SelectionHelper.Create(m_ScrPubCtrl); IScrBook book = m_ScrPubCtrl.GetBook(selHelper, SelectionHelper.SelLimitType.Anchor); Assert.AreEqual(genesis, book); }
public void PageElementsDontOverlap_TwoFootnotes() { IScripture scr = Cache.LangProject.TranslatedScriptureOA; IScrBook genesis = scr.ScriptureBooksOS[0]; // Add a footnote in the first book, first section, first paragraph IScrSection section = genesis.SectionsOS[0]; IStFootnote footnote = AddFootnote(genesis, (IStTxtPara)section.ContentOA.ParagraphsOS[0], 2); IStTxtPara para = AddParaToMockedText(footnote, ScrStyleNames.NormalFootnoteParagraph); AddRunToMockedPara(para, "Another footnote", para.Cache.DefaultVernWs); // Add a footnote in the first book, last section, 6th paragraph section = (IScrSection)genesis.SectionsOS[genesis.SectionsOS.Count - 1]; footnote = AddFootnote(genesis, (IStTxtPara)section.ContentOA.ParagraphsOS[5], 10); para = AddParaToMockedText(footnote, ScrStyleNames.NormalFootnoteParagraph); AddRunToMockedPara(para, "This is the footnote", para.Cache.DefaultVernWs); m_pub.CreatePages(); m_pub.PrepareToDrawPages(0, m_pub.AutoScrollMinSize.Height * 2); Page firstPage = m_pub.Pages[0]; int cFoonotesOnThisPage = (int)m_division.m_testPageFootnoteInfo[firstPage.Handle]; Assert.AreEqual(2, cFoonotesOnThisPage, "Should display two footnotes on first page"); // None of the page elements on the first page should intersect CheckThatPageElementsDontOverlap(firstPage); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure footnote exists and is referred to properly in the paragraph contents /// </summary> /// <param name="footnote"></param> /// <param name="para"></param> /// <param name="ich">Character position where ORC should be</param> /// ------------------------------------------------------------------------------------ public static void VerifyFootnote(IStFootnote footnote, IStTxtPara para, int ich) { ITsString tss = para.Contents; int iRun = tss.get_RunAt(ich); Guid newFootnoteGuid = TsStringUtils.GetGuidFromRun(tss, iRun, FwObjDataTypes.kodtOwnNameGuidHot); Assert.AreEqual(footnote.Guid, newFootnoteGuid); }
public void CreateFromStringRep_ExcptnUnknownElement() { // Define text representation and create a footnote from it. string footnoteRep = @"<FN><BLAH>o</BLAH>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a back translation footnote ref ORC in the given translation for the given footnote /// </summary> /// <param name="trans">The given translation, usually a back translation</param> /// <param name="ichPos">The 0-based character offset into the translation string /// at which we will insert the reference ORC</param> /// <param name="ws">writing system of the ORC</param> /// <param name="footnote">The given footnote</param> /// ------------------------------------------------------------------------------------ public void AddBtFootnote(ICmTranslation trans, int ichPos, int ws, IStFootnote footnote) { // Insert a footnote reference ORC into the given translation string ITsStrBldr tsStrBldr = trans.Translation.get_String(ws).GetBldr(); TsStringUtils.InsertOrcIntoPara(footnote.Guid, FwObjDataTypes.kodtNameGuidHot, tsStrBldr, ichPos, ichPos, ws); trans.Translation.set_String(ws, tsStrBldr.GetString()); }
public void CreateFromStringRep_ExcptnInvalidICU() { // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='AINT_IT' CS='Emphasis'>Test Text</RUN></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); }
public void IPAtBeginningOfPara_FootnoteInMiddleOfPara() { AddFootnote(m_philemon, m_para, 7); m_editingHelper.SetupSelectionInPara(m_para, 0, m_section, 0, m_philemon, 0, 0, false); IStFootnote footnote = m_editingHelper.FindFootnoteNearSelection(null); Assert.IsNotNull(footnote, "should find a footnote."); }
public void CreateFromStringRep_ExcptnWSWithoutValue() { // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS=>Run has a writing system attribute but no value.</RUN></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); }
public void DeleteFootnoteMarkerInBt_ContextMenu() { IScrBook book = AddBookToMockedScripture(1, "Genesis"); AddTitleToMockedBook(book, "Genesis"); m_draftView.BookFilter.Add(book); IScrSection section = AddSectionToMockedBook(book); AddSectionHeadParaToSection(section, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph IStTxtPara parentPara = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(parentPara, "uno ", null); AddRunToMockedPara(parentPara, "2", ScrStyleNames.VerseNumber); AddRunToMockedPara(parentPara, "dos ", null); IStFootnote footnote1 = AddFootnote(book, parentPara, 5); AddParaToMockedText(footnote1, ScrStyleNames.NormalFootnoteParagraph); IStFootnote footnote2 = AddFootnote(book, parentPara, 10); AddParaToMockedText(footnote2, ScrStyleNames.NormalFootnoteParagraph); Assert.AreEqual(2, book.FootnotesOS.Count); // Construct the initial back translation int wsBt = Cache.DefaultAnalWs; ICmTranslation trans = AddBtToMockedParagraph(parentPara, wsBt); AddRunToMockedTrans(trans, wsBt, "one two", null); ITsStrBldr btTssBldr = trans.Translation.get_String(wsBt).GetBldr(); TsStringUtils.InsertOrcIntoPara(footnote1.Guid, FwObjDataTypes.kodtNameGuidHot, btTssBldr, 3, 3, wsBt); TsStringUtils.InsertOrcIntoPara(footnote2.Guid, FwObjDataTypes.kodtNameGuidHot, btTssBldr, 8, 8, wsBt); trans.Translation.set_String(wsBt, btTssBldr.GetString()); m_draftView.RefreshDisplay(); // Delete the marker for the back translation of the first footnote. We have to make a range selection // because by the time the tested method is called, a range selection of any adjacent footnotes has // already been made. SelectionHelper selHelper = m_draftView.SelectRangeOfChars(0, 0, 0, 3, 4); m_draftView.CallDeleteFootnote(); // Verify that both original footnotes still exist and that the first BT footnote marker is // deleted. Assert.AreEqual(2, book.FootnotesOS.Count); VerifyFootnote(footnote1, parentPara, 5); VerifyFootnote(footnote2, parentPara, 10); Assert.AreEqual("one two" + StringUtils.kChObject, trans.Translation.get_String(wsBt).Text); FdoTestHelper.VerifyBtFootnote(footnote2, parentPara, wsBt, 7); }
public void CreateFromStringRep_easy1Para() { string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'></RUN></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep( m_book, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void CreateFromStringRep_ExcptnUnknownTRANS_Element() { // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Fine so far...</RUN>" + "<TRANS WS='en'><BLAH>...but here's the problem</BLAH></TRANS></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure the marker for the specified footnote exists in the free translation of /// the specified segment in the specified paragraph at the specified character position. /// </summary> /// <param name="footnote">The footnote</param> /// <param name="para">vernacular paragraph which owns the segment</param> /// <param name="iSeg">The index of the segment.</param> /// <param name="ws">the writing system</param> /// <param name="ich">Character position where ORC should be in the specified segment</param> /// ------------------------------------------------------------------------------------ public static void VerifyFootnoteInSegmentFt(IStFootnote footnote, IStTxtPara para, int iSeg, int ws, int ich) { ISegment segment = para.SegmentsOS[iSeg]; ITsString tss = segment.FreeTranslation.get_String(ws); int iRun = tss.get_RunAt(ich); Guid newFootnoteGuid = TsStringUtils.GetGuidFromRun(tss, iRun, FwObjDataTypes.kodtNameGuidHot); Assert.AreEqual(footnote.Guid, newFootnoteGuid); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure the marker for a footnote exists in the back translation and refers to the /// footnote properly. /// </summary> /// <param name="footnote">given footnote whose marker we want to verify in the BT</param> /// <param name="para">vernacular paragraph which owns the back translation</param> /// <param name="ws">writing system of the back transltion</param> /// <param name="ich">Character position where ORC should be in the specified back /// translation</param> /// ------------------------------------------------------------------------------------ public static void VerifyBtFootnote(IStFootnote footnote, IStTxtPara para, int ws, int ich) { ICmTranslation trans = para.GetBT(); ITsString btTss = trans.Translation.get_String(ws); int iRun = btTss.get_RunAt(ich); Guid newFootnoteGuid = TsStringUtils.GetGuidFromRun(btTss, iRun, FwObjDataTypes.kodtNameGuidHot); Assert.AreEqual(footnote.Guid, newFootnoteGuid); }
public void IPInBookTitle_FootnoteInMiddleOfTitle() { IStTxtPara para = m_philemon.TitleOA[0]; AddFootnote(m_philemon, para, 7); m_editingHelper.SetupSelectionInTitlePara(para, 0, m_philemon, 0, 0); IStFootnote footnote = m_editingHelper.FindFootnoteNearSelection(null); Assert.IsNotNull(footnote, "should find a footnote."); }
public void CreateOwnedObjects_MultipleFootnotesStartInMiddle() { CheckDisposed(); StTxtPara para = m_inMemoryCache.AddParaToMockedText(m_currentText.Hvo, "Normal"); m_inMemoryCache.AddRunToMockedPara(para, "This is the paragraph of the second section " + "of the first chapter of Genesis. This is here so that we have enough characters " + "to insert footnotes into it.", null); m_inMemoryCache.AddFootnote(m_currentFootnotesOS, para, 0, null); m_inMemoryCache.AddFootnote(m_currentFootnotesOS, para, 20, null); StFootnote footnotePrev = (StFootnote)m_currentFootnotesOS[0]; StFootnote footnoteAfter = (StFootnote)m_currentFootnotesOS[1]; para = (StTxtPara)m_currentText.ParagraphsOS[0]; m_archivedFootnotesOS = m_inMemoryCache.CreateArbitraryFootnoteSequence(m_archivedText); StFootnote footnote1 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, para, 4, null); footnote1.DisplayFootnoteMarker = true; footnote1.DisplayFootnoteReference = false; StFootnote footnote2 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, para, 7, null); footnote2.DisplayFootnoteMarker = false; footnote2.DisplayFootnoteReference = true; Cache.ChangeOwner(para.Hvo, m_currentText.Hvo, (int)StText.StTextTags.kflidParagraphs, 0); NMock.DynamicMock mockIObjectMetaInfoProvider = new DynamicMock(typeof(IObjectMetaInfoProvider)); mockIObjectMetaInfoProvider.Strict = true; mockIObjectMetaInfoProvider.ExpectAndReturn("NextFootnoteIndex", 1, new object[] { para, 0 }); mockIObjectMetaInfoProvider.SetupResult("FootnoteMarkerStyle", "Note Marker"); para.CreateOwnedObjects(0, 10, (IObjectMetaInfoProvider)mockIObjectMetaInfoProvider.MockInstance); mockIObjectMetaInfoProvider.Verify(); Assert.AreEqual(4, m_currentFootnotesOS.Count); IStFootnote testFootnote = m_currentFootnotesOS[0]; Assert.AreEqual(footnotePrev.Hvo, testFootnote.Hvo, "Previous footnote shouldn't have moved"); testFootnote = m_currentFootnotesOS[1]; VerifyFootnote(testFootnote, para, 4); Assert.IsTrue(testFootnote.DisplayFootnoteMarker); Assert.IsFalse(testFootnote.DisplayFootnoteReference); testFootnote = m_currentFootnotesOS[2]; VerifyFootnote(testFootnote, para, 7); Assert.IsFalse(testFootnote.DisplayFootnoteMarker); Assert.IsTrue(testFootnote.DisplayFootnoteReference); testFootnote = m_currentFootnotesOS[3]; Assert.AreEqual(footnoteAfter.Hvo, testFootnote.Hvo, "Following footnote should have gotten bumped two places"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Display the footnote marker. /// </summary> /// <param name="vwenv">View environment</param> /// <param name="footnote">The footnote.</param> /// ------------------------------------------------------------------------------------ protected override void DisplayFootnoteMarker(IVwEnv vwenv, IStFootnote footnote) { // The footnote marker is not editable. vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); ITsStrBldr strBldr = ((IScrFootnote)footnote).MakeFootnoteMarker(DefaultWs); strBldr.ReplaceTsString(strBldr.Length, strBldr.Length, OneSpaceString); vwenv.AddString(strBldr.GetString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Setup the selection in footnote. /// </summary> /// <param name="footnote">The footnote.</param> /// <param name="book">The book.</param> /// <param name="iBook">The 0-based index of the book.</param> /// <param name="ichStart">The 0-based starting character index.</param> /// <param name="ichEnd">The 0-based ending character index.</param> /// ------------------------------------------------------------------------------------ public void SetupSelectionInFootnote(IStFootnote footnote, IScrBook book, int iBook, int ichStart, int ichEnd) { CheckDisposed(); DynamicMock fakeSelHelper = new DynamicMock(typeof(SelectionHelper)); fakeSelHelper.SetupResult("GetTextPropId", StTxtParaTags.kflidContents, typeof(SelectionHelper.SelLimitType)); fakeSelHelper.SetupResult("NumberOfLevels", 3); // Setup the anchor SelLevInfo[] topInfo = new SelLevInfo[3]; IStTxtPara para = footnote[0]; topInfo[0].tag = StTextTags.kflidParagraphs; topInfo[0].ihvo = 0; // only one para per footnote allowed topInfo[0].hvo = para.Hvo; topInfo[1].tag = ScrBookTags.kflidFootnotes; topInfo[1].ihvo = footnote.IndexInOwner; topInfo[1].hvo = footnote.Hvo; topInfo[2].tag = BookFilter.Tag; topInfo[2].ihvo = iBook; topInfo[2].hvo = book.Hvo; // Setup the end SelLevInfo[] bottomInfo = new SelLevInfo[3]; for(int i = 0; i < 3; i++) bottomInfo[i] = topInfo[i]; fakeSelHelper.SetupResult("LevelInfo", topInfo); fakeSelHelper.SetupResult("IchAnchor", ichStart); fakeSelHelper.SetupResult("IchEnd", ichEnd); fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo, SelectionHelper.SelLimitType.Top); fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo, SelectionHelper.SelLimitType.Anchor); fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo, SelectionHelper.SelLimitType.Bottom); fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo, SelectionHelper.SelLimitType.End); fakeSelHelper.SetupResultForParams("GetIch", ichStart, SelectionHelper.SelLimitType.Top); fakeSelHelper.SetupResultForParams("GetIch", ichEnd, SelectionHelper.SelLimitType.Bottom); m_currentSelection = (SelectionHelper)fakeSelHelper.MockInstance; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the displayed text for a footnote. /// </summary> /// <param name="iBook">Index of the book the footnote is in</param> /// <param name="iFootnote">Index of the footnote</param> /// <param name="footnote">The footnote object</param> /// <returns>The TsString representing the text of the footnote, including any displayed /// marker, reference, etc.</returns> /// ------------------------------------------------------------------------------------ public ITsString GetDisplayedTextForFootnote(int iBook, int iFootnote, IStFootnote footnote) { SelectionHelper helper = new SelectionHelper(); // Create selection in footnote marker SelLevInfo[] anchorLevInfo = new SelLevInfo[4]; anchorLevInfo[3].tag = BookFilter.Tag; anchorLevInfo[3].ihvo = iBook; anchorLevInfo[2].tag = ScrBookTags.kflidFootnotes; anchorLevInfo[2].ihvo = iFootnote; anchorLevInfo[1].tag = StTextTags.kflidParagraphs; anchorLevInfo[1].ihvo = 0; anchorLevInfo[0].tag = -1; anchorLevInfo[0].ihvo = 0; helper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, anchorLevInfo); helper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, (int)VwSpecialAttrTags.ktagGapInAttrs); helper.IchAnchor = 0; SelLevInfo[] endLevInfo = new SelLevInfo[3]; endLevInfo[2].tag = BookFilter.Tag; endLevInfo[2].ihvo = iBook; endLevInfo[1].tag = ScrBookTags.kflidFootnotes; endLevInfo[1].ihvo = iFootnote; endLevInfo[0].tag = StTextTags.kflidParagraphs; endLevInfo[0].ihvo = 0; helper.SetLevelInfo(SelectionHelper.SelLimitType.End, endLevInfo); helper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); string footnoteText = ((IStTxtPara)footnote.ParagraphsOS[0]).Contents.Text; helper.IchEnd = footnoteText.Length; helper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); helper.SetSelection(this, true, true); IVwSelection sel = RootBox.Selection; ITsString tss; sel.GetSelectionString(out tss, string.Empty); return tss; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Show or hide the footnote view. /// </summary> /// <param name="footnote">Footnote to scroll to or <c>null</c> to just display or hide /// the footnote view. If a footnote is given the footnote view will always be shown.</param> /// <param name="fPutInsertionPtAtEnd">if set to <c>true</c> and showing the view, /// the insertion point will be put at the end of the footnote text instead of at the /// beginning, as would be appropriate in the case of a newly inserted footnote that has /// Reference Text. This parameter is ignored if footnote is null.</param> /// ------------------------------------------------------------------------------------ internal virtual void ShowOrHideFootnoteView(IStFootnote footnote, bool fPutInsertionPtAtEnd) { CheckDisposed(); // toggle the footnote view on or off bool fShow = !m_grid.Rows[kFootnoteRow].Visible || footnote != null; // Prevent painting while we possibly expand lazy boxes ((IRootSite)this).AllowPainting = false; try { // show or hide the footnote view m_grid.Rows[kFootnoteRow].Visible = fShow; #if __MonoCS__ // FWNX-360: work around mono datagridview differences // // TODO-Linux: write a datagridview test case a submit a bug report to mono // on mono after setting m_grid.Rows[kFootnoteRow].Visible to false // GetControl(kFootnoteRow, kDraftViewColumn) still returns true. // Also on mono Setting the last Row visiblity to false doesn't causes // the grid to expand to cover the space. // explicity changing it height works around this. FootnoteView.Visible = fShow; // set the Actual Control Visibilty. m_grid.Rows[kFootnoteRow].Height = m_grid.Rows[kFootnoteRow].Height - 1; m_grid.Rows[kFootnoteRow].Height = m_grid.Rows[kFootnoteRow].Height + 1; #endif } finally { ((IRootSite)this).AllowPainting = true; } if (fShow && FootnoteView != null) { if (footnote != null) FootnoteView.ScrollToFootnote(footnote, fPutInsertionPtAtEnd); FootnoteView.Focus(); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Show (or hide) the footnote view. /// </summary> /// <param name="footnote">Footnote to scroll to or <c>null</c> to just display or hide /// the footnote view. If a footnote is given the footnote view will always be shown. /// </param> /// <param name="fPutInsertionPtAtEnd">if set to <c>true</c> and showing the view, /// the insertion point will be put at the end of the footnote text instead of at the /// beginning, as would be appropriate in the case of a newly inserted footnote that has /// Reference Text. This parameter is ignored if footnote is null.</param> /// ------------------------------------------------------------------------------------ internal override void ShowOrHideFootnoteView(IStFootnote footnote, bool fPutInsertionPtAtEnd) { CheckDisposed(); //toggle bool fShow = !m_grid.Rows[kFootnoteRow].Visible || footnote != null; base.ShowOrHideFootnoteView(footnote, fPutInsertionPtAtEnd); if (fShow) { // We don't want to show both draft view rows together with the footnotes m_fBothDraftViewsShowing = (m_grid.Rows[kUpperDraftRow].Visible && m_grid.Rows[kLowerDraftRow].Visible); // Determine which of the draft view to collapse (if both are open) if (m_fBothDraftViewsShowing) { if (FocusedRootSite == GetControl(kUpperDraftRow, kDraftViewColumn)) m_grid.Rows[kLowerDraftRow].Visible = false; else m_grid.Rows[kUpperDraftRow].Visible = false; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure footnote exists and is referred to properly in the paragraph contents /// </summary> /// <param name="footnote">The expected footnote</param> /// <param name="para">The paragraph whose contents should contain an ORC for the footnote</param> /// <param name="ich">Character position where ORC should be</param> /// ------------------------------------------------------------------------------------ protected void VerifyFootnote(IStFootnote footnote, IStTxtPara para, int ich) { Guid guid = footnote.Guid; ITsString tss = para.Contents; int iRun = tss.get_RunAt(ich); ITsTextProps orcPropsParaFootnote = tss.get_Properties(iRun); string objData = orcPropsParaFootnote.GetStrPropValue( (int)FwTextPropType.ktptObjData); Assert.IsNotNull(objData, "Footnote not found at character offset " + ich); Assert.AreEqual((char)(int)FwObjDataTypes.kodtOwnNameGuidHot, objData[0]); // Send the objData string without the first character because the first character // is the object replacement character and the rest of the string is the GUID. Guid newFootnoteGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1)); Assert.AreEqual(guid, newFootnoteGuid); string sOrc = tss.get_RunText(iRun); Assert.AreEqual(StringUtils.kChObject, sOrc[0]); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure footnote exists and is referred to properly in the paragraph contents /// </summary> /// <param name="footnote">The footnote to verify</param> /// <param name="para">The paragraph that is expected to contain the footnote ORC</param> /// <param name="ich">Character position where ORC should be</param> /// ------------------------------------------------------------------------------------ protected void VerifyFootnote(IStFootnote footnote, IStTxtPara para, int ich) { StTxtParaTests.VerifyFootnote(footnote, para, ich); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a back translation footnote in the given translation for the given footnote. /// Inserts a ref ORC in the translation and sets the the BT text in the footnote. /// </summary> /// <param name="trans">The given back translation of an StTxtPara</param> /// <param name="ichPos">The 0-based character offset into the back translation string /// at which we will insert the reference ORC</param> /// <param name="ws">writing system of the BT and ORC</param> /// <param name="footnote">The given footnote</param> /// <param name="footnoteBtText">text for the back translation of the footnote</param> /// <returns>the back translation of the given footnote</returns> /// ------------------------------------------------------------------------------------ public ICmTranslation AddBtFootnote(ICmTranslation trans, int ichPos, int ws, IStFootnote footnote, string footnoteBtText) { AddBtFootnote(trans, ichPos, ws, footnote); // Add the given footnote BT text to the footnote. IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS[0]; ICmTranslation footnoteTrans = para.GetOrCreateBT(); ITsStrBldr tssFootnoteBldr = footnoteTrans.Translation.get_String(ws).GetBldr(); tssFootnoteBldr.ReplaceRgch(0, 0, footnoteBtText, footnoteBtText.Length, StyleUtils.CharStyleTextProps(null, ws)); footnoteTrans.Translation.set_String(ws, tssFootnoteBldr.GetString()); return footnoteTrans; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a book with two footnotes. /// </summary> /// <param name="philemon">The book of philemon that will have one paragraph with two /// footnotes.</param> /// <param name="footnote1">first footnote to be inserted at character index 1</param> /// <param name="footnote2">second footnote to be inserted at character index 10</param> /// ------------------------------------------------------------------------------------ private void CreateBookWithTwoFootnotes(out IScrBook philemon, out IStFootnote footnote1, out IStFootnote footnote2) { philemon = AddBookToMockedScripture(57, "Philemon"); IScrSection section = AddSectionToMockedBook(philemon); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "this is more text", null); footnote1 = AddFootnote(philemon, para, 1); IStTxtPara footnotePara = Cache.ServiceLocator.GetInstance<IScrTxtParaFactory>().CreateWithStyle( footnote1, ScrStyleNames.NormalFootnoteParagraph); footnotePara.Contents = Cache.TsStrFactory.MakeString("This is my first footnote", Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle); footnote2 = AddFootnote(philemon, para, 10); footnotePara = Cache.ServiceLocator.GetInstance<IScrTxtParaFactory>().CreateWithStyle( footnote2, ScrStyleNames.NormalFootnoteParagraph); footnotePara.Contents = Cache.TsStrFactory.MakeString("This is my second footnote", Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Process a back translation segment (duh) /// </summary> /// ------------------------------------------------------------------------------------ protected void ProcessBackTransSegment() { if (m_styleProxy.Function == FunctionValues.Chapter) { ProcessStartOfChapter(); return; } if (!m_settings.ImportBackTranslation) { if (m_styleProxy.Function == FunctionValues.Verse) m_currentRef.Verse = SOWrapper.SegmentFirstRef.Verse; return; } if (CurrentBook == null) { // An interleaved BT paragraph is being imported for a book that // doesn't exist. throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernBook, null, null, ScrReference.NumberToBookCode(m_nBookNumber), null, null, true); } // Any non-end marker ends a character style if (m_context != ContextValues.EndMarker) EndCharStyle(); ITsTextProps ttpBtSeg; bool fThisSegmentEndsAFootnote = false; if (m_importDomain == ImportDomain.Main) { int wsBT = BackTransWS; ttpBtSeg = GetBTProps(wsBT); if (wsBT != m_wsCurrBtPara && (m_styleProxy.Domain != MarkerDomain.Default || m_styleProxy.StyleType == StyleType.kstParagraph)) { // We're about to change which WS is being processed, so end any open character // style and/or footnote. EndCharStyle(); if (m_fInFootnote) { EndFootnote(); fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0; } m_wsCurrBtPara = wsBT; } else if (m_context == ContextValues.EndMarker) fThisSegmentEndsAFootnote = ProcessBTEndMarker(); else if (m_fInFootnote && (m_currDomain & MarkerDomain.Footnote) != 0 && m_styleProxy.StyleType == StyleType.kstParagraph) { EndFootnote(); fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0; } } else { ttpBtSeg = GetBTProps(m_wsCurrBtPara); if (m_context == ContextValues.EndMarker) fThisSegmentEndsAFootnote = ProcessBTEndMarker(); } if (m_importDomain == ImportDomain.BackTrans && ProcessingParagraphStart) { if (m_fInFootnote) { EndFootnote(); fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0; } AddBackTranslations(); } if (!m_fInScriptureText && m_styleProxy.Context == ContextValues.Text && m_styleProxy.Structure == StructureValues.Body) { // If this BT segment is a scripture body segment and we don't already have // a paragraph started, this file must have an implicit paragraph start, // so we initialize the member that holds the para style proxy for the // corresponding vernacular para so we'll have something reasonable to // look for when we go to find the corresponding para. if (m_BTStrBldrs.Count == 0 && m_importDomain == ImportDomain.BackTrans) m_vernParaStyleProxy = m_DefaultScrParaProxy; m_fInScriptureText = true; m_iNextBtPara = 0; } ITsStrBldr strbldr; if (m_BTStrBldrs.ContainsKey(m_wsCurrBtPara)) { // We continue to use the existing BT para builder (for this WS) until the // vernacular paragraph -- and hence any BT paragraph(s) -- get written. // This means that if the BT contains spurious paragraph markers, their // segments will just be appended to the one-and-only BT paragraph (for this // WS) already being built. // TODO: Generate an error annotation. Debug.Assert(m_wsCurrBtPara != 0); strbldr = m_BTStrBldrs[m_wsCurrBtPara]; } else { if (ProcessingParagraphStart) { if (m_importDomain == ImportDomain.Main) { if (m_vernParaStyleProxy == null || m_vernParaStyleProxy.StyleId == null) { // Got an unexpected BT paragraph segment. A BT paragraph came before // any vernacular paragraph in the import stream. int verse = SOWrapper.SegmentFirstRef.Verse; throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernPara, SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber, m_sMarker + " " + m_sSegmentText, m_fFoundABook ? CurrentBook.BookId : null, m_foundAChapter ? m_nChapter.ToString() : null, (verse > 0) ? verse.ToString() : null, true); } if (m_vernParaStyleProxy.StyleId != m_styleProxy.StyleId && m_styleProxy.Style.Type != StyleType.kstCharacter) { // Got an unexpected BT paragraph segment. The paragraph style of the BT // paragraph doesn't match the style of the corresponding (i.e., // preceding) vernacular paragraph. int verse = SOWrapper.SegmentFirstRef.Verse; throw new ScriptureUtilsException(SUE_ErrorCode.BackTransStyleMismatch, m_sMarker + " " + m_sSegmentText, string.Format( TeResourceHelper.GetResourceString("kstidBTStyleMismatchDetails"), m_styleProxy.StyleId, m_vernParaStyleProxy.StyleId), m_fFoundABook ? CurrentBook.BookId : null, m_foundAChapter ? m_nChapter.ToString() : null, (verse > 0) ? verse.ToString() : null, true); } } // Non-interleaved BT else { ProcessBtParaStart(); } } strbldr = TsStringUtils.MakeTss("", m_wsCurrBtPara).GetBldr(); Debug.Assert(m_wsCurrBtPara != 0); m_BTStrBldrs[m_wsCurrBtPara] = strbldr; } if (m_context == ContextValues.Title) { SetBookName(); if (m_fInBookTitle) { // We have another segment to add to the current title AddBookTitleSegment(strbldr, m_vernParaStyleProxy, ttpBtSeg); return; } m_fInBookTitle = true; } AddPendingVerseAndChapterNumsToBackTrans(GetVerseRefAsString(m_wsCurrBtPara), m_wsCurrBtPara, strbldr); if ((m_currDomain & MarkerDomain.Footnote) != 0 && !fThisSegmentEndsAFootnote) { if (m_BTFootnoteStrBldr == null) { if (m_fInFootnote) { // This BT footnote ends the vernacular footnote being built EndFootnote(); } // remember that we are now processing a footnote SetInFootnote(); CheckDataForFootnoteMarker(); m_BTFootnoteStrBldr = TsStrBldrClass.Create(); m_sBtFootnoteParaStyle = (m_styleProxy.StyleType == StyleType.kstCharacter) ? m_DefaultFootnoteParaProxy.StyleId : m_styleProxy.StyleId; if (m_importDomain == ImportDomain.Main) { // If we aren't importing the vernacular... (TE-7445) if (!m_settings.ImportTranslation) { // attempt to find an existing vernacular paragraph that corresponds // to the back translation para. bool append; m_lastPara = FindCorrespondingVernParaForSegment(m_vernParaStyleProxy.Style, m_currentRef, out append); m_CurrParaFootnotes = (m_lastPara != null ? m_lastPara.GetFootnotes() : null); } m_CurrBTFootnote = FindCorrespondingFootnote(m_sBtFootnoteParaStyle); if (m_CurrBTFootnote == null) { int verse = SOWrapper.SegmentFirstRef.Verse; throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernFootnote, SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber, m_sMarker + " " + m_sSegmentText, m_fFoundABook ? CurrentBook.BookId : null, m_foundAChapter ? m_nChapter.ToString(): null, (verse > 0) ? verse.ToString() : null, true); } } else { m_CurrBTFootnote = null; } } strbldr = m_BTFootnoteStrBldr; if (m_styleProxy.StyleType == StyleType.kstCharacter && m_styleProxy.Context != ContextValues.EndMarker) { SetInCharacterStyle(); } } else if (m_styleProxy.StyleType == StyleType.kstCharacter && m_styleProxy.Function != FunctionValues.Verse) { SetInCharacterStyle(); } // Add a line break between section head segments if we're processing // interleaved back translation section heading segments. if (m_fInSectionHeading && strbldr.Length > 0 && ProcessingParagraphStart && m_importDomain == ImportDomain.Main) { AddTextToPara(kHardLineBreak, ttpBtSeg, strbldr); } AddTextToPara(m_sSegmentText, ttpBtSeg, strbldr); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finalize the BT of the footnote, if any. /// </summary> /// ------------------------------------------------------------------------------------ protected void EndBTFootnote() { Debug.Assert(m_fInFootnote); Debug.Assert(m_BTFootnoteStrBldr != null); ITsStrBldr strbldr = m_BTStrBldrs[m_wsCurrBtPara]; TrimTrailingSpace(m_BTFootnoteStrBldr); // If the last character in the paragraph is a separator, then insert the footnote // marker before it. (see TE-2431) int ichMarker = strbldr.Length; if (ichMarker > 0) { string s = strbldr.GetChars(ichMarker - 1, ichMarker); if (UnicodeCharProps.get_IsSeparator(s[0])) ichMarker--; } if (m_CurrBTFootnote != null) { // Don't support importing multi-para footnotes IScrTxtPara para = (IScrTxtPara)m_CurrBTFootnote.ParagraphsOS[0]; ICmTranslation transl = para.GetOrCreateBT(); ITsString btTss = m_BTFootnoteStrBldr.Length == 0 ? m_TsStringFactory.MakeString(string.Empty, m_wsCurrBtPara) : m_BTFootnoteStrBldr.GetString(); transl.Translation.set_String(m_wsCurrBtPara, btTss); m_CurrBTFootnote.InsertRefORCIntoTrans(strbldr, ichMarker, m_wsCurrBtPara); m_CurrBTFootnote = null; } else { m_BtFootnoteStrBldrs.Add(new BtFootnoteBldrInfo(m_wsCurrBtPara, m_BTFootnoteStrBldr, m_sBtFootnoteParaStyle, ichMarker, m_currentRef)); } m_fInFootnote = false; m_BTFootnoteStrBldr = null; if ((m_styleProxy.Domain & MarkerDomain.Footnote) == 0) m_currDomain &= ~MarkerDomain.Footnote; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. if (m_SOWrapper != null) m_SOWrapper.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_cpe = null; m_settings = null; m_SOWrapper = null; m_sSegmentText = null; m_sMarker = null; m_styleProxy = null; m_vernParaStyleProxy = null; m_vernTextProps = null; m_analTextProps = null; m_styleProxies = null; m_notesStyleProxies = null; m_lastPara = null; m_BookTitleParaProxy = null; m_DefaultFootnoteParaProxy = null; m_TsStringFactory = null; m_BTFootnoteStrBldr = null; m_CurrParaPictures = null; m_CurrParaFootnotes = null; m_BTPendingPictures = null; m_CurrBTFootnote = null; m_sBtFootnoteParaStyle = null; m_BtFootnoteStrBldrs = null; m_PendingAnnotations = null; m_BTfootnoteIndex = null; m_sCharStyleEndMarker = null; m_sFootnoteEndMarker = null; m_sCharStyleBeginMarker = null; m_sFootnoteBeginMarker = null; m_scrTranslatorAnnotationDef = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Show (or hide) the footnote view. /// </summary> /// <param name="footnote">Footnote to scroll to or <c>null</c> to just display or hide /// the footnote view. If a footnote is given the footnote view will always be shown. /// </param> /// ------------------------------------------------------------------------------------ public void ShowFootnoteView(IStFootnote footnote) { CheckDisposed(); ShowOrHideFootnoteView(footnote, false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Show the footnote view. /// </summary> /// <param name="footnote">Footnote to scroll to or null to just display the footnote view</param> /// <param name="fPutInsertionPtAtEnd">if set to <c>true</c> and showing the view, /// the insertion point will be put at the end of the footnote text instead of at the /// beginning, as would be appropriate in the case of a newly inserted footnote that has /// Reference Text. This parameter is ignored if footnote is null.</param> /// ------------------------------------------------------------------------------------ internal override void ShowOrHideFootnoteView(IStFootnote footnote, bool fPutInsertionPtAtEnd) { CheckDisposed(); bool fBtActivated = IsBtActivated; if (footnote != null && FootnoteViewShowing) { FootnoteView footnoteView = (FootnoteView)GetControl(kFootnoteRow, fBtActivated ? kBackTransColumn : kDraftViewColumn); footnoteView.ScrollToFootnote(footnote, fPutInsertionPtAtEnd); } else base.ShowOrHideFootnoteView(footnote, fPutInsertionPtAtEnd); SetFocus(fBtActivated); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares the given footnote with the values in m_footnote. /// </summary> /// <param name="footnote">The footnote to compare</param> /// ------------------------------------------------------------------------------------ private void CompareFootnote(IStFootnote footnote) { Assert.AreEqual(m_footnote.MarkerType, footnote.MarkerType); if (footnote.MarkerType == FootnoteMarkerTypes.SymbolicFootnoteMarker) AssertEx.AreTsStringsEqual(m_footnote.FootnoteMarker, footnote.FootnoteMarker); Assert.AreEqual(m_footnote.ParagraphsOS.Count, footnote.ParagraphsOS.Count, "Footnote paragraph count did not match"); string diff = string.Empty; for (int i = 0; i < m_footnote.ParagraphsOS.Count; i++) { IStTxtPara expectedPara = (IStTxtPara)m_footnote.ParagraphsOS[i]; IStTxtPara actualPara = (IStTxtPara)footnote.ParagraphsOS[i]; bool result = TsTextPropsHelper.PropsAreEqual(expectedPara.StyleRules, actualPara.StyleRules, out diff); Assert.IsTrue(result, "paragraph " + i + " stylerules differed in: " + diff); result = TsStringHelper.TsStringsAreEqual(expectedPara.Contents, actualPara.Contents, out diff); Assert.IsTrue(result, "paragraph " + i + " differed in: " + diff); CompareFootnoteTrans(expectedPara.GetBT(), actualPara); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a footnote reference marker (ref orc) /// </summary> /// <param name="footnote">given footnote</param> /// <param name="para">paragraph owning the translation to insert footnote marker into</param> /// <param name="ws">given writing system for the back translation</param> /// <param name="ichPos">The 0-based character offset into the translation</param> /// ------------------------------------------------------------------------------------ protected void InsertTestBtFootnote(IStFootnote footnote, IStTxtPara para, int ws, int ichPos) { ICmTranslation trans = para.GetOrCreateBT(); ITsStrBldr bldr = trans.Translation.get_String(ws).GetBldr(); footnote.InsertRefORCIntoTrans(bldr, ichPos, ws); trans.Translation.set_String(ws, bldr.GetString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure footnote exists and is referred to properly in the paragraph contents /// </summary> /// <param name="footnote"></param> /// <param name="para"></param> /// <param name="ich">Character position where ORC should be</param> /// ------------------------------------------------------------------------------------ public static void VerifyFootnote(IStFootnote footnote, IStTxtPara para, int ich) { Guid guid = footnote.Cache.GetGuidFromId(footnote.Hvo); ITsString tss = para.Contents.UnderlyingTsString; int iRun = tss.get_RunAt(ich); ITsTextProps orcPropsParaFootnote = tss.get_Properties(iRun); string objData = orcPropsParaFootnote.GetStrPropValue( (int)FwTextPropType.ktptObjData); Assert.AreEqual((char)(int)FwObjDataTypes.kodtOwnNameGuidHot, objData[0]); // Send the objData string without the first character because the first character // is the object replacement character and the rest of the string is the GUID. Guid newFootnoteGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1)); Assert.AreEqual(guid, newFootnoteGuid); Assert.AreEqual(footnote.Hvo, footnote.Cache.GetIdFromGuid(newFootnoteGuid)); string sOrc = tss.get_RunText(iRun); Assert.AreEqual(StringUtils.kchObject, sOrc[0]); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Scrolls the requested footnote to the top of the view /// </summary> /// <param name="footnote">The target footnote</param> /// <param name="fPutInsertionPtAtEnd">if set to <c>true</c> and showing the view, /// the insertion point will be put at the end of the footnote text instead of at the /// beginning, as would be appropriate in the case of a newly inserted footnote that has /// Reference Text. This parameter is ignored if footnote is null.</param> /// ------------------------------------------------------------------------------------ public void ScrollToFootnote(IStFootnote footnote, bool fPutInsertionPtAtEnd) { CheckDisposed(); // find book owning this footnote int iBook = m_bookFilter.GetBookIndex((IScrBook)footnote.Owner); // find index of this footnote int iFootnote = footnote.IndexInOwner; // create selection pointing to this footnote // TODO (FWR-2270): This won't work correctly in BT or segmented BT footnote views whe // attempting to put the IP at the end of the footnote. FootnoteEditingHelper.ScrollToFootnote(iBook, iFootnote, (fPutInsertionPtAtEnd ? ((IStTxtPara)footnote.ParagraphsOS[0]).Contents.Length: 0)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Display the footnote marker /// </summary> /// <param name="vwenv">View environment</param> /// <param name="footnote">The footnote.</param> /// ------------------------------------------------------------------------------------ protected virtual void DisplayFootnoteMarker(IVwEnv vwenv, IStFootnote footnote) { // The footnote marker is not editable. vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); vwenv.AddStringProp(StFootnoteTags.kflidFootnoteMarker, null); // add a read-only space after the footnote marker vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); vwenv.AddString(OneSpaceString); }
/// -------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="FootnoteOrcLocation"/> class. /// </summary> /// <param name="footnote">The footnote.</param> /// -------------------------------------------------------------------------------- internal FootnoteOrcLocation(IStFootnote footnote) { this.footnote = footnote; }