49 #include <private/qfont_p.h> 50 #include <private/qfontengine_p.h> 51 #include <private/qpainter_p.h> 57 #include <private/qpicture_p.h> 73 { DMPAPER_LETTERSMALL, QPrinter::Letter },
80 { DMPAPER_A4SMALL, QPrinter::A4 },
88 { DMPAPER_LETTER_EXTRA, QPrinter::Letter },
89 { DMPAPER_LEGAL_EXTRA, QPrinter::Legal },
90 { DMPAPER_TABLOID_EXTRA, QPrinter::Tabloid },
91 { DMPAPER_A4_EXTRA, QPrinter::A4},
92 { DMPAPER_LETTER_TRANSVERSE, QPrinter::Letter},
93 { DMPAPER_A4_TRANSVERSE, QPrinter::A4},
94 { DMPAPER_LETTER_EXTRA_TRANSVERSE, QPrinter::Letter },
95 { DMPAPER_A_PLUS, QPrinter::A4 },
96 { DMPAPER_B_PLUS, QPrinter::A3 },
97 { DMPAPER_LETTER_PLUS, QPrinter::Letter },
98 { DMPAPER_A4_PLUS, QPrinter::A4 },
99 { DMPAPER_A5_TRANSVERSE, QPrinter::A5 },
100 { DMPAPER_B5_TRANSVERSE, QPrinter::B5 },
101 { DMPAPER_A3_EXTRA, QPrinter::A3 },
102 { DMPAPER_A5_EXTRA, QPrinter::A5 },
103 { DMPAPER_B5_EXTRA, QPrinter::B5 },
105 { DMPAPER_A3_TRANSVERSE, QPrinter::A3 },
106 { DMPAPER_A3_EXTRA_TRANSVERSE,QPrinter::A3 },
126 static const struct {
164 PaintEngineFeatures(PrimitiveTransform
166 | PerspectiveTransform
169 | PaintOutsidePaintEvent))
199 if (
d->printToFile &&
d->fileName.isEmpty())
200 d->fileName =
d->port;
202 d->devMode->dmCopies =
d->num_copies;
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) {
215 if (StartPage(
d->hdc) <= 0) {
229 d->has_brush =
false;
231 d->complex_xform =
false;
278 if (!EndPage(
d->hdc)) {
291 if (!StartPage(
d->hdc)) {
292 qErrnoWarning(
"Win32PrintEngine::newPage: StartPage failed");
296 SetTextAlign(
d->hdc, TA_BASELINE);
298 SetBkMode(
d->hdc, TRANSPARENT);
303 bool success =
false;
305 if (EndPage(
d->hdc) != SP_ERROR) {
315 qErrnoWarning(
"QWin32PrintEngine::newPage(), ResetDC failed (2)");
318 success = (StartPage(
d->hdc) != SP_ERROR);
345 ||
qAlpha(brushColor) != 0xff
354 SelectObject(
d->hdc, fe->
hfont);
356 if (GetDeviceCaps(
d->hdc, TECHNOLOGY) != DT_CHARSTREAM) {
358 GetTextFace(
d->hdc, 64, n);
372 bool convertToText = ti.
chars != 0;
375 convertToText =
false;
380 convertToText =
false;
385 COLORREF cf = RGB(
qRed(brushColor),
qGreen(brushColor),
qBlue(brushColor));
386 SelectObject(
d->hdc, CreateSolidBrush(cf));
387 SelectObject(
d->hdc, CreatePen(PS_SOLID, 1, cf));
388 SetTextColor(
d->hdc, cf);
391 DeleteObject(SelectObject(
d->hdc,GetStockObject(HOLLOW_BRUSH)));
392 DeleteObject(SelectObject(
d->hdc,GetStockObject(BLACK_PEN)));
397 return mm*0.039370147;
402 return in/0.039370147;
413 int res =
d->resolution;
417 if (
d->has_custom_paper_size) {
418 val =
qRound(
d->paper_size.width() * res / 72.0);
420 int logPixelsX = GetDeviceCaps(
d->hdc, LOGPIXELSX);
421 if (logPixelsX == 0) {
422 qWarning(
"QWin32PrintEngine::metric: GetDeviceCaps() failed, " 423 "might be a driver problem");
427 * GetDeviceCaps(
d->hdc,
d->fullPage ? PHYSICALWIDTH : HORZRES)
430 if (
d->pageMarginsSet)
431 val -= int(
mmToInches((
d->previousDialogMargins.left() +
432 d->previousDialogMargins.width()) / 100.0) * res);
435 if (
d->has_custom_paper_size) {
436 val =
qRound(
d->paper_size.height() * res / 72.0);
438 int logPixelsY = GetDeviceCaps(
d->hdc, LOGPIXELSY);
439 if (logPixelsY == 0) {
440 qWarning(
"QWin32PrintEngine::metric: GetDeviceCaps() failed, " 441 "might be a driver problem");
445 * GetDeviceCaps(
d->hdc,
d->fullPage ? PHYSICALHEIGHT : VERTRES)
448 if (
d->pageMarginsSet)
449 val -= int(
mmToInches((
d->previousDialogMargins.top() +
450 d->previousDialogMargins.height()) / 100.0) * res);
459 val = GetDeviceCaps(
d->hdc, LOGPIXELSX);
462 val = GetDeviceCaps(
d->hdc, LOGPIXELSY);
465 if (
d->has_custom_paper_size) {
466 val =
qRound(
d->paper_size.width()*25.4/72);
469 val = GetDeviceCaps(
d->hdc, HORZSIZE);
471 float wi = 25.4 * GetDeviceCaps(
d->hdc, PHYSICALWIDTH);
472 int logPixelsX = GetDeviceCaps(
d->hdc, LOGPIXELSX);
473 if (logPixelsX == 0) {
474 qWarning(
"QWin32PrintEngine::metric: GetDeviceCaps() failed, " 475 "might be a driver problem");
478 val =
qRound(wi / logPixelsX);
481 if (
d->pageMarginsSet)
482 val -= (
d->previousDialogMargins.left() +
483 d->previousDialogMargins.width()) / 100.0;
486 if (
d->has_custom_paper_size) {
487 val =
qRound(
d->paper_size.height()*25.4/72);
490 val = GetDeviceCaps(
d->hdc, VERTSIZE);
492 float hi = 25.4 * GetDeviceCaps(
d->hdc, PHYSICALHEIGHT);
493 int logPixelsY = GetDeviceCaps(
d->hdc, LOGPIXELSY);
494 if (logPixelsY == 0) {
495 qWarning(
"QWin32PrintEngine::metric: GetDeviceCaps() failed, " 496 "might be a driver problem");
499 val =
qRound(hi / logPixelsY);
502 if (
d->pageMarginsSet)
503 val -= (
d->previousDialogMargins.top() +
504 d->previousDialogMargins.height()) / 100.0;
508 int bpp = GetDeviceCaps(
d->hdc, BITSPIXEL);
512 val = GetDeviceCaps(
d->hdc, NUMCOLORS);
514 val = 1 << (bpp * GetDeviceCaps(
d->hdc, PLANES));
518 val = GetDeviceCaps(
d->hdc, PLANES);
521 qWarning(
"QPrinter::metric: Invalid metric command");
540 d->pen = state.
pen();
541 d->has_pen =
d->pen.style() !=
Qt::NoPen &&
d->pen.isSolid();
547 d->brush_color = brush.
color();
574 SelectClipRgn(
d->hdc, 0);
582 QRegion empty(-0x1000000, -0x1000000, 1, 1);
583 SelectClipRgn(
d->hdc, empty.
handle());
585 d->composeGdiPath(xformed);
592 Q_ASSERT(op > 0 &&
unsigned(op) <=
sizeof(ops) /
sizeof(
int));
593 SelectClipPath(
d->hdc, ops[op]);
599 QTransform tx(
d->stretch_x, 0, 0,
d->stretch_y,
d->origin_x,
d->origin_y);
600 d->composeGdiPath(tx.
map(aclip));
601 SelectClipPath(
d->hdc, RGN_DIFF);
609 QTransform stretch(
d->stretch_x, 0, 0,
d->stretch_y,
d->origin_x,
d->origin_y);
610 d->painterMatrix = m;
611 d->matrix =
d->painterMatrix * stretch;
612 d->txop =
d->matrix.type();
631 QPixmap pixmap = originalPixmap;
643 qreal xform_offset_x = adapted.
dx();
644 qreal xform_offset_y = adapted.dy();
646 if (
d->complex_xform) {
648 scaleX =
d->stretch_x;
649 scaleY =
d->stretch_y;
651 scaleX =
d->stretch_x * (r.
width() / pixmap.
width()) *
d->painterMatrix.m11();
652 scaleY =
d->stretch_y * (r.
height() / pixmap.
height()) *
d->painterMatrix.m22();
656 int tx = int(topLeft.
x() *
d->stretch_x +
d->origin_x);
657 int ty = int(topLeft.
y() *
d->stretch_y +
d->origin_y);
658 int tw =
qAbs(
int(pixmap.
width() * scaleX));
661 xform_offset_x *=
d->stretch_x;
662 xform_offset_y *=
d->stretch_y;
664 int dc_state = SaveDC(
d->hdc);
671 int txinc = tileSize*scaleX;
672 int tyinc = tileSize*scaleY;
674 for (
int y = 0; y < tilesh; ++y) {
675 int tposy = ty + (y * tyinc);
678 if (y == (tilesh - 1)) {
680 height = (th - (y * tyinc));
682 for (
int x = 0; x < tilesw; ++x) {
683 int tposx = tx + (x * txinc);
686 if (x == (tilesw - 1)) {
688 width = (tw - (x * txinc));
691 QPixmap p = pixmap.
copy(tileSize * x, tileSize * y, imgw, imgh);
693 HDC display_dc = GetDC(0);
694 HDC hbitmap_hdc = CreateCompatibleDC(display_dc);
695 HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap);
697 ReleaseDC(0, display_dc);
699 if (!StretchBlt(
d->hdc,
qRound(tposx - xform_offset_x),
qRound(tposy - xform_offset_y), width, height,
700 hbitmap_hdc, 0, 0, p.
width(), p.
height(), SRCCOPY))
701 qErrnoWarning(
"QWin32PrintEngine::drawPixmap, StretchBlt failed");
703 SelectObject(hbitmap_hdc, null_bitmap);
704 DeleteObject(hbitmap);
705 DeleteDC(hbitmap_hdc);
709 RestoreDC(
d->hdc, dc_state);
721 if (
d->complex_xform || !pos.
isNull()) {
724 int dc_state = SaveDC(
d->hdc);
726 HDC display_dc = GetDC(0);
728 HDC hbitmap_hdc = CreateCompatibleDC(display_dc);
729 HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap);
731 ReleaseDC(0, display_dc);
733 QRectF trect =
d->painterMatrix.mapRect(r);
734 int tx = int(trect.
left() *
d->stretch_x +
d->origin_x);
735 int ty = int(trect.
top() *
d->stretch_y +
d->origin_y);
737 int xtiles = int(trect.
width() / pm.
width()) + 1;
739 int xinc = int(pm.
width() *
d->stretch_x);
740 int yinc = int(pm.
height() *
d->stretch_y);
742 for (
int y = 0; y < ytiles; ++y) {
743 int ity = ty + (yinc * y);
745 if (y == (ytiles - 1)) {
749 for (
int x = 0; x < xtiles; ++x) {
750 int itx = tx + (xinc * x);
751 int itw = pm.
width();
752 if (x == (xtiles - 1)) {
756 if (!StretchBlt(
d->hdc, itx, ity,
int(itw *
d->stretch_x),
int(ith *
d->stretch_y),
757 hbitmap_hdc, 0, 0, itw, ith, SRCCOPY))
758 qErrnoWarning(
"QWin32PrintEngine::drawPixmap, StretchBlt failed");
763 SelectObject(hbitmap_hdc, null_bitmap);
764 DeleteObject(hbitmap);
765 DeleteDC(hbitmap_hdc);
767 RestoreDC(
d->hdc, dc_state);
775 qErrnoWarning(
"QWin32PrintEnginePrivate::drawPath: BeginPath failed");
800 PolyBezierTo(hdc, pts, 3);
804 qFatal(
"QWin32PaintEngine::drawPath: Unhandled type: %d", elm.
type);
814 qErrnoWarning(
"QWin32PaintEngine::drawPath: EndPath failed");
823 qDebug() <<
" --- QWin32PrintEnginePrivate::fillPath() bound:" << path.
boundingRect() << color;
826 composeGdiPath(path);
828 HBRUSH brush = CreateSolidBrush(RGB(color.
red(), color.
green(), color.
blue()));
829 HGDIOBJ old_brush = SelectObject(hdc, brush);
831 DeleteObject(SelectObject(hdc, old_brush));
836 composeGdiPath(path);
838 brush.lbStyle = BS_SOLID;
839 brush.lbColor = RGB(color.
red(), color.
green(), color.
blue());
840 DWORD capStyle = PS_ENDCAP_SQUARE;
841 DWORD joinStyle = PS_JOIN_BEVEL;
843 capStyle = PS_ENDCAP_FLAT;
845 capStyle = PS_ENDCAP_ROUND;
848 joinStyle = PS_JOIN_MITER;
850 joinStyle = PS_JOIN_ROUND;
852 HPEN pen = ExtCreatePen(((penWidth == 0) ? PS_COSMETIC : PS_GEOMETRIC)
853 | PS_SOLID | capStyle | joinStyle,
854 (penWidth == 0) ? 1 : penWidth, &brush, 0, 0);
856 HGDIOBJ old_pen = SelectObject(hdc, pen);
858 DeleteObject(SelectObject(hdc, old_pen));
864 fillPath_dev(path * matrix, color);
881 qreal width = pen.widthF();
883 strokePath_dev(path * matrix, color, width);
886 if (pen.isCosmetic()) {
890 QTransform stretch(stretch_x, 0, 0, stretch_y, origin_x, origin_y);
891 stroke = stroke * stretch;
897 fillPath_dev(stroke, color);
915 d->fillPath(path,
d->brush_color);
918 d->strokePath(path,
d->pen.color());
925 qDebug() <<
" - QWin32PrintEngine::drawPolygon(), pointCount: " << pointCount;
936 for (
int i=1; i<pointCount; ++i) {
942 bool has_brush =
d->has_brush;
945 d->has_brush =
false;
950 d->has_brush = has_brush;
960 GetProfileString(L
"windows", L
"device",
961 reinterpret_cast<const wchar_t *>(noPrinters.
utf16()),
964 if (output.
isEmpty() || output == noPrinters)
968 int infoSize = info.
size();
972 if (program.isEmpty() && infoSize > 1)
973 program = info.
at(1);
974 if (port.isEmpty() && infoSize > 2)
999 bool ok = OpenPrinter((LPWSTR)
name.utf16(), (LPHANDLE)&hPrinter, 0);
1001 qErrnoWarning(
"QWin32PrintEngine::initialize: OpenPrinter failed");
1007 DWORD infoSize, numBytes;
1008 GetPrinter(hPrinter, 2, NULL, 0, &infoSize);
1009 hMem = GlobalAlloc(GHND, infoSize);
1010 pInfo = (PRINTER_INFO_2*) GlobalLock(hMem);
1011 ok = GetPrinter(hPrinter, 2, (LPBYTE)pInfo, infoSize, &numBytes);
1014 qErrnoWarning(
"QWin32PrintEngine::initialize: GetPrinter failed");
1015 GlobalUnlock(pInfo);
1017 ClosePrinter(hPrinter);
1024 devMode = pInfo->pDevMode;
1025 hdc = CreateDC(reinterpret_cast<const wchar_t *>(program.utf16()),
1026 reinterpret_cast<const wchar_t *>(
name.utf16()), 0, devMode);
1032 num_copies = devMode->dmCopies;
1037 #ifdef QT_DEBUG_DRAW 1038 qDebug() <<
"QWin32PrintEngine::initialize()" <<
endl 1039 <<
" - paperRect" << devPaperRect <<
endl 1040 <<
" - pageRect" << devPageRect <<
endl 1041 <<
" - stretch_x" << stretch_x <<
endl 1042 <<
" - stretch_y" << stretch_y <<
endl 1043 <<
" - origin_x" << origin_x <<
endl 1044 <<
" - origin_y" << origin_y <<
endl;
1052 HDC display_dc = GetDC(0);
1053 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
1054 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
1055 dpi_display = GetDeviceCaps(display_dc, LOGPIXELSY);
1056 ReleaseDC(0, display_dc);
1057 if (dpi_display == 0) {
1058 qWarning(
"QWin32PrintEngine::metric: GetDeviceCaps() failed, " 1059 "might be a driver problem");
1065 resolution = dpi_display;
1066 stretch_x = dpi_x / double(dpi_display);
1067 stretch_y = dpi_y / double(dpi_display);
1084 devPaperRect =
QRect(0, 0,
1085 GetDeviceCaps(hdc, PHYSICALWIDTH),
1086 GetDeviceCaps(hdc, PHYSICALHEIGHT));
1087 devPhysicalPageRect =
QRect(GetDeviceCaps(hdc, PHYSICALOFFSETX),
1088 GetDeviceCaps(hdc, PHYSICALOFFSETY),
1089 GetDeviceCaps(hdc, HORZRES),
1090 GetDeviceCaps(hdc, VERTRES));
1091 if (!pageMarginsSet)
1092 devPageRect = devPhysicalPageRect;
1094 devPageRect = devPaperRect.adjusted(
qRound(
mmToInches(previousDialogMargins.left() / 100.0) * dpi_x),
1103 pageMarginsSet =
true;
1104 previousDialogMargins =
QRect(marginLeft, marginTop, marginRight, marginBottom);
1106 devPageRect = devPaperRect.adjusted(
qRound(
mmToInches(marginLeft / 100.0) * dpi_x),
1116 return previousDialogMargins;
1120 qRound(
inchesToMM(devPaperRect.right() - devPhysicalPageRect.right()) * 100.0 / dpi_x),
1121 qRound(
inchesToMM(devPaperRect.bottom() - devPhysicalPageRect.bottom()) * 100.0 / dpi_y));
1129 if (globalDevMode) {
1130 GlobalUnlock(globalDevMode);
1137 ClosePrinter(hPrinter);
1152 DWORD numRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(
name.utf16()),
1153 reinterpret_cast<const wchar_t *>(port.utf16()),
1154 DC_ENUMRESOLUTIONS, 0, 0);
1155 if (numRes == (DWORD)-1)
1158 LONG *enumRes = (LONG*)malloc(numRes * 2 *
sizeof(LONG));
1159 DWORD errRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(
name.utf16()),
1160 reinterpret_cast<const wchar_t *>(port.utf16()),
1161 DC_ENUMRESOLUTIONS, (LPWSTR)enumRes, 0);
1163 if (errRes == (DWORD)-1) {
1164 qErrnoWarning(
"QWin32PrintEngine::queryResolutions: DeviceCapabilities failed");
1168 for (
uint i=0; i<numRes; ++i)
1169 list.
append(
int(enumRes[i * 2]));
1190 origin_x = -devPhysicalPageRect.x();
1191 origin_y = -devPhysicalPageRect.y();
1192 if (pageMarginsSet) {
1193 origin_x += devPageRect.left();
1194 origin_y += devPageRect.top();
1199 if (pageMarginsSet) {
1200 origin_x = devPageRect.left() - devPhysicalPageRect.x();
1201 origin_y = devPageRect.top() - devPhysicalPageRect.y();
1214 d->devMode->dmCollate = value.
toBool() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE;
1234 qWarning(
"QWin32PrintEngine: Cannot change document name while printing is active");
1249 d->num_copies = value.
toInt();
1250 d->devMode->dmCopies =
d->num_copies;
1259 int old_orientation =
d->devMode->dmOrientation;
1260 d->devMode->dmOrientation = orientation;
1261 if (
d->has_custom_paper_size && old_orientation != orientation)
1262 d->paper_size =
QSizeF(
d->paper_size.height(),
d->paper_size.width());
1269 qWarning(
"QWin32PrintEngine: Cannot change filename while printing");
1288 int dmMapped = DMBIN_AUTO;
1294 d->devMode->dmDefaultSource = dmMapped;
1301 if(
d->name.isEmpty())
1308 d->resolution = value.
toInt();
1310 d->stretch_x =
d->dpi_x / double(
d->resolution);
1311 d->stretch_y =
d->dpi_y / double(
d->resolution);
1327 d->has_custom_paper_size =
false;
1328 d->devMode->dmPaperSize = value.
toInt();
1334 d->has_custom_paper_size =
true;
1338 int orientation =
d->devMode->dmOrientation;
1341 if (!EnumForms(
d->hPrinter, 1, 0, 0, &needed, &returned)) {
1342 BYTE *forms = (
BYTE *) malloc(needed);
1343 if (EnumForms(
d->hPrinter, 1, forms, needed, &needed, &returned)) {
1344 for (DWORD i=0; i< returned; ++i) {
1345 FORM_INFO_1 *formArray =
reinterpret_cast<FORM_INFO_1 *
>(forms);
1348 QSizeF size((formArray[i].Size.cx * 72/25.4)/1000.0,
1349 (formArray[i].Size.cy * 72/25.4)/1000.0);
1350 if (
qAbs(
d->paper_size.width() - size.
width()) <= 2
1351 &&
qAbs(
d->paper_size.height() - size.
height()) <= 2)
1353 d->devMode->dmPaperSize = i + 1;
1360 if (orientation != DMORIENT_PORTRAIT)
1361 d->paper_size =
QSizeF(
d->paper_size.height(),
d->paper_size.width());
1371 left = (margins.at(0).toReal()*25.4/72.0) * 100;
1372 top = (margins.at(1).toReal()*25.4/72.0) * 100;
1373 right = (margins.at(2).toReal()*25.4/72.0) * 100;
1374 bottom = (margins.at(3).toReal()*25.4/72.0) * 100;
1375 d->setPageMargins(left, top, right, bottom);
1409 value =
d->fullPage;
1413 value =
d->num_copies;
1435 value =
d->fileName;
1439 if (
d->has_custom_paper_size) {
1441 qRound(
d->paper_size.width() *
d->resolution / 72.0),
1442 qRound(
d->paper_size.height() *
d->resolution / 72.0));
1443 if (
d->pageMarginsSet) {
1451 value =
QTransform(1/
d->stretch_x, 0, 0, 1/
d->stretch_y, 0, 0)
1452 .
mapRect(
d->fullPage ?
d->devPhysicalPageRect :
d->devPageRect);
1457 if (
d->has_custom_paper_size) {
1469 if (
d->has_custom_paper_size) {
1471 qRound(
d->paper_size.width() *
d->resolution / 72.0),
1472 qRound(
d->paper_size.height() *
d->resolution / 72.0));
1491 if (
d->resolution || !
d->name.isEmpty())
1492 value =
d->resolution;
1496 value =
d->queryResolutions();
1503 value =
d->devMode->dmPaperSize;
1509 int available = DeviceCapabilities((
const wchar_t *)
d->name.utf16(),
1510 (
const wchar_t *)
d->port.utf16(), DC_BINS, 0,
d->devMode);
1515 wchar_t *
data =
new wchar_t[available];
1516 int count = DeviceCapabilities((
const wchar_t *)
d->name.utf16(),
1517 (
const wchar_t *)
d->port.utf16(), DC_BINS,
data,
d->devMode);
1520 for (
int i=0; i<count; ++i) {
1532 value =
d->paper_size;
1538 QRect pageMargins(
d->getPageMargins());
1541 margins << (
mmToInches(pageMargins.left()/100.0) * 72)
1542 << (
mmToInches(pageMargins.top()/100.0) * 72)
1543 << (
mmToInches(pageMargins.width()/100.0) * 72)
1544 << (
mmToInches(pageMargins.height()/100.0) * 72);
1557 return d_func()->state;
1562 return d_func()->hdc;
1572 int size =
sizeof(DEVNAMES)
1573 + program.length() * 2 + 2
1574 +
name.length() * 2 + 2
1575 + port.length() * 2 + 2;
1576 HGLOBAL *hGlobal = (HGLOBAL *) GlobalAlloc(
GMEM_MOVEABLE, size);
1577 DEVNAMES *dn = (DEVNAMES*) GlobalLock(hGlobal);
1579 dn->wDriverOffset =
sizeof(DEVNAMES) /
sizeof(
wchar_t);
1580 dn->wDeviceOffset = dn->wDriverOffset + program.length() + 1;
1581 dn->wOutputOffset = dn->wDeviceOffset +
name.length() + 1;
1583 memcpy((
ushort*)dn + dn->wDriverOffset, program.utf16(), program.length() * 2 + 2);
1584 memcpy((
ushort*)dn + dn->wDeviceOffset,
name.utf16(),
name.length() * 2 + 2);
1585 memcpy((
ushort*)dn + dn->wOutputOffset, port.utf16(), port.length() * 2 + 2);
1588 GlobalUnlock(hGlobal);
1608 if (globalDevnames) {
1609 DEVNAMES *dn = (DEVNAMES*) GlobalLock(globalDevnames);
1613 GlobalUnlock(globalDevnames);
1619 if (globalDevmode) {
1620 DEVMODE *dm = (DEVMODE*) GlobalLock(globalDevmode);
1622 globalDevMode = globalDevmode;
1624 hdc = CreateDC(reinterpret_cast<const wchar_t *>(program.utf16()),
1625 reinterpret_cast<const wchar_t *>(
name.utf16()), 0, dm);
1627 num_copies = devMode->dmCopies;
1628 if (!OpenPrinter((
wchar_t*)
name.utf16(), &hPrinter, 0))
1629 qWarning(
"QPrinter: OpenPrinter() failed after reading DEVMODE.");
1642 SetTextAlign(hdc, TA_BASELINE);
1643 SetBkMode(hdc, TRANSPARENT);
1645 bool has_kerning = ti.
f && ti.
f->
kerning();
1652 hfont = winfe->
hfont;
1658 HGDIOBJ old_font = SelectObject(hdc, hfont);
1660 wchar_t *convertedGlyphs = (
wchar_t *)ti.
chars;
1664 for (
int i = 0; fast && i < glyphs.numGlyphs; i++) {
1665 if (glyphs.offsets[i].x != 0 || glyphs.offsets[i].y != 0 || glyphs.justifications[i].space_18d6 != 0
1666 || glyphs.attributes[i].dontPrint) {
1672 #if !defined(Q_OS_WINCE) 1675 win_xform.eM11 = xform.
m11();
1676 win_xform.eM12 = xform.
m12();
1677 win_xform.eM21 = xform.
m21();
1678 win_xform.eM22 = xform.
m22();
1679 win_xform.eDx = xform.
dx();
1680 win_xform.eDy = xform.
dy();
1682 SetGraphicsMode(hdc, GM_ADVANCED);
1683 SetWorldTransform(hdc, &win_xform);
1689 for (
int i = 0; i < glyphs.numGlyphs; ++i)
1690 g[i] = glyphs.glyphs[i];
1692 qRound(baseline_pos.
x() + glyphs.offsets[0].x.toReal()),
1693 qRound(baseline_pos.
y() + glyphs.offsets[0].y.toReal()),
1694 options, 0, convertToText ? convertedGlyphs : g.
data(), glyphs.numGlyphs, 0);
1701 _glyphs, positions);
1702 if (_glyphs.
size() == 0) {
1703 SelectObject(hdc, old_font);
1707 convertToText = convertToText && glyphs.numGlyphs == _glyphs.
size();
1708 bool outputEntireItem = _glyphs.
size() > 0;
1710 if (outputEntireItem) {
1714 for (
int i=0; i<_glyphs.
size() - 1; ++i) {
1715 glyphDistances[i * 2] =
qRound(positions[i + 1].x) -
qRound(positions[i].x);
1716 glyphDistances[i * 2 + 1] =
qRound(positions[i + 1].y) -
qRound(positions[i].y);
1719 glyphDistances[(_glyphs.
size() - 1) * 2] = 0;
1720 glyphDistances[(_glyphs.
size() - 1) * 2 + 1] = 0;
1721 g[_glyphs.
size() - 1] = _glyphs[_glyphs.
size() - 1];
1722 ExtTextOut(hdc,
qRound(positions[0].x),
qRound(positions[0].y), options, 0,
1723 convertToText ? convertedGlyphs : g.data(), _glyphs.
size(),
1724 glyphDistances.data());
1727 while(i < _glyphs.
size()) {
1728 wchar_t g = _glyphs[i];
1730 ExtTextOut(hdc,
qRound(positions[i].x),
1731 qRound(positions[i].y), options, 0,
1732 convertToText ? convertedGlyphs + i : &g, 1, 0);
1738 #if !defined(Q_OS_WINCE) 1739 win_xform.eM11 = win_xform.eM22 = 1.0;
1740 win_xform.eM12 = win_xform.eM21 = win_xform.eDx = win_xform.eDy = 0.0;
1741 SetWorldTransform(hdc, &win_xform);
1744 SelectObject(hdc, old_font);
1752 has_custom_paper_size =
true;
1755 if (!EnumForms(hPrinter, 1, 0, 0, &needed, &returned)) {
1756 BYTE *forms = (
BYTE *) malloc(needed);
1757 if (EnumForms(hPrinter, 1, forms, needed, &needed, &returned)) {
1758 if (paperSize <= returned) {
1759 FORM_INFO_1 *formArray = (FORM_INFO_1 *) forms;
1760 int width = formArray[paperSize - 1].Size.cx;
1761 int height = formArray[paperSize - 1].Size.cy;
1762 paper_size =
QSizeF((width * 72 /25.4) / 1000.0, (height * 72 / 25.4) / 1000.0);
1764 has_custom_paper_size =
false;
1770 has_custom_paper_size =
false;
1776 #endif // QT_NO_PRINTER ElementType type
the type of element
The QVariant class acts like a union for the most common Qt data types.
QPainterPath clipPath() const
Returns the currently clip as a path.
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
The QColor class provides colors based on RGB, HSV or CMYK values.
void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width)
void setDashOffset(qreal offset)
Sets the dash offset for the generated outlines to offset.
The QPainterPath::Element class specifies the position and type of a subpath.
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
QPaintEngine::DirtyFlags state() const
Returns a combination of flags identifying the set of properties that need to be updated when updatin...
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
PaperSize paperSize(QPrinter::PaperSize paperSize)
QList< QVariant > queryResolutions() const
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
static mach_timebase_info_data_t info
static QMatrix trueMatrix(const QMatrix &m, int w, int h)
This convenience function loads the matrix m into a QTransform and calls the overloaded function with...
#define QT_END_NAMESPACE
This macro expands to.
const QColor & color() const
Returns the brush color.
QPrinter::PaperSize qtSizeName
int width() const
Returns the width of the pixmap.
QSize size() const
Returns the size of the pixmap.
virtual void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
QPaintEngineState * state
void releaseDC(HDC) const
Empty default implementation.
static const struct @249 dmMapping[]
qreal width() const
Returns the width.
PrinterMode
This enum describes the mode the printer should work in.
static void draw_text_item_win(const QPointF &_pos, const QTextItemInt &ti, HDC hdc, bool convertToText, const QTransform &xform, const QPointF &topLeft)
qreal dx() const
Returns the horizontal translation factor.
QTransform transform() const
Returns the matrix in the current paint engine state.
void setCapStyle(Qt::PenCapStyle style)
Sets the cap style of the generated outlines to style.
~QWin32PrintEnginePrivate()
void readDevmode(HGLOBAL globalDevmode)
The QPointF class defines a point in the plane using floating point precision.
qreal height() const
Returns the height.
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
qreal left() const
Returns the x-coordinate of the rectangle's left edge.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
QPrinter::PaperSource qtSourceName
QPointF topLeft() const
Returns the position of the rectangle's top-left corner.
QPixmap transformed(const QMatrix &, Qt::TransformationMode mode=Qt::FastTransformation) const
This convenience function loads the matrix into a QTransform and calls the overloaded function...
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
void updateState(const QPaintEngineState &state)
Reimplement this function to update the state of a paint engine.
const unsigned short * logClusters
ushort red
Returns the red color component of this color.
static QPrinter::PaperSource mapDevmodePaperSource(int s)
bool begin(QPaintDevice *dev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
qreal y
the y coordinate of the element's position.
bool isClipEnabled() const
Returns whether clipping is enabled or not in the current paint engine state.
The QString class provides a Unicode character string.
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
virtual bool end()
Reimplement this function to finish painting on the current paint device.
QRect getPageMargins() const
Q_DECL_CONSTEXPR T qAbs(const T &t)
void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
HGLOBAL * createDevNames()
bool kerning() const
Returns true if kerning should be used when drawing text with this font.
virtual Type type() const =0
QVariant property(PrintEnginePropertyKey key) const
Returns the print engine's property specified by key.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
void setMiterLimit(qreal length)
Sets the miter limit of the generated outlines to limit.
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QPrinter::PrinterState printerState() const
Returns the current state of the printer being used by the print engine.
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
qreal x() const
Returns the x-coordinate of this point.
QRectF boundingRect() const
Returns the bounding rectangle of this painter path as a rectangle with floating point precision...
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
void setDashPattern(Qt::PenStyle)
Sets the dash pattern for the generated outlines to style.
void updateMatrix(const QTransform &matrix)
static int mapPaperSizeDevmode(QPrinter::PaperSize s)
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
Q_CORE_EXPORT void qDebug(const char *,...)
QPrinter::PaperSize mapDevmodePaperSize(int s)
void append(const T &t)
Inserts value at the end of the list.
QPainter * painter() const
Returns the paint engine's painter.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QBrush brush() const
Returns the brush in the current paint engine state.
void setPageMargins(int margin_left, int margin_top, int margin_right, int margin_bottom)
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
The QRectF class defines a rectangle in the plane using floating point precision. ...
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
QPainterPath createStroke(const QPainterPath &path) const
Generates a new path that is a fillable area representing the outline of the given path...
bool newPage()
Instructs the print engine to start a new page.
Qt::ClipOperation clipOperation() const
Returns the clip operation in the current paint engine state.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static const QCssKnownValue positions[NumKnownPositionModes - 1]
qreal height() const
Returns the height of the rectangle.
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
void getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags, QVarLengthArray< glyph_t > &glyphs_out, QVarLengthArray< QFixedPoint > &positions)
Q_CORE_EXPORT void qWarning(const char *,...)
int metric(QPaintDevice::PaintDeviceMetric) const
Returns the metric for the given id.
static const char * data(const QByteArray &arr)
static const struct @250 sources[]
void fillPath(const QPainterPath &path, const QColor &color)
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...
qreal width() const
Returns the width of the rectangle.
void composeGdiPath(const QPainterPath &path)
The QRegion class specifies a clip region for a painter.
The QPainterPathStroker class is used to generate fillable outlines for a given painter path...
QPainterPath clipPath() const
Returns the clip path in the current paint engine state.
QBrush brush() const
Returns the brush used to fill strokes generated with this pen.
Qt::FillRule fillRule() const
Returns the painter path's currently set fill rule.
Qt::BrushStyle style() const
Returns the brush style.
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
QRect toRect() const
Returns a QRect based on the values of this rectangle.
QSizeF toSizeF() const
Returns the variant as a QSizeF if the variant has type() SizeF ; otherwise returns an invalid QSizeF...
The QBrush class defines the fill pattern of shapes drawn by QPainter.
static int mapPaperSourceDevmode(QPrinter::PaperSource s)
Q_CORE_EXPORT void qFatal(const char *,...)
void updateClipPath(const QPainterPath &clip, Qt::ClipOperation op)
ushort blue
Returns the blue color component of this color.
HBITMAP toWinHBITMAP(HBitmapFormat format=NoAlpha) const
It is the caller's responsibility to free the HBITMAP data after use.
bool abort()
Instructs the print engine to abort the printing process.
PaperSize
This enum type specifies what paper size QPrinter should use.
bool end()
Reimplement this function to finish painting on the current paint device.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style of the generated outlines to style.
int size() const
Returns the number of items in the list.
virtual bool begin(QPaintDevice *pdev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
static qreal mmToInches(double mm)
The QRect class defines a rectangle in the plane using integer precision.
bool continueCall() const
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
QSizeF size() const
Returns the size of the rectangle.
void updateCustomPaperSize()
qreal x
the x coordinate of the element's position.
qreal y() const
Returns the y-coordinate of this point.
The QPixmap class is an off-screen image representation that can be used as a paint device...
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
return(isPopup||isToolTip)
QRegion clipRegion() const
Returns the clip region in the current paint engine state.
HDC getDC() const
Empty default implementation.
static qreal inchesToMM(double in)
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
int height() const
Returns the height of the pixmap.
The QPaintEngineState class provides information about the active paint engine's current state...
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
int elementCount() const
Returns the number of path elements in the painter path.
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
QPen pen() const
Returns the pen in the current paint engine state.
QPainterPath qt_regionToPath(const QRegion ®ion)
void flushAndInit(bool init=true)
virtual void updateState(const QPaintEngineState &state)
Reimplement this function to update the state of a paint engine.
The QTextItem class provides all the information required to draw text in a custom paint engine...
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
void readDevnames(HGLOBAL globalDevnames)
QRegion alphaClipping() const
void strokePath(const QPainterPath &path, const QColor &color)
void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
ushort green
Returns the green color component of this color.
static const int tileSize
void fillPath_dev(const QPainterPath &path, const QColor &color)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
void setProperty(PrintEnginePropertyKey key, const QVariant &value)
Sets the print engine's property specified by key to the given value.
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
QRgb rgb() const
Returns the RGB value of the color.
Q_DECL_CONSTEXPR int qRound(qreal d)
Handle handle() const
Returns a platform-specific region handle.
QWin32PrintEngine(QPrinter::PrinterMode mode)
PaperSource
This enum type specifies what paper source QPrinter is to use.
void setWidth(qreal width)
Sets the width of the generated outline painter path to width.
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
PrintEnginePropertyKey
This enum is used to communicate properties between the print engine and QPrinter.
void qErrnoWarning(const char *msg,...)
void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...