Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 4505 → Rev 4506

/branches/Version13x/Scribus/scribus/util.cpp
36,9 → 36,9
 
#include "scconfig.h"
 
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
//#ifdef HAVE_UNISTD_H
//#include <unistd.h>
//#endif
 
#if defined(_WIN32)
#if defined(_MSC_VER)
196,235 → 196,6
return ex;
}
 
int callGS(const QStringList& args_in, const QString device)
{
QString cmd;
QStringList args;
PrefsManager* prefsManager = PrefsManager::instance();
args.append( getShortPathName(prefsManager->ghostscriptExecutable()) );
args.append( "-q" );
args.append( "-dNOPAUSE" );
args.append( "-dQUIET" );
args.append( "-dPARANOIDSAFER" );
args.append( "-dBATCH" );
// Choose rendering device
if (!device.isEmpty())
args.append( QString("-sDEVICE=%1").arg(device) ); // user specified device
else if (ScMW->HavePngAlpha != 0)
args.append( "-sDEVICE=png16m" );
else
args.append( "-sDEVICE=pngalpha" );
// and antialiasing
if (prefsManager->appPrefs.gs_AntiAliasText)
args.append( "-dTextAlphaBits=4" );
if (prefsManager->appPrefs.gs_AntiAliasGraphics)
args.append( "-dGraphicsAlphaBits=4" );
 
// Add any extra font paths being used by Scribus to gs's font search path
PrefsContext *pc = PrefsManager::instance()->prefsFile->getContext("Fonts");
PrefsTable *extraFonts = pc->getTable("ExtraFontDirs");
const char sep = ScPaths::envPathSeparator;
if (extraFonts->getRowCount() >= 1)
cmd = QString("-sFONTPATH=%1").arg(extraFonts->get(0,0));
for (int i = 1; i < extraFonts->getRowCount(); ++i)
cmd += QString("%1%2").arg(sep).arg(extraFonts->get(i,0));
if( !cmd.isEmpty() )
args.append( cmd );
 
args += args_in;
args.append("-c");
args.append("showpage");
return System( args );
}
 
int callGS(const QString& args_in, const QString device)
{
PrefsManager* prefsManager=PrefsManager::instance();
QString cmd1 = getShortPathName(prefsManager->ghostscriptExecutable());
cmd1 += " -q -dNOPAUSE -dQUIET -dPARANOIDSAFER -dBATCH";
// Choose rendering device
if (!device.isEmpty())
// user specified device
cmd1 += " -sDEVICE="+device;
else if (ScMW->HavePngAlpha != 0)
cmd1 += " -sDEVICE=png16m";
else
cmd1 += " -sDEVICE=pngalpha";
// and antialiasing
if (prefsManager->appPrefs.gs_AntiAliasText)
cmd1 += " -dTextAlphaBits=4";
if (prefsManager->appPrefs.gs_AntiAliasGraphics)
cmd1 += " -dGraphicsAlphaBits=4";
 
// Add any extra font paths being used by Scribus to gs's font search path
PrefsContext *pc = PrefsManager::instance()->prefsFile->getContext("Fonts");
PrefsTable *extraFonts = pc->getTable("ExtraFontDirs");
#ifndef _WIN32
if (extraFonts->getRowCount() >= 1)
cmd1 += QString(" -sFONTPATH='%1'").arg(extraFonts->get(0,0));
for (int i = 1; i < extraFonts->getRowCount(); ++i)
cmd1 += QString(":'%1'").arg(extraFonts->get(i,0));
#else
if (extraFonts->getRowCount() >= 1)
cmd1 += QString(" -sFONTPATH=\"%1\"").arg(extraFonts->get(0,0));
for (int i = 1; i < extraFonts->getRowCount(); ++i)
cmd1 += QString(";\"%1\"").arg(extraFonts->get(i,0));
#endif
 
// then add any user specified args and run gs
cmd1 += " " + args_in + " -c showpage";
// qDebug("Calling gs as: %s", cmd1.ascii());
return system(cmd1.local8Bit());
}
 
int convertPS2PS(QString in, QString out, const QStringList& opts, int level)
{
PrefsManager* prefsManager=PrefsManager::instance();
QStringList args;
args.append( getShortPathName(prefsManager->ghostscriptExecutable()) );
args.append( "-q" );
args.append( "-dQUIET" );
args.append( "-dNOPAUSE" );
args.append( "-dPARANOIDSAFER" );
args.append( "-dBATCH" );
args.append( "-sDEVICE=pswrite" );
if(level <= 3)
args.append( QString("-dLanguageLevel=%1").arg(level) );
args += opts;
args.append( QString("-sOutputFile=%1").arg(QDir::convertSeparators(out)) );
args.append( QDir::convertSeparators(in) );
int ret = System( args );
return ret;
}
 
int testGSAvailability( void )
{
QStringList args;
PrefsManager* prefsManager = PrefsManager::instance();
args.append( getShortPathName(prefsManager->ghostscriptExecutable()) );
args.append( "-h" );
int ret = System( args );
return ret;
}
 
int testGSDeviceAvailability( QString device )
{
QStringList args;
PrefsManager* prefsManager = PrefsManager::instance();
args.append( getShortPathName(prefsManager->ghostscriptExecutable()) );
args.append( QString("-sDEVICE=%1").arg( device ) );
args.append( "-c" );
args.append( "quit" );
int ret = System( args );
return ret;
}
 
// Return the GhostScript version string, or QString::null if it couldn't be retrived.
QString getGSVersion()
{
QString gsVer;
QStringList args;
QString gsExe = getShortPathName(PrefsManager::instance()->ghostscriptExecutable());
args.append(gsExe.local8Bit());
args.append(QString("--version").local8Bit());
QProcess proc(args);
proc.setCommunication(QProcess::Stdout);
proc.start();
while(proc.isRunning())
{
#ifndef _WIN32
usleep(5000);
#else
Sleep(5);
#endif
qApp->processEvents();
}
if(!proc.exitStatus())
gsVer = proc.readLineStdout();
return gsVer;
}
 
// Return the GhostScript major and minor version numbers.
bool getNumericGSVersion(int & major, int & minor)
{
QString gs_ver_string(getGSVersion());
// gs's version string is of the form MAJOR.MINOR, so look for the .
// then convert to numbers. 7.07 will become (7,7) for example.
bool success = false;
major = gs_ver_string.section('.', 0, 0).toInt(&success);
if (!success)
return false;
minor = gs_ver_string.section('.', 1, 1).toInt(&success);
if (!success)
return false;
return true;
}
 
QString getGSDefaultExeName(void)
{
QString gsName;
#if defined _WIN32
// Try to locate GhostScript thanks to the registry
DWORD size;
HKEY hKey;
LONG retValue;
DWORD regType = REG_SZ;
char regVersion[MAX_PATH];
char regPath[MAX_PATH];
char gsPath[MAX_PATH];
 
// Set gsName to its default value
gsName = "gswin32c.exe";
 
// Search AFPL Ghostscript first as it has more chance to be up to date
if( RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\AFPL Ghostscript", &hKey) == ERROR_SUCCESS )
strcpy(regPath, "SOFTWARE\\AFPL Ghostscript");
else if( RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\GPL Ghostscript", &hKey) == ERROR_SUCCESS )
strcpy(regPath, "SOFTWARE\\GPL Ghostscript");
else
return gsName;
 
// Search the first SubKey corresponding to the version key
size = sizeof(regVersion) - 1;
retValue = RegEnumKeyEx(hKey, 0, regVersion, &size, NULL, NULL, NULL, NULL);
RegCloseKey(hKey);
if( retValue != ERROR_SUCCESS )
return gsName;
 
strcat(regPath, "\\");
strcat(regPath, regVersion);
 
// Get the GS_DLL Value
if (RegOpenKey(HKEY_LOCAL_MACHINE, regPath, &hKey) != ERROR_SUCCESS)
return gsName;
size = sizeof(gsPath) - 1;
retValue = RegQueryValueEx(hKey, "GS_DLL", 0, &regType, (LPBYTE) gsPath, &size);
RegCloseKey(hKey);
if( retValue != ERROR_SUCCESS )
return gsName;
 
// We now have GhostScript dll path, but we want gswin32c.exe
// Normally gswin32c.exe and gsdll.dll are in the same directory
gsName = gsPath;
size = gsName.findRev("\\");
if(size <= 0)
return QString("gswin32c.exe");
gsName = gsName.left(size + 1);
gsName += "gswin32c.exe";
 
// Check GhostScript executable existence.
QFileInfo fInfo(gsName);
if( fInfo.exists() )
gsName.replace("\\", "/"); // Return a qt-styled path
else
gsName = "gswin32c.exe";
 
#else
gsName = "gs";
#endif
return gsName;
}
 
// On Windows, return short path name, else return longPath;
QString getShortPathName(QString longPath)
{
484,45 → 255,6
return 0;
}
 
QPixmap LoadPDF(QString fn, int Page, int Size, int *w, int *h)
{
QString tmp, cmd1, cmd2;
QString pdfFile = QDir::convertSeparators(fn);
QString tmpFile = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/sc.png");
QPixmap pm;
int ret = -1;
tmp.setNum(Page);
QStringList args;
args.append("-r72");
args.append("-sOutputFile=\""+tmpFile+"\"");
args.append("-dFirstPage="+tmp);
args.append("-dLastPage="+tmp);
args.append("\""+pdfFile+"\"");
ret = callGS(args);
if (ret == 0)
{
QImage image;
image.load(tmpFile);
unlink(tmpFile);
QImage im2;
*h = image.height();
*w = image.width();
double sx = image.width() / static_cast<double>(Size);
double sy = image.height() / static_cast<double>(Size);
double t = (sy < sx ? sx : sy);
im2 = image.smoothScale(static_cast<int>(image.width() / t), static_cast<int>(image.height() / t));
pm.convertFromImage(im2);
QPainter p;
p.begin(&pm);
p.setBrush(Qt::NoBrush);
p.setPen(Qt::black);
p.drawRect(0, 0, pm.width(), pm.height());
p.end();
im2.detach();
}
return pm;
}
 
QString GetAttr(QDomElement *el, QString at, QString def)
{
return el->attribute(at, def);
/branches/Version13x/Scribus/scribus/printerutil.h
10,6 → 10,7
#include "scribusapi.h"
 
#include <qstring.h>
#include <qwidget.h>
 
class QStringList;
 
18,13 → 19,39
public:
PrinterUtil() {};
~PrinterUtil() {};
QStringList static SCRIBUS_API getPrinterNames();
bool static SCRIBUS_API getDefaultSettings( QString printerName );
bool static SCRIBUS_API initDeviceSettings( QString printerName );
QStringList static getPrinterNames();
 
#if defined(_WIN32)
/**
* @brief Get the defaults settings for a specified printer (Windows only)
*
* This function retrieve the default settings for a specified
* printer and return true on success
* This function is available only on Windows systems
*
* @param printerName the printer name
* @param devModeA an array which will store the DEVMODE structure with printer settings
* @return true if default settings were successfully retrieved.
*/
bool static getDefaultSettings( QString printerName, QByteArray& devModeA );
/**
* @brief Initialize print options dialog box settings (Windows only)
*
* This function initialize the print options dialog box for a specified
* printer and return true on success
* This function is available only on Windows systems
*
* @param printerName the printer name
* @param devModeA an array storing the DEVMODE structure for the specified printer
* @return true if default settings were successfully retrieved.
*/
bool static initDeviceSettings( QString printerName, QByteArray& devModeA );
#endif
/**
* @brief Get the 4 minimum page margins for a certain paper size on the given printer
*
* @param printerName the printer name
* @param w a non-null widget pointer (necessary on Windows)
* @param printerName the printer name
* @param pageSize the page size to get the margins for
* @param ptsTopMargin the page's top margin in points
* @param ptsTopMargin the page's bottom margin in points
31,7 → 58,7
* @param ptsTopMargin the page's left margin in points
* @param ptsTopMargin the page's right margin in points
*/
bool static SCRIBUS_API getPrinterMarginValues(const QString& printerName, const QString& pageSize, double& ptsTopMargin, double& m_ptsBottomMargin, double& m_ptsLeftMargin, double& m_ptsRightMargin);
bool static getPrinterMarginValues( const QString& printerName, const QString& pageSize, double& ptsTopMargin, double& m_ptsBottomMargin, double& m_ptsLeftMargin, double& m_ptsRightMargin);
/**
* @brief Check if a specified printer supports postscript input
*
43,7 → 70,7
* @return true is printer support postscript, false otherwise.
*
*/
bool static SCRIBUS_API isPostscriptPrinter( QString printerName );
bool static isPostscriptPrinter( QString printerName );
};
 
#endif // DRUCK_H
/branches/Version13x/Scribus/scribus/sccolorshade.h
31,7 → 31,7
public:
 
ScColorShade( void );
ScColorShade( QColor& c, int level );
ScColorShade( const QColor& c, int level );
ScColorShade( const ScColor& c, int level );
 
ScColor getShadedColor(void);
/branches/Version13x/Scribus/scribus/preview.cpp
43,6 → 43,7
#include "scribusdoc.h"
#include "scpaths.h"
#include "pageselector.h"
#include "printerutil.h"
 
#if defined(_WIN32)
#include "scwinprint.h"
890,9 → 891,9
if ( printerName == tr("File") )
return true;
else if( printerName.isEmpty() )
return isPostscriptPrinter( ScWinPrint::getDefaultPrinter() );
return PrinterUtil::isPostscriptPrinter( ScWinPrint::getDefaultPrinter() );
else
return isPostscriptPrinter( printerName );
return PrinterUtil::isPostscriptPrinter( printerName );
#else
return true;
#endif
/branches/Version13x/Scribus/scribus/druck.cpp
293,9 → 293,10
#endif
 
setStoredValues(gcr);
 
#if defined(_WIN32)
if (!ToFile)
PrinterUtil::initDeviceSettings( PrintDest->currentText() );
PrinterUtil::initDeviceSettings( PrintDest->currentText(), DevMode );
#endif
if ( PrinterUtil::isPostscriptPrinter(PrintDest->currentText()) || ToFile )
psLevel->setEnabled( true );
else
480,9 → 481,11
#if defined(HAVE_CUPS) || defined(_WIN32)
OptButton->setEnabled(!setter);
#endif
#if defined(_WIN32)
if ( !ToFile )
if( !PrinterUtil::getDefaultSettings(PrintDest->currentText()) )
if( !PrinterUtil::getDefaultSettings(PrintDest->currentText(), DevMode) )
qWarning(tr("Failed to retrieve printer settings"));
#endif
if ( ToFile || PrinterUtil::isPostscriptPrinter(PrintDest->currentText()) )
{
psLevel->setEnabled( true );
/branches/Version13x/Scribus/scribus/Makefile.am
80,6 → 80,7
fpoint.cpp \
frameedit.cpp \
gradienteditor.cpp \
gsutil.cpp \
gtaction.cpp \
gtdialogs.cpp \
gtfont.cpp \
/branches/Version13x/Scribus/scribus/navigator.cpp
26,7 → 26,7
 
#include <qpainter.h>
#include "scribusview.h"
#include "util.h"
#include "gsutil.h"
 
Navigator::Navigator(QWidget *parent, int Size, int Seite, ScribusView* vie, QString fn) : QLabel(parent)
{
/branches/Version13x/Scribus/scribus/about.cpp
19,6 → 19,7
#include <qtooltip.h>
 
#include "scconfig.h"
#include "gsutil.h"
#include "util.h"
 
#include "langmgr.h"
/branches/Version13x/Scribus/scribus/prefsmanager.cpp
41,6 → 41,7
#include "scribus.h"
#include "scribusstructs.h"
#include "scribusapp.h"
#include "gsutil.h"
#include "util.h"
#include "werktoolb.h"
 
/branches/Version13x/Scribus/scribus/marginWidget.cpp
81,12 → 81,12
marginsForAllPages=NULL;
usePrinterMarginsButton=NULL;
#ifdef HAVE_CUPS
#if defined(HAVE_CUPS) || defined(_WIN32)
usePrinterMarginsButton=new QPushButton( tr("Printer Margins..."),this, "usePrinterMarginsButton" );
GroupLayout->addWidget( usePrinterMarginsButton, 5, 1 );
QToolTip::add( usePrinterMarginsButton, "<qt>" +tr( "Import the margins for the selected page size from the available printers." ) + "</qt>");
connect(usePrinterMarginsButton, SIGNAL(clicked()), this, SLOT(setMarginsToPrinterMargins()));
#endif
#endif
// hints
QToolTip::add( topR, "<qt>" + tr( "Distance between the top margin guide and the edge of the page" ) + "</qt>");
/branches/Version13x/Scribus/scribus/scpageoutput.cpp
649,7 → 649,7
}
else
{
if ((!item->PicArt) || (!item->PicAvail))
if ((!item->imageShown()) || (!item->PicAvail))
{
if ((item->Frame) && (m_doc->guidesSettings.framesShown))
{
1139,7 → 1139,7
lineCorr = item->lineWidth() / 2.0;
else
lineCorr = 0;
if ((item->isAnnotation()) && (item->annotation().Type() == 2) && (!item->Pfile.isEmpty()) && (item->PicAvail) && (item->PicArt) && (item->annotation().UseIcons()))
if ((item->isAnnotation()) && (item->annotation().Type() == 2) && (!item->Pfile.isEmpty()) && (item->PicAvail) && (item->imageShown()) && (item->annotation().UseIcons()))
{
painter->setupPolygon(&item->PoLine);
painter->setClipPath();
1292,7 → 1292,8
{
wide = Zli3.wide;
painter->setFillMode(1);
painter->setBrush(ScColorShade(Qt::darkBlue, 100));
//paintersetBrush( ScColorShade( Qt::darkBlue, 100) );
painter->setBrush( ScColorShade(qApp->palette().color(QPalette::Active, QColorGroup::Highlight), 100) );
painter->setLineWidth(0);
if ((a > 0) && (Zli3.Zeich == QChar(9)))
{
1301,7 → 1302,8
}
//if (!m_doc->RePos)
painter->drawRect(xcoZli, qRound(Zli3.yco-asce * (Zli3.scalev / 1000.0)), wide+1, qRound((asce+desc) * (Zli3.scalev / 1000.0)));
painter->setBrush(ScColorShade(Qt::white, 100));
//painter->setBrush(ScColorShade(Qt::white, 100));
painter->setBrush(ScColorShade(qApp->palette().color(QPalette::Active, QColorGroup::HighlightedText), 100));
}
if (Zli3.Farb2 != "None")
{
2514,7 → 2516,8
{
wide = Zli2->wide;
painter->setFillMode(1);
painter->setBrush(ScColorShade(Qt::darkBlue, 100));
//painter->setBrush( ScColorShade(Qt::darkBlue, 100) );
painter->setBrush( ScColorShade(qApp->palette().color(QPalette::Active, QColorGroup::Highlight), 100) );
painter->setLineWidth(0);
if ((zc > 0) && (Zli2->Zeich == QChar(9)))
{
2524,7 → 2527,8
}
/*if (!m_doc->RePos)*/
painter->drawRect(xcoZli, qRound(Zli2->yco-asce * (Zli2->scalev / 1000.0)), wide+1, qRound((asce+desc) * (Zli2->scalev / 1000.0)));
painter->setBrush(ScColorShade(Qt::white, 100));
//painter->setBrush(ScColorShade(Qt::white, 100));
painter->setBrush( ScColorShade(qApp->palette().color(QPalette::Active, QColorGroup::HighlightedText), 100) );
}
if (Zli2->Farb2 != "None")
{
2792,7 → 2796,8
{
wide = Zli2->wide;
painter->setFillMode(1);
painter->setBrush(ScColorShade(Qt::darkBlue, 100));
//painter->setBrush( ScColorShade(Qt::darkBlue, 100));
painter->setBrush( ScColorShade(qApp->palette().color(QPalette::Active, QColorGroup::Highlight), 100) );
painter->setLineWidth(0);
if ((zc > 0) && (Zli2->Zeich == QChar(9)))
{
2802,7 → 2807,8
}
/*if (!m_doc->RePos)*/
painter->drawRect(xcoZli, qRound(Zli2->yco-asce * (Zli2->scalev / 1000.0)), wide+1, qRound((asce+desc) * (Zli2->scalev / 1000.0)));
painter->setBrush(ScColorShade(Qt::white, 100));
//painter->setBrush( ScColorShade(Qt::white, 100));
painter->setBrush( ScColorShade(qApp->palette().color(QPalette::Active, QColorGroup::HighlightedText), 100) );
}
if (Zli2->Farb2 != "None")
{
/branches/Version13x/Scribus/scribus/scimage.cpp
23,7 → 23,7
extern int IntentMonitor;
extern int IntentPrinter;
#endif
#include "util.h"
#include "gsutil.h"
#include "exif.h"
 
 
/branches/Version13x/Scribus/scribus/scribus.cpp
151,6 → 151,7
#include "documentinformation.h"
#include "effectsdialog.h"
#include "documentchecker.h"
#include "gsutil.h"
#include "util.h"
#include "pagesize.h"
#include "loremipsum.h"
/branches/Version13x/Scribus/scribus/util.h
49,7 → 49,6
FPoint SCRIBUS_API getMaxClipF(FPointArray* Clip);
FPoint SCRIBUS_API getMinClipF(FPointArray* Clip);
QString SCRIBUS_API Path2Relative(QString Path);
QPixmap SCRIBUS_API LoadPDF(QString fn, int Page, int Size, int *w, int *h);
QByteArray SCRIBUS_API ComputeMD5Sum(QByteArray *in);
char SCRIBUS_API *toHex( uchar u );
QString SCRIBUS_API String2Hex(QString *in, bool lang = true);
113,33 → 112,6
*
*/
int SCRIBUS_API System(const QStringList & args, const QString fileStdErr = "", const QString fileStdOut = "");
/**
* @brief Call GhostScript synchronously and store output
*
* The gs commands are all similar and consist of a few constant
* arguments, the variable arguments and the end arguments which
* are also invariant. It will always use -q -dNOPAUSE and
* will always end with -c showpage -c quit. It also does automatic
* device selection unless overridden, and uses the user's antialiasing
* preferences and font search path.
*
* Shell metacharacters are not expanded - that includes quotes.
* @sa System .
*
* @param args_in Custom arguments to GhostScript
* @param device GS device to use (defaults to an image device if omitted)
*/
int SCRIBUS_API callGS(const QStringList& args_in, const QString device="");
int SCRIBUS_API callGS(const QString& args_in, const QString device="");
int SCRIBUS_API convertPS2PS(QString in, QString out, const QStringList& opts, int level);
int SCRIBUS_API testGSAvailability( void );
int SCRIBUS_API testGSDeviceAvailability( QString device );
/*! \brief Return gs version. If gs couldn't be found or there was a problem parsing output, return false
(in which case minor and major have undefined values).
\retval QString version or false on error */
QString SCRIBUS_API getGSVersion();
bool SCRIBUS_API getNumericGSVersion(int & major, int & minor);
QString SCRIBUS_API getGSDefaultExeName(void);
int SCRIBUS_API copyFile(QString source, QString target);
int SCRIBUS_API moveFile(QString source, QString target);
/*!
/branches/Version13x/Scribus/scribus/plugins/scriptplugin/objprinter.cpp
13,6 → 13,7
#include <qdir.h>
#include <vector>
#include "pslib.h"
#include "gsutil.h"
#include "util.h"
 
#ifdef HAVE_CUPS
/branches/Version13x/Scribus/scribus/plugins/barcodegenerator/barcodegenerator.cpp
6,6 → 6,7
*/
 
#include "barcodegenerator.h"
#include "gsutil.h"
#include "util.h"
#include "scribus.h"
 
/branches/Version13x/Scribus/scribus/printerutil.cpp
16,6 → 16,7
 
#include <qstringlist.h>
#include "util.h"
#include "scribus.h"
 
QStringList PrinterUtil::getPrinterNames()
{
72,9 → 73,9
return printerNames;
}
 
bool PrinterUtil::getDefaultSettings( QString printerName )
#if defined(_WIN32)
bool PrinterUtil::getDefaultSettings( QString printerName, QByteArray& devModeA )
{
#ifdef _WIN32
bool done;
uint size;
QCString printer;
86,22 → 87,20
if(!done)
return false;
// Get size of DEVMODE structure (public + private data)
size = DocumentProperties( winId(), handle, printer.data(), NULL, NULL, 0);
size = DocumentProperties( ScMW->winId(), handle, printer.data(), NULL, NULL, 0);
// Allocate the memory needed by the DEVMODE structure
DevMode.resize( size );
devModeA.resize( size );
// Retrieve printer default settings
result = DocumentProperties( winId(), handle, printer.data(), (DEVMODE*) DevMode.data(), NULL, DM_OUT_BUFFER);
result = DocumentProperties( ScMW->winId(), handle, printer.data(), (DEVMODE*) devModeA.data(), NULL, DM_OUT_BUFFER);
// Free the printer handle
ClosePrinter( handle );
return ( result == IDOK );
#else
return true;
}
#endif
}
 
bool PrinterUtil::initDeviceSettings( QString printerName )
#if defined(_WIN32)
bool PrinterUtil::initDeviceSettings( QString printerName, QByteArray& devModeA )
{
#ifdef _WIN32
bool done;
uint size;
QCString printer;
113,32 → 112,30
if(!done)
return false;
// Get size of DEVMODE structure (public + private data)
size = DocumentProperties( winId(), handle, printer.data(), NULL, NULL, 0);
size = DocumentProperties( ScMW->winId(), handle, printer.data(), NULL, NULL, 0);
// Compare size with DevMode structure size
if( DevMode.size() == size )
if( devModeA.size() == size )
{
// Merge printer settings
result = DocumentProperties( winId(), handle, printer.data(), (DEVMODE*) DevMode.data(), (DEVMODE*) DevMode.data(), DM_IN_BUFFER | DM_OUT_BUFFER);
result = DocumentProperties( ScMW->winId(), handle, printer.data(), (DEVMODE*) devModeA.data(), (DEVMODE*) devModeA.data(), DM_IN_BUFFER | DM_OUT_BUFFER);
}
else
{
// Retrieve default settings
DevMode.resize( size );
result = DocumentProperties( winId(), handle, printer.data(), (DEVMODE*) DevMode.data(), NULL, DM_OUT_BUFFER);
devModeA.resize( size );
result = DocumentProperties( ScMW->winId(), handle, printer.data(), (DEVMODE*) devModeA.data(), NULL, DM_OUT_BUFFER);
}
done = ( result == IDOK);
// Free the printer handle
ClosePrinter( handle );
return done;
#else
return true;
}
#endif
}
 
bool PrinterUtil::getPrinterMarginValues(const QString& printerName, const QString& pageSize, double& ptsTopMargin, double& ptsBottomMargin, double& ptsLeftMargin, double& ptsRightMargin)
{
bool retVal=false;
#if defined(HAVE_CUPS)
#if defined(HAVE_CUPS)
const char *filename; // tmp PPD filename
filename=cupsGetPPD(printerName);
if (filename!=NULL)
161,7 → 158,61
ppdClose(ppd);
}
}
#endif
#elif defined(_WIN32)
DWORD nPaper;
DWORD nPaperNames;
QCString printer;
typedef char char64[64];
printer = printerName.local8Bit();
nPaper = DeviceCapabilities( printerName.data(), NULL, DC_PAPERS, NULL, NULL );
nPaperNames = DeviceCapabilities( printerName.data(), NULL, DC_PAPERNAMES, NULL, NULL );
if ( (nPaper > 0) && (nPaperNames > 0) && (nPaper == nPaperNames) )
{
int paperIndex = -1;
DWORD *papers = new DWORD[nPaper];
char64 *paperNames = new char64[nPaperNames];
DWORD s1 = DeviceCapabilities( printerName.data(), NULL, DC_PAPERS, (LPSTR) papers, NULL );
DWORD s2 = DeviceCapabilities( printerName.data(), NULL, DC_PAPERNAMES, (LPSTR) paperNames, NULL );
for ( int i = 0; i < nPaperNames; i++ )
{
if ( pageSize == QString(paperNames[i]) )
{
paperIndex = i;
break;
}
}
if ( paperIndex >= 0 )
{
HANDLE handle = NULL;
if( OpenPrinter( printer.data(), &handle, NULL ) )
{
// Retrieve DEVMODE structure for selected device
uint size = DocumentProperties( ScMW->winId(), handle, printer.data(), NULL, NULL, 0);
QByteArray devModeA(size);
DEVMODE* devMode = (DEVMODE*) devModeA.data();
DocumentProperties( ScMW->winId(), handle, printer.data(), devMode, NULL, DM_OUT_BUFFER);
ClosePrinter( handle );
// Set paper size
devMode->dmPaperSize = papers[paperIndex];
// Create device context
HDC printerDC = CreateDC( NULL, printer.data(), 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
return retVal;
}
 
/branches/Version13x/Scribus/scribus/sccolorshade.cpp
29,7 → 29,7
shade = 100;
}
 
ScColorShade::ScColorShade( QColor& c, int level )
ScColorShade::ScColorShade( const QColor& c, int level )
{
color = ScColor(c.red(), c.green(), c.blue());
shade = level;