El mié, 22-04-2009 a las 00:36 +0200, Albert Astals Cid escribió:
> A Dimarts, 21 d'abril de 2009, Carlos Garcia Campos va escriure:
> > El lun, 20-04-2009 a las 21:56 +0200, Albert Astals Cid escribió:
> > > A Dilluns, 20 d'abril de 2009, Carlos Garcia Campos va escriure:
> > > > El dom, 19-04-2009 a las 23:41 +0200, Albert Astals Cid escribió:
> > > > > A Dissabte, 18 d'abril de 2009, Carlos Garcia Campos va escriure:
> > > > > > Hi all,
> > > > > >
> > > > > > we are still lacking write support in annotations. This patch, to
> > > > > > be able to modify the contents of an annotation, it's just a first
> > > > > > step.
> > > > > >
> > > > > > ok to commit?
> > > > >
> > > > > contents = new GooString(new_content);
> > > > >
> > > > > crashes if new_content is null, so you either protect this or remove
> > > > > the protection in
> > > >
> > > > fair enough. It makes me wonder what should we do in this case, I mean,
> > > > the Contents field is optional in the annotation array, should we
> > > > remove the key from the dict when NULL is set? or shouldn't we even
> > > > allow passing NULL to setContents()?
> > >
> > > I just would mark on the header that passing a NULL value to set contents
> > > is not ok, if you want to clear something just pass GooString() and
> > > that's all
> > >
> > > > > if (new_content && !contents->hasUnicodeMarker()) {
> > > > >
> > > > > I think obj1 is missing a free().
> > > >
> > > > No, because it's owned by the Dict.
> > >
> > > Right, i got tricked thinking that operator= in Object was the same as
> > > copy.
> > >
> > > > > Also you should probably update the modified member too.
> > > >
> > > > What do you mean with the modified member?
> > >
> > > GooString *modified; inside class Annot.
> >
> > I have committed the path without this for the moment. In page 1113 of
> > the pdf spec it says: "Acrobat viewers update the annotation
> > dictionary’s M entry only for text
> > annotations"
> >
> > Should we follow this and implement it only for text annotations?
>
> Hmpf, any reason in favor or against that? I'm leaning to doing it for all of
> them, unless someone knows why Acrobat decided to do it only for text and
> seems to make sense.I also think it makes more sense to always update M when the annot is modified. > BTW could you add a comment into the header near setContents saying the > ownership of the GooString is not taken and so the caller is responsible of > deleting it? Sure, I forgot it. Attached is a new set of patches, ok to commit? > Albert > > > > > > Albert > > > > > > > > Otherwise it think this can't hurt to let it go in :D > > > > > > > > Great, I'll commit it when I know what to do with the NULL case. > > > > > > > > Thanks. > > > > > > > > > Albert > > > > > _______________________________________________ > > > > > poppler mailing list > > > > > [email protected] > > > > > http://lists.freedesktop.org/mailman/listinfo/poppler > > > > > > _______________________________________________ > > > poppler mailing list > > > [email protected] > > > http://lists.freedesktop.org/mailman/listinfo/poppler > > > _______________________________________________ > poppler mailing list > [email protected] > http://lists.freedesktop.org/mailman/listinfo/poppler -- Carlos Garcia Campos [email protected] [email protected] http://carlosgc.linups.org PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x523E6462
From 9662bfa2b4b2282d0fc29d2a327b62d8bde56ff2 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos <[email protected]> Date: Thu, 23 Apr 2009 13:13:07 +0200 Subject: [PATCH] Add timeToDateString() to DateInfo This function converts a time_t into a string in PDF date format. --- configure.ac | 1 + poppler/DateInfo.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ poppler/DateInfo.h | 7 +++++++ 3 files changed, 55 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index e0d531e..37e08b7 100644 --- a/configure.ac +++ b/configure.ac @@ -22,6 +22,7 @@ AC_PROG_CXX AC_PROG_INSTALL AC_CHECK_FUNC(gettimeofday, AC_DEFINE(HAVE_GETTIMEOFDAY, 1, [Defines if gettimeofday is available on your system])) AC_CHECK_FUNC(localtime_r, AC_DEFINE(HAVE_LOCALTIME_R, 1, [Defines if localtime_r is available on your system])) +AC_CHECK_FUNC(gmtime_r, AC_DEFINE(HAVE_GMTIME_R, 1, [Defines if gmtime_r is available on your system])) dnl ##### Check for pkgconfig PKG_PROG_PKG_CONFIG diff --git a/poppler/DateInfo.cc b/poppler/DateInfo.cc index 6fac732..f2be57d 100644 --- a/poppler/DateInfo.cc +++ b/poppler/DateInfo.cc @@ -17,6 +17,8 @@ // //======================================================================== +#include <config.h> + #include "DateInfo.h" #include <stdio.h> @@ -68,3 +70,48 @@ GBool parseDateString(const char *dateString, int *year, int *month, int *day, i return gFalse; } + + +GooString *timeToDateString(time_t *timet) { + GooString *dateString; + char s[5]; + struct tm *gt; + size_t len; + time_t timep = timet ? *timet : time(NULL); + +#ifdef HAVE_GMTIME_R + struct tm t; + gt = gmtime_r (&timep, &t); +#else + gt = gmtime (&timep); +#endif + + dateString = new GooString ("D:"); + + /* Year YYYY */ + len = strftime (s, sizeof(s), "%Y", gt); + dateString->append (s, len); + + /* Month MM */ + len = strftime (s, sizeof(s), "%m", gt); + dateString->append (s, len); + + /* Day DD */ + len = strftime (s, sizeof(s), "%d", gt); + dateString->append (s, len); + + /* Hour HH */ + len = strftime (s, sizeof(s), "%H", gt); + dateString->append (s, len); + + /* Minute mm */ + len = strftime (s, sizeof(s), "%M", gt); + dateString->append (s, len); + + /* Second SS */ + len = strftime (s, sizeof(s), "%S", gt); + dateString->append (s, len); + + return dateString; +} + diff --git a/poppler/DateInfo.h b/poppler/DateInfo.h index c3e237e..a0c3942 100644 --- a/poppler/DateInfo.h +++ b/poppler/DateInfo.h @@ -21,7 +21,14 @@ #define DATE_INFO_H #include "goo/gtypes.h" +#include "goo/GooString.h" +#include <time.h> GBool parseDateString(const char *string, int *year, int *month, int *day, int *hour, int *minute, int *second, char *tz, int *tzHour, int *tzMinute); +/* Converts the time_t into a PDF Date format string. + * If timet is NULL, current time is used. + */ +GooString *timeToDateString(time_t *timet); + #endif -- 1.6.0.4 From 86a37a8f3f93e3378b446f8d81d80571267c7660 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos <[email protected]> Date: Thu, 23 Apr 2009 13:16:04 +0200 Subject: [PATCH] Update the annotation last modified time when it's modified --- poppler/Annot.cc | 26 ++++++++++++++++---------- poppler/Annot.h | 7 ++++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/poppler/Annot.cc b/poppler/Annot.cc index b6bb7d9..63d370e 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -56,6 +56,7 @@ #include "OptionalContent.h" #include "Sound.h" #include "FileSpec.h" +#include "DateInfo.h" #include <string.h> #define annotFlagHidden 0x0002 @@ -985,6 +986,20 @@ void Annot::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) { } } +void Annot::update(const char *key, Object *value) { + /* Set M to current time */ + delete modified; + modified = timeToDateString(NULL); + + Object obj1; + obj1.initString (modified->copy()); + annotObj.dictSet("M", &obj1); + + annotObj.dictSet(const_cast<char*>(key), value); + + xref->setModifiedObject(&annotObj, ref); +} + void Annot::setContents(GooString *new_content) { delete contents; @@ -1001,9 +1016,7 @@ void Annot::setContents(GooString *new_content) { Object obj1; obj1.initString(contents->copy()); - - annotObj.dictSet("Contents", &obj1); - xref->setModifiedObject(&annotObj, ref); + update ("Contents", &obj1); } double Annot::getXMin() { @@ -1347,13 +1360,6 @@ AnnotText::~AnnotText() { delete icon; } -void AnnotText::setModified(GooString *date) { - if (date) { - delete modified; - modified = new GooString(date); - } -} - void AnnotText::initialize(XRef *xrefA, Catalog *catalog, Dict *dict) { Object obj1; diff --git a/poppler/Annot.h b/poppler/Annot.h index 45e4ebe..a2c09e3 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -528,6 +528,10 @@ protected: void drawCircleTopLeft(double cx, double cy, double r); void drawCircleBottomRight(double cx, double cy, double r); + // Updates the field key of the annotation dictionary + // and sets M to the current time + void update(const char *key, Object *value); + Object annotObj; // required data @@ -649,9 +653,6 @@ public: GooString *getIcon() const { return icon; } AnnotTextState getState() const { return state; } - // setters - void setModified(GooString *date); - private: void initialize(XRef *xrefA, Catalog *catalog, Dict *dict); -- 1.6.0.4 From df0032cf5f6e5dc44bad056c659180e4065d32e2 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos <[email protected]> Date: Thu, 23 Apr 2009 13:19:25 +0200 Subject: [PATCH] Document Annot::setContents() method --- poppler/Annot.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/poppler/Annot.h b/poppler/Annot.h index a2c09e3..49c6ef0 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -497,6 +497,8 @@ public: double getFontSize() { return fontSize; } + // Sets the annotn contents to new_conten + // new_content should never be NULL void setContents(GooString *new_content); // getters -- 1.6.0.4
signature.asc
Description: Esta parte del mensaje está firmada digitalmente
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
