/// <summary>
        /// Displays installed font list in the console window.
        /// </summary>
        static void DisplayInstalledFontSampleWPF()
        {
            XmlLanguage en_us     = XmlLanguage.GetLanguage("en-us");
            XmlLanguage localLang = XmlLanguage.GetLanguage(System.Globalization.CultureInfo.CurrentCulture.Name);

            foreach (FontFamily fontFamily in System.Windows.Media.Fonts.SystemFontFamilies)
            {
                fontFamily.FamilyNames.TryGetValue(localLang, out var localFamilyName);
                WriteLine($"{fontFamily.FamilyNames[en_us]} {localFamilyName ?? ""}");

                FamilyTypefaceCollection typefaces = fontFamily.FamilyTypefaces;
                foreach (var face in typefaces)
                {
                    WriteLine($"\t{face.AdjustedFaceNames[en_us]}");

                    //日本語のFaceNameを含むフォントはおそらくない?ので以下はいらないだろう
                    //if (face.AdjustedFaceNames.TryGetValue(localLang, out var localFaceName))
                    //{
                    //    WriteLine($"\t\"{face.AdjustedFaceNames[en_us]}\" \"{localFaceName}\"");
                    //    continue;
                    //}
                    //WriteLine($"\t{face.AdjustedFaceNames[en_us]}");
                }
            }
        }
        /// <summary>
        /// Gets the list of family typefaces, creating it if necessary.
        /// </summary>
        internal FamilyTypefaceCollection GetFamilyTypefaceList()
        {
            if (_familyTypefaces == null)
            {
                _familyTypefaces = new FamilyTypefaceCollection();
            }

            return(_familyTypefaces);
        }
示例#3
0
        public void TestCodeSnippet8()
        {
            //<Snippet107>
            // Return the font family for the selected font name.
            FontFamily fontFamily = new FontFamily("Arial Narrow");

            // Return the family typeface collection for the font family.
            FamilyTypefaceCollection familyTypefaceCollection = fontFamily.FamilyTypefaces;

            // Enumerate the family typefaces in the collection.
            foreach (FamilyTypeface typeface in familyTypefaceCollection)
            {
                // Add the typeface style values to the styles combo box.
                comboBoxStyles.Items.Add(typeface.Style);
            }

            comboBoxStyles.SelectedIndex = 0;
            //</Snippet107>
        }
示例#4
0
        private void myTestComboBox_Initialized(object sender, EventArgs e)
        {
            System.Drawing.FontFamily fontFamily = new System.Drawing.FontFamily("Arial");
            FamilyTypefaceCollection  f          = this.FontFamily.FamilyTypefaces;

            InstalledFontCollection IFC = new InstalledFontCollection();

            System.Drawing.FontFamily[] ff = IFC.Families;

            foreach (System.Drawing.FontFamily fff in ff)
            {
                string uu = fff.Name;
                if (uu == "")
                {
                    continue;
                }

                int i = this.myTestComboBox.Items.Add(uu);
            }
            //this.myTestComboBox.ItemsSource = f;
        }
        /// <summary>
        /// Gets the list of family typefaces, creating it if necessary.
        /// </summary>
        internal FamilyTypefaceCollection GetFamilyTypefaceList()
        {
            if (_familyTypefaces == null)
                _familyTypefaces = new FamilyTypefaceCollection();

            return _familyTypefaces;
        }
示例#6
0
 public TypefaceCollection(FontFamily fontFamily, FamilyTypefaceCollection familyTypefaceCollection)
 {
     _fontFamily = fontFamily;
     _familyTypefaceCollection = familyTypefaceCollection;
     _family = null;
 }
示例#7
0
 public TypefaceCollection(FontFamily fontFamily, Text.TextInterface.FontFamily family)
 {
     _fontFamily = fontFamily;
     _family     = family;
     _familyTypefaceCollection = null;
 }
        private FontFamily GetMatchingFontFamily(IList <FontFamily> fontFamilies,
                                                 FontWeight weight, FontStyle style, FontStretch stretch)
        {
            if (fontFamilies == null || fontFamilies.Count == 0)
            {
                return(null);
            }
            // For a single match...
            if (fontFamilies.Count == 1)
            {
                return(fontFamilies[0]);
            }

            // 1. Look for a possibility of all properties matching
            foreach (FontFamily fontFamily in fontFamilies)
            {
                // Return the family typeface collection for the font family.
                FamilyTypefaceCollection familyTypefaces = fontFamily.FamilyTypefaces;

                // Enumerate the family typefaces in the collection.
                foreach (FamilyTypeface typeface in familyTypefaces)
                {
                    FontStyle   fontStyle   = typeface.Style;
                    FontWeight  fontWeight  = typeface.Weight;
                    FontStretch fontStretch = typeface.Stretch;

                    if (fontStyle.Equals(style) && fontWeight.Equals(weight) && fontStretch.Equals(stretch))
                    {
                        return(fontFamily);
                    }
                }
            }

            // For the defined font style...
            if (style != FontStyles.Normal)
            {
                // Then it is either oblique or italic
                FontFamily closeFamily   = null;
                FontFamily closestFamily = null;
                bool       isItalic      = style.Equals(FontStyles.Italic);

                foreach (FontFamily fontFamily in fontFamilies)
                {
                    // Return the family typeface collection for the font family.
                    FamilyTypefaceCollection familyTypefaces = fontFamily.FamilyTypefaces;

                    // Enumerate the family typefaces in the collection.
                    foreach (FamilyTypeface typeface in familyTypefaces)
                    {
                        FontStyle   fontStyle   = typeface.Style;
                        FontWeight  fontWeight  = typeface.Weight;
                        FontStretch fontStretch = typeface.Stretch;

                        if (fontStyle.Equals(style))
                        {
                            closeFamily = fontFamily;
                            if (closestFamily == null)
                            {
                                closestFamily = fontFamily;
                            }
                            if (fontStretch.Equals(stretch))
                            {
                                closestFamily = fontFamily;
                                if (fontWeight.Equals(weight))
                                {
                                    return(fontFamily);
                                }
                            }
                        }
                        if (closeFamily == null)
                        {
                            if (isItalic && fontStyle == FontStyles.Oblique)
                            {
                                closeFamily = fontFamily;
                            }
                            if (!isItalic && fontStyle == FontStyles.Italic)
                            {
                                closeFamily = fontFamily;
                            }
                        }
                    }
                    if (closestFamily != null)
                    {
                        closeFamily = closestFamily;
                    }

                    if (closeFamily != null)
                    {
                        return(closeFamily);
                    }
                }
            }

            // For the defined font weights...
            if (weight != FontWeights.Normal && weight != FontWeights.Regular)
            {
                int        weightValue      = weight.ToOpenTypeWeight();
                int        selectedValue    = int.MaxValue;
                FontFamily sameWeightFamily = null;
                FontFamily closestFamily    = null;
                foreach (FontFamily fontFamily in fontFamilies)
                {
                    // Return the family typeface collection for the font family.
                    FamilyTypefaceCollection familyTypefaces = fontFamily.FamilyTypefaces;

                    // Enumerate the family typefaces in the collection.
                    foreach (FamilyTypeface typeface in familyTypefaces)
                    {
                        FontStyle   fontStyle   = typeface.Style;
                        FontWeight  fontWeight  = typeface.Weight;
                        FontStretch fontStretch = typeface.Stretch;

                        if (fontWeight.Equals(weight))
                        {
                            sameWeightFamily = fontFamily;
                            if (fontStyle.Equals(style))
                            {
                                return(fontFamily);
                            }
                        }

                        int weightDiff = Math.Abs(weightValue - fontWeight.ToOpenTypeWeight());
                        if (weightDiff < selectedValue)
                        {
                            closestFamily = fontFamily;
                            selectedValue = weightDiff;
                        }

                        // If the weights matched, but not the style
                        if (sameWeightFamily != null)
                        {
                            return(sameWeightFamily);
                        }
                        if (closestFamily != null)
                        {
                            return(closestFamily);
                        }
                    }
                }
            }

            return(null);
        }
示例#9
0
        private static async Task CreateFontsArray(ComboBox box)
        {
            List <string> allFonts = new List <string>();

            await Task.Factory.StartNew(() =>
            {
                XmlLanguage enUS = XmlLanguage.GetLanguage("en-us");

                foreach (FontFamily fontFamily in Fonts.SystemFontFamilies)
                {
                    FamilyTypefaceCollection typefaces = fontFamily.FamilyTypefaces;

                    string baseName = fontFamily.Source;

                    if (typefaces.Count == 1)
                    {
                        allFonts.Add(baseName);
                    }
                    else
                    {
                        // Fonts from this group which are going to be shown
                        List <string> list = new List <string>(typefaces.Count);

                        foreach (FamilyTypeface variation in typefaces)
                        {
                            if (variation.Style == FontStyles.Normal)
                            {
                                string faceName = variation.AdjustedFaceNames[enUS];

                                if (faceName == "Regular")
                                {
                                    list.Add(baseName);
                                }
                                else if (faceName != "Bold" && !faceName.Contains(" Bold"))
                                {
                                    list.Add(baseName + " " + faceName);
                                }
                            }
                        }

                        if (list.Count == 1)
                        {
                            allFonts.Add(baseName);
                        }
                        else
                        {
                            allFonts.AddRange(list);
                        }
                    }
                }

                allFonts.Sort(string.Compare);

                //	int count = allFonts.Count - 1;

                //	// Sort
                //	bool swapHasBeenMade = true;

                //	while (swapHasBeenMade)
                //	{
                //		swapHasBeenMade = false;

                //		// run one pass for each item
                //		for (int i = 0; i < count; i++)
                //		{
                //			string s1 = allFonts[i];
                //			string s2 = allFonts[i + 1];

                //			if (string.Compare(s1, s2) > 0)
                //			{
                //				allFonts[i + 1] = s1;
                //				allFonts[i] = s2;

                //				swapHasBeenMade = true;
                //			}
                //		}
                //	}
            });

            box.Items.Clear();
            box.ItemsSource = allFonts;
        }