|
114 | 114 | #include <pdf.h>
|
115 | 115 | #include <zlib.h>
|
116 | 116 | #include <time.h>
|
| 117 | +#include <fitz/config.h> |
117 | 118 | char *JM_Python_str_AsChar(PyObject *str);
|
118 | 119 | %}
|
119 | 120 |
|
@@ -2667,7 +2668,6 @@ fannot._erase()
|
2667 | 2668 | fz_append_string(gctx, nres, data);
|
2668 | 2669 | fz_append_string(gctx, nres, " Do Q ");
|
2669 | 2670 |
|
2670 |
| - //JM_extend_contents(gctx, pdfout, tpageref, nres, overlay); |
2671 | 2671 | JM_insert_contents(gctx, pdfout, tpageref, nres, overlay);
|
2672 | 2672 | fz_drop_buffer(gctx, nres);
|
2673 | 2673 | }
|
@@ -5397,79 +5397,65 @@ struct fz_annot_s
|
5397 | 5397 | PyObject *setInfo(PyObject *info)
|
5398 | 5398 | {
|
5399 | 5399 | pdf_annot *annot = pdf_annot_from_fz_annot(gctx, $self);
|
5400 |
| - pdf_document *pdf = NULL; |
5401 |
| - if (annot) pdf = annot->page->doc; |
5402 |
| - PyObject *value = NULL; |
5403 | 5400 | char *uc = NULL;
|
5404 |
| - // ensure we have valid dictionary keys ... |
5405 |
| - int dictvalid = checkDictKeys(info, "content", "title", "modDate", "creationDate", "subject", "name", 0); |
| 5401 | + |
5406 | 5402 | // use this to indicate a 'markup' annot type
|
5407 | 5403 | int is_markup = pdf_annot_has_author(gctx, annot);
|
5408 | 5404 | fz_var(is_markup);
|
5409 | 5405 | fz_var(annot);
|
5410 |
| - fz_var(pdf); |
5411 | 5406 | fz_try(gctx)
|
5412 | 5407 | {
|
5413 | 5408 | assert_PDF(annot);
|
5414 | 5409 | if (!PyDict_Check(info))
|
5415 | 5410 | THROWMSG("info not a dict");
|
5416 |
| - if (!dictvalid) |
5417 |
| - THROWMSG("invalid key in info dict"); |
5418 | 5411 |
|
5419 | 5412 | // contents
|
5420 |
| - value = PyDict_GetItemString(info, "content"); |
5421 |
| - if (value) |
| 5413 | + uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "content")); |
| 5414 | + if (uc) |
5422 | 5415 | {
|
5423 |
| - uc = JM_Python_str_AsChar(value); |
5424 |
| - if (uc) pdf_set_annot_contents(gctx, annot, uc); |
| 5416 | + pdf_set_annot_contents(gctx, annot, uc); |
5425 | 5417 | JM_Python_str_DelForPy3(uc);
|
5426 | 5418 | }
|
5427 |
| - Py_XDECREF(value); |
5428 | 5419 |
|
5429 |
| - // title (= author) |
5430 |
| - value = PyDict_GetItemString(info, "title"); |
5431 |
| - if (value && is_markup) |
| 5420 | + if (is_markup) |
5432 | 5421 | {
|
5433 |
| - uc = JM_Python_str_AsChar(value); |
5434 |
| - if (uc) pdf_set_annot_author(gctx, annot, uc); |
5435 |
| - JM_Python_str_DelForPy3(uc); |
5436 |
| - } |
5437 |
| - Py_XDECREF(value); |
| 5422 | + // title (= author) |
| 5423 | + uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "title")); |
| 5424 | + if (uc) |
| 5425 | + { |
| 5426 | + pdf_set_annot_author(gctx, annot, uc); |
| 5427 | + JM_Python_str_DelForPy3(uc); |
| 5428 | + } |
5438 | 5429 |
|
5439 |
| - // creation date |
5440 |
| - value = PyDict_GetItemString(info, "creationDate"); |
5441 |
| - if (value && is_markup) |
5442 |
| - { |
5443 |
| - uc = JM_Python_str_AsChar(value); |
5444 |
| - if (uc) pdf_dict_puts_drop(gctx, annot->obj, "CreationDate", |
5445 |
| - pdf_new_string(gctx, pdf, uc, strlen(uc))); |
5446 |
| - JM_Python_str_DelForPy3(uc); |
5447 |
| - } |
5448 |
| - Py_XDECREF(value); |
| 5430 | + // creation date |
| 5431 | + uc = JM_Python_str_AsChar(PyDict_GetItemString(info, |
| 5432 | + "creationDate")); |
| 5433 | + if (uc) |
| 5434 | + { |
| 5435 | + pdf_dict_put_text_string(gctx, annot->obj, |
| 5436 | + PDF_NAME_CreationDate, uc); |
| 5437 | + JM_Python_str_DelForPy3(uc); |
| 5438 | + } |
5449 | 5439 |
|
5450 |
| - // mod date |
5451 |
| - value = PyDict_GetItemString(info, "modDate"); |
5452 |
| - if (value && is_markup) |
5453 |
| - { |
5454 |
| - uc = JM_Python_str_AsChar(value); |
5455 |
| - if (uc) pdf_dict_put_drop(gctx, annot->obj, PDF_NAME_M, |
5456 |
| - pdf_new_string(gctx, pdf, uc, strlen(uc))); |
5457 |
| - JM_Python_str_DelForPy3(uc); |
5458 |
| - } |
5459 |
| - Py_XDECREF(value); |
| 5440 | + // mod date |
| 5441 | + uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "modDate")); |
| 5442 | + if (uc) |
| 5443 | + { |
| 5444 | + pdf_dict_put_text_string(gctx, annot->obj, |
| 5445 | + PDF_NAME_M, uc); |
| 5446 | + JM_Python_str_DelForPy3(uc); |
| 5447 | + } |
5460 | 5448 |
|
5461 |
| - // subject |
5462 |
| - value = PyDict_GetItemString(info, "subject"); |
5463 |
| - if (value && is_markup) |
5464 |
| - { |
5465 |
| - uc = JM_Python_str_AsChar(value); |
5466 |
| - if (uc) pdf_dict_puts_drop(gctx, annot->obj, "Subj", |
5467 |
| - pdf_new_string(gctx, pdf, uc, strlen(uc))); |
5468 |
| - JM_Python_str_DelForPy3(uc); |
| 5449 | + // subject |
| 5450 | + uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "subject")); |
| 5451 | + if (uc) |
| 5452 | + { |
| 5453 | + pdf_dict_puts_drop(gctx, annot->obj, "Subj", |
| 5454 | + pdf_new_text_string(gctx, NULL, uc)); |
| 5455 | + JM_Python_str_DelForPy3(uc); |
| 5456 | + } |
5469 | 5457 | }
|
5470 |
| - Py_XDECREF(value); |
5471 | 5458 | }
|
5472 |
| - fz_always(gctx) Py_XDECREF(value); |
5473 | 5459 | fz_catch(gctx) return NULL;
|
5474 | 5460 | return NONE;
|
5475 | 5461 | }
|
|
0 commit comments