summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfont.cpp
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2011-06-04 14:47:22 +0200
committerQt Continuous Integration System <qt-info@nokia.com>2011-06-09 15:07:13 +0200
commit97391be5ebddc62545ddb88f92fc2045bfa10711 (patch)
tree0f7e7252a8e41d0c9a00f348dcfff2ff25666bef /src/gui/text/qfont.cpp
parentb97215b04c0bf12ecfd51ccdeaedd1fab5e8bc03 (diff)
Allow selecting fonts with irregular style names
Fonts like "Helvetica Neue UltraLight" or "Skia Regular Black Condensed" can't be selected in Qt because either they don't report correct numeric values for weight/stretch/etc. or these values are not mapped from QFont enums in a linear way. Thus we provide a shortcut to select these fonts with PostScript name or full name without resorting to family name matching in QFontDatabase (these fonts are not registered in font database anyway). After this, we can simply use: QFont font("Helvetica Neue"); font.setStyleName("UltraLight"); to select these fonts. QCoreTextFontEngineMulti matched like this can be created directly from the CTFontRef instance instead of creating from the font name, making this process faster. The commit also cleaned up the font loading process in Mac font database a bit, moving the code for family matching into a separate function. Add QFontInfo::styleName() and QRawFont::styleName() to access the resolved style name for a font. Task-number: QTBUG-19366 Change-Id: Iad07768c02ed06cc8d6b7395dec554384f410506 Reviewed-on: http://codereview.qt.nokia.com/333 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Diffstat (limited to 'src/gui/text/qfont.cpp')
-rw-r--r--src/gui/text/qfont.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp
index 90dd0293fc..d4c81b90db 100644
--- a/src/gui/text/qfont.cpp
+++ b/src/gui/text/qfont.cpp
@@ -348,6 +348,9 @@ void QFontPrivate::resolve(uint mask, const QFontPrivate *other)
if (! (mask & QFont::FamilyResolved))
request.family = other->request.family;
+ if (! (mask & QFont::StyleNameResolved))
+ request.styleName = other->request.styleName;
+
if (! (mask & QFont::SizeResolved)) {
request.pointSize = other->request.pointSize;
request.pixelSize = other->request.pixelSize;
@@ -897,6 +900,38 @@ void QFont::setFamily(const QString &family)
}
/*!
+ \since 4.8
+
+ Returns the requested font style name, it will be used to match the
+ font with irregular styles (that can't be normalized in other style
+ properties). It depends on system font support, thus only works for
+ Mac OS X and X11 so far. On Windows irregular styles will be added
+ as separate font families so there is no need for this.
+
+ \sa setFamily() setStyle()
+*/
+QString QFont::styleName() const
+{
+ return d->request.styleName;
+}
+
+/*!
+ \since 4.8
+
+ Sets the style name of the font. When set, other style properties
+ like \a style() and \a weight() will be ignored for font matching.
+
+ \sa styleName()
+*/
+void QFont::setStyleName(const QString &styleName)
+{
+ detach();
+
+ d->request.styleName = styleName;
+ resolve_mask |= QFont::StyleNameResolved;
+}
+
+/*!
Returns the point size of the font. Returns -1 if the font size
was specified in pixels.
@@ -2509,6 +2544,21 @@ QString QFontInfo::family() const
}
/*!
+ \since 4.8
+
+ Returns the style name of the matched window system font on
+ system that supports it.
+
+ \sa QFont::styleName()
+*/
+QString QFontInfo::styleName() const
+{
+ QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
+ Q_ASSERT(engine != 0);
+ return engine->fontDef.styleName;
+}
+
+/*!
Returns the point size of the matched window system font.
\sa pointSizeF() QFont::pointSize()