gnome-commander r1955 - in branches/gcmd-1-3: . data doc/C po src src/tags



Author: epiotr
Date: Fri Aug  8 23:40:06 2008
New Revision: 1955
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=1955&view=rev

Log:
Support for PDF metatags

Added:
   branches/gcmd-1-3/src/tags/gnome-cmd-tags-poppler.cc
   branches/gcmd-1-3/src/tags/gnome-cmd-tags-poppler.h
Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/README.in
   branches/gcmd-1-3/configure.in
   branches/gcmd-1-3/data/gnome-commander.spec.in
   branches/gcmd-1-3/doc/C/gnome-commander.xml
   branches/gcmd-1-3/po/POTFILES.in
   branches/gcmd-1-3/src/Makefile.am
   branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc
   branches/gcmd-1-3/src/gnome-cmd-advrename-lexer.ll
   branches/gcmd-1-3/src/gnome-cmd-file-props-dialog.cc
   branches/gcmd-1-3/src/tags/Makefile.am
   branches/gcmd-1-3/src/tags/gnome-cmd-tags.cc
   branches/gcmd-1-3/src/tags/gnome-cmd-tags.h

Modified: branches/gcmd-1-3/README.in
==============================================================================
--- branches/gcmd-1-3/README.in	(original)
+++ branches/gcmd-1-3/README.in	Fri Aug  8 23:40:06 2008
@@ -89,6 +89,9 @@
   * libgsf >= @LIBGSF_REQ@
     Optional - for OLE and ODF support.
 
+  * poppler >= @POPPLER_REQ@
+    Optional - for PDF support.
+
 
 Simple install procedure:
 

Modified: branches/gcmd-1-3/configure.in
==============================================================================
--- branches/gcmd-1-3/configure.in	(original)
+++ branches/gcmd-1-3/configure.in	Fri Aug  8 23:40:06 2008
@@ -52,6 +52,7 @@
 EXIV2_REQ=0.14
 TAGLIB_REQ=1.4
 LIBGSF_REQ=1.12.0
+POPPLER_REQ=0.6
 
 AC_SUBST(GLIB_REQ)
 AC_SUBST(GTK_REQ)
@@ -61,6 +62,7 @@
 AC_SUBST(EXIV2_REQ)
 AC_SUBST(TAGLIB_REQ)
 AC_SUBST(LIBGSF_REQ)
+AC_SUBST(POPPLER_REQ)
 
 dnl Check for glib
 AC_MSG_CHECKING(if glib >= ${GLIB_REQ} exists)
@@ -229,7 +231,18 @@
     PKG_CHECK_MODULES(GSF, libgsf-1 >= $LIBGSF_REQ, have_gsf=yes, have_gsf=no)
 fi
 if test "x$have_gsf" = "xyes"; then
-   AC_DEFINE(HAVE_GSF, 1, [Define to 1 if you have libgsf support])
+   AC_DEFINE(HAVE_GSF, 1, [Define to 1 if you have libgsf (OLE and ODF) support])
+fi
+
+
+dnl Check for poppler support
+AC_ARG_WITH(poppler, [  --without-poppler        disable PDF support])
+have_pdf=no
+if test x$with_poppler != xno; then
+    PKG_CHECK_MODULES(POPPLER, poppler >= $POPPLER_REQ, have_pdf=yes, have_pdf=no)
+fi
+if test "x$have_pdf" = "xyes"; then
+   AC_DEFINE(HAVE_PDF, 1, [Define to 1 if you have PDF support])
 fi
 
 
@@ -415,6 +428,7 @@
 echo "  chm support    : ${have_chm}"
 echo "  OLE2 support   : ${have_gsf}"
 echo "  ODF support    : ${have_gsf}"
+echo "  PDF support    : ${have_pdf}"
 echo ""
 echo ""
 echo "The following libraries will be used:"

Modified: branches/gcmd-1-3/data/gnome-commander.spec.in
==============================================================================
--- branches/gcmd-1-3/data/gnome-commander.spec.in	(original)
+++ branches/gcmd-1-3/data/gnome-commander.spec.in	Fri Aug  8 23:40:06 2008
@@ -18,6 +18,7 @@
 %define        exiv2_ver             @EXIV2_REQ@
 %define        taglib_ver            @TAGLIB_REQ@
 %define        libgsf_ver            @LIBGSF_REQ@
+%define        poppler_ver           @POPPLER_REQ@
 
 Name:          @PACKAGE@
 Version:       @VERSION@
@@ -54,10 +55,11 @@
 
 BuildRequires:   python-devel >= %{python_ver}
 BuildRequires:   exiv2-devel >= %{exiv2_ver}
-Requires:        taglib-devel >= %{taglib_ver}
+BuildRequires:   taglib-devel >= %{taglib_ver}
 %if 0%{?fedora} >= 6
 BuildRequires:   libgsf-devel >= %{libgsf_ver}
 %endif
+BuildRequires:   poppler-devel >= %{poppler_ver}
 
 Requires:        python >= %{python_ver}
 Requires:        gnome-python2-gnomevfs

Modified: branches/gcmd-1-3/doc/C/gnome-commander.xml
==============================================================================
--- branches/gcmd-1-3/doc/C/gnome-commander.xml	(original)
+++ branches/gcmd-1-3/doc/C/gnome-commander.xml	Fri Aug  8 23:40:06 2008
@@ -190,7 +190,7 @@
                 <para>Fast file viewer for text and images</para>
             </listitem>
             <listitem>
-                <para>Meta data support for Exif, IPTC, ID3, Vorbis, FLAC, APE, OLE2 and ODF tags</para>
+                <para>Meta data support for Exif, IPTC, ID3, Vorbis, FLAC, APE, OLE2, ODF and PDF tags</para>
             </listitem>
             <listitem>
                 <para>Tools for advanced batch renaming of files, searching, quick file name searching in current dir,

Modified: branches/gcmd-1-3/po/POTFILES.in
==============================================================================
--- branches/gcmd-1-3/po/POTFILES.in	(original)
+++ branches/gcmd-1-3/po/POTFILES.in	Fri Aug  8 23:40:06 2008
@@ -68,5 +68,6 @@
 src/tags/gnome-cmd-tags.cc
 src/tags/gnome-cmd-tags-doc.cc
 src/tags/gnome-cmd-tags-exiv2.cc
+src/tags/gnome-cmd-tags-poppler.cc
 src/tags/gnome-cmd-tags-taglib.cc
 src/utils.cc

Modified: branches/gcmd-1-3/src/Makefile.am
==============================================================================
--- branches/gcmd-1-3/src/Makefile.am	(original)
+++ branches/gcmd-1-3/src/Makefile.am	Fri Aug  8 23:40:06 2008
@@ -98,6 +98,7 @@
 	$(TAGLIB_LIBS) \
 	$(CHM_LIBS) \
 	$(GSF_LIBS) \
+	$(POPPLER_LIBS) \
 	$(PYTHON_LIBS) \
 	$(PYTHON_EXTRA_LIBS) \
 	$(top_builddir)/libgcmd/libgcmd.la \

Modified: branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc	Fri Aug  8 23:40:06 2008
@@ -273,6 +273,12 @@
                                      TAG_ID3_WWWCOPYRIGHT, TAG_ID3_WWWPAYMENT, TAG_ID3_WWWPUBLISHER,
                                      TAG_ID3_WWWRADIOPAGE, TAG_ID3_WWWUSER,
 
+                                     TAG_VORBIS_CONTACT, TAG_VORBIS_DESCRIPTION,
+                                     TAG_VORBIS_LICENSE, TAG_VORBIS_LOCATION,
+                                     TAG_VORBIS_MAXBITRATE, TAG_VORBIS_MINBITRATE,
+                                     TAG_VORBIS_NOMINALBITRATE, TAG_VORBIS_ORGANIZATION,
+                                     TAG_VORBIS_VENDOR, TAG_VORBIS_VERSION,
+
                                      TAG_EXIF_COPYRIGHT, TAG_EXIF_DATETIME,
                                      TAG_EXIF_EXPOSUREBIASVALUE, TAG_EXIF_EXPOSUREMODE, TAG_EXIF_EXPOSUREPROGRAM,
                                      TAG_EXIF_FLASH, TAG_EXIF_FLASHENERGY,
@@ -354,11 +360,18 @@
                                      TAG_IPTC_SUPPLCATEGORY, TAG_IPTC_TIMECREATED, TAG_IPTC_TIMESENT, TAG_IPTC_UNO,
                                      TAG_IPTC_URGENCY, TAG_IPTC_WRITEREDITOR,
 
-                                     TAG_VORBIS_CONTACT, TAG_VORBIS_DESCRIPTION,
-                                     TAG_VORBIS_LICENSE, TAG_VORBIS_LOCATION,
-                                     TAG_VORBIS_MAXBITRATE, TAG_VORBIS_MINBITRATE,
-                                     TAG_VORBIS_NOMINALBITRATE, TAG_VORBIS_ORGANIZATION,
-                                     TAG_VORBIS_VENDOR, TAG_VORBIS_VERSION
+                                     TAG_PDF_PAGESIZE, TAG_PDF_PAGEWIDTH, TAG_PDF_PAGEHEIGHT,
+                                     TAG_PDF_VERSION, TAG_PDF_PRODUCER,
+                                     TAG_PDF_EMBEDDEDFILES,
+                                     TAG_PDF_OPTIMIZED,
+                                     TAG_PDF_PRINTING,
+                                     TAG_PDF_HIRESPRINTING,
+                                     TAG_PDF_COPYING,
+                                     TAG_PDF_MODIFYING,
+                                     TAG_PDF_DOCASSEMBLY,
+                                     TAG_PDF_COMMENTING,
+                                     TAG_PDF_FORMFILLING,
+                                     TAG_PDF_ACCESSIBILITYSUPPORT
                                     };
 
     GtkItemFactoryEntry *items[] = {dir_items,

Modified: branches/gcmd-1-3/src/gnome-cmd-advrename-lexer.ll
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-advrename-lexer.ll	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-advrename-lexer.ll	Fri Aug  8 23:40:06 2008
@@ -111,10 +111,11 @@
 id3         [iI][dD]3
 image       [iI][mM][aA][gG][eE]
 iptc        [iI][pP][tT][cC]
+pdf         [pP][dD][fF]
 rpm         [rR][pP][mM]
 vorbis      [vV][oO][rR][bB][iI][sS]
 
-tag_name    {ape}|{audio}|{doc}|{exif}|{file}|{flac}|{id3}|{image}|{iptc}|{vorbis}
+tag_name    {ape}|{audio}|{doc}|{exif}|{file}|{flac}|{id3}|{image}|{iptc}|{pdf}|{vorbis}
 
 %%
 

Modified: branches/gcmd-1-3/src/gnome-cmd-file-props-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-props-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-props-dialog.cc	Fri Aug  8 23:40:06 2008
@@ -462,6 +462,8 @@
     {
         add_tag (dialog, table, y, *data->finfo->metadata, TAG_FILE_DESCRIPTION);
         add_tag (dialog, table, y, *data->finfo->metadata, TAG_FILE_PUBLISHER);
+        add_tag (dialog, table, y, *data->finfo->metadata, TAG_DOC_TITLE);
+        add_tag (dialog, table, y, *data->finfo->metadata, TAG_DOC_PAGECOUNT);
         add_width_height_tag (dialog, table, y, *data->finfo->metadata);
         add_tag (dialog, table, y, *data->finfo->metadata, TAG_AUDIO_ALBUMARTIST);
         add_tag (dialog, table, y, *data->finfo->metadata, TAG_AUDIO_TITLE);

Modified: branches/gcmd-1-3/src/tags/Makefile.am
==============================================================================
--- branches/gcmd-1-3/src/tags/Makefile.am	(original)
+++ branches/gcmd-1-3/src/tags/Makefile.am	Fri Aug  8 23:40:06 2008
@@ -12,11 +12,13 @@
 	$(TAGLIB_CFLAGS) \
 	$(CHM_CFLAGS) \
 	$(GSF_CFLAGS) \
+	$(POPPLER_CFLAGS) \
 	-DPLUGIN_DIR=\""$(libdir)/$(PACKAGE)/plugins"\"
 
 libgcmd_tags_a_SOURCES = \
 	gnome-cmd-tags.h gnome-cmd-tags.cc \
-	gnome-cmd-tags-file.h gnome-cmd-tags-file.cc \
-	gnome-cmd-tags-taglib.h gnome-cmd-tags-taglib.cc \
 	gnome-cmd-tags-doc.h gnome-cmd-tags-doc.cc \
-	gnome-cmd-tags-exiv2.h gnome-cmd-tags-exiv2.cc
+	gnome-cmd-tags-exiv2.h gnome-cmd-tags-exiv2.cc \
+	gnome-cmd-tags-file.h gnome-cmd-tags-file.cc \
+	gnome-cmd-tags-poppler.h gnome-cmd-tags-poppler.cc \
+	gnome-cmd-tags-taglib.h gnome-cmd-tags-taglib.cc

Added: branches/gcmd-1-3/src/tags/gnome-cmd-tags-poppler.cc
==============================================================================
--- (empty file)
+++ branches/gcmd-1-3/src/tags/gnome-cmd-tags-poppler.cc	Fri Aug  8 23:40:06 2008
@@ -0,0 +1,401 @@
+/*
+    GNOME Commander - A GNOME based file manager
+    Copyright (C) 2001-2006 Marcus Bjurman
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include <config.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include "gnome-cmd-includes.h"
+#include "gnome-cmd-tags.h"
+#include "utils.h"
+#include "dict.h"
+
+#ifdef HAVE_PDF
+#include <regex.h>
+#include <poppler/PDFDoc.h>
+#include <poppler/PDFDocEncoding.h>
+#include <poppler/Error.h>
+#endif
+
+using namespace std;
+
+
+#ifdef HAVE_PDF
+static regex_t rxDate;
+static gboolean rxDate_OK;
+
+static void noErrorReporting(int pos, char *msg, va_list args)
+{
+}
+#endif
+
+
+void gcmd_tags_poppler_init()
+{
+#ifdef HAVE_PDF
+    rxDate_OK = regcomp (&rxDate, "^(D:)?([12][019][0-9][0-9]([01][0-9]([0-3][0-9]([012][0-9]([0-5][0-9]([0-5][0-9])?)?)?)?)?)", REG_EXTENDED)==0;
+
+    setErrorFunction(noErrorReporting);
+#endif
+}
+
+
+void gcmd_tags_poppler_shutdown()
+{
+#ifdef HAVE_PDF
+    if (rxDate_OK)
+        regfree(&rxDate);
+#endif
+}
+
+
+#ifdef HAVE_PDF
+static gchar *convert_to_utf8(GooString *s)
+{
+    guint len = s->getLength();
+
+    if (s->hasUnicodeMarker())
+        return g_convert (s->getCString()+2, len-2, "UTF-8", "UTF-16BE", NULL, NULL, NULL);
+    else
+    {
+        static vector<gunichar> buff(64);
+
+        if (len>buff.size())
+            buff.resize(len);
+
+        gunichar *ucs4 = &buff[0];
+
+        for (guint i=0; i<len; ++i, ++ucs4)
+            *ucs4 = pdfDocEncoding[(unsigned char) s->getChar(i)];
+
+        return g_ucs4_to_utf8 (&buff[0], len, NULL, NULL, NULL);
+    }
+}
+
+
+inline void add(GnomeCmdFileMetadata &metadata, const GnomeCmdTag tag, GooString *s)
+{
+    if (!s)  return;
+
+    char *value = convert_to_utf8(s);
+
+    metadata.add(tag, value);
+
+    g_free (value);
+}
+
+
+inline void add(GnomeCmdFileMetadata &metadata, const GnomeCmdTag tag1, const GnomeCmdTag tag2, GooString *s)
+{
+    if (!s)  return;
+
+    char *value = convert_to_utf8(s);
+
+    metadata.add(tag1, value);
+    metadata.add(tag2, value);
+
+    g_free (value);
+}
+
+
+static void add_date(GnomeCmdFileMetadata &metadata, GnomeCmdTag tag, GooString *date)
+{
+    // PDF date format:     D:YYYYMMDDHHmmSSOHH'mm'
+
+    gchar *s = convert_to_utf8(date);
+
+    if (!s)  return;
+
+    regmatch_t m[3];
+
+    if (rxDate_OK && regexec(&rxDate, s, G_N_ELEMENTS(m), m, 0) == 0)
+    {
+        static char buff[32];
+
+        strcpy(buff, "YYYY-01-01 00:00:00");
+
+        gchar *src = s + m[2].rm_so;
+
+        switch (m[2].rm_eo-m[2].rm_so)
+        {
+            case 14:    //  SS
+                memcpy(buff+17,src+12,2);
+
+            case 12:    // mm
+                memcpy(buff+14,src+10,2);
+
+            case 10:    //  HH
+                memcpy(buff+11,src+8,2);
+
+            case 8:     //  DD
+                memcpy(buff+8,src+6,2);
+
+            case 6:     //  MM
+                memcpy(buff+5,src+4,2);
+
+            case 4:     //  YYYY
+                memcpy(buff,src,4);
+                break;
+
+            default:
+                break;
+        }
+
+        metadata.add(tag, buff);
+    }
+
+    g_free (s);
+}
+
+
+#if GTK_CHECK_VERSION (2, 12, 0)
+inline gdouble get_tolerance (gdouble size)
+{
+    if (size < 150.0f)
+        return 1.5f;
+
+    return size >= 150.0f && size <= 600.0f ? 2.0f : 3.0f;
+}
+#else /* ! GTK 2.12.0 */
+struct regular_paper_size
+{
+    double width;
+    double height;
+    double width_tolerance;
+    double height_tolerance;
+    const char *description;
+}
+const regular_paper_sizes[] =
+{
+    // ISO 216 paper sizes, all values are in mm.  Source: http://en.wikipedia.org/wiki/Paper_size
+    {  210.0f,  297.0f, 2.0f, 2.0f, "A4"  },
+    {  841.0f, 1189.0f, 3.0f, 3.0f, "A0"  },
+    {  594.0f,  841.0f, 2.0f, 3.0f, "A1"  },
+    {  420.0f,  594.0f, 2.0f, 2.0f, "A2"  },
+    {  297.0f,  420.0f, 2.0f, 2.0f, "A3"  },
+    {  148.0f,  210.0f, 1.5f, 2.0f, "A5"  },
+    {  105.0f,  148.0f, 1.5f, 1.5f, "A6"  },
+    {   74.0f,  105.0f, 1.5f, 1.5f, "A7"  },
+    {   52.0f,   74.0f, 1.5f, 1.5f, "A8"  },
+    {   37.0f,   52.0f, 1.5f, 1.5f, "A9"  },
+    {   26.0f,   37.0f, 1.5f, 1.5f, "A10" },
+    { 1000.0f, 1414.0f, 3.0f, 3.0f, "B0"  },
+    {  707.0f, 1000.0f, 3.0f, 3.0f, "B1"  },
+    {  500.0f,  707.0f, 2.0f, 3.0f, "B2"  },
+    {  353.0f,  500.0f, 2.0f, 2.0f, "B3"  },
+    {  250.0f,  353.0f, 2.0f, 2.0f, "B4"  },
+    {  176.0f,  250.0f, 2.0f, 2.0f, "B5"  },
+    {  125.0f,  176.0f, 1.5f, 2.0f, "B6"  },
+    {   88.0f,  125.0f, 1.5f, 1.5f, "B7"  },
+    {   62.0f,   88.0f, 1.5f, 1.5f, "B8"  },
+    {   44.0f,   62.0f, 1.5f, 1.5f, "B9"  },
+    {   31.0f,   44.0f, 1.5f, 1.5f, "B10" },
+    {  917.0f, 1297.0f, 3.0f, 3.0f, "C0"  },
+    {  648.0f,  917.0f, 3.0f, 3.0f, "C1"  },
+    {  458.0f,  648.0f, 2.0f, 3.0f, "C2"  },
+    {  324.0f,  458.0f, 2.0f, 2.0f, "C3"  },
+    {  229.0f,  324.0f, 2.0f, 2.0f, "C4"  },
+    {  162.0f,  229.0f, 2.0f, 2.0f, "C5"  },
+    {  114.0f,  162.0f, 1.5f, 2.0f, "C6"  },
+    {   81.0f,  114.0f, 1.5f, 1.5f, "C7"  },
+    {   57.0f,   81.0f, 1.5f, 1.5f, "C8"  },
+    {   40.0f,   57.0f, 1.5f, 1.5f, "C9"  },
+    {   28.0f,   40.0f, 1.5f, 1.5f, "C10" },
+
+    // US paper sizes
+    {  279.0f,  216.0f, 3.0f, 3.0f, "Letter" },
+    {  356.0f,  216.0f, 3.0f, 3.0f, "Legal"  },
+    {  432.0f,  279.0f, 3.0f, 3.0f, "Ledger" }
+};
+#endif
+
+
+inline gchar *paper_name (gdouble doc_width, double doc_height)
+{
+    gchar *s = NULL;
+
+#if GTK_CHECK_VERSION (2, 12, 0)
+    GList *paper_sizes = gtk_paper_size_get_paper_sizes (FALSE);
+
+    for (GList *l = paper_sizes; l && l->data; l = g_list_next (l))
+    {
+        GtkPaperSize *size = (GtkPaperSize *) l->data;
+
+        gdouble paper_width = gtk_paper_size_get_width (size, GTK_UNIT_MM);
+        gdouble paper_height = gtk_paper_size_get_height (size, GTK_UNIT_MM);
+
+        gdouble width_tolerance = get_tolerance (paper_width);
+        gdouble height_tolerance = get_tolerance (paper_height);
+
+        if (ABS (doc_height - paper_height) <= height_tolerance &&
+            ABS (doc_width - paper_width) <= width_tolerance)
+        {
+            // Note to translators: first placeholder is the paper name (eg. * A4)
+            s = g_strdup_printf (_("%s, Portrait"), gtk_paper_size_get_display_name (size));
+            break;
+        }
+        else
+            if (ABS (doc_width - paper_height) <= height_tolerance &&
+                ABS (doc_height - paper_width) <= width_tolerance)
+            {
+                // Note to translators: first placeholder is the paper name (eg. * A4)
+                s = g_strdup_printf (_("%s, Landscape"), gtk_paper_size_get_display_name (size));
+                break;
+            }
+    }
+
+    g_list_foreach (paper_sizes, (GFunc) gtk_paper_size_free, NULL);
+    g_list_free (paper_sizes);
+
+#else /* ! GTK 2.12.0 */
+
+    for (int i=G_N_ELEMENTS (regular_paper_sizes)-1; i >= 0; --i)
+    {
+        const regular_paper_size *size = &regular_paper_sizes[i];
+
+        if (ABS(doc_height - size->height) <= size->height_tolerance &&
+            ABS(doc_width - size->width) <= size->width_tolerance)
+            // Note to translators: first placeholder is the paper name (eg. * A4)
+            return g_strdup_printf (_("%s, Portrait"), size->description);
+        else
+            if (ABS(doc_width - size->height) <= size->height_tolerance &&
+                ABS(doc_height - size->width) <= size->width_tolerance)
+                // Note to translators: first placeholder is the paper name (eg. * A4)
+                return g_strdup_printf (_("%s, Landscape"), size->description);
+    }
+#endif
+
+    return s;
+}
+#endif
+
+
+void gcmd_tags_poppler_load_metadata(GnomeCmdFile *finfo)
+{
+    g_return_if_fail (finfo != NULL);
+    g_return_if_fail (finfo->info != NULL);
+
+#ifdef HAVE_PDF
+    if (finfo->metadata && finfo->metadata->is_accessed(TAG_PDF))  return;
+
+    if (!finfo->metadata)
+        finfo->metadata = new GnomeCmdFileMetadata;
+
+    if (!finfo->metadata)  return;
+
+    finfo->metadata->mark_as_accessed(TAG_PDF);
+    finfo->metadata->mark_as_accessed(TAG_DOC);
+
+    if (!gnome_cmd_file_is_local (finfo))  return;
+
+    gchar *fname = gnome_cmd_file_get_real_path (finfo);
+
+    DEBUG('t', "Loading PDF metadata for '%s'\n", fname);
+
+    PDFDoc doc(new GooString(fname));
+
+    g_free (fname);
+
+    if (!doc.isOk())
+        return;
+
+    finfo->metadata->addf(TAG_PDF_VERSION, "%.1f", doc.getPDFVersion());
+    finfo->metadata->addf(TAG_DOC_PAGECOUNT, "%i", doc.getNumPages());
+    finfo->metadata->addf(TAG_PDF_OPTIMIZED, "%u", doc.isLinearized());
+
+    finfo->metadata->addf(TAG_DOC_SECURITY, "%u", doc.isEncrypted());   //  FIXME: 1 -> "Password protected", 0 -> "No protection" ???
+
+    finfo->metadata->addf(TAG_PDF_PRINTING, "%u", doc.okToPrint());
+    finfo->metadata->addf(TAG_PDF_HIRESPRINTING, "%u", doc.okToPrintHighRes());
+    finfo->metadata->addf(TAG_PDF_MODIFYING, "%u", doc.okToChange());
+    finfo->metadata->addf(TAG_PDF_COPYING, "%u", doc.okToCopy());
+    finfo->metadata->addf(TAG_PDF_COMMENTING, "%u", doc.okToAddNotes());
+    finfo->metadata->addf(TAG_PDF_FORMFILLING, "%u", doc.okToFillForm());
+    finfo->metadata->addf(TAG_PDF_ACCESSIBILITYSUPPORT, "%u", doc.okToAccessibility());
+    finfo->metadata->addf(TAG_PDF_DOCASSEMBLY, "%u", doc.okToAssemble());
+
+    if (doc.getPDFVersion()>0)
+    {
+        double width = doc.getPageCropWidth(1)/72.0f*25.4f;
+        double height = doc.getPageCropHeight(1)/72.0f*25.4f;
+
+        finfo->metadata->addf(TAG_PDF_PAGEWIDTH, "%.0f", width);
+        finfo->metadata->addf(TAG_PDF_PAGEHEIGHT, "%.0f", height);
+
+        gchar *paper_size = paper_name (width, height);
+
+        finfo->metadata->add(TAG_PDF_PAGESIZE, paper_size);
+
+        g_free (paper_size);
+    }
+
+    Catalog *catalog = doc.getCatalog();
+
+    if (catalog)
+        finfo->metadata->addf(TAG_PDF_EMBEDDEDFILES, "%i", catalog->numEmbeddedFiles());
+
+    // GooString *xmp = doc.readMetadata();         // FIXME: future access to XMP metadata
+
+    // if (xmp)
+    // {
+        // TRACE(xmp->getCString());
+    // }
+
+    // delete xmp;
+
+    Object info;
+
+    doc.getDocInfo(&info);
+
+    if (info.isDict())
+    {
+        Object obj;
+        Dict *dict = info.getDict();
+
+        if (dict->lookup("Title", &obj)->isString())
+            add(*finfo->metadata, TAG_DOC_TITLE, obj.getString());
+
+        if (dict->lookup("Subject", &obj)->isString())
+            add(*finfo->metadata, TAG_DOC_SUBJECT, obj.getString());
+
+        if (dict->lookup("Keywords", &obj)->isString())
+            add(*finfo->metadata, TAG_DOC_KEYWORDS, TAG_FILE_KEYWORDS, obj.getString());        //  FIXME:  split keywords here
+
+        if (dict->lookup("Author", &obj)->isString())
+            add(*finfo->metadata, TAG_DOC_AUTHOR, TAG_FILE_PUBLISHER, obj.getString());
+
+        if (dict->lookup("Creator", &obj)->isString())
+            add(*finfo->metadata, TAG_PDF_PRODUCER, obj.getString());
+
+        if (dict->lookup("Producer", &obj)->isString())
+            add(*finfo->metadata, TAG_DOC_GENERATOR, obj.getString());
+
+        if (dict->lookup("CreationDate", &obj)->isString())
+            add_date(*finfo->metadata, TAG_DOC_DATECREATED, obj.getString());
+
+        if (dict->lookup("ModDate", &obj)->isString())
+            add_date(*finfo->metadata, TAG_DOC_DATEMODIFIED, obj.getString());
+
+        obj.free();
+    }
+
+    info.free();
+#endif
+}

Added: branches/gcmd-1-3/src/tags/gnome-cmd-tags-poppler.h
==============================================================================
--- (empty file)
+++ branches/gcmd-1-3/src/tags/gnome-cmd-tags-poppler.h	Fri Aug  8 23:40:06 2008
@@ -0,0 +1,30 @@
+/*
+    GNOME Commander - A GNOME based file manager
+    Copyright (C) 2001-2006 Marcus Bjurman
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __GNOME_CMD_TAGS_POPPLER_H__
+#define __GNOME_CMD_TAGS_POPPLER_H__
+
+#include "gnome-cmd-file.h"
+
+void gcmd_tags_poppler_init();
+void gcmd_tags_poppler_shutdown();
+
+void gcmd_tags_poppler_load_metadata(GnomeCmdFile *finfo);
+
+#endif // __GNOME_CMD_TAGS_POPPLER_H__

Modified: branches/gcmd-1-3/src/tags/gnome-cmd-tags.cc
==============================================================================
--- branches/gcmd-1-3/src/tags/gnome-cmd-tags.cc	(original)
+++ branches/gcmd-1-3/src/tags/gnome-cmd-tags.cc	Fri Aug  8 23:40:06 2008
@@ -30,6 +30,7 @@
 #include "gnome-cmd-tags-exiv2.h"
 #include "gnome-cmd-tags-taglib.h"
 #include "gnome-cmd-tags-doc.h"
+#include "gnome-cmd-tags-poppler.h"
 #include "utils.h"
 #include "dict.h"
 
@@ -70,6 +71,10 @@
 static char no_support_for_libgsf_tags_string[] = N_("<OLE2 and ODF tags not supported>");
 #endif
 
+#ifndef HAVE_PDF
+static char no_support_for_poppler_tags_string[] = N_("<PDF tags not supported>");
+#endif
+
 
 void GnomeCmdFileMetadata::addf(const GnomeCmdTag tag, const gchar *fmt, ...)
 {
@@ -504,6 +509,21 @@
                        {TAG_IPTC_UNO, {"IPTC.UNO", TAG_IPTC, N_("Unique Name of Object"), N_("An eternal, globally unique identification for the object, independent of provider and for any media form.")}},
                        {TAG_IPTC_URGENCY, {"IPTC.Urgency", TAG_IPTC, N_("Urgency"), N_("Specifies the editorial urgency of content and not necessarily the envelope handling priority. '1' is most urgent, '5' normal, and '8' least urgent.")}},
                        {TAG_IPTC_WRITEREDITOR, {"IPTC.WriterEditor", TAG_IPTC, N_("Writer/Editor"), N_("The name of the person involved in the writing, editing or correcting the object or caption/abstract (multiple values allowed)")}},
+                       {TAG_PDF_PAGESIZE, {"PDF.PageSize", TAG_PDF, N_("Page Size"), N_("Page size format.")}},
+                       {TAG_PDF_PAGEWIDTH, {"PDF.PageWidth", TAG_PDF, N_("Page Width"), N_("Page width in mm.")}},
+                       {TAG_PDF_PAGEHEIGHT, {"PDF.PageHeight", TAG_PDF, N_("Page Height"), N_("Page height in mm.")}},
+                       {TAG_PDF_VERSION, {"PDF.Version", TAG_PDF, N_("PDF Version"), N_("The PDF version of the document.")}},
+                       {TAG_PDF_PRODUCER, {"PDF.Producer", TAG_PDF, N_("Producer"), N_("The application that converted the document to PDF.")}},
+                       {TAG_PDF_EMBEDDEDFILES, {"PDF.EmbeddedFiles", TAG_PDF, N_("Embedded Files"), N_("Number of embedded files in the document.")}},
+                       {TAG_PDF_OPTIMIZED, {"PDF.Optimized", TAG_PDF, N_("Fast Web View"), N_("Set to \"1\" if optimized for network access.")}},
+                       {TAG_PDF_PRINTING, {"PDF.Printing", TAG_PDF, N_("Printing"), N_("Set to \"1\" if printing is allowed.")}},
+                       {TAG_PDF_HIRESPRINTING, {"PDF.HiResPrinting", TAG_PDF, N_("Printing in High Resolution"), N_("Set to \"1\" if high resolution printing is allowed.")}},
+                       {TAG_PDF_COPYING, {"PDF.Copying", TAG_PDF, N_("Copying"), N_("Set to \"1\" if copying the contents is allowed.")}},
+                       {TAG_PDF_MODIFYING, {"PDF.Modifying", TAG_PDF, N_("Modifying"), N_("Set to \"1\" if modifying the contents is allowed.")}},
+                       {TAG_PDF_DOCASSEMBLY, {"PDF.DocAssembly", TAG_PDF, N_("Document Assembly"), N_("Set to \"1\" if inserting, rotating, or deleting pages and creating navigation elements is allowed.")}},
+                       {TAG_PDF_COMMENTING, {"PDF.Commenting", TAG_PDF, N_("Commenting"), N_("Set to \"1\" if adding or modifying text annotations is allowed.")}},
+                       {TAG_PDF_FORMFILLING, {"PDF.FormFilling", TAG_PDF, N_("Form Filling"), N_("Set to \"1\" if filling of form fields is allowed.")}},
+                       {TAG_PDF_ACCESSIBILITYSUPPORT, {"PDF.AccessibilitySupport", TAG_PDF, N_("Accessibility Support"), N_("Set to \"1\" if accessibility support (eg. screen readers) is enabled.")}},
                        {TAG_VORBIS_CONTACT, {"Vorbis.Contact", TAG_VORBIS, N_("Contact"), N_("Contact information for the creators or distributors of the track.")}},
                        {TAG_VORBIS_DESCRIPTION, {"Vorbis.Description", TAG_VORBIS, N_("Description"), N_("A textual description of the data.")}},
                        {TAG_VORBIS_LICENSE, {"Vorbis.License", TAG_VORBIS, N_("License"), N_("License information.")}},
@@ -521,6 +541,7 @@
     gcmd_tags_exiv2_init();
     gcmd_tags_taglib_init();
     gcmd_tags_libgsf_init();
+    gcmd_tags_poppler_init();
 }
 
 
@@ -529,6 +550,7 @@
     gcmd_tags_exiv2_shutdown();
     gcmd_tags_taglib_shutdown();
     gcmd_tags_libgsf_shutdown();
+    gcmd_tags_poppler_shutdown();
 }
 
 
@@ -540,6 +562,7 @@
     gcmd_tags_exiv2_load_metadata(finfo);
     gcmd_tags_taglib_load_metadata(finfo);
     gcmd_tags_libgsf_load_metadata(finfo);
+    gcmd_tags_poppler_load_metadata(finfo);
 
     return finfo->metadata;
 }
@@ -597,6 +620,10 @@
                 t.name = "IPTC.";
                 break;
 
+            case TAG_PDF:
+                t.name = "PDF.";
+                break;
+
             case TAG_RPM:
                 t.name = "RPM.";
                 break;
@@ -673,6 +700,9 @@
         case TAG_IPTC:
             return "IPTC";
 
+        case TAG_PDF:
+            return "PDF";
+
         case TAG_RPM:
             return "RPM";
 
@@ -724,6 +754,11 @@
                         return _(no_support_for_libgsf_tags_string);
 #endif
                         gcmd_tags_libgsf_load_metadata(finfo);
+        case TAG_PDF  :
+#ifndef HAVE_PDF
+                        return _(no_support_for_poppler_tags_string);
+#endif
+                        gcmd_tags_poppler_load_metadata(finfo);
                         ret_val = finfo->metadata->operator [] (tag).c_str();
                         break;
 

Modified: branches/gcmd-1-3/src/tags/gnome-cmd-tags.h
==============================================================================
--- branches/gcmd-1-3/src/tags/gnome-cmd-tags.h	(original)
+++ branches/gcmd-1-3/src/tags/gnome-cmd-tags.h	Fri Aug  8 23:40:06 2008
@@ -40,9 +40,10 @@
     TAG_FLAC        = 1 << 11,
     TAG_ID3         = 1 << 12,
     TAG_VORBIS      = 1 << 13,
-    TAG_RPM         = 1 << 14,
+    TAG_PDF         = 1 << 14,
+    TAG_RPM         = 1 << 15,
     TAG_AUDIO       = TAG_APE | TAG_FLAC | TAG_ID3 | TAG_VORBIS,
-    TAG_DOC         = TAG_CHM+1,
+    TAG_DOC         = TAG_CHM | TAG_PDF,
     TAG_IMAGE       = TAG_EXIF | TAG_IPTC | TAG_ICC
 } GnomeCmdTagClass;
 
@@ -450,6 +451,21 @@
     TAG_IPTC_UNO,                           // eternal, globally unique identification for the object, independent of provider and for any media form
     TAG_IPTC_URGENCY,                       // specifies the editorial urgency of content and not necessarily the envelope handling priority
     TAG_IPTC_WRITEREDITOR,                  // name of the person involved in the writing, editing or correcting the object or caption/abstract
+    TAG_PDF_PAGESIZE,                       // page size format
+    TAG_PDF_PAGEWIDTH,                      // page width in mm
+    TAG_PDF_PAGEHEIGHT,                     // page height in mm
+    TAG_PDF_VERSION,                        // the PDF version of the document
+    TAG_PDF_PRODUCER,                       // the application that converted the document to PDF
+    TAG_PDF_EMBEDDEDFILES,                  // number of embedded files in the document
+    TAG_PDF_OPTIMIZED,                      // set to "1" if optimized for network access
+    TAG_PDF_PRINTING,                       // set to "1" if printing is allowed
+    TAG_PDF_HIRESPRINTING,                  // set to "1" if high resolution printing is allowed
+    TAG_PDF_COPYING,                        // set to "1" if copying the contents is allowed
+    TAG_PDF_MODIFYING,                      // set to "1" if modifying the contents is allowed
+    TAG_PDF_DOCASSEMBLY,                    // set to "1" if inserting, rotating, or deleting pages and creating navigation elements is allowed
+    TAG_PDF_COMMENTING,                     // set to "1" if adding or modifying text annotations is allowed
+    TAG_PDF_FORMFILLING,                    // set to "1" if filling of form fields is allowed
+    TAG_PDF_ACCESSIBILITYSUPPORT,           // set to "1" if accessibility support (eg. screen readers) is enabled
     TAG_VORBIS_CONTACT,                     // contact information for the creators or distributors of the track
     TAG_VORBIS_DESCRIPTION,                 // a textual description of the data
     TAG_VORBIS_LICENSE,                     // license information



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]