Skip to content

Commit 5e7fdcc

Browse files
author
Jørgen Lind
committed
Initial pluggable fontdatabase
QPlatformFontDatabase added. QPlatformIntegration now has a new virtual function: QPlatformDatabase::fontDatabase() const. Most unix platform plugins wants to follow the pattern implemented in directfb, linuxfb, vnc etc. In the pro file do: include(../fontdatabases/genericunix/genericunix.pri) In the QPlatformIntegration class do: and instansiate a QGenericFontDatabase in the constructor and return it in the getter function.
1 parent de66ffa commit 5e7fdcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2894
-62
lines changed

configure

+24
Original file line numberDiff line numberDiff line change
@@ -6093,6 +6093,30 @@ if [ "$PLATFORM_QPA" = "yes" ]; then
60936093
exit 1
60946094
fi
60956095
fi
6096+
6097+
# auto-detect FontConfig support
6098+
if [ "$CFG_FONTCONFIG" != "no" ]; then
6099+
if [ -n "$PKG_CONFIG" ] && $PKG_CONFIG --exists fontconfig --exists freetype2 2>/dev/null; then
6100+
QT_CFLAGS_FONTCONFIG=`$PKG_CONFIG --cflags fontconfig --cflags freetype2 2>/dev/null`
6101+
QT_LIBS_FONTCONFIG=`$PKG_CONFIG --libs fontconfig --libs freetype2 2>/dev/null`
6102+
else
6103+
QT_CFLAGS_FONTCONFIG=
6104+
QT_LIBS_FONTCONFIG="-lfreetype -lfontconfig"
6105+
fi
6106+
if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/x11/fontconfig "FontConfig" $L_FLAGS $I_FLAGS $l_FLAGS $X11TESTS_FLAGS $QT_CFLAGS_FONTCONFIG $QT_LIBS_FONTCONFIG; then
6107+
QT_CONFIG="$QT_CONFIG fontconfig"
6108+
QMakeVar set QMAKE_CFLAGS_FONTCONFIG "$QT_CFLAGS_FONTCONFIG"
6109+
QMakeVar set QMAKE_LIBS_FONTCONFIG "$QT_LIBS_FONTCONFIG"
6110+
CFG_LIBFREETYPE=system
6111+
fi
6112+
fi
6113+
6114+
# MIT_SHM is required for testlite
6115+
if [ "$CFG_MITSHM" != "no" ]; then
6116+
if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/x11/mitshm "mitshm" $L_FLAGS $I_FLAGS $l_FLAGS $X11TESTS_FLAGS; then
6117+
QT_CONFIG="$QT_CONFIG mitshm"
6118+
fi
6119+
fi
60966120
fi
60976121

60986122

lib/fonts/dejavu_sans_11_50.qpf2

396 KB
Binary file not shown.

src/gui/kernel/qplatformintegration_qpa.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
#include "qplatformintegration_qpa.h"
4343

44+
#include <QtGui/QPlatformFontDatabase>
45+
4446
QT_BEGIN_NAMESPACE
4547

4648
QPixmap QPlatformIntegration::grabWindow(WId window, int x, int y, int width, int height) const
@@ -63,4 +65,13 @@ bool QPlatformIntegration::hasOpenGL() const
6365
return false;
6466
}
6567

68+
QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const
69+
{
70+
static QPlatformFontDatabase *db = 0;
71+
if (!db) {
72+
db = new QPlatformFontDatabase;
73+
}
74+
return db;
75+
}
76+
6677
QT_END_NAMESPACE

src/gui/kernel/qplatformintegration_qpa.h

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class QWindowSurface;
5858
class QBlittable;
5959
class QWidget;
6060
class QPlatformEventLoopIntegration;
61+
class QPlatformFontDatabase;
6162

6263
class Q_GUI_EXPORT QPlatformIntegration
6364
{
@@ -75,6 +76,9 @@ class Q_GUI_EXPORT QPlatformIntegration
7576
virtual bool isVirtualDesktop() { return false; }
7677
virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const;
7778

79+
//Fontdatabase integration.
80+
virtual QPlatformFontDatabase *fontDatabase() const;
81+
7882
// Experimental in mainthread eventloop integration
7983
// This should only be used if it is only possible to do window system event processing in
8084
// the gui thread. All of the functions in QWindowSystemInterface are thread safe.

src/gui/painting/qpaintengine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class Q_GUI_EXPORT QPaintEngine
272272
friend class QProxyFontEngine;
273273
#endif
274274
#ifdef Q_WS_QPA
275-
friend class QProxyFontEngine;
275+
friend class QFontEngineQPA;
276276
#endif
277277
friend class QPainter;
278278
friend class QPainterPrivate;

src/gui/painting/qpaintengine_raster.cpp

+29-2
Original file line numberDiff line numberDiff line change
@@ -3396,9 +3396,36 @@ void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textIte
33963396
}
33973397
#endif // Q_WS_QWS
33983398

3399-
#if (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) || defined(Q_WS_QPA)) && !defined(QT_NO_FREETYPE)
3399+
#ifdef Q_WS_QPA
3400+
if (s->matrix.type() < QTransform::TxScale) {
34003401

3401-
#if (defined(Q_WS_QWS) || defined(Q_WS_QPA)) && !defined(QT_NO_QWS_QPF2)
3402+
QVarLengthArray<QFixedPoint> positions;
3403+
QVarLengthArray<glyph_t> glyphs;
3404+
QTransform matrix = state()->transform();
3405+
3406+
qreal _x = qFloor(p.x() + aliasedCoordinateDelta);
3407+
qreal _y = qFloor(p.y() + aliasedCoordinateDelta);
3408+
matrix.translate(_x, _y);
3409+
3410+
fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
3411+
if (glyphs.size() == 0)
3412+
return;
3413+
3414+
for(int i = 0; i < glyphs.size(); i++) {
3415+
QImage img = fontEngine->alphaMapForGlyph(glyphs[i]);
3416+
glyph_metrics_t metrics = fontEngine->boundingBox(glyphs[i]);
3417+
alphaPenBlt(img.bits(), img.bytesPerLine(), img.depth(),
3418+
qRound(positions[i].x + metrics.x),
3419+
qRound(positions[i].y + metrics.y),
3420+
img.width(), img.height());
3421+
}
3422+
return;
3423+
}
3424+
#endif //Q_WS_QPA
3425+
3426+
#if (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)) && !defined(QT_NO_FREETYPE)
3427+
3428+
#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_QPF2)
34023429
if (fontEngine->type() == QFontEngine::QPF2) {
34033430
QFontEngine *renderingEngine = static_cast<QFontEngineQPF *>(fontEngine)->renderingEngine();
34043431
if (renderingEngine)

src/gui/painting/qpdf.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ const char *QPdf::paperSizeToString(QPrinter::PaperSize paperSize)
916916
}
917917

918918

919-
QByteArray QPdf::stripSpecialCharacters(const QByteArray &string)
919+
Q_GUI_EXPORT QByteArray QPdf::stripSpecialCharacters(const QByteArray &string)
920920
{
921921
QByteArray s = string;
922922
s.replace(' ', "");

src/gui/text/qfont.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include <QtCore/qstring.h>
4747
#include <QtCore/qsharedpointer.h>
4848

49-
#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_QPA)
49+
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
5050
typedef struct FT_FaceRec_* FT_Face;
5151
#endif
5252

@@ -236,7 +236,7 @@ class Q_GUI_EXPORT QFont
236236
#ifdef Q_WS_MAC
237237
quint32 macFontID() const;
238238
#endif
239-
#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_QPA)
239+
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
240240
FT_Face freetypeFace() const;
241241
#endif
242242

src/gui/text/qfont_qpa.cpp

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4+
** All rights reserved.
5+
** Contact: Nokia Corporation ([email protected])
6+
**
7+
** This file is part of the QtGui module of the Qt Toolkit.
8+
**
9+
** $QT_BEGIN_LICENSE:LGPL$
10+
** No Commercial Usage
11+
** This file contains pre-release code and may not be distributed.
12+
** You may use this file in accordance with the terms and conditions
13+
** contained in the Technology Preview License Agreement accompanying
14+
** this package.
15+
**
16+
** GNU Lesser General Public License Usage
17+
** Alternatively, this file may be used under the terms of the GNU Lesser
18+
** General Public License version 2.1 as published by the Free Software
19+
** Foundation and appearing in the file LICENSE.LGPL included in the
20+
** packaging of this file. Please review the following information to
21+
** ensure the GNU Lesser General Public License version 2.1 requirements
22+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23+
**
24+
** In addition, as a special exception, Nokia gives you certain additional
25+
** rights. These rights are described in the Nokia Qt LGPL Exception
26+
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27+
**
28+
** If you have questions regarding the use of this file, please contact
29+
** Nokia at [email protected].
30+
**
31+
**
32+
**
33+
**
34+
**
35+
**
36+
**
37+
**
38+
** $QT_END_LICENSE$
39+
**
40+
****************************************************************************/
41+
42+
#include <QtGui/private/qapplication_p.h>
43+
#include <QtGui/QPlatformFontDatabase>
44+
45+
QT_BEGIN_NAMESPACE
46+
47+
void QFont::initialize()
48+
{
49+
QApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase();
50+
}
51+
52+
void QFont::cleanup()
53+
{
54+
QFontCache::cleanup();
55+
}
56+
57+
58+
/*****************************************************************************
59+
QFont member functions
60+
*****************************************************************************/
61+
62+
Qt::HANDLE QFont::handle() const
63+
{
64+
return 0;
65+
}
66+
67+
QString QFont::rawName() const
68+
{
69+
return QLatin1String("unknown");
70+
}
71+
72+
void QFont::setRawName(const QString &)
73+
{
74+
}
75+
76+
QString QFont::defaultFamily() const
77+
{
78+
QString familyName;
79+
switch(d->request.styleHint) {
80+
case QFont::Times:
81+
familyName = QString::fromLatin1("times");
82+
case QFont::Courier:
83+
case QFont::Monospace:
84+
familyName = QString::fromLatin1("monospace");
85+
case QFont::Decorative:
86+
familyName = QString::fromLatin1("old english");
87+
case QFont::Helvetica:
88+
case QFont::System:
89+
default:
90+
familyName = QString::fromLatin1("helvetica");
91+
}
92+
93+
QStringList list = QApplicationPrivate::platformIntegration()->fontDatabase()->fallbacksForFamily(familyName,QFont::StyleNormal,QUnicodeTables::Common);
94+
if (list.size()) {
95+
familyName = list.at(0);
96+
}
97+
return familyName;
98+
}
99+
100+
QString QFont::lastResortFamily() const
101+
{
102+
return QString::fromLatin1("helvetica");
103+
}
104+
105+
QString QFont::lastResortFont() const
106+
{
107+
qFatal("QFont::lastResortFont: Cannot find any reasonable font");
108+
// Shut compiler up
109+
return QString();
110+
}
111+
112+
113+
QT_END_NAMESPACE
114+

0 commit comments

Comments
 (0)