Changeset 561 for trunk/src/gui/painting/qprintengine_win.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/painting/qprintengine_win.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 200 200 d->fileName = d->port; 201 201 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 } 229 214 230 215 if (StartPage(d->hdc) <= 0) { … … 318 303 bool success = false; 319 304 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 DC323 // restorePainter = true;324 // }325 305 if (EndPage(d->hdc) != SP_ERROR) { 326 306 // reinitialize the DC before StartPage if needed, … … 338 318 success = (StartPage(d->hdc) != SP_ERROR); 339 319 } 340 if (!success) 320 if (!success) { 341 321 d->state = QPrinter::Aborted; 342 343 // if (qWinVersion() & Qt::WV_DOS_based)344 // if (restorePainter) {345 // painter->restore();346 // }347 348 if (!success)349 322 return false; 323 } 350 324 } 351 325 return true; … … 370 344 bool fallBack = state->pen().brush().style() != Qt::SolidPattern 371 345 || qAlpha(brushColor) != 0xff 372 || QT_WA_INLINE(d->txop >= QTransform::TxProject, d->txop >= QTransform::TxScale)346 || d->txop >= QTransform::TxProject 373 347 || ti.fontEngine->type() != QFontEngine::Win; 374 348 … … 381 355 382 356 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); 394 361 } 395 362 } … … 401 368 } 402 369 403 // We only want to convert the glyphs to text if the entire string is latin1404 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; 405 372 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; 408 380 break; 409 381 } … … 415 387 SetTextColor(d->hdc, cf); 416 388 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()); 418 390 DeleteObject(SelectObject(d->hdc,GetStockObject(HOLLOW_BRUSH))); 419 391 DeleteObject(SelectObject(d->hdc,GetStockObject(BLACK_PEN))); … … 664 636 qreal scaleY = 1.0f; 665 637 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()); 668 639 QTransform adapted = QPixmap::trueMatrix(d->painterMatrix * scaleMatrix, 669 640 pixmap.width(), pixmap.height()); … … 863 834 { 864 835 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 866 855 HGDIOBJ old_pen = SelectObject(hdc, pen); 867 856 StrokePath(hdc); … … 967 956 */ 968 957 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 985 966 QStringList info = output.split(QLatin1Char(',')); 986 967 if (info.size() > 0) { … … 1014 995 txop = QTransform::TxNone; 1015 996 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); 1023 998 if (!ok) { 1024 999 qErrnoWarning("QWin32PrintEngine::initialize: OpenPrinter failed"); … … 1029 1004 // printer settings. 1030 1005 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); 1047 1010 1048 1011 if (!ok) { … … 1057 1020 } 1058 1021 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); 1071 1025 1072 1026 Q_ASSERT(hPrinter); … … 1074 1028 1075 1029 if (devMode) { 1076 QT_WA( { 1077 num_copies = devModeW()->dmCopies; 1078 }, { 1079 num_copies = devModeA()->dmCopies; 1080 } ); 1030 num_copies = devMode->dmCopies; 1081 1031 } 1082 1032 … … 1196 1146 { 1197 1147 // Read the supported resolutions of the printer. 1198 DWORD numRes;1199 LONG *enumRes;1200 DWORD errRes;1201 1148 QList<QVariant> list; 1202 1149 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); 1220 1160 1221 1161 if (errRes == (DWORD)-1) { … … 1225 1165 1226 1166 for (uint i=0; i<numRes; ++i) 1227 list.append(int(enumRes[i*2])); 1167 list.append(int(enumRes[i * 2])); 1168 1228 1169 return list; 1229 1170 } … … 1269 1210 if (!d->devMode) 1270 1211 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; 1274 1213 d->doReinit(); 1275 1214 } … … 1280 1219 if (!d->devMode) 1281 1220 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; 1284 1222 d->doReinit(); 1285 1223 } … … 1307 1245 break; 1308 1246 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; 1311 1248 d->doReinit(); 1312 1249 break; … … 1317 1254 break; 1318 1255 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; 1327 1258 if (d->has_custom_paper_size && old_orientation != orientation) 1328 1259 d->paper_size = QSizeF(d->paper_size.height(), d->paper_size.width()); … … 1343 1274 if (!d->devMode) 1344 1275 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())); 1350 1277 d->has_custom_paper_size = (QPrinter::PaperSize(value.toInt()) == QPrinter::Custom); 1351 1278 d->doReinit(); … … 1362 1289 dmMapped = mapPaperSourceDevmode(QPrinter::PaperSource(value.toInt())); 1363 1290 1364 QT_WA( { 1365 d->devModeW()->dmDefaultSource = dmMapped; 1366 }, { 1367 d->devModeA()->dmDefaultSource = dmMapped; 1368 } ); 1291 d->devMode->dmDefaultSource = dmMapped; 1369 1292 d->doReinit(); 1370 1293 } … … 1400 1323 break; 1401 1324 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(); 1407 1326 d->doReinit(); 1408 1327 break; … … 1414 1333 if (!d->devMode) 1415 1334 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; 1436 1352 } 1437 1353 } 1438 free(forms);1439 1354 } 1440 }, { 1441 orientation = d->devModeA()->dmOrientation; 1442 } ); 1355 free(forms); 1356 } 1443 1357 if (orientation != DMORIENT_PORTRAIT) 1444 1358 d->paper_size = QSizeF(d->paper_size.height(), d->paper_size.width()); … … 1452 1366 int left, top, right, bottom; 1453 1367 // specified in 1/100 mm 1454 left = (margins.at(0).to Double()*25.4/72.0) * 100;1455 top = (margins.at(1).to Double()*25.4/72.0) * 100;1456 right = (margins.at(2).to Double()*25.4/72.0) * 100;1457 bottom = (margins.at(3).to Double()*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; 1458 1372 d->setPageMargins(left, top, right, bottom); 1459 1373 break; … … 1480 1394 value = QPrinter::Color; 1481 1395 } 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; 1489 1397 } 1490 1398 } … … 1508 1416 value = QPrinter::Portrait; 1509 1417 } 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; 1513 1419 } 1514 1420 } … … 1533 1439 } else { 1534 1440 value = QTransform(1/d->stretch_x, 0, 0, 1/d->stretch_y, 0, 0) 1535 .mapRect(d->fullPage ? d->devP aperRect : d->devPageRect);1441 .mapRect(d->fullPage ? d->devPhysicalPageRect : d->devPageRect); 1536 1442 } 1537 1443 break; … … 1544 1450 value = QPrinter::A4; 1545 1451 } else { 1546 QT_WA( { 1547 value = mapDevmodePaperSize(d->devModeW()->dmPaperSize); 1548 }, { 1549 value = mapDevmodePaperSize(d->devModeA()->dmPaperSize); 1550 } ); 1452 value = mapDevmodePaperSize(d->devMode->dmPaperSize); 1551 1453 } 1552 1454 } … … 1567 1469 value = QPrinter::Auto; 1568 1470 } else { 1569 QT_WA( { 1570 value = mapDevmodePaperSource(d->devModeW()->dmDefaultSource); 1571 }, { 1572 value = mapDevmodePaperSource(d->devModeA()->dmDefaultSource); 1573 } ); 1471 value = mapDevmodePaperSource(d->devMode->dmDefaultSource); 1574 1472 } 1575 1473 break; … … 1592 1490 value = -1; 1593 1491 } else { 1594 QT_WA( { 1595 value = d->devModeW()->dmPaperSize; 1596 }, { 1597 value = d->devModeA()->dmPaperSize; 1598 } ); 1492 value = d->devMode->dmPaperSize; 1599 1493 } 1600 1494 break; … … 1602 1496 case PPK_PaperSources: 1603 1497 { 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); 1614 1500 1615 1501 if (available <= 0) 1616 1502 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); 1626 1507 1627 1508 QList<QVariant> out; … … 1632 1513 } 1633 1514 value = out; 1634 free(data); 1515 1516 delete [] data; 1635 1517 } 1636 1518 break; … … 1677 1559 HGLOBAL *QWin32PrintEnginePrivate::createDevNames() 1678 1560 { 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); 1697 1578 1698 1579 // printf("QPrintDialogWinPrivate::createDevNames()\n" … … 1705 1586 1706 1587 // 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; 1732 1593 } 1733 1594 … … 1735 1596 { 1736 1597 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); 1750 1603 } 1751 1604 } … … 1754 1607 { 1755 1608 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."); 1778 1619 } 1779 1620 … … 1782 1623 } 1783 1624 1784 static void draw_text_item_win(const QPointF & _pos, const QTextItemInt &ti, HDC hdc,1625 static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC hdc, 1785 1626 bool convertToText, const QTransform &xform, const QPointF &topLeft) 1786 1627 { 1787 1788 // Make sure we translate for systems that can't handle world transforms1789 QPointF pos(QT_WA_INLINE(_pos, _pos + QPointF(xform.dx(), xform.dy())));1790 1628 QFontEngine *fe = ti.fontEngine; 1791 1629 QPointF baseline_pos = xform.inverted().map(xform.map(pos) - topLeft); … … 1799 1637 HFONT hfont; 1800 1638 bool ttf = false; 1801 bool useTextOutA = false;1802 1639 1803 1640 if (winfe) { 1804 1641 hfont = winfe->hfont; 1805 1642 ttf = winfe->ttf; 1806 useTextOutA = winfe->useTextOutA;1807 1643 } else { 1808 1644 hfont = (HFONT)GetStockObject(ANSI_VAR_FONT); … … 1814 1650 QGlyphLayout glyphs = ti.glyphs; 1815 1651 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); 1836 1684 } 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]; 1843 1707 } 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 } 1845 1726 1846 1727 #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); 1863 1731 #endif 1864 1732 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 1737 void 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; 1917 1754 } 1918 1755 } 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 } 1964 1761 } 1965 1762
Note:
See TracChangeset
for help on using the changeset viewer.