using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace TestProject;
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
Typeface emojiTypeface = new Typeface
(
new FontFamily("Segoe UI Emoji"),
FontStyles.Normal,
FontWeights.Normal,
FontStretches.Normal
);
List<(int, int)> emojiRangeList = new List<(int, int)>
{
(0x1f300, 0x1f5ff), // Miscellaneous Symbols and Pictographs
(0x1f600, 0x1f64f), // Emoticons
(0x1f680, 0x1f6ff), // Transport and Map Symbols
(0x1f900, 0x1f9ff), // Supplemental Symbols and Pictographs
(0x1fa70, 0x1faff), // Symbols and Pictographs Extended-A
(0x2600 , 0x26ff ), // Miscellaneous Symbols
(0x2700 , 0x27bf ) // Dingbats
};
foreach((int start, int end) in emojiRangeList)
{
for(int i = start; i <= end; i++)
{
string emojiString = char.ConvertFromUtf32(i);
if(HasGlyph(emojiTypeface, emojiString))
{
this.listBox.Items.Add(emojiString);
}
}
}
this.listBox.SelectionChanged += listBox_SelectionChanged;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 리스트 박스 선택 변경시 처리하기 - listBox_SelectionChanged(sender, e)
/// <summary>
/// 리스트 박스 선택 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(this.listBox.SelectedItem != null)
{
string emojiString = this.listBox.SelectedItem.ToString();
int unicode = char.ConvertToUtf32(emojiString, 0);
this.textBlock.Text = $"유니코드 : U+{unicode:X4}";
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 글리프 소유 여부 구하기 - HasGlyph(typeface, source)
/// <summary>
/// 글리프 소유 여부 구하기
/// </summary>
/// <param name="typeface">타입 페이스</param>
/// <param name="source">소스 문자열</param>
/// <returns>글리프 소유 여부</returns>
private bool HasGlyph(Typeface typeface, string source)
{
ushort glyphIndex;
bool resultToGetGlyphTypeface = typeface.TryGetGlyphTypeface(out GlyphTypeface glyphTypeface);
bool resultToGetGlyphIndex = glyphTypeface.CharacterToGlyphMap.TryGetValue(char.ConvertToUtf32(source, 0), out glyphIndex);
return resultToGetGlyphTypeface && resultToGetGlyphIndex && glyphIndex != 0;
}
#endregion
}