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("}");
                }
        }
Example #2
0
        public static UnicodeTrie GenerateBiDiTrie(out BiDiDataEntries biDiDataEntries, out Dictionary <int, BiDiDataItem> biDiData)
        {
            biDiData = new Dictionary <int, BiDiDataItem>();

            var biDiClassEntries =
                UnicodeEnumsGenerator.CreateBiDiClassEnum();

            var biDiClassMappings = CreateTagToIndexMappings(biDiClassEntries);

            var biDiClassData = ReadBiDiData();

            foreach (var(range, name) in biDiClassData)
            {
                var biDiClass = biDiClassMappings[name];

                AddBiDiClassRange(biDiData, range, biDiClass);
            }

            var biDiPairedBracketTypeEntries = UnicodeEnumsGenerator.CreateBiDiPairedBracketTypeEnum();

            var biDiPairedBracketTypeMappings = CreateTagToIndexMappings(biDiPairedBracketTypeEntries);

            var biDiPairedBracketData = ReadBiDiPairedBracketData();

            foreach (var(range, name) in biDiPairedBracketData)
            {
                var bracketType = biDiPairedBracketTypeMappings[name];

                AddBiDiBracket(biDiData, range, bracketType);
            }

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

            foreach (var properties in biDiData.Values)
            {
                //[bracket]|[bracketType]|[biDiClass]
                var value = (properties.BiDiClass << UnicodeData.BIDICLASS_SHIFT) |
                            (properties.BracketType << UnicodeData.BIDIPAIREDBRACKEDTYPE_SHIFT) | properties.Bracket;

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

            biDiDataEntries = new BiDiDataEntries()
            {
                PairedBracketTypes = biDiPairedBracketTypeEntries, BiDiClasses = biDiClassEntries
            };

            var trie = biDiTrieBuilder.Freeze();

            GenerateTrieClass("BiDi", trie);

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

                return(trie);
            }
        }