Issue #14759: link layers (of vector files) initial dimensions will fill…
… the whole canvas while keeping aspect ratio of the source image. The previous dimensions were not entirely "out of the blue" since they were taken from the file, but very often dimensions from vector images are kinda bogus (apart from aspect ratio, they don't mean much) anyway. Now we will just fill the canvas box by default. When changing the source file of an existing link layer though (through Link Layer properties), the dimensions will be within the current layer bounding box. Also I realized that we need to also store the link width/height in the XCF because the buffer width/height may not be right (in case a transform matrix was applied). This commit therefore breaks XCF file with link layers made in the last 2 days. Since we have not made even a dev release, it's probably fine to do this and not bump the XCF version.
This commit is contained in:
parent
9519901150
commit
4f3aee5e83
12 changed files with 88 additions and 18 deletions
|
|
@ -865,7 +865,7 @@ file_revert_confirm_response (GtkWidget *dialog,
|
|||
|
||||
new_image = file_open_image (gimp, gimp_get_user_context (gimp),
|
||||
GIMP_PROGRESS (display),
|
||||
file, 0, 0, FALSE, NULL,
|
||||
file, 0, 0, TRUE, FALSE, NULL,
|
||||
GIMP_RUN_INTERACTIVE,
|
||||
NULL, &status, NULL, &error);
|
||||
|
||||
|
|
|
|||
|
|
@ -548,7 +548,7 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
|
|||
}
|
||||
|
||||
image = file_open_image (private->gimp, context, progress,
|
||||
private->file, size, size,
|
||||
private->file, size, size, TRUE,
|
||||
FALSE, NULL,
|
||||
GIMP_RUN_NONINTERACTIVE,
|
||||
NULL, &status, &mime_type, error);
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ struct _GimpLinkPrivate
|
|||
gboolean is_vector;
|
||||
gint width;
|
||||
gint height;
|
||||
gboolean keep_ratio;
|
||||
GimpImageBaseType base_type;
|
||||
GimpPrecision precision;
|
||||
GimpPlugInProcedure *load_proc;
|
||||
|
|
@ -216,7 +217,7 @@ gimp_link_set_property (GObject *object,
|
|||
link->p->gimp = g_value_get_object (value);
|
||||
break;
|
||||
case PROP_FILE:
|
||||
gimp_link_set_file (link, g_value_get_object (value), NULL, NULL);
|
||||
gimp_link_set_file (link, g_value_get_object (value), 0, 0, FALSE, NULL, NULL);
|
||||
break;
|
||||
case PROP_ABSOLUTE_PATH:
|
||||
link->p->absolute_path = g_value_get_boolean (value);
|
||||
|
|
@ -304,6 +305,7 @@ gimp_link_update_buffer (GimpLink *link,
|
|||
progress,
|
||||
link->p->file,
|
||||
link->p->width, link->p->height,
|
||||
link->p->keep_ratio,
|
||||
FALSE, NULL,
|
||||
/* XXX We might want interactive opening
|
||||
* for a first opening (when done through
|
||||
|
|
@ -468,6 +470,9 @@ gimp_link_get_relative_path (GimpLink *link,
|
|||
GimpLink *
|
||||
gimp_link_new (Gimp *gimp,
|
||||
GFile *file,
|
||||
gint vector_width,
|
||||
gint vector_height,
|
||||
gboolean keep_ratio,
|
||||
GimpProgress *progress,
|
||||
GError **error)
|
||||
{
|
||||
|
|
@ -481,7 +486,7 @@ gimp_link_new (Gimp *gimp,
|
|||
"absolute-path", FALSE,
|
||||
NULL);
|
||||
|
||||
gimp_link_set_file (link, file, progress, error);
|
||||
gimp_link_set_file (link, file, vector_width, vector_height, keep_ratio, progress, error);
|
||||
|
||||
return GIMP_LINK (link);
|
||||
}
|
||||
|
|
@ -568,6 +573,9 @@ gimp_link_get_file (GimpLink *link,
|
|||
void
|
||||
gimp_link_set_file (GimpLink *link,
|
||||
GFile *file,
|
||||
gint vector_width,
|
||||
gint vector_height,
|
||||
gboolean keep_ratio,
|
||||
GimpProgress *progress,
|
||||
GError **error)
|
||||
{
|
||||
|
|
@ -577,7 +585,18 @@ gimp_link_set_file (GimpLink *link,
|
|||
|
||||
if (file == link->p->file ||
|
||||
(file && link->p->file && g_file_equal (file, link->p->file)))
|
||||
return;
|
||||
{
|
||||
if (link->p->width != vector_width ||
|
||||
link->p->height != vector_height ||
|
||||
link->p->keep_ratio != keep_ratio)
|
||||
gimp_link_set_size (link, vector_width, vector_height, keep_ratio);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
link->p->width = vector_width;
|
||||
link->p->height = vector_height;
|
||||
link->p->keep_ratio = keep_ratio;
|
||||
|
||||
g_clear_object (&link->p->monitor);
|
||||
|
||||
|
|
@ -654,12 +673,14 @@ gimp_link_is_broken (GimpLink *link)
|
|||
void
|
||||
gimp_link_set_size (GimpLink *link,
|
||||
gint width,
|
||||
gint height)
|
||||
gint height,
|
||||
gboolean keep_ratio)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_LINK (link));
|
||||
|
||||
link->p->width = width;
|
||||
link->p->height = height;
|
||||
link->p->width = width;
|
||||
link->p->height = height;
|
||||
link->p->keep_ratio = keep_ratio;
|
||||
|
||||
if (link->p->monitor && link->p->is_vector)
|
||||
gimp_link_update_buffer (link, NULL, NULL);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ GType gimp_link_get_type (void) G_GNUC_CONST;
|
|||
|
||||
GimpLink * gimp_link_new (Gimp *gimp,
|
||||
GFile *file,
|
||||
gint vector_width,
|
||||
gint vector_height,
|
||||
gboolean keep_ratio,
|
||||
GimpProgress *progress,
|
||||
GError **error);
|
||||
GimpLink * gimp_link_duplicate (GimpLink *link);
|
||||
|
|
@ -62,6 +65,9 @@ GFile * gimp_link_get_file (GimpLink *link,
|
|||
gchar **path);
|
||||
void gimp_link_set_file (GimpLink *layer,
|
||||
GFile *file,
|
||||
gint vector_width,
|
||||
gint vector_height,
|
||||
gboolean keep_ratio,
|
||||
GimpProgress *progress,
|
||||
GError **error);
|
||||
gboolean gimp_link_get_absolute_path (GimpLink *link);
|
||||
|
|
@ -75,7 +81,8 @@ gboolean gimp_link_is_broken (GimpLink *link);
|
|||
|
||||
void gimp_link_set_size (GimpLink *link,
|
||||
gint width,
|
||||
gint height);
|
||||
gint height,
|
||||
gboolean keep_ratio);
|
||||
void gimp_link_get_size (GimpLink *link,
|
||||
gint *width,
|
||||
gint *height);
|
||||
|
|
|
|||
|
|
@ -459,7 +459,7 @@ gimp_link_layer_scale (GimpItem *item,
|
|||
/* Non-modified vector images are always recomputed from the
|
||||
* source file and therefore are always sharp.
|
||||
*/
|
||||
gimp_link_set_size (link_layer->p->link, new_width, new_height);
|
||||
gimp_link_set_size (link_layer->p->link, new_width, new_height, FALSE);
|
||||
gimp_item_set_offset (item, new_offset_x, new_offset_y);
|
||||
gimp_link_layer_render_link (link_layer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -636,10 +636,27 @@ layer_options_file_set (GtkFileChooserButton *widget,
|
|||
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));
|
||||
if (file)
|
||||
{
|
||||
gimp_link_set_file (private->link, file, NULL, NULL);
|
||||
gint width = 0;
|
||||
gint height = 0;
|
||||
|
||||
if (private->layer)
|
||||
{
|
||||
width = gimp_item_get_width (GIMP_ITEM (private->layer));
|
||||
height = gimp_item_get_height (GIMP_ITEM (private->layer));
|
||||
|
||||
if (width == 0 || height == 0)
|
||||
{
|
||||
GimpImage *image = gimp_item_get_image (GIMP_ITEM (private->layer));
|
||||
|
||||
width = gimp_image_get_width (image);
|
||||
height = gimp_image_get_height (image);
|
||||
}
|
||||
}
|
||||
|
||||
gimp_link_set_file (private->link, file, width, height, TRUE, NULL, NULL);
|
||||
if (gimp_link_is_broken (private->link))
|
||||
{
|
||||
gimp_link_set_file (private->link, NULL, NULL, NULL);
|
||||
gimp_link_set_file (private->link, NULL, width, height, TRUE, NULL, NULL);
|
||||
g_signal_handlers_block_by_func (widget,
|
||||
G_CALLBACK (layer_options_file_set),
|
||||
private);
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ static GimpImage * file_open_link_image (Gimp *gimp,
|
|||
GFile *file,
|
||||
gint vector_width,
|
||||
gint vector_height,
|
||||
gboolean vector_keep_ratio,
|
||||
gboolean as_new,
|
||||
GimpPlugInProcedure *file_proc,
|
||||
GimpRunMode run_mode,
|
||||
|
|
@ -91,6 +92,7 @@ file_open_image (Gimp *gimp,
|
|||
GFile *file,
|
||||
gint vector_width,
|
||||
gint vector_height,
|
||||
gboolean vector_keep_ratio,
|
||||
gboolean as_new,
|
||||
GimpPlugInProcedure *file_proc,
|
||||
GimpRunMode run_mode,
|
||||
|
|
@ -207,7 +209,7 @@ file_open_image (Gimp *gimp,
|
|||
G_TYPE_FILE, file,
|
||||
G_TYPE_INT, vector_width,
|
||||
G_TYPE_INT, vector_height,
|
||||
G_TYPE_BOOLEAN, TRUE,
|
||||
G_TYPE_BOOLEAN, vector_keep_ratio,
|
||||
G_TYPE_BOOLEAN, vector_width && vector_height ? FALSE : TRUE,
|
||||
G_TYPE_NONE);
|
||||
}
|
||||
|
|
@ -515,7 +517,7 @@ file_open_with_proc_and_display (Gimp *gimp,
|
|||
|
||||
if (as_link)
|
||||
image = file_open_link_image (gimp, context, progress,
|
||||
file, 0, 0,
|
||||
file, 0, 0, TRUE,
|
||||
as_new,
|
||||
file_proc,
|
||||
run_mode,
|
||||
|
|
@ -525,7 +527,7 @@ file_open_with_proc_and_display (Gimp *gimp,
|
|||
error);
|
||||
else
|
||||
image = file_open_image (gimp, context, progress,
|
||||
file, 0, 0,
|
||||
file, 0, 0, TRUE,
|
||||
as_new,
|
||||
file_proc,
|
||||
run_mode,
|
||||
|
|
@ -635,6 +637,7 @@ file_open_layers (Gimp *gimp,
|
|||
file,
|
||||
gimp_image_get_width (dest_image),
|
||||
gimp_image_get_height (dest_image),
|
||||
TRUE,
|
||||
FALSE,
|
||||
file_proc,
|
||||
run_mode,
|
||||
|
|
@ -644,6 +647,7 @@ file_open_layers (Gimp *gimp,
|
|||
file,
|
||||
gimp_image_get_width (dest_image),
|
||||
gimp_image_get_height (dest_image),
|
||||
TRUE,
|
||||
FALSE,
|
||||
file_proc,
|
||||
run_mode,
|
||||
|
|
@ -761,6 +765,7 @@ file_open_link_image (Gimp *gimp,
|
|||
GFile *file,
|
||||
gint vector_width,
|
||||
gint vector_height,
|
||||
gboolean vector_keep_ratio,
|
||||
gboolean as_new,
|
||||
GimpPlugInProcedure *file_proc,
|
||||
GimpRunMode run_mode,
|
||||
|
|
@ -788,7 +793,9 @@ file_open_link_image (Gimp *gimp,
|
|||
|
||||
if (g_file_is_native (file) && file_proc != NULL)
|
||||
{
|
||||
GimpLink *link = gimp_link_new (gimp, file, progress, error);
|
||||
GimpLink *link = gimp_link_new (gimp, file,
|
||||
vector_width, vector_height, vector_keep_ratio,
|
||||
progress, error);
|
||||
|
||||
if (gimp_link_is_broken (link))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ GimpImage * file_open_image (Gimp *gimp,
|
|||
GFile *file,
|
||||
gint vector_width,
|
||||
gint vector_height,
|
||||
gboolean vector_keep_ratio,
|
||||
gboolean as_new,
|
||||
GimpPlugInProcedure *file_proc,
|
||||
GimpRunMode run_mode,
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ opened_xcf_file_files (gconstpointer data)
|
|||
NULL /*progress*/,
|
||||
file,
|
||||
0, 0, /* vector width, height */
|
||||
TRUE, /* vector keep ratio */
|
||||
FALSE /*as_new*/,
|
||||
NULL /*file_proc*/,
|
||||
GIMP_RUN_NONINTERACTIVE,
|
||||
|
|
@ -161,6 +162,7 @@ imported_file_files (gconstpointer data)
|
|||
NULL /*progress*/,
|
||||
file,
|
||||
0, 0, /* vector width, height */
|
||||
TRUE, /* vector keep ratio */
|
||||
FALSE /*as_new*/,
|
||||
NULL /*file_proc*/,
|
||||
GIMP_RUN_NONINTERACTIVE,
|
||||
|
|
@ -211,6 +213,7 @@ saved_imported_file_files (gconstpointer data)
|
|||
NULL /*progress*/,
|
||||
import_file,
|
||||
0, 0, /* vector width, height */
|
||||
TRUE, /* vector keep ratio */
|
||||
FALSE /*as_new*/,
|
||||
NULL /*file_proc*/,
|
||||
GIMP_RUN_NONINTERACTIVE,
|
||||
|
|
@ -320,6 +323,7 @@ clear_import_file_after_export (gconstpointer data)
|
|||
NULL /*progress*/,
|
||||
file,
|
||||
0, 0, /* vector width, height */
|
||||
TRUE, /* vector keep ratio */
|
||||
FALSE /*as_new*/,
|
||||
NULL /*file_proc*/,
|
||||
GIMP_RUN_NONINTERACTIVE,
|
||||
|
|
|
|||
|
|
@ -279,6 +279,7 @@ gimp_test_load_image (Gimp *gimp,
|
|||
NULL /*progress*/,
|
||||
file,
|
||||
0, 0, /* vector width, height */
|
||||
TRUE, /* vector keep ratio */
|
||||
FALSE /*as_new*/,
|
||||
proc,
|
||||
GIMP_RUN_NONINTERACTIVE,
|
||||
|
|
|
|||
|
|
@ -2231,6 +2231,7 @@ xcf_load_layer_props (XcfInfo *info,
|
|||
GList *selected;
|
||||
GList *linked;
|
||||
gboolean floating;
|
||||
guint32 dimensions[2];
|
||||
|
||||
selected = g_list_find (info->selected_layers, *layer);
|
||||
linked = g_list_find (info->linked_layers, *layer);
|
||||
|
|
@ -2238,9 +2239,12 @@ xcf_load_layer_props (XcfInfo *info,
|
|||
|
||||
xcf_read_int32 (info, &flags, 1);
|
||||
xcf_read_string (info, &path, 1);
|
||||
xcf_read_int32 (info, dimensions, 2);
|
||||
|
||||
folder = g_file_get_parent (info->file);
|
||||
link = gimp_link_new (info->gimp, g_file_resolve_relative_path (folder, path), NULL, NULL);
|
||||
link = gimp_link_new (info->gimp, g_file_resolve_relative_path (folder, path),
|
||||
(gint) dimensions[0], (gint) dimensions[1],
|
||||
FALSE, NULL, NULL);
|
||||
|
||||
*layer = gimp_layer_from_layer (*layer, GIMP_TYPE_LINK_LAYER,
|
||||
"image", image,
|
||||
|
|
|
|||
|
|
@ -1735,12 +1735,15 @@ xcf_save_prop (XcfInfo *info,
|
|||
{
|
||||
GimpLinkLayer *layer = va_arg (args, GimpLinkLayer *);
|
||||
gchar *path = NULL;
|
||||
gint width;
|
||||
gint height;
|
||||
guint32 dimensions[2];
|
||||
guint32 flags;
|
||||
|
||||
flags = gimp_link_layer_get_xcf_flags (layer);
|
||||
gimp_link_get_file (gimp_link_layer_get_link (layer), info->file, &path);
|
||||
|
||||
size = 4 + (strlen (path) ? strlen (path) + 1 : 4);
|
||||
size = 3 * 4 + (strlen (path) ? strlen (path) + 1 : 4);
|
||||
|
||||
xcf_write_prop_type_check_error (info, prop_type, va_end (args));
|
||||
xcf_write_int32_check_error (info, &size, 1, va_end (args));
|
||||
|
|
@ -1748,6 +1751,11 @@ xcf_save_prop (XcfInfo *info,
|
|||
xcf_write_int32_check_error (info, &flags, 1, va_end (args));
|
||||
xcf_write_string_check_error (info, (gchar **) &path, 1, va_end (args));
|
||||
|
||||
gimp_link_get_size (gimp_link_layer_get_link (layer), &width, &height);
|
||||
dimensions[0] = width;
|
||||
dimensions[1] = height;
|
||||
xcf_write_int32_check_error (info, dimensions, 2, va_end (args));
|
||||
|
||||
g_free (path);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in a new issue