diff --git a/src/calibre/manual/gui.rst b/src/calibre/manual/gui.rst index dd0451c087..02018c0b02 100644 --- a/src/calibre/manual/gui.rst +++ b/src/calibre/manual/gui.rst @@ -208,19 +208,24 @@ You can build advanced search queries easily using the :guilabel:`Advanced Searc clicking the button |sbi|. Available fields for searching are: ``tag, title, author, publisher, series, rating cover, comments, format, -isbn, date, pubdate, search``. +isbn, date, pubdate, search, size``. To find the search name for a custom column, hover your mouse over the column header. The syntax for searching for dates and publication dates is:: pubdate:>2000-1 Will find all books published after Jan, 2000 - date:<=2000-1-3 Will find all books added to calibre beforre 3 Jan, 2000 + date:<=2000-1-3 Will find all books added to calibre before 3 Jan, 2000 pubdate:=2009 Will find all books published in 2009 +You can search for books that have a format of a certain size like this:: + + size:>1.1M Will find books with a format larger than 1.1MB + size:<=1K Will find books with a format smaller than 1KB + The special field ``search`` is used for saved searches. So if you save a search with the name "My spouse's books" you can enter ``search:"My spouses' books"`` in the search bar to reuse the saved search. More about saving searches, below. -You can search for the absence or presnce of a filed using the specia "true" and "false" values. For example:: +You can search for the absence or presence of a field using the special "true" and "false" values. For example:: cover:false Will give you all books without a cover series:true Will give you all books that belong to a series diff --git a/src/calibre/utils/podofo/podofo.cpp b/src/calibre/utils/podofo/podofo.cpp index d88e71628d..ace8c58c70 100644 --- a/src/calibre/utils/podofo/podofo.cpp +++ b/src/calibre/utils/podofo/podofo.cpp @@ -6,15 +6,10 @@ #include using namespace PoDoFo; -class podofo_pdfmem_wrapper : public PdfMemDocument { - public: - inline void set_info(PdfInfo *i) { this->SetInfo(i); } -}; - typedef struct { PyObject_HEAD /* Type-specific fields go here. */ - podofo_pdfmem_wrapper *doc; + PdfMemDocument *doc; } podofo_PDFDoc; @@ -33,7 +28,7 @@ podofo_PDFDoc_new(PyTypeObject *type, PyObject *args, PyObject *kwds) self = (podofo_PDFDoc *)type->tp_alloc(type, 0); if (self != NULL) { - self->doc = new podofo_pdfmem_wrapper(); + self->doc = new PdfMemDocument(); if (self->doc == NULL) { Py_DECREF(self); return NULL; } } @@ -171,6 +166,19 @@ podofo_convert_pystring(PyObject *py) { return ans; } +static PdfString * +podofo_convert_pystring_single_byte(PyObject *py) { + Py_UNICODE* u = PyUnicode_AS_UNICODE(py); + PyObject *s = PyUnicode_Encode(u, PyUnicode_GET_SIZE(py), "cp1252", "replace"); + if (s == NULL) { PyErr_NoMemory(); return NULL; } + PdfString *ans = new PdfString(PyString_AS_STRING(s)); + Py_DECREF(s); + if (ans == NULL) PyErr_NoMemory(); + return ans; +} + + + static PyObject * podofo_PDFDoc_getter(podofo_PDFDoc *self, int field) { @@ -219,7 +227,10 @@ podofo_PDFDoc_setter(podofo_PDFDoc *self, PyObject *val, int field) { PyErr_SetString(PyExc_Exception, "You must first load a PDF Document"); return -1; } - PdfString *s = podofo_convert_pystring(val); + PdfString *s = NULL; + + if (self->doc->GetEncrypted()) s = podofo_convert_pystring_single_byte(val); + else s = podofo_convert_pystring(val); if (s == NULL) return -1; @@ -241,9 +252,6 @@ podofo_PDFDoc_setter(podofo_PDFDoc *self, PyObject *val, int field) { return -1; } - - self->doc->set_info(info); - return 0; }