public void CreateFromStringRep_twoParas() { CheckDisposed(); ITsStrBldr bldr = m_footnotePara.Contents.UnderlyingTsString.GetBldr(); bldr.Replace(0, 0, "Paragraph One", null); m_footnotePara.Contents.UnderlyingTsString = bldr.GetString(); // create second para StTxtPara para = new StTxtPara(); m_footnote.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps("Note Exegesis Paragraph"); bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Paragraph Two", StyleUtils.CharStyleTextProps("Foreign", m_wsUr)); para.Contents.UnderlyingTsString = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><ShowMarker/><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>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void CreateFromStringRep_BT_withBrackets() { CheckDisposed(); SetupBackTrans(); // Setup expected results for the footnote ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_vernWs); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Text in <brackets>", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); m_footnotePara.Contents.UnderlyingTsString = bldr.GetString(); // ... and now set up the expected results for the back translations of the footnote. m_scrInMemoryCache.AddRunToMockedTrans(m_trans, m_wsEs, "Spanish BT in <brackets>", null); m_scrInMemoryCache.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><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Text in <brackets></RUN>" + @"<TRANS WS='es'><RUN WS='es'>Spanish BT in <brackets></RUN></TRANS>" + @"<TRANS WS='de'><RUN WS='de'>German BT in <brackets></RUN></TRANS></P></FN>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
int m_wsUr; // Urdu writing system (used for Foreign style) #endregion #region Test setup /// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_inMemoryCache.InitializeWritingSystemEncodings(); // create footnote m_footnote = new StFootnote(); m_book = (ScrBook)m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_book.FootnotesOS.Append(m_footnote); m_footnote.FootnoteMarker.Text = "o"; m_footnote.DisplayFootnoteMarker = true; m_footnote.DisplayFootnoteReference = false; // create one empty footnote para StTxtPara para = new StTxtPara(); m_footnote.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); m_strFact = TsStrFactoryClass.Create(); m_vernWs = Cache.LangProject.DefaultVernacularWritingSystem; para.Contents.UnderlyingTsString = m_strFact.MakeString(string.Empty, m_vernWs); m_footnotePara = (StTxtPara)m_footnote.ParagraphsOS[0]; m_wsUr = InMemoryFdoCache.s_wsHvos.Ur; // used with 'foreign' character style m_wsDe = InMemoryFdoCache.s_wsHvos.De; // used for back translations m_wsEs = InMemoryFdoCache.s_wsHvos.Es; }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { ITsStrFactory strfact = TsStrFactoryClass.Create(); //Jude IScrBook jude = m_scrInMemoryCache.AddBookToMockedScripture(65, "Jude"); m_scrInMemoryCache.AddTitleToMockedBook(jude.Hvo, "Jude"); // Jude Scripture section IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(jude.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "First section", "Section Head"); StTxtPara judePara = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, "Paragraph"); m_scrInMemoryCache.AddRunToMockedPara(judePara, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(judePara, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(judePara, "This is the first verse", null); // Insert footnote into para 1 of Jude ITsStrBldr bldr = judePara.Contents.UnderlyingTsString.GetBldr(); StFootnote foot = ScrFootnote.InsertFootnoteAt(jude, 0, bldr, 10, "#"); StTxtPara footPara = new StTxtPara(); foot.ParagraphsOS.Append(footPara); footPara.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); footPara.Contents.UnderlyingTsString = strfact.MakeString("This is text for the footnote.", Cache.DefaultVernWs); judePara.Contents.UnderlyingTsString = bldr.GetString(); section.AdjustReferences(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a blank dummy footnote. Used when a footnote object is missing. /// Note: This does not insert an ORC into the paragraph. The caller is fixing the ORC /// with a missing object. /// </summary> /// <param name="owner">The owner to which we will add a footnote.</param> /// <param name="iFootnote">The 0-based index where the footnote will be inserted in the /// owner.</param> /// <param name="paraContents">The paragraph string where the ORC is being fixed.</param> /// <param name="iRun">The 0-based index of the run from which we will get the writing /// system used in the footnote.</param> /// <returns>a blank general footnote</returns> /// ------------------------------------------------------------------------------------ protected override StFootnote CreateBlankDummyFootnoteNoRecursion(ICmObject owner, int iFootnote, ITsString paraContents, int iRun) { if (!(owner is IScrBook)) { return(base.CreateBlankDummyFootnoteNoRecursion(owner, iFootnote, paraContents, iRun)); } // get the writing system of the existing ORC run int nDummy; int ws = paraContents.get_Properties(iRun).GetIntPropValues( (int)FwTextPropType.ktptWs, out nDummy); // Make a dummy blank footnote IScripture scr = m_cache.LangProject.TranslatedScriptureOA; string sMarker = scr.GeneralFootnoteMarker; StFootnote newFootnote = ScrFootnote.CreateFootnoteInScrBook((IScrBook)owner, iFootnote, ref sMarker, m_cache, ws); // Create an empty footnote paragraph with properties with default style and writing system. StTxtPara footnotePara = new StTxtPara(); newFootnote.ParagraphsOS.Append(footnotePara); footnotePara.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); // Insert an empty run into the footnote paragraph in order to set the // default writing system. ITsStrFactory strFactory = TsStrFactoryClass.Create(); footnotePara.Contents.UnderlyingTsString = strFactory.MakeString(string.Empty, m_cache.DefaultVernWs); return(newFootnote); }
/// ------------------------------------------------------------------------------------ /// <summary> /// A helper method for book merger tests- /// Verifies the contents of the given sub-difference /// for a two-sided subDiff representing a text comparison. This overload does not /// check for the starting and ending references for sub-diffs that are created without /// that information. /// </summary> /// <param name="rootDiff">The root difference.</param> /// <param name="iSubDiff">The sub difference to verify.</param> /// <param name="subDiffType">Type of the sub difference.</param> /// <param name="footnoteCurr">The footnote curr.</param> /// <param name="ichMinCurr">The beginning character offset of the difference in the /// current.</param> /// <param name="ichLimCurr">The ending character offset of the difference in the /// current.</param> /// <param name="footnoteRev">The footnote rev.</param> /// <param name="ichMinRev">The beginning character offset of the difference in the /// revision.</param> /// <param name="ichLimRev">The ending character offset of the difference in the /// current.</param> /// <remarks>char styles are not verified here; test code should just check /// those directly if relevant</remarks> /// ------------------------------------------------------------------------------------ public static void VerifySubDiffFootnote(Difference rootDiff, int iSubDiff, DifferenceType subDiffType, StFootnote footnoteCurr, int ichMinCurr, int ichLimCurr, StFootnote footnoteRev, int ichMinRev, int ichLimRev) { Difference subDiff = rootDiff.SubDiffsForORCs[iSubDiff]; // the Current para stuff Assert.AreEqual((footnoteCurr != null) ? footnoteCurr.ParagraphsOS[0].Hvo : 0, subDiff.HvoCurr); Assert.AreEqual(ichMinCurr, subDiff.IchMinCurr); Assert.AreEqual(ichLimCurr, subDiff.IchLimCurr); // the Revision para stuff Assert.AreEqual((footnoteRev != null) ? footnoteRev.ParagraphsOS[0].Hvo : 0, subDiff.HvoRev); Assert.AreEqual(ichMinRev, subDiff.IchMinRev); Assert.AreEqual(ichLimRev, subDiff.IchLimRev); // section stuff should be null Assert.IsNull(subDiff.HvosSectionsRev); Assert.IsNull(subDiff.HvosSectionsCurr); // subDiffs may not have subDiffs, so far Assert.IsNull(subDiff.SubDiffsForORCs); Assert.IsNull(subDiff.SubDiffsForParas); Assert.AreEqual(subDiffType, subDiff.DiffType); }
/// <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 (IsDisposed) { return; } if (disposing) { // Dispose managed resources here. } // Dispose unmanaged resources here, whether disposing is true or false. m_footnote = null;; m_book = null; if (m_strFact != null) { Marshal.ReleaseComObject(m_strFact); } m_strFact = null;; base.Dispose(disposing); }
public void ExportFootnote_Missing() { CheckDisposed(); 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! m_scrInMemoryCache.AddRunToMockedPara(m_para, "My text for footnotes", string.Empty); StFootnote testFootnote = m_scrInMemoryCache.AddFootnote(m_book, m_para, m_para.Contents.UnderlyingTsString.Length); // Set the GUID to an object that does not exist (Guid.Empty). testFootnote.Guid = new Guid("400BF7E7-B61A-4112-AFFD-188B505F177D"); 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 (StreamReader file = new StreamReader(m_fileName, Encoding.ASCII)) { string line = file.ReadLine(); // the line is the paragraph without the footnote marker. Assert.AreEqual(@"\pard\plain\s2\f2\fs20{My text for footnotes}", line); } }
/// ------------------------------------------------------------------------------------- /// <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) { return; } if (e != CheckingError.Empty) { EditingHelper.EditedRootBox.DestroySelection(); StTxtPara para = e.BeginObjectRA as StTxtPara; if (para != null && para.Owner is StFootnote) { // Checking error is for text in a footnote. Make sure the footnote pane is open. StFootnote footnote = para.Owner as StFootnote; ((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); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// A helper method for book merger tests- /// Verifies the contents of the given difference /// for a one-sided subDiff representing a footnote in the Revision. /// </summary> /// ------------------------------------------------------------------------------------ public static void VerifySubDiffFootnoteRev(Difference rootDiff, int iSubDiff, StFootnote footnoteRev) { Difference subDiff = rootDiff.SubDiffsForORCs[iSubDiff]; // verify the basics Assert.AreEqual(0, subDiff.RefStart); Assert.AreEqual(0, subDiff.RefEnd); Assert.AreEqual(DifferenceType.NoDifference, subDiff.DiffType); // the Current para stuff Assert.AreEqual(0, subDiff.HvoCurr); Assert.AreEqual(0, subDiff.IchMinCurr); Assert.AreEqual(0, subDiff.IchLimCurr); // the Revision para stuff Assert.AreEqual(((StTxtPara)footnoteRev.ParagraphsOS[0]).Hvo, subDiff.HvoRev); Assert.AreEqual(0, subDiff.IchMinRev); Assert.AreEqual(((StTxtPara)footnoteRev.ParagraphsOS[0]).Contents.Length, subDiff.IchLimRev); // style names should be null Assert.IsNull(subDiff.StyleNameCurr); Assert.IsNull(subDiff.StyleNameRev); // section stuff should be null Assert.IsNull(subDiff.HvosSectionsRev); Assert.IsNull(subDiff.HvosSectionsCurr); // subDiffs may not have subDiffs, so far Assert.IsNull(subDiff.SubDiffsForORCs); //check the root difference for consistency with this subDiff Assert.IsTrue(rootDiff.DiffType == DifferenceType.TextDifference || rootDiff.DiffType == DifferenceType.FootnoteMissingInCurrent); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Loads the footnotes. /// </summary> /// <param name="footnoteHvo">The footnote hvo.</param> /// ------------------------------------------------------------------------------------ private void LoadFootnotes(int footnoteHvo) { Debug.Assert(m_cache.GetClassOfObject(footnoteHvo) == StFootnote.kClassId); StFootnote foot = new StFootnote(m_cache, footnoteHvo); IScrBook book = new ScrBook(m_cache, foot.OwnerHVO); int footnoteCount = GetBookFootnoteCount(book.Hvo); FdoOwningSequence <IStFootnote> footnotes = book.FootnotesOS; // If the information we want is already in the cache, then do nothing if (footnotes.Count == footnoteCount && m_htFootnoteIndex.ContainsKey(footnoteHvo)) { return; } ScrFootnote footnote = null; int index = 0; for (int i = 0; i < footnotes.Count; i++) { footnote = new ScrFootnote(m_cache, footnotes.HvoArray[i]); if (footnote.FootnoteType == FootnoteMarkerTypes.AutoFootnoteMarker) { int oldIndex = GetFootnoteIndex(footnote.Hvo); if (oldIndex != index) { m_htFootnoteIndex[footnote.Hvo] = new FootnoteIndexCacheInfo(index, true); } index++; } } m_htBookFootnoteCount[book.Hvo] = footnotes.Count; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Helper method to set up the test paragraph in m_archivedText, including footnotes /// and back translations, plus any other fields deemed necessary. /// </summary> /// ------------------------------------------------------------------------------------ private StTxtPara SetUpParagraphInArchiveWithFootnotesAndBT() { // Prepare the Revision paragraph in m_archivedText // note: CreateTestData has already placed "11This is the previous version of the text." // in paragraph in m_archivedText. StTxtPara paraRev = (StTxtPara)m_archivedText.ParagraphsOS[0]; paraRev.StyleRules = StyleUtils.ParaStyleTextProps("Line 1"); // add footnotes to existing paragraph. StFootnote footnote1 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, paraRev, 6, "Footnote1"); StFootnote footnote2 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, paraRev, 10, "Footnote2"); Assert.AreEqual(2, m_archivedFootnotesOS.Count); // Add two back translations of the para and footnotes int[] wsBt = new int[] { InMemoryFdoCache.s_wsHvos.En, InMemoryFdoCache.s_wsHvos.De }; foreach (int ws in wsBt) { // add back translation of the para, and status ICmTranslation paraTrans = m_inMemoryCache.AddBtToMockedParagraph(paraRev, ws); m_inMemoryCache.AddRunToMockedTrans(paraTrans, ws, "BT of test paragraph" + ws.ToString(), null); paraTrans.Status.SetAlternative(BackTranslationStatus.Finished.ToString(), ws); // add BT footnotes, and status ICmTranslation footnoteTrans = m_inMemoryCache.AddFootnoteORCtoTrans(paraTrans, 2, ws, footnote1, "BT of footnote1 " + ws.ToString()); footnoteTrans.Status.SetAlternative(BackTranslationStatus.Checked.ToString(), ws); footnoteTrans = m_inMemoryCache.AddFootnoteORCtoTrans(paraTrans, 6, ws, footnote2, "BT of footnote2 " + ws.ToString()); footnoteTrans.Status.SetAlternative(BackTranslationStatus.Finished.ToString(), ws); } return(paraRev); }
public void CreateFromStringRep_twoCharStylePara() { CheckDisposed(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_vernWs); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Emphasis"); ITsStrBldr bldr = TsStrBldrClass.Create(); 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.UnderlyingTsString = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><ShowMarker/><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>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void UpdateAllFootnotesWhenValuesChangeInScripture() { CheckDisposed(); ScrBook james = (ScrBook)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++) { StFootnote fNote = (StFootnote)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++) { StFootnote fNote = (StFootnote)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> /// 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(StFootnote 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> /// Create test data in a right-to-left script. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { // Set the default writing system to a right-to-left writing system (Urdu) m_wsUrdu = InMemoryFdoCache.s_wsHvos.Ur; m_scrInMemoryCache.ChangeDefaultVernWs(m_wsUrdu); LgWritingSystem defWs = new LgWritingSystem(Cache, Cache.DefaultVernWs); // Add basic data for Genesis m_genesis = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_scrInMemoryCache.AddTitleToMockedBook(1, m_StartText); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, null); m_scrInMemoryCache.AddFormatTextToMockedPara(m_genesis, para, @"\c12\v13-14\*" + m_WordsText, m_wsUrdu); section.AdjustReferences(); // Add footnote ITsTextProps normalFootnoteParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); StFootnote footnote = m_scrInMemoryCache.AddFootnote(m_genesis, para, 10); StTxtPara footPara = new StTxtPara(); footnote.ParagraphsOS.Append(footPara); footPara.StyleRules = normalFootnoteParaProps; ITsStrFactory strfact = TsStrFactoryClass.Create(); footPara.Contents.UnderlyingTsString = strfact.MakeString(m_WordsText, m_wsUrdu); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares the given footnote with the values in m_footnote. /// </summary> /// <param name="footnote">The footnote to compare</param> /// ------------------------------------------------------------------------------------ private void CompareFootnote(StFootnote footnote) { Assert.AreEqual(m_footnote.DisplayFootnoteMarker, footnote.DisplayFootnoteMarker, "Display footnote marker values did not match"); Assert.AreEqual(m_footnote.DisplayFootnoteReference, footnote.DisplayFootnoteReference, "Display footnote reference values did not match"); Assert.AreEqual(m_footnote.FootnoteMarker.Text, footnote.FootnoteMarker.Text); 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++) { StTxtPara expectedPara = (StTxtPara)m_footnote.ParagraphsOS[i]; StTxtPara actualPara = (StTxtPara)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.UnderlyingTsString, actualPara.Contents.UnderlyingTsString, out diff); Assert.IsTrue(result, "paragraph " + i + " differed in: " + diff); CompareFootnoteTrans((CmTranslation)expectedPara.GetBT(), (CmTranslation)actualPara.GetBT(), actualPara.Hvo); } }
public void PageElementsDontOverlap_TwoFootnotes() { IScripture scr = Cache.LangProject.TranslatedScriptureOA; ScrBook genesis = (ScrBook)scr.ScriptureBooksOS[0]; // Add a footnote in the first book, first section, first paragraph IScrSection section = (IScrSection)genesis.SectionsOS[0]; StFootnote footnote = m_scrInMemoryCache.AddFootnote(genesis, (StTxtPara)section.ContentOA.ParagraphsOS[0], 2); StTxtPara para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, ScrStyleNames.NormalFootnoteParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "Another footnote", 0); // Add a footnote in the first book, last section, 6th paragraph section = (IScrSection)genesis.SectionsOS[genesis.SectionsOS.Count - 1]; footnote = m_scrInMemoryCache.AddFootnote(genesis, (StTxtPara)section.ContentOA.ParagraphsOS[5], 10); para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, ScrStyleNames.NormalFootnoteParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "This is the footnote", 0); 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); }
public void GetFootnoteMarkerFromGuid() { StFootnote footnote = new StFootnote(); m_scr.ScriptureBooksOS[0].FootnotesOS.Append(footnote); footnote.FootnoteMarker.Text = "a"; Guid guid = m_fdoCache.GetGuidFromId(footnote.Hvo); // Add the guid property so we can get it out as a string. ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); byte[] objData = MiscUtils.GetObjData(guid, 1); propsBldr.SetStrPropValueRgch(1, objData, objData.Length); // Get the guid property as a string. string sObjData; propsBldr.GetStrPropValue(1, out sObjData); using (StVc vc = new StVc()) { vc.Cache = m_fdoCache; vc.DefaultWs = m_fdoCache.LanguageWritingSystemFactoryAccessor.UserWs; ITsString footnoteMarker = vc.GetStrForGuid(sObjData.Substring(1)); Assert.AreEqual("2", footnoteMarker.Text); } }
/// ------------------------------------------------------------------------------------ /// <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(StFootnote footnote, bool fPutInsertionPtAtEnd) { CheckDisposed(); //toggle 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; } finally { ((IRootSite)this).AllowPainting = true; } if (fShow && FootnoteView != null) { if (footnote != null) { FootnoteView.ScrollToFootnote(footnote, fPutInsertionPtAtEnd); } FootnoteView.Focus(); } }
public void DeleteFootnoteMarkerInBt_ContextMenu() { CheckDisposed(); IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus"); m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Exodus"); m_btDraftView.BookFilter.Insert(0, book.Hvo); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph StTxtPara parentPara = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "uno ", null); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "2", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "dos ", null); StFootnote footnote1 = m_scrInMemoryCache.AddFootnote(book, parentPara, 5); m_scrInMemoryCache.AddParaToMockedText(footnote1.Hvo, ScrStyleNames.NormalFootnoteParagraph); StFootnote footnote2 = m_scrInMemoryCache.AddFootnote(book, parentPara, 10); m_scrInMemoryCache.AddParaToMockedText(footnote2.Hvo, ScrStyleNames.NormalFootnoteParagraph); Guid guid1 = footnote1.Guid; Guid guid2 = footnote2.Guid; Assert.AreEqual(2, book.FootnotesOS.Count); section.AdjustReferences(); // Construct the initial back translation int wsBt = m_inMemoryCache.Cache.DefaultAnalWs; ICmTranslation trans = m_inMemoryCache.AddBtToMockedParagraph(parentPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(trans, wsBt, "one two", null); ITsStrBldr btTssBldr = trans.Translation.GetAlternative(wsBt).UnderlyingTsString.GetBldr(); footnote1.InsertRefORCIntoTrans(btTssBldr, 3, wsBt); footnote2.InsertRefORCIntoTrans(btTssBldr, 8, wsBt); trans.Translation.SetAlternative(btTssBldr.GetString(), wsBt); SelectionHelper selHelper = m_btDraftView.SetInsertionPoint(0, 0, 0, 3, false); //set the IP // Delete the marker for the back translation of the first footnote m_btDraftView.OnDeleteFootnote(); // 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.GetAlternative(wsBt).UnderlyingTsString.Text); StTxtParaTests.VerifyBtFootnote(footnote2, parentPara, wsBt, 7); }
public void CreateFromStringRep_ExcptnUnknownElement() { // Define text representation and create a footnote from it. string footnoteRep = @"<FN><BLAH>o</BLAH>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); }
/// ------------------------------------------------------------------------------------ /// <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(StFootnote footnote, StTxtPara para, int ws, int ichPos) { ICmTranslation trans = para.GetOrCreateBT(); ITsStrBldr bldr = trans.Translation.GetAlternative(ws).UnderlyingTsString.GetBldr(); footnote.InsertRefORCIntoTrans(bldr, ichPos, ws); trans.Translation.SetAlternative(bldr.GetString(), ws); }
public void CreateFromStringRep_ExcptnWSWithoutValue() { // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN WS=>Run has a writing system attribute but no value.</RUN></P></FN>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); }
public void CreateFromStringRep_ExcptnInvalidICU() { // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN WS='AINT_IT' CS='Emphasis'>Test Text</RUN></P></FN>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); }
public void CreateFromStringRep_ExcptnWSMissingFromRunElement() { // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN>Run without a writing system.</RUN></P></FN>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); }
public void CreateFromStringRep_ExcptnUnknownTRANS_Element() { // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><ShowMarker/><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>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); }
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"); }
public void IPAtBeginningOfPara_FootnoteInMiddleOfPara() { CheckDisposed(); m_scrInMemoryCache.AddFootnote(m_philemon, m_para, 7); m_editingHelper.SetupSelectionInPara(m_para, 0, m_section, 0, m_philemon, 0, 0, false); StFootnote footnote = m_editingHelper.FindFootnoteNearSelection(null); Assert.IsNotNull(footnote, "should find a footnote."); }
public void PagesWithFootnotes() { CheckDisposed(); // Need VC with footnotes for this test, so we recreate one ConfigurePublication(true); // Add a footnote in the last book, last section, last paragraph IScripture scr = Cache.LangProject.TranslatedScriptureOA; ScrBook deut = (ScrBook)scr.ScriptureBooksOS[scr.ScriptureBooksOS.Count - 1]; IScrSection section = (IScrSection)deut.SectionsOS[deut.SectionsOS.Count - 1]; StFootnote footnote = m_scrInMemoryCache.AddFootnote(deut, (StTxtPara)section.ContentOA.ParagraphsOS[section.ContentOA.ParagraphsOS.Count - 1], 10); StTxtPara para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, ScrStyleNames.NormalFootnoteParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "This is the footnote", 0); // Set up the publication m_pub.PageHeight = 72000 * 11; // 11 inches m_pub.PageWidth = (int)(72000 * 8.5); // 8.5 inches m_division.TopMargin = 36000; // Half inch m_division.BottomMargin = 18000; // Quarter inch m_division.InsideMargin = 9000; // 1/8 inch m_division.OutsideMargin = 4500; // 1/16 inch DummyMainLazyViewVc vc = m_division.MainVc as DummyMainLazyViewVc; vc.m_estBookHeight = 2000; vc.m_estSectionHeight = 2000; m_pub.Width = 3 * 96; // represents a window that is 3" wide at 96 DPI m_pub.CreatePages(); Assert.AreEqual(14, m_pub.Pages.Count, "Our estimate of book should try to fit all of Scripture on 14 pages."); // expand the last page m_pub.ScrollPosition = new Point(-m_pub.ScrollPosition.X, m_pub.AutoScrollMinSize.Height - 10); m_pub.PrepareToDrawPages(0, 100); // now expand all of the pages m_pub.ScrollPosition = new Point(0, 0); m_pub.PrepareToDrawPages(0, m_pub.AutoScrollMinSize.Height * 2); Page lastPage = (Page)m_pub.Pages[m_pub.Pages.Count - 1]; PageElement peMain = lastPage.GetFirstElementForStream(m_division.MainLayoutStream); Assert.IsTrue(m_division.m_testPageFootnoteInfo.ContainsKey(lastPage.Handle)); Assert.AreEqual(2, lastPage.PageElements.Count, "Main and footnote streams should be laid out on page " + lastPage.PageNumber); int cFoonotesOnThisPage = (int)m_division.m_testPageFootnoteInfo[lastPage.Handle]; Assert.Greater(cFoonotesOnThisPage, 0, "Should display at least one footnote on last page"); }