[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Freetype] text appears clipped on small rasters
From: |
John Hunter |
Subject: |
[Freetype] text appears clipped on small rasters |
Date: |
Tue, 02 Mar 2004 10:19:32 -0600 |
User-agent: |
Gnus/5.090013 (Oort Gnus v0.13) Emacs/21.2 (i686-pc-linux-gnu) |
When I render characters at small raster sizes (eg 80 dpi, 12 point),
the right hand side of the character often appears as if it has been
clipped off. I suspect I am not handling something properly.
Below is code modified from example1.c in the tutorial that
illustrates the problem. When I print the raster for "0" to a string
with show image, I get
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 10 160 240 233 128 0 0 0 0
0 149 191 13 28 221 98 0 0 0
4 243 68 0 0 112 197 0 0 0
37 255 21 0 0 66 243 0 0 0
49 255 10 0 0 54 255 1 0 0
37 255 21 0 0 66 243 0 0 0
4 243 67 0 0 112 198 0 0 0
0 150 189 13 28 221 98 0 0 0
0 10 161 240 234 129 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
^
raster appears clipped here
I ran this code with Vera.ttf.
Any advice?
Thanks,
John Hunter
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#define WIDTH 10
#define HEIGHT 13
/* origin is the upper left corner */
unsigned char image[HEIGHT][WIDTH];
/* 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++ ) {
printf("%3u ",image[i][j]);
//putchar(image[i][j]);
}
printf("\n");
}
}
int
main( int argc,
char** argv )
{
FT_Library library;
FT_Face face;
FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_UInt glyph_index;
FT_Vector pen; /* untransformed origin */
FT_Error error;
char* filename;
char* text;
int target_height;
int n, num_chars;
filename = argv[1]; /* first argument */
text = "0"; /* second argument */
num_chars = strlen( text );
target_height = HEIGHT;
error = FT_Init_FreeType( &library ); /* initialize library */
/* error handling omitted */
error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
/* error handling omitted */
/* use 50pt at 100dpi */
error = FT_Set_Char_Size( face, 12 * 64, 0,
80, 0 ); /* set character size */
/* error handling omitted */
slot = face->glyph;
/* the pen position in 26.6 cartesian space coordinates; */
/* start at (300,200) relative to the upper left corner */
pen.x = 0;
pen.y = 0;
for ( n = 0; n < num_chars; n++ )
{
/* set transformation */
FT_Set_Transform( face, 0, &pen );
/* load glyph image into the slot (erase previous one) */
error = FT_Load_Char( face, text[n], FT_LOAD_RENDER );
if ( error )
continue; /* ignore errors */
/* now, draw to our target surface (convert position) */
draw_bitmap( &slot->bitmap,
slot->bitmap_left,
target_height-2 - 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;
}
/* EOF */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freetype] text appears clipped on small rasters,
John Hunter <=