diff mde/font/font.d @ 86:79d816b3e2d2

New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries. This (and the previous) commit are the result of several quite significant changes to mde. All the unittests run, but it hasn't had a huge amount of testing so don't be surprised if bugs show up.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 12 Sep 2008 17:36:14 +0100
parents 56c0ddd90193
children 97e6dce08037
line wrap: on
line diff
--- a/mde/font/font.d	Thu Sep 11 11:33:51 2008 +0100
+++ b/mde/font/font.d	Fri Sep 12 17:36:14 2008 +0100
@@ -130,13 +130,10 @@
         //FIXME: don't use GC for FontStyle resources
         /** Cleanup: delete all fonts. */
         StageState cleanup () {
-            // Clear loaded fonts:
+            // Clear loaded fonts (each has an FT_Face object needing to be freed):
             foreach (fs; fonts)
                 delete fs;
-            fonts = null;
-            delete fallback;
             
-            delete fontTex;     // clear texture
             FT_Done_FreeType (library); // free the library
             
             return StageState.INACTIVE;
@@ -226,7 +223,10 @@
      *
      * This function will only actually update the cache if it is invalid, caused either by the
      * font being changed or if cache.cacheVer < 0. */
-    void updateBlock (char[] str, ref TextBlock cache) {
+    void updateBlock (char[] str, ref TextBlock cache)
+    in {
+        debug assert (face, "FontStyle: face is null");
+    } body {
         try {
             fontTex.updateCache (face, str, cache);
         } catch (Exception e) {
@@ -259,7 +259,10 @@
      * than this cache only serves as a small optimisation. However, the only way to get the size
      * of a text block is to use a TextBlock cache and update it, either with this function or with
      * the updateBlock function. */
-    void textBlock (int x, int y, char[] str, ref TextBlock cache, Colour col) {
+    void textBlock (int x, int y, char[] str, ref TextBlock cache, Colour col)
+    in {
+        debug assert (face, "FontStyle: face is null");
+    } body {
         try {
             fontTex.drawCache (face, str, cache, x, y, col);
         } catch (Exception e) {
@@ -267,7 +270,10 @@
         }
     }
     /** ditto */
-    void textBlock (int x, int y, char[] str, Colour col) {
+    void textBlock (int x, int y, char[] str, Colour col)
+    in {
+        debug assert (face, "FontStyle: face is null");
+    } body {
         try {
             // Using the cache method for one-time use is slightly less than optimal, but doing so
             // isn't really recommended anyway (and maintaining two versions of fontTex.drawText
@@ -283,7 +289,10 @@
      *
      * Set the alpha by calling glColor*() first. See FontTexture.drawCacheA()'s documentation for
      * details. */
-    void textBlockA (int x, int y, char[] str, ref TextBlock cache, Colour col) {
+    void textBlockA (int x, int y, char[] str, ref TextBlock cache, Colour col) 
+    in {
+        debug assert (face, "FontStyle: face is null");
+    } body {
         try {
             fontTex.drawCacheA (face, str, cache, x, y, col);
         } catch (Exception e) {
@@ -297,9 +306,7 @@
     }
     
     ~this () {
-        debug logger.trace ("{}.~this: start", this);
         FT_Done_Face (face);
-        debug logger.trace ("{}.~this: done", this);
     }
     
 private: