예제 #1
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods


        /// <summary>
        /// Get typeface metrics of the specified style
        /// </summary>
        ITypefaceMetrics IFontFamily.GetTypefaceMetrics(
            FontStyle style,
            FontWeight weight,
            FontStretch stretch
            )
        {
            CachedFontFace bestFace = FindNearestTypeface(style, weight, stretch);

            if (!bestFace.IsNull)
            {
                unsafe
                {
                    return(new CompositeTypefaceMetrics(
                               bestFace.CompositeFace->underlinePosition,
                               bestFace.CompositeFace->underlineThickness,
                               bestFace.CompositeFace->strikeThroughPosition,
                               bestFace.CompositeFace->strikeThroughThickness,
                               bestFace.CompositeFace->capsHeight,
                               bestFace.CompositeFace->xHeight,
                               bestFace.CompositeFace->fontStyle,
                               bestFace.CompositeFace->fontWeight,
                               bestFace.CompositeFace->fontStretch
                               ));
                }
            }
            else
            {
                return(new CompositeTypefaceMetrics());
            }
        }
예제 #2
0
        /// <summary>
        /// Find the face exactly matching the specified style, weight and stretch.
        /// Returns CachedFontFace.Null if there is no matching face.
        /// </summary>
        private CachedFontFace FindExactTypeface(FontStyle style, FontWeight weight, FontStretch stretch)
        {
            MatchingStyle target = new MatchingStyle(style, weight, stretch);

            for (int i = 0; i < _cachedFamily.NumberOfFaces; i++)
            {
                CachedFontFace currentFace = _cachedFamily.FamilyCollection.GetCachedFace(_cachedFamily, i);
                if (currentFace.MatchingStyle == target)
                {
                    return(currentFace);
                }
            }

            return(CachedFontFace.Null);
        }
예제 #3
0
        /// <summary>
        /// Look up device font for the typeface.
        /// </summary>
        IDeviceFont IFontFamily.GetDeviceFont(FontStyle style, FontWeight weight, FontStretch stretch)
        {
            CachedFontFace bestFace = FindExactTypeface(style, weight, stretch);

            if (!bestFace.IsNull)
            {
                unsafe
                {
                    int offsetToDeviceFont = bestFace.CompositeFace->offsetToDeviceFont;
                    if (offsetToDeviceFont != 0)
                    {
                        return(new DeviceFont(
                                   _cachedFamily,
                                   bestFace.CheckedPointer + offsetToDeviceFont
                                   ));
                    }
                }
            }
            return(null);
        }
예제 #4
0
        /// <summary>
        /// Find the face most closely matching the specified style, weight and stretch.
        /// Returns CachedFontFace.Null if there is no available face.
        /// </summary>
        private CachedFontFace FindNearestTypeface(FontStyle style, FontWeight weight, FontStretch stretch)
        {
            if (_cachedFamily.NumberOfFaces == 0)
            {
                return(CachedFontFace.Null);
            }

            MatchingStyle  target    = new MatchingStyle(style, weight, stretch);
            CachedFontFace bestFace  = _cachedFamily.FamilyCollection.GetCachedFace(_cachedFamily, 0);
            MatchingStyle  bestMatch = bestFace.MatchingStyle;

            for (int i = 1; i < _cachedFamily.NumberOfFaces; i++)
            {
                CachedFontFace currentFace  = _cachedFamily.FamilyCollection.GetCachedFace(_cachedFamily, i);
                MatchingStyle  currentMatch = currentFace.MatchingStyle;
                if (MatchingStyle.IsBetterMatch(target, bestMatch, ref currentMatch))
                {
                    bestMatch = currentMatch;
                    bestFace  = currentFace;
                }
            }

            return(bestFace);
        }