glib/poppler-action.cc | 26 +++------- goo/GooString.h | 3 + poppler/Annot.cc | 2 poppler/Form.cc | 14 ++--- poppler/Link.cc | 109 ++++++++++++++------------------------------- poppler/Link.h | 70 ++++++++++++---------------- poppler/PDFDocEncoding.h | 4 + poppler/Sound.cc | 5 -- poppler/Sound.h | 5 +- poppler/Stream.h | 10 +++- qt5/src/poppler-page.cc | 30 ++++++------ qt5/src/poppler-private.cc | 12 +++- qt5/src/poppler-private.h | 2 utils/HtmlOutputDev.cc | 2 utils/JSInfo.cc | 19 +++---- 15 files changed, 137 insertions(+), 176 deletions(-)
New commits: commit 3355e20b2849fc1be131095bc2fe5b0a02d41d5a Author: Oliver Sander <[email protected]> Date: Wed Jan 29 09:41:35 2020 +0100 Implement fillGooString in terms of fillString This requires to add a method to GooString that allows access as a mutable std::string&. diff --git a/goo/GooString.h b/goo/GooString.h index 11baa8ae..78824455 100644 --- a/goo/GooString.h +++ b/goo/GooString.h @@ -68,6 +68,7 @@ public: explicit GooString(std::string&& str) : std::string(std::move(str)) {} const std::string& toStr() const { return *this; } + std::string& toNonConstStr() { return *this; } // Create a string from <lengthA> chars at <sA>. This string // can contain null characters. diff --git a/poppler/Stream.h b/poppler/Stream.h index e19790e5..04dfd053 100644 --- a/poppler/Stream.h +++ b/poppler/Stream.h @@ -142,12 +142,7 @@ public: inline void fillGooString(GooString *s) { - unsigned char readBuf[4096]; - int readChars; - reset(); - while ((readChars = doGetChars(4096, readBuf)) != 0) { - s->append((const char *)readBuf, readChars); - } + fillString(s->toNonConstStr()); } inline unsigned char *toUnsignedChars(int *length, int initialSize = 4096, int sizeIncrement = 4096) commit 5804f51c7cf439432082b668ba8df3b0a6048caf Author: Oliver Sander <[email protected]> Date: Mon Jan 27 17:33:49 2020 +0100 Use a std::string value in LinkURI diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index e6be5b9b..583efb53 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -405,9 +405,7 @@ static void build_uri (PopplerAction *action, const LinkURI *link) { - const gchar *uri; - - uri = link->getURI()->c_str (); + const gchar *uri = link->getURI().c_str (); if (uri != nullptr) action->uri.uri = g_strdup (uri); } diff --git a/poppler/Link.cc b/poppler/Link.cc index cfce4d36..318c6b96 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -560,38 +560,33 @@ LinkLaunch::~LinkLaunch() { //------------------------------------------------------------------------ LinkURI::LinkURI(const Object *uriObj, const GooString *baseURI) { - const GooString *uri2; - int n; - char c; - - uri = nullptr; + hasURIFlag = false; if (uriObj->isString()) { - uri2 = uriObj->getString(); - n = (int)strcspn(uri2->c_str(), "/:"); - if (n < uri2->getLength() && uri2->getChar(n) == ':') { + const std::string& uri2 = uriObj->getString()->toStr(); + size_t n = strcspn(uri2.c_str(), "/:"); + if (n < uri2.size() && uri2[n] == ':') { // "http:..." etc. - uri = uri2->copy(); - } else if (!uri2->cmpN("www.", 4)) { + uri = uri2; + } else if (!uri2.compare(0,4,"www.")) { // "www.[...]" without the leading "http://" - uri = new GooString("http://"); - uri->append(uri2); + uri = "http://" + uri2; } else { // relative URI if (baseURI) { - uri = baseURI->copy(); - if (uri->getLength() > 0) { - c = uri->getChar(uri->getLength() - 1); + uri = baseURI->toStr(); + if (uri.size() > 0) { + char c = uri.back(); if (c != '/' && c != '?') { - uri->append('/'); + uri += '/'; } } - if (uri2->getChar(0) == '/') { - uri->append(uri2->c_str() + 1, uri2->getLength() - 1); + if (uri2[0] == '/') { + uri.append(uri2.c_str() + 1, uri2.size() - 1); } else { - uri->append(uri2); + uri += uri2; } } else { - uri = uri2->copy(); + uri = uri2; } } } else { @@ -599,11 +594,6 @@ LinkURI::LinkURI(const Object *uriObj, const GooString *baseURI) { } } -LinkURI::~LinkURI() { - if (uri) - delete uri; -} - //------------------------------------------------------------------------ // LinkNamed //------------------------------------------------------------------------ diff --git a/poppler/Link.h b/poppler/Link.h index aaaf09c1..1871890f 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -253,19 +253,17 @@ public: // Build a LinkURI given the URI (string) and base URI. LinkURI(const Object *uriObj, const GooString *baseURI); - // Destructor. - ~LinkURI() override; - // Was the LinkURI created successfully? - bool isOk() const override { return uri != nullptr; } + bool isOk() const override { return hasURIFlag; } // Accessors. LinkActionKind getKind() const override { return actionURI; } - const GooString *getURI() const { return uri; } + const std::string& getURI() const { return uri; } private: - GooString *uri; // the URI + std::string uri; // the URI + bool hasURIFlag; }; //------------------------------------------------------------------------ diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 25731146..e36f6fd3 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -275,7 +275,7 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo case actionURI: { - popplerLink = new LinkBrowse( linkArea, ((LinkURI *)a)->getURI()->c_str() ); + popplerLink = new LinkBrowse( linkArea, ((LinkURI *)a)->getURI().c_str() ); } break; diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc index cb5bf8f1..e630f565 100644 --- a/qt5/src/poppler-private.cc +++ b/qt5/src/poppler-private.cc @@ -228,7 +228,7 @@ namespace Debug { case actionURI: { const LinkURI * u = static_cast< const LinkURI * >( a ); - e->setAttribute( QStringLiteral("DestinationURI"), u->getURI()->c_str() ); + e->setAttribute( QStringLiteral("DestinationURI"), u->getURI().c_str() ); } default: ; } diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc index 75fb5bbb..0212626b 100644 --- a/utils/HtmlOutputDev.cc +++ b/utils/HtmlOutputDev.cc @@ -1628,7 +1628,7 @@ GooString* HtmlOutputDev::getLinkDest(AnnotLink *link){ case actionURI: { LinkURI *ha=(LinkURI *) link->getAction(); - GooString* file=new GooString(ha->getURI()->c_str()); + GooString* file=new GooString(ha->getURI()); // printf("uri : %s\n",file->c_str()); return file; } commit 06a658708d73b4e2d0bcb9f5572be9b2754368eb Author: Oliver Sander <[email protected]> Date: Mon Jan 27 16:24:54 2020 +0100 Use a std::string value in LinkNamed diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index cbd78d85..e6be5b9b 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -416,9 +416,7 @@ static void build_named (PopplerAction *action, const LinkNamed *link) { - const gchar *name; - - name = link->getName ()->c_str (); + const gchar* name = link->getName ().c_str (); if (name != nullptr) action->named.named_dest = g_strdup (name); } diff --git a/poppler/Link.cc b/poppler/Link.cc index cd5ca00a..cfce4d36 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -609,15 +609,10 @@ LinkURI::~LinkURI() { //------------------------------------------------------------------------ LinkNamed::LinkNamed(const Object *nameObj) { - name = nullptr; + hasNameFlag = false; if (nameObj->isName()) { - name = new GooString(nameObj->getName()); - } -} - -LinkNamed::~LinkNamed() { - if (name) { - delete name; + name = (nameObj->getName()) ? nameObj->getName() : ""; + hasNameFlag = true; } } diff --git a/poppler/Link.h b/poppler/Link.h index 1e1bfd88..aaaf09c1 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -278,16 +278,15 @@ public: // Build a LinkNamed given the action name. LinkNamed(const Object *nameObj); - ~LinkNamed() override; - - bool isOk() const override { return name != nullptr; } + bool isOk() const override { return hasNameFlag; } LinkActionKind getKind() const override { return actionNamed; } - const GooString *getName() const { return name; } + const std::string& getName() const { return name; } private: - GooString *name; + std::string name; + bool hasNameFlag; }; diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 39753b7e..25731146 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -236,30 +236,30 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo case actionNamed: { - const char * name = ((LinkNamed *)a)->getName()->c_str(); - if ( !strcmp( name, "NextPage" ) ) + const std::string& name = ((LinkNamed *)a)->getName(); + if ( name == "NextPage" ) popplerLink = new LinkAction( linkArea, LinkAction::PageNext ); - else if ( !strcmp( name, "PrevPage" ) ) + else if ( name == "PrevPage" ) popplerLink = new LinkAction( linkArea, LinkAction::PagePrev ); - else if ( !strcmp( name, "FirstPage" ) ) + else if ( name == "FirstPage" ) popplerLink = new LinkAction( linkArea, LinkAction::PageFirst ); - else if ( !strcmp( name, "LastPage" ) ) + else if ( name == "LastPage" ) popplerLink = new LinkAction( linkArea, LinkAction::PageLast ); - else if ( !strcmp( name, "GoBack" ) ) + else if ( name == "GoBack" ) popplerLink = new LinkAction( linkArea, LinkAction::HistoryBack ); - else if ( !strcmp( name, "GoForward" ) ) + else if ( name == "GoForward" ) popplerLink = new LinkAction( linkArea, LinkAction::HistoryForward ); - else if ( !strcmp( name, "Quit" ) ) + else if ( name == "Quit" ) popplerLink = new LinkAction( linkArea, LinkAction::Quit ); - else if ( !strcmp( name, "GoToPage" ) ) + else if ( name == "GoToPage" ) popplerLink = new LinkAction( linkArea, LinkAction::GoToPage ); - else if ( !strcmp( name, "Find" ) ) + else if ( name == "Find" ) popplerLink = new LinkAction( linkArea, LinkAction::Find ); - else if ( !strcmp( name, "FullScreen" ) ) + else if ( name == "FullScreen" ) popplerLink = new LinkAction( linkArea, LinkAction::Presentation ); - else if ( !strcmp( name, "Print" ) ) + else if ( name == "Print" ) popplerLink = new LinkAction( linkArea, LinkAction::Print ); - else if ( !strcmp( name, "Close" ) ) + else if ( name == "Close" ) { // acroread closes the document always, doesnt care whether // its presentation mode or not commit 5d9a9c85bc27f7375a57f6c84913c8e0adcc38d1 Author: Oliver Sander <[email protected]> Date: Mon Jan 27 16:11:16 2020 +0100 Use a std::string value in LinkMovie diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index 3851a390..cbd78d85 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -436,7 +436,7 @@ find_annot_movie_for_action (PopplerDocument *document, annotObj = xref->fetch (*ref); } else if (link->hasAnnotTitle ()) { - const GooString *title = link->getAnnotTitle (); + const std::string& title = link->getAnnotTitle (); int i; for (i = 1; i <= document->doc->getNumPages (); ++i) { @@ -457,11 +457,8 @@ find_annot_movie_for_action (PopplerDocument *document, } obj1 = annotObj.dictLookup ("T"); - if (obj1.isString()) { - const GooString *t = obj1.getString (); - - if (title->cmp(t) == 0) - found = true; + if (obj1.isString() && obj1.getString()->toStr() == title) { + found = true; } } if (!found) diff --git a/poppler/Link.cc b/poppler/Link.cc index 0aca017a..cd5ca00a 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -627,7 +627,7 @@ LinkNamed::~LinkNamed() { LinkMovie::LinkMovie(const Object *obj) { annotRef = Ref::INVALID(); - annotTitle = nullptr; + hasAnnotTitleFlag = false; const Object &annotationObj = obj->dictLookupNF("Annotation"); if (annotationObj.isRef()) { @@ -636,10 +636,11 @@ LinkMovie::LinkMovie(const Object *obj) { Object tmp = obj->dictLookup("T"); if (tmp.isString()) { - annotTitle = tmp.getString()->copy(); + annotTitle = tmp.getString()->toStr(); + hasAnnotTitleFlag = true; } - if ((annotTitle == nullptr) && (annotRef == Ref::INVALID())) { + if ((!hasAnnotTitleFlag) && (annotRef == Ref::INVALID())) { error(errSyntaxError, -1, "Movie action is missing both the Annot and T keys"); } @@ -663,12 +664,6 @@ LinkMovie::LinkMovie(const Object *obj) { } } -LinkMovie::~LinkMovie() { - if (annotTitle) { - delete annotTitle; - } -} - //------------------------------------------------------------------------ // LinkSound //------------------------------------------------------------------------ diff --git a/poppler/Link.h b/poppler/Link.h index f3b2d787..1e1bfd88 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -306,25 +306,25 @@ public: }; LinkMovie(const Object *obj); - ~LinkMovie() override; - bool isOk() const override { return hasAnnotRef() || hasAnnotTitle(); } + bool isOk() const override { return hasAnnotRef() || hasAnnotTitleFlag; } LinkActionKind getKind() const override { return actionMovie; } // a movie action stores either an indirect reference to a movie annotation // or the movie annotation title bool hasAnnotRef() const { return annotRef != Ref::INVALID(); } - bool hasAnnotTitle() const { return annotTitle != nullptr; } + bool hasAnnotTitle() const { return hasAnnotTitleFlag; } const Ref *getAnnotRef() const { return &annotRef; } - const GooString *getAnnotTitle() const { return annotTitle; } + const std::string& getAnnotTitle() const { return annotTitle; } OperationType getOperation() const { return operation; } private: Ref annotRef; // Annotation - GooString *annotTitle; // T + std::string annotTitle; // T + bool hasAnnotTitleFlag; OperationType operation; // Operation }; commit 42eebb9bade006ceb602805c474bc9df5ef630b9 Author: Oliver Sander <[email protected]> Date: Sat Jan 25 20:44:56 2020 +0100 Use a std::string value in LinkRendition diff --git a/poppler/Link.cc b/poppler/Link.cc index 9433fd9f..0aca017a 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -714,7 +714,6 @@ LinkSound::LinkSound(const Object *soundObj) { LinkRendition::LinkRendition(const Object *obj) { operation = NoRendition; media = nullptr; - js = nullptr; int operationCode = -1; screenRef = Ref::INVALID(); @@ -723,11 +722,10 @@ LinkRendition::LinkRendition(const Object *obj) { Object tmp = obj->dictLookup("JS"); if (!tmp.isNull()) { if (tmp.isString()) { - js = new GooString(tmp.getString()); + js = tmp.getString()->toStr(); } else if (tmp.isStream()) { Stream *stream = tmp.getStream(); - js = new GooString(); - stream->fillGooString(js); + stream->fillString(js); } else { error(errSyntaxWarning, -1, "Invalid Rendition Action: JS not string or stream"); } @@ -736,7 +734,7 @@ LinkRendition::LinkRendition(const Object *obj) { tmp = obj->dictLookup("OP"); if (tmp.isInt()) { operationCode = tmp.getInt(); - if (!js && (operationCode < 0 || operationCode > 4)) { + if (js.empty() && (operationCode < 0 || operationCode > 4)) { error(errSyntaxWarning, -1, "Invalid Rendition Action: unrecognized operation valued: {0:d}", operationCode); } else { // retrieve rendition object @@ -773,14 +771,13 @@ LinkRendition::LinkRendition(const Object *obj) { operation = PlayRendition; break; } - } else if (!js) { + } else if (js=="") { error(errSyntaxWarning, -1, "Invalid Rendition action: no OP or JS field defined"); } } } LinkRendition::~LinkRendition() { - delete js; delete media; } diff --git a/poppler/Link.h b/poppler/Link.h index 053cbb85..f3b2d787 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -365,7 +365,7 @@ public: const MediaRendition* getMedia() const { return media; } - const GooString *getScript() const { return js; } + const std::string& getScript() const { return js; } private: @@ -375,7 +375,7 @@ private: MediaRendition* media; - GooString *js; + std::string js; }; //------------------------------------------------------------------------ diff --git a/utils/JSInfo.cc b/utils/JSInfo.cc index ba082904..aa9402d5 100644 --- a/utils/JSInfo.cc +++ b/utils/JSInfo.cc @@ -71,15 +71,13 @@ void JSInfo::scanLinkAction(LinkAction *link, const char *action, bool deleteLin if (link->getKind() == actionRendition) { LinkRendition *linkr = static_cast<LinkRendition *>(link); - if (linkr->getScript()) { + if (!linkr->getScript().empty()) { hasJS = true; if (print) { - const GooString *s = linkr->getScript(); - if (s && s->c_str()) { - fprintf(file, "%s (Rendition):\n", action); - printJS(s); - fputs("\n\n", file); - } + fprintf(file, "%s (Rendition):\n", action); + const GooString s(linkr->getScript()); + printJS(&s); + fputs("\n\n", file); } } } commit 887d35751979d3441a18db00b99cfc5b6b8d958f Author: Oliver Sander <[email protected]> Date: Sat Jan 25 17:29:54 2020 +0100 LinkSound: Store Sound in a std::unique_ptr Because the LinkSound class does own the pointer. diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 98f9dfef..102dbf3f 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -6140,7 +6140,7 @@ AnnotSound::~AnnotSound() = default; void AnnotSound::initialize(PDFDoc *docA, Dict* dict) { Object obj1 = dict->lookup("Sound"); - sound.reset(Sound::parseSound(&obj1)); + sound = Sound::parseSound(&obj1); if (!sound) { error(errSyntaxError, -1, "Bad Annot Sound"); ok = false; diff --git a/poppler/Link.cc b/poppler/Link.cc index af8d44dd..9433fd9f 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -707,10 +707,6 @@ LinkSound::LinkSound(const Object *soundObj) { } } -LinkSound::~LinkSound() { - delete sound; -} - //------------------------------------------------------------------------ // LinkRendition //------------------------------------------------------------------------ diff --git a/poppler/Link.h b/poppler/Link.h index 184e43e7..053cbb85 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -387,8 +387,6 @@ public: LinkSound(const Object *soundObj); - ~LinkSound() override; - bool isOk() const override { return sound != nullptr; } LinkActionKind getKind() const override { return actionSound; } @@ -397,7 +395,7 @@ public: bool getSynchronous() const { return sync; } bool getRepeat() const { return repeat; } bool getMix() const { return mix; } - Sound *getSound() const { return sound; } + Sound *getSound() const { return sound.get(); } private: @@ -405,7 +403,7 @@ private: bool sync; bool repeat; bool mix; - Sound *sound; + std::unique_ptr<Sound> sound; }; //------------------------------------------------------------------------ diff --git a/poppler/Sound.cc b/poppler/Sound.cc index 3e0323a7..20c1b7f8 100644 --- a/poppler/Sound.cc +++ b/poppler/Sound.cc @@ -22,7 +22,7 @@ #include "Stream.h" #include "FileSpec.h" -Sound *Sound::parseSound(Object *obj) +std::unique_ptr<Sound> Sound::parseSound(Object *obj) { // let's try to see if this Object is a Sound, according to the PDF specs // (section 9.2) @@ -40,7 +40,7 @@ Sound *Sound::parseSound(Object *obj) // the Dict must have the 'R' key of type num Object tmp = dict->lookup("R"); if (tmp.isNum()) { - return new Sound(obj); + return std::unique_ptr<Sound>(new Sound(obj)); } else { return nullptr; } diff --git a/poppler/Sound.h b/poppler/Sound.h index 802f6ff4..5c049448 100644 --- a/poppler/Sound.h +++ b/poppler/Sound.h @@ -20,6 +20,8 @@ #ifndef Sound_H #define Sound_H +#include <memory> + class Object; class Stream; @@ -41,7 +43,7 @@ class Sound { public: // Try to parse the Object obj - static Sound *parseSound(Object *obj); + static std::unique_ptr<Sound> parseSound(Object *obj); // Destructor ~Sound(); commit 57c7c79df6105300f32b1f5d8775a2be8d1b96f9 Author: Oliver Sander <[email protected]> Date: Sat Jan 25 17:29:28 2020 +0100 Do not include GooString.h It is not actually used. diff --git a/poppler/Sound.cc b/poppler/Sound.cc index fb7c4344..3e0323a7 100644 --- a/poppler/Sound.cc +++ b/poppler/Sound.cc @@ -17,7 +17,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "GooString.h" #include "Object.h" #include "Sound.h" #include "Stream.h" diff --git a/poppler/Sound.h b/poppler/Sound.h index c23fd0e1..802f6ff4 100644 --- a/poppler/Sound.h +++ b/poppler/Sound.h @@ -20,7 +20,6 @@ #ifndef Sound_H #define Sound_H -class GooString; class Object; class Stream; commit 70ba56662286257a84d0d979c8f47eb3d3a5356b Author: Oliver Sander <[email protected]> Date: Sat Jan 25 10:20:03 2020 +0100 Use a std::string value in LinkJavaScript diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index 193536c2..3851a390 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -523,11 +523,10 @@ static void build_javascript (PopplerAction *action, const LinkJavaScript *link) { - const GooString *script; - - script = link->getScript(); - if (script) - action->javascript.script = _poppler_goo_string_to_utf8 (script); + if (link->isOk()) { + const GooString script(link->getScript()); + action->javascript.script = _poppler_goo_string_to_utf8 (&script); + } } diff --git a/poppler/Link.cc b/poppler/Link.cc index f9d4edf9..af8d44dd 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -794,21 +794,16 @@ LinkRendition::~LinkRendition() { //------------------------------------------------------------------------ LinkJavaScript::LinkJavaScript(Object *jsObj) { - js = nullptr; + isValid = false; if (jsObj->isString()) { - js = new GooString(jsObj->getString()); + js = jsObj->getString()->toStr(); + isValid = true; } else if (jsObj->isStream()) { Stream *stream = jsObj->getStream(); - js = new GooString(); - stream->fillGooString(js); - } -} - -LinkJavaScript::~LinkJavaScript() { - if (js) { - delete js; + stream->fillString(js); + isValid = true; } } diff --git a/poppler/Link.h b/poppler/Link.h index 48a7a91e..184e43e7 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -418,18 +418,17 @@ public: // Build a LinkJavaScript given the action name. LinkJavaScript(Object *jsObj); - ~LinkJavaScript() override; - - bool isOk() const override { return js != nullptr; } + bool isOk() const override { return isValid; } LinkActionKind getKind() const override { return actionJavaScript; } - const GooString *getScript() const { return js; } + const std::string& getScript() const { return js; } static Object createObject(XRef *xref, const GooString &js); private: - GooString *js; + std::string js; + bool isValid; }; //------------------------------------------------------------------------ diff --git a/poppler/Stream.h b/poppler/Stream.h index 758433b3..e19790e5 100644 --- a/poppler/Stream.h +++ b/poppler/Stream.h @@ -28,6 +28,7 @@ // Copyright (C) 2013 Pino Toscano <[email protected]> // Copyright (C) 2019 Volker Krause <[email protected]> // Copyright (C) 2019 Alexander Volkov <[email protected]> +// Copyright (C) 2020 Oliver Sander <[email protected]> // // 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 @@ -129,6 +130,16 @@ public: } } + inline void fillString(std::string& s) + { + unsigned char readBuf[4096]; + int readChars; + reset(); + while ((readChars = doGetChars(4096, readBuf)) != 0) { + s.append((const char *)readBuf, readChars); + } + } + inline void fillGooString(GooString *s) { unsigned char readBuf[4096]; diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 9e08134a..39753b7e 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -289,7 +289,7 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo case actionJavaScript: { ::LinkJavaScript *ljs = (::LinkJavaScript *)a; - popplerLink = new LinkJavaScript( linkArea, UnicodeParsedString(ljs->getScript()) ); + popplerLink = new LinkJavaScript( linkArea, UnicodeParsedString( ljs->getScript() ) ); } break; diff --git a/utils/JSInfo.cc b/utils/JSInfo.cc index 1ebd8a4c..ba082904 100644 --- a/utils/JSInfo.cc +++ b/utils/JSInfo.cc @@ -59,10 +59,11 @@ void JSInfo::scanLinkAction(LinkAction *link, const char *action, bool deleteLin hasJS = true; if (print) { LinkJavaScript *linkjs = static_cast<LinkJavaScript *>(link); - const GooString *s = linkjs->getScript(); - if (s && s->c_str()) { + if (linkjs->isOk()) { + const std::string& s = linkjs->getScript(); fprintf(file, "%s:\n", action); - printJS(s); + GooString gooS = GooString(s); + printJS(&gooS); fputs("\n\n", file); } } commit e9278387cbff75ce75a87a92bc297b53256bd3fc Author: Oliver Sander <[email protected]> Date: Sat Jan 25 09:46:10 2020 +0100 Use a std::string value in LinkHide diff --git a/poppler/Link.cc b/poppler/Link.cc index 74b16d7f..f9d4edf9 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -872,13 +872,14 @@ LinkOCGState::LinkOCGState(const Object *obj) //------------------------------------------------------------------------ LinkHide::LinkHide(const Object *hideObj) { - targetName = nullptr; + hasTargetNameFlag = false; show = false; // Default if (hideObj->isDict()) { const Object targetObj = hideObj->dictLookup("T"); if (targetObj.isString()) { - targetName = targetObj.getString()->copy(); + targetName = targetObj.getString()->toStr(); + hasTargetNameFlag = true; } const Object shouldHide = hideObj->dictLookup("H"); if (shouldHide.isBool()) { @@ -887,10 +888,6 @@ LinkHide::LinkHide(const Object *hideObj) { } } -LinkHide::~LinkHide() { - delete targetName; -} - //------------------------------------------------------------------------ // LinkUnknown //------------------------------------------------------------------------ diff --git a/poppler/Link.h b/poppler/Link.h index 532eac74..48a7a91e 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -470,9 +470,7 @@ class LinkHide: public LinkAction { public: LinkHide(const Object *hideObj); - ~LinkHide() override; - - bool isOk() const override { return targetName != nullptr; } + bool isOk() const override { return hasTargetNameFlag; } LinkActionKind getKind() const override { return actionHide; } // According to spec the target can be either: @@ -484,14 +482,16 @@ public: // 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). - bool hasTargetName() const { return targetName != nullptr; } - const GooString *getTargetName() const { return targetName; } + bool hasTargetName() const { return hasTargetNameFlag; } + const std::string& getTargetName() const { return targetName; } // Should this action show or hide. bool isShowAction() const { return show; } private: - GooString *targetName; + + bool hasTargetNameFlag; + std::string targetName; bool show; }; commit 9c8d05116e8d4fc26c5a9cd5a41aadb1f39b7f9f Author: Oliver Sander <[email protected]> Date: Sun Jan 26 04:46:44 2020 +0100 Implement UnicodeParsedString for std::string diff --git a/goo/GooString.h b/goo/GooString.h index 5d17c4e5..11baa8ae 100644 --- a/goo/GooString.h +++ b/goo/GooString.h @@ -173,7 +173,9 @@ public: bool endsWith(const char *suffix) const; bool hasUnicodeMarker() const { return size() >= 2 && (*this)[0] == '\xfe' && (*this)[1] == '\xff'; } + static bool hasUnicodeMarker(const std::string& s) { return s.size() >= 2 && s[0] == '\xfe' && s[1] == '\xff'; } bool hasUnicodeMarkerLE() const { return size() >= 2 && (*this)[0] == '\xff' && (*this)[1] == '\xfe'; } + static bool hasUnicodeMarkerLE(const std::string& s) { return s.size() >= 2 && s[0] == '\xff' && s[1] == '\xfe'; } bool hasJustUnicodeMarker() const { return size() == 2 && hasUnicodeMarker(); } void prependUnicodeMarker(); diff --git a/poppler/Form.cc b/poppler/Form.cc index 2a8d5df6..60226223 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -59,12 +59,12 @@ #include "Lexer.h" //return a newly allocated char* containing an UTF16BE string of size length -char* pdfDocEncodingToUTF16 (const GooString* orig, int* length) +char* pdfDocEncodingToUTF16 (const std::string& orig, int* length) { //double size, a unicode char takes 2 char, add 2 for the unicode marker - *length = 2+2*orig->getLength(); + *length = 2+2*orig.size(); char *result = new char[(*length)]; - const char *cstring = orig->c_str(); + const char *cstring = orig.c_str(); //unicode marker result[0] = '\xfe'; result[1] = '\xff'; @@ -80,7 +80,7 @@ char* pdfDocEncodingToUTF16 (const GooString* orig, int* length) static GooString *convertToUtf16(GooString *pdfDocEncodingString) { int tmp_length; - char* tmp_str = pdfDocEncodingToUTF16(pdfDocEncodingString, &tmp_length); + char* tmp_str = pdfDocEncodingToUTF16(pdfDocEncodingString->toStr(), &tmp_length); delete pdfDocEncodingString; pdfDocEncodingString = new GooString(tmp_str, tmp_length); delete [] tmp_str; @@ -877,7 +877,7 @@ GooString* FormField::getFullyQualifiedName() { full_name->insert(0, parent_name->c_str() + 2, parent_name->getLength() - 2); // Remove the unicode BOM } else { int tmp_length; - char* tmp_str = pdfDocEncodingToUTF16(parent_name, &tmp_length); + char* tmp_str = pdfDocEncodingToUTF16(parent_name->toStr(), &tmp_length); full_name->insert(0, tmp_str + 2, tmp_length - 2); // Remove the unicode BOM delete [] tmp_str; } @@ -901,7 +901,7 @@ GooString* FormField::getFullyQualifiedName() { full_name->append(partialName->c_str() + 2, partialName->getLength() - 2); // Remove the unicode BOM } else { int tmp_length; - char* tmp_str = pdfDocEncodingToUTF16(partialName, &tmp_length); + char* tmp_str = pdfDocEncodingToUTF16(partialName->toStr(), &tmp_length); full_name->append(tmp_str + 2, tmp_length - 2); // Remove the unicode BOM delete [] tmp_str; } @@ -1189,7 +1189,7 @@ FormFieldText::FormFieldText(PDFDoc *docA, Object &&dictObj, const Ref refA, For } else if (obj1.getString()->getLength() > 0) { //non-unicode string -- assume pdfDocEncoding and try to convert to UTF16BE int tmp_length; - char* tmp_str = pdfDocEncodingToUTF16(obj1.getString(), &tmp_length); + char* tmp_str = pdfDocEncodingToUTF16(obj1.getString()->toStr(), &tmp_length); content = new GooString(tmp_str, tmp_length); delete [] tmp_str; } diff --git a/poppler/PDFDocEncoding.h b/poppler/PDFDocEncoding.h index 1d6080e1..7df3e8cb 100644 --- a/poppler/PDFDocEncoding.h +++ b/poppler/PDFDocEncoding.h @@ -24,12 +24,14 @@ #ifndef PDFDOCENCODING_H #define PDFDOCENCODING_H +#include <string> + #include "CharTypes.h" class GooString; extern const Unicode pdfDocEncoding[256]; -char* pdfDocEncodingToUTF16 (const GooString* orig, int* length); +char* pdfDocEncodingToUTF16 (const std::string& orig, int* length); #endif diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc index 81af2bed..cb5bf8f1 100644 --- a/qt5/src/poppler-private.cc +++ b/qt5/src/poppler-private.cc @@ -97,12 +97,16 @@ namespace Debug { } QString UnicodeParsedString(const GooString *s1) { - if ( !s1 || s1->getLength() == 0 ) + return (s1) ? UnicodeParsedString(s1->toStr()) : QString(); + } + + QString UnicodeParsedString(const std::string& s1) { + if ( s1.empty() ) return QString(); - if ( s1->hasUnicodeMarker() || s1->hasUnicodeMarkerLE() ) + if ( GooString::hasUnicodeMarker(s1) || GooString::hasUnicodeMarkerLE(s1) ) { - return QString::fromUtf16(reinterpret_cast<const ushort *>(s1->c_str()), s1->getLength() / 2); + return QString::fromUtf16(reinterpret_cast<const ushort *>(s1.c_str()), s1.size() / 2); } else { diff --git a/qt5/src/poppler-private.h b/qt5/src/poppler-private.h index 9131dba6..c6161364 100644 --- a/qt5/src/poppler-private.h +++ b/qt5/src/poppler-private.h @@ -71,6 +71,8 @@ namespace Poppler { POPPLER_QT5_EXPORT QString UnicodeParsedString(const GooString *s1); + POPPLER_QT5_EXPORT QString UnicodeParsedString(const std::string& s1); + POPPLER_QT5_EXPORT GooString *QStringToUnicodeGooString(const QString &s); POPPLER_QT5_EXPORT GooString *QStringToGooString(const QString &s); commit be45004531235f4dc3cce92e5a24b7cff6c385c1 Author: Oliver Sander <[email protected]> Date: Thu Jan 23 17:57:52 2020 +0100 Use a std::string value in LinkUnknown diff --git a/poppler/Link.cc b/poppler/Link.cc index 8d823919..74b16d7f 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -896,11 +896,7 @@ LinkHide::~LinkHide() { //------------------------------------------------------------------------ LinkUnknown::LinkUnknown(const char *actionA) { - action = new GooString(actionA); -} - -LinkUnknown::~LinkUnknown() { - delete action; + action = std::string(actionA ? actionA : ""); } //------------------------------------------------------------------------ diff --git a/poppler/Link.h b/poppler/Link.h index 4d10f2dd..532eac74 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -505,19 +505,17 @@ public: // Build a LinkUnknown with the specified action type. LinkUnknown(const char *actionA); - // Destructor. - ~LinkUnknown() override; - // Was the LinkUnknown create successfully? - bool isOk() const override { return action != nullptr; } + // Yes: nothing can go wrong when creating LinkUnknown objects + bool isOk() const override { return true; } // Accessors. LinkActionKind getKind() const override { return actionUnknown; } - const GooString *getAction() const { return action; } + const std::string& getAction() const { return action; } private: - GooString *action; // action subtype + std::string action; // action subtype }; //------------------------------------------------------------------------ _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
