mirror of https://github.com/buggins/dlangui.git
fix and optimization for monospace fonts - additional fix for #464
This commit is contained in:
parent
7e4c8accbb
commit
6dd1791490
|
@ -133,6 +133,14 @@ immutable int MAX_WIDTH_UNSPECIFIED = int.max;
|
||||||
* Use FontManager.instance.getFont() to retrieve font instance.
|
* Use FontManager.instance.getFont() to retrieve font instance.
|
||||||
*/
|
*/
|
||||||
class Font : RefCountedObject {
|
class Font : RefCountedObject {
|
||||||
|
|
||||||
|
this() {
|
||||||
|
_textSizeBuffer.reserve(100);
|
||||||
|
_textSizeBuffer.assumeSafeAppend();
|
||||||
|
}
|
||||||
|
~this() { clear(); }
|
||||||
|
|
||||||
|
|
||||||
/// returns font size (as requested from font engine)
|
/// returns font size (as requested from font engine)
|
||||||
abstract @property int size();
|
abstract @property int size();
|
||||||
/// returns actual font height including interline space
|
/// returns actual font height including interline space
|
||||||
|
@ -224,13 +232,18 @@ class Font : RefCountedObject {
|
||||||
return 0;
|
return 0;
|
||||||
const dchar * pstr = text.ptr;
|
const dchar * pstr = text.ptr;
|
||||||
uint len = cast(uint)text.length;
|
uint len = cast(uint)text.length;
|
||||||
if (widths.length < len)
|
if (widths.length < len) {
|
||||||
widths.length = len + 1;
|
widths.assumeSafeAppend;
|
||||||
bool useKerning = allowKerning && family != FontFamily.MonoSpace;
|
widths.length = len + 16;
|
||||||
|
}
|
||||||
|
bool fixed = isFixed;
|
||||||
|
bool useKerning = allowKerning && !fixed;
|
||||||
|
int fixedCharWidth = charWidth('M');
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int charsMeasured = 0;
|
int charsMeasured = 0;
|
||||||
int * pwidths = widths.ptr;
|
int * pwidths = widths.ptr;
|
||||||
int tabWidth = spaceWidth * tabSize; // width of full tab in pixels
|
int spWidth = fixed ? fixedCharWidth : spaceWidth;
|
||||||
|
int tabWidth = spWidth * tabSize; // width of full tab in pixels
|
||||||
tabOffset = tabOffset % tabWidth;
|
tabOffset = tabOffset % tabWidth;
|
||||||
if (tabOffset < 0)
|
if (tabOffset < 0)
|
||||||
tabOffset += tabWidth;
|
tabOffset += tabWidth;
|
||||||
|
@ -241,7 +254,7 @@ class Font : RefCountedObject {
|
||||||
if (ch == '\t') {
|
if (ch == '\t') {
|
||||||
// measure tab
|
// measure tab
|
||||||
int tabPosition = (x + tabWidth - tabOffset) / tabWidth * tabWidth + tabOffset;
|
int tabPosition = (x + tabWidth - tabOffset) / tabWidth * tabWidth + tabOffset;
|
||||||
while (tabPosition < x + spaceWidth)
|
while (tabPosition < x + spWidth)
|
||||||
tabPosition += tabWidth;
|
tabPosition += tabWidth;
|
||||||
pwidths[i] = tabPosition;
|
pwidths[i] = tabPosition;
|
||||||
charsMeasured = i + 1;
|
charsMeasured = i + 1;
|
||||||
|
@ -253,6 +266,12 @@ class Font : RefCountedObject {
|
||||||
prevChar = 0;
|
prevChar = 0;
|
||||||
continue; // skip '&' in hot key when measuring
|
continue; // skip '&' in hot key when measuring
|
||||||
}
|
}
|
||||||
|
if (fixed) {
|
||||||
|
// fast calculation for fixed pitch
|
||||||
|
x += fixedCharWidth;
|
||||||
|
pwidths[i] = x;
|
||||||
|
charsMeasured = i + 1;
|
||||||
|
} else {
|
||||||
Glyph * glyph = getCharGlyph(pstr[i], true); // TODO: what is better
|
Glyph * glyph = getCharGlyph(pstr[i], true); // TODO: what is better
|
||||||
//auto measureEnd = std.datetime.Clock.currAppTick;
|
//auto measureEnd = std.datetime.Clock.currAppTick;
|
||||||
//auto duration = measureEnd - measureStart;
|
//auto duration = measureEnd - measureStart;
|
||||||
|
@ -275,6 +294,7 @@ class Font : RefCountedObject {
|
||||||
pwidths[i] = w;
|
pwidths[i] = w;
|
||||||
x += width;
|
x += width;
|
||||||
charsMeasured = i + 1;
|
charsMeasured = i + 1;
|
||||||
|
}
|
||||||
if (x > maxWidth)
|
if (x > maxWidth)
|
||||||
break;
|
break;
|
||||||
prevChar = ch;
|
prevChar = ch;
|
||||||
|
@ -480,7 +500,6 @@ class Font : RefCountedObject {
|
||||||
|
|
||||||
void clear() {}
|
void clear() {}
|
||||||
|
|
||||||
~this() { clear(); }
|
|
||||||
}
|
}
|
||||||
alias FontRef = Ref!Font;
|
alias FontRef = Ref!Font;
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
v0.9.153
|
v0.9.154
|
Loading…
Reference in New Issue