summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorJerome Pasion <jerome.pasion@nokia.com>2011-07-08 11:17:37 (GMT)
committerJerome Pasion <jerome.pasion@nokia.com>2011-07-08 11:17:37 (GMT)
commitf037c0e87d186a01f07cb9aa360dcc496d11145e (patch)
tree9449cc65b856b4743e933cf2b8ae1cb2f85ba9fd /src/gui/text
parent5016de08d84c4d2887f7424dbf17f31e27c2e8e2 (diff)
parent1dd26ea2486db87b61e8e9f70a1e04f7386405ef (diff)
downloadQt-f037c0e87d186a01f07cb9aa360dcc496d11145e.zip
Qt-f037c0e87d186a01f07cb9aa360dcc496d11145e.tar.gz
Qt-f037c0e87d186a01f07cb9aa360dcc496d11145e.tar.bz2
Merge remote branch 'upstream/4.8'
Conflicts: doc/src/external-resources.qdoc
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qfontengine_qpf.cpp12
-rw-r--r--src/gui/text/qfontengine_qws.cpp216
-rw-r--r--src/gui/text/qstatictext.cpp10
3 files changed, 73 insertions, 165 deletions
diff --git a/src/gui/text/qfontengine_qpf.cpp b/src/gui/text/qfontengine_qpf.cpp
index 4c1045e..30a1623 100644
--- a/src/gui/text/qfontengine_qpf.cpp
+++ b/src/gui/text/qfontengine_qpf.cpp
@@ -251,8 +251,8 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras
{
QList<QByteArray> removedFonts;
QDir dir(qws_fontCacheDir(), QLatin1String("*.qsf"));
- for (int i = 0; i < int(dir.count()); ++i) {
- const QByteArray fileName = QFile::encodeName(dir.absoluteFilePath(dir[i]));
+ foreach (const QFileInfo &fi, dir.entryInfoList()) {
+ const QByteArray fileName = QFile::encodeName(fi.absoluteFilePath());
int fd = QT_OPEN(fileName.constData(), O_RDONLY, 0);
if (fd >= 0) {
@@ -342,14 +342,14 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng
fd = QT_OPEN(encodedFileName, O_RDONLY);
if (fd == -1) {
#if defined(DEBUG_FONTENGINE)
- qErrnoWarning("QFontEngineQPF: unable to open %s", encodedName.constData());
+ qErrnoWarning("QFontEngineQPF: unable to open %s", encodedFileName.constData());
#endif
return;
}
}
if (fd == -1) {
#if defined(DEBUG_FONTENGINE)
- qWarning("QFontEngineQPF: insufficient access rights to %s", encodedName.constData());
+ qWarning("QFontEngineQPF: insufficient access rights to %s", encodedFileName.constData());
#endif
return;
}
@@ -361,7 +361,7 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng
fd = QT_OPEN(encodedFileName, O_RDWR | O_EXCL | O_CREAT, 0644);
if (fd == -1) {
#if defined(DEBUG_FONTENGINE)
- qErrnoWarning(errno, "QFontEngineQPF: open() failed for %s", encodedName.constData());
+ qErrnoWarning(errno, "QFontEngineQPF: open() failed for %s", encodedFileName.constData());
#endif
return;
}
@@ -374,7 +374,7 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng
const QByteArray &data = buffer.data();
if (QT_WRITE(fd, data.constData(), data.size()) == -1) {
#if defined(DEBUG_FONTENGINE)
- qErrnoWarning(errno, "QFontEngineQPF: write() failed for %s", encodedName.constData());
+ qErrnoWarning(errno, "QFontEngineQPF: write() failed for %s", encodedFileName.constData());
#endif
return;
}
diff --git a/src/gui/text/qfontengine_qws.cpp b/src/gui/text/qfontengine_qws.cpp
index 4c6dff2..237842b 100644
--- a/src/gui/text/qfontengine_qws.cpp
+++ b/src/gui/text/qfontengine_qws.cpp
@@ -40,7 +40,6 @@
****************************************************************************/
#include "qfontengine_p.h"
-#include <private/qunicodetables_p.h>
#include <qwsdisplay_qws.h>
#include <qvarlengtharray.h>
#include <private/qpainter_p.h>
@@ -51,15 +50,17 @@
#include <qdebug.h>
-
#ifndef QT_NO_QWS_QPF
+#include "qplatformdefs.h"
#include "qfile.h"
-#include "qdir.h"
-#define QT_USE_MMAP
#include <stdlib.h>
+#if !defined(Q_OS_INTEGRITY)
+#define QT_USE_MMAP
+#endif
+
#ifdef QT_USE_MMAP
// for mmap
#include <unistd.h>
@@ -69,22 +70,17 @@
#include <fcntl.h>
#include <errno.h>
-# if defined(QT_LINUXBASE) && !defined(MAP_FILE)
- // LSB 3.2 does not define MAP_FILE
-# define MAP_FILE 0
-# endif
-
+#ifndef MAP_FILE
+# define MAP_FILE 0
+#endif
+#ifndef MAP_FAILED
+# define MAP_FAILED (void *)-1
#endif
-#endif // QT_NO_QWS_QPF
+#endif // QT_USE_MMAP
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_QWS_QPF
-QT_BEGIN_INCLUDE_NAMESPACE
-#include "qplatformdefs.h"
-QT_END_INCLUDE_NAMESPACE
-
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
unsigned int uc = str[i].unicode();
@@ -161,17 +157,10 @@ public:
QPFGlyphTree* more;
QPFGlyph* glyph;
public:
-#ifdef QT_USE_MMAP
QPFGlyphTree(uchar*& data)
{
read(data);
}
-#else
- QPFGlyphTree(QIODevice& f)
- {
- read(f);
- }
-#endif
~QPFGlyphTree()
{
@@ -237,7 +226,6 @@ private:
{
}
-#ifdef QT_USE_MMAP
void read(uchar*& data)
{
// All node data first
@@ -247,19 +235,7 @@ private:
// Then all video data
readData(data);
}
-#else
- void read(QIODevice& f)
- {
- // All node data first
- readNode(f);
- // Then all non-video data
- readMetrics(f);
- // Then all video data
- readData(f);
- }
-#endif
-#ifdef QT_USE_MMAP
void readNode(uchar*& data)
{
uchar rw = *data++;
@@ -285,38 +261,7 @@ private:
if ( more )
more->readNode(data);
}
-#else
- void readNode(QIODevice& f)
- {
- char rw;
- char cl;
- f.getChar(&rw);
- f.getChar(&cl);
- min = (rw << 8) | cl;
- f.getChar(&rw);
- f.getChar(&cl);
- max = (rw << 8) | cl;
- char flags;
- f.getChar(&flags);
- if ( flags & 1 )
- less = new QPFGlyphTree;
- else
- less = 0;
- if ( flags & 2 )
- more = new QPFGlyphTree;
- else
- more = 0;
- int n = max-min+1;
- glyph = new QPFGlyph[n];
-
- if ( less )
- less->readNode(f);
- if ( more )
- more->readNode(f);
- }
-#endif
-#ifdef QT_USE_MMAP
void readMetrics(uchar*& data)
{
int n = max-min+1;
@@ -329,22 +274,7 @@ private:
if ( more )
more->readMetrics(data);
}
-#else
- void readMetrics(QIODevice& f)
- {
- int n = max-min+1;
- for (int i=0; i<n; i++) {
- glyph[i].metrics = new QPFGlyphMetrics;
- f.read((char*)glyph[i].metrics, sizeof(QPFGlyphMetrics));
- }
- if ( less )
- less->readMetrics(f);
- if ( more )
- more->readMetrics(f);
- }
-#endif
-#ifdef QT_USE_MMAP
void readData(uchar*& data)
{
int n = max-min+1;
@@ -359,24 +289,6 @@ private:
if ( more )
more->readData(data);
}
-#else
- void readData(QIODevice& f)
- {
- int n = max-min+1;
- for (int i=0; i<n; i++) {
- QSize s( glyph[i].metrics->width, glyph[i].metrics->height );
- //############### s = qt_screen->mapToDevice( s );
- uint datasize = glyph[i].metrics->linestep * s.height();
- glyph[i].data = new uchar[datasize]; // ### deleted?
- f.read((char*)glyph[i].data, datasize);
- }
- if ( less )
- less->readData(f);
- if ( more )
- more->readData(f);
- }
-#endif
-
};
class QFontEngineQPF1Data
@@ -384,73 +296,58 @@ class QFontEngineQPF1Data
public:
QPFFontMetrics fm;
QPFGlyphTree *tree;
- void *mmapStart;
+ uchar *mmapStart;
size_t mmapLength;
-};
-
-#if defined(Q_OS_INTEGRITY)
-static void *qt_mmap(void *start, size_t length, int /*prot*/, int /*flags*/, int fd, off_t offset)
-{
- // INTEGRITY cannot mmap local files - load it into a local buffer
- if (::lseek(fd, offset, SEEK_SET) == -1) {
-# if defined(DEBUG_FONTENGINE)
- perror("lseek failed");
-# endif
- }
- void *buf = malloc(length);
- if (::read(fd, buf, length) != (ssize_t)length) {
-# if defined(DEBUG_FONTENGINE)
- perror("read failed");
-# endif
- }
-
- return buf;
-}
-#else
-static inline void *qt_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
-{
- return mmap(start, length, prot, flags, fd, offset);
-}
+#ifdef QT_USE_MMAP
+ bool used_mmap;
#endif
-
-
+};
QFontEngineQPF1::QFontEngineQPF1(const QFontDef&, const QString &fn)
{
cache_cost = 1;
- int f = QT_OPEN( QFile::encodeName(fn), O_RDONLY, 0);
- Q_ASSERT(f>=0);
+ int fd = QT_OPEN(QFile::encodeName(fn).constData(), O_RDONLY, 0);
+ if (fd == -1)
+ qFatal("Failed to open '%s'", QFile::encodeName(fn).constData());
+
QT_STATBUF st;
- if ( QT_FSTAT( f, &st ) )
- qFatal("Failed to stat %s",QFile::encodeName(fn).data());
- uchar* data = (uchar*)qt_mmap( 0, // any address
- st.st_size, // whole file
- PROT_READ, // read-only memory
-#if defined(Q_OS_INTEGRITY)
- 0,
-#elif !defined(Q_OS_SOLARIS) && !defined(Q_OS_QNX4) && !defined(Q_OS_VXWORKS)
- MAP_FILE | MAP_PRIVATE, // swap-backed map from file
-#else
- MAP_PRIVATE,
-#endif
- f, 0 ); // from offset 0 of f
-#if !defined(MAP_FAILED) && (defined(Q_OS_QNX4) || defined(Q_OS_INTEGRITY))
-#define MAP_FAILED ((void *)-1)
-#endif
- if ( !data || data == (uchar*)MAP_FAILED )
- qFatal("Failed to mmap %s",QFile::encodeName(fn).data());
- QT_CLOSE(f);
+ if (QT_FSTAT(fd, &st) != 0)
+ qFatal("Failed to stat '%s'", QFile::encodeName(fn).constData());
d = new QFontEngineQPF1Data;
- d->mmapStart = data;
+ d->mmapStart = 0;
d->mmapLength = st.st_size;
- memcpy(reinterpret_cast<char*>(&d->fm),data,sizeof(d->fm));
- data += sizeof(d->fm);
- d->tree = new QPFGlyphTree(data);
- glyphFormat = (d->fm.flags & FM_SMOOTH) ? QFontEngineGlyphCache::Raster_A8
- : QFontEngineGlyphCache::Raster_Mono;
+#ifdef QT_USE_MMAP
+ d->used_mmap = true;
+ d->mmapStart = (uchar *)::mmap(0, st.st_size, // any address, whole file
+ PROT_READ, // read-only memory
+ MAP_FILE | MAP_PRIVATE, // swap-backed map from file
+ fd, 0); // from offset 0 of fd
+ if (d->mmapStart == (uchar *)MAP_FAILED)
+ d->mmapStart = 0;
+#endif
+
+ if (!d->mmapStart) {
+#ifdef QT_USE_MMAP
+ d->used_mmap = false;
+#endif
+ d->mmapStart = new uchar[d->mmapLength];
+ if (QT_READ(fd, d->mmapStart, d->mmapLength) != d->mmapLength)
+ qFatal("Failed to read '%s'", QFile::encodeName(fn).constData());
+ }
+ QT_CLOSE(fd);
+
+ if (d->mmapStart) {
+ uchar* data = d->mmapStart;
+
+ memcpy(reinterpret_cast<char*>(&d->fm), data, sizeof(d->fm));
+ data += sizeof(d->fm);
+
+ d->tree = new QPFGlyphTree(data);
+ glyphFormat = (d->fm.flags & FM_SMOOTH) ? QFontEngineGlyphCache::Raster_A8
+ : QFontEngineGlyphCache::Raster_Mono;
#if 0
qDebug() << "font file" << fn
<< "ascent" << d->fm.ascent << "descent" << d->fm.descent
@@ -462,12 +359,19 @@ QFontEngineQPF1::QFontEngineQPF1(const QFontDef&, const QString &fn)
<< "underlinepos" << d->fm.underlinepos
<< "underlinewidth" << d->fm.underlinewidth;
#endif
+ }
}
QFontEngineQPF1::~QFontEngineQPF1()
{
- if (d->mmapStart)
- munmap(d->mmapStart, d->mmapLength);
+ if (d->mmapStart) {
+#if defined(QT_USE_MMAP)
+ if (d->used_mmap)
+ ::munmap(d->mmapStart, d->mmapLength);
+ else
+#endif
+ delete [] d->mmapStart;
+ }
delete d->tree;
delete d;
}
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp
index d8192b7..c985427 100644
--- a/src/gui/text/qstatictext.cpp
+++ b/src/gui/text/qstatictext.cpp
@@ -427,14 +427,17 @@ namespace {
public:
DrawTextItemRecorder(bool untransformedCoordinates, bool useBackendOptimizations)
: m_dirtyPen(false), m_useBackendOptimizations(useBackendOptimizations),
- m_untransformedCoordinates(untransformedCoordinates)
+ m_untransformedCoordinates(untransformedCoordinates), m_currentColor(Qt::black)
{
}
virtual void updateState(const QPaintEngineState &newState)
{
- if (newState.state() & QPaintEngine::DirtyPen)
+ if (newState.state() & QPaintEngine::DirtyPen
+ && newState.pen().color() != m_currentColor) {
m_dirtyPen = true;
+ m_currentColor = newState.pen().color();
+ }
}
virtual void drawTextItem(const QPointF &position, const QTextItem &textItem)
@@ -450,7 +453,7 @@ namespace {
currentItem.positionOffset = m_glyphs.size(); // Offset into position pool
currentItem.useBackendOptimizations = m_useBackendOptimizations;
if (m_dirtyPen)
- currentItem.color = state->pen().color();
+ currentItem.color = m_currentColor;
QTransform matrix = m_untransformedCoordinates ? QTransform() : state->transform();
matrix.translate(position.x(), position.y());
@@ -521,6 +524,7 @@ namespace {
bool m_dirtyPen;
bool m_useBackendOptimizations;
bool m_untransformedCoordinates;
+ QColor m_currentColor;
};
class DrawTextItemDevice: public QPaintDevice