Mercurial > projects > mde
comparison mde/resource/font.d @ 45:0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Moved the implementable widgets from mde.gui.widget.Widget to miscWidgets, leaving base widgets in Widget.
Rewrote some of GridLayoutWidget's implementation. Made many operations general to work for either columns or rows. Some optimisations were intended but ended up being removed due to problems.
Allowed layout's to resize from either direction (only with window resizes).
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 22 May 2008 11:34:09 +0100 |
parents | 07bd1a09e161 |
children | a98ffb64f066 |
comparison
equal
deleted
inserted
replaced
44:07bd1a09e161 | 45:0fd51d2c6c8a |
---|---|
29 logger = Log.getLogger ("mde.resource.font"); | 29 logger = Log.getLogger ("mde.resource.font"); |
30 } | 30 } |
31 | 31 |
32 /** Font class. | 32 /** Font class. |
33 * | 33 * |
34 * Particular to a font and size. (Maybe not size?) */ | 34 * Particular to a font and size. (Maybe not size?) |
35 * | |
36 * Note: it is not currently intended to be thread-safe. */ | |
35 class Font | 37 class Font |
36 { | 38 { |
37 //BEGIN Static: manager | 39 //BEGIN Static: manager |
38 static { | 40 static { |
39 /** Load the freetype library. */ | 41 /** Load the freetype library. */ |
75 assert (library !is null, "font: library is null"); | 77 assert (library !is null, "font: library is null"); |
76 } body { | 78 } body { |
77 if (FT_New_Face (library, toStringz(path), 0, &face)) | 79 if (FT_New_Face (library, toStringz(path), 0, &face)) |
78 throw new fontLoadException ("Unable to read font: "~path); | 80 throw new fontLoadException ("Unable to read font: "~path); |
79 | 81 |
80 if (FT_Set_Pixel_Sizes (face, 12,12)) | 82 if (FT_Set_Pixel_Sizes (face, 0,16)) |
81 throw new fontLoadException ("Unable to set pixel size"); | 83 throw new fontLoadException ("Unable to set pixel size"); |
82 } | 84 } |
83 | 85 |
84 void drawStr (int x, int y, char[] str) { | 86 void drawStr (int x, int y, char[] str) { |
85 FT_Vector pen = { x*64, y*64 }; | 87 FT_Vector pen = { x*64, y*64 }; |
92 | 94 |
93 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | 95 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
94 | 96 |
95 FT_Pos y_adj = 0; // y adjustment (for height) | 97 FT_Pos y_adj = 0; // y adjustment (for height) |
96 | 98 |
99 FT_Bool useKerning = FT_HAS_KERNING (face); | |
100 FT_UInt previous = 0; | |
101 | |
97 foreach (chr; str) { | 102 foreach (chr; str) { |
103 auto gi = FT_Get_Char_Index (face, chr); | |
104 | |
105 if (useKerning && previous && gi) | |
106 { | |
107 FT_Vector delta; | |
108 | |
109 | |
110 FT_Get_Kerning (face, previous, gi, FT_Kerning_Mode.FT_KERNING_DEFAULT, &delta); | |
111 | |
112 pen.x += delta.x; | |
113 } | |
114 | |
98 FT_Set_Transform(face, &m, &pen); | 115 FT_Set_Transform(face, &m, &pen); |
99 if (FT_Load_Char(face, chr, FT_LOAD_RENDER)) | 116 if (FT_Load_Glyph(face, gi, FT_LOAD_RENDER)) |
100 return; // give up | 117 return; // give up |
101 | 118 |
102 if (y_adj < g.metrics.height) y_adj = g.metrics.height; | 119 if (y_adj < g.metrics.height) y_adj = g.metrics.height; |
103 | 120 |
104 auto b = g.bitmap; | 121 auto b = g.bitmap; |
109 } | 126 } |
110 if (b.pitch != b.width) | 127 if (b.pitch != b.width) |
111 logger.info ("b.pitch != b.width"); | 128 logger.info ("b.pitch != b.width"); |
112 | 129 |
113 //NOTE: y direction! | 130 //NOTE: y direction! |
114 glRasterPos2i (g.bitmap_left,g.bitmap_top + y_adj/64); | 131 glRasterPos2i (g.bitmap_left,g.bitmap_top /+ (y_adj >> 6)+/); |
115 glDrawPixels (b.width, b.rows, GL_LUMINANCE, GL_UNSIGNED_BYTE, cast(void*) b.buffer); | 132 glDrawPixels (b.width, b.rows, GL_LUMINANCE, GL_UNSIGNED_BYTE, cast(void*) b.buffer); |
116 | 133 |
117 pen.x += g.advance.x; | 134 pen.x += g.advance.x; |
118 pen.y += g.advance.y; | 135 pen.y += g.advance.y; |
136 previous = gi; | |
119 } | 137 } |
120 } | 138 } |
121 | 139 |
122 ~this () { | 140 ~this () { |
123 FT_Done_Face (face); | 141 FT_Done_Face (face); |