mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Also delete DescendantFonts of Type0 fonts
This commit is contained in:
parent
7f3bd476d3
commit
6057bcbb5a
@ -251,6 +251,8 @@ typedef std::unordered_map<PdfReference, unsigned long, PdfReferenceHasher> char
|
||||
|
||||
PyObject*
|
||||
remove_unused_fonts(PDFDoc *self, PyObject *args) {
|
||||
unsigned long count = 0;
|
||||
try {
|
||||
unordered_reference_set used_fonts;
|
||||
for (int i = 0; i < self->doc->GetPageCount(); i++) {
|
||||
PdfPage *page = self->doc->GetPage(i);
|
||||
@ -280,7 +282,6 @@ remove_unused_fonts(PDFDoc *self, PyObject *args) {
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long count = 0;
|
||||
for (auto &ref : all_fonts) {
|
||||
if (used_fonts.find(ref) == used_fonts.end()) {
|
||||
PdfObject *font = objects.GetObject(ref);
|
||||
@ -290,6 +291,11 @@ remove_unused_fonts(PDFDoc *self, PyObject *args) {
|
||||
for (auto &x : font->GetIndirectKey("CharProcs")->GetDictionary().GetKeys()) {
|
||||
charprocs_usage[x.second->GetReference()] -= 1;
|
||||
}
|
||||
} else {
|
||||
for (auto &x : font->GetIndirectKey("DescendantFonts")->GetArray()) {
|
||||
PdfObject *dfont = objects.GetObject(x.GetReference());
|
||||
if (dfont) remove_font(objects, dfont);
|
||||
}
|
||||
}
|
||||
remove_font(objects, font);
|
||||
}
|
||||
@ -301,6 +307,8 @@ remove_unused_fonts(PDFDoc *self, PyObject *args) {
|
||||
delete objects.RemoveObject(x.first);
|
||||
}
|
||||
}
|
||||
} catch(const PdfError &err) { podofo_set_exception(err); return NULL; }
|
||||
|
||||
return Py_BuildValue("k", count);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user