Exemple #1
0
        /// <summary>
        /// A GDI+ font object is used to setup the internal font objects.
        /// </summary>
        void InitializeFromGdi()
        {
            try
            {
                Lock.EnterFontFactory();
                if (_gdiFontFamily != null)
                {
                    // Create font based on its family.
                    _gdiFont = new GdiFont(_gdiFontFamily, (float)_emSize, (GdiFontStyle)_style, GraphicsUnit.World);
                }

                if (_gdiFont != null)
                {
#if DEBUG_
                    string name1 = _gdiFont.Name;
                    string name2 = _gdiFont.OriginalFontName;
                    string name3 = _gdiFont.SystemFontName;
#endif
                    _familyName = _gdiFont.FontFamily.Name;
                    // TODO: _glyphTypeface = XGlyphTypeface.GetOrCreateFrom(_gdiFont);
                }
                else
                {
                    Debug.Assert(false);
                }

                if (_glyphTypeface == null)
                {
                    _glyphTypeface = XGlyphTypeface.GetOrCreateFromGdi(_gdiFont);
                }

                CreateDescriptorAndInitializeFontMetrics();
            }
            finally { Lock.ExitFontFactory(); }
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XFont"/> class from a System.Drawing.Font.
 /// </summary>
 /// <param name="font">The System.Drawing.Font.</param>
 /// <param name="pdfOptions">Additional PDF options.</param>
 public XFont(GdiFont font, XPdfFontOptions pdfOptions)
 {
     if (font.Unit != GraphicsUnit.World)
     {
         throw new ArgumentException("Font must use GraphicsUnit.World.");
     }
     _gdiFont = font;
     Debug.Assert(font.Name == font.FontFamily.Name);
     _familyName = font.Name;
     _emSize     = font.Size;
     _style      = FontStyleFrom(font);
     _pdfOptions = pdfOptions;
     InitializeFromGdi();
 }
Exemple #3
0
        public static GdiFont CreateFont(string familyName, double emSize, GdiFontStyle style, out XFontSource fontSource)
        {
            fontSource = null;
            // ReSharper disable once JoinDeclarationAndInitializer
            GdiFont font;

            // Use font resolver in CORE build. XPrivateFontCollection exists only in GDI and WPF build.
#if GDI
            // Try private font collection first.
            font = XPrivateFontCollection.TryCreateFont(familyName, emSize, style, out fontSource);
            if (font != null)
            {
                // Get font source is different for this font because Win32 does not know it.
                return(font);
            }
#endif
            // Create ordinary Win32 font.
            font = new GdiFont(familyName, (float)emSize, style, GraphicsUnit.World);
            return(font);
        }
Exemple #4
0
        public void portable_gdi_can_draw_to_an_image_like_real_gdi()
        {
            // We get fonts outside of the timing, as the OS has pre-cached font descriptors
            var portFont = new Port.Font("Consolas", 24.5f);
            var realFont = new Real.Font("Consolas", 24.5f);

            var portFontSmall = new Port.Font("Calibri", 6);
            var realFontSmall = new Real.Font("Calibri", 6);
            var sw            = new Stopwatch();

            // Normal GDI
            sw.Restart();
            using (var bmp = new Real.Bitmap(800, 600, Real.Imaging.PixelFormat.Format24bppRgb))
            {
                using var g = Real.Graphics.FromImage(bmp);

                g.InterpolationMode = Real.Drawing2D.InterpolationMode.High;
                g.SmoothingMode     = Real.Drawing2D.SmoothingMode.HighQuality;
                g.TextRenderingHint = Real.Text.TextRenderingHint.AntiAlias;

                g.Clear(Real.Color.Lavender);
                g.DrawLine(Real.Pens.Chocolate, 10, 10, 100, 100);
                g.FillPolygon(Real.Brushes.Black, new Real.PointF[] { new (150, 10), new (250, 10), new (200, 100) });
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XFont"/> class from a System.Drawing.Font.
 /// </summary>
 /// <param name="font">The System.Drawing.Font.</param>
 public XFont(GdiFont font)
     : this(font, new XPdfFontOptions(GlobalFontSettings.DefaultFontEncoding))
 {
 }