Example #1
0
        public void FwNewLangProjectModel_VernacularAndAnalysisSame_WarningIssued()
        {
            bool warningIssued = false;
            var  model         = new FwNewLangProjectModel();

            model.LoadProjectNameSetup = () => { };
            model.LoadVernacularSetup  = () => { };
            model.LoadAnalysisSetup    = () => { };
            model.LoadAnalysisSameAsVernacularWarning = () => { warningIssued = true; };
            model.ProjectName = DbName;
            var fakeTestWs = new CoreWritingSystemDefinition("fr");

            model.WritingSystemContainer.CurrentVernacularWritingSystems.Add(fakeTestWs);
            model.WritingSystemContainer.VernacularWritingSystems.Add(fakeTestWs);
            model.WritingSystemContainer.CurrentAnalysisWritingSystems.Add(fakeTestWs);
            model.WritingSystemContainer.AnalysisWritingSystems.Add(fakeTestWs);
            Assert.True(model.CanGoNext());
            model.Next();             // Move to choose default vernacular
            Assert.True(model.CanGoNext());
            model.Next();             // Move to choose default analysis
            model.SetDefaultWs(new LanguageInfo()
            {
                LanguageTag = "fr"
            });
            Assert.True(warningIssued, "Warning for analysis same as vernacular not triggered");
            Assert.True(model.CanGoNext());             // The user can ignore the warning
        }
Example #2
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_BeforeRulePrimaryGetsADigraph()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "& [before 1] a < aa <<< Aa <<< AA"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(data.Count, 1, "Wrong number of character mappings found");
                    Assert.AreEqual(mapChars.Count, 2, "Wrong number of character mappings found");
                    Assert.AreEqual(ignoreSet.Count, 0, "Ignorable character incorrectly parsed from rule");
                }
            }
        }
Example #3
0
        public void XHTMLExportGetDigraphMapsFirstCharactersFromICUSortRules()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "&b < az << a < c <<< ch"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    ISet <string> ignoreSet;
                    var           data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(mapChars.Count, 2, "Too many characters found equivalents");
                    Assert.AreEqual(mapChars["a"], "az");
                    Assert.AreEqual(mapChars["ch"], "c");
                }
            }
        }
Example #4
0
        /// <summary>
        /// non-undoable task
        /// </summary>
        private void DoSetupFixture()
        {
            // setup default vernacular ws.
            CoreWritingSystemDefinition wsXkal = Cache.ServiceLocator.WritingSystemManager.Set("qaa-x-kal");

            wsXkal.DefaultFont = new FontDefinition("Times New Roman");
            Cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Add(wsXkal);
            Cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Insert(0, wsXkal);
            var textFactory   = Cache.ServiceLocator.GetInstance <ITextFactory>();
            var stTextFactory = Cache.ServiceLocator.GetInstance <IStTextFactory>();

            m_text0 = textFactory.Create();
            //Cache.LangProject.TextsOC.Add(m_text0);
            m_stText0          = stTextFactory.Create();
            m_text0.ContentsOA = m_stText0;
            m_para0_0          = m_stText0.AddNewTextPara(null);
            m_para0_0.Contents = TsStringUtils.MakeString("Xxxhope xxxthis xxxwill xxxdo. xxxI xxxhope.", wsXkal.Handle);

            InterlinMaster.LoadParagraphAnnotationsAndGenerateEntryGuessesIfNeeded(m_stText0, false);
            // paragraph 0_0 simply has wordforms as analyses
            foreach (var occurence in SegmentServices.GetAnalysisOccurrences(m_para0_0))
            {
                if (occurence.HasWordform)
                {
                    m_analysis_para0_0.Add(new AnalysisTree(occurence.Analysis));
                }
            }
        }
Example #5
0
        /// <summary>
        /// Finds the ISO3 code for the given writing system.
        /// </summary>
        /// <param name="ws"></param>
        /// <returns>The ISO3 code, or <value>mis</value> if the code is not found.</returns>
        public static string GetIso3Code(this CoreWritingSystemDefinition ws)
        {
            string iso3Code = ws.Language.Iso3Code;

            if (!string.IsNullOrEmpty(iso3Code))
            {
                return(iso3Code);
            }

            iso3Code = ws.Id;

            // split the result, the iso3 code is in the first segment
            var segments = iso3Code.Split(new[] { '-' });

            iso3Code = segments[0];

            // if the code is "Local" return uncoded code
            if ((String.Compare(iso3Code, "q", StringComparison.OrdinalIgnoreCase) > 0) && (String.Compare(iso3Code, "qu", StringComparison.OrdinalIgnoreCase) < 0))
            {
                return("mis");
            }

            // return "mis" for uncoded languages
            if (string.IsNullOrEmpty(iso3Code) || (iso3Code.Length != 3))
            {
                return("mis");
            }

            return(iso3Code);
        }
Example #6
0
 /// <summary>
 /// This guess factors in the placement of an occurrence in its segment for making other
 /// decisions like matching lowercase alternatives for sentence initial occurrences.
 /// </summary>
 public IAnalysis GetBestGuess(AnalysisOccurrence occurrence)
 {
     // first see if we can make a guess based on the lowercase form of a sentence initial (non-lowercase) wordform
     // TODO: make it look for the first word in the sentence...may not be at Index 0!
     if (occurrence.Analysis is IWfiWordform && occurrence.Index == 0)
     {
         ITsString tssWfBaseline        = occurrence.BaselineText;
         CoreWritingSystemDefinition ws = Cache.ServiceLocator.WritingSystemManager.Get(tssWfBaseline.get_WritingSystemAt(0));
         string sLower = UnicodeString.ToLower(tssWfBaseline.Text, ws.IcuLocale);
         // don't bother looking up the lowercased wordform if the instanceOf is already in lowercase form.
         if (sLower != tssWfBaseline.Text)
         {
             ITsString    tssLower = TsStringUtils.MakeString(sLower, TsStringUtils.GetWsAtOffset(tssWfBaseline, 0));
             IWfiWordform lowercaseWf;
             if (Cache.ServiceLocator.GetInstance <IWfiWordformRepository>().TryGetObject(tssLower, out lowercaseWf))
             {
                 IAnalysis bestGuess;
                 if (TryGetBestGuess(lowercaseWf, occurrence.BaselineWs, out bestGuess))
                 {
                     return(bestGuess);
                 }
             }
         }
     }
     if (occurrence.BaselineWs == -1)
     {
         return(null);                // happens with empty translation lines
     }
     return(GetBestGuess(occurrence.Analysis, occurrence.BaselineWs));
 }
Example #7
0
        internal void SetupVernWsForText(int wsVern)
        {
            m_wsDefault = wsVern;
            CoreWritingSystemDefinition defWs = Cache.ServiceLocator.WritingSystemManager.Get(wsVern);

            RightToLeft = defWs.RightToLeftScript;
        }
Example #8
0
        /// <summary>non-undoable task because setting up an StText must be done in a Unit of Work</summary>
        private void DoSetupFixture()
        {
            m_application = new MockFwXApp(new MockFwManager {
                Cache = Cache
            }, null, null);
            var configFilePath = Path.Combine(FwDirectoryFinder.CodeDirectory, m_application.DefaultConfigurationPathname);

            m_window = new MockFwXWindow(m_application, configFilePath);
            ((MockFwXWindow)m_window).Init(Cache);             // initializes Mediator values
            m_mediator      = m_window.Mediator;
            m_propertyTable = m_window.PropTable;

            // set up default vernacular ws.
            m_wsDefaultVern = Cache.ServiceLocator.WritingSystemManager.Get("fr");
            m_wsOtherVern   = Cache.ServiceLocator.WritingSystemManager.Get("es");
            m_wsEn          = Cache.ServiceLocator.WritingSystemManager.Get("en");
            Cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Add(m_wsOtherVern);
            Cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Add(m_wsOtherVern);
            Cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Add(m_wsDefaultVern);
            Cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Insert(0, m_wsDefaultVern);

            // set up an StText with an empty paragraph with default Contents (empty English TsString)
            m_sttNoExplicitWs = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();
            Cache.ServiceLocator.GetInstance <ITextFactory>().Create().ContentsOA = m_sttNoExplicitWs;
            m_sttNoExplicitWs.AddNewTextPara(null);
            Assert.AreEqual(m_wsEn.Handle, m_sttNoExplicitWs.MainWritingSystem, "Our code counts on English being the defualt WS for very empty texts");

            // set up an StText with an empty paragraph with an empty TsString in a non-default vernacular
            m_sttEmptyButWithWs = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();
            Cache.ServiceLocator.GetInstance <ITextFactory>().Create().ContentsOA = m_sttEmptyButWithWs;
            m_sttEmptyButWithWs.AddNewTextPara(null);
            ((IStTxtPara)m_sttEmptyButWithWs.ParagraphsOS[0]).Contents = TsStringUtils.MakeString(string.Empty, m_wsOtherVern.Handle);
        }
Example #9
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_TertiaryIgnorableDoesNotCrash()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "&[last tertiary ignorable] = \\"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    // The second test catches the real world scenario, GetDigraphs is actually called many times, but the first time
                    // is the only one that should trigger the algorithm, afterward the information is cached in the exporter.
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(mapChars.Count, 0, "Too many characters found equivalents");
                    Assert.AreEqual(ignoreSet.Count, 1, "Ignorable character not parsed from rule");
                }
            }
        }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="wp"></param>
        /// <param name="mediator"></param>
        /// <param name="propertyTable"></param>
        public override void SetDlgInfo(LcmCache cache, WindowParams wp, Mediator mediator, XCore.PropertyTable propertyTable)
        {
            CheckDisposed();

            m_fwcbSenses.WritingSystemFactory = cache.LanguageWritingSystemFactoryAccessor;

            base.SetDlgInfo(cache, wp, mediator, propertyTable);
            // This is needed to make the replacement MatchingEntriesBrowser visible:
            Controls.SetChildIndex(m_matchingObjectsBrowser, 0);

            //Set the senses control so that it conforms to the size of the
            //DefaultAnalysisWritingSystem
            CoreWritingSystemDefinition defAnalWs = cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem;

            m_fwcbSenses.WritingSystemCode = defAnalWs.Handle;
            // the default font is set to size 100, so that when adding strings to the control
            // this becomes a limit.
            m_fwcbSenses.StyleSheet = m_tbForm.StyleSheet;
            m_fwcbSenses.AdjustForStyleSheet(this, grplbl, m_fwcbSenses.StyleSheet);

            if (wp != null)
            {
                switch (wp.m_title)
                {
                case "Identify sense":
                    m_helpTopic       = "khtpAddSenseToReversalEntry";
                    m_btnHelp.Enabled = true;
                    break;
                }
            }
        }
Example #11
0
        /// <summary>
        /// Method returns Guid of existing or created writing system
        /// </summary>
        /// <param name="wsObj">Writing system Object</param>
        /// <param name="cache">The FDO cache</param>
        /// <returns>returns Guid</returns>
        public static Guid GetOrCreateWsGuid(CoreWritingSystemDefinition wsObj, LcmCache cache)
        {
            var riRepo     = cache.ServiceLocator.GetInstance <IReversalIndexRepository>();
            var mHvoRevIdx = riRepo.FindOrCreateIndexForWs(wsObj.Handle).Hvo;

            return(cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(mHvoRevIdx).Guid);
        }
Example #12
0
        /// <summary>
        /// Try to find a WfiWordform object corresponding the the focus selection.
        /// If successful return its guid, otherwise, return Guid.Empty.
        /// </summary>
        /// <returns></returns>
        private ITsString ActiveWord()
        {
            if (InFriendliestTool)
            {
                // we should be able to get our info from the current record clerk.
                // but return null if we can't get the info, otherwise we allow the user to
                // bring up the change spelling dialog and crash because no wordform can be found (LT-8766).
                var clerk   = m_propertyTable.GetValue <RecordClerk>("ActiveClerk");
                var tssVern = (clerk?.CurrentObject as IWfiWordform)?.Form?.BestVernacularAlternative;
                return(tssVern);
            }
            var app   = m_propertyTable.GetValue <IApp>("App");
            var roots = (app?.ActiveMainWindow as FwXWindow)?.ActiveView?.AllRootBoxes();

            if (roots == null || roots.Count < 1 || roots[0] == null)
            {
                return(null);
            }
            var tssWord = SelectionHelper.Create(roots[0].Site)?.SelectedWord;

            if (tssWord != null)
            {
                // Check for a valid vernacular writing system.  (See LT-8892.)
                var ws    = TsStringUtils.GetWsAtOffset(tssWord, 0);
                var cache = m_propertyTable.GetValue <LcmCache>("cache");
                CoreWritingSystemDefinition wsObj = cache.ServiceLocator.WritingSystemManager.Get(ws);
                if (cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Contains(wsObj))
                {
                    return(tssWord);
                }
            }
            return(null);
        }
Example #13
0
        public void SetDefaultWs_PreservesCheckState()
        {
            var model = new FwNewLangProjectModel(true)
            {
                LoadProjectNameSetup = () => { },
                LoadVernacularSetup  = () => { },
                ProjectName          = DbName
            };

            model.Next();
            var french    = new CoreWritingSystemDefinition("fr");
            var esperanto = new CoreWritingSystemDefinition("eo");
            var english   = new CoreWritingSystemDefinition("en");

            model.WritingSystemContainer.AddToCurrentVernacularWritingSystems(french);      // selected
            model.WritingSystemContainer.AddToCurrentVernacularWritingSystems(esperanto);   // selected
            model.WritingSystemContainer.VernacularWritingSystems.Add(english);             // deselected
            model.SetDefaultWs(new LanguageInfo {
                LanguageTag = "de"
            });
            Assert.That(model.WritingSystemContainer.VernacularWritingSystems.Count, Is.EqualTo(3), "should be three total");
            Assert.That(model.WritingSystemContainer.VernacularWritingSystems.First().LanguageTag, Is.EqualTo("de"), "first should be German");
            Assert.That(model.WritingSystemContainer.VernacularWritingSystems.Contains(esperanto), "should contain Esperanto");
            Assert.That(model.WritingSystemContainer.VernacularWritingSystems.Contains(english), "should contain English");
            Assert.That(model.WritingSystemContainer.CurrentVernacularWritingSystems.Count, Is.EqualTo(2), "should be two selected");
            Assert.That(model.WritingSystemContainer.CurrentVernacularWritingSystems[0].LanguageTag, Is.EqualTo("de"), "default should be German");
            Assert.Contains(esperanto, (ICollection)model.WritingSystemContainer.CurrentVernacularWritingSystems, "Esperanto should be selected");
        }
Example #14
0
        public void FwNewLangProjectModel_CannotClickFinishWithBlankProjectName()
        {
            var model = new FwNewLangProjectModel();

            model.LoadProjectNameSetup  = () => { };
            model.LoadVernacularSetup   = () => { };
            model.LoadAnalysisSetup     = () => { };
            model.LoadAdvancedWsSetup   = () => { };
            model.LoadAnthropologySetup = () => { };
            model.ProjectName           = DbName;
            var fakeTestWs = new CoreWritingSystemDefinition("fr");

            model.WritingSystemContainer.CurrentVernacularWritingSystems.Add(fakeTestWs);
            model.WritingSystemContainer.VernacularWritingSystems.Add(fakeTestWs);
            model.WritingSystemContainer.CurrentAnalysisWritingSystems.Add(fakeTestWs);
            model.WritingSystemContainer.AnalysisWritingSystems.Add(fakeTestWs);
            Assert.True(model.CanGoNext());
            model.Next();             // Vernacular
            model.Next();             // Analysis
            Assert.True(model.CanFinish());
            model.Back();
            model.Back();
            model.ProjectName = "";
            Assert.False(model.CanFinish());
        }
Example #15
0
 public void get_Renderer_Uniscribe()
 {
     using (var control = new Form())
         using (var gm = new GraphicsManager(control))
             using (var reFactory = new RenderEngineFactory())
             {
                 gm.Init(1.0f);
                 try
                 {
                     var wsManager = new WritingSystemManager();
                     CoreWritingSystemDefinition ws = wsManager.Set("en-US");
                     var chrp = new LgCharRenderProps {
                         ws = ws.Handle, szFaceName = new ushort[32]
                     };
                     MarshalEx.StringToUShort("Arial", chrp.szFaceName);
                     gm.VwGraphics.SetupGraphics(ref chrp);
                     IRenderEngine engine = reFactory.get_Renderer(ws, gm.VwGraphics);
                     Assert.IsNotNull(engine);
                     Assert.AreSame(wsManager, engine.WritingSystemFactory);
                     Assert.IsInstanceOf(typeof(UniscribeEngine), engine);
                     wsManager.Save();
                 }
                 finally
                 {
                     gm.Uninit();
                 }
             }
 }
Example #16
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_UnicodeTertiaryIgnorableWithNoSpacesWorks()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "&[last tertiary ignorable]=\\uA78C"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(mapChars.Count, 0, "Too many characters found equivalents");
                    Assert.AreEqual(ignoreSet.Count, 1, "Ignorable character not parsed from rule");
                    Assert.IsTrue(ignoreSet.Contains('\uA78C'.ToString(CultureInfo.InvariantCulture)));
                }
            }
        }
Example #17
0
        /// <summary>
        /// Set up class.
        /// </summary>
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            // Add strings needed for tests.
            var englishWsHvo = Cache.WritingSystemFactory.GetWsFromStr("en");
            var spanishWsHvo = Cache.WritingSystemFactory.GetWsFromStr("es");
            var lp           = Cache.LangProject;

            NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () =>
            {
                // Set LP's WorldRegion.
                lp.WorldRegion.set_String(
                    englishWsHvo,
                    TsStringUtils.MakeString("Stateful LCM Test Project: World Region", englishWsHvo));
                lp.WorldRegion.set_String(
                    spanishWsHvo,
                    TsStringUtils.MakeString("Proyecto de prueba: LCM: RegiĆ³n del Mundo ", spanishWsHvo));

                // Set LP's Description.
                lp.Description.set_String(
                    englishWsHvo,
                    TsStringUtils.MakeString("Stateful LCM Test Language Project: Desc", englishWsHvo));
                lp.Description.set_String(
                    spanishWsHvo,
                    TsStringUtils.MakeString("Proyecto de prueba: LCM: desc", spanishWsHvo));

                // Add Spanish as Anal WS.
                CoreWritingSystemDefinition span = Cache.ServiceLocator.WritingSystemManager.Get(spanishWsHvo);
                lp.AddToCurrentAnalysisWritingSystems(span);
            });
        }
Example #18
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_TertiaryIgnorableMixedSpacingWorks()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "&[last tertiary ignorable]= '!'\r\n&[last tertiary ignorable] ='?'"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(mapChars.Count, 0, "Too many characters found equivalents");
                    Assert.AreEqual(ignoreSet.Count, 2, "Ignorable character not parsed from rule");
                    CollectionAssert.AreEquivalent(ignoreSet, new[] { "!", "?" });
                }
            }
        }
Example #19
0
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            m_wsNew = null;

            // show the menu to select which type of writing system to create
            var mnuAddWs = components.ContextMenu("mnuAddWs");

            // look like the "Add" button on the WS properties dlg
            List <CoreWritingSystemDefinition> xmlWs = GetOtherWritingSystems();
            var xmlWsV = new MenuItem[xmlWs.Count + 2];                     // one for Vernacular
            var xmlWsA = new MenuItem[xmlWs.Count + 2];                     // one for Analysis

            for (int i = 0; i < xmlWs.Count; i++)
            {
                CoreWritingSystemDefinition ws = xmlWs[i];
                xmlWsV[i]     = new MenuItem(ws.DisplayLabel, mnuAddWS_Vern);
                xmlWsA[i]     = new MenuItem(ws.DisplayLabel, mnuAddWS_Anal);
                xmlWsV[i].Tag = ws;
                xmlWsA[i].Tag = ws;
            }
            xmlWsV[xmlWs.Count]     = new MenuItem("-");
            xmlWsV[xmlWs.Count + 1] = new MenuItem(LexTextControls.ks_DefineNew_, mnuAddWS_Vern);
            xmlWsA[xmlWs.Count]     = new MenuItem("-");
            xmlWsA[xmlWs.Count + 1] = new MenuItem(LexTextControls.ks_DefineNew_, mnuAddWS_Anal);

            // have to have separate lists
            mnuAddWs.MenuItems.Add(LexTextControls.ks_VernacularWS, xmlWsV);
            mnuAddWs.MenuItems.Add(LexTextControls.ks_AnalysisWS, xmlWsA);

            mnuAddWs.Show(this, new Point(0, Height));
        }
Example #20
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_BeforeRuleSecondaryIgnored()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "& [before 2] a < aa <<< Aa <<< AA"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(data.Count, 0, "No characters should be generated by a before 2 rule");
                    Assert.AreEqual(mapChars.Count, 0, "The rule should have been ignored, no characters ought to have been mapped");
                    Assert.AreEqual(ignoreSet.Count, 0, "Ignorable character incorrectly parsed from rule");
                }
            }
        }
Example #21
0
 public void ChangingLangProjDefaultAnalysisWs_ChangesCacheDefaultAnalWs()
 {
     using (var cache = LcmCache.CreateCacheWithNewBlankLangProj(new TestProjectId(BackendProviderType.kMemoryOnly, null),
                                                                 "en", "fr", "en", m_ui, m_lcmDirectories, new LcmSettings()))
     {
         var wsEn = cache.DefaultAnalWs;
         Assert.That(cache.LangProject.DefaultAnalysisWritingSystem.Handle, Is.EqualTo(wsEn));
         CoreWritingSystemDefinition wsObjGerman = null;
         UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                     () =>
         {
             WritingSystemServices.FindOrCreateWritingSystem(cache, TestDirectoryFinder.TemplateDirectory, "de", true, false, out wsObjGerman);
             Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn));
             cache.LangProject.DefaultAnalysisWritingSystem = wsObjGerman;
             Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle));
         });
         UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor,
                                     () =>
         {
             cache.LangProject.CurAnalysisWss = "en";
             Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn));
         });
         cache.ActionHandlerAccessor.Undo();
         Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle));
         cache.ActionHandlerAccessor.Redo();
         Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn));
     }
 }
Example #22
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_BeforeRuleCombinedWithNormalRuleWorks()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "& a < bb & [before 1] a < aa"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(data.Count, 2, "The [before 1] rule should have added one additional character");
                }
            }
        }
Example #23
0
        private static void AddVariantTypeGlossInfo(ITsIncStrBldr sb, CoreWritingSystemDefinition wsGloss, IList <IMultiUnicode> multiUnicodeAccessors, CoreWritingSystemDefinition wsUser)
        {
            const string sSeriesSeparator = kDefaultSeriesSeparatorLexEntryTypeReverseAbbr;
            var          fBeginSeparator  = true;

            foreach (var multiUnicodeAccessor in multiUnicodeAccessors)
            {
                int wsActual2;
                var tssVariantTypeInfo = multiUnicodeAccessor.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual2);
                // just concatenate them together separated by comma.
                if (tssVariantTypeInfo == null || tssVariantTypeInfo.Length <= 0)
                {
                    continue;
                }
                if (!fBeginSeparator)
                {
                    sb.AppendTsString(TsStringUtils.MakeString(sSeriesSeparator, wsUser.Handle));
                }
                sb.AppendTsString((tssVariantTypeInfo));
                fBeginSeparator = false;
            }

            // Handle the special case where no reverse abbr was found.
            if (fBeginSeparator && multiUnicodeAccessors.Count > 0)
            {
                sb.AppendTsString(multiUnicodeAccessors.ElementAt(0).NotFoundTss);
            }
        }
Example #24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes this CharContextCtrl
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="wsContainer">The writing system container.</param>
        /// <param name="ws">The language definition.</param>
        /// <param name="app">The application.</param>
        /// <param name="contextFont">The context font.</param>
        /// <param name="tokenGrid">The token grid.</param>
        /// ------------------------------------------------------------------------------------
        public void Initialize(LcmCache cache, IWritingSystemContainer wsContainer,
                               CoreWritingSystemDefinition ws, IApp app, Font contextFont, DataGridView tokenGrid)
        {
            m_cache       = cache;
            m_wsContainer = wsContainer;
            m_ws          = ws;
            m_app         = app;
            ContextFont   = contextFont;
            TokenGrid     = tokenGrid;

            var isOkToDisplayScripture = m_cache != null && m_cache.ServiceLocator.GetInstance <IScrBookRepository>().AllInstances().Any();

            if (isOkToDisplayScripture)
            {
                m_scrChecksDllFile = FwDirectoryFinder.BasicEditorialChecksDll;
            }

            if (m_ws != null)
            {
                if (m_ws.RightToLeftScript)
                {
                    // Set the order of the columns for right-to-left text.
                    colContextAfter.DisplayIndex  = colContextBefore.DisplayIndex;
                    colContextBefore.DisplayIndex = gridContext.ColumnCount - 1;
                }
            }
        }
Example #25
0
            public SandboxVc(CachePair caches, InterlinLineChoices choices, bool fIconsForAnalysisChoices, SandboxBase sandbox)
            {
                m_caches  = caches;
                m_cache   = caches.MainCache;               //prior to 9-20-2011 this was not set, if we find there was a reason get rid of this.
                m_choices = choices;
                m_sandbox = sandbox;
                m_fIconsForAnalysisChoices = fIconsForAnalysisChoices;
                m_wsAnalysis       = caches.MainCache.DefaultAnalWs;
                m_wsUi             = caches.MainCache.LanguageWritingSystemFactoryAccessor.UserWs;
                m_tssMissingMorphs = TsStringUtils.MakeString(ITextStrings.ksStars, m_sandbox.RawWordformWs);
                m_tssEmptyAnalysis = TsStringUtils.EmptyString(m_wsAnalysis);
                m_tssEmptyVern     = TsStringUtils.EmptyString(m_sandbox.RawWordformWs);
                m_tssMissingEntry  = m_tssMissingMorphs;
                // It's tempting to re-use m_tssMissingMorphs, but the analysis and vernacular default
                // fonts may have different sizes, requiring differnt line heights to align things well.
                m_tssMissingMorphGloss = TsStringUtils.MakeString(ITextStrings.ksStars, m_wsAnalysis);
                m_tssMissingMorphPos   = TsStringUtils.MakeString(ITextStrings.ksStars, m_wsAnalysis);
                m_tssMissingWordPos    = m_tssMissingMorphPos;
                m_PulldownArrowPic     = OLECvt.ConvertImageToComPicture(ResourceHelper.InterlinPopupArrow);
                m_dxmpArrowPicWidth    = ConvertPictureWidthToMillipoints(m_PulldownArrowPic.Picture);
                CoreWritingSystemDefinition wsObj = caches.MainCache.ServiceLocator.WritingSystemManager.Get(m_sandbox.RawWordformWs);

                if (wsObj != null)
                {
                    m_fRtl = wsObj.RightToLeftScript;
                }
            }
Example #26
0
        public void GetWsForInputMethod_CorrectlyPrioritizesInputMethod()
        {
            var wsEn    = new CoreWritingSystemDefinition("en");
            var wsEnIpa = new CoreWritingSystemDefinition("en-fonipa");
            var wsFr    = new CoreWritingSystemDefinition("fr");
            var wsDe    = new CoreWritingSystemDefinition("de");
            DefaultKeyboardDefinition kbdEn = CreateKeyboard("English", "en-US");

            wsEn.LocalKeyboard = kbdEn;
            DefaultKeyboardDefinition kbdEnIpa = CreateKeyboard("English-IPA", "en-US");

            wsEnIpa.LocalKeyboard = kbdEnIpa;
            DefaultKeyboardDefinition kbdFr = CreateKeyboard("French", "fr-FR");

            wsFr.LocalKeyboard = kbdFr;
            DefaultKeyboardDefinition kbdDe = CreateKeyboard("German", "de-DE");

            wsDe.LocalKeyboard = kbdDe;

            CoreWritingSystemDefinition[] wss = { wsEn, wsFr, wsDe, wsEnIpa };

            // Exact match selects correct one, even though there are other matches for layout and/or culture
            Assert.That(SimpleRootSite.GetWSForInputMethod(kbdEn, wsFr, wss), Is.EqualTo(wsEn));
            Assert.That(SimpleRootSite.GetWSForInputMethod(kbdEnIpa, wsEn, wss), Is.EqualTo(wsEnIpa));
            Assert.That(SimpleRootSite.GetWSForInputMethod(kbdFr, wsDe, wss), Is.EqualTo(wsFr));
            Assert.That(SimpleRootSite.GetWSForInputMethod(kbdDe, wsEn, wss), Is.EqualTo(wsDe));
        }
Example #27
0
        public void GetWSForInputMethod_PrefersWSCurrentIfEqualMatches()
        {
            var wsEn    = new CoreWritingSystemDefinition("en");
            var wsEnUS  = new CoreWritingSystemDefinition("en-US");
            var wsEnIpa = new CoreWritingSystemDefinition("en-fonipa");
            var wsFr    = new CoreWritingSystemDefinition("fr");
            var wsDe    = new CoreWritingSystemDefinition("de");
            DefaultKeyboardDefinition kbdEn = CreateKeyboard("English", "en-US");

            wsEn.LocalKeyboard = kbdEn;
            DefaultKeyboardDefinition kbdEnIpa = CreateKeyboard("English-IPA", "en-US");

            wsEnIpa.LocalKeyboard = kbdEnIpa;
            wsEnUS.LocalKeyboard  = kbdEn;            // exact same keyboard used!
            DefaultKeyboardDefinition kbdFr = CreateKeyboard("French", "fr-FR");

            wsFr.LocalKeyboard = kbdFr;
            DefaultKeyboardDefinition kbdDe = CreateKeyboard("German", "de-DE");

            wsDe.LocalKeyboard = kbdDe;

            CoreWritingSystemDefinition[] wss = { wsEn, wsFr, wsDe, wsEnIpa, wsEnUS };

            // Exact matches
            Assert.That(SimpleRootSite.GetWSForInputMethod(kbdEn, wsFr, wss), Is.EqualTo(wsEn));             // first of 2
            Assert.That(SimpleRootSite.GetWSForInputMethod(kbdEn, wsEn, wss), Is.EqualTo(wsEn));             // prefer default
            Assert.That(SimpleRootSite.GetWSForInputMethod(kbdEn, wsEnUS, wss), Is.EqualTo(wsEnUS));         // prefer default
        }
Example #28
0
        /// <summary>
        /// sets up the dialog without actually showing it.
        /// </summary>
        /// <param name="ws">The writing system which properties will be displayed</param>
        /// <returns>A DialogResult value</returns>
        public int ShowDialog(CoreWritingSystemDefinition ws)
        {
            CheckDisposed();

            SetupDialog(ws, true);
            SwitchTab(kWsSorting);             // force setup of the Sorting tab
            return((int)DialogResult.OK);
        }
Example #29
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the text representation of a TsString.
        /// </summary>
        /// <param name="tss">The TsString.</param>
        /// <returns>text representation of the TsString</returns>
        /// ------------------------------------------------------------------------------------
        private string GetTextRepresentationOfTsString(ITsString tss)
        {
            string tssRepresentation = string.Empty;

            for (int iRun = 0; iRun < tss.RunCount; iRun++)
            {
                tssRepresentation += "<RUN";

                // writing system of run
                int nVar;
                int ws = tss.get_Properties(iRun).GetIntPropValues(
                    (int)FwTextPropType.ktptWs, out nVar);
                if (ws != -1)
                {
                    CoreWritingSystemDefinition wsObj = Services.WritingSystemManager.Get(ws);
                    tssRepresentation += " WS='" + wsObj.Id + "'";
                }

                // character style of run
                string charStyle = tss.get_Properties(iRun).GetStrPropValue(
                    (int)FwTextPropType.ktptNamedStyle);
                string runText = tss.get_RunText(iRun);
                // add the style tags
                if (charStyle != null)
                {
                    tssRepresentation += " CS='" + charStyle + @"'";
                }

                tssRepresentation += ">";

                // add the text for the tag
                if (runText != null && runText != string.Empty)
                {
                    var newString = new StringBuilder(runText.Length * 2);
                    for (var i = 0; i < runText.Length; i++)
                    {
                        // remove '<' and '>' from the text
                        if (runText[i] == '<')
                        {
                            newString.Append("&lt;");
                        }
                        else if (runText[i] == '>')
                        {
                            newString.Append("&gt;");
                        }
                        else
                        {
                            newString.Append(runText[i]);
                        }
                    }
                    tssRepresentation += newString.ToString();
                }

                // add the run end tag
                tssRepresentation += "</RUN>";
            }
            return(tssRepresentation);
        }
Example #30
0
        private void SetAnalysisRightToLeft()
        {
            CoreWritingSystemDefinition wsAnal = Cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem;

            if (wsAnal != null)
            {
                m_fAnalRtl = wsAnal.RightToLeftScript;
            }
        }