Skip to content

Commit

Permalink
Fewer goostring pointers
Browse files Browse the repository at this point in the history
Also more const functions and pointers
  • Loading branch information
svuorela authored and tsdgeos committed Jan 16, 2025
1 parent 3810d59 commit f4663b5
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 100 deletions.
14 changes: 6 additions & 8 deletions glib/poppler-document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3222,12 +3222,11 @@ static void layer_free(Layer *layer)
g_slice_free(Layer, layer);
}

static GList *get_optional_content_rbgroups(OCGs *ocg)
static GList *get_optional_content_rbgroups(const OCGs *ocg)
{
Array *rb;
GList *groups = nullptr;

rb = ocg->getRBGroupsArray();
const Array *rb = ocg->getRBGroupsArray();

if (rb) {
int i, j;
Expand Down Expand Up @@ -3276,7 +3275,7 @@ GList *_poppler_document_get_layer_rbgroup(PopplerDocument *document, Layer *lay
return nullptr;
}

static GList *get_optional_content_items_sorted(OCGs *ocg, Layer *parent, Array *order)
static GList *get_optional_content_items_sorted(const OCGs *ocg, Layer *parent, const Array *order)
{
GList *items = nullptr;
Layer *last_item = parent;
Expand Down Expand Up @@ -3309,12 +3308,11 @@ static GList *get_optional_content_items_sorted(OCGs *ocg, Layer *parent, Array
return g_list_reverse(items);
}

static GList *get_optional_content_items(OCGs *ocg)
static GList *get_optional_content_items(const OCGs *ocg)
{
Array *order;
GList *items = nullptr;

order = ocg->getOrderArray();
const Array *order = ocg->getOrderArray();

if (order) {
items = get_optional_content_items_sorted(ocg, nullptr, order);
Expand All @@ -3337,7 +3335,7 @@ GList *_poppler_document_get_layers(PopplerDocument *document)
{
if (!document->layers) {
Catalog *catalog = document->doc->getCatalog();
OCGs *ocg = catalog->getOptContentConfig();
const OCGs *ocg = catalog->getOptContentConfig();

if (!ocg) {
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion poppler/Annot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ bool Annot::isVisible(bool printing)
}

// check the OC
OCGs *optContentConfig = doc->getCatalog()->getOptContentConfig();
const OCGs *optContentConfig = doc->getCatalog()->getOptContentConfig();
if (optContentConfig) {
if (!optContentConfig->optContentIsVisible(&oc)) {
return false;
Expand Down
6 changes: 2 additions & 4 deletions poppler/Catalog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ Catalog::Catalog(PDFDoc *docA)
// get the Optional Content dictionary
Object optContentProps = catDict.dictLookup("OCProperties");
if (optContentProps.isDict()) {
optContent = new OCGs(&optContentProps, xref);
optContent = std::make_unique<OCGs>(optContentProps, xref);
if (!optContent->isOk()) {
delete optContent;
optContent = nullptr;
optContent.reset();
}
}

Expand Down Expand Up @@ -151,7 +150,6 @@ Catalog::~Catalog()
delete jsNameTree;
delete pageLabelInfo;
delete form;
delete optContent;
delete viewerPrefs;
delete structTreeRoot;
}
Expand Down
4 changes: 2 additions & 2 deletions poppler/Catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class POPPLER_PRIVATE_EXPORT Catalog
void removeFormFromAcroForm(const Ref formRef);
void setAcroFormModified();

OCGs *getOptContentConfig() { return optContent; }
const OCGs *getOptContentConfig() { return optContent.get(); }

int getPDFMajorVersion() const { return catalogPdfMajorVersion; }
int getPDFMinorVersion() const { return catalogPdfMinorVersion; }
Expand Down Expand Up @@ -296,7 +296,7 @@ class POPPLER_PRIVATE_EXPORT Catalog
Object outline; // outline dictionary
Object acroForm; // AcroForm dictionary
Object viewerPreferences; // ViewerPreference dictionary
OCGs *optContent; // Optional Content groups
std::unique_ptr<OCGs> optContent; // Optional Content groups
bool ok; // true if catalog is valid
PageLabelInfo *pageLabelInfo; // info about page labels
PageMode pageMode; // page mode
Expand Down
27 changes: 9 additions & 18 deletions poppler/FileSpec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ EmbFile::EmbFile(Object &&efStream)
// subtype is normally the mimetype
Object subtypeName = dataDict->lookup("Subtype");
if (subtypeName.isName()) {
m_mimetype = new GooString(subtypeName.getName());
m_mimetype = std::make_unique<GooString>(subtypeName.getName());
}

// paramDict corresponds to Table 3.42 in the PDF1.6 spec
Object paramDict = dataDict->lookup("Params");
if (paramDict.isDict()) {
Object paramObj = paramDict.dictLookup("ModDate");
if (paramObj.isString()) {
m_modDate = new GooString(paramObj.getString());
m_modDate = paramObj.getString()->copy();
}

paramObj = paramDict.dictLookup("CreationDate");
if (paramObj.isString()) {
m_createDate = new GooString(paramObj.getString());
m_createDate = paramObj.getString()->copy();
}

paramObj = paramDict.dictLookup("Size");
Expand All @@ -73,19 +73,13 @@ EmbFile::EmbFile(Object &&efStream)

paramObj = paramDict.dictLookup("CheckSum");
if (paramObj.isString()) {
m_checksum = new GooString(paramObj.getString());
m_checksum = paramObj.getString()->copy();
}
}
}
}

EmbFile::~EmbFile()
{
delete m_createDate;
delete m_modDate;
delete m_checksum;
delete m_mimetype;
}
EmbFile::~EmbFile() = default;

bool EmbFile::save(const std::string &path)
{
Expand Down Expand Up @@ -149,10 +143,7 @@ FileSpec::FileSpec(const Object *fileSpecA)
}
}

FileSpec::~FileSpec()
{
delete embFile;
}
FileSpec::~FileSpec() = default;

EmbFile *FileSpec::getEmbeddedFile()
{
Expand All @@ -161,13 +152,13 @@ EmbFile *FileSpec::getEmbeddedFile()
}

if (embFile) {
return embFile;
return embFile.get();
}

XRef *xref = fileSpec.getDict()->getXRef();
embFile = new EmbFile(fileStream.fetch(xref));
embFile = std::make_unique<EmbFile>(fileStream.fetch(xref));

return embFile;
return embFile.get();
}

Object FileSpec::newFileSpecObject(XRef *xref, GooFile *file, const std::string &fileName)
Expand Down
18 changes: 9 additions & 9 deletions poppler/FileSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class POPPLER_PRIVATE_EXPORT EmbFile
EmbFile &operator=(const EmbFile &) = delete;

int size() const { return m_size; }
const GooString *modDate() const { return m_modDate; }
const GooString *createDate() const { return m_createDate; }
const GooString *checksum() const { return m_checksum; }
const GooString *mimeType() const { return m_mimetype; }
const GooString *modDate() const { return m_modDate.get(); }
const GooString *createDate() const { return m_createDate.get(); }
const GooString *checksum() const { return m_checksum.get(); }
const GooString *mimeType() const { return m_mimetype.get(); }
Object *streamObject() { return &m_objStr; }
Stream *stream() { return isOk() ? m_objStr.getStream() : nullptr; }
bool isOk() const { return m_objStr.isStream(); }
Expand All @@ -43,10 +43,10 @@ class POPPLER_PRIVATE_EXPORT EmbFile
bool save2(FILE *f);

int m_size;
GooString *m_createDate;
GooString *m_modDate;
GooString *m_checksum;
GooString *m_mimetype;
std::unique_ptr<GooString> m_createDate;
std::unique_ptr<GooString> m_modDate;
std::unique_ptr<GooString> m_checksum;
std::unique_ptr<GooString> m_mimetype;
Object m_objStr;
};

Expand Down Expand Up @@ -76,7 +76,7 @@ class POPPLER_PRIVATE_EXPORT FileSpec
std::unique_ptr<GooString> fileName; // F, UF, DOS, Mac, Unix
std::unique_ptr<GooString> platformFileName;
Object fileStream; // Ref to F entry in UF
EmbFile *embFile;
std::unique_ptr<EmbFile> embFile;
std::unique_ptr<GooString> desc; // Desc
};

Expand Down
2 changes: 1 addition & 1 deletion poppler/Gfx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5038,7 +5038,7 @@ void Gfx::opBeginMarkedContent(Object args[], int numArgs)
// push a new stack entry
pushMarkedContent();

OCGs *contentConfig = catalog->getOptContentConfig();
const OCGs *contentConfig = catalog->getOptContentConfig();
const char *name0 = args[0].getName();
if (strncmp(name0, "OC", 2) == 0 && contentConfig) {
if (numArgs >= 2) {
Expand Down
36 changes: 13 additions & 23 deletions poppler/OptionalContent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <config.h>

#include "goo/gmem.h"
#include "goo/GooString.h"
#include "Error.h"
#include "OptionalContent.h"
Expand All @@ -31,12 +30,12 @@

//------------------------------------------------------------------------

OCGs::OCGs(Object *ocgObject, XRef *xref) : m_xref(xref)
OCGs::OCGs(const Object &ocgObject, XRef *xref) : m_xref(xref)
{
// we need to parse the dictionary here, and build optionalContentGroups
ok = true;

Object ocgList = ocgObject->dictLookup("OCGs");
Object ocgList = ocgObject.dictLookup("OCGs");
if (!ocgList.isArray()) {
error(errSyntaxError, -1, "Expected the optional content group list, but wasn't able to find it, or it isn't an Array");
ok = false;
Expand All @@ -60,7 +59,7 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) : m_xref(xref)
optionalContentGroups.emplace(ocgRef.getRef(), std::move(thisOptionalContentGroup));
}

Object defaultOcgConfig = ocgObject->dictLookup("D");
Object defaultOcgConfig = ocgObject.dictLookup("D");
if (!defaultOcgConfig.isDict()) {
error(errSyntaxError, -1, "Expected the default config, but wasn't able to find it, or it isn't a Dictionary");
ok = false;
Expand Down Expand Up @@ -119,13 +118,13 @@ bool OCGs::hasOCGs() const
return !(optionalContentGroups.empty());
}

OptionalContentGroup *OCGs::findOcgByRef(const Ref ref)
OptionalContentGroup *OCGs::findOcgByRef(const Ref ref) const
{
const auto ocg = optionalContentGroups.find(ref);
return ocg != optionalContentGroups.end() ? ocg->second.get() : nullptr;
}

bool OCGs::optContentIsVisible(const Object *dictRef)
bool OCGs::optContentIsVisible(const Object *dictRef) const
{
Dict *dict;
bool result = true;
Expand Down Expand Up @@ -184,7 +183,7 @@ bool OCGs::optContentIsVisible(const Object *dictRef)
return result;
}

bool OCGs::evalOCVisibilityExpr(const Object *expr, int recursion)
bool OCGs::evalOCVisibilityExpr(const Object *expr, int recursion) const
{
OptionalContentGroup *ocg;
bool ret;
Expand Down Expand Up @@ -231,7 +230,7 @@ bool OCGs::evalOCVisibilityExpr(const Object *expr, int recursion)
return ret;
}

bool OCGs::allOn(Array *ocgArray)
bool OCGs::allOn(Array *ocgArray) const
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
const Object &ocgItem = ocgArray->getNF(i);
Expand All @@ -245,7 +244,7 @@ bool OCGs::allOn(Array *ocgArray)
return true;
}

bool OCGs::allOff(Array *ocgArray)
bool OCGs::allOff(Array *ocgArray) const
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
const Object &ocgItem = ocgArray->getNF(i);
Expand All @@ -259,7 +258,7 @@ bool OCGs::allOff(Array *ocgArray)
return true;
}

bool OCGs::anyOn(Array *ocgArray)
bool OCGs::anyOn(Array *ocgArray) const
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
const Object &ocgItem = ocgArray->getNF(i);
Expand All @@ -273,7 +272,7 @@ bool OCGs::anyOn(Array *ocgArray)
return false;
}

bool OCGs::anyOff(Array *ocgArray)
bool OCGs::anyOff(Array *ocgArray) const
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
const Object &ocgItem = ocgArray->getNF(i);
Expand All @@ -295,7 +294,7 @@ OptionalContentGroup::OptionalContentGroup(Dict *ocgDict) : m_name(nullptr)
if (!ocgName.isString()) {
error(errSyntaxWarning, -1, "Expected the name of the OCG, but wasn't able to find it, or it isn't a String");
} else {
m_name = new GooString(ocgName.getString());
m_name = ocgName.getString()->copy();
}

viewState = printState = ocUsageUnset;
Expand Down Expand Up @@ -326,15 +325,9 @@ OptionalContentGroup::OptionalContentGroup(Dict *ocgDict) : m_name(nullptr)
}
}

OptionalContentGroup::OptionalContentGroup(GooString *label)
{
m_name = label;
m_state = On;
}

const GooString *OptionalContentGroup::getName() const
{
return m_name;
return m_name.get();
}

void OptionalContentGroup::setRef(const Ref ref)
Expand All @@ -347,7 +340,4 @@ Ref OptionalContentGroup::getRef() const
return m_ref;
}

OptionalContentGroup::~OptionalContentGroup()
{
delete m_name;
}
OptionalContentGroup::~OptionalContentGroup() = default;
Loading

0 comments on commit f4663b5

Please sign in to comment.