From 8966b715b6a8a8d8160b1b34b7ceb55e00a7281e Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 21 Aug 2020 16:22:37 +0200 Subject: [PATCH] poppler: Convert Line annotations via C++ Instead of via the magic XML cycle of Poppler::AnnotationUtils::storeAnnotation + Okular::AnnotationUtils::createAnnotation --- generators/poppler/annots.cpp | 79 ++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/generators/poppler/annots.cpp b/generators/poppler/annots.cpp index 00dfaea1a..0be9a32fc 100644 --- a/generators/poppler/annots.cpp +++ b/generators/poppler/annots.cpp @@ -364,6 +364,54 @@ static Okular::TextAnnotation::InplaceIntent popplerToOkular(Poppler::TextAnnota return Okular::TextAnnotation::Unknown; } +static Okular::LineAnnotation::TermStyle popplerToOkular(Poppler::LineAnnotation::TermStyle pts) +{ + switch (pts) { + case Poppler::LineAnnotation::Square: + return Okular::LineAnnotation::Square; + case Poppler::LineAnnotation::Circle: + return Okular::LineAnnotation::Circle; + case Poppler::LineAnnotation::Diamond: + return Okular::LineAnnotation::Diamond; + case Poppler::LineAnnotation::OpenArrow: + return Okular::LineAnnotation::OpenArrow; + case Poppler::LineAnnotation::ClosedArrow: + return Okular::LineAnnotation::ClosedArrow; + case Poppler::LineAnnotation::None: + return Okular::LineAnnotation::None; + case Poppler::LineAnnotation::Butt: + return Okular::LineAnnotation::Butt; + case Poppler::LineAnnotation::ROpenArrow: + return Okular::LineAnnotation::ROpenArrow; + case Poppler::LineAnnotation::RClosedArrow: + return Okular::LineAnnotation::RClosedArrow; + case Poppler::LineAnnotation::Slash: + return Okular::LineAnnotation::Slash; + default: + qWarning() << Q_FUNC_INFO << "unknown value" << pts; + } + + return Okular::LineAnnotation::None; +} + +static Okular::LineAnnotation::LineIntent popplerToOkular(Poppler::LineAnnotation::LineIntent pli) +{ + switch (pli) { + case Poppler::LineAnnotation::Unknown: + return Okular::LineAnnotation::Unknown; + case Poppler::LineAnnotation::Arrow: + return Okular::LineAnnotation::Arrow; + case Poppler::LineAnnotation::Dimension: + return Okular::LineAnnotation::Dimension; + case Poppler::LineAnnotation::PolygonCloud: + return Okular::LineAnnotation::PolygonCloud; + default: + qWarning() << Q_FUNC_INFO << "unknown value" << pli; + } + + return Okular::LineAnnotation::Unknown; +} + static Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::TextAnnotation *popplerAnnotation) { Okular::TextAnnotation *oTextAnn = new Okular::TextAnnotation(); @@ -385,6 +433,29 @@ static Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::TextAn return oTextAnn; } +static Okular::Annotation *createAnnotationFromPopplerAnnotation(const Poppler::LineAnnotation *popplerAnnotation) +{ + Okular::LineAnnotation *oLineAnn = new Okular::LineAnnotation(); + + oLineAnn->setLineStartStyle(popplerToOkular(popplerAnnotation->lineStartStyle())); + oLineAnn->setLineEndStyle(popplerToOkular(popplerAnnotation->lineEndStyle())); + oLineAnn->setLineClosed(popplerAnnotation->isLineClosed()); + oLineAnn->setLineInnerColor(popplerAnnotation->lineInnerColor()); + oLineAnn->setLineLeadingForwardPoint(popplerAnnotation->lineLeadingForwardPoint()); + oLineAnn->setLineLeadingBackwardPoint(popplerAnnotation->lineLeadingBackPoint()); + oLineAnn->setShowCaption(popplerAnnotation->lineShowCaption()); + oLineAnn->setLineIntent(popplerToOkular(popplerAnnotation->lineIntent())); + + QLinkedList points; + const QLinkedList popplerPoints = popplerAnnotation->linePoints(); + for (const QPointF &p : popplerPoints) { + points << Okular::NormalizedPoint(p.x(), p.y()); + } + oLineAnn->setLinePoints(points); + + return oLineAnn; +} + Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *popplerAnnotation, const Poppler::Page &popplerPage, bool *doDelete) { Okular::Annotation *okularAnnotation = nullptr; @@ -459,7 +530,13 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *p okularAnnotation = createAnnotationFromPopplerAnnotation(static_cast(popplerAnnotation)); break; } - case Poppler::Annotation::ALine: + case Poppler::Annotation::ALine: { + externallyDrawn = true; + tieToOkularAnn = true; + *doDelete = false; + okularAnnotation = createAnnotationFromPopplerAnnotation(static_cast(popplerAnnotation)); + break; + } case Poppler::Annotation::AGeom: case Poppler::Annotation::AHighlight: case Poppler::Annotation::AInk: