summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorC. Boemann <cbo@boemann.dk>2012-01-02 14:42:57 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-11 09:24:07 +0100
commitd060b6f04f956ab3a6358f826dc6928b3353f5f7 (patch)
tree74574afd291f73896f9b5945c375153df0d11c73
parent59d5c26075724a581ed276d62d884b44d2ca4489 (diff)
Add methods for font stretch and absolute letter spacing
We basicaly just rely on the methods in QFont Change-Id: Iaf8cbf4d90d0c5b10b3a85983de7ca58763e0371 Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
-rw-r--r--src/gui/text/qtextformat.cpp63
-rw-r--r--src/gui/text/qtextformat.h15
-rw-r--r--tests/auto/gui/text/qtextformat/tst_qtextformat.cpp37
3 files changed, 111 insertions, 4 deletions
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index 4db57282b7..9ce45fdaf3 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -394,6 +394,9 @@ void QTextFormatPrivate::recalcFont() const
case QTextFormat::FontStrikeOut:
f.setStrikeOut(props.at(i).value.toBool());
break;
+ case QTextFormat::FontAbsoluteLetterSpacing:
+ f.setLetterSpacing(QFont::AbsoluteSpacing, props.at(i).value.toReal());
+ break;
case QTextFormat::FontLetterSpacing:
f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toReal());
break;
@@ -408,6 +411,9 @@ void QTextFormatPrivate::recalcFont() const
if (f.fixedPitch() != value)
f.setFixedPitch(value);
break; }
+ case QTextFormat::FontStretch:
+ f.setStretch(props.at(i).value.toInt());
+ break;
case QTextFormat::FontStyleHint:
f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
break;
@@ -564,10 +570,12 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
\value FontOverline
\value FontStrikeOut
\value FontCapitalization Specifies the capitalization type that is to be applied to the text.
+ \value FontAbsoluteLetterSpacing If true FontLetterSpacing is absolute
\value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is
specified in percentage, with 100 as the default value.
\value FontWordSpacing Changes the default spacing between individual words. A positive value increases the word spacing
by the corresponding pixels; a negative value decreases the spacing.
+ \value FontStretch Corresponds to the QFont::Stretch property
\value FontStyleHint Corresponds to the QFont::StyleHint property
\value FontStyleStrategy Corresponds to the QFont::StyleStrategy property
\value FontKerning Specifies whether the font has kerning turned on.
@@ -1853,8 +1861,12 @@ void QTextCharFormat::setFont(const QFont &font)
setFontFixedPitch(font.fixedPitch());
setFontCapitalization(font.capitalization());
setFontWordSpacing(font.wordSpacing());
- if (font.letterSpacingType() == QFont::PercentageSpacing)
+ if (font.letterSpacingType() == QFont::AbsoluteSpacing) {
+ setFontAbsoluteLetterSpacing(font.letterSpacing());
+ } else {
setFontLetterSpacing(font.letterSpacing());
+ }
+ setFontStretch(font.stretch());
setFontStyleHint(font.styleHint());
setFontStyleStrategy(font.styleStrategy());
setFontKerning(font.kerning());
@@ -3045,14 +3057,37 @@ QTextImageFormat::QTextImageFormat(const QTextFormat &fmt)
*/
/*!
+ \fn void QTextCharFormat::setFontAbsoluteLetterSpacing(bool absolute)
+ \since 5.0
+
+ Sets the letter spacing type of this format to absolute.
+ \sa fontAbsoluteLetterSpacing()
+ \sa setFontLetterSpacing()
+ \sa fontLetterSpacing()
+*/
+
+/*!
+ \fn bool QTextCharFormat::fontAbsoluteLetterSpacing() const
+ \since 5.0
+
+ Returns if the current letter spacing is absolute (or percentage).
+ \sa setFontAbsoluteLetterSpacing()
+ \sa setFontLetterSpacing()
+ \sa fontLetterSpacing()
+*/
+
+/*!
\fn void QTextCharFormat::setFontLetterSpacing(qreal spacing)
\since 4.4
- Sets the letter spacing of this format to the given \a spacing, in percent.
- A value of 100 indicates default spacing; a value of 200 doubles the amount
+ Sets the letter spacing of this format to the given \a spacing.
+ Depending on fontAbsoluteLetterSpacing the value is given in absolutes or in percent.
+ For percent a value of 100 indicates default spacing; a value of 200 doubles the amount
of space a letter takes.
\sa fontLetterSpacing()
+ \sa setFontAbsoluteLetterSpacing()
+ \sa fontAbsoluteLetterSpacing()
*/
/*!
@@ -3079,6 +3114,28 @@ QTextImageFormat::QTextImageFormat(const QTextFormat &fmt)
*/
/*!
+ \fn void QTextCharFormat::setFontStretch(int factor)
+ \since 5.0
+
+ Sets the stretch factor for the font.
+
+ The stretch factor changes the width of all characters in the font by factor percent. For example, setting factor to 150 results in all characters in the font being 1.5 times (ie. 150%) wider. The default stretch factor is 100. The minimum stretch factor is 1, and the maximum stretch factor is 4000.
+
+ The stretch factor is only applied to outline fonts. The stretch factor is ignored for bitmap fonts.
+
+ NOTE: QFont cannot stretch XLFD fonts. When loading XLFD fonts on X11, the stretch factor is matched against a predefined set of values for the SETWIDTH_NAME field of the XLFD.
+ \sa fontStretch()
+*/
+
+/*!
+ \fn int QTextCharFormat::fontStretch() const
+ \since 5.0
+
+ Returns the current font stretching.
+ \sa setFontStretch()
+*/
+
+/*!
\fn qreal QTextTableCellFormat::topPadding() const
\since 4.4
diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h
index 2e1bcd8d33..5c9d6fe20e 100644
--- a/src/gui/text/qtextformat.h
+++ b/src/gui/text/qtextformat.h
@@ -180,8 +180,10 @@ public:
// character properties
FirstFontProperty = 0x1FE0,
FontCapitalization = FirstFontProperty,
+ FontAbsoluteLetterSpacing = 0x2033, // if true FontLetterSpacing is absolute
FontLetterSpacing = 0x1FE1,
FontWordSpacing = 0x1FE2,
+ FontStretch = 0x2034,
FontStyleHint = 0x1FE3,
FontStyleStrategy = 0x1FE4,
FontKerning = 0x1FE5,
@@ -428,8 +430,14 @@ public:
{ setProperty(FontCapitalization, capitalization); }
inline QFont::Capitalization fontCapitalization() const
{ return static_cast<QFont::Capitalization>(intProperty(FontCapitalization)); }
+ inline void setFontAbsoluteLetterSpacing(qreal absoluteSpacing)
+ { setProperty(FontAbsoluteLetterSpacing, absoluteSpacing);
+ clearProperty(FontLetterSpacing); }
+ inline qreal fontAbsoluteLetterSpacing() const
+ { return doubleProperty(FontAbsoluteLetterSpacing); }
inline void setFontLetterSpacing(qreal spacing)
- { setProperty(FontLetterSpacing, spacing); }
+ { setProperty(FontLetterSpacing, spacing);
+ clearProperty(FontAbsoluteLetterSpacing); }
inline qreal fontLetterSpacing() const
{ return doubleProperty(FontLetterSpacing); }
inline void setFontWordSpacing(qreal spacing)
@@ -461,6 +469,11 @@ public:
inline bool fontFixedPitch() const
{ return boolProperty(FontFixedPitch); }
+ inline void setFontStretch(qreal factor)
+ { setProperty(FontStretch, factor); }
+ inline int fontStretch() const
+ { return intProperty(FontStretch); }
+
inline void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy = QFont::PreferDefault)
{ setProperty(FontStyleHint, hint); setProperty(FontStyleStrategy, strategy); }
inline void setFontStyleStrategy(QFont::StyleStrategy strategy)
diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
index 096ea2dade..166b5d7c82 100644
--- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
+++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
@@ -63,6 +63,8 @@ private slots:
void testUnderlinePropertyPrecedence();
void toFormat();
void resolveFont();
+ void testLetterSpacing();
+ void testFontStretch();
void getSetTabs();
void testTabsUsed();
void testFontStyleSetters();
@@ -277,6 +279,41 @@ void tst_QTextFormat::resolveFont()
QVERIFY(fmt.font().strikeOut());
}
+
+void tst_QTextFormat::testLetterSpacing()
+{
+ QTextCharFormat format;
+
+ QCOMPARE(format.hasProperty(QTextFormat::FontLetterSpacing), false);
+ QCOMPARE(format.hasProperty(QTextFormat::FontAbsoluteLetterSpacing), false);
+
+ format.setFontAbsoluteLetterSpacing(10.0);
+
+ QCOMPARE(format.hasProperty(QTextFormat::FontLetterSpacing), false);
+ QCOMPARE(format.property(QTextFormat::FontAbsoluteLetterSpacing).toDouble(), 10.0);
+
+ format.setFontLetterSpacing(110.0);
+
+ QCOMPARE(format.property(QTextFormat::FontLetterSpacing).toDouble(), 110.0);
+ QCOMPARE(format.hasProperty(QTextFormat::FontAbsoluteLetterSpacing), false);
+
+ format.setFontAbsoluteLetterSpacing(10.0);
+
+ QCOMPARE(format.hasProperty(QTextFormat::FontLetterSpacing), false);
+ QCOMPARE(format.property(QTextFormat::FontAbsoluteLetterSpacing).toDouble(), 10.0);
+}
+
+void tst_QTextFormat::testFontStretch()
+{
+ QTextCharFormat format;
+
+ QCOMPARE(format.hasProperty(QTextFormat::FontStretch), false);
+
+ format.setFontStretch(130.0);
+
+ QCOMPARE(format.property(QTextFormat::FontStretch).toInt(), 130);
+}
+
void tst_QTextFormat::getSetTabs()
{
class Comparator {