public void Show(FontFamily font, char glyph, string code)
        {
            lblGlyph.FontFamily = font;
            lblGlyph.Content    = glyph.ToString();
            this.Title          = $"Details - U+{code}";

            var info = UnicodeInfo.GetCharInfo(glyph);

            lblName.Content = info.Name.Replace("WITH", "\nWITH");
            lblName.ToolTip = info.Name;
            tbxCode.Text    = $"U+{code} (&#x{code};) [Alt+{Convert.ToInt32(code, 16),0:D4}]";

            if (!string.IsNullOrEmpty(info.OldName))
            {
                PrintCharInfo("Old Name", info.OldName);
            }

            PrintCharInfo("Category", info.Category.ToString());
            PrintCharInfo("Block", info.Block);
            PrintCharInfo("Canoncial Combining Class", info.CanonicalCombiningClass.ToString());
            PrintCharInfo("Bidirectional Class", info.BidirectionalClass.ToString());
            PrintCharInfo("Contributory Properties", info.ContributoryProperties.ToString());
            PrintCharInfo("Core Properties", info.CoreProperties.ToString());

            this.Show();
        }
Ejemplo n.º 2
0
        private string GetResult(int value)
        {
            var  sb = new StringBuilder();
            char ch = (char)value;

            bool   isSurrogate = char.IsSurrogate(ch);
            string text        = null;

            if (!isSurrogate)
            {
                text = char.ConvertFromUtf32(value);
                sb.AppendLine(DivClass(Escape(text), "charSample"));
            }

            if (descriptions.TryGetValue(value, out string description))
            {
                sb.AppendLine(Div(description));
            }

            var info = UnicodeInfo.GetCharInfo(value);

            sb.AppendLine(TableStart("smallTable"));
            sb.AppendLine(Tr(Td(Gray("Code point:")), Td($"{value} (U+{value.ToHex()})")));
            sb.AppendLine(Tr(Td(Gray("Category:")), Td(CharUnicodeInfo.GetUnicodeCategory(ch).ToString())));
            sb.AppendLine(Tr(Td(Gray("Block:")), Td(info.Block)));
            sb.AppendLine(Tr(Td(Gray("Escape:")), Td(DivClass(GetEscapeString(value), "fixed"))));
            if (text != null)
            {
                sb.AppendLine(Tr(Td(Gray("UTF-8:")), Td(GetUtf8(text))));
            }

            sb.AppendLine("</table>");

            return(sb.ToString());
        }
        public static Models.CodePoint GetCodePoint(UnicodeCharInfo charInfo)
        {
            var category = UnicodeCategoryInfo.Get(charInfo.Category);

            return(new Models.CodePoint
                   (
                       charInfo.CodePoint,
                       UnicodeInfo.GetDisplayText(charInfo),
                       charInfo.Name,
                       charInfo.OldName,
                       charInfo.NameAliases.Select(na => new Models.NameAlias((Models.UnicodeNameAliasKind)(int) na.Kind, na.Name)).ToArray(),
                       new Models.UnicodeCategory(category.ShortName, category.LongName),
                       charInfo.Block,

                       (Models.UnicodeNumericType)(int) charInfo.NumericType,
                       (Models.UnihanNumericType)(int) charInfo.UnihanNumericType,
                       charInfo.NumericValue != null ?
                       new Models.RationalNumber(charInfo.NumericValue.GetValueOrDefault().Numerator, charInfo.NumericValue.GetValueOrDefault().Denominator) :
                       null,

                       charInfo.Definition,
                       charInfo.MandarinReading,
                       charInfo.CantoneseReading,
                       charInfo.JapaneseKunReading,
                       charInfo.JapaneseOnReading,
                       charInfo.KoreanReading,
                       charInfo.HangulReading,
                       charInfo.VietnameseReading,

                       charInfo.SimplifiedVariant,
                       charInfo.TraditionalVariant
                   ));
        }
Ejemplo n.º 4
0
 public void MethodGetDisplayTextShouldNeverFail()
 {
     for (int i = 0; i <= 0x10FFFF; i++)
     {
         UnicodeInfo.GetDisplayText(i);
     }
 }
Ejemplo n.º 5
0
        private static List <IndexEntry> BuildUnicodeIndex()
        {
            var sw     = Stopwatch.StartNew();
            var result = new List <IndexEntry>();
            var blocks = UnicodeInfo.GetBlocks();

            foreach (var block in blocks)
            {
                foreach (var codepoint in block.CodePointRange)
                {
                    if (char.IsSurrogate((char)codepoint))
                    {
                        continue;
                    }

                    var charInfo    = UnicodeInfo.GetCharInfo(codepoint);
                    var displayText = charInfo.Name;
                    if (displayText != null)
                    {
                        result.Add(new(charInfo, displayText, displayText.ToUpperInvariant()));
                    }
                }
            }

            Console.WriteLine("Index built in " + sw.Elapsed);
            return(result);
        }
Ejemplo n.º 6
0
 public void MethodGetCategoryShouldNeverFail()
 {
     for (int i = 0; i <= 0x10FFFF; i++)
     {
         UnicodeInfo.GetCategory(i);
     }
 }
Ejemplo n.º 7
0
 public void MethodGetCharInfoShouldNeverFail()
 {
     for (int i = 0; i <= 0x10FFFF; i++)
     {
         UnicodeInfo.GetCharInfo(i);
     }
 }
Ejemplo n.º 8
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int codePoint;

            if (value is int)
            {
                codePoint = (int)value;
            }
            else if (value is char)
            {
                codePoint = (char)value;
            }
            else if (value is string)
            {
                codePoint = ((string)value)[0];
            }
            else
            {
                //throw new ArgumentException("Unsupported value type.");
                return(null);
            }

            var info = UnicodeInfo.GetChar(codePoint);

            return("U+" + codePoint.ToString("X4") + "  " + info.Name);
        }
        public static Models.CodePoint[] GetCodePoints(int offset, int limit)
        {
            if (offset < 0 || offset > 0x10FFFF)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            if (limit < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(limit));
            }

            var codePoints = new List <Models.CodePoint>();

            int max = Math.Min(offset + limit - 1, 0x10FFFF);

            for (int i = offset; i <= max; i++)
            {
                var charInfo = UnicodeInfo.GetCharInfo(i);

                if (charInfo.Category != UnicodeCategory.OtherNotAssigned)
                {
                    codePoints.Add(GetCodePoint(charInfo));
                }
            }

            return(codePoints.ToArray());
        }
Ejemplo n.º 10
0
 public void ControlCharactersShouldHaveSpecificDisplayText()
 {
     for (int i = 0; i <= 0x20; ++i)
     {
         Assert.Equal(char.ConvertFromUtf32(0x2400 + i), UnicodeInfo.GetDisplayText(i));
         Assert.Equal(char.ConvertFromUtf32(0x2400 + i), UnicodeInfo.GetDisplayText(UnicodeInfo.GetCharInfo(i)));
     }
 }
Ejemplo n.º 11
0
        private static void PrintCodePointInfo(int codePoint)
        {
            var charInfo = UnicodeInfo.GetCharInfo(codePoint);

            Console.WriteLine(UnicodeInfo.GetDisplayText(charInfo));
            Console.WriteLine("U+" + codePoint.ToString("X4"));
            Console.WriteLine(charInfo.Name ?? charInfo.OldName);
            Console.WriteLine(charInfo.Category);
        }
Ejemplo n.º 12
0
        public override string ToDescriptionString()
        {
            var info = UnicodeInfo.GetCharInfo(codePoint);

            return(base.ToLongString() + "\n" +
                   "Kun: " + info.JapaneseKunReading + "\n" +
                   "On: " + info.JapaneseOnReading + "\n" +
                   info.Definition + "\n");
        }
Ejemplo n.º 13
0
 public void RadicalUnicodeCategories()
 {
     foreach (var radical in lookup.AllRadicals)
     {
         Console.Write(radical.ToString());
         Console.Write(": ");
         var info = UnicodeInfo.GetCharInfo(radical.Utf32);
         Console.WriteLine(info.Name);
     }
 }
Ejemplo n.º 14
0
        public void MethodGetCharInfoShouldHaveCoherentResults()
        {
            for (int i = 0; i <= 0x10FFFF; i++)
            {
                var charInfo = UnicodeInfo.GetCharInfo(i);

                Assert.Equal(charInfo.Name, UnicodeInfo.GetName(i));
                Assert.Equal(charInfo.Category, UnicodeInfo.GetCategory(i));
                Assert.Equal(UnicodeInfo.GetDisplayText(charInfo), UnicodeInfo.GetDisplayText(i));
            }
        }
Ejemplo n.º 15
0
        private void UpdateDisplayText()
        {
            string oldValue = displayText;

            displayText = character != null?UnicodeInfo.GetDisplayText(characterInfo) : null;

            if (displayText != oldValue)
            {
                NotifyPropertyChanged(nameof(DisplayText));
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            var radicalStrokeCount = (UnicodeRadicalStrokeCount)value;
            var radical            = UnicodeInfo.GetCjkRadicalInfo(radicalStrokeCount.Radical);

            return(radicalStrokeCount.IsSimplified ? radical.TraditionalRadicalCodePoint : radical.SimplifiedRadicalCodePoint);
        }
Ejemplo n.º 17
0
        public void Show(MainWindow owner)
        {
            this.Owner = owner;

            cbxBlocks.ItemsSource     = UnicodeInfo.GetBlocks().Select(b => $"{b.Name} [{b.CodePointRange.ToString().Replace("..", "-")}]");
            cbxCategories.ItemsSource = Enum.GetNames(typeof(UnicodeCategory));

            cbxBlocks.SelectedIndex   = cbxCategories.SelectedIndex = 0;
            chxBlockApplies.IsChecked = chxCategoryApplies.IsChecked = false;

            Show();
        }
        private static Dictionary <string, string> CreateUnicodeHashSet()
        {
            Dictionary <string, string> unicodeTable = new Dictionary <string, string>();

            for (int i = 0x13000; i < 0x1342E; i++)
            {
                string unicodeString = char.ConvertFromUtf32(i);
                string unicodeName   = UnicodeInfo.GetName(i).Split(' ').ToList().Last();
                unicodeName = FixUnicodeName(unicodeName);
                unicodeTable.Add(unicodeName, unicodeString);
            }
            return(unicodeTable);
        }
Ejemplo n.º 19
0
        private void UpdateFontView(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (sender is System.Windows.Controls.Image)
            {
                string preview = "";

                WriteableBitmap wbm = (WriteableBitmap)((System.Windows.Controls.Image)sender).Source;

                int[] Pixels = new int[TheFontW * TheFontH];
                wbm.CopyPixels(Pixels, wbm.BackBufferStride, 0);

                // lets use the average algorithm to get gray scale (4 bytes to 1)
                for (int x = 0; x < Pixels.Length; x++)
                {
                    // get the greyscale pixel
                    int average = GSPixel(Pixels[x]);

                    // Large Preview 1Bit per pixel
                    if (average > Threshold.Value)
                    {
                        preview += "@";
                    }
                    else if (average > Threshold.Value / 2)
                    {
                        preview += "&";
                    }
                    else
                    {
                        preview += ".";
                    }

                    if (x % wbm.PixelWidth == wbm.PixelWidth - 1)
                    {
                        preview += " ";
                    }
                }

                preview += Environment.NewLine + Environment.NewLine;

                string c        = ((System.Windows.Controls.Image)sender).ToolTip.ToString();
                string charname = UnicodeInfo.GetName((char)int.Parse(c));
                if (!string.IsNullOrEmpty(charname))
                {
                    preview += charname;
                }

                Preview.Text = preview;
            }
        }
        private static BlockInformation[] GetBlocksInternal()
        {
            var blocks = UnicodeInfo.GetBlocks();

            var blockViewModel = new BlockInformation[blocks.Length];

            for (int i = 0; i < blocks.Length; i++)
            {
                var block = blocks[i];

                blockViewModel[i] = new BlockInformation(block.Name, BlockMetadata.GetDescription(block.Name), new CodePointRange(block.CodePointRange.FirstCodePoint, block.CodePointRange.LastCodePoint));
            }

            return(blockViewModel);
        }
Ejemplo n.º 21
0
        public void RadicalStrokeCountShouldHaveExpectedResults()
        {
            var char5E7A = UnicodeInfo.GetCharInfo(0x5E7A);

            Assert.NotEmpty(char5E7A.UnicodeRadicalStrokeCounts);
            Assert.False(char5E7A.UnicodeRadicalStrokeCounts[0].IsSimplified);
            Assert.Equal(52, char5E7A.UnicodeRadicalStrokeCounts[0].Radical);
            Assert.Equal(0, char5E7A.UnicodeRadicalStrokeCounts[0].StrokeCount);

            var char2A6D6 = UnicodeInfo.GetCharInfo(0x2A6D6);

            Assert.NotEmpty(char2A6D6.UnicodeRadicalStrokeCounts);
            Assert.False(char2A6D6.UnicodeRadicalStrokeCounts[0].IsSimplified);
            Assert.Equal(214, char2A6D6.UnicodeRadicalStrokeCounts[0].Radical);
            Assert.Equal(20, char2A6D6.UnicodeRadicalStrokeCounts[0].StrokeCount);
        }
 public void CodePointEncodingTest()
 {
     using (var stream = new MemoryStream(4))
         using (var writer = new BinaryWriter(stream, Encoding.UTF8, true))
             using (var reader = new BinaryReader(stream, Encoding.UTF8, true))
             {
                 for (int i = 0; i <= 0x10FFFF; ++i)
                 {
                     writer.WriteCodePoint(i);
                     writer.Flush();
                     stream.Position = 0;
                     Assert.Equal(i, UnicodeInfo.ReadCodePoint(reader));
                     stream.Position = 0;
                 }
             }
 }
Ejemplo n.º 23
0
        public static CodePoint FromInt(int codePoint)
        {
            var info = UnicodeInfo.GetCharInfo(codePoint);

            switch (info.Block)
            {
            case "Hiragana":
                return(new Hiragana(codePoint));

            case "Katakana":
                return(new Katakana(codePoint));

            case "CJK Unified Ideographs":
                return(new Kanji(codePoint));

            default:
                return(new CodePoint(codePoint));
            }
        }
Ejemplo n.º 24
0
        public void CharacterInfoShouldHaveExpectedResults(int codePoint, UnicodeCategory expectedCategory, UnicodeNumericType expectedNumericType, string expectedNumericValue, string expectedName, string expectedBlock)
        {
            var info = UnicodeInfo.GetCharInfo(codePoint);

            Assert.Equal(codePoint, info.CodePoint);
            Assert.Equal(expectedCategory, info.Category);
            Assert.Equal(expectedNumericType, info.NumericType);
            if (expectedNumericValue != null)
            {
                Assert.Equal(UnicodeRationalNumber.Parse(expectedNumericValue), info.NumericValue);
            }
            else
            {
                Assert.Null(info.NumericValue);
            }
            Assert.Equal(expectedName, info.Name);
            Assert.Equal(expectedBlock, UnicodeInfo.GetBlockName(codePoint));
            Assert.Equal(expectedBlock, info.Block);
        }
Ejemplo n.º 25
0
        /*
         * //	Format:
         *      //	U,V,Width,Height
         */
        private void WriteTextCoords(int textureIndex)
        {
            int rpt;
            int cpt;
            int spt;
            int offset;

            if (textureIndex == 0)
            {
                rpt    = this.FontInfo.UVInfo.PrimaryRowsPerTexture;
                cpt    = this.FontInfo.UVInfo.PrimaryColumnsPerTexture;
                spt    = this.FontInfo.UVInfo.PrimarySpritesPerTexture;
                offset = 0;
            }
            else
            {
                rpt    = this.FontInfo.UVInfo.AuxRowsPerTexture;
                cpt    = this.FontInfo.UVInfo.AuxColumnsPerTexture;
                spt    = this.FontInfo.UVInfo.AuxSpritesPerTexture;
                offset = this.FontInfo.UVInfo.PrimarySpritesPerTexture - this.FontInfo.UVInfo.AuxSpritesPerTexture;
            }

            File.AppendLine($"static constexpr unsigned int {this.TextSizeName.ToLowerInvariant()}_font_{textureIndex}_texcoords[] = {{");
            for (int i = 0; i < rpt; i++)
            {
                for (int j = 0; j < cpt; j++)
                {
                    int characterIndex = (i * cpt) + j + (spt * textureIndex) + offset;
                    if (characterIndex >= this.Charset.Count)
                    {
                        break;
                    }
                    var charEntry = this.FontInfo.CharMap.First(c => c.Character == this.Charset[characterIndex]);
                    File.AppendLine($"    {j * this.FontInfo.UVInfo.TileWidth}, " +
                                    $"{i * this.FontInfo.UVInfo.TileHeight}, {charEntry.Width}, " +
                                    $"TEXT_{this.TextSizeName.Substring(0, 1)}Y, // {UnicodeInfo.GetName(charEntry.Character)}");
                }
            }
            File.AppendLine();
            File.AppendLine("};");
        }
Ejemplo n.º 26
0
        private void Initialize()
        {
            var builder = new IndexBuilder();

            for (int i = 0; i <= 0x10FFFF; i++)
            {
                var    charInfo = UnicodeInfo.GetCharInfo(i);
                string name     = charInfo.Name;

                if (!string.IsNullOrEmpty(name))
                {
                    foreach (string word in name.Split(i == 0x1180 ? SimplifiedWordSeparators : WordSeparators))
                    {
                        builder.AddWord(word, i);
                    }
                }

                if (!string.IsNullOrEmpty(charInfo.OldName))
                {
                    foreach (string word in RemoveForbiddenCharacters(charInfo.OldName).Split(WordSeparators))
                    {
                        builder.AddWord(word, i);
                    }
                }

                if (charInfo.NameAliases.Count > 0)
                {
                    foreach (var nameAlias in charInfo.NameAliases)
                    {
                        foreach (string word in nameAlias.Name.Split(WordSeparators))
                        {
                            builder.AddWord(word, i);
                        }
                    }
                }
            }

            _wordIndex = builder.Build();

            GC.Collect();
        }
Ejemplo n.º 27
0
        private void BuildUnicodeList()
        {
            var blocks = UnicodeInfo.GetBlocks();

            foreach (var block in blocks)
            {
                foreach (var codepoint in block.CodePointRange)
                {
                    if (char.IsSurrogate((char)codepoint))
                    {
                        continue;
                    }

                    var charInfo    = UnicodeInfo.GetCharInfo(codepoint);
                    var displayText = charInfo.Name;
                    if (displayText != null)
                    {
                        descriptions[codepoint] = displayText;
                    }
                }
            }
        }
Ejemplo n.º 28
0
        private string GetCharEncoded(int[] bits, char c)
        {
            StringBuilder result = new StringBuilder();

            BitArray ba = new BitArray(TheFontH * TheFontW);

            // lets use the average algorithm to get gray scale (4 bytes to 1)
            for (int x = 0; x < bits.Length; x++)
            {
                // get the greyscale pixel
                int average = GSPixel(bits[x]);

                // encode to 1Bit per pixel
                if (average > Threshold.Value)
                {
                    ba[x] = true;
                }
                else
                {
                    ba[x] = false;
                }
            }

            byte[] fontbyte = new byte[TheFontH * TheFontW / 8];
            ba.CopyTo(fontbyte, 0);

            // encode the font bits into code
            result.Append("            new byte[] { ");

            foreach (var b in fontbyte)
            {
                result.Append($"0x{b:X2}, ");
            }
            result.Remove(result.Length - 2, 2);

            result.Append($"}}, //{(int)c:X4}({c}) {UnicodeInfo.GetName(c)?.ToLowerInvariant()}");

            return(result.ToString());
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            string        fontPath = @"C:\Users\zhdon\Desktop\lsu.ttf";
            Uri           fontUri  = new Uri(fontPath);
            GlyphTypeface gt       = new GlyphTypeface(fontUri);

            WriteLine("FONT_METRICS.glyphCount = {0}", gt.GlyphCount);
            WriteLine("FONT_METRICS.baseline = {0}", gt.Baseline);
            WriteLine("FONT_METRICS.capsHeight = {0}", gt.CapsHeight);
            WriteLine("FONT_METRICS.xHeight = {0}", gt.XHeight);
            WriteLine("FONT_METRICS.height = {0}", gt.Height);
            WriteLine("FONT_METRICS.glyphs = {0}", "GLYPHS");
            foreach (var kvp in gt.CharacterToGlyphMap)
            {
                var          code    = kvp.Key;
                var          c       = char.ConvertFromUtf32(code);
                var          i       = kvp.Value;
                const double em      = 18;
                var          g       = gt.GetGlyphOutline(i, em, em);
                var          width   = (g.Bounds.Right - g.Bounds.Left) / em;
                var          ascent  = (0 - g.Bounds.Top) / em;
                var          descent = g.Bounds.Bottom / em;
                if (double.IsInfinity(ascent) || double.IsInfinity(descent))
                {
                    continue;
                }
                WriteLine("GLYPHS[{0}] = Glyph('{1}', '{2}', {3}, {4}, {5}, {6}, {7})",
                          code,
                          c != "'" && c != "\\" ? c : "\\" + c,
                          UnicodeInfo.GetName(code).ToLower(),
                          gt.AdvanceWidths[i],
                          descent,
                          ascent,
                          gt.LeftSideBearings[i],
                          gt.RightSideBearings[i]);
            }
            Pause();
        }
Ejemplo n.º 30
0
        public void RadicalInfoShouldHaveExpectedResults()
        {
            var radical1 = UnicodeInfo.GetCjkRadicalInfo(1);

            Assert.False(radical1.HasSimplifiedForm);
            Assert.Equal(1, radical1.RadicalIndex);
            Assert.Equal('\u2F00', radical1.TraditionalRadicalCodePoint);
            Assert.Equal('\u4E00', radical1.TraditionalCharacterCodePoint);
            Assert.Equal('\u2F00', radical1.SimplifiedRadicalCodePoint);
            Assert.Equal('\u4E00', radical1.SimplifiedCharacterCodePoint);

            var radical214 = UnicodeInfo.GetCjkRadicalInfo(214);

            Assert.False(radical214.HasSimplifiedForm);
            Assert.Equal(214, radical214.RadicalIndex);
            Assert.Equal('\u2FD5', radical214.TraditionalRadicalCodePoint);
            Assert.Equal('\u9FA0', radical214.TraditionalCharacterCodePoint);
            Assert.Equal('\u2FD5', radical214.SimplifiedRadicalCodePoint);
            Assert.Equal('\u9FA0', radical214.SimplifiedCharacterCodePoint);

            Assert.Throws <IndexOutOfRangeException>(() => UnicodeInfo.GetCjkRadicalInfo(0));
            Assert.Throws <IndexOutOfRangeException>(() => UnicodeInfo.GetCjkRadicalInfo(215));
        }