mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Some bugfixing
This commit is contained in:
@ -697,6 +697,7 @@ bool PDFAbstractColorSpace::transform(const PDFAbstractColorSpace* source,
|
|||||||
std::vector<PDFColorComponent> transformedOutputColorsVector;
|
std::vector<PDFColorComponent> transformedOutputColorsVector;
|
||||||
PDFColorBuffer transformedInput = input;
|
PDFColorBuffer transformedInput = input;
|
||||||
PDFColorBuffer transformedOutput = output;
|
PDFColorBuffer transformedOutput = output;
|
||||||
|
params.intent = intent;
|
||||||
|
|
||||||
switch (source->getColorSpace())
|
switch (source->getColorSpace())
|
||||||
{
|
{
|
||||||
|
@ -534,11 +534,14 @@ PDFTransparencyRenderer::PDFTransparencyRenderer(const PDFPage* page,
|
|||||||
const PDFFontCache* fontCache,
|
const PDFFontCache* fontCache,
|
||||||
const PDFCMS* cms,
|
const PDFCMS* cms,
|
||||||
const PDFOptionalContentActivity* optionalContentActivity,
|
const PDFOptionalContentActivity* optionalContentActivity,
|
||||||
|
const PDFInkMapper* inkMapper,
|
||||||
QMatrix pagePointToDevicePointMatrix) :
|
QMatrix pagePointToDevicePointMatrix) :
|
||||||
BaseClass(page, document, fontCache, cms, optionalContentActivity, pagePointToDevicePointMatrix, PDFMeshQualitySettings()),
|
BaseClass(page, document, fontCache, cms, optionalContentActivity, pagePointToDevicePointMatrix, PDFMeshQualitySettings()),
|
||||||
|
m_inkMapper(inkMapper),
|
||||||
m_active(false)
|
m_active(false)
|
||||||
{
|
{
|
||||||
|
m_deviceColorSpace.reset(new PDFDeviceRGBColorSpace());
|
||||||
|
m_processColorSpace.reset(new PDFDeviceCMYKColorSpace());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFTransparencyRenderer::setDeviceColorSpace(PDFColorSpacePointer colorSpace)
|
void PDFTransparencyRenderer::setDeviceColorSpace(PDFColorSpacePointer colorSpace)
|
||||||
@ -550,16 +553,51 @@ void PDFTransparencyRenderer::setDeviceColorSpace(PDFColorSpacePointer colorSpac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFTransparencyRenderer::beginPaint()
|
void PDFTransparencyRenderer::setProcessColorSpace(PDFColorSpacePointer colorSpace)
|
||||||
|
{
|
||||||
|
if (!colorSpace || colorSpace->isBlendColorSpace())
|
||||||
|
{
|
||||||
|
// Set process color space only, when it is a blend color space
|
||||||
|
m_processColorSpace = colorSpace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFTransparencyRenderer::beginPaint(QSize pixelSize)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_active);
|
Q_ASSERT(!m_active);
|
||||||
m_active = true;
|
m_active = true;
|
||||||
|
|
||||||
|
Q_ASSERT(pixelSize.isValid());
|
||||||
|
Q_ASSERT(m_deviceColorSpace);
|
||||||
|
Q_ASSERT(m_processColorSpace);
|
||||||
|
|
||||||
|
PDFPixelFormat pixelFormat = PDFPixelFormat::createFormat(uint8_t(m_deviceColorSpace->getColorComponentCount()),
|
||||||
|
uint8_t(m_inkMapper->getActiveSpotColorCount()),
|
||||||
|
true, m_deviceColorSpace->getColorComponentCount() == 4);
|
||||||
|
|
||||||
|
PDFTransparencyGroupPainterData deviceGroup;
|
||||||
|
deviceGroup.alphaIsShape = getGraphicState()->getAlphaIsShape();
|
||||||
|
deviceGroup.alphaStroke = getGraphicState()->getAlphaStroking();
|
||||||
|
deviceGroup.alphaFill = getGraphicState()->getAlphaFilling();
|
||||||
|
deviceGroup.blendMode = getGraphicState()->getBlendMode();
|
||||||
|
deviceGroup.blackPointCompensationMode = getGraphicState()->getBlackPointCompensationMode();
|
||||||
|
deviceGroup.renderingIntent = RenderingIntent::RelativeColorimetric;
|
||||||
|
deviceGroup.initialBackdrop = PDFFloatBitmapWithColorSpace(pixelSize.width(), pixelSize.height(), pixelFormat, m_deviceColorSpace);
|
||||||
|
deviceGroup.immediateBackdrop = deviceGroup.initialBackdrop;
|
||||||
|
deviceGroup.blendColorSpace = m_deviceColorSpace;
|
||||||
|
|
||||||
|
m_transparencyGroupDataStack.emplace_back(qMove(deviceGroup));
|
||||||
|
|
||||||
// Create page transparency group
|
// Create page transparency group
|
||||||
PDFObject pageTransparencyGroupObject = getPage()->getTransparencyGroup(&getDocument()->getStorage());
|
PDFObject pageTransparencyGroupObject = getPage()->getTransparencyGroup(&getDocument()->getStorage());
|
||||||
PDFTransparencyGroup transparencyGroup = parseTransparencyGroup(pageTransparencyGroupObject);
|
PDFTransparencyGroup transparencyGroup = parseTransparencyGroup(pageTransparencyGroupObject);
|
||||||
transparencyGroup.isolated = true;
|
transparencyGroup.isolated = true;
|
||||||
|
|
||||||
|
if (!transparencyGroup.colorSpacePointer)
|
||||||
|
{
|
||||||
|
transparencyGroup.colorSpacePointer = m_processColorSpace;
|
||||||
|
}
|
||||||
|
|
||||||
m_pageTransparencyGroupGuard.reset(new PDFTransparencyGroupGuard(this, qMove(transparencyGroup)));
|
m_pageTransparencyGroupGuard.reset(new PDFTransparencyGroupGuard(this, qMove(transparencyGroup)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -779,7 +817,16 @@ void PDFInkMapper::createSpotColors(bool activate)
|
|||||||
std::size_t colorSpaces = colorSpaceDictionary->getCount();
|
std::size_t colorSpaces = colorSpaceDictionary->getCount();
|
||||||
for (size_t csIndex = 0; csIndex < colorSpaces; ++ csIndex)
|
for (size_t csIndex = 0; csIndex < colorSpaces; ++ csIndex)
|
||||||
{
|
{
|
||||||
PDFColorSpacePointer colorSpacePointer = PDFAbstractColorSpace::createColorSpace(colorSpaceDictionary, m_document, colorSpaceDictionary->getValue(csIndex));
|
PDFColorSpacePointer colorSpacePointer;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
colorSpacePointer = PDFAbstractColorSpace::createColorSpace(colorSpaceDictionary, m_document, m_document->getObject(colorSpaceDictionary->getValue(csIndex)));
|
||||||
|
}
|
||||||
|
catch (PDFException)
|
||||||
|
{
|
||||||
|
// Ignore invalid color spaces
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!colorSpacePointer)
|
if (!colorSpacePointer)
|
||||||
{
|
{
|
||||||
|
@ -67,11 +67,11 @@ public:
|
|||||||
constexpr uint8_t getColorChannelIndexStart() const { return (hasProcessColors() || hasSpotColors()) ? 0 : INVALID_CHANNEL_INDEX; }
|
constexpr uint8_t getColorChannelIndexStart() const { return (hasProcessColors() || hasSpotColors()) ? 0 : INVALID_CHANNEL_INDEX; }
|
||||||
constexpr uint8_t getColorChannelIndexEnd() const { return (hasProcessColors() || hasSpotColors()) ? (m_processColors + m_spotColors) : INVALID_CHANNEL_INDEX; }
|
constexpr uint8_t getColorChannelIndexEnd() const { return (hasProcessColors() || hasSpotColors()) ? (m_processColors + m_spotColors) : INVALID_CHANNEL_INDEX; }
|
||||||
constexpr uint8_t getShapeChannelIndex() const { return hasShapeChannel() ? getProcessColorChannelCount() + getSpotColorChannelCount() : INVALID_CHANNEL_INDEX; }
|
constexpr uint8_t getShapeChannelIndex() const { return hasShapeChannel() ? getProcessColorChannelCount() + getSpotColorChannelCount() : INVALID_CHANNEL_INDEX; }
|
||||||
constexpr uint8_t getOpacityChannelIndex() const { return hasShapeChannel() ? getProcessColorChannelCount() + getSpotColorChannelCount() + getShapeChannelCount() : INVALID_CHANNEL_INDEX; }
|
constexpr uint8_t getOpacityChannelIndex() const { return hasOpacityChannel() ? getProcessColorChannelCount() + getSpotColorChannelCount() + getShapeChannelCount() : INVALID_CHANNEL_INDEX; }
|
||||||
|
|
||||||
/// Pixel format is valid, if we have at least one color channel
|
/// Pixel format is valid, if we have at least one color channel
|
||||||
/// (it doesn't matter, if it is process color, or spot color)
|
/// (it doesn't matter, if it is process color, or spot color)
|
||||||
constexpr bool isValid() const { return getColorChannelCount() > 0; }
|
constexpr bool isValid() const { return getChannelCount() > 0; }
|
||||||
|
|
||||||
inline void setProcessColors(const uint8_t& processColors) { m_processColors = processColors; }
|
inline void setProcessColors(const uint8_t& processColors) { m_processColors = processColors; }
|
||||||
inline void setSpotColors(const uint8_t& spotColors) { m_spotColors = spotColors; }
|
inline void setSpotColors(const uint8_t& spotColors) { m_spotColors = spotColors; }
|
||||||
@ -237,7 +237,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Ink mapper for mapping device inks (device colors) and spot inks (spot colors).
|
/// Ink mapper for mapping device inks (device colors) and spot inks (spot colors).
|
||||||
class PDFInkMapper
|
class Pdf4QtLIBSHARED_EXPORT PDFInkMapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit PDFInkMapper(const PDFDocument* document);
|
explicit PDFInkMapper(const PDFDocument* document);
|
||||||
@ -281,7 +281,7 @@ private:
|
|||||||
/// page blending space and device blending space. So, painted graphics is being
|
/// page blending space and device blending space. So, painted graphics is being
|
||||||
/// blended to the page blending space, and then converted to the device blending
|
/// blended to the page blending space, and then converted to the device blending
|
||||||
/// space.
|
/// space.
|
||||||
class PDFTransparencyRenderer : public PDFPageContentProcessor
|
class Pdf4QtLIBSHARED_EXPORT PDFTransparencyRenderer : public PDFPageContentProcessor
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
using BaseClass = PDFPageContentProcessor;
|
using BaseClass = PDFPageContentProcessor;
|
||||||
@ -292,13 +292,23 @@ public:
|
|||||||
const PDFFontCache* fontCache,
|
const PDFFontCache* fontCache,
|
||||||
const PDFCMS* cms,
|
const PDFCMS* cms,
|
||||||
const PDFOptionalContentActivity* optionalContentActivity,
|
const PDFOptionalContentActivity* optionalContentActivity,
|
||||||
|
const PDFInkMapper* inkMapper,
|
||||||
QMatrix pagePointToDevicePointMatrix);
|
QMatrix pagePointToDevicePointMatrix);
|
||||||
|
|
||||||
|
/// Sets device color space. This is final color space, to which
|
||||||
|
/// is painted page transformed.
|
||||||
|
/// \param colorSpace Color space
|
||||||
void setDeviceColorSpace(PDFColorSpacePointer colorSpace);
|
void setDeviceColorSpace(PDFColorSpacePointer colorSpace);
|
||||||
|
|
||||||
|
/// Sets process color space. This color space is used for blending
|
||||||
|
/// and intermediate results. If page has transparency group, then
|
||||||
|
/// blending color space from transparency group is used.
|
||||||
|
/// \param colorSpace Color space
|
||||||
|
void setProcessColorSpace(PDFColorSpacePointer colorSpace);
|
||||||
|
|
||||||
/// Starts painting on the device. This function must be called before page
|
/// Starts painting on the device. This function must be called before page
|
||||||
/// content stream is being processed (and must be called exactly once).
|
/// content stream is being processed (and must be called exactly once).
|
||||||
void beginPaint();
|
void beginPaint(QSize pixelSize);
|
||||||
|
|
||||||
/// Finishes painting on the device. This function must be called after page
|
/// Finishes painting on the device. This function must be called after page
|
||||||
/// content stream is processed and all result graphics is being drawn. Page
|
/// content stream is processed and all result graphics is being drawn. Page
|
||||||
@ -345,6 +355,7 @@ private:
|
|||||||
PDFColorSpacePointer m_processColorSpace; ///< Process color space (color space, in which is page graphic's blended)
|
PDFColorSpacePointer m_processColorSpace; ///< Process color space (color space, in which is page graphic's blended)
|
||||||
std::unique_ptr<PDFTransparencyGroupGuard> m_pageTransparencyGroupGuard;
|
std::unique_ptr<PDFTransparencyGroupGuard> m_pageTransparencyGroupGuard;
|
||||||
std::vector<PDFTransparencyGroupPainterData> m_transparencyGroupDataStack;
|
std::vector<PDFTransparencyGroupPainterData> m_transparencyGroupDataStack;
|
||||||
|
const PDFInkMapper* m_inkMapper;
|
||||||
bool m_active;
|
bool m_active;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,14 +18,28 @@
|
|||||||
#include "outputpreviewdialog.h"
|
#include "outputpreviewdialog.h"
|
||||||
#include "ui_outputpreviewdialog.h"
|
#include "ui_outputpreviewdialog.h"
|
||||||
|
|
||||||
|
#include "pdfcms.h"
|
||||||
|
#include "pdfrenderer.h"
|
||||||
|
#include "pdfdrawspacecontroller.h"
|
||||||
|
|
||||||
namespace pdfplugin
|
namespace pdfplugin
|
||||||
{
|
{
|
||||||
|
|
||||||
OutputPreviewDialog::OutputPreviewDialog(QWidget* parent) :
|
OutputPreviewDialog::OutputPreviewDialog(const pdf::PDFDocument* document, pdf::PDFWidget* widget, QWidget* parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::OutputPreviewDialog)
|
ui(new Ui::OutputPreviewDialog),
|
||||||
|
m_inkMapper(document),
|
||||||
|
m_document(document),
|
||||||
|
m_widget(widget)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
ui->pageIndexScrollBar->setMinimum(1);
|
||||||
|
ui->pageIndexScrollBar->setValue(1);
|
||||||
|
ui->pageIndexScrollBar->setMaximum(int(document->getCatalog()->getPageCount()));
|
||||||
|
|
||||||
|
m_inkMapper.createSpotColors(true);
|
||||||
|
updateImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputPreviewDialog::~OutputPreviewDialog()
|
OutputPreviewDialog::~OutputPreviewDialog()
|
||||||
@ -33,4 +47,32 @@ OutputPreviewDialog::~OutputPreviewDialog()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OutputPreviewDialog::updateImage()
|
||||||
|
{
|
||||||
|
const pdf::PDFPage* page = m_document->getCatalog()->getPage(ui->pageIndexScrollBar->value() - 1);
|
||||||
|
if (!page)
|
||||||
|
{
|
||||||
|
ui->imageLabel->setPixmap(QPixmap());
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF pageRect = page->getRotatedMediaBox();
|
||||||
|
QSizeF pageSize = pageRect.size();
|
||||||
|
pageSize.scale(ui->imageLabel->width(), ui->imageLabel->height(), Qt::KeepAspectRatio);
|
||||||
|
QSize imageSize = pageSize.toSize();
|
||||||
|
|
||||||
|
if (!imageSize.isValid())
|
||||||
|
{
|
||||||
|
ui->imageLabel->setPixmap(QPixmap());
|
||||||
|
}
|
||||||
|
|
||||||
|
QMatrix pagePointToDevicePoint = pdf::PDFRenderer::createPagePointToDevicePointMatrix(page, QRect(QPoint(0, 0), imageSize));
|
||||||
|
pdf::PDFDrawWidgetProxy* proxy = m_widget->getDrawWidgetProxy();
|
||||||
|
pdf::PDFCMSPointer cms = proxy->getCMSManager()->getCurrentCMS();
|
||||||
|
pdf::PDFTransparencyRenderer renderer(page, m_document, proxy->getFontCache(), cms.data(), proxy->getOptionalContentActivity(), &m_inkMapper, pagePointToDevicePoint);
|
||||||
|
|
||||||
|
renderer.beginPaint(imageSize);
|
||||||
|
renderer.processContents();
|
||||||
|
renderer.endPaint();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pdfplugin
|
} // namespace pdfplugin
|
||||||
|
@ -18,6 +18,10 @@
|
|||||||
#ifndef OUTPUTPREVIEWDIALOG_H
|
#ifndef OUTPUTPREVIEWDIALOG_H
|
||||||
#define OUTPUTPREVIEWDIALOG_H
|
#define OUTPUTPREVIEWDIALOG_H
|
||||||
|
|
||||||
|
#include "pdfdocument.h"
|
||||||
|
#include "pdfdrawwidget.h"
|
||||||
|
#include "pdftransparencyrenderer.h"
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
@ -33,11 +37,16 @@ class OutputPreviewDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit OutputPreviewDialog(QWidget* parent);
|
explicit OutputPreviewDialog(const pdf::PDFDocument* document, pdf::PDFWidget* widget, QWidget* parent);
|
||||||
virtual ~OutputPreviewDialog() override;
|
virtual ~OutputPreviewDialog() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateImage();
|
||||||
|
|
||||||
Ui::OutputPreviewDialog* ui;
|
Ui::OutputPreviewDialog* ui;
|
||||||
|
pdf::PDFInkMapper m_inkMapper;
|
||||||
|
const pdf::PDFDocument* m_document;
|
||||||
|
pdf::PDFWidget* m_widget;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pdf
|
} // namespace pdf
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QScrollBar" name="verticalScrollBar">
|
<widget class="QScrollBar" name="pageIndexScrollBar">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -62,7 +62,7 @@ std::vector<QAction*> OutputPreviewPlugin::getActions() const
|
|||||||
|
|
||||||
void OutputPreviewPlugin::onOutputPreviewTriggered()
|
void OutputPreviewPlugin::onOutputPreviewTriggered()
|
||||||
{
|
{
|
||||||
OutputPreviewDialog dialog(m_widget);
|
OutputPreviewDialog dialog(m_document, m_widget, m_widget);
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user