获取.net中的字体信息

发布于 2024-08-05 08:30:32 字数 136 浏览 0 评论 0原文

我想知道是否有人知道如何以编程方式从 true type 字体中获取版本和版权详细信息等信息。如果您在资源管理器中打开它以及预览,您将在 Windows 字体查看器中获得此信息。我查看了 Logfont 结构,但信息似乎不在这里,

干杯 卢克

I was wondering if anyone knows how to programatically get things like the version and copyright details out of a true type font. If you open it in explorer as well as the preview you get this info in the windows font viewer. I've looked at the Logfont structure but the info doesn't seem to be in here

Cheers
Luke

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风追烟花雨 2024-08-12 08:30:32

几年前我为了一个工作项目不得不这样做。我无法发布此内容,因为它是专有的,但 TT 字体的规范位于此处。

我为偏移表、名称记录、名称表头和表目录元素编写了类,以便每个类都有一个静态 FromStream 方法。

我还编写了一个名为 BigEndianReader 的实用程序类来处理从大端有序流中读取数据,我很高兴将其放在这里以使您的生活更轻松:

public class BigEndianReader
{
    public static bool Read(Stream stm, out uint i)
    {
        int bhihi = stm.ReadByte();
        if (bhihi == -1)
        {
            i = 0;
            return false;
        }
        int bhi = stm.ReadByte();
        if (bhi == -1)
        {
            i = 0;
            return false;
        }
        int blo = stm.ReadByte();
        if (blo == -1)
        {
            i = 0;
            return false;
        }
        int blolo = stm.ReadByte();
        if (blolo == -1)
        {
            i = 0;
            return false;
        }
        i = (uint)((bhihi << 24) | (bhi << 16) | (blo << 8) | blolo);
        return true;
    }

    public static bool Read(Stream stm, out int i)
    {
        int bhihi = stm.ReadByte();
        if (bhihi == -1)
        {
            i = 0;
            return false;
        }
        int bhi = stm.ReadByte();
        if (bhi == -1)
        {
            i = 0;
            return false;
        }
        int blo = stm.ReadByte();
        if (blo == -1)
        {
            i = 0;
            return false;
        }
        int blolo = stm.ReadByte();
        if (blolo == -1)
        {
            i = 0;
            return false;
        }
        i = ((bhihi << 24) | (bhi << 16) | (blo << 8) | blolo);
        return true;
    }


    public static bool Read(Stream stm, out ushort s)
    {
        int bhi = stm.ReadByte();
        if (bhi == -1)
        {
            s = 0;
            return false;
        }
        int blo = stm.ReadByte();
        if (blo == -1)
        {
            s = 0;
            return false;
        }
        s = (ushort)(((bhi << 8) | blo) & 0xffff);
        return true;
    }

    public static bool Read(Stream stm, out short s)
    {
        int bhi = stm.ReadByte();
        if (bhi == -1)
        {
            s = 0;
            return false;
        }
        int blo = stm.ReadByte();
        if (blo == -1)
        {
            s = 0;
            return false;
        }
        s = (short)(((bhi << 8) | blo) & 0xffff);
        return true;
    }
}

这不是特别优雅,但它很容易使用:

int val;

if (!BigEndianReader.Read(stm, out val))
    throw new SomeErrorOfSomeKind();

我想如果您足够关心,您可以在 Stream 上创建所有扩展方法,然后您可以阅读:

int val;

if(!stm.BERead(out val)) // BE prefix for Big Endian
    throw new SomeErrorOfSomeKind();

I had to do this a couple years ago for a work project. I can't post this as it's proprietary, but the spec for TT fonts is here.

I wrote classes for offset table, name record, name table header, and table directory elements such that each class had a static FromStream method.

I also wrote a utility class called BigEndianReader to handle reading data in from a big endian ordered stream, which I'm happy to put here to make your life easier:

public class BigEndianReader
{
    public static bool Read(Stream stm, out uint i)
    {
        int bhihi = stm.ReadByte();
        if (bhihi == -1)
        {
            i = 0;
            return false;
        }
        int bhi = stm.ReadByte();
        if (bhi == -1)
        {
            i = 0;
            return false;
        }
        int blo = stm.ReadByte();
        if (blo == -1)
        {
            i = 0;
            return false;
        }
        int blolo = stm.ReadByte();
        if (blolo == -1)
        {
            i = 0;
            return false;
        }
        i = (uint)((bhihi << 24) | (bhi << 16) | (blo << 8) | blolo);
        return true;
    }

    public static bool Read(Stream stm, out int i)
    {
        int bhihi = stm.ReadByte();
        if (bhihi == -1)
        {
            i = 0;
            return false;
        }
        int bhi = stm.ReadByte();
        if (bhi == -1)
        {
            i = 0;
            return false;
        }
        int blo = stm.ReadByte();
        if (blo == -1)
        {
            i = 0;
            return false;
        }
        int blolo = stm.ReadByte();
        if (blolo == -1)
        {
            i = 0;
            return false;
        }
        i = ((bhihi << 24) | (bhi << 16) | (blo << 8) | blolo);
        return true;
    }


    public static bool Read(Stream stm, out ushort s)
    {
        int bhi = stm.ReadByte();
        if (bhi == -1)
        {
            s = 0;
            return false;
        }
        int blo = stm.ReadByte();
        if (blo == -1)
        {
            s = 0;
            return false;
        }
        s = (ushort)(((bhi << 8) | blo) & 0xffff);
        return true;
    }

    public static bool Read(Stream stm, out short s)
    {
        int bhi = stm.ReadByte();
        if (bhi == -1)
        {
            s = 0;
            return false;
        }
        int blo = stm.ReadByte();
        if (blo == -1)
        {
            s = 0;
            return false;
        }
        s = (short)(((bhi << 8) | blo) & 0xffff);
        return true;
    }
}

This is not especially elegant, but it's easy enough to use:

int val;

if (!BigEndianReader.Read(stm, out val))
    throw new SomeErrorOfSomeKind();

I imagine that if you cared enough you could make this all extension methods on Stream and then your could would read:

int val;

if(!stm.BERead(out val)) // BE prefix for Big Endian
    throw new SomeErrorOfSomeKind();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文