* The property already exists in the font, so simply replace
* the value of the property with the current value.
*/
- fp = font->props + (unsigned int) hn->data;
+ fp = font->props + (long) hn->data;
switch (fp->format) {
case BDF_ATOM:
font->props_size++;
}
- propid = (unsigned int) hn->data;
+ propid = (long) hn->data;
if (propid >= _num_bdf_properties)
prop = user_props + (propid - _num_bdf_properties);
else
unsigned char *bp;
unsigned int i, slen = 0, nibbles;
double ps, rx, dw, sw;
- _bdf_line_func_t *next;
+ /*_bdf_line_func_t *next;*/
_bdf_parse_t *p;
bdf_glyph_t *glyph;
bdf_font_t *font;
char nbuf[128];
- next = (_bdf_line_func_t *) call_data;
+ /*next = (_bdf_line_func_t *) call_data;*/
p = (_bdf_parse_t *) client_data;
font = p->font;
void
bdf_setup(void)
{
- unsigned int i;
+ long i;
bdf_property_t *prop;
hash_init(&proptbl);
unsigned int vlen = 0;
char *name, *value;
_bdf_parse_t *p;
- _bdf_line_func_t *next;
+ /*_bdf_line_func_t *next;*/
char nbuf[24];
- next = (_bdf_line_func_t *) call_data;
+ /*next = (_bdf_line_func_t *) call_data;*/
p = (_bdf_parse_t *) client_data;
/*
bdf_load_hbf_font(char *filename, bdf_options_t *opts, bdf_callback_t callback,
void *data)
{
- int n, diff;
+ int /*n,*/ diff;
unsigned int lineno;
FILE *in;
HBF *hbf;
p.callback = callback;
p.client_data = data;
- n = _bdf_readlines(fileno(in), _bdf_parse_hbf_header, (void *) &p,
+ /*n = */_bdf_readlines(fileno(in), _bdf_parse_hbf_header, (void *) &p,
&lineno);
fclose(in);
}
}
+static const unsigned char lookup[16] = {
+ 0x0, 0x8, 0x4, 0xC,
+ 0x2, 0xA, 0x6, 0xE,
+ 0x1, 0x9, 0x5, 0xD,
+ 0x3, 0xB, 0x7, 0xF };
+
+static unsigned char byte_flip( const unsigned char n )
+{
+ return (lookup[n&0x0F] << 4) | lookup[n>>4];
+}
+
+void
+bdf_export_header(FILE *out, bdf_font_t *font, bdf_options_t *opts,
+ bdf_callback_t callback, void *data)
+{
+ int bpr, fbpr, j, k;
+ unsigned int i, ng;
+ bdf_glyph_t *gp, cell;
+ bdf_callback_struct_t cb;
+ bdf_property_t *fprop;
+ char fname[32], weightname[32];
+
+ if (font == 0 || out == 0)
+ return;
+
+ if (font->glyphs_used == 0)
+ return;
+
+ /*
+ * Call the callback if it was passed to start the export.
+ */
+ if (callback != 0) {
+ cb.reason = BDF_EXPORT_START;
+ cb.total = font->glyphs_used;
+ cb.current = 0;
+ (*callback)(&cb, data);
+ }
+
+ fbpr = ((font->bbx.width * font->bpp) + 7) >> 3;
+ bpr = (((font->bbx.width >> 1) * font->bpp) + 7) >> 3;
+ cell.bytes = fbpr * font->bbx.height;
+ cell.bitmap = (unsigned char *) malloc(cell.bytes);
+
+ fprop = bdf_get_font_property(font, "FAMILY_NAME");
+/*
+ if (fprop != NULL && fprop->format == BDF_ATOM)
+ fprintf(out, "fontname %s ", fprop->value.atom);
+*/
+ if (fprop != NULL && fprop->format == BDF_ATOM)
+ strncpy(fname, fprop->value.atom, 32);
+ else
+ strncpy(fname, "NoName", 32);
+
+ fprop = bdf_get_font_property(font, "WEIGHT_NAME");
+ if (fprop != NULL && fprop->format == BDF_ATOM)
+ strncpy(weightname, fprop->value.atom, 32);
+ else
+ strncpy(weightname, "none", 32);
+
+ fprintf(out, "/* %s */\n", font->name);
+ fprintf(out, "#define FONT_WIDTH_%s%s_%dx%d\t%d\n", fname, weightname, font->bbx.width, font->bbx.height, font->bbx.width);
+ fprintf(out, "#define FONT_HEIGHT_%s%s_%dx%d\t%d\n", fname, weightname, font->bbx.width, font->bbx.height, font->bbx.height);
+
+ fprintf(out, "const uint8_t FONT_DATA_%s%s_%dx%d[%d][%d] = {\n", fname, weightname, font->bbx.width, font->bbx.height, font->glyphs_used, cell.bytes + ((font->spacing == BDF_PROPORTIONAL) ? 1 : 0));
+
+ for (i = 0, ng = font->glyphs_used, gp = font->glyphs; i < ng; i++, gp++) {
+ _bdf_pad_cell(font, gp, &cell);
+/*
+ fprintf(out, "%dx%d ", gp->bbx.width, gp->bbx.height);
+ fprintf(out, "%04X:", gp->encoding & 0xffff);
+*/
+ if (font->spacing == BDF_PROPORTIONAL) {
+ fprintf(out, "{/*w*/%d,",gp->dwidth /*gp->bbx.width*/);
+ } else
+ fprintf(out, "{");
+/*
+ if (gp->bbx.width <= (font->bbx.width >> 1)) {
+ for (j = 0; j < cell.bytes; j += fbpr) {
+ for (k = 0; k < bpr; k++)
+ fprintf(out, "a0x%02x,", cell.bitmap[j + k]);
+ }
+ } else*/ {
+ for (j = 0; j < cell.bytes; j++)
+ fprintf(out, "0x%02x,", byte_flip(cell.bitmap[j]));
+ }
+ if (cell.bytes > 0)
+ fprintf(out, "},\n");
+
+ /*
+ * Call the callback if supplied.
+ */
+ if (callback != 0) {
+ cb.reason = BDF_EXPORTING;
+ cb.current++;
+ (*callback)(&cb, data);
+ }
+ }
+ fprintf(out, "};\n");
+
+ /*
+ * Clean up the cell.
+ */
+ free((char *) cell.bitmap);
+
+ /*
+ * Always call a final callback to make sure the client gets a chance to
+ * clean things up.
+ */
+ if (callback != 0) {
+ cb.reason = BDF_EXPORTING;
+ cb.current = cb.total;
+ (*callback)(&cb, data);
+ }
+}
+
void
bdf_free_font(bdf_font_t *font)
{
void
bdf_create_property(char *name, int format)
{
- unsigned int n;
+ long n;
bdf_property_t *p;
/*
if ((hn = hash_lookup(name, &proptbl)) == 0)
return 0;
- propid = (unsigned int) hn->data;
+ propid = (long) hn->data;
if (propid >= _num_bdf_properties)
return user_props + (propid - _num_bdf_properties);
return _bdf_properties + propid;
* If the property exists and is a user defined property, make sure
* its format is updated to match the property being added.
*/
- propid = (unsigned int) hn->data;
+ propid = (long) hn->data;
if (propid >= _num_bdf_properties) {
p = user_props + (propid - _num_bdf_properties);
if (p->format != property->format)
/*
* Changing an existing property value.
*/
- p = font->props + ((unsigned int) hn->data);
+ p = font->props + ((long) hn->data);
/*
* If the format changed, then free the atom value if the original
* name of the property.
*/
hn = hash_lookup(property->name, &proptbl);
- propid = (unsigned int) hn->data;
+ propid = (long) hn->data;
if (propid >= _num_bdf_properties)
ip = user_props + (propid - _num_bdf_properties);
else
bdf_delete_font_property(bdf_font_t *font, char *name)
{
hashnode hn;
- unsigned int off;
+ long off;
bdf_property_t *p;
if (font == 0 || name == 0 || *name == 0 || font->props_used == 0)
if ((hn = hash_lookup(name, (hashtable *) font->internal)) == 0)
return;
- off = (unsigned int) hn->data;
+ off = (long) hn->data;
p = font->props + off;
/*
return 0;
hn = hash_lookup(name, (hashtable *) font->internal);
- return (hn) ? (font->props + ((unsigned int) hn->data)) : 0;
+ return (hn) ? (font->props + ((long) hn->data)) : 0;
}
typedef struct {
{
int i;
unsigned short bpr, sbpr, bytes, si, byte, sx, sy;
- unsigned char *nbmap, *masks;
+ unsigned char *nbmap /*, *masks*/;
bdf_glyph_t *gp;
if (gl == 0 || gl->glyphs_used == 0)
return;
- masks = bdf_fourbpp;
+ /*masks = bdf_fourbpp;*/
gl->bpp = 2;
for (gp = gl->glyphs, i = 0; i < gl->glyphs_used; i++, gp++) {
{
int i;
unsigned short bpr, sbpr, bytes, col, si, byte, sx, sy;
- unsigned char *nbmap, *masks;
+ unsigned char *nbmap/*, *masks*/;
bdf_glyph_t *gp;
if (gl == 0 || gl->glyphs_used == 0)
return;
- masks = bdf_twobpp;
+ /*masks = bdf_twobpp;*/
for (gp = gl->glyphs, i = 0; i < gl->glyphs_used; i++, gp++) {
if (gp->bbx.width == 0 || gp->bbx.height == 0)