Beispiel #1
0
        /// <summary>
        /// Create the font image using WPF functionality.
        /// </summary>
        void CreateWpfFontData(XFont font, XPdfFontOptions options)
        {
            GlyphTypeface glyphTypeface;

            if (!font.typeface.TryGetGlyphTypeface(out glyphTypeface))
            {
                throw new InvalidOperationException(PSSR.CannotGetGlyphTypeface(font.Name));
            }

            Stream fontStream = null;

            try
            {
                fontStream = glyphTypeface.GetFontStream();
                int size = (int)fontStream.Length;
                Debug.Assert(size > 0);
                this.data = new byte[size];
                fontStream.Read(this.data, 0, size);
            }
            finally
            {
                if (fontStream != null)
                {
                    fontStream.Close();
                }
            }
        }
        /// <summary>
        /// Create a WPF GlyphTypeface and retrieve font data from it.
        /// </summary>
        internal static XFontSource CreateFontSource(string familyName, FontResolvingOptions fontResolvingOptions,
                                                     out WpfFontFamily wpfFontFamily, out WpfTypeface wpfTypeface, out WpfGlyphTypeface wpfGlyphTypeface, string typefaceKey)
        {
            if (string.IsNullOrEmpty(typefaceKey))
            {
                typefaceKey = XGlyphTypeface.ComputeKey(familyName, fontResolvingOptions);
            }
            XFontStyle style = fontResolvingOptions.FontStyle;

#if DEBUG
            if (StringComparer.OrdinalIgnoreCase.Compare(familyName, "Segoe UI Semilight") == 0 &&
                (style & XFontStyle.BoldItalic) == XFontStyle.Italic)
            {
                familyName.GetType();
            }
#endif

            // Use WPF technique to create font data.
            wpfTypeface = XPrivateFontCollection.TryCreateTypeface(familyName, style, out wpfFontFamily);
#if DEBUG__
            if (wpfTypeface != null)
            {
                WpfGlyphTypeface          glyphTypeface;
                ICollection <WpfTypeface> list = wpfFontFamily.GetTypefaces();
                foreach (WpfTypeface tf in list)
                {
                    if (!tf.TryGetGlyphTypeface(out glyphTypeface))
                    {
                        Debug - Break.Break();
                    }
                }

                //if (!WpfTypeface.TryGetGlyphTypeface(out glyphTypeface))
                //    throw new InvalidOperationException(PSSR.CannotGetGlyphTypeface(familyName));
            }
#endif
            if (wpfFontFamily == null)
            {
                wpfFontFamily = new WpfFontFamily(familyName);
            }

            if (wpfTypeface == null)
            {
                wpfTypeface = FontHelper.CreateTypeface(wpfFontFamily, style);
            }

            // Let WPF choose the right glyph typeface.
            if (!wpfTypeface.TryGetGlyphTypeface(out wpfGlyphTypeface))
            {
                throw new InvalidOperationException(PSSR.CannotGetGlyphTypeface(familyName));
            }

            // Get or create the font source and cache it unter the specified typeface key.
            XFontSource fontSource = XFontSource.GetOrCreateFromWpf(typefaceKey, wpfGlyphTypeface);
            return(fontSource);
        }
Beispiel #3
0
        /// <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
        }