[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Freetype] Problems rendering glyphs from .FON files
From: |
Wesley Leong |
Subject: |
[Freetype] Problems rendering glyphs from .FON files |
Date: |
Sun, 29 Jun 2003 19:18:01 -0700 |
I am doing some development work with .FON fixed fonts on Linux (RH9, but I
am using freetype 2 from source, not from RPM package). I am having some
problems with the font rendering with freetype 2. The fonts appear ok with
freetype 2.0.9, but with 2.1.4, the glyph renderings come out scrambled.
The scambled rendering has a pattern where the first byte is rendered
correctly (using mono mode rendering), but the next byte of data is the row
of pixels below the previous byte of data instead to the right of it. I
tried downloading the latest version in CVS and that one scrambles the
renderings differently and hands back the wrong pitch size. Is this a known
problem with .FON support?
I also noticed that all renderings with .FON formatted fonts are
automatically done in 1 bit bitmap format, even when I set the rendering
mode to FT_RENDER_MODE_NORMAL. The documentation says I should get an 8-bit
per pixel bitmap when using that optional flag. This seems to happen with
all versions of freetype 2 I have used so far. Is there anyway I can get
freetype 2 to render in 256 gray shade (I want the pixel depth to be 8 bit
even if only black and white values of 0 and 255 are used)?
I have none of these problems when using true type fonts. Here's some
sample code that demonstrates the problem:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ft2build.h>
#include FT_FREETYPE_H
int main (int argc, char** argv) {
FT_Library library;
FT_Face face;
if ( argc < 4 ) {
fprintf (stderr, "Usage: %s [letter] [size] [TTF or .FON]\n", argv[0]);
exit(1);
}
int error = FT_Init_FreeType( &library );
if( error ) {
fprintf( stderr, "Error in initializing FreeType library.\n" );
exit(1);
}
error = FT_New_Face( library,
argv[3],
0,
&face );
if( error == FT_Err_Unknown_File_Format ) {
fprintf( stderr, "Unknown font format\n" );
exit(1);
} else if( error ) {
fprintf( stderr, "Random error trying to load font file\n");
exit(1);
}
int ptsize = atoi( argv[2] );
/*error = FT_Set_Char_Size( face, 0, atoi(argv[2]) * 64, 72, 72 );*/
if ( !FT_IS_SCALABLE ( face ) ) {
if ( ptsize >= face->num_fixed_sizes )
ptsize = face->num_fixed_sizes - 1;
error = FT_Set_Pixel_Sizes(
face,
face->available_sizes[ptsize].width,
face->available_sizes[ptsize].height
);
} else {
error = FT_Set_Pixel_Sizes( face, 0, ptsize);
}
if (error) {
fprintf( stderr, " Cannot set pixel size\n");
}
char charcode = (char) argv[1][0];
FT_UInt glyph_index = FT_Get_Char_Index( face, charcode );
FT_GlyphSlot slot = face->glyph;
error = FT_Load_Glyph(
face,
glyph_index,
FT_LOAD_DEFAULT );
if( error ) {
fprintf ( stderr,"Error in load glyph.\n" );
exit(1);
}
error = FT_Render_Glyph( slot,
FT_RENDER_MODE_NORMAL);
/*0); // Use this one with v2.0.9*/
FT_Glyph_Metrics* metrics = & (slot->metrics);
fprintf( stderr,
"W:%d H:%d\nHBX:%d HBY:%d HA:%d\nVBX:%d VBY:%d VA:%d\n",
metrics->width,
metrics->height,
metrics->horiBearingX,
metrics->horiBearingY,
metrics->horiAdvance,
metrics->vertBearingX,
metrics->vertBearingY,
metrics->vertAdvance
);
FT_Bitmap* bitmap = &(slot->bitmap);
unsigned char* buffer = bitmap->buffer;
fprintf(stderr, "PRINTING: %d %d %d\n",
bitmap->rows, bitmap->width, bitmap->pitch);
int i = 0;
int j = 0;
int k = 0;
/* Quckly render to console just to see what a glyph looks like */
if ( ! FT_IS_SCALABLE (face) ) {
for (i=0; i < bitmap->rows; i++) {
int offset = bitmap->pitch * i;
unsigned char ch;
unsigned char *rowbyte = bitmap->buffer + offset;
for (j=0; j < bitmap->width; j += 8) {
ch = *rowbyte++;
for (k = 0; k < 8; ++k) {
if ((ch&0x80) >> 7) {
printf("0");
} else {
printf(".");
}
ch <<= 1;
}
}
printf("\n");
}
} else {
for (i=0; i < bitmap->rows; i++) {
for (j=0; j < (abs(bitmap->pitch)); j++) {
if ( buffer[(i * (abs(bitmap->pitch))) + j]== 0 ) {
printf(".");
} else {
printf("O");
}
}
printf("\n");
}
}
}
Thanks,
Wesley
_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freetype] Problems rendering glyphs from .FON files,
Wesley Leong <=