font size fixes

This commit is contained in:
Vadim Lopatin 2015-01-23 10:36:51 +03:00
parent fdb965b45c
commit b417db74a0
8 changed files with 48 additions and 22 deletions

View File

@ -66,7 +66,7 @@
<debuglevel>0</debuglevel>
<debugids>DebugFocus</debugids>
<versionlevel>0</versionlevel>
<versionids>EmbedStandardResources Unicode USE_SDL USE_OPENGL </versionids>
<versionids>EmbedStandardResources Unicode</versionids>
<dump_source>0</dump_source>
<mapverbosity>0</mapverbosity>
<createImplib>1</createImplib>

View File

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

View File

@ -66,7 +66,7 @@
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids>USE_OPENGL</versionids>
<versionids>Unicode</versionids>
<dump_source>0</dump_source>
<mapverbosity>3</mapverbosity>
<createImplib>0</createImplib>
@ -89,7 +89,6 @@
<resfile />
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
<useStdLibPath>1</useStdLibPath>
<cRuntime>2</cRuntime>
<additionalOptions>-profile</additionalOptions>
<preBuildCommand />
<postBuildCommand />
@ -184,7 +183,6 @@
<resfile />
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
<useStdLibPath>1</useStdLibPath>
<cRuntime>1</cRuntime>
<additionalOptions />
<preBuildCommand />
<postBuildCommand />

View File

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

View File

@ -173,6 +173,30 @@ struct Rect {
}
}
/// screen dots per inch
private __gshared int PRIVATE_SCREEN_DPI = 96;
@property int SCREEN_DPI() {
return PRIVATE_SCREEN_DPI;
}
@property void SCREEN_DPI(int dpi) {
PRIVATE_SCREEN_DPI = dpi;
}
/// one point is 1/72 of inch
immutable int POINTS_PER_INCH = 72;
/// convert points (1/72in units) to pixels according to SCREEN_DPI
int pointsToPixels(int pt) {
return pt * SCREEN_DPI / POINTS_PER_INCH;
}
/// convert points (1/72in units) to pixels according to SCREEN_DPI
int pixelsToPoints(int px) {
return px * POINTS_PER_INCH / SCREEN_DPI;
}
/**
Character glyph.

View File

@ -53,17 +53,18 @@ private struct FontDef {
* Font implementation based on Win32 API system fonts.
*/
class Win32Font : Font {
HFONT _hfont;
int _size;
int _height;
int _weight;
int _baseline;
bool _italic;
string _face;
FontFamily _family;
LOGFONTA _logfont;
Win32ColorDrawBuf _drawbuf;
GlyphCache _glyphCache;
protected HFONT _hfont;
protected int _dpi;
protected int _size;
protected int _height;
protected int _weight;
protected int _baseline;
protected bool _italic;
protected string _face;
protected FontFamily _family;
protected LOGFONTA _logfont;
protected Win32ColorDrawBuf _drawbuf;
protected GlyphCache _glyphCache;
/// need to call create() after construction to initialize font
this() {
@ -250,7 +251,6 @@ class Win32Font : Font {
return _glyphCache.put(ch, g);
}
/// init from font definition
bool create(FontDef * def, int size, int weight, bool italic) {
if (!isNull())
@ -259,7 +259,7 @@ class Win32Font : Font {
lf.lfCharSet = ANSI_CHARSET; //DEFAULT_CHARSET;
lf.lfFaceName[0..def.face.length] = def.face;
lf.lfFaceName[def.face.length] = 0;
lf.lfHeight = -size; //size; //-size;
lf.lfHeight = size; //pixelsToPoints(size);
lf.lfItalic = italic;
lf.lfWeight = weight;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS; //OUT_OUTLINE_PRECIS; //OUT_TT_ONLY_PRECIS;
@ -277,6 +277,7 @@ class Win32Font : Font {
_size = size;
_height = tm.tmHeight;
Log.d("Win32Font.create: height=", _height, " for size=", _size, " points=", lf.lfHeight, " dpi=", _dpi);
_baseline = _height - tm.tmDescent;
_weight = weight;
_italic = italic;
@ -314,7 +315,7 @@ class Win32FontManager : FontManager {
private FontList _activeFonts;
private FontDef[] _fontFaces;
private FontDef*[string] _faceByName;
/// initialize in constructor
this() {
debug Log.i("Creating Win32FontManager");

View File

@ -680,6 +680,10 @@ class Win32Platform : Platform {
{
return false;
}
HDC dc = CreateCompatibleDC(NULL);
SCREEN_DPI = GetDeviceCaps(dc, LOGPIXELSY);
DeleteObject(dc);
return true;
}
override int enterMessageLoop() {
@ -912,7 +916,6 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
// use Win32 font manager
if (FontManager.instance is null) {
//Win32FontManager fontMan = new Win32FontManager();
FontManager.instance = new Win32FontManager();
}

View File

@ -27,7 +27,7 @@ class SourceEdit : EditBox {
super(ID);
fontFace = "Consolas,Lucida Console,Courier New";
fontFamily = FontFamily.MonoSpace;
fontSize = 12;
fontSize = 16;
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
minFontSize(10).maxFontSize(75); // allow font zoom with Ctrl + MouseWheel
_showLineNumbers = true;