[AD] Destroying fonts

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi,

Although generally fonts are only destroyed in the datafile unloading
routines, there are cases where users may want to dynamically unload
them (eg. if using an addon which supports dynamic loading/creation of
fonts).

It would be nice to let the user call destroy_font() for any type of
font, generated from wherever, but currently destroy_font() only
understands fonts when each member of glyphs points at either a bitmap
or a single block of memory.

To this end, here is a patch which adds this support. Its implementation
is trivial, since we only allocate FONT structures in three routines,
each of which deals with loading a FONT from a datafile.

diff -ru c:/home/cvs/allegro/include/allegro.h ./allegro/include/allegro.h
--- c:/home/cvs/allegro/include/allegro.h	Wed Aug 16 23:27:26 2000
+++ ./allegro/include/allegro.h	Sat Aug 26 05:29:54 2000
@@ -1319,6 +1319,7 @@
    AL_METHOD(void, renderhook, (BITMAP *bmp, void *glyphs, int ch, int x, int y, int color));
    AL_METHOD(int, widthhook, (void *glyphs, int ch));
    AL_METHOD(int, heighthook, (void *glyphs));
+   AL_METHOD(void, destroyhook, (void *glyphs));
 } FONT;
 
 
diff -ru c:/home/cvs/allegro/src/datafile.c ./allegro/src/datafile.c
--- c:/home/cvs/allegro/src/datafile.c	Mon Jul 31 22:01:38 2000
+++ ./allegro/src/datafile.c	Sat Aug 26 05:31:40 2000
@@ -437,6 +437,7 @@
    p->renderhook = NULL;
    p->widthhook = NULL;
    p->heighthook = NULL;
+   p->destroyhook = NULL;
 
    p->glyphs = malloc(maxchars*sizeof(void *));
    if (!p->glyphs) {
@@ -491,6 +492,7 @@
    p->renderhook = NULL;
    p->widthhook = NULL;
    p->heighthook = NULL;
+   p->destroyhook = NULL;
 
    p->glyphs = malloc(maxchars*sizeof(void *));
    if (!p->glyphs) {
@@ -555,6 +557,7 @@
       p->renderhook = NULL;
       p->widthhook = NULL;
       p->heighthook = NULL;
+      p->destroyhook = NULL;
 
       if (last_p)
 	 last_p->next = p;
diff -ru c:/home/cvs/allegro/src/text.c ./allegro/src/text.c
--- c:/home/cvs/allegro/src/text.c	Mon Jul 31 22:02:28 2000
+++ ./allegro/src/text.c	Sat Aug 26 05:30:42 2000
@@ -353,6 +353,8 @@
 
    while (f) {
       if (f->glyphs) {
+        if(f->destroyhook) f->destroyhook(f->glyphs);
+        else {
 	 for (c=0; c<=f->end-f->start; c++) {
 	    if (f->glyphs[c]) {
 	       if (f->mono)
@@ -361,6 +363,7 @@
 		  destroy_bitmap(f->glyphs[c]);
 	    }
 	 }
+	 }
 
 	 free(f->glyphs);
       }
Somebody will have to fix the indentation in destroy_font(), since I
don't understand it :-)

Bye for now,
-- 
Laurence Withers, lwithers@xxxxxxxxxx
                http://www.lwithers.demon.co.uk/

Attachment: signature.asc
Description: PGP signature



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/