diff mde/resource/FontTexture.d @ 49:bca7e2342d77

Enabled getting the size of a text block (before or after rendering). committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 31 May 2008 13:10:06 +0100
parents a98ffb64f066
children f68ae1d667f9
line wrap: on
line diff
--- a/mde/resource/FontTexture.d	Sat May 31 12:40:26 2008 +0100
+++ b/mde/resource/FontTexture.d	Sat May 31 13:10:06 2008 +0100
@@ -28,7 +28,6 @@
 
 import Utf = tango.text.convert.Utf;
 import tango.util.log.Log : Log, Logger;
-import tango.io.Stdout;
 
 private Logger logger;
 static this () {
@@ -97,7 +96,7 @@
         
         for (size_t i = 0; i < chrs.length; ++i)
         {
-            // First, get maxmimal yMax for the current line.
+            // First, find yMax for the current line.
             int yMax = 0;	// Maximal glyph height above baseline.
             for (size_t j = i; j < chrs.length; ++j)
             {
@@ -147,6 +146,13 @@
                 x += cc.ga.advanceX;
                 
                 cache.chars ~= cc;
+                
+                // Update rect total size. Top and left coords should be zero, so make width and
+                // height maximal x and y coordinates.
+                if (cc.xPos + cc.ga.w > cache.w)
+                    cache.w = cc.xPos + cc.ga.w;
+                if (cc.yPos + cc.ga.h > cache.h)
+                    cache.h = cc.yPos + cc.ga.h;
             }
             // Now increment i and continue with the next line if there is one.
             y += lineSep - yMax;
@@ -191,7 +197,7 @@
     void addGlyph (FT_Face face, dchar chr) {
         debug scope (failure)
                 logger.warn ("FontTexture.addGlyph failed!");
-        //Stdout ("Adding glyph ")(chr).newline;
+        
         auto gi = FT_Get_Char_Index (face, chr);
         auto g = face.glyph;
         
@@ -214,7 +220,6 @@
         ga.top		= g.bitmap_top;
         ga.advanceX	= g.advance.x >> 6;
         ga.index	= gi;
-        Stdout ("Glyph left is: ")(ga.left).newline;
         
         foreach (ref t; tex) {
             if (t.addGlyph (ga))