diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2013-02-26 12:51:34 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-26 22:01:27 +0100 |
commit | 7729d89e15bc68899554b28f480a891c61ef0872 (patch) | |
tree | c1a2bdfa34a4150f0b2ecdd5e53926e8ac7a4be8 /src/printsupport/kernel/qprintengine_win.cpp | |
parent | 1b76cf017427a98bf4487f3cf576611d82097539 (diff) |
QWin32PrintEngine: Fix build on MinGW + avoid dummy allocations
Don't use wcscpy_s() which is not available on MinGW but determine the utf-16
string length and pass that value to QString::fromWCharArray() instead.
Change-Id: I45d1b1969fe03255fdb6353fa9f52417af530e40
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Diffstat (limited to 'src/printsupport/kernel/qprintengine_win.cpp')
-rw-r--r-- | src/printsupport/kernel/qprintengine_win.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index f5690c12f3..7c67fd2845 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -1596,6 +1596,16 @@ QList<QPrinter::PaperSize> QWin32PrintEngine::supportedPaperSizes(const QPrinter return returnList; } +static inline uint qwcsnlen(const wchar_t *str, uint maxlen) +{ + uint length = 0; + if (str) { + while (length < maxlen && *str++) + length++; + } + return length; +} + QList<QPair<QString, QSizeF> > QWin32PrintEngine::supportedSizesWithNames(const QPrinterInfo &printerInfo) { QList<QPair<QString, QSizeF> > paperSizes; @@ -1603,22 +1613,20 @@ QList<QPair<QString, QSizeF> > QWin32PrintEngine::supportedSizesWithNames(const return paperSizes; DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), NULL, DC_PAPERNAMES, NULL, NULL); - if ((int)size != -1) { + if ((int)size > 0) { wchar_t *papers = new wchar_t[size*64]; size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), NULL, DC_PAPERNAMES, papers, NULL); DWORD size2 = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), NULL, DC_PAPERSIZE, NULL, NULL); - if ((int)size2 != -1) { + if ((int)size2 > 0) { POINT *points = new POINT[size2*sizeof(POINT)]; size2 = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), NULL, DC_PAPERSIZE, (wchar_t *)points, NULL); - wchar_t copyOfPaper[65]; for (int i=0;i<(int)size;i++) { - wcscpy_s(copyOfPaper, 64, papers + (i * 64)); - copyOfPaper[64] = '\0'; - QString str = QString::fromWCharArray(copyOfPaper); + wchar_t *paper = papers + (i * 64); + QString str = QString::fromWCharArray(paper, qwcsnlen(paper, 64)); paperSizes << qMakePair(str, QSizeF(points[i].x / 10, points[i].y / 10)); } delete [] points; |