Exemple #1
0
        FontFamilyInternal(GdiFontFamily gdiFontFamily)
        {
            SourceName = Name = gdiFontFamily.Name;
            GdiFamily  = gdiFontFamily;
#if WPF
            // Hybrid build only.
            _wpfFontFamily = new WpfFontFamily(gdiFontFamily.Name);
#endif
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XFont"/> class from a System.DrawingCore.FontFamily.
 /// </summary>
 /// <param name="fontFamily">The System.DrawingCore.FontFamily.</param>
 /// <param name="emSize">The em size.</param>
 /// <param name="style">The font style.</param>
 /// <param name="pdfOptions">Additional PDF options.</param>
 public XFont(GdiFontFamily fontFamily, double emSize, XFontStyle style, XPDFFontOptions pdfOptions)
 {
     FamilyName    = fontFamily.Name;
     GdiFontFamily = fontFamily;
     Size          = emSize;
     Style         = style;
     _pdfOptions   = pdfOptions;
     InitializeFromGdi();
 }
Exemple #3
0
 internal static FontFamilyInternal GetOrCreateFromGdi(GdiFontFamily gdiFontFamily)
 {
     try
     {
         Lock.EnterFontFactory();
         FontFamilyInternal fontFamily = new FontFamilyInternal(gdiFontFamily);
         fontFamily = FontFamilyCache.CacheOrGetFontFamily(fontFamily);
         return(fontFamily);
     }
     finally { Lock.ExitFontFactory(); }
 }
Exemple #4
0
        FontFamilyInternal(WpfFontFamily wpfFontFamily)
        {
#if !SILVERLIGHT
            _sourceName    = wpfFontFamily.Source;
            _name          = wpfFontFamily.FamilyNames[FontHelper.XmlLanguageEnUs];
            _wpfFontFamily = wpfFontFamily;
#else
            _sourceName    = _name = wpfFontFamily.Source;
            _wpfFontFamily = wpfFontFamily;
#endif
#if GDI
            // Hybrid build only.
            _gdiFontFamily = new GdiFontFamily(_sourceName);
#endif
        }
Exemple #5
0
        // Implementation Notes
        // FontFamilyInternal implements an XFontFamily.
        //
        // * Each XFontFamily object is just a handle to its FontFamilyInternal singleton.
        //
        // * A FontFamilyInternal is uniquely identified by its name. It
        //    is not possible to use two different fonts that have the same
        //    family name.

        FontFamilyInternal(string familyName, bool createPlatformObjects)
        {
            SourceName = Name = familyName;
#if CORE || GDI
            if (createPlatformObjects)
            {
                GdiFamily = new GdiFontFamily(familyName);
                Name      = GdiFamily.Name;
            }
#endif
#if WPF && !SILVERLIGHT
            if (createPlatformObjects)
            {
                _wpfFontFamily = new WpfFontFamily(familyName);
                _name          = _wpfFontFamily.FamilyNames[FontHelper.XmlLanguageEnUs];
            }
#endif
#if SILVERLIGHT
            _wpfFontFamily = new WpfFontFamily(_name);
            _name          = _wpfFontFamily.Source; // Not expected to change _name.
#endif
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XFont"/> class from a System.DrawingCore.FontFamily.
 /// </summary>
 /// <param name="fontFamily">The System.DrawingCore.FontFamily.</param>
 /// <param name="emSize">The em size.</param>
 /// <param name="style">The font style.</param>
 public XFont(GdiFontFamily fontFamily, double emSize, XFontStyle style)
     : this(fontFamily, emSize, style, new XPDFFontOptions(GlobalFontSettings.DefaultFontEncoding))
 {
 }
Exemple #7
0
        public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
        {
            Object       value;
            byte         charSet    = 1;
            float        size       = 8;
            String       name       = null;
            bool         vertical   = false;
            FontStyle    style      = FontStyle.Regular;
            FontFamily   fontFamily = null;
            GraphicsUnit unit       = GraphicsUnit.Point;

            if ((value = propertyValues ["GdiCharSet"]) != null)
            {
                charSet = (byte)value;
            }

            if ((value = propertyValues ["Size"]) != null)
            {
                size = (float)value;
            }

            if ((value = propertyValues ["Unit"]) != null)
            {
                unit = (GraphicsUnit)value;
            }

            if ((value = propertyValues ["Name"]) != null)
            {
                name = (String)value;
            }

            if ((value = propertyValues ["GdiVerticalFont"]) != null)
            {
                vertical = (bool)value;
            }

            if ((value = propertyValues ["Bold"]) != null)
            {
                bool bold = (bool)value;
                if (bold == true)
                {
                    style |= FontStyle.Bold;
                }
            }

            if ((value = propertyValues ["Italic"]) != null)
            {
                bool italic = (bool)value;
                if (italic == true)
                {
                    style |= FontStyle.Italic;
                }
            }

            if ((value = propertyValues ["Strikeout"]) != null)
            {
                bool strike = (bool)value;
                if (strike == true)
                {
                    style |= FontStyle.Strikeout;
                }
            }

            if ((value = propertyValues ["Underline"]) != null)
            {
                bool underline = (bool)value;
                if (underline == true)
                {
                    style |= FontStyle.Underline;
                }
            }

            /* ?? Should default font be culture dependent ?? */
            if (name == null)
            {
                fontFamily = new FontFamily("Tahoma");
            }
            else
            {
                name = name.ToLower();
                FontCollection collection        = new InstalledFontCollection();
                FontFamily []  installedFontList = collection.Families;
                foreach (FontFamily font in installedFontList)
                {
                    if (name == font.Name.ToLower())
                    {
                        fontFamily = font;
                        break;
                    }
                }

                // font family not found in installed fonts
                if (fontFamily == null)
                {
                    collection = new PrivateFontCollection();
                    FontFamily [] privateFontList = collection.Families;
                    foreach (FontFamily font in privateFontList)
                    {
                        if (name == font.Name.ToLower())
                        {
                            fontFamily = font;
                            break;
                        }
                    }
                }

                // font family not found in private fonts also
                if (fontFamily == null)
                {
                    fontFamily = FontFamily.GenericSansSerif;
                }
            }

            return(new Font(fontFamily, size, style, unit, charSet, vertical));
        }