Redact bugfixing

This commit is contained in:
Jakub Melka
2020-12-30 15:45:24 +01:00
parent 59721d7de8
commit 6f0b72ba3b
8 changed files with 161 additions and 5 deletions

View File

@@ -1790,11 +1790,17 @@ void PDFWidgetAnnotationManager::mousePressEvent(QWidget* widget, QMouseEvent* e
if (m_editableAnnotation.isValid())
{
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* 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(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()
{
PDFEditObjectDialog dialog(EditObjectType::Annotation, m_proxy->getWidget());

View File

@@ -1661,6 +1661,8 @@ signals:
private:
void updateFromMouseEvent(QMouseEvent* event);
void onShowPopupAnnotation();
void onCopyAnnotation();
void onEditAnnotation();
void onDeleteAnnotation();
@@ -1685,6 +1687,7 @@ private:
PDFDrawWidgetProxy* m_proxy;
QString m_tooltip;
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_editableAnnotationPage; ///< Page of annotation above
};

View File

@@ -462,6 +462,30 @@ PDFObjectFactory& PDFObjectFactory::operator<<(TextAnnotationIcon icon)
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)
{
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,
QRectF box)
{

View File

@@ -118,6 +118,7 @@ public:
PDFObjectFactory& operator<<(Stamp stamp);
PDFObjectFactory& operator<<(FileAttachmentIcon icon);
PDFObjectFactory& operator<<(const PDFDestination& destination);
PDFObjectFactory& operator<<(PageRotation pageRotation);
/// Treat containers - write them as array
template<typename Container, typename ValueType = decltype(*std::begin(std::declval<Container>()))>
@@ -1421,6 +1422,13 @@ public:
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.
/// \param page Page
/// \param box Box

View File

@@ -18,6 +18,7 @@
#include "pdfredact.h"
#include "pdfpainter.h"
#include "pdfdocumentbuilder.h"
#include "pdfoptimizer.h"
namespace pdf
{
@@ -75,8 +76,8 @@ PDFDocument PDFRedact::perform(Options options)
{
builder.setPageArtBox(newPageReference, page->getArtBox());
}
builder.setPageRotation(newPageReference, page->getPageRotation());
// TODO: Nastavit natoceni stranky
// TODO: Popisek redakce anotace, Overlay text
// TODO: Redact searched text
// TODO: Duplikace redakce na vice stranek
@@ -133,7 +134,11 @@ PDFDocument PDFRedact::perform(Options options)
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();
}