Browse Source

* when cutting fonts, detect black pixels below 240, not below 128

* allow last column to be non-white
  * better error message when all glyphs


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/pwntcha/trunk@451 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 20 years ago
parent
commit
47b2c48535
1 changed files with 15 additions and 10 deletions
  1. +15
    -10
      src/font.c

+ 15
- 10
src/font.c View File

@@ -71,18 +71,22 @@ struct font *font_load_variable(char *file, char *chars)
font->size = strlen(chars); font->size = strlen(chars);
font->glyphs = malloc(font->size * sizeof(struct glyph)); font->glyphs = malloc(font->size * sizeof(struct glyph));


for(x = 0, i = 0, xmin = 0; x < font->img->width && i < font->size; x++)
for(x = 0, i = 0, xmin = 0; x <= font->img->width && i < font->size; x++)
{ {
int found = 0; int found = 0;
for(y = 0; y < font->img->height; y++)
{
getpixel(font->img, x, y, &r, &g, &b);
if(r < 128)
if(x != font->img->width)
for(y = 0; y < font->img->height; y++)
{ {
found = 1;
count += (255 - r);
getpixel(font->img, x, y, &r, &g, &b);
if(r < 240)
{
found = 1;
count += (255 - r);
}
} }
}
else
found = 0;

if(found && !incell) if(found && !incell)
{ {
incell = 1; incell = 1;
@@ -102,7 +106,7 @@ struct font *font_load_variable(char *file, char *chars)
for(newx = xmin; newx < xmax; newx++) for(newx = xmin; newx < xmax; newx++)
{ {
getpixel(font->img, newx, y, &r, &g, &b); getpixel(font->img, newx, y, &r, &g, &b);
if(r < 128)
if(r < 240)
{ {
gotit = 1; gotit = 1;
break; break;
@@ -131,7 +135,8 @@ struct font *font_load_variable(char *file, char *chars)


if(i != font->size) if(i != font->size)
{ {
printf("%s: could not find %i glyphs in font\n", argv0, font->size);
fprintf(stderr, "%s: could only find %i of %i glyphs in font %s\n",
argv0, i, font->size, file);
image_free(font->img); image_free(font->img);
free(font->glyphs); free(font->glyphs);
free(font); free(font);


Loading…
Cancel
Save