mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use range iteration for some more loops
This commit is contained in:
parent
bc68e6e735
commit
1fbfffd772
@ -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<PdfMemStream*>((*it)->GetStream());
|
||||
for (auto &it : self->doc->GetObjects()) {
|
||||
if(it->HasStream()) {
|
||||
PdfMemStream* stream = dynamic_cast<PdfMemStream*>(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);
|
||||
|
@ -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")) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user