I am trying to render chinese characters using stb_truetype.h. Yet the chinese character was rendered wrongly. I tried to render an English character like 'a' with no problem. Can anyone provide some insight on how to process unicode on ubuntu 13.04/gcc4.8.1 ?
Here is my code:
#include <stdio.h>
#include <math.h>
#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation
#include "stb_truetype.h"
char ttf_buffer[1<<25];
int main(int argc, char **argv)
{
stbtt_fontinfo font;
unsigned char *bitmap;
int w,h,i,j,c = (argc > 1 ? atoi(argv[1]) : 0x4e00)/*choose character here*/, s = (argc > 2 ? atoi(argv[2]) : 20/*set font size*/);
fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "mingliu.ttc", "rb"));
//c:/windows/fonts/arialbd.ttf
//also tried Dejavu font on ubuntu for the chinese character
stbtt_InitFont(&font, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0));
bitmap = stbtt_GetCodepointBitmap(&font, 0,stbtt_ScaleForPixelHeight(&font, s), c, &w, &h, 0,0);
for (j=0; j < h; ++j) {
for (i=0; i < w; ++i)
putchar(" 1234567"[bitmap[j*w+i]>>5]);
putchar('\n');
}
return 0;
}
output using 'a'
2342
52 61
7 32
1 43
2553
53 33
62 33
26 43
271 165
7763174
2 1
output using'一'
466666666666666664
653333333333333356
63 36
63 36
63 36
63 36
63 36
63 36
63 36
63 36
63 36
63 36
63 36
63 36
63 36
63 36
664444444444444466
466666666666666664
which should be look like this:
from http://www.fileformat.info/info/unicode/char/4e00/index.htm