/// <summary> /// Verifies that the FontFamily can be changed and returns a CompositeFontFamily /// </summary> private CompositeFontFamily VerifyMutable() { CompositeFontFamily mutableFamily = _firstFontFamily as CompositeFontFamily; if (mutableFamily == null) { throw new NotSupportedException(SR.Get(SRID.FontFamily_ReadOnly)); } return(mutableFamily); }
private static List <CompositeFontFamily> GetCompositeFontList(FontSourceCollection fontSourceCollection) { List <CompositeFontFamily> compositeFonts = new List <CompositeFontFamily>(); foreach (FontSource fontSource in fontSourceCollection) { if (fontSource.IsComposite) { CompositeFontInfo fontInfo = CompositeFontParser.LoadXml(fontSource.GetStream()); CompositeFontFamily compositeFamily = new CompositeFontFamily(fontInfo); compositeFonts.Add(compositeFamily); } } return(compositeFonts); }
private FontFamily CreateFontFamily(CompositeFontFamily compositeFontFamily, Uri fontFamilyBaseUri, string fontFamilyLocationReference) { IFontFamily fontFamily = (IFontFamily)compositeFontFamily; IEnumerator <string> familyNames = fontFamily.Names.Values.GetEnumerator(); if (familyNames.MoveNext()) { string ordinalName = familyNames.Current; string fontFamilyReference = Util.ConvertFamilyNameAndLocationToFontFamilyReference( ordinalName, fontFamilyLocationReference ); string friendlyName = Util.ConvertFontFamilyReferenceToFriendlyName(fontFamilyReference); return(new FontFamily(fontFamilyBaseUri, friendlyName)); } return(null); }
internal static CompositeFontFamily GetCompositeFontFamilyAtIndex(int index) { if (_systemCompositeFonts[index] == null) { lock (_systemCompositeFontsLock) { if (_systemCompositeFonts[index] == null) { FontSource fontSource = new FontSource(new Uri(Path.Combine(FamilyCollection.SxSFontsResourcePrefix, _systemCompositeFontsFileNames[index] + Util.CompositeFontExtension), UriKind.RelativeOrAbsolute), skipDemand: true, isComposite: true, isInternalCompositeFont: true); CompositeFontInfo fontInfo = CompositeFontParser.LoadXml(fontSource.GetStream()); _systemCompositeFonts[index] = new CompositeFontFamily(fontInfo); } } } return(_systemCompositeFonts[index]); }
internal static CompositeFontFamily GetCompositeFontFamilyAtIndex(int index) { if (_systemCompositeFonts[index] == null) { lock (_systemCompositeFontsLock) { if (_systemCompositeFonts[index] == null) { FontSource fontSource = new FontSource(new Uri(FamilyCollection.SxSFontsLocation + _systemCompositeFontsFileNames[index] + Util.CompositeFontExtension, UriKind.Absolute), true, //skipDemand. //We skip demand here since this class should cache //all system composite fonts for the current process //Demanding read permissions should be done by FamilyCollection.cs true //isComposite ); CompositeFontInfo fontInfo = CompositeFontParser.LoadXml(fontSource.GetStream()); _systemCompositeFonts[index] = new CompositeFontFamily(fontInfo); } } } return(_systemCompositeFonts[index]); }
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)); }