Commit 70ba5666 authored by Oliver Sander's avatar Oliver Sander Committed by Albert Astals Cid

Use a std::string value in LinkJavaScript

parent e9278387
......@@ -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);
}
}
......
......@@ -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;
}
}
......
......@@ -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;
};
//------------------------------------------------------------------------
......
......@@ -28,6 +28,7 @@
// Copyright (C) 2013 Pino Toscano <pino@kde.org>
// Copyright (C) 2019 Volker Krause <vkrause@kde.org>
// Copyright (C) 2019 Alexander Volkov <a.volkov@rusbitech.ru>
// Copyright (C) 2020 Oliver Sander <oliver.sander@tu-dresden.de>
//
// 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];
......
......@@ -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;
......
......@@ -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);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment