implement font gamma setting; tune fonts in default theme

This commit is contained in:
Vadim Lopatin 2015-01-30 12:04:46 +03:00
parent 20b54b412d
commit d74e995d02
7 changed files with 72 additions and 16 deletions

View File

@ -66,7 +66,7 @@
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids>Unicode</versionids>
<versionids>Unicode USE_FREETYPE</versionids>
<dump_source>0</dump_source>
<mapverbosity>3</mapverbosity>
<createImplib>0</createImplib>

View File

@ -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);
}

View File

@ -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]);
}
}
}

View File

@ -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;

View File

@ -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) {

View File

@ -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

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<theme id="theme_default"
fontSize="14"
fontSize="12"
fontFace="Verdana,Arial,DejaVu Sans"
fontFamily="SansSerif"
>
@ -116,6 +116,7 @@
backgroundImageId="tab_btn_dark_up"
/>
<style id="TAB_UP_BUTTON_DARK_TEXT"
fontSize="10"
textColor="#E0E0E0"
align="Center"
>
@ -134,6 +135,7 @@
</style>
<style id="TAB_UP_BUTTON_TEXT"
textColor="#000000"
fontSize="10"
align="Center"
>
<state state_selected="true" state_focused="true" textColor="#000000"/>
@ -282,6 +284,7 @@
layoutWidth="FILL_PARENT"
layoutHeight="WRAP_CONTENT"
padding="3,3,3,3"
fontSize="12"
align="Left|VCenter"
/>
<style id="DOCK_WINDOW_BODY"
@ -325,7 +328,7 @@
minHeight="14"
layoutWidth="FILL_PARENT"
layoutHeight="WRAP_CONTENT"
fontSize="14">
>
</style>
<style id="TREE_ITEM_EXPAND_ICON"
margins="0,0,0,0"
@ -348,7 +351,6 @@
layoutHeight="WRAP_CONTENT"
align="Left|VCenter"
textFlags="Parent"
fontSize="14"
/>
<style id="RESIZER_VERTICAL"
layoutWidth="FILL_PARENT"