public void MethodGetNameShouldNeverFail() { for (int i = 0; i <= 0x10FFFF; i++) { UnicodeInfo.GetName(i); } }
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)); } }
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); }
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; } }
/* * // 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("};"); }
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()); }
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(); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return(value != null?UnicodeInfo.GetName((int)value) : null); }
public void HangulNameShouldReturnExpectedResult(string expectedName, int codePoint) => Assert.Equal(expectedName, UnicodeInfo.GetName(codePoint));
private void UpdateNewFont() { string cr = ""; foreach (Typeface typeface in TheFontFamily.GetTypefaces()) { // which face are we using ? typeface.TryGetGlyphTypeface(out GlyphTypeface glyph); if (glyph != null) { characterMap = glyph.CharacterToGlyphMap; cr = glyph.Copyrights.Values.FirstOrDefault(); } } MyCharMap = new Dictionary <int, int>(); GridOChars.Children.Clear(); GridOChars.RowDefinitions.Clear(); GridOChars.ColumnDefinitions.Clear(); //Populate GridoChars for (int y = 0; y < 30; y++) { GridOChars.RowDefinitions.Add(new RowDefinition()); } for (int x = 0; x < 60; x++) { GridOChars.ColumnDefinitions.Add(new ColumnDefinition()); } // start at space (Char 32 x20) int c = 32; for (int y = 0; y < 30; y++) { for (int x = 0; x < 60; x++) { bool skipping = true; while (skipping && c < 0xFFFF) { if (characterMap.ContainsKey(c)) { skipping = false; var i = new System.Windows.Controls.Image() { Stretch = Stretch.None }; i.MouseEnter += UpdateFontView; i.Margin = new Thickness(0); i.Source = WriteChar2BM(((char)c).ToString()); i.ToolTip = c; string charname = UnicodeInfo.GetName(c); if (!string.IsNullOrEmpty(charname)) { i.Name = charname.Replace(" ", "_").Replace("-", "_").ToLowerInvariant(); } GridOChars.Children.Add(i); Grid.SetRow(i, y); Grid.SetColumn(i, x); MyCharMap[c] = x + y * 60; } c++; } } } Label1.Content = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*0123456789"; Label1.FontFamily = TheFontFamily; Label1.FontSize = 16; Label2.Content = TheFont.FontFamily.Name; // TheFontFamily.Source; Label2.FontFamily = TheFontFamily; Label2.FontSize = 16; Label3.Content = cr; Label3.FontSize = 16; CodeOutput.Text = RegenerateCode(); }