/// <summary> /// non-undoable task /// </summary> private void DoSetupFixture() { var textFactory = Cache.ServiceLocator.GetInstance<ITextFactory>(); var stTextFactory = Cache.ServiceLocator.GetInstance<IStTextFactory>(); m_text = textFactory.Create(); //Cache.LangProject.TextsOC.Add(m_text); m_stText = stTextFactory.Create(); m_text.ContentsOA = m_stText; m_para0 = m_stText.AddNewTextPara(null); m_para0.Contents = TsStringUtils.MakeTss("Xxxhope xxxthis xxxwill xxxdo. xxxI xxxhope.", Cache.DefaultVernWs); m_para1 = m_stText.AddNewTextPara(null); m_para1.Contents = TsStringUtils.MakeTss("Xxxcertain xxxto xxxcatch xxxa xxxfrog. xxxCertainly xxxcan. xxxOn xxxLake xxxMonroe.", Cache.DefaultVernWs); m_para2 = null; using (ParagraphParser pp = new ParagraphParser(Cache)) foreach (IStTxtPara para in m_stText.ParagraphsOS) pp.Parse(para); m_expectedAnOcs = new List<AnalysisOccurrence>(); foreach (IStTxtPara para in m_stText.ParagraphsOS) foreach (ISegment seg in para.SegmentsOS) for (int i = 0; i < seg.AnalysesRS.Count; i++) m_expectedAnOcs.Add(new AnalysisOccurrence(seg, i)); m_expectedAnOcsPara0 = new List<AnalysisOccurrence>(); foreach (ISegment seg in m_para0.SegmentsOS) for (int i = 0; i < seg.AnalysesRS.Count; i++) m_expectedAnOcsPara0.Add(new AnalysisOccurrence(seg, i)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="XmlNotePara"/> class based on the given /// StTxtPara. /// </summary> /// <param name="stTxtPara">The FDO paragraph.</param> /// <param name="wsDefault">The default (analysis) writing system.</param> /// <param name="lgwsf">The writing system factory.</param> /// ------------------------------------------------------------------------------------ public XmlNotePara(IStTxtPara stTxtPara, int wsDefault, ILgWritingSystemFactory lgwsf) { // REVIEW: Ask TomB about this. The only paragraph style allowed in // TE for notes is "Remark" so is it necessary to write it to the XML? // It causes a problem for the OXES validator. //StyleName = stTxtPara.StyleName; ITsString tssParaContents = stTxtPara.Contents; if (tssParaContents.RunCount == 0) return; int dummy; int wsFirstRun = tssParaContents.get_Properties(0).GetIntPropValues( (int)FwTextPropType.ktptWs, out dummy); //if (wsFirstRun != wsDefault) IcuLocale = lgwsf.GetStrFromWs(wsFirstRun); for (int iRun = 0; iRun < tssParaContents.RunCount; iRun++) { ITsTextProps props = tssParaContents.get_Properties(iRun); string text = tssParaContents.get_RunText(iRun); if (TsStringUtils.IsHyperlink(props)) Runs.Add(new XmlHyperlinkRun(wsFirstRun, lgwsf, text, props)); else Runs.Add(new XmlTextRun(wsFirstRun, lgwsf, text, props)); } }
public override void Initialize() { CheckDisposed(); base.Initialize(); //m_inMemoryCache.InitializeAnnotationDefs(); InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml", new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" }); m_wsVern = Cache.DefaultVernWs; m_wsTrans = Cache.DefaultAnalWs; m_text = new Text(); Cache.LangProject.TextsOC.Add(m_text); m_para = new StTxtPara(); StText text = new StText(); m_text.ContentsOA = text; text.ParagraphsOS.Append(m_para); m_trans = new CmTranslation(); m_para.TranslationsOC.Add(m_trans); kflidFT = StTxtPara.SegmentFreeTranslationFlid(Cache); kflidSegments = StTxtPara.SegmentsFlid(Cache); m_btPoss = Cache.LangProject.TranslationTagsOA.LookupPossibilityByGuid( LangProject.kguidTranBackTranslation); m_trans.TypeRA = m_btPoss; m_fWasUseScriptDigits = Cache.LangProject.TranslatedScriptureOA.UseScriptDigits; Cache.LangProject.TranslatedScriptureOA.UseScriptDigits = false; // do we need to set status? }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create minimal test data required for every test. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { base.CreateTestData(); m_helper = new DiscourseTestHelper(Cache); m_firstPara = m_helper.FirstPara; m_stText = m_firstPara.Owner as IStText; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Override to end the undoable UOW, Undo everything, and 'commit', /// which will essentially clear out the Redo stack. /// </summary> /// ------------------------------------------------------------------------------------ public override void TestTearDown() { m_philemon = null; m_section = null; m_para = null; base.TestTearDown(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make one for converting the specified paragraph. /// </summary> /// <param name="para">The paragraph.</param> /// <param name="wsBt">The writing system for which to do the conversion.</param> /// ------------------------------------------------------------------------------------ private BtConverter(IStTxtPara para, int wsBt) { m_para = para; m_cache = para.Cache; m_cpe = m_cache.ServiceLocator.UnicodeCharProps; m_scr = para.Cache.LangProject.TranslatedScriptureOA; m_wsBt = wsBt; }
/// <summary> /// Make an LfParagraph object from an FDO StTxtPara. /// </summary> /// <returns>The LFParagraph.</returns> /// <param name="fdoPara">FDO StTxtPara object to convert.</param> public static LfParagraph FdoParaToLfPara(IStTxtPara fdoPara, ILgWritingSystemFactory wsf) { var lfPara = new LfParagraph(); lfPara.Guid = fdoPara.Guid; lfPara.StyleName = fdoPara.StyleName; lfPara.Content = ConvertFdoToMongoTsStrings.TextFromTsString(fdoPara.Contents, wsf); return lfPara; }
/// <summary> /// Make one for converting the specified paragraph. /// </summary> /// <param name="para"></param> public BtConverter(IStTxtPara para) { m_para = para; m_cache = para.Cache; kflidFT = StTxtPara.SegmentFreeTranslationFlid(m_cache); kflidSegments = StTxtPara.SegmentsFlid(m_cache); m_cpe = m_cache.LanguageWritingSystemFactoryAccessor.UnicodeCharProps; m_scr = para.Cache.LangProject.TranslatedScriptureOA; }
private void FixtureSetupInternal() { // Setup default analysis ws m_wsEn = Cache.ServiceLocator.WritingSystemManager.Get("en").Handle; m_text = Cache.ServiceLocator.GetInstance<ITextFactory>().Create(); //Cache.LangProject.TextsOC.Add(m_text); Cache.LangProject.TranslatedScriptureOA = Cache.ServiceLocator.GetInstance<IScriptureFactory>().Create(); m_para = Cache.ServiceLocator.GetInstance<IStTxtParaFactory>().Create(); IStText text = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create(); m_text.ContentsOA = text; text.ParagraphsOS.Add(m_para); }
/// <summary> /// /// </summary> public override void TestSetup() { base.TestSetup(); m_wsVern = Cache.DefaultVernWs; m_wsTrans = Cache.DefaultAnalWs; m_book = Cache.ServiceLocator.GetInstance<IScrBookFactory>().Create(1); m_section = Cache.ServiceLocator.GetInstance<IScrSectionFactory>().Create(); m_book.SectionsOS.Add(m_section); m_section.ContentOA = m_text = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create(); ; m_para = m_text.AddNewTextPara(ScrStyleNames.NormalParagraph); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Override to start an undoable UOW. /// </summary> /// ------------------------------------------------------------------------------------ public override void TestSetup() { base.TestSetup(); m_editingHelper.m_fUsingMockedSelection = true; m_philemon = AddBookToMockedScripture(57, "Philemon"); AddTitleToMockedBook(m_philemon, "Philemon"); m_section = AddSectionToMockedBook(m_philemon); m_para = AddParaToMockedSectionContent(m_section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(m_para, "this is text", null); }
public void GotoVerse_ExactWhenClosestFirst() { // section1: 1, 2, 10 // section2: 3, 4, 5 // ip at beginning of section1 // goto verse 4 IScrSection section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse one", null); AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse two", null); AddRunToMockedPara(para, "10", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse ten", null); section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "3", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse three", null); AddRunToMockedPara(para, "4", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse four", null); AddRunToMockedPara(para, "5", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse five", null); m_draftView.RootBox.Reconstruct(); // update the view // Set the selection to the start of the section m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 0, false); // Attempt to go to Exodus 1:4 (should exist) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 4, m_scr.Versification))); // Make sure selection is at verse 4 in second section IVwSelection vwsel = m_draftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss2; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("4", tss2.Text.Substring(ich - 1, 1)); Assert.IsFalse(fAssocPrev); }
public void GotoVerse_BetweenSectionsToMinVerse() { // section1: 1, 3 // section2: 21, 20, 22 // ip at beginning of section1 // goto verse 19 IScrSection section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse one", null); AddRunToMockedPara(para, "3", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse three", null); section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "21", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse twenty-one", null); AddRunToMockedPara(para, "20", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse twenty", null); AddRunToMockedPara(para, "22", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse twenty-two", null); m_draftView.RootBox.Reconstruct(); // update the view // Set the selection to the start of the section m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 0, false); // Attempt to go to Exodus 1:19 (should not exist) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 19, m_scr.Versification))); // Make sure selection is between verse number 3 and it's verse text. IVwSelection vwsel = m_draftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss2; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("3", tss2.Text.Substring(ich - 1, 1)); Assert.AreEqual("verse three", tss2.Text.Substring(ich, 11)); Assert.IsFalse(fAssocPrev); }
public void Insert_UnownableObject() { IFdoServiceLocator servLoc = Cache.ServiceLocator; IScrBookFactory bookFact = servLoc.GetInstance <IScrBookFactory>(); // Setup the source sequence using the scripture books sequence. IStText text; IScrBook book0 = bookFact.Create(1, out text); IStTxtPara para = text.AddNewTextPara(ScrStyleNames.MainBookTitle); IScrRefSystem systemToAdd = servLoc.GetInstance <IScrRefSystemRepository>().Singleton; para.AnalyzedTextObjectsOS.Insert(0, systemToAdd); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize the text for the paragraph with the specified builder, or create an /// empty paragraph if the builder is null. /// </summary> /// <param name="bldr">paragraph builder</param> /// <param name="text">StText</param> /// ------------------------------------------------------------------------------------ private void InitializeText(StTxtParaBldr bldr, IStText text) { if (bldr == null) { IStTxtPara para = (StTxtPara)text.ParagraphsOS.Append(new StTxtPara()); para.Contents.UnderlyingTsString = StringUtils.MakeTss(String.Empty, Cache.DefaultAnalWs); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark); } else { bldr.CreateParagraph(text.Hvo); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Expose the ExportParagraph method for testing /// </summary> /// <param name="para"></param> /// ------------------------------------------------------------------------------------ public void ExportParagraph(IStTxtPara para) { CheckDisposed(); InitializeStateVariables(); CreateStyleTables(); CreateAnnotationList(m_currentBookOrd); m_currentParaIsHeading = false; IScrBook owningBook = (m_bookFilter != null) ? m_bookFilter.GetBookByOrd(m_currentBookOrd) : m_scr.FindBook(m_currentBookOrd); ExportParagraph(para, owningBook); }
/// ------------------------------------------------------------------------------------ /// <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> /// Ensure that the segments property of the paragraph is consistent with its contents and consists of real /// database objects. /// </summary> internal static FdoCache EnsureMainParaSegments(IStTxtPara para, int wsBt) { ParagraphParser pp = new ParagraphParser(para); List <int> EosOffsets; List <int> segs = pp.CollectSegmentAnnotationsOfPara(out EosOffsets); // Make sure the segments list is up to date. FdoCache cache = para.Cache; cache.VwCacheDaAccessor.CacheVecProp(para.Hvo, StTxtPara.SegmentsFlid(cache), segs.ToArray(), segs.Count); // This further makes sure all are real. StTxtPara.LoadSegmentFreeTranslations(new int[] { para.Hvo }, cache, wsBt); return(cache); }
private void FixtureSetupInternal() { // Setup default analysis ws m_wsEn = Cache.ServiceLocator.WritingSystemManager.Get("en").Handle; m_text = Cache.ServiceLocator.GetInstance <ITextFactory>().Create(); //Cache.LangProject.TextsOC.Add(m_text); Cache.LangProject.TranslatedScriptureOA = Cache.ServiceLocator.GetInstance <IScriptureFactory>().Create(); m_para = Cache.ServiceLocator.GetInstance <IStTxtParaFactory>().Create(); IStText text = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create(); m_text.ContentsOA = text; text.ParagraphsOS.Add(m_para); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create test data for tests. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_servloc = Cache.ServiceLocator; m_text = AddInterlinearTextToLangProj("My Interlinear Text"); m_stTextPara = AddParaToInterlinearTextContents(m_text, "Here is a sentence I can chart."); m_stText = m_text.ContentsOA; m_rowFact = m_servloc.GetInstance <IConstChartRowFactory>(); m_wordGrpFact = m_servloc.GetInstance <IConstChartWordGroupFactory>(); m_possFact = m_servloc.GetInstance <ICmPossibilityFactory>(); m_wfiFact = m_servloc.GetInstance <IWfiWordformFactory>(); m_mtMrkrFact = m_servloc.GetInstance <IConstChartMovedTextMarkerFactory>(); m_clsMrkrFact = m_servloc.GetInstance <IConstChartClauseMarkerFactory>(); }
public void GetFootnoteOwnerAndFlid() { CheckDisposed(); IStTxtPara para = (IStTxtPara)m_currentText.ParagraphsOS[0]; ICmObject owner; int flid; Assert.IsTrue(para.GetFootnoteOwnerAndFlid(out owner, out flid)); Assert.AreEqual(m_currentText.Hvo, owner.Hvo); Assert.AreEqual( Cache.MetaDataCacheAccessor.GetFieldId("StText", "DummyFootnotesOS", false), flid); }
public void PagesWithFootnotes() { // 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; IScrBook deut = scr.ScriptureBooksOS[scr.ScriptureBooksOS.Count - 1]; IScrSection section = deut.SectionsOS[deut.SectionsOS.Count - 1]; IStFootnote footnote = AddFootnote(deut, (IStTxtPara)section.ContentOA.ParagraphsOS[section.ContentOA.ParagraphsOS.Count - 1], 10); IStTxtPara para = AddParaToMockedText(footnote, ScrStyleNames.NormalFootnoteParagraph); AddRunToMockedPara(para, "This is the footnote", para.Cache.DefaultVernWs); // 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]; 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"); }
/// <summary> /// Returns hvo of the CmBaseAnnotation corresponding to the given bookmark location in the text. /// </summary> /// <param name="bookmark"></param> /// <param name="fOnlyTWFIC">If true, we only search in TWFIC annotations, otherwise we /// search for a match in TextSegments also.</param> /// <returns></returns> static public int AnnotationHvo(FdoCache cache, IStText stText, InterAreaBookmark bookmark, bool fOnlyTWFIC) { if (bookmark.IndexOfParagraph < 0 || stText == null || bookmark.IndexOfParagraph >= stText.ParagraphsOS.Count) { return(0); } IStTxtPara para = stText.ParagraphsOS[bookmark.IndexOfParagraph] as IStTxtPara; bool fExactMatch = false; int hvoAnn = FindAnnotationHvoForStTxtPara(cache, para.Hvo, bookmark.BeginCharOffset, bookmark.EndCharOffset, fOnlyTWFIC, out fExactMatch); return(hvoAnn); }
private static AnalysisOccurrence[] GetParaAnalyses(IStTxtPara para) { var result = new List<AnalysisOccurrence>(); var point1 = new AnalysisOccurrence(para.SegmentsOS[0], 0); if (!point1.IsValid) return result.ToArray(); do { if (point1.HasWordform) result.Add(point1); point1 = point1.NextWordform(); } while (point1 != null && point1.IsValid); return result.ToArray(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create test data for tests. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_servloc = Cache.ServiceLocator; m_text = AddInterlinearTextToLangProj("My Interlinear Text"); m_stTextPara = AddParaToInterlinearTextContents(m_text, "Here is a sentence I can chart."); m_stText = m_text.ContentsOA; m_tssFact = Cache.TsStrFactory; m_rowFact = m_servloc.GetInstance<IConstChartRowFactory>(); m_wordGrpFact = m_servloc.GetInstance<IConstChartWordGroupFactory>(); m_possFact = m_servloc.GetInstance<ICmPossibilityFactory>(); m_wfiFact = m_servloc.GetInstance<IWfiWordformFactory>(); m_mtMrkrFact = m_servloc.GetInstance<IConstChartMovedTextMarkerFactory>(); m_clsMrkrFact = m_servloc.GetInstance<IConstChartClauseMarkerFactory>(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Override of DisplayVec /// </summary> /// ------------------------------------------------------------------------------------ public override void DisplayVec(IVwEnv vwenv, int paraHvo, int tag, int frag) { CheckDisposed(); if (tag == StTxtParaTags.kflidTranslations && frag == (int)ScrFrags.kfrBtTranslationStatus) { IStTxtPara para = Cache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(paraHvo); vwenv.AddObj(GetTranslationForPara(paraHvo), this, frag); } else { base.DisplayVec(vwenv, paraHvo, tag, frag); } }
// Make a segment and its free translation. Append to or set up the segments property // of the para and set up the FT property of the segment. ICmIndirectAnnotation MakeFt(IStTxtPara para, string text, int beginOffset, int length) { ICmBaseAnnotation seg = MakeSegment(para, beginOffset, length); ICmIndirectAnnotation ft = CmIndirectAnnotation.CreateUnownedIndirectAnnotation(Cache); ft.AppliesToRS.Append(seg); ft.Comment.SetAlternative(text, m_wsTrans); ft.AnnotationTypeRAHvo = m_hvoFtDefn; // Backref links para.Cache.VwCacheDaAccessor.CacheObjProp(seg.Hvo, kflidFT, ft.Hvo); return(ft); }
public void GetVectorSize_on_New_Sequence() { CheckDisposed(); IText itext = m_inMemoryCache.AddInterlinearTextToLangProj("itName", false); IStText text = itext.ContentsOA = new StText(); IStTxtPara newPara = (IStTxtPara)text.ParagraphsOS.Append(new StTxtPara()); int chvoParas = Cache.GetVectorSize(text.Hvo, (int )SIL.FieldWorks.FDO.Cellar.StText.StTextTags.kflidParagraphs); Assert.AreEqual(1, chvoParas); Assert.AreEqual(text.ParagraphsOS.Count, chvoParas); }
public void IPAtBeginningOfSecondPara_FootnoteAlmostAtEndOfFirstPara() { IStTxtPara para = AddParaToMockedSectionContent(m_section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "more text", null); AddFootnote(m_philemon, m_para, m_para.Contents.Length - 1); IStFootnote expectedFootnote = AddFootnote(m_philemon, para, 5); m_editingHelper.SetupSelectionInPara(para, 1, m_section, 0, m_philemon, 0, 0, false); IStFootnote footnote = m_editingHelper.FindFootnoteNearSelection(null); Assert.IsNotNull(footnote, "should find a footnote."); Assert.AreEqual(expectedFootnote.Hvo, footnote.Hvo, "Should find first footnote in para"); }
public override void Initialize() { CheckDisposed(); base.Initialize(); m_inMemoryCache.InitializeAnnotationDefs(); InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml", new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" }); m_text = new Text(); Cache.LangProject.TextsOC.Add(m_text); m_para = new StTxtPara(); StText text = new StText(); m_text.ContentsOA = text; text.ParagraphsOS.Append(m_para); }
public void UserPromptForSectionHeadWithEmptyPara_NoOption() { // Set up section head with an empty paragraph IScrSection section = AddSectionToMockedBook(m_book); IStTxtPara para = AddSectionHeadParaToSection(section, "", ScrStyleNames.SectionHead); Options.ShowEmptyParagraphPromptsSetting = false; DummyTeStVc stVc = new DummyTeStVc(Cache, Cache.DefaultVernWs); bool fTextAdded = stVc.CallInsertUserPrompt(m_vwenvMock, para); Assert.IsFalse(fTextAdded, "User prompt added"); m_vwenvMock.VerifyAllExpectations(); }
public void ParagraphBreak_RemoveCharStyleFromAdjacentWhiteSpace() { m_draftView.RefreshDisplay(); // *** Test setup *** // Insert text with a character style. IStTxtPara para1 = m_exodus.SectionsOS[0].ContentOA[0]; ITsStrBldr tssBldr = para1.Contents.GetBldr(); ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Emphasis"); tssBldr.ReplaceRgch(15, 15, "really, really", 6, ttpBldr.GetTextProps()); int paraCount = m_exodus.SectionsOS[0].ContentOA.ParagraphsOS.Count; // Set the IP in the white space within the inserted text. m_draftView.SetInsertionPoint(0, 0, 0, 23, true); IVwSelection sel0 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel0); // Insert paragraph break m_draftView.OnKeyPress(new KeyPressEventArgs('\r')); Assert.AreEqual(paraCount + 1, m_exodus.SectionsOS[0].ContentOA.ParagraphsOS.Count, "Should have one more paragraph in the intro section"); // We expect that the last run of the first paragraph and first run of the new // paragraph will be a space character with no character style. ITsString tss1 = para1.Contents; Assert.AreEqual(3, tss1.RunCount, "First intro paragraph should have three runs"); Assert.AreEqual("really,", tss1.get_RunText(1)); ITsTextProps ttp = tss1.get_Properties(1); Assert.AreEqual("Emphasis", ttp.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle)); ttp = tss1.get_Properties(2); Assert.AreEqual(" ", tss1.get_RunText(2)); Assert.AreEqual(null, ttp.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle)); ITsString tss2 = m_exodus.SectionsOS[0].ContentOA[1].Contents; Assert.AreEqual(3, tss2.RunCount); Assert.AreEqual(" ", tss2.get_RunText(0)); ttp = tss1.get_Properties(0); Assert.AreEqual(null, ttp.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle)); ttp = tss1.get_Properties(1); Assert.AreEqual("Emphasis", ttp.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle)); Assert.AreEqual("really", tss2.get_RunText(0)); }
public void GetOccurrencesOfAnalysis() { UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor, () => { IStTxtPara para0 = MakeSimpleParsedText(); var seg0 = para0.SegmentsOS[0]; var analysisThe = seg0.AnalysesRS[0] as IWfiWordform; var occurrences = seg0.GetOccurrencesOfAnalysis(analysisThe, 1, true); Assert.AreEqual(analysisThe, occurrences[0].Analysis); Assert.AreEqual(0, occurrences[0].GetMyBeginOffsetInPara()); Assert.AreEqual(0, occurrences[0].Index); Assert.AreEqual(1, occurrences.Count); var seg1 = para0.SegmentsOS[1]; occurrences = seg1.GetOccurrencesOfAnalysis(analysisThe, 2, true); Assert.AreEqual(2, occurrences.Count); Assert.AreEqual(analysisThe, occurrences[0].Analysis); Assert.AreEqual("the book is red. ".Length, occurrences[0].GetMyBeginOffsetInPara()); Assert.AreEqual(0, occurrences[0].Index); Assert.AreEqual(analysisThe, occurrences[1].Analysis); Assert.AreEqual("the book is red. the pages in ".Length, occurrences[1].GetMyBeginOffsetInPara()); Assert.AreEqual(3, occurrences[1].Index); occurrences = seg1.GetOccurrencesOfAnalysis(analysisThe, 4, true); Assert.AreEqual(4, occurrences.Count); Assert.AreEqual(analysisThe, occurrences[0].Analysis); Assert.AreEqual("the book is red. ".Length, occurrences[0].GetMyBeginOffsetInPara()); Assert.AreEqual(0, occurrences[0].Index); Assert.AreEqual(analysisThe, occurrences[1].Analysis); Assert.AreEqual("the book is red. the pages in ".Length, occurrences[1].GetMyBeginOffsetInPara()); Assert.AreEqual(3, occurrences[1].Index); Assert.AreEqual(analysisThe, occurrences[3].Analysis); Assert.AreEqual("the book is red. the pages in the book are the color of ".Length, occurrences[3].GetMyBeginOffsetInPara()); Assert.AreEqual(9, occurrences[3].Index); occurrences = seg1.GetOccurrencesOfAnalysis(analysisThe, 6, true); Assert.AreEqual(4, occurrences.Count); Assert.AreEqual(analysisThe, occurrences[3].Analysis); Assert.AreEqual("the book is red. the pages in the book are the color of ".Length, occurrences[3].GetMyBeginOffsetInPara()); Assert.AreEqual(9, occurrences[3].Index); }); }
/// ------------------------------------------------------------------------------------ /// <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; }
public void ApplyParaStyle() { m_footnoteView.EditingHelper.ApplyStyle(ScrStyleNames.NormalFootnoteParagraph); int tag; int hvoSimple; bool fGotIt = m_footnoteView.GetSelectedFootnote(out tag, out hvoSimple); Assert.IsTrue(fGotIt); Assert.AreEqual(StTextTags.kflidParagraphs, tag); IStFootnote footnote = Cache.ServiceLocator.GetInstance <IStFootnoteRepository>().GetObject(hvoSimple); IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS[0]; Assert.AreEqual(ScrStyleNames.NormalFootnoteParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <remarks>This method is called after each test</remarks> /// ------------------------------------------------------------------------------------ public override void TestTearDown() { m_vc = null; m_section = null; m_para1 = null; m_para2 = null; m_para3 = null; if (Marshal.IsComObject(m_pattern)) { Marshal.ReleaseComObject(m_pattern); } m_pattern = null; base.TestTearDown(); }
public void Insert_UnownableObject() { ILcmServiceLocator servLoc = Cache.ServiceLocator; IScrBookFactory bookFact = servLoc.GetInstance <IScrBookFactory>(); // Setup the source sequence using the scripture books sequence. IStText text; bookFact.Create(1, out text); IStTxtPara para = text.AddNewTextPara(ScrStyleNames.MainBookTitle); IScrRefSystem systemToAdd = servLoc.GetInstance <IScrRefSystemRepository>().Singleton; Assert.That(() => para.AnalyzedTextObjectsOS.Insert(0, systemToAdd), Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("ScrRefSystem can not be owned!")); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a text for testing. /// </summary> /// ------------------------------------------------------------------------------------ private void CreateTestText() { m_txt = m_servLoc.GetInstance<ITextFactory>().Create(); //Cache.LangProject.TextsOC.Add(m_txt); m_stTxt = m_servLoc.GetInstance<IStTextFactory>().Create(); m_txt.ContentsOA = m_stTxt; m_txtPara = m_txt.ContentsOA.AddNewTextPara(null); // 0 1 2 3 4 // 0123456789012345678901234567890123456789012 // This is a test string for CopyObject tests. int hvoVernWs = Cache.DefaultVernWs; m_txtPara.Contents = TsStringUtils.MakeTss("This is a test string for CopyObject tests.", hvoVernWs); }
public void IPAtBeginningOfFirstContentPara_FootnoteAtEndOfHeadPara() { IStTxtPara para = AddSectionHeadParaToSection(m_section, "Section head", ScrStyleNames.SectionHead); // ENHANCE: Once we deal with looking at the previous paragraph accross contexts // we should expect this footnote! AddFootnote(m_philemon, para, para.Contents.Length); IStFootnote expectedFootnote = AddFootnote(m_philemon, m_para, 5); 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."); Assert.AreEqual(expectedFootnote.Hvo, footnote.Hvo, "Should find the footnote from section head"); }
public void NonScriptureText() { IText text = Cache.ServiceLocator.GetInstance <ITextFactory>().Create(); //Cache.LangProject.TextsOC.Add(text); IStText sttext = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create(); text.ContentsOA = sttext; m_para = sttext.AddNewTextPara(null); string paraContents = "Das buch ist rot"; string trans = "The book is red"; m_para.Contents = Cache.TsStrFactory.MakeString(paraContents, m_wsVern); SetFt(m_para, trans, 0); Assert.AreEqual(0, m_para.TranslationsOC.Count, "should not make CmTranslation for non-Scripture"); }
public void MakeAndBreakPhrase() { UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor, () => { //the book is red. the pages in the book are the color of the paper. IStTxtPara para0 = MakeSimpleParsedText(); Assert.AreEqual(5, para0.SegmentsOS[0].AnalysesRS.Count, "check preconditions -- includes final punctuation"); var firstBook = new AnalysisOccurrence(para0.SegmentsOS[0], 1); firstBook.Analysis.Wordform.Form.AnalysisDefaultWritingSystem = TsStringUtils.MakeString( "bookA", Cache.DefaultAnalWs); var firstIs = new AnalysisOccurrence(para0.SegmentsOS[0], 2); firstIs.Analysis.Wordform.Form.AnalysisDefaultWritingSystem = TsStringUtils.MakeString( "isA", Cache.DefaultAnalWs); var bookIs = firstBook.MakePhraseWithNextWord(); Assert.AreEqual(4, para0.SegmentsOS[0].AnalysesRS.Count); Assert.AreEqual("book is", bookIs.BaselineText.Text); Assert.AreEqual("bookA isA", bookIs.Analysis.Wordform.Form.AnalysisDefaultWritingSystem.Text); var firstThe = new AnalysisOccurrence(para0.SegmentsOS[0], 0); Assert.AreEqual(firstThe.BaselineWs, bookIs.BaselineWs); var bookIsRed = bookIs.MakePhraseWithNextWord(); Assert.AreEqual(3, para0.SegmentsOS[0].AnalysesRS.Count); Assert.AreEqual("book is red", bookIsRed.BaselineText.Text); Assert.AreEqual(firstThe.BaselineWs, bookIsRed.BaselineWs); Assert.IsNull(bookIsRed.MakePhraseWithNextWord()); Assert.IsFalse(bookIsRed.CanMakePhraseWithNextWord()); var phraseWf = bookIsRed.Analysis; bookIsRed.BreakPhrase(); Assert.AreEqual(5, para0.SegmentsOS[0].AnalysesRS.Count, "break phrase should have restored all wordforms"); Assert.AreEqual("the", new AnalysisOccurrence(para0.SegmentsOS[0], 0).BaselineText.Text); Assert.AreEqual("book", new AnalysisOccurrence(para0.SegmentsOS[0], 1).BaselineText.Text); Assert.AreEqual("is", new AnalysisOccurrence(para0.SegmentsOS[0], 2).BaselineText.Text); Assert.AreEqual("red", new AnalysisOccurrence(para0.SegmentsOS[0], 3).BaselineText.Text); Assert.AreEqual(".", new AnalysisOccurrence(para0.SegmentsOS[0], 4).BaselineText.Text); Assert.IsFalse(phraseWf.IsValidObject); // This checks that we do NOT delete a broken phrase when there are other references. firstThe.MakePhraseWithNextWord(); var secondTheBook = new AnalysisOccurrence(para0.SegmentsOS[1], 3).MakePhraseWithNextWord(); secondTheBook.BreakPhrase(); Assert.AreEqual("the book", firstThe.BaselineText.Text); Assert.IsTrue(firstThe.Analysis.IsValidObject); }); }
public void NoUserPromptForContentPara() { // Set up empty content paragraph IScrSection section = AddSectionToMockedBook(m_book); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); DummyTeStVc stVc = new DummyTeStVc(Cache, Cache.DefaultVernWs); bool fTextAdded = stVc.CallInsertUserPrompt(m_vwenvMock, para); Assert.IsFalse(fTextAdded, "User prompt was added to empty content para"); m_vwenvMock.AssertWasNotCalled(x => x.NoteDependency(Arg <int[]> .Is.Anything, Arg <int[]> .Is.Anything, Arg <int> .Is.Anything)); m_vwenvMock.AssertWasNotCalled(x => x.AddProp(Arg <int> .Is.Anything, Arg <IVwViewConstructor> .Is.Anything, Arg <int> .Is.Anything)); m_vwenvMock.VerifyAllExpectations(); }
/// <summary> /// Returns an AnalysisOccurrence corresponding to the word /// </summary> /// <param name="para"></param> /// <param name="hvoAnalysisToFind"></param> /// <param name="fAtBeginning">if true, we are finding the first </param> /// <returns></returns> private AnalysisOccurrence FindAnalysisInPara(IStTxtPara para, int hvoAnalysisToFind, bool fAtBeginning) { var paraOccurrences = m_allOccurrences[para]; var max = paraOccurrences.Length - 1; var start = fAtBeginning ? 0 : max; var incr = fAtBeginning ? 1 : -1; for (var i = start; i >= 0 && i <= max; i += incr) { if (paraOccurrences[i].Analysis.Hvo == hvoAnalysisToFind) { return(paraOccurrences[i]); } } return(null); // Failure! }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a text for testing. /// </summary> /// ------------------------------------------------------------------------------------ private void CreateTestText() { m_txt = m_servLoc.GetInstance <ITextFactory>().Create(); //Cache.LangProject.TextsOC.Add(m_txt); m_stTxt = m_servLoc.GetInstance <IStTextFactory>().Create(); m_txt.ContentsOA = m_stTxt; m_txtPara = m_txt.ContentsOA.AddNewTextPara(null); // 0 1 2 3 4 // 0123456789012345678901234567890123456789012 // This is a test string for CopyObject tests. int hvoVernWs = Cache.DefaultVernWs; m_txtPara.Contents = TsStringUtils.MakeString("This is a test string for CopyObject tests.", hvoVernWs); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a text for testing. /// </summary> /// ------------------------------------------------------------------------------------ private void CreateTestText() { m_txt = m_servLoc.GetInstance<ITextFactory>().Create(); //Cache.LangProject.TextsOC.Add(m_txt); m_possTagList = Cache.LangProject.GetDefaultTextTagList(); m_stTxt = m_servLoc.GetInstance<IStTextFactory>().Create(); m_txt.ContentsOA = m_stTxt; m_txtPara = m_txt.ContentsOA.AddNewTextPara(null); // 0 1 2 3 4 5 6 7 8 // This is a test string for ReferenceAdjusterService tests. var hvoVernWs = Cache.DefaultVernWs; m_txtPara.Contents = TsStringUtils.MakeTss("This is a test string for ReferenceAdjusterService tests.", hvoVernWs); ParseText(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates and initializes a footnote. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_vernWs = Cache.DefaultVernWs; // create footnote IFdoServiceLocator servloc = Cache.ServiceLocator; m_footnote = servloc.GetInstance<IScrFootnoteFactory>().Create(); m_book = AddBookToMockedScripture(1, "Genesis"); m_book.FootnotesOS.Add(m_footnote); m_footnote.FootnoteMarker = TsStringUtils.MakeTss("a", m_vernWs); m_scr.DisplaySymbolInFootnote = true; m_scr.DisplayFootnoteReference = false; // create one empty footnote para m_footnotePara = m_footnote.AddNewTextPara(ScrStyleNames.NormalFootnoteParagraph); m_footnotePara.Contents = TsStringUtils.MakeTss(string.Empty, m_vernWs); }
private void FixtureSetupInternal() { //IWritingSystem wsEn = Cache.WritingSystemFactory.get_Engine("en"); // Setup default analysis ws //m_wsEn = Cache.ServiceLocator.GetInstance<ILgWritingSystemRepository>().GetObject(wsEn.WritingSystem); m_wsVern = Cache.DefaultVernWs; m_wsTrans = Cache.DefaultAnalWs; m_text = Cache.ServiceLocator.GetInstance<ITextFactory>().Create(); //Cache.LangProject.TextsOC.Add(m_text); var stText = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create(); m_text.ContentsOA = stText; m_para = Cache.ServiceLocator.GetInstance<IScrTxtParaFactory>().CreateWithStyle(stText, ScrStyleNames.NormalParagraph); m_trans = m_para.GetOrCreateBT(); Cache.LangProject.TranslatedScriptureOA.UseScriptDigits = false; m_tsf = Cache.TsStrFactory; }
public override void Initialize() { CheckDisposed(); base.Initialize(); InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml", new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" }); m_wsVern = Cache.DefaultVernWs; m_wsTrans = Cache.DefaultAnalWs; m_book = new ScrBook(); Cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS.Append(m_book); m_section = new ScrSection(); m_book.SectionsOS.Append(m_section); m_para = new StTxtPara(); m_text = new StText(); m_section.ContentOA = m_text; m_text.ParagraphsOS.Append(m_para); m_hvoSegDefn = CmAnnotationDefn.TextSegment(Cache).Hvo; m_hvoFtDefn = Cache.GetIdFromGuid(new Guid(LangProject.kguidAnnFreeTranslation)); kflidFT = StTxtPara.SegmentFreeTranslationFlid(Cache); kflidSegments = StTxtPara.SegmentsFlid(Cache); }
/// <summary> /// non-undoable task /// </summary> private void DoSetupFixture() { // setup default vernacular ws. IWritingSystem wsXkal = Cache.ServiceLocator.WritingSystemManager.Set("qaa-x-kal"); wsXkal.DefaultFontName = "Times New Roman"; Cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Add(wsXkal); Cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Insert(0, wsXkal); var textFactory = Cache.ServiceLocator.GetInstance<ITextFactory>(); var stTextFactory = Cache.ServiceLocator.GetInstance<IStTextFactory>(); m_text0 = textFactory.Create(); //Cache.LangProject.TextsOC.Add(m_text0); m_stText0 = stTextFactory.Create(); m_text0.ContentsOA = m_stText0; m_para0_0 = m_stText0.AddNewTextPara(null); m_para0_0.Contents = TsStringUtils.MakeTss("Xxxhope xxxthis xxxwill xxxdo. xxxI xxxhope.", wsXkal.Handle); InterlinMaster.LoadParagraphAnnotationsAndGenerateEntryGuessesIfNeeded(m_stText0, false); // paragraph 0_0 simply has wordforms as analyses foreach (var occurence in SegmentServices.GetAnalysisOccurrences(m_para0_0)) if (occurence.HasWordform) m_analysis_para0_0.Add(new AnalysisTree(occurence.Analysis)); }
/// <summary> /// Get the next segment with either a non-null annotation that is configured or /// a non-punctuation analysis. Also skip segments that are Scripture labels (like /// Chapter/Verse/Footnote numbers. /// It tries the next one after the SelectedOccurrence.Segment /// then tries the next paragraph, etc.. /// Use this version if the calling code already has the actual para/seg objects. /// </summary> /// <param name="currentPara"></param> /// <param name="seg"></param> /// <param name="upward">true if moving up and left, false otherwise</param> /// <param name="realAnalysis">the first or last real analysis found in the next segment</param> /// <returns>A segment meeting the criteria or null if not found.</returns> private ISegment GetNextSegment(IStTxtPara currentPara, ISegment seg, bool upward, out AnalysisOccurrence realAnalysis) { ISegment nextSeg = null; realAnalysis = null; var currentText = currentPara.Owner as IStText; Debug.Assert(currentText != null, "Paragraph not owned by a text."); var lines = LineChoices.m_specs as IEnumerable<InterlinLineSpec>; var delta = upward ? -1 : 1; var nextSegIndex = delta + seg.IndexInOwner; do { if (0 <= nextSegIndex && nextSegIndex < currentPara.SegmentsOS.Count) { nextSeg = currentPara.SegmentsOS[nextSegIndex]; nextSegIndex += delta; // increment for next loop in case it doesn't check out } else { // try the first (last) segment in the next (previous) paragraph int nextParaIndex = delta + currentPara.IndexInOwner; nextSeg = null; IStTxtPara nextPara = null; if (0 <= nextParaIndex && nextParaIndex < currentText.ParagraphsOS.Count) { // try to find this paragraph's first (last) segment currentPara = (IStTxtPara)currentText.ParagraphsOS[nextParaIndex]; nextSegIndex = upward ? currentPara.SegmentsOS.Count - 1 : 0; } else { // no more paragraphs in this text break; } } realAnalysis = FindRealAnalysisInSegment(nextSeg, !upward); } while (nextSeg == null || (realAnalysis == null && !HasVisibleTranslationOrNote(nextSeg, lines))); return nextSeg; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create test data for tests. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_text = AddInterlinearTextToLangProj("My Interlinear Text"); m_stTextPara = AddParaToInterlinearTextContents(m_text, "Here is a sentence I can chart."); m_stText = m_text.ContentsOA; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares the translations of the footnote. /// </summary> /// <param name="expectedTrans">The expected translation</param> /// <param name="currentPara">The current footnote paragraph.</param> /// ------------------------------------------------------------------------------------ private void CompareFootnoteTrans(ICmTranslation expectedTrans, IStTxtPara currentPara) { ICmTranslation actualTrans = currentPara.GetBT(); if (expectedTrans == null) { Assert.IsNull(actualTrans, "Found an unexpected translation for footnote paragraph " + currentPara.IndexInOwner + " having text: " + currentPara.Contents.Text); return; } Assert.IsNotNull(actualTrans, "Translation missing for paragraph " + currentPara.IndexInOwner + " having text: " + currentPara.Contents.Text); foreach (int ws in actualTrans.Translation.AvailableWritingSystemIds) { ITsString tssExpected = expectedTrans.Translation.get_String(ws); ITsString tssActual = actualTrans.Translation.get_String(ws); if (tssExpected == null || tssExpected.Length == 0) { Assert.IsTrue(tssActual == null || tssActual.Length == 0, "Found an unexpected translation for WS " + ws); continue; } AssertEx.AreTsStringsEqual(tssExpected, tssActual); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Allows this StText to perform any side-effects when the contents of one of its /// paragraphs changes. /// </summary> /// <param name="stTxtPara">The changed paragraph.</param> /// <param name="originalValue">The original value.</param> /// <param name="newValue">The new value.</param> /// ------------------------------------------------------------------------------------ internal virtual void OnParagraphContentsChanged(IStTxtPara stTxtPara, ITsString originalValue, ITsString newValue) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Delete a paragraph from this StText. /// </summary> /// <param name="para">paragraph to delete</param> /// ------------------------------------------------------------------------------------ public void DeleteParagraph(IStTxtPara para) { // delete any linked objects (footnotes or pictures) ((StTxtPara)para).RemoveOwnedObjectsForString(0, para.Contents.Length); // delete the paragraph ((IStText)para.Owner).ParagraphsOS.Remove(para); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure picture exists and is referred to properly in the paragraph contents /// </summary> /// <param name="pictureOrig">The original picture</param> /// <param name="para"></param> /// <param name="ich">Character position where ORC should be</param> /// ------------------------------------------------------------------------------------ private void VerifyPicture(ICmPicture pictureOrig, IStTxtPara para, int ich) { 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.kodtGuidMoveableObjDisp, 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 newPicGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1)); int newPicHvo = m_fdoCache.GetIdFromGuid(newPicGuid); Assert.IsTrue(pictureOrig.Guid != newPicGuid); Assert.IsTrue(pictureOrig.Hvo != newPicHvo); string sOrc = tss.get_RunText(iRun); Assert.AreEqual(StringUtils.kchObject, sOrc[0]); CmPicture pictureNew = new CmPicture(m_fdoCache, newPicHvo); Assert.IsTrue(pictureOrig.PictureFileRAHvo != pictureNew.PictureFileRAHvo); Assert.AreEqual(pictureOrig.PictureFileRA.InternalPath, pictureNew.PictureFileRA.InternalPath); }
/// ------------------------------------------------------------------------------------ /// <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> /// Create a mindless footnote (i.e., it's marker, paragraph style, etc. won't be set). /// </summary> /// <param name="book">Book to insert footnote into</param> /// <param name="para">Paragraph to insert footnote into</param> /// <param name="iFootnotePos">The 0-based index of the new footnote in the collection /// of footnotes owned by the book</param> /// <param name="ichPos">The 0-based character offset into the paragraph</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected StFootnote InsertTestFootnote(IScrBook book, IStTxtPara para, int iFootnotePos, int ichPos) { // Create the footnote StFootnote footnote = new StFootnote(); book.FootnotesOS.InsertAt(footnote, iFootnotePos); // Update the paragraph contents to include the footnote marker ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr(); footnote.InsertOwningORCIntoPara(tsStrBldr, ichPos, 0); // Don't care about ws para.Contents.UnderlyingTsString = tsStrBldr.GetString(); return footnote; }
void SetParaContents(IStTxtPara para, string contents) { para.Contents = Cache.TsStrFactory.MakeString(contents, Cache.DefaultVernWs); }
/// <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. } // Dispose unmanaged resources here, whether disposing is true or false. if (m_cpe != null && Marshal.IsComObject(m_cpe)) Marshal.ReleaseComObject(m_cpe); 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); }