internal CachedTypeface(
            FontStyle        canonicalStyle,
            FontWeight       canonicalWeight,
            FontStretch      canonicalStretch,
            IFontFamily      firstFontFamily,
            ITypefaceMetrics typefaceMetrics,
            bool             nullFont
            )
        {
            _canonicalStyle   = canonicalStyle;
            _canonicalWeight  = canonicalWeight;
            _canonicalStretch = canonicalStretch;

            Invariant.Assert(firstFontFamily != null && typefaceMetrics != null);
            
            _firstFontFamily  = firstFontFamily;
            _typefaceMetrics  = typefaceMetrics;
            _nullFont         = nullFont;            
        }        
Esempio n. 2
0
        internal CachedTypeface(
            FontStyle canonicalStyle,
            FontWeight canonicalWeight,
            FontStretch canonicalStretch,
            IFontFamily firstFontFamily,
            ITypefaceMetrics typefaceMetrics,
            bool nullFont
            )
        {
            _canonicalStyle   = canonicalStyle;
            _canonicalWeight  = canonicalWeight;
            _canonicalStretch = canonicalStretch;

            Invariant.Assert(firstFontFamily != null && typefaceMetrics != null);

            _firstFontFamily = firstFontFamily;
            _typefaceMetrics = typefaceMetrics;
            _nullFont        = nullFont;
        }
        private CachedTypeface ConstructCachedTypeface()
        {
            FontStyle   canonicalStyle   = _style;
            FontWeight  canonicalWeight  = _weight;
            FontStretch canonicalStretch = _stretch;

            //
            // We always call FontFamily.FindFirstFontFamilyAndFace() method to resolve the
            // canonical styles since the implied styles in FontFamily name will override
            // the given styles in the Typeface. But we don't always use the IFontFamily
            // instance returned from this method because an equal instance might already be
            // cached.
            //
            FontFamily sourceFontFamily = FontFamily;

            IFontFamily firstFontFamily = sourceFontFamily.FindFirstFontFamilyAndFace(
                ref canonicalStyle,
                ref canonicalWeight,
                ref canonicalStretch
                );

            if (firstFontFamily == null)
            {
                if (FallbackFontFamily != null)
                {
                    sourceFontFamily = FallbackFontFamily;
                    firstFontFamily  = sourceFontFamily.FindFirstFontFamilyAndFace(
                        ref canonicalStyle,
                        ref canonicalWeight,
                        ref canonicalStretch
                        );
                }

                if (firstFontFamily == null)
                {
                    sourceFontFamily = null;
                    firstFontFamily  = FontFamily.LookupFontFamily(FontFamily.NullFontFamilyCanonicalName);
                }
            }

            // If it's a named font, map all occurrences of the same name to one cached IFontFamily.
            if (sourceFontFamily != null && sourceFontFamily.Source != null)
            {
                // We lookup in the cache to see if there is cached IFontFamily instance of the source FontFamily. Otherwise,
                // this IFontFamily value is added to the TypefaceMetrics cache.
                IFontFamily cachedValue = TypefaceMetricsCache.ReadonlyLookup(sourceFontFamily.FamilyIdentifier) as IFontFamily;

                if (cachedValue != null)
                {
                    firstFontFamily = cachedValue;
                }
                else
                {
                    TypefaceMetricsCache.Add(sourceFontFamily.FamilyIdentifier, firstFontFamily);
                }
            }

            ITypefaceMetrics typefaceMetrics = firstFontFamily.GetTypefaceMetrics(canonicalStyle, canonicalWeight, canonicalStretch);

            return(new CachedTypeface(
                       canonicalStyle,
                       canonicalWeight,
                       canonicalStretch,
                       firstFontFamily,
                       typefaceMetrics,
                       sourceFontFamily == null
                       ));
        }