Editor plugin: WIP

This commit is contained in:
Jakub Melka
2023-03-06 16:09:09 +01:00
parent 1e52c0c063
commit 1b6bb6086c
32 changed files with 2243 additions and 311 deletions

View File

@ -23,6 +23,7 @@
#include "pdfexecutionpolicy.h"
#include "pdfstreamfilters.h"
#include <QScopeGuard>
#include <QPainterPathStroker>
#include <QtMath>
@ -390,9 +391,10 @@ void PDFPageContentProcessor::performClipping(const QPainterPath& path, Qt::Fill
Q_UNUSED(fillRule);
}
bool PDFPageContentProcessor::performOriginalImagePainting(const PDFImage& image)
bool PDFPageContentProcessor::performOriginalImagePainting(const PDFImage& image, const PDFStream* stream)
{
Q_UNUSED(image);
Q_UNUSED(stream);
return false;
}
@ -485,6 +487,12 @@ void PDFPageContentProcessor::performTextEnd(ProcessOrder order)
Q_UNUSED(order);
}
void PDFPageContentProcessor::performProcessTextSequence(const TextSequence& textSequence, ProcessOrder order)
{
Q_UNUSED(textSequence);
Q_UNUSED(order);
}
bool PDFPageContentProcessor::isContentKindSuppressed(ContentKind kind) const
{
Q_UNUSED(kind);
@ -528,6 +536,15 @@ PDFPageContentProcessor::PDFTransparencyGroup PDFPageContentProcessor::parseTran
return group;
}
void PDFPageContentProcessor::performInterceptInstruction(Operator currentOperator,
ProcessOrder processOrder,
const QByteArray& operatorAsText)
{
Q_UNUSED(currentOperator);
Q_UNUSED(processOrder);
Q_UNUSED(operatorAsText);
}
void PDFPageContentProcessor::processContent(const QByteArray& content)
{
PDFLexicalAnalyzer parser(content.constBegin(), content.constEnd());
@ -738,6 +755,12 @@ void PDFPageContentProcessor::processForm(const QTransform& matrix,
const QByteArray& content,
PDFInteger formStructuralParent)
{
if (isContentKindSuppressed(ContentKind::Forms))
{
// Process of forms is suppressed
return;
}
PDFPageContentProcessorStateGuard guard(this);
PDFTemporaryValueChange structuralParentChangeGuard(&m_structuralParentKey, formStructuralParent);
@ -1129,6 +1152,9 @@ void PDFPageContentProcessor::processCommand(const QByteArray& command)
}
}
performInterceptInstruction(op, ProcessOrder::BeforeOperation, command);
auto callInterceptInstAtEnd = qScopeGuard([&, this](){ performInterceptInstruction(op, ProcessOrder::AfterOperation, command); });
switch (op)
{
case Operator::SetLineWidth:
@ -1855,6 +1881,11 @@ bool PDFPageContentProcessor::isProcessingCancelled() const
return m_operationControl && m_operationControl->isOperationCancelled();
}
bool PDFPageContentProcessor::isTextProcessing() const
{
return m_textBeginEndState > 0;
}
void PDFPageContentProcessor::reportRenderErrorOnce(RenderErrorType type, QString message)
{
if (!m_onceReportedErrors.count(message))
@ -2973,7 +3004,7 @@ void PDFPageContentProcessor::paintXObjectImage(const PDFStream* stream)
PDFImage pdfImage = PDFImage::createImage(m_document, stream, qMove(colorSpace), false, m_graphicState.getRenderingIntent(), this);
if (!performOriginalImagePainting(pdfImage))
if (!performOriginalImagePainting(pdfImage, stream))
{
QImage image = pdfImage.getImage(m_CMS, this, m_operationControl);
@ -3007,6 +3038,12 @@ void PDFPageContentProcessor::reportWarningAboutColorOperatorsInUTP()
void PDFPageContentProcessor::processForm(const PDFStream* stream)
{
if (isContentKindSuppressed(ContentKind::Forms))
{
// Process of forms is suppressed
return;
}
PDFDocumentDataLoaderDecorator loader(getDocument());
const PDFDictionary* streamDictionary = stream->getDictionary();
@ -3165,6 +3202,8 @@ void PDFPageContentProcessor::drawText(const TextSequence& textSequence)
return;
}
performProcessTextSequence(textSequence, ProcessOrder::BeforeOperation);
const PDFRealizedFontPointer& font = getRealizedFont();
if (font)
{
@ -3340,6 +3379,8 @@ void PDFPageContentProcessor::drawText(const TextSequence& textSequence)
{
throw PDFRendererException(RenderErrorType::Error, PDFTranslationContext::tr("Invalid font, text can't be printed."));
}
performProcessTextSequence(textSequence, ProcessOrder::AfterOperation);
}
PDFRealizedFontPointer PDFPageContentProcessor::getRealizedFontImpl()
@ -3415,7 +3456,7 @@ bool PDFPageContentProcessor::isContentSuppressedByOC(PDFObjectReference ocgOrOc
return false;
}
PDFPageContentProcessor::PDFPageContentProcessorState::PDFPageContentProcessorState() :
PDFPageContentProcessorState::PDFPageContentProcessorState() :
m_currentTransformationMatrix(),
m_strokeColorSpace(),
m_fillColorSpace(),
@ -3456,12 +3497,12 @@ PDFPageContentProcessor::PDFPageContentProcessorState::PDFPageContentProcessorSt
m_strokeColorOriginal = m_fillColorOriginal;
}
PDFPageContentProcessor::PDFPageContentProcessorState::~PDFPageContentProcessorState()
PDFPageContentProcessorState::~PDFPageContentProcessorState()
{
}
PDFPageContentProcessor::PDFPageContentProcessorState& PDFPageContentProcessor::PDFPageContentProcessorState::operator=(const PDFPageContentProcessor::PDFPageContentProcessorState& other)
PDFPageContentProcessorState& PDFPageContentProcessorState::operator=(const PDFPageContentProcessorState& other)
{
setCurrentTransformationMatrix(other.getCurrentTransformationMatrix());
setStrokeColorSpace(other.m_strokeColorSpace);
@ -3504,7 +3545,7 @@ PDFPageContentProcessor::PDFPageContentProcessorState& PDFPageContentProcessor::
return *this;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setCurrentTransformationMatrix(const QTransform& currentTransformationMatrix)
void PDFPageContentProcessorState::setCurrentTransformationMatrix(const QTransform& currentTransformationMatrix)
{
if (m_currentTransformationMatrix != currentTransformationMatrix)
{
@ -3513,7 +3554,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setCurrentTransforma
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setStrokeColorSpace(const QSharedPointer<PDFAbstractColorSpace>& strokeColorSpace)
void PDFPageContentProcessorState::setStrokeColorSpace(const QSharedPointer<PDFAbstractColorSpace>& strokeColorSpace)
{
if (m_strokeColorSpace != strokeColorSpace)
{
@ -3522,7 +3563,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setStrokeColorSpace(
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setFillColorSpace(const QSharedPointer<PDFAbstractColorSpace>& fillColorSpace)
void PDFPageContentProcessorState::setFillColorSpace(const QSharedPointer<PDFAbstractColorSpace>& fillColorSpace)
{
if (m_fillColorSpace != fillColorSpace)
{
@ -3531,7 +3572,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setFillColorSpace(co
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setStrokeColor(const QColor& strokeColor, const PDFColor& originalColor)
void PDFPageContentProcessorState::setStrokeColor(const QColor& strokeColor, const PDFColor& originalColor)
{
if (m_strokeColor != strokeColor || m_strokeColorOriginal != originalColor)
{
@ -3541,7 +3582,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setStrokeColor(const
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setFillColor(const QColor& fillColor, const PDFColor& originalColor)
void PDFPageContentProcessorState::setFillColor(const QColor& fillColor, const PDFColor& originalColor)
{
if (m_fillColor != fillColor || m_fillColorOriginal != originalColor)
{
@ -3551,7 +3592,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setFillColor(const Q
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setLineWidth(PDFReal lineWidth)
void PDFPageContentProcessorState::setLineWidth(PDFReal lineWidth)
{
if (m_lineWidth != lineWidth)
{
@ -3560,7 +3601,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setLineWidth(PDFReal
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setLineCapStyle(Qt::PenCapStyle lineCapStyle)
void PDFPageContentProcessorState::setLineCapStyle(Qt::PenCapStyle lineCapStyle)
{
if (m_lineCapStyle != lineCapStyle)
{
@ -3569,7 +3610,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setLineCapStyle(Qt::
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setLineJoinStyle(Qt::PenJoinStyle lineJoinStyle)
void PDFPageContentProcessorState::setLineJoinStyle(Qt::PenJoinStyle lineJoinStyle)
{
if (m_lineJoinStyle != lineJoinStyle)
{
@ -3578,7 +3619,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setLineJoinStyle(Qt:
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setMitterLimit(PDFReal mitterLimit)
void PDFPageContentProcessorState::setMitterLimit(PDFReal mitterLimit)
{
if (m_mitterLimit != mitterLimit)
{
@ -3587,7 +3628,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setMitterLimit(PDFRe
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setLineDashPattern(PDFLineDashPattern pattern)
void PDFPageContentProcessorState::setLineDashPattern(PDFLineDashPattern pattern)
{
if (m_lineDashPattern != pattern)
{
@ -3596,7 +3637,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setLineDashPattern(P
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setRenderingIntentName(const QByteArray& renderingIntentName)
void PDFPageContentProcessorState::setRenderingIntentName(const QByteArray& renderingIntentName)
{
if (m_renderingIntentName != renderingIntentName)
{
@ -3605,7 +3646,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setRenderingIntentNa
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setFlatness(PDFReal flatness)
void PDFPageContentProcessorState::setFlatness(PDFReal flatness)
{
if (m_flatness != flatness)
{
@ -3614,7 +3655,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setFlatness(PDFReal
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setSmoothness(PDFReal smoothness)
void PDFPageContentProcessorState::setSmoothness(PDFReal smoothness)
{
if (m_smoothness != smoothness)
{
@ -3623,7 +3664,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setSmoothness(PDFRea
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextLeading(PDFReal textLeading)
void PDFPageContentProcessorState::setTextLeading(PDFReal textLeading)
{
if (m_textLeading != textLeading)
{
@ -3632,7 +3673,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextLeading(PDFRe
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextFontSize(PDFReal textFontSize)
void PDFPageContentProcessorState::setTextFontSize(PDFReal textFontSize)
{
if (m_textFontSize != textFontSize)
{
@ -3641,7 +3682,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextFontSize(PDFR
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextKnockout(bool textKnockout)
void PDFPageContentProcessorState::setTextKnockout(bool textKnockout)
{
if (m_textKnockout != textKnockout)
{
@ -3650,7 +3691,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextKnockout(bool
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextLineMatrix(const QTransform& textLineMatrix)
void PDFPageContentProcessorState::setTextLineMatrix(const QTransform& textLineMatrix)
{
if (m_textLineMatrix != textLineMatrix)
{
@ -3659,7 +3700,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextLineMatrix(co
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setAlphaStroking(PDFReal alpha)
void PDFPageContentProcessorState::setAlphaStroking(PDFReal alpha)
{
if (m_alphaStroking != alpha)
{
@ -3668,7 +3709,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setAlphaStroking(PDF
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setAlphaFilling(PDFReal alpha)
void PDFPageContentProcessorState::setAlphaFilling(PDFReal alpha)
{
if (m_alphaFilling != alpha)
{
@ -3677,7 +3718,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setAlphaFilling(PDFR
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setBlendMode(BlendMode mode)
void PDFPageContentProcessorState::setBlendMode(BlendMode mode)
{
if (m_blendMode != mode)
{
@ -3686,7 +3727,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setBlendMode(BlendMo
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setRenderingIntent(RenderingIntent renderingIntent)
void PDFPageContentProcessorState::setRenderingIntent(RenderingIntent renderingIntent)
{
if (m_renderingIntent != renderingIntent)
{
@ -3695,21 +3736,21 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setRenderingIntent(R
}
}
QColor PDFPageContentProcessor::PDFPageContentProcessorState::getStrokeColorWithAlpha() const
QColor PDFPageContentProcessorState::getStrokeColorWithAlpha() const
{
QColor color = getStrokeColor();
color.setAlphaF(m_alphaStroking);
return color;
}
QColor PDFPageContentProcessor::PDFPageContentProcessorState::getFillColorWithAlpha() const
QColor PDFPageContentProcessorState::getFillColorWithAlpha() const
{
QColor color = getFillColor();
color.setAlphaF(m_alphaFilling);
return color;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setOverprintMode(PDFOverprintMode overprintMode)
void PDFPageContentProcessorState::setOverprintMode(PDFOverprintMode overprintMode)
{
if (m_overprintMode != overprintMode)
{
@ -3718,7 +3759,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setOverprintMode(PDF
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setAlphaIsShape(bool alphaIsShape)
void PDFPageContentProcessorState::setAlphaIsShape(bool alphaIsShape)
{
if (m_alphaIsShape != alphaIsShape)
{
@ -3727,12 +3768,12 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setAlphaIsShape(bool
}
}
bool PDFPageContentProcessor::PDFPageContentProcessorState::getStrokeAdjustment() const
bool PDFPageContentProcessorState::getStrokeAdjustment() const
{
return m_strokeAdjustment;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setStrokeAdjustment(bool strokeAdjustment)
void PDFPageContentProcessorState::setStrokeAdjustment(bool strokeAdjustment)
{
if (m_strokeAdjustment != strokeAdjustment)
{
@ -3741,12 +3782,12 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setStrokeAdjustment(
}
}
const PDFDictionary* PDFPageContentProcessor::PDFPageContentProcessorState::getSoftMask() const
const PDFDictionary* PDFPageContentProcessorState::getSoftMask() const
{
return m_softMask;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setSoftMask(const PDFDictionary* softMask)
void PDFPageContentProcessorState::setSoftMask(const PDFDictionary* softMask)
{
if (m_softMask != softMask)
{
@ -3755,12 +3796,12 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setSoftMask(const PD
}
}
BlackPointCompensationMode PDFPageContentProcessor::PDFPageContentProcessorState::getBlackPointCompensationMode() const
BlackPointCompensationMode PDFPageContentProcessorState::getBlackPointCompensationMode() const
{
return m_blackPointCompensationMode;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setBlackPointCompensationMode(BlackPointCompensationMode blackPointCompensationMode)
void PDFPageContentProcessorState::setBlackPointCompensationMode(BlackPointCompensationMode blackPointCompensationMode)
{
if (m_blackPointCompensationMode != blackPointCompensationMode)
{
@ -3769,12 +3810,12 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setBlackPointCompens
}
}
PDFObject PDFPageContentProcessor::PDFPageContentProcessorState::getHalftone() const
PDFObject PDFPageContentProcessorState::getHalftone() const
{
return m_halftone;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setHalftone(const PDFObject& halftone)
void PDFPageContentProcessorState::setHalftone(const PDFObject& halftone)
{
if (m_halftone != halftone)
{
@ -3783,12 +3824,12 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setHalftone(const PD
}
}
QPointF PDFPageContentProcessor::PDFPageContentProcessorState::getHalftoneOrigin() const
QPointF PDFPageContentProcessorState::getHalftoneOrigin() const
{
return m_halftoneOrigin;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setHalftoneOrigin(const QPointF& halftoneOrigin)
void PDFPageContentProcessorState::setHalftoneOrigin(const QPointF& halftoneOrigin)
{
if (m_halftoneOrigin != halftoneOrigin)
{
@ -3797,12 +3838,12 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setHalftoneOrigin(co
}
}
PDFObject PDFPageContentProcessor::PDFPageContentProcessorState::getTransferFunction() const
PDFObject PDFPageContentProcessorState::getTransferFunction() const
{
return m_transferFunction;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTransferFunction(const PDFObject& transferFunction)
void PDFPageContentProcessorState::setTransferFunction(const PDFObject& transferFunction)
{
if (m_transferFunction != transferFunction)
{
@ -3811,12 +3852,12 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTransferFunction(
}
}
PDFObject PDFPageContentProcessor::PDFPageContentProcessorState::getUndercolorRemovalFunction() const
PDFObject PDFPageContentProcessorState::getUndercolorRemovalFunction() const
{
return m_undercolorRemovalFunction;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setUndercolorRemovalFunction(const PDFObject& undercolorRemovalFunction)
void PDFPageContentProcessorState::setUndercolorRemovalFunction(const PDFObject& undercolorRemovalFunction)
{
if (m_undercolorRemovalFunction != undercolorRemovalFunction)
{
@ -3825,12 +3866,12 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setUndercolorRemoval
}
}
PDFObject PDFPageContentProcessor::PDFPageContentProcessorState::getBlackGenerationFunction() const
PDFObject PDFPageContentProcessorState::getBlackGenerationFunction() const
{
return m_blackGenerationFunction;
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setBlackGenerationFunction(const PDFObject& blackGenerationFunction)
void PDFPageContentProcessorState::setBlackGenerationFunction(const PDFObject& blackGenerationFunction)
{
if (m_blackGenerationFunction != blackGenerationFunction)
{
@ -3839,7 +3880,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setBlackGenerationFu
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextMatrix(const QTransform& textMatrix)
void PDFPageContentProcessorState::setTextMatrix(const QTransform& textMatrix)
{
if (m_textMatrix != textMatrix)
{
@ -3848,7 +3889,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextMatrix(const
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextRise(PDFReal textRise)
void PDFPageContentProcessorState::setTextRise(PDFReal textRise)
{
if (m_textRise != textRise)
{
@ -3857,7 +3898,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextRise(PDFReal
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextRenderingMode(TextRenderingMode textRenderingMode)
void PDFPageContentProcessorState::setTextRenderingMode(TextRenderingMode textRenderingMode)
{
if (m_textRenderingMode != textRenderingMode)
{
@ -3866,7 +3907,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextRenderingMode
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextFont(const PDFFontPointer& textFont)
void PDFPageContentProcessorState::setTextFont(const PDFFontPointer& textFont)
{
if (m_textFont != textFont)
{
@ -3875,7 +3916,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextFont(const PD
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextHorizontalScaling(PDFReal textHorizontalScaling)
void PDFPageContentProcessorState::setTextHorizontalScaling(PDFReal textHorizontalScaling)
{
if (m_textHorizontalScaling != textHorizontalScaling)
{
@ -3884,7 +3925,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextHorizontalSca
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextWordSpacing(PDFReal textWordSpacing)
void PDFPageContentProcessorState::setTextWordSpacing(PDFReal textWordSpacing)
{
if (m_textWordSpacing != textWordSpacing)
{
@ -3893,7 +3934,7 @@ void PDFPageContentProcessor::PDFPageContentProcessorState::setTextWordSpacing(P
}
}
void PDFPageContentProcessor::PDFPageContentProcessorState::setTextCharacterSpacing(PDFReal textCharacterSpacing)
void PDFPageContentProcessorState::setTextCharacterSpacing(PDFReal textCharacterSpacing)
{
if (m_textCharacterSpacing != textCharacterSpacing)
{