[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ft] bottom-row first pixel order?
From: |
Joe Krahn |
Subject: |
Re: [ft] bottom-row first pixel order? |
Date: |
Wed, 21 Sep 2005 14:21:30 -0400 |
User-agent: |
Mozilla Thunderbird 0.9 (X11/20041103) |
Here is some sample code and results illustrating problems with a
mat.yy=-1 transform. Somtimes it works OK, but even then, the hinter
seems to malfunction, even though the transform does not intersect whole
pixels.
Joe Krahn
/****** test.c ******/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ft2build.h>
#include FT_FREETYPE_H
int main( int argc, char** argv ) {
FT_Library library;
FT_Face face;
FT_Error error;
FT_Bitmap *bitmap;
unsigned char *buffer;
int x, y;
FT_Matrix mat={0x10000,0,0,0x10000};
FT_Vector vec={0,0};
char *filename, ch;
int target_height;
if (argc<6) {
printf("usage: %s <font_file> <char> <height> <y-scale>
<y-shift>\n",argv[0]);
exit(1);
}
filename = argv[1];
ch = argv[2][0];
target_height = atoi(argv[3]);
mat.yy = (int)(atof(argv[4])*65536.0);
vec.y = (int)(atof(argv[5])*64.0);
printf ("Transform: M={0x%08lx,0x%08lx,0x%08lx,0x%08lx},
V={0x%08lx,0x%08lx}\n",
mat.xx,mat.xy,mat.yx,mat.yy,vec.x,vec.y);
FT_Init_FreeType( &library );
error = FT_New_Face( library, filename, 0, &face );
if (error) { printf("Error 0x%04x loading %s\n",error,filename);
exit(error); }
FT_Set_Pixel_Sizes( face, 0, target_height );
FT_Set_Transform(face,&mat,&vec);
error=FT_Load_Char( face, ch, FT_LOAD_RENDER | FT_LOAD_TARGET_MONO);
if (error) { printf("Error 0x%04x loading character
'%c'\n",error,ch); exit(error); }
bitmap=&face->glyph->bitmap;
buffer = (unsigned char *)bitmap->buffer;
for(y=0;y<bitmap->rows;y++) {
for(x=0;x<bitmap->width;x++) {
putchar ( (buffer[y*bitmap->pitch+(x>>3)] & (0x80>>(x&7))) ? '#'
: '.');
}
putchar('\n');
}
FT_Done_Face ( face );
FT_Done_FreeType( library );
return 0;
}
/***** END test.c *****/
> rpm -q freetype-devel
freetype-devel-2.1.7-4
> gcc -Wall `freetype-config --cflags --libs` -o test test.c
Identity transform OK:
> ./test Courier.ttf W 16 1 0
Transform: M={0x00010000,0x00000000,0x00000000,0x00010000},
V={0x00000000,0x00000000}
###...###
#......#.
#...#..#.
#..#.#.#.
.#.#.#.#.
.#.#.#.#.
.##..#.#.
.##...##.
.##...##.
Negative Y gives an error:
> ./test Courier.ttf W 16 -1 0
Transform: M={0x00010000,0x00000000,0x00000000,0xffff0000},
V={0x00000000,0x00000000}
Error 0x0014 loading character 'W
Negative Y with a small Y shift works, but different shifts affect the
scale:
> ./test Courier.ttf W 16 -1 -0.1
Transform: M={0x00010000,0x00000000,0x00000000,0xffff0000},
V={0x00000000,0xfffffffa}
.#######.
> ./test Courier.ttf W 16 -1 0.6
Transform: M={0x00010000,0x00000000,0x00000000,0xffff0000},
V={0x00000000,0x00000026}
.#.....#.
.##...##.
.##...##.
.##...##.
.##...##.
.##..#.#.
.#.#.#.#.
.#.#.#.#.
.#.#.#.#.
.#.#.#.#.
#..#.#.#.
#..##..#.
#...#..#.
#......#.
#......#.
###...###
.........
This one is shorter even though the Y scale is unchaged:
> ./test Courier.ttf W 16 -1 2.6
Transform: M={0x00010000,0x00000000,0x00000000,0xffff0000},
V={0x00000000,0x000000a6}
.........
.##...##.
.##...##.
.##...##.
.##..#.#.
.#.#.#.#.
.#.#.#.#.
.#.#.#.#.
#..##..#.
#......#.
#......#.
###...###
.........
For some fonts+sizes, Y-flipping works:
> ./test Symbol.ttf W 16 -1 0
Transform: M={0x00010000,0x00000000,0x00000000,0xffff0000},
V={0x00000000,0x00000000}
...###.
...#...
...#...
...#...
...#...
...#...
.######
xenon:~/Prog/gltext> ./test Symbol.ttf W 16 1 0
Transform: M={0x00010000,0x00000000,0x00000000,0x00010000},
V={0x00000000,0x00000000}
.######
...#...
...#...
...#...
...#...
...#...
...###.