예제 #1
0
        public static void CreatePropertyValueAliasHelper(UnicodeDataEntries unicodeDataEntries,
                                                          BiDiDataEntries biDiDataEntries)
        {
            using (var stream = File.Create("Generated\\PropertyValueAliasHelper.cs"))
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine("using System.Collections.Generic;");
                    writer.WriteLine();

                    writer.WriteLine("namespace Avalonia.Media.TextFormatting.Unicode");
                    writer.WriteLine("{");
                    writer.WriteLine("    internal static class PropertyValueAliasHelper");
                    writer.WriteLine("    {");

                    WritePropertyValueAliasGetTag(writer, unicodeDataEntries.Scripts, "Script", "Zzzz");

                    WritePropertyValueAlias(writer, unicodeDataEntries.Scripts, "Script", "Unknown");

                    WritePropertyValueAlias(writer, unicodeDataEntries.GeneralCategories, "GeneralCategory", "Other");

                    WritePropertyValueAlias(writer, unicodeDataEntries.LineBreakClasses, "LineBreakClass", "Unknown");

                    WritePropertyValueAlias(writer, biDiDataEntries.PairedBracketTypes, "BiDiPairedBracketType", "None");

                    WritePropertyValueAlias(writer, biDiDataEntries.BiDiClasses, "BiDiClass", "LeftToRight");

                    writer.WriteLine("    }");
                    writer.WriteLine("}");
                }
        }
예제 #2
0
        public static UnicodeTrie GenerateUnicodeDataTrie(out UnicodeDataEntries dataEntries, out Dictionary <int, UnicodeDataItem> unicodeData)
        {
            var generalCategoryEntries =
                UnicodeEnumsGenerator.CreateGeneralCategoryEnum();

            var generalCategoryMappings = CreateTagToIndexMappings(generalCategoryEntries);

            var scriptEntries = UnicodeEnumsGenerator.CreateScriptEnum();

            var scriptMappings = CreateNameToIndexMappings(scriptEntries);

            var lineBreakClassEntries =
                UnicodeEnumsGenerator.CreateLineBreakClassEnum();

            var lineBreakClassMappings = CreateTagToIndexMappings(lineBreakClassEntries);

            unicodeData = GetUnicodeData(generalCategoryMappings, scriptMappings, lineBreakClassMappings);

            var unicodeDataTrieBuilder = new UnicodeTrieBuilder(/*initialValue*/);

            foreach (var properties in unicodeData.Values)
            {
                //[line break]|[biDi]|[script]|[category]
                var value = (properties.LineBreakClass << UnicodeData.LINEBREAK_SHIFT) |
                            (properties.Script << UnicodeData.SCRIPT_SHIFT) | properties.GeneralCategory;

                unicodeDataTrieBuilder.Set(properties.Codepoint, (uint)value);
            }

            dataEntries = new UnicodeDataEntries
            {
                Scripts           = scriptEntries,
                GeneralCategories = generalCategoryEntries,
                LineBreakClasses  = lineBreakClassEntries
            };

            var trie = unicodeDataTrieBuilder.Freeze();

            GenerateTrieClass("UnicodeData", trie);

            using (var stream = File.Create("Generated\\UnicodeData.trie"))
            {
                trie.Save(stream);

                return(trie);
            }
        }