Caret annotation graphics

This commit is contained in:
Jakub Melka
2020-04-05 13:56:12 +02:00
parent a3ce271349
commit 992e4b32f3
6 changed files with 617 additions and 282 deletions

View File

@@ -1911,4 +1911,31 @@ void PDFFreeTextAnnotation::draw(AnnotationDrawParameters& parameters) const
painter.drawText(QRectF(QPointF(0, 0), textRect.size()), getContents(), option);
}
void PDFCaretAnnotation::draw(AnnotationDrawParameters& parameters) const
{
QPainter& painter = *parameters.painter;
parameters.boundingRectangle = getRectangle();
QRectF caretRect = getCaretRectangle();
if (caretRect.isEmpty())
{
caretRect = getRectangle();
}
QPointF controlPoint(caretRect.center());
controlPoint.setY(caretRect.top());
QPointF topPoint = controlPoint;
topPoint.setY(caretRect.bottom());
QPainterPath path;
path.moveTo(caretRect.topLeft());
path.quadTo(controlPoint, topPoint);
path.quadTo(controlPoint, caretRect.topRight());
path.lineTo(caretRect.topLeft());
path.closeSubpath();
painter.fillPath(path, QBrush(getStrokeColor(), Qt::SolidPattern));
}
} // namespace pdf

View File

@@ -917,6 +917,7 @@ public:
};
virtual AnnotationType getType() const override { return AnnotationType::Caret; }
virtual void draw(AnnotationDrawParameters& parameters) const override;
const QRectF& getCaretRectangle() const { return m_caretRectangle; }
Symbol getSymbol() const { return m_symbol; }

View File

@@ -1100,6 +1100,71 @@ PDFObjectReference PDFDocumentBuilder::createActionURI(QString URL)
}
PDFObjectReference PDFDocumentBuilder::createAnnotationCaret(PDFObjectReference page,
QRectF rectangle,
PDFReal borderWidth,
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("Caret");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Rect");
objectBuilder << rectangle;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("F");
objectBuilder << 4;
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("Border");
objectBuilder << std::initializer_list<PDFReal>{ 0.0, 0.0, borderWidth };
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("C");
objectBuilder << WrapAnnotationColor(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.endDictionary();
PDFObjectReference annotationObject = addObject(objectBuilder.takeObject());
PDFObjectReference popupAnnotation = createAnnotationPopup(page, annotationObject, getPopupWindowRect(rectangle), false);
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Annots");
objectBuilder.beginArray();
objectBuilder << annotationObject;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject pageAnnots = objectBuilder.takeObject();
appendTo(page, pageAnnots);
updateAnnotationAppearanceStreams(annotationObject);
return annotationObject;
}
PDFObjectReference PDFDocumentBuilder::createAnnotationCircle(PDFObjectReference page,
QRectF rectangle,
PDFReal borderWidth,

View File

@@ -289,6 +289,25 @@ public:
PDFObjectReference createActionURI(QString URL);
/// Caret annotations are used to indicate, where text should be inserted (for example, if reviewer
/// reviews the document, and he wants to mark, that some text should be inserted, he uses this
/// annotation).
/// \param page Page to which is annotation added
/// \param rectangle Area in which is caret displayed
/// \param borderWidth Border width
/// \param color Caret color. If you do not want to have a border, then use invalid QColor.
/// \param title Title
/// \param subject Subject
/// \param contents Contents
PDFObjectReference createAnnotationCaret(PDFObjectReference page,
QRectF rectangle,
PDFReal borderWidth,
QColor color,
QString title,
QString subject,
QString contents);
/// Circle annotation displays ellipse (or circle). Circle border/fill color can be defined, along with
/// border width. Popup annotation can be attached to this annotation.
/// \param page Page to which is annotation added