0

Chrome 和 Firefox 不会渲染 Font-Awesome 的 WOFF/TTF,即使他们从 HttpListener 下载它们,也就是说,iOS 上的 Safari 正在正确渲染 Font-Awesome。我正在使用 .NET 的 HttpListener 类发送 HTTP 响应,如下所示:

private void Send(HttpListenerContext context, byte[] response, string contentType)
    {
        context.Response.StatusCode = (int)HttpStatusCode.OK;
        context.Response.ContentEncoding = Encoding.UTF8;
        context.Response.ContentType = contentType;
        context.Response.ContentLength64 = response.Length;
        context.Response.AddHeader("Server", SERVER);

        if (response == null || response.Length == 0)
        {
            logger.Error("Send: Engine generated null or empty content");
            context.Response.StatusCode = (int)HttpStatusCode.NotFound;
            return;
        }

        using (var s = context.Response.OutputStream)
        {
            s.Write(response, 0, response.Length);
        }
    }

WOFF 是否有另一种编码类型(UTF8 除外)?或者在 Chrome 或 Firefox 中我有什么需要注意的吗?

任何帮助或指针表示赞赏,谢谢。

4

2 回答 2

0

在我自己的实现中,我在提供字体或二进制文件时将 ContentEncoding 标头全部省略了。

这应该有效:

context.Response.ContentLength64 = response.Length;
context.Response.ContentType = "application/x-font-woff";
context.Response.OutputStream.Write(response, 0, response.Length);

context.Response.OutputStream.Close();
于 2015-07-07T07:46:36.667 回答
0

问题是我将所有 www 内容都设置为Embedded Resource,并且我创建了一种方法来将它们转换Embedded Resource Streambyte数组,方法是首先将其转换为stringusingUTF-8编码。所以这个stackoverflow问题帮助我查明了根本原因。一旦我将其Embedded Resource Stream直接转换为byte数组,Chrome 就会开始正确显示 Font-Awesome 字体!

于 2015-07-09T16:27:05.567 回答