diff mde/font/font.d @ 85:56c0ddd90193

Intermediate commit (not stable). Changes to init system.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 11 Sep 2008 11:33:51 +0100
parents e0f1ec7fe73a
children 79d816b3e2d2
line wrap: on
line diff
--- a/mde/font/font.d	Sun Aug 31 15:59:17 2008 +0100
+++ b/mde/font/font.d	Thu Sep 11 11:33:51 2008 +0100
@@ -24,6 +24,7 @@
 import mde.file.mergetag.Reader;
 import mde.file.mergetag.DataSet;
 import mde.setup.paths;
+import mde.setup.exception;     // InitStage stuff
 
 import derelict.freetype.ft;
 import derelict.opengl.gl;
@@ -55,9 +56,9 @@
                 fontTex.drawTexture;
         }
         
-        /** Load the freetype library from the file fileName. */
+        /** Load the freetype library with settings from the file fileName. */
         private const fileName = "fonts";
-        void initialize () {
+        StageState initialize () {
             if (FT_Init_FreeType (&library))
                 throw new fontException ("error initialising the FreeType library");
             
@@ -76,7 +77,7 @@
                 /* An error occurred, presumably because LCD rendering support
                 * is not compiled into the library. */
                 logger.warn ("Bad/unsupported LCD filter option; disabling LCD font rendering.");
-                logger.warn ("Your FreeType 2 library may compiled without support for LCD/sub-pixel rendering.");
+                logger.warn ("Your FreeType 2 library may be compiled without support for LCD/sub-pixel rendering.");
                 
                 // Reset the default filter (in case an invalid value was set in config files).
                 fontOpts.set!(int) ("lcdFilter", FT_LcdFilter.FT_LCD_FILTER_DEFAULT);
@@ -122,12 +123,23 @@
             // Load the fallback now, to ensure it's available.
             // Also note that get() doesn't make sure the fallback is loaded before returning it.
             fallback.load;
+            
+            return StageState.ACTIVE;
         }
         
         //FIXME: don't use GC for FontStyle resources
         /** Cleanup: delete all fonts. */
-        void cleanup () {
-            FT_Done_FreeType (library);
+        StageState cleanup () {
+            // Clear loaded fonts:
+            foreach (fs; fonts)
+                delete fs;
+            fonts = null;
+            delete fallback;
+            
+            delete fontTex;     // clear texture
+            FT_Done_FreeType (library); // free the library
+            
+            return StageState.INACTIVE;
         }
         
         /** Get a FontStyle instance, for a section in the fonts.mtt file.
@@ -285,7 +297,9 @@
     }
     
     ~this () {
+        debug logger.trace ("{}.~this: start", this);
         FT_Done_Face (face);
+        debug logger.trace ("{}.~this: done", this);
     }
     
 private: