Beispiel #1
0
        //// Methods
        //public Font(Font prototype, FontStyle newStyle);
        //public Font(FontFamily family, float emSize);
        //public Font(string familyName, float emSize);
        //public Font(FontFamily family, float emSize, FontStyle style);
        //public Font(FontFamily family, float emSize, GraphicsUnit unit);
        //public Font(string familyName, float emSize, FontStyle style);
        //public Font(string familyName, float emSize, GraphicsUnit unit);
        //public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit);
        //public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit);
        ////public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet);
        ////public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet);
        ////public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont);
        ////public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont);
        //public object Clone();
        //private static FontFamily CreateFontFamilyWithFallback(string familyName);
        //private void Dispose(bool disposing);
        //public override bool Equals(object obj);
        //protected override void Finalize();
        //public static Font FromHdc(IntPtr hdc);
        //public static Font FromHfont(IntPtr hfont);
        //public static Font FromLogFont(object lf);
        //public static Font FromLogFont(object lf, IntPtr hdc);
        //public override int GetHashCode();

        /// <summary>
        /// Initializes this instance by computing the glyph typeface, font family, font source and TrueType fontface.
        /// (PDFsharp currently only deals with TrueType fonts.)
        /// </summary>
        void Initialize()
        {
#if DEBUG
            if (_familyName == "Segoe UI Semilight" && (_style & XFontStyle.BoldItalic) == XFontStyle.Italic)
            {
                GetType();
            }
#endif

            FontResolvingOptions fontResolvingOptions = OverrideStyleSimulations
                ? new FontResolvingOptions(_style, StyleSimulations)
                : new FontResolvingOptions(_style);

            // HACK: 'PlatformDefault' is used in unit test code.
            if (StringComparer.OrdinalIgnoreCase.Compare(_familyName, GlobalFontSettings.DefaultFontName) == 0)
            {
#if CORE || GDI || WPF
                _familyName = "Calibri";
#endif
            }

            // In principle an XFont is an XGlyphTypeface plus an em-size.
            _glyphTypeface = XGlyphTypeface.GetOrCreateFrom(_familyName, fontResolvingOptions);
#if GDI                             // TODO: In CORE build it is not necessary to create a GDI font at all
            // Create font by using font family.
            XFontSource fontSource; // Not needed here.
            _gdiFont = FontHelper.CreateFont(_familyName, (float)_emSize, (GdiFontStyle)(_style & XFontStyle.BoldItalic), out fontSource);
#endif
#if WPF && !SILVERLIGHT  // Pure WPF
            _wpfFontFamily = _glyphTypeface.FontFamily.WpfFamily;
            _wpfTypeface   = _glyphTypeface.WpfTypeface;

            if (_wpfFontFamily == null)
            {
                _wpfFontFamily = new WpfFontFamily(Name);
            }

            if (_wpfTypeface == null)
            {
                _wpfTypeface = FontHelper.CreateTypeface(WpfFontFamily, _style);
            }
#endif
#if WPF && SILVERLIGHT_  // Pure Silverlight 5
            if (GlyphTypeface == null)
            {
                //Debug.Assert(Typeface == null);
                // #P F C
                //GlyphTypeface = XPrivateFontCollection.TryGetXGlyphTypeface(Name, _style);
                //if (GlyphTypeface == null)
                //{
                //    // HACK: Just make it work...
                //    GlyphTypeface = GlobalFontSettings.TryGetXGlyphTypeface(Name, _style, out Data);
                //}
#if DEBUG
                if (GlyphTypeface == null)
                {
                    throw new Exception("No font: " + Name);
                }
#endif
                _wpfFamily = GlyphTypeface.FontFamily;
            }

            //if (Family == null)
            //  Family = new System.Windows.Media.FontFamily(Name);

            //if (Typeface == null)
            //  Typeface = FontHelper.CreateTypeface(Family, _style);
#endif
            CreateDescriptorAndInitializeFontMetrics();
        }
Beispiel #2
0
 /// <summary>
 /// Computes the bijective key for a typeface.
 /// </summary>
 internal static string ComputeKey(string familyName, bool isBold, bool isItalic)
 {
     return(ComputeKey(familyName, new FontResolvingOptions(FontHelper.CreateStyle(isBold, isItalic))));
 }