mirror of https://github.com/JakubMelka/PDF4QT.git
Redact bugfixing
This commit is contained in:
parent
59721d7de8
commit
6f0b72ba3b
|
@ -160,7 +160,8 @@ public:
|
||||||
_AnnotationBorderStyle,
|
_AnnotationBorderStyle,
|
||||||
_FileAttachmentIcon,
|
_FileAttachmentIcon,
|
||||||
_Stamp,
|
_Stamp,
|
||||||
_PDFDestination
|
_PDFDestination,
|
||||||
|
_PageRotation
|
||||||
};
|
};
|
||||||
Q_ENUM(DataType)
|
Q_ENUM(DataType)
|
||||||
|
|
||||||
|
|
|
@ -1790,11 +1790,17 @@ void PDFWidgetAnnotationManager::mousePressEvent(QWidget* widget, QMouseEvent* e
|
||||||
if (m_editableAnnotation.isValid())
|
if (m_editableAnnotation.isValid())
|
||||||
{
|
{
|
||||||
QMenu menu(tr("Annotation"), widget);
|
QMenu menu(tr("Annotation"), widget);
|
||||||
|
QAction* showPopupAction = menu.addAction(tr("Show Popup Window"));
|
||||||
|
QAction* copyAction = menu.addAction(tr("Copy to Multiple Pages"));
|
||||||
QAction* editAction = menu.addAction(tr("Edit"));
|
QAction* editAction = menu.addAction(tr("Edit"));
|
||||||
QAction* deleteAction = menu.addAction(tr("Delete"));
|
QAction* deleteAction = menu.addAction(tr("Delete"));
|
||||||
|
connect(showPopupAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onShowPopupAnnotation);
|
||||||
|
connect(copyAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onCopyAnnotation);
|
||||||
connect(editAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onEditAnnotation);
|
connect(editAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onEditAnnotation);
|
||||||
connect(deleteAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onDeleteAnnotation);
|
connect(deleteAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onDeleteAnnotation);
|
||||||
menu.exec(widget->mapToGlobal(event->pos()));
|
|
||||||
|
m_editableAnnotationGlobalPosition = widget->mapToGlobal(event->pos());
|
||||||
|
menu.exec(m_editableAnnotationGlobalPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1977,6 +1983,36 @@ void PDFWidgetAnnotationManager::updateFromMouseEvent(QMouseEvent* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFWidgetAnnotationManager::onShowPopupAnnotation()
|
||||||
|
{
|
||||||
|
PDFWidgetSnapshot snapshot = m_proxy->getSnapshot();
|
||||||
|
for (const PDFWidgetSnapshot::SnapshotItem& snapshotItem : snapshot.items)
|
||||||
|
{
|
||||||
|
PageAnnotations& pageAnnotations = getPageAnnotations(snapshotItem.pageIndex);
|
||||||
|
for (PageAnnotation& pageAnnotation : pageAnnotations.annotations)
|
||||||
|
{
|
||||||
|
if (pageAnnotation.annotation->isReplyTo())
|
||||||
|
{
|
||||||
|
// Annotation is reply to another annotation, do not interact with it
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageAnnotation.annotation->getSelfReference() == m_editableAnnotation)
|
||||||
|
{
|
||||||
|
QDialog* dialog = createDialogForMarkupAnnotations(m_proxy->getWidget(), pageAnnotation, pageAnnotations);
|
||||||
|
dialog->move(m_editableAnnotationGlobalPosition);
|
||||||
|
dialog->exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFWidgetAnnotationManager::onCopyAnnotation()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void PDFWidgetAnnotationManager::onEditAnnotation()
|
void PDFWidgetAnnotationManager::onEditAnnotation()
|
||||||
{
|
{
|
||||||
PDFEditObjectDialog dialog(EditObjectType::Annotation, m_proxy->getWidget());
|
PDFEditObjectDialog dialog(EditObjectType::Annotation, m_proxy->getWidget());
|
||||||
|
|
|
@ -1661,6 +1661,8 @@ signals:
|
||||||
private:
|
private:
|
||||||
void updateFromMouseEvent(QMouseEvent* event);
|
void updateFromMouseEvent(QMouseEvent* event);
|
||||||
|
|
||||||
|
void onShowPopupAnnotation();
|
||||||
|
void onCopyAnnotation();
|
||||||
void onEditAnnotation();
|
void onEditAnnotation();
|
||||||
void onDeleteAnnotation();
|
void onDeleteAnnotation();
|
||||||
|
|
||||||
|
@ -1685,6 +1687,7 @@ private:
|
||||||
PDFDrawWidgetProxy* m_proxy;
|
PDFDrawWidgetProxy* m_proxy;
|
||||||
QString m_tooltip;
|
QString m_tooltip;
|
||||||
std::optional<QCursor> m_cursor;
|
std::optional<QCursor> m_cursor;
|
||||||
|
QPoint m_editableAnnotationGlobalPosition; ///< Position, where action on annotation was executed
|
||||||
PDFObjectReference m_editableAnnotation; ///< Annotation to be edited or deleted
|
PDFObjectReference m_editableAnnotation; ///< Annotation to be edited or deleted
|
||||||
PDFObjectReference m_editableAnnotationPage; ///< Page of annotation above
|
PDFObjectReference m_editableAnnotationPage; ///< Page of annotation above
|
||||||
};
|
};
|
||||||
|
|
|
@ -462,6 +462,30 @@ PDFObjectFactory& PDFObjectFactory::operator<<(TextAnnotationIcon icon)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PDFObjectFactory& PDFObjectFactory::operator<<(PageRotation pageRotation)
|
||||||
|
{
|
||||||
|
switch (pageRotation)
|
||||||
|
{
|
||||||
|
case pdf::PageRotation::None:
|
||||||
|
*this << PDFInteger(0);
|
||||||
|
break;
|
||||||
|
case pdf::PageRotation::Rotate90:
|
||||||
|
*this << PDFInteger(90);
|
||||||
|
break;
|
||||||
|
case pdf::PageRotation::Rotate180:
|
||||||
|
*this << PDFInteger(180);
|
||||||
|
break;
|
||||||
|
case pdf::PageRotation::Rotate270:
|
||||||
|
*this << PDFInteger(270);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
PDFObjectFactory& PDFObjectFactory::operator<<(WrapEmptyArray)
|
PDFObjectFactory& PDFObjectFactory::operator<<(WrapEmptyArray)
|
||||||
{
|
{
|
||||||
beginArray();
|
beginArray();
|
||||||
|
@ -4788,6 +4812,20 @@ void PDFDocumentBuilder::setPageMediaBox(PDFObjectReference page,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PDFDocumentBuilder::setPageRotation(PDFObjectReference page,
|
||||||
|
PageRotation rotation)
|
||||||
|
{
|
||||||
|
PDFObjectFactory objectBuilder;
|
||||||
|
|
||||||
|
objectBuilder.beginDictionary();
|
||||||
|
objectBuilder.beginDictionaryItem("Rotate");
|
||||||
|
objectBuilder << rotation;
|
||||||
|
objectBuilder.endDictionaryItem();
|
||||||
|
objectBuilder.endDictionary();
|
||||||
|
PDFObject updatedPageObject = objectBuilder.takeObject();
|
||||||
|
mergeTo(page, updatedPageObject);
|
||||||
|
}
|
||||||
|
|
||||||
void PDFDocumentBuilder::setPageTrimBox(PDFObjectReference page,
|
void PDFDocumentBuilder::setPageTrimBox(PDFObjectReference page,
|
||||||
QRectF box)
|
QRectF box)
|
||||||
{
|
{
|
||||||
|
|
|
@ -118,6 +118,7 @@ public:
|
||||||
PDFObjectFactory& operator<<(Stamp stamp);
|
PDFObjectFactory& operator<<(Stamp stamp);
|
||||||
PDFObjectFactory& operator<<(FileAttachmentIcon icon);
|
PDFObjectFactory& operator<<(FileAttachmentIcon icon);
|
||||||
PDFObjectFactory& operator<<(const PDFDestination& destination);
|
PDFObjectFactory& operator<<(const PDFDestination& destination);
|
||||||
|
PDFObjectFactory& operator<<(PageRotation pageRotation);
|
||||||
|
|
||||||
/// Treat containers - write them as array
|
/// Treat containers - write them as array
|
||||||
template<typename Container, typename ValueType = decltype(*std::begin(std::declval<Container>()))>
|
template<typename Container, typename ValueType = decltype(*std::begin(std::declval<Container>()))>
|
||||||
|
@ -1421,6 +1422,13 @@ public:
|
||||||
QRectF box);
|
QRectF box);
|
||||||
|
|
||||||
|
|
||||||
|
/// Set page's rotation.
|
||||||
|
/// \param page Page
|
||||||
|
/// \param rotation Rotation
|
||||||
|
void setPageRotation(PDFObjectReference page,
|
||||||
|
PageRotation rotation);
|
||||||
|
|
||||||
|
|
||||||
/// Sets trim box to the page. Trim box is physical region, of the printed page after trimming.
|
/// Sets trim box to the page. Trim box is physical region, of the printed page after trimming.
|
||||||
/// \param page Page
|
/// \param page Page
|
||||||
/// \param box Box
|
/// \param box Box
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "pdfredact.h"
|
#include "pdfredact.h"
|
||||||
#include "pdfpainter.h"
|
#include "pdfpainter.h"
|
||||||
#include "pdfdocumentbuilder.h"
|
#include "pdfdocumentbuilder.h"
|
||||||
|
#include "pdfoptimizer.h"
|
||||||
|
|
||||||
namespace pdf
|
namespace pdf
|
||||||
{
|
{
|
||||||
|
@ -75,8 +76,8 @@ PDFDocument PDFRedact::perform(Options options)
|
||||||
{
|
{
|
||||||
builder.setPageArtBox(newPageReference, page->getArtBox());
|
builder.setPageArtBox(newPageReference, page->getArtBox());
|
||||||
}
|
}
|
||||||
|
builder.setPageRotation(newPageReference, page->getPageRotation());
|
||||||
|
|
||||||
// TODO: Nastavit natoceni stranky
|
|
||||||
// TODO: Popisek redakce anotace, Overlay text
|
// TODO: Popisek redakce anotace, Overlay text
|
||||||
// TODO: Redact searched text
|
// TODO: Redact searched text
|
||||||
// TODO: Duplikace redakce na vice stranek
|
// TODO: Duplikace redakce na vice stranek
|
||||||
|
@ -133,7 +134,11 @@ PDFDocument PDFRedact::perform(Options options)
|
||||||
builder.setOutline(m_document->getCatalog()->getOutlineRootPtr().data());
|
builder.setOutline(m_document->getCatalog()->getOutlineRootPtr().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
PDFDocument redactedDocument = builder.build();
|
||||||
|
PDFOptimizer optimizer(PDFOptimizer::All, nullptr);
|
||||||
|
optimizer.setDocument(&redactedDocument);
|
||||||
|
optimizer.optimize();
|
||||||
|
return optimizer.takeOptimizedDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "pdfdocumentwriter.h"
|
#include "pdfdocumentwriter.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
namespace pdfplugin
|
namespace pdfplugin
|
||||||
{
|
{
|
||||||
|
@ -148,7 +149,7 @@ void RedactPlugin::onCreateRedactedDocumentTriggered()
|
||||||
pdf::PDFOperationResult result = writer.write(dialog.getFileName(), &redactedDocument, false);
|
pdf::PDFOperationResult result = writer.write(dialog.getFileName(), &redactedDocument, false);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
|
QMessageBox::critical(m_widget, tr("Error"), result.getErrorMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11189,6 +11189,70 @@ return rootNodeReference;</property>
|
||||||
<property name="functionDescription">Sets media box to the page. The media box defines size of physical medium, onto which the page is to be printed. </property>
|
<property name="functionDescription">Sets media box to the page. The media box defines size of physical medium, onto which the page is to be printed. </property>
|
||||||
<property name="returnType">_void</property>
|
<property name="returnType">_void</property>
|
||||||
</QObject>
|
</QObject>
|
||||||
|
<QObject class="codegen::GeneratedFunction">
|
||||||
|
<property name="objectName"></property>
|
||||||
|
<property name="items">
|
||||||
|
<QObject class="codegen::GeneratedAction">
|
||||||
|
<property name="objectName"></property>
|
||||||
|
<property name="items">
|
||||||
|
<QObject class="codegen::GeneratedParameter">
|
||||||
|
<property name="objectName"></property>
|
||||||
|
<property name="items"/>
|
||||||
|
<property name="parameterName">page</property>
|
||||||
|
<property name="parameterType">_PDFObjectReference</property>
|
||||||
|
<property name="parameterDescription">Page</property>
|
||||||
|
</QObject>
|
||||||
|
<QObject class="codegen::GeneratedParameter">
|
||||||
|
<property name="objectName"></property>
|
||||||
|
<property name="items"/>
|
||||||
|
<property name="parameterName">rotation</property>
|
||||||
|
<property name="parameterType">_PageRotation</property>
|
||||||
|
<property name="parameterDescription">Rotation</property>
|
||||||
|
</QObject>
|
||||||
|
</property>
|
||||||
|
<property name="actionType">Parameters</property>
|
||||||
|
<property name="variableName"></property>
|
||||||
|
<property name="variableType">_void</property>
|
||||||
|
<property name="code"></property>
|
||||||
|
</QObject>
|
||||||
|
<QObject class="codegen::GeneratedAction">
|
||||||
|
<property name="objectName"></property>
|
||||||
|
<property name="items">
|
||||||
|
<QObject class="codegen::GeneratedPDFObject">
|
||||||
|
<property name="objectName"></property>
|
||||||
|
<property name="items">
|
||||||
|
<QObject class="codegen::GeneratedPDFObject">
|
||||||
|
<property name="objectName"></property>
|
||||||
|
<property name="items"/>
|
||||||
|
<property name="dictionaryItemName">Rotate</property>
|
||||||
|
<property name="objectType">DictionaryItemSimple</property>
|
||||||
|
<property name="value">rotation</property>
|
||||||
|
</QObject>
|
||||||
|
</property>
|
||||||
|
<property name="dictionaryItemName"></property>
|
||||||
|
<property name="objectType">Dictionary</property>
|
||||||
|
<property name="value"></property>
|
||||||
|
</QObject>
|
||||||
|
</property>
|
||||||
|
<property name="actionType">CreateObject</property>
|
||||||
|
<property name="variableName">updatedPageObject</property>
|
||||||
|
<property name="variableType">_PDFObject</property>
|
||||||
|
<property name="code"></property>
|
||||||
|
</QObject>
|
||||||
|
<QObject class="codegen::GeneratedAction">
|
||||||
|
<property name="objectName"></property>
|
||||||
|
<property name="items"/>
|
||||||
|
<property name="actionType">Code</property>
|
||||||
|
<property name="variableName"></property>
|
||||||
|
<property name="variableType">_void</property>
|
||||||
|
<property name="code">mergeTo(page, updatedPageObject);</property>
|
||||||
|
</QObject>
|
||||||
|
</property>
|
||||||
|
<property name="functionType">Structure</property>
|
||||||
|
<property name="functionName">setPageRotation</property>
|
||||||
|
<property name="functionDescription">Set page's rotation.</property>
|
||||||
|
<property name="returnType">_void</property>
|
||||||
|
</QObject>
|
||||||
<QObject class="codegen::GeneratedFunction">
|
<QObject class="codegen::GeneratedFunction">
|
||||||
<property name="objectName"></property>
|
<property name="objectName"></property>
|
||||||
<property name="items">
|
<property name="items">
|
||||||
|
|
Loading…
Reference in New Issue