C# PrivateFontCollection.AddMemoryFont是否可用于WOFF文件?

C# PrivateFontCollection.AddMemoryFont是否可用于WOFF文件?,c#,truetype,woff,C#,Truetype,Woff,我正在尝试编写一个web应用程序,该应用程序应该获取字体链接,并返回以发送的字体格式写入的内容的图像 我正在打开一个读取字体文件的流,并将文件的InPtr发送到PrivateFontCollection.AddMemoryFont,以便稍后可以将其用于某些图形对象。 当我使用有效的.ttf文件时,一切都很好,但是每当我尝试使用.woff字体文件时,我会在AddMemoryFont行中得到“System.IO.FileNotFoundException:file not found”,即使我可以看

我正在尝试编写一个web应用程序,该应用程序应该获取字体链接,并返回以发送的字体格式写入的内容的图像

我正在打开一个读取字体文件的流,并将文件的InPtr发送到PrivateFontCollection.AddMemoryFont,以便稍后可以将其用于某些图形对象。 当我使用有效的.ttf文件时,一切都很好,但是每当我尝试使用.woff字体文件时,我会在AddMemoryFont行中得到“System.IO.FileNotFoundException:file not found”,即使我可以看到文件读取时没有错误

我尝试使用在线转换器将.woff文件转换为.ttf,当我在新的.ttf文件上运行代码时,它工作得非常好

使用.woff文件是否有问题,或者我是否需要更改某些内容以使其正常工作

WebClient client = new WebClient();
Stream stream = client.OpenRead("http://www.drivehq.com/file/df.aspx/shareID2129391/fileID59377155/arial.ttf"); // Works fine.
//Stream stream = client.OpenRead("http://themes.googleusercontent.com/static/fonts/kiteone/v1/VNHoD96LpZ9rGZTwjozAOvesZW2xOQ-xsNqO47m55DA.woff"); // Doesn't work.
PrivateFontCollection fonts;
FontFamily family = LoadFontFamily(stream, out fonts);

public static FontFamily LoadFontFamily(Stream stream, out PrivateFontCollection fontCollection)
{
    byte[] buffer = null;
    using (MemoryStream ms = new MemoryStream())
    {
        int count = 0;
        do
        {
            byte[] buf = new byte[1024];
            count = stream.Read(buf, 0, 1024);
            ms.Write(buf, 0, count);
        } while (stream.CanRead && count > 0);
        buffer = ms.ToArray();
    }

    var handle = System.Runtime.InteropServices.GCHandle.Alloc(buffer, System.Runtime.InteropServices.GCHandleType.Pinned);

    try
    {
        var ptr = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
        fontCollection = new PrivateFontCollection();
        fontCollection.AddMemoryFont(ptr, buffer.Length);
        return fontCollection.Families[0];
    }
    finally
    {
        handle.Free();
    }
}

.NET Framework不支持导入WOFF字体,就像Windows XP/Vista/7/8一样


您必须使用将其转换为TTF并导入TTF。

它必须是TTF文件,scratch WOFF。这是我的问题。有没有办法使用WOFF,或者根本没有办法?(当然,转换文件除外)