/// <summary> /// Adds the default word-forming character overrides to the list of valid /// characters for each vernacular writing system that is using the old /// valid characters representation. /// </summary> /// <param name="cache">The cache.</param> void AddDefaultWordformingOverridesIfNeeded(FdoCache cache) { ILgWritingSystemFactory lgwsf = cache.LanguageWritingSystemFactoryAccessor; foreach (ILgWritingSystem wsObj in cache.LangProject.VernWssRC) { IWritingSystem ws = lgwsf.get_EngineOrNull(wsObj.Hvo); string validCharsSrc = ws.ValidChars; if (!ValidCharacters.IsNewValidCharsString(validCharsSrc)) { LanguageDefinition langDef = new LanguageDefinition(ws); ValidCharacters valChars = ValidCharacters.Load(langDef); valChars.AddDefaultWordformingCharOverrides(); ws.ValidChars = langDef.ValidChars = valChars.XmlString; using (new SuppressSubTasks(cache)) { ws.SaveIfDirty(cache.DatabaseAccessor); } langDef.Serialize(); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the "invalid" character as a valid character. /// </summary> /// <param name="addedCharError">The checking error containing the character that will /// be added to the valid character inventory.</param> /// ------------------------------------------------------------------------------------ private void AddAsValidCharacter(CheckingError addedCharError) { Debug.Assert(addedCharError.CheckId == StandardCheckIds.kguidCharacters, "Checking error should be from the valid characters check"); ILgWritingSystemFactory lgwsf = m_cache.LanguageWritingSystemFactoryAccessor; int hvoWs = m_cache.DefaultVernWs; IWritingSystem ws = lgwsf.get_EngineOrNull(hvoWs); LanguageDefinition langDef = new LanguageDefinition(ws); LgWritingSystem lgWs = new LgWritingSystem(m_cache, hvoWs); langDef.ValidChars = ws.ValidChars; if (StringUtils.IsCharacterDefined(addedCharError.CitedText)) { using (new WaitCursor(Parent)) { // Get the valid characters from the database ValidCharacters validChars = ValidCharacters.Load(langDef); if (validChars != null) { validChars.AddCharacter(addedCharError.CitedText); ws.ValidChars = langDef.ValidChars = validChars.XmlString; StringUtils.UpdatePUACollection(langDef, validChars.AllCharacters); ws.SaveIfDirty(m_cache.DatabaseAccessor); langDef.Serialize(); } // Mark all data grid view rows containing the newly-defined valid character to irrelevant. for (int iRow = 0; iRow < m_list.Count; iRow++) { CheckingError checkError = GetCheckingError(iRow); if (((StTxtPara)checkError.QuoteOA.ParagraphsOS[0]).Contents.Text == addedCharError.CitedText) { // We don't want to create an undoable action, so we suppress subtasks. using (SuppressSubTasks supressActionHandler = new SuppressSubTasks(m_cache, true)) checkError.Status = CheckingStatus.StatusEnum.Irrelevant; } } IsStale = true; m_dataGridView.Invalidate(); } } else { string msg = ResourceHelper.GetResourceString("kstidUndefinedCharacterMsg"); MessageBox.Show(this, msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Tests can override this to specify a temp location to store the output. /// </summary> /// <param name="finalLangDef"></param> /// ------------------------------------------------------------------------------------ protected virtual void Serialize(LanguageDefinition finalLangDef) { finalLangDef.Serialize(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Display the punctuation dialog box, using the specified guid to determine what /// tab on the dialog is initially brought to front. /// </summary> /// ------------------------------------------------------------------------------------ private void ShowPunctuationDialog(Guid initialTab) { ILgWritingSystemFactory lgwsf = m_cache.LanguageWritingSystemFactoryAccessor; int hvoWs = m_cache.DefaultVernWs; IWritingSystem ws = lgwsf.get_EngineOrNull(hvoWs); LanguageDefinition langDef = new LanguageDefinition(ws); LgWritingSystem lgWs = new LgWritingSystem(m_cache, hvoWs); using (PunctuationDlg dlg = new PunctuationDlg(m_cache, FwApp.App, langDef, lgWs.Name.UserDefaultWritingSystem, initialTab)) { if (dlg.ShowDialog(this) == DialogResult.OK) { ws.SaveIfDirty(m_cache.DatabaseAccessor); langDef.Serialize(); } } }
private static void SerializeAndGetReader(LanguageDefinition langDef, out MemoryStream stream, out XmlTextWriter xtw, out StreamReader sr) { stream = new MemoryStream(); xtw = new XmlTextWriter(stream, Encoding.UTF8); langDef.Serialize(xtw); xtw.Flush(); stream.Seek(0, SeekOrigin.Begin); sr = new StreamReader(stream); }
/// <summary> /// /// </summary> /// <param name="langDef"></param> internal static void SerializeToTempfile(LanguageDefinition langDef) { if (LanguageDefinitionFactory.WritingSystemFactory == null) LanguageDefinitionFactory.WritingSystemFactory = langDef.WritingSystem.WritingSystemFactory; string tmpFilename; if (!s_icuLocaleToTmpLangDefFiles.TryGetValue(langDef.WritingSystem.IcuLocale, out tmpFilename)) { tmpFilename = Path.GetTempFileName(); langDef.Serialize(tmpFilename); if (File.Exists(tmpFilename)) s_icuLocaleToTmpLangDefFiles.Add(langDef.WritingSystem.IcuLocale, tmpFilename); return; } langDef.Serialize(tmpFilename); }
public void SerializeAndDeserialize() { IWritingSystem ws = m_wsf.get_Engine("tl"); int wsIdTl = m_wsf.GetWsFromStr("tl"); ws.Locale = 13321; ws.DefaultMonospace = "Courier New"; ws.DefaultSansSerif = "Arial"; ws.DefaultBodyFont = "Charis SIL"; ws.DefaultSerif = "Times New Roman"; ws.set_Name(m_wsIdEn, "Tagalog"); ws.set_Name(wsIdTl, "Tagalog"); ws.set_Abbr(m_wsIdEn, "TGL"); ICollation coll = CollationClass.Create(); coll.WinLCID = 1033; coll.WinCollation = "Latin1_General_CI_AI"; coll.set_Name(m_wsIdEn, "Default Collation"); coll.WritingSystemFactory = m_wsf; ws.set_Collation(0, coll); LanguageDefinition langDef = new LanguageDefinition(ws); langDef.BaseLocale = "en_US"; langDef.XmlWritingSystem.WritingSystem.IcuLocale = "tl"; langDef.LocaleName = "Tagalog"; langDef.LocaleScript = ""; langDef.LocaleCountry = ""; langDef.LocaleVariant = ""; langDef.XmlWritingSystem.WritingSystem.Locale = 13321; langDef.CollationElements = "\"& B < ..."; langDef.ValidChars = "abcdefg"; langDef.LocaleResources = @" zoneStrings { { 'Europe/London', 'Greenwich Mean Time', } }"; CharDef[] charDefs = new CharDef[2]; charDefs[0] = new CharDef(0xF170, "COMBINING SNAKE BELOW;Mn;202;NSM;;;;"); charDefs[1] = new CharDef(0xF210, "LATIN SMALL LETTER P WITH STROKE;Ll;0;L;;;;"); langDef.PuaDefinitions = charDefs; FileName[] fonts = new FileName[4]; fonts[0] = new FileName("arial.ttf"); fonts[1] = new FileName("arialbd.ttf"); fonts[2] = new FileName("ariali.ttf"); fonts[3] = new FileName("arialbi.ttf"); langDef.Fonts = fonts; langDef.Keyboard = new FileName("Tagalog.kmx"); langDef.EncodingConverter = new EncodingConverter("SIL_IPA93.tec.vbs", "SIL-IPA93.tec"); string tmpFileName = Path.GetTempFileName(); langDef.Serialize(tmpFileName); LanguageDefinitionFactory otherIcuWs = new LanguageDefinitionFactory(); LanguageDefinitionFactory.WritingSystemFactory = m_wsf; otherIcuWs.Deserialize(tmpFileName); ILanguageDefinition newLangDef = otherIcuWs.LanguageDefinition; IWritingSystem deserializedWs = newLangDef.WritingSystem; ICollation deserializedColl = newLangDef.GetCollation(0); StreamReader reader = new StreamReader(tmpFileName); string line = reader.ReadLine(); while (line != null) { Console.WriteLine(line); line = reader.ReadLine(); } reader.Close(); File.Delete(tmpFileName); Assert.AreEqual(ws.Locale, deserializedWs.Locale); Assert.AreEqual(ws.IcuLocale, deserializedWs.IcuLocale); Assert.AreEqual(ws.DefaultSansSerif, deserializedWs.DefaultSansSerif); Assert.AreEqual(ws.DefaultBodyFont, deserializedWs.DefaultBodyFont); Assert.AreEqual(ws.get_Name(m_wsIdEn), deserializedWs.get_Name(m_wsIdEn)); Assert.AreEqual(coll.WinLCID, deserializedColl.WinLCID); Assert.AreEqual(coll.WinCollation, deserializedColl.WinCollation); // ENHANCE: Add ValidChars to the interface // Assert.AreEqual(ws.ValidChars, deserializedWs.ValidChars); Assert.AreEqual(coll.get_Name(m_wsIdEn), deserializedColl.get_Name(m_wsIdEn)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Display the valid characters dialog box. Return true if OK was chosen. /// </summary> /// ------------------------------------------------------------------------------------ public static bool RunDialog(FdoCache cache, IWin32Window owner, IHelpTopicProvider helpTopicProvider) { ILgWritingSystemFactory lgwsf = cache.LanguageWritingSystemFactoryAccessor; int hvoWs = cache.DefaultVernWs; IWritingSystem ws = lgwsf.get_EngineOrNull(hvoWs); LanguageDefinition langDef = new LanguageDefinition(ws); LgWritingSystem lgWs = new LgWritingSystem(cache, hvoWs); langDef.ValidChars = ws.ValidChars; string sWsName = lgWs.Name.UserDefaultWritingSystem; if (String.IsNullOrEmpty(sWsName)) sWsName = lgWs.Name.BestAnalysisAlternative.Text; if (String.IsNullOrEmpty(sWsName) || sWsName == lgWs.Name.NotFoundTss.Text) sWsName = lgWs.Name.BestVernacularAlternative.Text; using (ValidCharactersDlg dlg = new ValidCharactersDlg(cache, helpTopicProvider, langDef, sWsName)) { if (dlg.ShowDialog(owner) == DialogResult.OK) { ws.ValidChars = langDef.ValidChars; ws.SaveIfDirty(cache.DatabaseAccessor); langDef.Serialize(); return true; } } return false; }