forked from eteran/edb-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFont.cpp
38 lines (31 loc) · 763 Bytes
/
Font.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "util/Font.h"
#include <QFont>
#include <QFontMetrics>
namespace Font {
QFont fromString(const QString &fontName) {
QFont font;
font.fromString(fontName);
font.setStyleName(QString());
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
font.setStyleStrategy(QFont::ForceIntegerMetrics);
#endif
return font;
}
int maxWidth(const QFontMetrics &fm) {
return Font::characterWidth(fm, QLatin1Char('X'));
}
int characterWidth(const QFontMetrics &fm, QChar ch) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
return fm.horizontalAdvance(ch);
#else
return fm.width(ch);
#endif
}
int stringWidth(const QFontMetrics &fm, const QString &s) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
return fm.horizontalAdvance(s);
#else
return fm.width(s);
#endif
}
}