mirror of https://github.com/buggins/dlangui.git
subpixel antialiasing in freetype fonts
This commit is contained in:
parent
d66f79c019
commit
b15478b8e5
|
@ -66,7 +66,7 @@
|
||||||
<debuglevel>0</debuglevel>
|
<debuglevel>0</debuglevel>
|
||||||
<debugids>DebugFocus</debugids>
|
<debugids>DebugFocus</debugids>
|
||||||
<versionlevel>0</versionlevel>
|
<versionlevel>0</versionlevel>
|
||||||
<versionids>EmbedStandardResources Unicode</versionids>
|
<versionids>EmbedStandardResources Unicode USE_FREETYPE</versionids>
|
||||||
<dump_source>0</dump_source>
|
<dump_source>0</dump_source>
|
||||||
<mapverbosity>0</mapverbosity>
|
<mapverbosity>0</mapverbosity>
|
||||||
<createImplib>1</createImplib>
|
<createImplib>1</createImplib>
|
||||||
|
@ -89,6 +89,7 @@
|
||||||
<resfile />
|
<resfile />
|
||||||
<exefile>$(OutDir)\$(ProjectName).lib</exefile>
|
<exefile>$(OutDir)\$(ProjectName).lib</exefile>
|
||||||
<useStdLibPath>1</useStdLibPath>
|
<useStdLibPath>1</useStdLibPath>
|
||||||
|
<cRuntime>2</cRuntime>
|
||||||
<additionalOptions />
|
<additionalOptions />
|
||||||
<preBuildCommand />
|
<preBuildCommand />
|
||||||
<postBuildCommand />
|
<postBuildCommand />
|
||||||
|
@ -183,6 +184,7 @@
|
||||||
<resfile />
|
<resfile />
|
||||||
<exefile>$(OutDir)\$(ProjectName).lib</exefile>
|
<exefile>$(OutDir)\$(ProjectName).lib</exefile>
|
||||||
<useStdLibPath>1</useStdLibPath>
|
<useStdLibPath>1</useStdLibPath>
|
||||||
|
<cRuntime>1</cRuntime>
|
||||||
<additionalOptions />
|
<additionalOptions />
|
||||||
<preBuildCommand />
|
<preBuildCommand />
|
||||||
<postBuildCommand />
|
<postBuildCommand />
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
<debuglevel>0</debuglevel>
|
<debuglevel>0</debuglevel>
|
||||||
<debugids />
|
<debugids />
|
||||||
<versionlevel>0</versionlevel>
|
<versionlevel>0</versionlevel>
|
||||||
<versionids>Unicode</versionids>
|
<versionids>Unicode USE_FREETYPE</versionids>
|
||||||
<dump_source>0</dump_source>
|
<dump_source>0</dump_source>
|
||||||
<mapverbosity>3</mapverbosity>
|
<mapverbosity>3</mapverbosity>
|
||||||
<createImplib>0</createImplib>
|
<createImplib>0</createImplib>
|
||||||
|
@ -89,6 +89,7 @@
|
||||||
<resfile />
|
<resfile />
|
||||||
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
||||||
<useStdLibPath>1</useStdLibPath>
|
<useStdLibPath>1</useStdLibPath>
|
||||||
|
<cRuntime>2</cRuntime>
|
||||||
<additionalOptions>-profile</additionalOptions>
|
<additionalOptions>-profile</additionalOptions>
|
||||||
<preBuildCommand />
|
<preBuildCommand />
|
||||||
<postBuildCommand />
|
<postBuildCommand />
|
||||||
|
@ -183,6 +184,7 @@
|
||||||
<resfile />
|
<resfile />
|
||||||
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
||||||
<useStdLibPath>1</useStdLibPath>
|
<useStdLibPath>1</useStdLibPath>
|
||||||
|
<cRuntime>1</cRuntime>
|
||||||
<additionalOptions />
|
<additionalOptions />
|
||||||
<preBuildCommand />
|
<preBuildCommand />
|
||||||
<postBuildCommand />
|
<postBuildCommand />
|
||||||
|
|
|
@ -206,8 +206,13 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
// you can override antialiasing setting here (0 means antialiasing always on, some big value = always off)
|
// you can override antialiasing setting here (0 means antialiasing always on, some big value = always off)
|
||||||
// fonts with size less than specified value will not be antialiased
|
// fonts with size less than specified value will not be antialiased
|
||||||
FontManager.minAnitialiasedFontSize = 0; // 0 means always antialiased
|
FontManager.minAnitialiasedFontSize = 0; // 0 means always antialiased
|
||||||
|
version (USE_OPENGL) {
|
||||||
// you can turn on subpixel font rendering (ClearType) here
|
// you can turn on subpixel font rendering (ClearType) here
|
||||||
FontManager.subpixelRenderingMode = SubpixelRenderingMode.None;// SubpixelRenderingMode.BGR;
|
FontManager.subpixelRenderingMode = SubpixelRenderingMode.None; //
|
||||||
|
} else {
|
||||||
|
// you can turn on subpixel font rendering (ClearType) here
|
||||||
|
FontManager.subpixelRenderingMode = SubpixelRenderingMode.BGR; //SubpixelRenderingMode.None; //
|
||||||
|
}
|
||||||
|
|
||||||
// create window
|
// create window
|
||||||
Window window = Platform.instance.createWindow("My Window", null);
|
Window window = Platform.instance.createWindow("My Window", null);
|
||||||
|
|
|
@ -246,8 +246,9 @@ private class FreeTypeFontFile {
|
||||||
//FONT_GUARD
|
//FONT_GUARD
|
||||||
int glyph_index = getCharIndex(code, def_char);
|
int glyph_index = getCharIndex(code, def_char);
|
||||||
int flags = FT_LOAD_DEFAULT;
|
int flags = FT_LOAD_DEFAULT;
|
||||||
const bool _drawMonochrome = _size < FontManager.instance.minAnitialiasedFontSize;
|
const bool _drawMonochrome = _size < FontManager.minAnitialiasedFontSize;
|
||||||
flags |= (!_drawMonochrome ? FT_LOAD_TARGET_NORMAL : FT_LOAD_TARGET_MONO);
|
SubpixelRenderingMode subpixel = _drawMonochrome ? SubpixelRenderingMode.None : FontManager.subpixelRenderingMode;
|
||||||
|
flags |= (!_drawMonochrome ? (subpixel ? FT_LOAD_TARGET_LCD : FT_LOAD_TARGET_NORMAL) : FT_LOAD_TARGET_MONO);
|
||||||
if (withImage)
|
if (withImage)
|
||||||
flags |= FT_LOAD_RENDER;
|
flags |= FT_LOAD_RENDER;
|
||||||
if (FontManager.instance.hintingMode == HintingMode.AutoHint)
|
if (FontManager.instance.hintingMode == HintingMode.AutoHint)
|
||||||
|
@ -261,16 +262,16 @@ private class FreeTypeFontFile {
|
||||||
if ( error )
|
if ( error )
|
||||||
return false;
|
return false;
|
||||||
glyph.lastUsage = 1;
|
glyph.lastUsage = 1;
|
||||||
glyph.blackBoxX = cast(ubyte)(_slot.metrics.width >> 6);
|
glyph.blackBoxX = cast(ushort)(_slot.metrics.width >> 6);
|
||||||
glyph.blackBoxY = cast(ubyte)(_slot.metrics.height >> 6);
|
glyph.blackBoxY = cast(ubyte)(_slot.metrics.height >> 6);
|
||||||
glyph.originX = cast(byte)(_slot.metrics.horiBearingX >> 6);
|
glyph.originX = cast(byte)(_slot.metrics.horiBearingX >> 6);
|
||||||
glyph.originY = cast(byte)(_slot.metrics.horiBearingY >> 6);
|
glyph.originY = cast(byte)(_slot.metrics.horiBearingY >> 6);
|
||||||
glyph.width = cast(ubyte)(myabs(cast(int)(_slot.metrics.horiAdvance)) >> 6);
|
glyph.width = cast(ubyte)(myabs(cast(int)(_slot.metrics.horiAdvance)) >> 6);
|
||||||
glyph.subpixelMode = SubpixelRenderingMode.None;
|
glyph.subpixelMode = subpixel;
|
||||||
//glyph.glyphIndex = cast(ushort)code;
|
//glyph.glyphIndex = cast(ushort)code;
|
||||||
if (withImage) {
|
if (withImage) {
|
||||||
FT_Bitmap* bitmap = &_slot.bitmap;
|
FT_Bitmap* bitmap = &_slot.bitmap;
|
||||||
ubyte w = cast(ubyte)(bitmap.width);
|
ushort w = cast(ushort)(bitmap.width);
|
||||||
ubyte h = cast(ubyte)(bitmap.rows);
|
ubyte h = cast(ubyte)(bitmap.rows);
|
||||||
glyph.blackBoxX = w;
|
glyph.blackBoxX = w;
|
||||||
glyph.blackBoxY = h;
|
glyph.blackBoxY = h;
|
||||||
|
@ -298,8 +299,11 @@ private class FreeTypeFontFile {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// antialiased
|
// antialiased
|
||||||
for (int i = 0; i < sz; i++)
|
for (uint y = 0; y < h; y++) {
|
||||||
glyph.glyph[i] = bitmap.buffer[i];
|
for (uint x = 0; x < w; x++) {
|
||||||
|
glyph.glyph[y * w + x] = bitmap.buffer[y * bitmap.pitch + x];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
version (USE_OPENGL) {
|
version (USE_OPENGL) {
|
||||||
|
@ -491,6 +495,7 @@ class FreeTypeFontManager : FontManager {
|
||||||
Log.e("Cannot init freetype library, error=", error);
|
Log.e("Cannot init freetype library, error=", error);
|
||||||
throw new Exception("Cannot init freetype library");
|
throw new Exception("Cannot init freetype library");
|
||||||
}
|
}
|
||||||
|
FT_Library_SetLcdFilter(_library, FT_LCD_FILTER_DEFAULT);
|
||||||
}
|
}
|
||||||
~this() {
|
~this() {
|
||||||
debug Log.d("FreeTypeFontManager ~this()");
|
debug Log.d("FreeTypeFontManager ~this()");
|
||||||
|
|
Loading…
Reference in New Issue