glib/poppler-action.cc | 12 ++++---- poppler/Link.cc | 58 +++++++++++------------------------------- poppler/Link.h | 17 +++++------- qt5/src/poppler-optcontent.cc | 14 +++++----- 4 files changed, 37 insertions(+), 64 deletions(-)
New commits: commit 42d5e54134ca82c96cb29e672e71e924d75526cf Author: Oliver Sander <[email protected]> Date: Tue Dec 17 21:06:31 2019 +0100 Make StateList assignable Because it is already copy-constructible, and having one without the other is weird. diff --git a/poppler/Link.h b/poppler/Link.h index be77ece9..4477dd3f 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -451,8 +451,6 @@ public: struct StateList { StateList() = default; ~StateList() = default; - StateList(const StateList &) = default; - StateList& operator=(const StateList &) = delete; State st; std::vector<Ref> list; }; commit 62ae50571b1b0dca5369be76a962380b4c6e276a Author: Oliver Sander <[email protected]> Date: Sat Dec 14 22:19:53 2019 +0100 LinkOCGState: Make stateList a std::vector of objects diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index d449bdcf..193536c2 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -579,7 +579,7 @@ build_ocg_state (PopplerDocument *document, PopplerAction *action, const LinkOCGState *ocg_state) { - const std::vector<LinkOCGState::StateList*>& st_list = ocg_state->getStateList(); + const std::vector<LinkOCGState::StateList>& st_list = ocg_state->getStateList(); bool preserve_rb = ocg_state->getPreserveRB(); GList *layer_state = nullptr; @@ -588,10 +588,10 @@ build_ocg_state (PopplerDocument *document, return; } - for (const LinkOCGState::StateList *list : st_list) { + for (const LinkOCGState::StateList& list : st_list) { PopplerActionLayer *action_layer = g_slice_new0 (PopplerActionLayer); - switch (list->st) { + switch (list.st) { case LinkOCGState::On: action_layer->action = POPPLER_ACTION_LAYER_ON; break; @@ -603,7 +603,7 @@ build_ocg_state (PopplerDocument *document, break; } - for (const Ref& ref : list->list) { + for (const Ref& ref : list.list) { PopplerLayer *layer = get_layer_for_ref (document, document->layers, ref, preserve_rb); action_layer->layers = g_list_prepend (action_layer->layers, layer); diff --git a/poppler/Link.cc b/poppler/Link.cc index a821b2b4..a25037ae 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -843,40 +843,35 @@ LinkOCGState::LinkOCGState(const Object *obj) Object obj1 = obj->dictLookup("State"); if (obj1.isArray()) { - StateList *stList = nullptr; + StateList stList; for (int i = 0; i < obj1.arrayGetLength(); ++i) { const Object &obj2 = obj1.arrayGetNF(i); if (obj2.isName()) { - if (stList) + if (!stList.list.empty()) stateList.push_back(stList); const char *name = obj2.getName(); - stList = new StateList(); + stList.list.clear(); if (!strcmp (name, "ON")) { - stList->st = On; + stList.st = On; } else if (!strcmp (name, "OFF")) { - stList->st = Off; + stList.st = Off; } else if (!strcmp (name, "Toggle")) { - stList->st = Toggle; + stList.st = Toggle; } else { error(errSyntaxWarning, -1, "Invalid name '{0:s}' in OCG Action state array", name); - delete stList; - stList = nullptr; + isValid = false; } } else if (obj2.isRef()) { - if (stList) { - stList->list.push_back(obj2.getRef()); - } else { - error(errSyntaxWarning, -1, "Invalid OCG Action State array, expected name instead of ref"); - } + stList.list.push_back(obj2.getRef()); } else { error(errSyntaxWarning, -1, "Invalid item in OCG Action State array"); isValid = false; } } // Add the last group - if (stList) + if (!stList.list.empty()) stateList.push_back(stList); } else { error(errSyntaxWarning, -1, "Invalid OCGState action"); @@ -889,12 +884,6 @@ LinkOCGState::LinkOCGState(const Object *obj) } } -LinkOCGState::~LinkOCGState() { - for (auto entry : stateList) { - delete entry; - } -} - //------------------------------------------------------------------------ // LinkHide //------------------------------------------------------------------------ diff --git a/poppler/Link.h b/poppler/Link.h index 59c224f0..be77ece9 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -441,7 +441,7 @@ class LinkOCGState: public LinkAction { public: LinkOCGState(const Object *obj); - ~LinkOCGState() override; + ~LinkOCGState() override = default; bool isOk() const override { return isValid; } @@ -451,17 +451,17 @@ public: struct StateList { StateList() = default; ~StateList() = default; - StateList(const StateList &) = delete; + StateList(const StateList &) = default; StateList& operator=(const StateList &) = delete; State st; std::vector<Ref> list; }; - const std::vector<StateList*>& getStateList() const { return stateList; } + const std::vector<StateList>& getStateList() const { return stateList; } bool getPreserveRB() const { return preserveRB; } private: - std::vector<StateList*> stateList; + std::vector<StateList> stateList; bool isValid; bool preserveRB; }; diff --git a/qt5/src/poppler-optcontent.cc b/qt5/src/poppler-optcontent.cc index 5aac5c92..ad959db8 100644 --- a/qt5/src/poppler-optcontent.cc +++ b/qt5/src/poppler-optcontent.cc @@ -401,15 +401,15 @@ namespace Poppler QSet<OptContentItem *> changedItems; - const std::vector<::LinkOCGState::StateList*>& statesList = popplerLinkOCGState->getStateList(); - for (const ::LinkOCGState::StateList *stateList : statesList) { - const std::vector<Ref>& refsList = stateList->list; + const std::vector<::LinkOCGState::StateList>& statesList = popplerLinkOCGState->getStateList(); + for (const ::LinkOCGState::StateList& stateList : statesList) { + const std::vector<Ref>& refsList = stateList.list; for (const Ref& ref : refsList) { OptContentItem *item = d->itemFromRef(QString::number(ref.num)); - if (stateList->st == ::LinkOCGState::On) { + if (stateList.st == ::LinkOCGState::On) { item->setState(OptContentItem::On, popplerLinkOCGState->getPreserveRB(), changedItems); - } else if (stateList->st == ::LinkOCGState::Off) { + } else if (stateList.st == ::LinkOCGState::Off) { item->setState(OptContentItem::Off, popplerLinkOCGState->getPreserveRB(), changedItems); } else { OptContentItem::ItemState newState = item->state() == OptContentItem::On ? OptContentItem::Off : OptContentItem::On; commit bd8d88f0db6954aa5d4181c0a5b4d0e19a635359 Author: Oliver Sander <[email protected]> Date: Sat Dec 14 21:48:07 2019 +0100 LinkOCGState: Replace std::vector* by std::vector diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index 2117693f..d449bdcf 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -603,7 +603,7 @@ build_ocg_state (PopplerDocument *document, break; } - for (const Ref& ref : (*list->list)) { + for (const Ref& ref : list->list) { PopplerLayer *layer = get_layer_for_ref (document, document->layers, ref, preserve_rb); action_layer->layers = g_list_prepend (action_layer->layers, layer); diff --git a/poppler/Link.cc b/poppler/Link.cc index d1d56b0b..a821b2b4 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -853,7 +853,6 @@ LinkOCGState::LinkOCGState(const Object *obj) const char *name = obj2.getName(); stList = new StateList(); - stList->list = new std::vector<Ref>(); if (!strcmp (name, "ON")) { stList->st = On; } else if (!strcmp (name, "OFF")) { @@ -867,7 +866,7 @@ LinkOCGState::LinkOCGState(const Object *obj) } } else if (obj2.isRef()) { if (stList) { - stList->list->push_back(obj2.getRef()); + stList->list.push_back(obj2.getRef()); } else { error(errSyntaxWarning, -1, "Invalid OCG Action State array, expected name instead of ref"); } @@ -896,12 +895,6 @@ LinkOCGState::~LinkOCGState() { } } -LinkOCGState::StateList::~StateList() { - if (list) { - delete list; - } -} - //------------------------------------------------------------------------ // LinkHide //------------------------------------------------------------------------ diff --git a/poppler/Link.h b/poppler/Link.h index 8b87f375..59c224f0 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -449,12 +449,12 @@ public: enum State { On, Off, Toggle}; struct StateList { - StateList() { list = nullptr; } - ~StateList(); + StateList() = default; + ~StateList() = default; StateList(const StateList &) = delete; StateList& operator=(const StateList &) = delete; State st; - std::vector<Ref> *list; + std::vector<Ref> list; }; const std::vector<StateList*>& getStateList() const { return stateList; } diff --git a/qt5/src/poppler-optcontent.cc b/qt5/src/poppler-optcontent.cc index 177fbe04..5aac5c92 100644 --- a/qt5/src/poppler-optcontent.cc +++ b/qt5/src/poppler-optcontent.cc @@ -403,8 +403,8 @@ namespace Poppler const std::vector<::LinkOCGState::StateList*>& statesList = popplerLinkOCGState->getStateList(); for (const ::LinkOCGState::StateList *stateList : statesList) { - const std::vector<Ref> *refsList = stateList->list; - for (const Ref& ref : *refsList) { + const std::vector<Ref>& refsList = stateList->list; + for (const Ref& ref : refsList) { OptContentItem *item = d->itemFromRef(QString::number(ref.num)); if (stateList->st == ::LinkOCGState::On) { commit 27958cb0c7ec165ab65433dd602387eb37eb7650 Author: Oliver Sander <[email protected]> Date: Sat Dec 14 21:41:39 2019 +0100 StateList: Replace std::vector<Ref*> by std::vector<Ref> A Ref is really just two ints. Let's not call malloc separately for each of them. diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index 34536782..2117693f 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -544,7 +544,7 @@ build_rendition (PopplerAction *action, static PopplerLayer * get_layer_for_ref (PopplerDocument *document, GList *layers, - const Ref *ref, + const Ref ref, gboolean preserve_rb) { GList *l; @@ -555,7 +555,7 @@ get_layer_for_ref (PopplerDocument *document, if (layer->oc) { const Ref ocgRef = layer->oc->getRef(); - if (*ref == ocgRef) { + if (ref == ocgRef) { GList *rb_group = nullptr; if (preserve_rb) @@ -603,7 +603,7 @@ build_ocg_state (PopplerDocument *document, break; } - for (const Ref *ref : (*list->list)) { + for (const Ref& ref : (*list->list)) { PopplerLayer *layer = get_layer_for_ref (document, document->layers, ref, preserve_rb); action_layer->layers = g_list_prepend (action_layer->layers, layer); diff --git a/poppler/Link.cc b/poppler/Link.cc index 4acc05eb..d1d56b0b 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -853,7 +853,7 @@ LinkOCGState::LinkOCGState(const Object *obj) const char *name = obj2.getName(); stList = new StateList(); - stList->list = new std::vector<Ref*>(); + stList->list = new std::vector<Ref>(); if (!strcmp (name, "ON")) { stList->st = On; } else if (!strcmp (name, "OFF")) { @@ -867,10 +867,7 @@ LinkOCGState::LinkOCGState(const Object *obj) } } else if (obj2.isRef()) { if (stList) { - Ref ocgRef = obj2.getRef(); - Ref *item = new Ref(); - *item = ocgRef; - stList->list->push_back(item); + stList->list->push_back(obj2.getRef()); } else { error(errSyntaxWarning, -1, "Invalid OCG Action State array, expected name instead of ref"); } @@ -901,9 +898,6 @@ LinkOCGState::~LinkOCGState() { LinkOCGState::StateList::~StateList() { if (list) { - for (auto entry : *list) { - delete entry; - } delete list; } } diff --git a/poppler/Link.h b/poppler/Link.h index b329e38a..8b87f375 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -454,7 +454,7 @@ public: StateList(const StateList &) = delete; StateList& operator=(const StateList &) = delete; State st; - std::vector<Ref*> *list; + std::vector<Ref> *list; }; const std::vector<StateList*>& getStateList() const { return stateList; } diff --git a/qt5/src/poppler-optcontent.cc b/qt5/src/poppler-optcontent.cc index d64d2452..177fbe04 100644 --- a/qt5/src/poppler-optcontent.cc +++ b/qt5/src/poppler-optcontent.cc @@ -403,9 +403,9 @@ namespace Poppler const std::vector<::LinkOCGState::StateList*>& statesList = popplerLinkOCGState->getStateList(); for (const ::LinkOCGState::StateList *stateList : statesList) { - const std::vector<Ref*> *refsList = stateList->list; - for (const Ref *ref : *refsList) { - OptContentItem *item = d->itemFromRef(QString::number(ref->num)); + const std::vector<Ref> *refsList = stateList->list; + for (const Ref& ref : *refsList) { + OptContentItem *item = d->itemFromRef(QString::number(ref.num)); if (stateList->st == ::LinkOCGState::On) { item->setState(OptContentItem::On, popplerLinkOCGState->getPreserveRB(), changedItems); commit a5a713621649d916508e8695169df9221b2b3f9d Author: Oliver Sander <[email protected]> Date: Sat Dec 14 21:26:38 2019 +0100 LinkOCGState: Replace std::vector* by std::vector The LinkOCGState has a 'stateList' member, which previously was a pointer to a std::vector. As a std::vector is little more than a pointer itself, one may as well keep it directly within the LinkOCGState object. This is what the patch does. diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index f6fed6ba..34536782 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -579,7 +579,7 @@ build_ocg_state (PopplerDocument *document, PopplerAction *action, const LinkOCGState *ocg_state) { - const std::vector<LinkOCGState::StateList*> *st_list = ocg_state->getStateList(); + const std::vector<LinkOCGState::StateList*>& st_list = ocg_state->getStateList(); bool preserve_rb = ocg_state->getPreserveRB(); GList *layer_state = nullptr; @@ -588,7 +588,7 @@ build_ocg_state (PopplerDocument *document, return; } - for (const LinkOCGState::StateList *list : *st_list) { + for (const LinkOCGState::StateList *list : st_list) { PopplerActionLayer *action_layer = g_slice_new0 (PopplerActionLayer); switch (list->st) { diff --git a/poppler/Link.cc b/poppler/Link.cc index 35ddfb92..4acc05eb 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -836,8 +836,9 @@ Object LinkJavaScript::createObject(XRef *xref, const GooString &js) //------------------------------------------------------------------------ // LinkOCGState //------------------------------------------------------------------------ -LinkOCGState::LinkOCGState(const Object *obj) { - stateList = new std::vector<StateList*>(); +LinkOCGState::LinkOCGState(const Object *obj) +: isValid(true) +{ preserveRB = true; Object obj1 = obj->dictLookup("State"); @@ -848,7 +849,7 @@ LinkOCGState::LinkOCGState(const Object *obj) { const Object &obj2 = obj1.arrayGetNF(i); if (obj2.isName()) { if (stList) - stateList->push_back(stList); + stateList.push_back(stList); const char *name = obj2.getName(); stList = new StateList(); @@ -875,15 +876,15 @@ LinkOCGState::LinkOCGState(const Object *obj) { } } else { error(errSyntaxWarning, -1, "Invalid item in OCG Action State array"); + isValid = false; } } // Add the last group if (stList) - stateList->push_back(stList); + stateList.push_back(stList); } else { error(errSyntaxWarning, -1, "Invalid OCGState action"); - delete stateList; - stateList = nullptr; + isValid = false; } obj1 = obj->dictLookup("PreserveRB"); @@ -893,11 +894,8 @@ LinkOCGState::LinkOCGState(const Object *obj) { } LinkOCGState::~LinkOCGState() { - if (stateList) { - for (auto entry : *stateList) { - delete entry; - } - delete stateList; + for (auto entry : stateList) { + delete entry; } } diff --git a/poppler/Link.h b/poppler/Link.h index 14665a29..b329e38a 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -443,7 +443,7 @@ public: ~LinkOCGState() override; - bool isOk() const override { return stateList != nullptr; } + bool isOk() const override { return isValid; } LinkActionKind getKind() const override { return actionOCGState; } @@ -457,11 +457,12 @@ public: std::vector<Ref*> *list; }; - const std::vector<StateList*> *getStateList() const { return stateList; } + const std::vector<StateList*>& getStateList() const { return stateList; } bool getPreserveRB() const { return preserveRB; } private: - std::vector<StateList*> *stateList; + std::vector<StateList*> stateList; + bool isValid; bool preserveRB; }; diff --git a/qt5/src/poppler-optcontent.cc b/qt5/src/poppler-optcontent.cc index 1a659bf6..d64d2452 100644 --- a/qt5/src/poppler-optcontent.cc +++ b/qt5/src/poppler-optcontent.cc @@ -401,8 +401,8 @@ namespace Poppler QSet<OptContentItem *> changedItems; - const std::vector<::LinkOCGState::StateList*> *statesList = popplerLinkOCGState->getStateList(); - for (const ::LinkOCGState::StateList *stateList : *statesList) { + const std::vector<::LinkOCGState::StateList*>& statesList = popplerLinkOCGState->getStateList(); + for (const ::LinkOCGState::StateList *stateList : statesList) { const std::vector<Ref*> *refsList = stateList->list; for (const Ref *ref : *refsList) { OptContentItem *item = d->itemFromRef(QString::number(ref->num)); _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
