r21179 by fschmid -
scribus-commit
scribus-commit at lists.scribus.net
Sat Apr 9 17:08:25 UTC 2016
Author: fschmid
Date: Sat Apr 9 17:08:24 2016
New Revision: 21179
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21179
Log:
Fixed Bug #13682: Cups APIs outdated and need fixing
Modified:
trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp
trunk/Scribus/scribus/ui/about.cpp
trunk/Scribus/scribus/ui/cupsoptions.cpp
trunk/Scribus/scribus/ui/marginwidget.cpp
trunk/Scribus/scribus/ui/prefs_printer.cpp
trunk/Scribus/scribus/util_printer.cpp
Modified: trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21179&path=/trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp Sat Apr 9 17:08:24 2016
@@ -23,9 +23,6 @@
#include "util_ghostscript.h"
#include "util_printer.h"
-#ifdef HAVE_CUPS
-#include <cups/cups.h>
-#endif
// these functions are located at utils.cpp
bool SCRIBUS_API loadText(QString nam, QString *Buffer);
void SCRIBUS_API ReOrderText(ScribusDoc *doc, ScribusView *view);
@@ -492,10 +489,6 @@
cmd = "lpr -P" + prn;
if (Nr > 1)
cmd += " -#" + cc.setNum(Nr);
-#ifdef HAVE_CUPS
-// This need yet to be implemented by object Printer
-// cmd += printer->PrinterOpts;
-#endif
cmd += " "+fna;
}
system(cmd.toLocal8Bit().constData());
Modified: trunk/Scribus/scribus/ui/about.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21179&path=/trunk/Scribus/scribus/ui/about.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/about.cpp (original)
+++ trunk/Scribus/scribus/ui/about.cpp Sat Apr 9 17:08:24 2016
@@ -114,8 +114,8 @@
buildID = new QLabel( tab );
buildID->setAlignment(Qt::AlignCenter);
buildID->setTextInteractionFlags(Qt::TextSelectableByMouse);
- QString BUILD_DAY = "19";
- QString BUILD_MONTH = CommonStrings::march;
+ QString BUILD_DAY = "3";
+ QString BUILD_MONTH = CommonStrings::april;
QString BUILD_YEAR = "2016";
QString BUILD_TIME = "";
QString BUILD_TZ = "";
@@ -137,11 +137,6 @@
QString bu;
bu += "C";
bu += "-";
-#ifdef HAVE_CUPS
- bu += "C";
-#else
- bu += "*";
-#endif
bu += "-";
bu += "T";
bu += "-";
Modified: trunk/Scribus/scribus/ui/cupsoptions.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21179&path=/trunk/Scribus/scribus/ui/cupsoptions.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/cupsoptions.cpp (original)
+++ trunk/Scribus/scribus/ui/cupsoptions.cpp Sat Apr 9 17:08:24 2016
@@ -34,6 +34,8 @@
#include <QStringList>
#include <QToolTip>
#include <QSpacerItem>
+#include <QPrinterInfo>
+#include <QPrinter>
#include "prefsmanager.h"
#include "prefscontext.h"
Modified: trunk/Scribus/scribus/ui/marginwidget.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21179&path=/trunk/Scribus/scribus/ui/marginwidget.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/marginwidget.cpp (original)
+++ trunk/Scribus/scribus/ui/marginwidget.cpp Sat Apr 9 17:08:24 2016
@@ -98,12 +98,10 @@
}
usePrinterMarginsButton=NULL;
-#if defined(HAVE_CUPS) || defined(_WIN32)
- usePrinterMarginsButton=new QPushButton( tr("Printer Margins..."),marginPage );
+ usePrinterMarginsButton = new QPushButton( tr("Printer Margins..."),marginPage );
GroupLayout->addWidget( usePrinterMarginsButton, 5, 1 );
usePrinterMarginsButton->setToolTip( "<qt>" + tr( "Import the margins for the selected page size from the available printers" ) + "</qt>");
connect(usePrinterMarginsButton, SIGNAL(clicked()), this, SLOT(setMarginsToPrinterMargins()));
-#endif
addTab(marginPage, tr("Margin Guides"));
Modified: trunk/Scribus/scribus/ui/prefs_printer.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21179&path=/trunk/Scribus/scribus/ui/prefs_printer.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_printer.cpp (original)
+++ trunk/Scribus/scribus/ui/prefs_printer.cpp Sat Apr 9 17:08:24 2016
@@ -14,8 +14,7 @@
#include "util_printer.h"
#include "units.h"
-Prefs_Printer::Prefs_Printer(QWidget* parent, ScribusDoc* doc)
- : Prefs_Pane(parent)
+Prefs_Printer::Prefs_Printer(QWidget* parent, ScribusDoc* doc) : Prefs_Pane(parent)
{
setupUi(this);
languageChange();
Modified: trunk/Scribus/scribus/util_printer.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21179&path=/trunk/Scribus/scribus/util_printer.cpp
==============================================================================
--- trunk/Scribus/scribus/util_printer.cpp (original)
+++ trunk/Scribus/scribus/util_printer.cpp Sat Apr 9 17:08:24 2016
@@ -6,11 +6,11 @@
*/
#include "util_printer.h"
#include "scconfig.h"
-
-#if defined(HAVE_CUPS)
- #include <cups/cups.h>
- #include <cups/ppd.h>
-#elif defined(_WIN32)
+#include <QPrinterInfo>
+#include <QPrinter>
+#include <QPageLayout>
+
+#if defined(_WIN32)
#include <windows.h>
#include <winspool.h>
#endif
@@ -25,57 +25,7 @@
QStringList PrinterUtil::getPrinterNames()
{
- QString printerName;
- QStringList printerNames;
-#if defined (HAVE_CUPS)
- cups_dest_t *dests;
- int num_dests = cupsGetDests(&dests);
- for (int pr = 0; pr < num_dests; ++pr)
- {
- printerName = QString(dests[pr].name);
- printerNames.append(printerName);
- }
- cupsFreeDests(num_dests, dests);
-#elif defined(_WIN32)
- DWORD size;
- DWORD numPrinters;
- PRINTER_INFO_2W* printerInfos = NULL;
- EnumPrintersW (PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS , NULL, 2, NULL, 0, &size, &numPrinters);
- printerInfos = (PRINTER_INFO_2W*) malloc(size);
- if (EnumPrintersW (PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, (LPBYTE) printerInfos, size, &size, &numPrinters))
- {
- for (uint i = 0; i < numPrinters; i++)
- {
- printerName = QString::fromUtf16((const ushort*) printerInfos[i].pPrinterName);
- printerNames.append(printerName);
- }
- printerNames.sort();
- }
- if (printerInfos) free(printerInfos);
-#else
- QString tmp;
- QStringList wt;
- QByteArray printCap;
- if (loadRawText("/etc/printcap", printCap))
- {
- QDataStream ts(&printCap, QIODevice::ReadOnly);
- while(!ts.atEnd())
- {
- tmp = readLinefromDataStream(ts);
- if (tmp.isEmpty())
- continue;
- if ((tmp[0] != '#') && (tmp[0] != ' ') && (tmp[0] != '\n') && (tmp[0] != '\t'))
- {
- tmp = tmp.trimmed();
- tmp = tmp.left(tmp.length() - (tmp.right(2) == ":\\" ? 2 : 1));
- wt = tmp.split("|", QString::SkipEmptyParts);
- printerName = wt[0];
- printerNames.append(printerName);
- }
- }
- }
-#endif
- return printerNames;
+ return QPrinterInfo::availablePrinterNames();
}
#if defined(_WIN32)
@@ -135,83 +85,18 @@
bool PrinterUtil::getPrinterMarginValues(const QString& printerName, const QString& pageSize, double& ptsTopMargin, double& ptsBottomMargin, double& ptsLeftMargin, double& ptsRightMargin)
{
- bool retVal=false;
-#if defined(HAVE_CUPS)
- const char *filename; // tmp PPD filename
- filename=cupsGetPPD(printerName.toLocal8Bit().constData());
- if (filename!=NULL)
- {
- ppd_file_t *ppd; // PPD data
- ppd = ppdOpenFile(filename);
- if (ppd!=NULL)
- {
- ppd_size_t *size; // page size data, null if printer doesn't support selected size
- size = ppdPageSize(ppd, pageSize.toLocal8Bit().constData());
- if (size!=NULL)
- {
- //Store in pts for returning via getNewPrinterMargins in pts
- retVal=true;
- ptsTopMargin=size->length-size->top;
- ptsBottomMargin=size->bottom;
- ptsLeftMargin=size->left;
- ptsRightMargin=size->width-size->right;
- }
- ppdClose(ppd);
- }
- }
-#elif defined(_WIN32)
- DWORD nPaper;
- DWORD nPaperNames;
- typedef WCHAR wchar64[64];
- nPaper = DeviceCapabilitiesW((LPCWSTR) printerName.utf16(), NULL, DC_PAPERS, NULL, NULL);
- nPaperNames = DeviceCapabilitiesW((LPCWSTR) printerName.utf16(), NULL, DC_PAPERNAMES, NULL, NULL);
- if ((nPaper > 0) && (nPaperNames > 0) && (nPaper == nPaperNames))
- {
- int paperIndex = -1;
- DWORD *papers = new DWORD[nPaper];
- wchar64 *paperNames = new wchar64[nPaperNames];
- DWORD s1 = DeviceCapabilitiesW((LPCWSTR) printerName.utf16(), NULL, DC_PAPERS, (LPWSTR) papers, NULL);
- DWORD s2 = DeviceCapabilitiesW((LPCWSTR) printerName.utf16(), NULL, DC_PAPERNAMES, (LPWSTR) paperNames, NULL);
- for (uint i = 0; i < nPaperNames; i++)
- {
- if (pageSize == QString::fromUtf16((const ushort*) paperNames[i]))
- {
- paperIndex = i;
- break;
- }
- }
- if (paperIndex >= 0)
- {
- Qt::HANDLE handle = NULL;
- if (OpenPrinterW((LPWSTR) printerName.utf16(), &handle, NULL))
- {
- // Retrieve DEVMODE structure for selected device
- uint size = DocumentPropertiesW((HWND) ScCore->primaryMainWindow()->winId(), handle, (LPWSTR) printerName.utf16(), NULL, NULL, 0);
- QByteArray devModeW(size, 0);
- DEVMODEW* devMode = (DEVMODEW*) devModeW.data();
- DocumentPropertiesW((HWND) ScCore->primaryMainWindow()->winId(), handle, (LPWSTR) printerName.utf16(), devMode, NULL, DM_OUT_BUFFER);
- ClosePrinter(handle);
- // Set paper size
- devMode->dmPaperSize = papers[paperIndex];
- // Create device context
- HDC printerDC = CreateDCW(NULL, (LPWSTR) printerName.utf16(), NULL, devMode);
- if (printerDC)
- {
- retVal = true;
- int logPixelsX = GetDeviceCaps(printerDC, LOGPIXELSX);
- int logPixelsY = GetDeviceCaps(printerDC, LOGPIXELSY);
- int physicalOffsetX = GetDeviceCaps(printerDC, PHYSICALOFFSETX);
- int physicalOffsetY = GetDeviceCaps(printerDC, PHYSICALOFFSETY);
- ptsLeftMargin = ptsRightMargin = (physicalOffsetX / (double) logPixelsX * 72);
- ptsTopMargin = ptsBottomMargin = (physicalOffsetY / (double) logPixelsY * 72);
- DeleteDC(printerDC);
- }
- }
- }
- delete[] papers;
- delete[] paperNames;
- }
-#endif
+ bool retVal = false;
+ QPrinterInfo pInfo = QPrinterInfo::printerInfo(printerName);
+ if (!pInfo.isNull())
+ {
+ QPrinter printer(pInfo, QPrinter::HighResolution);
+ QMarginsF margs = printer.pageLayout().margins(QPageLayout::Point);
+ ptsTopMargin = margs.top();
+ ptsBottomMargin = margs.bottom();
+ ptsLeftMargin = margs.left();
+ ptsRightMargin = margs.right();
+ retVal = true;
+ }
return retVal;
}
More information about the scribus-commit
mailing list