aboutsummaryrefslogtreecommitdiffstats
path: root/src/base/UFont.pas
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-10-28 18:57:02 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-10-28 18:57:02 +0000
commite8a388e32a4563ac9ea0895ca6c7cdf83cf9d3ec (patch)
tree832c59176b260af0a3e89f058699cec2b9a7dca0 /src/base/UFont.pas
parentc01eba6a6494bb583b5bf43bea404b918b5c9c63 (diff)
downloadusdx-e8a388e32a4563ac9ea0895ca6c7cdf83cf9d3ec.tar.gz
usdx-e8a388e32a4563ac9ea0895ca6c7cdf83cf9d3ec.tar.xz
usdx-e8a388e32a4563ac9ea0895ca6c7cdf83cf9d3ec.zip
- glPrint(Pchar) -> glPrint(string)
- glPrintLetter removed - font engine handles FT_PIXEL_MODE_MONO as FT_Glyph_To_Bitmap(FT_RENDER_MODE_NORMAL) might return a 1bit/pixel black/white image instead of 8bit/pixel gray shaded one (happened with 16px japanese glyphs of simsun.ttf, latin ones were correct). git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1482 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'src/base/UFont.pas')
-rw-r--r--src/base/UFont.pas28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/base/UFont.pas b/src/base/UFont.pas
index 30be4c3b..a72bca21 100644
--- a/src/base/UFont.pas
+++ b/src/base/UFont.pas
@@ -2019,8 +2019,8 @@ var
Glyph: FT_Glyph;
BitmapGlyph: FT_BitmapGlyph;
Bitmap: PFT_Bitmap;
- BitmapLine: PChar;
- BitmapBuffer: PChar;
+ BitmapLine: PByteArray;
+ BitmapBuffer: PByteArray;
TexBuffer: TGLubyteDynArray;
TexLine: PGLubyteArray;
CBox: FT_BBox;
@@ -2045,8 +2045,9 @@ begin
fBounds.Bottom := CBox.yMin / 64;
fBounds.Top := CBox.yMax / 64 + fOutset*2;
- // convert the glyph to a bitmap (and destroy original glyph image)
- FT_Glyph_To_Bitmap(Glyph, ft_render_mode_normal, nil, 1);
+ // convert the glyph to a bitmap (and destroy original glyph image).
+ // Request 8 bit gray level pixel mode.
+ FT_Glyph_To_Bitmap(Glyph, FT_RENDER_MODE_NORMAL, nil, 1);
BitmapGlyph := FT_BitmapGlyph(Glyph);
// get bitmap offsets
@@ -2094,8 +2095,23 @@ begin
// get next lower line offset, use pitch instead of width as it tells
// us the storage direction of the lines. In addition a line might be padded.
BitmapLine := @BitmapBuffer[Y * Bitmap.pitch];
- for X := 0 to Bitmap.width-1 do
- TexLine[X] := GLubyte(BitmapLine[X]);
+
+ // check for pixel mode and copy pixels
+ // Should be 8 bit gray, but even with FT_RENDER_MODE_NORMAL, freetype
+ // sometimes (e.g. 16px sized japanese fonts) fallbacks to 1 bit pixels.
+ case (Bitmap.pixel_mode) of
+ FT_PIXEL_MODE_GRAY: begin // 8 bit gray
+ for X := 0 to Bitmap.width-1 do
+ TexLine[X] := BitmapLine[X];
+ end;
+ FT_PIXEL_MODE_MONO: begin // 1 bit mono
+ for X := 0 to Bitmap.width-1 do
+ TexLine[X] := High(GLubyte) * ((BitmapLine[X div 8] shr (7-(X mod 8))) and $1);
+ end;
+ else begin
+ // unhandled pixel format
+ end;
+ end;
end;
if (fOutset > 0) then