Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 13959 → Rev 13960

/trunk/Scribus/cmake/modules/GMAGICKConfig.cmake
0,0 → 1,55
#
# Find the native GraphicksMagick++ includes and library
#
 
# This module defines
# GMAGICK_INCLUDE_DIR, where to find Magick++.h
# GMAGICK_LIBRARY, the libraries to link against to use GraphicksMagick++.
# GMAGICK_FOUND, If false, do not try to use GraphicksMagick++.
# GMAGICK_LIBS, link information
# GMAGICK_CFLAGS, cflags for include information
 
 
find_program(GMAGICK_CONFIG_EXECUTABLE NAMES GraphicsMagick++-config PATH ${PREFIX_GMAGICK} DOC "GraphicsMagick++-config executable")
mark_as_advanced(GMAGICK_CONFIG_EXECUTABLE)
 
MESSAGE(STATUS "Gmconf ${GMAGICK_CONFIG_EXECUTABLE}")
 
macro(_gmagickconfig_invoke _type _varname _regexp)
set(_gmagickconfig_invoke_result)
 
execute_process(
COMMAND ${GMAGICK_CONFIG_EXECUTABLE} ${_type}
OUTPUT_VARIABLE _gmagickconfig_invoke_result
RESULT_VARIABLE _gmagickconfig_failed)
 
if (NOT _gmagickconfig_failed)
set(GMAGICK_FOUND "YES")
string(REGEX REPLACE "[\r\n]" " " _gmagickconfig_invoke_result "${_gmagickconfig_invoke_result}")
string(REGEX REPLACE " +$" "" _gmagickconfig_invoke_result "${_gmagickconfig_invoke_result}")
 
if (NOT ${_regexp} STREQUAL "")
string(REGEX REPLACE "${_regexp}" " " _gmagickconfig_invoke_result "${_gmagickconfig_invoke_result}")
endif(NOT ${_regexp} STREQUAL "")
 
separate_arguments(_gmagickconfig_invoke_result)
MESSAGE(STATUS "GMAGICK result for ${_type}: ${_gmagickconfig_invoke_result}")
 
#message(STATUS " ${_varname} ... ${_pkgconfig_invoke_result}")
set(${_varname} ${_gmagickconfig_invoke_result})
# _pkgconfig_set(${_prefix}_${_varname} "${_pkgconfig_invoke_result}")
endif(NOT _gmagickconfig_failed)
endmacro(_gmagickconfig_invoke)
 
_gmagickconfig_invoke("--cppflags" GMAGICK_INCLUDES "(^| )-I")
_gmagickconfig_invoke("--ldflags" GMAGICK_LDFLAGS "(^| )-L")
_gmagickconfig_invoke("--libs" GMAGICK_LIBRARIES "(^| )-l")
 
if(${GMAGICK_INCLUDES})
SET(${GMAGICK_FOUND "YES")
else(${GMAGICK_INCLUDES})
SET(${GMAGICK_INCLUDES})
SET(${GMAGICK_LIBRARIES})
SET(${GMAGICK_LDFLAGS})
endif(${GMAGICK_INCLUDES})
/trunk/Scribus/scribus/scimgdataloader_gmagick.h
0,0 → 1,28
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#ifndef SCIMGDATALOADER_GMAGICK_H
#define SCIMGDATALOADER_GMAGICK_H
 
#include "scimgdataloader.h"
 
 
class ScImgDataLoader_GMagick : public ScImgDataLoader
{
protected:
void initSupportedFormatList();
bool m_useRawImage;
 
public:
ScImgDataLoader_GMagick(void);
 
virtual bool preloadAlphaChannel(const QString& fn, int page, int res, bool& hasAlpha);
virtual void loadEmbeddedProfile(const QString& fn, int page = 0);
virtual bool loadPicture(const QString& fn, int page, int res, bool thumbnail);
virtual bool useRawImage() { return m_useRawImage; }
};
 
#endif
/trunk/Scribus/scribus/scimgdataloader_gmagick.cpp
0,0 → 1,216
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include <QFile>
#include <QFileInfo>
#include <QObject>
#include <QDebug>
#include <setjmp.h>
#include "scconfig.h"
#include "scimgdataloader_gmagick.h"
#include <Magick++.h>
using namespace Magick;
 
static bool read_cmyk(Image *input, RawImage *output, int width, int height)
{
/* Mapping:
red: cyan
green: magenta
blue: yellow
opacity: black
index: alpha
*/
//Copied from GraphicsMagick header and modified
#define GetCyanSample(p) (p.red)
#define GetMagentaSample(p) (p.green)
#define GetYellowSample(p) (p.blue)
#define GetCMYKBlackSample(p) (p.opacity)
#define GetAlphaSample(p) (p)
bool hasAlpha = input->matte();
if (!output->create(width, height, hasAlpha ? 5 : 4)) return false;
const PixelPacket *pixels = input->getConstPixels(0, 0, width, height);
const IndexPacket *alpha = input->getConstIndexes();
unsigned char *buffer = output->bits();
 
int i;
for (i = 0; i < width*height; i++) {
*buffer++ = ScaleQuantumToChar(GetCyanSample(pixels[i]));
*buffer++ = ScaleQuantumToChar(GetMagentaSample(pixels[i]));
*buffer++ = ScaleQuantumToChar(GetYellowSample(pixels[i]));
*buffer++ = ScaleQuantumToChar(GetCMYKBlackSample(pixels[i]));
if (hasAlpha) {
*buffer++ = 255 - ScaleQuantumToChar(GetAlphaSample(alpha[i]));
}
}
return true;
}
 
 
static bool read_rgb(Image *input, QImage *output, int width, int height)
{
//Copied from GraphicsMagick header and modified
#define GetRedSample(p) (p.red)
#define GetGreenSample(p) (p.green)
#define GetBlueSample(p) (p.blue)
#define GetRGBAlphaSample(p) (p.opacity)
bool hasAlpha = input->matte();
const PixelPacket *pixels = input->getConstPixels(0, 0, width, height);
unsigned char *buffer = output->bits();
 
int i;
for (i = 0; i < width*height; i++) {
*buffer++ = ScaleQuantumToChar(GetBlueSample(pixels[i]));
*buffer++ = ScaleQuantumToChar(GetGreenSample(pixels[i]));
*buffer++ = ScaleQuantumToChar(GetRedSample(pixels[i]));
if (hasAlpha) {
*buffer++ = 255 - ScaleQuantumToChar(GetRGBAlphaSample(pixels[i]));
} else {
*buffer++ = 255;
}
}
return true;
}
 
ScImgDataLoader_GMagick::ScImgDataLoader_GMagick(void)
{
initSupportedFormatList();
m_useRawImage = true;
}
 
void ScImgDataLoader_GMagick::initSupportedFormatList(void)
{
//This is unused! See util_formats.{h,cpp}
m_supportedFormats.clear();
m_supportedFormats.append("bmp"); //TODO
}
 
void ScImgDataLoader_GMagick::loadEmbeddedProfile(const QString& fn, int /*page*/)
{
if (!QFile::exists(fn)) {
m_embeddedProfile.resize(0);
m_profileComponents = 0;
return;
}
try {
Image image(std::string(fn.toUtf8()));
Blob icc = image.iccColorProfile();
if (image.colorSpace() == CMYKColorspace) {
m_profileComponents = 4;
} else if (image.colorSpace() == RGBColorspace) {
m_profileComponents = 3;
} else {
m_profileComponents = 0;
m_embeddedProfile.resize(0);
}
m_embeddedProfile.resize(icc.length());
char *dest = m_embeddedProfile.data();
const char *src = (const char *)icc.data();
unsigned int i;
for (i=0; i<icc.length(); i++) {
dest[i] = src[i];
}
 
} catch (std::exception &error_) {
m_profileComponents = 0;
m_embeddedProfile.resize(0);
qDebug() << "GraphicsMagic Exception in ScImgDataLoader_GMagick::loadEmbeddedProfile("
<< fn << "):" << error_.what();
return;
}
}
 
bool ScImgDataLoader_GMagick::preloadAlphaChannel(const QString& fn, int /*page*/, int res, bool& hasAlpha)
{
qDebug() << "GMAGICK: preloadAlpha" << fn;
initialize();
hasAlpha = false;
if (!QFile::exists(fn))
return false;
 
try {
Image image(std::string(fn.toUtf8()));
hasAlpha = image.matte();
if (!hasAlpha) {
return true; //No need to load any image data
} else {
return loadPicture(fn, 0, 0, false);
}
} catch (std::exception &error_) {
qDebug() << "GraphicsMagic Exception in ScImgDataLoader_GMagick::preloadAlphaChannel("
<< fn << "):" << error_.what();
return false;
}
return true;
}
 
bool ScImgDataLoader_GMagick::loadPicture(const QString& fn, int /*page*/, int res, bool thumbnail)
{
qDebug() << "Loading image" << fn << "Tumbnail:" << thumbnail;
 
if (!QFile::exists(fn))
return false;
initialize();
try {
Image image(std::string(fn.toUtf8()));
qDebug() << "Detected format:" << QString(image.format().c_str())
<< ", has matte(alpha):" << image.matte();
 
int width = image.baseColumns();
int height = image.baseRows();
image.resolutionUnits(PixelsPerInchResolution);
double xres = image.xResolution();
double yres = image.yResolution();
int resInf = m_imageInfoRecord.lowResType;
/*NOTE:
- The BGRO bit ordering was found by try'n'error
- Always use "O" for the alpha channel! "A" is inverted!
- image.write() is broken for cmyk images!
*/
if (image.colorSpace() == CMYKColorspace) {
qDebug() << "CMYK image";
m_useRawImage = true;
if (!read_cmyk(&image, &r_image, width, height)) return false;
m_imageInfoRecord.colorspace = ColorSpaceCMYK;
} else {
m_useRawImage = false;
m_image = QImage(width, height, QImage::Format_ARGB32);
if (!read_rgb(&image, &m_image, width, height)) return false;
m_imageInfoRecord.colorspace = ColorSpaceRGB;
}
m_imageInfoRecord.type = ImageTypeOther;
m_imageInfoRecord.exifDataValid = false;
m_imageInfoRecord.xres = qMax(72, qRound(xres));
m_imageInfoRecord.yres = qMax(72, qRound(yres));
m_imageInfoRecord.lowResType = resInf;
m_imageInfoRecord.BBoxX = 0;
m_imageInfoRecord.BBoxH = m_image.height();
m_imageInfoRecord.valid = true;
} catch (std::exception &error_) {
qDebug() << "GraphicsMagic Exception in ScImgDataLoader_GMagick::loadImage("
<< fn << "):" << error_.what();
return false;
}
return true;
}
/trunk/Scribus/scribus/plugins/uniconvertorplugin/uniconvplugin.cpp
0,0 → 1,191
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
 
#include "uniconvplugin.h"
#include "scraction.h"
#include "util_formats.h"
#include "prefsmanager.h"
 
#include <QDebug>
#include <QMessageBox>
#include <QString>
#include <QProcess>
#include <QTemporaryFile>
 
 
#include <QCursor>
#include <QDrag>
#include <QFile>
#include <QList>
#include <QMimeData>
#include <QPainterPath>
#include <QRegExp>
#include <cmath>
 
#include "commonstrings.h"
#include "scribuscore.h"
#include "undomanager.h"
 
int uniconvertorplugin_getPluginAPIVersion()
{
return PLUGIN_API_VERSION;
}
 
ScPlugin* uniconvertorplugin_getPlugin()
{
UniconvImportPlugin* plug = new UniconvImportPlugin();
Q_CHECK_PTR(plug);
return plug;
return 0;
}
 
void uniconvertorplugin_freePlugin(ScPlugin* plugin)
{
UniconvImportPlugin* plug = dynamic_cast<UniconvImportPlugin*>(plugin);
Q_ASSERT(plug);
delete plug;
}
 
UniconvImportPlugin::UniconvImportPlugin() : LoadSavePlugin()
{
// Set action info in languageChange, so we only have to do
// it in one place. This includes registering file format
// support.
languageChange();
}
 
UniconvImportPlugin::~UniconvImportPlugin()
{
unregisterAll();
};
 
void UniconvImportPlugin::languageChange()
{
// (Re)register file format support.
unregisterAll();
registerFormats();
}
 
const QString UniconvImportPlugin::fullTrName() const
{
return QObject::tr("Uniconvertor Import");
}
 
const ScActionPlugin::AboutData* UniconvImportPlugin::getAboutData() const
{
AboutData* about = new AboutData;
about->authors = "Hermann Kraus <herm@scribus.info>";
about->shortDescription = tr("Imports Vector Files with UniConvertor");
about->description = tr("Converts many vector formats to SVG and then "
"loads the resulting SVG.");
about->license = "GPL";
Q_CHECK_PTR(about);
return about;
}
 
void UniconvImportPlugin::deleteAboutData(const AboutData* about) const
{
Q_ASSERT(about);
delete about;
}
 
void UniconvImportPlugin::registerFormats()
{
QString name = tr("Uniconvertor Import");
FileFormat fmt(this);
fmt.trName = name;
fmt.formatId = FORMATID_UNICONVIMPORT;
fmt.filter = name + " (" +
FormatsManager::instance()->extensionListForFormat(
FormatsManager::UNICONV, 0)+")"; // QFileDialog filter
fmt.nameMatch = QRegExp("\\.("+
FormatsManager::instance()->extensionListForFormat(
FormatsManager::UNICONV, 1)+")$", Qt::CaseInsensitive);
fmt.load = true;
fmt.save = false;
//TODO: fmt.mimeTypes = QStringList(""); // MIME types
fmt.priority = 64; // Lowest priority
registerFormat(fmt);
}
 
bool UniconvImportPlugin::fileSupported(QIODevice* /* file */,
const QString & fileName) const
{
// TODO: It's hard to tell if a file is supported without first loading it
return true;
}
 
bool UniconvImportPlugin::loadFile(const QString & fileName,
const FileFormat & /* fmt */, int flags, int /*index*/)
{
// For now, "load file" and import are the same thing for this plugin
return import(fileName, flags);
}
 
bool UniconvImportPlugin::import(QString fileName, int flags)
{
if (!checkFlags(flags))
return false;
 
m_Doc = ScCore->primaryMainWindow()->doc;
ScribusMainWindow *mw =
(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
 
//Get a temporary filename ending in .svg (sadly
//uniconvertor has no other way of specifying the output format
QTemporaryFile *tempFile =
new QTemporaryFile(QDir::tempPath() + "/scribus_uniconv_XXXXXX");
tempFile->open();
QString tempFileName = tempFile->fileName() + ".svg";
tempFile->close();
delete tempFile;
 
//prepare arguments for uniconvertor call
QStringList arguments;
arguments << fileName << tempFileName;
//execute uniconvertor
QProcess uniconv;
uniconv.setProcessChannelMode(QProcess::MergedChannels);
uniconv.start(PrefsManager::instance()->uniconvExecutable(), arguments);
//handle errors
if (!uniconv.waitForStarted(10000)) {
qWarning() << "Uniconvertor failed:" <<
PrefsManager::instance()->uniconvExecutable() << arguments;
QMessageBox::warning(mw, CommonStrings::trWarning,
tr("Starting Uniconvertor failed! The executable name in "
"File->Preferences->External Tools may be incorrect or the "
"software has been uninstalled since preferences "
"were set. (%1)").arg(uniconv.errorString()));
return false;
}
if (!uniconv.waitForFinished(10000)) {
qDebug() << "Uniconv exit code:" << uniconv.exitCode();
QMessageBox::warning(mw, CommonStrings::trWarning,
tr("Uniconvertor did not exit correctly: %1").arg(
uniconv.errorString()).arg(QString(uniconv.readAll())));
return false;
}
if (uniconv.exitCode()) {
qDebug() << "Uniconv exit code:" << uniconv.exitCode();
QMessageBox::warning(mw, CommonStrings::trWarning,
tr("Uniconvertor failed to convert the file: %1").arg(
QString(uniconv.readAll())));
return false;
}
//Import SVG
const FileFormat *fmt = LoadSavePlugin::getFormatById(FORMATID_SVGIMPORT);
if (!fmt) {
QMessageBox::warning(mw, CommonStrings::trWarning, tr("The SVG Import plugin could not be found"), 1, 0, 0);
return false;
}
qDebug() << "Loading file!";
fmt->loadFile(tempFileName, flags);
return true;
}
/trunk/Scribus/scribus/plugins/uniconvertorplugin/uniconvplugin.h
0,0 → 1,54
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#ifndef UNICONVPLUGIN_H
#define UNICONVPLUGIN_H
 
#include "pluginapi.h"
#include "loadsaveplugin.h"
#include "../formatidlist.h"
#include <QObject>
 
class ScrAction;
class ScribusMainWindow;
 
/**
* \brief A class providing the plugin interface implementation for the uniconvertor plugin
*/
class PLUGIN_API UniconvImportPlugin : public LoadSavePlugin
{
Q_OBJECT
 
public:
// Standard plugin implementation
UniconvImportPlugin();
virtual ~UniconvImportPlugin();
virtual const QString fullTrName() const;
virtual const AboutData* getAboutData() const;
virtual void deleteAboutData(const AboutData* about) const;
virtual void languageChange();
virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const;
virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
virtual void addToMainWindowMenu(ScribusMainWindow *) {};
 
public slots:
/*!
\brief Run UniConvertor and import results
\param filename a file name to import
\retval true for success
*/
virtual bool import(QString fileName = QString::null, int flags = lfUseCurrentPage|lfInteractive);
 
private:
void registerFormats();
 
};
 
extern "C" PLUGIN_API int uniconvertorplugin_getPluginAPIVersion();
extern "C" PLUGIN_API ScPlugin* uniconvertorplugin_getPlugin();
extern "C" PLUGIN_API void uniconvertorplugin_freePlugin(ScPlugin* plugin);
 
#endif
/trunk/Scribus/scribus/plugins/uniconvertorplugin/.cvsignore
0,0 → 1,26
Makefile
Makefile.in
*.la
*.lo
*.moc.cpp
*.moc
*.o
.deps
.libs
CVS
scribus
CMakeFiles
cmake_install.cmake
Makefile
Makefile.in
*.la
*.lo
*.moc.cpp
*.moc
*.o
.deps
.libs
CVS
scribus
CMakeFiles
cmake_install.cmake
/trunk/Scribus/scribus/plugins/uniconvertorplugin/CMakeLists.txt
0,0 → 1,30
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/scribus
)
 
SET(IMPORTUNICONVERTOR_PLUGIN_MOC_CLASSES
uniconvplugin.h
)
 
SET(IMPORTUNICONVERTOR_PLUGIN_SOURCES
uniconvplugin.cpp
)
 
SET(SCRIBUS_IMPORTUNICONVERTOR_PLUGIN "uniconvertorplugin")
 
QT4_WRAP_CPP(IMPORTUNICONVERTOR_PLUGIN_MOC_SOURCES ${IMPORTUNICONVERTOR_PLUGIN_MOC_CLASSES})
 
ADD_LIBRARY(${SCRIBUS_IMPORTUNICONVERTOR_PLUGIN} MODULE ${IMPORTUNICONVERTOR_PLUGIN_SOURCES} ${IMPORTUNICONVERTOR_PLUGIN_MOC_SOURCES})
 
TARGET_LINK_LIBRARIES(${SCRIBUS_IMPORTUNICONVERTOR_PLUGIN} ${PLUGIN_LIBRARIES})
 
INSTALL(TARGETS ${SCRIBUS_IMPORTUNICONVERTOR_PLUGIN}
LIBRARY
DESTINATION ${PLUGINDIR}
PERMISSIONS ${PLUGIN_PERMISSIONS}
)
 
ADD_DEPENDENCIES(${SCRIBUS_IMPORTUNICONVERTOR_PLUGIN} ${EXE_NAME})
 
# SET_TARGET_PROPERTIES(${SCRIBUS_FONTPREVIEW_PLUGIN} PROPERTIES VERSION "0.0.0")