Annotation settings functions

This commit is contained in:
Jakub Melka
2020-03-28 14:25:32 +01:00
parent f81d409d12
commit 8bce1bc1e5
6 changed files with 1062 additions and 48 deletions

View File

@@ -134,6 +134,8 @@ private:
std::vector<PDFReal> m_dashPattern;
};
using AnnotationBorderStyle = PDFAnnotationBorder::Style;
/// Annotation border effect
class PDFAnnotationBorderEffect
{

View File

@@ -64,6 +64,38 @@ void PDFObjectFactory::endDictionaryItem()
std::get<PDFDictionary>(dictionaryItem.object).addEntry(qMove(topItem.itemName), qMove(std::get<PDFObject>(topItem.object)));
}
PDFObjectFactory& PDFObjectFactory::operator<<(AnnotationBorderStyle style)
{
switch (style)
{
case AnnotationBorderStyle::Solid:
*this << WrapName("S");
break;
case AnnotationBorderStyle::Dashed:
*this << WrapName("D");
break;
case AnnotationBorderStyle::Beveled:
*this << WrapName("B");
break;
case AnnotationBorderStyle::Inset:
*this << WrapName("I");
break;
case AnnotationBorderStyle::Underline:
*this << WrapName("U");
break;
default:
Q_ASSERT(false);
break;
}
return *this;
}
PDFObjectFactory& PDFObjectFactory::operator<<(const QDateTime& dateTime)
{
addObject(PDFObject::createString(std::make_shared<PDFString>(PDFEncoding::converDateTimeToString(dateTime))));
@@ -1903,6 +1935,170 @@ PDFObject PDFDocumentBuilder::createTrailerDictionary(PDFObjectReference catalog
}
void PDFDocumentBuilder::setAnnotationBorder(PDFObjectReference annotation,
PDFReal hRadius,
PDFReal vRadius,
PDFReal width)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Border");
objectBuilder.beginArray();
objectBuilder << hRadius;
objectBuilder << vRadius;
objectBuilder << width;
objectBuilder.endArray();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setAnnotationBorderStyle(PDFObjectReference annotation,
AnnotationBorderStyle style,
PDFReal width)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("BS");
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("W");
objectBuilder << width;
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("S");
objectBuilder << style;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setAnnotationColor(PDFObjectReference annotation,
QColor color)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("C");
objectBuilder << WrapAnnotationColor(color);
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setAnnotationContents(PDFObjectReference annotation,
QString contents)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Contents");
objectBuilder << contents;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setAnnotationOpacity(PDFObjectReference annotation,
PDFReal opacity)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("CA");
objectBuilder << opacity;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setAnnotationOpenState(PDFObjectReference annotation,
bool isOpen)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Open");
objectBuilder << isOpen;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setAnnotationQuadPoints(PDFObjectReference annotation,
QPolygonF quadrilaterals)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("QuadPoints");
objectBuilder << quadrilaterals;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setAnnotationRichText(PDFObjectReference annotation,
QString richText)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("RC");
objectBuilder << richText;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setAnnotationSubject(PDFObjectReference annotation,
QString subject)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Subj");
objectBuilder << subject;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setAnnotationTitle(PDFObjectReference annotation,
QString title)
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("T");
objectBuilder << title;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject annotationObject = objectBuilder.takeObject();
mergeTo(annotation, annotationObject);
}
void PDFDocumentBuilder::setDocumentAuthor(QString author)
{
PDFObjectFactory objectBuilder;
@@ -2001,6 +2197,14 @@ void PDFDocumentBuilder::setDocumentTitle(QString title)
}
void PDFDocumentBuilder::setLanguage(QLocale locale)
{
PDFObjectFactory objectBuilder;
setLanguage(locale.name());
}
void PDFDocumentBuilder::setLanguage(QString language)
{
PDFObjectFactory objectBuilder;
@@ -2015,14 +2219,6 @@ void PDFDocumentBuilder::setLanguage(QString language)
}
void PDFDocumentBuilder::setLanguage(QLocale locale)
{
PDFObjectFactory objectBuilder;
setLanguage(locale.name());
}
void PDFDocumentBuilder::updateTrailerDictionary(PDFInteger objectCount)
{
PDFObjectFactory objectBuilder;

View File

@@ -107,6 +107,7 @@ public:
PDFObjectFactory& operator<<(AnnotationLineEnding lineEnding);
PDFObjectFactory& operator<<(const QPointF& point);
PDFObjectFactory& operator<<(const QDateTime& dateTime);
PDFObjectFactory& operator<<(AnnotationBorderStyle style);
/// Treat containers - write them as array
template<typename Container, typename ValueType = decltype(*std::begin(std::declval<Container>()))>
@@ -617,6 +618,84 @@ public:
PDFObject createTrailerDictionary(PDFObjectReference catalog);
/// Sets annotation border.
/// \param annotation Annotation
/// \param hRadius Horizontal corner radius
/// \param vRadius Vertical corner radius
/// \param width Line width
void setAnnotationBorder(PDFObjectReference annotation,
PDFReal hRadius,
PDFReal vRadius,
PDFReal width);
/// Sets annotation border style.
/// \param annotation Annotation
/// \param style Style
/// \param width Width
void setAnnotationBorderStyle(PDFObjectReference annotation,
AnnotationBorderStyle style,
PDFReal width);
/// Sets annotation color.
/// \param annotation Annotation
/// \param color Color
void setAnnotationColor(PDFObjectReference annotation,
QColor color);
/// Sets annotation contents.
/// \param annotation Annotation
/// \param contents Contents
void setAnnotationContents(PDFObjectReference annotation,
QString contents);
/// Sets constant opacity of annotation's graphics.
/// \param annotation Annotation
/// \param opacity Opacity (value must be in range from 0.0 to 1.0)
void setAnnotationOpacity(PDFObjectReference annotation,
PDFReal opacity);
/// Sets open state of the annotation.
/// \param annotation Annotation
/// \param isOpen Is annotation opened?
void setAnnotationOpenState(PDFObjectReference annotation,
bool isOpen);
/// Sets annotation quadrilaterals. Quadrilaterals are sequence of 4 points, where first two points are
/// on the upper side of quadrilateral, and the last two points are on the lower side of quadrilateral.
/// Quadrilaterals are represented as unclosed polygon with 4 * n vertices.
/// \param annotation Annotation
/// \param quadrilaterals Quadrilaterals
void setAnnotationQuadPoints(PDFObjectReference annotation,
QPolygonF quadrilaterals);
/// Sets annotation rich text contents. This function will work only on markup annotations.
/// \param annotation Annotation
/// \param richText Rich text contents
void setAnnotationRichText(PDFObjectReference annotation,
QString richText);
/// Sets annotation subject.
/// \param annotation Annotation
/// \param subject Subject
void setAnnotationSubject(PDFObjectReference annotation,
QString subject);
/// Sets annotation title.
/// \param annotation Annotation
/// \param title Title
void setAnnotationTitle(PDFObjectReference annotation,
QString title);
/// Set document author.
/// \param author Author
void setDocumentAuthor(QString author);
@@ -652,6 +731,11 @@ public:
void setDocumentTitle(QString title);
/// Set document language.
/// \param locale Locale, from which is language determined
void setLanguage(QLocale locale);
/// Set document language.
/// \param language Document language. It should be a language identifier, as defined in ISO 639
/// and ISO 3166. For example, "en-US", where first two letter means language code (en =
@@ -659,11 +743,6 @@ public:
void setLanguage(QString language);
/// Set document language.
/// \param locale Locale, from which is language determined
void setLanguage(QLocale locale);
/// This function is used to update trailer dictionary. Must be called each time the final document is
/// being built.
/// \param objectCount Number of objects (including empty ones)