+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+ PopplerPage *poppler_page;
+ cairo_surface_t *surface;
+ GdkPixbuf *pixbuf = NULL;
+ GdkPixbuf *border_pixbuf;
+ double page_width, page_height;
+ gint width, height;
+
+ poppler_page = POPPLER_PAGE (rc->page->backend_page);
+
+ poppler_page_get_size (poppler_page,
+ &page_width, &page_height);
+
+ width = MAX ((gint)(page_width * rc->scale + 0.5), 1);
+ height = MAX ((gint)(page_height * rc->scale + 0.5), 1);
+
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ gint temp;
+
+ temp = width;
+ width = height;
+ height = temp;
+ }
+
+ surface = poppler_page_get_thumbnail (poppler_page);
+ if (surface) {
+ pixbuf = ev_document_misc_pixbuf_from_surface (surface);
+ cairo_surface_destroy (surface);
+ }
+
+ if (pixbuf != NULL) {
+ int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ?
+ gdk_pixbuf_get_height (pixbuf) :
+ gdk_pixbuf_get_width (pixbuf);
+
+ if (thumb_width == width) {
+ GdkPixbuf *rotated_pixbuf;
+
+ rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf,
+ (GdkPixbufRotation) (360 - rc->rotation));
+ g_object_unref (pixbuf);
+ pixbuf = rotated_pixbuf;
+ } else {
+ /* The provided thumbnail has a different size */
+ g_object_unref (pixbuf);
+ pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
+ }
+ } else {
+ /* There is no provided thumbnail. We need to make one. */
+ pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
+ }
+
+ return pixbuf;
+}
+
+/* reference:
+http://www.pdfa.org/lib/exe/fetch.php?id=pdfa%3Aen%3Atechdoc&cache=cache&media=pdfa:techdoc:tn0001_pdfa-1_and_namespaces_2008-03-18.pdf */
+static char *
+pdf_document_get_format_from_metadata (xmlDocPtr doc,
+ xmlXPathContextPtr xpathCtx)
+{
+ xmlXPathObjectPtr xpathObj;
+ xmlChar *part = NULL;
+ xmlChar *conf = NULL;
+ char *result = NULL;
+ int i;
+
+ /* add pdf/a namespaces */
+ xmlXPathRegisterNs (xpathCtx, BAD_CAST "x", BAD_CAST "adobe:ns:meta/");
+ xmlXPathRegisterNs (xpathCtx, BAD_CAST "rdf", BAD_CAST "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ xmlXPathRegisterNs (xpathCtx, BAD_CAST "pdfaid", BAD_CAST "http://www.aiim.org/pdfa/ns/id/");
+
+ /* reads pdf/a part */
+ /* first syntax: child node */
+ xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/pdfaid:part", xpathCtx);
+ if (xpathObj != NULL) {
+ if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
+ part = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
+
+ xmlXPathFreeObject (xpathObj);
+ }
+ if (part == NULL) {
+ /* second syntax: attribute */
+ xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/@pdfaid:part", xpathCtx);
+ if (xpathObj != NULL) {
+ if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
+ part = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
+
+ xmlXPathFreeObject (xpathObj);
+ }
+ }
+
+ /* reads pdf/a conformance */
+ /* first syntax: child node */
+ xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/pdfaid:conformance", xpathCtx);
+ if (xpathObj != NULL) {
+ if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
+ conf = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
+
+ xmlXPathFreeObject (xpathObj);
+ }
+ if (conf == NULL) {
+ /* second syntax: attribute */
+ xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/@pdfaid:conformance", xpathCtx);
+ if (xpathObj != NULL) {
+ if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
+ conf = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
+
+ xmlXPathFreeObject (xpathObj);
+ }
+ }
+
+ if (part != NULL && conf != NULL) {
+ /* makes conf lowercase */
+ for (i = 0; conf[i]; i++)
+ conf[i] = g_ascii_tolower (conf[i]);
+
+ /* return buffer */
+ result = g_strdup_printf ("PDF/A - %s%s", part, conf);
+ }
+
+ /* Cleanup */
+ xmlFree (part);
+ xmlFree (conf);
+
+ return result;
+}
+
+static EvDocumentLicense *
+pdf_document_get_license_from_metadata (xmlDocPtr doc,
+ xmlXPathContextPtr xpathCtx)
+{
+ xmlXPathObjectPtr xpathObj;
+ xmlChar *marked = NULL;
+ const char *language_string;
+ char *aux;
+ gchar **tags;
+ gchar *tag, *tag_aux;
+ int i, j;
+ EvDocumentLicense *license;
+
+ /* register namespaces */
+ xmlXPathRegisterNs (xpathCtx, BAD_CAST "x", BAD_CAST "adobe:ns:meta/");
+ xmlXPathRegisterNs (xpathCtx, BAD_CAST "rdf", BAD_CAST "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ xmlXPathRegisterNs (xpathCtx, BAD_CAST "dc", BAD_CAST "http://purl.org/dc/elements/1.1/");
+ /* XMP Rights Management Schema */
+ xmlXPathRegisterNs (xpathCtx, BAD_CAST "xmpRights", BAD_CAST "http://ns.adobe.com/xap/1.0/rights/");
+ /* Creative Commons Schema */
+ xmlXPathRegisterNs (xpathCtx, BAD_CAST "cc", BAD_CAST "http://creativecommons.org/ns#");
+
+ /* checking if the document has been marked as defined on the XMP Rights
+ * Management Schema */
+ xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_MARKED, xpathCtx);
+ if (xpathObj != NULL) {
+ if (xpathObj->nodesetval != NULL &&
+ xpathObj->nodesetval->nodeNr != 0)
+ marked = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
+ xmlXPathFreeObject (xpathObj);
+ }
+
+ /* a) Not marked => No XMP Rights information */
+ if (!marked) {
+ xmlFree (marked);
+ return NULL;
+ }
+
+ license = ev_document_license_new ();
+
+ /* b) Marked False => Public Domain, no copyrighted material and no
+ * license needed */
+ if (g_strrstr ((char *) marked, "False") != NULL) {
+ license->text = g_strdup (_("This work is in the Public Domain"));
+ /* c) Marked True => Copyrighted material */
+ } else {
+ /* Checking usage terms as defined by the XMP Rights Management
+ * Schema. This field is recomended to be checked by Creative
+ * Commons */
+ /* 1) checking for a suitable localized string */
+ language_string = pango_language_to_string (gtk_get_default_language ());
+ tags = g_strsplit (language_string, "-", -1);
+ i = g_strv_length (tags);
+ while (i-- && !license->text) {
+ tag = g_strdup (tags[0]);
+ for (j = 1; j <= i; j++) {
+ tag_aux = g_strdup_printf ("%s-%s", tag, tags[j]);
+ g_free (tag);
+ tag = tag_aux;
+ }
+ aux = g_strdup_printf (LICENSE_TEXT, tag);
+ xpathObj = xmlXPathEvalExpression (BAD_CAST aux, xpathCtx);
+ if (xpathObj != NULL) {
+ if (xpathObj->nodesetval != NULL &&
+ xpathObj->nodesetval->nodeNr != 0)
+ license->text = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
+ xmlXPathFreeObject (xpathObj);
+ }
+ g_free (tag);
+ g_free (aux);
+ }
+ g_strfreev(tags);
+
+ /* 2) if not, use the default string */
+ if (!license->text) {
+ aux = g_strdup_printf (LICENSE_TEXT, "x-default");
+ xpathObj = xmlXPathEvalExpression (BAD_CAST aux, xpathCtx);
+ if (xpathObj != NULL) {
+ if (xpathObj->nodesetval != NULL &&
+ xpathObj->nodesetval->nodeNr != 0)
+ license->text = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
+ xmlXPathFreeObject (xpathObj);
+ }
+ g_free (aux);
+ }
+
+ /* Checking the license URI as defined by the Creative Commons
+ * Schema. This field is recomended to be checked by Creative
+ * Commons */
+ xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_URI, xpathCtx);
+ if (xpathObj != NULL) {
+ if (xpathObj->nodesetval != NULL &&
+ xpathObj->nodesetval->nodeNr != 0)
+ license->uri = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
+ xmlXPathFreeObject (xpathObj);
+ }
+
+ /* Checking the web statement as defined by the XMP Rights
+ * Management Schema. Checking it out is a sort of above-and-beyond
+ * the basic recommendations by Creative Commons. It can be
+ * considered as a "reinforcement" approach to add certainty. */
+ xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_WEB_STATEMENT, xpathCtx);
+ if (xpathObj != NULL) {
+ if (xpathObj->nodesetval != NULL &&
+ xpathObj->nodesetval->nodeNr != 0)
+ license->web_statement = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
+ xmlXPathFreeObject (xpathObj);
+ }
+ }
+ xmlFree (marked);
+
+ if (!license->text && !license->uri && !license->web_statement) {
+ ev_document_license_free (license);
+ return NULL;
+ }
+
+ return license;