Esempio n. 1
0
        public void Load_Nonempty()
        {
            CoreWritingSystemDefinition ws1 = m_wsManager.Create("en");

            ws1.CharacterSets.Add(new CharacterSetDefinition("main")
            {
                Characters = { "e", "f", "g", "h" }
            });
            ws1.CharacterSets.Add(new CharacterSetDefinition("punctuation")
            {
                Characters = { ",", "!", "*" }
            });
            ValidCharacters validChars  = ValidCharacters.Load(ws1);
            var             validCharsW = new ValidCharsWrapper(validChars);

            Assert.AreEqual(4, validCharsW.WordFormingCharacters.Count);
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("e"));
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("f"));
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("g"));
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("h"));
            Assert.AreEqual(3, validCharsW.OtherCharacters.Count);
            Assert.IsTrue(validCharsW.OtherCharacters.Contains(","));
            Assert.IsTrue(validCharsW.OtherCharacters.Contains("!"));
            Assert.IsTrue(validCharsW.OtherCharacters.Contains("*"));
            CoreWritingSystemDefinition ws2 = m_wsManager.Create("en");

            validChars.SaveTo(ws2);
            Assert.That(ws1.ValueEquals(ws2), Is.True);
        }
Esempio n. 2
0
        public void Load_DuplicateCharacters()
        {
            CoreWritingSystemDefinition ws = m_wsManager.Create("en-US");

            ws.CharacterSets.Add(new CharacterSetDefinition("main")
            {
                Characters = { "a", "a" }
            });
            ws.CharacterSets.Add(new CharacterSetDefinition("numeric")
            {
                Characters = { "4", "4" }
            });
            ws.CharacterSets.Add(new CharacterSetDefinition("punctuation")
            {
                Characters = { "'", "'" }
            });
            ValidCharacters validChars  = ValidCharacters.Load(ws);
            var             validCharsW = new ValidCharsWrapper(validChars);

            Assert.AreEqual(1, validCharsW.WordFormingCharacters.Count);
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("a"));
            Assert.AreEqual(1, validCharsW.NumericCharacters.Count);
            Assert.IsTrue(validCharsW.NumericCharacters.Contains("4"));
            Assert.AreEqual(1, validCharsW.OtherCharacters.Count);
            Assert.IsTrue(validCharsW.OtherCharacters.Contains("'"));
        }
Esempio n. 3
0
        public void Load_ValidAndBogusCharacters()
        {
            CoreWritingSystemDefinition ws = m_wsManager.Create("en-US");

            ws.CharacterSets.Add(new CharacterSetDefinition("main")
            {
                Characters = { "\u05F6", "g", "\u05F7", "h" }
            });
            ws.CharacterSets.Add(new CharacterSetDefinition("numeric")
            {
                Characters = { "1" }
            });
            ValidCharacters validChars  = ValidCharacters.Load(ws, RememberError);
            var             validCharsW = new ValidCharsWrapper(validChars);

            Assert.AreEqual(2, validCharsW.WordFormingCharacters.Count);
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("g"));
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("h"));
            Assert.AreEqual(1, validCharsW.NumericCharacters.Count);
            Assert.IsTrue(validCharsW.NumericCharacters.Contains("1"));
            Assert.AreEqual(0, validCharsW.OtherCharacters.Count);

            Assert.AreEqual("Invalid ValidChars field while loading the English (United States) writing system. " +
                            "The following characters are invalid:" +
                            Environment.NewLine + "\t\u05F6 (U+05F6)" +
                            Environment.NewLine + "\t\u05F7 (U+05F7)" +
                            Environment.NewLine + "Parameter name: ws",
                            m_lastException.Message);
        }
Esempio n. 4
0
        public void get_IsWordForming()
        {
            var wsManager = new WritingSystemManager();
            CoreWritingSystemDefinition ws = wsManager.Set("zh-CN");

            ws.CharacterSets.Add(new CharacterSetDefinition("main")
            {
                Characters = { "e", "f", "g", "h", "'" }
            });
            ws.CharacterSets.Add(new CharacterSetDefinition("numeric")
            {
                Characters = { "4", "5" }
            });
            ws.CharacterSets.Add(new CharacterSetDefinition("punctuation")
            {
                Characters = { ",", "!", "*" }
            });
            Assert.IsTrue(ws.get_IsWordForming('\''));
            Assert.IsFalse(ws.get_IsWordForming('"'));

            ws.CharacterSets.Clear();
            Assert.IsFalse(ws.get_IsWordForming('\''));
            Assert.IsFalse(ws.get_IsWordForming('"'));
            wsManager.Save();
        }
Esempio n. 5
0
        public void AddCharacter_DuplicateOfOverriddenWordFormingChar()
        {
            CoreWritingSystemDefinition ws = m_wsManager.Create("en-US");

            ws.CharacterSets.Add(new CharacterSetDefinition("main")
            {
                Characters = { "a", "-" }
            });
            ws.CharacterSets.Add(new CharacterSetDefinition("punctuation")
            {
                Characters = { "{" }
            });
            ValidCharacters validChars  = ValidCharacters.Load(ws);
            var             validCharsW = new ValidCharsWrapper(validChars);

            Assert.AreEqual(2, validCharsW.WordFormingCharacters.Count);
            Assert.AreEqual(0, validCharsW.NumericCharacters.Count);
            Assert.AreEqual(1, validCharsW.OtherCharacters.Count);
            Assert.IsTrue(validChars.IsWordForming("-"));
            Assert.IsFalse(validChars.IsWordForming("{"));
            validChars.AddCharacter("-");
            Assert.AreEqual(2, validCharsW.WordFormingCharacters.Count);
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("a"));
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("-"));
            Assert.IsTrue(validChars.IsWordForming("-"));
            Assert.AreEqual(0, validCharsW.NumericCharacters.Count);
            Assert.AreEqual(1, validCharsW.OtherCharacters.Count);
            Assert.IsTrue(validCharsW.OtherCharacters.Contains("{"));
            Assert.IsFalse(validChars.IsWordForming("{"));
        }
 /// <summary>
 /// Copies all of the properties from the source writing system to this writing system.
 /// </summary>
 /// <param name="source">The source writing system.</param>
 public void Copy(CoreWritingSystemDefinition source)
 {
     Language = source.Language;
     Script   = source.Script;
     Region   = source.Region;
     Variants.ReplaceAll(source.Variants);
     Abbreviation      = source.Abbreviation;
     RightToLeftScript = source.RightToLeftScript;
     Fonts.ReplaceAll(source.Fonts.CloneItems());
     DefaultFont        = source.DefaultFont == null ? null : Fonts[source.Fonts.IndexOf(source.DefaultFont)];
     Keyboard           = source.Keyboard;
     VersionNumber      = source.VersionNumber;
     VersionDescription = source.VersionDescription;
     SpellCheckDictionaries.ReplaceAll(source.SpellCheckDictionaries.CloneItems());
     SpellCheckingId = source.SpellCheckingId;
     DateModified    = source.DateModified;
     LocalKeyboard   = source.LocalKeyboard;
     WindowsLcid     = source.WindowsLcid;
     DefaultRegion   = source.DefaultRegion;
     KnownKeyboards.ReplaceAll(source.KnownKeyboards);
     MatchedPairs.Clear();
     MatchedPairs.UnionWith(source.MatchedPairs);
     PunctuationPatterns.Clear();
     PunctuationPatterns.UnionWith(source.PunctuationPatterns);
     QuotationMarks.ReplaceAll(source.QuotationMarks);
     QuotationParagraphContinueType = source.QuotationParagraphContinueType;
     Collations.ReplaceAll(source.Collations.CloneItems());
     DefaultCollation = source.DefaultCollation == null ? null : Collations[source.Collations.IndexOf(source.DefaultCollation)];
     CharacterSets.ReplaceAll(source.CharacterSets.CloneItems());
     LegacyMapping     = source.LegacyMapping;
     IsGraphiteEnabled = source.IsGraphiteEnabled;
 }
Esempio n. 7
0
        public void InterpretChrp()
        {
            var wsManager = new WritingSystemManager();
            CoreWritingSystemDefinition ws = wsManager.Create("en-US");
            var chrp = new LgCharRenderProps
            {
                ws         = ws.Handle,
                szFaceName = new ushort[32],
                dympHeight = 10000,
                ssv        = (int)FwSuperscriptVal.kssvSuper
            };

            MarshalEx.StringToUShort("<default font>", chrp.szFaceName);
            ws.InterpretChrp(ref chrp);

            Assert.AreEqual(ws.DefaultFontName, MarshalEx.UShortToString(chrp.szFaceName));
            Assert.AreEqual(10000 / 3, chrp.dympOffset);
            Assert.AreEqual((10000 * 2) / 3, chrp.dympHeight);
            Assert.AreEqual((int)FwSuperscriptVal.kssvOff, chrp.ssv);

            chrp.ssv        = (int)FwSuperscriptVal.kssvSub;
            chrp.dympHeight = 10000;
            chrp.dympOffset = 0;
            ws.InterpretChrp(ref chrp);

            Assert.AreEqual(-(10000 / 5), chrp.dympOffset);
            Assert.AreEqual((10000 * 2) / 3, chrp.dympHeight);
            Assert.AreEqual((int)FwSuperscriptVal.kssvOff, chrp.ssv);
            wsManager.Save();
        }
Esempio n. 8
0
        public void Create()
        {
            var wsManager = new WritingSystemManager();
            CoreWritingSystemDefinition enWS = wsManager.Create("en-Latn-US-fonipa");

            Assert.That(enWS.Abbreviation, Is.EqualTo("Eng"));
            Assert.That(enWS.Language, Is.EqualTo((LanguageSubtag)"en"));
            Assert.That(enWS.Script, Is.EqualTo((ScriptSubtag)"Latn"));
            Assert.That(enWS.Region, Is.EqualTo((RegionSubtag)"US"));
            Assert.That(enWS.Variants, Is.EqualTo(new VariantSubtag[] { "fonipa" }));
            Assert.That(enWS.DefaultFontName, Is.EqualTo("Charis SIL"));
            Assert.That(enWS.DefaultCollation.ValueEquals(new IcuRulesCollationDefinition("standard")), Is.True);
            Assert.That(enWS.LanguageTag, Is.EqualTo("en-US-fonipa"));
            Assert.That(string.IsNullOrEmpty(enWS.WindowsLcid), Is.True);

            CoreWritingSystemDefinition chWS = wsManager.Create("zh-CN");

            Assert.That(chWS.Abbreviation, Is.EqualTo("Chi"));
            Assert.That(chWS.Language, Is.EqualTo((LanguageSubtag)"zh"));
            Assert.That(chWS.Script, Is.EqualTo((ScriptSubtag)"Hans"));
            Assert.That(chWS.Region, Is.EqualTo((RegionSubtag)"CN"));
            Assert.That(chWS.DefaultFontName, Is.EqualTo("Charis SIL"));
            Assert.That(chWS.DefaultCollation.ValueEquals(new SystemCollationDefinition {
                LanguageTag = "zh-CN"
            }), Is.True);
        }
Esempio n. 9
0
        public void GetNaturalCharType(int codepoint, ValidCharacterType type)
        {
            CoreWritingSystemDefinition ws         = m_wsManager.Create("en-US");
            ValidCharacters             validChars = ValidCharacters.Load(ws);

            Assert.AreEqual(type, ReflectionHelper.GetResult(validChars, "GetNaturalCharType", codepoint));
        }
Esempio n. 10
0
        /// <summary>
        /// Replaces an existing writing system with the specified new writing system if they
        /// have the same identifier.
        /// </summary>
        /// <param name="ws">The writing system.</param>
        public void Replace(CoreWritingSystemDefinition ws)
        {
            lock (m_syncRoot)
            {
                CoreWritingSystemDefinition existingWs;
                if (TryGet(ws.LanguageTag, out existingWs))
                {
                    if (existingWs == ws)
                    {
                        // don't do anything
                        return;
                    }

                    m_handleWSs.Remove(existingWs.Handle);
                    m_repo.Remove(existingWs.Id);
                    m_repo.Set(ws);
                    ws.WritingSystemFactory = this;
                    ws.Handle = existingWs.Handle;
                    m_handleWSs[ws.Handle] = ws;
                }
                else
                {
                    Set(ws);
                }
            }
        }
Esempio n. 11
0
        public void SortAfterAddRange()
        {
            CoreWritingSystemDefinition ws         = m_wsManager.Create("en");
            ValidCharacters             validChars = ValidCharacters.Load(ws);

            validChars.AddCharacters(new[] { "z", "c", "t", "b", "8", "7", "6", "5" });
            VerifySortOrder(validChars);
        }
Esempio n. 12
0
        public void GetStrFromWs()
        {
            var wsManager = new WritingSystemManager();

            Assert.IsNull(wsManager.GetStrFromWs(1));
            CoreWritingSystemDefinition ws = wsManager.Set("en-US");

            Assert.AreEqual("en-US", wsManager.GetStrFromWs(ws.Handle));
            wsManager.Save();
        }
Esempio n. 13
0
        public void get_EngineOrNull()
        {
            var wsManager = new WritingSystemManager();

            Assert.IsNull(wsManager.get_EngineOrNull(1));
            CoreWritingSystemDefinition ws = wsManager.Set("en-US");

            Assert.AreSame(ws, wsManager.get_EngineOrNull(ws.Handle));
            wsManager.Save();
        }
Esempio n. 14
0
 /// <summary>
 /// Sets the specified writing system.
 /// </summary>
 /// <param name="ws">The writing system.</param>
 public void Set(CoreWritingSystemDefinition ws)
 {
     lock (m_syncRoot)
     {
         m_repo.Set(ws);
         ws.WritingSystemFactory = this;
         ws.Handle = m_nextHandle++;
         m_handleWSs[ws.Handle] = ws;
     }
 }
Esempio n. 15
0
        public void GetWsFromStr()
        {
            var wsManager = new WritingSystemManager();

            Assert.AreEqual(0, wsManager.GetWsFromStr("en-US"));
            CoreWritingSystemDefinition ws = wsManager.Set("en-US");

            Assert.AreEqual(ws.Handle, wsManager.GetWsFromStr("en-US"));
            wsManager.Save();
        }
Esempio n. 16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the valid characters from the specified language definition into a new
        /// instance of the <see cref="ValidCharacters"/> class.
        /// </summary>
        /// <returns>A <see cref="ValidCharacters"/> initialized with the valid characters data
        /// from the language definition.</returns>
        /// ------------------------------------------------------------------------------------
        public static ValidCharacters Load(CoreWritingSystemDefinition ws)
        {
            var validChars = new ValidCharacters();

            validChars.AddCharactersFromWritingSystem(ws, "main", ValidCharacterType.WordForming);
            validChars.AddCharactersFromWritingSystem(ws, "punctuation", ValidCharacterType.Other);

            validChars.InitSortComparer(ws);

            return(validChars);
        }
Esempio n. 17
0
 /// <summary>
 /// Gets the specified writing system if it exists, otherwise it creates
 /// a writing system using the specified identifier and sets it.
 /// </summary>
 /// <param name="identifier">The identifier.</param>
 /// <param name="ws">The writing system.</param>
 /// <returns><c>true</c> if the writing system already existed, otherwise <c>false</c></returns>
 public bool GetOrSet(string identifier, out CoreWritingSystemDefinition ws)
 {
     lock (m_syncRoot)
     {
         if (TryGet(identifier, out ws))
         {
             return(true);
         }
         return(Set(identifier, out ws));
     }
 }
Esempio n. 18
0
        public void Load_Empty()
        {
            CoreWritingSystemDefinition ws1        = m_wsManager.Create("en");
            ValidCharacters             validChars = ValidCharacters.Load(ws1);

            Assert.That(validChars.WordFormingCharacters, Is.Empty);
            Assert.That(validChars.OtherCharacters, Is.Empty);
            CoreWritingSystemDefinition ws2 = m_wsManager.Create("en");

            validChars.SaveTo(ws2);
            Assert.That(ws1.ValueEquals(ws2), Is.True);
        }
Esempio n. 19
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sorts the lists.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void InitSortComparer(CoreWritingSystemDefinition ws)
        {
            if (m_comparer != null && m_comparer.WritingSystem != ws)
            {
                m_comparer = null;
            }

            if (m_comparer == null && ws != null)
            {
                m_comparer = new TsStringComparer(ws);
            }
        }
Esempio n. 20
0
        public void IsWordFormingChar()
        {
            CoreWritingSystemDefinition ws = m_wsManager.Create("en-US");

            ws.CharacterSets.Add(new CharacterSetDefinition("main")
            {
                Characters = { "a", "b", "c", "d", "e", "#" }
            });
            ValidCharacters validChars = ValidCharacters.Load(ws);

            Assert.IsTrue(validChars.IsWordForming('#'));
        }
Esempio n. 21
0
        public void CreateAudioWritingSystemVariantFirst()
        {
            var wsManager = new WritingSystemManager();

            CoreWritingSystemDefinition newWs = wsManager.Create(WellKnownSubtags.UnlistedLanguage, null, null, Enumerable.Empty <VariantSubtag>());

            Assert.DoesNotThrow(() =>
            {
                newWs.Variants.Add(WellKnownSubtags.AudioPrivateUse);
                newWs.Script = WellKnownSubtags.AudioScript;
            });
        }
Esempio n. 22
0
        public void AddCharacter_SuperscriptedToneNumber()
        {
            CoreWritingSystemDefinition ws         = m_wsManager.Create("en-US");
            ValidCharacters             validChars = ValidCharacters.Load(ws);
            var validCharsW = new ValidCharsWrapper(validChars);

            validChars.AddCharacter("\u00b9");
            validChars.AddCharacter("\u2079");
            Assert.AreEqual(2, validCharsW.WordFormingCharacters.Count);
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("\u00b9"));
            Assert.IsTrue(validCharsW.WordFormingCharacters.Contains("\u2079"));
            Assert.AreEqual(0, validCharsW.OtherCharacters.Count);
        }
Esempio n. 23
0
 /// <summary>
 /// Gets the specified writing system if it exists.
 /// </summary>
 /// <param name="identifier">The identifier.</param>
 /// <param name="ws">The writing system.</param>
 /// <returns></returns>
 public bool TryGet(string identifier, out CoreWritingSystemDefinition ws)
 {
     lock (m_syncRoot)
     {
         if (Exists(identifier))
         {
             ws = Get(identifier);
             return(true);
         }
         ws = null;
         return(false);
     }
 }
Esempio n. 24
0
        public void Load_AllowGroupedCombiningDiacritics()
        {
            CoreWritingSystemDefinition ws = m_wsManager.Create("en-US");

            ws.CharacterSets.Add(new CharacterSetDefinition("main")
            {
                Characters = { "a\u0301" }
            });                                                                                                  // combining acute accent
            var validChars = ValidCharacters.Load(ws).WordFormingCharacters.ToList();

            Assert.AreEqual(1, validChars.Count);
            CollectionAssert.Contains(validChars, "a\u0301");
        }
Esempio n. 25
0
        private void AddCharactersFromWritingSystem(CoreWritingSystemDefinition ws, string charSetType, ValidCharacterType validCharType)
        {
            CharacterSetDefinition charSet;

            if (!ws.CharacterSets.TryGet(charSetType, out charSet))
            {
                return;
            }

            foreach (string chr in charSet.Characters)
            {
                AddCharacter(chr, validCharType);
            }
        }
Esempio n. 26
0
        public void Load_AllowHardLineBreakCharacter()
        {
            CoreWritingSystemDefinition ws1 = m_wsManager.Create("en");

            ws1.CharacterSets.Add(new CharacterSetDefinition("punctuation")
            {
                Characters = { "\u2028" }
            });
            ValidCharacters validChars  = ValidCharacters.Load(ws1);
            var             validCharsW = new ValidCharsWrapper(validChars);

            Assert.AreEqual(1, validCharsW.OtherCharacters.Count);
            Assert.IsTrue(validCharsW.OtherCharacters.Contains("\u2028"));
        }
Esempio n. 27
0
        public void Load_AllowMultigraphs()
        {
            CoreWritingSystemDefinition ws1 = m_wsManager.Create("en");

            ws1.CharacterSets.Add(new CharacterSetDefinition("punctuation")
            {
                Characters = { "Ll", "Sch", "Th" }
            });
            var validChars = ValidCharacters.Load(ws1).OtherCharacters.ToList();

            Assert.AreEqual(3, validChars.Count);
            CollectionAssert.Contains(validChars, "Ll");
            CollectionAssert.Contains(validChars, "Sch");
            CollectionAssert.Contains(validChars, "Th");
        }
Esempio n. 28
0
        public void Load_Empty()
        {
            CoreWritingSystemDefinition ws1        = m_wsManager.Create("en");
            ValidCharacters             validChars = ValidCharacters.Load(ws1, RememberError);
            var validCharsW = new ValidCharsWrapper(validChars);

            Assert.That(validCharsW.WordFormingCharacters, Is.Empty);
            Assert.That(validCharsW.NumericCharacters, Is.Empty);
            Assert.That(validCharsW.OtherCharacters, Is.Empty);
            CoreWritingSystemDefinition ws2 = m_wsManager.Create("en");

            validChars.SaveTo(ws2);
            Assert.That(ws1.ValueEquals(ws2), Is.True);
            Assert.That(m_lastException, Is.Null);
        }
Esempio n. 29
0
        public void SortAfterAddSingles()
        {
            CoreWritingSystemDefinition ws         = m_wsManager.Create("en");
            ValidCharacters             validChars = ValidCharacters.Load(ws);

            validChars.AddCharacter("z");
            validChars.AddCharacter("c");
            validChars.AddCharacter("t");
            validChars.AddCharacter("b");
            validChars.AddCharacter("8");
            validChars.AddCharacter("7");
            validChars.AddCharacter("6");
            validChars.AddCharacter("5");
            VerifySortOrder(validChars);
        }
Esempio n. 30
0
        public void GetNaturalCharType()
        {
            CoreWritingSystemDefinition ws         = m_wsManager.Create("en-US");
            ValidCharacters             validChars = ValidCharacters.Load(ws);

            Assert.AreEqual(ValidCharacterType.WordForming,
                            ReflectionHelper.GetResult(validChars, "GetNaturalCharType", (int)'a'));
            Assert.AreEqual(ValidCharacterType.WordForming,
                            ReflectionHelper.GetResult(validChars, "GetNaturalCharType", 0x00B2));
            Assert.AreEqual(ValidCharacterType.WordForming,
                            ReflectionHelper.GetResult(validChars, "GetNaturalCharType", 0x2079));
            Assert.AreEqual(ValidCharacterType.Numeric,
                            ReflectionHelper.GetResult(validChars, "GetNaturalCharType", (int)'1'));
            Assert.AreEqual(ValidCharacterType.Other,
                            ReflectionHelper.GetResult(validChars, "GetNaturalCharType", (int)' '));
        }