Beispiel #1
0
void main()
{
    char* s = "测test试";
    int len;
    unsigned char *bits, *save;
    unsigned char *in, data;
    int sz;
    short ch;
    int i, d, n, bmp, pos;

    sz = 0;
    bits = malloc(font.width * font.height);
    save = bits;
    in = font.rundata;
    while((data = *in++)) {
        memset(bits, (data & 0x80) ? 255 : 0, data & 0x7f);
        bits += (data & 0x7f);
        sz += (data & 0x7f);
    }
    free(save);
    printf("%d * %d %c= %d(%d)\n", font.width, font.height, ((font.width * font.height == sz) ? '=' : '!'), sz, font.width * font.height);
    font_bitmap_count = font.width / font.cwidth / font_char_per_bitmap + 1;
    printf("bitmaps: %d\n", font_bitmap_count);
    font_data = (void**)malloc(font_bitmap_count * sizeof(void*));
    for(n = 0; n < font_bitmap_count; n++)
    {
        font_data[n] = malloc(font_char_per_bitmap * font.cwidth * font.cheight);
        memset(font_data[n], 0, font_char_per_bitmap * font.cwidth * font.cheight);
    }
    d = 0;
    in = font.rundata;
    while((data = *in++))
    {
        n = data & 0x7f;
        for(i = 0; i < n; i++, d++)
        {
            bmp = d % font.width / (font.cwidth * font_char_per_bitmap);
            pos = d / font.width * (font.cwidth * font_char_per_bitmap) + (d % (font.cwidth * font_char_per_bitmap));
            //printf("x = %d y = %d => b = %d x = %d y = %d\n", d % font.width, d / font.width, bmp, pos % (font.cwidth * font_char_per_bitmap), pos / (font.cwidth * font_char_per_bitmap));
            ((unsigned char*)(font_data[bmp]))[pos] = (data & 0x80) ? 0xff : 0;
        }
    }
    printf("%d %d\n", font.width * font.height, d);
    for(n = 0; n < font_bitmap_count; n++)
    {
        free(font_data[n]);
        //free(font_data);
    }
    // 1 0
    printf("%d %d\n", ch_test_cjk(s), ch_test_cjk(s + 3));
    len = ch_utf8_length(s);
    // 3
    printf("%d\n", len);
    len = ch_utf8_length(s+3);
    // 1
    printf("%d\n", len);
    len = str_utf8_length(s);
    // 8
    printf("%s %d\n", s, len);
    len = ch_utf8_to_custom(s);
    // ???
    printf("%d\n", len);
    // 84
    len = ch_utf8_to_custom(s + 3);
    printf("%d\n", len);
}
Beispiel #2
0
int gr_measure(const char *s)
{
    return gr_font->cwidth * str_utf8_length(s);
}