diff --git a/examples/example1/example1.visualdproj b/examples/example1/example1.visualdproj index 3a6f08da..a0510bd7 100644 --- a/examples/example1/example1.visualdproj +++ b/examples/example1/example1.visualdproj @@ -66,7 +66,7 @@ 0 0 - Unicode + Unicode USE_FREETYPE 0 3 0 diff --git a/src/dlangui/graphics/fonts.d b/src/dlangui/graphics/fonts.d index 0fd4552f..2213833c 100644 --- a/src/dlangui/graphics/fonts.d +++ b/src/dlangui/graphics/fonts.d @@ -584,6 +584,20 @@ class FontManager { _subpixelRenderingMode = mode; } + private static __gshared double _fontGamma = 1.0; + /// get font gamma (1.0 is neutral, < 1.0 makes glyphs lighter, >1.0 makes glyphs bolder) + static @property double fontGamma() { return _fontGamma; } + /// set font gamma (1.0 is neutral, < 1.0 makes glyphs lighter, >1.0 makes glyphs bolder) + static @property void fontGamma(double v) { + if (v < 0.1) + v = 0.1; + else if (v > 4) + v = 4; + _fontGamma = v; + _gamma65.gamma = v; + _gamma256.gamma = v; + } + ~this() { Log.d("Destroying font manager"); } @@ -688,3 +702,46 @@ struct GlyphCache } +// support of font glyph Gamma correction +// table to correct gamma and translate to output range 0..255 +// maxv is 65 for win32 fonts, 256 for freetype +import std.math; +//--------------------------------- +struct glyph_gamma_table(int maxv = 65) +{ + this(double gammaValue = 1.0) + { + gamma = gammaValue; + } + @property double gamma() { return _gamma; } + @property void gamma(double g) { + _gamma = g; + for(int i = 0; i < maxv; i++) + { + double v = (maxv - 1.0 - i) / maxv; + v = pow(v, g); + int n = cast(int)round(v * 255); + n = 255 - n; + if (n < 0) + n = 0; + else if (n > 255) + n = 255; + _map[i] = cast(ubyte)n; + } + } + /// correct byte value from source range to 0..255 applying gamma + ubyte correct(ubyte src) { + if (src >= maxv) src = maxv - 1; + return _map[src]; + } +private: + ubyte _map[maxv]; + double _gamma = 1.0; +}; + +__gshared glyph_gamma_table!65 _gamma65; +__gshared glyph_gamma_table!256 _gamma256; +__gshared static this() { + _gamma65 = glyph_gamma_table!65(1.0); + _gamma256 = glyph_gamma_table!256(1.0); +} diff --git a/src/dlangui/graphics/ftfonts.d b/src/dlangui/graphics/ftfonts.d index 2e4bf77c..3918d4b9 100644 --- a/src/dlangui/graphics/ftfonts.d +++ b/src/dlangui/graphics/ftfonts.d @@ -304,7 +304,7 @@ private class FreeTypeFontFile { // antialiased for (uint y = 0; y < h; y++) { for (uint x = 0; x < w; x++) { - glyph.glyph[y * w + x] = bitmap.buffer[y * bitmap.pitch + x]; + glyph.glyph[y * w + x] = _gamma256.correct(bitmap.buffer[y * bitmap.pitch + x]); } } } diff --git a/src/dlangui/platforms/windows/win32fonts.d b/src/dlangui/platforms/windows/win32fonts.d index f551e00a..8f254e8a 100644 --- a/src/dlangui/platforms/windows/win32fonts.d +++ b/src/dlangui/platforms/windows/win32fonts.d @@ -375,11 +375,7 @@ class Win32Font : Font { { for (int x = 0; x < g.blackBoxX; x++) { - ubyte b = src[x]; - if (b>=64) - b = 63; - b = (b<<2) & 0xFC; - dst[x] = b; + dst[x] = _gamma65.correct(src[x]); } src += glyph_row_size; dst += g.blackBoxX; diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 5e323fdd..2f15857b 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -2766,11 +2766,12 @@ class EditBox : EditWidgetBase { return true; case EditorActions.ZoomIn: { - if (_minFontSize < _maxFontSize && _minFontSize >= 9 && _maxFontSize >= 9) { + if (_minFontSize < _maxFontSize && _minFontSize >= 7 && _maxFontSize >= 7) { int currentFontSize = fontSize; - int increment = currentFontSize >= 30 ? 2 : 1; + int increment = currentFontSize >= 40 ? 2 : 1; int newFontSize = currentFontSize + increment; //* 110 / 100; - if (currentFontSize != newFontSize && newFontSize <= _maxFontSize) { + if (currentFontSize != newFontSize && newFontSize <= _maxFontSize && newFontSize >= _minFontSize) { + Log.i("Font size in editor ", id, " zoomed to ", newFontSize); fontSize = cast(ushort)newFontSize; updateFontProps(); measureVisibleText(); @@ -2973,11 +2974,11 @@ class LogWidget : EditBox { super(ID); _scrollLock = true; enabled = false; - fontSize = 15; + fontSize = 14; //fontFace = "Consolas,Lucida Console,Courier New"; fontFace = "Consolas,DejaVuSansMono,Lucida Sans Typewriter,Courier New,Lucida Console"; fontFamily = FontFamily.MonoSpace; - minFontSize(10).maxFontSize(32); // allow font zoom with Ctrl + MouseWheel + minFontSize(8).maxFontSize(32); // allow font zoom with Ctrl + MouseWheel } /// append lines to the end of text void appendText(dstring text) { diff --git a/src/dlangui/widgets/srcedit.d b/src/dlangui/widgets/srcedit.d index cead2da3..fac243ca 100644 --- a/src/dlangui/widgets/srcedit.d +++ b/src/dlangui/widgets/srcedit.d @@ -28,7 +28,7 @@ class SourceEdit : EditBox { fontFace = "Consolas,DejaVuSansMono,Lucida Sans Typewriter,Courier New,Lucida Console"; //fontFace = "Consolas,Lucida Console,Courier New"; fontFamily = FontFamily.MonoSpace; - fontSize = 17; + fontSize = 14; layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); minFontSize(10).maxFontSize(75); // allow font zoom with Ctrl + MouseWheel diff --git a/views/res/theme_default.xml b/views/res/theme_default.xml index 8c1c404e..95b4bba7 100644 --- a/views/res/theme_default.xml +++ b/views/res/theme_default.xml @@ -1,6 +1,6 @@ @@ -116,6 +116,7 @@ backgroundImageId="tab_btn_dark_up" />