程式語言 - Visual C++ 6.0 - 顯示倚天中文字型



參考資訊:
http://billor.chsh.chc.edu.tw/php/Tools/qBig5.php
http://programmer-club.com.tw/ShowSameTitleN/cb/5801.html
https://github.com/rofl0r/microwindows/blob/master/src/engine/font_hzk.c

main.c

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

int is_big5(unsigned int val)
{
    if ((val >= 0xa140 && val <= 0xa3bf) ||
        (val >= 0xa440 && val <= 0xc67e) ||
        (val >= 0xc6a1 && val <= 0xc8d3) ||
        (val >= 0xc940 && val <= 0xf9fe))
    {
        return 1;
    }
    return 0;
}

int main(int argc, char **argv)
{
    FILE *f;
    unsigned int high, low;
    unsigned char top[30] = {0};
    unsigned int font = 0xae7b;

    if ((is_big5(font)) == 0)
    {
        printf("not big5 !\n");
        return -1;
    }

    f = fopen("stdfont.15", "rb");
    low = font & 0xff;
    high = 157 * (((font >> 8) & 0xff) - 164);
    if (low < 127)
    {
        low -= 64;
    }
    else
    {
        low -= 98;
    }
    fseek(f, (high + low) * 30, 0);
    fread(top, 30, 1, f);
    fclose(f);

    int x, y, z, t, cnt = 0;
    for (y = 0; y < 15; y++)
    {
        for (z = 0; z < 2; z++)
        {
            t = top[cnt++];
            for (x = 0; x < 8; x++)
            {
                if (t & 0x80)
                {
                    printf("1");
                }
                else
                {
                    printf(" ");
                }
                t <<= 1;
            }
        }
        printf("\n");
    }
    return 0;
}

完成