Sfoglia il codice sorgente

* Made makefont more configurable. Also, store the commandline in a comment

so that the font can be easily rebuilt.
tags/v0.99.beta14
Sam Hocevar sam 18 anni fa
parent
commit
5d2afb9232
1 ha cambiato i file con 44 aggiunte e 17 eliminazioni
  1. +44
    -17
      tools/makefont.c

+ 44
- 17
tools/makefont.c Vedi File

@@ -23,10 +23,6 @@
#include <pango/pango.h>
#include <pango/pangoft2.h>

#define FONT "Monospace 9"
#define DPI 96
#define BPP 4

static int const blocklist[] =
{
0x0000, 0x0080, /* Basic latin: A, B, C, a, img, c */
@@ -50,7 +46,7 @@ static int printf_hex(char const *, uint8_t *, int);
static int printf_u32(char const *, uint32_t);
static int printf_u16(char const *, uint16_t);

int main(void)
int main(int argc, char *argv[])
{
PangoContext *cx;
PangoFontDescription *fd;
@@ -59,12 +55,31 @@ int main(void)
PangoRectangle r;

FT_Bitmap img;
int width, height, b, i, n, blocks, glyphs, data_bytes;
int width, height, b, i, n, blocks, glyphs;
unsigned int glyph_size, control_size, data_size;
uint8_t *glyph_data;

int bpp = BPP;
int dpi = DPI;
char const *font = FONT;
unsigned int bpp, dpi;
char const *prefix, *font;

if(argc != 5)
{
fprintf(stderr, "%s: wrong argument count\n", argv[0]);
fprintf(stderr, "usage: %s <prefix> <font> <dpi> <bpp>\n", argv[0]);
fprintf(stderr, "eg: %s monospace9 \"Monospace 9\" 96 4\n", argv[0]);
return -1;
}

prefix = argv[1];
font = argv[2];
dpi = atoi(argv[3]);
bpp = atoi(argv[4]);

if(dpi == 0 || (bpp != 1 && bpp != 2 && bpp != 4 && bpp != 8))
{
fprintf(stderr, "%s: invalid argument\n", argv[0]);
return -1;
}

fprintf(stderr, "Font \"%s\", %i dpi, %i bpp\n", font, dpi, bpp);

@@ -76,6 +91,7 @@ int main(void)
l = pango_layout_new(cx);
if(!l)
{
fprintf(stderr, "%s: unable to initialise pango\n", argv[0]);
g_object_unref(cx);
return -1;
}
@@ -97,8 +113,8 @@ int main(void)
pango_layout_get_extents(l, NULL, &r);
width = PANGO_PIXELS(r.width);
height = PANGO_PIXELS(r.height);
data_bytes = ((width * height) + (8 / bpp) - 1) / (8 / bpp);
glyph_data = malloc(data_bytes);
glyph_size = ((width * height) + (8 / bpp) - 1) / (8 / bpp);
glyph_data = malloc(glyph_size);

/* Compute blocks and glyphs count */
blocks = 0;
@@ -109,21 +125,30 @@ int main(void)
glyphs += blocklist[b + 1] - blocklist[b];
}

control_size = 24 + 12 * blocks + 8 * glyphs;
data_size = glyph_size * glyphs;

/* Let's go! */
printf("/* libcucul font file\n");
printf(" * \"%s\": %i dpi, %i bpp, %ix%i glyphs\n",
font, dpi, bpp, width, height);
printf(" * Automatically generated by tools/makefont.c */\n");
printf(" * Automatically generated by tools/makefont.c:\n");
printf(" * tools/makefont %s \"%s\" %i %i\n", prefix, font, dpi, bpp);
printf(" */\n");
printf("\n");

printf("static unsigned int const %s_size = %i;\n",
prefix, 8 + control_size + data_size);
printf("static unsigned char const %s_data[] =\n", prefix);

printf("/* file: */\n");
printf("\"CACA\" /* caca_header */\n");
printf("\"FONT\" /* caca_file_type */\n");
printf("\n");

printf("/* font_header: */\n");
printf_u32("\"%s\" /* header_size */\n", 24 + 12 * blocks + 8 * glyphs);
printf_u32("\"%s\" /* data_size */\n", data_bytes * glyphs);
printf_u32("\"%s\" /* control_size */\n", control_size);
printf_u32("\"%s\" /* data_size */\n", data_size);
printf_u16("\"%s\" /* version */\n", 1);
printf_u16("\"%s\" /* blocks */\n", blocks);
printf_u32("\"%s\" /* glyphs */\n", glyphs);
@@ -152,7 +177,7 @@ int main(void)
{
printf_u16("\"%s", width);
printf_u16("%s", height);
printf_u32("%s\"\n", n * data_bytes);
printf_u32("%s\"\n", n * glyph_size);
n++;
}
}
@@ -204,7 +229,7 @@ int main(void)

/* Render glyph on a bitmap */
pango_layout_set_text(l, buf, -1);
memset(glyph_data, 0, data_bytes);
memset(glyph_data, 0, glyph_size);
memset(img.buffer, 0, img.pitch * height);
pango_ft2_render_layout(&img, l, 0, 0);

@@ -221,10 +246,12 @@ int main(void)
n += bpp;
}
}
printf_hex("\"%s\"\n", glyph_data, data_bytes);
printf_hex("\"%s\"\n", glyph_data, glyph_size);
}
}

printf(";\n");

free(img.buffer);
g_object_unref(l);
g_object_unref(cx);


Caricamento…
Annulla
Salva