Mercurial > projects > mde
annotate mde/font/font.d @ 137:9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Content restrutured a lot:
New IContent module, Content module includes more functionality.
New ContentLoader module to manage content loading/saving/translation.
Translation module moved to content dir and cut down to reflect current usage.
File format unchanged except renames: FontOptions -> Font, VideoOptions -> Screen.
Font render mode and LCD filter options are now enums.
GUI loading needs to create content (and set type for enums), but doesn't save/load value.
Some setup of mainSchedule moved to mde.mainLoop.
Content callbacks are called on content change now.
ContentLists are set up implicitly from content symbols. Not as fast but much easier!
Bug-fix in the new MTTagReader.
Renamed MT *Reader maker functions to avoid confusion in paths.d.
New mde.setup.logger module to allow logger setup before any other module's static this().
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 07 Feb 2009 12:46:03 +0000 |
parents | 7ababdf97748 |
children |
rev | line source |
---|---|
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /// Sets up freetype (in a basic way). |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
17 module mde.font.font; |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
18 |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
19 public import mde.types.Colour; |
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
20 import mde.font.FontTexture; |
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
21 import mde.font.exception; |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
23 import mde.setup.exception; // InitStage stuff |
134
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
101
diff
changeset
|
24 import mde.file.paths; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
25 |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
26 import derelict.freetype.ft; |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
27 |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
28 import tango.stdc.stringz; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
29 import Util = tango.text.Util; |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
30 import tango.util.log.Log : Log, Logger; |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
32 // "Publically import" this symbol: |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
33 alias mde.font.FontTexture.TextBlock TextBlock; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
34 |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
35 private Logger logger; |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 static this () { |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
37 logger = Log.getLogger ("mde.font.font"); |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
38 } |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
39 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
40 /** FontStyle class. |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 * |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
42 * Particular to a font and size, and any other effects like bold/italic if ever implemented. |
45
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
43 * |
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
44 * Note: it is not currently intended to be thread-safe. */ |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
45 class FontStyle |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
46 { |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
47 //BEGIN Static: manager |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
48 static { |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
57
diff
changeset
|
49 debug (drawGlyphCache) void drawTexture() { |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
50 if (fontTex !is null) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
51 fontTex.drawTexture; |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
52 } |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
53 |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
54 /** Load the freetype library with settings from options. */ |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
55 StageState initialize () { |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
56 if (FT_Init_FreeType (&library)) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
57 throw new fontException ("error initialising the FreeType library"); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
58 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
59 // Check version |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
60 FT_Int maj, min, patch; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
61 FT_Library_Version (library, &maj, &min, &patch); |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
62 if (maj != 2 || min != 3) { |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
64
diff
changeset
|
63 logger.warn ("Using an untested FreeType version: {}.{}.{}", maj, min, patch); |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
64 logger.info ("The only tested version of freetype is 2.3"); |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
65 } |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
66 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
67 // Set LCD filtering method if LCD rendering is enabled. |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
68 if (fontOpts.mode() & 2 && |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
97
diff
changeset
|
69 FT_Library_SetLcdFilter(library, cast(FT_LcdFilter)fontOpts.lcdFilter())) { |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
70 /* An error occurred, presumably because LCD rendering support |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
71 * is not compiled into the library. */ |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
72 logger.warn ("Bad/unsupported LCD filter option; disabling LCD font rendering."); |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
73 logger.warn ("Your FreeType 2 library may be compiled without support for LCD/sub-pixel rendering."); |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
74 |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
75 // Reset the default filter (in case an invalid value was set in config files). |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
97
diff
changeset
|
76 fontOpts.lcdFilter = FT_LcdFilter.FT_LCD_FILTER_DEFAULT; |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
77 |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
78 /* If no support for LCD filtering, then LCD rendering only emulates NORMAL with 3 |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
79 * times wider glyphs. So disable and save the extra work. */ |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
80 fontOpts.mode = 0; |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
81 } |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
82 |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
83 // Load the fallback font; if it throws let exception abort program |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
84 fallback = new FontStyle (fontOpts.defaultFont(), fontOpts.defaultSize()); |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
85 |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
86 return StageState.ACTIVE; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
87 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
88 |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
89 /** Cleanup: delete all fonts. */ |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
90 StageState cleanup () { |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
91 // Clear loaded fonts (each has an FT_Face object needing to be freed): |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
92 /* FIXME |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
93 foreach (fs; fonts) |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
94 fs.freeFace; |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
95 */ |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
96 |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
97 FT_Done_FreeType (library); // free the library |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
98 |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
99 return StageState.INACTIVE; |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
100 } |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
101 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
102 /** Get a FontStyle instance, for a section in the fonts.mtt file. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
103 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
104 * Also loads the font if it's not already loaded, so the first call may take some time. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
105 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
106 * Uses fallback font-style if the desired style isn't known about or fails to load, so |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
107 * this function should never fail or throw, in theory (unless out of memory). The |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
108 * fallback should already be loaded. */ |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
109 FontStyle getDefault () { |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
110 //FIXME: Ddoc, new purpose; rename |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
111 return fallback; |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
112 } |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
113 |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
114 private: |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
115 FT_Library library; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
116 FontTexture fontTex; |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
117 //FontStyle[char[]] fonts; // loaded fonts, by file name FIXME: use hash of struct { char[] path; int size; }? |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
118 FontStyle fallback; // default & used when requested font can't be loaded |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
119 } |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
120 //END Static |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
121 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
122 /** Load the font file. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
123 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
124 * Even if the same font is used at multiple sizes, multiple copies of FT_Face are used. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
125 * Sharing an FT_Face would require calling FT_Set_Pixel_Sizes each time a glyph is rendered or |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
126 * swapping the size information (face.size)? */ |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
100
diff
changeset
|
127 this (char[] file, int size) |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
128 in { |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
129 assert (library !is null, "font: library is null"); |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
130 } body { |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
100
diff
changeset
|
131 if (FT_New_Face (library, getFontPath (file).ptr, 0, &face)) |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
100
diff
changeset
|
132 throw new fontLoadException ("Unable to read font: "~file[0..$-1]); |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
133 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
134 if (!FT_IS_SCALABLE (face)) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
135 throw new fontLoadException ("Currently no support for non-scalable fonts (which " ~ |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
100
diff
changeset
|
136 file[0..$-1] ~ " is). Please report if you want to see support."); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
137 /* The following will need to be addressed when adding support for non-scalables: |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
138 * Use of face.size.metrics.height property. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
139 */ |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
140 |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
141 if (FT_Set_Pixel_Sizes (face, 0, size)) |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
142 throw new fontLoadException ("Unable to set pixel size"); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
143 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
144 // Create if necessary: |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
145 if (fontTex is null) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
146 fontTex = new FontTexture; |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
147 |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
148 return this; |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
149 } |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
150 |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
151 this (FontStyle font, int size) { |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
152 //FIXME: copy font's face and set new size? |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
153 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
154 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
155 /** Update a TextBlock cache, as used by the textBlock function. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
156 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
157 * The only use of this is to get the text block's size ahead of rendering, via TextBlock's w |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
158 * and h properties. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
159 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
160 * This function will only actually update the cache if it is invalid, caused either by the |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
161 * font being changed or if cache.cacheVer < 0. */ |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
162 void updateBlock (char[] str, ref TextBlock cache) |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
163 in { |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
164 debug assert (face, "FontStyle: face is null"); |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
165 } body { |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
166 try { |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
167 fontTex.updateCache (face, str, cache); |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
168 } catch (Exception e) { |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
169 logger.warn ("Exception while drawing text: "~e.msg); |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
170 } |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
171 } |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
172 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
173 /** Draw a block of text (may inlcude new-lines). |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
174 * |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
175 * Params: |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
176 * x = Top left x-coordinate of text block |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
177 * y = Top left y-coordinate of text block |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
178 * str = Text to render |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
179 * cache = An (optional) TextBlock used for rendering this text, to save some CPU work. See updateBlock |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
180 * col = Colour to render the text; see mde.types.Colour |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
181 * index = Either the index of the character to draw with an edit cursor or size_t.max. Not |
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
182 * the index within str, but the number of characters, excluding new-lines. |
49
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
183 * The text block is drawn with top-left corner at x,y. To put the text's baseline at a given |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
184 * y coordinate would require some changes. Line height is fixed (see getLineSeparation). |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
185 * Due to hinter, glyphs are not guaranteed to lie within the "bounding box" defined by cache. |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
186 * Can be changed to test size of each glyph if necessary. |
57
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
187 * |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
188 * Specify the text's colour with col. Use textBlockA() instead for transparent text. |
49
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
189 * |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
190 * As a CPU-side code optimisation, store a TextBlock (unique to str) and pass a reference as |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
191 * the cache argument. This is the recommended method, although for one-time calls when you |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
192 * don't need to know the size, the other version of textBlock may be used. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
193 * --------------------------------- |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
194 * char[] str; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
195 * TextBlock strCache; |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
196 * textBlock (x, y, str, strCache, Colour.WHITE); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
197 * --------------------------------- |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
198 * The TextBlock cache will be updated as necessary. Besides the initial update, this will only |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
199 * be if the font changes, or it is manually invalidated. This can be done by setting the |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
200 * TextBlock's cacheVer property to -1, which should be done if str is changed. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
201 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
202 * The TextBlock's w and h properties are set to the size (in pixels) of the text block; other |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
203 * than this cache only serves as a small optimisation. However, the only way to get the size |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
204 * of a text block is to use a TextBlock cache and update it, either with this function or with |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
205 * the updateBlock function. */ |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
206 void textBlock (int x, int y, char[] str, ref TextBlock cache, Colour col, size_t index = size_t.max) |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
207 in { |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
208 assert (face, "FontStyle: face is null"); |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
209 } body { |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
210 try { |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
211 fontTex.drawCache (face, str, cache, x, y, col, index); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
212 } catch (Exception e) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
213 logger.warn ("Exception while drawing text: "~e.msg); |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
214 } |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
215 } |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
216 /** ditto */ |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
217 void textBlock (int x, int y, char[] str, Colour col, size_t index = size_t.max) |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
218 in { |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
219 assert (face, "FontStyle: face is null"); |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
220 } body { |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
221 try { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
222 // Using the cache method for one-time use is slightly less than optimal, but doing so |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
223 // isn't really recommended anyway (and maintaining two versions of fontTex.drawText |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
224 // would be horrible). |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
225 TextBlock cache; |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
226 fontTex.drawCache (face, str, cache, x, y, col, index); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
227 } catch (Exception e) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
228 logger.warn ("Exception while drawing text: "~e.msg); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
229 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
230 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
231 |
57
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
232 /** A variation of textBlock for transparency. |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
233 * |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
234 * Set the alpha by calling glColor*() first. See FontTexture.drawCacheA()'s documentation for |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
235 * details. */ |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
236 void textBlockA (int x, int y, char[] str, ref TextBlock cache, Colour col, size_t index = size_t.max) |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
237 in { |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
238 assert (face, "FontStyle: face is null"); |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
239 } body { |
57
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
240 try { |
100
0ea4a3e651ae
There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
98
diff
changeset
|
241 fontTex.drawCacheA (face, str, cache, x, y, col, index); |
57
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
242 } catch (Exception e) { |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
243 logger.warn ("Exception while drawing text: "~e.msg); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
244 } |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
245 } |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
246 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
247 /** The font-specified vertical distance between the baseline of consecutive lines. */ |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
248 int getLineSeparation () |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
249 in { |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
250 assert (face, "FontStyle: face is null"); |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
251 } body { |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
252 return face.size.metrics.height >> 6; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
253 } |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
254 |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
255 void freeFace () { |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
256 FT_Done_Face (face); |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
257 face = null; // functions using face use assertions on face to check its validity. |
44
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
258 } |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
259 |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
260 private: |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
261 FT_Face face; |
07bd1a09e161
Started implementing text rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
262 } |