Ignore:
Timestamp:
Nov 16, 2005, 8:36:46 PM (20 years ago)
Author:
dmik
Message:

Transferred Qt for OS/2 version 3.3.1-rc5 sources from the CVS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel/qfontdatabase.cpp

    r7 r8  
    7171#endif
    7272
     73#define SMOOTH_SCALABLE 0xffff
     74
    7375static int ucstricmp( const QString &as, const QString &bs )
    7476{
     
    138140    unsigned short pixelSize;
    139141
     142#ifdef Q_WS_PM
     143    unsigned short pointSize;                   // in deca-points
     144    LONG lMatch;
     145#endif
    140146#ifdef Q_WS_X11
    141147    int count;
     
    206212          fakeOblique( FALSE ), count( 0 ), pixelSizes( 0 )
    207213    {
    208 #if defined(Q_WS_X11)
     214#if defined(Q_WS_PM)
     215        szFacename[0] = 0;
     216#elif defined(Q_WS_X11)
    209217        weightName = setwidthName = 0;
    210 #endif // Q_WS_X11
     218#endif
    211219    }
    212220
     
    228236    QtFontSize *pixelSizes;
    229237
     238#ifdef Q_WS_PM
     239    CHAR szFacename [FACESIZE];
     240#endif
    230241#ifdef Q_WS_X11
    231242    const char *weightName;
     
    233244#endif // Q_WS_X11
    234245
     246#ifdef Q_WS_PM
     247    QtFontSize *pixelSize(
     248        unsigned short size, bool = FALSE, unsigned short pointSize = 0 );
     249#else   
    235250    QtFontSize *pixelSize( unsigned short size, bool = FALSE );
     251#endif   
    236252};
    237253
     
    247263}
    248264
     265#ifdef Q_WS_PM
     266QtFontSize *QtFontStyle::pixelSize(
     267    unsigned short size, bool add, unsigned short pointSize )
     268#else
    249269QtFontSize *QtFontStyle::pixelSize( unsigned short size, bool add )
     270#endif
    250271{
    251272    for ( int i = 0; i < count; i++ ) {
     273#ifdef Q_WS_PM
     274        if (
     275            pixelSizes[i].pixelSize == size &&
     276            (
     277                size == SMOOTH_SCALABLE ||
     278                !pointSize ||
     279                pixelSizes[i].pointSize == pointSize
     280            )
     281        )
     282#else       
    252283        if ( pixelSizes[i].pixelSize == size )
     284#endif           
    253285            return pixelSizes + i;
    254286    }
     
    261293                              (((count+8) >> 3 ) << 3) * sizeof(QtFontSize) );
    262294    pixelSizes[count].pixelSize = size;
     295#ifdef Q_WS_PM
     296    pixelSizes[count].pointSize = pointSize;
     297    pixelSizes[count].lMatch = 0;
     298#endif
    263299#ifdef Q_WS_X11
    264300    pixelSizes[count].count = 0;
     
    336372          name( n ), count( 0 ), foundries( 0 ) {
    337373        memset( scripts, 0, sizeof( scripts ) );
     374#ifdef Q_WS_PM
     375//@@TODO (dmik): temporary solution to let QFontDialog work:
     376//  at least UnknownScript is supported.
     377        scripts[QFont::UnknownScript] = Supported;
     378#endif       
    338379    }
    339380    ~QtFontFamily() {
     
    357398    bool fullyLoaded : 1;
    358399    QString name;
     400#ifndef Q_WS_X11
    359401    QString rawName;
     402#endif   
    360403#ifdef Q_WS_X11
    361404    QCString fontFilename;
     
    393436class QFontDatabasePrivate {
    394437public:
    395     QFontDatabasePrivate() : count( 0 ), families( 0 ) { }
     438    QFontDatabasePrivate() :
     439        count( 0 ), families( 0 ) { }
    396440    ~QFontDatabasePrivate() {
     441#ifdef Q_WS_PM
     442        cleanup();
     443#else
    397444        while ( count-- )
    398445            delete families[count];
    399446        free( families );
     447#endif
    400448    }
    401449    QtFontFamily *family( const QString &f, bool = FALSE );
     
    403451    int count;
    404452    QtFontFamily **families;
     453
     454#ifdef Q_WS_PM
     455    static QFontDatabasePrivate* instance();
     456private:   
     457    void cleanup() {
     458        while ( count )
     459            delete families[--count];
     460        free( families );
     461        families = 0;
     462    }
     463    void reload();
     464#endif
    405465};
    406466
     
    627687
    628688static QSingleCleanupHandler<QFontDatabasePrivate> qfontdatabase_cleanup;
     689#ifdef Q_WS_PM
     690QFontDatabasePrivate* QFontDatabasePrivate::instance()
     691{
     692    static QFontDatabasePrivate *db = 0;
     693    if ( !db ) {
     694        db = new QFontDatabasePrivate;
     695        qfontdatabase_cleanup.set(&db);
     696        db->reload();
     697    }
     698    return db;
     699}
     700#else
    629701static QFontDatabasePrivate *db=0;
    630 #define SMOOTH_SCALABLE 0xffff
     702#endif
    631703
    632704#if defined( Q_WS_X11 )
     
    636708#elif defined( Q_WS_WIN )
    637709#  include "qfontdatabase_win.cpp"
     710#elif defined( Q_WS_PM )
     711#  include "qfontdatabase_pm.cpp"
    638712#elif defined( Q_WS_QWS )
    639713#  include "qfontdatabase_qws.cpp"
     
    643717
    644718
    645 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
     719#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_PM)
    646720static
    647721unsigned int bestFoundry( QFont::Script script, unsigned int score, int styleStrategy,
     
    650724                          QtFontFoundry **best_foundry, QtFontStyle **best_style,
    651725                          QtFontSize **best_size
    652 #ifdef Q_WS_X11
     726#if defined(Q_WS_X11)
    653727                          , QtFontEncoding **best_encoding, int force_encoding_id
     728#elif defined(Q_WS_PM)
     729                          , int pointSize
    654730#endif
    655731                          )
     
    711787        // 1. see if we have an exact matching size
    712788        if (! (styleStrategy & QFont::ForceOutline)) {
     789#if defined(Q_WS_PM)
     790            size = style->pixelSize(pixelSize, FALSE, pointSize);
     791#else           
    713792            size = style->pixelSize(pixelSize);
     793#endif           
    714794            if (size) px = size->pixelSize;
    715795        }
     
    843923#endif
    844924
     925#ifdef Q_WS_PM
     926    QFontDatabasePrivate *db = QFontDatabasePrivate::instance();
     927#else   
    845928    if ( !db )
    846929        initializeDb();
     930#endif
    847931
    848932    QFontEngine *fe = 0;
    849933    if ( fp ) {
     934#ifndef Q_WS_PM
    850935        if ( fp->rawMode ) {
    851936            fe = loadEngine( script, fp, request, 0, 0, 0
     
    859944            return fe;
    860945        }
     946#endif // !Q_WS_PM
    861947
    862948        QFontCache::Key key( request, script,
    863 #ifdef Q_WS_WIN
     949#if defined(Q_WS_WIN) || defined(Q_WS_PM)
    864950                             (int)fp->paintdevice
    865951#else
     
    880966    parseFontName( request.family, foundry_name, family_name );
    881967
     968#ifdef Q_WS_PM
     969    // the "System VIO" PM font is broken in such way that its real pixel
     970    // sizes do not correspond to their nominal point sizes specified in the
     971    // font header (i.e. pixelSize is not equal to (pointSize * dpi) / 720).
     972    // therefore we use the special table to convert pointSize to pixelSize
     973    // in order to let bestFoundry() select the proper font with its nominal
     974    // point size corresponding to the requested one.
     975    // NOTE: this will produce incorrect results if "System VIO" is NOT
     976    // an OS/2 standatd supplied bitmap font.
     977    if( !ucstricmp( family_name, "System VIO") ) {
     978        // possible sizes of the "System VIO" font ("pixel, point" pairs),
     979        // sorted by point size
     980        static const short SystemVIO_sz[] = {
     981            12, 20,         16, 30,
     982            8,  40,         13, 50,
     983            15, 60,         24, 70,
     984            8,  80,         10, 90,
     985            12, 100,        14, 110,
     986            16, 120,        18, 130,
     987            16, 140,        12, 150,
     988            20, 160,        21, 170,
     989            29, 180,
     990        };
     991        const int SystemVIO_sz_len = sizeof(SystemVIO_sz) / sizeof(SystemVIO_sz[0]);
     992        int pt = request.pointSize;
     993        pt = QMAX( pt, SystemVIO_sz [1] );                      // min limit
     994        pt = QMIN( pt, SystemVIO_sz [SystemVIO_sz_len - 1] );   // max limit
     995        int i = 1;
     996        while ( SystemVIO_sz[i] < pt ) i += 2;
     997        if ( SystemVIO_sz[i] > pt ) {
     998            int prev = SystemVIO_sz[i-2];
     999            int mid = prev + (SystemVIO_sz[i] - prev + 1) / 2;
     1000            if ( pt < mid ) i -= 2;
     1001        }
     1002        ((QFontDef&)request).pixelSize = SystemVIO_sz[i-1];
     1003        ((QFontDef&)request).pointSize = SystemVIO_sz[i];
     1004    }
     1005#endif
     1006   
    8821007#ifdef Q_WS_X11
    8831008    if (family_name.isEmpty() && script == QFont::Han) {
     
    9051030              "    stretch: %d\n"
    9061031              "    pixelSize: %d\n"
     1032              "    pointSize: %d\n"
    9071033              "    pitch: %c",
    9081034              family_name.isEmpty() ? "-- first in script --" : family_name.latin1(),
    9091035              foundry_name.isEmpty() ? "-- any --" : foundry_name.latin1(),
    9101036              script, scriptName( script ).latin1(),
    911               request.weight, request.italic, request.stretch, request.pixelSize, pitch );
     1037              request.weight, request.italic, request.stretch,
     1038              request.pixelSize, request.pointSize,
     1039              pitch );
    9121040
    9131041#ifdef QT_XFT2
     
    9441072            uint score_adjust = 0;
    9451073            QFont::Script override_script = script;
     1074#ifndef Q_WS_PM
    9461075            if ( ! ( try_family->scripts[script] & QtFontFamily::Supported )
    9471076                 && script != QFont::Unicode) {
     
    9781107                }
    9791108            }
     1109#endif // !Q_WS_PM
    9801110
    9811111            QtFontFoundry *try_foundry = 0;
     
    9921122                             try_family, foundry_name, styleKey, request.pixelSize, pitch,
    9931123                             &try_foundry, &try_style, &try_size
    994 #ifdef Q_WS_X11
     1124#if defined(Q_WS_X11)
    9951125                             , &try_encoding, force_encoding_id
     1126#elif defined(Q_WS_PM)
     1127                             , request.pointSize
    9961128#endif
    9971129                    );
     
    10021134                                        QString::null, styleKey, request.pixelSize,
    10031135                                        pitch, &try_foundry, &try_style, &try_size
    1004 #ifdef Q_WS_X11
     1136#if defined(Q_WS_X11)
    10051137                                        , &try_encoding, force_encoding_id
     1138#elif defined(Q_WS_PM)
     1139                                        , request.pointSize
    10061140#endif
    10071141                    );
     
    10471181
    10481182            fe = loadEngine( script, fp, request, best_family, best_foundry, best_style
    1049 #ifdef Q_WS_X11
     1183#if defined(Q_WS_PM)
     1184                             , best_size
     1185#elif defined(Q_WS_X11)
    10501186                             , best_size, best_encoding, ( force_encoding_id >= 0 )
    10511187#endif
     
    10601196            }
    10611197
     1198#ifdef Q_WS_PM
     1199            // On OS/2, fontDef.pixelSize and fontDef.pointSize are filled
     1200            // by QFontEnginePM constructor
     1201#else             
    10621202            if ( best_style->smoothScalable )
    10631203                fe->fontDef.pixelSize = request.pixelSize;
     
    10821222                fe->fontDef.pointSize = request.pointSize;
    10831223            }
     1224#endif           
    10841225            fe->fontDef.styleHint     = request.styleHint;
    10851226            fe->fontDef.styleStrategy = request.styleStrategy;
     
    10941235
    10951236    if ( fe ) {
     1237#ifdef Q_WS_PM
     1238///@@TODO (dmik): should do something here?
     1239#else
    10961240        if ( script != QFont::Unicode && !canRender( fe, script ) ) {
    10971241            FM_DEBUG( "  WARN: font loaded cannot render sample 0x%04x",
     
    11171261            return fe;
    11181262        }
     1263#endif // !Q_WS_PM
    11191264
    11201265        if ( fp ) {
    11211266            QFontCache::Key key( request, script,
    1122 #ifdef Q_WS_WIN
     1267#if defined(Q_WS_WIN) || defined(Q_WS_PM)
    11231268                                 (int)fp->paintdevice
    11241269#else
     
    11281273            QFontCache::instance->insertEngine( key, fe );
    11291274
     1275#ifndef Q_WS_PM
    11301276            for ( int i = 0; i < QFont::NScripts; ++i ) {
    11311277                if ( i == script ) continue;
     
    11371283                QFontCache::instance->insertEngine( key, fe );
    11381284            }
     1285#endif // !Q_WS_PM
    11391286        }
    11401287    } else {
    11411288        if ( request.family.isEmpty() ) {
     1289#ifdef Q_WS_PM
     1290//@@TODO (dmik): what to return in such case?
     1291            qFatal( "QFontDatabase::findFont: request.family is empty and nothing is found, should it ever happen?" );
     1292#else
    11421293            FM_DEBUG( "returning box engine" );
    11431294
     
    11461297            if ( fp ) {
    11471298                QFontCache::Key key( request, script,
    1148 #ifdef Q_WS_WIN
     1299#if defined(Q_WS_WIN) || defined(Q_WS_PM)
    11491300                                     (int)fp->paintdevice
    11501301#else
     
    11541305                QFontCache::instance->insertEngine( key, fe );
    11551306            }
     1307#endif // Q_WS_PM
    11561308        }
    11571309    }
     
    11591311    return fe;
    11601312}
    1161 #endif // Q_WS_X11 || Q_WS_WIN
     1313#endif // Q_WS_X11 || Q_WS_WIN || Q_WS_PM
    11621314
    11631315
     
    13551507QFontDatabase::QFontDatabase()
    13561508{
     1509#ifdef Q_WS_PM
     1510    d = QFontDatabasePrivate::instance();   
     1511#else   
    13571512    createDatabase();
    13581513
    13591514    d = db;
     1515#endif
    13601516}
    13611517
     
    16351791
    16361792                if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) {
    1637 #ifdef Q_WS_X11
     1793#if defined(Q_WS_X11)
    16381794                    const uint pointSize = qRound(qt_pointSize(size->pixelSize, 0, -1));
     1795#elif defined(Q_WS_PM)
     1796//@@TODO (dmik): some bitmap fonts (i.e. System VIO) have point sizes
     1797//  that do not really correlate with their actual pixel sizes (i.e.
     1798//  their pointsize != pixelsizde * DPI / 72), What to return in that case? 
     1799                    const uint pointSize = size->pointSize / 10;
    16391800#else
    16401801                    const uint pointSize = size->pixelSize; // embedded uses 72dpi
     
    17401901
    17411902                if ( size->pixelSize != 0 && size->pixelSize != USHRT_MAX ) {
    1742 #ifdef Q_WS_X11
     1903#if defined(Q_WS_X11)
    17431904                    const uint pointSize = qRound(qt_pointSize(size->pixelSize, 0, -1));
     1905#elif defined(Q_WS_PM)
     1906//@@TODO (dmik): some bitmap fonts (i.e. System VIO) have point sizes
     1907//  that do not really correlate with their actual pixel sizes (i.e.
     1908//  their pointsize != pixelsizde * DPI / 72), What to return in that case? 
     1909                    const uint pointSize = size->pointSize / 10;
    17441910#else
    17451911                    const uint pointSize = size->pixelSize; // embedded uses 72dpi
Note: See TracChangeset for help on using the changeset viewer.