# HG changeset patch # User Diggory Hardy # Date 1212235806 -3600 # Node ID bca7e2342d779961646907d6ffbcf73245b7d943 # Parent a98ffb64f066bcc4d43da717f320a6748ffbd6ec Enabled getting the size of a text block (before or after rendering). committer: Diggory Hardy diff -r a98ffb64f066 -r bca7e2342d77 codeDoc/jobs.txt --- a/codeDoc/jobs.txt Sat May 31 12:40:26 2008 +0100 +++ b/codeDoc/jobs.txt Sat May 31 13:10:06 2008 +0100 @@ -51,7 +51,4 @@ Done (for git log message): -Implemented font rendering (grayscale only; i.e. non-LCD). -FontTexture creates a texture and caches glyphs. -Font supports multiple styles/faces, loaded from config file (should probably be loaded via Options instead). -TextBlock cache for glyph placement within a string. \ No newline at end of file +Enabled getting the size of a text block (before or after rendering). \ No newline at end of file diff -r a98ffb64f066 -r bca7e2342d77 mde/gl/draw.d --- a/mde/gl/draw.d Sat May 31 12:40:26 2008 +0100 +++ b/mde/gl/draw.d Sat May 31 13:10:06 2008 +0100 @@ -38,7 +38,7 @@ glClear(GL_COLOR_BUFFER_BIT); gui.draw (); - FontStyle.drawTexture; + debug FontStyle.drawTexture; GLenum err = glGetError(); if (err != GL_NO_ERROR) { diff -r a98ffb64f066 -r bca7e2342d77 mde/gui/widget/miscWidgets.d --- a/mde/gui/widget/miscWidgets.d Sat May 31 12:40:26 2008 +0100 +++ b/mde/gui/widget/miscWidgets.d Sat May 31 13:10:06 2008 +0100 @@ -107,19 +107,20 @@ { this (IWindow wind, int[] data) { if (data.length != 1) throw new WidgetDataException; - mw = 100; //FIXME: set properly - mh = 50; + if (font is null) font = FontStyle.get("default"); + font.updateBlock (str, textCache); + mw = textCache.w; + mh = textCache.h; super (wind,data); } void draw () { super.draw(); - if (font is null) font = FontStyle.get("default"); - font.textBlock (x,y, "|−|−| .,.,.", textCache); // test new-lines and unicode characters - //old string: "Text Widget\nαβγ − ΑΒΓ" + font.textBlock (x,y, str, textCache); // test new-lines and unicode characters } protected: + const str = "Text Widget\nαβγ − ΑΒΓ"; TextBlock textCache; static FontStyle font; } diff -r a98ffb64f066 -r bca7e2342d77 mde/resource/FontTexture.d --- 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)) diff -r a98ffb64f066 -r bca7e2342d77 mde/resource/font.d --- a/mde/resource/font.d Sat May 31 12:40:26 2008 +0100 +++ b/mde/resource/font.d Sat May 31 13:10:06 2008 +0100 @@ -204,6 +204,10 @@ /** 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. + * * 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 * don't need to know the size, the other version of textBlock may be used. diff -r a98ffb64f066 -r bca7e2342d77 mde/scheduler/init2.d --- a/mde/scheduler/init2.d Sat May 31 12:40:26 2008 +0100 +++ b/mde/scheduler/init2.d Sat May 31 13:10:06 2008 +0100 @@ -25,6 +25,8 @@ * * Currently some external modules depend on InitFunctions, while some are set up from here. Once * all are set up from here, the Init* modules can be rearranged. */ +/* Idea: go back to init being controlled from elsewhere. Add a function to wait for another init + * function to complete (threaded; might need to be done differently for non-threaded). */ module mde.scheduler.init2; import mde.scheduler.initFunctions; @@ -45,11 +47,11 @@ init.addFunc (&initInput, "initInput"); init.addFunc (&guiLoad, "guiLoad"); - init.addFunc (&initFreeType, "initFreeType"); } void guiLoad () { // init func try { + font.FontStyle.initialize; gui.load (GUI); cleanup.addFunc (&guiSave, "guiSave"); } catch (Exception e) { @@ -84,15 +86,6 @@ } } -void initFreeType () { // init func - try { - font.FontStyle.initialize; - } catch (Exception e) { - logger.fatal ("initFreeType failed: " ~ e.msg); - setInitFailure; - } -} - /+ Potential wrapper function: // Template to call function, catching exceptions: void wrap(alias Func) () {