How can I convert a System.Drawing.font to a System.Windows.Media.Fonts or TypeFace?

后端 未结 2 869
有刺的猬
有刺的猬 2021-01-02 00:55

How can I convert a System.Drawing.Font to a System.Windows.Media.Fonts or TypeFace?

Or how can I generate an instance of

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 01:20

    I'm using below codes

    private static Typeface NewTypeFaceFromFont(System.Drawing.Font f)
    {
        Typeface typeface = null;
    
        FontFamily ff = new FontFamily(f.Name);
    
    
        if (typeface == null)
        {
            typeface = new Typeface(ff, (f.Style == System.Drawing.FontStyle.Italic ? FontStyles.Italic : FontStyles.Normal),
                             (f.Style == System.Drawing.FontStyle.Bold ? FontWeights.Bold : FontWeights.Normal),
                                        FontStretches.Normal);
        }
        if (typeface == null)
        {
            typeface = new Typeface(new FontFamily("Arial"),
                                            FontStyles.Italic,
                                            FontWeights.Normal,
                                            FontStretches.Normal);            
        }
        return typeface;
    
    }
    

提交回复
热议问题