diff --git a/PdfExampleGenerator/PdfExampleGenerator.pro b/PdfExampleGenerator/PdfExampleGenerator.pro
index bc1d2b5..cd710f3 100644
--- a/PdfExampleGenerator/PdfExampleGenerator.pro
+++ b/PdfExampleGenerator/PdfExampleGenerator.pro
@@ -1,4 +1,4 @@
-QT += gui
+QT += gui widgets
CONFIG += c++11 console
CONFIG -= app_bundle
diff --git a/PdfExampleGenerator/main.cpp b/PdfExampleGenerator/main.cpp
index 13fa186..d227e93 100644
--- a/PdfExampleGenerator/main.cpp
+++ b/PdfExampleGenerator/main.cpp
@@ -15,12 +15,12 @@
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see .
-#include
+#include
#include "pdfexamplesgenerator.h"
int main(int argc, char *argv[])
{
- QCoreApplication a(argc, argv);
+ QApplication a(argc, argv);
PDFExamplesGenerator::generateAnnotationsExample();
}
diff --git a/PdfExampleGenerator/pdfexamplesgenerator.cpp b/PdfExampleGenerator/pdfexamplesgenerator.cpp
index c95a4db..f06e1e6 100644
--- a/PdfExampleGenerator/pdfexamplesgenerator.cpp
+++ b/PdfExampleGenerator/pdfexamplesgenerator.cpp
@@ -160,36 +160,42 @@ void PDFExamplesGenerator::generateAnnotationsExample()
pdf::PDFObjectReference annotation = builder.createAnnotationSquare(page5, QRectF(50, 50, 50, 50), 3.0, Qt::green, Qt::red, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.setAnnotationBorderStyle(annotation, pdf::PDFAnnotationBorder::Style::Solid, 2.718);
builder.setAnnotationColor(annotation, Qt::black);
+ builder.updateAnnotationAppearanceStreams(annotation);
}
{
pdf::PDFObjectReference annotation = builder.createAnnotationSquare(page5, QRectF(50, 150, 50, 50), 3.0, Qt::green, Qt::red, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.setAnnotationBorderStyle(annotation, pdf::PDFAnnotationBorder::Style::Underline, 2.718);
builder.setAnnotationColor(annotation, Qt::black);
+ builder.updateAnnotationAppearanceStreams(annotation);
}
{
pdf::PDFObjectReference annotation = builder.createAnnotationSquare(page5, QRectF(50, 250, 50, 50), 3.0, Qt::green, Qt::red, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.setAnnotationBorderStyle(annotation, pdf::PDFAnnotationBorder::Style::Inset, 2.718);
builder.setAnnotationColor(annotation, Qt::black);
+ builder.updateAnnotationAppearanceStreams(annotation);
}
{
pdf::PDFObjectReference annotation = builder.createAnnotationSquare(page5, QRectF(150, 50, 50, 50), 3.0, Qt::green, Qt::red, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.setAnnotationBorderStyle(annotation, pdf::PDFAnnotationBorder::Style::Beveled, 2.718);
builder.setAnnotationColor(annotation, Qt::black);
+ builder.updateAnnotationAppearanceStreams(annotation);
}
{
pdf::PDFObjectReference annotation = builder.createAnnotationSquare(page5, QRectF(150, 150, 50, 50), 3.0, Qt::green, Qt::red, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.setAnnotationBorderStyle(annotation, pdf::PDFAnnotationBorder::Style::Dashed, 2.718);
builder.setAnnotationColor(annotation, Qt::black);
+ builder.updateAnnotationAppearanceStreams(annotation);
}
{
pdf::PDFObjectReference annotation = builder.createAnnotationSquare(page5, QRectF(150, 250, 50, 50), 3.0, Qt::green, Qt::red, "Title1", "Subject1", "Contents - green filling, red boundary");
builder.setAnnotationBorder(annotation, 5.0, 3.0, 2.0);
builder.setAnnotationColor(annotation, Qt::black);
+ builder.updateAnnotationAppearanceStreams(annotation);
}
}
diff --git a/PdfForQtLib/sources/pdfannotation.cpp b/PdfForQtLib/sources/pdfannotation.cpp
index 3caf81f..9eaa82a 100644
--- a/PdfForQtLib/sources/pdfannotation.cpp
+++ b/PdfForQtLib/sources/pdfannotation.cpp
@@ -24,6 +24,8 @@
#include "pdfwidgetutils.h"
#include "pdfpagecontentprocessor.h"
+#include
+
namespace pdf
{
@@ -1079,7 +1081,11 @@ void PDFSimpleGeometryAnnotation::draw(AnnotationDrawParameters& parameters) con
case AnnotationType::Circle:
{
- painter.drawEllipse(getRectangle());
+ const PDFAnnotationBorder& border = getBorder();
+ const PDFReal width = border.getWidth();
+ QRectF rectangle = getRectangle();
+ rectangle.adjust(width, width, -width, -width);
+ painter.drawEllipse(rectangle);
break;
}
@@ -1121,4 +1127,73 @@ QColor PDFMarkupAnnotation::getFillColor() const
return color;
}
+void PDFTextAnnotation::draw(AnnotationDrawParameters& parameters) const
+{
+ const PDFReal opacity = getOpacity();
+ QColor strokeColor = QColor::fromRgbF(0.0, 0.0, 0.0, opacity);
+ QColor fillColor = QColor::fromRgbF(1.0, 1.0, 0.0, opacity);
+
+ constexpr const PDFReal rectSize = 32.0;
+ constexpr const PDFReal penWidth = 2.0;
+
+ QPainter& painter = *parameters.painter;
+ QRectF rectangle = getRectangle();
+ rectangle.setSize(QSizeF(rectSize, rectSize));
+
+ QPen pen(strokeColor);
+ pen.setWidthF(penWidth);
+ painter.setPen(pen);
+
+ painter.setBrush(QBrush(fillColor, Qt::SolidPattern));
+
+ QRectF ellipseRectangle = rectangle;
+ ellipseRectangle.adjust(penWidth, penWidth, -penWidth, -penWidth);
+
+ // Draw the ellipse
+ painter.drawEllipse(ellipseRectangle);
+
+ QFont font = QApplication::font();
+ font.setPixelSize(16.0);
+
+ QString text = "?";
+ if (m_iconName == "Comment")
+ {
+ text = QString::fromUtf16(u"\U0001F4AC");
+ }
+ else if (m_iconName == "Help")
+ {
+ text = "?";
+ }
+ else if (m_iconName == "Insert")
+ {
+ text = QString::fromUtf16(u"\u2380");
+ }
+ else if (m_iconName == "Key")
+ {
+ text = QString::fromUtf16(u"\U0001F511");
+ }
+ else if (m_iconName == "NewParagraph")
+ {
+ text = QString::fromUtf16(u"\u2606");
+ }
+ else if (m_iconName == "Note")
+ {
+ text = QString::fromUtf16(u"\u266A");
+ }
+ else if (m_iconName == "Paragraph")
+ {
+ text = QString::fromUtf16(u"\u00B6");
+ }
+
+ QPainterPath textPath;
+ textPath.addText(0.0, 0.0, font, text);
+ textPath = QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0).map(textPath);
+ QRectF textBoundingRect = textPath.boundingRect();
+ QPointF offset = rectangle.center() - textBoundingRect.center();
+ textPath.translate(offset);
+ painter.fillPath(textPath, QBrush(strokeColor, Qt::SolidPattern));
+
+ parameters.boundingRectangle = rectangle;
+}
+
} // namespace pdf
diff --git a/PdfForQtLib/sources/pdfannotation.h b/PdfForQtLib/sources/pdfannotation.h
index 8c4a5f8..37fc787 100644
--- a/PdfForQtLib/sources/pdfannotation.h
+++ b/PdfForQtLib/sources/pdfannotation.h
@@ -580,6 +580,7 @@ public:
inline explicit PDFTextAnnotation() = default;
virtual AnnotationType getType() const override { return AnnotationType::Text; }
+ virtual void draw(AnnotationDrawParameters& parameters) const override;
bool isOpen() const { return m_open; }
const QByteArray& getIconName() const { return m_iconName; }