예제 #1
0
        /// <summary>
        /// Code separated from Metric getter to make code easier to debug.
        /// (Setup properties in their getters caused side effects during debugging because Visual Studio calls a getter
        /// to early to show its value in a debugger window.)
        /// </summary>
        void CreateDescriptorAndInitializeFontMetrics()  // TODO: refactor
        {
            Debug.Assert(_fontMetrics == null, "InitializeFontMetrics() was already called.");
            _descriptor  = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(this); //_familyName, _style, _glyphTypeface.Fontface);
            _fontMetrics = new XFontMetrics(_descriptor.FontName, _descriptor.UnitsPerEm, _descriptor.Ascender, _descriptor.Descender,
                                            _descriptor.Leading, _descriptor.LineSpacing, _descriptor.CapHeight, _descriptor.XHeight, _descriptor.StemV, 0, 0, 0,
                                            _descriptor.UnderlinePosition, _descriptor.UnderlineThickness, _descriptor.StrikeoutPosition, _descriptor.StrikeoutSize);

            XFontMetrics fm = Metrics;

            // Already done in CreateDescriptorAndInitializeFontMetrics.
            //if (_descriptor == null)
            //    _descriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(this);  //(Name, (XGdiFontStyle)Font.Style);

            UnitsPerEm  = _descriptor.UnitsPerEm;
            CellAscent  = _descriptor.Ascender;
            CellDescent = _descriptor.Descender;
            CellSpace   = _descriptor.LineSpacing;

#if DEBUG_ && GDI
            int gdiValueUnitsPerEm = Font.FontFamily.GetEmHeight(Font.Style);
            Debug.Assert(gdiValueUnitsPerEm == UnitsPerEm);
            int gdiValueAscent = Font.FontFamily.GetCellAscent(Font.Style);
            Debug.Assert(gdiValueAscent == CellAscent);
            int gdiValueDescent = Font.FontFamily.GetCellDescent(Font.Style);
            Debug.Assert(gdiValueDescent == CellDescent);
            int gdiValueLineSpacing = Font.FontFamily.GetLineSpacing(Font.Style);
            Debug.Assert(gdiValueLineSpacing == CellSpace);
#endif
#if DEBUG_ && WPF && !SILVERLIGHT
            int wpfValueLineSpacing = (int)Math.Round(Family.LineSpacing * _descriptor.UnitsPerEm);
            Debug.Assert(wpfValueLineSpacing == CellSpace);
#endif
            Debug.Assert(fm.UnitsPerEm == _descriptor.UnitsPerEm);
        }
예제 #2
0
        public static int GetWpfValue(XFontFamily family, XFontStyle style, GWV value)
        {
            FontDescriptor descriptor = FontDescriptorStock.Global.CreateDescriptor(family, style);
            XFontMetrics   metrics    = descriptor.FontMetrics;

            switch (value)
            {
            case GWV.GetCellAscent:
                return(metrics.Ascent);

            case GWV.GetCellDescent:
                return(Math.Abs(metrics.Descent));

            case GWV.GetEmHeight:
                //return (int)metrics.CapHeight;
                return(metrics.UnitsPerEm);

            case GWV.GetLineSpacing:
                return(metrics.Ascent + Math.Abs(metrics.Descent) + metrics.Leading);

            default:
                throw new InvalidOperationException("Unknown GWV value.");
                // DELETE
                //case GWV.IsStyleAvailable:
                //  style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic
                //  List<Typeface> s_typefaces = new List<Typeface>(family.wpfFamily.GetTypefaces());
                //  foreach (Typeface typeface in s_typefaces)
                //  {
                //  }
                //  Debugger.Break();
                ////typeface.Style = FontStyles.
            }
        }
예제 #3
0
        /// <summary>
        /// Determines whether the style is available as a glyph type face in the specified font family, i.e. the specified style is not simulated.
        /// </summary>
        public static bool IsStyleAvailable(XFontFamily family, XFontStyle style)
        {
#if !SILVERLIGHT
            // TODOWPF: check for correctness
            FontDescriptor descriptor = FontDescriptorStock.Global.CreateDescriptor(family, style);
            XFontMetrics   metrics    = descriptor.FontMetrics;

            style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic
            List <Typeface> typefaces = new List <Typeface>(family.wpfFamily.GetTypefaces());
            foreach (Typeface typeface in typefaces)
            {
                bool          available = false;
                GlyphTypeface glyphTypeface;
                if (typeface.TryGetGlyphTypeface(out glyphTypeface))
                {
#if DEBUG
                    glyphTypeface.GetType();
#endif
                    available = true;
                }

#if DEBUG_ //
                int weightClass = typeface.Weight.ToOpenTypeWeight();
                switch (style)
                {
                case XFontStyle.Regular:
                    //if (typeface.TryGetGlyphTypeface(.Style == FontStyles.Normal && typeface.Weight== FontWeights.Normal.)
                    break;

                case XFontStyle.Bold:
                    break;

                case XFontStyle.Italic:
                    break;

                case XFontStyle.BoldItalic:
                    break;
                }
#endif
                if (available)
                {
                    return(true);
                }
            }
            return(false);
#else
            return(true); // AGHACK
#endif
        }
예제 #4
0
        /// <summary>
        /// Code separated from Metric getter to make code easier to debug.
        /// (Setup properties in their getters caused side effects during debugging because Visual Studio calls a getter
        /// to early to show its value in a debugger window.)
        /// </summary>
        void CreateDescriptorAndInitializeFontMetrics()  // TODO: refactor
        {
            Debug.Assert(_fontMetrics == null, "InitializeFontMetrics() was already called.");
            Descriptor   = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(this); //_familyName, _style, _glyphTypeface.Fontface);
            _fontMetrics = new XFontMetrics(Descriptor.FontName, Descriptor.UnitsPerEm, Descriptor.Ascender, Descriptor.Descender,
                                            Descriptor.Leading, Descriptor.LineSpacing, Descriptor.CapHeight, Descriptor.XHeight, Descriptor.StemV, 0, 0, 0,
                                            Descriptor.UnderlinePosition, Descriptor.UnderlineThickness, Descriptor.StrikeoutPosition, Descriptor.StrikeoutSize);

            XFontMetrics fm = Metrics;

            // Already done in CreateDescriptorAndInitializeFontMetrics.
            //if (Descriptor == null)
            //    Descriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(this);  //(Name, (XGdiFontStyle)Font.Style);

            UnitsPerEm  = Descriptor.UnitsPerEm;
            CellAscent  = Descriptor.Ascender;
            CellDescent = Descriptor.Descender;
            CellSpace   = Descriptor.LineSpacing;

            Debug.Assert(fm.UnitsPerEm == Descriptor.UnitsPerEm);
        }
예제 #5
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
        }
예제 #6
0
파일: XFont.cs 프로젝트: Core2D/PDFsharp
        /// <summary>
        /// Code separated from Metric getter to make code easier to debug.
        /// (Setup properties in their getters caused side effects during debugging because Visual Studio calls a getter
        /// to early to show its value in a debugger window.)
        /// </summary>
        void CreateDescriptorAndInitializeFontMetrics()  // TODO: refactor
        {
            Debug.Assert(_fontMetrics == null, "InitializeFontMetrics() was already called.");
            _descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(this); //_familyName, _style, _glyphTypeface.Fontface);
            _fontMetrics = new XFontMetrics(_descriptor.FontName, _descriptor.UnitsPerEm, _descriptor.Ascender, _descriptor.Descender,
                _descriptor.Leading, _descriptor.LineSpacing, _descriptor.CapHeight, _descriptor.XHeight, _descriptor.StemV, 0, 0, 0,
                _descriptor.UnderlinePosition, _descriptor.UnderlineThickness, _descriptor.StrikeoutPosition, _descriptor.StrikeoutSize);

            XFontMetrics fm = Metrics;

            // Already done in CreateDescriptorAndInitializeFontMetrics.
            //if (_descriptor == null)
            //    _descriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(this);  //(Name, (XGdiFontStyle)Font.Style);

            UnitsPerEm = _descriptor.UnitsPerEm;
            CellAscent = _descriptor.Ascender;
            CellDescent = _descriptor.Descender;
            CellSpace = _descriptor.LineSpacing;

#if DEBUG_ && GDI
            int gdiValueUnitsPerEm = Font.FontFamily.GetEmHeight(Font.Style);
            Debug.Assert(gdiValueUnitsPerEm == UnitsPerEm);
            int gdiValueAscent = Font.FontFamily.GetCellAscent(Font.Style);
            Debug.Assert(gdiValueAscent == CellAscent);
            int gdiValueDescent = Font.FontFamily.GetCellDescent(Font.Style);
            Debug.Assert(gdiValueDescent == CellDescent);
            int gdiValueLineSpacing = Font.FontFamily.GetLineSpacing(Font.Style);
            Debug.Assert(gdiValueLineSpacing == CellSpace);
#endif
#if DEBUG_ && WPF && !SILVERLIGHT
            int wpfValueLineSpacing = (int)Math.Round(Family.LineSpacing * _descriptor.UnitsPerEm);
            Debug.Assert(wpfValueLineSpacing == CellSpace);
#endif
            Debug.Assert(fm.UnitsPerEm == _descriptor.UnitsPerEm);
        }