internal FontFamily[] GetFontFamilies(Uri fontFamilyBaseUri, string fontFamilyLocationReference) { FontFamily[] fontFamilyList = new FontFamily[FamilyCount]; int i = 0; foreach (MS.Internal.Text.TextInterface.FontFamily family in GetPhysicalFontFamilies()) { string fontFamilyReference = Util.ConvertFamilyNameAndLocationToFontFamilyReference( family.OrdinalName, fontFamilyLocationReference ); string friendlyName = Util.ConvertFontFamilyReferenceToFriendlyName(fontFamilyReference); fontFamilyList[i++] = new FontFamily(fontFamilyBaseUri, friendlyName); } FontFamily fontFamily; if (UseSystemFonts) { for (int j = 0; j < SystemCompositeFonts.NumOfSystemCompositeFonts; ++j) { fontFamily = CreateFontFamily(SystemCompositeFonts.GetCompositeFontFamilyAtIndex(j), fontFamilyBaseUri, fontFamilyLocationReference); if (fontFamily != null) { fontFamilyList[i++] = fontFamily; } } } else { foreach (CompositeFontFamily compositeFontFamily in UserCompositeFonts) { fontFamily = CreateFontFamily(compositeFontFamily, fontFamilyBaseUri, fontFamilyLocationReference); if (fontFamily != null) { fontFamilyList[i++] = fontFamily; } } } Debug.Assert(i == FamilyCount); return(fontFamilyList); }
internal IFontFamily LookupFamily( string familyName, ref FontStyle fontStyle, ref FontWeight fontWeight, ref FontStretch fontStretch ) { if (familyName == null || familyName.Length == 0) { return(null); } familyName = familyName.Trim(); // If we are referencing fonts from the system fonts, then it is cheap to lookup the 4 composite fonts // that ship with WPF. Also, it happens often that familyName is "Global User Interface". // So in this case we preceed looking into SystemComposite Fonts. if (UseSystemFonts) { CompositeFontFamily compositeFamily = SystemCompositeFonts.FindFamily(familyName); if (compositeFamily != null) { return(compositeFamily); } } Text.TextInterface.FontFamily fontFamilyDWrite = _fontCollection[familyName]; // A font family was not found in DWrite's font collection. if (fontFamilyDWrite == null) { // Having user defined composite fonts is not very common. So we defer looking into them to looking DWrite // (which is opposite to what we do for system fonts). if (!UseSystemFonts) { // The family name was not found in DWrite's font collection. It may possibly be the name of a composite font // since DWrite does not recognize composite fonts. CompositeFontFamily compositeFamily = LookUpUserCompositeFamily(familyName); if (compositeFamily != null) { return(compositeFamily); } } // The family name cannot be found. This may possibly be because the family name contains styling info. // For example, "Arial Bold" // We will strip off the styling info (one word at a time from the end) and try to find the family name. int indexOfSpace = -1; System.Text.StringBuilder potentialFaceName = new System.Text.StringBuilder(); // Start removing off strings from the end hoping they are // style info so as to get down to the family name. do { indexOfSpace = familyName.LastIndexOf(' '); if (indexOfSpace < 0) { break; } else { // store the stripped off style names to look for the specific face later. potentialFaceName.Insert(0, familyName.Substring(indexOfSpace)); familyName = familyName.Substring(0, indexOfSpace); } fontFamilyDWrite = _fontCollection[familyName]; } while (fontFamilyDWrite == null); if (fontFamilyDWrite == null) { return(null); } // If there was styling information. if (potentialFaceName.Length > 0) { // The first character in the potentialFaceName will be a space so we need to strip it off. Text.TextInterface.Font font = GetFontFromFamily(fontFamilyDWrite, potentialFaceName.ToString(1, potentialFaceName.Length - 1)); if (font != null) { fontStyle = new FontStyle((int)font.Style); fontWeight = new FontWeight((int)font.Weight); fontStretch = new FontStretch((int)font.Stretch); } } } if (UseSystemFonts && LegacyArabicFonts.UsePrivateFontCollectionForLegacyArabicFonts // familyName will hold the family name without any face info. && LegacyArabicFonts.IsLegacyArabicFont(familyName)) { fontFamilyDWrite = LegacyArabicFonts.LegacyArabicFontCollection[familyName]; if (fontFamilyDWrite == null) { return(SystemCompositeFonts.GetFallbackFontForArabicLegacyFonts()); } } return(new PhysicalFontFamily(fontFamilyDWrite)); }