public void PopulatePossibility(ICmPossibility poss) // Creating, assigning parent, etc., is handled elsewhere. This function only sets text values. { ILgWritingSystemFactory wsf = poss.Cache.WritingSystemFactory; foreach (KeyValuePair <string, string> kv in Abbrevs) { int wsId = wsf.GetWsFromStr(kv.Key); if (wsId != 0) { poss.Abbreviation.set_String(wsId, kv.Value); } } foreach (KeyValuePair <string, string> kv in Descriptions) { int wsId = wsf.GetWsFromStr(kv.Key); if (wsId != 0) { poss.Description.set_String(wsId, kv.Value); } } foreach (KeyValuePair <string, string> kv in Names) { int wsId = wsf.GetWsFromStr(kv.Key); if (wsId != 0) { poss.Name.set_String(wsId, kv.Value); } } PopulatePossibilityFromExtraData(poss); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the a text run from a string representation. /// </summary> /// <param name="owner">The owner of the paragraph (book).</param> /// <param name="strBldr">The structured string builder.</param> /// <param name="textNode">The text node which describes runs to be added to the /// paragraph or to the translation for a particular writing system</param> /// ------------------------------------------------------------------------------------ private static void CreateRunFromStringRep(CmObject owner, ITsIncStrBldr strBldr, XmlNode textNode) { XmlNode charStyle = textNode.Attributes.GetNamedItem("CS"); if (charStyle != null) { strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, charStyle.Value); } else { strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); } XmlNode wsICULocale = textNode.Attributes.GetNamedItem("WS"); if (wsICULocale != null) { ILgWritingSystemFactory wsf = owner.Cache.LanguageWritingSystemFactoryAccessor; int ws = wsf.GetWsFromStr(wsICULocale.Value); if (ws <= 0) { throw new ArgumentException("Unknown ICU locale encountered: '" + wsICULocale.Value + "'"); } strBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, wsf.GetWsFromStr(wsICULocale.Value)); } else { throw new ArgumentException("Required attribute WS missing from RUN element."); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize the object with the proper writing system factory, which also initializes /// some standard writing system ids. /// </summary> /// <param name="wsf">the writing system factory</param> /// <returns>nothing</returns> /// ------------------------------------------------------------------------------------ public virtual void InitializeWritingSystems(ILgWritingSystemFactory wsf) { m_wsEnglish = wsf.GetWsFromStr("en"); m_wsSpanish = wsf.GetWsFromStr("es"); // Rebuild the namesets with the new writing system ids. InitNameSets(); }
public void CreateScrBookRefs() { ReflectionHelper.CallMethod(typeof(TeScrBookRefsInit), "SetNamesAndAbbreviations", new DummyProgressDlg(), Cache); IFdoOwningSequence <IScrBookRef> books = Cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().Singleton.BooksOS; // Make sure the right number of books was generated. Assert.AreEqual(66, books.Count); ILgWritingSystemFactory wsf = Cache.WritingSystemFactory; int wsEnglish = wsf.GetWsFromStr("en"); int wsSpanish = wsf.GetWsFromStr("es"); // Check English Genesis IScrBookRef genesis = books[0]; Assert.AreEqual("Genesis", genesis.BookName.get_String(wsEnglish).Text); Assert.AreEqual("Gen", genesis.BookAbbrev.get_String(wsEnglish).Text); Assert.IsNull(genesis.BookNameAlt.get_String(wsEnglish).Text); // Check Spanish Matthew IScrBookRef mateo = books[39]; Assert.AreEqual("Mateo", mateo.BookName.get_String(wsSpanish).Text); Assert.AreEqual("Mt", mateo.BookAbbrev.get_String(wsSpanish).Text); Assert.IsNull(mateo.BookNameAlt.get_String(wsSpanish).Text); // Check English 2 Corinthians IScrBookRef iiCor = books[46]; Assert.AreEqual("2 Corinthians", iiCor.BookName.get_String(wsEnglish).Text); Assert.AreEqual("2Cor", iiCor.BookAbbrev.get_String(wsEnglish).Text); Assert.AreEqual("II Corinthians", iiCor.BookNameAlt.get_String(wsEnglish).Text); // Check Spanish Revelation IScrBookRef apocalipsis = books[65]; Assert.AreEqual("Apocalipsis", apocalipsis.BookName.get_String(wsSpanish).Text); Assert.AreEqual("Ap", apocalipsis.BookAbbrev.get_String(wsSpanish).Text); Assert.IsNull(apocalipsis.BookNameAlt.get_String(wsSpanish).Text); MultilingScrBooks mlsb = new MultilingScrBooks(m_scr.ScrProjMetaDataProvider); foreach (IScrBookRef brf in books) { Assert.IsTrue(!String.IsNullOrEmpty(brf.BookName.get_String(wsEnglish).Text)); Assert.IsTrue(!String.IsNullOrEmpty(brf.BookAbbrev.get_String(wsEnglish).Text)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add French paragraphs /// </summary> /// ------------------------------------------------------------------------------------ protected void MakeFrenchParagraphs() { CheckDisposed(); int wsFrn = m_wsf.GetWsFromStr("fr"); AddParagraphs(wsFrn, kFirstParaFra, kSecondParaFra); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the test data. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_servLoc = Cache.ServiceLocator; m_wsf = Cache.WritingSystemFactory; m_ws_en = m_wsf.GetWsFromStr("en"); m_ws_fr = m_wsf.GetWsFromStr("fr"); CreateTestText(); }
public void MoreWritingSystemLists() { ILgWritingSystemFactory factWs = Cache.ServiceLocator.GetInstance <ILgWritingSystemFactory>(); char[] rgchSplit = new char[] { ' ' }; string sVern = factWs.GetStrFromWs(Cache.DefaultVernWs); Assert.IsTrue(Cache.LangProject.CurVernWss.Contains(sVern)); Assert.IsTrue(Cache.LangProject.VernWss.Contains(sVern)); Set <string> setVern = new Set <string>(); setVern.AddRange(Cache.LangProject.VernWss.Split(rgchSplit)); Assert.Less(0, setVern.Count, "should be at least one Vernacular WS"); Set <string> setCurVern = new Set <string>(); setCurVern.AddRange(Cache.LangProject.CurVernWss.Split(rgchSplit)); Assert.Less(0, setCurVern.Count, "should be at least one Current Vernacular WS"); Assert.LessOrEqual(setCurVern.Count, setVern.Count, "at least as many Current Vernacular as Vernacular"); foreach (string x in setCurVern) { Assert.IsTrue(setVern.Contains(x), "Vernacular contains everything in Current Vernacular"); int ws = factWs.GetWsFromStr(x); Assert.AreNotEqual(0, ws, "factory should contain everything in Current Vernacular"); } foreach (string x in setVern) { int ws = factWs.GetWsFromStr(x); Assert.AreNotEqual(0, ws, "factory should contain everything in Vernacular"); } string sAnal = factWs.GetStrFromWs(Cache.DefaultAnalWs); Assert.IsTrue(Cache.LangProject.CurAnalysisWss.Contains(sAnal)); Assert.IsTrue(Cache.LangProject.AnalysisWss.Contains(sAnal)); Set <string> setAnal = new Set <string>(); setAnal.AddRange(Cache.LangProject.AnalysisWss.Split(rgchSplit)); Assert.Less(0, setAnal.Count, "should be at least one Analysis WS"); Set <string> setCurAnal = new Set <string>(); setCurAnal.AddRange(Cache.LangProject.CurAnalysisWss.Split(rgchSplit)); Assert.Less(0, setCurAnal.Count, "should be at least one Current Analysis WS"); Assert.LessOrEqual(setCurAnal.Count, setAnal.Count, "at least as many Current Analysis as Analysis"); foreach (string x in setCurAnal) { Assert.IsTrue(setAnal.Contains(x), "Analysis contains everything in Current Analysis"); int ws = factWs.GetWsFromStr(x); Assert.AreNotEqual(0, ws, "factory should contain everything in Current Analysis"); } foreach (string x in setAnal) { int ws = factWs.GetWsFromStr(x); Assert.AreNotEqual(0, ws, "factory should contain everything in Analysis"); } }
public void Setup() { tsf = TsStrFactoryClass.Create(); wsf = new MockWsf(); wsEn = wsf.GetWsFromStr("en"); wsFrn = wsf.GetWsFromStr("fr"); ITsPropsBldr propBldr = TsPropsBldrClass.Create(); propBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, wsFrn); ttpFrn = propBldr.GetTextProps(); }
public void WritingSystemsLists() { List <IWritingSystem> list = new List <IWritingSystem>(); foreach (var x in Cache.LangProject.AllWritingSystems) { list.Add(x); } Assert.AreEqual(2, list.Count); ILgWritingSystemFactory factWs = Cache.ServiceLocator.GetInstance <ILgWritingSystemFactory>(); Assert.LessOrEqual(list.Count, factWs.NumberOfWs, "factory list is at least as large as AllWritingSystems"); Set <int> set = new Set <int>(); using (ArrayPtr rgwsT = MarshalEx.ArrayToNative <int>(factWs.NumberOfWs)) { factWs.GetWritingSystems(rgwsT, factWs.NumberOfWs); set.AddRange(MarshalEx.NativeToArray <int>(rgwsT, factWs.NumberOfWs)); } int wsEn = factWs.GetWsFromStr("en"); Assert.AreNotEqual(0, wsEn, "factory should contain English WS"); int wsFr = factWs.GetWsFromStr("fr"); Assert.AreNotEqual(0, wsFr, "factory should contain French WS"); IWritingSystem eng = null; IWritingSystem frn = null; foreach (var x in list) { Assert.IsTrue(set.Contains(x.Handle), "AllWritingSystems should be a subset of the factory list"); if (x.Handle == wsEn) { eng = x; } else if (x.Handle == wsFr) { frn = x; } } Assert.IsNotNull(eng, "AllWritingSystems should contain English"); Assert.AreEqual("English", factWs.get_EngineOrNull(wsEn).LanguageName); Assert.AreEqual("English", eng.LanguageName); Assert.IsNotNull(frn, "AllWritingSystems should contain French"); Assert.AreEqual("French", frn.LanguageName); Assert.AreEqual("French", factWs.get_Engine("fr").LanguageName); }
private void SetContentFromNode(FdoCache cache, string sNodeName, bool fFixName, ITsMultiString item) { ILgWritingSystemFactory wsf = cache.WritingSystemFactory; ITsStrFactory tsf = cache.TsStrFactory; int iWS; XmlNode nd; bool fContentFound = false; // be pessimistic foreach (IWritingSystem ws in cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems) { string sWS = ws.Id; 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.set_String(iWS, (tsf.MakeString(sNodeContent, iWS))); } if (!fContentFound) { iWS = cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle; item.set_String(iWS, tsf.MakeString("", iWS)); } }
public static InterlinLineChoices Restore(string data, ILgWritingSystemFactory wsf, int defVern, int defAnalysis, ILangProject proj) { InterlinLineChoices result; string[] parts = data.Split(','); switch (parts[0]) { case "InterlinLineChoices": result = new InterlinLineChoices(defVern, defAnalysis, proj); break; case "EditableInterlinLineChoices": result = new EditableInterlinLineChoices(defVern, defAnalysis, proj); break; default: throw new Exception("Unrecognised type of InterlinLineChoices: " + parts[0]); } for (int i = 1; i < parts.Length; i++) { string[] flidAndWs = parts[i].Split('%'); if (flidAndWs.Length != 2) { throw new Exception("Unrecognized InterlinLineSpec: " + parts[i]); } int flid = Int32.Parse(flidAndWs[0]); int ws = wsf.GetWsFromStr(flidAndWs[1]); result.Add(flid, ws); } return(result); }
public void WriteToLcmMultiString(IMultiAccessorBase dest, ILgWritingSystemFactory wsManager) { if (dest == null) { return; } HashSet <int> destWsIdsToClear = new HashSet <int>(dest.AvailableWritingSystemIds); foreach (KeyValuePair <string, LfStringField> kv in this) { int wsId = wsManager.GetWsFromStr(kv.Key); if (wsId == 0) { continue; // Skip any unidentified writing systems } string value = kv.Value.Value; ITsString tss = LfMerge.Core.DataConverters.ConvertMongoToLcmTsStrings.SpanStrToTsString(value, wsId, wsManager); dest.set_String(wsId, tss); destWsIdsToClear.Remove(wsId); } foreach (int wsId in destWsIdsToClear) { dest.set_String(wsId, string.Empty); } }
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); } }
protected override void PopulatePossibilityFromExtraData(ICmPossibility poss) { ICmSemanticDomain semdom = poss as ICmSemanticDomain; if (semdom == null) { return; } ILgWritingSystemFactory wsf = semdom.Cache.WritingSystemFactory; var questionFactory = semdom.Cache.ServiceLocator.GetInstance <ICmDomainQFactory>(); Dictionary <string, List <SemDomQuestion> > questionsByWs = GetExtraDataWsDict <SemDomQuestion>("Questions"); // This dict looks like {"en": (question 1, question 2...)} but each question object wants to get data that // looks more or less like {"en": "the question in English", "fr": "la question en francais"}... // So first we ensure that there are enough question objects available, and then we'll access them by index // as we step through the writing systems. int numQuestions = questionsByWs.Values.Select(questionList => questionList.Count).Max(); while (semdom.QuestionsOS.Count < numQuestions) { semdom.QuestionsOS.Add(questionFactory.Create()); } foreach (string ws in questionsByWs.Keys) { int wsId = wsf.GetWsFromStr(ws); int i = 0; foreach (SemDomQuestion qStruct in questionsByWs[ws]) { semdom.QuestionsOS[i].Question.set_String(wsId, qStruct.Question ?? string.Empty); semdom.QuestionsOS[i].ExampleSentences.set_String(wsId, qStruct.ExampleSentences ?? string.Empty); semdom.QuestionsOS[i].ExampleWords.set_String(wsId, qStruct.ExampleWords ?? string.Empty); i++; } } }
public override void Initialize() { CheckDisposed(); base.Initialize(); m_wsf = Cache.LanguageWritingSystemFactoryAccessor; m_wsEng = m_wsf.GetWsFromStr("en"); }
public override void FixtureSetup() { base.FixtureSetup(); m_flidContainingTexts = ScrBookTags.kflidFootnotes; m_wsf = Cache.WritingSystemFactory; m_wsEng = m_wsf.GetWsFromStr("en"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add English paragraphs /// </summary> /// ------------------------------------------------------------------------------------ public void MakeEnglishParagraphs() { CheckDisposed(); ILgWritingSystemFactory wsf = m_fdoCache.WritingSystemFactory; int wsEng = wsf.GetWsFromStr("en"); AddParagraphsToLangProj(wsEng, kFirstParaEng, kSecondParaEng); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:KeyTermRenderingsControl"/> class. /// </summary> /// <param name="cache">The cache.</param> /// <param name="mainWnd">the FwMainWnd that owns this control.</param> /// ------------------------------------------------------------------------------------ public KeyTermRenderingsControl(FdoCache cache, FwMainWnd mainWnd) : base(cache, mainWnd) { InitializeComponent(); DataGridView = m_dataGridView; // Setup columns m_Rendering.Cache = m_cache; m_Rendering.WritingSystemCode = m_cache.DefaultVernWs; m_OriginalTerm.Cache = m_cache; ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor; m_wsGreek = wsf.GetWsFromStr("grc"); if (m_wsGreek <= 0) { throw new Exception("The Greek writing system is not defined."); } m_wsHebrew = wsf.GetWsFromStr("hbo"); if (m_wsHebrew <= 0) { throw new Exception("The Hebrew writing system is not defined."); } if (mainWnd != null) { Parent = mainWnd; m_stylesheet = mainWnd.StyleSheet; m_Rendering.Font = new Font( m_stylesheet.GetNormalFontFaceName(cache, cache.DefaultVernWs), FontInfo.kDefaultFontSize / 1000); } m_list = new List <ICheckGridRowObject>(); m_gridSorter = new CheckGridListSorter(m_list); m_gridSorter.AddComparer(m_Rendering.DataPropertyName, m_tsStrComparer); m_gridSorter.AddComparer(m_OriginalTerm.DataPropertyName, m_tsStrComparer); m_gridSorter.AddComparer(m_Status.DataPropertyName, new RenderingStatusComparer()); m_gridSorter.AddComparer(m_Reference.DataPropertyName, new ScriptureReferenceComparer((Scripture)m_cache.LangProject.TranslatedScriptureOA)); m_dataGridView.Cache = m_cache; m_dataGridView.ColumnHeaderMouseClick += m_dataGridView_ColumnHeaderMouseClick; }
public void Setup() { m_wsf = LgWritingSystemFactoryClass.Create(); // This is typically run during the build process before InstallLanguage.exe has // been built, so we want to disable InstallLanguage for this test. m_wsf.BypassInstall = true; m_wsEn = m_wsf.get_Engine("en"); m_wsIdEn = m_wsf.GetWsFromStr("en"); m_wsEn.set_Name(m_wsIdEn, "English"); m_wsEn.set_Abbr(m_wsIdEn, "ENG"); }
private int GetWsFromStr(string sWs) { int ws = m_wsf.GetWsFromStr(sWs); if (ws != 0) { return(ws); } // Add this writing system. ILgWritingSystem lgws = m_wsf.get_Engine(sWs); return(lgws.Handle); }
/// <summary> /// Translate the ICU locale string into the writing system id for the given /// writing system factory, adding it to the factory as needed. /// </summary> /// <param name="icuLocale"></param> /// <param name="wsf"></param> /// <returns></returns> static public int GetWsFromStr(string icuLocale, ILgWritingSystemFactory wsf) { int ws = wsf.GetWsFromStr(icuLocale); if (ws == 0) { // This adds the icuLocale as a new writing system to the factory. IWritingSystem lws = wsf.get_Engine(icuLocale); ws = lws.WritingSystem; lws = null; } return(ws); }
public KeyValuePair <int, string> WsIdAndFirstNonEmptyString(LcmCache cache) { KeyValuePair <string, string> kv = FirstNonEmptyKeyValue(); if (kv.Key == null) { return(new KeyValuePair <int, string>()); } ILgWritingSystemFactory wsManager = cache.ServiceLocator.WritingSystemManager; int wsId = wsManager.GetWsFromStr(kv.Key); return(new KeyValuePair <int, string>(wsId, kv.Value)); }
/// <summary> /// Read multilingual Unicode data from XML fragments like /// <Name> /// <AUni ws="en">FRAME and OCM Categories</AUni> /// </Name> /// </summary> private void SetMultiUnicodeFromXml(XmlReader xrdr, IMultiUnicode mu) { if (xrdr.IsEmptyElement) { xrdr.Read(); return; } if (xrdr.ReadToDescendant("AUni")) { do { string sWs = xrdr.GetAttribute("ws"); string sVal = xrdr.ReadString(); int ws = m_wsf.GetWsFromStr(sWs); if (ws != 0) { mu.set_String(ws, sVal); } } while (xrdr.ReadToNextSibling("AUni")); } xrdr.Read(); // read the end tag. }
/// ------------------------------------------------------------------------------------ /// <summary> /// Update the existing categories and terms with new localized strings. /// </summary> /// <param name="dlg">The progress dialog.</param> /// <param name="parameters">The parameters: 1) the BiblicalTermsLocalization object /// representing the contents of the XML file with the localized strings; 2) The ICU /// locale (string).</param> /// <returns>always null</returns> /// ------------------------------------------------------------------------------------ protected object UpdateLocalization(IThreadedProgress dlg, params object[] parameters) { BiblicalTermsLocalization loc = (BiblicalTermsLocalization)parameters[0]; string locale = (string)parameters[1]; const int kcStepsToBuildLookupTable = 4; dlg.Position = 0; dlg.Minimum = 0; dlg.Maximum = loc.Categories.Count + loc.Terms.Count + kcStepsToBuildLookupTable; dlg.Title = TeResourceHelper.GetResourceString("kstidLoadKeyTermsInDBCaption"); dlg.Message = TeResourceHelper.FormatResourceString("kstidLoadKeyTermsLocalizations", m_wsf.get_Engine(locale).LanguageName); m_wsDefault = m_servLoc.WritingSystemManager.GetWsFromStr("en"); int hvoLocWs = loc.WritingSystemHvo = m_wsf.GetWsFromStr(locale); IEnumerable <ICmPossibility> categories = ((ILangProject)m_scr.Owner).KeyTermsList.PossibilitiesOS; foreach (CategoryLocalization localizedCategory in loc.Categories) { ICmPossibility category = categories.FirstOrDefault( p => p.Abbreviation.get_String(m_wsDefault).Text == localizedCategory.Id); if (category != null) { category.Name.set_String(hvoLocWs, localizedCategory.Gloss); } dlg.Step(1); } Dictionary <int, IChkTerm> termLookupTable = m_servLoc.GetInstance <IChkTermRepository>().AllInstances().ToDictionary(t => t.TermId); dlg.Step(kcStepsToBuildLookupTable); IChkTerm term; string message = TeResourceHelper.GetResourceString("kstidLoadKeyTermsInDBStatus"); foreach (TermLocalization localizedTerm in loc.Terms) { dlg.Message = string.Format(message, localizedTerm.Gloss); if (termLookupTable.TryGetValue(localizedTerm.Id, out term)) { SetLocalizedGlossAndDescription(term, localizedTerm, loc.WritingSystemHvo); } dlg.Step(1); } return(null); }
public void AddingWritingSystems() { Assert.AreEqual(1, Cache.LangProject.CurrentVernacularWritingSystems.Count, "Only one current vernacular WS"); Assert.AreEqual(1, Cache.LangProject.VernacularWritingSystems.Count, "Only one vernacular WS"); Assert.IsFalse(Cache.LangProject.VernWss.Contains("es"), "Vernacular WSs do not include Spanish"); Assert.IsFalse(Cache.LangProject.CurVernWss.Contains("es"), "Current Vernacular WSs do not include Spanish"); Assert.IsFalse(Cache.LangProject.AnalysisWss.Contains("es"), "Analysis WSs do not include Spanish"); Assert.IsFalse(Cache.LangProject.CurAnalysisWss.Contains("es"), "Current Analysis WSs do not include Spanish"); Assert.AreEqual(1, Cache.LangProject.CurrentAnalysisWritingSystems.Count, "Only one current analysis WS"); Assert.AreEqual(1, Cache.LangProject.AnalysisWritingSystems.Count, "Only one analysis WS"); Assert.IsFalse(Cache.LangProject.VernWss.Contains("de"), "Vernacular WSs do not include German"); Assert.IsFalse(Cache.LangProject.CurVernWss.Contains("de"), "Current Vernacular WSs do not include German"); Assert.IsFalse(Cache.LangProject.AnalysisWss.Contains("de"), "Analysis WSs do not include German"); Assert.IsFalse(Cache.LangProject.CurAnalysisWss.Contains("de"), "Current Analysis WSs do not include German"); ILgWritingSystemFactory factWs = Cache.ServiceLocator.GetInstance <ILgWritingSystemFactory>(); int wsEs = factWs.GetWsFromStr("es"); if (wsEs != 0) { Cache.LangProject.VernWss = Cache.LangProject.VernWss + " es"; Cache.LangProject.CurVernWss = Cache.LangProject.CurVernWss + " es"; Assert.AreEqual(2, Cache.LangProject.CurrentVernacularWritingSystems.Count, "Now two current vernacular WS"); Assert.AreEqual(2, Cache.LangProject.VernacularWritingSystems.Count, "Now two vernacular WS"); } int wsDe = factWs.GetWsFromStr("de"); if (wsDe != 0) { IWritingSystem german = factWs.get_EngineOrNull(wsDe) as IWritingSystem; Assert.IsNotNull(german, "IWritingSystem and ILgWritingSystem are the same now"); Cache.LangProject.AnalysisWritingSystems.Add(german); Cache.LangProject.CurrentAnalysisWritingSystems.Add(german); Assert.IsTrue(Cache.LangProject.AnalysisWss.Contains("de"), "Analysis WSs now include German"); Assert.IsTrue(Cache.LangProject.CurAnalysisWss.Contains("de"), "Current Analysis WSs now include German"); } }
public void AddToDatabase(FdoCache cache, ICmPossibilityList posList, MasterCategory parent, IPartOfSpeech subItemOwner) { CheckDisposed(); if (m_pos != null) { return; // It's already in the database, so nothing more can be done. } cache.BeginUndoTask(LexTextControls.ksUndoCreateCategory, LexTextControls.ksRedoCreateCategory); int newOwningFlid; int insertLocation; int newOwner = DeterminePOSLocationInfo(subItemOwner, parent, posList, out newOwningFlid, out insertLocation); ILgWritingSystemFactory wsf = cache.LanguageWritingSystemFactoryAccessor; Debug.Assert(m_pos != null); if (m_node == null) { // should not happen, but just in case... we still get something useful m_pos.Name.SetAlternative(m_term, wsf.GetWsFromStr(m_termWs)); m_pos.Abbreviation.SetAlternative(m_abbrev, wsf.GetWsFromStr(m_abbrevWs)); m_pos.Description.SetAlternative(m_def, wsf.GetWsFromStr(m_defWs)); } else { SetContentFromNode(cache, "abbrev", false, m_pos.Abbreviation); SetContentFromNode(cache, "term", true, m_pos.Name); SetContentFromNode(cache, "def", false, m_pos.Description); } m_pos.CatalogSourceId = m_id; // Need a PropChanged, since it isn't done in the 'Append' for some reason. cache.PropChanged(null, PropChangeType.kpctNotifyAll, newOwner, newOwningFlid, insertLocation, 1, 0); cache.EndUndoTask(); }
public void AddToDatabase(FdoCache cache, ICmPossibilityList posList, MasterCategory parent, IPartOfSpeech subItemOwner) { if (m_pos != null) { return; // It's already in the database, so nothing more can be done. } UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoCreateCategory, LexTextControls.ksRedoCreateCategory, cache.ServiceLocator.GetInstance <IActionHandler>(), () => { int newOwningFlid; int insertLocation; int newOwner = DeterminePOSLocationInfo(cache, subItemOwner, parent, posList, out newOwningFlid, out insertLocation); ILgWritingSystemFactory wsf = cache.WritingSystemFactory; Debug.Assert(m_pos != null); int termWs = wsf.GetWsFromStr(m_termWs); int abbrevWs = wsf.GetWsFromStr(m_abbrevWs); int defWs = wsf.GetWsFromStr(m_defWs); ITsStrFactory tsf = cache.TsStrFactory; if (m_node == null) { // should not happen, but just in case... we still get something useful m_pos.Name.set_String(termWs, tsf.MakeString(m_term, termWs)); m_pos.Abbreviation.set_String(abbrevWs, tsf.MakeString(m_abbrev, abbrevWs)); m_pos.Description.set_String(defWs, tsf.MakeString(m_def, defWs)); } else { SetContentFromNode(cache, "abbrev", false, m_pos.Abbreviation); SetContentFromNode(cache, "term", true, m_pos.Name); SetContentFromNode(cache, "def", false, m_pos.Description); } m_pos.CatalogSourceId = m_id; }); }
internal static int ReadAstrElementOfMultiString(XElement aStrNode, ILgWritingSystemFactory wsf, out ITsString tss) { var wsHvo = 0; var wsAttr = aStrNode.Attribute("ws"); if (wsAttr != null) { wsHvo = wsf.GetWsFromStr(wsAttr.Value); } tss = TsStringSerializer.DeserializeTsStringFromXml(aStrNode, wsf); if (wsHvo == 0) { // THIS SHOULD NEVER HAPPEN but we live in a fallen world! var ttp = tss.get_PropertiesAt(0); int nVar; wsHvo = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar); } return(wsHvo); }
public static ITsString SpanStrToTsString(string source, int mainWs, ILgWritingSystemFactory wsf) { // How to build up an ITsString via an ITsIncStrBldr - // 1. Use SetIntPropValues or SetStrPropValues to set a property "to be applied to any subsequent append operations". // 2. THEN use Append(string s) to add a string, which will "pick up" the properties set in step 1. // See ScrFootnoteFactory.CreateRunFromStringRep() in LcmFactoryAdditions.cs for a good example. if (source == null) { return(null); } List <Run> runs = GetSpanRuns(source); var builder = TsStringUtils.MakeIncStrBldr(); // Will become: ITsIncStrBldr builder = TsStringUtils.MakeIncStrBldr(); // Add "using SIL.CoreImpl;" when this line is uncommented. foreach (Run run in runs) { builder.ClearProps(); // Make sure there aren't leftover properties from previous run // To remove a string property, you set it to null, so we can just use StyleName directly whether or not it's null. builder.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, run.StyleName); int runWs = (run.Lang == null) ? mainWs : wsf.GetWsFromStr(run.Lang); builder.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, runWs); // We don't care about Guids in this function, so run.Guid is ignored // But we do need to set any other int or string properties that were in the original if (run.IntProperties != null) { foreach (KeyValuePair <int, IntProperty> prop in run.IntProperties) { builder.SetIntPropValues(prop.Key, prop.Value.Variation, prop.Value.Value); } } if (run.StringProperties != null) { foreach (KeyValuePair <int, string> prop in run.StringProperties) { builder.SetStrPropValue(prop.Key, prop.Value); } } builder.Append(run.Content); } return(builder.GetString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes the data source combo. /// </summary> /// ------------------------------------------------------------------------------------ private void CheckForScrProject() { if (m_cache == null || m_langDef == null) { return; } m_scrChecksDllFile = DirectoryFinder.BasicEditorialChecksDll; ILgWritingSystemFactory lgwsf = m_cache.LanguageWritingSystemFactoryAccessor; string strLocale = m_langDef.HasChangedIcuLocale ? m_langDef.LocaleAbbr : m_langDef.IcuLocaleOriginal; bool modifyingVernWs = lgwsf.GetWsFromStr(strLocale) == m_cache.DefaultVernWs; // If TE isn't installed, we can't support creating an inventory // based on Scripture data. cmnuScanScripture.Visible = (MiscUtils.IsTEInstalled && File.Exists(m_scrChecksDllFile) && m_cache.LangProject.TranslatedScriptureOA != null && modifyingVernWs); }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="wsf"></param> /// <param name="proj"></param> /// <param name="defVern">Typically you want to pass in LgWritingSystemTags.kwsVernInParagraph</param> /// <param name="defAnalysis"></param> /// <returns></returns> public static InterlinLineChoices Restore(string data, ILgWritingSystemFactory wsf, ILangProject proj, int defVern, int defAnalysis) { Debug.Assert(defVern != 0); Debug.Assert(defAnalysis != 0); InterlinLineChoices result; string[] parts = data.Split(','); switch(parts[0]) { case "InterlinLineChoices": result = new InterlinLineChoices(proj, defVern, defAnalysis); break; case "EditableInterlinLineChoices": result = new EditableInterlinLineChoices(proj, defVern, defAnalysis); break; default: throw new Exception("Unrecognised type of InterlinLineChoices: " + parts[0]); } for (int i = 1; i < parts.Length; i++) { string[] flidAndWs = parts[i].Split('%'); if (flidAndWs.Length != 2) throw new Exception("Unrecognized InterlinLineSpec: " + parts[i]); int flid = Int32.Parse(flidAndWs[0]); int ws = wsf.GetWsFromStr(flidAndWs[1]); result.Add(flid, ws); } return result; }
/// <summary> /// Translate the ICU locale string into the writing system id for the given /// writing system factory, adding it to the factory as needed. /// </summary> /// <param name="icuLocale"></param> /// <param name="wsf"></param> /// <returns></returns> static public int GetWsFromStr(string icuLocale, ILgWritingSystemFactory wsf) { int ws = wsf.GetWsFromStr(icuLocale); if (ws == 0) { // This adds the icuLocale as a new writing system to the factory. IWritingSystem lws = wsf.get_Engine(icuLocale); ws = lws.WritingSystem; lws = null; } return ws; }
public static ITsString SpanStrToTsString(string source, int mainWs, ILgWritingSystemFactory wsf) { // How to build up an ITsString via an ITsIncStrBldr - // 1. Use SetIntPropValues or SetStrPropValues to set a property "to be applied to any subsequent append operations". // 2. THEN use Append(string s) to add a string, which will "pick up" the properties set in step 1. // See ScrFootnoteFactory.CreateRunFromStringRep() in FdoFactoryAdditions.cs for a good example. List<Run> runs = GetSpanRuns(source); ITsIncStrBldr builder = TsIncStrBldrClass.Create(); foreach (Run run in runs) { // To remove a string property, you set it to null, so we can just use StyleName directly whether or not it's null. builder.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, run.StyleName); int runWs = (run.Lang == null) ? mainWs : wsf.GetWsFromStr(run.Lang); builder.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, runWs); // We don't care about Guids in this function, so run.Guid is ignored // But we do need to set any other int or string properties that were in the original if (run.IntProperties != null) foreach (KeyValuePair<int, IntProperty> prop in run.IntProperties) builder.SetIntPropValues(prop.Key, prop.Value.Variation, prop.Value.Value); if (run.StringProperties != null) foreach (KeyValuePair<int, string> prop in run.StringProperties) builder.SetStrPropValue(prop.Key, prop.Value); builder.Append(run.Content); } return builder.GetString(); }
public void Setup() { // Create the following: // - part and layout inventories // - metadata cache // - DataAccess cache // - collection of columns to display. // We want a MetaDataCache that knows about // - LexEntry.Senses, Msas, CitationForm, Bibliography, Etymology // - LexSense.SemanticDomains, SenseType, Status, gloss // - CmPossibility Name, abbr // - MoMorphSynAnalysis // - MoStemMsa // - MoDerivationalMsa m_mdc = FwMetaDataCacheClass.Create(); string m_sTestPath = Path.Combine(DirectoryFinder.FwSourceDirectory, @"Common\Controls\XmlViews\XmlViewsTests\SampleCm.xml"); m_mdc.InitXml(m_sTestPath, true); // We want ISilDataAccess with: // - LexEntry (1) with no senses and one MSA (2) // - LexEntry (4) with one sense (5) and no MSA // - LexEntry (6) with three senses (7, 8, 9) and two MSAs (10, 11) // - sense(5) with no semantic domains // - senses with one SD (7->30, 8->31) // - sense with three SDs, one the same as the first (9->30, 31, 32) // - MoStemMsa (2, 11) // - MoDerivationalMsa (10) m_cda = VwCacheDaClass.Create(); m_sda = m_cda as ISilDataAccess; m_wsf = LgWritingSystemFactoryClass.Create(); m_sda.WritingSystemFactory = m_wsf; SimpleDataParser parser = new SimpleDataParser(m_mdc, m_cda); parser.Parse(Path.Combine(DirectoryFinder.FwSourceDirectory, @"Common\Controls\XmlViews\XmlViewsTests\SampleData.xml")); int wsEn = m_wsf.GetWsFromStr("en"); // These are mainly to check out the parser. Assert.AreEqual(3, m_sda.get_ObjectProp(2, 23011), "part of speech of an MoStemMsa"); Assert.AreEqual(2, m_sda.get_VecItem(1, 2009, 0), "owned msa"); Assert.AreEqual("noun", m_sda.get_MultiStringAlt(3, 7003, wsEn).Text, "got ms property"); Assert.AreEqual(9, m_sda.get_VecItem(6, 2010, 2), "3rd sense"); Assert.AreEqual(31, m_sda.get_VecItem(9, 21016, 1), "2nd semantic domain"); // Columns includes // - CitationForm (string inside span) // - Bibliography (string not in span) // - Sense glosses (string in para in seq, nested in column element) // - Semantic domains (pair of strings in para in seq in seq, using layout refs) // - MSAs (simplified, but polymorphic with one having <choice> and one <obj> to CmPossibility XmlDocument docColumns = new XmlDocument(); docColumns.Load(Path.Combine(DirectoryFinder.FwSourceDirectory, @"Common\Controls\XmlViews\XmlViewsTests\TestColumns.xml")); m_columnList = docColumns.DocumentElement.ChildNodes; // Parts just has what those columns need. string partDirectory = Path.Combine(DirectoryFinder.FwSourceDirectory, @"Common\Controls\XmlViews\XmlViewsTests"); Dictionary<string, string[]> keyAttrs = new Dictionary<string, string[]>(); keyAttrs["layout"] = new string[] {"class", "type", "name" }; keyAttrs["group"] = new string[] {"label"}; keyAttrs["part"] = new string[] {"ref"}; // Currently there are no specialized layout files that match. m_layoutInventory = new Inventory(new string[] {partDirectory}, "*Layouts.xml", "/LayoutInventory/*", keyAttrs); keyAttrs = new Dictionary<string, string[]>(); keyAttrs["part"] = new string[] {"id"}; m_partInventory = new Inventory(new string[] {partDirectory}, "TestParts.xml", "/PartInventory/bin/*", keyAttrs); if (m_layouts != null) m_layouts.Dispose(); m_layouts = new LayoutCache(m_mdc, m_layoutInventory, m_partInventory); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the a text run from a string representation. /// </summary> /// <param name="wsf">The writing system factory.</param> /// <param name="strBldr">The structured string builder.</param> /// <param name="textNode">The text node which describes runs to be added to the /// paragraph or to the translation for a particular writing system</param> /// ------------------------------------------------------------------------------------ private void CreateRunFromStringRep(ILgWritingSystemFactory wsf, ITsIncStrBldr strBldr, XmlNode textNode) { XmlNode charStyle = textNode.Attributes.GetNamedItem("CS"); if (charStyle != null) strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, charStyle.Value); else strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); XmlNode wsICULocale = textNode.Attributes.GetNamedItem("WS"); if (wsICULocale != null) { int ws = wsf.GetWsFromStr(wsICULocale.Value); if (ws <= 0) throw new ArgumentException("Unknown ICU locale encountered: '" + wsICULocale.Value + "'"); strBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, wsf.GetWsFromStr(wsICULocale.Value)); } else throw new ArgumentException("Required attribute WS missing from RUN element."); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets (or makes) the writing system. If there isn't already one with this locale id, /// we assume there is an XML language definition we can load. /// </summary> /// ------------------------------------------------------------------------------------ public IWritingSystem EnsureRealWs(ILgWritingSystemFactory wsf) { if (wsf.GetWsFromStr(m_icuLocale) == 0) { // Need to create a new writing system from the XML file. LanguageDefinitionFactory ldf = new LanguageDefinitionFactory(wsf, m_icuLocale); string pathname = DirectoryFinder.LanguagesDirectory + "\\" + m_icuLocale + ".xml"; ldf.Deserialize(pathname); ldf.LanguageDefinition.SaveWritingSystem(m_icuLocale); } return wsf.get_EngineOrNull(wsf.GetWsFromStr(m_icuLocale)); }
public override void FixtureSetup() { CheckDisposed(); base.FixtureSetup(); Debug.Assert(m_fdoCache == null, "m_fdoCache is not null"); //if (m_fdoCache != null) // m_fdoCache.DisposeWithWSFactoryShutdown(); m_fdoCache = InDatabaseFdoTestBase.SetupCache(); ScrReferenceTests.InitializeScrReferenceForTests(); m_wsf = m_fdoCache.LanguageWritingSystemFactoryAccessor; m_wsf.BypassInstall = true; m_wsEn = m_wsf.GetWsFromStr("en"); m_factory = TsStrFactoryClass.Create(); }