1
/* xmp-encode.c - generate XMP metadata from the tree model
3
* Copyright (C) 2005, Raphaël Quinet <raphael@gimp.org>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
27
#include <libgimp/gimp.h>
28
#include <libgimp/gimpui.h>
30
#include "libgimp/stdplugins-intl.h"
32
#include "xmp-encode.h"
33
#include "xmp-schemas.h"
36
gen_schema_start (GString *buffer,
37
const XMPSchema *schema)
39
g_string_append_printf (buffer, " <rdf:Description xmlns:%s='%s'>\n",
40
schema->prefix, schema->uri);
44
gen_schema_end (GString *buffer)
46
g_string_append (buffer, " </rdf:Description>\n\n");
50
gen_property (GString *buffer,
51
const XMPSchema *schema,
52
const XMPProperty *property,
53
const gchar **value_array)
56
const gchar *ns_prefix;
58
switch (property->type)
60
case XMP_TYPE_BOOLEAN:
62
case XMP_TYPE_INTEGER:
64
case XMP_TYPE_MIME_TYPE:
66
case XMP_TYPE_RATIONAL:
67
g_string_append_printf (buffer, " <%s:%s>%s</%s:%s>\n",
68
schema->prefix, property->name,
70
schema->prefix, property->name);
73
case XMP_TYPE_LOCALE_BAG:
74
case XMP_TYPE_TEXT_BAG:
75
case XMP_TYPE_XPATH_BAG:
76
case XMP_TYPE_JOB_BAG:
77
g_string_append_printf (buffer, " <%s:%s>\n <rdf:Bag>\n",
78
schema->prefix, property->name);
79
for (i = 0; value_array[i] != NULL; i++)
80
g_string_append_printf (buffer, " <rdf:li>%s</rdf:li>\n",
82
g_string_append_printf (buffer, " </rdf:Bag>\n </%s:%s>\n",
83
schema->prefix, property->name);
86
case XMP_TYPE_INTEGER_SEQ:
87
case XMP_TYPE_TEXT_SEQ:
88
case XMP_TYPE_RESOURCE_EVENT_SEQ:
89
case XMP_TYPE_RATIONAL_SEQ:
90
g_string_append_printf (buffer, " <%s:%s>\n <rdf:Seq>\n",
91
schema->prefix, property->name);
92
for (i = 0; value_array[i] != NULL; i++)
93
g_string_append_printf (buffer, " <rdf:li>%s</rdf:li>\n",
95
g_string_append_printf (buffer, " </rdf:Seq>\n </%s:%s>\n",
96
schema->prefix, property->name);
99
case XMP_TYPE_LANG_ALT:
100
g_string_append_printf (buffer, " <%s:%s>\n <rdf:Alt>\n",
101
schema->prefix, property->name);
102
for (i = 0; value_array[i] != NULL; i += 2)
103
g_string_append_printf (buffer,
104
" <rdf:li xml:lang='%s'>%s</rdf:li>\n",
105
value_array[i], value_array[i + 1]);
106
g_string_append_printf (buffer, " </rdf:Alt>\n </%s:%s>\n",
107
schema->prefix, property->name);
111
g_string_append_printf (buffer, " <%s:%s rdf:resource='%s' />\n",
112
schema->prefix, property->name, value_array[0]);
115
case XMP_TYPE_RESOURCE_REF:
116
case XMP_TYPE_DIMENSIONS:
117
case XMP_TYPE_GPS_COORDINATE:
119
case XMP_TYPE_OECF_SFR:
120
case XMP_TYPE_CFA_PATTERN:
121
case XMP_TYPE_DEVICE_SETTINGS:
122
case XMP_TYPE_CONTACT_INFO:
123
case XMP_TYPE_GENERIC_STRUCTURE:
124
if (value_array[0] && value_array[1]
125
&& !! strcmp (value_array[1], schema->uri))
127
g_string_append_printf (buffer,
128
" <%s:%s rdf:parseType='Resource'\n"
130
schema->prefix, property->name,
131
value_array[0], value_array[1]);
132
ns_prefix = value_array[0];
136
g_string_append_printf (buffer,
137
" <%s:%s rdf:parseType='Resource'>\n",
138
schema->prefix, property->name);
139
ns_prefix = schema->prefix;
141
for (i = 2; value_array[i] != NULL; i += 2)
142
g_string_append_printf (buffer, " <%s:%s>%s</%s:%s>\n",
143
ns_prefix, value_array[i],
145
ns_prefix, value_array[i]);
146
g_string_append_printf (buffer, " </%s:%s>\n",
147
schema->prefix, property->name);
150
case XMP_TYPE_THUMBNAIL_ALT:
151
g_warning ("FIXME: output not implemented yet (%s:%s)",
152
schema->prefix, property->name);
155
case XMP_TYPE_UNKNOWN:
156
g_warning ("Unknown property type for %s", property->name);
162
* xmp_generate_block:
163
* @xmp_model: An #XMPModel
164
* @buffer: A #GString in which the generated XMP packet will be stored.
166
* Generate XMP packet from xmp_model and store it in the supplied buffer.
170
xmp_generate_packet (XMPModel *xmp_model,
176
const XMPSchema *schema;
179
g_return_if_fail (xmp_model != NULL);
180
g_return_if_fail (buffer != NULL);
181
model = xmp_model_get_tree_model (xmp_model);
182
g_return_if_fail (model != NULL);
184
buffer = g_string_new (NULL);
185
buffer = g_string_append (buffer,
186
"<?xpacket begin='\357\273\277' id='W5M0MpCehiHzreSzNTczkc9d'?>\n"
187
"<x:xmpmeta xmlns:x='adobe:ns:meta/'>\n"
188
"<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n"
190
/* generate the contents of the XMP packet */
191
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter))
195
gtk_tree_model_get (model, &iter,
196
COL_XMP_TYPE_XREF, &schema,
198
gen_schema_start (buffer, schema);
199
if (gtk_tree_model_iter_children (model, &child, &iter))
204
const XMPProperty *property;
205
const gchar **value_array;
207
gtk_tree_model_get (model, &child,
208
COL_XMP_TYPE_XREF, &property,
209
COL_XMP_VALUE_RAW, &value_array,
211
/* do not process structured types multiple times */
212
if (saved_ref != value_array)
214
saved_ref = value_array;
215
g_return_if_fail (property->name != NULL);
216
gen_property (buffer, schema, property, value_array);
219
while (gtk_tree_model_iter_next (model, &child));
221
gen_schema_end (buffer);
223
while (gtk_tree_model_iter_next (model, &iter));
225
g_string_append (buffer, "</rdf:RDF>\n</x:xmpmeta>\n<?xpacket end='r'?>\n");