简体   繁体   English

如何使用asp.net应用程序的自定义字体

[英]How to use custom font asp.net application

How to use custom font asp.net application. 如何使用asp.net应用程序的自定义字体。
I have a font file with me. 我有一个字体文件。 I want to add that file as a resource and use it inside the project. 我想将该文件添加为资源,并在项目中使用它。 how to do it? 怎么做?

        PrivateFontCollection pfc = new PrivateFontCollection();
        Stream fontStream = this.GetType().Assembly.GetManifestResourceStream(Server.MapPath("~/Resources/EAN-13.ttf"));

        byte[] fontdata = new byte[fontStream.Length];
        fontStream.Read(fontdata, 0, (int)fontStream.Length);
        fontStream.Close();

        unsafe
        {
            fixed (byte* pFontData = fontdata)
            {
                pfc.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
            }
        }

I tried this. 我试过了 But its not working. 但是它不起作用。

You must distinguish between the code that run on server and the code that run on client browser. 您必须区分服务器上运行的代码和客户端浏览器上运行的代码

The fonts that you have on your computer, on your server, can not be visible on user computer using the code behind just because you loading the fonts. 您使用计算机上服务器上的字体无法使用后面的代码在用户计算机上看到,因为您加载了字体。

So you have two options here. 所以您在这里有两个选择。

  1. Load the fonts, and render a text in an image using this fonts, then show this image to the user. 加载字体,并使用该字体在图像中渲染文本,然后向用户显示该图像。

  2. Use client side techniques to show this fonts. 使用客户端技术来显示此字体。 Some of them are cross browser font embedding , and other can be javascript that can rendered them on client side. 其中一些是跨浏览器字体嵌入的 ,而另一些可以是JavaScript,可以在客户端呈现它们。

You can google it with "embed custom fonts website". 您可以使用“嵌入自定义字体网站”对它进行Google搜索。

Also you can check : http://typeface.neocracy.org/ 您也可以查看: http : //typeface.neocracy.org/
and Is it possible to use custom fonts - using font-face? 是否可以使用自定义字体-使用font-face?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM