Highlight annotations

This commit is contained in:
Jakub Melka 2020-03-27 19:29:21 +01:00
parent 23b8373f98
commit 77972bbad3
5 changed files with 2059 additions and 235 deletions

View File

@ -102,7 +102,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -160,6 +160,26 @@ void PDFExamplesGenerator::generateAnnotationsExample()
polygon.translate(0, -100); polygon.translate(0, -100);
builder.createAnnotationPolyline(page7, polygon, 2.0, Qt::green, Qt::yellow, "Title", "Subject", "Contents", pdf::AnnotationLineEnding::ClosedArrow, pdf::AnnotationLineEnding::Circle); builder.createAnnotationPolyline(page7, polygon, 2.0, Qt::green, Qt::yellow, "Title", "Subject", "Contents", pdf::AnnotationLineEnding::ClosedArrow, pdf::AnnotationLineEnding::Circle);
pdf::PDFObjectReference page8 = builder.appendPage(QRectF(0, 0, 400, 400));
builder.createAnnotationHighlight(page8, QRectF(50, 50, 50, 50), Qt::yellow, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.createAnnotationHighlight(page8, QRectF(50, 150, 50, 50), Qt::green);
builder.createAnnotationHighlight(page8, QRectF(50, 250, 50, 50), Qt::red);
pdf::PDFObjectReference page9 = builder.appendPage(QRectF(0, 0, 400, 400));
builder.createAnnotationUnderline(page9, QRectF(50, 50, 50, 50), Qt::yellow, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.createAnnotationUnderline(page9, QRectF(50, 150, 50, 50), Qt::green);
builder.createAnnotationUnderline(page9, QRectF(50, 250, 50, 50), Qt::red);
pdf::PDFObjectReference page10 = builder.appendPage(QRectF(0, 0, 400, 400));
builder.createAnnotationSquiggly(page10, QRectF(50, 50, 50, 50), Qt::yellow, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.createAnnotationSquiggly(page10, QRectF(50, 150, 50, 50), Qt::green);
builder.createAnnotationSquiggly(page10, QRectF(50, 250, 50, 50), Qt::red);
pdf::PDFObjectReference page11 = builder.appendPage(QRectF(0, 0, 400, 400));
builder.createAnnotationStrikeout(page11, QRectF(50, 50, 50, 50), Qt::yellow, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.createAnnotationStrikeout(page11, QRectF(50, 150, 50, 50), Qt::green);
builder.createAnnotationStrikeout(page11, QRectF(50, 250, 50, 50), Qt::red);
// Write result to a file // Write result to a file
pdf::PDFDocument document = builder.build(); pdf::PDFDocument document = builder.build();
pdf::PDFDocumentWriter writer(nullptr); pdf::PDFDocumentWriter writer(nullptr);

View File

@ -604,24 +604,14 @@ PDFObjectReference PDFDocumentBuilder::createAnnotationCircle(PDFObjectReference
objectBuilder.endDictionaryItem(); objectBuilder.endDictionaryItem();
objectBuilder.endDictionary(); objectBuilder.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject()); PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(rectangle), false);
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Popup");
objectBuilder << popupAnnotation;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject updateAnnotationPopup = objectBuilder.takeObject();
objectBuilder.beginDictionary(); objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots"); objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray(); objectBuilder.beginArray();
objectBuilder << annotationObject; objectBuilder << annotationObject;
objectBuilder << popupAnnotation;
objectBuilder.endArray(); objectBuilder.endArray();
objectBuilder.endDictionaryItem(); objectBuilder.endDictionaryItem();
objectBuilder.endDictionary(); objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject(); PDFObject pageAnnots = objectBuilder.takeObject();
mergeTo(annotationObject, updateAnnotationPopup);
appendTo(page, pageAnnots); appendTo(page, pageAnnots);
return annotationObject; return annotationObject;
} }
@ -771,6 +761,117 @@ PDFObjectReference PDFDocumentBuilder::createAnnotationFreeText(PDFObjectReferen
} }
PDFObjectReference PDFDocumentBuilder::createAnnotationHighlight(PDFObjectReference page,
QRectF rectangle,
QColor color,
QString title,
QString subject,
QString contents)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Annot");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subtype");
objectBuilder << WrapName("Highlight");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Rect");
objectBuilder << rectangle;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("P");
objectBuilder << page;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("M");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("CreationDate");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("C");
objectBuilder << color;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("T");
objectBuilder << title;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Contents");
objectBuilder << contents;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subj");
objectBuilder << subject;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("QuadPoints");
objectBuilder.beginArray();
objectBuilder << rectangle.bottomLeft();
objectBuilder << rectangle.bottomRight();
objectBuilder << rectangle.topLeft();
objectBuilder << rectangle.topRight();
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray();
objectBuilder << annotationObject;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject();
appendTo(page, pageAnnots);
return annotationObject;
}
PDFObjectReference PDFDocumentBuilder::createAnnotationHighlight(PDFObjectReference page,
QRectF rectangle,
QColor color)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Annot");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subtype");
objectBuilder << WrapName("Highlight");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Rect");
objectBuilder << rectangle;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("P");
objectBuilder << page;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("CreationDate");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("C");
objectBuilder << color;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("QuadPoints");
objectBuilder.beginArray();
objectBuilder << rectangle.bottomLeft();
objectBuilder << rectangle.bottomRight();
objectBuilder << rectangle.topLeft();
objectBuilder << rectangle.topRight();
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray();
objectBuilder << annotationObject;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject();
appendTo(page, pageAnnots);
return annotationObject;
}
PDFObjectReference PDFDocumentBuilder::createAnnotationLine(PDFObjectReference page, PDFObjectReference PDFDocumentBuilder::createAnnotationLine(PDFObjectReference page,
QRectF boundingRect, QRectF boundingRect,
QPointF startPoint, QPointF startPoint,
@ -844,22 +945,14 @@ PDFObjectReference PDFDocumentBuilder::createAnnotationLine(PDFObjectReference p
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject()); PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(boundingRect), false); PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(boundingRect), false);
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Popup");
objectBuilder << popupAnnotation;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject updateAnnotationPopup = objectBuilder.takeObject();
objectBuilder.beginDictionary(); objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots"); objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray(); objectBuilder.beginArray();
objectBuilder << annotationObject; objectBuilder << annotationObject;
objectBuilder << popupAnnotation;
objectBuilder.endArray(); objectBuilder.endArray();
objectBuilder.endDictionaryItem(); objectBuilder.endDictionaryItem();
objectBuilder.endDictionary(); objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject(); PDFObject pageAnnots = objectBuilder.takeObject();
mergeTo(annotationObject, updateAnnotationPopup);
appendTo(page, pageAnnots); appendTo(page, pageAnnots);
return annotationObject; return annotationObject;
} }
@ -958,22 +1051,14 @@ PDFObjectReference PDFDocumentBuilder::createAnnotationLine(PDFObjectReference p
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject()); PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(boundingRect), false); PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(boundingRect), false);
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Popup");
objectBuilder << popupAnnotation;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject updateAnnotationPopup = objectBuilder.takeObject();
objectBuilder.beginDictionary(); objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots"); objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray(); objectBuilder.beginArray();
objectBuilder << annotationObject; objectBuilder << annotationObject;
objectBuilder << popupAnnotation;
objectBuilder.endArray(); objectBuilder.endArray();
objectBuilder.endDictionaryItem(); objectBuilder.endDictionaryItem();
objectBuilder.endDictionary(); objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject(); PDFObject pageAnnots = objectBuilder.takeObject();
mergeTo(annotationObject, updateAnnotationPopup);
appendTo(page, pageAnnots); appendTo(page, pageAnnots);
return annotationObject; return annotationObject;
} }
@ -1089,22 +1174,14 @@ PDFObjectReference PDFDocumentBuilder::createAnnotationPolygon(PDFObjectReferenc
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject()); PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(polygon.boundingRect()), false); PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(polygon.boundingRect()), false);
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Popup");
objectBuilder << popupAnnotation;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject updateAnnotationPopup = objectBuilder.takeObject();
objectBuilder.beginDictionary(); objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots"); objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray(); objectBuilder.beginArray();
objectBuilder << annotationObject; objectBuilder << annotationObject;
objectBuilder << popupAnnotation;
objectBuilder.endArray(); objectBuilder.endArray();
objectBuilder.endDictionaryItem(); objectBuilder.endDictionaryItem();
objectBuilder.endDictionary(); objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject(); PDFObject pageAnnots = objectBuilder.takeObject();
mergeTo(annotationObject, updateAnnotationPopup);
appendTo(page, pageAnnots); appendTo(page, pageAnnots);
return annotationObject; return annotationObject;
} }
@ -1176,22 +1253,14 @@ PDFObjectReference PDFDocumentBuilder::createAnnotationPolyline(PDFObjectReferen
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject()); PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(polyline.boundingRect()), false); PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(polyline.boundingRect()), false);
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Popup");
objectBuilder << popupAnnotation;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject updateAnnotationPopup = objectBuilder.takeObject();
objectBuilder.beginDictionary(); objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots"); objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray(); objectBuilder.beginArray();
objectBuilder << annotationObject; objectBuilder << annotationObject;
objectBuilder << popupAnnotation;
objectBuilder.endArray(); objectBuilder.endArray();
objectBuilder.endDictionaryItem(); objectBuilder.endDictionaryItem();
objectBuilder.endDictionary(); objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject(); PDFObject pageAnnots = objectBuilder.takeObject();
mergeTo(annotationObject, updateAnnotationPopup);
appendTo(page, pageAnnots); appendTo(page, pageAnnots);
return annotationObject; return annotationObject;
} }
@ -1225,6 +1294,13 @@ PDFObjectReference PDFDocumentBuilder::createAnnotationPopup(PDFObjectReference
objectBuilder.endDictionaryItem(); objectBuilder.endDictionaryItem();
objectBuilder.endDictionary(); objectBuilder.endDictionary();
PDFObjectReference popupAnnotation = addObject(objectBuilder.takeObject()); PDFObjectReference popupAnnotation = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Popup");
objectBuilder << popupAnnotation;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject upgradedParentAnnotation = objectBuilder.takeObject();
mergeTo(parentAnnotation, upgradedParentAnnotation);
return popupAnnotation; return popupAnnotation;
} }
@ -1284,22 +1360,236 @@ PDFObjectReference PDFDocumentBuilder::createAnnotationSquare(PDFObjectReference
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject()); PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(rectangle), false); PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(rectangle), false);
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Popup");
objectBuilder << popupAnnotation;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject updateAnnotationPopup = objectBuilder.takeObject();
objectBuilder.beginDictionary(); objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots"); objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray(); objectBuilder.beginArray();
objectBuilder << annotationObject; objectBuilder << annotationObject;
objectBuilder << popupAnnotation;
objectBuilder.endArray(); objectBuilder.endArray();
objectBuilder.endDictionaryItem(); objectBuilder.endDictionaryItem();
objectBuilder.endDictionary(); objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject(); PDFObject pageAnnots = objectBuilder.takeObject();
mergeTo(annotationObject, updateAnnotationPopup); appendTo(page, pageAnnots);
return annotationObject;
}
PDFObjectReference PDFDocumentBuilder::createAnnotationSquiggly(PDFObjectReference page,
QRectF rectangle,
QColor color,
QString title,
QString subject,
QString contents)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Annot");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subtype");
objectBuilder << WrapName("Squiggly");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Rect");
objectBuilder << rectangle;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("P");
objectBuilder << page;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("M");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("CreationDate");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("C");
objectBuilder << color;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("T");
objectBuilder << title;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Contents");
objectBuilder << contents;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subj");
objectBuilder << subject;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("QuadPoints");
objectBuilder.beginArray();
objectBuilder << rectangle.bottomLeft();
objectBuilder << rectangle.bottomRight();
objectBuilder << rectangle.topLeft();
objectBuilder << rectangle.topRight();
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray();
objectBuilder << annotationObject;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject();
appendTo(page, pageAnnots);
return annotationObject;
}
PDFObjectReference PDFDocumentBuilder::createAnnotationSquiggly(PDFObjectReference page,
QRectF rectangle,
QColor color)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Annot");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subtype");
objectBuilder << WrapName("Squiggly");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Rect");
objectBuilder << rectangle;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("P");
objectBuilder << page;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("CreationDate");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("C");
objectBuilder << color;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("QuadPoints");
objectBuilder.beginArray();
objectBuilder << rectangle.bottomLeft();
objectBuilder << rectangle.bottomRight();
objectBuilder << rectangle.topLeft();
objectBuilder << rectangle.topRight();
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray();
objectBuilder << annotationObject;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject();
appendTo(page, pageAnnots);
return annotationObject;
}
PDFObjectReference PDFDocumentBuilder::createAnnotationStrikeout(PDFObjectReference page,
QRectF rectangle,
QColor color,
QString title,
QString subject,
QString contents)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Annot");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subtype");
objectBuilder << WrapName("StrikeOut");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Rect");
objectBuilder << rectangle;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("P");
objectBuilder << page;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("M");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("CreationDate");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("C");
objectBuilder << color;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("T");
objectBuilder << title;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Contents");
objectBuilder << contents;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subj");
objectBuilder << subject;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("QuadPoints");
objectBuilder.beginArray();
objectBuilder << rectangle.bottomLeft();
objectBuilder << rectangle.bottomRight();
objectBuilder << rectangle.topLeft();
objectBuilder << rectangle.topRight();
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray();
objectBuilder << annotationObject;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject();
appendTo(page, pageAnnots);
return annotationObject;
}
PDFObjectReference PDFDocumentBuilder::createAnnotationStrikeout(PDFObjectReference page,
QRectF rectangle,
QColor color)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Annot");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subtype");
objectBuilder << WrapName("StrikeOut");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Rect");
objectBuilder << rectangle;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("P");
objectBuilder << page;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("CreationDate");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("C");
objectBuilder << color;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("QuadPoints");
objectBuilder.beginArray();
objectBuilder << rectangle.bottomLeft();
objectBuilder << rectangle.bottomRight();
objectBuilder << rectangle.topLeft();
objectBuilder << rectangle.topRight();
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray();
objectBuilder << annotationObject;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject();
appendTo(page, pageAnnots); appendTo(page, pageAnnots);
return annotationObject; return annotationObject;
} }
@ -1377,6 +1667,117 @@ PDFObjectReference PDFDocumentBuilder::createAnnotationText(PDFObjectReference p
} }
PDFObjectReference PDFDocumentBuilder::createAnnotationUnderline(PDFObjectReference page,
QRectF rectangle,
QColor color,
QString title,
QString subject,
QString contents)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Annot");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subtype");
objectBuilder << WrapName("Underline");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Rect");
objectBuilder << rectangle;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("P");
objectBuilder << page;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("M");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("CreationDate");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("C");
objectBuilder << color;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("T");
objectBuilder << title;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Contents");
objectBuilder << contents;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subj");
objectBuilder << subject;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("QuadPoints");
objectBuilder.beginArray();
objectBuilder << rectangle.bottomLeft();
objectBuilder << rectangle.bottomRight();
objectBuilder << rectangle.topLeft();
objectBuilder << rectangle.topRight();
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray();
objectBuilder << annotationObject;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject();
appendTo(page, pageAnnots);
return annotationObject;
}
PDFObjectReference PDFDocumentBuilder::createAnnotationUnderline(PDFObjectReference page,
QRectF rectangle,
QColor color)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Annot");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Subtype");
objectBuilder << WrapName("Underline");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Rect");
objectBuilder << rectangle;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("P");
objectBuilder << page;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("CreationDate");
objectBuilder << WrapCurrentDateTime();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("C");
objectBuilder << color;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("QuadPoints");
objectBuilder.beginArray();
objectBuilder << rectangle.bottomLeft();
objectBuilder << rectangle.bottomRight();
objectBuilder << rectangle.topLeft();
objectBuilder << rectangle.topRight();
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray();
objectBuilder << annotationObject;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject();
appendTo(page, pageAnnots);
return annotationObject;
}
PDFObjectReference PDFDocumentBuilder::createCatalog() PDFObjectReference PDFDocumentBuilder::createCatalog()
{ {
PDFObjectFactory objectBuilder; PDFObjectFactory objectBuilder;

View File

@ -222,9 +222,8 @@ public:
PDFObjectReference createActionURI(QString URL); PDFObjectReference createActionURI(QString URL);
/// Circle annotation displays ellipse (or circle). When opened, they display pop-up window containing /// Circle annotation displays ellipse (or circle). Circle border/fill color can be defined, along with
/// the text of associated note (and window title). Circle border/fill color can be defined, along with /// border width. Popup annotation can be attached to this annotation.
/// border width.
/// \param page Page to which is annotation added /// \param page Page to which is annotation added
/// \param rectangle Area in which is circle/ellipse displayed /// \param rectangle Area in which is circle/ellipse displayed
/// \param borderWidth Width of the border line of circle/ellipse /// \param borderWidth Width of the border line of circle/ellipse
@ -292,6 +291,34 @@ public:
AnnotationLineEnding endLineType); AnnotationLineEnding endLineType);
/// Text markup annotation is used to highlight text. It is a markup annotation, so it can contain
/// window to be opened (and commented). This annotation is usually used to highlight text, but can
/// also highlight other things, such as images, or other graphics.
/// \param page Page to which is annotation added
/// \param rectangle Area in which is highlight displayed
/// \param color Color
/// \param title Title
/// \param subject Subject
/// \param contents Contents
PDFObjectReference createAnnotationHighlight(PDFObjectReference page,
QRectF rectangle,
QColor color,
QString title,
QString subject,
QString contents);
/// Text markup annotation is used to highlight text. It is a markup annotation, so it can contain
/// window to be opened (and commented). This annotation is usually used to highlight text, but can
/// also highlight other things, such as images, or other graphics.
/// \param page Page to which is annotation added
/// \param rectangle Area in which is highlight displayed
/// \param color Color
PDFObjectReference createAnnotationHighlight(PDFObjectReference page,
QRectF rectangle,
QColor color);
/// Line annotation represents straight line, or some more advanced graphics, such as dimension with /// Line annotation represents straight line, or some more advanced graphics, such as dimension with
/// text. Line annotations are markup annotations, so they can have popup window. Line endings can /// text. Line annotations are markup annotations, so they can have popup window. Line endings can
/// be specified. /// be specified.
@ -392,7 +419,8 @@ public:
/// Polygon annotation. When opened, they display pop-up window containing the text of associated /// Polygon annotation. When opened, they display pop-up window containing the text of associated
/// note (and window title). Polygon border/fill color can be defined, along with border width. /// note (and window title), if popup annotation is attached. Polygon border/fill color can be defined,
/// along with border width.
/// \param page Page to which is annotation added /// \param page Page to which is annotation added
/// \param polygon Polygon /// \param polygon Polygon
/// \param borderWidth Border line width /// \param borderWidth Border line width
@ -412,7 +440,8 @@ public:
/// Polyline annotation. When opened, they display pop-up window containing the text of associated /// Polyline annotation. When opened, they display pop-up window containing the text of associated
/// note (and window title). Polyline border/fill color can be defined, along with border width. /// note (and window title), if popup annotation is attached. Polyline border/fill color can be defined,
/// along with border width.
/// \param page Page to which is annotation added /// \param page Page to which is annotation added
/// \param polyline Polyline /// \param polyline Polyline
/// \param borderWidth Border line width /// \param borderWidth Border line width
@ -450,8 +479,8 @@ public:
/// Square annotation displays rectangle (or square). When opened, they display pop-up window /// Square annotation displays rectangle (or square). When opened, they display pop-up window
/// containing the text of associated note (and window title). Square border/fill color can be defined, /// containing the text of associated note (and window title), if popup annotation is attached. Square
/// along with border width. /// border/fill color can be defined, along with border width.
/// \param page Page to which is annotation added /// \param page Page to which is annotation added
/// \param rectangle Area in which is rectangle displayed /// \param rectangle Area in which is rectangle displayed
/// \param borderWidth Width of the border line of rectangle /// \param borderWidth Width of the border line of rectangle
@ -472,10 +501,63 @@ public:
QString contents); QString contents);
/// Text markup annotation is used to squiggly underline text. It is a markup annotation, so it can
/// contain window to be opened (and commented).
/// \param page Page to which is annotation added
/// \param rectangle Area in which is markup displayed
/// \param color Color
/// \param title Title
/// \param subject Subject
/// \param contents Contents
PDFObjectReference createAnnotationSquiggly(PDFObjectReference page,
QRectF rectangle,
QColor color,
QString title,
QString subject,
QString contents);
/// Text markup annotation is used to squiggly underline text. It is a markup annotation, so it can
/// contain window to be opened (and commented).
/// \param page Page to which is annotation added
/// \param rectangle Area in which is markup displayed
/// \param color Color
PDFObjectReference createAnnotationSquiggly(PDFObjectReference page,
QRectF rectangle,
QColor color);
/// Text markup annotation is used to strikeout text. It is a markup annotation, so it can contain
/// window to be opened (and commented).
/// \param page Page to which is annotation added
/// \param rectangle Area in which is markup displayed
/// \param color Color
/// \param title Title
/// \param subject Subject
/// \param contents Contents
PDFObjectReference createAnnotationStrikeout(PDFObjectReference page,
QRectF rectangle,
QColor color,
QString title,
QString subject,
QString contents);
/// Text markup annotation is used to strikeout text. It is a markup annotation, so it can contain
/// window to be opened (and commented).
/// \param page Page to which is annotation added
/// \param rectangle Area in which is markup displayed
/// \param color Color
PDFObjectReference createAnnotationStrikeout(PDFObjectReference page,
QRectF rectangle,
QColor color);
/// Creates text annotation. Text annotation is "sticky note" attached to a point in the PDF document. /// Creates text annotation. Text annotation is "sticky note" attached to a point in the PDF document.
/// When closed, it is displayed as icon, if opened, widget appears with attached text. Text annotations /// When closed, it is displayed as icon, if opened, widget appears with attached text. Text annotations
/// do not scale or rotate, they appear independent of zoom/rotate. So, they behave as if flags /// do not scale or rotate, they appear independent of zoom/rotate. So, they behave as if flags
/// NoZoom or NoRotate to the annotations are being set. /// NoZoom or NoRotate to the annotations are being set. Popup annotation is automatically created
/// for this annotation.
/// \param page Page to which is annotation added /// \param page Page to which is annotation added
/// \param rectangle Area in which is icon displayed /// \param rectangle Area in which is icon displayed
/// \param iconType Icon type /// \param iconType Icon type
@ -492,6 +574,32 @@ public:
bool open); bool open);
/// Text markup annotation is used to underline text. It is a markup annotation, so it can contain
/// window to be opened (and commented).
/// \param page Page to which is annotation added
/// \param rectangle Area in which is markup displayed
/// \param color Color
/// \param title Title
/// \param subject Subject
/// \param contents Contents
PDFObjectReference createAnnotationUnderline(PDFObjectReference page,
QRectF rectangle,
QColor color,
QString title,
QString subject,
QString contents);
/// Text markup annotation is used to underline text. It is a markup annotation, so it can contain
/// window to be opened (and commented).
/// \param page Page to which is annotation added
/// \param rectangle Area in which is markup displayed
/// \param color Color
PDFObjectReference createAnnotationUnderline(PDFObjectReference page,
QRectF rectangle,
QColor color);
/// Creates empty catalog. This function is used, when a new document is being created. Do not call /// Creates empty catalog. This function is used, when a new document is being created. Do not call
/// this function manually. /// this function manually.
PDFObjectReference createCatalog(); PDFObjectReference createCatalog();

File diff suppressed because it is too large Load Diff