コード例 #1
0
        /// <summary>
        /// Gets a FontFamily for a given font family name
        /// </summary>
        /// <param name="name">The name of the FontFamily to quire</param>
        /// <returns>A newly created FontFamily based on the given name</returns>
        public FontFamily GetFontFamily(string name)
        {
            FontFamily family;
            // Split font family list on "," and then trim start and end spaces and quotes.
            var fontParts = name.Split(new[] { ',' }).Select(fontName => fontName.Trim(new[] { '"', ' ', '\'' }));

            // Check known fonts
            foreach (var part in fontParts)
            {
                if (m_knownFonts.TryGetValue(part, out family))
                {
                    return(family);
                }
            }

            if (FontFamilyLookup != null)
            {
                foreach (var part in fontParts)
                {
                    try
                    {
                        var e = new FontFamilyLookupArgs(part);
                        FontFamilyLookup(this, e);
                        if (e.FontFamily != null)
                        {
                            m_knownFonts[e.FontFamily.Name] = e.FontFamily;
                            return(e.FontFamily);
                        }
                    }
                    catch { }
                }
            }
            // No valid font family found from the list requested.
            return(new FontFamily(SvgText.DefaultFontFamily));
        }
コード例 #2
0
ファイル: TestRender.cs プロジェクト: bromose/SVG
 void TestRenderCustomFont_FontFamilyLookup(object sender, FontFamilyLookupArgs e)
 {
     if (e.Name == NASALIZA)
     {
         var content = TestingSources.NASALIZA;
         // pin array so we can get its address
         var handle = GCHandle.Alloc(content, GCHandleType.Pinned);
         try
         {
             var ptr            = Marshal.UnsafeAddrOfPinnedArrayElement(content, 0);
             var fontCollection = new PrivateFontCollection();
             fontCollection.AddMemoryFont(ptr, content.Length);
             e.FontFamily = fontCollection.Families[0];
         }
         finally
         {
             // don't forget to unpin the array!
             handle.Free();
         }
     }
 }