After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 349173 - Creative Commons license show
Creative Commons license show
Status: RESOLVED FIXED
Product: evince
Classification: Core
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Evince Maintainers
Evince Maintainers
Depends on:
Blocks:
 
 
Reported: 2006-07-29 14:37 UTC by Jaime Frutos Morales
Modified: 2009-10-26 08:05 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
PDF with embedded license XMP data (291.79 KB, application/x-pdf)
2008-10-20 18:42 UTC, Greg Grossmeier
  Details
Add support for (Creative Commons) license info (9.31 KB, patch)
2009-06-07 22:06 UTC, Juanjo Marín
needs-work Details | Review
Add support for (Creative Commons) license info (without a dedicated tab yet) (9.41 KB, patch)
2009-06-13 11:05 UTC, Juanjo Marín
none Details | Review
Proposes patch for Bug 349173 – Show license information from metadata (20.76 KB, patch)
2009-07-21 22:24 UTC, Juanjo Marín
committed Details | Review

Description Jaime Frutos Morales 2006-07-29 14:37:03 UTC
It would be great if Evince shows the Creative Commons license of the open PDF if available. Info on how to do this:

http://creativecommons.org/technology/xmp
Comment 1 Nickolay V. Shmyrev 2006-08-04 23:41:50 UTC
Sorry, I don't understand completely, where should we show it. Doesn't document itself should include licence sign? Why then must we duplicate that into viewer?
Comment 2 Jaime Frutos Morales 2006-08-05 00:22:06 UTC
I'm talking about metadata info. A document can have an embedded CC license but this doesn't mean that it has to show a CC license sign (altough it should). See this link (http://creativecommons.org/technology/xmp) for more info.

I think that if the document has an embedded license as metadata, we should notify the user about it by a CC icon and showing the kind of license and maybe a link to the license deed web.
Comment 3 Nickolay V. Shmyrev 2006-10-01 12:05:56 UTC
Well, it would be nice to have something like that in properties.
Comment 4 Luis Villa 2006-10-20 00:01:01 UTC
See for reference:
http://creativecommons.org/weblog/entry/6108

CC plugin for Acrobat.
Comment 5 Greg Grossmeier 2008-10-19 19:17:49 UTC
Simply showing the license information in the Properties dialog would be sufficient for this.

A license line with something like "License: Creative Commons Attribution-ShareAlike Unported 3.0" that is a clickable link to the license online would probably be preferable.

Creative Commons has developed a software library (LGPL) that reads and writes license metadata to a variety of file formats, including PDF.  If the file has the embedded license information it can give you a license name (eg: "Creative Commons Attribution"), link, and icon.  For this purpose the icon isn't needed nor the ability to write the metadata.

More information about the library, called liblicense, can be found here: http://wiki.creativecommons.org/Liblicense

Comment 6 Greg Grossmeier 2008-10-20 18:42:11 UTC
Created attachment 120951 [details]
PDF with embedded license XMP data

Attached is a pdf with embedded XMP license metadata.  The license is Creative Commons Attribution-ShareAlike 3.0.  

The raw XMP:
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
 <x:xmpmeta xmlns:x='adobe:ns:meta/'>
  <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
   <rdf:Description rdf:about='' xmlns:xapRights='http://ns.adobe.com/xap/1.0/rights/'>
    <xapRights:Marked>True</xapRights:Marked>
    <xapRights:WebStatement>http://creativecommons.org/licenses/by-sa/3.0/</xapRights:WebStatement>
   </rdf:Description>
   <rdf:Description rdf:about='' xmlns:dc='http://purl.org/dc/elements/1.1/'>
    <dc:rights>
     <rdf:Alt>
      <rdf:li xml:lang='x-default'>This work is licensed to the public under the Creative Commons Attribution-ShareAlike 3.0 License.</rdf:li>
     </rdf:Alt>
    </dc:rights>
   </rdf:Description>
   <rdf:Description rdf:about='' xmlns:cc='http://creativecommons.org/ns#'>
    <cc:license>http://creativecommons.org/licenses/by-sa/3.0/</cc:license>
   </rdf:Description>
  </rdf:RDF>
 </x:xmpmeta>
Comment 7 Juanjo Marín 2009-05-31 23:40:35 UTC
I'm working on a patch for this bug. By know I'm little bit confused about the properties I have to check. AFIK, the XMP license metadata attached above is not does not fullfil the recommended template (1) because the license url must be on the rdf:resource attribute.

On the other hand, on (2), the recommended propierties to check are xapRights:WebStatement for the web reference and cc:license for the license. But it doesn't mention anything about rdf:Description/dc:rights/rdf:Alt/rdf:li used on the template. 

Any comment or tip about this ? ;)

(1) http://creativecommons.org/license/xmp?q_1=2&q_1=1&field_commercial=yes&field_derivatives=yes&field_jurisdiction=us&field_format=&field_worktitle=&field_attribute_to_name=&field_attribute_to_url=&field_sourceurl=&field_morepermissionsurl=&lang=en_US&language=en_US&n_questions=3
This link is on http://wiki.creativecommons.org/Marking , on the instructions for PDF files.

(2) http://wiki.creativecommons.org/Marking_Works_Technical#Document_formats
Comment 8 Juanjo Marín 2009-05-31 23:44:28 UTC
... And the recommended template doesn't have the xapRights:WebStatement :(
Comment 9 Juanjo Marín 2009-06-07 22:06:15 UTC
Created attachment 136111 [details] [review]
Add support for (Creative Commons) license info

I attach my patch for this bug. I follow the rules about tagging by Creative Commons. The information extracted from metadata is the license, license uri and web statement (optional field).

I've noticed that there is some confusion about where is the license uri must be located. On the example sent by Greg Grossmeier this info is an element's content but I was told [1] that this information must be an attribute value [2].

Probably, the pdf sent by Greg Grossmeier was tagged with PdfLicenseManager [3] that doesn't tag the pdfs correctly. I sent a patch to fix this [4]. Anyway, this app tag the web statement with the license uri, so this information is not lost in the pdf tagged with this program.

I took the following decisions for this patch:

1) Search for a translated license text. Though I think is not very common, the XMP specification documents it as such: "Informal rights statement, selected by language." [5]

2) Show the license, license uri and web statement as a new items for the window propierties.

3) These lines are only shown if there is information, not if empty

4) I turns the uri's from the window propierties linkable (this means to turn the File path linkable, but, I think this is a feature, not a bug).

PS: I have some concerns about using just a line for the license text. This can be a problem if the license text is very long.

References:

[1] http://lists.ibiblio.org/pipermail/cc-devel/2009-June/001386.html
[2] http://creativecommons.org/license/xmp?q_1=2&q_1=1&field_commercial=yes&field_derivatives=yes&field_jurisdiction=us&field_format=&field_worktitle=&field_attribute_to_name=&field_attribute_to_url=&field_sourceurl=&field_morepermissionsurl=&lang=en_US&language=en_US&n_questions=3
[3] http://wiki.creativecommons.org/PdfLicenseManager
[4] http://lists.ibiblio.org/pipermail/cc-devel/2009-June/001390.html
[5] http://lists.ibiblio.org/pipermail/cc-devel/2009-June/001388.html
Comment 10 Carlos Garcia Campos 2009-06-08 09:09:05 UTC
Comment on attachment 136111 [details] [review]
Add support for (Creative Commons) license info

Hey Juanjo, good job!. Some comments below

>diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
>index 71f2da4..8499185 100644
>--- a/backend/pdf/ev-poppler.cc
>+++ b/backend/pdf/ev-poppler.cc
>@@ -667,6 +667,127 @@ pdf_document_get_format_from_metadata (const char *metadata)
> }
> 
> 
>+static void
>+pdf_document_get_license_from_metadata (const char *metadata, EvDocumentInfo *info)
>+{
>+	xmlDocPtr doc;
>+	xmlXPathContextPtr xpathCtx;
>+	xmlXPathObjectPtr xpathObj;
>+	xmlChar *marked = NULL;
>+	
>+	const char *license = "/x:xmpmeta/rdf:RDF/rdf:Description/dc:rights/rdf:Alt/rdf:li[lang('%s')]";
>+	const char *license_uri = "/x:xmpmeta/rdf:RDF/rdf:Description/cc:license/@rdf:resource";
>+	const char *license_web_statement = "/x:xmpmeta/rdf:RDF/rdf:Description/xmpRights:WebStatement";

move these as #define better

>+	const char *language_string;
>+	gchar **tags;
>+	gchar *tag, *tag_aux;
>+	int i, j;
>+
>+	doc = xmlParseMemory (metadata, strlen (metadata));
>+	if (doc == NULL)
>+		return;		/* invalid xml metadata */
>+
>+	xpathCtx = xmlXPathNewContext (doc);
>+	if (xpathCtx == NULL) {
>+		xmlFreeDoc (doc);
>+		return;		/* invalid xpath context */
>+	}
>+
>+	/* add license 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 "xmpRights", BAD_CAST "http://ns.adobe.com/xap/1.0/rights/");
>+	xmlXPathRegisterNs (xpathCtx, BAD_CAST "dc", BAD_CAST "http://purl.org/dc/elements/1.1/");
>+	xmlXPathRegisterNs (xpathCtx, BAD_CAST "cc", BAD_CAST "http://creativecommons.org/ns#");
>+	
>+	xpathObj = xmlXPathEvalExpression (BAD_CAST 
>+		"/x:xmpmeta/rdf:RDF/rdf:Description/xmpRights:Marked", xpathCtx);
>+	if (xpathObj != NULL) {
>+		if (xpathObj->nodesetval != NULL &&
>+		    xpathObj->nodesetval->nodeNr != 0)
>+			marked = xmlNodeGetContent (
>+				xpathObj->nodesetval->nodeTab[0]);
>+		xmlXPathFreeObject (xpathObj);
>+	}
>+	if (marked) {

I prefer if (!marked) { free everything and return } so that we save an indentation level here. 

>+		if (g_strrstr (g_ascii_strdown ((char *) marked, -1), "false") != 
>+		    NULL)

why this? marked should be True or False and only this way according to the xmp spec:

"Boolean
Allowed values are True or False (the strings should be spelled exactly as shown)."

>+			info->license = _("Public Domain");
>+		else {
>+			/* license text */
>+			/* a) check 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-- && !info->license) {

tags is a null terminated array of strings, something like this looks more natural to me and you don't need the length. 

for (i = 0; tags[i] && !info->license; i++) 


>+				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;
>+				}
>+				xpathObj = xmlXPathEvalExpression (BAD_CAST 
>+						g_strdup_printf (license, tag), 
>+						xpathCtx);

g_strdup_printf returns a new allocated string, you need a variable to be able to free the result. 

>+				if (xpathObj != NULL) {
>+					if (xpathObj->nodesetval != NULL && 
>+					    xpathObj->nodesetval->nodeNr != 0)
>+						info->license = (char *) 
>+						     xmlNodeGetContent (
>+						        xpathObj->nodesetval->nodeTab[0]);
>+					xmlXPathFreeObject (xpathObj);
>+				}
>+				g_free (tag);


>+			}
>+			g_strfreev(tags);
>+			/* b) if not, use the default string */
>+			if (!info->license) {
>+				xpathObj = xmlXPathEvalExpression (BAD_CAST 
>+						g_strdup_printf (license, "x-default"), 
>+						xpathCtx);

you are leaking here too. 


I think the license might be a struct with 3 members, instead of 3 different properties. You can make it a boxed type so that it'll be a single property. 

Regarding the case of a long license text, what about adding a new tab in the properties dialog for the license?
Comment 11 Juanjo Marín 2009-06-13 11:05:24 UTC
Created attachment 136497 [details] [review]
Add support for (Creative Commons) license info (without a dedicated tab yet)

Thanks for your reviewing and for your comments :)

>>+			i = g_strv_length (tags);
>>+			while (i-- && !info->license) {
>
>tags is a null terminated array of strings, something like this looks more
>natural to me and you don't need the length. 
>
>for (i = 0; tags[i] && !info->license; i++) 
>
>+				tag = g_strdup (tags[0]);

Well, although your suggestions makes the code cleaner, it doesn't do what I try to do. I just want to choose the closest tag to the locale, so, for example, I want to try first "en-US" and then "en". This is a sort-of the lookup scheme as explained in [1]


>Regarding the case of a long license text, what about adding a new tab in the
>properties dialog for the license?

Good idea, but I don't have time to implement it. I have to present my essay for the Master tomorrow, 14th june; after that, I have to defend it, but, even worse, I have an exam for promotion at the end of the month that I want to pass. So surely I'll have no free time to implement until july, so I hope I can finish it before the string freeze.

The strings will be, License (for the tab), and License, License uri and Web statement for the fields (unless someone suggests better names). On the present patch, these string are used (License tab = License field), so maybe it can be applied now and add the tab on another patch. 

[1] http://tools.ietf.org/html/rfc4647#section-3.4
Comment 12 Juanjo Marín 2009-06-13 11:17:00 UTC
Related:

Bug 585627 – The new GtkLabel link support seems to be broken
Comment 13 Christian Persch 2009-07-03 17:04:50 UTC
The code in pdf_document_get_license_from_metadata is rather hard to understand. I guess one needs to be familiar with the spec to understand it? Could you add some verbose code comments explaining the various steps?
Comment 14 Juanjo Marín 2009-07-03 22:05:51 UTC
#13
You right chpe, I'll add some comments on the next patch. I'm starting to work on this patch showing the license information on a different propierty tab.
Comment 15 Juanjo Marín 2009-07-21 22:24:04 UTC
Created attachment 138948 [details] [review]
Proposes patch for  Bug 349173 – Show license information from metadata

Hi, I added a nice optional -HIGified?- tab [1] and some comments about the process of parsing the metadata information.

I'm not quite sure about the correctness of the code for this new tab. I added a new class called EvPropertiesLicenseView (properties/ev-properties-license-view.h|c). It's a sort of copy/paste from properties/ev-license-view.h|c and I don't know if this is a good practice, it seems to me a ugly hack. But I wasn't able to make more beautiful code ;)

Reviews, comments and suggestions are welcome !!!

[1] http://www.flickr.com/photos/jjmarin/3735878162/
Comment 16 Juanjo Marín 2009-10-15 23:40:19 UTC
I tried the patch with the current master [1] and it applies without any conflict.

http://git.gnome.org/cgit/evince/commit/?id=b22c1a082138df98c8f8de51fb263f02e3bb17bd
Comment 17 Carlos Garcia Campos 2009-10-25 18:38:42 UTC
Review of attachment 138948 [details] [review]:

Patch applied to git master with some modifications. Thank you very much!
Comment 18 Juanjo Marín 2009-10-26 08:05:21 UTC
Final tab propierty added:

http://www.flickr.com/photos/jjmarin/4044765162/