Make pixel size a qreal in QRawFont

The pixel size in the font engines is already a floating point value.
For maximum flexibility, we should expose this in the public API.

Task-number: QTBUG-18817
Reviewed-by: Jiang Jiang
(cherry picked from commit ac9e63b58533a3215106ed9da82cff3a3e3dda3a)
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2011-05-02 10:06:44 +02:00
parent f26c4ba80d
commit ac4af55972
3 changed files with 21 additions and 21 deletions

View File

@ -308,10 +308,10 @@ qreal QRawFont::descent() const
\sa setPixelSize() \sa setPixelSize()
*/ */
int QRawFont::pixelSize() const qreal QRawFont::pixelSize() const
{ {
if (!isValid()) if (!isValid())
return -1; return 0.0;
return d->fontEngine->fontDef.pixelSize; return d->fontEngine->fontDef.pixelSize;
} }
@ -577,7 +577,7 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ
/*! /*!
Sets the pixel size with which this font should be rendered to \a pixelSize. Sets the pixel size with which this font should be rendered to \a pixelSize.
*/ */
void QRawFont::setPixelSize(int pixelSize) void QRawFont::setPixelSize(qreal pixelSize)
{ {
if (d->fontEngine == 0) if (d->fontEngine == 0)
return; return;

View File

@ -96,8 +96,8 @@ public:
const QTransform &transform = QTransform()) const; const QTransform &transform = QTransform()) const;
QPainterPath pathForGlyph(quint32 glyphIndex) const; QPainterPath pathForGlyph(quint32 glyphIndex) const;
void setPixelSize(int pixelSize); void setPixelSize(qreal pixelSize);
int pixelSize() const; qreal pixelSize() const;
QFont::HintingPreference hintingPreference() const; QFont::HintingPreference hintingPreference() const;

View File

@ -104,7 +104,7 @@ void tst_QRawFont::invalidRawFont()
{ {
QRawFont font; QRawFont font;
QVERIFY(!font.isValid()); QVERIFY(!font.isValid());
QCOMPARE(font.pixelSize(), -1); QCOMPARE(font.pixelSize(), 0.0);
QVERIFY(font.familyName().isEmpty()); QVERIFY(font.familyName().isEmpty());
QCOMPARE(font.style(), QFont::StyleNormal); QCOMPARE(font.style(), QFont::StyleNormal);
QCOMPARE(font.weight(), -1); QCOMPARE(font.weight(), -1);
@ -165,7 +165,7 @@ void tst_QRawFont::correctFontData_data()
QTest::addColumn<QFont::Weight>("weight"); QTest::addColumn<QFont::Weight>("weight");
QTest::addColumn<QFont::HintingPreference>("hintingPreference"); QTest::addColumn<QFont::HintingPreference>("hintingPreference");
QTest::addColumn<qreal>("unitsPerEm"); QTest::addColumn<qreal>("unitsPerEm");
QTest::addColumn<int>("pixelSize"); QTest::addColumn<qreal>("pixelSize");
int hintingPreferences[] = { int hintingPreferences[] = {
int(QFont::PreferDefaultHinting), int(QFont::PreferDefaultHinting),
@ -189,7 +189,7 @@ void tst_QRawFont::correctFontData_data()
<< QFont::Normal << QFont::Normal
<< QFont::HintingPreference(*hintingPreference) << QFont::HintingPreference(*hintingPreference)
<< 1000.0 << 1000.0
<< 10; << 10.0;
fileName = QLatin1String(SRCDIR "testfont_bold_italic.ttf"); fileName = QLatin1String(SRCDIR "testfont_bold_italic.ttf");
title = fileName title = fileName
@ -203,7 +203,7 @@ void tst_QRawFont::correctFontData_data()
<< QFont::Bold << QFont::Bold
<< QFont::HintingPreference(*hintingPreference) << QFont::HintingPreference(*hintingPreference)
<< 1000.0 << 1000.0
<< 10; << 10.0;
++hintingPreference; ++hintingPreference;
} }
@ -217,7 +217,7 @@ void tst_QRawFont::correctFontData()
QFETCH(QFont::Weight, weight); QFETCH(QFont::Weight, weight);
QFETCH(QFont::HintingPreference, hintingPreference); QFETCH(QFont::HintingPreference, hintingPreference);
QFETCH(qreal, unitsPerEm); QFETCH(qreal, unitsPerEm);
QFETCH(int, pixelSize); QFETCH(qreal, pixelSize);
QRawFont font(fileName, 10, hintingPreference); QRawFont font(fileName, 10, hintingPreference);
QVERIFY(font.isValid()); QVERIFY(font.isValid());
@ -284,7 +284,7 @@ void tst_QRawFont::textLayout()
QString familyName = QString::fromLatin1("QtBidiTestFont"); QString familyName = QString::fromLatin1("QtBidiTestFont");
QFont font(familyName); QFont font(familyName);
font.setPixelSize(18); font.setPixelSize(18.0);
QCOMPARE(QFontInfo(font).family(), familyName); QCOMPARE(QFontInfo(font).family(), familyName);
QTextLayout layout(QLatin1String("Foobar")); QTextLayout layout(QLatin1String("Foobar"));
@ -301,7 +301,7 @@ void tst_QRawFont::textLayout()
QRawFont rawFont = glyphs.font(); QRawFont rawFont = glyphs.font();
QVERIFY(rawFont.isValid()); QVERIFY(rawFont.isValid());
QCOMPARE(rawFont.familyName(), familyName); QCOMPARE(rawFont.familyName(), familyName);
QCOMPARE(rawFont.pixelSize(), 18); QCOMPARE(rawFont.pixelSize(), 18.0);
QVector<quint32> expectedGlyphIndices; QVector<quint32> expectedGlyphIndices;
expectedGlyphIndices << 44 << 83 << 83 << 70 << 69 << 86; expectedGlyphIndices << 44 << 83 << 83 << 70 << 69 << 86;
@ -597,12 +597,12 @@ void tst_QRawFont::fromFont()
QFont font(familyName); QFont font(familyName);
font.setHintingPreference(hintingPreference); font.setHintingPreference(hintingPreference);
font.setPixelSize(26); font.setPixelSize(26.0);
QRawFont rawFont = QRawFont::fromFont(font, writingSystem); QRawFont rawFont = QRawFont::fromFont(font, writingSystem);
QVERIFY(rawFont.isValid()); QVERIFY(rawFont.isValid());
QCOMPARE(rawFont.familyName(), familyName); QCOMPARE(rawFont.familyName(), familyName);
QCOMPARE(rawFont.pixelSize(), 26); QCOMPARE(rawFont.pixelSize(), 26.0);
QVERIFY(fontDatabase.removeApplicationFont(id)); QVERIFY(fontDatabase.removeApplicationFont(id));
} }
@ -623,7 +623,7 @@ void tst_QRawFont::copyConstructor()
{ {
QString rawFontFamilyName; QString rawFontFamilyName;
int rawFontPixelSize; qreal rawFontPixelSize;
qreal rawFontAscent; qreal rawFontAscent;
qreal rawFontDescent; qreal rawFontDescent;
int rawFontTableSize; int rawFontTableSize;
@ -691,7 +691,7 @@ void tst_QRawFont::detach()
{ {
QString rawFontFamilyName; QString rawFontFamilyName;
int rawFontPixelSize; qreal rawFontPixelSize;
qreal rawFontAscent; qreal rawFontAscent;
qreal rawFontDescent; qreal rawFontDescent;
int rawFontTableSize; int rawFontTableSize;
@ -773,15 +773,15 @@ void tst_QRawFont::unsupportedWritingSystem()
QFont font("QtBidiTestFont"); QFont font("QtBidiTestFont");
font.setHintingPreference(hintingPreference); font.setHintingPreference(hintingPreference);
font.setPixelSize(12); font.setPixelSize(12.0);
QRawFont rawFont = QRawFont::fromFont(font, QFontDatabase::Any); QRawFont rawFont = QRawFont::fromFont(font, QFontDatabase::Any);
QCOMPARE(rawFont.familyName(), QString::fromLatin1("QtBidiTestFont")); QCOMPARE(rawFont.familyName(), QString::fromLatin1("QtBidiTestFont"));
QCOMPARE(rawFont.pixelSize(), 12); QCOMPARE(rawFont.pixelSize(), 12.0);
rawFont = QRawFont::fromFont(font, QFontDatabase::Hebrew); rawFont = QRawFont::fromFont(font, QFontDatabase::Hebrew);
QCOMPARE(rawFont.familyName(), QString::fromLatin1("QtBidiTestFont")); QCOMPARE(rawFont.familyName(), QString::fromLatin1("QtBidiTestFont"));
QCOMPARE(rawFont.pixelSize(), 12); QCOMPARE(rawFont.pixelSize(), 12.0);
QString arabicText = QFontDatabase::writingSystemSample(QFontDatabase::Arabic); QString arabicText = QFontDatabase::writingSystemSample(QFontDatabase::Arabic);
@ -798,11 +798,11 @@ void tst_QRawFont::unsupportedWritingSystem()
QGlyphs glyphs = glyphss.at(0); QGlyphs glyphs = glyphss.at(0);
QRawFont layoutFont = glyphs.font(); QRawFont layoutFont = glyphs.font();
QVERIFY(layoutFont.familyName() != QString::fromLatin1("QtBidiTestFont")); QVERIFY(layoutFont.familyName() != QString::fromLatin1("QtBidiTestFont"));
QCOMPARE(layoutFont.pixelSize(), 12); QCOMPARE(layoutFont.pixelSize(), 12.0);
rawFont = QRawFont::fromFont(font, QFontDatabase::Arabic); rawFont = QRawFont::fromFont(font, QFontDatabase::Arabic);
QCOMPARE(rawFont.familyName(), layoutFont.familyName()); QCOMPARE(rawFont.familyName(), layoutFont.familyName());
QCOMPARE(rawFont.pixelSize(), 12); QCOMPARE(rawFont.pixelSize(), 12.0);
fontDatabase.removeApplicationFont(id); fontDatabase.removeApplicationFont(id);
} }