mirror of https://github.com/buggins/dlangui.git
implement font gamma setting; tune fonts in default theme
This commit is contained in:
parent
20b54b412d
commit
d74e995d02
|
@ -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>
|
||||||
|
|
|
@ -584,6 +584,20 @@ class FontManager {
|
||||||
_subpixelRenderingMode = mode;
|
_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() {
|
~this() {
|
||||||
Log.d("Destroying font manager");
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -304,7 +304,7 @@ private class FreeTypeFontFile {
|
||||||
// antialiased
|
// antialiased
|
||||||
for (uint y = 0; y < h; y++) {
|
for (uint y = 0; y < h; y++) {
|
||||||
for (uint x = 0; x < w; x++) {
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -375,11 +375,7 @@ class Win32Font : Font {
|
||||||
{
|
{
|
||||||
for (int x = 0; x < g.blackBoxX; x++)
|
for (int x = 0; x < g.blackBoxX; x++)
|
||||||
{
|
{
|
||||||
ubyte b = src[x];
|
dst[x] = _gamma65.correct(src[x]);
|
||||||
if (b>=64)
|
|
||||||
b = 63;
|
|
||||||
b = (b<<2) & 0xFC;
|
|
||||||
dst[x] = b;
|
|
||||||
}
|
}
|
||||||
src += glyph_row_size;
|
src += glyph_row_size;
|
||||||
dst += g.blackBoxX;
|
dst += g.blackBoxX;
|
||||||
|
|
|
@ -2766,11 +2766,12 @@ class EditBox : EditWidgetBase {
|
||||||
return true;
|
return true;
|
||||||
case EditorActions.ZoomIn:
|
case EditorActions.ZoomIn:
|
||||||
{
|
{
|
||||||
if (_minFontSize < _maxFontSize && _minFontSize >= 9 && _maxFontSize >= 9) {
|
if (_minFontSize < _maxFontSize && _minFontSize >= 7 && _maxFontSize >= 7) {
|
||||||
int currentFontSize = fontSize;
|
int currentFontSize = fontSize;
|
||||||
int increment = currentFontSize >= 30 ? 2 : 1;
|
int increment = currentFontSize >= 40 ? 2 : 1;
|
||||||
int newFontSize = currentFontSize + increment; //* 110 / 100;
|
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;
|
fontSize = cast(ushort)newFontSize;
|
||||||
updateFontProps();
|
updateFontProps();
|
||||||
measureVisibleText();
|
measureVisibleText();
|
||||||
|
@ -2973,11 +2974,11 @@ class LogWidget : EditBox {
|
||||||
super(ID);
|
super(ID);
|
||||||
_scrollLock = true;
|
_scrollLock = true;
|
||||||
enabled = false;
|
enabled = false;
|
||||||
fontSize = 15;
|
fontSize = 14;
|
||||||
//fontFace = "Consolas,Lucida Console,Courier New";
|
//fontFace = "Consolas,Lucida Console,Courier New";
|
||||||
fontFace = "Consolas,DejaVuSansMono,Lucida Sans Typewriter,Courier New,Lucida Console";
|
fontFace = "Consolas,DejaVuSansMono,Lucida Sans Typewriter,Courier New,Lucida Console";
|
||||||
fontFamily = FontFamily.MonoSpace;
|
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
|
/// append lines to the end of text
|
||||||
void appendText(dstring text) {
|
void appendText(dstring text) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ class SourceEdit : EditBox {
|
||||||
fontFace = "Consolas,DejaVuSansMono,Lucida Sans Typewriter,Courier New,Lucida Console";
|
fontFace = "Consolas,DejaVuSansMono,Lucida Sans Typewriter,Courier New,Lucida Console";
|
||||||
//fontFace = "Consolas,Lucida Console,Courier New";
|
//fontFace = "Consolas,Lucida Console,Courier New";
|
||||||
fontFamily = FontFamily.MonoSpace;
|
fontFamily = FontFamily.MonoSpace;
|
||||||
fontSize = 17;
|
fontSize = 14;
|
||||||
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||||
minFontSize(10).maxFontSize(75); // allow font zoom with Ctrl + MouseWheel
|
minFontSize(10).maxFontSize(75); // allow font zoom with Ctrl + MouseWheel
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<theme id="theme_default"
|
<theme id="theme_default"
|
||||||
fontSize="14"
|
fontSize="12"
|
||||||
fontFace="Verdana,Arial,DejaVu Sans"
|
fontFace="Verdana,Arial,DejaVu Sans"
|
||||||
fontFamily="SansSerif"
|
fontFamily="SansSerif"
|
||||||
>
|
>
|
||||||
|
@ -116,6 +116,7 @@
|
||||||
backgroundImageId="tab_btn_dark_up"
|
backgroundImageId="tab_btn_dark_up"
|
||||||
/>
|
/>
|
||||||
<style id="TAB_UP_BUTTON_DARK_TEXT"
|
<style id="TAB_UP_BUTTON_DARK_TEXT"
|
||||||
|
fontSize="10"
|
||||||
textColor="#E0E0E0"
|
textColor="#E0E0E0"
|
||||||
align="Center"
|
align="Center"
|
||||||
>
|
>
|
||||||
|
@ -134,6 +135,7 @@
|
||||||
</style>
|
</style>
|
||||||
<style id="TAB_UP_BUTTON_TEXT"
|
<style id="TAB_UP_BUTTON_TEXT"
|
||||||
textColor="#000000"
|
textColor="#000000"
|
||||||
|
fontSize="10"
|
||||||
align="Center"
|
align="Center"
|
||||||
>
|
>
|
||||||
<state state_selected="true" state_focused="true" textColor="#000000"/>
|
<state state_selected="true" state_focused="true" textColor="#000000"/>
|
||||||
|
@ -282,6 +284,7 @@
|
||||||
layoutWidth="FILL_PARENT"
|
layoutWidth="FILL_PARENT"
|
||||||
layoutHeight="WRAP_CONTENT"
|
layoutHeight="WRAP_CONTENT"
|
||||||
padding="3,3,3,3"
|
padding="3,3,3,3"
|
||||||
|
fontSize="12"
|
||||||
align="Left|VCenter"
|
align="Left|VCenter"
|
||||||
/>
|
/>
|
||||||
<style id="DOCK_WINDOW_BODY"
|
<style id="DOCK_WINDOW_BODY"
|
||||||
|
@ -325,7 +328,7 @@
|
||||||
minHeight="14"
|
minHeight="14"
|
||||||
layoutWidth="FILL_PARENT"
|
layoutWidth="FILL_PARENT"
|
||||||
layoutHeight="WRAP_CONTENT"
|
layoutHeight="WRAP_CONTENT"
|
||||||
fontSize="14">
|
>
|
||||||
</style>
|
</style>
|
||||||
<style id="TREE_ITEM_EXPAND_ICON"
|
<style id="TREE_ITEM_EXPAND_ICON"
|
||||||
margins="0,0,0,0"
|
margins="0,0,0,0"
|
||||||
|
@ -348,7 +351,6 @@
|
||||||
layoutHeight="WRAP_CONTENT"
|
layoutHeight="WRAP_CONTENT"
|
||||||
align="Left|VCenter"
|
align="Left|VCenter"
|
||||||
textFlags="Parent"
|
textFlags="Parent"
|
||||||
fontSize="14"
|
|
||||||
/>
|
/>
|
||||||
<style id="RESIZER_VERTICAL"
|
<style id="RESIZER_VERTICAL"
|
||||||
layoutWidth="FILL_PARENT"
|
layoutWidth="FILL_PARENT"
|
||||||
|
|
Loading…
Reference in New Issue