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/painting/qprintengine_win.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**
     
    200200        d->fileName = d->port;
    201201
    202     QT_WA({
    203     d->devModeW()->dmCopies = d->num_copies;
    204         DOCINFO di;
    205         memset(&di, 0, sizeof(DOCINFO));
    206         di.cbSize = sizeof(DOCINFO);
    207         di.lpszDocName = reinterpret_cast<const wchar_t *>(d->docName.utf16());
    208         if (d->printToFile && !d->fileName.isEmpty())
    209             di.lpszOutput = reinterpret_cast<const wchar_t *>(d->fileName.utf16());
    210         if (ok && StartDoc(d->hdc, &di) == SP_ERROR) {
    211             qErrnoWarning("QWin32PrintEngine::begin: StartDoc failed");
    212             ok = false;
    213         }
    214     } , {
    215     d->devModeA()->dmCopies = d->num_copies;
    216         DOCINFOA di;
    217         memset(&di, 0, sizeof(DOCINFOA));
    218         di.cbSize = sizeof(DOCINFOA);
    219         QByteArray docNameA = d->docName.toLocal8Bit();
    220         di.lpszDocName = docNameA.data();
    221         QByteArray outfileA = d->fileName.toLocal8Bit();
    222         if (d->printToFile && !d->fileName.isEmpty())
    223             di.lpszOutput = outfileA;
    224         if (ok && StartDocA(d->hdc, &di) == SP_ERROR) {
    225             qErrnoWarning("QWin32PrintEngine::begin: StartDoc failed");
    226             ok = false;
    227         }
    228     });
     202    d->devMode->dmCopies = d->num_copies;
     203
     204    DOCINFO di;
     205    memset(&di, 0, sizeof(DOCINFO));
     206    di.cbSize = sizeof(DOCINFO);
     207    di.lpszDocName = reinterpret_cast<const wchar_t *>(d->docName.utf16());
     208    if (d->printToFile && !d->fileName.isEmpty())
     209        di.lpszOutput = reinterpret_cast<const wchar_t *>(d->fileName.utf16());
     210    if (ok && StartDoc(d->hdc, &di) == SP_ERROR) {
     211        qErrnoWarning("QWin32PrintEngine::begin: StartDoc failed");
     212        ok = false;
     213    }
    229214
    230215    if (StartPage(d->hdc) <= 0) {
     
    318303    bool success = false;
    319304    if (d->hdc && d->state == QPrinter::Active) {
    320 //         bool restorePainter = false;
    321 //         if ((qWinVersion()& Qt::WV_DOS_based) && painter && painter->isActive()) {
    322 //             painter->save();               // EndPage/StartPage ruins the DC
    323 //             restorePainter = true;
    324 //         }
    325305        if (EndPage(d->hdc) != SP_ERROR) {
    326306            // reinitialize the DC before StartPage if needed,
     
    338318            success = (StartPage(d->hdc) != SP_ERROR);
    339319        }
    340         if (!success)
     320        if (!success) {
    341321            d->state = QPrinter::Aborted;
    342 
    343 //         if (qWinVersion() & Qt::WV_DOS_based)
    344 //         if (restorePainter) {
    345 //             painter->restore();
    346 //      }
    347 
    348         if (!success)
    349322            return false;
     323        }
    350324    }
    351325    return true;
     
    370344    bool fallBack = state->pen().brush().style() != Qt::SolidPattern
    371345                    || qAlpha(brushColor) != 0xff
    372                     || QT_WA_INLINE(d->txop >= QTransform::TxProject, d->txop >= QTransform::TxScale)
     346                    || d->txop >= QTransform::TxProject
    373347                    || ti.fontEngine->type() != QFontEngine::Win;
    374348
     
    381355
    382356        if (GetDeviceCaps(d->hdc, TECHNOLOGY) != DT_CHARSTREAM) {
    383             QT_WA({
    384                 TCHAR n[64];
    385                 GetTextFaceW(d->hdc, 64, n);
    386                 fallBack = QString::fromUtf16((ushort *)n)
    387                         != QString::fromUtf16((ushort *)fe->logfont.lfFaceName);
    388             } , {
    389                 char an[64];
    390                 GetTextFaceA(d->hdc, 64, an);
    391                 fallBack = QString::fromLocal8Bit(an)
    392                         != QString::fromLocal8Bit(((LOGFONTA*)(&fe->logfont))->lfFaceName);
    393             });
     357            wchar_t n[64];
     358            GetTextFace(d->hdc, 64, n);
     359            fallBack = QString::fromWCharArray(n)
     360                    != QString::fromWCharArray(fe->logfont.lfFaceName);
    394361        }
    395362    }
     
    401368    }
    402369
    403     // We only want to convert the glyphs to text if the entire string is latin1
    404     bool latin1String = true;
     370    // We only want to convert the glyphs to text if the entire string is compatible with ASCII
     371    bool convertToText = true;
    405372    for (int i=0;  i < ti.num_chars; ++i) {
    406         if (ti.chars[i].unicode() >= 0x100) {
    407             latin1String = false;
     373        if (ti.chars[i].unicode() >= 0x80) {
     374            convertToText = false;
     375            break;
     376        }
     377
     378        if (ti.logClusters[i] != i) {
     379            convertToText = false;
    408380            break;
    409381        }
     
    415387    SetTextColor(d->hdc, cf);
    416388
    417     draw_text_item_win(p, ti, d->hdc, latin1String, d->matrix, d->devPaperRect.topLeft());
     389    draw_text_item_win(p, ti, d->hdc, convertToText, d->matrix, d->devPaperRect.topLeft());
    418390    DeleteObject(SelectObject(d->hdc,GetStockObject(HOLLOW_BRUSH)));
    419391    DeleteObject(SelectObject(d->hdc,GetStockObject(BLACK_PEN)));
     
    664636    qreal scaleY = 1.0f;
    665637
    666     QTransform scaleMatrix;
    667     scaleMatrix.scale(r.width() / pixmap.width(), r.height() / pixmap.height());
     638    QTransform scaleMatrix = QTransform::fromScale(r.width() / pixmap.width(), r.height() / pixmap.height());
    668639    QTransform adapted = QPixmap::trueMatrix(d->painterMatrix * scaleMatrix,
    669640                                             pixmap.width(), pixmap.height());
     
    863834{
    864835    composeGdiPath(path);
    865     HPEN pen = CreatePen(PS_SOLID, qRound(penWidth), RGB(color.red(), color.green(), color.blue()));
     836    LOGBRUSH brush;
     837    brush.lbStyle = BS_SOLID;
     838    brush.lbColor = RGB(color.red(), color.green(), color.blue());
     839    DWORD capStyle = PS_ENDCAP_SQUARE;
     840    DWORD joinStyle = PS_JOIN_BEVEL;
     841    if (pen.capStyle() == Qt::FlatCap)
     842        capStyle = PS_ENDCAP_FLAT;
     843    else if (pen.capStyle() == Qt::RoundCap)
     844        capStyle = PS_ENDCAP_ROUND;
     845
     846    if (pen.joinStyle() == Qt::MiterJoin)
     847        joinStyle = PS_JOIN_MITER;
     848    else if (pen.joinStyle() == Qt::RoundJoin)
     849        joinStyle = PS_JOIN_ROUND;
     850
     851    HPEN pen = ExtCreatePen(((penWidth == 0) ? PS_COSMETIC : PS_GEOMETRIC)
     852                            | PS_SOLID | capStyle | joinStyle,
     853                            penWidth, &brush, 0, 0);
     854
    866855    HGDIOBJ old_pen = SelectObject(hdc, pen);
    867856    StrokePath(hdc);
     
    967956     */
    968957    QString noPrinters(QLatin1String("qt_no_printers"));
    969     QString output;
    970     QT_WA({
    971         ushort buffer[256];
    972         GetProfileStringW(L"windows", L"device",
    973                           reinterpret_cast<const wchar_t *>(noPrinters.utf16()),
    974                           reinterpret_cast<wchar_t *>(buffer), 256);
    975         output = QString::fromUtf16(buffer);
    976         if (output.isEmpty() || output == noPrinters) // no printers
    977             return;
    978     }, {
    979         char buffer[256];
    980         GetProfileStringA("windows", "device", noPrinters.toLatin1(), buffer, 256);
    981         output = QString::fromLocal8Bit(buffer);
    982         if (output.isEmpty() || output == noPrinters) // no printers
    983             return;
    984     });
     958    wchar_t buffer[256];
     959    GetProfileString(L"windows", L"device",
     960                     reinterpret_cast<const wchar_t *>(noPrinters.utf16()),
     961                     buffer, 256);
     962    QString output = QString::fromWCharArray(buffer);
     963    if (output.isEmpty() || output == noPrinters) // no printers
     964        return;
     965
    985966    QStringList info = output.split(QLatin1Char(','));
    986967    if (info.size() > 0) {
     
    1014995    txop = QTransform::TxNone;
    1015996
    1016     bool ok;
    1017     QT_WA( {
    1018         ok = OpenPrinterW((LPWSTR)name.utf16(), (LPHANDLE)&hPrinter, 0);
    1019     }, {
    1020         ok = OpenPrinterA((LPSTR)name.toLatin1().data(), (LPHANDLE)&hPrinter, 0);
    1021     } );
    1022 
     997    bool ok = OpenPrinter((LPWSTR)name.utf16(), (LPHANDLE)&hPrinter, 0);
    1023998    if (!ok) {
    1024999        qErrnoWarning("QWin32PrintEngine::initialize: OpenPrinter failed");
     
    10291004    // printer settings.
    10301005    DWORD infoSize, numBytes;
    1031     ok = true;
    1032     QT_WA( {
    1033         GetPrinterW(hPrinter, 2, NULL, 0, &infoSize);
    1034         hMem = GlobalAlloc(GHND, infoSize);
    1035         pInfo = GlobalLock(hMem);
    1036         if (!GetPrinterW(hPrinter, 2, (LPBYTE)pInfo, infoSize, &numBytes)) {
    1037             ok = false;
    1038         }
    1039     }, {
    1040         GetPrinterA(hPrinter, 2, NULL, 0, &infoSize);
    1041         hMem = GlobalAlloc(GHND, infoSize);
    1042         pInfo = GlobalLock(hMem);
    1043         if (!GetPrinterA(hPrinter, 2, (LPBYTE)pInfo, infoSize, &numBytes)) {
    1044             ok = false;
    1045         }
    1046     });
     1006    GetPrinter(hPrinter, 2, NULL, 0, &infoSize);
     1007    hMem = GlobalAlloc(GHND, infoSize);
     1008    pInfo = (PRINTER_INFO_2*) GlobalLock(hMem);
     1009    ok = GetPrinter(hPrinter, 2, (LPBYTE)pInfo, infoSize, &numBytes);
    10471010
    10481011    if (!ok) {
     
    10571020    }
    10581021
    1059     QT_WA( {
    1060         devMode = pInfoW()->pDevMode;
    1061     }, {
    1062         devMode = pInfoA()->pDevMode;
    1063     } );
    1064 
    1065     QT_WA( {
    1066         hdc = CreateDC(reinterpret_cast<const wchar_t *>(program.utf16()),
    1067                        reinterpret_cast<const wchar_t *>(name.utf16()), 0, devModeW());
    1068     }, {
    1069         hdc = CreateDCA(program.toLatin1(), name.toLatin1(), 0, devModeA());
    1070     } );
     1022    devMode = pInfo->pDevMode;
     1023    hdc = CreateDC(reinterpret_cast<const wchar_t *>(program.utf16()),
     1024                   reinterpret_cast<const wchar_t *>(name.utf16()), 0, devMode);
    10711025
    10721026    Q_ASSERT(hPrinter);
     
    10741028
    10751029    if (devMode) {
    1076         QT_WA( {
    1077             num_copies = devModeW()->dmCopies;
    1078         }, {
    1079             num_copies = devModeA()->dmCopies;
    1080         } );
     1030        num_copies = devMode->dmCopies;
    10811031    }
    10821032
     
    11961146{
    11971147    // Read the supported resolutions of the printer.
    1198     DWORD numRes;
    1199     LONG *enumRes;
    1200     DWORD errRes;
    12011148    QList<QVariant> list;
    12021149
    1203     QT_WA({
    1204         numRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(name.utf16()),
    1205                                     reinterpret_cast<const wchar_t *>(port.utf16()),
    1206                                     DC_ENUMRESOLUTIONS, 0, 0);
    1207         if (numRes == (DWORD)-1)
    1208             return list;
    1209         enumRes = (LONG*)malloc(numRes * 2 * sizeof(LONG));
    1210         errRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(name.utf16()),
    1211                                     reinterpret_cast<const wchar_t *>(port.utf16()),
    1212                                     DC_ENUMRESOLUTIONS, (LPWSTR)enumRes, 0);
    1213     }, {
    1214         numRes = DeviceCapabilitiesA(name.toLocal8Bit(), port.toLocal8Bit(), DC_ENUMRESOLUTIONS, 0, 0);
    1215         if (numRes == (DWORD)-1)
    1216             return list;
    1217         enumRes = (LONG*)malloc(numRes * 2 * sizeof(LONG));
    1218         errRes = DeviceCapabilitiesA(name.toLocal8Bit(), port.toLocal8Bit(), DC_ENUMRESOLUTIONS, (LPSTR)enumRes, 0);
    1219     });
     1150    DWORD numRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(name.utf16()),
     1151                                      reinterpret_cast<const wchar_t *>(port.utf16()),
     1152                                      DC_ENUMRESOLUTIONS, 0, 0);
     1153    if (numRes == (DWORD)-1)
     1154        return list;
     1155
     1156    LONG *enumRes = (LONG*)malloc(numRes * 2 * sizeof(LONG));
     1157    DWORD errRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(name.utf16()),
     1158                                      reinterpret_cast<const wchar_t *>(port.utf16()),
     1159                                      DC_ENUMRESOLUTIONS, (LPWSTR)enumRes, 0);
    12201160
    12211161    if (errRes == (DWORD)-1) {
     
    12251165
    12261166    for (uint i=0; i<numRes; ++i)
    1227         list.append(int(enumRes[i*2]));
     1167        list.append(int(enumRes[i * 2]));
     1168
    12281169    return list;
    12291170}
     
    12691210            if (!d->devMode)
    12701211                break;
    1271             short collate = value.toBool() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE;
    1272             QT_WA( { d->devModeW()->dmCollate = collate; },
    1273                    { d->devModeA()->dmCollate = collate; } );
     1212            d->devMode->dmCollate = value.toBool() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE;
    12741213            d->doReinit();
    12751214        }
     
    12801219            if (!d->devMode)
    12811220                break;
    1282             int cm = value.toInt() == QPrinter::Color ? DMCOLOR_COLOR : DMCOLOR_MONOCHROME;
    1283             QT_WA( { d->devModeW()->dmColor = cm; }, { d->devModeA()->dmColor = cm; } );
     1221            d->devMode->dmColor = (value.toInt() == QPrinter::Color) ? DMCOLOR_COLOR : DMCOLOR_MONOCHROME;
    12841222            d->doReinit();
    12851223        }
     
    13071245            break;
    13081246        d->num_copies = value.toInt();
    1309         QT_WA( { d->devModeW()->dmCopies = d->num_copies; },
    1310                { d->devModeA()->dmCopies = d->num_copies; });
     1247        d->devMode->dmCopies = d->num_copies;
    13111248        d->doReinit();
    13121249        break;
     
    13171254                break;
    13181255            int orientation = value.toInt() == QPrinter::Landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
    1319             int old_orientation;
    1320             QT_WA( {
    1321                 old_orientation = d->devModeW()->dmOrientation;
    1322                 d->devModeW()->dmOrientation = orientation;
    1323             }, {
    1324                 old_orientation = d->devModeA()->dmOrientation;
    1325                 d->devModeA()->dmOrientation = orientation;
    1326             } );
     1256            int old_orientation = d->devMode->dmOrientation;
     1257            d->devMode->dmOrientation = orientation;
    13271258            if (d->has_custom_paper_size && old_orientation != orientation)
    13281259                d->paper_size = QSizeF(d->paper_size.height(), d->paper_size.width());
     
    13431274        if (!d->devMode)
    13441275            break;
    1345         QT_WA( {
    1346             d->devModeW()->dmPaperSize = mapPaperSizeDevmode(QPrinter::PaperSize(value.toInt()));
    1347         }, {
    1348             d->devModeA()->dmPaperSize = mapPaperSizeDevmode(QPrinter::PaperSize(value.toInt()));
    1349         } );
     1276        d->devMode->dmPaperSize = mapPaperSizeDevmode(QPrinter::PaperSize(value.toInt()));
    13501277        d->has_custom_paper_size = (QPrinter::PaperSize(value.toInt()) == QPrinter::Custom);
    13511278        d->doReinit();
     
    13621289                dmMapped = mapPaperSourceDevmode(QPrinter::PaperSource(value.toInt()));
    13631290
    1364             QT_WA( {
    1365                 d->devModeW()->dmDefaultSource = dmMapped;
    1366             }, {
    1367                 d->devModeA()->dmDefaultSource = dmMapped;
    1368             } );
     1291            d->devMode->dmDefaultSource = dmMapped;
    13691292            d->doReinit();
    13701293        }
     
    14001323            break;
    14011324        d->has_custom_paper_size = false;
    1402         QT_WA( {
    1403             d->devModeW()->dmPaperSize = value.toInt();
    1404         }, {
    1405             d->devModeA()->dmPaperSize = value.toInt();
    1406         } );
     1325        d->devMode->dmPaperSize = value.toInt();
    14071326        d->doReinit();
    14081327        break;
     
    14141333        if (!d->devMode)
    14151334            break;
    1416         int orientation;
    1417         QT_WA( {
    1418             orientation = d->devModeW()->dmOrientation;
    1419             DWORD needed = 0;
    1420             DWORD returned = 0;
    1421             if (!EnumForms(d->hPrinter, 1, 0, 0, &needed, &returned)) {
    1422                 BYTE *forms = (BYTE *) malloc(needed);
    1423                 if (EnumForms(d->hPrinter, 1, forms, needed, &needed, &returned)) {
    1424                     for (DWORD i=0; i< returned; ++i) {
    1425                         FORM_INFO_1 *formArray = reinterpret_cast<FORM_INFO_1 *>(forms);
    1426                         // the form sizes are specified in 1000th of a mm,
    1427                         // convert the size to Points
    1428                         QSizeF size((formArray[i].Size.cx * 72/25.4)/1000.0,
    1429                                     (formArray[i].Size.cy * 72/25.4)/1000.0);
    1430                         if (qAbs(d->paper_size.width() - size.width()) <= 2
    1431                             && qAbs(d->paper_size.height() - size.height()) <= 2)
    1432                         {
    1433                             d->devModeW()->dmPaperSize = i+1;
    1434                             break;
    1435                         }
     1335        int orientation = d->devMode->dmOrientation;
     1336        DWORD needed = 0;
     1337        DWORD returned = 0;
     1338        if (!EnumForms(d->hPrinter, 1, 0, 0, &needed, &returned)) {
     1339            BYTE *forms = (BYTE *) malloc(needed);
     1340            if (EnumForms(d->hPrinter, 1, forms, needed, &needed, &returned)) {
     1341                for (DWORD i=0; i< returned; ++i) {
     1342                    FORM_INFO_1 *formArray = reinterpret_cast<FORM_INFO_1 *>(forms);
     1343                    // the form sizes are specified in 1000th of a mm,
     1344                    // convert the size to Points
     1345                    QSizeF size((formArray[i].Size.cx * 72/25.4)/1000.0,
     1346                                (formArray[i].Size.cy * 72/25.4)/1000.0);
     1347                    if (qAbs(d->paper_size.width() - size.width()) <= 2
     1348                        && qAbs(d->paper_size.height() - size.height()) <= 2)
     1349                    {
     1350                        d->devMode->dmPaperSize = i + 1;
     1351                        break;
    14361352                    }
    14371353                }
    1438                 free(forms);
    14391354            }
    1440         }, {
    1441             orientation = d->devModeA()->dmOrientation;
    1442         } );
     1355            free(forms);
     1356        }
    14431357        if (orientation != DMORIENT_PORTRAIT)
    14441358            d->paper_size = QSizeF(d->paper_size.height(), d->paper_size.width());
     
    14521366        int left, top, right, bottom;
    14531367        // specified in 1/100 mm
    1454         left = (margins.at(0).toDouble()*25.4/72.0) * 100;
    1455         top = (margins.at(1).toDouble()*25.4/72.0) * 100;
    1456         right = (margins.at(2).toDouble()*25.4/72.0) * 100;
    1457         bottom = (margins.at(3).toDouble()*25.4/72.0) * 100;
     1368        left = (margins.at(0).toReal()*25.4/72.0) * 100;
     1369        top = (margins.at(1).toReal()*25.4/72.0) * 100;
     1370        right = (margins.at(2).toReal()*25.4/72.0) * 100;
     1371        bottom = (margins.at(3).toReal()*25.4/72.0) * 100;
    14581372        d->setPageMargins(left, top, right, bottom);
    14591373        break;
     
    14801394                value = QPrinter::Color;
    14811395            } else {
    1482                 int mode;
    1483                 QT_WA( {
    1484                     mode = d->devModeW()->dmColor;
    1485                 }, {
    1486                     mode = d->devModeA()->dmColor;
    1487                 } );
    1488                 value = mode == DMCOLOR_COLOR ? QPrinter::Color : QPrinter::GrayScale;
     1396                value = (d->devMode->dmColor == DMCOLOR_COLOR) ? QPrinter::Color : QPrinter::GrayScale;
    14891397            }
    14901398        }
     
    15081416                value = QPrinter::Portrait;
    15091417            } else {
    1510                 int o;
    1511                 QT_WA( { o = d->devModeW()->dmOrientation; }, { o = d->devModeA()->dmOrientation; } );
    1512                 value = o == DMORIENT_LANDSCAPE ? QPrinter::Landscape : QPrinter::Portrait;
     1418                value = (d->devMode->dmOrientation == DMORIENT_LANDSCAPE) ? QPrinter::Landscape : QPrinter::Portrait;
    15131419            }
    15141420        }
     
    15331439        } else {
    15341440            value = QTransform(1/d->stretch_x, 0, 0, 1/d->stretch_y, 0, 0)
    1535                     .mapRect(d->fullPage ? d->devPaperRect : d->devPageRect);
     1441                    .mapRect(d->fullPage ? d->devPhysicalPageRect : d->devPageRect);
    15361442        }
    15371443        break;
     
    15441450                value = QPrinter::A4;
    15451451            } else {
    1546                 QT_WA( {
    1547                         value = mapDevmodePaperSize(d->devModeW()->dmPaperSize);
    1548                     }, {
    1549                         value = mapDevmodePaperSize(d->devModeA()->dmPaperSize);
    1550                     } );
     1452                value = mapDevmodePaperSize(d->devMode->dmPaperSize);
    15511453            }
    15521454        }
     
    15671469            value = QPrinter::Auto;
    15681470        } else {
    1569             QT_WA( {
    1570                 value = mapDevmodePaperSource(d->devModeW()->dmDefaultSource);
    1571             }, {
    1572                 value = mapDevmodePaperSource(d->devModeA()->dmDefaultSource);
    1573             } );
     1471            value = mapDevmodePaperSource(d->devMode->dmDefaultSource);
    15741472        }
    15751473        break;
     
    15921490            value = -1;
    15931491        } else {
    1594             QT_WA( {
    1595                 value = d->devModeW()->dmPaperSize;
    1596             }, {
    1597                 value = d->devModeA()->dmPaperSize;
    1598             } );
     1492            value = d->devMode->dmPaperSize;
    15991493        }
    16001494        break;
     
    16021496    case PPK_PaperSources:
    16031497        {
    1604             int available, count;
    1605             WORD *data;
    1606 
    1607             QT_WA({
    1608                 available = DeviceCapabilitiesW((const WCHAR *)d->name.utf16(), (const WCHAR *)d->port.utf16(), DC_BINS, 0,
    1609                                                 d->devModeW());
    1610             }, {
    1611                 available = DeviceCapabilitiesA(d->name.toLatin1(), d->port.toLatin1(), DC_BINS, 0,
    1612                                                 d->devModeA());
    1613             });
     1498            int available = DeviceCapabilities((const wchar_t *)d->name.utf16(),
     1499                                               (const wchar_t *)d->port.utf16(), DC_BINS, 0, d->devMode);
    16141500
    16151501            if (available <= 0)
    16161502                break;
    1617             data = (WORD *) malloc(available * sizeof(WORD));
    1618 
    1619             QT_WA({
    1620                 count = DeviceCapabilitiesW((const WCHAR *)d->name.utf16(), (const WCHAR *)d->port.utf16(), DC_BINS, (WCHAR *)data,
    1621                                             d->devModeW());
    1622             }, {
    1623                 count = DeviceCapabilitiesA(d->name.toLatin1(), d->port.toLatin1(), DC_BINS,
    1624                                             (char *) data, d->devModeA());
    1625             });
     1503
     1504            wchar_t *data = new wchar_t[available];
     1505            int count = DeviceCapabilities((const wchar_t *)d->name.utf16(),
     1506                                           (const wchar_t *)d->port.utf16(), DC_BINS, data, d->devMode);
    16261507
    16271508            QList<QVariant> out;
     
    16321513            }
    16331514            value = out;
    1634             free(data);
     1515
     1516            delete [] data;
    16351517        }
    16361518        break;
     
    16771559HGLOBAL *QWin32PrintEnginePrivate::createDevNames()
    16781560{
    1679     QT_WA( {
    1680         int size = sizeof(DEVNAMES)
    1681                    + program.length() * 2 + 2
    1682                    + name.length() * 2 + 2
    1683                    + port.length() * 2 + 2;
    1684         HGLOBAL *hGlobal = (HGLOBAL *) GlobalAlloc(GMEM_MOVEABLE, size);
    1685         DEVNAMES *dn = (DEVNAMES*) GlobalLock(hGlobal);
    1686 
    1687         dn->wDriverOffset = sizeof(DEVNAMES) / sizeof(TCHAR);
    1688         dn->wDeviceOffset = dn->wDriverOffset + program.length() + 1;
    1689         dn->wOutputOffset = dn->wDeviceOffset + name.length() + 1;
    1690 
    1691         memcpy((ushort*)dn + dn->wDriverOffset, program.utf16(), program.length() * 2 + 2);
    1692         memcpy((ushort*)dn + dn->wDeviceOffset, name.utf16(), name.length() * 2 + 2);
    1693         memcpy((ushort*)dn + dn->wOutputOffset, port.utf16(), port.length() * 2 + 2);
    1694         dn->wDefault = 0;
    1695 
    1696         GlobalUnlock(hGlobal);
     1561    int size = sizeof(DEVNAMES)
     1562               + program.length() * 2 + 2
     1563               + name.length() * 2 + 2
     1564               + port.length() * 2 + 2;
     1565    HGLOBAL *hGlobal = (HGLOBAL *) GlobalAlloc(GMEM_MOVEABLE, size);
     1566    DEVNAMES *dn = (DEVNAMES*) GlobalLock(hGlobal);
     1567
     1568    dn->wDriverOffset = sizeof(DEVNAMES) / sizeof(wchar_t);
     1569    dn->wDeviceOffset = dn->wDriverOffset + program.length() + 1;
     1570    dn->wOutputOffset = dn->wDeviceOffset + name.length() + 1;
     1571
     1572    memcpy((ushort*)dn + dn->wDriverOffset, program.utf16(), program.length() * 2 + 2);
     1573    memcpy((ushort*)dn + dn->wDeviceOffset, name.utf16(), name.length() * 2 + 2);
     1574    memcpy((ushort*)dn + dn->wOutputOffset, port.utf16(), port.length() * 2 + 2);
     1575    dn->wDefault = 0;
     1576
     1577    GlobalUnlock(hGlobal);
    16971578
    16981579//         printf("QPrintDialogWinPrivate::createDevNames()\n"
     
    17051586
    17061587//         printf("QPrintDialogWinPrivate::createDevNames(): %s, %s, %s\n",
    1707 //                QString::fromUtf16((ushort*)(dn) + dn->wDriverOffset).latin1(),
    1708 //                QString::fromUtf16((ushort*)(dn) + dn->wDeviceOffset).latin1(),
    1709 //                QString::fromUtf16((ushort*)(dn) + dn->wOutputOffset).latin1());
    1710 
    1711         return hGlobal;
    1712     }, {
    1713         int size = sizeof(DEVNAMES)
    1714                    + program.length() + 2
    1715                    + name.length() + 2
    1716                    + port.length() + 2;
    1717         HGLOBAL *hGlobal = (HGLOBAL *) GlobalAlloc(GMEM_MOVEABLE, size);
    1718         DEVNAMES *dn = (DEVNAMES*) GlobalLock(hGlobal);
    1719 
    1720         dn->wDriverOffset = sizeof(DEVNAMES);
    1721         dn->wDeviceOffset = dn->wDriverOffset + program.length() + 1;
    1722         dn->wOutputOffset = dn->wDeviceOffset + name.length() + 1;
    1723 
    1724         memcpy((char*)dn + dn->wDriverOffset, program.toLatin1(), program.length() + 2);
    1725         memcpy((char*)dn + dn->wDeviceOffset, name.toLatin1(), name.length() + 2);
    1726         memcpy((char*)dn + dn->wOutputOffset, port.toLatin1(), port.length() + 2);
    1727         dn->wDefault = 0;
    1728 
    1729         GlobalUnlock(hGlobal);
    1730         return hGlobal;
    1731     } );
     1588//                QString::fromWCharArray((wchar_t*)(dn) + dn->wDriverOffset).latin1(),
     1589//                QString::fromWCharArray((wchar_t*)(dn) + dn->wDeviceOffset).latin1(),
     1590//                QString::fromWCharArray((wchar_t*)(dn) + dn->wOutputOffset).latin1());
     1591
     1592    return hGlobal;
    17321593}
    17331594
     
    17351596{
    17361597    if (globalDevnames) {
    1737         QT_WA( {
    1738             DEVNAMES *dn = (DEVNAMES*) GlobalLock(globalDevnames);
    1739             name = QString::fromUtf16((ushort*)(dn) + dn->wDeviceOffset);
    1740             port = QString::fromUtf16((ushort*)(dn) + dn->wOutputOffset);
    1741             program = QString::fromUtf16((ushort*)(dn) + dn->wDriverOffset);
    1742             GlobalUnlock(globalDevnames);
    1743         }, {
    1744             DEVNAMES *dn = (DEVNAMES*) GlobalLock(globalDevnames);
    1745             name = QString::fromLatin1((char*)(dn) + dn->wDeviceOffset);
    1746             port = QString::fromLatin1((char*)(dn) + dn->wOutputOffset);
    1747             program = QString::fromLatin1((char*)(dn) + dn->wDriverOffset);
    1748             GlobalUnlock(globalDevnames);
    1749         } );
     1598        DEVNAMES *dn = (DEVNAMES*) GlobalLock(globalDevnames);
     1599        name = QString::fromWCharArray((wchar_t*)(dn) + dn->wDeviceOffset);
     1600        port = QString::fromWCharArray((wchar_t*)(dn) + dn->wOutputOffset);
     1601        program = QString::fromWCharArray((wchar_t*)(dn) + dn->wDriverOffset);
     1602        GlobalUnlock(globalDevnames);
    17501603    }
    17511604}
     
    17541607{
    17551608    if (globalDevmode) {
    1756         QT_WA( {
    1757             DEVMODE *dm = (DEVMODE*) GlobalLock(globalDevmode);
    1758             release();
    1759             globalDevMode = globalDevmode;
    1760             devMode = dm;
    1761             hdc = CreateDC(reinterpret_cast<const wchar_t *>(program.utf16()),
    1762                            reinterpret_cast<const wchar_t *>(name.utf16()), 0, dm);
    1763 
    1764             num_copies = devModeW()->dmCopies;
    1765             if (!OpenPrinterW((LPWSTR)name.utf16(), (LPHANDLE)&hPrinter, 0))
    1766                 qWarning("QPrinter: OpenPrinter() failed after reading DEVMODE.");
    1767         }, {
    1768             DEVMODEA *dm = (DEVMODEA*) GlobalLock(globalDevmode);
    1769             release();
    1770             globalDevMode = globalDevmode;
    1771             devMode = dm;
    1772             hdc = CreateDCA(program.toLatin1(), name.toLatin1(), 0, dm);
    1773 
    1774             num_copies = devModeA()->dmCopies;
    1775             if (!OpenPrinterA((LPSTR)name.toLatin1().data(), (LPHANDLE)&hPrinter, 0))
    1776                 qWarning("QPrinter: OpenPrinter() failed after reading DEVMODE.");
    1777         } );
     1609        DEVMODE *dm = (DEVMODE*) GlobalLock(globalDevmode);
     1610        release();
     1611        globalDevMode = globalDevmode;
     1612        devMode = dm;
     1613        hdc = CreateDC(reinterpret_cast<const wchar_t *>(program.utf16()),
     1614                       reinterpret_cast<const wchar_t *>(name.utf16()), 0, dm);
     1615
     1616        num_copies = devMode->dmCopies;
     1617        if (!OpenPrinter((wchar_t*)name.utf16(), &hPrinter, 0))
     1618            qWarning("QPrinter: OpenPrinter() failed after reading DEVMODE.");
    17781619    }
    17791620
     
    17821623}
    17831624
    1784 static void draw_text_item_win(const QPointF &_pos, const QTextItemInt &ti, HDC hdc,
     1625static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC hdc,
    17851626                               bool convertToText, const QTransform &xform, const QPointF &topLeft)
    17861627{
    1787 
    1788     // Make sure we translate for systems that can't handle world transforms
    1789     QPointF pos(QT_WA_INLINE(_pos, _pos + QPointF(xform.dx(), xform.dy())));
    17901628    QFontEngine *fe = ti.fontEngine;
    17911629    QPointF baseline_pos = xform.inverted().map(xform.map(pos) - topLeft);
     
    17991637    HFONT hfont;
    18001638    bool ttf = false;
    1801     bool useTextOutA = false;
    18021639
    18031640    if (winfe) {
    18041641        hfont = winfe->hfont;
    18051642        ttf = winfe->ttf;
    1806         useTextOutA = winfe->useTextOutA;
    18071643    } else {
    18081644        hfont = (HFONT)GetStockObject(ANSI_VAR_FONT);
     
    18141650    QGlyphLayout glyphs = ti.glyphs;
    18151651
    1816     if (!(ti.flags & QTextItem::RightToLeft) && useTextOutA) {
    1817         qreal x = pos.x();
    1818         qreal y = pos.y();
    1819 
    1820         // hack to get symbol fonts working on Win95. See also QFontEngine constructor
    1821         // can only happen if !ttf
    1822         for(int i = 0; i < glyphs.numGlyphs; i++) {
    1823             QString str(QChar(glyphs.glyphs[i]));
    1824             QT_WA({
    1825                 TextOutW(hdc, qRound(x + glyphs.offsets[i].x.toReal()),
    1826                         qRound(y + glyphs.offsets[i].y.toReal()),
    1827                         (LPWSTR)str.utf16(), str.length());
    1828             } , {
    1829                 QByteArray cstr = str.toLocal8Bit();
    1830                 TextOutA(hdc, qRound(x + glyphs.offsets[i].x.toReal()),
    1831                         qRound(y + glyphs.offsets[i].y.toReal()),
    1832                         cstr.data(), cstr.length());
    1833             });
    1834             x += glyphs.effectiveAdvance(i).toReal();
    1835         }
     1652    bool fast = !has_kerning && !(ti.flags & QTextItem::RightToLeft);
     1653    for (int i = 0; fast && i < glyphs.numGlyphs; i++) {
     1654        if (glyphs.offsets[i].x != 0 || glyphs.offsets[i].y != 0 || glyphs.justifications[i].space_18d6 != 0
     1655            || glyphs.attributes[i].dontPrint) {
     1656            fast = false;
     1657            break;
     1658        }
     1659    }
     1660
     1661#if !defined(Q_OS_WINCE)
     1662    // Scale, rotate and translate here.
     1663    XFORM win_xform;
     1664    win_xform.eM11 = xform.m11();
     1665    win_xform.eM12 = xform.m12();
     1666    win_xform.eM21 = xform.m21();
     1667    win_xform.eM22 = xform.m22();
     1668    win_xform.eDx = xform.dx();
     1669    win_xform.eDy = xform.dy();
     1670
     1671    SetGraphicsMode(hdc, GM_ADVANCED);
     1672    SetWorldTransform(hdc, &win_xform);
     1673#endif
     1674
     1675    if (fast) {
     1676        // fast path
     1677        QVarLengthArray<wchar_t> g(glyphs.numGlyphs);
     1678        for (int i = 0; i < glyphs.numGlyphs; ++i)
     1679            g[i] = glyphs.glyphs[i];
     1680        ExtTextOut(hdc,
     1681                   qRound(baseline_pos.x() + glyphs.offsets[0].x.toReal()),
     1682                   qRound(baseline_pos.y() + glyphs.offsets[0].y.toReal()),
     1683                   options, 0, convertToText ? convertedGlyphs : g.data(), glyphs.numGlyphs, 0);
    18361684    } else {
    1837         bool fast = !has_kerning && !(ti.flags & QTextItem::RightToLeft);
    1838         for(int i = 0; fast && i < glyphs.numGlyphs; i++) {
    1839             if (glyphs.offsets[i].x != 0 || glyphs.offsets[i].y != 0 || glyphs.justifications[i].space_18d6 != 0
    1840                 || glyphs.attributes[i].dontPrint) {
    1841                 fast = false;
    1842                 break;
     1685        QVarLengthArray<QFixedPoint> positions;
     1686        QVarLengthArray<glyph_t> _glyphs;
     1687
     1688        QTransform matrix = QTransform::fromTranslate(baseline_pos.x(), baseline_pos.y());
     1689        ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags,
     1690            _glyphs, positions);
     1691        if (_glyphs.size() == 0) {
     1692            SelectObject(hdc, old_font);
     1693            return;
     1694        }
     1695
     1696        convertToText = convertToText && glyphs.numGlyphs == _glyphs.size();
     1697        bool outputEntireItem = _glyphs.size() > 0;
     1698
     1699        if (outputEntireItem) {
     1700            options |= ETO_PDY;
     1701            QVarLengthArray<INT> glyphDistances(_glyphs.size() * 2);
     1702            QVarLengthArray<wchar_t> g(_glyphs.size());
     1703            for (int i=0; i<_glyphs.size() - 1; ++i) {
     1704                glyphDistances[i * 2] = qRound(positions[i + 1].x) - qRound(positions[i].x);
     1705                glyphDistances[i * 2 + 1] = qRound(positions[i + 1].y) - qRound(positions[i].y);
     1706                g[i] = _glyphs[i];
    18431707            }
    1844         }
     1708            glyphDistances[(_glyphs.size() - 1) * 2] = 0;
     1709            glyphDistances[(_glyphs.size() - 1) * 2 + 1] = 0;
     1710            g[_glyphs.size() - 1] = _glyphs[_glyphs.size() - 1];
     1711            ExtTextOut(hdc, qRound(positions[0].x), qRound(positions[0].y), options, 0,
     1712                       convertToText ? convertedGlyphs : g.data(), _glyphs.size(),
     1713                       glyphDistances.data());
     1714        } else {
     1715            int i = 0;
     1716            while(i < _glyphs.size()) {
     1717                wchar_t g = _glyphs[i];
     1718
     1719                ExtTextOut(hdc, qRound(positions[i].x),
     1720                           qRound(positions[i].y), options, 0,
     1721                           convertToText ? convertedGlyphs + i : &g, 1, 0);
     1722                ++i;
     1723            }
     1724        }
     1725    }
    18451726
    18461727#if !defined(Q_OS_WINCE)
    1847         // Scale, rotate and translate here. This is only valid for systems > Windows Me.
    1848         // We should never get here on Windows Me or lower if the transformation specifies
    1849         // scaling or rotation.
    1850         QT_WA({
    1851             XFORM win_xform;
    1852             win_xform.eM11 = xform.m11();
    1853             win_xform.eM12 = xform.m12();
    1854             win_xform.eM21 = xform.m21();
    1855             win_xform.eM22 = xform.m22();
    1856             win_xform.eDx = xform.dx();
    1857             win_xform.eDy = xform.dy();
    1858             SetGraphicsMode(hdc, GM_ADVANCED);
    1859             SetWorldTransform(hdc, &win_xform);
    1860         }, {
    1861             // nothing
    1862         });
     1728        win_xform.eM11 = win_xform.eM22 = 1.0;
     1729        win_xform.eM12 = win_xform.eM21 = win_xform.eDx = win_xform.eDy = 0.0;
     1730        SetWorldTransform(hdc, &win_xform);
    18631731#endif
    18641732
    1865         if (fast) {
    1866             // fast path
    1867             QVarLengthArray<wchar_t> g(glyphs.numGlyphs);
    1868             for (int i = 0; i < glyphs.numGlyphs; ++i)
    1869                 g[i] = glyphs.glyphs[i];
    1870             ExtTextOutW(hdc,
    1871                         qRound(baseline_pos.x() + glyphs.offsets[0].x.toReal()),
    1872                         qRound(baseline_pos.y() + glyphs.offsets[0].y.toReal()),
    1873                         options, 0, convertToText ? convertedGlyphs : g.data(), glyphs.numGlyphs, 0);
    1874         } else {
    1875             QVarLengthArray<QFixedPoint> positions;
    1876             QVarLengthArray<glyph_t> _glyphs;
    1877 
    1878             QTransform matrix;
    1879             matrix.translate(baseline_pos.x(), baseline_pos.y());
    1880             ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags,
    1881                 _glyphs, positions);
    1882             if (_glyphs.size() == 0) {
    1883                 SelectObject(hdc, old_font);
    1884                 return;
    1885             }
    1886 
    1887             convertToText = convertToText && glyphs.numGlyphs == _glyphs.size();
    1888 
    1889             bool outputEntireItem = (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)
    1890                 && QSysInfo::WindowsVersion != QSysInfo::WV_NT
    1891                 && _glyphs.size() > 0;
    1892 
    1893             if (outputEntireItem) {
    1894                 options |= ETO_PDY;
    1895                 QVarLengthArray<INT> glyphDistances(_glyphs.size() * 2);
    1896                 QVarLengthArray<wchar_t> g(_glyphs.size());
    1897                 for (int i=0; i<_glyphs.size() - 1; ++i) {
    1898                     glyphDistances[i * 2] = qRound(positions[i + 1].x) - qRound(positions[i].x);
    1899                     glyphDistances[i * 2 + 1] = qRound(positions[i + 1].y) - qRound(positions[i].y);
    1900                     g[i] = _glyphs[i];
    1901                 }
    1902                 glyphDistances[(_glyphs.size() - 1) * 2] = 0;
    1903                 glyphDistances[(_glyphs.size() - 1) * 2 + 1] = 0;
    1904                 g[_glyphs.size() - 1] = _glyphs[_glyphs.size() - 1];
    1905                 ExtTextOutW(hdc, qRound(positions[0].x), qRound(positions[0].y), options, 0,
    1906                             convertToText ? convertedGlyphs : g.data(), _glyphs.size(),
    1907                             glyphDistances.data());
    1908             } else {
    1909                 int i = 0;
    1910                 while(i < _glyphs.size()) {
    1911                     wchar_t g = _glyphs[i];
    1912 
    1913                     ExtTextOutW(hdc, qRound(positions[i].x),
    1914                         qRound(positions[i].y), options, 0,
    1915                                 convertToText ? convertedGlyphs + i : &g, 1, 0);
    1916                     ++i;
     1733    SelectObject(hdc, old_font);
     1734}
     1735
     1736
     1737void QWin32PrintEnginePrivate::updateCustomPaperSize()
     1738{
     1739    uint paperSize = devMode->dmPaperSize;
     1740    if (paperSize > 0 && mapDevmodePaperSize(paperSize) == QPrinter::Custom) {
     1741        has_custom_paper_size = true;
     1742        DWORD needed = 0;
     1743        DWORD returned = 0;
     1744        if (!EnumForms(hPrinter, 1, 0, 0, &needed, &returned)) {
     1745            BYTE *forms = (BYTE *) malloc(needed);
     1746            if (EnumForms(hPrinter, 1, forms, needed, &needed, &returned)) {
     1747                if (paperSize <= returned) {
     1748                    FORM_INFO_1 *formArray = (FORM_INFO_1 *) forms;
     1749                    int width = formArray[paperSize - 1].Size.cx; // 1/1000 of a mm
     1750                    int height = formArray[paperSize - 1].Size.cy; // 1/1000 of a mm
     1751                    paper_size = QSizeF((width * 72 /25.4) / 1000.0, (height * 72 / 25.4) / 1000.0);
     1752                } else {
     1753                    has_custom_paper_size = false;
    19171754                }
    19181755            }
    1919         }
    1920 
    1921 #if !defined(Q_OS_WINCE)
    1922         QT_WA({
    1923             XFORM win_xform;
    1924             win_xform.eM11 = win_xform.eM22 = 1.0;
    1925             win_xform.eM12 = win_xform.eM21 = win_xform.eDx = win_xform.eDy = 0.0;
    1926             SetWorldTransform(hdc, &win_xform);
    1927         }, {
    1928             // nothing
    1929         });
    1930 #endif
    1931     }
    1932     SelectObject(hdc, old_font);
    1933 }
    1934 
    1935 
    1936 void QWin32PrintEnginePrivate::updateCustomPaperSize()
    1937 {
    1938     QT_WA( {
    1939         uint paperSize = devModeW()->dmPaperSize;
    1940         if (paperSize > 0 && mapDevmodePaperSize(paperSize) == QPrinter::Custom) {
    1941             has_custom_paper_size = true;
    1942             DWORD needed = 0;
    1943             DWORD returned = 0;
    1944             if (!EnumForms(hPrinter, 1, 0, 0, &needed, &returned)) {
    1945                 BYTE *forms = (BYTE *) malloc(needed);
    1946                 if (EnumForms(hPrinter, 1, forms, needed, &needed, &returned)) {
    1947                     if (paperSize <= returned) {
    1948                         FORM_INFO_1 *formArray = (FORM_INFO_1 *) forms;
    1949                         int width = formArray[paperSize-1].Size.cx; // 1/1000 of a mm
    1950                         int height = formArray[paperSize-1].Size.cy; // 1/1000 of a mm
    1951                         paper_size = QSizeF((width*72/25.4)/1000.0, (height*72/25.4)/1000.0);
    1952                     } else {
    1953                         has_custom_paper_size = false;
    1954                     }
    1955                 }
    1956                 free(forms);
    1957             }
    1958         } else {
    1959             has_custom_paper_size = false;
    1960         }
    1961     }, {
    1962         // Not supported under Win98
    1963     } );
     1756            free(forms);
     1757        }
     1758    } else {
     1759        has_custom_paper_size = false;
     1760    }
    19641761}
    19651762
Note: See TracChangeset for help on using the changeset viewer.