示例#1
0
        // ----- AddString ----------------------------------------------------------------------------

        /// <summary>
        /// Adds a text string to this path.
        /// </summary>
        public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin,
                              XStringFormat format)
        {
            try
            {
                DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString");
            }
            catch
            {
                throw;
            }
        }
示例#2
0
        const string KeyPrefix = "tk:";  // "typeface key"

#if CORE || GDI
        XGlyphTypeface(string key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations, GdiFont gdiFont)
        {
            _key        = key;
            _fontFamily = fontFamily;
            _fontSource = fontSource;

            _fontface = OpenTypeFontface.CetOrCreateFrom(fontSource);
            Debug.Assert(ReferenceEquals(_fontSource.Fontface, _fontface));

            _gdiFont = gdiFont;

            _styleSimulations = styleSimulations;
            Initialize();
        }
示例#3
0
        public static XGlyphTypeface GetOrCreateFromWpf(WpfTypeface wpfTypeface)
        {
#if DEBUG
            if (wpfTypeface.FontFamily.Source == "Segoe UI Semilight")
            {
                wpfTypeface.GetType();
            }
#endif
            //string typefaceKey = ComputeKey(wpfTypeface);
            //XGlyphTypeface glyphTypeface;
            //if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface))
            //{
            //    // We have the glyph typeface already in cache.
            //    return glyphTypeface;
            //}

            // Create WPF glyph typeface.
            WpfGlyphTypeface wpfGlyphTypeface;
            if (!wpfTypeface.TryGetGlyphTypeface(out wpfGlyphTypeface))
            {
                return(null);
            }

            string typefaceKey = ComputeKey(wpfGlyphTypeface);

            string name1 = wpfGlyphTypeface.DesignerNames[FontHelper.CultureInfoEnUs];
            string name2 = wpfGlyphTypeface.FaceNames[FontHelper.CultureInfoEnUs];
            string name3 = wpfGlyphTypeface.FamilyNames[FontHelper.CultureInfoEnUs];
            string name4 = wpfGlyphTypeface.ManufacturerNames[FontHelper.CultureInfoEnUs];
            string name5 = wpfGlyphTypeface.Win32FaceNames[FontHelper.CultureInfoEnUs];
            string name6 = wpfGlyphTypeface.Win32FamilyNames[FontHelper.CultureInfoEnUs];

            XGlyphTypeface glyphTypeface;
            if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface))
            {
                // We have the glyph typeface already in cache.
                return(glyphTypeface);
            }

            XFontFamily fontFamily = XFontFamily.GetOrCreateFromWpf(wpfTypeface.FontFamily);
            XFontSource fontSource = XFontSource.GetOrCreateFromWpf(typefaceKey, wpfGlyphTypeface);

            glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource,
                                               (XStyleSimulations)wpfGlyphTypeface.StyleSimulations,
                                               wpfTypeface, wpfGlyphTypeface);
            GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface);

            return(glyphTypeface);
        }
示例#4
0
        public XGlyphTypeface(string key, XFontSource fontSource)
        {
            string familyName = fontSource.Fontface.name.Name;

            _fontFamily = new XFontFamily(familyName, false);
            _fontface   = fontSource.Fontface;
            _isBold     = _fontface.os2.IsBold;
            _isItalic   = _fontface.os2.IsItalic;

            _key = key;
            //_fontFamily =xfont  FontFamilyCache.GetFamilyByName(familyName);
            _fontSource = fontSource;

            Initialize();
        }
示例#5
0
        //public XFontFamily(GdiFontFamily gdiFontFamily)
        //{
        //    FamilyInternal = FontFamilyInternal.GetOrCreateFromGdi(gdiFontFamily);
        //}
#endif

#if WPF
        //public XFontFamily(WpfFontFamily wpfFontFamily)
        //{
        //    FamilyInternal = FontFamilyInternal.GetOrCreateFromWpf(wpfFontFamily);
        //    //// HACK
        //    //int idxHash = _name.LastIndexOf('#');
        //    //if (idxHash > 0)
        //    //    _name = _name.Substring(idxHash + 1);
        //    //_wpfFamily = family;
        //}
#endif

        internal static XFontFamily CreateFromName_not_used(string name, bool createPlatformFamily)
        {
            XFontFamily fontFamily = new XFontFamily(name);

            if (createPlatformFamily)
            {
#if GDI
                //fontFamily._gdiFamily = new System.Drawing.FontFamily(name);
#endif
#if WPF
                //fontFamily._wpfFamily = new System.Windows.Media.FontFamily(name);
#endif
            }
            return(fontFamily);
        }
        public static XGlyphTypeface GetOrCreateFrom(string familyName, FontResolvingOptions fontResolvingOptions)
        {
            // Check cache for requested type face.
            string         typefaceKey = ComputeKey(familyName, fontResolvingOptions);
            XGlyphTypeface glyphTypeface;

            if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface))
            {
                // Just return existing one.
                return(glyphTypeface);
            }

            // Resolve typeface by FontFactory.
            FontResolverInfo fontResolverInfo = FontFactory.ResolveTypeface(familyName, fontResolvingOptions, typefaceKey);

            if (fontResolverInfo == null)
            {
                // No fallback - just stop.
                throw new InvalidOperationException("No appropriate font found.");
            }
            // Now create the font family at the first.
            XFontFamily fontFamily;
            PlatformFontResolverInfo platformFontResolverInfo = fontResolverInfo as PlatformFontResolverInfo;

            if (platformFontResolverInfo != null)
            {
            }
            else
            {
                // Create new and exclusively used font family for custom font resolver retrieved font source.
                fontFamily = XFontFamily.CreateSolitary(fontResolverInfo.FaceName);
            }

            // We have a valid font resolver info. That means we also have an XFontSource object loaded in the cache.
            ////XFontSource fontSource = FontFactory.GetFontSourceByTypefaceKey(fontResolverInfo.FaceName);
            XFontSource fontSource = FontFactory.GetFontSourceByFontName(fontResolverInfo.FaceName);

            Debug.Assert(fontSource != null);

            // Each font source already contains its OpenTypeFontface.
            glyphTypeface = new XGlyphTypeface(typefaceKey, fontSource);
            GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface);

            return(glyphTypeface);
        }
示例#7
0
        public static XGlyphTypeface GetOrCreateFrom(string familyName, FontResolvingOptions fontResolvingOptions)
        {
            // Check cache for requested type face.
            string         typefaceKey = ComputeKey(familyName, fontResolvingOptions);
            XGlyphTypeface glyphTypeface;

            if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface))
            {
                // Just return existing one.
                return(glyphTypeface);
            }

            // Resolve typeface by FontFactory.
            FontResolverInfo fontResolverInfo = FontFactory.ResolveTypeface(familyName, fontResolvingOptions, typefaceKey);

            if (fontResolverInfo == null)
            {
                // No fallback - just stop.
                throw new InvalidOperationException("No appropriate font found.");
            }

#if CORE || GDI
            GdiFont gdiFont = null;
#endif
#if WPF
            WpfFontFamily    wpfFontFamily    = null;
            WpfTypeface      wpfTypeface      = null;
            WpfGlyphTypeface wpfGlyphTypeface = null;
#endif
#if UWP
            // Nothing to do.
#endif
            // Now create the font family at the first.
            XFontFamily fontFamily;
            PlatformFontResolverInfo platformFontResolverInfo = fontResolverInfo as PlatformFontResolverInfo;
            if (platformFontResolverInfo != null)
            {
#if CORE || GDI
                // $TODO THHO Lock???
                // Reuse GDI+ font from platform font resolver.
                gdiFont    = platformFontResolverInfo.GdiFont;
                fontFamily = XFontFamily.GetOrCreateFromGdi(gdiFont);
#endif
#if WPF
#if !SILVERLIGHT
                // Reuse WPF font family created from platform font resolver.
                wpfFontFamily    = platformFontResolverInfo.WpfFontFamily;
                wpfTypeface      = platformFontResolverInfo.WpfTypeface;
                wpfGlyphTypeface = platformFontResolverInfo.WpfGlyphTypeface;
                fontFamily       = XFontFamily.GetOrCreateFromWpf(wpfFontFamily);
#else
                fontFamily = XFontFamily.GetOrCreateFromWpf(new WpfFontFamily(familyName));
#endif
#endif
#if NETFX_CORE || UWP
                fontFamily = null;
#endif
            }
            else
            {
                // Create new and exclusively used font family for custom font resolver retrieved font source.
                fontFamily = XFontFamily.CreateSolitary(fontResolverInfo.FaceName);
            }

            // We have a valid font resolver info. That means we also have an XFontSource object loaded in the cache.
            ////XFontSource fontSource = FontFactory.GetFontSourceByTypefaceKey(fontResolverInfo.FaceName);
            XFontSource fontSource = FontFactory.GetFontSourceByFontName(fontResolverInfo.FaceName);
            Debug.Assert(fontSource != null);

            // Each font source already contains its OpenTypeFontface.
#if CORE || GDI
            glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations, gdiFont);
#endif
#if WPF
            glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations, wpfTypeface, wpfGlyphTypeface);
#endif
#if NETFX_CORE || UWP
            glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations);
#endif
#if __IOS__
            glyphTypeface = new XGlyphTypeface(typefaceKey, fontSource);
#endif
            glyphTypeface = new XGlyphTypeface(typefaceKey, fontSource);
            GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface);

            return(glyphTypeface);
        }
示例#8
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, XGdiFontStyle style)
        {
            style &= XGdiFontStyle.BoldItalic;
#if !SILVERLIGHT
            // TODOWPF: check for correctness
            // FontDescriptor descriptor = FontDescriptorCache.GetOrCreateDescriptor(family.Name, style);
            //XFontMetrics metrics = descriptor.FontMetrics;

            // style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic
            List <WpfTypeface> typefaces = new List <WpfTypeface>(family.WpfFamily.GetTypefaces());
            foreach (WpfTypeface typeface in typefaces)
            {
                bool bold   = typeface.Weight == FontWeights.Bold;
                bool italic = typeface.Style == FontStyles.Italic;
                switch (style)
                {
                case XGdiFontStyle.Regular:
                    if (!bold && !italic)
                    {
                        return(true);
                    }
                    break;

                case XGdiFontStyle.Bold:
                    if (bold && !italic)
                    {
                        return(true);
                    }
                    break;

                case XGdiFontStyle.Italic:
                    if (!bold && italic)
                    {
                        return(true);
                    }
                    break;

                case XGdiFontStyle.BoldItalic:
                    if (bold && italic)
                    {
                        return(true);
                    }
                    break;
                }
                //////                typeface.sty
                //////                bool available = false;
                //////                GlyphTypeface glyphTypeface;
                //////                if (typeface.TryGetGlyphTypeface(out glyphTypeface))
                //////                {
                //////#if DEBUG_
                //////                    glyphTypeface.GetType();
                //////#endif
                //////                    available = true;
                //////                }
                //////                if (available)
                //////                    return true;
            }
            return(false);
#else
            return(true); // AGHACK
#endif
        }
示例#9
0
 public XTypeface_not_yet_used(XFontFamily family, XFontStyle style)
 {
     _family = family;
     _style  = style;
 }
        internal static XFontFamily CreateFromName_not_used(string name, bool createPlatformFamily)
        {
            XFontFamily fontFamily = new XFontFamily(name);

            return(fontFamily);
        }