From f124ad0b47fa9e0e433442a16af0e385cd27616f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Jun 2010 13:11:48 -0600 Subject: [PATCH 1/3] PDF metadata: Fix last character corrupted when setting metadata in encrypted files. The fix required a workaround, which means that setting metadata in encrypted PDF files will only work for values of metadata that can be encoded in the cp-1252 encoding. --- src/calibre/utils/podofo/podofo.cpp | 30 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) 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; } From 551bc933f9a09bfc6fe5a7666ed8be71dc72d867 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Jun 2010 13:17:22 -0600 Subject: [PATCH 2/3] ... --- src/calibre/manual/gui.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/manual/gui.rst b/src/calibre/manual/gui.rst index dd0451c087..d27f09705f 100644 --- a/src/calibre/manual/gui.rst +++ b/src/calibre/manual/gui.rst @@ -213,14 +213,14 @@ isbn, date, pubdate, search``. 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 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 From 1a5f73d86d03684d42f60cbab4a2b026795a0478 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Jun 2010 13:21:18 -0600 Subject: [PATCH 3/3] Add size searching to user manual --- src/calibre/manual/gui.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/calibre/manual/gui.rst b/src/calibre/manual/gui.rst index d27f09705f..02018c0b02 100644 --- a/src/calibre/manual/gui.rst +++ b/src/calibre/manual/gui.rst @@ -208,7 +208,7 @@ 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:: @@ -216,6 +216,11 @@ The syntax for searching for dates and publication dates is:: 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.