如何获得字库中的所有符号或文字

其实我也恋长安 2021-03-04 05:03:38
请问有人知道如何使用C语言提取ttf字库文件中的所有字符吗,freetype也没有找到相关的函数
...全文
755 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_45334213 2021-03-09
  • 打赏
  • 举报
回复
......................................................
finalfantasy_xu 2021-03-08
  • 打赏
  • 举报
回复
学习一下了!
赵4老师 2021-03-05
  • 打赏
  • 举报
回复
仅供参考:
#pragma comment(lib,"gdi32")
#include <windows.h>
#include <stdio.h>

int main() {
    const DWORD uWidth = 18 + 17 * 256, uHeight = 18 + 17 * 128;

    PBITMAPINFO pbmi = (PBITMAPINFO) LocalAlloc (LPTR, sizeof (BITMAPINFOHEADER) + sizeof (RGBQUAD) * 2);
    pbmi->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
    pbmi->bmiHeader.biWidth = uWidth;
    pbmi->bmiHeader.biHeight = uHeight;
    pbmi->bmiHeader.biPlanes = 1;
    pbmi->bmiHeader.biBitCount = 1;
    pbmi->bmiHeader.biSizeImage = ((uWidth + 31) & ~31) / 8 * uHeight;
    pbmi->bmiColors[0].rgbBlue = 0;
    pbmi->bmiColors[0].rgbGreen = 0;
    pbmi->bmiColors[0].rgbRed = 0;
    pbmi->bmiColors[1].rgbBlue = 255;
    pbmi->bmiColors[1].rgbGreen = 255;
    pbmi->bmiColors[1].rgbRed = 255;

    HDC hDC = CreateCompatibleDC (0);
    void * pvBits;
    HBITMAP hBitmap = CreateDIBSection (hDC, pbmi, 0, &pvBits, NULL, 0);
    SelectObject (hDC, hBitmap);
    HFONT hFont = CreateFont (16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "宋体");
//  HFONT hFont = CreateFont (16, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, 0, 0, 0, 0, "宋体");
    SelectObject (hDC, hFont);
    BitBlt (hDC, 0, 0, uWidth, uHeight, NULL, 0, 0, WHITENESS);

    char c[4];
    int i, j;
    for (i = 128; i < 256; i++) {
        sprintf (c, "%02X", i);
        TextOut (hDC, 1, (i - 127) * 17 + 1, c, 2);
    }
    for (j = 0; j < 256; j++) {
        sprintf (c, "%02X", j);
        TextOut (hDC, (j + 1)* 17 + 1, 1, c, 2);
    }
    for (i = 128; i < 256; i++) {
        for (j = 0; j < 256; j++) {
            c[0] = (char) i;
            c[1] = (char) j;
            TextOut (hDC, (j + 1) * 17 + 1, (i - 127) * 17 + 1, c, 2);
        }
    }
    for (i = 0; i < 130; i++) {
        MoveToEx (hDC, 0, i * 17, NULL);
        LineTo (hDC, uWidth, i * 17);
    }
    for (j = 0; j < 258; j++) {
        MoveToEx (hDC, j * 17, 0, NULL);
        LineTo (hDC, j * 17, uHeight);
    }

    BITMAPFILEHEADER bmfh;
    bmfh.bfType = *(PWORD) "BM";
    bmfh.bfReserved1 = 0;
    bmfh.bfReserved2 = 0;
    bmfh.bfOffBits = sizeof (BITMAPFILEHEADER) + sizeof (BITMAPINFOHEADER) + sizeof (RGBQUAD) * 2;
    bmfh.bfSize = bmfh.bfOffBits + pbmi->bmiHeader.biSizeImage;

    HANDLE hFile = CreateFile ("goal.bmp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
    if (hFile != INVALID_HANDLE_VALUE) {
        DWORD dwWritten;
        WriteFile (hFile, &bmfh, sizeof (BITMAPFILEHEADER), &dwWritten, NULL);
        WriteFile (hFile, pbmi, sizeof (BITMAPINFOHEADER) + sizeof (RGBQUAD) * 2, &dwWritten, NULL);
        WriteFile (hFile, pvBits, pbmi->bmiHeader.biSizeImage, &dwWritten, NULL);

        CloseHandle (hFile);
    }

    DeleteObject (hFont);
    DeleteObject (hBitmap);
    DeleteDC (hDC);
    LocalFree (pbmi);

    return 0;
}
趁CSDN的程序猿表情还没戒烟,我赶紧多抽两口!
forever74 2021-03-05
  • 打赏
  • 举报
回复
编码的意思就是你输入的字的内码,编码空间就是内码的取值范围。 结合你编程环境的实际情况,写个循环就好。
  • 打赏
  • 举报
回复
引用 4 楼 forever74 的回复:
最笨最简单的办法,循环穷举编码空间,找不到的跳过。
编码空间怎么弄,能否详细说下吗
forever74 2021-03-05
  • 打赏
  • 举报
回复
最笨最简单的办法,循环穷举编码空间,找不到的跳过。
  • 打赏
  • 举报
回复
我可以通过freetype输入自定义的文字,然后生成bmp图片,但是我不想输入自定义的字,想直接获得字体文件中的字,然后再将所有文字显示到一张图片中
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903 的回复:
https://tchayen.github.io/posts/ttf-file-parsing
看了下,都是JavaScript,看不太懂,而且我这边也只能用C
  • 打赏
  • 举报
回复
引用 8 楼 早打大打打核战争 的回复:
GetFontUnicodeRanges
这个函数可以,我去找找用法。
  • 打赏
  • 举报
回复
引用 6 楼 forever74 的回复:
编码的意思就是你输入的字的内码,编码空间就是内码的取值范围。 结合你编程环境的实际情况,写个循环就好。
好的,谢谢
赵4老师 2021-03-05
  • 打赏
  • 举报
回复
WCRANGE [This is preliminary documentation and subject to change.] The WCRANGE structure specifies a range of Unicode characters. typedef struct tagWCRANGE { WCHAR wcLow; USHORT cGlyphs; } WCRANGE, *PWCRANGE,FAR *LPWCRANGE; Members wcLow Low Unicode code point in the range of supported Unicode code points. cGlyphs Number of supported Unicode code points in this range. QuickInfo Windows NT: Requires version 5.0 or later. Windows: Requires Windows 98 or later. Windows CE: Unsupported. Header: Declared in wingdi.h. See Also Fonts and Text Overview, Font and Text Structures, GLYPHSET
赵4老师 2021-03-05
  • 打赏
  • 举报
回复
GetFontUnicodeRanges [This is preliminary documentation and subject to change.] The GetFontUnicodeRanges function returns information about which Unicode characters are supported by a font. The information is returned as a GLYPHSET structure. WINGDIAPI DWORD WINAPI GetFontUnicodeRanges( HDC hdc, // handle to the device context LPGLYPHSET lpgs // pointer to the glyph set structure ); Parameters hdc Handle to the device context. lpgs Pointer to a buffer to contain the GLYPHSET structure. If this parameter is NULL, the function returns a pointer to the GLYPHSET structure for the current font. Return Values If the function succeeds, it returns a pointer to the font's GLYPHSET structure for the current device context. If the function fails, it returns zero. QuickInfo Windows NT: Requires version 5.0 or later. Windows: Unsupported. Windows CE: Unsupported. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. See Also Fonts and Text Overview, Font and Text Functions, GLYPHSET GLYPHSET [This is preliminary documentation and subject to change.] The GLYPHSET structure contains information about a range of Unicode code points. typedef struct tagGLYPHSET { DWORD cbThis; DWORD flAccel; DWORD cGlyphsSupported; DWORD cRanges; WCRANGE ranges[1]; } GLYPHSET, *PGLYPHSET, FAR *LPGLYPHSET; Members cbThis Size, in bytes, of this structure. flAccel Flags describing the maximum size of the glyph indices. This member can be the following value: Value Meaning GS_8BIT_INDICES Treat glyph indices as 8-bit wide values. Otherwise, they are 16-bit wide values. cGlyphsSupported Total number of Unicode code points supported in the font. cRanges Total number of Unicode ranges in ranges. ranges Array of Unicode ranges that are supported in the font. QuickInfo Windows NT: Requires version 5.0 or later. Windows: Requires Windows 98 or later. Windows CE: Unsupported. Header: Declared in wingdi.h. See Also Fonts and Text Overview, Font and Text Structures, GetFontUnicodeRanges, WCRANGE
  • 打赏
  • 举报
回复
GetFontUnicodeRanges

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧