private string WritingSystemId(int ws) { if (ws == 0) { return(String.Empty); } string sWs; if (m_dictWsStr.TryGetValue(ws, out sWs)) { return(sWs); } if (m_fUseRFC4646) { ILgWritingSystem lgws = LgWritingSystem.CreateFromDBObject(m_cache, ws); sWs = lgws.RFC4646bis; } else { sWs = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(ws); } sWs = XmlUtils.MakeSafeXmlAttribute(sWs); m_dictWsStr.Add(ws, sWs); return(sWs); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get a string that describes the Scripture passage based on the selection. /// </summary> /// <param name="tag">The flid of the selected element</param> /// <param name="hvoSel">The hvo of the selected element, either a ScrSection (usually) /// or ScrBook (if in a title)</param> /// <param name="fSimpleFormat">Gets a simple, standardized reference (uses SIL 3-letter /// codes and no verse bridges)</param> /// <returns> /// String that describes the Scripture passage or null if the selection /// can't be interpreted as a book and/or section reference. /// </returns> /// ------------------------------------------------------------------------------------ public override string GetPassageAsString(int tag, int hvoSel, bool fSimpleFormat) { CheckDisposed(); if (m_cache == null) { return(null); } string sEditRef = null; // Title/reference/etc of text being edited in the draft pane switch (tag) { case (int)ScrBook.ScrBookTags.kflidFootnotes: { ScrBook book = new ScrBook(m_cache, hvoSel, false, false); sEditRef = (fSimpleFormat ? (book.BookId + " 0:0") : book.BestUIName); break; } default: return(base.GetPassageAsString(tag, hvoSel, fSimpleFormat)); } // Add the back translation writing system info to the output string, if needed if (IsBackTranslation) { LgWritingSystem ws = new LgWritingSystem(m_cache, ViewConstructorWS); sEditRef = string.Format( TeResourceHelper.GetResourceString("kstidCaptionInBackTrans"), sEditRef, ws.Name.UserDefaultWritingSystem); } return(string.IsNullOrEmpty(sEditRef) ? null : sEditRef); }
public ITsString WsLabel(FdoCache cache) { if (m_tssWsLabel == null) { ITsPropsFactory tpf = TsPropsFactoryClass.Create(); ITsTextProps ttp = tpf.MakeProps("Language Code", cache.DefaultUserWs, 0); ITsStrFactory tsf = TsStrFactoryClass.Create(); string label = null; if (m_ws == LangProject.kwsFirstAnal) { label = ITextStrings.ksBstAn; } else if (m_ws == LangProject.kwsVernInParagraph) { label = ITextStrings.ksBaselineAbbr; } else { LgWritingSystem wsAnalysis = new LgWritingSystem(cache, m_ws); label = wsAnalysis.Abbr.UserDefaultWritingSystem; } m_tssWsLabel = tsf.MakeStringWithPropsRgch(label, label.Length, ttp); } return(m_tssWsLabel); }
private void SetupWritingSystemsForTitle(FdoCache cache) { m_ttpWsLabel = LgWritingSystem.AbbreviationTextProperties; m_writingSystems = new LgWritingSystem[2]; m_writingSystems[0] = new LgWritingSystem(cache, cache.DefaultVernWs); m_writingSystems[1] = new LgWritingSystem(cache, cache.DefaultAnalWs); m_WsLabels = new ITsString[m_writingSystems.Length]; int wsEn = cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"); if (wsEn == 0) { wsEn = cache.DefaultUserWs; } if (wsEn == 0) { wsEn = cache.FallbackUserWs; } for (int i = 0; i < m_writingSystems.Length; i++) { //m_WsLabels[i] = LgWritingSystem.UserAbbr(cache, m_writingSystems[i].Hvo); // For now (August 2008), try English abbreviation before UI writing system. // (See LT-8185.) m_WsLabels[i] = cache.GetMultiStringAlt(m_writingSystems[i].Hvo, (int)LgWritingSystem.LgWritingSystemTags.kflidAbbr, wsEn); if (String.IsNullOrEmpty(m_WsLabels[i].Text)) { m_WsLabels[i] = LgWritingSystem.UserAbbr(cache, m_writingSystems[i].Hvo); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="hvos"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private void AddWritingSystems(int[] hvos) { string langId = string.Empty; string langName = string.Empty; foreach (int hvo in hvos) { if (hvo == InMemoryFdoCache.s_wsHvos.En) { langId = "en"; langName = "English"; } else if (hvo == InMemoryFdoCache.s_wsHvos.Es) { langId = "es"; langName = "Spanish"; } else if (hvo == InMemoryFdoCache.s_wsHvos.Fr) { langId = "Fr"; langName = "French"; } else if (hvo == InMemoryFdoCache.s_wsHvos.Ipa) { langId = "en__IPA"; langName = "English IPA"; } LgWritingSystem ws = new LgWritingSystem(m_inMemoryCache.Cache, hvo); ws.ICULocale = langId; m_inMemoryCache.Cache.SetMultiUnicodeAlt(hvo, (int)LgWritingSystem.LgWritingSystemTags.kflidName, InMemoryFdoCache.s_wsHvos.En, langName); } }
internal void SetupVernWsForText(int wsVern) { m_wsDefault = wsVern; LgWritingSystem defWs = new LgWritingSystem(Cache, wsVern); RightToLeft = defWs.RightToLeft; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create test data in a right-to-left script. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { // Set the default writing system to a right-to-left writing system (Urdu) m_wsUrdu = InMemoryFdoCache.s_wsHvos.Ur; m_scrInMemoryCache.ChangeDefaultVernWs(m_wsUrdu); LgWritingSystem defWs = new LgWritingSystem(Cache, Cache.DefaultVernWs); // Add basic data for Genesis m_genesis = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_scrInMemoryCache.AddTitleToMockedBook(1, m_StartText); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, null); m_scrInMemoryCache.AddFormatTextToMockedPara(m_genesis, para, @"\c12\v13-14\*" + m_WordsText, m_wsUrdu); section.AdjustReferences(); // Add footnote ITsTextProps normalFootnoteParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); StFootnote footnote = m_scrInMemoryCache.AddFootnote(m_genesis, para, 10); StTxtPara footPara = new StTxtPara(); footnote.ParagraphsOS.Append(footPara); footPara.StyleRules = normalFootnoteParaProps; ITsStrFactory strfact = TsStrFactoryClass.Create(); footPara.Contents.UnderlyingTsString = strfact.MakeString(m_WordsText, m_wsUrdu); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Raises the visible changed event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event /// data.</param> /// ------------------------------------------------------------------------------------ protected override void OnVisibleChanged(EventArgs e) { base.OnVisibleChanged(e); if (!Visible || Disposing) { return; } if (DesignMode) { return; } if (m_cache == null) { throw new InvalidOperationException("Cache must be set before showing the FwMultilingualPropView named " + Name); } if (m_hvoRootObject == 0) { throw new InvalidOperationException("Root object must be set before showing the FwMultilingualPropView named " + Name); } if (m_fieldsToDisplay.Count == 0) { throw new InvalidOperationException("At least one field must be added to the FieldsToDisplay property before showing the FwMultilingualPropView named " + Name); } if (m_writingSystemsToDisplay.Count == 0) { throw new InvalidOperationException("At least one writing system must be added to the WritingSystemsToDisplay property before showing the FwMultilingualPropView named " + Name); } // Add column headers foreach (ColumnInfo colInfo in m_fieldsToDisplay) { AddColumn(colInfo.name, colInfo.widthPct); } int iRow = 0; foreach (int ws in m_writingSystemsToDisplay) { Rows.Add(new FwTextBoxRow(ws)); LgWritingSystem lgws = new LgWritingSystem(m_cache, ws); Rows[iRow].Cells[0].Value = lgws.Abbreviation; int iCol = 1; foreach (ColumnInfo colInfo in m_fieldsToDisplay) { AddStringToCell(ws, colInfo.flid, iRow, iCol++); } iRow++; } AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCells); AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); // Now set the current cell to the second column so that we skip the (read-only) // language name. CurrentCell = CurrentRow.Cells[1]; }
public void GetFontFaceNameFromStyle() { CheckDisposed(); // Get the default font names LgWritingSystem ws = new LgWritingSystem(m_fdoCache, m_fdoCache.DefaultVernWs); string defaultSerif = ws.DefaultSerif; string defaultSansSerif = ws.DefaultSansSerif; // do the tests m_styleSheet.SetStyleFont("Section Head", "Helvetica"); Assert.AreEqual("Helvetica", m_styleSheet.GetFaceNameFromStyle("Section Head", m_fdoCache.LangProject.DefaultVernacularWritingSystem, m_wsf)); m_styleSheet.SetStyleFont("Paragraph", "Symbol"); Assert.AreEqual("Symbol", m_styleSheet.GetFaceNameFromStyle("Paragraph", m_fdoCache.LangProject.DefaultVernacularWritingSystem, m_wsf)); m_styleSheet.SetStyleFont("Intro Section Head", StStyle.DefaultHeadingFont); Assert.AreEqual(defaultSansSerif, m_styleSheet.GetFaceNameFromStyle( "Intro Section Head", m_fdoCache.LangProject.DefaultVernacularWritingSystem, m_wsf)); m_styleSheet.SetStyleFont("Intro Paragraph", StStyle.DefaultFont); Assert.AreEqual(defaultSerif, m_styleSheet.GetFaceNameFromStyle("Intro Paragraph", m_fdoCache.LangProject.DefaultVernacularWritingSystem, m_wsf)); }
/// <summary> /// Return an array of writing systems given an array of their HVOs. /// </summary> /// <returns></returns> private ILgWritingSystem[] WssFromHvos(int[] hvos) { ILgWritingSystem[] result = new LgWritingSystem[hvos.Length]; for (int i = 0; i < hvos.Length; i++) { result[i] = new LgWritingSystem(m_lp.Cache, hvos[i]); } return(result); }
public void GetParameterValue_VerseBridge() { ILgWritingSystem lgws = new LgWritingSystem(Cache, Cache.DefaultVernWs); lgws.RightToLeft = true; Assert.AreEqual("\u200f-\u200f", m_dataSource.GetParameterValue("Verse Bridge")); lgws.RightToLeft = false; Assert.AreEqual("-", m_dataSource.GetParameterValue("Verse Bridge")); }
public static ITsString WsLabel(FdoCache cache, int ws) { ITsPropsFactory tpf = TsPropsFactoryClass.Create(); ITsTextProps ttp = tpf.MakeProps("Language Code", cache.DefaultUserWs, 0); ILgWritingSystem wsObj = LgWritingSystem.CreateFromDBObject(cache, ws); ITsStrFactory tsf = TsStrFactoryClass.Create(); string sAbbr = wsObj.Abbr.UserDefaultWritingSystem; return(tsf.MakeStringWithPropsRgch(sAbbr, sAbbr.Length, ttp)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new Vernacular writing system based on the name given. /// </summary> /// ------------------------------------------------------------------------------------ protected void CreateVernacularWritingSystem(FdoCache cache) { string icuLocale = (m_vernWrtSys == null) ? "fr" : m_vernWrtSys.IcuLocale; LgWritingSystem wsVern = FindOrCreateWs(cache, icuLocale); // Add the writing system to the list of Vernacular writing systems and make it the // first one in the list of current Vernacular writing systems. cache.LangProject.VernWssRC.Add(wsVern); cache.LangProject.CurVernWssRS.InsertAt(wsVern, 0); }
private string LanguageCode(int ws) { string sLang; if (!m_mapWsToRFC.TryGetValue(ws, out sLang)) { // "magic" (and other invalid) codes shouldn't sneak through to here, but if // they do, we don't want to crash! See TE-7708 and TE-7727. int wsReal; switch (ws) { case LangProject.kwsAnal: case LangProject.kwsAnals: case LangProject.kwsAnalVerns: case LangProject.kwsFirstAnal: case LangProject.kwsFirstAnalOrVern: wsReal = m_cache.DefaultAnalWs; break; case LangProject.kwsVern: case LangProject.kwsVerns: case LangProject.kwsVernAnals: case LangProject.kwsFirstVern: case LangProject.kwsFirstVernOrAnal: case LangProject.kwsVernInParagraph: case LangProject.kwsFirstVernOrNamed: wsReal = m_cache.DefaultVernWs; break; case LangProject.kwsPronunciation: case LangProject.kwsFirstPronunciation: case LangProject.kwsPronunciations: wsReal = m_cache.DefaultPronunciationWs; break; default: // Anything invalid that we don't recognize is treated as vernacular. if (ws <= 0) { wsReal = m_cache.DefaultVernWs; } else { wsReal = ws; } break; } LgWritingSystem lgws = LgWritingSystem.CreateFromDBObject(m_cache, wsReal) as LgWritingSystem; sLang = lgws.RFC4646bis; m_mapWsToRFC.Add(ws, sLang); } return(sLang); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor /// </summary> /// <param name="page">Page info</param> /// <param name="wsDefault">default writing system</param> /// <param name="printDateTime">Printing date/time</param> /// <param name="cache">The cache.</param> /// ------------------------------------------------------------------------------------ public HeaderFooterVc(IPageInfo page, int wsDefault, DateTime printDateTime, FdoCache cache) { m_page = page; m_wsDefault = wsDefault; m_printDateTime = printDateTime; m_cache = cache; LgWritingSystem defWs = new LgWritingSystem(m_cache, m_wsDefault); RightToLeft = defWs.RightToLeft; }
/// <summary> /// Convert the RFC language code (string) to an ICU locale (string). /// </summary> /// <param name="sRFC"></param> /// <returns></returns> public string ConvertFromRFCtoICU(string sRFC) { if (m_mapRFCtoICU.ContainsKey(sRFC)) { return(m_mapRFCtoICU[sRFC]); } string sICU = LgWritingSystem.ConvertRFC4646ToICU(sRFC); m_mapRFCtoICU[sRFC] = sICU; return(sICU); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Computes the settings. /// </summary> /// <param name="normalStyle">The normal style.</param> /// <param name="ws">The HVO of the vernacular writing system.</param> /// ------------------------------------------------------------------------------------ private void ComputeSettings(UsfmStyEntry normalStyle, int ws) { FontInfo fontInfo = normalStyle.FontInfoForWs(ws); m_fontName = normalStyle.RealFontNameForWs(ws); m_fontSize = (fontInfo.m_fontSize.Value / 1000).ToString(); LgWritingSystem lgws = new LgWritingSystem(m_cache, ws); m_wsName = lgws.Name.UserDefaultWritingSystem; m_RtoL = (lgws.RightToLeft ? "T" : "F"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Computes the settings. /// </summary> /// <param name="format">The format.</param> /// <param name="projPath">The proj path.</param> /// <param name="ws">The ws.</param> /// ------------------------------------------------------------------------------------ private void ComputeSettings(FileNameFormat format, string projPath, int ws) { m_projPath = projPath.Trim(); LgWritingSystem lgws = new LgWritingSystem(m_cache, ws); m_wsName = lgws.Name.UserDefaultWritingSystem; m_fileScheme = format.ParatextFileScheme; m_sPostPart = format.m_fileSuffix + "." + format.m_fileExtension; m_sPrePart = format.m_filePrefix; m_LtoR = (lgws.RightToLeft ? "F" : "T"); m_versification = ((int)m_cache.LangProject.TranslatedScriptureOA.Versification).ToString(); }
public void UpdateParatextLdsFile_GeneralSectionMissing() { if (File.Exists("test.lds")) { File.Delete("test.lds"); } int wsHvo = Cache.DefaultVernWs; LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo); vernWs.Name.UserDefaultWritingSystem = "French"; DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry(); StyleInfoTable styleTable = new StyleInfoTable("Normal", Cache.LanguageWritingSystemFactoryAccessor); styleTable.Add("Normal", normalEntry); normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000; normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings"; string ldsContentsOrig = "[OtherStuff]"; DummyFileWriter writer = new DummyFileWriter(); writer.Open("test.lds"); ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache); ReflectionHelper.CallMethod(ldsAccessor, "UpdateLdsContents", ldsContentsOrig, normalEntry, Cache.DefaultVernWs, writer); // Verify the .lds file string[] expectedLdsContents = { "[OtherStuff]", //Environment.NewLine + "[General]", "codepage=65001", "font=Wingdings", "size=14", "name=French", "RTL=F" }; writer.VerifyOutput(expectedLdsContents); }
public void WriteParatextLdsFile() { if (File.Exists("test.lds")) { File.Delete("test.lds"); } int wsHvo = Cache.DefaultVernWs; LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo); vernWs.Name.UserDefaultWritingSystem = "French"; DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry(); StyleInfoTable styleTable = new StyleInfoTable("Normal", Cache.LanguageWritingSystemFactoryAccessor); styleTable.Add("Normal", normalEntry); normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000; normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings"; ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache); DummyFileWriter actualLds = new DummyFileWriter(); ReflectionHelper.CallMethod(ldsAccessor, "WriteParatextLdsFile", "test.lds", Cache.DefaultVernWs, normalEntry, actualLds); // Verify the .lds file string[] expectedLds = { "[General]", "codepage=65001", "RTL=F", "font=Wingdings", "name=French", "size=14", string.Empty, "[Checking]", string.Empty, "[Characters]", string.Empty, "[Punctuation]" }; actualLds.VerifyOutput(expectedLds); }
private void CreateReversalIndexDlg_FormClosing(object sender, FormClosingEventArgs e) { switch (DialogResult) { default: { Debug.Assert(false, "Unexpected DialogResult."); break; } case DialogResult.Cancel: { if (!m_btnCancel.Visible) { e.Cancel = true; MessageBox.Show(LexEdStrings.ksMustSelectOne); } break; } case DialogResult.OK: { NamedWritingSystem nws = m_cbWritingSystems.SelectedItem as NamedWritingSystem; if (nws != null) { ILgWritingSystem lgws = LgWritingSystem.CreateFromDBObject(m_cache, nws.Hvo); IReversalIndex newIdx = m_cache.LangProject.LexDbOA.ReversalIndexesOC.Add(new ReversalIndex()); newIdx.WritingSystemRA = lgws; // Copy any and all alternatives from lgws.Name to newIdx.Name // LT-4907 dies here. foreach (ILgWritingSystem lgwsLoop in m_cache.LanguageEncodings) { string lgsNameAlt = lgws.Name.GetAlternative(lgwsLoop.Hvo); if (lgsNameAlt != null && lgsNameAlt.Length > 0) { newIdx.Name.SetAlternative(lgsNameAlt, lgws.Hvo); } } m_hvoRevIdx = newIdx.Hvo; } break; } } }
public void VernacularWsListAdd() { m_inMemoryCache.InitializeWritingSystemEncodings(); // Setup so the order in the Analysis WS list should be: English, French, // English IPA and Spanish. SetupVernWss(); // Disable all these buttons so we can verify that they will be enabled after // adding a new writing system. m_dlg.OkButton.Enabled = false; m_dlg.VernWsDeleteButton.Enabled = false; m_dlg.VernWsModifyButton.Enabled = false; m_dlg.VernWsMoveUpButton.Enabled = false; m_dlg.VernWsMoveDownButton.Enabled = false; // Add a new writing system to the cache. int newWsHvo = m_inMemoryCache.SetupWs("no"); LgWritingSystem ws = m_inMemoryCache.CreateWritingSystem(m_inMemoryCache.Cache, newWsHvo, "no", new int[] { (int)InMemoryFdoCache.s_wsHvos.En }, new string[] { "new one" }); m_dlg.SimulateVernAddingWs(ws); VerifyWritingSystemOrder(m_dlg.VernWsList, new string[] { "English", "French", "English IPA", "Spanish", "new one" }); // Verify that the new writing system is the selected one. Assert.AreEqual(ws, (LgWritingSystem)m_dlg.VernWsList.SelectedItem, "New writing system is not selected."); // Verify that the correct items are checked. VerifyCheckedWritingSystems(m_dlg.VernWsList, new string[] { "English", "French", "new one" }, true); // Verify that the correct items are not checked. VerifyCheckedWritingSystems(m_dlg.VernWsList, new string[] { "English IPA", "Spanish" }, false); Assert.IsTrue(m_dlg.OkButton.Enabled); Assert.IsTrue(m_dlg.VernWsDeleteButton.Enabled); Assert.IsTrue(m_dlg.VernWsModifyButton.Enabled); Assert.IsTrue(m_dlg.VernWsMoveUpButton.Enabled); Assert.IsTrue(m_dlg.VernWsMoveDownButton.Enabled); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the ws specific font info to the style description /// </summary> /// <param name="text">The text description to append to</param> /// ------------------------------------------------------------------------------------ private void AddWsSpecificFontInfo(StringBuilder text) { if (m_style == null) { return; } text.AppendLine(); foreach (KeyValuePair <int, FontInfo> wsInfo in m_fontInfoOverrides) { if (wsInfo.Value.IsAnyExplicit) { LgWritingSystem ws = new LgWritingSystem(m_style.Cache, wsInfo.Key); text.Append(ws.Name.UserDefaultWritingSystem); text.Append(": "); text.Append(wsInfo.Value.ToString()); text.AppendLine(); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set an analysis writing system in the database and create one if needed. /// </summary> /// ------------------------------------------------------------------------------------ private void CreateAnalysisWritingSystem(FdoCache cache) { string icuLocale = (m_analWrtSys == null) ? "en" : m_analWrtSys.IcuLocale; LgWritingSystem wsAnalysis = FindOrCreateWs(cache, icuLocale); // Add the writing system to the list of Analysis writing systems and make it the // first one in the list of current Analysis writing systems. cache.LangProject.AnalysisWssRC.Add(wsAnalysis); cache.LangProject.CurAnalysisWssRS.InsertAt(wsAnalysis, 0); // hard wire to "en" for now - future should be below: "UserWs" if ("en" != icuLocale) { // TE-985: Don't need to tell the user we're doing this when they don't have a choice anyway. // // show the message box with the information about adding it. // string msg = (res != null) ? res.GetString("kstidAutoAddEnglish") : string.Empty; // string caption = (res != null) ? string.Format(res.GetString("kstidCreateLangProjCaption"), // ProjectName) : string.Empty; // // MessageBox.Show(msg, caption, MessageBoxButtons.OK, // MessageBoxIcon.Information); // Add the "en" writing system to the list of Analysis writing systems and // append it to the the list of current Analysis writing systems. LgWritingSystem lgwsEN = FindOrCreateWs(cache, "en"); cache.LangProject.AnalysisWssRC.Add(lgwsEN); cache.LangProject.CurAnalysisWssRS.Append(lgwsEN); } // // get UI writing system // int wsUser = cache.LanguageWritingSystemFactoryAccessor.UserWs; // string icuUILocale = cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(wsUser); // if (icuUILocale != icuLocale) // { // // Add the UI writing system to the list of Vernacular writing systems // LgWritingSystem lgwsUI = FindOrCreateWs(cache, icuUILocale); // cache.LangProject.AnalysisWssRC.Add(lgwsUI); // } }
private void ExportWsAsLDML(string sDirectory) { LdmlInFolderWritingSystemStore ldmlstore = new LdmlInFolderWritingSystemStore(sDirectory); ldmlstore.DontAddDefaultDefinitions = true; Set <int> rgwsWritten = new Set <int>(); foreach (LgWritingSystem lgws in m_cache.LangProject.VernWssRC) { ExportLDML(lgws, ldmlstore); rgwsWritten.Add(lgws.Hvo); } foreach (LgWritingSystem lgws in m_cache.LangProject.AnalysisWssRC) { if (!rgwsWritten.Contains(lgws.Hvo)) { ExportLDML(lgws, ldmlstore); rgwsWritten.Add(lgws.Hvo); } } foreach (NamedWritingSystem nws in m_cache.LangProject.GetPronunciationWritingSystems()) { if (nws.Hvo > 0 && !rgwsWritten.Contains(nws.Hvo)) { LgWritingSystem lgws = LgWritingSystem.CreateFromDBObject(m_cache, nws.Hvo) as LgWritingSystem; ExportLDML(lgws, ldmlstore); rgwsWritten.Add(nws.Hvo); } } foreach (ReversalIndex ri in m_cache.LangProject.LexDbOA.ReversalIndexesOC) { if (ri.WritingSystemRAHvo > 0 && !rgwsWritten.Contains(ri.WritingSystemRAHvo)) { ExportLDML(ri.WritingSystemRA as LgWritingSystem, ldmlstore); rgwsWritten.Add(ri.WritingSystemRAHvo); } } }
public void DisplayOrCreateEntry_EmptyString() { // Create a WfiWordform with some string. // We need this wordform to get a real hvo, flid, and ws. // Make Spanish be the vern ws. LgWritingSystem spanish = Cache.GetObject(Cache.WritingSystemFactory.GetWsFromStr("es")) as LgWritingSystem; Cache.LanguageProject.VernWssRC.Add(spanish); Cache.LanguageProject.CurVernWssRS.Add(spanish); Cache.LanguageProject.CurAnalysisWssRS.Remove(spanish); Cache.LanguageProject.AnalysisWssRC.Remove(spanish); int defVernWs = spanish.Hvo; ITsString form = Cache.TsStrFactory.MakeString(String.Empty, defVernWs); WfiWordform wf = new WfiWordform(); Cache.LanguageProject.WordformInventoryOA.WordformsOC.Add(wf); wf.FormAccessor.set_String(defVernWs, form); // We shouldn't get an exception if we call DisplayOrCreateEntry with an empty string LexEntryUi.DisplayOrCreateEntry(Cache, wf.Hvo, (int)WfiWordform.WfiWordformTags.kflidForm, defVernWs, 0, 0, null, null, null, null); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get an encoding converter for a mapping /// </summary> /// <param name="icuLocale">An ICU Locale</param> /// <param name="marker">The marker whose data is to be converted (used only for /// error reporting)</param> /// <returns>the encoding converter for the writing system of the mapping's ICU locale /// </returns> /// ------------------------------------------------------------------------------------ private IEncConverter GetEncodingConverterForLocale(string icuLocale, string marker) { // If an entry already exists, then just look it up and return it if (m_icuLocaleToConverterMap.ContainsKey(icuLocale)) { return(m_icuLocaleToConverterMap[icuLocale]); } // If there is no entry, then find the writing system with the ICU locale, get its // converter name and get a converter for that name. ILgWritingSystem ws = new LgWritingSystem(Cache, Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(icuLocale)); IEncConverter converter = null; if (ws.LegacyMapping != null) { try { converter = (IEncConverter)m_encConverters[ws.LegacyMapping]; } catch { // Something bad happened... Try to carry on. // This is a workaround until TE-5068 is fixed. converter = null; } if (converter == null) { throw new EncodingConverterException(string.Format(ScriptureUtilsException.GetResourceString( "kstidEncConvMissingConverter"), m_lineNumber, m_currentFile.FileName, ws.LegacyMapping, marker), "/Beginning_Tasks/Import_Standard_Format/Unable_to_Import/Encoding_converter_not_found.htm"); } } m_icuLocaleToConverterMap[icuLocale] = converter; return(converter); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the Writiing System selector combo box /// </summary> /// ------------------------------------------------------------------------------------ public void UpdateWritingSystemSelectorForSelection(IVwRootBox rootbox) { ComboBox box = WritingSystemSelector; if (box == null || rootbox == null) { return; } int hvoWs = SelectionHelper.GetFirstWsOfSelection(rootbox.Selection); if (hvoWs == 0) { box.SelectedIndex = -1; return; } LgWritingSystem lgws = new LgWritingSystem(Cache, hvoWs); if (lgws == null) { box.SelectedIndex = -1; return; } box.SelectedIndex = box.FindString(lgws.ShortName); }
/// <summary> /// This is the basic method needed for the view constructor. /// </summary> public override void Display(IVwEnv vwenv, int hvo, int frag) { switch (frag) { case VectorReferenceView.kfragTargetVector: // Check for an empty vector. if (hvo == 0 || m_cache.DomainDataByFlid.get_VecSize(hvo, m_flid) == 0) { vwenv.set_IntProperty((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); vwenv.set_IntProperty((int)FwTextPropType.ktptLeadingIndent, (int)FwTextPropVar.ktpvMilliPoint, 18000); vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvDefault, (int)TptEditable.ktptNotEditable); vwenv.set_IntProperty((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalRight); //vwenv.AddString(m_cache.MakeUserTss("Click to select -->")); if (hvo != 0) { vwenv.NoteDependency(new[] { hvo }, new[] { m_flid }, 1); } } else { if (!string.IsNullOrEmpty(TextStyle)) { vwenv.set_StringProperty((int)FwTextPropType.ktptNamedStyle, TextStyle); } vwenv.OpenParagraph(); vwenv.AddObjVec(m_flid, this, frag); vwenv.CloseParagraph(); } break; case VectorReferenceView.kfragTargetObj: // Display one object from the vector. { ILgWritingSystemFactory wsf = m_cache.WritingSystemFactory; vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvDefault, (int)TptEditable.ktptNotEditable); ITsString tss; Debug.Assert(hvo != 0); #if USEBESTWS if (m_displayWs != null && m_displayWs.StartsWith("best")) { // The flid can be a variety of types, so deal with those. Debug.WriteLine("Using 'best ws': " + m_displayWs); int magicWsId = LgWritingSystem.GetMagicWsIdFromName(m_displayWs); int actualWS = m_cache.LanguageProject.ActualWs(magicWsId, hvo, m_flid); Debug.WriteLine("Actual ws: " + actualWS.ToString()); } else { #endif // Use reflection to get a prebuilt name if we can. Otherwise // settle for piecing together a string. Debug.Assert(m_cache != null); var obj = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvo); Debug.Assert(obj != null); Type type = obj.GetType(); System.Reflection.PropertyInfo pi = type.GetProperty("TsName", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy); if (pi != null) { tss = (ITsString)pi.GetValue(obj, null); } else { if (!string.IsNullOrEmpty(m_displayNameProperty)) { pi = type.GetProperty(m_displayNameProperty, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy); } int ws = wsf.GetWsFromStr(obj.SortKeyWs); if (ws == 0) { ws = m_cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle; } if (pi != null) { object s = pi.GetValue(obj, null); if (s is ITsString) { tss = (ITsString)s; } else { tss = TsStringUtils.MakeString((string)s, ws); } } else { // ShortNameTss sometimes gets PropChanged, so worth letting the view know that's // what we're inserting. var flid = Cache.MetaDataCacheAccessor.GetFieldId2(obj.ClassID, "ShortNameTSS", true); vwenv.AddStringProp(flid, this); break; } #if USEBESTWS } #endif } if (!string.IsNullOrEmpty(TextStyle)) { vwenv.set_StringProperty((int)FwTextPropType.ktptNamedStyle, TextStyle); } vwenv.AddString(tss); } break; default: throw new ArgumentException( "Don't know what to do with the given frag.", "frag"); } }
/// <summary> /// Write the ITsString out. /// </summary> /// <param name="tssPara"></param> /// <param name="cchIndent"></param> /// <remarks>TODO: this maybe should go into a generic method somewhere? /// Except that part of it is specific to XHTML output...</remarks> private void WriteTsStringAsXml(ITsString tssPara, int cchIndent) { // First, build the indentation. StringBuilder bldr = new StringBuilder(); while (cchIndent > 0) { bldr.Append(" "); --cchIndent; } string sIndent = bldr.ToString(); bldr.Append(" "); string sIndent2 = bldr.ToString(); m_writer.WriteLine("{0}<Str>", sIndent); int crun = tssPara.RunCount; string sField = null; for (int irun = 0; irun < crun; ++irun) { TsRunInfo tri; ITsTextProps ttpRun = tssPara.FetchRunInfo(irun, out tri); int ctip = ttpRun.IntPropCount; int ctsp = ttpRun.StrPropCount; string sFieldRun = ttpRun.GetStrPropValue((int)FwTextPropType.ktptFieldName); if (sFieldRun != sField) { if (!String.IsNullOrEmpty(sField)) { m_writer.WriteLine("{0}</Field>", sIndent2); } if (!String.IsNullOrEmpty(sFieldRun)) { m_writer.WriteLine("{0}<Field name=\"{1}\">", sIndent2, sFieldRun); } sField = sFieldRun; sFieldRun = null; } bool fMarkItem; int tpt; string sVal; bool fSkipText = false; int nVar; int nVal = ttpRun.GetIntPropValues((int)FwTextPropType.ktptMarkItem, out nVar); if (nVal == (int)FwTextToggleVal.kttvForceOn && nVar == (int)FwTextPropVar.ktpvEnum) { m_writer.Write("{0}<Item><Run", sIndent2); fMarkItem = true; } else { m_writer.Write("{0}<Run", sIndent2); fMarkItem = false; } for (int itip = 0; itip < ctip; ++itip) { nVal = ttpRun.GetIntProp(itip, out tpt, out nVar); if (tpt == (int)FwTextPropType.ktptWs || tpt == (int)FwTextPropType.ktptBaseWs) { if (nVal != 0) { ILgWritingSystem lgws = LgWritingSystem.CreateFromDBObject(m_cache, nVal); m_writer.Write(" {0}=\"{1}\"", tpt == (int)FwTextPropType.ktptWs ? "ws" : "wsBase", lgws.RFC4646bis); } } else if (tpt != (int)FwTextPropType.ktptMarkItem) { WriteIntTextProp(m_writer, m_cache.LanguageWritingSystemFactoryAccessor, tpt, nVar, nVal); } } string sRun = tssPara.get_RunText(irun); Guid guidFootnote = Guid.Empty; for (int itsp = 0; itsp < ctsp; ++itsp) { sVal = ttpRun.GetStrProp(itsp, out tpt); Debug.Assert(tpt != (int)FwTextPropType.ktptBulNumFontInfo); Debug.Assert(tpt != (int)FwTextPropType.ktptWsStyle); WriteStrTextProp(m_writer, tpt, sVal); if (sRun != null && sRun.Length == 1 && sRun[0] == StringUtils.kchObject) { Debug.Assert(tpt == (int)FwTextPropType.ktptObjData); fSkipText = true; if ((int)sVal[0] == (int)FwObjDataTypes.kodtOwnNameGuidHot) { guidFootnote = MiscUtils.GetGuidFromObjData(sVal.Substring(1)); } } } m_writer.Write(">"); if (!fSkipText) { int cch = tri.ichLim - tri.ichMin; if (cch > 0) { sRun = sRun.Normalize(); m_writer.Write(XmlUtils.MakeSafeXml(sRun)); } } if (fMarkItem) { m_writer.WriteLine("</Run></Item>"); } else { m_writer.WriteLine("</Run>"); } if (guidFootnote != Guid.Empty) { int hvoFootnote = m_cache.GetIdFromGuid(guidFootnote); if (hvoFootnote != 0) { ExportFootnote(new ScrFootnote(m_cache, hvoFootnote)); } } } if (!String.IsNullOrEmpty(sField)) { m_writer.WriteLine("{0}</Field>", sIndent2); } m_writer.WriteLine("{0}</Str>", sIndent); }