Skip to content

Commit

Permalink
Initial pluggable fontdatabase
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jørgen Lind committed Sep 2, 2010
1 parent de66ffa commit 5e7fdcc
Show file tree
Hide file tree
Showing 49 changed files with 2,894 additions and 62 deletions.
24 changes: 24 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -6093,6 +6093,30 @@ if [ "$PLATFORM_QPA" = "yes" ]; then
exit 1
fi
fi

# auto-detect FontConfig support
if [ "$CFG_FONTCONFIG" != "no" ]; then
if [ -n "$PKG_CONFIG" ] && $PKG_CONFIG --exists fontconfig --exists freetype2 2>/dev/null; then
QT_CFLAGS_FONTCONFIG=`$PKG_CONFIG --cflags fontconfig --cflags freetype2 2>/dev/null`
QT_LIBS_FONTCONFIG=`$PKG_CONFIG --libs fontconfig --libs freetype2 2>/dev/null`
else
QT_CFLAGS_FONTCONFIG=
QT_LIBS_FONTCONFIG="-lfreetype -lfontconfig"
fi
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
QT_CONFIG="$QT_CONFIG fontconfig"
QMakeVar set QMAKE_CFLAGS_FONTCONFIG "$QT_CFLAGS_FONTCONFIG"
QMakeVar set QMAKE_LIBS_FONTCONFIG "$QT_LIBS_FONTCONFIG"
CFG_LIBFREETYPE=system
fi
fi

# MIT_SHM is required for testlite
if [ "$CFG_MITSHM" != "no" ]; then
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
QT_CONFIG="$QT_CONFIG mitshm"
fi
fi
fi


Expand Down
Binary file added lib/fonts/dejavu_sans_11_50.qpf2
Binary file not shown.
11 changes: 11 additions & 0 deletions src/gui/kernel/qplatformintegration_qpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

#include "qplatformintegration_qpa.h"

#include <QtGui/QPlatformFontDatabase>

QT_BEGIN_NAMESPACE

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

QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const
{
static QPlatformFontDatabase *db = 0;
if (!db) {
db = new QPlatformFontDatabase;
}
return db;
}

QT_END_NAMESPACE
4 changes: 4 additions & 0 deletions src/gui/kernel/qplatformintegration_qpa.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class QWindowSurface;
class QBlittable;
class QWidget;
class QPlatformEventLoopIntegration;
class QPlatformFontDatabase;

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

//Fontdatabase integration.
virtual QPlatformFontDatabase *fontDatabase() const;

// Experimental in mainthread eventloop integration
// This should only be used if it is only possible to do window system event processing in
// the gui thread. All of the functions in QWindowSystemInterface are thread safe.
Expand Down
2 changes: 1 addition & 1 deletion src/gui/painting/qpaintengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class Q_GUI_EXPORT QPaintEngine
friend class QProxyFontEngine;
#endif
#ifdef Q_WS_QPA
friend class QProxyFontEngine;
friend class QFontEngineQPA;
#endif
friend class QPainter;
friend class QPainterPrivate;
Expand Down
31 changes: 29 additions & 2 deletions src/gui/painting/qpaintengine_raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3396,9 +3396,36 @@ void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textIte
}
#endif // Q_WS_QWS

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

#if (defined(Q_WS_QWS) || defined(Q_WS_QPA)) && !defined(QT_NO_QWS_QPF2)
QVarLengthArray<QFixedPoint> positions;
QVarLengthArray<glyph_t> glyphs;
QTransform matrix = state()->transform();

qreal _x = qFloor(p.x() + aliasedCoordinateDelta);
qreal _y = qFloor(p.y() + aliasedCoordinateDelta);
matrix.translate(_x, _y);

fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
if (glyphs.size() == 0)
return;

for(int i = 0; i < glyphs.size(); i++) {
QImage img = fontEngine->alphaMapForGlyph(glyphs[i]);
glyph_metrics_t metrics = fontEngine->boundingBox(glyphs[i]);
alphaPenBlt(img.bits(), img.bytesPerLine(), img.depth(),
qRound(positions[i].x + metrics.x),
qRound(positions[i].y + metrics.y),
img.width(), img.height());
}
return;
}
#endif //Q_WS_QPA

#if (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)) && !defined(QT_NO_FREETYPE)

#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_QPF2)
if (fontEngine->type() == QFontEngine::QPF2) {
QFontEngine *renderingEngine = static_cast<QFontEngineQPF *>(fontEngine)->renderingEngine();
if (renderingEngine)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/painting/qpdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ const char *QPdf::paperSizeToString(QPrinter::PaperSize paperSize)
}


QByteArray QPdf::stripSpecialCharacters(const QByteArray &string)
Q_GUI_EXPORT QByteArray QPdf::stripSpecialCharacters(const QByteArray &string)
{
QByteArray s = string;
s.replace(' ', "");
Expand Down
4 changes: 2 additions & 2 deletions src/gui/text/qfont.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <QtCore/qstring.h>
#include <QtCore/qsharedpointer.h>

#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_QPA)
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
typedef struct FT_FaceRec_* FT_Face;
#endif

Expand Down Expand Up @@ -236,7 +236,7 @@ class Q_GUI_EXPORT QFont
#ifdef Q_WS_MAC
quint32 macFontID() const;
#endif
#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_QPA)
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
FT_Face freetypeFace() const;
#endif

Expand Down
114 changes: 114 additions & 0 deletions src/gui/text/qfont_qpa.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation ([email protected])
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at [email protected].
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtGui/private/qapplication_p.h>
#include <QtGui/QPlatformFontDatabase>

QT_BEGIN_NAMESPACE

void QFont::initialize()
{
QApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase();
}

void QFont::cleanup()
{
QFontCache::cleanup();
}


/*****************************************************************************
QFont member functions
*****************************************************************************/

Qt::HANDLE QFont::handle() const
{
return 0;
}

QString QFont::rawName() const
{
return QLatin1String("unknown");
}

void QFont::setRawName(const QString &)
{
}

QString QFont::defaultFamily() const
{
QString familyName;
switch(d->request.styleHint) {
case QFont::Times:
familyName = QString::fromLatin1("times");
case QFont::Courier:
case QFont::Monospace:
familyName = QString::fromLatin1("monospace");
case QFont::Decorative:
familyName = QString::fromLatin1("old english");
case QFont::Helvetica:
case QFont::System:
default:
familyName = QString::fromLatin1("helvetica");
}

QStringList list = QApplicationPrivate::platformIntegration()->fontDatabase()->fallbacksForFamily(familyName,QFont::StyleNormal,QUnicodeTables::Common);
if (list.size()) {
familyName = list.at(0);
}
return familyName;
}

QString QFont::lastResortFamily() const
{
return QString::fromLatin1("helvetica");
}

QString QFont::lastResortFont() const
{
qFatal("QFont::lastResortFont: Cannot find any reasonable font");
// Shut compiler up
return QString();
}


QT_END_NAMESPACE

Loading

0 comments on commit 5e7fdcc

Please sign in to comment.