Esempio n. 1
0
        public void GetParameterValue_SentenceFinalPunctuation()
        {
            // Set up the punctuation for a Roman-script vernacular writing system.
            int hvoWs = Cache.DefaultVernWs;
            ILgWritingSystemFactory lgwsf   = Cache.LanguageWritingSystemFactoryAccessor;
            IWritingSystem          ws      = lgwsf.get_EngineOrNull(hvoWs);
            LanguageDefinition      langDef = new LanguageDefinition(ws);

            // The test writing system has the following characters for punctuation:
            //   .?!;-)(:
            langDef.PunctuationPatterns = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" +
                                          "<PunctuationPatterns>" +
                                          "<pattern value=\". \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"? \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"! \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"; \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"- \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\") \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"( \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\": \" context=\"WordFinal\" valid=\"true\" /></PunctuationPatterns>";

            // Get the sentence-final punctuation
            string sentenceFinalPunc = m_dataSource.GetParameterValue("SentenceFinalPunctuation");

            // We expect that only sentence-final punctuation would be returned.
            Assert.AreEqual(".?!", sentenceFinalPunc);
        }
Esempio n. 2
0
        /// <summary>
        /// Enable vernacular spelling.
        /// </summary>
        void OnEnableVernacularSpelling()
        {
            // Enable all vernacular spelling dictionaries by changing those that are set to <None>
            // to point to the appropriate Locale ID. Do this BEFORE updating the spelling dictionaries,
            // otherwise, the update won't see that there is any dictionary set to update.
            FdoCache cache = Cache;
            ILgWritingSystemFactory wsf = cache.LanguageWritingSystemFactoryAccessor;

            foreach (LgWritingSystem wsObj in cache.LangProject.CurVernWssRS)
            {
                int            ws     = wsObj.Hvo;
                IWritingSystem engine = wsf.get_EngineOrNull(ws);
                if (engine == null)
                {
                    continue;                     // paranoia
                }
                // This allows it to try to find a dictionary, but doesn't force one to exist.
                if (engine.SpellCheckDictionary == "<None>")
                {
                    engine.SpellCheckDictionary = engine.IcuLocale;
                }
            }
            // This forces the default verancular WS spelling dictionary to exist, and updates
            // all existing ones.
            OnAddWordsToSpellDict(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the character render properties for the given style name and writing system.
        /// </summary>
        /// <param name="styleName">The style name.</param>
        /// <param name="styleSheet">The stylesheet.</param>
        /// <param name="hvoWs">The HVO of the WS.</param>
        /// <param name="writingSystemFactory">The writing system factory.</param>
        /// <returns>The character render properties.</returns>
        public static LgCharRenderProps GetChrpForStyle(string styleName, IVwStylesheet styleSheet,
                                                        int hvoWs, ILgWritingSystemFactory writingSystemFactory)
        {
            if (string.IsNullOrEmpty(writingSystemFactory.GetStrFromWs(hvoWs)))
            {
                try
                {
                    throw new ArgumentException("This is a hard-to-reproduce scenario (TE-6891) where writing system (" + hvoWs + ") and factory are inconsistent. Call an expert (JohnT)");
                }
                catch (ArgumentException e)
                {
                    Logger.WriteError(e);
                    Debug.Fail("This is a hard-to-reproduce scenario (TE-6891) where writing system and factory are inconsistent. Call an expert (JohnT) while you have this Assert active!");
                    hvoWs = writingSystemFactory.UserWs;
                }
            }

            IVwPropertyStore vwps = VwPropertyStoreClass.Create();

            vwps.Stylesheet           = styleSheet;
            vwps.WritingSystemFactory = writingSystemFactory;

            ITsPropsBldr ttpBldr = TsPropsBldrClass.Create();

            ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName);
            ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoWs);
            ITsTextProps ttp = ttpBldr.GetTextProps();

            LgCharRenderProps chrps = vwps.get_ChrpFor(ttp);
            IWritingSystem    ws    = writingSystemFactory.get_EngineOrNull(hvoWs);

            ws.InterpretChrp(ref chrps);
            return(chrps);
        }
Esempio n. 4
0
        /// <summary>
        /// Get a dictionary for the specified writing system, or null if we don't know of one.
        /// We ideally want a dictionary that exactly matches the specified writing system, that is,
        /// dict.Information.Language == the SpellCheckDictionary of the writing system.
        /// If we can't find such a dictionary, for major languages (those that have non-trivial base dictionary files),
        /// we will return a dictionary that shares a prefix, for example, 'en' when looking for 'en_US' or vice versa.
        /// This is not allowed for minority languages (where the dictionary is one we created ourselves that is empty,
        /// and all the spelling information is in the overrides kept by Enchant); we return null if we can't find
        /// an exact match or an approximate match that is a 'major' language dictionary.
        /// Note: a similar algorithm is unfortunately implemented in VwRootBox::GetDictionary
        /// and in WritingSystemPropertiesDialog.PopulateSpellingDictionaryComboBox.
        /// </summary>
        public static Enchant.Dictionary GetDictionary(int ws, ILgWritingSystemFactory wsf)
        {
            string dictId = DictionaryId(ws, wsf);

            if (dictId == null)
            {
                return(null);
            }
            Dictionary dict = GetDict(dictId);

            if (dict == null)
            {
                return(null);
            }

            ILgWritingSystem engine = wsf.get_EngineOrNull(ws);

            if (engine == null)
            {
                return(dict);                // should never happen? Can't verify ID so go ahead and return it.
            }
            if (dict.Information.Language == engine.SpellCheckingId)
            {
                return(dict);                // exact match
            }
            if (IsPrivateDictionary(dict.Information.Language))
            {
                return(null);                // private dictionaries may only be returned when matching exactly.
            }
            return(dict);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a value determining if the new writing systems should be created as a side-effect
        /// of a paste operation.
        /// </summary>
        /// <param name="wsf">writing system factory containing the new writing systems</param>
        /// <param name="destWs">The destination writing system (writing system used at the
        /// selection).</param>
        /// <returns>
        ///     an indication of how the paste should be handled.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs)
        {
            // Determine writing system at selection (destination for paste).
            destWs = 0;
            if (CurrentSelection != null)
            {
                destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor);
            }
            if (destWs <= 0)
            {
                destWs = Cache.DefaultAnalWs;                 // set to default analysis, if 0.
            }
            int cws = wsf.NumberOfWs;

            using (ArrayPtr ptr = MarshalEx.ArrayToNative <int>(cws))
            {
                wsf.GetWritingSystems(ptr, cws);
                int[] vws = MarshalEx.NativeToArray <int>(ptr, cws);

                for (int iws = 0; iws < cws; iws++)
                {
                    if (vws[iws] != 0 && wsf.get_EngineOrNull(vws[iws]) == null)
                    {
                        // found corrupt writing system--don't want to use any ws in this pasted string
                        return(PasteStatus.UseDestWs);
                    }
                }
            }

            return(PasteStatus.PreserveWs);
        }
Esempio n. 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Resolve a magic font name to the real font name for the given writing system.
        /// </summary>
        /// <param name="fontName"></param>
        /// <param name="ws"></param>
        /// <exception cref="InvalidOperationException">Thrown if StyleInfoTable was constructed
        /// with a null writing system factory</exception>
        /// ------------------------------------------------------------------------------------
        internal string ResolveMagicFontName(string fontName, int ws)
        {
            if (m_wsf == null)
            {
                throw new InvalidOperationException("StyleInfoTable was constructed with a null writing system factory. Cannot resolve magic font name.");
            }

            IWritingSystem lgws = m_wsf.get_EngineOrNull(ws);

            if (lgws == null)
            {
                throw new ArgumentException("Writing system ID (" + ws + ") could not be resolved to a real writing systm.", "ws");
            }
            switch (fontName)
            {
            case StStyle.DefaultHeadingFont:
                return(lgws.DefaultSansSerif);

            case StStyle.DefaultFont:
                return(lgws.DefaultSerif);

            case StStyle.DefaultMonospace:
                return(lgws.DefaultSerif);

            case StStyle.DefaultPubFont:
                return(lgws.DefaultBodyFont);

            default:
                Debug.Fail("ResolveMagicFontName called with unexpected (non-magic?) font name.");
                return(fontName);                        // This method probably shouldn't have been called, but oh well...
            }
        }
Esempio n. 7
0
        public void GetParameterValue_SentenceFinalPunctuationNR()
        {
            // Set up the punctuation for a Roman-script vernacular writing system.
            int hvoWs = Cache.DefaultVernWs;
            ILgWritingSystemFactory lgwsf   = Cache.LanguageWritingSystemFactoryAccessor;
            IWritingSystem          ws      = lgwsf.get_EngineOrNull(hvoWs);
            LanguageDefinition      langDef = new LanguageDefinition(ws);

            // We add the following Arabic punctuation: percent sign (066A), decimal separator (066B),
            // thousands separator (066C), five pointed star (066D), full stop (06D4), question mark (061F)
            langDef.PunctuationPatterns = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" +
                                          "<PunctuationPatterns>" +
                                          "<pattern value=\"\u066A \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"\u066B \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"\u066C \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"\u066D \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"\u06D4 \" context=\"WordFinal\" valid=\"true\" />" +
                                          "<pattern value=\"\u061F \" context=\"WordFinal\" valid=\"true\" /></PunctuationPatterns>";

            // Get the sentence-final punctuation
            string sentenceFinalPunc = m_dataSource.GetParameterValue("SentenceFinalPunctuation");

            // We expect that only sentence-final punctuation would be returned.
            Assert.AreEqual("\u06D4\u061F", sentenceFinalPunc);
        }
Esempio n. 8
0
        /// <summary>
        /// Return true if the main direction of the script is right-to-left.
        /// </summary>
        public bool RightToLeft(int ws)
        {
            var wsEngine = m_wsf.get_EngineOrNull(ws);

            if (wsEngine == null)
            {
                return(false);
            }
            return(wsEngine.RightToLeftScript);
        }
Esempio n. 9
0
 private static Font GetVernacularFont(ILgWritingSystemFactory wsf, int wsVern, IVwStylesheet stylesheet)
 {
     if (stylesheet == null)
     {
         ILgWritingSystem wsEngine = wsf.get_EngineOrNull(wsVern);
         string           fontName = wsEngine.DefaultFontName;
         return(new Font(fontName, (float)10.0));
     }
     else
     {
         return(FontHeightAdjuster.GetFontForNormalStyle(wsVern, stylesheet, wsf));
     }
 }
        public void SetUp()
        {
            CheckDisposed();
            if (m_cache != null)
            {
                m_cache.Dispose();
            }

            m_cache = InMemoryFdoCache.CreateInMemoryFdoCache();
            m_cache.InitializeWritingSystemEncodings();
            ILgWritingSystemFactory lgwsf = m_cache.Cache.LanguageWritingSystemFactoryAccessor;

            m_ws = lgwsf.get_EngineOrNull(InMemoryFdoCache.s_wsHvos.En);
        }
Esempio n. 11
0
        /// <summary>
        /// (re)initialize the current list to correspond to the items in m_choices.
        /// This will destroy the selection, and then try to select the indicated line.
        /// </summary>
        void InitCurrentList(int index)
        {
            currentList.SuspendLayout();
            currentList.Items.Clear();
            StringUtils.InitIcuDataDir();               // used for normalizing strings to NFC
            foreach (InterlinLineSpec ls in m_choices)
            {
                string[] cols = new string[2];

                cols[0] = StringUtils.NormalizeToNFC(m_choices.LabelFor(ls.Flid));

                string wsName = "";
                // This tries to find a matching ws from the combo box that would be displayed for this item
                // The reason we use the combo box is because that will give us names like "Default Analysis" instead of
                // the actual analysis ws name.
                foreach (WsComboItem item in WsComboItems(ls.ComboContent))
                {
                    if (getWsFromIcuCode(item.IcuCode) == ls.WritingSystem)
                    {
                        wsName = item.ToString();
                        break;
                    }
                }
                // Last ditch effort
                if (wsName == "")
                {
                    ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor;
                    int            wsui         = m_cache.DefaultUserWs;
                    IWritingSystem engine       = wsf.get_EngineOrNull(ls.WritingSystem);
                    if (engine != null)
                    {
                        wsName = engine.get_UiName(wsui);
                    }
                }
                cols[1] = StringUtils.NormalizeToNFC(wsName);

                currentList.Items.Add(new ListViewItem(cols));
            }

            if (index > currentList.Items.Count && index > 0)
            {
                index--;                                       // for when we delete the last item.
            }
            if (index >= 0 && index < currentList.Items.Count) // range check mainly for passing 0 on empty
            {
                currentList.Items[index].Selected = true;
            }

            currentList.ResumeLayout();
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        protected string TransformToHtml(XPathDocument doc, TransformKind kind)
        {
            string sOutput = null;
            XslCompiledTransform transformer = new XslCompiledTransform();
            XsltArgumentList     args        = new XsltArgumentList();

            switch (kind)
            {
            case TransformKind.kcptParse:
                sOutput = CreateTempFile(m_sParse, "htm");
                transformer.Load(Path.Combine(TransformPath, m_sFormatParse));
                break;

            case TransformKind.kcptTrace:
                sOutput = CreateTempFile(m_sTrace, "htm");
                transformer.Load(Path.Combine(TransformPath, m_sFormatTrace));
                string sIconPath = CreateIconPath();
                args.AddParam("prmIconPath", "", sIconPath);
                break;

            case TransformKind.kcptWordGrammarDebugger:
                string sDepthLevel = m_XmlHtmlStack.Count.ToString();
                sOutput = CreateTempFile(CreateWordGrammarDebuggerFileName(), "htm");
                transformer.Load(Path.Combine(TransformPath, "FormatXAmpleWordGrammarDebuggerResult.xsl"));
                break;
            }
            TextWriter writer           = File.CreateText(sOutput);
            ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor;
            Font myFont = FontHeightAdjuster.GetFontForNormalStyle(m_cache.LangProject.DefaultAnalysisWritingSystem, m_mediator, wsf);

            args.AddParam("prmAnalysisFont", "", myFont.FontFamily.Name);
            args.AddParam("prmAnalysisFontSize", "", myFont.Size.ToString() + "pt");
            int vernWs = m_cache.LangProject.DefaultVernacularWritingSystem;

            myFont = FontHeightAdjuster.GetFontForNormalStyle(vernWs, m_mediator, wsf);
            args.AddParam("prmVernacularFont", "", myFont.FontFamily.Name);
            args.AddParam("prmVernacularFontSize", "", myFont.Size.ToString() + "pt");
            string         sRTL  = "N";
            IWritingSystem wsObj = wsf.get_EngineOrNull(vernWs);

            if (wsObj != null && wsObj.RightToLeft)
            {
                sRTL = "Y";
            }
            args.AddParam("prmVernacularRTL", "", sRTL);
            transformer.Transform(doc, args, writer);
            writer.Close();
            return(sOutput);
        }
Esempio n. 14
0
        /// <summary>
        /// Ensure that there is a spell-checking dictionary for this writing system. If there is not
        /// already, create one. Then return it (whether new or not).
        /// </summary>
        /// <returns></returns>
        public Enchant.Dictionary EnsureDictionary()
        {
            // This undoes the effect of disabling it by setting the spelling dictionary name to <None>.
            ILgWritingSystemFactory wsf      = m_cache.LanguageWritingSystemFactoryAccessor;
            IWritingSystem          wsEngine = wsf.get_EngineOrNull(Hvo);

            if (String.IsNullOrEmpty(wsEngine.SpellCheckDictionary) || wsEngine.SpellCheckDictionary == "<None>")
            {
                wsEngine.SpellCheckDictionary = wsEngine.IcuLocale;
            }

            int ws = m_cache.DefaultVernWs;

            return(EnchantHelper.EnsureDictionary(ws, ICULocale, wsf));
        }
Esempio n. 15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Given a start character position that is within a word, and a direction
        /// return the index of the first non-wordforming (and non-number) character in that direction,
        /// or -1 if the start of the string is reached, or string.Length if the end is reached.
        /// For our purposes here, ORC (0xfffc) is considered word-forming.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private int AdjustWordBoundary(ILgWritingSystemFactory wsf, ITsString tss, bool forward,
                                       int ichStart, int lim)
        {
            int ich;

            for (ich = NextCharIndex(tss, forward, ichStart); !BeyondLim(forward, ich, lim); ich = NextCharIndex(tss, forward, ich))
            {
                int ch = tss.CharAt(ich);
                ILgWritingSystem ws = wsf.get_EngineOrNull(tss.get_WritingSystemAt(ich));
                if (!ws.get_IsWordForming(ch) && !Icu.Character.IsNumeric(ch) && ch != 0xfffc)
                {
                    break;
                }
            }
            return(ich);
        }
Esempio n. 16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets a collection of suggestions for what to do when a "word" consists of multiple
        /// writing systems
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private ICollection <SpellCorrectMenuItem> MakeWssSuggestions(ITsString tssWord,
                                                                      List <int> wss, IVwRootBox rootb, int hvoObj, int tag, int wsAlt,
                                                                      int ichMin, int ichLim)
        {
            List <SpellCorrectMenuItem> result = new List <SpellCorrectMenuItem>(wss.Count + 1);

            // Make an item with inserted spaces.
            ITsStrBldr bldr    = tssWord.GetBldr();
            int        wsFirst = TsStringUtils.GetWsOfRun(tssWord, 0);
            int        offset  = 0;

            for (int irun = 1; irun < tssWord.RunCount; irun++)
            {
                int wsNew = TsStringUtils.GetWsOfRun(tssWord, irun);
                if (wsNew != wsFirst)
                {
                    int ichInsert = tssWord.get_MinOfRun(irun) + offset;
                    bldr.Replace(ichInsert, ichInsert, " ", null);
                    wsFirst = wsNew;
                    offset++;
                }
            }
            ITsString suggest      = bldr.GetString();
            string    menuItemText = suggest.Text;

            result.Add(new SpellCorrectMenuItem(rootb, hvoObj, tag, wsAlt, ichMin, ichLim, menuItemText, suggest));

            // And items for each writing system.
            foreach (int ws in wss)
            {
                bldr = tssWord.GetBldr();
                bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, ws);
                suggest = bldr.GetString();
                ILgWritingSystemFactory wsf    = rootb.DataAccess.WritingSystemFactory;
                ILgWritingSystem        engine = wsf.get_EngineOrNull(ws);
                string wsName   = engine.LanguageName;
                string itemText = string.Format(RootSiteStrings.ksMlStringIsMono, tssWord.Text, wsName);
                result.Add(new SpellCorrectMenuItem(rootb, hvoObj, tag, wsAlt, ichMin, ichLim, itemText, suggest));
            }

            return(result);
        }
Esempio n. 17
0
        // The raw id that should be used to create a dictionary for the given WS, if none exists.
        private static string RawDictionaryId(int ws, ILgWritingSystemFactory wsf)
        {
            ILgWritingSystem wsEngine = wsf.get_EngineOrNull(ws);

            if (wsEngine == null)
            {
                return(null);
            }
            string wsId = wsEngine.SpellCheckingId;

            if (String.IsNullOrEmpty(wsId))
            {
                return(wsEngine.Id.Replace('-', '_'));                // Enchant does not allow hyphen; that is OK since lang ID does not allow underscore.
            }
            if (wsId == "<None>")
            {
                return(null);
            }
            return(wsId);
        }
Esempio n. 18
0
        /// <summary>
        /// The user abbreviation we'd like to see typically for this writing system.
        /// Currently this is the user writing system of the Abbr field, or if that
        /// is empty, the ICU code.
        /// We will probably change this (when everything is using it) to try
        /// the analysis writing systems in order, then the user ws.
        /// </summary>
        public static ITsString UserAbbr(FdoCache cache, int hvo)
        {
            ITsString result = cache.MainCacheAccessor.get_MultiStringAlt(hvo,
                                                                          (int)LgWritingSystem.LgWritingSystemTags.kflidAbbr, cache.DefaultUserWs);

            if (result != null && result.Length != 0)
            {
                return(result);
            }
            ILgWritingSystemFactory wsf = cache.LanguageWritingSystemFactoryAccessor;
            IWritingSystem          ws  = wsf.get_EngineOrNull(hvo);

            if (ws == null)
            {
                return(cache.MakeUserTss(Strings.ksStars));
            }
            else
            {
                return(cache.MakeUserTss(ws.get_UiName(cache.DefaultUserWs)));
            }
        }
Esempio n. 19
0
        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");
            }
        }
Esempio n. 20
0
        // The raw id that should be used to create a dictionary for the given WS, if none exists.
        private static string RawDictionaryId(int ws, ILgWritingSystemFactory wsf)
        {
            ILgWritingSystem wsEngine = wsf.get_EngineOrNull(ws);

            if (wsEngine == null)
            {
                return(null);
            }
            string wsId = wsEngine.SpellCheckingId;

            if (String.IsNullOrEmpty(wsId))
            {
                // Our old spelling engine, Enchant, did not allow hyphen;
                // keeping that rule in case we switch again or there is some other good reason for it that we don't know.
                // Changing to underscore is OK since lang ID does not allow underscore.
                return(wsEngine.Id.Replace('-', '_'));
            }
            if (wsId == "<None>")
            {
                return(null);
            }
            return(wsId);
        }
Esempio n. 21
0
        /// <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();
                }
            }
        }
Esempio n. 22
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the valid characters list.
        /// </summary>
        /// <param name="key">The valid characters parameter key.</param>
        /// <param name="ws">The default vernacular writing system.</param>
        /// ------------------------------------------------------------------------------------
        private string GetValidCharactersList(string key, IWritingSystem ws)
        {
            if (key.StartsWith("ValidCharacters_"))
            {
                // If the key contains a locale ID, then don't use the default vernacular
                // writing system, build one from the locale.
                ILgWritingSystemFactory lgwsf = m_cache.LanguageWritingSystemFactoryAccessor;
                string icuLocale = key.Substring(key.IndexOf("_") + 1);
                int    hvoWs     = lgwsf.GetWsFromStr(icuLocale);
                ws = lgwsf.get_EngineOrNull(hvoWs);
            }
            else if (key == "AlwaysValidCharacters")
            {
                StringBuilder bldr = new StringBuilder(13);

                // Add the vernacular digits 0 through 9.
                for (int i = 0; i < 10; i++)
                {
                    bldr.Append(m_scr.ConvertToString(i));
                }

                if (ws.RightToLeft)
                {
                    // Add the LTR and RTL marks.
                    bldr.Append('\u202A');
                    bldr.Append('\u202B');
                }

                // Add the line separator.
                bldr.Append('\u2028');
                return(bldr.ToString());
            }

            ValidCharacters validChars = ValidCharacters.Load(ws);

            return(validChars != null ? validChars.SpaceDelimitedList : string.Empty);
        }
Esempio n. 23
0
        /// <summary>
        /// Gets the character render properties for the given style name and writing system.
        /// </summary>
        /// <param name="styleName">The style name.</param>
        /// <param name="styleSheet">The stylesheet.</param>
        /// <param name="hvoWs">The HVO of the WS.</param>
        /// <param name="writingSystemFactory">The writing system factory.</param>
        /// <returns>The character render properties.</returns>
        public static LgCharRenderProps GetChrpForStyle(string styleName, IVwStylesheet styleSheet,
                                                        int hvoWs, ILgWritingSystemFactory writingSystemFactory)
        {
            if (string.IsNullOrEmpty(writingSystemFactory.GetStrFromWs(hvoWs)))
            {
                try
                {
                    //You may have forgotten to set the WritingSystemFactory in a recently added custom control?
                    throw new ArgumentException("This is a hard-to-reproduce scenario (TE-6891) where writing system (" + hvoWs + ") and factory are inconsistent.");
                }
                catch (ArgumentException e)
                {
                    Logger.WriteError(e);
                    var msg = e.Message + " If we aren't called from a Widget, "
                              + "call an expert (JohnT) while you have this Assert active!";
                    Debug.Fail(msg);
                    hvoWs = writingSystemFactory.UserWs;
                }
            }

            IVwPropertyStore vwps = VwPropertyStoreClass.Create();

            vwps.Stylesheet           = styleSheet;
            vwps.WritingSystemFactory = writingSystemFactory;

            ITsPropsBldr ttpBldr = TsStringUtils.MakePropsBldr();

            ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName);
            ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoWs);
            ITsTextProps ttp = ttpBldr.GetTextProps();

            LgCharRenderProps chrps = vwps.get_ChrpFor(ttp);
            ILgWritingSystem  ws    = writingSystemFactory.get_EngineOrNull(hvoWs);

            ws.InterpretChrp(ref chrps);
            return(chrps);
        }
Esempio n. 24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a value determining if the new writing systems should be created as a side-effect
        /// of a paste operation.
        /// </summary>
        /// <param name="wsf">writing system factory containing the new writing systems</param>
        /// <param name="destWs">The destination writing system (writing system used at the
        /// selection).</param>
        /// <returns>
        ///     an indication of how the paste should be handled.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs)
        {
            // Determine writing system at selection (destination for paste).
            destWs = 0;
            if (CurrentSelection != null)
            {
                destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor);
            }
            if (destWs <= 0)
            {
                destWs = Cache.DefaultAnalWs;                 // set to default analysis, if 0.
            }
            // Get list of writing system names.
            List <string> wsMissingNames = new List <string>();
            int           cws            = wsf.NumberOfWs;

            using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int)))
            {
                wsf.GetWritingSystems(ptr, cws);
                int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int));

                IWritingSystem ws;
                for (int iws = 0; iws < cws; iws++)
                {
                    if (vws[iws] == 0)
                    {
                        continue;
                    }
                    ws = wsf.get_EngineOrNull(vws[iws]);
                    if (ws == null)
                    {
                        // found corrupt writing system--don't want to use any ws in this pasted string
                        return(PasteStatus.UseDestWs);
                    }
                    if (Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(ws.IcuLocale) == 0)
                    {
                        wsMissingNames.Add(ws.LanguageName);                         // writing system not found in ws factory
                    }
                }
            }

            PasteStatus pasteStatus;

            if (wsMissingNames.Count > 0)
            {
                if (!Options.ShowPasteWsChoice)
                {
                    return(PasteStatus.UseDestWs);
                }

                // Ask user whether to use destination writing system or copy original writing systems.
                LgWritingSystem lgws = new LgWritingSystem(Cache, destWs);
                Debug.Assert(lgws != null);
                using (AddWsFromPastedTextDlg newWsDlg = new AddWsFromPastedTextDlg(
                           m_cache.LangProject.Name.BestAnalysisAlternative.Text,
                           lgws.Name.BestAnalysisAlternative.Text, wsMissingNames))
                {
                    newWsDlg.ShowDialog(Control.FindForm());
                    pasteStatus = newWsDlg.PasteStatus;
                }
            }
            else             // no missing writing systems in TsString to paste
            {
                pasteStatus = PasteStatus.PreserveWs;
            }

            return(pasteStatus);
        }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Return a hash table from converter name to writing system name for converters
		/// that are currently in use by some writing system. (This is a needed argument
		/// for initializeing an AddCnvtrDlg, so that it can avoid deleting converters that
		/// are currently in use by writing systems.)
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static Set<string> ConvertersInUse(ILgWritingSystemFactory wsf)
		{
			Set<string> wsInUse = new Set<string>();
			// Make a hash of the writing systems currently in use.
			IWritingSystem currentWS;
			int cws = wsf.NumberOfWs;

			using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int)))
			{
				wsf.GetWritingSystems(ptr, cws);
				int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int));

				for (int iws = 0; iws < cws; iws++)
				{
					if (vws[iws] == 0)
						continue;
					currentWS = wsf.get_EngineOrNull(vws[iws]);
					if (currentWS == null)
						continue;
					string legMapping = currentWS.LegacyMapping;
					if (legMapping == null)
						continue;
					wsInUse.Add(legMapping);
				}
			}
			return wsInUse;
		}
Esempio n. 26
0
        /// <summary>
        /// Disable the dictionary (by telling the WS that it should have none; don't touch any external dictionary).
        /// </summary>
        public void DisableDictionary()
        {
            ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor;

            wsf.get_EngineOrNull(Hvo).SpellCheckDictionary = "<None>";
        }
Esempio n. 27
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets the writing system factory and the writing system hvo.
		/// </summary>
		/// <param name="wsf">The WSF.</param>
		/// <param name="ws">The ws.</param>
		/// ------------------------------------------------------------------------------------
		public void setWsfAndWs(ILgWritingSystemFactory wsf, int ws)
		{
			Debug.Assert(wsf != null, "Set the WritingSystemFactory first!");
			ILgWritingSystem wsObj = wsf.get_EngineOrNull(ws);
			m_rtl = (wsObj != null && wsObj.RightToLeftScript);
		}
Esempio n. 28
0
		/// <summary>
		/// Gets the character render properties for the given style name and writing system.
		/// </summary>
		/// <param name="styleName">The style name.</param>
		/// <param name="styleSheet">The stylesheet.</param>
		/// <param name="hvoWs">The HVO of the WS.</param>
		/// <param name="writingSystemFactory">The writing system factory.</param>
		/// <returns>The character render properties.</returns>
		public static LgCharRenderProps GetChrpForStyle(string styleName, IVwStylesheet styleSheet,
			int hvoWs, ILgWritingSystemFactory writingSystemFactory)
		{
			if (string.IsNullOrEmpty(writingSystemFactory.GetStrFromWs(hvoWs)))
			{
				try
				{
					throw new ArgumentException("This is a hard-to-reproduce scenario (TE-6891) where writing system (" + hvoWs + ") and factory are inconsistent. Call an expert (JohnT)");
				}
				catch (ArgumentException e)
				{
					Logger.WriteError(e);
					Debug.Fail("This is a hard-to-reproduce scenario (TE-6891) where writing system and factory are inconsistent. Call an expert (JohnT) while you have this Assert active!");
					hvoWs = writingSystemFactory.UserWs;
				}
			}

			IVwPropertyStore vwps = VwPropertyStoreClass.Create();
			vwps.Stylesheet = styleSheet;
			vwps.WritingSystemFactory = writingSystemFactory;

			ITsPropsBldr ttpBldr = TsPropsBldrClass.Create();
			ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName);
			ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoWs);
			ITsTextProps ttp = ttpBldr.GetTextProps();

			LgCharRenderProps chrps = vwps.get_ChrpFor(ttp);
			IWritingSystem ws = writingSystemFactory.get_EngineOrNull(hvoWs);
			ws.InterpretChrp(ref chrps);
			return chrps;
		}
Esempio n. 29
0
		/// <summary>
		/// This sets the original wordform and morph-broken word into the dialog.
		/// </summary>
		/// <param name="sWord"></param>
		/// <param name="sMorphs"></param>
		public void Initialize(ITsString tssWord, string sMorphs, ILgWritingSystemFactory wsf,
			FdoCache cache, SIL.Utils.StringTable stringTable, IVwStylesheet stylesheet)
		{
			CheckDisposed();

			Debug.Assert(tssWord != null);
			Debug.Assert(wsf != null);
			ITsTextProps ttp = tssWord.get_Properties(0);
			Debug.Assert(ttp != null);
			int var;
			int ws = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out var);
			Debug.Assert(ws != 0);
			IWritingSystem wsVern = wsf.get_EngineOrNull(ws);
			Debug.Assert(wsVern != null);
			// The following is needed for Graphite fonts.
			string sFontVar = wsVern.FontVariation;
			if (sFontVar == null)
				sFontVar = "";

			this.m_txtMorphs.WritingSystemFactory = wsf;
			this.m_txtMorphs.WritingSystemCode = ws;
			this.m_txtMorphs.Text = sMorphs;
			m_sMorphs = sMorphs;

			// Fix the help strings to use the actual MorphType markers.
			IMoMorphType mmtStem = null;
			IMoMorphType mmtPrefix = null;
			IMoMorphType mmtSuffix = null;
			IMoMorphType mmtInfix = null;
			IMoMorphType mmtBoundStem = null;
			IMoMorphType mmtProclitic = null;
			IMoMorphType mmtEnclitic = null;
			IMoMorphType mmtSimulfix = null;
			IMoMorphType mmtSuprafix = null;
			MoMorphType.GetMajorMorphTypes(cache, out mmtStem, out mmtPrefix, out mmtSuffix, out mmtInfix,
				out mmtBoundStem, out mmtProclitic, out mmtEnclitic, out mmtSimulfix, out mmtSuprafix);
			// Format the labels according to the MoMorphType Prefix/Postfix values.
			string sExample1 = stringTable.GetString("EditMorphBreaks-Example1", "DialogStrings");
			string sExample2 = stringTable.GetString("EditMorphBreaks-Example2", "DialogStrings");
			string sStemExample = stringTable.GetString("EditMorphBreaks-stemExample", "DialogStrings");
			string sAffixExample = stringTable.GetString("EditMorphBreaks-affixExample", "DialogStrings");
			lblHelp2_Example1.Text = String.Format(sExample1,
				mmtStem.Prefix == null ? "" : mmtStem.Prefix,
				mmtStem.Postfix == null ? "" : mmtStem.Postfix);
			lblHelp2_Example2.Text = String.Format(sExample2,
				mmtSuffix.Prefix == null ? "" : mmtSuffix.Prefix,
				mmtSuffix.Postfix == null ? "" : mmtSuffix.Postfix);
			lblBreak_stemExample.Text = String.Format(sStemExample,
				mmtStem.Prefix == null ? "" : mmtStem.Prefix,
				mmtStem.Postfix == null ? "" : mmtStem.Postfix);
			lblBreak_boundStemExample.Text = String.Format(sStemExample,
				mmtBoundStem.Prefix == null ? "" : mmtBoundStem.Prefix,
				mmtBoundStem.Postfix == null ? "" : mmtBoundStem.Postfix);
			lblBreak_prefixExample.Text = String.Format(sAffixExample,
				mmtPrefix.Prefix == null ? "" : " " + mmtPrefix.Prefix,
				mmtPrefix.Postfix == null ? "" : mmtPrefix.Postfix + " ");
			lblBreak_suffixExample.Text = String.Format(sAffixExample,
				mmtSuffix.Prefix == null ? "" : " " + mmtSuffix.Prefix,
				mmtSuffix.Postfix == null ? "" : mmtSuffix.Postfix + " ");
			lblBreak_infixExample.Text = String.Format(sAffixExample,
				mmtInfix.Prefix == null ? "" : " " + mmtInfix.Prefix,
				mmtInfix.Postfix == null ? "" : mmtInfix.Postfix + " ");
			lblBreak_procliticExample.Text = String.Format(sAffixExample,
				mmtProclitic.Prefix == null ? "" : " " + mmtProclitic.Prefix,
				mmtProclitic.Postfix == null ? "" : mmtProclitic.Postfix + " ");
			lblBreak_encliticExample.Text = String.Format(sAffixExample,
				mmtEnclitic.Prefix == null ? "" : " " + mmtEnclitic.Prefix,
				mmtEnclitic.Postfix == null ? "" : mmtEnclitic.Postfix + " ");
			lblBreak_simulfixExample.Text = String.Format(sAffixExample,
				mmtSimulfix.Prefix == null ? "" : " " + mmtSimulfix.Prefix,
				mmtSimulfix.Postfix == null ? "" : mmtSimulfix.Postfix + " ");
			lblBreak_suprafixExample.Text = String.Format(sAffixExample,
				mmtSuprafix.Prefix == null ? "" : " " + mmtSuprafix.Prefix,
				mmtSuprafix.Postfix == null ? "" : mmtSuprafix.Postfix + " ");

			morphBreakContextMenu = new MorphBreakHelperMenu(m_txtMorphs, FwApp.App, cache, stringTable);
			m_txtMorphs.AdjustForStyleSheet(this, null, stylesheet);
		}
Esempio n. 30
0
        private void LexImportWizardLanguage_Load(object sender, System.EventArgs e)
        {
            // (Bev) modify a few labels
            if (m_LinguaLinksImport)
            {
                this.Text        = LexTextControls.ksSpecifyFwWs;
                lblComment.Text  = LexTextControls.ksSpecifyFwWsDescription;
                lblLangDesc.Text = LexTextControls.ksLanguageDefinition;
            }
            else
            {
                if (m_AddUsage)
                {
                    this.Text = LexTextControls.ksAddLangMapping;
                }
                else
                {
                    this.Text = LexTextControls.ksModifyLangMapping;
                }
            }

            tbLangDesc.Text = m_LangDesc;

            //getting name for a writing system given the ICU code.
            ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor;
            int            wsUser       = wsf.UserWs;
            int            wsVern       = m_cache.DefaultVernWs;
            IWritingSystem ws           = wsf.get_EngineOrNull(wsVern);

            m_wsiDefault = new WsInfo(wsVern, ws.get_UiName(wsVern), ws.IcuLocale, ws.LegacyMapping);

            // getting list of writing systems to populate a combo.
            int cws = wsf.NumberOfWs;

            using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int)))
            {
                wsf.GetWritingSystems(ptr, cws);
                int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int));
                for (int iws = 0; iws < cws; iws++)
                {
                    if (vws[iws] == 0)
                    {
                        continue;
                    }
                    ws = wsf.get_EngineOrNull(vws[iws]);
                    if (ws == null)
                    {
                        continue;
                    }
                    string name     = ws.get_UiName(wsUser);
                    string icuLocal = ws.IcuLocale;
                    string mapName  = ws.LegacyMapping;
                    WsInfo wsi      = new WsInfo(vws[iws], name, icuLocal, mapName);
                    m_wsInfo.Add(wsi.KEY, wsi);
                }
            }

            // initialize the 'ws' combo box with the data from the DB
            foreach (DictionaryEntry entry in m_wsInfo)
            {
                WsInfo wsi = entry.Value as WsInfo;
                cbWS.Items.Add(wsi);
            }
            cbWS.Sorted = false;
            WsInfo wsiIgnore = new WsInfo();

            cbWS.Items.Add(wsiIgnore);

            // select the proper index if there is a valid writhing system
            int index = 0;

            if (m_wsName != null && m_wsName != "")
            {
                index = cbWS.FindStringExact(m_wsName);
                if (index < 0)
                {
                    index = 0;
                }
            }
            cbWS.SelectedIndex = index;

            LoadEncodingConverters();

            index = 0;
            if (m_encConverter != null && m_encConverter != "")
            {
                index = cbEC.FindStringExact(m_encConverter);
                if (index < 0)
                {
                    index = 0;
                }
            }
            cbEC.SelectedIndex = index;
        }
Esempio n. 31
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a value determining if the new writing systems should be created as a side-effect
		/// of a paste operation.
		/// </summary>
		/// <param name="wsf">writing system factory containing the new writing systems</param>
		/// <param name="destWs">The destination writing system (writing system used at the
		/// selection).</param>
		/// <returns>
		/// 	an indication of how the paste should be handled.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs)
		{
			// Determine writing system at selection (destination for paste).
			destWs = 0;
			if (CurrentSelection != null)
				destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor);
			if (destWs <= 0)
				destWs = Cache.DefaultAnalWs; // set to default analysis, if 0.

			// Get list of writing system names.
			List<string> wsMissingNames = new List<string>();
			int cws = wsf.NumberOfWs;

			using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int)))
			{
				wsf.GetWritingSystems(ptr, cws);
				int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int));

				IWritingSystem ws;
				for (int iws = 0; iws < cws; iws++)
				{
					if (vws[iws] == 0)
						continue;
					ws = wsf.get_EngineOrNull(vws[iws]);
					if (ws == null)
					{
						// found corrupt writing system--don't want to use any ws in this pasted string
						return PasteStatus.UseDestWs;
					}
					if (Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(ws.IcuLocale) == 0)
						wsMissingNames.Add(ws.LanguageName); // writing system not found in ws factory
				}
			}

			PasteStatus pasteStatus;
			if (wsMissingNames.Count > 0)
			{
				if (!Options.ShowPasteWsChoice)
					return PasteStatus.UseDestWs;

				// Ask user whether to use destination writing system or copy original writing systems.
				LgWritingSystem lgws = new LgWritingSystem(Cache, destWs);
				Debug.Assert(lgws != null);
				using (AddWsFromPastedTextDlg newWsDlg = new AddWsFromPastedTextDlg(
					m_cache.LangProject.Name.BestAnalysisAlternative.Text,
					lgws.Name.BestAnalysisAlternative.Text, wsMissingNames))
				{
					newWsDlg.ShowDialog(Control.FindForm());
					pasteStatus = newWsDlg.PasteStatus;
				}
			}
			else // no missing writing systems in TsString to paste
				pasteStatus = PasteStatus.PreserveWs;

			return pasteStatus;
		}
Esempio n. 32
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a value determining if the new writing systems should be created as a side-effect
		/// of a paste operation.
		/// </summary>
		/// <param name="wsf">writing system factory containing the new writing systems</param>
		/// <param name="destWs">The destination writing system (writing system used at the
		/// selection).</param>
		/// <returns>
		/// 	an indication of how the paste should be handled.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs)
		{
			// Determine writing system at selection (destination for paste).
			destWs = 0;
			if (CurrentSelection != null)
				destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor);
			if (destWs <= 0)
				destWs = Cache.DefaultAnalWs; // set to default analysis, if 0.

			int cws = wsf.NumberOfWs;

			using (ArrayPtr ptr = MarshalEx.ArrayToNative<int>(cws))
			{
				wsf.GetWritingSystems(ptr, cws);
				int[] vws = MarshalEx.NativeToArray<int>(ptr, cws);

				for (int iws = 0; iws < cws; iws++)
				{
					if (vws[iws] != 0 && wsf.get_EngineOrNull(vws[iws]) == null)
					{
						// found corrupt writing system--don't want to use any ws in this pasted string
						return PasteStatus.UseDestWs;
					}
				}
			}

			return PasteStatus.PreserveWs;
		}
Esempio n. 33
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets the writing system factory and the writing system hvo.
		/// </summary>
		/// <param name="wsf">The WSF.</param>
		/// <param name="ws">The ws.</param>
		/// ------------------------------------------------------------------------------------
		public void setWsfAndWs(ILgWritingSystemFactory wsf, int ws)
		{
			CheckDisposed();

			IWritingSystem wsObj = wsf.get_EngineOrNull(ws);
			m_rtl = (wsObj != null && wsObj.RightToLeft);
		}
Esempio n. 34
0
		/// <summary>
		/// This sets the original wordform and morph-broken word into the dialog.
		/// </summary>
		public void Initialize(ITsString tssWord, string sMorphs, ILgWritingSystemFactory wsf,
			FdoCache cache, StringTable stringTable, IVwStylesheet stylesheet)
		{
			CheckDisposed();

			Debug.Assert(tssWord != null);
			Debug.Assert(wsf != null);
			ITsTextProps ttp = tssWord.get_Properties(0);
			Debug.Assert(ttp != null);
			int var;
			int ws = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out var);
			Debug.Assert(ws != 0);
			ILgWritingSystem wsVern = wsf.get_EngineOrNull(ws);
			Debug.Assert(wsVern != null);

			m_txtMorphs.WritingSystemFactory = wsf;
			m_txtMorphs.WritingSystemCode = ws;
			m_txtMorphs.Text = sMorphs;
			m_sMorphs = sMorphs;

			// Fix the help strings to use the actual MorphType markers.
			IMoMorphType mmtStem;
			IMoMorphType mmtPrefix;
			IMoMorphType mmtSuffix;
			IMoMorphType mmtInfix;
			IMoMorphType mmtBoundStem;
			IMoMorphType mmtProclitic;
			IMoMorphType mmtEnclitic;
			IMoMorphType mmtSimulfix;
			IMoMorphType mmtSuprafix ;
			var morphTypeRepo = cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>();
			morphTypeRepo.GetMajorMorphTypes(out mmtStem, out mmtPrefix, out mmtSuffix, out mmtInfix,
				out mmtBoundStem, out mmtProclitic, out mmtEnclitic, out mmtSimulfix, out mmtSuprafix);
			// Format the labels according to the MoMorphType Prefix/Postfix values.
			string sExample1 = stringTable.GetString("EditMorphBreaks-Example1", "DialogStrings");
			string sExample2 = stringTable.GetString("EditMorphBreaks-Example2", "DialogStrings");
			string sStemExample = stringTable.GetString("EditMorphBreaks-stemExample", "DialogStrings");
			string sAffixExample = stringTable.GetString("EditMorphBreaks-affixExample", "DialogStrings");
			m_lblHelp2Example1.Text = String.Format(sExample1, mmtStem.Prefix ?? "", mmtStem.Postfix ?? "");
			m_lblHelp2Example2.Text = String.Format(sExample2, mmtSuffix.Prefix ?? "", mmtSuffix.Postfix ?? "");
			m_lblBreakStemExample.Text = String.Format(sStemExample, mmtStem.Prefix ?? "", mmtStem.Postfix ?? "");
			m_lblBreakBoundStemExample.Text = String.Format(sStemExample, mmtBoundStem.Prefix ?? "", mmtBoundStem.Postfix ?? "");
			m_lblBreakPrefixExample.Text = String.Format(sAffixExample,
				mmtPrefix.Prefix == null ? "" : " " + mmtPrefix.Prefix,
				mmtPrefix.Postfix == null ? "" : mmtPrefix.Postfix + " ");
			m_lblBreakSuffixExample.Text = String.Format(sAffixExample,
				mmtSuffix.Prefix == null ? "" : " " + mmtSuffix.Prefix,
				mmtSuffix.Postfix == null ? "" : mmtSuffix.Postfix + " ");
			m_lblBreakInfixExample.Text = String.Format(sAffixExample,
				mmtInfix.Prefix == null ? "" : " " + mmtInfix.Prefix,
				mmtInfix.Postfix == null ? "" : mmtInfix.Postfix + " ");
			m_lblBreakProcliticExample.Text = String.Format(sAffixExample,
				mmtProclitic.Prefix == null ? "" : " " + mmtProclitic.Prefix,
				mmtProclitic.Postfix == null ? "" : mmtProclitic.Postfix + " ");
			m_lblBreakEncliticExample.Text = String.Format(sAffixExample,
				mmtEnclitic.Prefix == null ? "" : " " + mmtEnclitic.Prefix,
				mmtEnclitic.Postfix == null ? "" : mmtEnclitic.Postfix + " ");
			m_lblBreakSimulfixExample.Text = String.Format(sAffixExample,
				mmtSimulfix.Prefix == null ? "" : " " + mmtSimulfix.Prefix,
				mmtSimulfix.Postfix == null ? "" : mmtSimulfix.Postfix + " ");
			m_lblBreakSuprafixExample.Text = String.Format(sAffixExample,
				mmtSuprafix.Prefix == null ? "" : " " + mmtSuprafix.Prefix,
				mmtSuprafix.Postfix == null ? "" : mmtSuprafix.Postfix + " ");

			m_morphBreakContextMenu = new MorphBreakHelperMenu(m_txtMorphs, m_helpTopicProvider, cache, stringTable);
			m_txtMorphs.AdjustForStyleSheet(this, null, stylesheet);
			m_morphBreakHelper.Height = m_txtMorphs.Height;
		}
Esempio n. 35
0
		// The raw id that should be used to create a dictionary for the given WS, if none exists.
		private static string RawDictionaryId(int ws, ILgWritingSystemFactory wsf)
		{
			ILgWritingSystem wsEngine = wsf.get_EngineOrNull(ws);
			if (wsEngine == null)
				return null;
			string wsId = wsEngine.SpellCheckingId;
			if (String.IsNullOrEmpty(wsId))
			{
				// Our old spelling engine, Enchant, did not allow hyphen;
				// keeping that rule in case we switch again or there is some other good reason for it that we don't know.
				// Changing to underscore is OK since lang ID does not allow underscore.
				return wsEngine.Id.Replace('-', '_');
			}
			if (wsId == "<None>")
				return null;
			return wsId;
		}
Esempio n. 36
0
		/// <summary>
		/// Gets the first vernacular ws.
		/// </summary>
		/// <param name="vernWsVecImage">The vern ws vec image, like "seh pt mar-fonipa".</param>
		/// <param name="wsf">The Writing System Factory.</param>
		/// <param name="text">The text.</param>
		/// <returns>
		/// The first vernacular ws used in the text or -1 if none
		/// </returns>
		public static int GetFirstVernacularWs(string vernWsVecImage, ILgWritingSystemFactory wsf, ITsString text)
		{
			int wid = -1; // writing system id
			for (int runSeq = 0; runSeq < text.RunCount; runSeq++)
			{
				wid = text.get_WritingSystem(runSeq);
				var ws = wsf.get_EngineOrNull(wid);
				if (ws != null)
				{   // ws.Id is short like "en"
					if (vernWsVecImage.IndexOf(ws.Id) >= 0)
						break; // wid > -1
				}
				wid = -1;
			}
			return wid;
		}
Esempio n. 37
0
		private static Font GetVernacularFont(ILgWritingSystemFactory wsf, int wsVern, IVwStylesheet stylesheet)
		{
			if (stylesheet == null)
			{
				ILgWritingSystem wsEngine = wsf.get_EngineOrNull(wsVern);
				string fontName = wsEngine.DefaultFontName;
				return new Font(fontName, (float)10.0);
			}
			else
			{
				return FontHeightAdjuster.GetFontForNormalStyle(wsVern, stylesheet, wsf);
			}
		}
Esempio n. 38
0
        private void UpdateLanguageCodes()
        {
            if (m_sLastXmlFileName != m_LinguaLinksXmlFileName.Text)
            {
                m_sLastXmlFileName = m_LinguaLinksXmlFileName.Text;
                listViewMapping.Items.Clear();
                btnImport.Enabled = false;                      // default to not enabled now that there are no items
                m_nextInput       = m_LinguaLinksXmlFileName.Text;
                if (!File.Exists(m_nextInput))
                {
                    MessageBox.Show(
                        String.Format(ITextStrings.ksLLFileNotFound, m_nextInput),
                        ITextStrings.ksLLImport,
                        MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }

                StringUtils.InitIcuDataDir();                   // used for normalizing strings to NFC
                m_startPhase = 1;
                string nameTest;
                if (m_nextInput.Length > 19)
                {
                    nameTest = m_nextInput.Substring(m_nextInput.Length - 19, 19);
                    if (nameTest == "\\LLPhase1Output.xml")
                    {
                        m_startPhase = 2;
                    }
                    else if (nameTest == "\\LLPhase2Output.xml")
                    {
                        m_startPhase = 3;
                    }
                    else if (nameTest == "\\LLPhase3Output.xml")
                    {
                        m_startPhase = 4;
                    }
                }

                if (m_startPhase == 1)
                {
                    StreamReader streamReader = File.OpenText(m_nextInput);
                    String       input;

                    bool   inWritingSystem = false;
                    bool   inIcuLocale24 = false;
                    bool   inName24 = false;
                    bool   lineDone = false;
                    bool   formatOkay = false;
                    int    pos, pos1, pos2, pos3;
                    string wsLLCode                    = "";
                    string wsName                      = "";
                    Dictionary <string, WsInfo> wsInfo = new Dictionary <string, WsInfo>();                     // Dictioanry of wsInfo

                    //getting name for a writing system given the ICU code.
                    ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor;
                    int            wsUser       = wsf.UserWs;
                    int            wsVern       = m_cache.DefaultVernWs;
                    IWritingSystem ws           = wsf.get_EngineOrNull(wsVern);

                    // getting list of writing systems to eventually populate a list box
                    int cws = wsf.NumberOfWs;
                    using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int)))
                    {
                        wsf.GetWritingSystems(ptr, cws);
                        int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int));
                        for (int iws = 0; iws < cws; iws++)
                        {
                            if (vws[iws] == 0)
                            {
                                continue;
                            }
                            ws = wsf.get_EngineOrNull(vws[iws]);
                            if (ws == null)
                            {
                                continue;
                            }
                            string name     = ws.get_UiName(wsUser);
                            string icuLocal = ws.IcuLocale;
                            string mapName  = ws.LegacyMapping;
                            if ((mapName == null) || (mapName == ""))
                            {
                                mapName = "Windows1252<>Unicode";                                       // REVIEW: SHOULD THIS NAME BE LOCALIZED?
                            }
                            WsInfo wsi = new WsInfo(vws[iws], name, icuLocal, mapName);
                            wsInfo.Add(wsi.KEY, wsi);
                        }
                    }

                    while ((input = streamReader.ReadLine()) != null)
                    {
                        lineDone = false;
                        while (!lineDone)
                        {
                            if (!inWritingSystem)
                            {
                                pos = input.IndexOf("<LgWritingSystem");
                                if (pos >= 0)
                                {
                                    inWritingSystem = true;
                                    wsLLCode        = "";
                                    wsName          = "";
                                    if (input.Length >= pos + 21)
                                    {
                                        input = input.Substring(pos + 21, input.Length - pos - 21);
                                    }
                                    else
                                    {
                                        input = input.Substring(pos + 16);
                                    }
                                }

                                else
                                {
                                    lineDone = true;
                                }
                            }
                            if (inWritingSystem && !inIcuLocale24 && !inName24)
                            {
                                pos1 = input.IndexOf("</LgWritingSystem>");
                                pos2 = input.IndexOf("<ICULocale24>");
                                pos3 = input.IndexOf("<Name24>");
                                if (pos1 < 0 && pos2 < 0 && pos3 < 0)
                                {
                                    lineDone = true;
                                }
                                else if (pos1 >= 0 && (pos2 < 0 || pos2 > pos1) && (pos3 < 0 || pos3 > pos1))
                                {
                                    input = input.Substring(pos1 + 18, input.Length - pos1 - 18);
                                    if (wsLLCode != "")
                                    {
                                        if (wsName == "")
                                        {
                                            wsName = "<" + wsLLCode + ">";
                                        }
                                        string wsFWName = "";
                                        string wsEC     = "";
                                        string wsFWCode = "";

                                        foreach (KeyValuePair <string, WsInfo> kvp in wsInfo)
                                        {
                                            WsInfo wsi = kvp.Value;
                                            if (wsName == wsi.Name)
                                            {
                                                wsFWName = StringUtils.NormalizeToNFC(wsi.Name);
                                                wsEC     = StringUtils.NormalizeToNFC(wsi.Map);
                                                wsFWCode = StringUtils.NormalizeToNFC(wsi.Locale);
                                            }
                                        }

                                        if (wsFWName == "")
                                        {
                                            foreach (KeyValuePair <string, WsInfo> kvp in wsInfo)
                                            {
                                                WsInfo wsi = kvp.Value;
                                                if (BaseName(wsName) == BaseName(wsi.Name))
                                                {
                                                    wsFWName = StringUtils.NormalizeToNFC(wsi.Name);
                                                    wsEC     = StringUtils.NormalizeToNFC(wsi.Map);
                                                    wsFWCode = StringUtils.NormalizeToNFC(wsi.Locale);
                                                }
                                            }
                                        }

                                        ListViewItem lvItem = new ListViewItem(new string[] { StringUtils.NormalizeToNFC(wsName), wsFWName, wsEC, StringUtils.NormalizeToNFC(wsLLCode), wsFWCode });
                                        lvItem.Tag = wsName;
                                        listViewMapping.Items.Add(lvItem);
                                        formatOkay = true;
                                    }
                                    inWritingSystem = false;
                                }
                                else if (pos2 >= 0 && (pos3 < 0 || pos3 > pos2))
                                {
                                    input         = input.Substring(pos2 + 13, input.Length - pos2 - 13);
                                    inIcuLocale24 = true;
                                }
                                else
                                {
                                    input    = input.Substring(pos3 + 8, input.Length - pos3 - 8);
                                    inName24 = true;
                                }
                            }
                            if (inIcuLocale24)
                            {
                                pos = input.IndexOf(">");
                                if (pos < 0)
                                {
                                    lineDone = true;
                                }
                                else
                                {
                                    input         = input.Substring(pos + 1, input.Length - pos - 1);
                                    pos           = input.IndexOf("<");
                                    wsLLCode      = input.Substring(0, pos);
                                    input         = input.Substring(pos, input.Length - pos);
                                    inIcuLocale24 = false;
                                }
                            }
                            if (inName24)
                            {
                                pos = input.IndexOf(">");
                                if (pos < 0)
                                {
                                    lineDone = true;
                                }
                                else
                                {
                                    input    = input.Substring(pos + 1, input.Length - pos - 1);
                                    pos      = input.IndexOf("<");
                                    wsName   = input.Substring(0, pos);
                                    input    = input.Substring(pos, input.Length - pos);
                                    inName24 = false;
                                }
                            }
                        }
                    }
                    streamReader.Close();
                    listViewMapping_SelectedIndexChanged();
                    CheckImportEnabled();
                    if (!formatOkay)
                    {
                        ShowFinishLabel();                              // update the button before showing the msg box just in case...
                        MessageBox.Show(
                            String.Format(ITextStrings.ksInvalidLLFile, m_nextInput),
                            ITextStrings.ksLLImport,
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return;
                    }
                }
                else
                {
                    btnImport.Enabled = true;
                }
                ShowFinishLabel();
            }
        }
Esempio n. 39
0
        /// <summary>
        /// This sets the original wordform and morph-broken word into the dialog.
        /// </summary>
        /// <param name="sWord"></param>
        /// <param name="sMorphs"></param>
        public void Initialize(ITsString tssWord, string sMorphs, ILgWritingSystemFactory wsf,
                               FdoCache cache, SIL.Utils.StringTable stringTable, IVwStylesheet stylesheet)
        {
            CheckDisposed();

            Debug.Assert(tssWord != null);
            Debug.Assert(wsf != null);
            ITsTextProps ttp = tssWord.get_Properties(0);

            Debug.Assert(ttp != null);
            int var;
            int ws = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out var);

            Debug.Assert(ws != 0);
            IWritingSystem wsVern = wsf.get_EngineOrNull(ws);

            Debug.Assert(wsVern != null);
            // The following is needed for Graphite fonts.
            string sFontVar = wsVern.FontVariation;

            if (sFontVar == null)
            {
                sFontVar = "";
            }

            this.m_txtMorphs.WritingSystemFactory = wsf;
            this.m_txtMorphs.WritingSystemCode    = ws;
            this.m_txtMorphs.Text = sMorphs;
            m_sMorphs             = sMorphs;

            // Fix the help strings to use the actual MorphType markers.
            IMoMorphType mmtStem      = null;
            IMoMorphType mmtPrefix    = null;
            IMoMorphType mmtSuffix    = null;
            IMoMorphType mmtInfix     = null;
            IMoMorphType mmtBoundStem = null;
            IMoMorphType mmtProclitic = null;
            IMoMorphType mmtEnclitic  = null;
            IMoMorphType mmtSimulfix  = null;
            IMoMorphType mmtSuprafix  = null;

            MoMorphType.GetMajorMorphTypes(cache, out mmtStem, out mmtPrefix, out mmtSuffix, out mmtInfix,
                                           out mmtBoundStem, out mmtProclitic, out mmtEnclitic, out mmtSimulfix, out mmtSuprafix);
            // Format the labels according to the MoMorphType Prefix/Postfix values.
            string sExample1     = stringTable.GetString("EditMorphBreaks-Example1", "DialogStrings");
            string sExample2     = stringTable.GetString("EditMorphBreaks-Example2", "DialogStrings");
            string sStemExample  = stringTable.GetString("EditMorphBreaks-stemExample", "DialogStrings");
            string sAffixExample = stringTable.GetString("EditMorphBreaks-affixExample", "DialogStrings");

            lblHelp2_Example1.Text = String.Format(sExample1,
                                                   mmtStem.Prefix == null ? "" : mmtStem.Prefix,
                                                   mmtStem.Postfix == null ? "" : mmtStem.Postfix);
            lblHelp2_Example2.Text = String.Format(sExample2,
                                                   mmtSuffix.Prefix == null ? "" : mmtSuffix.Prefix,
                                                   mmtSuffix.Postfix == null ? "" : mmtSuffix.Postfix);
            lblBreak_stemExample.Text = String.Format(sStemExample,
                                                      mmtStem.Prefix == null ? "" : mmtStem.Prefix,
                                                      mmtStem.Postfix == null ? "" : mmtStem.Postfix);
            lblBreak_boundStemExample.Text = String.Format(sStemExample,
                                                           mmtBoundStem.Prefix == null ? "" : mmtBoundStem.Prefix,
                                                           mmtBoundStem.Postfix == null ? "" : mmtBoundStem.Postfix);
            lblBreak_prefixExample.Text = String.Format(sAffixExample,
                                                        mmtPrefix.Prefix == null ? "" : " " + mmtPrefix.Prefix,
                                                        mmtPrefix.Postfix == null ? "" : mmtPrefix.Postfix + " ");
            lblBreak_suffixExample.Text = String.Format(sAffixExample,
                                                        mmtSuffix.Prefix == null ? "" : " " + mmtSuffix.Prefix,
                                                        mmtSuffix.Postfix == null ? "" : mmtSuffix.Postfix + " ");
            lblBreak_infixExample.Text = String.Format(sAffixExample,
                                                       mmtInfix.Prefix == null ? "" : " " + mmtInfix.Prefix,
                                                       mmtInfix.Postfix == null ? "" : mmtInfix.Postfix + " ");
            lblBreak_procliticExample.Text = String.Format(sAffixExample,
                                                           mmtProclitic.Prefix == null ? "" : " " + mmtProclitic.Prefix,
                                                           mmtProclitic.Postfix == null ? "" : mmtProclitic.Postfix + " ");
            lblBreak_encliticExample.Text = String.Format(sAffixExample,
                                                          mmtEnclitic.Prefix == null ? "" : " " + mmtEnclitic.Prefix,
                                                          mmtEnclitic.Postfix == null ? "" : mmtEnclitic.Postfix + " ");
            lblBreak_simulfixExample.Text = String.Format(sAffixExample,
                                                          mmtSimulfix.Prefix == null ? "" : " " + mmtSimulfix.Prefix,
                                                          mmtSimulfix.Postfix == null ? "" : mmtSimulfix.Postfix + " ");
            lblBreak_suprafixExample.Text = String.Format(sAffixExample,
                                                          mmtSuprafix.Prefix == null ? "" : " " + mmtSuprafix.Prefix,
                                                          mmtSuprafix.Postfix == null ? "" : mmtSuprafix.Postfix + " ");

            morphBreakContextMenu = new MorphBreakHelperMenu(m_txtMorphs, FwApp.App, cache, stringTable);
            m_txtMorphs.AdjustForStyleSheet(this, null, stylesheet);
        }
Esempio n. 40
0
			private Font GetVernacularFont(ILgWritingSystemFactory wsf, int wsVern, IVwStylesheet stylesheet)
			{
				if (stylesheet == null)
				{
					IWritingSystem wsEngine = wsf.get_EngineOrNull(wsVern);
					string fontName = wsEngine.DefaultSansSerif;
					return new Font(fontName, (float)10.0);
				}
				else
				{
					return SIL.FieldWorks.Common.Widgets.FontHeightAdjuster.GetFontForNormalStyle(wsVern, stylesheet, wsf);
				}
			}
Esempio n. 41
0
        /// <summary>
        /// This sets the original wordform and morph-broken word into the dialog.
        /// </summary>
        public void Initialize(ITsString tssWord, string sMorphs, ILgWritingSystemFactory wsf,
                               FdoCache cache, StringTable stringTable, IVwStylesheet stylesheet)
        {
            CheckDisposed();

            Debug.Assert(tssWord != null);
            Debug.Assert(wsf != null);
            ITsTextProps ttp = tssWord.get_Properties(0);

            Debug.Assert(ttp != null);
            int var;
            int ws = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out var);

            Debug.Assert(ws != 0);
            ILgWritingSystem wsVern = wsf.get_EngineOrNull(ws);

            Debug.Assert(wsVern != null);

            m_txtMorphs.WritingSystemFactory = wsf;
            m_txtMorphs.WritingSystemCode    = ws;
            m_txtMorphs.Text = sMorphs;
            m_sMorphs        = sMorphs;

            // Fix the help strings to use the actual MorphType markers.
            IMoMorphType mmtStem;
            IMoMorphType mmtPrefix;
            IMoMorphType mmtSuffix;
            IMoMorphType mmtInfix;
            IMoMorphType mmtBoundStem;
            IMoMorphType mmtProclitic;
            IMoMorphType mmtEnclitic;
            IMoMorphType mmtSimulfix;
            IMoMorphType mmtSuprafix;
            var          morphTypeRepo = cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>();

            morphTypeRepo.GetMajorMorphTypes(out mmtStem, out mmtPrefix, out mmtSuffix, out mmtInfix,
                                             out mmtBoundStem, out mmtProclitic, out mmtEnclitic, out mmtSimulfix, out mmtSuprafix);
            // Format the labels according to the MoMorphType Prefix/Postfix values.
            string sExample1     = stringTable.GetString("EditMorphBreaks-Example1", "DialogStrings");
            string sExample2     = stringTable.GetString("EditMorphBreaks-Example2", "DialogStrings");
            string sStemExample  = stringTable.GetString("EditMorphBreaks-stemExample", "DialogStrings");
            string sAffixExample = stringTable.GetString("EditMorphBreaks-affixExample", "DialogStrings");

            m_lblHelp2Example1.Text         = String.Format(sExample1, mmtStem.Prefix ?? "", mmtStem.Postfix ?? "");
            m_lblHelp2Example2.Text         = String.Format(sExample2, mmtSuffix.Prefix ?? "", mmtSuffix.Postfix ?? "");
            m_lblBreakStemExample.Text      = String.Format(sStemExample, mmtStem.Prefix ?? "", mmtStem.Postfix ?? "");
            m_lblBreakBoundStemExample.Text = String.Format(sStemExample, mmtBoundStem.Prefix ?? "", mmtBoundStem.Postfix ?? "");
            m_lblBreakPrefixExample.Text    = String.Format(sAffixExample,
                                                            mmtPrefix.Prefix == null ? "" : " " + mmtPrefix.Prefix,
                                                            mmtPrefix.Postfix == null ? "" : mmtPrefix.Postfix + " ");
            m_lblBreakSuffixExample.Text = String.Format(sAffixExample,
                                                         mmtSuffix.Prefix == null ? "" : " " + mmtSuffix.Prefix,
                                                         mmtSuffix.Postfix == null ? "" : mmtSuffix.Postfix + " ");
            m_lblBreakInfixExample.Text = String.Format(sAffixExample,
                                                        mmtInfix.Prefix == null ? "" : " " + mmtInfix.Prefix,
                                                        mmtInfix.Postfix == null ? "" : mmtInfix.Postfix + " ");
            m_lblBreakProcliticExample.Text = String.Format(sAffixExample,
                                                            mmtProclitic.Prefix == null ? "" : " " + mmtProclitic.Prefix,
                                                            mmtProclitic.Postfix == null ? "" : mmtProclitic.Postfix + " ");
            m_lblBreakEncliticExample.Text = String.Format(sAffixExample,
                                                           mmtEnclitic.Prefix == null ? "" : " " + mmtEnclitic.Prefix,
                                                           mmtEnclitic.Postfix == null ? "" : mmtEnclitic.Postfix + " ");
            m_lblBreakSimulfixExample.Text = String.Format(sAffixExample,
                                                           mmtSimulfix.Prefix == null ? "" : " " + mmtSimulfix.Prefix,
                                                           mmtSimulfix.Postfix == null ? "" : mmtSimulfix.Postfix + " ");
            m_lblBreakSuprafixExample.Text = String.Format(sAffixExample,
                                                           mmtSuprafix.Prefix == null ? "" : " " + mmtSuprafix.Prefix,
                                                           mmtSuprafix.Postfix == null ? "" : mmtSuprafix.Postfix + " ");

            m_morphBreakContextMenu = new MorphBreakHelperMenu(m_txtMorphs, m_helpTopicProvider, cache, stringTable);
            m_txtMorphs.AdjustForStyleSheet(this, null, stylesheet);
            m_morphBreakHelper.Height = m_txtMorphs.Height;
        }
Esempio n. 42
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Retrieve named checking parameter value.
        /// Checks use this to get their setup information.
        /// </summary>
        /// <param name="key">Parameter name</param>
        /// <returns>Parameter value</returns>
        /// ------------------------------------------------------------------------------------
        public string GetParameterValue(string key)
        {
            ILgWritingSystemFactory lgwsf = m_cache.LanguageWritingSystemFactoryAccessor;
            int            hvoWs          = m_cache.DefaultVernWs;
            IWritingSystem ws             = lgwsf.get_EngineOrNull(hvoWs);

            if (key.Contains("ValidCharacters"))
            {
                return(GetValidCharactersList(key, ws));
            }

            switch (key)
            {
            case "PoeticStyles":
                return(GetPoeticStyles());

            case "Versification Scheme":
                return(m_scr.Versification.ToString());

            case "IntroductionOutlineStyles":
                //REVIEW: Do we need this? return "Intro_List_Item1";
                return(string.Empty);

            case "PunctCheckLevel":
                return("Intermediate");

            case "PunctWhitespaceChar":
                return(ResourceHelper.GetResourceString("kstidPunctCheckWhitespaceChar").Substring(0, 1));

            case "MatchedPairs":
                return(ws.MatchedPairs);

            case "PunctuationPatterns":
                return(ws.PunctuationPatterns);

            case "SentenceFinalPunctuation":
                return(GetSentenceFinalPunctuation(ws, lgwsf.UnicodeCharProps));

            case "QuotationMarkInfo":
                return(ws.QuotationMarks);

            case "StylesInfo":
                return(StyleInfo.XmlString);

            case "DefaultWritingSystemName":
                return(ws.get_UiName(m_cache.DefaultUserWs));

            case "Verse Bridge":
                return(m_scr.BridgeForWs(hvoWs));

            case "Script Digit Zero":
                return(m_scr.UseScriptDigits ? ((char)m_scr.ScriptDigitZero).ToString() : "0");

            case "Sub-verse Letter A":
                return("a");                        // TODO (TE-8593): Support sub-verse letters for non-Roman text

            case "Sub-verse Letter B":
                return("b");                        // TODO (TE-8593): Support sub-verse letters for non-Roman text

            default:
                string value;
                return((m_checkingParameters.TryGetValue(key, out value)) ? value : string.Empty);
            }
        }
Esempio n. 43
0
		/// ------------------------------------------------------------------------------------
		/// <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));
		}