|
From: | Peter M |
Subject: | [ft-devel] MONOCHROME with hinting??? |
Date: | Thu, 23 Mar 2006 10:46:59 +0100 |
I
am trying to make a monochrome sample. 0==
white; 255== black The
results are bad and the image always gets grayscale
values. I
can’t get a 1bit monochrome image. Can somebody help??? Also
monochrome hinting help is welcome… Regards Peter
M CODE: =============================================================================== #include
<stdio.h> #include
<string.h> #include
<math.h> #include
<ft2build.h> #include
FT_FREETYPE_H #define
WIDTH 132
#define
HEIGHT 128 /*
origin is the upper left corner */ unsigned
char image[HEIGHT][WIDTH]; char
test; /*
Replace this function with something useful. */ void draw_bitmap(
FT_Bitmap*
bitmap,
FT_Int
x,
FT_Int
y) { FT_Int i, j, p, q; FT_Int x_max = x +
bitmap->width; FT_Int y_max = y +
bitmap->rows; for ( i = x, p = 0; i < x_max; i++,
p++ ) { for ( j = y, q = 0; j <
y_max; j++, q++ ) { if ( i >=
WIDTH || j >= HEIGHT )
continue; image[j][i] |=
bitmap->buffer[q * bitmap->width + p]; } } } void show_image(
void ) { int i, j; for ( i = 0; i < HEIGHT; i++
) { for ( j = 0; j < WIDTH;
j++ )
{
if(image[i][j] == 0)
test=' ';
if(image[i][j] == 255)
test='*';
putchar(test);
} putchar(
'\n' ); } } int main() { FT_Library
library; FT_Face
face; FT_UInt
glyph_index; FT_GlyphSlot slot; FT_Matrix matrix;
/* transformation matrix */ FT_Vector pen;
/* untransformed origin
*/ FT_Error
error; char*
filename; unsigned int text[]= { 0x0054, 0x0065,
0x0073, 0x0074, 0x0020, 0x0050, 0x0052, 0x0049, 0x004E, 0x0054, 0x0021};//
UNICODE HEX text codes "Test PRINT!" double
angle; int
target_height; int
n, num_chars; filename =
"arial.ttf"; num_chars= sizeof(text)/sizeof(int);
angle
= ( 0 / 360 ) * 3.14159 * 2; /* use 25
degrees
*/ target_height =
HEIGHT; error = FT_Init_FreeType( &library
);
/* initialize library */ /* error handling omitted
*/ error = FT_New_Face( library, filename,
0, &face ); /* create face object */ /* error handling omitted
*/ /* use 50pt at 100dpi
*/ error = FT_Set_Char_Size( face ,
14 *64 ,
0
,
100
,
0
);
/* set character size */ slot =
face->glyph; /* set up matrix
*/ matrix.xx = (FT_Fixed)( cos( angle ) *
0x10000L ); matrix.xy = (FT_Fixed)(-sin( angle ) *
0x10000L ); matrix.yx = (FT_Fixed)( sin( angle ) *
0x10000L ); matrix.yy = (FT_Fixed)( cos( angle ) *
0x10000L ); /* the pen position in 26.6 cartesian
space coordinates; */ /* start at (300,200) relative to the
upper left corner
*/ pen.x = 1 * 64; pen.y = ( target_height- 10 ) * 64; for ( n = 0; n < num_chars; n++
) { /* set transformation
*/ FT_Set_Transform( face,
&matrix, &pen ); glyph_index
= FT_Get_Char_Index( face, text[n] ); /* load
glyph image into the slot (erase previous one) */ error =
FT_Load_Glyph( face, glyph_index,FT_LOAD_TARGET_MONO ); /* convert
to an anti-aliased bitmap */
error =
FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO);
if ( error
) continue;
/* ignore errors */ /* now, draw to our target
surface (convert position) */ draw_bitmap(
&slot->bitmap,
slot->bitmap_left,
target_height - slot->bitmap_top ); /* increment pen position
*/ pen.x +=
slot->advance.x; pen.y +=
slot->advance.y; } show_image(); FT_Done_Face ( face
); FT_Done_FreeType( library
); return 0; } |
[Prev in Thread] | Current Thread | [Next in Thread] |