/// ------------------------------------------------------------------------------------ /// <summary> /// Return a string that can be stored in a MultiUnicodeAccessor, where the only properties /// allowed are the writing system. /// </summary> /// ------------------------------------------------------------------------------------ public static ITsString ToWsOnlyString(this ITsString tss) { var props = tss.get_Properties(0); if (tss.RunCount == 1 && props.IntPropCount == 1 && props.StrPropCount == 0) { return(tss); // assume the one property is the writing system. } int dummy; var ws = props.GetIntPropValues((int)FwTextPropType.ktptWs, out dummy); var text = tss.Text; if (ws != -1) { return(TsStrFactoryClass.Create().MakeString(text, ws)); } // pathologically, the string may include a leading newline where no WS is specified. // Rather than fail, just drop any part of the string that has no WS. Typically we drop at // most a leading newline, which is also not appropriate in this kind of field anyway. for (int i = 1; i < tss.Length; i++) { ws = tss.get_WritingSystemAt(i); if (ws != -1) { return(TsStrFactoryClass.Create().MakeString(text.Substring(i), ws)); } } // This probably never happens. Debug.Assert(false, "trying to paste a TsString that has no WS anywhere!"); return(null); // May well crash, but what can we do? This method has no access to any valid WS. }
public void FindNextMissingBtFootnoteMarker_BtSectionHeadToNowhere() { IScrSection section = m_exodus.SectionsOS[1]; ITsStrFactory strfact = TsStrFactoryClass.Create(); IStTxtPara contentPara = section.ContentOA[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); IStFootnote foot = m_exodus.InsertFootnoteAt(0, strBldr, 7); contentPara.Contents = strBldr.GetString(); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs); ICmTranslation trans = contentPara.GetOrCreateBT(); ITsStrBldr bldr = trans.Translation.get_String(Cache.DefaultAnalWs).GetBldr(); TsStringUtils.InsertOrcIntoPara(foot.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, 2, 2, Cache.DefaultAnalWs); trans.Translation.set_String(Cache.DefaultAnalWs, bldr.GetString()); m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0); m_draftView.CallNextMissingBtFootnoteMarker(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(0, helper.IchAnchor); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidHeading, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation); }
public void FixOrcsWithoutProps_OrphanedFootnoteAndValidPicture() { CheckDisposed(); IScrBook exodus = CreateExodusData(); StTxtPara para = AddPara(exodus.SectionsOS[2]); AddVerse(para, 2, 3, "ORC is here, you see, my friend."); // Update the paragraph contents to include the picture ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr(); ITsStrFactory factory = TsStrFactoryClass.Create(); CmPicture pict = new CmPicture(Cache, "c:\\junk.jpg", factory.MakeString("Test picture", Cache.DefaultVernWs), StringUtils.LocalPictures); Assert.IsNotNull(pict); pict.InsertOwningORCIntoPara(tsStrBldr, 11, 0); para.Contents.UnderlyingTsString = tsStrBldr.GetString(); // Update the paragraph contents to include the (orphaned) footnote marker CreateFootnote(exodus, 1, 0, 1, 19, ScrStyleNames.CrossRefFootnoteParagraph, true); TeScrInitializer scrInit = new TestTeScrInitializer(Cache); List <string> report = (List <string>)ReflectionHelper.GetResult(scrInit, "FixOrcsWithoutProps"); VerifyNoOrphanedFootnotes(); VerifyResourceForFixedOrphans(); Assert.AreEqual(1, report.Count); Assert.AreEqual("EXO 1:2 - Deleted corrupted footnote marker or picture anchor", report[0]); Assert.AreEqual(0, exodus.FootnotesOS.Count); }
/// <summary> /// We understand how to get a multistring for any hvo in the tagEditColumn range. /// We also handle the virtual property LexEntry.ReversalEntriesBulkText in a /// special way. (See FWR-376.) /// </summary> public override ITsString get_MultiStringAlt(int hvo, int tag, int ws) { ITsString result1 = null; if (tag < ktagEditColumnBase || tag > ktagEditColumnLim) { result1 = base.get_MultiStringAlt(hvo, tag, ws); if (tag != m_tagReversalEntriesBulkText) { return(result1); } } ITsString result; if (m_mlStringCache.TryGetValue(new HvoFlidWSKey(hvo, tag, ws), out result)) { return(result); } if (tag == m_tagReversalEntriesBulkText && result1 != null) { return(result1); } ITsStrFactory tsf = TsStrFactoryClass.Create(); return(tsf.MakeString("", ws)); }
/// ------------------------------------------------------------------------------------ /// <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); }
public void FindNextMissingBtFootnoteMarker_BtSectionHeadToContent() { IScrSection section = m_exodus.SectionsOS[1]; ITsStrFactory strfact = TsStrFactoryClass.Create(); IStTxtPara contentPara = section.ContentOA[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); IStFootnote foot = m_exodus.InsertFootnoteAt(0, strBldr, 7); contentPara.Contents = strBldr.GetString(); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs); m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidHeading, 0, 1, 0, 0, true, true, false, VwScrollSelOpts.kssoDefault); m_draftView.CallNextMissingBtFootnoteMarker(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.IsFalse(helper.IsRange); Assert.AreEqual(1, helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor)[0].ihvo, "IP should be in first non-label segment."); Assert.AreEqual(0, helper.IchAnchor, "IP should be at start of segment."); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidContent, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation); }
public void HardLineBreaks() { ITsStrFactory tsf = TsStrFactoryClass.Create(); // String with embedded ORC. string test1 = "This is a simple sentence"; string lineBreak = StringUtils.kChHardLB.ToString(); string test3 = "with a hard break."; ITsString tss = tsf.MakeString(test1 + lineBreak + test3, m_wsEn); m_para.Contents = tss; List <int> results; var segments = m_pp.CollectSegments(tss, out results); VerifyBreaks(new int[] { test1.Length, test1.Length + 1, tss.Length - 1 }, results, "simple string with hard break"); Assert.AreEqual(3, segments.Count); // The segments break around the ORC. VerifySegment(segments[0], 0, test1.Length, m_para, "simple string with hard break"); VerifySegment(segments[1], test1.Length, test1.Length + 1, m_para, "simple string with hard break"); VerifySegment(segments[2], test1.Length + 1, tss.Length, m_para, "simple string with hard break"); // Now try with an EOS before the hard break. string test1a = "This is a proper sentence?!"; tss = tsf.MakeString(test1a + lineBreak + test3, m_wsEn); m_para.Contents = tss; segments = m_pp.CollectSegments(tss, out results); VerifyBreaks(new int[] { test1a.Length - 2, test1a.Length + 1, tss.Length - 1 }, results, "EOS before hard break"); Assert.AreEqual(3, segments.Count); // The segments break around the ORC. VerifySegment(segments[0], 0, test1a.Length, m_para, "EOS before hard break"); VerifySegment(segments[1], test1a.Length, test1a.Length + 1, m_para, "EOS before hard break"); VerifySegment(segments[2], test1a.Length + 1, tss.Length, m_para, "EOS before hard break"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { ITsStrFactory strfact = TsStrFactoryClass.Create(); //Jude IScrBook jude = AddBookToMockedScripture(65, "Jude"); AddTitleToMockedBook(jude, "Jude"); // Jude Scripture section IScrSection section = AddSectionToMockedBook(jude); AddSectionHeadParaToSection(section, "First section", "Section Head"); IStTxtPara judePara = AddParaToMockedSectionContent(section, "Paragraph"); AddRunToMockedPara(judePara, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(judePara, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(judePara, "This is the first verse", null); // Insert footnote into para 1 of Jude ITsStrBldr bldr = judePara.Contents.GetBldr(); IScrFootnote foot = jude.InsertFootnoteAt(0, bldr, 10); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is text for the footnote.", Cache.DefaultVernWs); judePara.Contents = bldr.GetString(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds paragraphs to the database /// </summary> /// <param name="ws"></param> /// <param name="firstPara"></param> /// <param name="secondPara"></param> /// ------------------------------------------------------------------------------------ private void AddParagraphs(int ws, string firstPara, string secondPara) { int hvoPara1 = m_hvoPara++; int hvoPara2 = m_hvoPara++; int hvoText1 = m_hvoText++; int hvoText2 = m_hvoText++; ITsStrFactory tsf = TsStrFactoryClass.Create(); ITsString tsString = tsf.MakeString(firstPara, ws); IVwCacheDa cda = Cache.VwCacheDaAccessor; cda.CacheStringProp(hvoPara1, (int)StTxtPara.StTxtParaTags.kflidContents, tsString); tsString = tsf.MakeString(secondPara, ws); cda.CacheStringProp(hvoPara2, (int)StTxtPara.StTxtParaTags.kflidContents, tsString); // Now make each of them the paragraphs of an StText. int[] hvoParas = { hvoPara1 }; cda.CacheVecProp(hvoText1, (int)StText.StTextTags.kflidParagraphs, hvoParas, 1); hvoParas[0] = hvoPara2; cda.CacheVecProp(hvoText2, (int)StText.StTextTags.kflidParagraphs, hvoParas, 1); // And the StTexts to the contents of a dummy property. AddVecProp(new int[] { hvoText1, hvoText2 }); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="vwenv"></param> /// <param name="hvo"></param> /// <param name="frag"></param> /// ------------------------------------------------------------------------------------ public override void Display(IVwEnv vwenv, int hvo, int frag) { if (m_displayOptions.LiteralStringLabels) { ITsStrFactory factory = TsStrFactoryClass.Create(); vwenv.AddString(factory.MakeString("Label" + m_counter++, m_wsDefault)); } switch (frag) { case kfragRoot: // the root; Display the paragraph AddParagraphBoxContents(vwenv, () => { if (m_displayOptions.ReadOnlyView) { vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); } }); break; default: throw new ApplicationException("Unexpected frag in SimpleRootSiteDataProviderVc"); } }
private void AddSimpleString(int ws, string s) { ITsStrFactory tsStrFactory = TsStrFactoryClass.Create(); VwCache.CacheStringProp(m_hvoRoot, kflidSimpleTsString, tsStrFactory.MakeString(s, ws)); }
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); } }
public void ExportFootnote_Missing() { int markerStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.FootnoteMarker).IndexInOwner + 1; int footnoteStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.NormalFootnoteParagraph).IndexInOwner + 1; ITsStrFactory stringFactory = TsStrFactoryClass.Create(); // Create a book with a section that has a paragraph with some text and a footnote! AddRunToMockedPara(m_para, "My text for footnotes", string.Empty); IStFootnote testFootnote = AddFootnote(m_book, m_para, m_para.Contents.Length, string.Empty); m_exporter = new DummyExportRtf(m_fileName, Cache, m_styleSheet); m_exporter.CallExportParagraph(m_para); // Verify the contents of the temp file m_exporter.CloseOutputFile(); using (TextReader file = FileUtils.OpenFileForRead(m_fileName, Encoding.ASCII)) { string line = file.ReadLine(); // the line is the paragraph without the footnote marker. Assert.AreEqual(@"\pard\plain\s2\f1\fs20{My text for footnotes}", line); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Static method to create a new structured text. It creates an StText object owned by /// hvoOwner in property tag, then creates an StTxtPara owned by the new StText. It /// sets the contents of the paragraph to be an empty string in the specified writing system, /// and Normal paragraph style. /// </summary> /// ENHANCE JohnT: probably we will identify styles by something other than name. /// REVIEW JohnT(TomB): Are we supposed to be supplying a style name rather than just /// using "Normal"? /// /// <param name="cache">FieldWorks database access</param> /// <param name="hvoOwner">id of object to own the new StText</param> /// <param name="propTag">property (field) type of the new StText</param> /// <param name="ws">language writing system of empty paragraph</param> /// <returns>HVO of the newly created StText object</returns> /// ----------------------------------------------------------------------------------- public static int MakeEmptyStText(FdoCache cache, int hvoOwner, int propTag, int ws) { // REVIEW TomB: Lastparm should really be null if Randy changes CreateObject. // Response from RandyR: I changed CreateObject. Null should work for // everything now. // Most of this code could be moved into the FDO objects, if desired. int hvoStText = cache.CreateObject(StText.kclsidStText, hvoOwner, propTag, 0); int hvoPara = cache.CreateObject(StTxtPara.kclsidStTxtPara, hvoStText, (int)StText.StTextTags.kflidParagraphs, 0); // Set the style of the paragraph to Normal ITsTextProps ttpNormal; ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, StyleNames.ksNormal); ttpNormal = tsPropsBldr.GetTextProps(); cache.MainCacheAccessor.SetUnknown(hvoPara, (int)StPara.StParaTags.kflidStyleRules, ttpNormal); // Set its contents to an empty string in the right writing system. ITsStrFactory tsFactory = TsStrFactoryClass.Create(); cache.SetTsStringProperty(hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents, tsFactory.MakeStringRgch("", 0, ws)); return(hvoStText); }
private void SetContentFromNode(FdoCache cache, string sNodeName, bool fFixName, MultiAccessor item) { ILgWritingSystemFactory wsf = cache.LanguageWritingSystemFactoryAccessor; ITsStrFactory tsf = TsStrFactoryClass.Create(); int iWS; XmlNode nd; bool fContentFound = false; // be pessimistic foreach (ILgWritingSystem ws in cache.LangProject.CurAnalysisWssRS) { string sWS = ws.ICULocale; nd = m_node.SelectSingleNode(sNodeName + "[@ws='" + sWS + "']"); if (nd == null || nd.InnerText.Length == 0) { continue; } fContentFound = true; string sNodeContent; if (fFixName) { sNodeContent = NameFixer(nd.InnerText); } else { sNodeContent = nd.InnerText; } iWS = wsf.GetWsFromStr(sWS); item.SetAlternative(tsf.MakeString(sNodeContent, iWS), iWS); } if (!fContentFound) { iWS = cache.LangProject.DefaultAnalysisWritingSystem; item.SetAlternative(tsf.MakeString("", iWS), iWS); } }
public void SetAndAccessMultiStrings() { ITsStrFactory tsf = TsStrFactoryClass.Create(); int kflid = XMLViewsDataCache.ktagEditColumnBase; int hvoRoot = 10578; int wsEng = Cache.WritingSystemFactory.GetWsFromStr("en"); XMLViewsDataCache xmlCache = new XMLViewsDataCache(Cache.MainCacheAccessor as ISilDataAccessManaged, true, new Dictionary <int, int>()); Notifiee recorder = new Notifiee(); xmlCache.AddNotification(recorder); Assert.AreEqual(0, xmlCache.get_MultiStringAlt(hvoRoot, kflid, wsEng).Length); Assert.AreEqual(0, recorder.Changes.Count); ITsString test1 = tsf.MakeString("test1", wsEng); xmlCache.CacheMultiString(hvoRoot, kflid, wsEng, test1); Assert.AreEqual(0, recorder.Changes.Count); Assert.AreEqual(test1, xmlCache.get_MultiStringAlt(hvoRoot, kflid, wsEng)); ITsString test2 = tsf.MakeString("blah", wsEng); xmlCache.SetMultiStringAlt(hvoRoot, kflid, wsEng, test2); Assert.AreEqual(test2, xmlCache.get_MultiStringAlt(hvoRoot, kflid, wsEng)); recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, kflid, wsEng, 0, 0) }, "expected PropChanged from setting string"); xmlCache.RemoveNotification(recorder); // Enhance JohnT: a better test would verify that it doesn't intefere with other multistrings, // and that it can store stuff independently for different HVOs, tags, and WSs. }
public override void TestSetup() { base.TestSetup(); m_vc = new StVc(); m_vc.Cache = Cache; m_pattern = VwPatternClass.Create(); m_strFactory = TsStrFactoryClass.Create(); m_pattern.Pattern = m_strFactory.MakeString("a", Cache.DefaultVernWs); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; IScrBook genesis = AddBookWithTwoSections(1, "Genesis"); m_section = genesis.SectionsOS[0]; // Add paragraphs (because we use an StVc in the test we add them all to the same section) m_para1 = AddParaToMockedSectionContent(m_section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(m_para1, "This is some text so that we can test the find functionality.", null); m_para2 = AddParaToMockedSectionContent(m_section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(m_para2, "Some more text so that we can test the find and replace functionality.", null); m_para3 = AddParaToMockedSectionContent( m_section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(m_para3, "This purugruph doesn't contuin the first letter of the ulphubet.", null); }
/// <summary> /// /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { IMoMorphSynAnalysis msa = MoMorphSynAnalysis.CreateFromDBObject(m_cache, hvo); ITsStrFactory tsf = TsStrFactoryClass.Create(); cda.CacheStringProp(hvo, tag, tsf.MakeString(msa.InterlinearName, m_cache.DefaultAnalWs)); }
public void LeadingPunctuation() { ITsStrFactory tsf = TsStrFactoryClass.Create(); string test1 = "?This is a question with special punctuation?"; ITsString tss = tsf.MakeString(test1, m_wsEn); m_para.Contents = tss; List <int> results; var segments = m_pp.CollectSegments(tss, out results); VerifyBreaks(new int[] { test1.Length - 1 }, results, "leading QM"); Assert.AreEqual(1, segments.Count); VerifySegment(segments[0], 0, test1.Length, m_para, "leading QM"); // Now try leading punctuation following a verse number. ITsStrBldr bldr = tss.GetBldr(); string verse = "5 "; bldr.Replace(0, 0, verse, null); bldr.SetStrPropValue(0, 1, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); ITsString tssMultiV = bldr.GetString(); m_para.Contents = tssMultiV; segments = m_pp.CollectSegments(tssMultiV, out results); VerifyBreaks(new int[] { verse.Length, tssMultiV.Length - 1 }, results, "leading verse and QM"); Assert.AreEqual(2, segments.Count); VerifySegment(segments[0], 0, verse.Length, m_para, "first seg of leading verse and QM"); VerifySegment(segments[1], verse.Length, tssMultiV.Length, m_para, "second seg of leading verse and QM"); }
public void GoToNextPara_NextFlid() { // Add a title to the root object int hvoTitle = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStText, m_hvoRoot, SimpleRootsiteTestsConstants.kflidDocTitle, -2); int hvoTitlePara = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStTxtPara, hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas, 0); ITsStrFactory tsStrFactory = TsStrFactoryClass.Create(); m_cache.CacheStringProp(hvoTitlePara, SimpleRootsiteTestsConstants.kflidParaContents, tsStrFactory.MakeString("The First Book of the Law given by Moses", m_wsFrn)); ShowForm(Lng.English, SimpleViewVc.DisplayType.kNormal | SimpleViewVc.DisplayType.kTitle); m_basicView.Show(); m_basicView.RefreshDisplay(); // Set the IP at the beginning of the only (0th) instance of the only (0th) paragraph // of the only (0th) instance of the second (1th) footnote of the book we're displaying. m_SelectionHelper = new DummySelectionHelper(null, m_basicView); SetSelection(0, 1, 0, 0, 2, 0, 0, true); IVwSelection vwsel = m_SelectionHelper.SetSelection(true); Assert.IsNotNull(vwsel, "No selection made"); Assert.IsTrue(m_basicView.IsSelectionVisible(null), "Selection is not visible"); m_basicView.EditingHelper.GoToNextPara(); // We expect that the selection will be at the start of the book title. SelectionHelper selectionHelper = SelectionHelper.GetSelectionInfo(null, m_basicView); Assert.IsFalse(selectionHelper.IsRange); CheckSelectionHelperValues(SelectionHelper.SelLimitType.Anchor, selectionHelper, 0, 0, 0, 0, false, 2, SimpleRootsiteTestsConstants.kflidDocTitle, 0, 0, SimpleRootsiteTestsConstants.kflidTextParas, 0, 0); }
/// <summary> /// Extra cleanup that fieldworks doesn't do correctly. /// </summary> public void Dispose() { // StructureMapService doesn't close this ITsStrFactory tsf = TsStrFactoryClass.Create(); Marshal.FinalReleaseComObject(tsf); }
public void GetSetClipboard() { var wsManager = new PalasoWritingSystemManager(); IWritingSystem enWs; wsManager.GetOrSet("en", out enWs); int wsEng = enWs.Handle; IWritingSystem swgWs; wsManager.GetOrSet("swg", out swgWs); int wsSwg = swgWs.Handle; var strFactory = TsStrFactoryClass.Create(); var incStrBldr = strFactory.GetIncBldr(); incStrBldr.AppendTsString(strFactory.MakeString("Gogomer ", wsSwg)); incStrBldr.AppendTsString(strFactory.MakeString("cucumber", wsEng)); EditingHelper.SetTsStringOnClipboard(incStrBldr.GetString(), false, wsManager); var tss = m_basicView.EditingHelper.GetTsStringFromClipboard(wsManager); Assert.IsNotNull(tss, "Couldn't get TsString from clipboard"); Assert.AreEqual(2, tss.RunCount); Assert.AreEqual("Gogomer ", tss.get_RunText(0)); Assert.AreEqual("cucumber", tss.get_RunText(1)); var newDataObj = ClipboardUtils.GetDataObject(); Assert.IsNotNull(newDataObj, "Couldn't get DataObject from clipboard"); Assert.AreEqual("Gogomer cucumber", newDataObj.GetData("Text")); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the RelatedWordsVc class. /// </summary> /// <param name="wsUser">The ws user.</param> /// <param name="headword">Headword of the target lexical entry.</param> /// ------------------------------------------------------------------------------------ public RelatedWordsVc(int wsUser, ITsString headword) { m_wsDefault = wsUser; ITsStrFactory tsf = TsStrFactoryClass.Create(); m_tssColon = tsf.MakeString(": ", wsUser); m_tssComma = tsf.MakeString(", ", wsUser); m_tssSdRelation = tsf.MakeString(FdoUiStrings.ksWordsRelatedBySemanticDomain, wsUser); m_tssLexRelation = tsf.MakeString(FdoUiStrings.ksLexicallyRelatedWords, wsUser); var semanticDomainStrBuilder = m_tssSdRelation.GetBldr(); var index = semanticDomainStrBuilder.Text.IndexOf("{0}"); if (index > 0) { semanticDomainStrBuilder.ReplaceTsString(index, index + "{0}".Length, headword); } m_tssSdRelation = semanticDomainStrBuilder.GetString(); var lexStrBuilder = m_tssLexRelation.GetBldr(); index = lexStrBuilder.Text.IndexOf("{0}"); if (index > 0) { lexStrBuilder.ReplaceTsString(index, index + "{0}".Length, headword); } m_tssLexRelation = lexStrBuilder.GetString(); }
public void OrcIsLabel() { ITsStrFactory tsf = TsStrFactoryClass.Create(); ParagraphParser pp = new ParagraphParser(m_para); // String with embedded ORC. string test1 = "This is a simple sentence"; string test2 = "\xfffc"; string test3 = " with a footnote."; ITsString tss = tsf.MakeString(test1 + test2 + test3, 1); // To be recognized an ORC must have unique properties. ITsStrBldr bldr = tss.GetBldr(); bldr.SetStrPropValue(test1.Length, test1.Length + test2.Length, (int)FwTextPropType.ktptObjData, "nonsence"); tss = bldr.GetString(); m_para.Contents.UnderlyingTsString = tss; List <int> results; List <int> segments = pp.CollectSegmentAnnotations(tss, out results); VerifyBreaks(new int[] { test1.Length, test1.Length + test2.Length + 1, test1.Length + test2.Length + test3.Length - 1 }, results, "multi-sentence string with ORC"); Assert.AreEqual(3, segments.Count); // The segments break around the ORC. VerifySegment(segments[0], 0, test1.Length, m_para.Hvo, "first seg of multi-sentence w. ORC"); VerifySegment(segments[1], test1.Length, test1.Length + test2.Length + 1, m_para.Hvo, "second seg of multi-sentence w. ORC"); VerifySegment(segments[2], test1.Length + test2.Length + 1, test1.Length + test2.Length + test3.Length, m_para.Hvo, "third seg of multi-sentence w. ORC"); }
public void FindNextMissingBtFootnoteMarker_BtSectionHeadToContent() { IScrSection section = m_exodus.SectionsOS[1]; ITsStrFactory strfact = TsStrFactoryClass.Create(); IStTxtPara contentPara = section.ContentOA[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); IStFootnote foot = m_exodus.InsertFootnoteAt(0, strBldr, 7); contentPara.Contents = strBldr.GetString(); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs); ICmTranslation trans = contentPara.GetOrCreateBT(); m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0); m_draftView.CallNextMissingBtFootnoteMarker(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(2, helper.IchAnchor, "IP should be after chapter and verse number."); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidContent, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation); }
/// ----------------------------------------------------------------------------------- /// <summary> /// This version knows how to display a generic date as a string. /// </summary> /// ----------------------------------------------------------------------------------- public override ITsString DisplayVariant(IVwEnv vwenv, int tag, int frag) { if (vwenv.DataAccess.MetaDataCache.GetFieldType(tag) == (int)CellarPropertyType.GenDate) { // handle generic date. Because the actual GenDate struct is not available to // Views code, we have to handle the display of the GenDate here var sda = vwenv.DataAccess as ISilDataAccessManaged; Debug.Assert(sda != null); var genDate = sda.get_GenDateProp(vwenv.CurrentObject(), tag); var tsf = TsStrFactoryClass.Create(); string str = ""; switch (frag) { case kfragGenDateLong: str = genDate.ToLongString(); break; case kfragGenDateShort: str = genDate.ToShortString(); break; case kfragGenDateSort: str = genDate.ToSortString(); break; } return(tsf.MakeString(str, sda.WritingSystemFactory.UserWs)); } else { return(base.DisplayVariant(vwenv, tag, frag)); } }
public TitleContentsVc(FdoCache cache) { int wsUser = cache.DefaultUserWs; ITsStrFactory tsf = TsStrFactoryClass.Create(); m_tssTitle = tsf.MakeString(ITextStrings.ksTitle, wsUser); ITsPropsBldr tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); m_ttpBold = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); // Set some padding all around. tpb.SetIntPropValues((int)FwTextPropType.ktptPadTop, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptPadBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptPadLeading, (int)FwTextPropVar.ktpvMilliPoint, 3000); tpb.SetIntPropValues((int)FwTextPropType.ktptPadTrailing, (int)FwTextPropVar.ktpvMilliPoint, 3000); tpb.SetIntPropValues((int)FwTextPropType.ktptMarginTrailing, (int)FwTextPropVar.ktpvMilliPoint, 11000); // 10000 clips right border. m_ttpDataCellProps = tpb.GetTextProps(); m_vtagStTextTitle = cache.MetaDataCacheAccessor.GetFieldId("StText", "Title", false); // Set up the array of writing systems we will display for title. SetupWritingSystemsForTitle(cache); }
public void MySetup() { Setup(); m_tsf = TsStrFactoryClass.Create(); m_wsEng = m_wsf.GetWsFromStr("en"); m_wsFrn = m_wsf.GetWsFromStr("fr"); }
public void FixOrcsWithoutProps_OrcForMissingObject() { CheckDisposed(); IScrBook exodus = CreateExodusData(); StTxtPara para = AddPara(exodus.SectionsOS[2]); AddVerse(para, 2, 3, "ORC is here, you see, my friend."); // Update the paragraph contents to include the picture ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr(); ITsStrFactory factory = TsStrFactoryClass.Create(); StringUtils.InsertOrcIntoPara(Guid.NewGuid(), FwObjDataTypes.kodtOwnNameGuidHot, tsStrBldr, 11, 11, 0); para.Contents.UnderlyingTsString = tsStrBldr.GetString(); TeScrInitializer scrInit = new TestTeScrInitializer(Cache); List <string> report = (List <string>)ReflectionHelper.GetResult(scrInit, "FixOrcsWithoutProps"); VerifyNoOrphanedFootnotes(); VerifyResourceForFixedOrphans(); Assert.AreEqual(1, report.Count); Assert.AreEqual("EXO 2:3 - Deleted corrupted footnote marker or picture anchor", report[0]); Assert.AreEqual(0, exodus.FootnotesOS.Count); }
/// ------------------------------------------------------------------------------------ /// <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(); }