]> git.karo-electronics.de Git - gbdfed.git/blobdiff - bdf.c
Fixup several compile faults due to changes in recent distributions,
[gbdfed.git] / bdf.c
diff --git a/bdf.c b/bdf.c
index cf0e9a75a6d309441c10bdd76568876964aa07b6..565cc856b6214220cedd7ff1b110660a7d6cf56d 100644 (file)
--- a/bdf.c
+++ b/bdf.c
@@ -1097,7 +1097,7 @@ _bdf_add_property(bdf_font_t *font, char *name, char *value)
          * 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:
@@ -1151,7 +1151,7 @@ _bdf_add_property(bdf_font_t *font, char *name, char *value)
         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
@@ -1230,13 +1230,13 @@ _bdf_parse_glyphs(char *line, unsigned int linelen, unsigned int lineno,
     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;
@@ -1876,7 +1876,7 @@ _bdf_parse_start(char *line, unsigned int linelen, unsigned int lineno,
 void
 bdf_setup(void)
 {
-    unsigned int i;
+    long i;
     bdf_property_t *prop;
 
     hash_init(&proptbl);
@@ -2064,10 +2064,10 @@ _bdf_parse_hbf_header(char *line, unsigned int linelen, unsigned int lineno,
     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;
 
     /*
@@ -2368,7 +2368,7 @@ bdf_font_t *
 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;
@@ -2393,7 +2393,7 @@ bdf_load_hbf_font(char *filename, bdf_options_t *opts, bdf_callback_t callback,
     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);
@@ -3111,6 +3111,121 @@ bdf_export_hex(FILE *out, bdf_font_t *font, bdf_options_t *opts,
     }
 }
 
+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)
 {
@@ -3199,7 +3314,7 @@ bdf_free_font(bdf_font_t *font)
 void
 bdf_create_property(char *name, int format)
 {
-    unsigned int n;
+    long n;
     bdf_property_t *p;
 
     /*
@@ -3244,7 +3359,7 @@ bdf_get_property(char *name)
     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;
@@ -3353,7 +3468,7 @@ bdf_add_font_property(bdf_font_t *font, bdf_property_t *property)
          * 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)
@@ -3369,7 +3484,7 @@ bdf_add_font_property(bdf_font_t *font, bdf_property_t *property)
         /*
          * 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
@@ -3426,7 +3541,7 @@ bdf_add_font_property(bdf_font_t *font, bdf_property_t *property)
          * 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
@@ -3545,7 +3660,7 @@ void
 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)
@@ -3554,7 +3669,7 @@ bdf_delete_font_property(bdf_font_t *font, char *name)
     if ((hn = hash_lookup(name, (hashtable *) font->internal)) == 0)
       return;
 
-    off = (unsigned int) hn->data;
+    off = (long) hn->data;
     p = font->props + off;
 
     /*
@@ -3609,7 +3724,7 @@ bdf_get_font_property(bdf_font_t *font, char *name)
       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 {
@@ -4721,13 +4836,13 @@ _bdf_eight_to_two(bdf_glyphlist_t *gl)
 {
     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++) {
@@ -4806,13 +4921,13 @@ _bdf_eight_to_four(bdf_glyphlist_t *gl)
 {
     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)