diff mde/font/font.d @ 89:97e6dce08037

Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 29 Sep 2008 18:27:17 +0100
parents 79d816b3e2d2
children 30470bc19ca4
line wrap: on
line diff
--- a/mde/font/font.d	Mon Sep 29 12:09:44 2008 +0100
+++ b/mde/font/font.d	Mon Sep 29 18:27:17 2008 +0100
@@ -127,12 +127,11 @@
             return StageState.ACTIVE;
         }
         
-        //FIXME: don't use GC for FontStyle resources
         /** Cleanup: delete all fonts. */
         StageState cleanup () {
             // Clear loaded fonts (each has an FT_Face object needing to be freed):
             foreach (fs; fonts)
-                delete fs;
+                fs.freeFace;
             
             FT_Done_FreeType (library); // free the library
             
@@ -237,11 +236,11 @@
     /** Draw a block of text (may inlcude new-lines).
      *
      * The text block is drawn with top-left corner at x,y. To put the text's baseline at a given
-     * y coordinate would require some changes. Line height is currently variable, depending on the
-     * highest glyph in the line (should probably be fixed: FIXME).
+     * y coordinate would require some changes. Line height is fixed based on largest glyph.
+     * Due to hinter, glyphs are not guaranteed to lie within the "bounding box" defined by cache.
+     * Can be changed to test size of each glyph if necessary.
      *
-     * Specify the text's colour with col; currently this is only Colour.WHITE or Colour.BLACK
-     * (FIXME). FIXME: add alpha support.
+     * Specify the text's colour with col. Use textBlockA() instead  for transparent text.
      *
      * As a CPU-side code optimisation, store a TextBlock (unique to str) and pass a reference as
      * the cache argument. This is the recommended method, although for one-time calls when you
@@ -261,7 +260,7 @@
      * the updateBlock function. */
     void textBlock (int x, int y, char[] str, ref TextBlock cache, Colour col)
     in {
-        debug assert (face, "FontStyle: face is null");
+        assert (face, "FontStyle: face is null");
     } body {
         try {
             fontTex.drawCache (face, str, cache, x, y, col);
@@ -272,7 +271,7 @@
     /** ditto */
     void textBlock (int x, int y, char[] str, Colour col)
     in {
-        debug assert (face, "FontStyle: face is null");
+        assert (face, "FontStyle: face is null");
     } body {
         try {
             // Using the cache method for one-time use is slightly less than optimal, but doing so
@@ -291,7 +290,7 @@
      * details. */
     void textBlockA (int x, int y, char[] str, ref TextBlock cache, Colour col) 
     in {
-        debug assert (face, "FontStyle: face is null");
+        assert (face, "FontStyle: face is null");
     } body {
         try {
             fontTex.drawCacheA (face, str, cache, x, y, col);
@@ -301,12 +300,16 @@
     }
     
     /** The font-specified vertical distance between the baseline of consecutive lines. */
-    int getLineSeparation () {
+    int getLineSeparation ()
+    in {
+        assert (face, "FontStyle: face is null");
+    } body {
         return face.size.metrics.height >> 6;
     }
     
-    ~this () {
+    void freeFace () {
         FT_Done_Face (face);
+        face = null;    // functions using face use assertions on face to check its validity.
     }
     
 private: