Index: poppler/Link.h =================================================================== --- poppler/Link.h +++ poppler/Link.h @@ -18,6 +18,7 @@ // Copyright (C) 2010, 2011 Carlos Garcia Campos // Copyright (C) 2012 Tobias Koening // Copyright (C) 2018 Albert Astals Cid +// Copyright (C) 2018 Intevation GmbH // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -57,6 +58,7 @@ actionSound, // sound action actionJavaScript, // JavaScript action actionOCGState, // Set-OCG-State action + actionHide, // Hide action actionUnknown // anything else }; @@ -451,6 +453,39 @@ }; //------------------------------------------------------------------------ +// LinkHide +//------------------------------------------------------------------------ + +class LinkHide: public LinkAction { +public: + LinkHide(Object *hideObj); + + ~LinkHide(); + + GBool isOk() override { return targetName != nullptr; } + LinkActionKind getKind() override { return actionHide; } + + // According to spec the target can be either: + // a) A text string containing the fully qualified name of the target + // field. + // b) An indirect reference to an annotation dictionary. + // c) An array of "such dictionaries or text strings". + // + // While b / c appear to be very uncommon and can't easily be + // created with Adobe Acrobat DC. So only support hide + // actions with named targets (yet). + GBool hasTargetName() { return targetName != nullptr; } + GooString *getTargetName() { return targetName; } + + // Should this action show or hide. + GBool isShowAction() { return show; } + +private: + GooString *targetName; + GBool show; +}; + +//------------------------------------------------------------------------ // LinkUnknown //------------------------------------------------------------------------ Index: poppler/Link.cc =================================================================== --- poppler/Link.cc +++ poppler/Link.cc @@ -20,6 +20,7 @@ // Copyright (C) 2009 Kovid Goyal // Copyright (C) 2009 Ilya Gorenbein // Copyright (C) 2012 Tobias Koening +// Copyright (C) 2018 Intevation GmbH // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -119,6 +120,10 @@ } else if (obj2.isName("SetOCGState")) { action = new LinkOCGState(obj); + // Hide action + } else if (obj2.isName("Hide")) { + action = new LinkHide(obj); + // unknown action } else if (obj2.isName()) { action = new LinkUnknown(obj2.getName()); @@ -810,6 +815,32 @@ } //------------------------------------------------------------------------ +// LinkHide +//------------------------------------------------------------------------ + +LinkHide::LinkHide(Object *hideObj) { + targetName = nullptr; + show = false; // Default + + if (hideObj->isDict()) { + Object targetObj = hideObj->dictLookup("T"); + if (targetObj.isString()) { + targetName = targetObj.getString()->copy(); + } + Object shouldHide = hideObj->dictLookup("H"); + if (shouldHide.isBool()) { + show = !shouldHide.getBool(); + } + } +} + +LinkHide::~LinkHide() { + if (targetName) { + delete targetName; + } +} + +//------------------------------------------------------------------------ // LinkUnknown //------------------------------------------------------------------------ Index: qt5/src/poppler-annotation.cc =================================================================== --- qt5/src/poppler-annotation.cc +++ qt5/src/poppler-annotation.cc @@ -3945,6 +3945,11 @@ hyperlinkElement.setAttribute( QStringLiteral("type"), QStringLiteral("OCGState") ); break; } + case Poppler::Link::Hide: + { + hyperlinkElement.setAttribute( QStringLiteral("type"), QStringLiteral("Hide") ); + break; + } case Poppler::Link::None: break; } Index: qt5/src/poppler-link.h =================================================================== --- qt5/src/poppler-link.h +++ qt5/src/poppler-link.h @@ -49,6 +49,7 @@ class LinkDestinationPrivate; class LinkRenditionPrivate; class LinkOCGStatePrivate; +class LinkHidePrivate; class MediaRendition; class SoundObject; @@ -197,7 +198,8 @@ Movie, ///< An action to be executed on a movie Rendition, ///< A rendition link \since 0.20 JavaScript, ///< A JavaScript code to be interpreted \since 0.10 - OCGState ///< An Optional Content Group state change \since 0.50 + OCGState, ///< An Optional Content Group state change \since 0.50 + Hide, ///< An action to hide a field \since 0.64 }; /** @@ -627,6 +629,40 @@ Q_DISABLE_COPY( LinkOCGState ) }; +/** + * Hide: an action to show / hide a field. + * + * \since 0.64 + */ +class POPPLER_QT5_EXPORT LinkHide: public Link +{ + public: + /** + * Create a new Hide link. + */ + LinkHide( const QRectF &linkArea, const QString &targetName, bool isShow ); + /** + * Destructor. + */ + ~LinkHide(); + + LinkType linkType() const override; + + /** + * The fully qualified target name of the action. + */ + QString targetName() const; + + /** + * Should this action change the visibility of the target to true. + */ + bool isShowAction() const; + + private: + Q_DECLARE_PRIVATE( LinkHide ) + Q_DISABLE_COPY( LinkHide ) +}; + } #endif Index: qt5/src/poppler-link.cc =================================================================== --- qt5/src/poppler-link.cc +++ qt5/src/poppler-link.cc @@ -4,6 +4,7 @@ * Copyright (C) 2010 Hib Eris * Copyright (C) 2012, Tobias Koenig * Copyright (C) 2012, Guillermo A. Amaral B. + * Copyright (C) 2018 Intevation GmbH * Adapting code from * Copyright (C) 2004 by Enrico Ros * @@ -220,6 +221,20 @@ { } +class LinkHidePrivate : public LinkPrivate +{ + public: + LinkHidePrivate( const QRectF &area ); + + QString targetName; + bool isShow; +}; + + LinkHidePrivate::LinkHidePrivate( const QRectF &area ) + : LinkPrivate( area ) + { + } + static void cvtUserToDev(::Page *page, double xu, double yu, int *xd, int *yd) { double ctm[6]; @@ -704,4 +719,34 @@ { return OCGState; } + + // LinkHide + LinkHide::LinkHide( const QRectF &linkArea, const QString &targetName, bool isShow ) + : Link( *new LinkHidePrivate( linkArea ) ) + { + Q_D( LinkHide ); + d->targetName = targetName; + d->isShow = isShow; + } + + LinkHide::~LinkHide() + { + } + + Link::LinkType LinkHide::linkType() const + { + return Hide; + } + + QString LinkHide::targetName() const + { + Q_D( const LinkHide ); + return d->targetName; + } + + bool LinkHide::isShowAction() const + { + Q_D( const LinkHide ); + return d->isShow; + } } Index: qt5/src/poppler-page.cc =================================================================== --- qt5/src/poppler-page.cc +++ qt5/src/poppler-page.cc @@ -20,6 +20,7 @@ * Copyright (C) 2017, Oliver Sander * Copyright (C) 2017 Adrian Johnson * Copyright (C) 2017, 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, . Work sponsored by the LiMux project of the city of Munich + * Copyright (C) 2018 Intevation GmbH * * 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 @@ -343,6 +344,13 @@ popplerLink = new LinkOCGState( locgp ); } + case actionHide: + { + ::LinkHide *lh = (::LinkHide *)a; + popplerLink = new LinkHide( linkArea, lh->hasTargetName() ? UnicodeParsedString( lh->getTargetName() ) : QString(), lh->isShowAction() ); + } + break; + case actionUnknown: break; }