Exemple #1
0
        public static sw.FontFamily GetFontFamily(string familyName)
        {
            sw.FontFamily result = null;
            int           index;

            if (FontHandler.FontCollection.FindFamilyName(familyName, out index))
            {
                result = FontHandler.FontCollection.GetFontFamily(index);
            }
            return(result);
        }
Exemple #2
0
        private async void LoadFont()
        {
            try
            {
                int currentSelectedIndex = _cmbFontFamily.SelectedIndex;
                if (currentSelectedIndex == -1)
                {
                    return;
                }
                SharpDX.DirectWrite.FontFamily   fontFamily = InstalledFonts[currentSelectedIndex].FontFamily;
                Windows.UI.Xaml.Media.FontFamily windowsFF  = new Windows.UI.Xaml.Media.FontFamily(InstalledFonts[currentSelectedIndex].FontName);

                List <FontItem> list = new List <FontItem>();

                Font font     = fontFamily.GetFont(0);
                int  fontSize = Convert.ToInt32(_txtDefaultFontSize.Text);

                for (int i = 0; i < 65535; i++)
                {
                    char c = Convert.ToChar(i);
                    if (c == ' ' || c == '\r' || c == '\n' || c == '\t')
                    {
                        continue;
                    }

                    if (font.HasCharacter(i))
                    {
                        list.Add(new FontItem()
                        {
                            Symbol      = c.ToString(),
                            Label       = "U+" + i.ToString("X4"),
                            FontFamily  = windowsFF,
                            XamlEncoded = "&#x" + i.ToString("X4") + ";",
                            FontSize    = fontSize
                        });
                    }
                }

                ResultList.ItemsSource = list;
                ResultList.ScrollIntoView(list[0]);
            }
            catch (Exception e)
            {
                string        msg    = e.Message;
                MessageDialog errDlg = new MessageDialog(e.Message);
                await errDlg.ShowAsync();
            }
        }
        /// <summary>
        /// Gets a collection containing all available font familily names.
        /// </summary>
        public IEnumerable <string> GetFontFamilyNames(string localeName = "en-us")
        {
            localeName.EnsureNotNullOrEmpty(nameof(localeName));
            localeName = localeName.ToLower();

            // Query for all available FontFamilies installed on the system
            List <string> result = null;

            using (DWrite.FontCollection fontCollection = this.FactoryDWrite.GetSystemFontCollection(false))
            {
                int fontFamilyCount = fontCollection.FontFamilyCount;
                result = new List <string>(fontFamilyCount);

                for (int loop = 0; loop < fontFamilyCount; loop++)
                {
                    using (DWrite.FontFamily actFamily = fontCollection.GetFontFamily(loop))
                        using (DWrite.LocalizedStrings actLocalizedStrings = actFamily.FamilyNames)
                        {
                            int localeIndex = -1;
                            if ((bool)actLocalizedStrings.FindLocaleName(localeName, out localeIndex))
                            {
                                string actName = actLocalizedStrings.GetString(0);
                                if (!string.IsNullOrWhiteSpace(actName))
                                {
                                    result.Add(actName);
                                }
                            }
                            else if ((bool)actLocalizedStrings.FindLocaleName("en-us", out localeIndex))
                            {
                                string actName = actLocalizedStrings.GetString(0);
                                if (!string.IsNullOrWhiteSpace(actName))
                                {
                                    result.Add(actName);
                                }
                            }
                        }
                }
            }

            // Sort the list finally
            result.Sort();

            return(result);
        }
Exemple #4
0
        public static Windows.UI.Xaml.Media.FontFamily SharpDxToXamlFontFamily(SharpDX.DirectWrite.FontFamily ff)
        {
            string familyName = ff.FamilyNames.GetString(0);

            return(new Windows.UI.Xaml.Media.FontFamily(familyName));
        }
Exemple #5
0
 public FontFamilyItem(string fontName, SharpDX.DirectWrite.FontFamily fontFamily, bool isSymbol)
 {
     FontName   = fontName;
     FontFamily = fontFamily;
     IsSymbol   = isSymbol;
 }
Exemple #6
0
 private FontFamilyCacheItem(DWrite.FontFamily fontFamily)
 {
     this.fontFamily = fontFamily;
 }