annots.cpp 19.2 KB
Newer Older
1 2
/***************************************************************************
 *   Copyright (C) 2008 by Pino Toscano <pino@kde.org>                     *
3
 *   Copyright (C) 2012 by Guillermo A. Amaral B. <gamaral@kde.org>        *
4 5 6
 *   Copyright (C) 2017    Klarälvdalens Datakonsult AB, a KDAB Group      *
 *                         company, info@kdab.com. Work sponsored by the   *
 *                         LiMux project of the city of Munich             *
7 8 9 10 11 12 13
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

Yuri Chornoivan's avatar
Yuri Chornoivan committed
14 15
#include "annots.h"

16 17
#include <poppler-annotation.h>

18
// qt/kde includes
Yuri Chornoivan's avatar
Yuri Chornoivan committed
19 20
#include <QLoggingCategory>
#include <QVariant>
21

22
#include <core/annotations.h>
23
#include <core/area.h>
24

Albert Astals Cid's avatar
Albert Astals Cid committed
25
#include "config-okular-poppler.h"
26
#include "debug_pdf.h"
27
#include "generator_pdf.h"
28
#include "popplerembeddedfile.h"
29

Albert Astals Cid's avatar
Albert Astals Cid committed
30
Q_DECLARE_METATYPE(Poppler::Annotation *)
31

Albert Astals Cid's avatar
Albert Astals Cid committed
32 33 34 35
extern Okular::Sound *createSoundFromPopplerSound(const Poppler::SoundObject *popplerSound);
extern Okular::Movie *createMovieFromPopplerMovie(const Poppler::MovieObject *popplerMovie);
extern Okular::Movie *createMovieFromPopplerScreen(const Poppler::LinkRendition *popplerScreen);
extern QPair<Okular::Movie *, Okular::EmbeddedFile *> createMovieFromPopplerRichMedia(const Poppler::RichMediaAnnotation *popplerRichMedia);
36

Albert Astals Cid's avatar
Albert Astals Cid committed
37
static void disposeAnnotation(const Okular::Annotation *ann)
38
{
Albert Astals Cid's avatar
Albert Astals Cid committed
39
    Poppler::Annotation *popplerAnn = qvariant_cast<Poppler::Annotation *>(ann->nativeId());
40 41 42
    delete popplerAnn;
}

Albert Astals Cid's avatar
Albert Astals Cid committed
43
static QPointF normPointToPointF(const Okular::NormalizedPoint &pt)
44 45 46 47
{
    return QPointF(pt.x, pt.y);
}

Albert Astals Cid's avatar
Albert Astals Cid committed
48
static QRectF normRectToRectF(const Okular::NormalizedRect &rect)
49
{
Albert Astals Cid's avatar
Albert Astals Cid committed
50
    return QRectF(QPointF(rect.left, rect.top), QPointF(rect.right, rect.bottom));
51 52
}

53 54 55
// Poppler and Okular share the same flag values, but we don't want to export internal flags
static int maskExportedFlags(int flags)
{
Albert Astals Cid's avatar
Albert Astals Cid committed
56 57 58
    return flags &
        (Okular::Annotation::Hidden | Okular::Annotation::FixedSize | Okular::Annotation::FixedRotation | Okular::Annotation::DenyPrint | Okular::Annotation::DenyWrite | Okular::Annotation::DenyDelete |
         Okular::Annotation::ToggleHidingOnMouse);
59 60
}

Albert Astals Cid's avatar
Albert Astals Cid committed
61 62 63 64 65
// BEGIN PopplerAnnotationProxy implementation
PopplerAnnotationProxy::PopplerAnnotationProxy(Poppler::Document *doc, QMutex *userMutex, QHash<Okular::Annotation *, Poppler::Annotation *> *annotsOnOpenHash)
    : ppl_doc(doc)
    , mutex(userMutex)
    , annotationsOnOpenHash(annotsOnOpenHash)
66 67 68 69 70 71 72
{
}

PopplerAnnotationProxy::~PopplerAnnotationProxy()
{
}

Albert Astals Cid's avatar
Albert Astals Cid committed
73
bool PopplerAnnotationProxy::supports(Capability cap) const
74
{
Albert Astals Cid's avatar
Albert Astals Cid committed
75 76 77 78 79 80 81
    switch (cap) {
    case Addition:
    case Modification:
    case Removal:
        return true;
    default:
        return false;
82 83 84
    }
}

Albert Astals Cid's avatar
Albert Astals Cid committed
85
void PopplerAnnotationProxy::notifyAddition(Okular::Annotation *okl_ann, int page)
86 87 88
{
    // Export annotation to DOM
    QDomDocument doc;
Albert Astals Cid's avatar
Albert Astals Cid committed
89 90
    QDomElement dom_ann = doc.createElement(QStringLiteral("root"));
    Okular::AnnotationUtils::storeAnnotation(okl_ann, dom_ann, doc);
91

92 93
    QMutexLocker ml(mutex);

94
    // Create poppler annotation
Albert Astals Cid's avatar
Albert Astals Cid committed
95
    Poppler::Annotation *ppl_ann = Poppler::AnnotationUtils::createAnnotation(dom_ann);
96 97

    // Poppler doesn't render StampAnnotations yet
Albert Astals Cid's avatar
Albert Astals Cid committed
98 99
    if (ppl_ann->subType() != Poppler::Annotation::AStamp)
        okl_ann->setFlags(okl_ann->flags() | Okular::Annotation::ExternallyDrawn);
100 101

    // Poppler stores highlight points in swapped order
Albert Astals Cid's avatar
Albert Astals Cid committed
102 103
    if (ppl_ann->subType() == Poppler::Annotation::AHighlight) {
        Poppler::HighlightAnnotation *hlann = static_cast<Poppler::HighlightAnnotation *>(ppl_ann);
104
        QList<Poppler::HighlightAnnotation::Quad> quads = hlann->highlightQuads();
Albert Astals Cid's avatar
Albert Astals Cid committed
105 106
        QMutableListIterator<Poppler::HighlightAnnotation::Quad> it(quads);
        while (it.hasNext()) {
107 108 109 110 111 112 113 114 115
            Poppler::HighlightAnnotation::Quad &q = it.next();
            QPointF t;
            t = q.points[3];
            q.points[3] = q.points[0];
            q.points[0] = t;
            t = q.points[2];
            q.points[2] = q.points[1];
            q.points[1] = t;
        }
Albert Astals Cid's avatar
Albert Astals Cid committed
116
        hlann->setHighlightQuads(quads);
117 118 119
    }

    // Bind poppler object to page
Albert Astals Cid's avatar
Albert Astals Cid committed
120 121
    Poppler::Page *ppl_page = ppl_doc->page(page);
    ppl_page->addAnnotation(ppl_ann);
122 123 124
    delete ppl_page;

    // Set pointer to poppler annotation as native Id
Albert Astals Cid's avatar
Albert Astals Cid committed
125 126
    okl_ann->setNativeId(QVariant::fromValue(ppl_ann));
    okl_ann->setDisposeDataFunction(disposeAnnotation);
127

128
    qCDebug(OkularPdfDebug) << okl_ann->uniqueName();
129 130
}

Albert Astals Cid's avatar
Albert Astals Cid committed
131
void PopplerAnnotationProxy::notifyModification(const Okular::Annotation *okl_ann, int page, bool appearanceChanged)
132
{
Albert Astals Cid's avatar
Albert Astals Cid committed
133 134
    Q_UNUSED(page);
    Q_UNUSED(appearanceChanged);
135

Albert Astals Cid's avatar
Albert Astals Cid committed
136
    Poppler::Annotation *ppl_ann = qvariant_cast<Poppler::Annotation *>(okl_ann->nativeId());
137

Albert Astals Cid's avatar
Albert Astals Cid committed
138
    if (!ppl_ann) // Ignore non-native annotations
139 140
        return;

141 142
    QMutexLocker ml(mutex);

Albert Astals Cid's avatar
Albert Astals Cid committed
143
    if (okl_ann->flags() & (Okular::Annotation::BeingMoved | Okular::Annotation::BeingResized)) {
144
        // Okular ui already renders the annotation on its own
Albert Astals Cid's avatar
Albert Astals Cid committed
145
        ppl_ann->setFlags(Poppler::Annotation::Hidden);
146 147 148
        return;
    }

149
    // Set basic properties
150 151
    // Note: flags and boundary must be set first in order to correctly handle
    // FixedRotation annotations.
Albert Astals Cid's avatar
Albert Astals Cid committed
152 153
    ppl_ann->setFlags(maskExportedFlags(okl_ann->flags()));
    ppl_ann->setBoundary(normRectToRectF(okl_ann->boundingRectangle()));
154

Albert Astals Cid's avatar
Albert Astals Cid committed
155 156
    ppl_ann->setAuthor(okl_ann->author());
    ppl_ann->setContents(okl_ann->contents());
157 158 159

    // Set style
    Poppler::Annotation::Style s;
Albert Astals Cid's avatar
Albert Astals Cid committed
160 161 162 163
    s.setColor(okl_ann->style().color());
    s.setWidth(okl_ann->style().width());
    s.setOpacity(okl_ann->style().opacity());
    ppl_ann->setStyle(s);
164 165

    // Set type-specific properties (if any)
Albert Astals Cid's avatar
Albert Astals Cid committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    switch (ppl_ann->subType()) {
    case Poppler::Annotation::AText: {
        const Okular::TextAnnotation *okl_txtann = static_cast<const Okular::TextAnnotation *>(okl_ann);
        Poppler::TextAnnotation *ppl_txtann = static_cast<Poppler::TextAnnotation *>(ppl_ann);
        ppl_txtann->setTextIcon(okl_txtann->textIcon());
        ppl_txtann->setTextFont(okl_txtann->textFont());
#ifdef HAVE_POPPLER_0_69
        ppl_txtann->setTextColor(okl_txtann->textColor());
#endif // HAVE_POPPLER_0_69
        ppl_txtann->setInplaceAlign(okl_txtann->inplaceAlignment());
        ppl_txtann->setCalloutPoints(QVector<QPointF>());
        ppl_txtann->setInplaceIntent((Poppler::TextAnnotation::InplaceIntent)okl_txtann->inplaceIntent());
        break;
    }
    case Poppler::Annotation::ALine: {
        const Okular::LineAnnotation *okl_lineann = static_cast<const Okular::LineAnnotation *>(okl_ann);
        Poppler::LineAnnotation *ppl_lineann = static_cast<Poppler::LineAnnotation *>(ppl_ann);
        QLinkedList<QPointF> points;
        const QLinkedList<Okular::NormalizedPoint> annotPoints = okl_lineann->linePoints();
        for (const Okular::NormalizedPoint &p : annotPoints) {
            points.append(normPointToPointF(p));
187
        }
Albert Astals Cid's avatar
Albert Astals Cid committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
        ppl_lineann->setLinePoints(points);
        ppl_lineann->setLineStartStyle((Poppler::LineAnnotation::TermStyle)okl_lineann->lineStartStyle());
        ppl_lineann->setLineEndStyle((Poppler::LineAnnotation::TermStyle)okl_lineann->lineEndStyle());
        ppl_lineann->setLineClosed(okl_lineann->lineClosed());
        ppl_lineann->setLineInnerColor(okl_lineann->lineInnerColor());
        ppl_lineann->setLineLeadingForwardPoint(okl_lineann->lineLeadingForwardPoint());
        ppl_lineann->setLineLeadingBackPoint(okl_lineann->lineLeadingBackwardPoint());
        ppl_lineann->setLineShowCaption(okl_lineann->showCaption());
        ppl_lineann->setLineIntent((Poppler::LineAnnotation::LineIntent)okl_lineann->lineIntent());
        break;
    }
    case Poppler::Annotation::AGeom: {
        const Okular::GeomAnnotation *okl_geomann = static_cast<const Okular::GeomAnnotation *>(okl_ann);
        Poppler::GeomAnnotation *ppl_geomann = static_cast<Poppler::GeomAnnotation *>(ppl_ann);
        ppl_geomann->setGeomType((Poppler::GeomAnnotation::GeomType)okl_geomann->geometricalType());
        ppl_geomann->setGeomInnerColor(okl_geomann->geometricalInnerColor());
        break;
    }
    case Poppler::Annotation::AHighlight: {
        const Okular::HighlightAnnotation *okl_hlann = static_cast<const Okular::HighlightAnnotation *>(okl_ann);
        Poppler::HighlightAnnotation *ppl_hlann = static_cast<Poppler::HighlightAnnotation *>(ppl_ann);
        ppl_hlann->setHighlightType((Poppler::HighlightAnnotation::HighlightType)okl_hlann->highlightType());
        break;
    }
    case Poppler::Annotation::AStamp: {
        const Okular::StampAnnotation *okl_stampann = static_cast<const Okular::StampAnnotation *>(okl_ann);
        Poppler::StampAnnotation *ppl_stampann = static_cast<Poppler::StampAnnotation *>(ppl_ann);
        ppl_stampann->setStampIconName(okl_stampann->stampIconName());
        break;
    }
    case Poppler::Annotation::AInk: {
        const Okular::InkAnnotation *okl_inkann = static_cast<const Okular::InkAnnotation *>(okl_ann);
        Poppler::InkAnnotation *ppl_inkann = static_cast<Poppler::InkAnnotation *>(ppl_ann);
        QList<QLinkedList<QPointF>> paths;
        const QList<QLinkedList<Okular::NormalizedPoint>> inkPathsList = okl_inkann->inkPaths();
        for (const QLinkedList<Okular::NormalizedPoint> &path : inkPathsList) {
224
            QLinkedList<QPointF> points;
Albert Astals Cid's avatar
Albert Astals Cid committed
225 226
            for (const Okular::NormalizedPoint &p : path) {
                points.append(normPointToPointF(p));
227
            }
Albert Astals Cid's avatar
Albert Astals Cid committed
228
            paths.append(points);
229
        }
Albert Astals Cid's avatar
Albert Astals Cid committed
230 231 232 233 234 235
        ppl_inkann->setInkPaths(paths);
        break;
    }
    default:
        qCDebug(OkularPdfDebug) << "Type-specific property modification is not implemented for this annotation type";
        break;
236 237
    }

238
    qCDebug(OkularPdfDebug) << okl_ann->uniqueName();
239 240
}

Albert Astals Cid's avatar
Albert Astals Cid committed
241
void PopplerAnnotationProxy::notifyRemoval(Okular::Annotation *okl_ann, int page)
242
{
Albert Astals Cid's avatar
Albert Astals Cid committed
243
    Poppler::Annotation *ppl_ann = qvariant_cast<Poppler::Annotation *>(okl_ann->nativeId());
244

Albert Astals Cid's avatar
Albert Astals Cid committed
245
    if (!ppl_ann) // Ignore non-native annotations
246 247
        return;

248 249
    QMutexLocker ml(mutex);

Albert Astals Cid's avatar
Albert Astals Cid committed
250 251 252
    Poppler::Page *ppl_page = ppl_doc->page(page);
    annotationsOnOpenHash->remove(okl_ann);
    ppl_page->removeAnnotation(ppl_ann); // Also destroys ppl_ann
253 254
    delete ppl_page;

Albert Astals Cid's avatar
Albert Astals Cid committed
255
    okl_ann->setNativeId(QVariant::fromValue(0)); // So that we don't double-free in disposeAnnotation
256

257
    qCDebug(OkularPdfDebug) << okl_ann->uniqueName();
258
}
Albert Astals Cid's avatar
Albert Astals Cid committed
259
// END PopplerAnnotationProxy implementation
260

261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
static Okular::Annotation::LineStyle okularLineStyleFromAnnotationLineStyle(Poppler::Annotation::LineStyle s)
{
    switch (s) {
    case Poppler::Annotation::Solid:
        return Okular::Annotation::Solid;
    case Poppler::Annotation::Dashed:
        return Okular::Annotation::Dashed;
    case Poppler::Annotation::Beveled:
        return Okular::Annotation::Beveled;
    case Poppler::Annotation::Inset:
        return Okular::Annotation::Inset;
    case Poppler::Annotation::Underline:
        return Okular::Annotation::Underline;
    }

    Q_UNREACHABLE();
    return Okular::Annotation::Solid;
}

static Okular::Annotation::LineEffect okularLineEffectFromAnnotationLineEffect(Poppler::Annotation::LineEffect e)
{
    switch (e) {
    case Poppler::Annotation::NoEffect:
        return Okular::Annotation::NoEffect;
    case Poppler::Annotation::Cloudy:
        return Okular::Annotation::Cloudy;
    }

    Q_UNREACHABLE();
    return Okular::Annotation::NoEffect;
}

293
Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *popplerAnnotation, const Poppler::Page &popplerPage, bool *doDelete)
294
{
295
    Okular::Annotation *okularAnnotation = nullptr;
296
    *doDelete = true;
297
    bool tieToOkularAnn = false;
298
    bool externallyDrawn = false;
299
    switch (popplerAnnotation->subType()) {
Albert Astals Cid's avatar
Albert Astals Cid committed
300
    case Poppler::Annotation::AFileAttachment: {
301
        Poppler::FileAttachmentAnnotation *attachann = static_cast<Poppler::FileAttachmentAnnotation *>(popplerAnnotation);
Albert Astals Cid's avatar
Albert Astals Cid committed
302
        Okular::FileAttachmentAnnotation *f = new Okular::FileAttachmentAnnotation();
303
        okularAnnotation = f;
Albert Astals Cid's avatar
Albert Astals Cid committed
304 305 306 307 308 309 310 311 312
        tieToOkularAnn = true;
        *doDelete = false;

        f->setFileIconName(attachann->fileIconName());
        f->setEmbeddedFile(new PDFEmbeddedFile(attachann->embeddedFile()));

        break;
    }
    case Poppler::Annotation::ASound: {
313
        Poppler::SoundAnnotation *soundann = static_cast<Poppler::SoundAnnotation *>(popplerAnnotation);
Albert Astals Cid's avatar
Albert Astals Cid committed
314
        Okular::SoundAnnotation *s = new Okular::SoundAnnotation();
315
        okularAnnotation = s;
316

Albert Astals Cid's avatar
Albert Astals Cid committed
317 318
        s->setSoundIconName(soundann->soundIconName());
        s->setSound(createSoundFromPopplerSound(soundann->sound()));
319

Albert Astals Cid's avatar
Albert Astals Cid committed
320 321 322
        break;
    }
    case Poppler::Annotation::AMovie: {
323
        Poppler::MovieAnnotation *movieann = static_cast<Poppler::MovieAnnotation *>(popplerAnnotation);
Albert Astals Cid's avatar
Albert Astals Cid committed
324
        Okular::MovieAnnotation *m = new Okular::MovieAnnotation();
325
        okularAnnotation = m;
Albert Astals Cid's avatar
Albert Astals Cid committed
326 327
        tieToOkularAnn = true;
        *doDelete = false;
328

Albert Astals Cid's avatar
Albert Astals Cid committed
329
        m->setMovie(createMovieFromPopplerMovie(movieann->movie()));
330

Albert Astals Cid's avatar
Albert Astals Cid committed
331 332 333
        break;
    }
    case Poppler::Annotation::AWidget: {
334
        okularAnnotation = new Okular::WidgetAnnotation();
Albert Astals Cid's avatar
Albert Astals Cid committed
335 336 337 338
        break;
    }
    case Poppler::Annotation::AScreen: {
        Okular::ScreenAnnotation *m = new Okular::ScreenAnnotation();
339
        okularAnnotation = m;
Albert Astals Cid's avatar
Albert Astals Cid committed
340 341 342 343 344
        tieToOkularAnn = true;
        *doDelete = false;
        break;
    }
    case Poppler::Annotation::ARichMedia: {
345
        Poppler::RichMediaAnnotation *richmediaann = static_cast<Poppler::RichMediaAnnotation *>(popplerAnnotation);
Albert Astals Cid's avatar
Albert Astals Cid committed
346
        const QPair<Okular::Movie *, Okular::EmbeddedFile *> result = createMovieFromPopplerRichMedia(richmediaann);
347

Albert Astals Cid's avatar
Albert Astals Cid committed
348 349
        if (result.first) {
            Okular::RichMediaAnnotation *r = new Okular::RichMediaAnnotation();
350 351
            tieToOkularAnn = true;
            *doDelete = false;
352
            okularAnnotation = r;
353

Albert Astals Cid's avatar
Albert Astals Cid committed
354 355
            r->setMovie(result.first);
            r->setEmbeddedFile(result.second);
356
        }
Albert Astals Cid's avatar
Albert Astals Cid committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376

        break;
    }
    case Poppler::Annotation::AText:
    case Poppler::Annotation::ALine:
    case Poppler::Annotation::AGeom:
    case Poppler::Annotation::AHighlight:
    case Poppler::Annotation::AInk:
    case Poppler::Annotation::ACaret:
        externallyDrawn = true;
        /* fallthrough */
    case Poppler::Annotation::AStamp:
        tieToOkularAnn = true;
        *doDelete = false;
        /* fallthrough */
    default: {
        // this is uber ugly but i don't know a better way to do it without introducing a poppler::annotation dependency on core
        QDomDocument doc;
        QDomElement root = doc.createElement(QStringLiteral("root"));
        doc.appendChild(root);
377 378
        Poppler::AnnotationUtils::storeAnnotation(popplerAnnotation, root, doc);
        okularAnnotation = Okular::AnnotationUtils::createAnnotation(root);
Albert Astals Cid's avatar
Albert Astals Cid committed
379 380
        break;
    }
381
    }
382
    if (okularAnnotation) {
383
        // the Contents field might have lines separated by \r
384
        QString contents = popplerAnnotation->contents();
Albert Astals Cid's avatar
Albert Astals Cid committed
385
        contents.replace(QLatin1Char('\r'), QLatin1Char('\n'));
386

387 388 389 390 391 392 393
        okularAnnotation->setAuthor(popplerAnnotation->author());
        okularAnnotation->setContents(contents);
        okularAnnotation->setUniqueName(popplerAnnotation->uniqueName());
        okularAnnotation->setModificationDate(popplerAnnotation->modificationDate());
        okularAnnotation->setCreationDate(popplerAnnotation->creationDate());
        okularAnnotation->setFlags(popplerAnnotation->flags() | Okular::Annotation::External);
        okularAnnotation->setBoundingRectangle(Okular::NormalizedRect::fromQRectF(popplerAnnotation->boundary()));
394 395

        if (externallyDrawn)
396
            okularAnnotation->setFlags(okularAnnotation->flags() | Okular::Annotation::ExternallyDrawn);
397 398

        // Poppler stores highlight points in swapped order
399 400
        if (okularAnnotation->subType() == Okular::Annotation::AHighlight) {
            Okular::HighlightAnnotation *hlann = static_cast<Okular::HighlightAnnotation *>(okularAnnotation);
Albert Astals Cid's avatar
Albert Astals Cid committed
401 402 403 404 405 406 407
            for (Okular::HighlightAnnotation::Quad &quad : hlann->highlightQuads()) {
                const Okular::NormalizedPoint p3 = quad.point(3);
                quad.setPoint(quad.point(0), 3);
                quad.setPoint(p3, 0);
                const Okular::NormalizedPoint p2 = quad.point(2);
                quad.setPoint(quad.point(1), 2);
                quad.setPoint(p2, 1);
408 409 410
            }
        }

411 412
        if (okularAnnotation->subType() == Okular::Annotation::AText) {
            Okular::TextAnnotation *txtann = static_cast<Okular::TextAnnotation *>(okularAnnotation);
413

Albert Astals Cid's avatar
Albert Astals Cid committed
414
            if (txtann->textType() == Okular::TextAnnotation::Linked) {
415
                Poppler::TextAnnotation *ppl_txtann = static_cast<Poppler::TextAnnotation *>(popplerAnnotation);
416 417 418

                // Poppler and Okular assume a different default icon name in XML
                // We re-read it via getter, which always tells the right one
Albert Astals Cid's avatar
Albert Astals Cid committed
419
                txtann->setTextIcon(ppl_txtann->textIcon());
420 421
            }
        }
422

423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
        // Convert the poppler annotation style to Okular annotation style
        Okular::Annotation::Style &okularStyle = okularAnnotation->style();
        const Poppler::Annotation::Style popplerStyle = popplerAnnotation->style();
        okularStyle.setColor(popplerStyle.color());
        okularStyle.setOpacity(popplerStyle.opacity());
        okularStyle.setWidth(popplerStyle.width());
        okularStyle.setLineStyle(okularLineStyleFromAnnotationLineStyle(popplerStyle.lineStyle()));
        okularStyle.setXCorners(popplerStyle.xCorners());
        okularStyle.setYCorners(popplerStyle.yCorners());
        const QVector<double> &dashArray = popplerStyle.dashArray();
        if (dashArray.size() > 0)
            okularStyle.setMarks(dashArray[0]);
        if (dashArray.size() > 1)
            okularStyle.setSpaces(dashArray[1]);
        okularStyle.setLineEffect(okularLineEffectFromAnnotationLineEffect(popplerStyle.lineEffect()));
        okularStyle.setEffectIntensity(popplerStyle.effectIntensity());

440 441 442 443 444 445 446 447 448 449 450 451 452
        // Convert the poppler annotation popup to Okular annotation window
        Okular::Annotation::Window &okularWindow = okularAnnotation->window();
        const Poppler::Annotation::Popup popplerPopup = popplerAnnotation->popup();
        // This assumes that both "flags" int mean the same, but since we don't use the flags in okular anywhere it's not really that important
        okularWindow.setFlags(popplerPopup.flags());
        const QRectF popplerGeometry = popplerPopup.geometry();
        const QSize popplerPageSize = popplerPage.pageSize();
        okularWindow.setTopLeft(Okular::NormalizedPoint(popplerGeometry.top(), popplerGeometry.left(), popplerPageSize.width(), popplerPageSize.height()));
        okularWindow.setWidth(popplerGeometry.width());
        okularWindow.setHeight(popplerGeometry.height());
        okularWindow.setTitle(popplerPopup.title());
        okularWindow.setSummary(popplerPopup.summary());

453
        // TODO clone revisions
Albert Astals Cid's avatar
Albert Astals Cid committed
454
        if (tieToOkularAnn) {
455 456
            okularAnnotation->setNativeId(QVariant::fromValue(popplerAnnotation));
            okularAnnotation->setDisposeDataFunction(disposeAnnotation);
457
        }
458
    }
459
    return okularAnnotation;
460
}