diff --git a/src/calibre/utils/podofo/doc.cpp b/src/calibre/utils/podofo/doc.cpp index ed91b02cd7..0134b28d02 100644 --- a/src/calibre/utils/podofo/doc.cpp +++ b/src/calibre/utils/podofo/doc.cpp @@ -130,9 +130,9 @@ PDFDoc_save_to_fileobj(PDFDoc *self, PyObject *args) { static PyObject * PDFDoc_uncompress_pdf(PDFDoc *self, PyObject *args) { - for (TIVecObjects it = self->doc->GetObjects().begin(); it != self->doc->GetObjects().end(); it++) { - if((*it)->HasStream()) { - PdfMemStream* stream = dynamic_cast((*it)->GetStream()); + for (auto &it : self->doc->GetObjects()) { + if(it->HasStream()) { + PdfMemStream* stream = dynamic_cast(it->GetStream()); stream->Uncompress(); } } @@ -175,16 +175,13 @@ PDFDoc_image_count(PDFDoc *self, PyObject *args) { const PdfObject* obj_type = NULL; const PdfObject* obj_sub_type = NULL; try { - TCIVecObjects it = self->doc->GetObjects().begin(); - while( it != self->doc->GetObjects().end() ) { - if( (*it)->IsDictionary() ) { - obj_type = (*it)->GetDictionary().GetKey( PdfName::KeyType ); - obj_sub_type = (*it)->GetDictionary().GetKey( PdfName::KeySubtype ); + for (auto &it : self->doc->GetObjects()) { + if( it->IsDictionary() ) { + obj_type = it->GetDictionary().GetKey( PdfName::KeyType ); + obj_sub_type = it->GetDictionary().GetKey( PdfName::KeySubtype ); if( ( obj_type && obj_type->IsName() && ( obj_type->GetName().GetName() == "XObject" ) ) || ( obj_sub_type && obj_sub_type->IsName() && ( obj_sub_type->GetName().GetName() == "Image" ) ) ) count++; - self->doc->FreeObjectMemory( *it ); } - it++; } } catch(const PdfError & err) { podofo_set_exception(err); diff --git a/src/calibre/utils/podofo/fonts.cpp b/src/calibre/utils/podofo/fonts.cpp index 0454bcc20b..e5657fed6f 100644 --- a/src/calibre/utils/podofo/fonts.cpp +++ b/src/calibre/utils/podofo/fonts.cpp @@ -170,15 +170,15 @@ list_fonts(PDFDoc *self, PyObject *args) { pyunique_ptr ans(PyList_New(0)); if (!ans) return NULL; const PdfVecObjects &objects = self->doc->GetObjects(); - for (TCIVecObjects it = objects.begin(); it != objects.end(); it++) { - if ((*it)->IsDictionary()) { - const PdfDictionary &dict = (*it)->GetDictionary(); + for (auto &it : objects) { + if (it->IsDictionary()) { + const PdfDictionary &dict = it->GetDictionary(); if (dictionary_has_key_name(dict, PdfName::KeyType, "Font") && dict.HasKey("BaseFont")) { const std::string &name = dict.GetKey("BaseFont")->GetName().GetName(); const std::string &subtype = dict.GetKey(PdfName::KeySubtype)->GetName().GetName(); - const PdfReference &ref = (*it)->Reference(); + const PdfReference &ref = it->Reference(); unsigned long num = ref.ObjectNumber(), generation = ref.GenerationNumber(); - const PdfObject *descriptor = (*it)->GetIndirectKey("FontDescriptor"); + const PdfObject *descriptor = it->GetIndirectKey("FontDescriptor"); pyunique_ptr descendant_font, stream_ref, encoding, w, w2; PyBytesOutputStream stream_data, to_unicode; if (dict.HasKey("W")) {