■ Typeface 클래스에서 Segoe UI Emoji 폰트를 사용해 이모지 문자를 나열하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="TestProject" Height="600" Width="800" FontFamily="나눔소딕코딩" FontSize="16"> <Grid Margin="10"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <ListBox Name="listBox" Grid.Row="0" BorderThickness="1" BorderBrush="DarkGray" FontFamily="Segoe UI Emoji" FontSize="24"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Orientation="Horizontal" Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox> <TextBlock Name="textBlock" Grid.Row="1" Margin="0 10 0 0" /> </Grid> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
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 } |