typedef struct sImage
{
unsigned w, h;
- char *data;
+ unsigned char *data;
} Image;
typedef struct sGlyph
free(font.glyphs);
free(font.kerning);
free(font.image.data);
+ free(ranges);
FT_Done_Face(face);
FT_Done_FreeType(freetype);
unsigned i, j;
unsigned size = 0;
- font->ascent = (face->size->metrics.ascender+63)>>6;
- font->descent = (face->size->metrics.descender+63)>>6;
+ font->ascent = (face->size->metrics.ascender+63)/64;
+ font->descent = (face->size->metrics.descender-63)/64;
if(verbose>=1)
{
kern = &font->kerning[font->n_kerning++];
kern->left_code = font->glyphs[i].code;
kern->right_code = font->glyphs[j].code;
- kern->distance = kerning.x/64;
+ kern->distance = (kerning.x+32)/64;
}
}
printf(": glyph %u, size %dx%d\n", n, bmp->width, bmp->rows);
}
- if(bmp->pixel_mode!=FT_PIXEL_MODE_GRAY)
+ if(bmp->pixel_mode!=FT_PIXEL_MODE_GRAY && bmp->pixel_mode!=FT_PIXEL_MODE_MONO)
{
- fprintf(stderr, "Warning: Glyph %u skipped, not grayscale\n", n);
+ fprintf(stderr, "Warning: Glyph %u skipped, incompatible pixel mode\n", n);
continue;
}
{
unsigned x, y;
unsigned char *src;
- char *dst;
+ unsigned char *dst;
image->w = bmp->width;
image->h = bmp->rows;
return 0;
}
- image->data = (char *)malloc(image->w*image->h);
+ image->data = (unsigned char *)malloc(image->w*image->h);
if(!image->data)
{
fprintf(stderr, "Cannot allocate %d bytes of memory for glyph\n", image->w*image->h);
for(y=0; y<bmp->rows; ++y)
{
- for(x=0; x<bmp->width; ++x)
- dst[x] = src[x];
+ if(bmp->pixel_mode==FT_PIXEL_MODE_MONO)
+ {
+ for(x=0; x<bmp->width; ++x)
+ dst[x] = ((src[x/8]&(0x80>>(x%8))) ? 0xFF : 0x00);
+ }
+ else
+ {
+ for(x=0; x<bmp->width; ++x)
+ dst[x] = src[x];
+ }
src += bmp->pitch;
dst += image->w;
if(!npot)
font->image.h = round_to_pot(font->image.h);
- font->image.data = (char *)alloc_image_data(font->image.w, font->image.h);
+ font->image.data = (unsigned char *)alloc_image_data(font->image.w, font->image.h);
if(!font->image.data)
return -1;
memset(font->image.data, 255, font->image.w*font->image.h);
glyphs. Since glyphs are rectangular and the image is filled starting from
the top, it's enough to track the number of used pixels at the top of each
column. */
- font->image.data = (char *)alloc_image_data(font->image.w, font->image.h);
+ font->image.data = (unsigned char *)alloc_image_data(font->image.w, font->image.h);
if(!font->image.data)
return -1;
memset(font->image.data, 255, font->image.w*font->image.h);