/// <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)))); }
//// 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(); }
/// <summary> /// Connects the specifications of a font from XFont to a real glyph type face. /// </summary> void Initialize() { XFontMetrics fm = null; #if DEBUG___ FontData[] fontDataArray = FontDataStock.Global.GetFontDataList(); if (fontDataArray.Length > 0) { //// GetType(); ////#if GDI //// var x = XPrivateFontCollection.global.GlobalPrivateFontCollection; //// families = x.Families; //// bool fff = families[0].IsStyleAvailable(System.Drawing.FontStyle.Regular); //// fff.GetType(); //// this.font = new Font(families[0].Name, 12, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel); //// this.font = new Font("Oblivious", 12, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel); //// this.font = new Font(families[0], 12, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel); //// System.Drawing.FontFamily f = new System.Drawing.FontFamily(families[0].Name); //// f.GetType(); ////#endif } #endif #if GDI if (this.font == null) { if (this.gdifamily != null) { this.font = new Font(this.gdifamily, (float)this.emSize, (System.Drawing.FontStyle) this.style, GraphicsUnit.World); this.familyName = this.gdifamily.Name; // Do we need this??? } else { // First check private fonts this.font = XPrivateFontCollection.TryFindPrivateFont(this.familyName, this.emSize, (System.Drawing.FontStyle) this.style) ?? new Font(this.familyName, (float)this.emSize, (System.Drawing.FontStyle) this.style, GraphicsUnit.World); } #if DEBUG // new Font returns MSSansSerif if the requested font was not found ... //Debug.Assert(this.familyName == this.font.FontFamily.Name); #endif } fm = Metrics; System.Drawing.FontFamily fontFamily = this.font.FontFamily; this.unitsPerEm = fm.UnitsPerEm; System.Drawing.FontFamily fontFamily2 = this.font.FontFamily; this.cellSpace = fontFamily2.GetLineSpacing(font.Style); //Debug.Assert(this.cellSpace == fm.Ascent + Math.Abs(fm.Descent) + fm.Leading, "Value differs from information retrieved from font image."); this.cellAscent = fontFamily.GetCellAscent(font.Style); #pragma warning disable 1030 #warning delTHHO //!!!delTHHO 14.08.2008 Debug.Assert(this.cellAscent == fm.Ascent, "Value differs from information retrieved from font image."); //Debug.Assert(this.cellAscent == fm.Ascent, "Value differs from information retrieved from font image."); this.cellDescent = fontFamily.GetCellDescent(font.Style); #if DEBUG int desc = Math.Abs(fm.Descent); if (this.cellDescent != desc) { Debug.Assert(false, "Value differs from information retrieved from font image."); } #endif #endif #if WPF #if !SILVERLIGHT if (this.family == null) { Debug.Assert(this.typeface == null); this.typeface = XPrivateFontCollection.TryFindTypeface(Name, this.style, out this.family); #if true if (this.typeface != null) { GlyphTypeface glyphTypeface; ICollection <Typeface> list = this.family.GetTypefaces(); foreach (Typeface tf in list) { if (!tf.TryGetGlyphTypeface(out glyphTypeface)) { Debugger.Break(); } } if (!this.typeface.TryGetGlyphTypeface(out glyphTypeface)) { throw new InvalidOperationException(PSSR.CannotGetGlyphTypeface(Name)); } } #endif } if (this.family == null) { this.family = new System.Windows.Media.FontFamily(Name); } if (typeface == null) { this.typeface = FontHelper.CreateTypeface(this.family, style); } fm = Metrics; Debug.Assert(this.unitsPerEm == 0 || this.unitsPerEm == fm.UnitsPerEm); this.unitsPerEm = fm.UnitsPerEm; //Debug.Assert(this.cellSpace == 0 || this.cellSpace == fm.Ascent + Math.Abs(fm.Descent) + fm.Leading); this.cellSpace = fm.Ascent + Math.Abs(fm.Descent) + fm.Leading; Debug.Assert(this.cellAscent == 0 || this.cellAscent == fm.Ascent); this.cellAscent = fm.Ascent; Debug.Assert(this.cellDescent == 0 || this.cellDescent == Math.Abs(fm.Descent)); this.cellDescent = Math.Abs(fm.Descent); #else if (fm != null) { fm.GetType(); } #endif #endif }