Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/text/qfontengine_qpf.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5252#include "private/qfontengine_ft_p.h"
    5353#endif
     54#include "private/qcore_unix_p.h" // overrides QT_OPEN
    5455
    5556// for mmap
     
    6667#ifndef QT_NO_QWS_QPF2
    6768
     69#include "qpfutil.cpp"
     70
    6871QT_BEGIN_INCLUDE_NAMESPACE
    69 #include "qpfutil.cpp"
    7072
    7173#if defined(Q_WS_QWS)
     
    253255        const QByteArray fileName = QFile::encodeName(dir.absoluteFilePath(dir[i]));
    254256
    255         int fd = ::open(fileName.constData(), O_RDONLY);
     257        int fd = QT_OPEN(fileName.constData(), O_RDONLY, 0);
    256258        if (fd >= 0) {
    257259            void *header = ::mmap(0, sizeof(QFontEngineQPF::Header), PROT_READ, MAP_SHARED, fd, 0);
     
    266268                ::munmap(header, sizeof(QFontEngineQPF::Header));
    267269            }
    268             ::close(fd);
     270            QT_CLOSE(fd);
    269271        }
    270272    }
     
    309311
    310312#if defined(DEBUG_FONTENGINE)
    311     qDebug() << "QFontEngineQPF::QFontEngineQPF( fd =" << fd << ", renderingFontEngine =" << renderingFontEngine << ")";
     313    qDebug() << "QFontEngineQPF::QFontEngineQPF( fd =" << fd << ", renderingFontEngine =" << renderingFontEngine << ')';
    312314#endif
    313315
     
    317319            return;
    318320
    319         fileName = fontDef.family.toLower() + QLatin1String("_")
     321        fileName = fontDef.family.toLower() + QLatin1Char('_')
    320322                   + QString::number(fontDef.pixelSize)
    321                    + QLatin1String("_") + QString::number(fontDef.weight)
     323                   + QLatin1Char('_') + QString::number(fontDef.weight)
    322324                   + (fontDef.style != QFont::StyleNormal ?
    323325                      QLatin1String("_italic") : QLatin1String(""))
     
    326328        fileName.prepend(qws_fontCacheDir());
    327329
    328         const QByteArray encodedName = QFile::encodeName(fileName);
    329         if (::access(encodedName, F_OK) == 0) {
     330        encodedFileName = QFile::encodeName(fileName);
     331        if (::access(encodedFileName, F_OK) == 0) {
    330332#if defined(DEBUG_FONTENGINE)
    331333            qDebug() << "found existing qpf:" << fileName;
    332334#endif
    333             if (::access(encodedName, W_OK | R_OK) == 0)
    334                 fd = ::open(encodedName, O_RDWR);
    335             else if (::access(encodedName, R_OK) == 0)
    336                 fd = ::open(encodedName, O_RDONLY);
     335            if (::access(encodedFileName, W_OK | R_OK) == 0) {
     336                fd = QT_OPEN(encodedFileName, O_RDWR);
     337            }
     338            // read-write access failed - try read-only access
     339            if (fd == -1 && ::access(encodedFileName, R_OK) == 0) {
     340                fd = QT_OPEN(encodedFileName, O_RDONLY);
     341                if (fd == -1) {
     342#if defined(DEBUG_FONTENGINE)
     343                    qErrnoWarning("QFontEngineQPF: unable to open %s", encodedName.constData());
     344#endif
     345                    return;
     346                }
     347            }
     348            if (fd == -1) {
     349#if defined(DEBUG_FONTENGINE)
     350                qWarning("QFontEngineQPF: insufficient access rights to %s", encodedName.constData());
     351#endif
     352                return;
     353            }
    337354        } else {
    338355#if defined(DEBUG_FONTENGINE)
     
    340357#endif
    341358            if (::access(QFile::encodeName(qws_fontCacheDir()), W_OK) == 0) {
    342                 fd = ::open(encodedName, O_RDWR | O_EXCL | O_CREAT, 0644);
     359                fd = QT_OPEN(encodedFileName, O_RDWR | O_EXCL | O_CREAT, 0644);
     360                if (fd == -1) {
     361#if defined(DEBUG_FONTENGINE)
     362                    qErrnoWarning(errno, "QFontEngineQPF: open() failed for %s", encodedName.constData());
     363#endif
     364                    return;
     365                }
    343366
    344367                QBuffer buffer;
     
    348371                buffer.close();
    349372                const QByteArray &data = buffer.data();
    350                 ::write(fd, data.constData(), data.size());
     373                if (QT_WRITE(fd, data.constData(), data.size()) == -1) {
     374#if defined(DEBUG_FONTENGINE)
     375                    qErrnoWarning(errno, "QFontEngineQPF: write() failed for %s", encodedName.constData());
     376#endif
     377                    return;
     378                }
     379            } else {
     380#if defined(DEBUG_FONTENGINE)
     381                qErrnoWarning(errno, "QFontEngineQPF: access() failed for %s", qPrintable(qws_fontCacheDir()));
     382#endif
     383                return;
    351384            }
    352385        }
     
    356389    if (QT_FSTAT(fd, &st)) {
    357390#if defined(DEBUG_FONTENGINE)
    358         qDebug() << "stat failed!";
     391        qErrnoWarning(errno, "QFontEngineQPF: fstat failed!");
    359392#endif
    360393        return;
     
    475508#if defined(Q_WS_QWS)
    476509    if (isValid() && renderingFontEngine)
    477         qt_fbdpy->sendFontCommand(QWSFontCommand::StartedUsingFont, QFile::encodeName(fileName));
     510        qt_fbdpy->sendFontCommand(QWSFontCommand::StartedUsingFont, encodedFileName);
    478511#endif
    479512}
     
    482515{
    483516#if defined(Q_WS_QWS)
    484     if (isValid() && renderingFontEngine)
    485         qt_fbdpy->sendFontCommand(QWSFontCommand::StoppedUsingFont, QFile::encodeName(fileName));
     517    if (isValid() && renderingFontEngine) {
     518        QT_TRY {
     519            qt_fbdpy->sendFontCommand(QWSFontCommand::StoppedUsingFont, encodedFileName);
     520        } QT_CATCH(...) {
     521            qDebug("QFontEngineQPF::~QFontEngineQPF: Out of memory");
     522            // ignore.
     523        }
     524    }
    486525#endif
    487526    delete renderingFontEngine;
    488     if (fontData)
    489         munmap((void *)fontData, dataSize);
     527    if (fontData) {
     528        if (munmap((void *)fontData, dataSize) == -1) {
     529#if defined(DEBUG_FONTENGINE)
     530            qErrnoWarning(errno, "~QFontEngineQPF: Unable to munmap");
     531#endif
     532        }
     533    }
    490534    if (fd != -1)
    491535        ::close(fd);
     
    551595            QChar c(uc);
    552596            if (!findGlyph(glyphs[glyph_pos].glyph) && !seenGlyphs.contains(c))
    553                 qDebug() << "glyph for character" << c << "/" << hex << uc << "is" << dec << glyphs[glyph_pos].glyph;
     597                qDebug() << "glyph for character" << c << '/' << hex << uc << "is" << dec << glyphs[glyph_pos].glyph;
    554598
    555599            seenGlyphs.insert(c);
     
    585629    const Glyph *glyph = findGlyph(g);
    586630    if (!glyph)
    587         QImage();
     631        return QImage();
    588632
    589633    const uchar *bits = ((const uchar *) glyph) + sizeof(Glyph);
     
    591635    QImage image(glyph->width, glyph->height, QImage::Format_Indexed8);
    592636    for (int j=0; j<256; ++j)
    593         image.setColor(j, 0xff000000 | j | (j<<8) | (j<<16));
     637        image.setColor(j, qRgba(0, 0, 0, j));
    594638
    595639    for (int i=0; i<glyph->height; ++i) {
     
    776820
    777821    // ### not perfect
    778     const int ysize = fontDef.pixelSize << 6;
     822    const int ysize = qRound(fontDef.pixelSize * qreal(64));
    779823    const int xsize = ysize;
    780824
     
    894938    g.advance = qRound(metrics.xoff);
    895939
    896     ::write(fd, &g, sizeof(g));
    897     ::write(fd, img.bits(), img.numBytes());
     940    QT_WRITE(fd, &g, sizeof(g));
     941    QT_WRITE(fd, img.bits(), img.byteCount());
    898942
    899943    glyphPos = oldSize - glyphDataOffset;
     
    905949    gmap[glyph] = qToBigEndian(glyphPos);
    906950
    907     glyphDataSize = glyphPos + sizeof(g) + img.numBytes();
     951    glyphDataSize = glyphPos + sizeof(g) + img.byteCount();
    908952    quint32 *blockSizePtr = (quint32 *)(fontData + glyphDataOffset - 4);
    909953    *blockSizePtr = qToBigEndian(glyphDataSize);
     
    11291173#endif // QT_NO_QWS_QPF2
    11301174
     1175/*
     1176    Creates a new multi qws engine.
     1177
     1178    This function takes ownership of the QFontEngine, increasing it's refcount.
     1179*/
    11311180QFontEngineMultiQWS::QFontEngineMultiQWS(QFontEngine *fe, int _script, const QStringList &fallbacks)
    11321181    : QFontEngineMulti(fallbacks.size() + 1),
Note: See TracChangeset for help on using the changeset viewer.