Changeset 769 for trunk/src/gui/text


Ignore:
Timestamp:
Aug 2, 2010, 9:27:30 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r651 r769  
    896896        *width = lengthValueFromData(data.width, f);
    897897        *style = data.style;
    898         *color = brushFromData(data.color, pal);
     898        *color = data.color.type != BrushData::Invalid ? brushFromData(data.color, pal) : QBrush(QColor());
    899899        return;
    900900    }
  • trunk/src/gui/text/qfont.cpp

    r651 r769  
    646646    Returns the name of the font within the underlying window system.
    647647
    648     Only on X11 when Qt was built without FontConfig support the XLFD (X Logical Font Description)
    649     is returned; otherwise an empty string.
     648    On X11, this function will return an empty string if Qt is built with
     649    FontConfig support; otherwise the XLFD (X Logical Font Description) is
     650    returned.
    650651
    651652    Using the return value of this function is usually \e not \e
     
    820821        resolve_mask |= QFont::WeightResolved | QFont::StyleResolved;
    821822    }
     823
     824    if (italic)
     825        resolve_mask |= QFont::StyleResolved;
    822826
    823827    d->request.family = family;
     
    26412645QFontCache::~QFontCache()
    26422646{
     2647    clear();
    26432648    {
    26442649        EngineDataCache::ConstIterator it = engineDataCache.constBegin(),
  • trunk/src/gui/text/qfontdatabase.cpp

    r651 r769  
    8787#define SMOOTH_SCALABLE 0xffff
    8888
    89 extern int qt_defaultDpiY(); // in qfont.cpp
     89Q_GUI_EXPORT extern int qt_defaultDpiY(); // in qfont.cpp
    9090
    9191bool qt_enable_test_font = false;
     
    611611#if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
    612612// class with virtual destructor, derived in qfontdatabase_s60.cpp
    613 class QFontDatabaseS60Store
     613class QSymbianFontDatabaseExtras
    614614{
    615615public:
    616     virtual ~QFontDatabaseS60Store() {}
     616    virtual ~QSymbianFontDatabaseExtras() {}
    617617};
    618618#endif
     
    630630#endif
    631631#if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
    632           , s60Store(0)
     632          , symbianExtras(0)
    633633#endif
    634634    { }
     
    644644        count = 0;
    645645#if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
    646         if (s60Store) {
    647             delete s60Store;
    648             s60Store = 0;
     646        if (symbianExtras) {
     647            delete symbianExtras;
     648            symbianExtras = 0;
    649649        }
    650650#endif
     
    691691    QStringList fallbackFamilies;
    692692#elif defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
    693     const QFontDatabaseS60Store *s60Store;
     693    const QSymbianFontDatabaseExtras *symbianExtras;
    694694#endif
    695695
  • trunk/src/gui/text/qfontdatabase_s60.cpp

    r651 r769  
    5151#include <private/qcore_symbian_p.h>
    5252#if defined(QT_NO_FREETYPE)
    53 #include <OPENFONT.H>
     53#include <openfont.h>
    5454#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    5555#include <graphics/openfontrasterizer.h> // COpenFontRasterizer has moved to a new header file
     
    9393
    9494#if defined(QT_NO_FREETYPE)
    95 class QFontDatabaseS60StoreImplementation : public QFontDatabaseS60Store
     95class QSymbianFontDatabaseExtrasImplementation : public QSymbianFontDatabaseExtras
    9696{
    9797public:
    98     QFontDatabaseS60StoreImplementation();
    99     ~QFontDatabaseS60StoreImplementation();
    100 
    101     const QFontEngineS60Extensions *extension(const QString &typeface) const;
     98    QSymbianFontDatabaseExtrasImplementation();
     99    ~QSymbianFontDatabaseExtrasImplementation();
     100
     101    const QSymbianTypeFaceExtras *extras(const QString &typeface, bool bold, bool italic) const;
    102102
    103103private:
     
    105105    CFontStore *m_store;
    106106    COpenFontRasterizer *m_rasterizer;
    107     mutable QHash<QString, const QFontEngineS60Extensions *> m_extensions;
     107    mutable QList<const QSymbianTypeFaceExtras *> m_extras;
     108    mutable QHash<QString, const QSymbianTypeFaceExtras *> m_extrasHash;
    108109};
    109110
    110 QFontDatabaseS60StoreImplementation::QFontDatabaseS60StoreImplementation()
    111 {
    112     m_heap = User::ChunkHeap(NULL, 0x1000, 0x100000);
     111QSymbianFontDatabaseExtrasImplementation::QSymbianFontDatabaseExtrasImplementation()
     112{
     113    QStringList filters;
     114    filters.append(QLatin1String("*.ttf"));
     115    filters.append(QLatin1String("*.ccc"));
     116    filters.append(QLatin1String("*.ltt"));
     117    const QFileInfoList fontFiles = alternativeFilePaths(QLatin1String("resource\\Fonts"), filters);
     118
     119    const TInt heapMinLength = 0x1000;
     120    const TInt heapMaxLength = qMax(0x20000 * fontFiles.count(), heapMinLength);
     121    m_heap = User::ChunkHeap(NULL, heapMinLength, heapMaxLength);
    113122    QT_TRAP_THROWING(
    114123        m_store = CFontStore::NewL(m_heap);
     
    118127        CleanupStack::Pop(m_rasterizer););
    119128
    120     QStringList filters;
    121     filters.append(QString::fromLatin1("*.ttf"));
    122     filters.append(QString::fromLatin1("*.ccc"));
    123     const QFileInfoList fontFiles = alternativeFilePaths(QString::fromLatin1("resource\\Fonts"), filters);
    124129    foreach (const QFileInfo &fontFileInfo, fontFiles) {
    125130        const QString fontFile = QDir::toNativeSeparators(fontFileInfo.absoluteFilePath());
     
    128133    }
    129134}
    130 QFontDatabaseS60StoreImplementation::~QFontDatabaseS60StoreImplementation()
    131 {
    132     typedef QHash<QString, const QFontEngineS60Extensions *>::iterator iterator;
    133     for (iterator p = m_extensions.begin(); p != m_extensions.end(); ++p) {
     135
     136QSymbianFontDatabaseExtrasImplementation::~QSymbianFontDatabaseExtrasImplementation()
     137{
     138    typedef QList<const QSymbianTypeFaceExtras *>::iterator iterator;
     139    for (iterator p = m_extras.begin(); p != m_extras.end(); ++p) {
    134140        m_store->ReleaseFont((*p)->fontOwner());
    135141        delete *p;
     
    157163#endif // FNTSTORE_H_INLINES_SUPPORT_FMM
    158164
    159 const QFontEngineS60Extensions *QFontDatabaseS60StoreImplementation::extension(const QString &typeface) const
    160 {
    161     if (!m_extensions.contains(typeface)) {
     165const QSymbianTypeFaceExtras *QSymbianFontDatabaseExtrasImplementation::extras(const QString &typeface,
     166                                                                               bool bold, bool italic) const
     167{
     168    const QString searchKey = typeface + QString::number(int(bold)) + QString::number(int(italic));
     169    if (!m_extrasHash.contains(searchKey)) {
    162170        CFont* font = NULL;
    163         TFontSpec spec(qt_QString2TPtrC(typeface), 1);
    164         spec.iHeight = 1;
    165         const TInt err = m_store->GetNearestFontToDesignHeightInPixels(font, spec);
     171        TFontSpec searchSpec(qt_QString2TPtrC(typeface), 1);
     172        if (bold)
     173            searchSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
     174        if (italic)
     175            searchSpec.iFontStyle.SetPosture(EPostureItalic);
     176        const TInt err = m_store->GetNearestFontToDesignHeightInPixels(font, searchSpec);
    166177        Q_ASSERT(err == KErrNone && font);
    167178        const CBitmapFont *bitmapFont = static_cast<CBitmapFont*>(font);
     
    172183            OpenFontFromBitmapFont(bitmapFont);
    173184#endif // FNTSTORE_H_INLINES_SUPPORT_FMM
    174         m_extensions.insert(typeface, new QFontEngineS60Extensions(font, openFont));
    175     }
    176     return m_extensions.value(typeface);
     185        const TOpenFontFaceAttrib* const attrib = openFont->FaceAttrib();
     186        const QString foundKey =
     187                QString((const QChar*)attrib->FullName().Ptr(), attrib->FullName().Length());
     188        if (!m_extrasHash.contains(foundKey)) {
     189            QSymbianTypeFaceExtras *extras = new QSymbianTypeFaceExtras(font, openFont);
     190            m_extras.append(extras);
     191            m_extrasHash.insert(searchKey, extras);
     192            m_extrasHash.insert(foundKey, extras);
     193        } else {
     194            m_store->ReleaseFont(font);
     195            m_extrasHash.insert(searchKey, m_extrasHash.value(foundKey));
     196        }
     197    }
     198    return m_extrasHash.value(searchKey);
    177199}
    178200#else
     
    241263
    242264#if defined(QT_NO_FREETYPE)
    243     if (!db->s60Store)
    244         db->s60Store = new QFontDatabaseS60StoreImplementation;
     265    if (!db->symbianExtras)
     266        db->symbianExtras = new QSymbianFontDatabaseExtrasImplementation;
    245267
    246268    QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
    247269   
    248270    const int numTypeFaces = QS60Data::screenDevice()->NumTypefaces();
    249     const QFontDatabaseS60StoreImplementation *store =
    250             static_cast<const QFontDatabaseS60StoreImplementation*>(db->s60Store);
     271    const QSymbianFontDatabaseExtrasImplementation *dbExtras =
     272            static_cast<const QSymbianFontDatabaseExtrasImplementation*>(db->symbianExtras);
    251273    bool fontAdded = false;
    252274    for (int i = 0; i < numTypeFaces; i++) {
     
    274296            style->pixelSize(0, true);
    275297
    276             const QFontEngineS60Extensions *extension = store->extension(familyName);
    277             const QByteArray os2Table = extension->getSfntTable(MAKE_TAG('O', 'S', '/', '2'));
     298            const QSymbianTypeFaceExtras *typeFaceExtras =
     299                    dbExtras->extras(familyName, faceAttrib.IsBold(), faceAttrib.IsItalic());
     300            const QByteArray os2Table = typeFaceExtras->getSfntTable(MAKE_TAG('O', 'S', '/', '2'));
    278301            const unsigned char* data = reinterpret_cast<const unsigned char*>(os2Table.constData());
    279302            const unsigned char* ulUnicodeRange = data + 42;
     
    333356}
    334357
     358bool QFontDatabase::removeAllApplicationFonts()
     359{
     360    return false;
     361}
     362
    335363bool QFontDatabase::supportsThreadedFontRendering()
    336364{
     
    390418        request.family = fontFamily;
    391419#if defined(QT_NO_FREETYPE)
    392         const QFontDatabaseS60StoreImplementation *store =
    393                 static_cast<const QFontDatabaseS60StoreImplementation*>(db->s60Store);
    394         const QFontEngineS60Extensions *extension = store->extension(fontFamily);
    395         fe = new QFontEngineS60(request, extension);
     420        const QSymbianFontDatabaseExtrasImplementation *dbExtras =
     421                static_cast<const QSymbianFontDatabaseExtrasImplementation*>(db->symbianExtras);
     422        const QSymbianTypeFaceExtras *typeFaceExtras =
     423                dbExtras->extras(fontFamily, request.weight > QFont::Normal, request.style != QFont::StyleNormal);
     424        fe = new QFontEngineS60(request, typeFaceExtras);
    396425#else
    397426        QFontEngine::FaceId faceId;
  • trunk/src/gui/text/qfontdatabase_win.cpp

    r651 r769  
    337337            };
    338338            QList<QFontDatabase::WritingSystem> systems = determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange);
    339             for (int i = 0; i < systems.count(); ++i)
    340                 family->writingSystems[systems.at(i)] = QtFontFamily::Supported;
     339
     340            for (int i = 0; i < systems.count(); ++i) {
     341                QFontDatabase::WritingSystem writingSystem = systems.at(i);
     342
     343                // ### Hack to work around problem with Thai text on Windows 7. Segoe UI contains
     344                // the symbol for Baht, and Windows thus reports that it supports the Thai script.
     345                // Since it's the default UI font on this platform, most widgets will be unable to
     346                // display Thai text by default. As a temporary work around, we special case Segoe UI
     347                // and remove the Thai script from its list of supported writing systems.
     348                if (writingSystem != QFontDatabase::Thai || familyName != QLatin1String("Segoe UI"))
     349                    family->writingSystems[writingSystem] = QtFontFamily::Supported;
     350            }
    341351        } else if (!family->writingSystemCheck) {
    342352            //qDebug("family='%s' script=%s", family->name.latin1(), script.latin1());
  • trunk/src/gui/text/qfontengine.cpp

    r651 r769  
    358358            }
    359359        } else {
    360             positions.resize(glyphs.numGlyphs);
    361             glyphs_out.resize(glyphs.numGlyphs);
    362             int i = 0;
    363360            while (i < glyphs.numGlyphs) {
    364361                if (!glyphs.attributes[i].dontPrint) {
     
    383380}
    384381
     382void QFontEngine::getGlyphBearings(glyph_t glyph, qreal *leftBearing, qreal *rightBearing)
     383{
     384    glyph_metrics_t gi = boundingBox(glyph);
     385    bool isValid = gi.isValid();
     386    if (leftBearing != 0)
     387        *leftBearing = isValid ? gi.x.toReal() : 0.0;
     388    if (rightBearing != 0)
     389        *rightBearing = isValid ? (gi.xoff - gi.x - gi.width).toReal() : 0.0;
     390}
    385391
    386392glyph_metrics_t QFontEngine::tightBoundingBox(const QGlyphLayout &glyphs)
     
    13891395}
    13901396
     1397void QFontEngineMulti::getGlyphBearings(glyph_t glyph, qreal *leftBearing, qreal *rightBearing)
     1398{
     1399    int which = highByte(glyph);
     1400    engine(which)->getGlyphBearings(stripped(glyph), leftBearing, rightBearing);
     1401}
     1402
    13911403void QFontEngineMulti::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs,
    13921404                                        QPainterPath *path, QTextItem::RenderFlags flags)
  • trunk/src/gui/text/qfontengine_p.h

    r651 r769  
    207207    virtual qreal minRightBearing() const { return qreal(); }
    208208
     209    virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0);
     210
    209211    virtual const char *name() const = 0;
    210212
     
    375377    virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const;
    376378    virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags);
     379    virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0);
    377380
    378381    virtual QFixed ascent() const;
  • trunk/src/gui/text/qfontengine_s60.cpp

    r651 r769  
    4545#include <private/qapplication_p.h>
    4646#include "qimage.h"
    47 #include "qt_s60_p.h"
     47#include <private/qt_s60_p.h>
    4848
    4949#include <e32base.h>
     
    5454QT_BEGIN_NAMESPACE
    5555
    56 QFontEngineS60Extensions::QFontEngineS60Extensions(CFont* fontOwner, COpenFont *font)
     56QSymbianTypeFaceExtras::QSymbianTypeFaceExtras(CFont* fontOwner, COpenFont *font)
    5757    : m_font(font)
    5858    , m_cmap(0)
     
    6060    , m_fontOwner(fontOwner)
    6161{
    62     TAny *shapingExtension = NULL;
    63     m_font->ExtendedInterface(KUidOpenFontShapingExtension, shapingExtension);
    64     m_shapingExtension = static_cast<MOpenFontShapingExtension*>(shapingExtension);
    6562    TAny *trueTypeExtension = NULL;
    6663    m_font->ExtendedInterface(KUidOpenFontTrueTypeExtension, trueTypeExtension);
    6764    m_trueTypeExtension = static_cast<MOpenFontTrueTypeExtension*>(trueTypeExtension);
    68     Q_ASSERT(m_shapingExtension && m_trueTypeExtension);
    69 }
    70 
    71 QByteArray QFontEngineS60Extensions::getSfntTable(uint tag) const
     65    Q_ASSERT(m_trueTypeExtension);
     66}
     67
     68QByteArray QSymbianTypeFaceExtras::getSfntTable(uint tag) const
    7269{
    7370    Q_ASSERT(m_trueTypeExtension->HasTrueTypeTable(tag));
     
    8077}
    8178
    82 const unsigned char *QFontEngineS60Extensions::cmap() const
     79bool QSymbianTypeFaceExtras::getSfntTableData(uint tag, uchar *buffer, uint *length) const
     80{
     81    if (!m_trueTypeExtension->HasTrueTypeTable(tag))
     82        return false;
     83
     84    bool result = true;
     85    TInt error = KErrNone;
     86    TInt tableByteLength;
     87    TAny *table =
     88        q_check_ptr(m_trueTypeExtension->GetTrueTypeTable(error, tag, &tableByteLength));
     89
     90    if (error != KErrNone) {
     91        return false;
     92    } else if (*length > 0 && *length < tableByteLength) {
     93        result = false; // Caller did not allocate enough memory
     94    } else {
     95        *length = tableByteLength;
     96        if (buffer)
     97            qMemCopy(buffer, table, tableByteLength);
     98    }
     99
     100    m_trueTypeExtension->ReleaseTrueTypeTable(table);
     101    return result;
     102}
     103
     104const unsigned char *QSymbianTypeFaceExtras::cmap() const
    83105{
    84106    if (!m_cmap) {
     
    90112}
    91113
    92 QPainterPath QFontEngineS60Extensions::glyphOutline(glyph_t glyph) const
    93 {
    94     QPainterPath result;
    95     QPolygonF polygon;
    96     TInt glyphIndex = glyph;
    97     TInt pointNumber = 0;
    98     TInt x, y;
    99     while (m_shapingExtension->GlyphPointInFontUnits(glyphIndex, pointNumber++, x, y)) {
    100         const QPointF point(qreal(x) / 0xffff, qreal(y) / 0xffff);
    101         if (polygon.contains(point)) {
    102             result.addPolygon(polygon);
    103             result.closeSubpath();
    104             polygon.clear();
    105         } else {
    106             polygon.append(point);
    107         }
    108     }
    109     return result;
    110 }
    111 
    112 CFont *QFontEngineS60Extensions::fontOwner() const
     114CFont *QSymbianTypeFaceExtras::fontOwner() const
    113115{
    114116    return m_fontOwner;
     
    168170}
    169171
    170 QFontEngineS60::QFontEngineS60(const QFontDef &request, const QFontEngineS60Extensions *extensions)
    171     : m_extensions(extensions)
     172QFontEngineS60::QFontEngineS60(const QFontDef &request, const QSymbianTypeFaceExtras *extras)
     173    : m_extras(extras)
    172174    , m_originalFont(0)
    173175    , m_originalFontSizeInPixels((request.pixelSize >= 0)?
     
    196198
    197199    HB_Glyph *g = glyphs->glyphs;
    198     const unsigned char* cmap = m_extensions->cmap();
     200    const unsigned char* cmap = m_extras->cmap();
     201    const bool isRtl = (flags & QTextEngine::RightToLeft);
    199202    for (int i = 0; i < len; ++i) {
    200203        const unsigned int uc = getChar(characters, i, len);
    201         *g++ = QFontEngine::getTrueTypeGlyphIndex(cmap, uc);
     204        *g++ = QFontEngine::getTrueTypeGlyphIndex(cmap,
     205                        isRtl ? QChar::mirroredChar(uc) : uc);
    202206    }
    203207
     
    217221    for (int i = 0; i < glyphs->numGlyphs; i++) {
    218222        const glyph_metrics_t bbox = boundingBox_const(glyphs->glyphs[i]);
    219         glyphs->advances_x[i] = glyphs->offsets[i].x = bbox.xoff;
    220         glyphs->advances_y[i] = glyphs->offsets[i].y = bbox.yoff;
     223        glyphs->advances_x[i] = bbox.xoff;
     224        glyphs->advances_y[i] = bbox.yoff;
    221225    }
    222226}
     
    313317bool QFontEngineS60::canRender(const QChar *string, int len)
    314318{
    315     const unsigned char *cmap = m_extensions->cmap();
     319    const unsigned char *cmap = m_extras->cmap();
    316320    for (int i = 0; i < len; ++i) {
    317321        const unsigned int uc = getChar(string, i, len);
     
    324328QByteArray QFontEngineS60::getSfntTable(uint tag) const
    325329{
    326     return m_extensions->getSfntTable(tag);
     330    return m_extras->getSfntTable(tag);
     331}
     332
     333bool QFontEngineS60::getSfntTableData(uint tag, uchar *buffer, uint *length) const
     334{
     335    return m_extras->getSfntTableData(tag, buffer, length);
    327336}
    328337
  • trunk/src/gui/text/qfontengine_s60_p.h

    r651 r769  
    5757#include "qfontengine_p.h"
    5858#include "qsize.h"
    59 #include <OPENFONT.H>
     59#include <openfont.h>
    6060
    61 class CFbsBitmap;
    62 class CFbsBitmapDevice;
    63 class CFbsBitGc;
    6461class CFont;
    6562
    6663QT_BEGIN_NAMESPACE
    6764
    68 // ..gives us access to truetype tables, UTF-16<->GlyphID mapping, and glyph outlines
    69 class QFontEngineS60Extensions
     65// ..gives us access to truetype tables
     66class QSymbianTypeFaceExtras
    7067{
    7168public:
    72     QFontEngineS60Extensions(CFont* fontOwner, COpenFont *font);
     69    QSymbianTypeFaceExtras(CFont* fontOwner, COpenFont *font);
    7370
    7471    QByteArray getSfntTable(uint tag) const;
     72    bool getSfntTableData(uint tag, uchar *buffer, uint *length) const;
    7573    const unsigned char *cmap() const;
    76     QPainterPath glyphOutline(glyph_t glyph) const;
    7774    CFont *fontOwner() const;
    7875
    7976private:
    8077    COpenFont *m_font;
    81     const MOpenFontShapingExtension *m_shapingExtension;
    8278    mutable MOpenFontTrueTypeExtension *m_trueTypeExtension;
    8379    mutable const unsigned char *m_cmap;
     
    9086{
    9187public:
    92     QFontEngineS60(const QFontDef &fontDef, const QFontEngineS60Extensions *extensions);
     88    QFontEngineS60(const QFontDef &fontDef, const QSymbianTypeFaceExtras *extras);
    9389    ~QFontEngineS60();
    9490
     
    110106
    111107    QByteArray getSfntTable(uint tag) const;
     108    bool getSfntTableData(uint tag, uchar *buffer, uint *length) const;
    112109
    113110    static qreal pixelsToPoints(qreal pixels, Qt::Orientation orientation = Qt::Horizontal);
     
    130127    static void releaseFont(CFont *&font);
    131128
    132     const QFontEngineS60Extensions *m_extensions;
     129    const QSymbianTypeFaceExtras *m_extras;
    133130    CFont* m_originalFont;
    134131    const qreal m_originalFontSizeInPixels;
  • trunk/src/gui/text/qfontengine_win.cpp

    r651 r769  
    4040****************************************************************************/
    4141
     42#if _WIN32_WINNT < 0x0500
     43#undef _WIN32_WINNT
     44#define _WIN32_WINNT 0x0500
     45#endif
     46
    4247#include "qfontengine_p.h"
    4348#include "qtextengine_p.h"
     
    650655static const int char_table_entries = sizeof(char_table)/sizeof(ushort);
    651656
     657#ifndef Q_CC_MINGW
     658void QFontEngineWin::getGlyphBearings(glyph_t glyph, qreal *leftBearing, qreal *rightBearing)
     659{
     660    HDC hdc = shared_dc();
     661    SelectObject(hdc, hfont);
     662
     663#ifndef Q_WS_WINCE
     664    if (ttf)
     665#endif
     666
     667    {
     668        ABC abcWidths;
     669        GetCharABCWidthsI(hdc, glyph, 1, 0, &abcWidths);
     670        if (leftBearing)
     671            *leftBearing = abcWidths.abcA;
     672        if (rightBearing)
     673            *rightBearing = abcWidths.abcC;
     674    }
     675
     676#ifndef Q_WS_WINCE
     677    else {
     678        QFontEngine::getGlyphBearings(glyph, leftBearing, rightBearing);
     679    }
     680#endif
     681}
     682#endif // Q_CC_MINGW
    652683
    653684qreal QFontEngineWin::minLeftBearing() const
  • trunk/src/gui/text/qfontengine_win_p.h

    r651 r769  
    107107    virtual QImage alphaRGBMapForGlyph(glyph_t t, int margin, const QTransform &xform);
    108108
     109#ifndef Q_CC_MINGW
     110    virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0);
     111#endif
     112
    109113    int getGlyphIndexes(const QChar *ch, int numChars, QGlyphLayout *glyphs, bool mirrored) const;
    110114    void getCMap();
  • trunk/src/gui/text/qfontmetrics.cpp

    r651 r769  
    6464                           int tabStops, int *tabArray, int tabArrayLen,
    6565                           QPainter *painter);
    66 extern int qt_defaultDpi();
     66Q_GUI_EXPORT extern int qt_defaultDpi();
    6767
    6868/*****************************************************************************
     
    473473    engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
    474474    // ### can nglyphs != 1 happen at all? Not currently I think
    475     glyph_metrics_t gi = engine->boundingBox(glyphs.glyphs[0]);
    476     return qRound(gi.x);
     475    qreal lb;
     476    engine->getGlyphBearings(glyphs.glyphs[0], &lb);
     477    return qRound(lb);
    477478}
    478479
     
    507508    engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
    508509    // ### can nglyphs != 1 happen at all? Not currently I think
    509     glyph_metrics_t gi = engine->boundingBox(glyphs.glyphs[0]);
    510     return qRound(gi.xoff - gi.x - gi.width);
     510    qreal rb;
     511    engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb);
     512    return qRound(rb);
    511513}
    512514
     
    13181320    engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
    13191321    // ### can nglyphs != 1 happen at all? Not currently I think
    1320     glyph_metrics_t gi = engine->boundingBox(glyphs.glyphs[0]);
    1321     return gi.x.toReal();
     1322    qreal lb;
     1323    engine->getGlyphBearings(glyphs.glyphs[0], &lb);
     1324    return lb;
    13221325}
    13231326
     
    13521355    engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
    13531356    // ### can nglyphs != 1 happen at all? Not currently I think
    1354     glyph_metrics_t gi = engine->boundingBox(glyphs.glyphs[0]);
    1355     return (gi.xoff - gi.x - gi.width).toReal();
     1357    qreal rb;
     1358    engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb);
     1359    return rb;
     1360
    13561361}
    13571362
  • trunk/src/gui/text/qtextcontrol.cpp

    r651 r769  
    12001200            cursor.setBlockFormat(blockFmt);
    12011201        } else {
    1202             cursor.deletePreviousChar();
     1202            QTextCursor localCursor = cursor;
     1203            localCursor.deletePreviousChar();
    12031204        }
    12041205        goto accept;
     
    12331234#endif
    12341235    else if (e == QKeySequence::Delete) {
    1235         cursor.deleteChar();
     1236        QTextCursor localCursor = cursor;
     1237        localCursor.deleteChar();
    12361238    }
    12371239    else if (e == QKeySequence::DeleteEndOfWord) {
  • trunk/src/gui/text/qtextdocument.cpp

    r651 r769  
    16321632}
    16331633
    1634 extern int qt_defaultDpi();
     1634Q_GUI_EXPORT extern int qt_defaultDpi();
    16351635
    16361636/*!
     
    16801680
    16811681    const QTextDocument *doc = this;
    1682     QTextDocument *clonedDoc = 0;
     1682    QScopedPointer<QTextDocument> clonedDoc;
    16831683    (void)doc->documentLayout(); // make sure that there is a layout
    16841684
     
    17131713    } else {
    17141714        doc = clone(const_cast<QTextDocument *>(this));
    1715         clonedDoc = const_cast<QTextDocument *>(doc);
     1715        clonedDoc.reset(const_cast<QTextDocument *>(doc));
    17161716
    17171717        for (QTextBlock srcBlock = firstBlock(), dstBlock = clonedDoc->firstBlock();
     
    17881788                if (printer->printerState() == QPrinter::Aborted
    17891789                    || printer->printerState() == QPrinter::Error)
    1790                     goto UserCanceled;
     1790                    return;
    17911791                printPage(page, &p, doc, body, pageNumberPos);
    17921792                if (j < pageCopies - 1)
     
    18081808            printer->newPage();
    18091809    }
    1810 
    1811 UserCanceled:
    1812     delete clonedDoc;
    18131810}
    18141811#endif
  • trunk/src/gui/text/qtextdocumentlayout.cpp

    r651 r769  
    7676QT_BEGIN_NAMESPACE
    7777
    78 extern int qt_defaultDpi();
     78Q_GUI_EXPORT extern int qt_defaultDpi();
    7979
    8080// ################ should probably add frameFormatChange notification!
  • trunk/src/gui/text/qtextengine.cpp

    r651 r769  
    8282    {
    8383        if ((int)caps == (int)QFont::SmallCaps)
    84             generateScriptItemsSmallCaps(m_string.utf16(), start, length);
     84            generateScriptItemsSmallCaps(reinterpret_cast<const ushort *>(m_string.unicode()), start, length);
    8585        else if(caps == QFont::Capitalize)
    8686            generateScriptItemsCapitalize(start, length);
     
    857857}
    858858
    859 extern int qt_defaultDpiY(); // in qfont.cpp
     859Q_GUI_EXPORT extern int qt_defaultDpiY(); // in qfont.cpp
    860860
    861861void QTextEngine::shapeText(int item) const
     
    14351435    }
    14361436
    1437     const ushort *unicode = layoutData->string.utf16();
    1438     // correctly assign script, isTab and isObject to the script analysis
    1439     const ushort *uc = unicode;
     1437    const ushort *uc = reinterpret_cast<const ushort *>(layoutData->string.unicode());
    14401438    const ushort *e = uc + length;
    14411439    int lastScript = QUnicodeTables::Common;
     
    16511649            }
    16521650
    1653             glyph_t glyph = glyphs.glyphs[logClusters[pos + ilen - 1]];
     1651            glyph_t glyph = glyphs.glyphs[logClusters[ilen - 1]];
    16541652            glyph_metrics_t gi = fe->boundingBox(glyph);
    16551653            if (gi.isValid())
     
    24982496}
    24992497
    2500 extern int qt_defaultDpiY();
     2498Q_GUI_EXPORT extern int qt_defaultDpiY();
    25012499
    25022500QFixed QTextEngine::calculateTabWidth(int item, QFixed x) const
  • trunk/src/gui/text/qtextengine_p.h

    r651 r769  
    383383    QFixed width;
    384384    QFixed textWidth;
     385    QFixed textAdvance;
    385386    int from;
    386387    signed int length : 29;
  • trunk/src/gui/text/qtextformat.cpp

    r651 r769  
    30863086        f.d->resolveFont(defaultFnt);
    30873087
    3088         hashes.insert(hash, idx);
     3088        if (!hashes.contains(hash, idx))
     3089            hashes.insert(hash, idx);
    30893090
    30903091    } QT_CATCH(...) {
  • trunk/src/gui/text/qtextimagehandler.cpp

    r651 r769  
    124124    QPaintDevice *pdev = doc->documentLayout()->paintDevice();
    125125    if (pdev) {
    126         extern int qt_defaultDpi();
     126        Q_GUI_EXPORT extern int qt_defaultDpi();
    127127        if (pm.isNull())
    128128            pm = getPixmap(doc, format);
  • trunk/src/gui/text/qtextlayout.cpp

    r651 r769  
    9090            align = Qt::AlignRight;
    9191        if (align & Qt::AlignRight)
    92             x = line.width - (line.textWidth + leadingSpaceWidth(eng, line));
     92            x = line.width - (line.textAdvance + leadingSpaceWidth(eng, line));
    9393        else if (align & Qt::AlignHCenter)
    94             x = (line.width - line.textWidth)/2;
     94            x = (line.width - line.textAdvance)/2;
    9595    }
    9696    return x;
     
    13321332    const QScriptLine &sl = d->lines[line];
    13331333
    1334     const qreal x = position.x() + l.cursorToX(cursorPosition);
     1334    qreal x = position.x() + l.cursorToX(cursorPosition);
    13351335
    13361336    int itm = d->findItem(cursorPosition - 1);
     
    13511351    if (toggleAntialiasing)
    13521352        p->setRenderHint(QPainter::Antialiasing);
     1353#if defined(QT_MAC_USE_COCOA)
     1354    // Always draw the cursor aligned to pixel boundary.
     1355    x = qRound(x);
     1356#endif
    13531357    p->fillRect(QRectF(x, y, qreal(width), (base + descent + 1).toReal()), p->pen().brush());
    13541358    if (toggleAntialiasing)
     
    16411645    struct LineBreakHelper
    16421646    {
    1643         LineBreakHelper() : glyphCount(0), maxGlyphs(0), manualWrap(false) {}
     1647        LineBreakHelper()
     1648            : glyphCount(0), maxGlyphs(0), currentPosition(0), fontEngine(0), logClusters(0),
     1649              manualWrap(false)
     1650        {
     1651        }
     1652
    16441653
    16451654        QScriptLine tmpData;
    16461655        QScriptLine spaceData;
    16471656
     1657        QGlyphLayout glyphs;
     1658
    16481659        int glyphCount;
    16491660        int maxGlyphs;
     1661        int currentPosition;
    16501662
    16511663        QFixed minw;
    16521664        QFixed softHyphenWidth;
    16531665        QFixed rightBearing;
     1666        QFixed minimumRightBearing;
     1667
     1668        QFontEngine *fontEngine;
     1669        const unsigned short *logClusters;
    16541670
    16551671        bool manualWrap;
    16561672
    16571673        bool checkFullOtherwiseExtend(QScriptLine &line);
     1674
     1675        QFixed calculateNewWidth(const QScriptLine &line) const {
     1676            return line.textWidth + tmpData.textWidth + spaceData.textWidth + softHyphenWidth
     1677                    - qMin(rightBearing, QFixed());
     1678        }
     1679
     1680        inline glyph_t currentGlyph() const
     1681        {
     1682            Q_ASSERT(currentPosition > 0);
     1683            return glyphs.glyphs[logClusters[currentPosition - 1]];
     1684        }
     1685
     1686        inline void adjustRightBearing()
     1687        {
     1688            if (currentPosition <= 0)
     1689                return;
     1690
     1691            qreal rb;
     1692            fontEngine->getGlyphBearings(currentGlyph(), 0, &rb);
     1693            rightBearing = qMin(QFixed(), QFixed::fromReal(rb));
     1694        }
     1695
     1696        inline void resetRightBearing()
     1697        {
     1698            rightBearing = QFixed(1); // Any positive number is defined as invalid since only
     1699                                      // negative right bearings are interesting to us.
     1700        }
    16581701    };
    16591702
     
    16621705    LB_DEBUG("possible break width %f, spacew=%f", tmpData.textWidth.toReal(), spaceData.textWidth.toReal());
    16631706
    1664     QFixed newWidth = line.textWidth + tmpData.textWidth + spaceData.textWidth + softHyphenWidth + rightBearing;
     1707    QFixed newWidth = calculateNewWidth(line);
    16651708    if (line.length && !manualWrap && (newWidth > line.width || glyphCount > maxGlyphs))
    16661709        return true;
     
    17381781
    17391782    const HB_CharAttributes *attributes = eng->attributes();
    1740     int pos = line.from;
     1783    lbh.currentPosition = line.from;
    17411784    int end = 0;
    1742     QGlyphLayout glyphs;
    1743     const unsigned short *logClusters = eng->layoutData->logClustersPtr;
     1785    lbh.logClusters = eng->layoutData->logClustersPtr;
    17441786
    17451787    while (newItem < eng->layoutData->items.size()) {
    1746         lbh.rightBearing = 0;
     1788        lbh.resetRightBearing();
    17471789        lbh.softHyphenWidth = 0;
    17481790        if (newItem != item) {
     
    17521794                eng->shape(item);
    17531795                attributes = eng->attributes();
    1754                 logClusters = eng->layoutData->logClustersPtr;
     1796                lbh.logClusters = eng->layoutData->logClustersPtr;
    17551797            }
    1756             pos = qMax(line.from, current.position);
     1798            lbh.currentPosition = qMax(line.from, current.position);
    17571799            end = current.position + eng->length(item);
    1758             glyphs = eng->shapedGlyphs(&current);
     1800            lbh.glyphs = eng->shapedGlyphs(&current);
    17591801        }
    17601802        const QScriptItem &current = eng->layoutData->items[item];
     1803        QFontEngine *fontEngine = eng->fontEngine(current);
     1804        if (lbh.fontEngine != fontEngine) {
     1805            lbh.fontEngine = fontEngine;
     1806            lbh.minimumRightBearing = qMin(QFixed(),
     1807                                           QFixed::fromReal(fontEngine->minRightBearing()));
     1808        }
    17611809
    17621810        lbh.tmpData.leading = qMax(lbh.tmpData.leading + lbh.tmpData.ascent,
     
    17881836                line.setDefaultHeight(eng);
    17891837            if (eng->option.flags() & QTextOption::ShowLineAndParagraphSeparators) {
    1790                 addNextCluster(pos, end, lbh.tmpData, lbh.glyphCount,
    1791                                current, logClusters, glyphs);
     1838                addNextCluster(lbh.currentPosition, end, lbh.tmpData, lbh.glyphCount,
     1839                               current, lbh.logClusters, lbh.glyphs);
    17921840            } else {
    17931841                lbh.tmpData.length++;
     
    18081856            if (lbh.checkFullOtherwiseExtend(line))
    18091857                goto found;
    1810         } else if (attributes[pos].whiteSpace) {
    1811             while (pos < end && attributes[pos].whiteSpace)
    1812                 addNextCluster(pos, end, lbh.spaceData, lbh.glyphCount,
    1813                                current, logClusters, glyphs);
     1858        } else if (attributes[lbh.currentPosition].whiteSpace) {
     1859            while (lbh.currentPosition < end && attributes[lbh.currentPosition].whiteSpace)
     1860                addNextCluster(lbh.currentPosition, end, lbh.spaceData, lbh.glyphCount,
     1861                               current, lbh.logClusters, lbh.glyphs);
    18141862
    18151863            if (!lbh.manualWrap && lbh.spaceData.textWidth > line.width) {
     
    18201868            bool sb_or_ws = false;
    18211869            do {
    1822                 addNextCluster(pos, end, lbh.tmpData, lbh.glyphCount,
    1823                                current, logClusters, glyphs);
    1824 
    1825                 if (attributes[pos].whiteSpace || attributes[pos-1].lineBreakType != HB_NoBreak) {
     1870                addNextCluster(lbh.currentPosition, end, lbh.tmpData, lbh.glyphCount,
     1871                               current, lbh.logClusters, lbh.glyphs);
     1872
     1873                if (attributes[lbh.currentPosition].whiteSpace || attributes[lbh.currentPosition-1].lineBreakType != HB_NoBreak) {
    18261874                    sb_or_ws = true;
    18271875                    break;
    1828                 } else if (breakany && attributes[pos].charStop) {
     1876                } else if (breakany && attributes[lbh.currentPosition].charStop) {
    18291877                    break;
    18301878                }
    1831             } while (pos < end);
     1879            } while (lbh.currentPosition < end);
    18321880            lbh.minw = qMax(lbh.tmpData.textWidth, lbh.minw);
    18331881
    1834             if (pos && attributes[pos - 1].lineBreakType == HB_SoftHyphen) {
     1882            if (lbh.currentPosition && attributes[lbh.currentPosition - 1].lineBreakType == HB_SoftHyphen) {
    18351883                // if we are splitting up a word because of
    18361884                // a soft hyphen then we ...
     
    18501898                //
    18511899                if (line.length)
    1852                     lbh.softHyphenWidth = glyphs.advances_x[logClusters[pos - 1]];
     1900                    lbh.softHyphenWidth = lbh.glyphs.advances_x[lbh.logClusters[lbh.currentPosition - 1]];
    18531901                else if (breakany)
    1854                     lbh.tmpData.textWidth += glyphs.advances_x[logClusters[pos - 1]];
     1902                    lbh.tmpData.textWidth += lbh.glyphs.advances_x[lbh.logClusters[lbh.currentPosition - 1]];
    18551903            }
    18561904
     
    18591907            // of the advance of the glyph, the bearing will be negative. We flip the sign
    18601908            // for the code to be more readable. Logic borrowed from qfontmetrics.cpp.
    1861             if (pos) {
    1862                 QFontEngine *fontEngine = eng->fontEngine(current);
    1863                 glyph_t glyph = glyphs.glyphs[logClusters[pos - 1]];
    1864                 glyph_metrics_t gi = fontEngine->boundingBox(glyph);
    1865                 if (gi.isValid())
    1866                     lbh.rightBearing = qMax(QFixed(), -(gi.xoff - gi.x - gi.width));
     1909            // We ignore the right bearing if the minimum negative bearing is too little to
     1910            // expand the text beyond the edge.
     1911            if (sb_or_ws|breakany) {
     1912                if (lbh.calculateNewWidth(line) + lbh.minimumRightBearing > line.width)
     1913                    lbh.adjustRightBearing();
     1914                if (lbh.checkFullOtherwiseExtend(line)) {
     1915                    if (!breakany) {
     1916                        line.textWidth += lbh.softHyphenWidth;
     1917                    }
     1918
     1919                    goto found;
     1920                }
    18671921            }
    1868 
    1869             if ((sb_or_ws|breakany) && lbh.checkFullOtherwiseExtend(line)) {
    1870                 if (!breakany) {
    1871                     line.textWidth += lbh.softHyphenWidth;
    1872                 }
    1873 
    1874                 line.textWidth += lbh.rightBearing;
    1875 
    1876                 goto found;
    1877             }
    1878         }
    1879         if (pos == end)
     1922        }
     1923        if (lbh.currentPosition == end)
    18801924            newItem = item + 1;
    18811925    }
    18821926    LB_DEBUG("reached end of line");
    18831927    lbh.checkFullOtherwiseExtend(line);
    1884     line.textWidth += lbh.rightBearing;
    1885 
    18861928found:       
     1929    if (lbh.rightBearing > 0) // If right bearing has not yet been adjusted
     1930        lbh.adjustRightBearing();
     1931    line.textAdvance = line.textWidth;
     1932    line.textWidth -= qMin(QFixed(), lbh.rightBearing);
     1933
    18871934    if (line.length == 0) {
    18881935        LB_DEBUG("no break available in line, adding temp: length %d, width %f, space: length %d, width %f",
  • trunk/src/gui/text/qzip.cpp

    r651 r769  
    5555
    5656#if defined(Q_OS_WIN)
    57 #undef S_IFREG
    58 #define S_IFREG 0100000
     57#  undef S_IFREG
     58#  define S_IFREG 0100000
     59#  ifndef S_IFDIR
     60#    define S_IFDIR 0040000
     61#  endif
    5962#  ifndef S_ISDIR
    60 #    define S_ISDIR(x) ((x) & 0040000) > 0
     63#    define S_ISDIR(x) ((x) & S_IFDIR) > 0
    6164#  endif
    6265#  ifndef S_ISREG
  • trunk/src/gui/text/qzipreader_p.h

    r651 r769  
    5050//
    5151// This file is not part of the Qt API.  It exists for the convenience
    52 // of the QLibrary class.  This header file may change from
     52// of the QZipReader class.  This header file may change from
    5353// version to version without notice, or even be removed.
    5454//
  • trunk/src/gui/text/qzipwriter_p.h

    r651 r769  
    4848//
    4949// This file is not part of the Qt API.  It exists for the convenience
    50 // of the QLibrary class.  This header file may change from
     50// of the QZipWriter class.  This header file may change from
    5151// version to version without notice, or even be removed.
    5252//
Note: See TracChangeset for help on using the changeset viewer.