• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作図ソフト dia の改良版


Commit MetaInfo

Revision8f4005ff0481d7205c0b69fce8c84dfdd044a092 (tree)
Zeit2014-09-26 04:20:11
AutorHans Breuer <hans@breu...>
CommiterHans Breuer

Log Message

image: fix 'Standard - Image' set_props() for pixbuf changes

- switch on inline data => make inline: set pixbuf, keep filename
- switch off inline data => save pixbuf to filename, if new filename
- set a new, non empty filename => load the file
- set an empty filename => make inline
- set a new, non NULL pixbuf => use as image, inline

Also provide a test file and an updated uninline_data.py script.

Ändern Zusammenfassung

Diff

--- a/objects/standard/image.c
+++ b/objects/standard/image.c
@@ -116,9 +116,9 @@ static PropDescription image_props[] = {
116116 ELEMENT_COMMON_PROPERTIES,
117117 { "image_file", PROP_TYPE_FILE, PROP_FLAG_VISIBLE,
118118 N_("Image file"), NULL, NULL},
119- { "inline_data", PROP_TYPE_BOOL, PROP_FLAG_DONT_MERGE|PROP_FLAG_VISIBLE|PROP_FLAG_OPTIONAL,
119+ { "inline_data", PROP_TYPE_BOOL, PROP_FLAG_VISIBLE|PROP_FLAG_OPTIONAL,
120120 N_("Inline data"), N_("Store image data in diagram"), NULL },
121- { "pixbuf", PROP_TYPE_PIXBUF, PROP_FLAG_OPTIONAL,
121+ { "pixbuf", PROP_TYPE_PIXBUF, PROP_FLAG_DONT_MERGE|PROP_FLAG_OPTIONAL,
122122 N_("Pixbuf"), N_("The Pixbuf reference"), NULL },
123123 { "show_border", PROP_TYPE_BOOL, PROP_FLAG_VISIBLE,
124124 N_("Draw border"), NULL, NULL},
@@ -191,6 +191,27 @@ image_get_props(Image *image, GPtrArray *props)
191191 object_get_props_from_offsets(&image->element.object, image_offsets, props);
192192 }
193193
194+/*!
195+ * \brief Set properties of the _Image
196+ * \memberof _Image
197+ *
198+ * The properties of _Image are not completely independent. Some logic
199+ * in this method should lead to a consistent object state.
200+ *
201+ * - with inline_data=TRUE we shall have a valid pixbuf
202+ * - with inline_data=FALSE we should have a valid filename (when created
203+ * from scratch we don't)
204+ *
205+ * Changing the properties tries to ensure consistency and might trigger
206+ * additional actions like saving a file or loading it from disk. Also
207+ * some dependent parameters might change in response.
208+ *
209+ * - switch on inline data => make inline: set pixbuf, keep filename
210+ * - switch off inline data => save pixbuf to filename, if new filename
211+ * - set a new, non empty filename => load the file
212+ * - set an empty filename => make inline
213+ * - set a new, non NULL pixbuf => use as image, inline
214+ */
194215 static void
195216 image_set_props(Image *image, GPtrArray *props)
196217 {
@@ -202,43 +223,47 @@ image_set_props(Image *image, GPtrArray *props)
202223
203224 object_set_props_from_offsets(&image->element.object, image_offsets, props);
204225
205- if (old_pixbuf != image->pixbuf) {
206- if (!image->file || *image->file == '\0') {
207- GdkPixbuf *pixbuf = NULL;
208- image->inline_data = TRUE; /* otherwise we'll loose it */
209- /* somebody deleting the filename? */
210- if (!image->pixbuf && image->image)
211- pixbuf = g_object_ref ((GdkPixbuf *)dia_image_pixbuf (image->image));
212- if (image->image)
213- g_object_unref (image->image);
214- image->image = dia_image_new_from_pixbuf (image->pixbuf ? image->pixbuf : pixbuf);
215- if (image->pixbuf)
216- g_object_unref (image->pixbuf);
217- image->pixbuf = g_object_ref ((GdkPixbuf *)dia_image_pixbuf (image->image));
218- if (pixbuf)
219- g_object_unref (pixbuf);
220- } else {
221- if (image->pixbuf) {
222- if (image->image)
223- g_object_unref (image->image);
224- image->image = dia_image_new_from_pixbuf (image->pixbuf);
225- }
226- }
227- }
228-
229226 /* use old value on error */
230227 if (!image->file || g_stat (image->file, &st) != 0)
231228 mtime = image->mtime;
232229 else
233230 mtime = st.st_mtime;
234231
235- /* handle changing the image. */
236- if (image->file && image->pixbuf && was_inline && !image->inline_data) {
237- /* export inline data */
238- if (was_inline && !image->inline_data)
239- /* if saving fails we keep it inline */
240- image->inline_data = !dia_image_save (image->image, image->file);
241- } else if (image->file && ((old_file && strcmp(image->file, old_file) != 0) || image->mtime != mtime)) {
232+ if ( (!was_inline && image->inline_data && old_pixbuf)
233+ || ( (!image->file || strlen(image->file) == 0)
234+ && old_pixbuf)
235+ || (image->pixbuf && (image->pixbuf != old_pixbuf))) { /* switch on inline */
236+ if (!image->pixbuf || old_pixbuf == image->pixbuf) { /* just reference the old image */
237+ image->pixbuf = g_object_ref ((GdkPixbuf *)old_pixbuf);
238+ image->inline_data = TRUE;
239+ } else if (old_pixbuf != image->pixbuf && image->pixbuf) { /* substitute the image and pixbuf */
240+ DiaImage *old_image = image->image;
241+ image->image = dia_image_new_from_pixbuf (image->pixbuf);
242+ image->pixbuf = g_object_ref ((GdkPixbuf *)dia_image_pixbuf (image->image));
243+ if (old_image)
244+ g_object_unref (old_image);
245+ image->inline_data = TRUE;
246+ } else {
247+ image->inline_data = FALSE;
248+ g_warning ("Not setting inline_data");
249+ }
250+ } else if (was_inline && !image->inline_data) { /* switch off inline */
251+ if (old_file && image->file && strcmp (old_file, image->file) != 0) {
252+ /* export inline data, if saving fails we keep it inline */
253+ image->inline_data = !dia_image_save (image->image, image->file);
254+ } else if (!image->file) {
255+ message_warning (_("Can't save image without filename"));
256+ image->inline_data = TRUE; /* keep inline */
257+ }
258+ if (!image->inline_data) {
259+ /* drop the pixbuf reference */
260+ if (image->pixbuf)
261+ g_object_unref (image->pixbuf);
262+ image->pixbuf = NULL;
263+ }
264+ } else if ( image->file && strlen(image->file) > 0
265+ && ( (!old_file || (strcmp (old_file, image->file) != 0))
266+ || (image->mtime != mtime))) { /* load new file */
242267 Element *elem = &image->element;
243268 DiaImage *img = NULL;
244269
@@ -249,9 +274,20 @@ image_set_props(Image *image, GPtrArray *props)
249274 elem->height = (elem->width*(float)dia_image_height(image->image))/
250275 (float)dia_image_width(image->image);
251276 /* release image->pixbuf? */
277+ } else if ((!image->file || strlen(image->file)==0) && !image->pixbuf) {
278+ /* make it a "broken image" without complaints */
279+ dia_log_message ("_Image::set_props() seting empty.");
280+ } else {
281+ if ( (image->inline_data && image->pixbuf != NULL) /* don't need a filename */
282+ || (!image->inline_data && image->file)) /* don't need a pixbuf */
283+ dia_log_message ("_Image::set_props() ok.");
284+ else
285+ g_warning ("_Image::set_props() not handled file='%s', pixbuf=%p, inline=%s",
286+ image->file ? image->file : "",
287+ image->pixbuf, image->inline_data ? "TRUE" : "FALSE");
252288 }
253289 g_free(old_file);
254- /* remember it */
290+ /* remember modification time */
255291 image->mtime = mtime;
256292
257293 image_update_data(image);
@@ -839,6 +875,11 @@ image_load(ObjectNode obj_node, int version, DiaContext *ctx)
839875 g_object_unref (pixbuf);
840876 }
841877 }
878+ } else {
879+ attr = object_find_attribute(obj_node, "inline_data");
880+ if (attr != NULL)
881+ image->inline_data = data_boolean(attribute_first_data(attr), ctx);
882+ /* Should be set pixbuf, too? Or leave it till the first get. */
842883 }
843884
844885 /* update mtime */
--- a/plug-ins/python/uninline_data.py
+++ b/plug-ins/python/uninline_data.py
@@ -24,6 +24,7 @@ class UninlineRenderer :
2424 def begin_render (self, data, filename) :
2525 imgmap = {}
2626 dirname = os.path.dirname (filename)
27+ basename = os.path.basename(filename)
2728 ext = filename[string.rfind(filename, ".")+1:]
2829 for layer in data.layers :
2930 for o in layer.objects :
@@ -33,7 +34,7 @@ class UninlineRenderer :
3334 pos = o.properties["obj_pos"].value
3435 xk = "%03g" % pos.x
3536 yk = "%03g" % pos.y
36- key = "L" + layer.name + "x" + xk + "y" + yk
37+ key = basename + "-" + layer.name + "x" + xk + "y" + yk
3738 imgmap[key] = o
3839 for k, o in imgmap.iteritems() :
3940 fname = dirname + "/" + k + "." + ext
Binary files /dev/null and b/samples/image-test.dia differ