From d493f0537fc2bef4288b9030f77e7f4d047ad994 Mon Sep 17 00:00:00 2001 From: Jehan Date: Thu, 25 Jul 2024 20:55:21 +0200 Subject: [PATCH] Issue #8900 and #9923: reimplementing GimpUnit as a proper class. This fixes all our GObject Introspection issues with GimpUnit which was both an enum and an int-derived type of user-defined units *completing* the enum values. GIR clearly didn't like this! Now GimpUnit is a proper class and units are unique objects, allowing to compare them with an identity test (i.e. `unit == gimp_unit_pixel ()` tells us if unit is the pixel unit or not), which makes it easy to use, just like with int, yet adding also methods, making for nicer introspected API. As an aside, this also fixes #10738, by having all the built-in units retrievable even if libgimpbase had not been properly initialized with gimp_base_init(). I haven't checked in details how GIR works to introspect, but it looks like it loads the library to inspect and runs functions, hence triggering some CRITICALS because virtual methods (supposed to be initialized with gimp_base_init() run by libgimp) are not set. This new code won't trigger any critical because the vtable method are now not necessary, at least for all built-in units. Note that GimpUnit is still in libgimpbase. It could have been moved to libgimp in order to avoid any virtual method table (since we need to keep core and libgimp side's units in sync, PDB is required), but too many libgimpwidgets widgets were already using GimpUnit. And technically most of GimpUnit logic doesn't require PDB (only the creation/sync part). This is one of the reasons why user-created GimpUnit list is handled and stored differently from other types of objects. Globally this simplifies the code a lot too and we don't need separate implementations of various utils for core and libgimp, which means less prone to errors. --- app/actions/buffers-commands.c | 3 +- app/actions/edit-commands.c | 2 +- app/actions/image-commands.c | 30 +- app/actions/images-commands.c | 3 +- app/actions/layers-commands.c | 30 +- app/actions/select-commands.c | 25 +- app/config/gimpconfig-dump.c | 17 +- app/config/test-config.c | 34 +- app/core/gimp-gui.c | 2 +- app/core/gimp-gui.h | 4 +- app/core/gimp-units.c | 167 +-- app/core/gimp-utils.c | 14 +- app/core/gimp-utils.h | 2 +- app/core/gimp.h | 1 - app/core/gimpbuffer.c | 8 +- app/core/gimpbuffer.h | 6 +- app/core/gimpdrawable-stroke.c | 6 +- app/core/gimpgrid.c | 12 +- app/core/gimpgrid.h | 4 +- app/core/gimpimage-private.h | 2 +- app/core/gimpimage.c | 12 +- app/core/gimpimage.h | 4 +- app/core/gimpimageundo.c | 2 +- app/core/gimpimageundo.h | 2 +- app/core/gimpparamspecs-desc.c | 12 + app/core/gimpstrokeoptions.c | 12 +- app/core/gimpstrokeoptions.h | 2 +- app/core/gimptemplate.c | 24 +- app/core/gimptemplate.h | 4 +- app/core/gimpunit.c | 269 +---- app/core/gimpunit.h | 31 +- app/dialogs/dialogs-types.h | 4 +- app/dialogs/image-scale-dialog.c | 14 +- app/dialogs/image-scale-dialog.h | 2 +- app/dialogs/layer-options-dialog.c | 8 +- app/dialogs/print-size-dialog.h | 2 +- app/dialogs/resize-dialog.c | 30 +- app/dialogs/resize-dialog.h | 6 +- app/dialogs/resolution-calibrate-dialog.c | 2 +- app/dialogs/scale-dialog.c | 8 +- app/dialogs/scale-dialog.h | 2 +- app/display/gimpcursorview.c | 24 +- app/display/gimpcursorview.h | 2 +- app/display/gimpdisplay.c | 4 +- app/display/gimpdisplay.h | 4 +- app/display/gimpdisplayshell-dnd.c | 8 +- app/display/gimpdisplayshell-handlers.c | 2 +- app/display/gimpdisplayshell-title.c | 8 +- app/display/gimpdisplayshell-utils.c | 4 +- app/display/gimpdisplayshell.c | 16 +- app/display/gimpdisplayshell.h | 10 +- app/display/gimpstatusbar.c | 10 +- app/file/file-open.c | 2 +- app/gui/gui-vtable.c | 4 +- app/gui/gui.c | 2 +- app/paint/gimppaintoptions.c | 36 +- app/paint/gimppaintoptions.h | 2 +- app/pdb/context-cmds.c | 17 +- app/pdb/display-cmds.c | 2 +- app/pdb/gimprc-cmds.c | 16 +- app/pdb/image-cmds.c | 14 +- app/pdb/internal-procs.c | 2 +- app/pdb/text-layer-cmds.c | 24 +- app/pdb/unit-cmds.c | 691 +++--------- app/plug-in/gimpgpparams.c | 1 + app/tests/gimp-app-test-utils.c | 4 +- app/tests/test-xcf.c | 6 +- app/text/gimptext-xlfd.c | 18 +- app/text/gimptext-xlfd.h | 12 +- app/text/gimptext.c | 12 +- app/text/gimptext.h | 4 +- app/tools/gimpeditselectiontool.c | 2 +- app/tools/gimpgradienttool-editor.c | 6 +- app/tools/gimpmeasuretool.c | 10 +- app/tools/gimpoffsettool.c | 5 +- app/tools/gimprectangleoptions.c | 20 +- app/tools/gimprectangleoptions.h | 6 +- app/tools/gimprotatetool.c | 3 +- app/tools/gimptextoptions.c | 12 +- app/tools/gimptextoptions.h | 4 +- app/tools/gimptexttool.c | 6 +- app/tools/gimptransform3dtool.c | 6 +- app/tools/gimpwarptool.c | 3 +- app/vectors/gimppath-export.c | 6 +- app/vectors/gimppath-import.c | 16 +- app/widgets/gimpimagepropview.c | 4 +- app/widgets/gimpsizebox.c | 12 +- app/widgets/gimpsizebox.h | 4 +- app/widgets/gimptextstyleeditor.c | 6 +- app/widgets/gimptoolbox-dnd.c | 8 +- app/xcf/xcf-load.c | 53 +- app/xcf/xcf-save.c | 13 +- libgimp/gimp.c | 21 +- libgimp/gimp.def | 1 + libgimp/gimp_pdb_headers.h | 1 + libgimp/gimpcontext_pdb.c | 8 +- libgimp/gimpcontext_pdb.h | 4 +- libgimp/gimpgimprc_pdb.c | 10 +- libgimp/gimpgimprc_pdb.h | 2 +- libgimp/gimpgpparams-body.c | 32 +- libgimp/gimpimage_pdb.c | 8 +- libgimp/gimpimage_pdb.h | 4 +- libgimp/gimpimagemetadata.c | 2 +- libgimp/gimpparamspecs-desc.c | 12 + libgimp/gimpprocedure-params.c | 6 +- libgimp/gimpprocedure-params.h | 15 +- libgimp/gimpresolutionentry-private.c | 22 +- libgimp/gimpresolutionentry-private.h | 6 +- libgimp/gimptextlayer.c | 4 +- libgimp/gimptextlayer.h | 2 +- libgimp/gimptextlayer_pdb.c | 10 +- libgimp/gimptextlayer_pdb.h | 104 +- libgimp/gimpunit_pdb.c | 425 ++------ libgimp/gimpunit_pdb.h | 36 +- libgimp/gimpunitcache.c | 236 ----- libgimp/gimpunitcache.h | 52 - libgimp/gimpvectorloadprocedure.c | 24 +- libgimp/gimpvectorloadprocedure.h | 20 +- libgimp/gimpvectorloadproceduredialog.c | 10 +- libgimp/meson.build | 4 +- libgimpbase/gimpbase-private.c | 9 +- libgimpbase/gimpbase-private.h | 43 +- libgimpbase/gimpbase.def | 13 +- libgimpbase/gimpbaseenums.h | 8 +- libgimpbase/gimpbasetypes.h | 1 + libgimpbase/gimpmetadata.c | 14 +- libgimpbase/gimpmetadata.h | 4 +- libgimpbase/gimpunit.c | 1178 ++++++++++++++------- libgimpbase/gimpunit.h | 117 +- libgimpconfig/gimpconfig-deserialize.c | 49 +- libgimpconfig/gimpconfig-params.c | 21 +- libgimpconfig/gimpconfig-serialize.c | 14 + libgimpwidgets/gimppropwidgets.c | 47 +- libgimpwidgets/gimpquerybox.c | 8 +- libgimpwidgets/gimpquerybox.h | 4 +- libgimpwidgets/gimpruler.c | 28 +- libgimpwidgets/gimpruler.h | 4 +- libgimpwidgets/gimpsizeentry.c | 245 ++--- libgimpwidgets/gimpsizeentry.h | 6 +- libgimpwidgets/gimpunitcombobox.c | 16 +- libgimpwidgets/gimpunitcombobox.h | 4 +- libgimpwidgets/gimpunitstore.c | 251 ++--- libgimpwidgets/gimpunitstore.h | 4 +- libgimpwidgets/gimpwidgets.c | 4 +- libgimpwidgets/gimpwidgets.h | 2 +- pdb/app.pl | 7 +- pdb/enums.pl | 2 +- pdb/groups/display.pdb | 2 +- pdb/groups/gimprc.pdb | 6 +- pdb/groups/image.pdb | 2 +- pdb/groups/unit.pdb | 329 ++---- pdb/pdb.pl | 15 +- plug-ins/common/border-average.c | 2 +- plug-ins/common/checkerboard.c | 2 +- plug-ins/common/file-pdf-export.c | 2 +- plug-ins/common/file-pdf-load.c | 6 +- plug-ins/common/file-png.c | 2 +- plug-ins/common/file-ps.c | 12 +- plug-ins/common/file-svg.c | 43 +- plug-ins/common/file-wmf.c | 4 +- plug-ins/common/grid.c | 8 +- plug-ins/common/smooth-palette.c | 2 +- plug-ins/common/unit-editor.c | 60 +- plug-ins/file-jpeg/jpeg-load.c | 2 +- plug-ins/file-psd/psd-export.c | 10 +- plug-ins/file-psd/psd-image-res-load.c | 10 +- plug-ins/file-tiff/file-tiff-load.c | 10 +- plug-ins/print/print-settings.c | 6 +- plug-ins/print/print.h | 4 +- plug-ins/twain/twain.c | 2 +- 170 files changed, 2362 insertions(+), 3353 deletions(-) delete mode 100644 libgimp/gimpunitcache.c delete mode 100644 libgimp/gimpunitcache.h diff --git a/app/actions/buffers-commands.c b/app/actions/buffers-commands.c index a7eead1d01..ab285dc1d7 100644 --- a/app/actions/buffers-commands.c +++ b/app/actions/buffers-commands.c @@ -20,6 +20,7 @@ #include #include +#include "libgimpbase/gimpbase.h" #include "libgimpwidgets/gimpwidgets.h" #include "actions-types.h" @@ -125,7 +126,7 @@ buffers_paste_as_new_image_cmd_callback (GimpAction *action, GIMP_OBJECT (buffer), context); gimp_create_display (context->gimp, new_image, - GIMP_UNIT_PIXEL, 1.0, + gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (new_image); } diff --git a/app/actions/edit-commands.c b/app/actions/edit-commands.c index 053dd8f6dc..cf63320b96 100644 --- a/app/actions/edit-commands.c +++ b/app/actions/edit-commands.c @@ -436,7 +436,7 @@ edit_paste_as_new_image_cmd_callback (GimpAction *action, if (image) { - gimp_create_display (gimp, image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (gimp, image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (image); } diff --git a/app/actions/image-commands.c b/app/actions/image-commands.c index d892ac3de6..484c4e821e 100644 --- a/app/actions/image-commands.c +++ b/app/actions/image-commands.c @@ -136,12 +136,12 @@ static void image_resize_callback (GtkWidget *dialog, GimpContext *context, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, gint offset_x, gint offset_y, gdouble xres, gdouble yres, - GimpUnit res_unit, + GimpUnit *res_unit, GimpFillType fill_type, GimpItemSet layer_set, gboolean resize_text_layers, @@ -151,18 +151,18 @@ static void image_print_size_callback (GtkWidget *dialog, GimpImage *image, gdouble xresolution, gdouble yresolution, - GimpUnit resolution_unit, + GimpUnit *resolution_unit, gpointer user_data); static void image_scale_callback (GtkWidget *dialog, GimpViewable *viewable, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, gdouble xresolution, gdouble yresolution, - GimpUnit resolution_unit, + GimpUnit *resolution_unit, gpointer user_data); static void image_merge_layers_callback (GtkWidget *dialog, @@ -185,8 +185,8 @@ static void image_softproof_profile_callback (GtkWidget *dialo /* private variables */ -static GimpUnit image_resize_unit = GIMP_UNIT_PIXEL; -static GimpUnit image_scale_unit = GIMP_UNIT_PIXEL; +static GimpUnit *image_resize_unit = NULL; +static GimpUnit *image_scale_unit = NULL; static GimpInterpolationType image_scale_interp = -1; static GimpPalette *image_convert_indexed_custom_palette = NULL; @@ -657,7 +657,7 @@ image_resize_cmd_callback (GimpAction *action, { GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config); - if (image_resize_unit != GIMP_UNIT_PERCENT) + if (image_resize_unit != gimp_unit_percent ()) image_resize_unit = gimp_display_get_shell (display)->unit; dialog = resize_dialog_new (GIMP_VIEWABLE (image), @@ -786,7 +786,7 @@ image_scale_cmd_callback (GimpAction *action, if (! dialog) { - if (image_scale_unit != GIMP_UNIT_PERCENT) + if (image_scale_unit != gimp_unit_percent ()) image_scale_unit = gimp_display_get_shell (display)->unit; if (image_scale_interp == -1) @@ -1364,12 +1364,12 @@ image_resize_callback (GtkWidget *dialog, GimpContext *context, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, gint offset_x, gint offset_y, gdouble xres, gdouble yres, - GimpUnit res_unit, + GimpUnit *res_unit, GimpFillType fill_type, GimpItemSet layer_set, gboolean resize_text_layers, @@ -1386,7 +1386,7 @@ image_resize_callback (GtkWidget *dialog, GimpProgress *progress; gdouble old_xres; gdouble old_yres; - GimpUnit old_res_unit; + GimpUnit *old_res_unit; gboolean update_resolution; g_object_set (config, @@ -1448,7 +1448,7 @@ image_print_size_callback (GtkWidget *dialog, GimpImage *image, gdouble xresolution, gdouble yresolution, - GimpUnit resolution_unit, + GimpUnit *resolution_unit, gpointer data) { gdouble xres; @@ -1479,11 +1479,11 @@ image_scale_callback (GtkWidget *dialog, GimpViewable *viewable, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, gdouble xresolution, gdouble yresolution, - GimpUnit resolution_unit, + GimpUnit *resolution_unit, gpointer user_data) { GimpProgress *progress = user_data; diff --git a/app/actions/images-commands.c b/app/actions/images-commands.c index 30e2fc52cd..5252c75647 100644 --- a/app/actions/images-commands.c +++ b/app/actions/images-commands.c @@ -20,6 +20,7 @@ #include #include +#include "libgimpbase/gimpbase.h" #include "libgimpwidgets/gimpwidgets.h" #include "actions-types.h" @@ -88,7 +89,7 @@ images_new_view_cmd_callback (GimpAction *action, if (image && gimp_container_have (container, GIMP_OBJECT (image))) { - gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (image->gimp, image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (GTK_WIDGET (editor)))); } } diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c index be9b7e968f..0360964fe2 100644 --- a/app/actions/layers-commands.c +++ b/app/actions/layers-commands.c @@ -148,23 +148,23 @@ static void layers_scale_callback (GtkWidget *dialog, GimpViewable *viewable, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, gdouble xresolution, gdouble yresolution, - GimpUnit resolution_unit, + GimpUnit *resolution_unit, gpointer user_data); static void layers_resize_callback (GtkWidget *dialog, GimpViewable *viewable, GimpContext *context, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, gint offset_x, gint offset_y, gdouble unused0, gdouble unused1, - GimpUnit unused2, + GimpUnit *unused2, GimpFillType fill_type, GimpItemSet unused3, gboolean unused4, @@ -177,8 +177,8 @@ static gint layers_mode_index (GimpLayerMode layer_mode /* private variables */ -static GimpUnit layer_resize_unit = GIMP_UNIT_PIXEL; -static GimpUnit layer_scale_unit = GIMP_UNIT_PIXEL; +static GimpUnit *layer_resize_unit = NULL; +static GimpUnit *layer_scale_unit = NULL; static GimpInterpolationType layer_scale_interp = -1; @@ -1179,7 +1179,10 @@ layers_resize_cmd_callback (GimpAction *action, if (GIMP_IS_IMAGE_WINDOW (data)) display = action_data_get_display (data); - if (layer_resize_unit != GIMP_UNIT_PERCENT && display) + if (layer_resize_unit == NULL) + layer_resize_unit = gimp_unit_pixel (); + + if (layer_resize_unit != gimp_unit_percent () && display) layer_resize_unit = gimp_display_get_shell (display)->unit; dialog = resize_dialog_new (GIMP_VIEWABLE (layer), @@ -1254,7 +1257,10 @@ layers_scale_cmd_callback (GimpAction *action, if (GIMP_IS_IMAGE_WINDOW (data)) display = action_data_get_display (data); - if (layer_scale_unit != GIMP_UNIT_PERCENT && display) + if (layer_scale_unit == NULL) + layer_scale_unit = gimp_unit_pixel ();; + + if (layer_scale_unit != gimp_unit_percent () && display) layer_scale_unit = gimp_display_get_shell (display)->unit; if (layer_scale_interp == -1) @@ -2492,11 +2498,11 @@ layers_scale_callback (GtkWidget *dialog, GimpViewable *viewable, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, gdouble xresolution, /* unused */ gdouble yresolution, /* unused */ - GimpUnit resolution_unit,/* unused */ + GimpUnit *resolution_unit,/* unused */ gpointer user_data) { GimpDisplay *display = GIMP_DISPLAY (user_data); @@ -2553,12 +2559,12 @@ layers_resize_callback (GtkWidget *dialog, GimpContext *context, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, gint offset_x, gint offset_y, gdouble unused0, gdouble unused1, - GimpUnit unused2, + GimpUnit *unused2, GimpFillType fill_type, GimpItemSet unused3, gboolean unused4, diff --git a/app/actions/select-commands.c b/app/actions/select-commands.c index ef62926ace..86a50be449 100644 --- a/app/actions/select-commands.c +++ b/app/actions/select-commands.c @@ -20,6 +20,7 @@ #include #include +#include "libgimpbase/gimpbase.h" #include "libgimpmath/gimpmath.h" #include "libgimpwidgets/gimpwidgets.h" @@ -53,19 +54,19 @@ static void select_feather_callback (GtkWidget *widget, gdouble size, - GimpUnit unit, + GimpUnit *unit, gpointer data); static void select_border_callback (GtkWidget *widget, gdouble size, - GimpUnit unit, + GimpUnit *unit, gpointer data); static void select_grow_callback (GtkWidget *widget, gdouble size, - GimpUnit unit, + GimpUnit *unit, gpointer data); static void select_shrink_callback (GtkWidget *widget, gdouble size, - GimpUnit unit, + GimpUnit *unit, gpointer data); static void select_float (GimpAction *action, GVariant *value, @@ -502,7 +503,7 @@ select_stroke_last_vals_cmd_callback (GimpAction *action, static void select_feather_callback (GtkWidget *widget, gdouble size, - GimpUnit unit, + GimpUnit *unit, gpointer data) { GimpImage *image = GIMP_IMAGE (data); @@ -522,7 +523,7 @@ select_feather_callback (GtkWidget *widget, radius_x = config->selection_feather_radius; radius_y = config->selection_feather_radius; - if (unit != GIMP_UNIT_PIXEL) + if (unit != gimp_unit_pixel ()) { gdouble xres; gdouble yres; @@ -548,7 +549,7 @@ select_feather_callback (GtkWidget *widget, static void select_border_callback (GtkWidget *widget, gdouble size, - GimpUnit unit, + GimpUnit *unit, gpointer data) { GimpImage *image = GIMP_IMAGE (data); @@ -574,7 +575,7 @@ select_border_callback (GtkWidget *widget, radius_x = ROUND (config->selection_border_radius); radius_y = ROUND (config->selection_border_radius); - if (unit != GIMP_UNIT_PIXEL) + if (unit != gimp_unit_pixel ()) { gdouble xres; gdouble yres; @@ -601,7 +602,7 @@ select_border_callback (GtkWidget *widget, static void select_grow_callback (GtkWidget *widget, gdouble size, - GimpUnit unit, + GimpUnit *unit, gpointer data) { GimpImage *image = GIMP_IMAGE (data); @@ -616,7 +617,7 @@ select_grow_callback (GtkWidget *widget, radius_x = ROUND (config->selection_grow_radius); radius_y = ROUND (config->selection_grow_radius); - if (unit != GIMP_UNIT_PIXEL) + if (unit != gimp_unit_pixel ()) { gdouble xres; gdouble yres; @@ -640,7 +641,7 @@ select_grow_callback (GtkWidget *widget, static void select_shrink_callback (GtkWidget *widget, gdouble size, - GimpUnit unit, + GimpUnit *unit, gpointer data) { GimpImage *image = GIMP_IMAGE (data); @@ -660,7 +661,7 @@ select_shrink_callback (GtkWidget *widget, radius_x = ROUND (config->selection_shrink_radius); radius_y = ROUND (config->selection_shrink_radius); - if (unit != GIMP_UNIT_PIXEL) + if (unit != gimp_unit_pixel ()) { gdouble xres; gdouble yres; diff --git a/app/config/gimpconfig-dump.c b/app/config/gimpconfig-dump.c index 78359aa1c4..29927f5b32 100644 --- a/app/config/gimpconfig-dump.c +++ b/app/config/gimpconfig-dump.c @@ -506,9 +506,20 @@ dump_describe_param (GParamSpec *param_spec) } else if (GIMP_IS_PARAM_SPEC_UNIT (param_spec)) { - values = - "The unit can be one inches, millimeters, points or picas plus " - "those in your user units database."; + GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (param_spec); + + if (uspec->allow_pixel && uspec->allow_percent) + values = "The unit can be one inches, millimeters, points or picas plus " + "those in your user units database. Pixel And Percent units are allowed too."; + else if (uspec->allow_pixel) + values = "The unit can be one inches, millimeters, points or picas plus " + "those in your user units database. Pixel unit is allowed too."; + else if (uspec->allow_percent) + values = "The unit can be one inches, millimeters, points or picas plus " + "those in your user units database. Percent unit is allowed too."; + else + values = "The unit can be one inches, millimeters, points or picas plus " + "those in your user units database."; } else if (g_type_is_a (param_spec->value_type, GIMP_TYPE_CONFIG)) { diff --git a/app/config/test-config.c b/app/config/test-config.c index 7bd0c0ed38..99f095439a 100644 --- a/app/config/test-config.c +++ b/app/config/test-config.c @@ -246,41 +246,11 @@ output_unknown_token (const gchar *key, } -/* minimal dummy units implementation */ - -static const gchar * -unit_get_identifier (GimpUnit unit) -{ - switch (unit) - { - case GIMP_UNIT_PIXEL: - return "pixels"; - case GIMP_UNIT_INCH: - return "inches"; - case GIMP_UNIT_MM: - return "millimeters"; - case GIMP_UNIT_POINT: - return "points"; - case GIMP_UNIT_PICA: - return "picas"; - default: - return NULL; - } -} - -static gint -unit_get_number_of_units (void) -{ - return GIMP_UNIT_END; -} - static void units_init (void) { - GimpUnitVtable vtable; - - vtable.unit_get_number_of_units = unit_get_number_of_units; - vtable.unit_get_identifier = unit_get_identifier; + /* Empty dummy units implementation */ + GimpUnitVtable vtable = { 0 }; gimp_base_init (&vtable); } diff --git a/app/core/gimp-gui.c b/app/core/gimp-gui.c index 0e9ff24c21..140813b982 100644 --- a/app/core/gimp-gui.c +++ b/app/core/gimp-gui.c @@ -339,7 +339,7 @@ gimp_get_display_window_id (Gimp *gimp, GimpDisplay * gimp_create_display (Gimp *gimp, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale, GObject *monitor) { diff --git a/app/core/gimp-gui.h b/app/core/gimp-gui.h index fc554745ce..b4b264f2f2 100644 --- a/app/core/gimp-gui.h +++ b/app/core/gimp-gui.h @@ -57,7 +57,7 @@ struct _GimpGui GBytes * (* display_get_window_id) (GimpDisplay *display); GimpDisplay * (* display_create) (Gimp *gimp, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale, GObject *monitor); void (* display_delete) (GimpDisplay *display); @@ -127,7 +127,7 @@ GBytes * gimp_get_display_window_id (Gimp *gimp, GimpDisplay *display); GimpDisplay * gimp_create_display (Gimp *gimp, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale, GObject *monitor); void gimp_delete_display (Gimp *gimp, diff --git a/app/core/gimp-units.c b/app/core/gimp-units.c index 77a4c84f14..91213b7630 100644 --- a/app/core/gimp-units.c +++ b/app/core/gimp-units.c @@ -46,126 +46,30 @@ * or the GTokenType they would have expected but didn't get. */ -static GTokenType gimp_unitrc_unit_info_deserialize (GScanner *scanner, - Gimp *gimp); +static GTokenType gimp_unitrc_unit_info_deserialize (GScanner *scanner, + Gimp *gimp); + +static GimpUnit * gimp_units_get_user_unit (gint unit_id); static Gimp *the_unit_gimp = NULL; -static gint -gimp_units_get_number_of_units (void) -{ - return _gimp_unit_get_number_of_units (the_unit_gimp); -} - -static gint -gimp_units_get_number_of_built_in_units (void) -{ - return GIMP_UNIT_END; -} - -static GimpUnit -gimp_units_unit_new (gchar *identifier, - gdouble factor, - gint digits, - gchar *symbol, - gchar *abbreviation, - gchar *singular, - gchar *plural) -{ - return _gimp_unit_new (the_unit_gimp, - identifier, - factor, - digits, - symbol, - abbreviation, - singular, - plural); -} - -static gboolean -gimp_units_unit_get_deletion_flag (GimpUnit unit) -{ - return _gimp_unit_get_deletion_flag (the_unit_gimp, unit); -} - -static void -gimp_units_unit_set_deletion_flag (GimpUnit unit, - gboolean deletion_flag) -{ - _gimp_unit_set_deletion_flag (the_unit_gimp, unit, deletion_flag); -} - -static gdouble -gimp_units_unit_get_factor (GimpUnit unit) -{ - return _gimp_unit_get_factor (the_unit_gimp, unit); -} - -static gint -gimp_units_unit_get_digits (GimpUnit unit) -{ - return _gimp_unit_get_digits (the_unit_gimp, unit); -} - -static const gchar * -gimp_units_unit_get_identifier (GimpUnit unit) -{ - return _gimp_unit_get_identifier (the_unit_gimp, unit); -} - -static const gchar * -gimp_units_unit_get_symbol (GimpUnit unit) -{ - return _gimp_unit_get_symbol (the_unit_gimp, unit); -} - -static const gchar * -gimp_units_unit_get_abbreviation (GimpUnit unit) -{ - return _gimp_unit_get_abbreviation (the_unit_gimp, unit); -} - -static const gchar * -gimp_units_unit_get_singular (GimpUnit unit) -{ - return _gimp_unit_get_singular (the_unit_gimp, unit); -} - -static const gchar * -gimp_units_unit_get_plural (GimpUnit unit) -{ - return _gimp_unit_get_plural (the_unit_gimp, unit); -} - void gimp_units_init (Gimp *gimp) { - GimpUnitVtable vtable; + GimpUnitVtable vtable = { 0 }; g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (the_unit_gimp == NULL); the_unit_gimp = gimp; - vtable.unit_get_number_of_units = gimp_units_get_number_of_units; - vtable.unit_get_number_of_built_in_units = gimp_units_get_number_of_built_in_units; - vtable.unit_new = gimp_units_unit_new; - vtable.unit_get_deletion_flag = gimp_units_unit_get_deletion_flag; - vtable.unit_set_deletion_flag = gimp_units_unit_set_deletion_flag; - vtable.unit_get_factor = gimp_units_unit_get_factor; - vtable.unit_get_digits = gimp_units_unit_get_digits; - vtable.unit_get_identifier = gimp_units_unit_get_identifier; - vtable.unit_get_symbol = gimp_units_unit_get_symbol; - vtable.unit_get_abbreviation = gimp_units_unit_get_abbreviation; - vtable.unit_get_singular = gimp_units_unit_get_singular; - vtable.unit_get_plural = gimp_units_unit_get_plural; + vtable.get_user_unit = gimp_units_get_user_unit; gimp_base_init (&vtable); - gimp->user_units = NULL; - gimp->n_user_units = 0; + gimp->user_units = NULL; } void @@ -173,7 +77,10 @@ gimp_units_exit (Gimp *gimp) { g_return_if_fail (GIMP_IS_GIMP (gimp)); - gimp_user_units_free (gimp); + gimp_base_exit (); + + g_list_free_full (gimp->user_units, g_object_unref); + gimp->user_units = NULL; } @@ -292,7 +199,7 @@ gimp_unitrc_save (Gimp *gimp) { GimpConfigWriter *writer; GFile *file; - gint i; + GList *iter; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); @@ -319,49 +226,48 @@ gimp_unitrc_save (Gimp *gimp) if (!writer) return; - /* save user defined units */ - for (i = _gimp_unit_get_number_of_built_in_units (gimp); - i < _gimp_unit_get_number_of_units (gimp); - i++) + for (iter = gimp->user_units; iter; iter = iter->next) { - if (_gimp_unit_get_deletion_flag (gimp, i) == FALSE) + GimpUnit *unit = iter->data; + + if (gimp_unit_get_deletion_flag (unit) == FALSE) { gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gimp_config_writer_open (writer, "unit-info"); gimp_config_writer_string (writer, - _gimp_unit_get_identifier (gimp, i)); + gimp_unit_get_identifier (unit)); gimp_config_writer_open (writer, "factor"); gimp_config_writer_print (writer, g_ascii_dtostr (buf, sizeof (buf), - _gimp_unit_get_factor (gimp, i)), + gimp_unit_get_factor (unit)), -1); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "digits"); gimp_config_writer_printf (writer, - "%d", _gimp_unit_get_digits (gimp, i)); + "%d", gimp_unit_get_digits (unit)); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "symbol"); gimp_config_writer_string (writer, - _gimp_unit_get_symbol (gimp, i)); + gimp_unit_get_symbol (unit)); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "abbreviation"); gimp_config_writer_string (writer, - _gimp_unit_get_abbreviation (gimp, i)); + gimp_unit_get_abbreviation (unit)); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "singular"); gimp_config_writer_string (writer, - _gimp_unit_get_singular (gimp, i)); + gimp_unit_get_singular (unit)); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "plural"); gimp_config_writer_string (writer, - _gimp_unit_get_plural (gimp, i)); + gimp_unit_get_plural (unit)); gimp_config_writer_close (writer); gimp_config_writer_close (writer); @@ -466,13 +372,13 @@ gimp_unitrc_unit_info_deserialize (GScanner *scanner, if (g_scanner_peek_next_token (scanner) == token) { - GimpUnit unit = _gimp_unit_new (gimp, - identifier, factor, digits, - symbol, abbreviation, - singular, plural); + GimpUnit *unit = _gimp_unit_new (gimp, + identifier, factor, digits, + symbol, abbreviation, + singular, plural); /* make the unit definition persistent */ - _gimp_unit_set_deletion_flag (gimp, unit, FALSE); + gimp_unit_set_deletion_flag (unit, FALSE); } } @@ -486,3 +392,20 @@ gimp_unitrc_unit_info_deserialize (GScanner *scanner, return token; } + +/** + * gimp_units_get_user_unit: + * @unit_id: + * + * This function will return the user-created GimpUnit with ID @unit_id. + */ +static GimpUnit * +gimp_units_get_user_unit (gint unit_id) +{ + g_return_val_if_fail (the_unit_gimp != NULL, NULL); + g_return_val_if_fail (unit_id >= GIMP_UNIT_END && unit_id != GIMP_UNIT_PERCENT, NULL); + + unit_id -= GIMP_UNIT_END; + + return g_list_nth_data (the_unit_gimp->user_units, unit_id); +} diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c index 5e6f6f57c6..ca6359a0d3 100644 --- a/app/core/gimp-utils.c +++ b/app/core/gimp-utils.c @@ -193,7 +193,7 @@ gimp_get_default_language (const gchar *category) return lang; } -GimpUnit +GimpUnit * gimp_get_default_unit (void) { #if defined (HAVE__NL_MEASUREMENT_MEASUREMENT) @@ -202,10 +202,10 @@ gimp_get_default_unit (void) switch (*((guchar *) measurement)) { case 1: /* metric */ - return GIMP_UNIT_MM; + return gimp_unit_mm (); case 2: /* imperial */ - return GIMP_UNIT_INCH; + return gimp_unit_inch (); } #elif defined (G_OS_WIN32) @@ -222,15 +222,15 @@ gimp_get_default_unit (void) switch ((guint) measurement) { case 0: /* metric */ - return GIMP_UNIT_MM; + return gimp_unit_mm (); case 1: /* imperial */ - return GIMP_UNIT_INCH; + return gimp_unit_inch (); } } #endif - return GIMP_UNIT_MM; + return gimp_unit_mm (); } gchar ** @@ -1281,7 +1281,7 @@ gimp_create_image_from_buffer (Gimp *gimp, NULL /* same image */); gimp_image_add_layer (image, layer, NULL, -1, FALSE); - gimp_create_display (gimp, image, GIMP_UNIT_PIXEL, 1.0, NULL); + gimp_create_display (gimp, image, gimp_unit_pixel (), 1.0, NULL); /* unref the image unconditionally, even when no display was created */ g_object_add_weak_pointer (G_OBJECT (image), (gpointer) &image); diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h index 064bb0f37a..b180294196 100644 --- a/app/core/gimp-utils.h +++ b/app/core/gimp-utils.h @@ -40,7 +40,7 @@ gint gimp_get_pid (void); guint64 gimp_get_physical_memory_size (void); gchar * gimp_get_default_language (const gchar *category); -GimpUnit gimp_get_default_unit (void); +GimpUnit * gimp_get_default_unit (void); gchar ** gimp_properties_append (GType object_type, gint *n_properties, diff --git a/app/core/gimp.h b/app/core/gimp.h index 45cf74a412..8ea0e11cec 100644 --- a/app/core/gimp.h +++ b/app/core/gimp.h @@ -69,7 +69,6 @@ struct _Gimp guint busy_idle_id; GList *user_units; - gint n_user_units; GimpParasiteList *parasites; diff --git a/app/core/gimpbuffer.c b/app/core/gimpbuffer.c index 2d700ac0da..63f44e0b31 100644 --- a/app/core/gimpbuffer.c +++ b/app/core/gimpbuffer.c @@ -511,18 +511,18 @@ gimp_buffer_get_resolution (GimpBuffer *buffer, void gimp_buffer_set_unit (GimpBuffer *buffer, - GimpUnit unit) + GimpUnit *unit) { g_return_if_fail (GIMP_IS_BUFFER (buffer)); - g_return_if_fail (unit > GIMP_UNIT_PIXEL); + g_return_if_fail (GIMP_IS_UNIT (unit)); buffer->unit = unit; } -GimpUnit +GimpUnit * gimp_buffer_get_unit (GimpBuffer *buffer) { - g_return_val_if_fail (GIMP_IS_BUFFER (buffer), GIMP_UNIT_PIXEL); + g_return_val_if_fail (GIMP_IS_BUFFER (buffer), gimp_unit_pixel ()); return buffer->unit; } diff --git a/app/core/gimpbuffer.h b/app/core/gimpbuffer.h index 1e1c738e19..89daa6b4ab 100644 --- a/app/core/gimpbuffer.h +++ b/app/core/gimpbuffer.h @@ -42,7 +42,7 @@ struct _GimpBuffer gdouble resolution_x; gdouble resolution_y; - GimpUnit unit; + GimpUnit *unit; GimpColorProfile *color_profile; GimpColorProfile *format_profile; @@ -80,8 +80,8 @@ gboolean gimp_buffer_get_resolution (GimpBuffer *buffer, gdouble *resolution_y); void gimp_buffer_set_unit (GimpBuffer *buffer, - GimpUnit unit); -GimpUnit gimp_buffer_get_unit (GimpBuffer *buffer); + GimpUnit *unit); +GimpUnit * gimp_buffer_get_unit (GimpBuffer *buffer); void gimp_buffer_set_color_profile (GimpBuffer *buffer, GimpColorProfile *profile); diff --git a/app/core/gimpdrawable-stroke.c b/app/core/gimpdrawable-stroke.c index cd0f788de9..05cacda3ee 100644 --- a/app/core/gimpdrawable-stroke.c +++ b/app/core/gimpdrawable-stroke.c @@ -119,8 +119,8 @@ gimp_drawable_stroke_scan_convert (GimpDrawable *drawable, GimpScanConvert *scan_convert, gboolean push_undo) { - gdouble width; - GimpUnit unit; + gdouble width; + GimpUnit *unit; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); @@ -136,7 +136,7 @@ gimp_drawable_stroke_scan_convert (GimpDrawable *drawable, width = gimp_stroke_options_get_width (options); unit = gimp_stroke_options_get_unit (options); - if (unit != GIMP_UNIT_PIXEL) + if (unit != gimp_unit_pixel ()) { GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); gdouble xres; diff --git a/app/core/gimpgrid.c b/app/core/gimpgrid.c index 5d596b5933..426a2caf5f 100644 --- a/app/core/gimpgrid.c +++ b/app/core/gimpgrid.c @@ -123,7 +123,7 @@ gimp_grid_class_init (GimpGridClass *klass) "spacing-unit", _("Spacing unit"), NULL, - FALSE, FALSE, GIMP_UNIT_INCH, + FALSE, FALSE, gimp_unit_inch (), GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_XOFFSET, @@ -148,7 +148,7 @@ gimp_grid_class_init (GimpGridClass *klass) "offset-unit", _("Offset unit"), NULL, - FALSE, FALSE, GIMP_UNIT_INCH, + FALSE, FALSE, gimp_unit_inch (), GIMP_PARAM_STATIC_STRINGS); g_object_unref (black); @@ -199,7 +199,7 @@ gimp_grid_get_property (GObject *object, g_value_set_double (value, grid->yspacing); break; case PROP_SPACING_UNIT: - g_value_set_int (value, grid->spacing_unit); + g_value_set_object (value, grid->spacing_unit); break; case PROP_XOFFSET: g_value_set_double (value, grid->xoffset); @@ -208,7 +208,7 @@ gimp_grid_get_property (GObject *object, g_value_set_double (value, grid->yoffset); break; case PROP_OFFSET_UNIT: - g_value_set_int (value, grid->offset_unit); + g_value_set_object (value, grid->offset_unit); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -244,7 +244,7 @@ gimp_grid_set_property (GObject *object, grid->yspacing = g_value_get_double (value); break; case PROP_SPACING_UNIT: - grid->spacing_unit = g_value_get_int (value); + grid->spacing_unit = g_value_get_object (value); break; case PROP_XOFFSET: grid->xoffset = g_value_get_double (value); @@ -253,7 +253,7 @@ gimp_grid_set_property (GObject *object, grid->yoffset = g_value_get_double (value); break; case PROP_OFFSET_UNIT: - grid->offset_unit = g_value_get_int (value); + grid->offset_unit = g_value_get_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); diff --git a/app/core/gimpgrid.h b/app/core/gimpgrid.h index c9e98af842..9e816b712c 100644 --- a/app/core/gimpgrid.h +++ b/app/core/gimpgrid.h @@ -44,10 +44,10 @@ struct _GimpGrid GeglColor *bgcolor; gdouble xspacing; gdouble yspacing; - GimpUnit spacing_unit; + GimpUnit *spacing_unit; gdouble xoffset; gdouble yoffset; - GimpUnit offset_unit; + GimpUnit *offset_unit; }; diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h index 75e1ae411e..cba59c67d2 100644 --- a/app/core/gimpimage-private.h +++ b/app/core/gimpimage-private.h @@ -44,7 +44,7 @@ struct _GimpImagePrivate gint height; /* height in pixels */ gdouble xresolution; /* image x-res, in dpi */ gdouble yresolution; /* image y-res, in dpi */ - GimpUnit resolution_unit; /* resolution unit */ + GimpUnit *resolution_unit; /* resolution unit */ gboolean resolution_set; /* resolution explicitly set */ GimpImageBaseType base_type; /* base gimp_image type */ GimpPrecision precision; /* image's precision */ diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 666e9ca69d..4196b2430e 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -750,7 +750,7 @@ gimp_image_init (GimpImage *image) private->xresolution = 1.0; private->yresolution = 1.0; private->resolution_set = FALSE; - private->resolution_unit = GIMP_UNIT_INCH; + private->resolution_unit = gimp_unit_inch (); private->base_type = GIMP_RGB; private->precision = GIMP_PRECISION_U8_NON_LINEAR; private->new_layer_mode = -1; @@ -2539,7 +2539,7 @@ gimp_image_set_imported_file (GimpImage *image, */ private->xresolution = 72.0; private->yresolution = 72.0; - private->resolution_unit = GIMP_UNIT_INCH; + private->resolution_unit = gimp_unit_inch (); } } @@ -3213,12 +3213,12 @@ gimp_image_resolution_changed (GimpImage *image) void gimp_image_set_unit (GimpImage *image, - GimpUnit unit) + GimpUnit *unit) { GimpImagePrivate *private; g_return_if_fail (GIMP_IS_IMAGE (image)); - g_return_if_fail (unit > GIMP_UNIT_PIXEL); + g_return_if_fail (GIMP_IS_UNIT (unit)); private = GIMP_IMAGE_GET_PRIVATE (image); @@ -3232,10 +3232,10 @@ gimp_image_set_unit (GimpImage *image, } } -GimpUnit +GimpUnit * gimp_image_get_unit (GimpImage *image) { - g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_UNIT_INCH); + g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); return GIMP_IMAGE_GET_PRIVATE (image)->resolution_unit; } diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h index fc8841d750..c36b2caf22 100644 --- a/app/core/gimpimage.h +++ b/app/core/gimpimage.h @@ -200,8 +200,8 @@ void gimp_image_get_resolution (GimpImage *image, void gimp_image_resolution_changed (GimpImage *image); void gimp_image_set_unit (GimpImage *image, - GimpUnit unit); -GimpUnit gimp_image_get_unit (GimpImage *image); + GimpUnit *unit); +GimpUnit * gimp_image_get_unit (GimpImage *image); void gimp_image_unit_changed (GimpImage *image); gint gimp_image_get_width (GimpImage *image); diff --git a/app/core/gimpimageundo.c b/app/core/gimpimageundo.c index d03f7ed5fa..bf7bbca71e 100644 --- a/app/core/gimpimageundo.c +++ b/app/core/gimpimageundo.c @@ -423,7 +423,7 @@ gimp_image_undo_pop (GimpUndo *undo, if (image_undo->resolution_unit != gimp_image_get_unit (image)) { - GimpUnit unit; + GimpUnit *unit; unit = gimp_image_get_unit (image); private->resolution_unit = image_undo->resolution_unit; diff --git a/app/core/gimpimageundo.h b/app/core/gimpimageundo.h index 9ee2c525d2..a3144e1428 100644 --- a/app/core/gimpimageundo.h +++ b/app/core/gimpimageundo.h @@ -47,7 +47,7 @@ struct _GimpImageUndo gint previous_height; gdouble xresolution; gdouble yresolution; - GimpUnit resolution_unit; + GimpUnit *resolution_unit; GimpGrid *grid; gint num_colors; guchar *colormap; diff --git a/app/core/gimpparamspecs-desc.c b/app/core/gimpparamspecs-desc.c index edf14f299b..3f7ef9d8fc 100644 --- a/app/core/gimpparamspecs-desc.c +++ b/app/core/gimpparamspecs-desc.c @@ -45,6 +45,17 @@ gimp_param_spec_boolean_desc (GParamSpec *pspec) return g_strconcat (blurb, " (TRUE or FALSE)", NULL); } +static gchar * +gimp_param_spec_unit_desc (GParamSpec *pspec) +{ + GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec); + + return g_strdup_printf ("(default %s%s%s)", + gimp_unit_get_abbreviation (uspec->default_value), + uspec->allow_pixel ? ", pixel allowed": "", + uspec->allow_percent ? ", percent allowed": ""); +} + static gchar * gimp_param_spec_int_desc (GParamSpec *pspec) { @@ -169,6 +180,7 @@ gimp_param_spec_get_desc (GParamSpec *pspec) if (GIMP_IS_PARAM_SPEC_UNIT (pspec)) { + return gimp_param_spec_unit_desc (pspec); } else if (G_IS_PARAM_SPEC_INT (pspec)) { diff --git a/app/core/gimpstrokeoptions.c b/app/core/gimpstrokeoptions.c index 0a94a635dd..0f62336ad8 100644 --- a/app/core/gimpstrokeoptions.c +++ b/app/core/gimpstrokeoptions.c @@ -79,7 +79,7 @@ struct _GimpStrokeOptionsPrivate /* options for method == LIBART */ gdouble width; - GimpUnit unit; + GimpUnit *unit; GimpCapStyle cap_style; GimpJoinStyle join_style; @@ -167,7 +167,7 @@ gimp_stroke_options_class_init (GimpStrokeOptionsClass *klass) "unit", _("Unit"), NULL, - TRUE, FALSE, GIMP_UNIT_PIXEL, + TRUE, FALSE, gimp_unit_pixel (), GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_ENUM (object_class, PROP_CAP_STYLE, @@ -278,7 +278,7 @@ gimp_stroke_options_set_property (GObject *object, private->width = g_value_get_double (value); break; case PROP_UNIT: - private->unit = g_value_get_int (value); + private->unit = g_value_get_object (value); break; case PROP_CAP_STYLE: private->cap_style = g_value_get_enum (value); @@ -336,7 +336,7 @@ gimp_stroke_options_get_property (GObject *object, g_value_set_double (value, private->width); break; case PROP_UNIT: - g_value_set_int (value, private->unit); + g_value_set_object (value, private->unit); break; case PROP_CAP_STYLE: g_value_set_enum (value, private->cap_style); @@ -450,10 +450,10 @@ gimp_stroke_options_get_width (GimpStrokeOptions *options) return GET_PRIVATE (options)->width; } -GimpUnit +GimpUnit * gimp_stroke_options_get_unit (GimpStrokeOptions *options) { - g_return_val_if_fail (GIMP_IS_STROKE_OPTIONS (options), GIMP_UNIT_PIXEL); + g_return_val_if_fail (GIMP_IS_STROKE_OPTIONS (options), gimp_unit_pixel ()); return GET_PRIVATE (options)->unit; } diff --git a/app/core/gimpstrokeoptions.h b/app/core/gimpstrokeoptions.h index f5210e8578..f82250dc80 100644 --- a/app/core/gimpstrokeoptions.h +++ b/app/core/gimpstrokeoptions.h @@ -58,7 +58,7 @@ GimpStrokeOptions * gimp_stroke_options_new (Gimp GimpStrokeMethod gimp_stroke_options_get_method (GimpStrokeOptions *options); gdouble gimp_stroke_options_get_width (GimpStrokeOptions *options); -GimpUnit gimp_stroke_options_get_unit (GimpStrokeOptions *options); +GimpUnit * gimp_stroke_options_get_unit (GimpStrokeOptions *options); GimpCapStyle gimp_stroke_options_get_cap_style (GimpStrokeOptions *options); GimpJoinStyle gimp_stroke_options_get_join_style (GimpStrokeOptions *options); gdouble gimp_stroke_options_get_miter_limit (GimpStrokeOptions *options); diff --git a/app/core/gimptemplate.c b/app/core/gimptemplate.c index 148a40cf2e..993b76fe48 100644 --- a/app/core/gimptemplate.c +++ b/app/core/gimptemplate.c @@ -77,11 +77,11 @@ struct _GimpTemplatePrivate { gint width; gint height; - GimpUnit unit; + GimpUnit *unit; gdouble xresolution; gdouble yresolution; - GimpUnit resolution_unit; + GimpUnit *resolution_unit; GimpImageBaseType base_type; GimpPrecision precision; @@ -158,7 +158,7 @@ gimp_template_class_init (GimpTemplateClass *klass) _("Unit"), _("The unit used for coordinate display " "when not in dot-for-dot mode."), - TRUE, FALSE, GIMP_UNIT_PIXEL, + TRUE, FALSE, gimp_unit_pixel (), GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_RESOLUTION (object_class, PROP_XRESOLUTION, @@ -181,7 +181,7 @@ gimp_template_class_init (GimpTemplateClass *klass) "resolution-unit", _("Resolution unit"), NULL, - FALSE, FALSE, GIMP_UNIT_INCH, + FALSE, FALSE, gimp_unit_inch (), GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_ENUM (object_class, PROP_BASE_TYPE, @@ -310,7 +310,7 @@ gimp_template_set_property (GObject *object, private->height = g_value_get_int (value); break; case PROP_UNIT: - private->unit = g_value_get_int (value); + private->unit = g_value_get_object (value); break; case PROP_XRESOLUTION: private->xresolution = g_value_get_double (value); @@ -319,7 +319,7 @@ gimp_template_set_property (GObject *object, private->yresolution = g_value_get_double (value); break; case PROP_RESOLUTION_UNIT: - private->resolution_unit = g_value_get_int (value); + private->resolution_unit = g_value_get_object (value); break; case PROP_BASE_TYPE: private->base_type = g_value_get_enum (value); @@ -398,7 +398,7 @@ gimp_template_get_property (GObject *object, g_value_set_int (value, private->height); break; case PROP_UNIT: - g_value_set_int (value, private->unit); + g_value_set_object (value, private->unit); break; case PROP_XRESOLUTION: g_value_set_double (value, private->xresolution); @@ -407,7 +407,7 @@ gimp_template_get_property (GObject *object, g_value_set_double (value, private->yresolution); break; case PROP_RESOLUTION_UNIT: - g_value_set_int (value, private->resolution_unit); + g_value_set_object (value, private->resolution_unit); break; case PROP_BASE_TYPE: g_value_set_enum (value, private->base_type); @@ -558,10 +558,10 @@ gimp_template_get_height (GimpTemplate *template) return GET_PRIVATE (template)->height; } -GimpUnit +GimpUnit * gimp_template_get_unit (GimpTemplate *template) { - g_return_val_if_fail (GIMP_IS_TEMPLATE (template), GIMP_UNIT_INCH); + g_return_val_if_fail (GIMP_IS_TEMPLATE (template), gimp_unit_inch ()); return GET_PRIVATE (template)->unit; } @@ -582,10 +582,10 @@ gimp_template_get_resolution_y (GimpTemplate *template) return GET_PRIVATE (template)->yresolution; } -GimpUnit +GimpUnit * gimp_template_get_resolution_unit (GimpTemplate *template) { - g_return_val_if_fail (GIMP_IS_TEMPLATE (template), GIMP_UNIT_INCH); + g_return_val_if_fail (GIMP_IS_TEMPLATE (template), gimp_unit_inch ()); return GET_PRIVATE (template)->resolution_unit; } diff --git a/app/core/gimptemplate.h b/app/core/gimptemplate.h index 39ee4707e1..f3e977248e 100644 --- a/app/core/gimptemplate.h +++ b/app/core/gimptemplate.h @@ -75,11 +75,11 @@ void gimp_template_set_from_image (GimpTemplate *template, gint gimp_template_get_width (GimpTemplate *template); gint gimp_template_get_height (GimpTemplate *template); -GimpUnit gimp_template_get_unit (GimpTemplate *template); +GimpUnit * gimp_template_get_unit (GimpTemplate *template); gdouble gimp_template_get_resolution_x (GimpTemplate *template); gdouble gimp_template_get_resolution_y (GimpTemplate *template); -GimpUnit gimp_template_get_resolution_unit (GimpTemplate *template); +GimpUnit * gimp_template_get_resolution_unit (GimpTemplate *template); GimpImageBaseType gimp_template_get_base_type (GimpTemplate *template); GimpPrecision gimp_template_get_precision (GimpTemplate *template); diff --git a/app/core/gimpunit.c b/app/core/gimpunit.c index 3fad305ca3..7a84412b0b 100644 --- a/app/core/gimpunit.c +++ b/app/core/gimpunit.c @@ -36,78 +36,9 @@ #include "gimp-intl.h" -/* internal structures */ - -typedef struct -{ - gboolean delete_on_exit; - gdouble factor; - gint digits; - gchar *identifier; - gchar *symbol; - gchar *abbreviation; - gchar *singular; - gchar *plural; -} GimpUnitDef; - - -/* these are the built-in units - */ -static const GimpUnitDef gimp_unit_defs[GIMP_UNIT_END] = -{ - /* pseudo unit */ - { FALSE, 0.0, 0, "pixels", "px", "px", - NC_("unit-singular", "pixel"), NC_("unit-plural", "pixels") }, - - /* standard units */ - { FALSE, 1.0, 2, "inches", "''", "in", - NC_("unit-singular", "inch"), NC_("unit-plural", "inches") }, - - { FALSE, 25.4, 1, "millimeters", "mm", "mm", - NC_("unit-singular", "millimeter"), NC_("unit-plural", "millimeters") }, - - /* professional units */ - { FALSE, 72.0, 0, "points", "pt", "pt", - NC_("unit-singular", "point"), NC_("unit-plural", "points") }, - - { FALSE, 6.0, 1, "picas", "pc", "pc", - NC_("unit-singular", "pica"), NC_("unit-plural", "picas") } -}; - -/* not a unit at all but kept here to have the strings in one place - */ -static const GimpUnitDef gimp_unit_percent = -{ - FALSE, 0.0, 0, "percent", "%", "%", - NC_("singular", "percent"), NC_("plural", "percent") -}; - - -/* private functions */ - -static GimpUnitDef * -_gimp_unit_get_user_unit (Gimp *gimp, - GimpUnit unit) -{ - return g_list_nth_data (gimp->user_units, unit - GIMP_UNIT_END); -} - - /* public functions */ -gint -_gimp_unit_get_number_of_units (Gimp *gimp) -{ - return GIMP_UNIT_END + gimp->n_user_units; -} - -gint -_gimp_unit_get_number_of_built_in_units (Gimp *gimp) -{ - return GIMP_UNIT_END; -} - -GimpUnit +GimpUnit * _gimp_unit_new (Gimp *gimp, const gchar *identifier, gdouble factor, @@ -117,189 +48,23 @@ _gimp_unit_new (Gimp *gimp, const gchar *singular, const gchar *plural) { - GimpUnitDef *user_unit = g_slice_new0 (GimpUnitDef); + GimpUnit *unit; + gint unit_id; - user_unit->delete_on_exit = TRUE; - user_unit->factor = factor; - user_unit->digits = digits; - user_unit->identifier = g_strdup (identifier); - user_unit->symbol = g_strdup (symbol); - user_unit->abbreviation = g_strdup (abbreviation); - user_unit->singular = g_strdup (singular); - user_unit->plural = g_strdup (plural); + unit_id = GIMP_UNIT_END + g_list_length (gimp->user_units); + unit = g_object_new (GIMP_TYPE_UNIT, + "id", unit_id, + "name", identifier, + "factor", factor, + "digits", digits, + "symbol", symbol, + "abbreviation", abbreviation, + "singular", singular, + "plural", plural, + NULL); - gimp->user_units = g_list_append (gimp->user_units, user_unit); - gimp->n_user_units++; + gimp->user_units = g_list_append (gimp->user_units, unit); + gimp_unit_set_deletion_flag (unit, TRUE); - return GIMP_UNIT_END + gimp->n_user_units - 1; -} - -gboolean -_gimp_unit_get_deletion_flag (Gimp *gimp, - GimpUnit unit) -{ - g_return_val_if_fail (unit < (GIMP_UNIT_END + gimp->n_user_units), FALSE); - - if (unit < GIMP_UNIT_END) - return FALSE; - - return _gimp_unit_get_user_unit (gimp, unit)->delete_on_exit; -} - -void -_gimp_unit_set_deletion_flag (Gimp *gimp, - GimpUnit unit, - gboolean deletion_flag) -{ - g_return_if_fail ((unit >= GIMP_UNIT_END) && - (unit < (GIMP_UNIT_END + gimp->n_user_units))); - - _gimp_unit_get_user_unit (gimp, unit)->delete_on_exit = - deletion_flag ? TRUE : FALSE; -} - -gdouble -_gimp_unit_get_factor (Gimp *gimp, - GimpUnit unit) -{ - g_return_val_if_fail (unit < (GIMP_UNIT_END + gimp->n_user_units) || - (unit == GIMP_UNIT_PERCENT), - gimp_unit_defs[GIMP_UNIT_INCH].factor); - - if (unit < GIMP_UNIT_END) - return gimp_unit_defs[unit].factor; - - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.factor; - - return _gimp_unit_get_user_unit (gimp, unit)->factor; -} - -gint -_gimp_unit_get_digits (Gimp *gimp, - GimpUnit unit) -{ - g_return_val_if_fail (unit < (GIMP_UNIT_END + gimp->n_user_units) || - (unit == GIMP_UNIT_PERCENT), - gimp_unit_defs[GIMP_UNIT_INCH].digits); - - if (unit < GIMP_UNIT_END) - return gimp_unit_defs[unit].digits; - - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.digits; - - return _gimp_unit_get_user_unit (gimp, unit)->digits; -} - -const gchar * -_gimp_unit_get_identifier (Gimp *gimp, - GimpUnit unit) -{ - g_return_val_if_fail ((unit < (GIMP_UNIT_END + gimp->n_user_units)) || - (unit == GIMP_UNIT_PERCENT), - gimp_unit_defs[GIMP_UNIT_INCH].identifier); - - if (unit < GIMP_UNIT_END) - return gimp_unit_defs[unit].identifier; - - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.identifier; - - return _gimp_unit_get_user_unit (gimp, unit)->identifier; -} - -const gchar * -_gimp_unit_get_symbol (Gimp *gimp, - GimpUnit unit) -{ - g_return_val_if_fail ((unit < (GIMP_UNIT_END + gimp->n_user_units)) || - (unit == GIMP_UNIT_PERCENT), - gimp_unit_defs[GIMP_UNIT_INCH].symbol); - - if (unit < GIMP_UNIT_END) - return gimp_unit_defs[unit].symbol; - - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.symbol; - - return _gimp_unit_get_user_unit (gimp, unit)->symbol; -} - -const gchar * -_gimp_unit_get_abbreviation (Gimp *gimp, - GimpUnit unit) -{ - g_return_val_if_fail ((unit < (GIMP_UNIT_END + gimp->n_user_units)) || - (unit == GIMP_UNIT_PERCENT), - gimp_unit_defs[GIMP_UNIT_INCH].abbreviation); - - if (unit < GIMP_UNIT_END) - return gimp_unit_defs[unit].abbreviation; - - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.abbreviation; - - return _gimp_unit_get_user_unit (gimp, unit)->abbreviation; -} - -const gchar * -_gimp_unit_get_singular (Gimp *gimp, - GimpUnit unit) -{ - g_return_val_if_fail ((unit < (GIMP_UNIT_END + gimp->n_user_units)) || - (unit == GIMP_UNIT_PERCENT), - gimp_unit_defs[GIMP_UNIT_INCH].singular); - - if (unit < GIMP_UNIT_END) - return g_dpgettext2 (NULL, "unit-singular", gimp_unit_defs[unit].singular); - - if (unit == GIMP_UNIT_PERCENT) - return g_dpgettext2 (NULL, "unit-singular", gimp_unit_percent.singular); - - return _gimp_unit_get_user_unit (gimp, unit)->singular; -} - -const gchar * -_gimp_unit_get_plural (Gimp *gimp, - GimpUnit unit) -{ - g_return_val_if_fail ((unit < (GIMP_UNIT_END + gimp->n_user_units)) || - (unit == GIMP_UNIT_PERCENT), - gimp_unit_defs[GIMP_UNIT_INCH].plural); - - if (unit < GIMP_UNIT_END) - return g_dpgettext2 (NULL, "unit-plural", gimp_unit_defs[unit].plural); - - if (unit == GIMP_UNIT_PERCENT) - return g_dpgettext2 (NULL, "unit-plural", gimp_unit_percent.plural); - - return _gimp_unit_get_user_unit (gimp, unit)->plural; -} - - -/* The sole purpose of this function is to release the allocated - * memory. It must only be used from gimp_units_exit(). - */ -void -gimp_user_units_free (Gimp *gimp) -{ - GList *list; - - for (list = gimp->user_units; list; list = g_list_next (list)) - { - GimpUnitDef *user_unit = list->data; - - g_free (user_unit->identifier); - g_free (user_unit->symbol); - g_free (user_unit->abbreviation); - g_free (user_unit->singular); - g_free (user_unit->plural); - - g_slice_free (GimpUnitDef, user_unit); - } - - g_list_free (gimp->user_units); - gimp->user_units = NULL; - gimp->n_user_units = 0; + return unit; } diff --git a/app/core/gimpunit.h b/app/core/gimpunit.h index 60dbc752b6..d8eb66e56a 100644 --- a/app/core/gimpunit.h +++ b/app/core/gimpunit.h @@ -19,10 +19,7 @@ #define __APP_GIMP_UNIT_H__ -gint _gimp_unit_get_number_of_units (Gimp *gimp); -gint _gimp_unit_get_number_of_built_in_units (Gimp *gimp) G_GNUC_CONST; - -GimpUnit _gimp_unit_new (Gimp *gimp, +GimpUnit * _gimp_unit_new (Gimp *gimp, const gchar *identifier, gdouble factor, gint digits, @@ -31,31 +28,5 @@ GimpUnit _gimp_unit_new (Gimp *gimp, const gchar *singular, const gchar *plural); -gboolean _gimp_unit_get_deletion_flag (Gimp *gimp, - GimpUnit unit); -void _gimp_unit_set_deletion_flag (Gimp *gimp, - GimpUnit unit, - gboolean deletion_flag); - -gdouble _gimp_unit_get_factor (Gimp *gimp, - GimpUnit unit); - -gint _gimp_unit_get_digits (Gimp *gimp, - GimpUnit unit); - -const gchar * _gimp_unit_get_identifier (Gimp *gimp, - GimpUnit unit); - -const gchar * _gimp_unit_get_symbol (Gimp *gimp, - GimpUnit unit); -const gchar * _gimp_unit_get_abbreviation (Gimp *gimp, - GimpUnit unit); -const gchar * _gimp_unit_get_singular (Gimp *gimp, - GimpUnit unit); -const gchar * _gimp_unit_get_plural (Gimp *gimp, - GimpUnit unit); - -void gimp_user_units_free (Gimp *gimp); - #endif /* __APP_GIMP_UNIT_H__ */ diff --git a/app/dialogs/dialogs-types.h b/app/dialogs/dialogs-types.h index afdd02534c..0972d8cb13 100644 --- a/app/dialogs/dialogs-types.h +++ b/app/dialogs/dialogs-types.h @@ -26,11 +26,11 @@ typedef void (* GimpScaleCallback) (GtkWidget *dialog, GimpViewable *viewable, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, gdouble xresolution, gdouble yresolution, - GimpUnit resolution_unit, + GimpUnit *resolution_unit, gpointer user_data); diff --git a/app/dialogs/image-scale-dialog.c b/app/dialogs/image-scale-dialog.c index 9e9a8be1a8..264d076729 100644 --- a/app/dialogs/image-scale-dialog.c +++ b/app/dialogs/image-scale-dialog.c @@ -53,11 +53,11 @@ typedef struct gint width; gint height; - GimpUnit unit; + GimpUnit *unit; GimpInterpolationType interpolation; gdouble xresolution; gdouble yresolution; - GimpUnit resolution_unit; + GimpUnit *resolution_unit; GimpScaleCallback callback; gpointer user_data; @@ -71,11 +71,11 @@ static void image_scale_callback (GtkWidget *widget, GimpViewable *viewable, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, gdouble xresolution, gdouble yresolution, - GimpUnit resolution_unit, + GimpUnit *resolution_unit, gpointer data); static GtkWidget * image_scale_confirm_dialog (ImageScaleDialog *private); @@ -94,7 +94,7 @@ GtkWidget * image_scale_dialog_new (GimpImage *image, GimpContext *context, GtkWidget *parent, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, GimpScaleCallback callback, gpointer user_data) @@ -142,11 +142,11 @@ image_scale_callback (GtkWidget *widget, GimpViewable *viewable, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, gdouble xresolution, gdouble yresolution, - GimpUnit resolution_unit, + GimpUnit *resolution_unit, gpointer data) { ImageScaleDialog *private = data; diff --git a/app/dialogs/image-scale-dialog.h b/app/dialogs/image-scale-dialog.h index fe3d257571..bbd9ae8c65 100644 --- a/app/dialogs/image-scale-dialog.h +++ b/app/dialogs/image-scale-dialog.h @@ -22,7 +22,7 @@ GtkWidget * image_scale_dialog_new (GimpImage *image, GimpContext *context, GtkWidget *parent, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, GimpScaleCallback callback, gpointer user_data); diff --git a/app/dialogs/layer-options-dialog.c b/app/dialogs/layer-options-dialog.c index e4d1a39d93..1132725d8e 100644 --- a/app/dialogs/layer-options-dialog.c +++ b/app/dialogs/layer-options-dialog.c @@ -265,7 +265,7 @@ layer_options_dialog_new (GimpImage *image, gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10); - private->size_se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", + private->size_se = gimp_size_entry_new (1, gimp_unit_pixel (), "%a", TRUE, TRUE, FALSE, 10, GIMP_SIZE_ENTRY_UPDATE_SIZE); @@ -278,7 +278,7 @@ layer_options_dialog_new (GimpImage *image, gtk_widget_show (private->size_se); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (private->size_se), - GIMP_UNIT_PIXEL); + gimp_unit_pixel ()); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (private->size_se), 0, xres, FALSE); @@ -322,7 +322,7 @@ layer_options_dialog_new (GimpImage *image, gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10); - private->offset_se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", + private->offset_se = gimp_size_entry_new (1, gimp_unit_pixel (), "%a", TRUE, TRUE, FALSE, 10, GIMP_SIZE_ENTRY_UPDATE_SIZE); @@ -335,7 +335,7 @@ layer_options_dialog_new (GimpImage *image, gtk_widget_show (private->offset_se); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (private->offset_se), - GIMP_UNIT_PIXEL); + gimp_unit_pixel ()); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (private->offset_se), 0, xres, FALSE); diff --git a/app/dialogs/print-size-dialog.h b/app/dialogs/print-size-dialog.h index 53f37f5f6f..75a80535b4 100644 --- a/app/dialogs/print-size-dialog.h +++ b/app/dialogs/print-size-dialog.h @@ -23,7 +23,7 @@ typedef void (* GimpResolutionCallback) (GtkWidget *dialog, GimpImage *image, gdouble xresolution, gdouble yresolution, - GimpUnit resolution_unit, + GimpUnit *resolution_unit, gpointer user_data); diff --git a/app/dialogs/resize-dialog.c b/app/dialogs/resize-dialog.c index 34e937f1c4..ce98155108 100644 --- a/app/dialogs/resize-dialog.c +++ b/app/dialogs/resize-dialog.c @@ -62,10 +62,10 @@ struct _ResizeDialog gdouble old_xres; gdouble old_yres; - GimpUnit old_res_unit; + GimpUnit *old_res_unit; gint old_width; gint old_height; - GimpUnit old_unit; + GimpUnit *old_unit; GimpFillType old_fill_type; GimpItemSet old_layer_set; gboolean old_resize_text_layers; @@ -123,7 +123,7 @@ resize_dialog_new (GimpViewable *viewable, GtkWidget *parent, GimpHelpFunc help_func, const gchar *help_id, - GimpUnit unit, + GimpUnit *unit, GimpFillType fill_type, GimpItemSet layer_set, gboolean resize_text_layers, @@ -554,12 +554,12 @@ resize_dialog_response (GtkWidget *dialog, ResizeDialog *private) { GimpSizeEntry *entry = GIMP_SIZE_ENTRY (private->offset); - GimpUnit unit; + GimpUnit *unit; gint width; gint height; gdouble xres; gdouble yres; - GimpUnit res_unit; + GimpUnit *res_unit; switch (response_id) { @@ -729,7 +729,7 @@ template_changed (GimpContext *context, GimpTemplate *template, ResizeDialog *private) { - GimpUnit unit = private->old_unit; + GimpUnit *unit = private->old_unit; private->template = template; @@ -738,10 +738,10 @@ template_changed (GimpContext *context, if (template != NULL) { - gdouble xres; - gdouble yres; - GimpUnit res_unit; - gboolean resolution_mismatch; + gdouble xres; + gdouble yres; + GimpUnit *res_unit; + gboolean resolution_mismatch; unit = gimp_template_get_unit (template); xres = gimp_template_get_resolution_x (template); @@ -752,8 +752,7 @@ template_changed (GimpContext *context, yres != private->old_yres || res_unit != private->old_res_unit; - if (resolution_mismatch && - unit != GIMP_UNIT_PIXEL) + if (resolution_mismatch && unit != gimp_unit_pixel ()) { gchar *text; @@ -785,10 +784,10 @@ ppi_select_toggled (GtkWidget *radio, { gint width; gint height; - GimpUnit unit; + GimpUnit *unit; gdouble xres; gdouble yres; - GimpUnit res_unit; + GimpUnit *res_unit; GtkToggleButton *image_button; gboolean use_image_ppi; @@ -812,8 +811,7 @@ ppi_select_toggled (GtkWidget *radio, res_unit = gimp_template_get_resolution_unit (private->template); } - if (private->template != NULL && - unit != GIMP_UNIT_PIXEL) + if (private->template != NULL && unit != gimp_unit_pixel ()) { if (use_image_ppi) { diff --git a/app/dialogs/resize-dialog.h b/app/dialogs/resize-dialog.h index 223b43cc6d..61e22e70b4 100644 --- a/app/dialogs/resize-dialog.h +++ b/app/dialogs/resize-dialog.h @@ -24,12 +24,12 @@ typedef void (* GimpResizeCallback) (GtkWidget *dialog, GimpContext *context, gint width, gint height, - GimpUnit unit, + GimpUnit *unit, gint offset_x, gint offset_y, gdouble xres, gdouble yres, - GimpUnit res_unit, + GimpUnit *res_unit, GimpFillType fill_type, GimpItemSet layer_set, gboolean resize_text_layers, @@ -43,7 +43,7 @@ GtkWidget * resize_dialog_new (GimpViewable *viewable, GtkWidget *parent, GimpHelpFunc help_func, const gchar *help_id, - GimpUnit unit, + GimpUnit *unit, GimpFillType fill_type, GimpItemSet layer_set, gboolean resize_text_layers, diff --git a/app/dialogs/resolution-calibrate-dialog.c b/app/dialogs/resolution-calibrate-dialog.c index 2f9418a76f..d1a6378ab7 100644 --- a/app/dialogs/resolution-calibrate-dialog.c +++ b/app/dialogs/resolution-calibrate-dialog.c @@ -137,7 +137,7 @@ resolution_calibrate_dialog (GtkWidget *resolution_entry, gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (resolution_entry), 1); calibrate_entry = - gimp_coordinates_new (GIMP_UNIT_INCH, "%p", + gimp_coordinates_new (gimp_unit_inch (), "%p", FALSE, FALSE, 10, GIMP_SIZE_ENTRY_UPDATE_SIZE, FALSE, diff --git a/app/dialogs/scale-dialog.c b/app/dialogs/scale-dialog.c index c64acc9ef1..507abde93c 100644 --- a/app/dialogs/scale-dialog.c +++ b/app/dialogs/scale-dialog.c @@ -45,7 +45,7 @@ typedef struct _ScaleDialog ScaleDialog; struct _ScaleDialog { GimpViewable *viewable; - GimpUnit unit; + GimpUnit *unit; GimpInterpolationType interpolation; GtkWidget *box; GtkWidget *combo; @@ -73,7 +73,7 @@ scale_dialog_new (GimpViewable *viewable, GtkWidget *parent, GimpHelpFunc help_func, const gchar *help_id, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, GimpScaleCallback callback, gpointer user_data) @@ -221,9 +221,9 @@ scale_dialog_response (GtkWidget *dialog, gint response_id, ScaleDialog *private) { - GimpUnit unit = private->unit; + GimpUnit *unit = private->unit; gint interpolation = private->interpolation; - GimpUnit resolution_unit; + GimpUnit *resolution_unit; gint width, height; gdouble xres, yres; diff --git a/app/dialogs/scale-dialog.h b/app/dialogs/scale-dialog.h index 46e8f9cfd8..5f0177736f 100644 --- a/app/dialogs/scale-dialog.h +++ b/app/dialogs/scale-dialog.h @@ -26,7 +26,7 @@ GtkWidget * scale_dialog_new (GimpViewable *viewable, GtkWidget *parent, GimpHelpFunc help_func, const gchar *help_id, - GimpUnit unit, + GimpUnit *unit, GimpInterpolationType interpolation, GimpScaleCallback callback, gpointer user_data); diff --git a/app/display/gimpcursorview.c b/app/display/gimpcursorview.c index 9543d99d7a..b4002be6c7 100644 --- a/app/display/gimpcursorview.c +++ b/app/display/gimpcursorview.c @@ -87,10 +87,10 @@ struct _GimpCursorViewPrivate GimpDisplayShell *shell; GimpImage *image; - GimpUnit unit; + GimpUnit *unit; guint cursor_idle_id; GimpImage *cursor_image; - GimpUnit cursor_unit; + GimpUnit *cursor_unit; gdouble cursor_x; gdouble cursor_y; }; @@ -128,7 +128,7 @@ static void gimp_cursor_view_diplay_changed (GimpCursorView *v static void gimp_cursor_view_shell_unit_changed (GimpCursorView *view, GParamSpec *pspec, GimpDisplayShell *shell); -static void gimp_cursor_view_format_as_unit (GimpUnit unit, +static void gimp_cursor_view_format_as_unit (GimpUnit *unit, gchar *output_buf, gint output_buf_size, gdouble pixel_value, @@ -137,7 +137,7 @@ static void gimp_cursor_view_set_label_italic (GtkWidget *l gboolean italic); static void gimp_cursor_view_update_selection_info (GimpCursorView *view, GimpImage *image, - GimpUnit unit); + GimpUnit *unit); static gboolean gimp_cursor_view_cursor_idle (GimpCursorView *view); @@ -193,7 +193,7 @@ gimp_cursor_view_init (GimpCursorView *view) view->priv->context = NULL; view->priv->shell = NULL; view->priv->image = NULL; - view->priv->unit = GIMP_UNIT_PIXEL; + view->priv->unit = gimp_unit_pixel (); view->priv->cursor_idle_id = 0; gtk_widget_style_get (GTK_WIDGET (view), @@ -510,7 +510,7 @@ gimp_cursor_view_get_aux_info (GimpDocked *docked) } static void -gimp_cursor_view_format_as_unit (GimpUnit unit, +gimp_cursor_view_format_as_unit (GimpUnit *unit, gchar *output_buf, gint output_buf_size, gdouble pixel_value, @@ -523,7 +523,7 @@ gimp_cursor_view_format_as_unit (GimpUnit unit, value = gimp_pixels_to_units (pixel_value, unit, image_res); - if (unit != GIMP_UNIT_PIXEL) + if (unit != gimp_unit_pixel ()) { unit_digits = gimp_unit_get_scaled_digits (unit, image_res); unit_str = gimp_unit_get_abbreviation (unit); @@ -689,7 +689,7 @@ gimp_cursor_view_shell_unit_changed (GimpCursorView *view, GParamSpec *pspec, GimpDisplayShell *shell) { - GimpUnit new_unit = GIMP_UNIT_PIXEL; + GimpUnit *new_unit = gimp_unit_pixel (); if (shell) { @@ -706,7 +706,7 @@ gimp_cursor_view_shell_unit_changed (GimpCursorView *view, static void gimp_cursor_view_update_selection_info (GimpCursorView *view, GimpImage *image, - GimpUnit unit) + GimpUnit *unit) { gint x, y, width, height; @@ -751,7 +751,7 @@ gimp_cursor_view_cursor_idle (GimpCursorView *view) if (view->priv->cursor_image) { GimpImage *image = view->priv->cursor_image; - GimpUnit unit = view->priv->cursor_unit; + GimpUnit *unit = view->priv->cursor_unit; gdouble x = view->priv->cursor_x; gdouble y = view->priv->cursor_y; gboolean in_image; @@ -764,7 +764,7 @@ gimp_cursor_view_cursor_idle (GimpCursorView *view) gint int_x; gint int_y; - if (unit == GIMP_UNIT_PIXEL) + if (unit == gimp_unit_pixel ()) unit = gimp_image_get_unit (image); gimp_image_get_resolution (image, &xres, &yres); @@ -883,7 +883,7 @@ gimp_cursor_view_get_sample_merged (GimpCursorView *view) void gimp_cursor_view_update_cursor (GimpCursorView *view, GimpImage *image, - GimpUnit shell_unit, + GimpUnit *shell_unit, gdouble x, gdouble y) { diff --git a/app/display/gimpcursorview.h b/app/display/gimpcursorview.h index 2a774b6c6f..e0bf40f433 100644 --- a/app/display/gimpcursorview.h +++ b/app/display/gimpcursorview.h @@ -60,7 +60,7 @@ gboolean gimp_cursor_view_get_sample_merged (GimpCursorView *view); void gimp_cursor_view_update_cursor (GimpCursorView *view, GimpImage *image, - GimpUnit shell_unit, + GimpUnit *shell_unit, gdouble x, gdouble y); void gimp_cursor_view_clear_cursor (GimpCursorView *view); diff --git a/app/display/gimpdisplay.c b/app/display/gimpdisplay.c index 5a40bf3323..75d3691c49 100644 --- a/app/display/gimpdisplay.c +++ b/app/display/gimpdisplay.c @@ -359,7 +359,7 @@ gimp_display_progress_canceled (GimpProgress *progress, GimpDisplay * gimp_display_new (Gimp *gimp, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale, GimpUIManager *popup_manager, GimpDialogFactory *dialog_factory, @@ -682,7 +682,7 @@ gimp_display_empty (GimpDisplay *display) void gimp_display_fill (GimpDisplay *display, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale) { GimpDisplayImplPrivate *private; diff --git a/app/display/gimpdisplay.h b/app/display/gimpdisplay.h index b928fdbf2b..21109e384b 100644 --- a/app/display/gimpdisplay.h +++ b/app/display/gimpdisplay.h @@ -53,7 +53,7 @@ GType gimp_display_impl_get_type (void) G_GNUC_CONST; GimpDisplay * gimp_display_new (Gimp *gimp, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale, GimpUIManager *popup_manager, GimpDialogFactory *dialog_factory, @@ -74,7 +74,7 @@ GimpDisplayShell * gimp_display_get_shell (GimpDisplay *display); void gimp_display_empty (GimpDisplay *display); void gimp_display_fill (GimpDisplay *display, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale); void gimp_display_update_bounding_box diff --git a/app/display/gimpdisplayshell-dnd.c b/app/display/gimpdisplayshell-dnd.c index d4ac826a17..94b2ef3a88 100644 --- a/app/display/gimpdisplayshell-dnd.c +++ b/app/display/gimpdisplayshell-dnd.c @@ -227,7 +227,7 @@ gimp_display_shell_drop_drawable (GtkWidget *widget, { image = gimp_image_new_from_drawable (shell->display->gimp, GIMP_DRAWABLE (viewable)); - gimp_create_display (shell->display->gimp, image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (shell->display->gimp, image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (image); @@ -478,7 +478,7 @@ gimp_display_shell_drop_buffer (GtkWidget *widget, { image = gimp_image_new_from_buffer (shell->display->gimp, GIMP_BUFFER (viewable)); - gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (image->gimp, image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (image); @@ -664,7 +664,7 @@ gimp_display_shell_drop_component (GtkWidget *widget, { dest_image = gimp_image_new_from_component (image->gimp, image, component); - gimp_create_display (dest_image->gimp, dest_image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (dest_image->gimp, dest_image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (dest_image); @@ -721,7 +721,7 @@ gimp_display_shell_drop_pixbuf (GtkWidget *widget, { image = gimp_image_new_from_pixbuf (shell->display->gimp, pixbuf, _("Dropped Buffer")); - gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (image->gimp, image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (image); diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c index 7af627e46b..28e8c483f1 100644 --- a/app/display/gimpdisplayshell-handlers.c +++ b/app/display/gimpdisplayshell-handlers.c @@ -659,7 +659,7 @@ gimp_display_shell_resolution_changed_handler (GimpImage *image, if (shell->dot_for_dot) { - if (shell->unit != GIMP_UNIT_PIXEL) + if (shell->unit != gimp_unit_pixel ()) { gimp_display_shell_rulers_update (shell); } diff --git a/app/display/gimpdisplayshell-title.c b/app/display/gimpdisplayshell-title.c index 17a0683e25..f31e7baecd 100644 --- a/app/display/gimpdisplayshell-title.c +++ b/app/display/gimpdisplayshell-title.c @@ -420,7 +420,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell, break; case 'W': /* width in real-world units */ - if (shell->unit != GIMP_UNIT_PIXEL) + if (shell->unit != gimp_unit_pixel ()) { gdouble xres; gdouble yres; @@ -443,7 +443,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell, break; case 'H': /* height in real-world units */ - if (shell->unit != GIMP_UNIT_PIXEL) + if (shell->unit != gimp_unit_pixel ()) { gdouble xres; gdouble yres; @@ -476,7 +476,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell, break; case 'X': /* drawable width in real world units */ - if (drawable && shell->unit != GIMP_UNIT_PIXEL) + if (drawable && shell->unit != gimp_unit_pixel ()) { gdouble xres; gdouble yres; @@ -501,7 +501,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell, break; case 'Y': /* drawable height in real world units */ - if (drawable && shell->unit != GIMP_UNIT_PIXEL) + if (drawable && shell->unit != gimp_unit_pixel ()) { gdouble xres; gdouble yres; diff --git a/app/display/gimpdisplayshell-utils.c b/app/display/gimpdisplayshell-utils.c index b8089635c2..7775e54fc1 100644 --- a/app/display/gimpdisplayshell-utils.c +++ b/app/display/gimpdisplayshell-utils.c @@ -155,7 +155,7 @@ gimp_display_shell_get_line_status (GimpDisplayShell *shell, return g_strdup (status); } - if (shell->unit == GIMP_UNIT_PIXEL) + if (shell->unit == gimp_unit_pixel ()) xres = yres = 1.0; else gimp_image_get_resolution (image, &xres, &yres); @@ -188,7 +188,7 @@ gimp_display_shell_get_line_status (GimpDisplayShell *shell, angle = 0.0; } - if (shell->unit == GIMP_UNIT_PIXEL) + if (shell->unit == gimp_unit_pixel ()) { enhanced_status = g_strdup_printf ("%.1f %s, %.2f\302\260%s%s", pixel_dist, _("pixels"), angle, diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index 24ba875679..83ece443d5 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -280,7 +280,7 @@ gimp_display_shell_class_init (GimpDisplayShellClass *klass) g_object_class_install_property (object_class, PROP_UNIT, gimp_param_spec_unit ("unit", NULL, NULL, TRUE, FALSE, - GIMP_UNIT_PIXEL, + gimp_unit_pixel (), GIMP_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_TITLE, @@ -919,7 +919,7 @@ gimp_display_shell_set_property (GObject *object, shell->display = g_value_get_object (value); break; case PROP_UNIT: - gimp_display_shell_set_unit (shell, g_value_get_int (value)); + gimp_display_shell_set_unit (shell, g_value_get_object (value)); break; case PROP_TITLE: g_free (shell->title); @@ -959,7 +959,7 @@ gimp_display_shell_get_property (GObject *object, g_value_set_object (value, shell->display); break; case PROP_UNIT: - g_value_set_int (value, shell->unit); + g_value_set_object (value, shell->unit); break; case PROP_TITLE: g_value_set_string (value, shell->title); @@ -1335,7 +1335,7 @@ gimp_display_shell_transform_overlay (GimpDisplayShell *shell, GtkWidget * gimp_display_shell_new (GimpDisplay *display, - GimpUnit unit, + GimpUnit *unit, gdouble scale, GimpUIManager *popup_manager, GdkMonitor *monitor) @@ -1590,7 +1590,7 @@ gimp_display_shell_fill_idle (GimpDisplayShell *shell) void gimp_display_shell_fill (GimpDisplayShell *shell, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale) { GimpDisplayConfig *config; @@ -1702,7 +1702,7 @@ gimp_display_shell_rotated (GimpDisplayShell *shell) void gimp_display_shell_set_unit (GimpDisplayShell *shell, - GimpUnit unit) + GimpUnit *unit) { g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); @@ -1718,10 +1718,10 @@ gimp_display_shell_set_unit (GimpDisplayShell *shell, } } -GimpUnit +GimpUnit * gimp_display_shell_get_unit (GimpDisplayShell *shell) { - g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), GIMP_UNIT_PIXEL); + g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), gimp_unit_pixel ()); return shell->unit; } diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h index 859faf37cb..0969b457e3 100644 --- a/app/display/gimpdisplayshell.h +++ b/app/display/gimpdisplayshell.h @@ -60,7 +60,7 @@ struct _GimpDisplayShell GimpDisplayOptions *fullscreen_options; GimpDisplayOptions *no_image_options; - GimpUnit unit; + GimpUnit *unit; gint offset_x; /* offset of display image */ gint offset_y; @@ -269,7 +269,7 @@ struct _GimpDisplayShellClass GType gimp_display_shell_get_type (void) G_GNUC_CONST; GtkWidget * gimp_display_shell_new (GimpDisplay *display, - GimpUnit unit, + GimpUnit *unit, gdouble scale, GimpUIManager *popup_manager, GdkMonitor *monitor); @@ -302,7 +302,7 @@ void gimp_display_shell_reconnect (GimpDisplayShell *shell); void gimp_display_shell_empty (GimpDisplayShell *shell); void gimp_display_shell_fill (GimpDisplayShell *shell, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale); void gimp_display_shell_scaled (GimpDisplayShell *shell); @@ -310,8 +310,8 @@ void gimp_display_shell_scrolled (GimpDisplayShell *shell); void gimp_display_shell_rotated (GimpDisplayShell *shell); void gimp_display_shell_set_unit (GimpDisplayShell *shell, - GimpUnit unit); -GimpUnit gimp_display_shell_get_unit (GimpDisplayShell *shell); + GimpUnit *unit); +GimpUnit * gimp_display_shell_get_unit (GimpDisplayShell *shell); gboolean gimp_display_shell_snap_coords (GimpDisplayShell *shell, GimpCoords *coords, diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c index 3ba9cf9314..c87f27cae6 100644 --- a/app/display/gimpstatusbar.c +++ b/app/display/gimpstatusbar.c @@ -1477,7 +1477,7 @@ gimp_statusbar_push_coords (GimpStatusbar *statusbar, break; } - if (shell->unit == GIMP_UNIT_PIXEL) + if (shell->unit == gimp_unit_pixel ()) { if (precision == GIMP_CURSOR_PRECISION_SUBPIXEL) { @@ -1540,7 +1540,7 @@ gimp_statusbar_push_length (GimpStatusbar *statusbar, shell = statusbar->shell; - if (shell->unit == GIMP_UNIT_PIXEL) + if (shell->unit == gimp_unit_pixel ()) { gimp_statusbar_push (statusbar, context, icon_name, @@ -1768,7 +1768,7 @@ gimp_statusbar_update_cursor (GimpStatusbar *statusbar, } statusbar->cursor_precision = precision; - if (shell->unit == GIMP_UNIT_PIXEL) + if (shell->unit == gimp_unit_pixel ()) { if (precision == GIMP_CURSOR_PRECISION_SUBPIXEL) { @@ -1911,7 +1911,7 @@ gimp_statusbar_shell_scaled (GimpDisplayShell *shell, g_signal_handlers_unblock_by_func (statusbar->unit_combo, gimp_statusbar_unit_changed, statusbar); - if (shell->unit == GIMP_UNIT_PIXEL) + if (shell->unit == gimp_unit_pixel ()) { g_snprintf (statusbar->cursor_format_str, sizeof (statusbar->cursor_format_str), @@ -2468,7 +2468,7 @@ gimp_statusbar_queue_pos_redraw (gpointer data) * Of course, it could still happen for people going way * off-canvas but that's acceptable edge-case. */ - if (shell->unit == GIMP_UNIT_PIXEL) + if (shell->unit == gimp_unit_pixel ()) { label_width_chars = floor (log10 (2 * image_width)) + floor (log10 (2 * image_height)) + 6; diff --git a/app/file/file-open.c b/app/file/file-open.c index 2f6b62c1f6..859cc8c97e 100644 --- a/app/file/file-open.c +++ b/app/file/file-open.c @@ -561,7 +561,7 @@ file_open_with_proc_and_display (Gimp *gimp, g_free (basename); } - if (gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0, + if (gimp_create_display (image->gimp, image, gimp_unit_pixel (), 1.0, monitor)) { /* the display owns the image now */ diff --git a/app/gui/gui-vtable.c b/app/gui/gui-vtable.c index 0dfec4e991..46e0089bc1 100644 --- a/app/gui/gui-vtable.c +++ b/app/gui/gui-vtable.c @@ -138,7 +138,7 @@ static GimpDisplay * gui_get_empty_display (Gimp *gimp); static GBytes * gui_display_get_window_id (GimpDisplay *display); static GimpDisplay * gui_display_create (Gimp *gimp, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale, GObject *monitor); static void gui_display_delete (GimpDisplay *display); @@ -396,7 +396,7 @@ gui_display_get_window_id (GimpDisplay *display) static GimpDisplay * gui_display_create (Gimp *gimp, GimpImage *image, - GimpUnit unit, + GimpUnit *unit, gdouble scale, GObject *monitor) { diff --git a/app/gui/gui.c b/app/gui/gui.c index 0695ebc3d2..40d6304a24 100644 --- a/app/gui/gui.c +++ b/app/gui/gui.c @@ -616,7 +616,7 @@ gui_restore_after_callback (Gimp *gimp, /* create the empty display */ display = GIMP_DISPLAY (gimp_create_display (gimp, NULL, - GIMP_UNIT_PIXEL, 1.0, + gimp_unit_pixel (), 1.0, G_OBJECT (initial_monitor))); shell = gimp_display_get_shell (display); diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c index 511a467046..68269d706d 100644 --- a/app/paint/gimppaintoptions.c +++ b/app/paint/gimppaintoptions.c @@ -67,7 +67,7 @@ #define DEFAULT_FADE_LENGTH 100.0 #define DEFAULT_FADE_REVERSE FALSE #define DEFAULT_FADE_REPEAT GIMP_REPEAT_NONE -#define DEFAULT_FADE_UNIT GIMP_UNIT_PIXEL +#define DEFAULT_FADE_UNIT gimp_unit_pixel () #define DEFAULT_GRADIENT_REVERSE FALSE #define DEFAULT_GRADIENT_BLEND_SPACE GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL @@ -627,7 +627,7 @@ gimp_paint_options_set_property (GObject *object, fade_options->fade_repeat = g_value_get_enum (value); break; case PROP_FADE_UNIT: - fade_options->fade_unit = g_value_get_int (value); + fade_options->fade_unit = g_value_get_object (value); break; case PROP_GRADIENT_REVERSE: @@ -786,7 +786,7 @@ gimp_paint_options_get_property (GObject *object, g_value_set_enum (value, fade_options->fade_repeat); break; case PROP_FADE_UNIT: - g_value_set_int (value, fade_options->fade_unit); + g_value_set_object (value, fade_options->fade_unit); break; case PROP_GRADIENT_REVERSE: @@ -983,30 +983,26 @@ gimp_paint_options_get_fade (GimpPaintOptions *paint_options, fade_options = paint_options->fade_options; - switch (fade_options->fade_unit) + if (fade_options->fade_unit == gimp_unit_pixel ()) { - case GIMP_UNIT_PIXEL: fade_out = fade_options->fade_length; - break; - - case GIMP_UNIT_PERCENT: + } + else if (fade_options->fade_unit == gimp_unit_percent ()) + { fade_out = (MAX (gimp_image_get_width (image), gimp_image_get_height (image)) * fade_options->fade_length / 100); - break; + } + else + { + gdouble xres; + gdouble yres; - default: - { - gdouble xres; - gdouble yres; + gimp_image_get_resolution (image, &xres, &yres); - gimp_image_get_resolution (image, &xres, &yres); - - unit_factor = gimp_unit_get_factor (fade_options->fade_unit); - fade_out = (fade_options->fade_length * - MAX (xres, yres) / unit_factor); - } - break; + unit_factor = gimp_unit_get_factor (fade_options->fade_unit); + fade_out = (fade_options->fade_length * + MAX (xres, yres) / unit_factor); } /* factor in the fade out value */ diff --git a/app/paint/gimppaintoptions.h b/app/paint/gimppaintoptions.h index 76b8b3488a..a5f2f9ed34 100644 --- a/app/paint/gimppaintoptions.h +++ b/app/paint/gimppaintoptions.h @@ -46,7 +46,7 @@ struct _GimpFadeOptions { gboolean fade_reverse; gdouble fade_length; - GimpUnit fade_unit; + GimpUnit *fade_unit; GimpRepeatMode fade_repeat; }; diff --git a/app/pdb/context-cmds.c b/app/pdb/context-cmds.c index 2bdd9597c0..f01fb1ce96 100644 --- a/app/pdb/context-cmds.c +++ b/app/pdb/context-cmds.c @@ -27,6 +27,7 @@ #include +#include "libgimpbase/gimpbase.h" #include "libgimpcolor/gimpcolor.h" #include "libgimpconfig/gimpconfig.h" @@ -497,7 +498,7 @@ context_get_line_width_unit_invoker (GimpProcedure *procedure, GError **error) { GimpValueArray *return_vals; - GimpUnit line_width_unit = GIMP_UNIT_PIXEL; + GimpUnit *line_width_unit = NULL; GimpStrokeOptions *options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context)); @@ -507,7 +508,7 @@ context_get_line_width_unit_invoker (GimpProcedure *procedure, NULL); return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); - g_value_set_int (gimp_value_array_index (return_vals, 1), line_width_unit); + g_value_set_object (gimp_value_array_index (return_vals, 1), line_width_unit); return return_vals; } @@ -521,9 +522,9 @@ context_set_line_width_unit_invoker (GimpProcedure *procedure, GError **error) { gboolean success = TRUE; - GimpUnit line_width_unit; + GimpUnit *line_width_unit; - line_width_unit = g_value_get_int (gimp_value_array_index (args, 0)); + line_width_unit = g_value_get_object (gimp_value_array_index (args, 0)); if (success) { @@ -3533,9 +3534,9 @@ register_context_procs (GimpPDB *pdb) gimp_param_spec_unit ("line-width-unit", "line width unit", "The line width unit setting", - TRUE, FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); @@ -3560,9 +3561,9 @@ register_context_procs (GimpPDB *pdb) gimp_param_spec_unit ("line-width-unit", "line width unit", "The line width setting unit", - TRUE, FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); diff --git a/app/pdb/display-cmds.c b/app/pdb/display-cmds.c index 6af856105a..21bc5c6aca 100644 --- a/app/pdb/display-cmds.c +++ b/app/pdb/display-cmds.c @@ -88,7 +88,7 @@ display_new_invoker (GimpProcedure *procedure, { gimp_image_flush (image); - display = gimp_create_display (gimp, image, GIMP_UNIT_PIXEL, 1.0, NULL); + display = gimp_create_display (gimp, image, gimp_unit_pixel (), 1.0, NULL); if (display) { diff --git a/app/pdb/gimprc-cmds.c b/app/pdb/gimprc-cmds.c index 87976770b5..0d3eb20fc5 100644 --- a/app/pdb/gimprc-cmds.c +++ b/app/pdb/gimprc-cmds.c @@ -142,12 +142,12 @@ get_default_unit_invoker (GimpProcedure *procedure, GError **error) { GimpValueArray *return_vals; - GimpUnit unit_id = GIMP_UNIT_PIXEL; + GimpUnit *unit = NULL; - unit_id = gimp_get_default_unit (); + unit = gimp_get_default_unit (); return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); - g_value_set_int (gimp_value_array_index (return_vals, 1), unit_id); + g_value_set_object (gimp_value_array_index (return_vals, 1), unit); return return_vals; } @@ -312,19 +312,19 @@ register_gimprc_procs (GimpPDB *pdb) "gimp-get-default-unit"); gimp_procedure_set_static_help (procedure, "Get the default unit (taken from the user's locale).", - "Returns the default unit's integer ID.", + "Returns the default unit.", NULL); gimp_procedure_set_static_attribution (procedure, "Spencer Kimball & Peter Mattis", "Spencer Kimball & Peter Mattis", "1995-1996"); gimp_procedure_add_return_value (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", + gimp_param_spec_unit ("unit", + "unit", "Default unit", - TRUE, FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c index 2ade1a5773..852289d246 100644 --- a/app/pdb/image-cmds.c +++ b/app/pdb/image-cmds.c @@ -2484,7 +2484,7 @@ image_get_unit_invoker (GimpProcedure *procedure, gboolean success = TRUE; GimpValueArray *return_vals; GimpImage *image; - GimpUnit unit = GIMP_UNIT_PIXEL; + GimpUnit *unit = NULL; image = g_value_get_object (gimp_value_array_index (args, 0)); @@ -2497,7 +2497,7 @@ image_get_unit_invoker (GimpProcedure *procedure, error ? *error : NULL); if (success) - g_value_set_int (gimp_value_array_index (return_vals, 1), unit); + g_value_set_object (gimp_value_array_index (return_vals, 1), unit); return return_vals; } @@ -2512,10 +2512,10 @@ image_set_unit_invoker (GimpProcedure *procedure, { gboolean success = TRUE; GimpImage *image; - GimpUnit unit; + GimpUnit *unit; image = g_value_get_object (gimp_value_array_index (args, 0)); - unit = g_value_get_int (gimp_value_array_index (args, 1)); + unit = g_value_get_object (gimp_value_array_index (args, 1)); if (success) { @@ -5195,9 +5195,9 @@ register_image_procs (GimpPDB *pdb) gimp_param_spec_unit ("unit", "unit", "The unit", - TRUE, FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); @@ -5228,7 +5228,7 @@ register_image_procs (GimpPDB *pdb) "The new image unit", FALSE, FALSE, - GIMP_UNIT_INCH, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 4ec21cd53f..8fdbe57831 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -30,7 +30,7 @@ #include "internal-procs.h" -/* 786 procedures registered total */ +/* 778 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/app/pdb/text-layer-cmds.c b/app/pdb/text-layer-cmds.c index 1322741c0a..6e58529f7f 100644 --- a/app/pdb/text-layer-cmds.c +++ b/app/pdb/text-layer-cmds.c @@ -65,14 +65,14 @@ text_layer_new_invoker (GimpProcedure *procedure, const gchar *text; GimpFont *font; gdouble size; - GimpUnit unit; + GimpUnit *unit; GimpTextLayer *layer = NULL; image = g_value_get_object (gimp_value_array_index (args, 0)); text = g_value_get_string (gimp_value_array_index (args, 1)); font = g_value_get_object (gimp_value_array_index (args, 2)); size = g_value_get_double (gimp_value_array_index (args, 3)); - unit = g_value_get_int (gimp_value_array_index (args, 4)); + unit = g_value_get_object (gimp_value_array_index (args, 4)); if (success) { @@ -318,7 +318,7 @@ text_layer_get_font_size_invoker (GimpProcedure *procedure, GimpValueArray *return_vals; GimpTextLayer *layer; gdouble font_size = 0.0; - GimpUnit unit = GIMP_UNIT_PIXEL; + GimpUnit *unit = NULL; layer = g_value_get_object (gimp_value_array_index (args, 0)); @@ -336,7 +336,7 @@ text_layer_get_font_size_invoker (GimpProcedure *procedure, if (success) { g_value_set_double (gimp_value_array_index (return_vals, 1), font_size); - g_value_set_int (gimp_value_array_index (return_vals, 2), unit); + g_value_set_object (gimp_value_array_index (return_vals, 2), unit); } return return_vals; @@ -353,11 +353,11 @@ text_layer_set_font_size_invoker (GimpProcedure *procedure, gboolean success = TRUE; GimpTextLayer *layer; gdouble font_size; - GimpUnit unit; + GimpUnit *unit; layer = g_value_get_object (gimp_value_array_index (args, 0)); font_size = g_value_get_double (gimp_value_array_index (args, 1)); - unit = g_value_get_int (gimp_value_array_index (args, 2)); + unit = g_value_get_object (gimp_value_array_index (args, 2)); if (success) { @@ -1039,9 +1039,9 @@ register_text_layer_procs (GimpPDB *pdb) gimp_param_spec_unit ("unit", "unit", "The units of specified size", - TRUE, FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_procedure_add_return_value (procedure, gimp_param_spec_text_layer ("layer", @@ -1261,9 +1261,9 @@ register_text_layer_procs (GimpPDB *pdb) gimp_param_spec_unit ("unit", "unit", "The unit used for the font size", - TRUE, FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); @@ -1298,9 +1298,9 @@ register_text_layer_procs (GimpPDB *pdb) gimp_param_spec_unit ("unit", "unit", "The unit to use for the font size", - TRUE, FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); diff --git a/app/pdb/unit-cmds.c b/app/pdb/unit-cmds.c index 13389437e9..9144133fc6 100644 --- a/app/pdb/unit-cmds.c +++ b/app/pdb/unit-cmds.c @@ -31,6 +31,7 @@ #include "pdb-types.h" +#include "core/gimp.h" #include "core/gimpparamspecs.h" #include "core/gimpunit.h" @@ -39,44 +40,6 @@ #include "internal-procs.h" -static GimpValueArray * -unit_get_number_of_units_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - GimpValueArray *return_vals; - gint num_units = 0; - - num_units = _gimp_unit_get_number_of_units (gimp); - - return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); - g_value_set_int (gimp_value_array_index (return_vals, 1), num_units); - - return return_vals; -} - -static GimpValueArray * -unit_get_number_of_built_in_units_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - GimpValueArray *return_vals; - gint num_units = 0; - - num_units = _gimp_unit_get_number_of_built_in_units (gimp); - - return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); - g_value_set_int (gimp_value_array_index (return_vals, 1), num_units); - - return return_vals; -} - static GimpValueArray * unit_new_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -94,7 +57,7 @@ unit_new_invoker (GimpProcedure *procedure, const gchar *abbreviation; const gchar *singular; const gchar *plural; - GimpUnit unit_id = GIMP_UNIT_PIXEL; + GimpUnit *unit = NULL; identifier = g_value_get_string (gimp_value_array_index (args, 0)); factor = g_value_get_double (gimp_value_array_index (args, 1)); @@ -106,15 +69,72 @@ unit_new_invoker (GimpProcedure *procedure, if (success) { - unit_id = _gimp_unit_new (gimp, identifier, factor, digits, - symbol, abbreviation, singular, plural); + unit = _gimp_unit_new (gimp, identifier, factor, digits, + symbol, abbreviation, singular, plural); } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) - g_value_set_int (gimp_value_array_index (return_vals, 1), unit_id); + g_value_set_object (gimp_value_array_index (return_vals, 1), unit); + + return return_vals; +} + +static GimpValueArray * +unit_get_data_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpValueArray *return_vals; + gint unit_id; + gchar *identifier = NULL; + gdouble factor = 0.0; + gint digits = 0; + gchar *symbol = NULL; + gchar *abbreviation = NULL; + gchar *singular = NULL; + gchar *plural = NULL; + + unit_id = g_value_get_int (gimp_value_array_index (args, 0)); + + if (success) + { + if (unit_id >= 0) + { + GimpUnit *unit = gimp_unit_get_by_id (unit_id); + + if (unit != NULL) + { + identifier = g_strdup (gimp_unit_get_identifier (unit)); + factor = gimp_unit_get_factor (unit); + digits = gimp_unit_get_digits (unit); + symbol = g_strdup (gimp_unit_get_symbol (unit)); + abbreviation = g_strdup (gimp_unit_get_abbreviation (unit)); + singular = g_strdup (gimp_unit_get_singular (unit)); + plural = g_strdup (gimp_unit_get_plural (unit)); + } + } + } + + return_vals = gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); + + if (success) + { + g_value_take_string (gimp_value_array_index (return_vals, 1), identifier); + g_value_set_double (gimp_value_array_index (return_vals, 2), factor); + g_value_set_int (gimp_value_array_index (return_vals, 3), digits); + g_value_take_string (gimp_value_array_index (return_vals, 4), symbol); + g_value_take_string (gimp_value_array_index (return_vals, 5), abbreviation); + g_value_take_string (gimp_value_array_index (return_vals, 6), singular); + g_value_take_string (gimp_value_array_index (return_vals, 7), plural); + } return return_vals; } @@ -129,14 +149,14 @@ unit_get_deletion_flag_invoker (GimpProcedure *procedure, { gboolean success = TRUE; GimpValueArray *return_vals; - GimpUnit unit_id; + GimpUnit *unit; gboolean deletion_flag = FALSE; - unit_id = g_value_get_int (gimp_value_array_index (args, 0)); + unit = g_value_get_object (gimp_value_array_index (args, 0)); if (success) { - deletion_flag = _gimp_unit_get_deletion_flag (gimp, unit_id); + deletion_flag = gimp_unit_get_deletion_flag (unit); } return_vals = gimp_procedure_get_return_values (procedure, success, @@ -157,275 +177,26 @@ unit_set_deletion_flag_invoker (GimpProcedure *procedure, GError **error) { gboolean success = TRUE; - GimpUnit unit_id; + GimpUnit *unit; gboolean deletion_flag; - unit_id = g_value_get_int (gimp_value_array_index (args, 0)); + unit = g_value_get_object (gimp_value_array_index (args, 0)); deletion_flag = g_value_get_boolean (gimp_value_array_index (args, 1)); if (success) { - _gimp_unit_set_deletion_flag (gimp, unit_id, deletion_flag); + gimp_unit_set_deletion_flag (unit, deletion_flag); } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); } -static GimpValueArray * -unit_get_identifier_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpValueArray *return_vals; - GimpUnit unit_id; - gchar *identifier = NULL; - - unit_id = g_value_get_int (gimp_value_array_index (args, 0)); - - if (success) - { - identifier = g_strdup (_gimp_unit_get_identifier (gimp, unit_id)); - } - - return_vals = gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); - - if (success) - g_value_take_string (gimp_value_array_index (return_vals, 1), identifier); - - return return_vals; -} - -static GimpValueArray * -unit_get_factor_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpValueArray *return_vals; - GimpUnit unit_id; - gdouble factor = 0.0; - - unit_id = g_value_get_int (gimp_value_array_index (args, 0)); - - if (success) - { - factor = _gimp_unit_get_factor (gimp, unit_id); - } - - return_vals = gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); - - if (success) - g_value_set_double (gimp_value_array_index (return_vals, 1), factor); - - return return_vals; -} - -static GimpValueArray * -unit_get_digits_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpValueArray *return_vals; - GimpUnit unit_id; - gint digits = 0; - - unit_id = g_value_get_int (gimp_value_array_index (args, 0)); - - if (success) - { - digits = _gimp_unit_get_digits (gimp, unit_id); - } - - return_vals = gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); - - if (success) - g_value_set_int (gimp_value_array_index (return_vals, 1), digits); - - return return_vals; -} - -static GimpValueArray * -unit_get_symbol_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpValueArray *return_vals; - GimpUnit unit_id; - gchar *symbol = NULL; - - unit_id = g_value_get_int (gimp_value_array_index (args, 0)); - - if (success) - { - symbol = g_strdup (_gimp_unit_get_symbol (gimp, unit_id)); - } - - return_vals = gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); - - if (success) - g_value_take_string (gimp_value_array_index (return_vals, 1), symbol); - - return return_vals; -} - -static GimpValueArray * -unit_get_abbreviation_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpValueArray *return_vals; - GimpUnit unit_id; - gchar *abbreviation = NULL; - - unit_id = g_value_get_int (gimp_value_array_index (args, 0)); - - if (success) - { - abbreviation = g_strdup (_gimp_unit_get_abbreviation (gimp, unit_id)); - } - - return_vals = gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); - - if (success) - g_value_take_string (gimp_value_array_index (return_vals, 1), abbreviation); - - return return_vals; -} - -static GimpValueArray * -unit_get_singular_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpValueArray *return_vals; - GimpUnit unit_id; - gchar *singular = NULL; - - unit_id = g_value_get_int (gimp_value_array_index (args, 0)); - - if (success) - { - singular = g_strdup (_gimp_unit_get_singular (gimp, unit_id)); - } - - return_vals = gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); - - if (success) - g_value_take_string (gimp_value_array_index (return_vals, 1), singular); - - return return_vals; -} - -static GimpValueArray * -unit_get_plural_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpValueArray *return_vals; - GimpUnit unit_id; - gchar *plural = NULL; - - unit_id = g_value_get_int (gimp_value_array_index (args, 0)); - - if (success) - { - plural = g_strdup (_gimp_unit_get_plural (gimp, unit_id)); - } - - return_vals = gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); - - if (success) - g_value_take_string (gimp_value_array_index (return_vals, 1), plural); - - return return_vals; -} - void register_unit_procs (GimpPDB *pdb) { GimpProcedure *procedure; - /* - * gimp-unit-get-number-of-units - */ - procedure = gimp_procedure_new (unit_get_number_of_units_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-unit-get-number-of-units"); - gimp_procedure_set_static_help (procedure, - "Returns the number of units.", - "This procedure returns the number of defined units.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Michael Natterer ", - "Michael Natterer", - "1999"); - gimp_procedure_add_return_value (procedure, - g_param_spec_int ("num-units", - "num units", - "The number of units", - G_MININT32, G_MAXINT32, 0, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - - /* - * gimp-unit-get-number-of-built-in-units - */ - procedure = gimp_procedure_new (unit_get_number_of_built_in_units_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-unit-get-number-of-built-in-units"); - gimp_procedure_set_static_help (procedure, - "Returns the number of built-in units.", - "This procedure returns the number of defined units built-in to GIMP.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Michael Natterer ", - "Michael Natterer", - "1999"); - gimp_procedure_add_return_value (procedure, - g_param_spec_int ("num-units", - "num units", - "The number of built-in units", - G_MININT32, G_MAXINT32, 0, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - /* * gimp-unit-new */ @@ -433,8 +204,8 @@ register_unit_procs (GimpPDB *pdb) gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-unit-new"); gimp_procedure_set_static_help (procedure, - "Creates a new unit and returns it's integer ID.", - "This procedure creates a new unit and returns it's integer ID. Note that the new unit will have it's deletion flag set to TRUE, so you will have to set it to FALSE with 'gimp-unit-set-deletion-flag' to make it persistent.", + "Creates a new unit.", + "This procedure creates a new unit and returns it. Note that the new unit will have it's deletion flag set to TRUE, so you will have to set it to FALSE with 'gimp-unit-set-deletion-flag' to make it persistent.", NULL); gimp_procedure_set_static_attribution (procedure, "Michael Natterer ", @@ -488,16 +259,86 @@ register_unit_procs (GimpPDB *pdb) NULL, GIMP_PARAM_READWRITE)); gimp_procedure_add_return_value (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The new unit's ID", - TRUE, + gimp_param_spec_unit ("unit", + "unit", + "The new unit", FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-unit-get-data + */ + procedure = gimp_procedure_new (unit_get_data_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-unit-get-data"); + gimp_procedure_set_static_help (procedure, + "Returns the various data pertaining to a given unit ID.", + "This procedure returns all properties making up an unit. It is only meant for internal usage to query non built-in units and it is a programming error to use it directly, in particular for any of the built-in units.", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Jehan", + "Jehan", + "2023"); + gimp_procedure_add_argument (procedure, + g_param_spec_int ("unit-id", + "unit id", + "The unit's integer ID", + G_MININT32, G_MAXINT32, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_string ("identifier", + "identifier", + "The unit's textual identifier", + FALSE, FALSE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + g_param_spec_double ("factor", + "factor", + "The unit's factor", + -G_MAXDOUBLE, G_MAXDOUBLE, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + g_param_spec_int ("digits", + "digits", + "The unit's number of digits", + G_MININT32, G_MAXINT32, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_string ("symbol", + "symbol", + "The unit's symbol", + FALSE, FALSE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_string ("abbreviation", + "abbreviation", + "The unit's abbreviation", + FALSE, FALSE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_string ("singular", + "singular", + "The unit's singular form", + FALSE, FALSE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_string ("plural", + "plural", + "The unit's plural form", + FALSE, FALSE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-unit-get-deletion-flag */ @@ -513,12 +354,12 @@ register_unit_procs (GimpPDB *pdb) "Michael Natterer", "1999"); gimp_procedure_add_argument (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The unit's integer ID", - TRUE, + gimp_param_spec_unit ("unit", + "unit", + "The unit", FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_procedure_add_return_value (procedure, g_param_spec_boolean ("deletion-flag", @@ -544,12 +385,12 @@ register_unit_procs (GimpPDB *pdb) "Michael Natterer", "1999"); gimp_procedure_add_argument (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The unit's integer ID", - TRUE, + gimp_param_spec_unit ("unit", + "unit", + "The unit", FALSE, - GIMP_UNIT_PIXEL, + FALSE, + gimp_unit_inch (), GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, g_param_spec_boolean ("deletion-flag", @@ -559,226 +400,4 @@ register_unit_procs (GimpPDB *pdb) GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); - - /* - * gimp-unit-get-identifier - */ - procedure = gimp_procedure_new (unit_get_identifier_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-unit-get-identifier"); - gimp_procedure_set_static_help (procedure, - "Returns the textual identifier of the unit.", - "This procedure returns the textual identifier of the unit. For built-in units it will be the english singular form of the unit's name. For user-defined units this should equal to the singular form.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Michael Natterer ", - "Michael Natterer", - "1999"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The unit's integer ID", - TRUE, - FALSE, - GIMP_UNIT_PIXEL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - gimp_param_spec_string ("identifier", - "identifier", - "The unit's textual identifier", - FALSE, FALSE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - - /* - * gimp-unit-get-factor - */ - procedure = gimp_procedure_new (unit_get_factor_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-unit-get-factor"); - gimp_procedure_set_static_help (procedure, - "Returns the factor of the unit.", - "This procedure returns the unit's factor which indicates how many units make up an inch. Note that asking for the factor of \"pixels\" will produce an error.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Michael Natterer ", - "Michael Natterer", - "1999"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The unit's integer ID", - TRUE, - FALSE, - GIMP_UNIT_PIXEL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - g_param_spec_double ("factor", - "factor", - "The unit's factor", - -G_MAXDOUBLE, G_MAXDOUBLE, 0, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - - /* - * gimp-unit-get-digits - */ - procedure = gimp_procedure_new (unit_get_digits_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-unit-get-digits"); - gimp_procedure_set_static_help (procedure, - "Returns the number of digits of the unit.", - "This procedure returns the number of digits you should provide in input or output functions to get approximately the same accuracy as with two digits and inches. Note that asking for the digits of \"pixels\" will produce an error.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Michael Natterer ", - "Michael Natterer", - "1999"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The unit's integer ID", - TRUE, - FALSE, - GIMP_UNIT_PIXEL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - g_param_spec_int ("digits", - "digits", - "The unit's number of digits", - G_MININT32, G_MAXINT32, 0, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - - /* - * gimp-unit-get-symbol - */ - procedure = gimp_procedure_new (unit_get_symbol_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-unit-get-symbol"); - gimp_procedure_set_static_help (procedure, - "Returns the symbol of the unit.", - "This procedure returns the symbol of the unit (\"''\" for inches).", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Michael Natterer ", - "Michael Natterer", - "1999"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The unit's integer ID", - TRUE, - FALSE, - GIMP_UNIT_PIXEL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - gimp_param_spec_string ("symbol", - "symbol", - "The unit's symbol", - FALSE, FALSE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - - /* - * gimp-unit-get-abbreviation - */ - procedure = gimp_procedure_new (unit_get_abbreviation_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-unit-get-abbreviation"); - gimp_procedure_set_static_help (procedure, - "Returns the abbreviation of the unit.", - "This procedure returns the abbreviation of the unit (\"in\" for inches).", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Michael Natterer ", - "Michael Natterer", - "1999"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The unit's integer ID", - TRUE, - FALSE, - GIMP_UNIT_PIXEL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - gimp_param_spec_string ("abbreviation", - "abbreviation", - "The unit's abbreviation", - FALSE, FALSE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - - /* - * gimp-unit-get-singular - */ - procedure = gimp_procedure_new (unit_get_singular_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-unit-get-singular"); - gimp_procedure_set_static_help (procedure, - "Returns the singular form of the unit.", - "This procedure returns the singular form of the unit.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Michael Natterer ", - "Michael Natterer", - "1999"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The unit's integer ID", - TRUE, - FALSE, - GIMP_UNIT_PIXEL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - gimp_param_spec_string ("singular", - "singular", - "The unit's singular form", - FALSE, FALSE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - - /* - * gimp-unit-get-plural - */ - procedure = gimp_procedure_new (unit_get_plural_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-unit-get-plural"); - gimp_procedure_set_static_help (procedure, - "Returns the plural form of the unit.", - "This procedure returns the plural form of the unit.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Michael Natterer ", - "Michael Natterer", - "1999"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_unit ("unit-id", - "unit id", - "The unit's integer ID", - TRUE, - FALSE, - GIMP_UNIT_PIXEL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - gimp_param_spec_string ("plural", - "plural", - "The unit's plural form", - FALSE, FALSE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); } diff --git a/app/plug-in/gimpgpparams.c b/app/plug-in/gimpgpparams.c index 3dd74d39b3..5437264084 100644 --- a/app/plug-in/gimpgpparams.c +++ b/app/plug-in/gimpgpparams.c @@ -41,6 +41,7 @@ #include "core/gimppalette.h" #include "core/gimppattern.h" #include "core/gimpselection.h" +#include "core/gimpunit.h" #include "text/gimpfont.h" #include "text/gimptextlayer.h" diff --git a/app/tests/gimp-app-test-utils.c b/app/tests/gimp-app-test-utils.c index 4ab44eac43..681e64cbd7 100644 --- a/app/tests/gimp-app-test-utils.c +++ b/app/tests/gimp-app-test-utils.c @@ -20,6 +20,8 @@ #include #include +#include "libgimpbase/gimpbase.h" + #include "display/display-types.h" #include "display/gimpdisplay.h" @@ -196,7 +198,7 @@ gimp_test_utils_create_image (Gimp *gimp, gimp_create_display (gimp, image, - GIMP_UNIT_PIXEL, + gimp_unit_pixel (), 1.0 /*scale*/, NULL); } diff --git a/app/tests/test-xcf.c b/app/tests/test-xcf.c index 178a925ef7..c4138bf583 100644 --- a/app/tests/test-xcf.c +++ b/app/tests/test-xcf.c @@ -126,7 +126,7 @@ "manually and may thus look weird if "\ "opened and inspected in GIMP." -#define GIMP_MAINIMAGE_UNIT GIMP_UNIT_PICA +#define GIMP_MAINIMAGE_UNIT gimp_unit_pica () #define GIMP_MAINIMAGE_GRIDXSPACING 25.0 #define GIMP_MAINIMAGE_GRIDYSPACING 27.0 @@ -903,9 +903,7 @@ gimp_assert_mainimage (GimpImage *image, g_free (parasite_data); /* Unit */ - g_assert_cmpint (gimp_image_get_unit (image), - ==, - GIMP_MAINIMAGE_UNIT); + g_assert_true (gimp_image_get_unit (image) == GIMP_MAINIMAGE_UNIT); /* Grid */ grid = gimp_image_get_grid (image); diff --git a/app/text/gimptext-xlfd.c b/app/text/gimptext-xlfd.c index c83a63e955..b70ba665a2 100644 --- a/app/text/gimptext-xlfd.c +++ b/app/text/gimptext-xlfd.c @@ -144,9 +144,9 @@ gimp_text_font_name_from_xlfd (const gchar *xlfd) * Returns: %TRUE on success, %FALSE otherwise. **/ gboolean -gimp_text_font_size_from_xlfd (const gchar *xlfd, - gdouble *size, - GimpUnit *size_unit) +gimp_text_font_size_from_xlfd (const gchar *xlfd, + gdouble *size, + GimpUnit **size_unit) { gchar buffer[XLFD_MAX_FIELD_LEN]; gchar *field; @@ -158,7 +158,7 @@ gimp_text_font_size_from_xlfd (const gchar *xlfd, if (field) { *size = atoi (field); - *size_unit = GIMP_UNIT_PIXEL; + *size_unit = gimp_unit_pixel (); return TRUE; } @@ -166,7 +166,7 @@ gimp_text_font_size_from_xlfd (const gchar *xlfd, if (field) { *size = atoi (field) / 10.0; - *size_unit = GIMP_UNIT_POINT; + *size_unit = gimp_unit_point (); return TRUE; } @@ -185,10 +185,10 @@ void gimp_text_set_font_from_xlfd (GimpText *text, const gchar *xlfd) { - gchar *font_name; - GimpFont *font = NULL; - gdouble size; - GimpUnit size_unit; + gchar *font_name; + GimpFont *font = NULL; + gdouble size; + GimpUnit *size_unit; g_return_if_fail (GIMP_IS_TEXT (text)); diff --git a/app/text/gimptext-xlfd.h b/app/text/gimptext-xlfd.h index 3a9c50961b..a6189588b5 100644 --- a/app/text/gimptext-xlfd.h +++ b/app/text/gimptext-xlfd.h @@ -24,13 +24,13 @@ /* handle X Logical Font Descriptions for compat */ -gchar * gimp_text_font_name_from_xlfd (const gchar *xlfd); -gboolean gimp_text_font_size_from_xlfd (const gchar *xlfd, - gdouble *size, - GimpUnit *size_unit); +gchar * gimp_text_font_name_from_xlfd (const gchar *xlfd); +gboolean gimp_text_font_size_from_xlfd (const gchar *xlfd, + gdouble *size, + GimpUnit **size_unit); -void gimp_text_set_font_from_xlfd (GimpText *text, - const gchar *xlfd); +void gimp_text_set_font_from_xlfd (GimpText *text, + const gchar *xlfd); #endif /* __GIMP_TEXT_COMPAT_H__ */ diff --git a/app/text/gimptext.c b/app/text/gimptext.c index a55716224b..d39669e8e1 100644 --- a/app/text/gimptext.c +++ b/app/text/gimptext.c @@ -192,7 +192,7 @@ gimp_text_class_init (GimpTextClass *klass) GIMP_CONFIG_PROP_UNIT (object_class, PROP_UNIT, "font-size-unit", NULL, NULL, - TRUE, FALSE, GIMP_UNIT_PIXEL, + TRUE, FALSE, gimp_unit_pixel (), GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_ANTIALIAS, @@ -299,7 +299,7 @@ gimp_text_class_init (GimpTextClass *klass) GIMP_CONFIG_PROP_UNIT (object_class, PROP_BOX_UNIT, "box-unit", NULL, NULL, - TRUE, FALSE, GIMP_UNIT_PIXEL, + TRUE, FALSE, gimp_unit_pixel (), GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_MATRIX2 (object_class, PROP_TRANSFORMATION, @@ -448,7 +448,7 @@ gimp_text_get_property (GObject *object, g_value_set_double (value, text->font_size); break; case PROP_UNIT: - g_value_set_int (value, text->unit); + g_value_set_object (value, text->unit); break; case PROP_ANTIALIAS: g_value_set_boolean (value, text->antialias); @@ -493,7 +493,7 @@ gimp_text_get_property (GObject *object, g_value_set_double (value, text->box_height); break; case PROP_BOX_UNIT: - g_value_set_int (value, text->box_unit); + g_value_set_object (value, text->box_unit); break; case PROP_TRANSFORMATION: g_value_set_boxed (value, &text->transformation); @@ -593,7 +593,7 @@ gimp_text_set_property (GObject *object, text->font_size = g_value_get_double (value); break; case PROP_UNIT: - text->unit = g_value_get_int (value); + text->unit = g_value_get_object (value); break; case PROP_ANTIALIAS: text->antialias = g_value_get_boolean (value); @@ -639,7 +639,7 @@ gimp_text_set_property (GObject *object, text->box_height = g_value_get_double (value); break; case PROP_BOX_UNIT: - text->box_unit = g_value_get_int (value); + text->box_unit = g_value_get_object (value); break; case PROP_TRANSFORMATION: matrix = g_value_get_boxed (value); diff --git a/app/text/gimptext.h b/app/text/gimptext.h index c013a949a0..117b237767 100644 --- a/app/text/gimptext.h +++ b/app/text/gimptext.h @@ -42,7 +42,7 @@ struct _GimpText gchar *text; gchar *markup; GimpFont *font; - GimpUnit unit; + GimpUnit *unit; gdouble font_size; gboolean antialias; GimpTextHintStyle hint_style; @@ -68,7 +68,7 @@ struct _GimpText GimpTextBoxMode box_mode; gdouble box_width; gdouble box_height; - GimpUnit box_unit; + GimpUnit *box_unit; GimpMatrix2 transformation; gdouble offset_x; gdouble offset_y; diff --git a/app/tools/gimpeditselectiontool.c b/app/tools/gimpeditselectiontool.c index b09191f7ac..cada0bde93 100644 --- a/app/tools/gimpeditselectiontool.c +++ b/app/tools/gimpeditselectiontool.c @@ -638,7 +638,7 @@ gimp_edit_selection_tool_draw (GimpDrawTool *draw_tool) GimpDisplay *display = GIMP_TOOL (draw_tool)->display; GimpImage *image = gimp_display_get_image (display); GimpDisplayShell *shell = gimp_display_get_shell (display); - GimpUnit unit = gimp_display_shell_get_unit (shell); + GimpUnit *unit = gimp_display_shell_get_unit (shell); const gchar *abbreviation = gimp_unit_get_abbreviation (unit); GList *selected_items; GList *iter; diff --git a/app/tools/gimpgradienttool-editor.c b/app/tools/gimpgradienttool-editor.c index 94fa55b493..87431bac88 100644 --- a/app/tools/gimpgradienttool-editor.c +++ b/app/tools/gimpgradienttool-editor.c @@ -1304,7 +1304,7 @@ gimp_gradient_tool_editor_init_endpoint_gui (GimpGradientTool *gradient_tool) gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 6); gradient_tool->endpoint_se = - se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", + se = gimp_size_entry_new (1, gimp_unit_pixel (), "%a", TRUE, TRUE, FALSE, 6, GIMP_SIZE_ENTRY_UPDATE_SIZE); gtk_grid_set_row_spacing (GTK_GRID (se), 4); @@ -1391,7 +1391,7 @@ gimp_gradient_tool_editor_init_stop_gui (GimpGradientTool *gradient_tool) /* the position size entry */ gradient_tool->stop_se = - se = gimp_size_entry_new (1, GIMP_UNIT_PERCENT, "%a", + se = gimp_size_entry_new (1, gimp_unit_percent (), "%a", FALSE, TRUE, FALSE, 6, GIMP_SIZE_ENTRY_UPDATE_SIZE); gimp_size_entry_show_unit_menu (GIMP_SIZE_ENTRY (se), FALSE); @@ -1490,7 +1490,7 @@ gimp_gradient_tool_editor_init_midpoint_gui (GimpGradientTool *gradient_tool) /* the position size entry */ gradient_tool->midpoint_se = - se = gimp_size_entry_new (1, GIMP_UNIT_PERCENT, "%a", + se = gimp_size_entry_new (1, gimp_unit_percent (), "%a", FALSE, TRUE, FALSE, 6, GIMP_SIZE_ENTRY_UPDATE_SIZE); gimp_size_entry_show_unit_menu (GIMP_SIZE_ENTRY (se), FALSE); diff --git a/app/tools/gimpmeasuretool.c b/app/tools/gimpmeasuretool.c index ea2756c6d9..91bbc05836 100644 --- a/app/tools/gimpmeasuretool.c +++ b/app/tools/gimpmeasuretool.c @@ -591,7 +591,7 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure, pixel_distance = sqrt (SQR (ax - bx) + SQR (ay - by)); inch_distance = sqrt (SQR ((gdouble) (ax - bx) / xres) + SQR ((gdouble) (ay - by) / yres)); - unit_distance = gimp_unit_get_factor (shell->unit) * inch_distance; + unit_distance = gimp_unit_get_factor (shell->unit) * inch_distance; g_object_get (measure->widget, "pixel-angle", &pixel_angle, @@ -611,7 +611,7 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure, unit_width_digits = gimp_unit_get_scaled_digits (shell->unit, xres); unit_height_digits = gimp_unit_get_scaled_digits (shell->unit, yres); - if (shell->unit == GIMP_UNIT_PIXEL) + if (shell->unit == gimp_unit_pixel ()) { gimp_tool_replace_status (GIMP_TOOL (measure), display, "%.1f %s, %.2f\302\260 (%d × %d)", @@ -640,7 +640,7 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure, g_snprintf (buf, sizeof (buf), "%.1f", pixel_distance); gtk_label_set_text (GTK_LABEL (measure->distance_label[0]), buf); - if (shell->unit != GIMP_UNIT_PIXEL) + if (shell->unit != gimp_unit_pixel ()) { g_snprintf (format, sizeof (format), "%%.%df", unit_distance_digits); @@ -677,7 +677,7 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure, g_snprintf (buf, sizeof (buf), "%d", pixel_width); gtk_label_set_text (GTK_LABEL (measure->width_label[0]), buf); - if (shell->unit != GIMP_UNIT_PIXEL) + if (shell->unit != gimp_unit_pixel ()) { g_snprintf (format, sizeof (format), "%%.%df", unit_width_digits); @@ -697,7 +697,7 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure, gtk_label_set_text (GTK_LABEL (measure->height_label[0]), buf); /* Height */ - if (shell->unit != GIMP_UNIT_PIXEL) + if (shell->unit != gimp_unit_pixel ()) { g_snprintf (format, sizeof (format), "%%.%df", unit_height_digits); diff --git a/app/tools/gimpoffsettool.c b/app/tools/gimpoffsettool.c index b270a1bf58..4042d98d3f 100644 --- a/app/tools/gimpoffsettool.c +++ b/app/tools/gimpoffsettool.c @@ -22,6 +22,7 @@ #include #include +#include "libgimpbase/gimpbase.h" #include "libgimpmath/gimpmath.h" #include "libgimpwidgets/gimpwidgets.h" @@ -484,7 +485,7 @@ gimp_offset_tool_dialog (GimpFilterTool *filter_tool) gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10); - offset_tool->offset_se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", + offset_tool->offset_se = gimp_size_entry_new (1, gimp_unit_pixel (), "%a", TRUE, TRUE, FALSE, 10, GIMP_SIZE_ENTRY_UPDATE_SIZE); @@ -502,7 +503,7 @@ gimp_offset_tool_dialog (GimpFilterTool *filter_tool) gtk_widget_show (offset_tool->offset_se); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (offset_tool->offset_se), - GIMP_UNIT_PIXEL); + gimp_unit_pixel ()); g_signal_connect (offset_tool->offset_se, "refval-changed", G_CALLBACK (gimp_offset_tool_offset_changed), diff --git a/app/tools/gimprectangleoptions.c b/app/tools/gimprectangleoptions.c index a4fafd70dc..dd2717a1ec 100644 --- a/app/tools/gimprectangleoptions.c +++ b/app/tools/gimprectangleoptions.c @@ -148,7 +148,7 @@ gimp_rectangle_options_default_init (GimpRectangleOptionsInterface *iface) NULL, _("Unit of top left corner coordinate"), TRUE, TRUE, - GIMP_UNIT_PIXEL, + gimp_unit_pixel (), GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT)); @@ -157,7 +157,7 @@ gimp_rectangle_options_default_init (GimpRectangleOptionsInterface *iface) NULL, _("Unit of selection size"), TRUE, TRUE, - GIMP_UNIT_PIXEL, + gimp_unit_pixel (), GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT)); @@ -287,7 +287,7 @@ gimp_rectangle_options_default_init (GimpRectangleOptionsInterface *iface) NULL, _("Unit of fixed width, height or size"), TRUE, TRUE, - GIMP_UNIT_PIXEL, + gimp_unit_pixel (), GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT)); @@ -483,10 +483,10 @@ gimp_rectangle_options_set_property (GObject *object, private->height = g_value_get_double (value); break; case GIMP_RECTANGLE_OPTIONS_PROP_POSITION_UNIT: - private->position_unit = g_value_get_int (value); + private->position_unit = g_value_get_object (value); break; case GIMP_RECTANGLE_OPTIONS_PROP_SIZE_UNIT: - private->size_unit = g_value_get_int (value); + private->size_unit = g_value_get_object (value); break; case GIMP_RECTANGLE_OPTIONS_PROP_FIXED_RULE_ACTIVE: @@ -535,7 +535,7 @@ gimp_rectangle_options_set_property (GObject *object, private->use_string_current = g_value_get_boolean (value); break; case GIMP_RECTANGLE_OPTIONS_PROP_FIXED_UNIT: - private->fixed_unit = g_value_get_int (value); + private->fixed_unit = g_value_get_object (value); break; case GIMP_RECTANGLE_OPTIONS_PROP_FIXED_CENTER: @@ -590,10 +590,10 @@ gimp_rectangle_options_get_property (GObject *object, g_value_set_double (value, private->height); break; case GIMP_RECTANGLE_OPTIONS_PROP_POSITION_UNIT: - g_value_set_int (value, private->position_unit); + g_value_set_object (value, private->position_unit); break; case GIMP_RECTANGLE_OPTIONS_PROP_SIZE_UNIT: - g_value_set_int (value, private->size_unit); + g_value_set_object (value, private->size_unit); break; case GIMP_RECTANGLE_OPTIONS_PROP_FIXED_RULE_ACTIVE: @@ -642,7 +642,7 @@ gimp_rectangle_options_get_property (GObject *object, g_value_set_boolean (value, private->use_string_current); break; case GIMP_RECTANGLE_OPTIONS_PROP_FIXED_UNIT: - g_value_set_int (value, private->fixed_unit); + g_value_set_object (value, private->fixed_unit); break; case GIMP_RECTANGLE_OPTIONS_PROP_FIXED_CENTER: @@ -763,7 +763,7 @@ gimp_rectangle_options_prop_dimension_frame_new (GObject *config, GtkSizeGroup *label_group, GtkWidget **entry) { - GimpUnit unit_value; + GimpUnit *unit_value; GtkWidget *frame; GtkWidget *hbox; GtkWidget *label; diff --git a/app/tools/gimprectangleoptions.h b/app/tools/gimprectangleoptions.h index e3d011c4b0..e3afeacdcd 100644 --- a/app/tools/gimprectangleoptions.h +++ b/app/tools/gimprectangleoptions.h @@ -89,8 +89,8 @@ struct _GimpRectangleOptionsPrivate gdouble width; gdouble height; - GimpUnit position_unit; - GimpUnit size_unit; + GimpUnit *position_unit; + GimpUnit *size_unit; gboolean fixed_rule_active; GimpRectangleFixedRule fixed_rule; @@ -119,7 +119,7 @@ struct _GimpRectangleOptionsPrivate */ gboolean use_string_current; - GimpUnit fixed_unit; + GimpUnit *fixed_unit; /* options gui */ diff --git a/app/tools/gimprotatetool.c b/app/tools/gimprotatetool.c index 51715afdfe..9193594fa5 100644 --- a/app/tools/gimprotatetool.c +++ b/app/tools/gimprotatetool.c @@ -21,6 +21,7 @@ #include #include +#include "libgimpbase/gimpbase.h" #include "libgimpmath/gimpmath.h" #include "libgimpwidgets/gimpwidgets.h" @@ -302,7 +303,7 @@ gimp_rotate_tool_dialog (GimpTransformGridTool *tg_tool) gimp_grid_attach_aligned (GTK_GRID (grid), 0, 2, _("Center _X:"), 0.0, 0.5, button, 1); - rotate->sizeentry = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", + rotate->sizeentry = gimp_size_entry_new (1, gimp_unit_pixel (), "%a", TRUE, TRUE, FALSE, SB_WIDTH, GIMP_SIZE_ENTRY_UPDATE_SIZE); gimp_size_entry_add_field (GIMP_SIZE_ENTRY (rotate->sizeentry), diff --git a/app/tools/gimptextoptions.c b/app/tools/gimptextoptions.c index 5fe60a138a..595722c7d2 100644 --- a/app/tools/gimptextoptions.c +++ b/app/tools/gimptextoptions.c @@ -163,7 +163,7 @@ gimp_text_options_class_init (GimpTextOptionsClass *klass) "font-size-unit", _("Unit"), _("Font size unit"), - TRUE, FALSE, GIMP_UNIT_PIXEL, + TRUE, FALSE, gimp_unit_pixel (), GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_FONT_SIZE, "font-size", @@ -306,7 +306,7 @@ gimp_text_options_class_init (GimpTextOptionsClass *klass) "outline-unit", _("Unit"), _("Outline width unit"), - TRUE, FALSE, GIMP_UNIT_PIXEL, + TRUE, FALSE, gimp_unit_pixel (), GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_ENUM (object_class, PROP_OUTLINE_CAP_STYLE, "outline-cap-style", @@ -397,7 +397,7 @@ gimp_text_options_get_property (GObject *object, g_value_set_double (value, options->font_size); break; case PROP_UNIT: - g_value_set_int (value, options->unit); + g_value_set_object (value, options->unit); break; case PROP_ANTIALIAS: g_value_set_boolean (value, options->antialias); @@ -443,7 +443,7 @@ gimp_text_options_get_property (GObject *object, g_value_set_double (value, options->outline_width); break; case PROP_OUTLINE_UNIT: - g_value_set_int (value, options->outline_unit); + g_value_set_object (value, options->outline_unit); break; case PROP_OUTLINE_CAP_STYLE: g_value_set_enum (value, options->outline_cap_style); @@ -503,7 +503,7 @@ gimp_text_options_set_property (GObject *object, options->font_size = g_value_get_double (value); break; case PROP_UNIT: - options->unit = g_value_get_int (value); + options->unit = g_value_get_object (value); break; case PROP_ANTIALIAS: options->antialias = g_value_get_boolean (value); @@ -560,7 +560,7 @@ gimp_text_options_set_property (GObject *object, options->outline_width = g_value_get_double (value); break; case PROP_OUTLINE_UNIT: - options->outline_unit = g_value_get_int (value); + options->outline_unit = g_value_get_object (value); break; case PROP_OUTLINE_CAP_STYLE: options->outline_cap_style = g_value_get_enum (value); diff --git a/app/tools/gimptextoptions.h b/app/tools/gimptextoptions.h index c1a6cc10d0..d0ae0daef9 100644 --- a/app/tools/gimptextoptions.h +++ b/app/tools/gimptextoptions.h @@ -37,7 +37,7 @@ struct _GimpTextOptions { GimpToolOptions tool_options; - GimpUnit unit; + GimpUnit *unit; gdouble font_size; gboolean antialias; GimpTextHintStyle hint_style; @@ -54,7 +54,7 @@ struct _GimpTextOptions GeglColor *outline_foreground; GimpPattern *outline_pattern; gdouble outline_width; - GimpUnit outline_unit; + GimpUnit *outline_unit; GimpCapStyle outline_cap_style; GimpJoinStyle outline_join_style; gdouble outline_miter_limit; diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c index 012e6043ad..dad4f6d9dc 100644 --- a/app/tools/gimptexttool.c +++ b/app/tools/gimptexttool.c @@ -1163,7 +1163,7 @@ gimp_text_tool_rectangle_change_complete (GimpToolRectangle *rectangle, if ((x2 - x1) != gimp_item_get_width (item) || (y2 - y1) != gimp_item_get_height (item)) { - GimpUnit box_unit = text_tool->proxy->box_unit; + GimpUnit *box_unit = text_tool->proxy->box_unit; gdouble xres, yres; gboolean push_undo = TRUE; GimpUndo *undo; @@ -1681,8 +1681,8 @@ gimp_text_tool_create_layer (GimpTextTool *text_tool, if (text_tool->text_box_fixed) { - GimpUnit box_unit = text_tool->proxy->box_unit; - gdouble xres, yres; + GimpUnit *box_unit = text_tool->proxy->box_unit; + gdouble xres, yres; gimp_image_get_resolution (image, &xres, &yres); diff --git a/app/tools/gimptransform3dtool.c b/app/tools/gimptransform3dtool.c index 1872697a37..c84951bb44 100644 --- a/app/tools/gimptransform3dtool.c +++ b/app/tools/gimptransform3dtool.c @@ -250,7 +250,7 @@ gimp_transform_3d_tool_dialog (GimpTransformGridTool *tg_tool) gtk_widget_show (vbox2); /* vanishing-point size entry */ - se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", TRUE, TRUE, FALSE, 6, + se = gimp_size_entry_new (1, gimp_unit_pixel (), "%a", TRUE, TRUE, FALSE, 6, GIMP_SIZE_ENTRY_UPDATE_SIZE); gtk_grid_set_row_spacing (GTK_GRID (se), 2); gtk_grid_set_column_spacing (GTK_GRID (se), 2); @@ -298,7 +298,7 @@ gimp_transform_3d_tool_dialog (GimpTransformGridTool *tg_tool) gtk_widget_show (vbox2); /* focal-length size entry */ - se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", TRUE, FALSE, FALSE, 6, + se = gimp_size_entry_new (1, gimp_unit_pixel (), "%a", TRUE, FALSE, FALSE, 6, GIMP_SIZE_ENTRY_UPDATE_SIZE); gtk_grid_set_row_spacing (GTK_GRID (se), 2); gtk_box_pack_start (GTK_BOX (vbox2), se, FALSE, FALSE, 0); @@ -348,7 +348,7 @@ gimp_transform_3d_tool_dialog (GimpTransformGridTool *tg_tool) gtk_widget_show (vbox2); /* offset size entry */ - se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", TRUE, TRUE, FALSE, 6, + se = gimp_size_entry_new (1, gimp_unit_pixel (), "%a", TRUE, TRUE, FALSE, 6, GIMP_SIZE_ENTRY_UPDATE_SIZE); gtk_grid_set_row_spacing (GTK_GRID (se), 2); gtk_grid_set_column_spacing (GTK_GRID (se), 2); diff --git a/app/tools/gimpwarptool.c b/app/tools/gimpwarptool.c index 10aa0408b0..3a6f2bad2d 100644 --- a/app/tools/gimpwarptool.c +++ b/app/tools/gimpwarptool.c @@ -24,6 +24,7 @@ #include #include +#include "libgimpbase/gimpbase.h" #include "libgimpmath/gimpmath.h" #include "libgimpwidgets/gimpwidgets.h" @@ -1529,7 +1530,7 @@ gimp_warp_tool_animate (GimpWarpTool *wt) gimp_warp_tool_update_stroke (wt, NULL); widget = GTK_WIDGET (gimp_display_get_shell (tool->display)); - gimp_create_display (orig_image->gimp, image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (orig_image->gimp, image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (image); } diff --git a/app/vectors/gimppath-export.c b/app/vectors/gimppath-export.c index 17a96ba576..59f3cbda38 100644 --- a/app/vectors/gimppath-export.c +++ b/app/vectors/gimppath-export.c @@ -173,7 +173,7 @@ static void gimp_path_export_image_size (GimpImage *image, GString *str) { - GimpUnit unit; + GimpUnit *unit; const gchar *abbrev; gchar wbuf[G_ASCII_DTOSTR_BUF_SIZE]; gchar hbuf[G_ASCII_DTOSTR_BUF_SIZE]; @@ -188,14 +188,14 @@ gimp_path_export_image_size (GimpImage *image, /* FIXME: should probably use the display unit here */ unit = gimp_image_get_unit (image); - switch (unit) + switch (gimp_unit_get_id (unit)) { case GIMP_UNIT_INCH: abbrev = "in"; break; case GIMP_UNIT_MM: abbrev = "mm"; break; case GIMP_UNIT_POINT: abbrev = "pt"; break; case GIMP_UNIT_PICA: abbrev = "pc"; break; default: abbrev = "cm"; - unit = GIMP_UNIT_MM; + unit = gimp_unit_mm (); w /= 10.0; h /= 10.0; break; diff --git a/app/vectors/gimppath-import.c b/app/vectors/gimppath-import.c index 2331c57133..9f123f8a99 100644 --- a/app/vectors/gimppath-import.c +++ b/app/vectors/gimppath-import.c @@ -1063,7 +1063,7 @@ parse_svg_length (const gchar *value, gdouble resolution, gdouble *length) { - GimpUnit unit = GIMP_UNIT_PIXEL; + GimpUnit *unit = gimp_unit_pixel (); gdouble len; gchar *ptr; @@ -1081,8 +1081,8 @@ parse_svg_length (const gchar *value, switch (ptr[1]) { case 'x': break; - case 't': unit = GIMP_UNIT_POINT; break; - case 'c': unit = GIMP_UNIT_PICA; break; + case 't': unit = gimp_unit_point (); break; + case 'c': unit = gimp_unit_pica (); break; default: return FALSE; } @@ -1091,7 +1091,7 @@ parse_svg_length (const gchar *value, case 'c': if (ptr[1] == 'm') - len *= 10.0, unit = GIMP_UNIT_MM; + len *= 10.0, unit = gimp_unit_mm (); else return FALSE; ptr += 2; @@ -1099,7 +1099,7 @@ parse_svg_length (const gchar *value, case 'm': if (ptr[1] == 'm') - unit = GIMP_UNIT_MM; + unit = gimp_unit_mm (); else return FALSE; ptr += 2; @@ -1107,14 +1107,14 @@ parse_svg_length (const gchar *value, case 'i': if (ptr[1] == 'n') - unit = GIMP_UNIT_INCH; + unit = gimp_unit_inch (); else return FALSE; ptr += 2; break; case '%': - unit = GIMP_UNIT_PERCENT; + unit = gimp_unit_percent (); ptr += 1; break; @@ -1128,7 +1128,7 @@ parse_svg_length (const gchar *value, if (*ptr) return FALSE; - switch (unit) + switch (gimp_unit_get_id (unit)) { case GIMP_UNIT_PERCENT: *length = len * reference / 100.0; diff --git a/app/widgets/gimpimagepropview.c b/app/widgets/gimpimagepropview.c index faaa446041..3e3fb6e7cb 100644 --- a/app/widgets/gimpimagepropview.c +++ b/app/widgets/gimpimagepropview.c @@ -424,7 +424,7 @@ gimp_image_prop_view_update (GimpImagePropView *view) GimpColorProfile *profile; GimpImageBaseType type; GimpPrecision precision; - GimpUnit unit; + GimpUnit *unit; gdouble unit_factor; const gchar *desc; gchar format_buf[32]; @@ -463,7 +463,7 @@ gimp_image_prop_view_update (GimpImagePropView *view) g_snprintf (buf, sizeof (buf), _("%g × %g %s"), xres / unit_factor, yres / unit_factor, - unit == GIMP_UNIT_INCH ? _("ppi") : format_buf); + unit == gimp_unit_inch () ? _("ppi") : format_buf); gtk_label_set_text (GTK_LABEL (view->resolution_label), buf); /* color space */ diff --git a/app/widgets/gimpsizebox.c b/app/widgets/gimpsizebox.c index 8efe457ce5..406abee0c7 100644 --- a/app/widgets/gimpsizebox.c +++ b/app/widgets/gimpsizebox.c @@ -115,7 +115,7 @@ gimp_size_box_class_init (GimpSizeBoxClass *klass) g_object_class_install_property (object_class, PROP_UNIT, gimp_param_spec_unit ("unit", NULL, NULL, TRUE, TRUE, - GIMP_UNIT_PIXEL, + gimp_unit_pixel (), GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT)); g_object_class_install_property (object_class, PROP_XRESOLUTION, @@ -138,7 +138,7 @@ gimp_size_box_class_init (GimpSizeBoxClass *klass) gimp_param_spec_unit ("resolution-unit", NULL, NULL, FALSE, FALSE, - GIMP_UNIT_INCH, + gimp_unit_inch (), GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT)); g_object_class_install_property (object_class, PROP_KEEP_ASPECT, @@ -330,7 +330,7 @@ gimp_size_box_set_property (GObject *object, break; case PROP_UNIT: - box->unit = g_value_get_int (value); + box->unit = g_value_get_object (value); break; case PROP_XRESOLUTION: @@ -350,7 +350,7 @@ gimp_size_box_set_property (GObject *object, break; case PROP_RESOLUTION_UNIT: - box->resolution_unit = g_value_get_int (value); + box->resolution_unit = g_value_get_object (value); break; case PROP_KEEP_ASPECT: @@ -389,7 +389,7 @@ gimp_size_box_get_property (GObject *object, break; case PROP_UNIT: - g_value_set_int (value, box->unit); + g_value_set_object (value, box->unit); break; case PROP_XRESOLUTION: @@ -401,7 +401,7 @@ gimp_size_box_get_property (GObject *object, break; case PROP_RESOLUTION_UNIT: - g_value_set_int (value, box->resolution_unit); + g_value_set_object (value, box->resolution_unit); break; case PROP_KEEP_ASPECT: diff --git a/app/widgets/gimpsizebox.h b/app/widgets/gimpsizebox.h index 4c76e88d4b..88b6b57fd9 100644 --- a/app/widgets/gimpsizebox.h +++ b/app/widgets/gimpsizebox.h @@ -42,10 +42,10 @@ struct _GimpSizeBox gint width; gint height; - GimpUnit unit; + GimpUnit *unit; gdouble xresolution; gdouble yresolution; - GimpUnit resolution_unit; + GimpUnit *resolution_unit; gboolean edit_resolution; }; diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c index 9f7f4e9bb5..3405d7536f 100644 --- a/app/widgets/gimptextstyleeditor.c +++ b/app/widgets/gimptextstyleeditor.c @@ -569,7 +569,7 @@ gimp_text_style_editor_list_tags (GimpTextStyleEditor *editor, gdouble points; points = gimp_units_to_points (pixels, - GIMP_UNIT_PIXEL, + gimp_unit_pixel (), editor->resolution_y); tag = gimp_text_buffer_get_size_tag (editor->buffer, PANGO_SCALE * points); @@ -857,7 +857,7 @@ gimp_text_style_editor_size_changed (GimpSizeEntry *entry, gdouble points; points = gimp_units_to_points (gimp_size_entry_get_refval (entry, 0), - GIMP_UNIT_PIXEL, editor->resolution_y); + gimp_unit_pixel (), editor->resolution_y); if (gtk_text_buffer_get_has_selection (buffer)) { @@ -891,7 +891,7 @@ gimp_text_style_editor_set_size (GimpTextStyleEditor *editor, editor); pixels = gimp_units_to_pixels ((gdouble) size / PANGO_SCALE, - GIMP_UNIT_POINT, + gimp_unit_point (), editor->resolution_y); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (editor->size_entry), 0, pixels); diff --git a/app/widgets/gimptoolbox-dnd.c b/app/widgets/gimptoolbox-dnd.c index 91c0155de8..9a1056d282 100644 --- a/app/widgets/gimptoolbox-dnd.c +++ b/app/widgets/gimptoolbox-dnd.c @@ -199,7 +199,7 @@ gimp_toolbox_drop_drawable (GtkWidget *widget, new_image = gimp_image_new_from_drawable (context->gimp, GIMP_DRAWABLE (viewable)); - gimp_create_display (context->gimp, new_image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (context->gimp, new_image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (new_image); } @@ -234,7 +234,7 @@ gimp_toolbox_drop_buffer (GtkWidget *widget, image = gimp_image_new_from_buffer (context->gimp, GIMP_BUFFER (viewable)); - gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (image->gimp, image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (image); } @@ -255,7 +255,7 @@ gimp_toolbox_drop_component (GtkWidget *widget, new_image = gimp_image_new_from_component (context->gimp, image, component); - gimp_create_display (new_image->gimp, new_image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (new_image->gimp, new_image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (new_image); } @@ -275,7 +275,7 @@ gimp_toolbox_drop_pixbuf (GtkWidget *widget, new_image = gimp_image_new_from_pixbuf (context->gimp, pixbuf, _("Dropped Buffer")); - gimp_create_display (new_image->gimp, new_image, GIMP_UNIT_PIXEL, 1.0, + gimp_create_display (new_image->gimp, new_image, gimp_unit_pixel (), 1.0, G_OBJECT (gimp_widget_get_monitor (widget))); g_object_unref (new_image); } diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c index aa59f501a9..7870540e55 100644 --- a/app/xcf/xcf-load.c +++ b/app/xcf/xcf-load.c @@ -63,6 +63,7 @@ #include "core/gimpselection.h" #include "core/gimpsymmetry.h" #include "core/gimptemplate.h" +#include "core/gimpunit.h" #include "operations/layer-modes/gimp-layer-modes.h" @@ -1418,23 +1419,22 @@ xcf_load_image_props (XcfInfo *info, case PROP_UNIT: { - guint32 unit; + guint32 unit_index; - xcf_read_int32 (info, &unit, 1); + xcf_read_int32 (info, &unit_index, 1); - GIMP_LOG (XCF, "prop unit=%d", unit); + GIMP_LOG (XCF, "prop unit=%d", unit_index); - if ((unit <= GIMP_UNIT_PIXEL) || - (unit >= gimp_unit_get_number_of_built_in_units ())) + if (unit_index <= GIMP_UNIT_PIXEL || unit_index >= GIMP_UNIT_END) { gimp_message_literal (info->gimp, G_OBJECT (info->progress), GIMP_MESSAGE_WARNING, "Warning, unit out of range in XCF file, " "falling back to inches"); - unit = GIMP_UNIT_INCH; + unit_index = GIMP_UNIT_INCH; } - gimp_image_set_unit (image, unit); + gimp_image_set_unit (image, gimp_unit_get_by_id (unit_index)); } break; @@ -1455,12 +1455,12 @@ xcf_load_image_props (XcfInfo *info, case PROP_USER_UNIT: { - gchar *unit_strings[5]; - float factor; - guint32 digits; - GimpUnit unit; - gint num_units; - gint i; + gchar *unit_strings[5]; + float factor; + guint32 digits; + GimpUnit *unit; + GList *iter; + gint i; xcf_read_float (info, &factor, 1); xcf_read_int32 (info, &digits, 1); @@ -1470,11 +1470,9 @@ xcf_load_image_props (XcfInfo *info, if (unit_strings[i] == NULL) unit_strings[i] = g_strdup (""); - num_units = gimp_unit_get_number_of_units (); - - for (unit = gimp_unit_get_number_of_built_in_units (); - unit < num_units; unit++) + for (iter = info->gimp->user_units; iter; iter = iter->next) { + unit = iter->data; /* if the factor and the identifier match some unit * in unitrc, use the unitrc unit */ @@ -1486,15 +1484,18 @@ xcf_load_image_props (XcfInfo *info, } } - /* no match */ - if (unit == num_units) - unit = gimp_unit_new (unit_strings[0], - factor, - digits, - unit_strings[1], - unit_strings[2], - unit_strings[3], - unit_strings[4]); + if (iter == NULL) + /* No match. Create a temporary unit set with deletion + * flag. + */ + unit = _gimp_unit_new (info->gimp, + unit_strings[0], + (gdouble) factor, + digits, + unit_strings[1], + unit_strings[2], + unit_strings[3], + unit_strings[4]); gimp_image_set_unit (image, unit); diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c index ec77dfad0f..8a252eaec7 100644 --- a/app/xcf/xcf-save.c +++ b/app/xcf/xcf-save.c @@ -478,7 +478,7 @@ xcf_save_image_props (XcfInfo *info, GimpParasite *meta_parasite = NULL; GList *symmetry_parasites = NULL; GList *iter; - GimpUnit unit = gimp_image_get_unit (image); + GimpUnit *unit = gimp_image_get_unit (image); gdouble xres; gdouble yres; @@ -519,7 +519,7 @@ xcf_save_image_props (XcfInfo *info, xcf_check_error (xcf_save_prop (info, image, PROP_TATTOO, error, gimp_image_get_tattoo_state (image)), ;); - if (unit < gimp_unit_get_number_of_built_in_units ()) + if (gimp_unit_is_built_in (unit)) xcf_check_error (xcf_save_prop (info, image, PROP_UNIT, error, unit), ;); if (gimp_container_get_n_children (gimp_image_get_paths (image)) > 0 && @@ -531,7 +531,7 @@ xcf_save_image_props (XcfInfo *info, xcf_check_error (xcf_save_prop (info, image, PROP_VECTORS, error), ;); } - if (unit >= gimp_unit_get_number_of_built_in_units ()) + if (! gimp_unit_is_built_in (unit)) xcf_check_error (xcf_save_prop (info, image, PROP_USER_UNIT, error, unit), ;); if (gimp_image_get_grid (image)) @@ -1539,14 +1539,15 @@ xcf_save_prop (XcfInfo *info, case PROP_UNIT: { - guint32 unit = va_arg (args, guint32); + GimpUnit *unit = va_arg (args, GimpUnit *); + guint32 unit_index = gimp_unit_get_id (unit); size = 4; xcf_write_prop_type_check_error (info, prop_type, va_end (args)); xcf_write_int32_check_error (info, &size, 1, va_end (args)); - xcf_write_int32_check_error (info, &unit, 1, va_end (args)); + xcf_write_int32_check_error (info, &unit_index, 1, va_end (args)); } break; @@ -1581,7 +1582,7 @@ xcf_save_prop (XcfInfo *info, case PROP_USER_UNIT: { - GimpUnit unit = va_arg (args, guint32); + GimpUnit *unit = va_arg (args, GimpUnit *); const gchar *unit_strings[5]; gfloat factor; guint32 digits; diff --git a/libgimp/gimp.c b/libgimp/gimp.c index 5df8b19f0f..914224a292 100644 --- a/libgimp/gimp.c +++ b/libgimp/gimp.c @@ -94,7 +94,6 @@ #include "gimpgpparams.h" #include "gimppdb-private.h" #include "gimpplugin-private.h" -#include "gimpunitcache.h" #include "libgimp-intl.h" @@ -462,21 +461,11 @@ gimp_main (GType plug_in_type, /* initialize units */ { - GimpUnitVtable vtable; + GimpUnitVtable vtable = { 0 }; - vtable.unit_get_number_of_units = _gimp_unit_cache_get_number_of_units; - vtable.unit_get_number_of_built_in_units = - _gimp_unit_cache_get_number_of_built_in_units; - vtable.unit_new = _gimp_unit_cache_new; - vtable.unit_get_deletion_flag = _gimp_unit_cache_get_deletion_flag; - vtable.unit_set_deletion_flag = _gimp_unit_cache_set_deletion_flag; - vtable.unit_get_factor = _gimp_unit_cache_get_factor; - vtable.unit_get_digits = _gimp_unit_cache_get_digits; - vtable.unit_get_identifier = _gimp_unit_cache_get_identifier; - vtable.unit_get_symbol = _gimp_unit_cache_get_symbol; - vtable.unit_get_abbreviation = _gimp_unit_cache_get_abbreviation; - vtable.unit_get_singular = _gimp_unit_cache_get_singular; - vtable.unit_get_plural = _gimp_unit_cache_get_plural; + vtable.get_deletion_flag = _gimp_unit_get_deletion_flag; + vtable.set_deletion_flag = _gimp_unit_set_deletion_flag; + vtable.get_data = _gimp_unit_get_data; gimp_base_init (&vtable); } @@ -949,6 +938,8 @@ gimp_close (void) if (_gimp_get_debug_flags () & GIMP_DEBUG_QUIT) _gimp_debug_stop (); + gimp_base_exit (); + _gimp_plug_in_quit (PLUG_IN); if (PDB) diff --git a/libgimp/gimp.def b/libgimp/gimp.def index 1e0db11d38..b779612ab7 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -1016,6 +1016,7 @@ EXPORTS gimp_thumbnail_procedure_new gimp_tile_height gimp_tile_width + gimp_unit_new gimp_user_time gimp_vector_load_procedure_extract_dimensions gimp_vector_load_procedure_get_type diff --git a/libgimp/gimp_pdb_headers.h b/libgimp/gimp_pdb_headers.h index aceaf4f71c..350a5afb34 100644 --- a/libgimp/gimp_pdb_headers.h +++ b/libgimp/gimp_pdb_headers.h @@ -79,5 +79,6 @@ #include #include #include +#include #endif /* __GIMP_PDB_HEADERS_H__ */ diff --git a/libgimp/gimpcontext_pdb.c b/libgimp/gimpcontext_pdb.c index 851e040c56..8998a341f6 100644 --- a/libgimp/gimpcontext_pdb.c +++ b/libgimp/gimpcontext_pdb.c @@ -767,12 +767,12 @@ gimp_context_set_line_width (gdouble line_width) * * Since: 2.10 **/ -GimpUnit +GimpUnit * gimp_context_get_line_width_unit (void) { GimpValueArray *args; GimpValueArray *return_vals; - GimpUnit line_width_unit = GIMP_UNIT_PIXEL; + GimpUnit *line_width_unit = NULL; args = gimp_value_array_new_from_types (NULL, G_TYPE_NONE); @@ -783,7 +783,7 @@ gimp_context_get_line_width_unit (void) gimp_value_array_unref (args); if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - line_width_unit = GIMP_VALUES_GET_INT (return_vals, 1); + line_width_unit = GIMP_VALUES_GET_UNIT (return_vals, 1); gimp_value_array_unref (return_vals); @@ -807,7 +807,7 @@ gimp_context_get_line_width_unit (void) * Since: 2.10 **/ gboolean -gimp_context_set_line_width_unit (GimpUnit line_width_unit) +gimp_context_set_line_width_unit (GimpUnit *line_width_unit) { GimpValueArray *args; GimpValueArray *return_vals; diff --git a/libgimp/gimpcontext_pdb.h b/libgimp/gimpcontext_pdb.h index 83c57571b7..c7420d9a06 100644 --- a/libgimp/gimpcontext_pdb.h +++ b/libgimp/gimpcontext_pdb.h @@ -52,8 +52,8 @@ GimpLayerMode gimp_context_get_paint_mode (void) gboolean gimp_context_set_paint_mode (GimpLayerMode paint_mode); gdouble gimp_context_get_line_width (void); gboolean gimp_context_set_line_width (gdouble line_width); -GimpUnit gimp_context_get_line_width_unit (void); -gboolean gimp_context_set_line_width_unit (GimpUnit line_width_unit); +GimpUnit* gimp_context_get_line_width_unit (void); +gboolean gimp_context_set_line_width_unit (GimpUnit *line_width_unit); GimpCapStyle gimp_context_get_line_cap_style (void); gboolean gimp_context_set_line_cap_style (GimpCapStyle cap_style); GimpJoinStyle gimp_context_get_line_join_style (void); diff --git a/libgimp/gimpgimprc_pdb.c b/libgimp/gimpgimprc_pdb.c index 68de0f4732..3b7e9ac88e 100644 --- a/libgimp/gimpgimprc_pdb.c +++ b/libgimp/gimpgimprc_pdb.c @@ -157,18 +157,18 @@ gimp_get_default_comment (void) * * Get the default unit (taken from the user's locale). * - * Returns the default unit's integer ID. + * Returns the default unit. * * Returns: (transfer none): Default unit. * * Since: 2.4 **/ -GimpUnit +GimpUnit * gimp_get_default_unit (void) { GimpValueArray *args; GimpValueArray *return_vals; - GimpUnit unit_id = GIMP_UNIT_PIXEL; + GimpUnit *unit = NULL; args = gimp_value_array_new_from_types (NULL, G_TYPE_NONE); @@ -179,11 +179,11 @@ gimp_get_default_unit (void) gimp_value_array_unref (args); if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - unit_id = GIMP_VALUES_GET_INT (return_vals, 1); + unit = GIMP_VALUES_GET_UNIT (return_vals, 1); gimp_value_array_unref (return_vals); - return unit_id; + return unit; } /** diff --git a/libgimp/gimpgimprc_pdb.h b/libgimp/gimpgimprc_pdb.h index 42d500a995..5d75a48515 100644 --- a/libgimp/gimpgimprc_pdb.h +++ b/libgimp/gimpgimprc_pdb.h @@ -36,7 +36,7 @@ gchar* gimp_gimprc_query (const gchar *token); gboolean gimp_gimprc_set (const gchar *token, const gchar *value); gchar* gimp_get_default_comment (void); -GimpUnit gimp_get_default_unit (void); +GimpUnit* gimp_get_default_unit (void); gboolean gimp_get_monitor_resolution (gdouble *xres, gdouble *yres); G_GNUC_INTERNAL gchar* _gimp_get_color_configuration (void); diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c index 662cf43d18..0b200ee09e 100644 --- a/libgimp/gimpgpparams-body.c +++ b/libgimp/gimpgpparams-body.c @@ -109,7 +109,7 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def) return gimp_param_spec_unit (name, nick, blurb, param_def->meta.m_unit.allow_pixels, param_def->meta.m_unit.allow_percent, - param_def->meta.m_unit.default_val, + gimp_unit_get_by_id (param_def->meta.m_unit.default_val), flags); break; @@ -349,14 +349,13 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec, } else if (pspec_type == GIMP_TYPE_PARAM_UNIT) { - GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec); GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec); param_def->param_def_type = GP_PARAM_DEF_TYPE_UNIT; - param_def->meta.m_unit.allow_pixels = (ispec->minimum < GIMP_UNIT_INCH); + param_def->meta.m_unit.allow_pixels = uspec->allow_pixel; param_def->meta.m_unit.allow_percent = uspec->allow_percent; - param_def->meta.m_unit.default_val = ispec->default_value; + param_def->meta.m_unit.default_val = gimp_unit_get_id (uspec->default_value); } else if (G_IS_PARAM_SPEC_ENUM (pspec)) { @@ -643,6 +642,13 @@ get_resource_id (GObject *resource) #endif } +static GimpUnit * +get_unit_by_id (gpointer gimp, + gint id) +{ + return gimp_unit_get_by_id (id); +} + /* Deserialize a gp_param (from the wire) to an instance of object or * primitive type. @@ -682,8 +688,7 @@ gimp_gp_param_to_value (gpointer gimp, g_value_init (value, type); - if (type == G_TYPE_INT || - type == GIMP_TYPE_UNIT) + if (type == G_TYPE_INT) { g_value_set_int (value, param->data.d_int); } @@ -915,6 +920,10 @@ gimp_gp_param_to_value (gpointer gimp, { g_value_set_object (value, get_resource_by_id (param->data.d_int)); } + else if (GIMP_VALUE_HOLDS_UNIT (value)) + { + g_value_set_object (value, get_unit_by_id (gimp, param->data.d_int)); + } else if (G_VALUE_HOLDS_PARAM (value)) { GParamSpec *pspec = @@ -1032,8 +1041,7 @@ gimp_value_to_gp_param (const GValue *value, else param->type_name = (gchar *) g_type_name (type); - if (type == G_TYPE_INT || - type == GIMP_TYPE_UNIT) + if (type == G_TYPE_INT) { param->param_type = GP_PARAM_TYPE_INT; @@ -1343,6 +1351,14 @@ gimp_value_to_gp_param (const GValue *value, param->data.d_int = resource ? get_resource_id (resource) : -1; } + else if (GIMP_VALUE_HOLDS_UNIT (value)) + { + GimpUnit *unit = g_value_get_object (value); + + param->param_type = GP_PARAM_TYPE_INT; + + param->data.d_int = unit ? gimp_unit_get_id (unit) : -1; + } else if (G_VALUE_HOLDS_PARAM (value)) { param->param_type = GP_PARAM_TYPE_PARAM_DEF; diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c index eacc413f96..ed8a73ad46 100644 --- a/libgimp/gimpimage_pdb.c +++ b/libgimp/gimpimage_pdb.c @@ -2886,12 +2886,12 @@ gimp_image_set_resolution (GimpImage *image, * * Returns: (transfer none): The unit. **/ -GimpUnit +GimpUnit * gimp_image_get_unit (GimpImage *image) { GimpValueArray *args; GimpValueArray *return_vals; - GimpUnit unit = GIMP_UNIT_PIXEL; + GimpUnit *unit = NULL; args = gimp_value_array_new_from_types (NULL, GIMP_TYPE_IMAGE, image, @@ -2903,7 +2903,7 @@ gimp_image_get_unit (GimpImage *image) gimp_value_array_unref (args); if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - unit = GIMP_VALUES_GET_INT (return_vals, 1); + unit = GIMP_VALUES_GET_UNIT (return_vals, 1); gimp_value_array_unref (return_vals); @@ -2927,7 +2927,7 @@ gimp_image_get_unit (GimpImage *image) **/ gboolean gimp_image_set_unit (GimpImage *image, - GimpUnit unit) + GimpUnit *unit) { GimpValueArray *args; GimpValueArray *return_vals; diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h index d23f174c39..0712058566 100644 --- a/libgimp/gimpimage_pdb.h +++ b/libgimp/gimpimage_pdb.h @@ -170,9 +170,9 @@ gboolean gimp_image_get_resolution (GimpImage gboolean gimp_image_set_resolution (GimpImage *image, gdouble xresolution, gdouble yresolution); -GimpUnit gimp_image_get_unit (GimpImage *image); +GimpUnit* gimp_image_get_unit (GimpImage *image); gboolean gimp_image_set_unit (GimpImage *image, - GimpUnit unit); + GimpUnit *unit); guint gimp_image_get_tattoo_state (GimpImage *image); gboolean gimp_image_set_tattoo_state (GimpImage *image, guint tattoo_state); diff --git a/libgimp/gimpimagemetadata.c b/libgimp/gimpimagemetadata.c index b4651076c6..ef37385cb3 100644 --- a/libgimp/gimpimagemetadata.c +++ b/libgimp/gimpimagemetadata.c @@ -221,7 +221,7 @@ gimp_image_metadata_load_finish (GimpImage *image, { gdouble xres; gdouble yres; - GimpUnit unit; + GimpUnit *unit; if (gimp_metadata_get_resolution (metadata, &xres, &yres, &unit)) { diff --git a/libgimp/gimpparamspecs-desc.c b/libgimp/gimpparamspecs-desc.c index b5cfdc5af5..fd7296a6eb 100644 --- a/libgimp/gimpparamspecs-desc.c +++ b/libgimp/gimpparamspecs-desc.c @@ -41,6 +41,17 @@ gimp_param_spec_boolean_desc (GParamSpec *pspec) bspec->default_value ? "TRUE" : "FALSE"); } +static gchar * +gimp_param_spec_unit_desc (GParamSpec *pspec) +{ + GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec); + + return g_strdup_printf ("(default %s%s%s)", + gimp_unit_get_abbreviation (uspec->default_value), + uspec->allow_pixel ? ", pixel allowed": "", + uspec->allow_percent ? ", percent allowed": ""); +} + static gchar * gimp_param_spec_choice_desc (GParamSpec *pspec) { @@ -238,6 +249,7 @@ gimp_param_spec_get_desc (GParamSpec *pspec) if (GIMP_IS_PARAM_SPEC_UNIT (pspec)) { + return gimp_param_spec_unit_desc (pspec); } else if (GIMP_IS_PARAM_SPEC_CHOICE (pspec)) { diff --git a/libgimp/gimpprocedure-params.c b/libgimp/gimpprocedure-params.c index ad6f1bd441..12e561ad50 100644 --- a/libgimp/gimpprocedure-params.c +++ b/libgimp/gimpprocedure-params.c @@ -316,7 +316,7 @@ gimp_procedure_add_unit_argument (GimpProcedure *procedure, const gchar *blurb, gboolean show_pixels, gboolean show_percent, - GimpUnit value, + GimpUnit *value, GParamFlags flags) { _gimp_procedure_add_argument (procedure, @@ -347,7 +347,7 @@ gimp_procedure_add_unit_aux_argument (GimpProcedure *procedure, const gchar *blurb, gboolean show_pixels, gboolean show_percent, - GimpUnit value, + GimpUnit *value, GParamFlags flags) { _gimp_procedure_add_aux_argument (procedure, @@ -378,7 +378,7 @@ gimp_procedure_add_unit_return_value (GimpProcedure *procedure, const gchar *blurb, gboolean show_pixels, gboolean show_percent, - GimpUnit value, + GimpUnit *value, GParamFlags flags) { _gimp_procedure_add_return_value (procedure, diff --git a/libgimp/gimpprocedure-params.h b/libgimp/gimpprocedure-params.h index 042cd6faac..f8c0c42b9d 100644 --- a/libgimp/gimpprocedure-params.h +++ b/libgimp/gimpprocedure-params.h @@ -422,6 +422,15 @@ G_BEGIN_DECLS #define GIMP_VALUES_SET_PATTERN(args, n, value) \ g_value_set_object (gimp_value_array_index (args, n), value) + +/* Unit */ + +#define GIMP_VALUES_GET_UNIT(args, n) \ + g_value_get_object (gimp_value_array_index (args, n)) +#define GIMP_VALUES_SET_UNIT(args, n, value) \ + g_value_set_object (gimp_value_array_index (args, n), value) + + void gimp_procedure_add_boolean_argument (GimpProcedure *procedure, const gchar *name, const gchar *nick, @@ -497,7 +506,7 @@ void gimp_procedure_add_unit_argument (GimpProcedure *procedure const gchar *blurb, gboolean show_pixels, gboolean show_percent, - GimpUnit value, + GimpUnit *value, GParamFlags flags); void gimp_procedure_add_unit_aux_argument (GimpProcedure *procedure, const gchar *name, @@ -505,7 +514,7 @@ void gimp_procedure_add_unit_aux_argument (GimpProcedure *procedure const gchar *blurb, gboolean show_pixels, gboolean show_percent, - GimpUnit value, + GimpUnit *value, GParamFlags flags); void gimp_procedure_add_unit_return_value (GimpProcedure *procedure, const gchar *name, @@ -513,7 +522,7 @@ void gimp_procedure_add_unit_return_value (GimpProcedure *procedure const gchar *blurb, gboolean show_pixels, gboolean show_percent, - GimpUnit value, + GimpUnit *value, GParamFlags flags); void gimp_procedure_add_double_argument (GimpProcedure *procedure, diff --git a/libgimp/gimpresolutionentry-private.c b/libgimp/gimpresolutionentry-private.c index 257951bc17..43b8b62820 100644 --- a/libgimp/gimpresolutionentry-private.c +++ b/libgimp/gimpresolutionentry-private.c @@ -50,7 +50,7 @@ struct _GimpResolutionEntry gint width; gint height; gdouble ppi; - GimpUnit unit; + GimpUnit *unit; gdouble ratio; gboolean keep_ratio; @@ -136,7 +136,7 @@ gimp_resolution_entry_class_init (GimpResolutionEntryClass *klass) _("This unit is used to select the pixel density " "and show dimensions in physical unit"), FALSE, FALSE, - GIMP_UNIT_INCH, + gimp_unit_inch (), GIMP_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_CONSTRUCT); @@ -157,7 +157,7 @@ gimp_resolution_entry_init (GimpResolutionEntry *entry) entry->width = 0; entry->height = 0; entry->ppi = 300.0; - entry->unit = GIMP_UNIT_INCH; + entry->unit = gimp_unit_inch (); entry->keep_ratio = TRUE; gtk_grid_set_row_spacing (GTK_GRID (entry), 2); @@ -267,7 +267,7 @@ gimp_resolution_entry_set_property (GObject *object, gimp_resolution_entry_set_pixel_density (entry, g_value_get_double (value)); break; case PROP_UNIT: - gimp_resolution_entry_set_unit (entry, g_value_get_int (value)); + gimp_resolution_entry_set_unit (entry, g_value_get_object (value)); break; case PROP_KEEP_RATIO: gimp_resolution_entry_set_keep_ratio (entry, g_value_get_boolean (value)); @@ -299,7 +299,7 @@ gimp_resolution_entry_get_property (GObject *object, g_value_set_double (value, entry->ppi); break; case PROP_UNIT: - g_value_set_int (value, entry->unit); + g_value_set_object (value, entry->unit); break; case PROP_KEEP_RATIO: g_value_set_boolean (value, entry->keep_ratio); @@ -326,7 +326,7 @@ gimp_prop_resolution_entry_new (GObject *config, gint width = 0; gint height = 0; gdouble ppi = 300.0; - GimpUnit unit = GIMP_UNIT_INCH; + GimpUnit *unit = gimp_unit_inch (); g_return_val_if_fail (G_IS_OBJECT (config), NULL); g_return_val_if_fail (width_prop != NULL, NULL); @@ -399,7 +399,7 @@ gimp_resolution_entry_new (const gchar *width_label, gint height, const gchar *res_label, gdouble pixel_density, - GimpUnit display_unit) + GimpUnit *display_unit) { GimpResolutionEntry *entry; @@ -516,10 +516,10 @@ gimp_resolution_entry_set_pixel_density (GimpResolutionEntry *entry, void gimp_resolution_entry_set_unit (GimpResolutionEntry *entry, - GimpUnit unit) + GimpUnit *unit) { - g_return_if_fail (unit != GIMP_UNIT_PIXEL); - g_return_if_fail (unit != GIMP_UNIT_PERCENT); + g_return_if_fail (unit != gimp_unit_pixel ()); + g_return_if_fail (unit != gimp_unit_percent ()); if (entry->unit != unit) { @@ -575,7 +575,7 @@ gimp_resolution_entry_get_density (GimpResolutionEntry *entry) return entry->ppi; } -GimpUnit +GimpUnit * gimp_resolution_entry_get_unit (GimpResolutionEntry *entry) { return entry->unit; diff --git a/libgimp/gimpresolutionentry-private.h b/libgimp/gimpresolutionentry-private.h index 737f063cd4..ee3cc4e789 100644 --- a/libgimp/gimpresolutionentry-private.h +++ b/libgimp/gimpresolutionentry-private.h @@ -56,7 +56,7 @@ GtkWidget * gimp_resolution_entry_new (const gchar *w gint height, const gchar *res_label, gdouble pixel_density, - GimpUnit display_unit); + GimpUnit *display_unit); void gimp_resolution_entry_set_width (GimpResolutionEntry *entry, gint width); @@ -65,14 +65,14 @@ void gimp_resolution_entry_set_height (GimpResolutionEntry *e void gimp_resolution_entry_set_pixel_density (GimpResolutionEntry *entry, gdouble ppi); void gimp_resolution_entry_set_unit (GimpResolutionEntry *entry, - GimpUnit unit); + GimpUnit *unit); void gimp_resolution_entry_set_keep_ratio (GimpResolutionEntry *entry, gboolean keep_ratio); gint gimp_resolution_entry_get_width (GimpResolutionEntry *entry); gint gimp_resolution_entry_get_height (GimpResolutionEntry *entry); gdouble gimp_resolution_entry_get_density (GimpResolutionEntry *entry); -GimpUnit gimp_resolution_entry_get_unit (GimpResolutionEntry *entry); +GimpUnit * gimp_resolution_entry_get_unit (GimpResolutionEntry *entry); gboolean gimp_resolution_entry_get_keep_ratio (GimpResolutionEntry *entry); G_END_DECLS diff --git a/libgimp/gimptextlayer.c b/libgimp/gimptextlayer.c index fc6067a5c4..491ecb5913 100644 --- a/libgimp/gimptextlayer.c +++ b/libgimp/gimptextlayer.c @@ -109,7 +109,7 @@ gimp_text_layer_new (GimpImage *image, const gchar *text, GimpFont *font, gdouble size, - GimpUnit unit) + GimpUnit *unit) { return _gimp_text_layer_new (image, text, font, size, unit); } @@ -124,7 +124,7 @@ gimp_text_layer_copy (GimpLayer *layer) gchar *text; GimpFont *font; gdouble size; - GimpUnit unit; + GimpUnit *unit; g_return_val_if_fail (GIMP_IS_TEXT_LAYER (layer), NULL); diff --git a/libgimp/gimptextlayer.h b/libgimp/gimptextlayer.h index 75cc7658dc..cc98979e81 100644 --- a/libgimp/gimptextlayer.h +++ b/libgimp/gimptextlayer.h @@ -44,7 +44,7 @@ GimpTextLayer * gimp_text_layer_new (GimpImage *image, const gchar *text, GimpFont *font, gdouble size, - GimpUnit unit) G_GNUC_WARN_UNUSED_RESULT; + GimpUnit *unit) G_GNUC_WARN_UNUSED_RESULT; G_END_DECLS diff --git a/libgimp/gimptextlayer_pdb.c b/libgimp/gimptextlayer_pdb.c index 3d50b33b0b..6594a700f3 100644 --- a/libgimp/gimptextlayer_pdb.c +++ b/libgimp/gimptextlayer_pdb.c @@ -62,7 +62,7 @@ _gimp_text_layer_new (GimpImage *image, const gchar *text, GimpFont *font, gdouble size, - GimpUnit unit) + GimpUnit *unit) { GimpValueArray *args; GimpValueArray *return_vals; @@ -339,8 +339,8 @@ gimp_text_layer_set_font (GimpTextLayer *layer, * Since: 2.6 **/ gdouble -gimp_text_layer_get_font_size (GimpTextLayer *layer, - GimpUnit *unit) +gimp_text_layer_get_font_size (GimpTextLayer *layer, + GimpUnit **unit) { GimpValueArray *args; GimpValueArray *return_vals; @@ -358,7 +358,7 @@ gimp_text_layer_get_font_size (GimpTextLayer *layer, if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) { font_size = GIMP_VALUES_GET_DOUBLE (return_vals, 1); - *unit = GIMP_VALUES_GET_INT (return_vals, 2); + *unit = GIMP_VALUES_GET_UNIT (return_vals, 2); } gimp_value_array_unref (return_vals); @@ -384,7 +384,7 @@ gimp_text_layer_get_font_size (GimpTextLayer *layer, gboolean gimp_text_layer_set_font_size (GimpTextLayer *layer, gdouble font_size, - GimpUnit unit) + GimpUnit *unit) { GimpValueArray *args; GimpValueArray *return_vals; diff --git a/libgimp/gimptextlayer_pdb.h b/libgimp/gimptextlayer_pdb.h index 20402a7aba..657e943d16 100644 --- a/libgimp/gimptextlayer_pdb.h +++ b/libgimp/gimptextlayer_pdb.h @@ -32,58 +32,58 @@ G_BEGIN_DECLS /* For information look into the C source or the html documentation */ -G_GNUC_INTERNAL GimpTextLayer* _gimp_text_layer_new (GimpImage *image, - const gchar *text, - GimpFont *font, - gdouble size, - GimpUnit unit); -gchar* gimp_text_layer_get_text (GimpTextLayer *layer); -gboolean gimp_text_layer_set_text (GimpTextLayer *layer, - const gchar *text); -gchar* gimp_text_layer_get_markup (GimpTextLayer *layer); -gboolean gimp_text_layer_set_markup (GimpTextLayer *layer, - const gchar *markup); -GimpFont* gimp_text_layer_get_font (GimpTextLayer *layer); -gboolean gimp_text_layer_set_font (GimpTextLayer *layer, - GimpFont *font); -gdouble gimp_text_layer_get_font_size (GimpTextLayer *layer, - GimpUnit *unit); -gboolean gimp_text_layer_set_font_size (GimpTextLayer *layer, - gdouble font_size, - GimpUnit unit); -gboolean gimp_text_layer_get_antialias (GimpTextLayer *layer); -gboolean gimp_text_layer_set_antialias (GimpTextLayer *layer, - gboolean antialias); -GimpTextHintStyle gimp_text_layer_get_hint_style (GimpTextLayer *layer); -gboolean gimp_text_layer_set_hint_style (GimpTextLayer *layer, - GimpTextHintStyle style); -gboolean gimp_text_layer_get_kerning (GimpTextLayer *layer); -gboolean gimp_text_layer_set_kerning (GimpTextLayer *layer, - gboolean kerning); -gchar* gimp_text_layer_get_language (GimpTextLayer *layer); -gboolean gimp_text_layer_set_language (GimpTextLayer *layer, - const gchar *language); -GimpTextDirection gimp_text_layer_get_base_direction (GimpTextLayer *layer); -gboolean gimp_text_layer_set_base_direction (GimpTextLayer *layer, - GimpTextDirection direction); -GimpTextJustification gimp_text_layer_get_justification (GimpTextLayer *layer); -gboolean gimp_text_layer_set_justification (GimpTextLayer *layer, - GimpTextJustification justify); -GeglColor* gimp_text_layer_get_color (GimpTextLayer *layer); -gboolean gimp_text_layer_set_color (GimpTextLayer *layer, - GeglColor *color); -gdouble gimp_text_layer_get_indent (GimpTextLayer *layer); -gboolean gimp_text_layer_set_indent (GimpTextLayer *layer, - gdouble indent); -gdouble gimp_text_layer_get_line_spacing (GimpTextLayer *layer); -gboolean gimp_text_layer_set_line_spacing (GimpTextLayer *layer, - gdouble line_spacing); -gdouble gimp_text_layer_get_letter_spacing (GimpTextLayer *layer); -gboolean gimp_text_layer_set_letter_spacing (GimpTextLayer *layer, - gdouble letter_spacing); -gboolean gimp_text_layer_resize (GimpTextLayer *layer, - gdouble width, - gdouble height); +G_GNUC_INTERNAL GimpTextLayer* _gimp_text_layer_new (GimpImage *image, + const gchar *text, + GimpFont *font, + gdouble size, + GimpUnit *unit); +gchar* gimp_text_layer_get_text (GimpTextLayer *layer); +gboolean gimp_text_layer_set_text (GimpTextLayer *layer, + const gchar *text); +gchar* gimp_text_layer_get_markup (GimpTextLayer *layer); +gboolean gimp_text_layer_set_markup (GimpTextLayer *layer, + const gchar *markup); +GimpFont* gimp_text_layer_get_font (GimpTextLayer *layer); +gboolean gimp_text_layer_set_font (GimpTextLayer *layer, + GimpFont *font); +gdouble gimp_text_layer_get_font_size (GimpTextLayer *layer, + GimpUnit **unit); +gboolean gimp_text_layer_set_font_size (GimpTextLayer *layer, + gdouble font_size, + GimpUnit *unit); +gboolean gimp_text_layer_get_antialias (GimpTextLayer *layer); +gboolean gimp_text_layer_set_antialias (GimpTextLayer *layer, + gboolean antialias); +GimpTextHintStyle gimp_text_layer_get_hint_style (GimpTextLayer *layer); +gboolean gimp_text_layer_set_hint_style (GimpTextLayer *layer, + GimpTextHintStyle style); +gboolean gimp_text_layer_get_kerning (GimpTextLayer *layer); +gboolean gimp_text_layer_set_kerning (GimpTextLayer *layer, + gboolean kerning); +gchar* gimp_text_layer_get_language (GimpTextLayer *layer); +gboolean gimp_text_layer_set_language (GimpTextLayer *layer, + const gchar *language); +GimpTextDirection gimp_text_layer_get_base_direction (GimpTextLayer *layer); +gboolean gimp_text_layer_set_base_direction (GimpTextLayer *layer, + GimpTextDirection direction); +GimpTextJustification gimp_text_layer_get_justification (GimpTextLayer *layer); +gboolean gimp_text_layer_set_justification (GimpTextLayer *layer, + GimpTextJustification justify); +GeglColor* gimp_text_layer_get_color (GimpTextLayer *layer); +gboolean gimp_text_layer_set_color (GimpTextLayer *layer, + GeglColor *color); +gdouble gimp_text_layer_get_indent (GimpTextLayer *layer); +gboolean gimp_text_layer_set_indent (GimpTextLayer *layer, + gdouble indent); +gdouble gimp_text_layer_get_line_spacing (GimpTextLayer *layer); +gboolean gimp_text_layer_set_line_spacing (GimpTextLayer *layer, + gdouble line_spacing); +gdouble gimp_text_layer_get_letter_spacing (GimpTextLayer *layer); +gboolean gimp_text_layer_set_letter_spacing (GimpTextLayer *layer, + gdouble letter_spacing); +gboolean gimp_text_layer_resize (GimpTextLayer *layer, + gdouble width, + gdouble height); G_END_DECLS diff --git a/libgimp/gimpunit_pdb.c b/libgimp/gimpunit_pdb.c index 7b135ca92d..0552867d90 100644 --- a/libgimp/gimpunit_pdb.c +++ b/libgimp/gimpunit_pdb.c @@ -25,74 +25,20 @@ #include "stamp-pdbgen.h" #include "gimp.h" -#include "gimpunit_pdb.h" + /** - * _gimp_unit_get_number_of_units: + * SECTION: gimpunit + * @title: gimpunit + * @short_description: Operations on units. * - * Returns the number of units. - * - * This procedure returns the number of defined units. - * - * Returns: The number of units. + * Provides operations on units, a collection of predefined units and + * functions to create new units. **/ -gint -_gimp_unit_get_number_of_units (void) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gint num_units = GIMP_UNIT_END; - args = gimp_value_array_new_from_types (NULL, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-unit-get-number-of-units", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - num_units = GIMP_VALUES_GET_INT (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return num_units; -} /** - * _gimp_unit_get_number_of_built_in_units: - * - * Returns the number of built-in units. - * - * This procedure returns the number of defined units built-in to GIMP. - * - * Returns: The number of built-in units. - **/ -gint -_gimp_unit_get_number_of_built_in_units (void) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gint num_units = GIMP_UNIT_END; - - args = gimp_value_array_new_from_types (NULL, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-unit-get-number-of-built-in-units", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - num_units = GIMP_VALUES_GET_INT (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return num_units; -} - -/** - * _gimp_unit_new: + * gimp_unit_new: * @identifier: The new unit's identifier. * @factor: The new unit's factor. * @digits: The new unit's digits. @@ -101,27 +47,27 @@ _gimp_unit_get_number_of_built_in_units (void) * @singular: The new unit's singular form. * @plural: The new unit's plural form. * - * Creates a new unit and returns it's integer ID. + * Creates a new unit. * - * This procedure creates a new unit and returns it's integer ID. Note - * that the new unit will have it's deletion flag set to TRUE, so you - * will have to set it to FALSE with gimp_unit_set_deletion_flag() to - * make it persistent. + * This procedure creates a new unit and returns it. Note that the new + * unit will have it's deletion flag set to TRUE, so you will have to + * set it to FALSE with gimp_unit_set_deletion_flag() to make it + * persistent. * - * Returns: (transfer none): The new unit's ID. + * Returns: (transfer none): The new unit. **/ -GimpUnit -_gimp_unit_new (const gchar *identifier, - gdouble factor, - gint digits, - const gchar *symbol, - const gchar *abbreviation, - const gchar *singular, - const gchar *plural) +GimpUnit * +gimp_unit_new (const gchar *identifier, + gdouble factor, + gint digits, + const gchar *symbol, + const gchar *abbreviation, + const gchar *singular, + const gchar *plural) { GimpValueArray *args; GimpValueArray *return_vals; - GimpUnit unit_id = GIMP_UNIT_INCH; + GimpUnit *unit = NULL; args = gimp_value_array_new_from_types (NULL, G_TYPE_STRING, identifier, @@ -139,16 +85,74 @@ _gimp_unit_new (const gchar *identifier, gimp_value_array_unref (args); if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - unit_id = GIMP_VALUES_GET_INT (return_vals, 1); + unit = GIMP_VALUES_GET_UNIT (return_vals, 1); gimp_value_array_unref (return_vals); - return unit_id; + return unit; +} + +/** + * _gimp_unit_get_data: + * @unit_id: The unit's integer ID. + * @factor: (out): The unit's factor. + * @digits: (out): The unit's number of digits. + * @symbol: (out) (transfer full): The unit's symbol. + * @abbreviation: (out) (transfer full): The unit's abbreviation. + * @singular: (out) (transfer full): The unit's singular form. + * @plural: (out) (transfer full): The unit's plural form. + * + * Returns the various data pertaining to a given unit ID. + * + * This procedure returns all properties making up an unit. It is only + * meant for internal usage to query non built-in units and it is a + * programming error to use it directly, in particular for any of the + * built-in units. + * + * Returns: (transfer full): The unit's textual identifier. + * The returned value must be freed with g_free(). + **/ +gchar * +_gimp_unit_get_data (gint unit_id, + gdouble *factor, + gint *digits, + gchar **symbol, + gchar **abbreviation, + gchar **singular, + gchar **plural) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + gchar *identifier = NULL; + + args = gimp_value_array_new_from_types (NULL, + G_TYPE_INT, unit_id, + G_TYPE_NONE); + + return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-unit-get-data", + args); + gimp_value_array_unref (args); + + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + { + identifier = GIMP_VALUES_DUP_STRING (return_vals, 1); + *factor = GIMP_VALUES_GET_DOUBLE (return_vals, 2); + *digits = GIMP_VALUES_GET_INT (return_vals, 3); + *symbol = GIMP_VALUES_DUP_STRING (return_vals, 4); + *abbreviation = GIMP_VALUES_DUP_STRING (return_vals, 5); + *singular = GIMP_VALUES_DUP_STRING (return_vals, 6); + *plural = GIMP_VALUES_DUP_STRING (return_vals, 7); + } + + gimp_value_array_unref (return_vals); + + return identifier; } /** * _gimp_unit_get_deletion_flag: - * @unit_id: The unit's integer ID. + * @unit: The unit. * * Returns the deletion flag of the unit. * @@ -159,14 +163,14 @@ _gimp_unit_new (const gchar *identifier, * Returns: The unit's deletion flag. **/ gboolean -_gimp_unit_get_deletion_flag (GimpUnit unit_id) +_gimp_unit_get_deletion_flag (GimpUnit *unit) { GimpValueArray *args; GimpValueArray *return_vals; gboolean deletion_flag = FALSE; args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_UNIT, unit_id, + GIMP_TYPE_UNIT, unit, G_TYPE_NONE); return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), @@ -184,7 +188,7 @@ _gimp_unit_get_deletion_flag (GimpUnit unit_id) /** * _gimp_unit_set_deletion_flag: - * @unit_id: The unit's integer ID. + * @unit: The unit. * @deletion_flag: The new deletion flag of the unit. * * Sets the deletion flag of a unit. @@ -196,15 +200,15 @@ _gimp_unit_get_deletion_flag (GimpUnit unit_id) * Returns: TRUE on success. **/ gboolean -_gimp_unit_set_deletion_flag (GimpUnit unit_id, - gboolean deletion_flag) +_gimp_unit_set_deletion_flag (GimpUnit *unit, + gboolean deletion_flag) { GimpValueArray *args; GimpValueArray *return_vals; gboolean success = TRUE; args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_UNIT, unit_id, + GIMP_TYPE_UNIT, unit, G_TYPE_BOOLEAN, deletion_flag, G_TYPE_NONE); @@ -219,254 +223,3 @@ _gimp_unit_set_deletion_flag (GimpUnit unit_id, return success; } - -/** - * _gimp_unit_get_identifier: - * @unit_id: The unit's integer ID. - * - * Returns the textual identifier of the unit. - * - * This procedure returns the textual identifier of the unit. For - * built-in units it will be the english singular form of the unit's - * name. For user-defined units this should equal to the singular form. - * - * Returns: (transfer full): The unit's textual identifier. - * The returned value must be freed with g_free(). - **/ -gchar * -_gimp_unit_get_identifier (GimpUnit unit_id) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gchar *identifier = NULL; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_UNIT, unit_id, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-unit-get-identifier", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - identifier = GIMP_VALUES_DUP_STRING (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return identifier; -} - -/** - * _gimp_unit_get_factor: - * @unit_id: The unit's integer ID. - * - * Returns the factor of the unit. - * - * This procedure returns the unit's factor which indicates how many - * units make up an inch. Note that asking for the factor of \"pixels\" - * will produce an error. - * - * Returns: The unit's factor. - **/ -gdouble -_gimp_unit_get_factor (GimpUnit unit_id) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gdouble factor = 0.0; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_UNIT, unit_id, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-unit-get-factor", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - factor = GIMP_VALUES_GET_DOUBLE (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return factor; -} - -/** - * _gimp_unit_get_digits: - * @unit_id: The unit's integer ID. - * - * Returns the number of digits of the unit. - * - * This procedure returns the number of digits you should provide in - * input or output functions to get approximately the same accuracy as - * with two digits and inches. Note that asking for the digits of - * \"pixels\" will produce an error. - * - * Returns: The unit's number of digits. - **/ -gint -_gimp_unit_get_digits (GimpUnit unit_id) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gint digits = 0; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_UNIT, unit_id, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-unit-get-digits", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - digits = GIMP_VALUES_GET_INT (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return digits; -} - -/** - * _gimp_unit_get_symbol: - * @unit_id: The unit's integer ID. - * - * Returns the symbol of the unit. - * - * This procedure returns the symbol of the unit (\"''\" for inches). - * - * Returns: (transfer full): The unit's symbol. - * The returned value must be freed with g_free(). - **/ -gchar * -_gimp_unit_get_symbol (GimpUnit unit_id) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gchar *symbol = NULL; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_UNIT, unit_id, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-unit-get-symbol", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - symbol = GIMP_VALUES_DUP_STRING (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return symbol; -} - -/** - * _gimp_unit_get_abbreviation: - * @unit_id: The unit's integer ID. - * - * Returns the abbreviation of the unit. - * - * This procedure returns the abbreviation of the unit (\"in\" for - * inches). - * - * Returns: (transfer full): The unit's abbreviation. - * The returned value must be freed with g_free(). - **/ -gchar * -_gimp_unit_get_abbreviation (GimpUnit unit_id) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gchar *abbreviation = NULL; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_UNIT, unit_id, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-unit-get-abbreviation", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - abbreviation = GIMP_VALUES_DUP_STRING (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return abbreviation; -} - -/** - * _gimp_unit_get_singular: - * @unit_id: The unit's integer ID. - * - * Returns the singular form of the unit. - * - * This procedure returns the singular form of the unit. - * - * Returns: (transfer full): The unit's singular form. - * The returned value must be freed with g_free(). - **/ -gchar * -_gimp_unit_get_singular (GimpUnit unit_id) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gchar *singular = NULL; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_UNIT, unit_id, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-unit-get-singular", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - singular = GIMP_VALUES_DUP_STRING (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return singular; -} - -/** - * _gimp_unit_get_plural: - * @unit_id: The unit's integer ID. - * - * Returns the plural form of the unit. - * - * This procedure returns the plural form of the unit. - * - * Returns: (transfer full): The unit's plural form. - * The returned value must be freed with g_free(). - **/ -gchar * -_gimp_unit_get_plural (GimpUnit unit_id) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gchar *plural = NULL; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_UNIT, unit_id, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-unit-get-plural", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - plural = GIMP_VALUES_DUP_STRING (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return plural; -} diff --git a/libgimp/gimpunit_pdb.h b/libgimp/gimpunit_pdb.h index 3481649149..3db638be77 100644 --- a/libgimp/gimpunit_pdb.h +++ b/libgimp/gimpunit_pdb.h @@ -32,25 +32,23 @@ G_BEGIN_DECLS /* For information look into the C source or the html documentation */ -G_GNUC_INTERNAL gint _gimp_unit_get_number_of_units (void); -G_GNUC_INTERNAL gint _gimp_unit_get_number_of_built_in_units (void); -G_GNUC_INTERNAL GimpUnit _gimp_unit_new (const gchar *identifier, - gdouble factor, - gint digits, - const gchar *symbol, - const gchar *abbreviation, - const gchar *singular, - const gchar *plural); -G_GNUC_INTERNAL gboolean _gimp_unit_get_deletion_flag (GimpUnit unit_id); -G_GNUC_INTERNAL gboolean _gimp_unit_set_deletion_flag (GimpUnit unit_id, - gboolean deletion_flag); -G_GNUC_INTERNAL gchar* _gimp_unit_get_identifier (GimpUnit unit_id); -G_GNUC_INTERNAL gdouble _gimp_unit_get_factor (GimpUnit unit_id); -G_GNUC_INTERNAL gint _gimp_unit_get_digits (GimpUnit unit_id); -G_GNUC_INTERNAL gchar* _gimp_unit_get_symbol (GimpUnit unit_id); -G_GNUC_INTERNAL gchar* _gimp_unit_get_abbreviation (GimpUnit unit_id); -G_GNUC_INTERNAL gchar* _gimp_unit_get_singular (GimpUnit unit_id); -G_GNUC_INTERNAL gchar* _gimp_unit_get_plural (GimpUnit unit_id); +GimpUnit* gimp_unit_new (const gchar *identifier, + gdouble factor, + gint digits, + const gchar *symbol, + const gchar *abbreviation, + const gchar *singular, + const gchar *plural); +G_GNUC_INTERNAL gchar* _gimp_unit_get_data (gint unit_id, + gdouble *factor, + gint *digits, + gchar **symbol, + gchar **abbreviation, + gchar **singular, + gchar **plural); +G_GNUC_INTERNAL gboolean _gimp_unit_get_deletion_flag (GimpUnit *unit); +G_GNUC_INTERNAL gboolean _gimp_unit_set_deletion_flag (GimpUnit *unit, + gboolean deletion_flag); G_END_DECLS diff --git a/libgimp/gimpunitcache.c b/libgimp/gimpunitcache.c deleted file mode 100644 index 95bca08768..0000000000 --- a/libgimp/gimpunitcache.c +++ /dev/null @@ -1,236 +0,0 @@ -/* LIBGIMP - The GIMP Library - * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball - * - * gimpunitcache.c - * Copyright (C) 1999-2000 Michael Natterer - * - * This library is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * . - */ - -#include "config.h" - -#include - -#include "libgimpbase/gimpbase.h" - -#include "gimpunitcache.h" -#include "gimpunit_pdb.h" - -#include "libgimp-intl.h" - -/* internal structures */ - -typedef struct -{ - gdouble factor; - gint digits; - const gchar *identifier; - const gchar *symbol; - const gchar *abbreviation; - const gchar *singular; - const gchar *plural; -} GimpUnitDef; - - -static GimpUnitDef * gimp_unit_defs = NULL; -static GimpUnit gimp_units_initialized = 0; - -/* not a unit at all but kept here to have the strings in one place - */ -static const GimpUnitDef gimp_unit_percent = -{ - 0.0, 0, "percent", "%", "%", N_("percent"), N_("percent") -}; - - -static void gimp_unit_def_init (GimpUnitDef *unit_def, - GimpUnit unit); - - -static gboolean -gimp_unit_init (GimpUnit unit) -{ - gint i, n; - - if (unit < gimp_units_initialized) - return TRUE; - - n = _gimp_unit_get_number_of_units (); - - if (unit >= n) - return FALSE; - - gimp_unit_defs = g_renew (GimpUnitDef, gimp_unit_defs, n); - - for (i = gimp_units_initialized; i < n; i++) - { - gimp_unit_def_init (&gimp_unit_defs[i], i); - } - - gimp_units_initialized = n; - - return TRUE; -} - -static void -gimp_unit_def_init (GimpUnitDef *unit_def, - GimpUnit unit) -{ - unit_def->factor = _gimp_unit_get_factor (unit); - unit_def->digits = _gimp_unit_get_digits (unit); - unit_def->identifier = _gimp_unit_get_identifier (unit); - unit_def->symbol = _gimp_unit_get_symbol (unit); - unit_def->abbreviation = _gimp_unit_get_abbreviation (unit); - unit_def->singular = _gimp_unit_get_singular (unit); - unit_def->plural = _gimp_unit_get_plural (unit); -} - -gint -_gimp_unit_cache_get_number_of_units (void) -{ - return _gimp_unit_get_number_of_units (); -} - -gint -_gimp_unit_cache_get_number_of_built_in_units (void) -{ - return GIMP_UNIT_END; -} - -GimpUnit -_gimp_unit_cache_new (gchar *identifier, - gdouble factor, - gint digits, - gchar *symbol, - gchar *abbreviation, - gchar *singular, - gchar *plural) -{ - return _gimp_unit_new (identifier, - factor, - digits, - symbol, - abbreviation, - singular, - plural); -} - -gboolean -_gimp_unit_cache_get_deletion_flag (GimpUnit unit) -{ - if (unit < GIMP_UNIT_END) - return FALSE; - - return _gimp_unit_get_deletion_flag (unit); -} - -void -_gimp_unit_cache_set_deletion_flag (GimpUnit unit, - gboolean deletion_flag) -{ - if (unit < GIMP_UNIT_END) - return; - - _gimp_unit_set_deletion_flag (unit, - deletion_flag); -} - -gdouble -_gimp_unit_cache_get_factor (GimpUnit unit) -{ - g_return_val_if_fail (unit >= GIMP_UNIT_INCH, 1.0); - - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.factor; - - if (!gimp_unit_init (unit)) - return 1.0; - - return gimp_unit_defs[unit].factor; -} - -gint -_gimp_unit_cache_get_digits (GimpUnit unit) -{ - g_return_val_if_fail (unit >= GIMP_UNIT_INCH, 0); - - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.digits; - - if (!gimp_unit_init (unit)) - return 0; - - return gimp_unit_defs[unit].digits; -} - -const gchar * -_gimp_unit_cache_get_identifier (GimpUnit unit) -{ - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.identifier; - - if (!gimp_unit_init (unit)) - return NULL; - - return gimp_unit_defs[unit].identifier; -} - -const gchar * -_gimp_unit_cache_get_symbol (GimpUnit unit) -{ - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.symbol; - - if (!gimp_unit_init (unit)) - return NULL; - - return gimp_unit_defs[unit].symbol; -} - -const gchar * -_gimp_unit_cache_get_abbreviation (GimpUnit unit) -{ - if (unit == GIMP_UNIT_PERCENT) - return gimp_unit_percent.abbreviation; - - if (!gimp_unit_init (unit)) - return NULL; - - return gimp_unit_defs[unit].abbreviation; -} - -const gchar * -_gimp_unit_cache_get_singular (GimpUnit unit) -{ - if (unit == GIMP_UNIT_PERCENT) - return gettext (gimp_unit_percent.singular); - - if (!gimp_unit_init (unit)) - return NULL; - - return gettext (gimp_unit_defs[unit].singular); -} - -const gchar * -_gimp_unit_cache_get_plural (GimpUnit unit) -{ - if (unit == GIMP_UNIT_PERCENT) - return gettext (gimp_unit_percent.plural); - - if (!gimp_unit_init (unit)) - return NULL; - - return gettext (gimp_unit_defs[unit].plural); -} diff --git a/libgimp/gimpunitcache.h b/libgimp/gimpunitcache.h deleted file mode 100644 index 245127fd3f..0000000000 --- a/libgimp/gimpunitcache.h +++ /dev/null @@ -1,52 +0,0 @@ -/* LIBGIMP - The GIMP Library - * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball - * - * gimpunitcache.c - * Copyright (C) 2003 Michael Natterer - * - * This library is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * . - */ - -#ifndef __GIMP_UNIT_CACHE_H__ -#define __GIMP_UNIT_CACHE_H__ - -G_BEGIN_DECLS - - -G_GNUC_INTERNAL gint _gimp_unit_cache_get_number_of_units (void); -G_GNUC_INTERNAL gint _gimp_unit_cache_get_number_of_built_in_units (void) G_GNUC_CONST; - -G_GNUC_INTERNAL GimpUnit _gimp_unit_cache_new (gchar *identifier, - gdouble factor, - gint digits, - gchar *symbol, - gchar *abbreviation, - gchar *singular, - gchar *plural); -G_GNUC_INTERNAL gboolean _gimp_unit_cache_get_deletion_flag (GimpUnit unit); -G_GNUC_INTERNAL void _gimp_unit_cache_set_deletion_flag (GimpUnit unit, - gboolean deletion_flag); -G_GNUC_INTERNAL gdouble _gimp_unit_cache_get_factor (GimpUnit unit); -G_GNUC_INTERNAL gint _gimp_unit_cache_get_digits (GimpUnit unit); -G_GNUC_INTERNAL const gchar * _gimp_unit_cache_get_identifier (GimpUnit unit); -G_GNUC_INTERNAL const gchar * _gimp_unit_cache_get_symbol (GimpUnit unit); -G_GNUC_INTERNAL const gchar * _gimp_unit_cache_get_abbreviation (GimpUnit unit); -G_GNUC_INTERNAL const gchar * _gimp_unit_cache_get_singular (GimpUnit unit); -G_GNUC_INTERNAL const gchar * _gimp_unit_cache_get_plural (GimpUnit unit); - - -G_END_DECLS - -#endif /* __GIMP_UNIT_CACHE_H__ */ diff --git a/libgimp/gimpvectorloadprocedure.c b/libgimp/gimpvectorloadprocedure.c index 52fc2a3df3..9169d933d4 100644 --- a/libgimp/gimpvectorloadprocedure.c +++ b/libgimp/gimpvectorloadprocedure.c @@ -141,11 +141,11 @@ gimp_vector_load_procedure_constructed (GObject *object) GIMP_MIN_RESOLUTION, GIMP_MAX_RESOLUTION, GIMP_VECTOR_LOAD_DEFAULT_PIXEL_DENSITY, G_PARAM_READWRITE); - gimp_procedure_add_int_aux_argument (procedure, "physical-unit", - _("Unit"), - _("Physical unit"), - GIMP_UNIT_INCH, GIMP_UNIT_PICA, GIMP_UNIT_INCH, - G_PARAM_READWRITE); + gimp_procedure_add_unit_aux_argument (procedure, "physical-unit", + _("Unit"), + _("Physical unit"), + FALSE, FALSE, gimp_unit_inch (), + G_PARAM_READWRITE); } static void @@ -274,10 +274,10 @@ gimp_vector_load_procedure_run (GimpProcedure *procedure, if (extracted_dimensions.width != 0 && extracted_dimensions.height != 0) { if (extracted_dimensions.pixel_density > 0.0 && - extracted_dimensions.density_unit != GIMP_UNIT_PERCENT && - extracted_dimensions.density_unit != GIMP_UNIT_PIXEL) + extracted_dimensions.density_unit != gimp_unit_percent () && + extracted_dimensions.density_unit != gimp_unit_pixel ()) { - if (extracted_dimensions.density_unit == GIMP_UNIT_INCH) + if (extracted_dimensions.density_unit == gimp_unit_inch ()) { resolution = extracted_dimensions.pixel_density; } @@ -289,9 +289,9 @@ gimp_vector_load_procedure_run (GimpProcedure *procedure, default_resolution = resolution; } - if (extracted_dimensions.width_unit == GIMP_UNIT_PIXEL || + if (extracted_dimensions.width_unit == gimp_unit_pixel () || /* This is kinda bogus, but it at least gives ratio data. */ - extracted_dimensions.width_unit == GIMP_UNIT_PERCENT) + extracted_dimensions.width_unit == gimp_unit_percent ()) { default_pixel_width = extracted_dimensions.width; res_pixel_width = (gint) default_pixel_width; @@ -306,8 +306,8 @@ gimp_vector_load_procedure_run (GimpProcedure *procedure, res_pixel_width = (gint) ceil (default_inch_width * resolution); } - if (extracted_dimensions.height_unit == GIMP_UNIT_PIXEL || - extracted_dimensions.height_unit == GIMP_UNIT_PERCENT) + if (extracted_dimensions.height_unit == gimp_unit_pixel () || + extracted_dimensions.height_unit == gimp_unit_percent ()) { default_pixel_height = extracted_dimensions.height; res_pixel_height = (gint) default_pixel_height; diff --git a/libgimp/gimpvectorloadprocedure.h b/libgimp/gimpvectorloadprocedure.h index 1ba6656cb3..260f9df345 100644 --- a/libgimp/gimpvectorloadprocedure.h +++ b/libgimp/gimpvectorloadprocedure.h @@ -31,19 +31,19 @@ G_BEGIN_DECLS typedef struct _GimpVectorLoadData { - gdouble width; - GimpUnit width_unit; - gboolean exact_width; + gdouble width; + GimpUnit *width_unit; + gboolean exact_width; - gdouble height; - GimpUnit height_unit; - gboolean exact_height; + gdouble height; + GimpUnit *height_unit; + gboolean exact_height; - gboolean correct_ratio; + gboolean correct_ratio; - gdouble pixel_density; - GimpUnit density_unit; - gboolean exact_density; + gdouble pixel_density; + GimpUnit *density_unit; + gboolean exact_density; } GimpVectorLoadData; /** diff --git a/libgimp/gimpvectorloadproceduredialog.c b/libgimp/gimpvectorloadproceduredialog.c index 9732e41946..08b0365552 100644 --- a/libgimp/gimpvectorloadproceduredialog.c +++ b/libgimp/gimpvectorloadproceduredialog.c @@ -147,19 +147,19 @@ gimp_vector_load_procedure_dialog_fill_start (GimpProcedureDialog *dialog, { ratio_width = vector_dialog->extracted_data->width; ratio_height = vector_dialog->extracted_data->height; - if (vector_dialog->extracted_data->width_unit == GIMP_UNIT_PIXEL || - vector_dialog->extracted_data->width_unit == GIMP_UNIT_PERCENT) + if (vector_dialog->extracted_data->width_unit == gimp_unit_pixel () || + vector_dialog->extracted_data->width_unit == gimp_unit_percent ()) ratio_width_digits = ratio_height_digits = 0; else ratio_width_digits = ratio_height_digits = gimp_unit_get_digits (vector_dialog->extracted_data->width_unit); } - else if (vector_dialog->extracted_data->width_unit != GIMP_UNIT_PIXEL && vector_dialog->extracted_data->height_unit != GIMP_UNIT_PIXEL && - vector_dialog->extracted_data->width_unit != GIMP_UNIT_PERCENT && vector_dialog->extracted_data->height_unit != GIMP_UNIT_PERCENT) + else if (vector_dialog->extracted_data->width_unit != gimp_unit_pixel () && vector_dialog->extracted_data->height_unit != gimp_unit_pixel () && + vector_dialog->extracted_data->width_unit != gimp_unit_percent () && vector_dialog->extracted_data->height_unit != gimp_unit_percent ()) { ratio_width = vector_dialog->extracted_data->width / gimp_unit_get_factor (vector_dialog->extracted_data->width_unit); ratio_height = vector_dialog->extracted_data->height / gimp_unit_get_factor (vector_dialog->extracted_data->height_unit); - ratio_width_digits = ratio_height_digits = gimp_unit_get_digits (GIMP_UNIT_INCH); + ratio_width_digits = ratio_height_digits = gimp_unit_get_digits (gimp_unit_inch ()); } if (ratio_width != 0.0 && ratio_height != 0.0) diff --git a/libgimp/meson.build b/libgimp/meson.build index 7a4aa82a51..d72c111145 100644 --- a/libgimp/meson.build +++ b/libgimp/meson.build @@ -112,6 +112,7 @@ pdb_wrappers_sources = [ 'gimpselection_pdb.c', 'gimptextlayer_pdb.c', 'gimptexttool_pdb.c', + 'gimpunit_pdb.c', ] pdb_wrappers_headers = [ @@ -168,6 +169,7 @@ pdb_wrappers_headers = [ 'gimpselection_pdb.h', 'gimptextlayer_pdb.h', 'gimptexttool_pdb.h', + 'gimpunit_pdb.h', ] libgimp_sources_introspectable = [ @@ -222,8 +224,6 @@ libgimp_sources = [ 'gimppdbprocedure.c', 'gimppixbuf.c', 'gimpplugin_pdb.c', - 'gimpunit_pdb.c', - 'gimpunitcache.c', 'gimptilebackendplugin.c', ] diff --git a/libgimpbase/gimpbase-private.c b/libgimpbase/gimpbase-private.c index 187d2e52e3..2bd3e8efbd 100644 --- a/libgimpbase/gimpbase-private.c +++ b/libgimpbase/gimpbase-private.c @@ -29,7 +29,8 @@ #include "gimpcompatenums.h" -GimpUnitVtable _gimp_unit_vtable = { NULL, }; +GHashTable *_gimp_units = NULL; +GimpUnitVtable _gimp_unit_vtable = { NULL, }; void @@ -49,6 +50,12 @@ gimp_base_init (GimpUnitVtable *vtable) gimp_base_initialized = TRUE; } +void +gimp_base_exit (void) +{ + g_clear_pointer (&_gimp_units, g_hash_table_unref); +} + void gimp_base_compat_enums_init (void) { diff --git a/libgimpbase/gimpbase-private.h b/libgimpbase/gimpbase-private.h index a36b4a7241..47bf9f4246 100644 --- a/libgimpbase/gimpbase-private.h +++ b/libgimpbase/gimpbase-private.h @@ -27,41 +27,44 @@ typedef struct _GimpUnitVtable GimpUnitVtable; struct _GimpUnitVtable { - gint (* unit_get_number_of_units) (void); - gint (* unit_get_number_of_built_in_units) (void); + /* These methods MUST only be set on libgimp, not in core app. */ + gboolean (* get_deletion_flag) (GimpUnit *unit); + gboolean (* set_deletion_flag) (GimpUnit *unit, + gboolean deletion_flag); + gchar * (* get_data) (gint unit_id, + gdouble *factor, + gint *digits, + gchar **symbol, + gchar **abbreviation, + gchar **singular, + gchar **plural); - GimpUnit (* unit_new) (gchar *identifier, - gdouble factor, - gint digits, - gchar *symbol, - gchar *abbreviation, - gchar *singular, - gchar *plural); - gboolean (* unit_get_deletion_flag) (GimpUnit unit); - void (* unit_set_deletion_flag) (GimpUnit unit, - gboolean deletion_flag); + /* These methods MUST only be set on app, not in libgimp. */ + GimpUnit * (* get_user_unit) (gint unit_id); - gdouble (* unit_get_factor) (GimpUnit unit); - gint (* unit_get_digits) (GimpUnit unit); - const gchar * (* unit_get_identifier) (GimpUnit unit); - const gchar * (* unit_get_symbol) (GimpUnit unit); - const gchar * (* unit_get_abbreviation) (GimpUnit unit); - const gchar * (* unit_get_singular) (GimpUnit unit); - const gchar * (* unit_get_plural) (GimpUnit unit); + /* Reserved methods. */ + void (* _reserved_0) (void); void (* _reserved_1) (void); void (* _reserved_2) (void); void (* _reserved_3) (void); void (* _reserved_4) (void); + void (* _reserved_5) (void); + void (* _reserved_6) (void); + void (* _reserved_7) (void); + void (* _reserved_8) (void); + void (* _reserved_9) (void); }; -extern GimpUnitVtable _gimp_unit_vtable; +extern GimpUnitVtable _gimp_unit_vtable; +extern GHashTable *_gimp_units; G_BEGIN_DECLS void gimp_base_init (GimpUnitVtable *vtable); +void gimp_base_exit (void); void gimp_base_compat_enums_init (void); G_END_DECLS diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def index 4397fc14b7..ab9a3ef3da 100644 --- a/libgimpbase/gimpbase.def +++ b/libgimpbase/gimpbase.def @@ -6,6 +6,7 @@ EXPORTS gimp_array_get_type gimp_array_new gimp_base_compat_enums_init + gimp_base_exit gimp_base_init gimp_bind_text_domain gimp_brush_generated_shape_get_type @@ -199,19 +200,25 @@ EXPORTS gimp_type_set_translation_domain gimp_unit_format_string gimp_unit_get_abbreviation + gimp_unit_get_by_id gimp_unit_get_deletion_flag gimp_unit_get_digits gimp_unit_get_factor + gimp_unit_get_id gimp_unit_get_identifier - gimp_unit_get_number_of_built_in_units - gimp_unit_get_number_of_units gimp_unit_get_plural gimp_unit_get_scaled_digits gimp_unit_get_singular gimp_unit_get_symbol gimp_unit_get_type + gimp_unit_inch + gimp_unit_is_built_in gimp_unit_is_metric - gimp_unit_new + gimp_unit_mm + gimp_unit_percent + gimp_unit_pica + gimp_unit_pixel + gimp_unit_point gimp_unit_set_deletion_flag gimp_units_to_pixels gimp_units_to_points diff --git a/libgimpbase/gimpbaseenums.h b/libgimpbase/gimpbaseenums.h index 72f4ab63ac..ef15e1cda4 100644 --- a/libgimpbase/gimpbaseenums.h +++ b/libgimpbase/gimpbaseenums.h @@ -1279,7 +1279,7 @@ typedef enum /** - * GimpUnit: + * GimpUnitID: * @GIMP_UNIT_PIXEL: Pixels * @GIMP_UNIT_INCH: Inches * @GIMP_UNIT_MM: Millimeters @@ -1288,7 +1288,9 @@ typedef enum * @GIMP_UNIT_END: Marker for end-of-builtin-units * @GIMP_UNIT_PERCENT: Pseudo-unit percent * - * Units used for dimensions in images. + * Integer IDs of built-in units used for dimensions in images. These + * IDs are meant to stay stable but user-created units IDs may change + * from one session to another. **/ typedef enum /*< skip >*/ { @@ -1302,7 +1304,7 @@ typedef enum /*< skip >*/ GIMP_UNIT_END = 5, GIMP_UNIT_PERCENT = 65536 /*< pdb-skip >*/ -} GimpUnit; +} GimpUnitID; /** diff --git a/libgimpbase/gimpbasetypes.h b/libgimpbase/gimpbasetypes.h index b323ee8d5f..7e9077f238 100644 --- a/libgimpbase/gimpbasetypes.h +++ b/libgimpbase/gimpbasetypes.h @@ -48,6 +48,7 @@ typedef struct _GimpChoice GimpChoice; typedef struct _GimpParasite GimpParasite; typedef struct _GimpEnumDesc GimpEnumDesc; typedef struct _GimpFlagsDesc GimpFlagsDesc; +typedef struct _GimpUnit GimpUnit; typedef struct _GimpValueArray GimpValueArray; typedef struct _GimpMetadata GimpMetadata; diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c index 77d931f583..38e87f7d59 100644 --- a/libgimpbase/gimpmetadata.c +++ b/libgimpbase/gimpmetadata.c @@ -1557,10 +1557,10 @@ gimp_metadata_set_bits_per_sample (GimpMetadata *metadata, * Since: 2.10 */ gboolean -gimp_metadata_get_resolution (GimpMetadata *metadata, - gdouble *xres, - gdouble *yres, - GimpUnit *unit) +gimp_metadata_get_resolution (GimpMetadata *metadata, + gdouble *xres, + gdouble *yres, + GimpUnit **unit) { gint xnom, xdenom; gint ynom, ydenom; @@ -1611,9 +1611,9 @@ gimp_metadata_get_resolution (GimpMetadata *metadata, if (unit) { if (exif_unit == 3) - *unit = GIMP_UNIT_MM; + *unit = gimp_unit_mm (); else - *unit = GIMP_UNIT_INCH; + *unit = gimp_unit_inch (); } return TRUE; @@ -1640,7 +1640,7 @@ void gimp_metadata_set_resolution (GimpMetadata *metadata, gdouble xres, gdouble yres, - GimpUnit unit) + GimpUnit *unit) { gchar buffer[32]; gint exif_unit; diff --git a/libgimpbase/gimpmetadata.h b/libgimpbase/gimpmetadata.h index 5467f221b3..60fb4c9dac 100644 --- a/libgimpbase/gimpmetadata.h +++ b/libgimpbase/gimpmetadata.h @@ -137,11 +137,11 @@ void gimp_metadata_set_bits_per_sample (GimpMetadata *metada gboolean gimp_metadata_get_resolution (GimpMetadata *metadata, gdouble *xres, gdouble *yres, - GimpUnit *unit); + GimpUnit **unit); void gimp_metadata_set_resolution (GimpMetadata *metadata, gdouble xres, gdouble yres, - GimpUnit unit); + GimpUnit *unit); GimpMetadataColorspace gimp_metadata_get_colorspace (GimpMetadata *metadata); diff --git a/libgimpbase/gimpunit.c b/libgimpbase/gimpunit.c index 2184861691..dd156338c6 100644 --- a/libgimpbase/gimpunit.c +++ b/libgimpbase/gimpunit.c @@ -24,196 +24,321 @@ #include #include +#include #include #include "gimpbasetypes.h" #include "gimpbase-private.h" +#include "gimpparamspecs.h" #include "gimpunit.h" - -/** - * SECTION: gimpunit - * @title: gimpunit - * @short_description: Provides a collection of predefined units and - * functions for creating user-defined units. - * @see_also: #GimpUnitMenu, #GimpSizeEntry. - * - * Provides a collection of predefined units and functions for - * creating user-defined units. - **/ +#include "libgimp/libgimp-intl.h" -static void unit_to_string (const GValue *src_value, - GValue *dest_value); -static void string_to_unit (const GValue *src_value, - GValue *dest_value); - -GType -gimp_unit_get_type (void) +enum { - static GType unit_type = 0; + PROP_0, + PROP_ID, + PROP_NAME, + PROP_FACTOR, + PROP_DIGITS, + PROP_SYMBOL, + PROP_ABBREVIATION, + PROP_SINGULAR, + PROP_PLURAL, +}; - if (! unit_type) +typedef struct +{ + gboolean delete_on_exit; + gdouble factor; + gint digits; + gchar *identifier; + gchar *symbol; + gchar *abbreviation; + gchar *singular; + gchar *plural; +} GimpUnitDef; + +struct _GimpUnit +{ + GObject parent_instance; + + gint id; + gchar *name; + + gboolean built_in; + + gboolean delete_on_exit; + gdouble factor; + gint digits; + gchar *symbol; + gchar *abbreviation; + gchar *singular; + gchar *plural; +}; + + +/* these are the built-in units + */ +static const GimpUnitDef _gimp_unit_defs[GIMP_UNIT_END] = +{ + /* pseudo unit */ + { FALSE, 0.0, 0, "pixels", "px", "px", + NC_("unit-singular", "pixel"), NC_("unit-plural", "pixels") }, + + /* standard units */ + { FALSE, 1.0, 2, "inches", "''", "in", + NC_("unit-singular", "inch"), NC_("unit-plural", "inches") }, + + { FALSE, 25.4, 1, "millimeters", "mm", "mm", + NC_("unit-singular", "millimeter"), NC_("unit-plural", "millimeters") }, + + /* professional units */ + { FALSE, 72.0, 0, "points", "pt", "pt", + NC_("unit-singular", "point"), NC_("unit-plural", "points") }, + + { FALSE, 6.0, 1, "picas", "pc", "pc", + NC_("unit-singular", "pica"), NC_("unit-plural", "picas") } +}; + +/* not a unit at all but kept here to have the strings in one place + */ +static const GimpUnitDef _gimp_unit_percent_def = +{ + FALSE, 0.0, 0, "percent", "%", "%", + NC_("singular", "percent"), NC_("plural", "percent") +}; + + +static void gimp_unit_constructed (GObject *object); +static void gimp_unit_finalize (GObject *object); +static void gimp_unit_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gimp_unit_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gint print (gchar *buf, + gint len, + gint start, + const gchar *fmt, + ...) G_GNUC_PRINTF (4, 5); + + +G_DEFINE_TYPE (GimpUnit, gimp_unit, G_TYPE_OBJECT) + +#define parent_class gimp_unit_parent_class + + +static void +gimp_unit_class_init (GimpUnitClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->constructed = gimp_unit_constructed; + object_class->finalize = gimp_unit_finalize; + object_class->set_property = gimp_unit_set_property; + object_class->get_property = gimp_unit_get_property; + + g_object_class_install_property (object_class, PROP_ID, + g_param_spec_int ("id", NULL, NULL, + 0, G_MAXINT, 0, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_NAME, + g_param_spec_string ("name", NULL, NULL, + NULL, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_FACTOR, + g_param_spec_double ("factor", NULL, NULL, + 0.0, G_MAXDOUBLE, 1.0, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_DIGITS, + g_param_spec_int ("digits", NULL, NULL, + 0, G_MAXINT, 0, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_SYMBOL, + g_param_spec_string ("symbol", NULL, NULL, + NULL, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_ABBREVIATION, + g_param_spec_string ("abbreviation", NULL, NULL, + NULL, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_SINGULAR, + g_param_spec_string ("singular", NULL, NULL, + NULL, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_PLURAL, + g_param_spec_string ("plural", NULL, NULL, + NULL, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + /*klass->id_table = gimp_id_table_new ();*/ +} + +static void +gimp_unit_init (GimpUnit *unit) +{ + unit->name = NULL; + unit->symbol = NULL; + unit->abbreviation = NULL; + unit->singular = NULL; + unit->plural = NULL; +} + +static void +gimp_unit_constructed (GObject *object) +{ + G_OBJECT_CLASS (parent_class)->constructed (object); +} + +static void +gimp_unit_finalize (GObject *object) +{ + GimpUnit *unit = GIMP_UNIT (object); + + g_free (unit->name); + g_free (unit->symbol); + g_free (unit->abbreviation); + g_free (unit->singular); + g_free (unit->plural); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +gimp_unit_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GimpUnit *unit = GIMP_UNIT (object); + + switch (property_id) { - const GTypeInfo type_info = { 0, }; - - unit_type = g_type_register_static (G_TYPE_INT, "GimpUnit", - &type_info, 0); - - g_value_register_transform_func (unit_type, G_TYPE_STRING, - unit_to_string); - g_value_register_transform_func (G_TYPE_STRING, unit_type, - string_to_unit); - } - - return unit_type; -} - -static void -unit_to_string (const GValue *src_value, - GValue *dest_value) -{ - GimpUnit unit = (GimpUnit) g_value_get_int (src_value); - - g_value_set_string (dest_value, gimp_unit_get_identifier (unit)); -} - -static void -string_to_unit (const GValue *src_value, - GValue *dest_value) -{ - const gchar *str; - gint num_units; - gint i; - - str = g_value_get_string (src_value); - - if (!str || !*str) - goto error; - - num_units = gimp_unit_get_number_of_units (); - - for (i = GIMP_UNIT_PIXEL; i < num_units; i++) - if (strcmp (str, gimp_unit_get_identifier (i)) == 0) + case PROP_ID: + unit->id = g_value_get_int (value); + break; + case PROP_NAME: + unit->name = g_value_dup_string (value); + break; + case PROP_FACTOR: + unit->factor = g_value_get_double (value); + break; + case PROP_DIGITS: + unit->digits = g_value_get_int (value); + break; + case PROP_SYMBOL: + unit->symbol = g_value_dup_string (value); + break; + case PROP_ABBREVIATION: + unit->abbreviation = g_value_dup_string (value); + break; + case PROP_SINGULAR: + unit->singular = g_value_dup_string (value); + break; + case PROP_PLURAL: + unit->plural = g_value_dup_string (value); break; - if (i == num_units) - { - if (strcmp (str, gimp_unit_get_identifier (GIMP_UNIT_PERCENT)) == 0) - i = GIMP_UNIT_PERCENT; - else - goto error; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; } - - g_value_set_int (dest_value, i); - return; - - error: - g_warning ("Can't convert string '%s' to GimpUnit.", str); } +static void +gimp_unit_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GimpUnit *unit = GIMP_UNIT (object); + + switch (property_id) + { + case PROP_ID: + g_value_set_int (value, unit->id); + break; + case PROP_NAME: + g_value_set_string (value, unit->name); + break; + case PROP_FACTOR: + g_value_set_double (value, unit->factor); + break; + case PROP_DIGITS: + g_value_set_int (value, unit->digits); + break; + case PROP_SYMBOL: + g_value_set_string (value, unit->symbol); + break; + case PROP_ABBREVIATION: + g_value_set_string (value, unit->abbreviation); + break; + case PROP_SINGULAR: + g_value_set_string (value, unit->singular); + break; + case PROP_PLURAL: + g_value_set_string (value, unit->plural); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +/* public functions */ + /** - * gimp_unit_get_number_of_units: + * gimp_unit_get_id: + * @unit: The unit you want to know the integer ID of. * - * Returns the number of units which are known to the #GimpUnit system. + * The ID can be used to retrieve the unit with [func@Unit.get_by_id]. * - * Returns: The number of defined units. + * Note that this ID will be stable within a single session of GIMP, but + * you should not expect this ID to stay the same across multiple runs. + * + * Returns: The unit's ID. **/ gint -gimp_unit_get_number_of_units (void) +gimp_unit_get_id (GimpUnit *unit) { - g_return_val_if_fail (_gimp_unit_vtable.unit_get_number_of_units != NULL, - GIMP_UNIT_END); + g_return_val_if_fail (GIMP_IS_UNIT (unit), -1); - return _gimp_unit_vtable.unit_get_number_of_units (); + return unit->id; } /** - * gimp_unit_get_number_of_built_in_units: + * gimp_unit_get_identifier: + * @unit: The unit you want to know the identifier of. * - * Returns the number of #GimpUnit's which are hardcoded in the unit system - * (UNIT_INCH, UNIT_MM, UNIT_POINT, UNIT_PICA and the two "pseudo unit" - * UNIT_PIXEL). + * This is an untranslated string which must not be changed or freed. * - * Returns: The number of built-in units. + * Returns: The unit's identifier. **/ -gint -gimp_unit_get_number_of_built_in_units (void) +const gchar * +gimp_unit_get_identifier (GimpUnit *unit) { - g_return_val_if_fail (_gimp_unit_vtable.unit_get_number_of_built_in_units - != NULL, GIMP_UNIT_END); + g_return_val_if_fail (GIMP_IS_UNIT (unit), NULL); - return _gimp_unit_vtable.unit_get_number_of_built_in_units (); -} - -/** - * gimp_unit_new: - * @identifier: The unit's identifier string. - * @factor: The unit's factor (how many units are in one inch). - * @digits: The unit's suggested number of digits (see gimp_unit_get_digits()). - * @symbol: The symbol of the unit (e.g. "''" for inch). - * @abbreviation: The abbreviation of the unit. - * @singular: The singular form of the unit. - * @plural: The plural form of the unit. - * - * Returns the integer ID of the new #GimpUnit. - * - * Note that a new unit is always created with its deletion flag - * set to %TRUE. You will have to set it to %FALSE with - * gimp_unit_set_deletion_flag() to make the unit definition persistent. - * - * Returns: The ID of the new unit. - **/ -GimpUnit -gimp_unit_new (gchar *identifier, - gdouble factor, - gint digits, - gchar *symbol, - gchar *abbreviation, - gchar *singular, - gchar *plural) -{ - g_return_val_if_fail (_gimp_unit_vtable.unit_new != NULL, GIMP_UNIT_INCH); - - return _gimp_unit_vtable.unit_new (identifier, factor, digits, - symbol, abbreviation, singular, plural); -} - -/** - * gimp_unit_get_deletion_flag: - * @unit: The unit you want to know the @deletion_flag of. - * - * Returns: The unit's @deletion_flag. - **/ -gboolean -gimp_unit_get_deletion_flag (GimpUnit unit) -{ - g_return_val_if_fail (_gimp_unit_vtable.unit_get_deletion_flag != NULL, FALSE); - - return _gimp_unit_vtable.unit_get_deletion_flag (unit); -} - -/** - * gimp_unit_set_deletion_flag: - * @unit: The unit you want to set the @deletion_flag for. - * @deletion_flag: The new deletion_flag. - * - * Sets a #GimpUnit's @deletion_flag. If the @deletion_flag of a unit is - * %TRUE when GIMP exits, this unit will not be saved in the users's - * "unitrc" file. - * - * Trying to change the @deletion_flag of a built-in unit will be silently - * ignored. - **/ -void -gimp_unit_set_deletion_flag (GimpUnit unit, - gboolean deletion_flag) -{ - g_return_if_fail (_gimp_unit_vtable.unit_set_deletion_flag != NULL); - - _gimp_unit_vtable.unit_set_deletion_flag (unit, deletion_flag); + return unit->name; } /** @@ -229,14 +354,11 @@ gimp_unit_set_deletion_flag (GimpUnit unit, * Returns: The unit's factor. **/ gdouble -gimp_unit_get_factor (GimpUnit unit) +gimp_unit_get_factor (GimpUnit *unit) { - g_return_val_if_fail (_gimp_unit_vtable.unit_get_factor != NULL, 1.0); + g_return_val_if_fail (GIMP_IS_UNIT (unit), 1.0); - if (unit == GIMP_UNIT_PIXEL) - return 0.0; - - return _gimp_unit_vtable.unit_get_factor (unit); + return unit->factor; } /** @@ -248,8 +370,8 @@ gimp_unit_get_factor (GimpUnit unit) * two digits. User-defined units can suggest a different accuracy. * * Note: the value is as-set by defaults or by the user and does not - * necessary provide enough precision on high-resolution images. - * When the information is needed for a specific image, the use of + * necessary provide enough precision on high-resolution units. + * When the information is needed for a specific unit, the use of * gimp_unit_get_scaled_digits() may be more appropriate. * * Returns 0 for @unit == GIMP_UNIT_PIXEL. @@ -257,11 +379,11 @@ gimp_unit_get_factor (GimpUnit unit) * Returns: The suggested number of digits. **/ gint -gimp_unit_get_digits (GimpUnit unit) +gimp_unit_get_digits (GimpUnit *unit) { - g_return_val_if_fail (_gimp_unit_vtable.unit_get_digits != NULL, 2); + g_return_val_if_fail (GIMP_IS_UNIT (unit), 0); - return _gimp_unit_vtable.unit_get_digits (unit); + return unit->digits; } /** @@ -274,19 +396,19 @@ gimp_unit_get_digits (GimpUnit unit) * value from neighboring pixels. * * Note: when needing digit accuracy to display a diagonal distance, - * the @resolution may not correspond to the image's horizontal or + * the @resolution may not correspond to the unit's horizontal or * vertical resolution, but instead to the result of: * `distance_in_pixel / distance_in_inch`. * * Returns: The suggested number of digits. **/ gint -gimp_unit_get_scaled_digits (GimpUnit unit, - gdouble resolution) +gimp_unit_get_scaled_digits (GimpUnit *unit, + gdouble resolution) { gint digits; - g_return_val_if_fail (_gimp_unit_vtable.unit_get_digits != NULL, 2); + g_return_val_if_fail (GIMP_IS_UNIT (unit), 0); digits = ceil (log10 (1.0 / gimp_pixels_to_units (1.0, unit, resolution))); @@ -294,22 +416,6 @@ gimp_unit_get_scaled_digits (GimpUnit unit, return MAX (digits, gimp_unit_get_digits (unit)); } -/** - * gimp_unit_get_identifier: - * @unit: The unit you want to know the identifier of. - * - * This is an untranslated string and must not be changed or freed. - * - * Returns: The unit's identifier. - **/ -const gchar * -gimp_unit_get_identifier (GimpUnit unit) -{ - g_return_val_if_fail (_gimp_unit_vtable.unit_get_identifier != NULL, NULL); - - return _gimp_unit_vtable.unit_get_identifier (unit); -} - /** * gimp_unit_get_symbol: * @unit: The unit you want to know the symbol of. @@ -321,95 +427,398 @@ gimp_unit_get_identifier (GimpUnit unit) * Returns: The unit's symbol. **/ const gchar * -gimp_unit_get_symbol (GimpUnit unit) +gimp_unit_get_symbol (GimpUnit *unit) { - g_return_val_if_fail (_gimp_unit_vtable.unit_get_symbol != NULL, NULL); + g_return_val_if_fail (GIMP_IS_UNIT (unit), NULL); - return _gimp_unit_vtable.unit_get_symbol (unit); + return unit->symbol; } /** * gimp_unit_get_abbreviation: * @unit: The unit you want to know the abbreviation of. * - * For built-in units, this function returns the translated abbreviation - * of the unit. + * For built-in units, this function returns the abbreviation + * of the unit (e.g. "in" for inches). * * NOTE: This string must not be changed or freed. * * Returns: The unit's abbreviation. **/ const gchar * -gimp_unit_get_abbreviation (GimpUnit unit) +gimp_unit_get_abbreviation (GimpUnit *unit) { - g_return_val_if_fail (_gimp_unit_vtable.unit_get_abbreviation != NULL, NULL); + g_return_val_if_fail (GIMP_IS_UNIT (unit), NULL); - return _gimp_unit_vtable.unit_get_abbreviation (unit); + return unit->abbreviation; } /** * gimp_unit_get_singular: * @unit: The unit you want to know the singular form of. * - * For built-in units, this function returns the translated singular form - * of the unit's name. + * For built-in units, this function returns the singular form of the + * unit's name. * * NOTE: This string must not be changed or freed. * * Returns: The unit's singular form. **/ const gchar * -gimp_unit_get_singular (GimpUnit unit) +gimp_unit_get_singular (GimpUnit *unit) { - g_return_val_if_fail (_gimp_unit_vtable.unit_get_singular != NULL, NULL); + g_return_val_if_fail (GIMP_IS_UNIT (unit), NULL); - return _gimp_unit_vtable.unit_get_singular (unit); + return unit->singular; } /** * gimp_unit_get_plural: * @unit: The unit you want to know the plural form of. * - * For built-in units, this function returns the translated plural form - * of the unit's name. + * For built-in units, this function returns the plural form of the + * unit's name. * * NOTE: This string must not be changed or freed. * * Returns: The unit's plural form. **/ const gchar * -gimp_unit_get_plural (GimpUnit unit) +gimp_unit_get_plural (GimpUnit *unit) { - g_return_val_if_fail (_gimp_unit_vtable.unit_get_plural != NULL, NULL); + g_return_val_if_fail (GIMP_IS_UNIT (unit), NULL); - return _gimp_unit_vtable.unit_get_plural (unit); + return unit->plural; } -static gint print (gchar *buf, - gint len, - gint start, - const gchar *fmt, - ...) G_GNUC_PRINTF (4, 5); - -static gint -print (gchar *buf, - gint len, - gint start, - const gchar *fmt, - ...) +/** + * gimp_unit_get_deletion_flag: + * @unit: The unit you want to know the @deletion_flag of. + * + * Returns: The unit's @deletion_flag. + **/ +gboolean +gimp_unit_get_deletion_flag (GimpUnit *unit) { - va_list args; - gint printed; + g_return_val_if_fail (GIMP_IS_UNIT (unit), TRUE); - va_start (args, fmt); + if ((unit->id >= 0 && unit->id < GIMP_UNIT_END) || + unit->id == GIMP_UNIT_PERCENT) + return FALSE; - printed = g_vsnprintf (buf + start, len - start, fmt, args); - if (printed < 0) - printed = len - start; + if (_gimp_unit_vtable.get_deletion_flag != NULL) + /* This code path will only happen in libgimp. */ + return _gimp_unit_vtable.get_deletion_flag (unit); + else + return unit->delete_on_exit; +} - va_end (args); +/** + * gimp_unit_set_deletion_flag: + * @unit: The unit you want to set the @deletion_flag for. + * @deletion_flag: The new deletion_flag. + * + * Sets a #GimpUnit's @deletion_flag. If the @deletion_flag of a unit is + * %TRUE when GIMP exits, this unit will not be saved in the users's + * "unitrc" file. + * + * Trying to change the @deletion_flag of a built-in unit will be silently + * ignored. + **/ +void +gimp_unit_set_deletion_flag (GimpUnit *unit, + gboolean deletion_flag) +{ + g_return_if_fail (GIMP_IS_UNIT (unit)); - return printed; + if ((unit->id >= 0 && unit->id < GIMP_UNIT_END) || + unit->id == GIMP_UNIT_PERCENT) + return; + + unit->delete_on_exit = deletion_flag; + + if (_gimp_unit_vtable.set_deletion_flag != NULL) + /* This code path will only happen in libgimp. */ + _gimp_unit_vtable.set_deletion_flag (unit, deletion_flag); +} + +/** + * gimp_unit_get_by_id: + * @unit_id: The unit id. + * + * Returns the unique [class@Unit] object corresponding to @unit_id, + * which is the integer identifier as returned by [method@Unit.get_id]. + * + * Returns: (transfer none): the #GimpUnit object with ID @unit_id. + * + * Since: 3.0 + **/ +GimpUnit * +gimp_unit_get_by_id (gint unit_id) +{ + GimpUnit *unit = NULL; + + if (unit_id < 0) + return NULL; + + if (G_UNLIKELY (! _gimp_units)) + _gimp_units = g_hash_table_new_full (g_direct_hash, + g_direct_equal, + NULL, + (GDestroyNotify) g_object_unref); + + unit = g_hash_table_lookup (_gimp_units, GINT_TO_POINTER (unit_id)); + + if (! unit) + { + if (unit_id < GIMP_UNIT_END) + { + GimpUnitDef def = _gimp_unit_defs[unit_id]; + + unit = g_object_new (GIMP_TYPE_UNIT, + "id", unit_id, + "name", def.identifier, + "factor", def.factor, + "digits", def.digits, + "symbol", def.symbol, + "abbreviation", def.abbreviation, + "singular", def.singular, + "plural", def.plural, + NULL); + unit->delete_on_exit = FALSE; + } + else if (unit_id == GIMP_UNIT_PERCENT) + { + unit = g_object_new (GIMP_TYPE_UNIT, + "id", unit_id, + "name", _gimp_unit_percent_def.identifier, + "factor", _gimp_unit_percent_def.factor, + "digits", _gimp_unit_percent_def.digits, + "symbol", _gimp_unit_percent_def.symbol, + "abbreviation", _gimp_unit_percent_def.abbreviation, + "singular", _gimp_unit_percent_def.singular, + "plural", _gimp_unit_percent_def.plural, + NULL); + unit->delete_on_exit = FALSE; + } + else if (_gimp_unit_vtable.get_data != NULL) + { + /* This code path should never happen in app/ where get_data() + * is NULL, because non built-in units are created in app/ + * whereas they are only queried in libgimp. + */ + gchar *identifier = NULL; + gdouble factor; + gint digits; + gchar *symbol = NULL; + gchar *abbreviation = NULL; + gchar *singular = NULL; + gchar *plural = NULL; + + identifier = _gimp_unit_vtable.get_data (unit_id, + &factor, + &digits, + &symbol, + &abbreviation, + &singular, + &plural); + + if (identifier != NULL) + unit = g_object_new (GIMP_TYPE_UNIT, + "id", unit_id, + "name", identifier, + "factor", factor, + "digits", digits, + "symbol", symbol, + "abbreviation", abbreviation, + "singular", singular, + "plural", plural, + NULL); + + g_free (identifier); + g_free (symbol); + g_free (abbreviation); + g_free (singular); + g_free (plural); + } + else if (_gimp_unit_vtable.get_user_unit != NULL) + { + /* This code path should never happen in libgimp, only in app/. */ + + unit = _gimp_unit_vtable.get_user_unit (unit_id); + + if (unit != NULL) + g_object_ref (unit); + } + + if (unit != NULL) + g_hash_table_insert (_gimp_units, GINT_TO_POINTER (unit_id), unit); + } + + return unit; +} + +/** + * gimp_unit_pixel: + * + * Returns the unique object representing pixel unit. + * + * This procedure returns the unit representing pixel. The returned + * object is unique across the whole run. + * + * Returns: (transfer none): The unique pixel unit. + * + * Since: 3.0 + **/ +GimpUnit * +gimp_unit_pixel (void) +{ + return gimp_unit_get_by_id (GIMP_UNIT_PIXEL); +} + +/** + * gimp_unit_inch: + * + * Returns the unique object representing inch unit. + * + * This procedure returns the unit representing inch. The returned + * object is unique across the whole run. + * + * Returns: (transfer none): The unique inch unit. + * + * Since: 3.0 + **/ +GimpUnit * +gimp_unit_inch (void) +{ + return gimp_unit_get_by_id (GIMP_UNIT_INCH); +} + +/** + * gimp_unit_mm: + * + * Returns the unique object representing millimeter unit. + * + * This procedure returns the unit representing millimeter. The + * returned object is unique across the whole run. + * + * Returns: (transfer none): The unique millimeter unit. + * + * Since: 3.0 + **/ +GimpUnit * +gimp_unit_mm (void) +{ + return gimp_unit_get_by_id (GIMP_UNIT_MM); +} + +/** + * gimp_unit_point: + * + * Returns the unique object representing typographical point unit. + * + * This procedure returns the unit representing typographical points. + * The returned object is unique across the whole run. + * + * Returns: (transfer none): The unique point unit. + * + * Since: 3.0 + **/ +GimpUnit * +gimp_unit_point (void) +{ + return gimp_unit_get_by_id (GIMP_UNIT_POINT); +} + +/** + * gimp_unit_pica: + * + * Returns the unique object representing Pica unit. + * + * This procedure returns the unit representing Picas. + * The returned object is unique across the whole run. + * + * Returns: (transfer none): The unique pica unit. + * + * Since: 3.0 + **/ +GimpUnit * +gimp_unit_pica (void) +{ + return gimp_unit_get_by_id (GIMP_UNIT_PICA); +} + +/** + * gimp_unit_percent: + * + * Returns the unique object representing percent dimensions relatively + * to an image. + * + * This procedure returns the unit representing typographical points. + * The returned object is unique across the whole run. + * + * Returns: (transfer none): The unique percent unit. + * + * Since: 3.0 + **/ +GimpUnit * +gimp_unit_percent (void) +{ + return gimp_unit_get_by_id (GIMP_UNIT_PERCENT); +} + +/** + * gimp_unit_is_built_in: + * @unit: the unit. + * + * Returns whether the unit is built-in. + * + * This procedure returns @unit is a built-in unit. In particular the + * deletion flag cannot be set on built-in units. + * + * Returns: Whether @unit is built-in. + * + * Since: 3.0 + **/ +gboolean +gimp_unit_is_built_in (GimpUnit *unit) +{ + g_return_val_if_fail (GIMP_IS_UNIT (unit), FALSE); + + return (unit->id >= 0 && unit->id < GIMP_UNIT_END) || unit->id == GIMP_UNIT_PERCENT; +} + +/** + * gimp_unit_is_metric: + * @unit: The unit + * + * Checks if the given @unit is metric. A simplistic test is used + * that looks at the unit's factor and checks if it is 2.54 multiplied + * by some common powers of 10. Currently it checks for mm, cm, dm, m. + * + * See also: gimp_unit_get_factor() + * + * Returns: %TRUE if the @unit is metric. + * + * Since: 2.10 + **/ +gboolean +gimp_unit_is_metric (GimpUnit *unit) +{ + gdouble factor; + + if (unit == gimp_unit_mm ()) + return TRUE; + + factor = gimp_unit_get_factor (unit); + + if (factor == 0.0) + return FALSE; + + return ((ABS (factor - 0.0254) < 1e-7) || /* m */ + (ABS (factor - 0.254) < 1e-6) || /* dm */ + (ABS (factor - 2.54) < 1e-5) || /* cm */ + (ABS (factor - 25.4) < 1e-4)); /* mm */ } /** @@ -458,15 +867,13 @@ print (gchar *buf, **/ gchar * gimp_unit_format_string (const gchar *format, - GimpUnit unit) + GimpUnit *unit) { gchar buffer[1024]; gint i = 0; + g_return_val_if_fail (GIMP_IS_UNIT (unit), NULL); g_return_val_if_fail (format != NULL, NULL); - g_return_val_if_fail (unit == GIMP_UNIT_PERCENT || - (unit >= GIMP_UNIT_PIXEL && - unit < gimp_unit_get_number_of_units ()), NULL); while (i < (sizeof (buffer) - 1) && *format) { @@ -530,116 +937,6 @@ gimp_unit_format_string (const gchar *format, return g_strdup (buffer); } -/* - * GIMP_TYPE_PARAM_UNIT - */ - -static void gimp_param_unit_class_init (GParamSpecClass *class); -static gboolean gimp_param_unit_value_validate (GParamSpec *pspec, - GValue *value); - -/** - * gimp_param_unit_get_type: - * - * Reveals the object type - * - * Returns: the #GType for a unit param object - * - * Since: 2.4 - **/ -GType -gimp_param_unit_get_type (void) -{ - static GType spec_type = 0; - - if (! spec_type) - { - const GTypeInfo type_info = - { - sizeof (GParamSpecClass), - NULL, NULL, - (GClassInitFunc) gimp_param_unit_class_init, - NULL, NULL, - sizeof (GimpParamSpecUnit), - 0, NULL, NULL - }; - - spec_type = g_type_register_static (G_TYPE_PARAM_INT, - "GimpParamUnit", - &type_info, 0); - } - - return spec_type; -} - -static void -gimp_param_unit_class_init (GParamSpecClass *class) -{ - class->value_type = GIMP_TYPE_UNIT; - class->value_validate = gimp_param_unit_value_validate; -} - -static gboolean -gimp_param_unit_value_validate (GParamSpec *pspec, - GValue *value) -{ - GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec); - GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec); - gint oval = value->data[0].v_int; - - if (!(uspec->allow_percent && value->data[0].v_int == GIMP_UNIT_PERCENT)) - { - value->data[0].v_int = CLAMP (value->data[0].v_int, - ispec->minimum, - gimp_unit_get_number_of_units () - 1); - } - - return value->data[0].v_int != oval; -} - -/** - * gimp_param_spec_unit: - * @name: Canonical name of the param - * @nick: Nickname of the param - * @blurb: Brief description of param. - * @allow_pixels: Whether "pixels" is an allowed unit. - * @allow_percent: Whether "percent" is an allowed unit. - * @default_value: Unit to use if none is assigned. - * @flags: a combination of #GParamFlags - * - * Creates a param spec to hold a units param. - * See g_param_spec_internal() for more information. - * - * Returns: (transfer full): a newly allocated #GParamSpec instance - * - * Since: 2.4 - **/ -GParamSpec * -gimp_param_spec_unit (const gchar *name, - const gchar *nick, - const gchar *blurb, - gboolean allow_pixels, - gboolean allow_percent, - GimpUnit default_value, - GParamFlags flags) -{ - GimpParamSpecUnit *pspec; - GParamSpecInt *ispec; - - pspec = g_param_spec_internal (GIMP_TYPE_PARAM_UNIT, - name, nick, blurb, flags); - - ispec = G_PARAM_SPEC_INT (pspec); - - ispec->default_value = default_value; - ispec->minimum = allow_pixels ? GIMP_UNIT_PIXEL : GIMP_UNIT_INCH; - ispec->maximum = GIMP_UNIT_PERCENT - 1; - - pspec->allow_percent = allow_percent; - - return G_PARAM_SPEC (pspec); -} - /** * gimp_pixels_to_units: * @pixels: value in pixels @@ -653,11 +950,13 @@ gimp_param_spec_unit (const gchar *name, * Since: 2.8 **/ gdouble -gimp_pixels_to_units (gdouble pixels, - GimpUnit unit, - gdouble resolution) +gimp_pixels_to_units (gdouble pixels, + GimpUnit *unit, + gdouble resolution) { - if (unit == GIMP_UNIT_PIXEL) + g_return_val_if_fail (gimp_unit_pixel != NULL, 0.0); + + if (unit == gimp_unit_pixel ()) return pixels; return pixels * gimp_unit_get_factor (unit) / resolution; @@ -676,11 +975,13 @@ gimp_pixels_to_units (gdouble pixels, * Since: 2.8 **/ gdouble -gimp_units_to_pixels (gdouble value, - GimpUnit unit, - gdouble resolution) +gimp_units_to_pixels (gdouble value, + GimpUnit *unit, + gdouble resolution) { - if (unit == GIMP_UNIT_PIXEL) + g_return_val_if_fail (gimp_unit_pixel != NULL, 0.0); + + if (unit == gimp_unit_pixel ()) return value; return value * resolution / gimp_unit_get_factor (unit); @@ -699,49 +1000,174 @@ gimp_units_to_pixels (gdouble value, * Since: 2.8 **/ gdouble -gimp_units_to_points (gdouble value, - GimpUnit unit, - gdouble resolution) +gimp_units_to_points (gdouble value, + GimpUnit *unit, + gdouble resolution) { - if (unit == GIMP_UNIT_POINT) + g_return_val_if_fail (gimp_unit_pixel != NULL, 0.0); + g_return_val_if_fail (gimp_unit_point != NULL, 0.0); + + if (unit == gimp_unit_point ()) return value; - if (unit == GIMP_UNIT_PIXEL) - return (value * gimp_unit_get_factor (GIMP_UNIT_POINT) / resolution); + if (unit == gimp_unit_pixel ()) + return (value * gimp_unit_get_factor (gimp_unit_point ()) / resolution); return (value * - gimp_unit_get_factor (GIMP_UNIT_POINT) / gimp_unit_get_factor (unit)); + gimp_unit_get_factor (gimp_unit_point ()) / gimp_unit_get_factor (unit)); +} + + +/* + * GIMP_TYPE_PARAM_UNIT + */ + +static void gimp_param_unit_class_init (GParamSpecClass *klass); +static void gimp_param_unit_init (GParamSpec *pspec); +static void gimp_param_unit_set_default (GParamSpec *pspec, + GValue *value); +static gboolean gimp_param_unit_validate (GParamSpec *pspec, + GValue *value); + +/** + * gimp_param_unit_get_type: + * + * Reveals the object type + * + * Returns: the #GType for a unit param object + * + * Since: 2.4 + **/ +GType +gimp_param_unit_get_type (void) +{ + static GType type = 0; + + if (! type) + { + const GTypeInfo info = + { + sizeof (GParamSpecClass), + NULL, NULL, + (GClassInitFunc) gimp_param_unit_class_init, + NULL, NULL, + sizeof (GimpParamSpecUnit), + 0, + (GInstanceInitFunc) gimp_param_unit_init + }; + + type = g_type_register_static (G_TYPE_PARAM_OBJECT, + "GimpParamUnit", &info, 0); + } + + return type; +} + +static void +gimp_param_unit_class_init (GParamSpecClass *klass) +{ + klass->value_type = GIMP_TYPE_UNIT; + klass->value_set_default = gimp_param_unit_set_default; + klass->value_validate = gimp_param_unit_validate; +} + +static void +gimp_param_unit_init (GParamSpec *pspec) +{ + GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec); + + uspec->allow_pixel = TRUE; + uspec->allow_percent = TRUE; + uspec->default_value = gimp_unit_inch (); +} + +static void +gimp_param_unit_set_default (GParamSpec *pspec, + GValue *value) +{ + GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec); + + g_value_set_object (value, uspec->default_value); +} + +static gboolean +gimp_param_unit_validate (GParamSpec *pspec, + GValue *value) +{ + GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec); + GObject *unit = value->data[0].v_pointer; + + if (unit == NULL || + (! uspec->allow_percent && value->data[0].v_pointer == gimp_unit_percent ()) || + (! uspec->allow_pixel && value->data[0].v_pointer == gimp_unit_pixel ())) + { + g_clear_object (&unit); + value->data[0].v_pointer = g_object_ref (uspec->default_value); + return TRUE; + } + + return FALSE; } /** - * gimp_unit_is_metric: - * @unit: The unit + * gimp_param_spec_unit: + * @name: Canonical name of the param + * @nick: Nickname of the param + * @blurb: Brief description of param. + * @allow_pixel: Whether "pixels" is an allowed unit. + * @allow_percent: Whether "percent" is an allowed unit. + * @default_value: Unit to use if none is assigned. + * @flags: a combination of #GParamFlags * - * Checks if the given @unit is metric. A simplistic test is used - * that looks at the unit's factor and checks if it is 2.54 multiplied - * by some common powers of 10. Currently it checks for mm, cm, dm, m. + * Creates a param spec to hold a units param. + * See g_param_spec_internal() for more information. * - * See also: gimp_unit_get_factor() + * Returns: (transfer full): a newly allocated #GParamSpec instance * - * Returns: %TRUE if the @unit is metric. - * - * Since: 2.10 + * Since: 2.4 **/ -gboolean -gimp_unit_is_metric (GimpUnit unit) +GParamSpec * +gimp_param_spec_unit (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean allow_pixel, + gboolean allow_percent, + GimpUnit *default_value, + GParamFlags flags) { - gdouble factor; + GimpParamSpecUnit *uspec; - if (unit == GIMP_UNIT_MM) - return TRUE; + g_return_val_if_fail (GIMP_IS_UNIT (default_value), NULL); - factor = gimp_unit_get_factor (unit); + uspec = g_param_spec_internal (GIMP_TYPE_PARAM_UNIT, + name, nick, blurb, flags); - if (factor == 0.0) - return FALSE; + g_return_val_if_fail (uspec, NULL); - return ((ABS (factor - 0.0254) < 1e-7) || /* m */ - (ABS (factor - 0.254) < 1e-6) || /* dm */ - (ABS (factor - 2.54) < 1e-5) || /* cm */ - (ABS (factor - 25.4) < 1e-4)); /* mm */ + uspec->allow_pixel = allow_pixel; + uspec->allow_percent = allow_percent; + uspec->default_value = default_value; + + return G_PARAM_SPEC (uspec); +} + +static gint +print (gchar *buf, + gint len, + gint start, + const gchar *fmt, + ...) +{ + va_list args; + gint printed; + + va_start (args, fmt); + + printed = g_vsnprintf (buf + start, len - start, fmt, args); + if (printed < 0) + printed = len - start; + + va_end (args); + + return printed; } diff --git a/libgimpbase/gimpunit.h b/libgimpbase/gimpunit.h index a88b7629f2..01c8772e4f 100644 --- a/libgimpbase/gimpunit.h +++ b/libgimpbase/gimpunit.h @@ -33,19 +33,61 @@ G_BEGIN_DECLS /** * GIMP_TYPE_UNIT: * - * #GIMP_TYPE_UNIT is a #GType derived from #G_TYPE_INT. + * #GIMP_TYPE_UNIT is a class representing units used for measuring + * dimensions in GIMP. **/ -#define GIMP_TYPE_UNIT (gimp_unit_get_type ()) -#define GIMP_VALUE_HOLDS_UNIT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_UNIT)) +#define GIMP_TYPE_UNIT (gimp_unit_get_type ()) +G_DECLARE_FINAL_TYPE (GimpUnit, gimp_unit, GIMP, UNIT, GObject) -GType gimp_unit_get_type (void) G_GNUC_CONST; +gint32 gimp_unit_get_id (GimpUnit *unit); + +const gchar * gimp_unit_get_identifier (GimpUnit *unit); +gdouble gimp_unit_get_factor (GimpUnit *unit); +gint gimp_unit_get_digits (GimpUnit *unit); +gint gimp_unit_get_scaled_digits (GimpUnit *unit, + gdouble resolution); +const gchar * gimp_unit_get_symbol (GimpUnit *unit); +const gchar * gimp_unit_get_abbreviation (GimpUnit *unit); +const gchar * gimp_unit_get_singular (GimpUnit *unit); +const gchar * gimp_unit_get_plural (GimpUnit *unit); + +gboolean gimp_unit_get_deletion_flag (GimpUnit *unit); +void gimp_unit_set_deletion_flag (GimpUnit *unit, + gboolean deletion_flag); + +GimpUnit * gimp_unit_get_by_id (gint unit_id); +GimpUnit * gimp_unit_pixel (void); +GimpUnit * gimp_unit_mm (void); +GimpUnit * gimp_unit_inch (void); +GimpUnit * gimp_unit_point (void); +GimpUnit * gimp_unit_pica (void); +GimpUnit * gimp_unit_percent (void); + +gboolean gimp_unit_is_built_in (GimpUnit *unit); +gboolean gimp_unit_is_metric (GimpUnit *unit); + + +gchar * gimp_unit_format_string (const gchar *format, + GimpUnit *unit); + +gdouble gimp_pixels_to_units (gdouble pixels, + GimpUnit *unit, + gdouble resolution); +gdouble gimp_units_to_pixels (gdouble value, + GimpUnit *unit, + gdouble resolution); +gdouble gimp_units_to_points (gdouble value, + GimpUnit *unit, + gdouble resolution); /* * GIMP_TYPE_PARAM_UNIT */ +#define GIMP_VALUE_HOLDS_UNIT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_UNIT)) + #define GIMP_TYPE_PARAM_UNIT (gimp_param_unit_get_type ()) #define GIMP_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_UNIT, GimpParamSpecUnit)) #define GIMP_IS_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_UNIT)) @@ -54,65 +96,22 @@ typedef struct _GimpParamSpecUnit GimpParamSpecUnit; struct _GimpParamSpecUnit { - GParamSpecInt parent_instance; + GParamSpecObject parent_instance; - gboolean allow_percent; + gboolean allow_pixel; + gboolean allow_percent; + GimpUnit *default_value; }; -GType gimp_param_unit_get_type (void) G_GNUC_CONST; +GType gimp_param_unit_get_type (void) G_GNUC_CONST; -GParamSpec * gimp_param_spec_unit (const gchar *name, - const gchar *nick, - const gchar *blurb, - gboolean allow_pixels, - gboolean allow_percent, - GimpUnit default_value, - GParamFlags flags); - - - -gint gimp_unit_get_number_of_units (void); -gint gimp_unit_get_number_of_built_in_units (void) G_GNUC_CONST; - -GimpUnit gimp_unit_new (gchar *identifier, - gdouble factor, - gint digits, - gchar *symbol, - gchar *abbreviation, - gchar *singular, - gchar *plural); - -gboolean gimp_unit_get_deletion_flag (GimpUnit unit); -void gimp_unit_set_deletion_flag (GimpUnit unit, - gboolean deletion_flag); - -gdouble gimp_unit_get_factor (GimpUnit unit); - -gint gimp_unit_get_digits (GimpUnit unit); -gint gimp_unit_get_scaled_digits (GimpUnit unit, - gdouble resolution); - -const gchar * gimp_unit_get_identifier (GimpUnit unit); - -const gchar * gimp_unit_get_symbol (GimpUnit unit); -const gchar * gimp_unit_get_abbreviation (GimpUnit unit); -const gchar * gimp_unit_get_singular (GimpUnit unit); -const gchar * gimp_unit_get_plural (GimpUnit unit); - -gchar * gimp_unit_format_string (const gchar *format, - GimpUnit unit); - -gdouble gimp_pixels_to_units (gdouble pixels, - GimpUnit unit, - gdouble resolution); -gdouble gimp_units_to_pixels (gdouble value, - GimpUnit unit, - gdouble resolution); -gdouble gimp_units_to_points (gdouble value, - GimpUnit unit, - gdouble resolution); - -gboolean gimp_unit_is_metric (GimpUnit unit); +GParamSpec * gimp_param_spec_unit (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean allow_pixel, + gboolean allow_percent, + GimpUnit *default_value, + GParamFlags flags); G_END_DECLS diff --git a/libgimpconfig/gimpconfig-deserialize.c b/libgimpconfig/gimpconfig-deserialize.c index cc87c8d0cb..26a20e70f6 100644 --- a/libgimpconfig/gimpconfig-deserialize.c +++ b/libgimpconfig/gimpconfig-deserialize.c @@ -89,6 +89,7 @@ static GTokenType gimp_config_deserialize_value_array (GValue *value, GimpConfig *config, GParamSpec *prop_spec, GScanner *scanner); +static GimpUnit * gimp_config_get_unit_from_identifier (const gchar *identifier); static GTokenType gimp_config_deserialize_unit (GValue *value, GParamSpec *prop_spec, GScanner *scanner); @@ -305,9 +306,10 @@ gimp_config_deserialize_property (GimpConfig *config, } else { - if (G_VALUE_HOLDS_OBJECT (&value) && - G_VALUE_TYPE (&value) != G_TYPE_FILE && - G_VALUE_TYPE (&value) != GEGL_TYPE_COLOR) + if (G_VALUE_HOLDS_OBJECT (&value) && + G_VALUE_TYPE (&value) != G_TYPE_FILE && + G_VALUE_TYPE (&value) != GEGL_TYPE_COLOR && + G_VALUE_TYPE (&value) != GIMP_TYPE_UNIT) { token = gimp_config_deserialize_object (&value, config, prop_spec, @@ -877,6 +879,31 @@ gimp_config_deserialize_value_array (GValue *value, return G_TOKEN_RIGHT_PAREN; } +static GimpUnit * +gimp_config_get_unit_from_identifier (const gchar *identifier) +{ + GimpUnit *unit; + + unit = gimp_unit_get_by_id (GIMP_UNIT_PIXEL); + for (gint i = GIMP_UNIT_PIXEL; unit; i++) + { + if (g_strcmp0 (identifier, gimp_unit_get_identifier (unit)) == 0) + break; + + unit = gimp_unit_get_by_id (i); + } + + if (unit == NULL && g_strcmp0 (identifier, "percent") == 0) + unit = gimp_unit_percent (); + + /* XXX This may return NULL, especially for user-defined units which + * may have disappeared from one session to another. Should we return + * some default unit then? + */ + + return unit; +} + /* This function is entirely sick, so is our method of serializing * units, which we write out as (unit foo bar) instead of * (unit "foo bar"). The assumption that caused this shit was that a @@ -896,7 +923,7 @@ gimp_config_deserialize_unit (GValue *value, gchar *old_cset_identifier_first; gchar *old_cset_identifier_nth; GString *buffer; - GValue src = G_VALUE_INIT; + GimpUnit *unit; GTokenType token; /* parse the next token *before* reconfiguring the scanner, so it @@ -905,7 +932,13 @@ gimp_config_deserialize_unit (GValue *value, token = g_scanner_peek_next_token (scanner); if (token == G_TOKEN_STRING) - return gimp_config_deserialize_any (value, prop_spec, scanner); + { + g_scanner_get_next_token (scanner); + unit = gimp_config_get_unit_from_identifier (scanner->value.v_string); + g_value_set_object (value, unit); + + return G_TOKEN_RIGHT_PAREN; + } old_cset_skip_characters = scanner->config->cset_skip_characters; old_cset_identifier_first = scanner->config->cset_identifier_first; @@ -944,10 +977,8 @@ gimp_config_deserialize_unit (GValue *value, } } - g_value_init (&src, G_TYPE_STRING); - g_value_set_static_string (&src, buffer->str); - g_value_transform (&src, value); - g_value_unset (&src); + unit = gimp_config_get_unit_from_identifier (buffer->str); + g_value_set_object (value, unit); token = G_TOKEN_RIGHT_PAREN; diff --git a/libgimpconfig/gimpconfig-params.c b/libgimpconfig/gimpconfig-params.c index ca1b150a27..df72c10468 100644 --- a/libgimpconfig/gimpconfig-params.c +++ b/libgimpconfig/gimpconfig-params.c @@ -193,17 +193,6 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec) gspec->ui_step_small, gspec->ui_step_big); } - else if (GIMP_IS_PARAM_SPEC_UNIT (pspec)) - { - GimpParamSpecUnit *spec = GIMP_PARAM_SPEC_UNIT (pspec); - GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec); - - copy = gimp_param_spec_unit (name, nick, blurb, - ispec->minimum == GIMP_UNIT_PIXEL, - spec->allow_percent, - ispec->default_value, - flags); - } else { copy = g_param_spec_int (name, nick, blurb, @@ -240,6 +229,16 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec) flags); } } + else if (GIMP_IS_PARAM_SPEC_UNIT (pspec)) + { + GimpParamSpecUnit *spec = GIMP_PARAM_SPEC_UNIT (pspec); + + copy = gimp_param_spec_unit (name, nick, blurb, + spec->allow_pixel, + spec->allow_percent, + spec->default_value, + flags); + } else if (GIMP_IS_PARAM_SPEC_CHOICE (pspec)) { GimpParamSpecChoice *spec = GIMP_PARAM_SPEC_CHOICE (pspec); diff --git a/libgimpconfig/gimpconfig-serialize.c b/libgimpconfig/gimpconfig-serialize.c index 430beff680..f9710c9f4b 100644 --- a/libgimpconfig/gimpconfig-serialize.c +++ b/libgimpconfig/gimpconfig-serialize.c @@ -370,6 +370,20 @@ gimp_config_serialize_property (GimpConfig *config, if (free_color) g_object_unref (color); } + else if (GIMP_VALUE_HOLDS_UNIT (&value)) + { + GimpUnit *unit = g_value_get_object (&value); + + gimp_config_writer_open (writer, param_spec->name); + + if (unit) + gimp_config_writer_printf (writer, "%s", gimp_unit_get_identifier (unit)); + else + gimp_config_writer_printf (writer, "%s", "NULL"); + + success = TRUE; + gimp_config_writer_close (writer); + } else if (G_VALUE_HOLDS_OBJECT (&value) && G_VALUE_TYPE (&value) != G_TYPE_FILE) { diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c index 1ae52b3488..3d6d102030 100644 --- a/libgimpwidgets/gimppropwidgets.c +++ b/libgimpwidgets/gimppropwidgets.c @@ -3461,7 +3461,7 @@ gimp_prop_size_entry_new (GObject *config, gdouble value; gdouble lower; gdouble upper; - GimpUnit unit_value; + GimpUnit *unit_value; gint scaled_resolution; param_spec = find_param_spec (config, property_name, G_STRFUNC); @@ -3483,11 +3483,11 @@ gimp_prop_size_entry_new (GObject *config, g_value_init (&value, unit_param_spec->value_type); - g_value_set_int (&value, GIMP_UNIT_PIXEL); + g_value_set_object (&value, gimp_unit_pixel ()); show_pixels = (g_param_value_validate (unit_param_spec, &value) == FALSE); - g_value_set_int (&value, GIMP_UNIT_PERCENT); + g_value_set_object (&value, gimp_unit_percent ()); show_percent = (g_param_value_validate (unit_param_spec, &value) == FALSE); @@ -3500,12 +3500,12 @@ gimp_prop_size_entry_new (GObject *config, else { unit_param_spec = NULL; - unit_value = GIMP_UNIT_INCH; + unit_value = gimp_unit_inch (); show_pixels = FALSE; show_percent = FALSE; } - if (unit_value != GIMP_UNIT_PIXEL) + if (unit_value != gimp_unit_pixel ()) scaled_resolution = gimp_unit_get_scaled_digits (unit_value, resolution); else scaled_resolution = (gint) resolution; @@ -3584,7 +3584,7 @@ gimp_prop_size_entry_callback (GimpSizeEntry *entry, GParamSpec *unit_param_spec; gdouble value; gboolean value_is_pixel; - GimpUnit unit_value; + GimpUnit *unit_value; param_spec = g_object_get_data (G_OBJECT (entry), "gimp-config-param-spec"); if (! param_spec) @@ -3605,7 +3605,7 @@ gimp_prop_size_entry_callback (GimpSizeEntry *entry, if (unit_param_spec) { - GimpUnit old_unit; + GimpUnit *old_unit; g_object_get (config, unit_param_spec->name, &old_unit, @@ -3693,7 +3693,7 @@ gimp_prop_size_entry_notify_unit (GObject *config, GParamSpec *param_spec, GimpSizeEntry *entry) { - GimpUnit value; + GimpUnit *value; g_object_get (config, param_spec->name, &value, @@ -3783,7 +3783,7 @@ gimp_prop_coordinates_new (GObject *config, GtkWidget *entry; GtkWidget *chainbutton = NULL; - entry = gimp_size_entry_new (2, GIMP_UNIT_INCH, unit_format, + entry = gimp_size_entry_new (2, gimp_unit_inch (), unit_format, FALSE, FALSE, TRUE, 10, update_policy); @@ -3829,7 +3829,7 @@ gimp_prop_coordinates_connect (GObject *config, GParamSpec *unit_param_spec; gdouble x_value, x_lower, x_upper; gdouble y_value, y_lower, y_upper; - GimpUnit unit_value; + GimpUnit *unit_value; gdouble *old_x_value; gdouble *old_y_value; GimpUnit *old_unit_value; @@ -3869,7 +3869,7 @@ gimp_prop_coordinates_connect (GObject *config, else { unit_param_spec = NULL; - unit_value = GIMP_UNIT_INCH; + unit_value = gimp_unit_inch (); } set_param_spec (NULL, @@ -3957,11 +3957,10 @@ gimp_prop_coordinates_connect (GObject *config, g_object_set_data (G_OBJECT (entry), "gimp-config-param-spec-unit", unit_param_spec); - old_unit_value = g_new0 (GimpUnit, 1); - *old_unit_value = unit_value; + old_unit_value = unit_value; g_object_set_data_full (G_OBJECT (entry), "old-unit-value", old_unit_value, - (GDestroyNotify) g_free); + (GDestroyNotify) NULL); g_signal_connect (entry, "unit-changed", G_CALLBACK (gimp_prop_coordinates_callback), @@ -3984,7 +3983,7 @@ gimp_prop_coordinates_callback (GimpSizeEntry *entry, GParamSpec *unit_param_spec; gdouble x_value; gdouble y_value; - GimpUnit unit_value; + GimpUnit *unit_value; gdouble *old_x_value; gdouble *old_y_value; GimpUnit *old_unit_value; @@ -4038,14 +4037,14 @@ gimp_prop_coordinates_callback (GimpSizeEntry *entry, if (*old_x_value == x_value && *old_y_value == y_value && - (old_unit_value == NULL || *old_unit_value == unit_value)) + (old_unit_value == NULL || old_unit_value == unit_value)) return; *old_x_value = x_value; *old_y_value = y_value; if (old_unit_value) - *old_unit_value = unit_value; + old_unit_value = unit_value; if (unit_param_spec) g_object_set (config, @@ -4182,7 +4181,7 @@ gimp_prop_coordinates_notify_unit (GObject *config, GParamSpec *param_spec, GimpSizeEntry *entry) { - GimpUnit value; + GimpUnit *value; g_object_get (config, param_spec->name, &value, @@ -4449,7 +4448,7 @@ gimp_prop_unit_combo_box_new (GObject *config, GParamSpec *param_spec; GtkWidget *combo; GtkTreeModel *model; - GimpUnit unit; + GimpUnit *unit; GValue value = G_VALUE_INIT; gboolean show_pixels; gboolean show_percent; @@ -4461,10 +4460,10 @@ gimp_prop_unit_combo_box_new (GObject *config, g_value_init (&value, param_spec->value_type); - g_value_set_int (&value, GIMP_UNIT_PIXEL); + g_value_set_object (&value, gimp_unit_pixel ()); show_pixels = (g_param_value_validate (param_spec, &value) == FALSE); - g_value_set_int (&value, GIMP_UNIT_PERCENT); + g_value_set_object (&value, gimp_unit_percent ()); show_percent = (g_param_value_validate (param_spec, &value) == FALSE); g_value_unset (&value); @@ -4502,8 +4501,8 @@ gimp_prop_unit_combo_box_callback (GtkWidget *combo, GObject *config) { GParamSpec *param_spec; - GimpUnit value; - GimpUnit v; + GimpUnit *value; + GimpUnit *v; param_spec = get_param_spec (G_OBJECT (combo)); if (! param_spec) @@ -4534,7 +4533,7 @@ gimp_prop_unit_combo_box_notify (GObject *config, GParamSpec *param_spec, GtkWidget *combo) { - GimpUnit unit; + GimpUnit *unit; g_object_get (config, param_spec->name, &unit, diff --git a/libgimpwidgets/gimpquerybox.c b/libgimpwidgets/gimpquerybox.c index 3adf4b85d6..b2f9c6293e 100644 --- a/libgimpwidgets/gimpquerybox.c +++ b/libgimpwidgets/gimpquerybox.c @@ -459,7 +459,7 @@ gimp_query_size_box (const gchar *title, gdouble lower, gdouble upper, gint digits, - GimpUnit unit, + GimpUnit *unit, gdouble resolution, gboolean dot_for_dot, GObject *object, @@ -487,7 +487,7 @@ gimp_query_size_box (const gchar *title, sizeentry = gimp_size_entry_new (1, unit, "%p", TRUE, FALSE, FALSE, 12, GIMP_SIZE_ENTRY_UPDATE_SIZE); if (dot_for_dot) - gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), GIMP_UNIT_PIXEL); + gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), gimp_unit_pixel ()); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0, resolution, FALSE); gimp_size_entry_set_refval_digits (GIMP_SIZE_ENTRY (sizeentry), 0, digits); @@ -669,8 +669,8 @@ size_query_box_response (GtkWidget *widget, gint response_id, QueryBox *query_box) { - gdouble size; - GimpUnit unit; + gdouble size; + GimpUnit *unit; query_box_disconnect (query_box); diff --git a/libgimpwidgets/gimpquerybox.h b/libgimpwidgets/gimpquerybox.h index 515aa50b31..8ad2295d0e 100644 --- a/libgimpwidgets/gimpquerybox.h +++ b/libgimpwidgets/gimpquerybox.h @@ -78,7 +78,7 @@ typedef void (* GimpQueryDoubleCallback) (GtkWidget *query_box, **/ typedef void (* GimpQuerySizeCallback) (GtkWidget *query_box, gdouble size, - GimpUnit unit, + GimpUnit *unit, gpointer data); /** @@ -156,7 +156,7 @@ GtkWidget * gimp_query_size_box (const gchar *title, gdouble lower, gdouble upper, gint digits, - GimpUnit unit, + GimpUnit *unit, gdouble resolution, gboolean dot_for_dot, GObject *object, diff --git a/libgimpwidgets/gimpruler.c b/libgimpwidgets/gimpruler.c index 1d13e74412..006897b5ec 100644 --- a/libgimpwidgets/gimpruler.c +++ b/libgimpwidgets/gimpruler.c @@ -64,7 +64,7 @@ struct _GimpRuler GtkWidget parent_instance; GtkOrientation orientation; - GimpUnit unit; + GimpUnit *unit; gdouble lower; gdouble upper; gdouble position; @@ -162,7 +162,7 @@ static void gimp_ruler_make_pixmap (GimpRuler *ruler); static PangoLayout * gimp_ruler_get_layout (GtkWidget *widget, const gchar *text); static const RulerMetric * - gimp_ruler_get_metric (GimpUnit unit); + gimp_ruler_get_metric (GimpUnit *unit); G_DEFINE_TYPE (GimpRuler, gimp_ruler, GTK_TYPE_WIDGET) @@ -201,8 +201,7 @@ gimp_ruler_class_init (GimpRulerClass *klass) object_props[PROP_UNIT] = gimp_param_spec_unit ("unit", "Unit", "Unit of ruler", - TRUE, TRUE, - GIMP_UNIT_PIXEL, + TRUE, TRUE, gimp_unit_pixel (), GIMP_PARAM_READWRITE); object_props[PROP_LOWER] = g_param_spec_double ("lower", @@ -248,7 +247,7 @@ gimp_ruler_init (GimpRuler *ruler) gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE); ruler->orientation = GTK_ORIENTATION_HORIZONTAL; - ruler->unit = GIMP_UNIT_PIXEL; + ruler->unit = gimp_unit_pixel (); } static void @@ -284,7 +283,7 @@ gimp_ruler_set_property (GObject *object, break; case PROP_UNIT: - gimp_ruler_set_unit (ruler, g_value_get_int (value)); + gimp_ruler_set_unit (ruler, g_value_get_object (value)); break; case PROP_LOWER: @@ -332,7 +331,7 @@ gimp_ruler_get_property (GObject *object, break; case PROP_UNIT: - g_value_set_int (value, ruler->unit); + g_value_set_object (value, ruler->unit); break; case PROP_LOWER: @@ -567,9 +566,10 @@ gimp_ruler_remove_track_widget (GimpRuler *ruler, */ void gimp_ruler_set_unit (GimpRuler *ruler, - GimpUnit unit) + GimpUnit *unit) { g_return_if_fail (GIMP_IS_RULER (ruler)); + g_return_if_fail (GIMP_IS_UNIT (unit)); if (ruler->unit != unit) { @@ -589,7 +589,7 @@ gimp_ruler_set_unit (GimpRuler *ruler, * * Since: 2.8 **/ -GimpUnit +GimpUnit * gimp_ruler_get_unit (GimpRuler *ruler) { g_return_val_if_fail (GIMP_IS_RULER (ruler), 0); @@ -976,7 +976,7 @@ gimp_ruler_draw_ticks (GimpRuler *ruler) gint text_size; gint pos; gdouble max_size; - GimpUnit unit; + GimpUnit *unit; PangoLayout *layout; PangoRectangle logical_rect, ink_rect; const RulerMetric *ruler_metric; @@ -1070,7 +1070,7 @@ gimp_ruler_draw_ticks (GimpRuler *ruler) gdouble subd_incr; /* hack to get proper subdivisions at full pixels */ - if (unit == GIMP_UNIT_PIXEL && scale == 1 && i == 1) + if (unit == gimp_unit_pixel () && scale == 1 && i == 1) subd_incr = 1.0; else subd_incr = ((gdouble) ruler_metric->ruler_scale[scale] / @@ -1080,7 +1080,7 @@ gimp_ruler_draw_ticks (GimpRuler *ruler) continue; /* don't subdivide pixels */ - if (unit == GIMP_UNIT_PIXEL && subd_incr < 1.0) + if (unit == gimp_unit_pixel () && subd_incr < 1.0) continue; /* Calculate the length of the tickmarks. Make sure that @@ -1362,9 +1362,9 @@ gimp_ruler_get_layout (GtkWidget *widget, #define FACTOR_EQUAL(u, f) (ABS (f - gimp_unit_get_factor (u)) < FACTOR_EPSILON) static const RulerMetric * -gimp_ruler_get_metric (GimpUnit unit) +gimp_ruler_get_metric (GimpUnit *unit) { - if (unit == GIMP_UNIT_INCH) + if (unit == gimp_unit_inch ()) { return &ruler_metric_inches; } diff --git a/libgimpwidgets/gimpruler.h b/libgimpwidgets/gimpruler.h index dee879cc4f..bf826d1d76 100644 --- a/libgimpwidgets/gimpruler.h +++ b/libgimpwidgets/gimpruler.h @@ -37,8 +37,8 @@ void gimp_ruler_remove_track_widget (GimpRuler *ruler, GtkWidget *widget); void gimp_ruler_set_unit (GimpRuler *ruler, - GimpUnit unit); -GimpUnit gimp_ruler_get_unit (GimpRuler *ruler); + GimpUnit *unit); +GimpUnit * gimp_ruler_get_unit (GimpRuler *ruler); void gimp_ruler_set_position (GimpRuler *ruler, gdouble position); gdouble gimp_ruler_get_position (GimpRuler *ruler); diff --git a/libgimpwidgets/gimpsizeentry.c b/libgimpwidgets/gimpsizeentry.c index e0851243db..f11d1fe179 100644 --- a/libgimpwidgets/gimpsizeentry.c +++ b/libgimpwidgets/gimpsizeentry.c @@ -109,7 +109,7 @@ typedef struct _GimpSizeEntryPrivate gint number_of_fields; GtkWidget *unit_combo; - GimpUnit unit; + GimpUnit *unit; gboolean menu_show_pixels; gboolean menu_show_percent; @@ -128,7 +128,7 @@ static void gimp_size_entry_update_refval (GimpSizeEntryField *gsef, static void gimp_size_entry_refval_callback (GtkAdjustment *adjustment, gpointer data); static void gimp_size_entry_update_unit (GimpSizeEntry *gse, - GimpUnit unit); + GimpUnit *unit); static void gimp_size_entry_unit_callback (GtkWidget *widget, GimpSizeEntry *sizeentry); static void gimp_size_entry_attach_eevl (GtkSpinButton *spin_button, @@ -192,7 +192,7 @@ gimp_size_entry_init (GimpSizeEntry *gse) priv = gimp_size_entry_get_instance_private (gse); - priv->unit = GIMP_UNIT_PIXEL; + priv->unit = gimp_unit_pixel (); priv->menu_show_pixels = TRUE; priv->menu_show_percent = TRUE; priv->show_refval = FALSE; @@ -269,7 +269,7 @@ gimp_size_entry_finalize (GObject *object) **/ GtkWidget * gimp_size_entry_new (gint number_of_fields, - GimpUnit unit, + GimpUnit *unit, const gchar *unit_format, gboolean menu_show_pixels, gboolean menu_show_percent, @@ -333,8 +333,8 @@ gimp_size_entry_new (gint number_of_fields, (update_policy == GIMP_SIZE_ENTRY_UPDATE_SIZE) ? 0 : 3; gsef->stop_recursion = 0; - digits = ((unit == GIMP_UNIT_PIXEL) ? - gsef->refval_digits : ((unit == GIMP_UNIT_PERCENT) ? + digits = ((unit == gimp_unit_pixel ()) ? + gsef->refval_digits : ((unit == gimp_unit_percent ()) ? 2 : GIMP_SIZE_ENTRY_DIGITS (unit))); gsef->value_adjustment = gtk_adjustment_new (gsef->value, @@ -391,7 +391,7 @@ gimp_size_entry_new (gint number_of_fields, gtk_widget_show (gsef->refval_spinbutton); } - if (priv->menu_show_pixels && (unit == GIMP_UNIT_PIXEL) && + if (priv->menu_show_pixels && (unit == gimp_unit_pixel ()) && ! priv->show_refval) gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton), gsef->refval_digits); @@ -507,15 +507,15 @@ gimp_size_entry_add_field (GimpSizeEntry *gse, gsef); } - digits = ((priv->unit == GIMP_UNIT_PIXEL) ? gsef->refval_digits : - (priv->unit == GIMP_UNIT_PERCENT) ? 2 : + digits = ((priv->unit == gimp_unit_pixel ()) ? gsef->refval_digits : + (priv->unit == gimp_unit_percent ()) ? 2 : GIMP_SIZE_ENTRY_DIGITS (priv->unit)); gtk_spin_button_set_digits (GTK_SPIN_BUTTON (value_spinbutton), digits); if (priv->menu_show_pixels && !priv->show_refval && - (priv->unit == GIMP_UNIT_PIXEL)) + (priv->unit == gimp_unit_pixel ())) { gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton), gsef->refval_digits); @@ -773,32 +773,26 @@ gimp_size_entry_set_value_boundaries (GimpSizeEntry *gse, break; case GIMP_SIZE_ENTRY_UPDATE_SIZE: - switch (priv->unit) - { - case GIMP_UNIT_PIXEL: - gimp_size_entry_set_refval_boundaries (gse, field, - gsef->min_value, - gsef->max_value); - break; - case GIMP_UNIT_PERCENT: - gimp_size_entry_set_refval_boundaries (gse, field, - gsef->lower + - (gsef->upper - gsef->lower) * - gsef->min_value / 100, - gsef->lower + - (gsef->upper - gsef->lower) * - gsef->max_value / 100); - break; - default: - gimp_size_entry_set_refval_boundaries (gse, field, - gsef->min_value * - gsef->resolution / - gimp_unit_get_factor (priv->unit), - gsef->max_value * - gsef->resolution / - gimp_unit_get_factor (priv->unit)); - break; - } + if (priv->unit == gimp_unit_pixel ()) + gimp_size_entry_set_refval_boundaries (gse, field, + gsef->min_value, + gsef->max_value); + else if (priv->unit == gimp_unit_percent ()) + gimp_size_entry_set_refval_boundaries (gse, field, + gsef->lower + + (gsef->upper - gsef->lower) * + gsef->min_value / 100, + gsef->lower + + (gsef->upper - gsef->lower) * + gsef->max_value / 100); + else + gimp_size_entry_set_refval_boundaries (gse, field, + gsef->min_value * + gsef->resolution / + gimp_unit_get_factor (priv->unit), + gsef->max_value * + gsef->resolution / + gimp_unit_get_factor (priv->unit)); break; case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION: @@ -871,23 +865,16 @@ gimp_size_entry_update_value (GimpSizeEntryField *gsef, break; case GIMP_SIZE_ENTRY_UPDATE_SIZE: - switch (priv->unit) - { - case GIMP_UNIT_PIXEL: - gsef->refval = value; - break; - case GIMP_UNIT_PERCENT: - gsef->refval = - CLAMP (gsef->lower + (gsef->upper - gsef->lower) * value / 100, - gsef->min_refval, gsef->max_refval); - break; - default: - gsef->refval = - CLAMP (value * gsef->resolution / - gimp_unit_get_factor (priv->unit), - gsef->min_refval, gsef->max_refval); - break; - } + if (priv->unit == gimp_unit_pixel ()) + gsef->refval = value; + else if (priv->unit == gimp_unit_percent ()) + gsef->refval = CLAMP (gsef->lower + (gsef->upper - gsef->lower) * value / 100, + gsef->min_refval, gsef->max_refval); + else + gsef->refval = CLAMP (value * gsef->resolution / + gimp_unit_get_factor (priv->unit), + gsef->min_refval, gsef->max_refval); + if (priv->show_refval) gtk_adjustment_set_value (gsef->refval_adjustment, gsef->refval); break; @@ -1018,32 +1005,26 @@ gimp_size_entry_set_refval_boundaries (GimpSizeEntry *gse, break; case GIMP_SIZE_ENTRY_UPDATE_SIZE: - switch (priv->unit) - { - case GIMP_UNIT_PIXEL: - gimp_size_entry_set_value_boundaries (gse, field, - gsef->min_refval, - gsef->max_refval); - break; - case GIMP_UNIT_PERCENT: - gimp_size_entry_set_value_boundaries (gse, field, - 100 * (gsef->min_refval - - gsef->lower) / - (gsef->upper - gsef->lower), - 100 * (gsef->max_refval - - gsef->lower) / - (gsef->upper - gsef->lower)); - break; - default: - gimp_size_entry_set_value_boundaries (gse, field, - gsef->min_refval * - gimp_unit_get_factor (priv->unit) / - gsef->resolution, - gsef->max_refval * - gimp_unit_get_factor (priv->unit) / - gsef->resolution); - break; - } + if (priv->unit == gimp_unit_pixel ()) + gimp_size_entry_set_value_boundaries (gse, field, + gsef->min_refval, + gsef->max_refval); + else if (priv->unit == gimp_unit_percent ()) + gimp_size_entry_set_value_boundaries (gse, field, + 100 * (gsef->min_refval - + gsef->lower) / + (gsef->upper - gsef->lower), + 100 * (gsef->max_refval - + gsef->lower) / + (gsef->upper - gsef->lower)); + else + gimp_size_entry_set_value_boundaries (gse, field, + gsef->min_refval * + gimp_unit_get_factor (priv->unit) / + gsef->resolution, + gsef->max_refval * + gimp_unit_get_factor (priv->unit) / + gsef->resolution); break; case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION: @@ -1102,7 +1083,7 @@ gimp_size_entry_set_refval_digits (GimpSizeEntry *gse, if (priv->show_refval) gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->refval_spinbutton), gsef->refval_digits); - else if (priv->unit == GIMP_UNIT_PIXEL) + else if (priv->unit == gimp_unit_pixel ()) gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton), gsef->refval_digits); } @@ -1157,23 +1138,16 @@ gimp_size_entry_update_refval (GimpSizeEntryField *gsef, break; case GIMP_SIZE_ENTRY_UPDATE_SIZE: - switch (priv->unit) - { - case GIMP_UNIT_PIXEL: - gsef->value = refval; - break; - case GIMP_UNIT_PERCENT: - gsef->value = - CLAMP (100 * (refval - gsef->lower) / (gsef->upper - gsef->lower), - gsef->min_value, gsef->max_value); - break; - default: - gsef->value = - CLAMP (refval * gimp_unit_get_factor (priv->unit) / - gsef->resolution, - gsef->min_value, gsef->max_value); - break; - } + if (priv->unit == gimp_unit_pixel ()) + gsef->value = refval; + else if (priv->unit == gimp_unit_percent ()) + gsef->value = CLAMP (100 * (refval - gsef->lower) / (gsef->upper - gsef->lower), + gsef->min_value, gsef->max_value); + else + gsef->value = CLAMP (refval * gimp_unit_get_factor (priv->unit) / + gsef->resolution, + gsef->min_value, gsef->max_value); + gtk_adjustment_set_value (gsef->value_adjustment, gsef->value); break; @@ -1252,12 +1226,12 @@ gimp_size_entry_refval_callback (GtkAdjustment *adjustment, * * Returns: (transfer none): The sizeentry's unit. **/ -GimpUnit +GimpUnit * gimp_size_entry_get_unit (GimpSizeEntry *gse) { GimpSizeEntryPrivate *priv; - g_return_val_if_fail (GIMP_IS_SIZE_ENTRY (gse), GIMP_UNIT_INCH); + g_return_val_if_fail (GIMP_IS_SIZE_ENTRY (gse), gimp_unit_inch ()); priv = gimp_size_entry_get_instance_private (gse); @@ -1266,7 +1240,7 @@ gimp_size_entry_get_unit (GimpSizeEntry *gse) static void gimp_size_entry_update_unit (GimpSizeEntry *gse, - GimpUnit unit) + GimpUnit *unit) { GimpSizeEntryPrivate *priv = gimp_size_entry_get_instance_private (gse); GimpSizeEntryField *gsef; @@ -1284,10 +1258,10 @@ gimp_size_entry_update_unit (GimpSizeEntry *gse, if (priv->update_policy == GIMP_SIZE_ENTRY_UPDATE_SIZE) { - if (unit == GIMP_UNIT_PIXEL) + if (unit == gimp_unit_pixel ()) gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton), gsef->refval_digits + digits); - else if (unit == GIMP_UNIT_PERCENT) + else if (unit == gimp_unit_percent ()) gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton), 2 + digits); else @@ -1296,8 +1270,7 @@ gimp_size_entry_update_unit (GimpSizeEntry *gse, } else if (priv->update_policy == GIMP_SIZE_ENTRY_UPDATE_RESOLUTION) { - digits = (gimp_unit_get_digits (GIMP_UNIT_INCH) - - gimp_unit_get_digits (unit)); + digits = (gimp_unit_get_digits (gimp_unit_inch ()) - gimp_unit_get_digits (unit)); gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton), MAX (3 + digits, 3)); } @@ -1325,7 +1298,7 @@ gimp_size_entry_update_unit (GimpSizeEntry *gse, **/ void gimp_size_entry_set_unit (GimpSizeEntry *gse, - GimpUnit unit) + GimpUnit *unit) { GimpSizeEntryPrivate *priv; @@ -1333,8 +1306,8 @@ gimp_size_entry_set_unit (GimpSizeEntry *gse, priv = gimp_size_entry_get_instance_private (gse); - g_return_if_fail (priv->menu_show_pixels || (unit != GIMP_UNIT_PIXEL)); - g_return_if_fail (priv->menu_show_percent || (unit != GIMP_UNIT_PERCENT)); + g_return_if_fail (priv->menu_show_pixels || (unit != gimp_unit_pixel ())); + g_return_if_fail (priv->menu_show_percent || (unit != gimp_unit_percent ())); gimp_unit_combo_box_set_active (GIMP_UNIT_COMBO_BOX (priv->unit_combo), unit); gimp_size_entry_update_unit (gse, unit); @@ -1345,7 +1318,7 @@ gimp_size_entry_unit_callback (GtkWidget *widget, GimpSizeEntry *gse) { GimpSizeEntryPrivate *priv; - GimpUnit new_unit; + GimpUnit *new_unit; new_unit = gimp_unit_combo_box_get_active (GIMP_UNIT_COMBO_BOX (widget)); @@ -1449,14 +1422,14 @@ gimp_size_entry_eevl_input_callback (GtkSpinButton *spinner, gtk_widget_error_bell (GTK_WIDGET (spinner)); return GTK_INPUT_ERROR; } - else if (result.dimension != 1 && priv->unit != GIMP_UNIT_PERCENT) + else if (result.dimension != 1 && priv->unit != gimp_unit_percent ()) { g_printerr ("ERROR: result has wrong dimension (expected 1, got %d)\n", result.dimension); gtk_widget_error_bell (GTK_WIDGET (spinner)); return GTK_INPUT_ERROR; } - else if (result.dimension != 0 && priv->unit == GIMP_UNIT_PERCENT) + else if (result.dimension != 0 && priv->unit == gimp_unit_percent ()) { g_printerr ("ERROR: result has wrong dimension (expected 0, got %d)\n", result.dimension); @@ -1470,20 +1443,20 @@ gimp_size_entry_eevl_input_callback (GtkSpinButton *spinner, GtkAdjustment *adj; gdouble val; - switch (priv->unit) + if (priv->unit == gimp_unit_pixel ()) { - case GIMP_UNIT_PIXEL: ui_unit.value = gsef->resolution; ui_unit.dimension = 1; - break; - case GIMP_UNIT_PERCENT: + } + else if (priv->unit == gimp_unit_percent ()) + { ui_unit.value = 1.0; ui_unit.dimension = 0; - break; - default: + } + else + { ui_unit.value = gimp_unit_get_factor(priv->unit); ui_unit.dimension = 1; - break; } *return_val = result.value * ui_unit.value; @@ -1517,7 +1490,8 @@ gimp_size_entry_eevl_unit_resolver (const gchar *identifier, GimpSizeEntryField *gsef = (GimpSizeEntryField *) data; GimpSizeEntryPrivate *priv; gboolean resolve_default_unit = (identifier == NULL); - GimpUnit unit; + GimpUnit *unit = gimp_unit_pixel (); + gint i = 1; g_return_val_if_fail (gsef, FALSE); g_return_val_if_fail (factor != NULL, FALSE); @@ -1528,23 +1502,16 @@ gimp_size_entry_eevl_unit_resolver (const gchar *identifier, *offset = 0.0; - for (unit = 0; - unit <= gimp_unit_get_number_of_units (); - unit++) + while (unit != NULL) { - /* Hack to handle percent within the loop */ - if (unit == gimp_unit_get_number_of_units ()) - unit = GIMP_UNIT_PERCENT; - if ((resolve_default_unit && unit == priv->unit) || (identifier && (strcmp (gimp_unit_get_symbol (unit), identifier) == 0 || strcmp (gimp_unit_get_abbreviation (unit), identifier) == 0))) { - switch (unit) + if (unit == gimp_unit_percent ()) { - case GIMP_UNIT_PERCENT: - if (priv->unit == GIMP_UNIT_PERCENT) + if (priv->unit == gimp_unit_percent ()) { factor->value = 1; factor->dimension = 0; @@ -1559,15 +1526,17 @@ gimp_size_entry_eevl_unit_resolver (const gchar *identifier, } /* return here, don't perform percentage conversion */ return TRUE; - case GIMP_UNIT_PIXEL: - factor->value = gsef->resolution; - break; - default: - factor->value = gimp_unit_get_factor (unit); - break; + } + else if (unit == gimp_unit_pixel ()) + { + factor->value = gsef->resolution; + } + else + { + factor->value = gimp_unit_get_factor (unit); } - if (priv->unit == GIMP_UNIT_PERCENT) + if (priv->unit == gimp_unit_percent ()) { /* map non-percentages onto percent */ factor->value = gsef->upper/(100*gsef->resolution); @@ -1581,6 +1550,12 @@ gimp_size_entry_eevl_unit_resolver (const gchar *identifier, /* We are done */ return TRUE; } + + unit = gimp_unit_get_by_id (i++); + + /* Hack to handle percent within the loop */ + if (unit == NULL && unit != gimp_unit_percent ()) + unit = gimp_unit_percent (); } return FALSE; diff --git a/libgimpwidgets/gimpsizeentry.h b/libgimpwidgets/gimpsizeentry.h index 5b053c2319..16541f61fc 100644 --- a/libgimpwidgets/gimpsizeentry.h +++ b/libgimpwidgets/gimpsizeentry.h @@ -58,7 +58,7 @@ struct _GimpSizeEntryClass /* For information look into the C source or the html documentation */ GtkWidget * gimp_size_entry_new (gint number_of_fields, - GimpUnit unit, + GimpUnit *unit, const gchar *unit_format, gboolean menu_show_pixels, gboolean menu_show_percent, @@ -116,9 +116,9 @@ void gimp_size_entry_set_refval (GimpSizeEntry *gse, gint field, gdouble refval); -GimpUnit gimp_size_entry_get_unit (GimpSizeEntry *gse); +GimpUnit * gimp_size_entry_get_unit (GimpSizeEntry *gse); void gimp_size_entry_set_unit (GimpSizeEntry *gse, - GimpUnit unit); + GimpUnit *unit); void gimp_size_entry_show_unit_menu (GimpSizeEntry *gse, gboolean show); diff --git a/libgimpwidgets/gimpunitcombobox.c b/libgimpwidgets/gimpunitcombobox.c index b2ab392f81..d323cc4e96 100644 --- a/libgimpwidgets/gimpunitcombobox.c +++ b/libgimpwidgets/gimpunitcombobox.c @@ -173,13 +173,13 @@ gimp_unit_combo_box_new_with_model (GimpUnitStore *model) * * Returns: (transfer none): The selected #GimpUnit. **/ -GimpUnit +GimpUnit * gimp_unit_combo_box_get_active (GimpUnitComboBox *combo) { - GtkTreeIter iter; - gint unit; + GtkTreeIter iter; + GimpUnit *unit; - g_return_val_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo), -1); + g_return_val_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo), NULL); gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter); @@ -187,7 +187,7 @@ gimp_unit_combo_box_get_active (GimpUnitComboBox *combo) GIMP_UNIT_STORE_UNIT, &unit, -1); - return (GimpUnit) unit; + return unit; } /** @@ -199,7 +199,7 @@ gimp_unit_combo_box_get_active (GimpUnitComboBox *combo) **/ void gimp_unit_combo_box_set_active (GimpUnitComboBox *combo, - GimpUnit unit) + GimpUnit *unit) { GtkTreeModel *model; GtkTreeIter iter; @@ -215,13 +215,13 @@ gimp_unit_combo_box_set_active (GimpUnitComboBox *combo, iter_valid; iter_valid = gtk_tree_model_iter_next (model, &iter)) { - gint iter_unit; + GimpUnit *iter_unit; gtk_tree_model_get (model, &iter, GIMP_UNIT_STORE_UNIT, &iter_unit, -1); - if (unit == (GimpUnit) iter_unit) + if (unit == iter_unit) { gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter); break; diff --git a/libgimpwidgets/gimpunitcombobox.h b/libgimpwidgets/gimpunitcombobox.h index e5b38c955d..66e6be8860 100644 --- a/libgimpwidgets/gimpunitcombobox.h +++ b/libgimpwidgets/gimpunitcombobox.h @@ -68,9 +68,9 @@ GType gimp_unit_combo_box_get_type (void) G_GNUC_CONST; GtkWidget * gimp_unit_combo_box_new (void); GtkWidget * gimp_unit_combo_box_new_with_model (GimpUnitStore *model); -GimpUnit gimp_unit_combo_box_get_active (GimpUnitComboBox *combo); +GimpUnit * gimp_unit_combo_box_get_active (GimpUnitComboBox *combo); void gimp_unit_combo_box_set_active (GimpUnitComboBox *combo, - GimpUnit unit); + GimpUnit *unit); G_END_DECLS diff --git a/libgimpwidgets/gimpunitstore.c b/libgimpwidgets/gimpunitstore.c index 14924f2f0f..2a64db90b5 100644 --- a/libgimpwidgets/gimpunitstore.c +++ b/libgimpwidgets/gimpunitstore.c @@ -51,17 +51,17 @@ enum struct _GimpUnitStorePrivate { - gint num_values; - gboolean has_pixels; - gboolean has_percent; + gint num_values; + gboolean has_pixels; + gboolean has_percent; - gchar *short_format; - gchar *long_format; + gchar *short_format; + gchar *long_format; - gdouble *values; - gdouble *resolutions; + gdouble *values; + gdouble *resolutions; - GimpUnit synced_unit; + GimpUnitID synced_ID; }; #define GET_PRIVATE(obj) (((GimpUnitStore *) (obj))->priv) @@ -194,7 +194,7 @@ gimp_unit_store_init (GimpUnitStore *store) private->has_percent = FALSE; private->short_format = g_strdup ("%a"); private->long_format = g_strdup ("%p"); - private->synced_unit = gimp_unit_get_number_of_units () - 1; + private->synced_ID = 0; } static void @@ -340,43 +340,41 @@ gimp_unit_store_get_iter (GtkTreeModel *tree_model, { GimpUnitStorePrivate *private = GET_PRIVATE (tree_model); gint index; - GimpUnit unit; + GimpUnit *unit = NULL; g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE); index = gtk_tree_path_get_indices (path)[0]; - unit = index; - if (! private->has_pixels) - unit++; + index++; + else if (index == 0) + unit = gimp_unit_pixel (); - if (private->has_percent) + if (unit == NULL && private->has_percent) { - unit--; - if (private->has_pixels) { - if (index == 0) - unit = GIMP_UNIT_PIXEL; - else if (index == 1) - unit = GIMP_UNIT_PERCENT; + if (index == 1) + unit = gimp_unit_percent (); } - else + else if (index == 0) { - if (index == 0) - unit = GIMP_UNIT_PERCENT; + unit = gimp_unit_percent (); } + index--; } - if ((unit >= 0 && unit < gimp_unit_get_number_of_units ()) || - ((unit == GIMP_UNIT_PERCENT && private->has_percent))) + if (unit == NULL) + unit = gimp_unit_get_by_id (index); + + if (unit != NULL) { - iter->user_data = GINT_TO_POINTER (unit); - return TRUE; + iter->user_data = unit; + private->synced_ID = MAX (private->synced_ID, gimp_unit_get_id (unit)); } - return FALSE; + return (unit != NULL); } static GtkTreePath * @@ -385,10 +383,10 @@ gimp_unit_store_get_path (GtkTreeModel *tree_model, { GimpUnitStorePrivate *private = GET_PRIVATE (tree_model); GtkTreePath *path = gtk_tree_path_new (); - GimpUnit unit = GPOINTER_TO_INT (iter->user_data); + GimpUnit *unit = iter->user_data; gint index; - index = unit; + index = gimp_unit_get_id (unit); if (! private->has_pixels) index--; @@ -399,14 +397,14 @@ gimp_unit_store_get_path (GtkTreeModel *tree_model, if (private->has_pixels) { - if (unit == GIMP_UNIT_PIXEL) + if (unit == gimp_unit_pixel ()) index = 0; - else if (unit == GIMP_UNIT_PERCENT) + else if (unit == gimp_unit_percent ()) index = 1; } else { - if (unit == GIMP_UNIT_PERCENT) + if (unit == gimp_unit_percent ()) index = 0; } } @@ -423,7 +421,7 @@ gimp_unit_store_tree_model_get_value (GtkTreeModel *tree_model, GValue *value) { GimpUnitStorePrivate *private = GET_PRIVATE (tree_model); - GimpUnit unit; + GimpUnit *unit; g_return_if_fail (column >= 0 && column < GIMP_UNIT_STORE_UNIT_COLUMNS + private->num_values); @@ -433,63 +431,59 @@ gimp_unit_store_tree_model_get_value (GtkTreeModel *tree_model, column_types[column] : G_TYPE_DOUBLE); - unit = GPOINTER_TO_INT (iter->user_data); + unit = iter->user_data; - if ((unit >= 0 && unit < gimp_unit_get_number_of_units ()) || - ((unit == GIMP_UNIT_PERCENT && private->has_percent))) + switch (column) { - switch (column) - { - case GIMP_UNIT_STORE_UNIT: - g_value_set_int (value, unit); - break; - case GIMP_UNIT_STORE_UNIT_FACTOR: - g_value_set_double (value, gimp_unit_get_factor (unit)); - break; - case GIMP_UNIT_STORE_UNIT_DIGITS: - g_value_set_int (value, gimp_unit_get_digits (unit)); - break; - case GIMP_UNIT_STORE_UNIT_IDENTIFIER: - g_value_set_static_string (value, gimp_unit_get_identifier (unit)); - break; - case GIMP_UNIT_STORE_UNIT_SYMBOL: - g_value_set_static_string (value, gimp_unit_get_symbol (unit)); - break; - case GIMP_UNIT_STORE_UNIT_ABBREVIATION: - g_value_set_static_string (value, gimp_unit_get_abbreviation (unit)); - break; - case GIMP_UNIT_STORE_UNIT_SINGULAR: - g_value_set_static_string (value, gimp_unit_get_singular (unit)); - break; - case GIMP_UNIT_STORE_UNIT_PLURAL: - g_value_set_static_string (value, gimp_unit_get_plural (unit)); - break; - case GIMP_UNIT_STORE_UNIT_SHORT_FORMAT: - g_value_take_string (value, - gimp_unit_format_string (private->short_format, - unit)); - break; - case GIMP_UNIT_STORE_UNIT_LONG_FORMAT: - g_value_take_string (value, - gimp_unit_format_string (private->long_format, - unit)); - break; + case GIMP_UNIT_STORE_UNIT: + g_value_set_object (value, unit); + break; + case GIMP_UNIT_STORE_UNIT_FACTOR: + g_value_set_double (value, gimp_unit_get_factor (unit)); + break; + case GIMP_UNIT_STORE_UNIT_DIGITS: + g_value_set_int (value, gimp_unit_get_digits (unit)); + break; + case GIMP_UNIT_STORE_UNIT_IDENTIFIER: + g_value_set_static_string (value, gimp_unit_get_identifier (unit)); + break; + case GIMP_UNIT_STORE_UNIT_SYMBOL: + g_value_set_static_string (value, gimp_unit_get_symbol (unit)); + break; + case GIMP_UNIT_STORE_UNIT_ABBREVIATION: + g_value_set_static_string (value, gimp_unit_get_abbreviation (unit)); + break; + case GIMP_UNIT_STORE_UNIT_SINGULAR: + g_value_set_static_string (value, gimp_unit_get_singular (unit)); + break; + case GIMP_UNIT_STORE_UNIT_PLURAL: + g_value_set_static_string (value, gimp_unit_get_plural (unit)); + break; + case GIMP_UNIT_STORE_UNIT_SHORT_FORMAT: + g_value_take_string (value, + gimp_unit_format_string (private->short_format, + unit)); + break; + case GIMP_UNIT_STORE_UNIT_LONG_FORMAT: + g_value_take_string (value, + gimp_unit_format_string (private->long_format, + unit)); + break; - default: - column -= GIMP_UNIT_STORE_UNIT_COLUMNS; - if (unit == GIMP_UNIT_PIXEL) - { - g_value_set_double (value, private->values[column]); - } - else if (private->resolutions[column]) - { - g_value_set_double (value, - private->values[column] * - gimp_unit_get_factor (unit) / - private->resolutions[column]); - } - break; + default: + column -= GIMP_UNIT_STORE_UNIT_COLUMNS; + if (unit == gimp_unit_pixel ()) + { + g_value_set_double (value, private->values[column]); } + else if (private->resolutions[column]) + { + g_value_set_double (value, + private->values[column] * + gimp_unit_get_factor (unit) / + private->resolutions[column]); + } + break; } } @@ -498,28 +492,18 @@ gimp_unit_store_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter) { GimpUnitStorePrivate *private = GET_PRIVATE (tree_model); - GimpUnit unit = GPOINTER_TO_INT (iter->user_data); + GimpUnit *unit = iter->user_data; - if (unit == GIMP_UNIT_PIXEL && private->has_percent) - { - unit = GIMP_UNIT_PERCENT; - } - else if (unit == GIMP_UNIT_PERCENT) - { - unit = GIMP_UNIT_INCH; - } - else if (unit >= 0 && unit < gimp_unit_get_number_of_units () - 1) - { - unit++; - } + if (unit == gimp_unit_pixel () && private->has_percent) + unit = gimp_unit_percent (); + else if (unit == gimp_unit_percent () || unit == gimp_unit_pixel ()) + unit = gimp_unit_inch (); else - { - return FALSE; - } + unit = gimp_unit_get_by_id (gimp_unit_get_id (unit) + 1); - iter->user_data = GINT_TO_POINTER (unit); + iter->user_data = unit; - return TRUE; + return (unit != NULL); } static gboolean @@ -528,26 +512,20 @@ gimp_unit_store_iter_children (GtkTreeModel *tree_model, GtkTreeIter *parent) { GimpUnitStorePrivate *private = GET_PRIVATE (tree_model); - GimpUnit unit; + GimpUnit *unit; /* this is a list, nodes have no children */ if (parent) return FALSE; if (private->has_pixels) - { - unit = GIMP_UNIT_PIXEL; - } + unit = gimp_unit_pixel (); else if (private->has_percent) - { - unit = GIMP_UNIT_PERCENT; - } + unit = gimp_unit_percent (); else - { - unit = GIMP_UNIT_INCH; - } + unit = gimp_unit_inch (); - iter->user_data = GINT_TO_POINTER (unit); + iter->user_data = unit; return TRUE; } @@ -563,13 +541,18 @@ static gint gimp_unit_store_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter) { - GimpUnitStorePrivate *private = GET_PRIVATE (tree_model); - gint n_children; + GimpUnitStorePrivate *private = GET_PRIVATE (tree_model); + GimpUnit *unit; + gint n_children = GIMP_UNIT_END; if (iter) return 0; - n_children = gimp_unit_get_number_of_units (); + do + unit = gimp_unit_get_by_id (n_children++); + while (unit != NULL); + + n_children--; if (! private->has_pixels) n_children--; @@ -596,30 +579,30 @@ gimp_unit_store_iter_nth_child (GtkTreeModel *tree_model, if (n >= 0 && n < n_children) { - GimpUnit unit = n; + gint index = n; if (! private->has_pixels) - unit++; + index++; if (private->has_percent) { - unit--; + index--; if (private->has_pixels) { if (n == 0) - unit = GIMP_UNIT_PIXEL; + index = GIMP_UNIT_PIXEL; else if (n == 1) - unit = GIMP_UNIT_PERCENT; + index = GIMP_UNIT_PERCENT; } else { if (n == 0) - unit = GIMP_UNIT_PERCENT; + index = GIMP_UNIT_PERCENT; } } - iter->user_data = GINT_TO_POINTER (unit); + iter->user_data = gimp_unit_get_by_id (index); return TRUE; } @@ -852,7 +835,7 @@ gimp_unit_store_set_resolutions (GimpUnitStore *store, gdouble gimp_unit_store_get_nth_value (GimpUnitStore *store, - GimpUnit unit, + GimpUnit *unit, gint index) { GimpUnitStorePrivate *private; @@ -865,7 +848,7 @@ gimp_unit_store_get_nth_value (GimpUnitStore *store, g_return_val_if_fail (index >= 0 && index < private->num_values, 0.0); - iter.user_data = GINT_TO_POINTER (unit); + iter.user_data = unit; gimp_unit_store_tree_model_get_value (GTK_TREE_MODEL (store), &iter, @@ -877,7 +860,7 @@ gimp_unit_store_get_nth_value (GimpUnitStore *store, void gimp_unit_store_get_values (GimpUnitStore *store, - GimpUnit unit, + GimpUnit *unit, gdouble *first_value, ...) { @@ -920,14 +903,14 @@ _gimp_unit_store_sync_units (GimpUnitStore *store) iter_valid; iter_valid = gtk_tree_model_iter_next (model, &iter)) { - gint unit; + GimpUnit *unit; gtk_tree_model_get (model, &iter, GIMP_UNIT_STORE_UNIT, &unit, -1); - if (unit != GIMP_UNIT_PERCENT && - unit > private->synced_unit) + if (unit != gimp_unit_percent () && + gimp_unit_get_id (unit) > private->synced_ID) { GtkTreePath *path; @@ -935,7 +918,7 @@ _gimp_unit_store_sync_units (GimpUnitStore *store) gtk_tree_model_row_inserted (model, path, &iter); gtk_tree_path_free (path); } - } - private->synced_unit = gimp_unit_get_number_of_units () - 1; + g_object_unref (unit); + } } diff --git a/libgimpwidgets/gimpunitstore.h b/libgimpwidgets/gimpunitstore.h index e6da7d1691..63ee209a27 100644 --- a/libgimpwidgets/gimpunitstore.h +++ b/libgimpwidgets/gimpunitstore.h @@ -105,10 +105,10 @@ void gimp_unit_store_set_resolutions (GimpUnitStore *store, gdouble first_resolution, ...); gdouble gimp_unit_store_get_nth_value (GimpUnitStore *store, - GimpUnit unit, + GimpUnit *unit, gint index); void gimp_unit_store_get_values (GimpUnitStore *store, - GimpUnit unit, + GimpUnit *unit, gdouble *first_value, ...); diff --git a/libgimpwidgets/gimpwidgets.c b/libgimpwidgets/gimpwidgets.c index 81c9219ae1..0435ee6f4a 100644 --- a/libgimpwidgets/gimpwidgets.c +++ b/libgimpwidgets/gimpwidgets.c @@ -449,7 +449,7 @@ gimp_coordinates_chainbutton_toggled (GimpChainButton *button, * Returns: (transfer full): The new #GimpSizeEntry. **/ GtkWidget * -gimp_coordinates_new (GimpUnit unit, +gimp_coordinates_new (GimpUnit *unit, const gchar *unit_format, gboolean menu_show_pixels, gboolean menu_show_percent, @@ -507,7 +507,7 @@ gimp_coordinates_new (GimpUnit unit, gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), (update_policy == GIMP_SIZE_ENTRY_UPDATE_RESOLUTION) || (menu_show_pixels == FALSE) ? - GIMP_UNIT_INCH : GIMP_UNIT_PIXEL); + gimp_unit_inch () : gimp_unit_pixel ()); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1, yres, TRUE); diff --git a/libgimpwidgets/gimpwidgets.h b/libgimpwidgets/gimpwidgets.h index 47da13de77..5842ed1019 100644 --- a/libgimpwidgets/gimpwidgets.h +++ b/libgimpwidgets/gimpwidgets.h @@ -160,7 +160,7 @@ GtkWidget * gimp_random_seed_new (guint32 *seed, #define GIMP_COORDINATES_CHAINBUTTON(sizeentry) \ (g_object_get_data (G_OBJECT (sizeentry), "chainbutton")) -GtkWidget * gimp_coordinates_new (GimpUnit unit, +GtkWidget * gimp_coordinates_new (GimpUnit *unit, const gchar *unit_format, gboolean menu_show_pixels, gboolean menu_show_percent, diff --git a/pdb/app.pl b/pdb/app.pl index 6937e66b8a..a7d582e5ec 100644 --- a/pdb/app.pl +++ b/pdb/app.pl @@ -553,15 +553,14 @@ CODE } } elsif ($pdbtype eq 'unit') { - $typeinfo[0] = 'GIMP_UNIT_PIXEL' unless defined $typeinfo[0]; - $allow_pixels = $typeinfo[0] eq 'GIMP_UNIT_PIXEL' ? TRUE : FALSE; + $allow_pixel = exists $arg->{allow_pixel} ? TRUE : FALSE; $allow_percent = exists $arg->{allow_percent} ? TRUE : FALSE; - $default = exists $arg->{default} ? $arg->{default} : $typeinfo[0]; + $default = exists $arg->{default} ? $arg->{default} : 'gimp_unit_inch ()'; $pspec = < '2', GIMP_TRANSFORM_RESIZE_CROP_WITH_ASPECT => '3' } }, - GimpUnit => + GimpUnitID => { contig => 1, header => 'libgimpbase/gimpbaseenums.h', symbols => [ qw(GIMP_UNIT_PIXEL GIMP_UNIT_INCH GIMP_UNIT_MM diff --git a/pdb/groups/display.pdb b/pdb/groups/display.pdb index c02a099622..298e020867 100644 --- a/pdb/groups/display.pdb +++ b/pdb/groups/display.pdb @@ -74,7 +74,7 @@ HELP { gimp_image_flush (image); - display = gimp_create_display (gimp, image, GIMP_UNIT_PIXEL, 1.0, NULL); + display = gimp_create_display (gimp, image, gimp_unit_pixel (), 1.0, NULL); if (display) { diff --git a/pdb/groups/gimprc.pdb b/pdb/groups/gimprc.pdb index 8995cdd57b..c3175b9674 100644 --- a/pdb/groups/gimprc.pdb +++ b/pdb/groups/gimprc.pdb @@ -149,13 +149,13 @@ CODE sub get_default_unit { $blurb = 'Get the default unit (taken from the user\'s locale).'; - $help = 'Returns the default unit\'s integer ID.'; + $help = 'Returns the default unit.'; &std_pdb_misc; $since = '2.4'; @outargs = ( - { name => 'unit_id', type => 'unit', + { name => 'unit', type => 'unit', desc => 'Default unit' } ); @@ -164,7 +164,7 @@ sub get_default_unit { "core/gimp-utils.h") ], code => <<'CODE' { - unit_id = gimp_get_default_unit (); + unit = gimp_get_default_unit (); } CODE ); diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb index 11db7ce8ee..14184f5803 100644 --- a/pdb/groups/image.pdb +++ b/pdb/groups/image.pdb @@ -2607,7 +2607,7 @@ HELP @inargs = ( { name => 'image', type => 'image', desc => 'The image' }, - { name => 'unit', type => 'unit (min GIMP_UNIT_INCH)', + { name => 'unit', type => 'unit', desc => 'The new image unit' } ); diff --git a/pdb/groups/unit.pdb b/pdb/groups/unit.pdb index bcbc61185e..5380ef55da 100644 --- a/pdb/groups/unit.pdb +++ b/pdb/groups/unit.pdb @@ -16,67 +16,75 @@ # "Perlized" from C source by Manish Singh -sub unit_get_number_of_units { - $blurb = 'Returns the number of units.'; - - $help = 'This procedure returns the number of defined units.'; - - &mitch_pdb_misc('1999'); - - $lib_private = 1; - - @outargs = ( - { name => 'num_units', type => 'int32', libdef => 'GIMP_UNIT_END', - desc => 'The number of units' } - ); - - %invoke = ( - code => <<'CODE' -{ - num_units = _gimp_unit_get_number_of_units (gimp); -} -CODE - ); -} - -sub unit_get_number_of_built_in_units { - $blurb = 'Returns the number of built-in units.'; +sub unit_get_data { + $blurb = "Returns the various data pertaining to a given unit ID."; $help = <<'HELP'; -This procedure returns the number of defined units built-in to GIMP. +This procedure returns all properties making up an unit. +It is only meant for internal usage to query non built-in units and it +is a programming error to use it directly, in particular for any of the built-in units. HELP - &mitch_pdb_misc('1999'); + &jehan_pdb_misc('2023'); $lib_private = 1; + @inargs = ( + { name => 'unit_id', type => 'int32', + desc => "The unit's integer ID" } + ); + @outargs = ( - { name => 'num_units', type => 'int32', libdef => 'GIMP_UNIT_END', - desc => 'The number of built-in units' } + { name => 'identifier', type => 'string', + desc => "The unit's textual identifier" }, + { name => 'factor', type => 'float', + desc => "The unit's factor" }, + { name => 'digits', type => 'int32', + desc => "The unit's number of digits" }, + { name => 'symbol', type => 'string', + desc => "The unit's symbol" }, + { name => 'abbreviation', type => 'string', + desc => "The unit's abbreviation" }, + { name => 'singular', type => 'string', + desc => "The unit's singular form" }, + { name => 'plural', type => 'string', + desc => "The unit's plural form" } ); %invoke = ( code => <<'CODE' { - num_units = _gimp_unit_get_number_of_built_in_units (gimp); + if (unit_id >= 0) + { + GimpUnit *unit = gimp_unit_get_by_id (unit_id); + + if (unit != NULL) + { + identifier = g_strdup (gimp_unit_get_identifier (unit)); + factor = gimp_unit_get_factor (unit); + digits = gimp_unit_get_digits (unit); + symbol = g_strdup (gimp_unit_get_symbol (unit)); + abbreviation = g_strdup (gimp_unit_get_abbreviation (unit)); + singular = g_strdup (gimp_unit_get_singular (unit)); + plural = g_strdup (gimp_unit_get_plural (unit)); + } + } } CODE ); } sub unit_new { - $blurb = "Creates a new unit and returns it's integer ID."; + $blurb = "Creates a new unit."; $help = <<'HELP'; -This procedure creates a new unit and returns it's integer ID. Note that the -new unit will have it's deletion flag set to TRUE, so you will have to set it +This procedure creates a new unit and returns it. Note that the new unit +will have it's deletion flag set to TRUE, so you will have to set it to FALSE with gimp_unit_set_deletion_flag() to make it persistent. HELP &mitch_pdb_misc('1999'); - $lib_private = 1; - @inargs = ( { name => 'identifier', type => 'string', non_empty => 1, desc => "The new unit's identifier" }, @@ -95,16 +103,15 @@ HELP ); @outargs = ( - { name => 'unit_id', type => 'unit', - desc => "The new unit's ID", - libdef => 'GIMP_UNIT_INCH' } + { name => 'unit', type => 'unit', + desc => "The new unit" } ); %invoke = ( code => <<'CODE' { - unit_id = _gimp_unit_new (gimp, identifier, factor, digits, - symbol, abbreviation, singular, plural); + unit = _gimp_unit_new (gimp, identifier, factor, digits, + symbol, abbreviation, singular, plural); } CODE ); @@ -123,8 +130,8 @@ HELP $lib_private = 1; @inargs = ( - { name => 'unit_id', type => 'unit', - desc => "The unit's integer ID" } + { name => 'unit', type => 'unit', + desc => "The unit" } ); @outargs = ( @@ -135,7 +142,7 @@ HELP %invoke = ( code => <<'CODE' { - deletion_flag = _gimp_unit_get_deletion_flag (gimp, unit_id); + deletion_flag = gimp_unit_get_deletion_flag (unit); } CODE ); @@ -155,8 +162,8 @@ HELP $lib_private = 1; @inargs = ( - { name => 'unit_id', type => 'unit', - desc => "The unit's integer ID" }, + { name => 'unit', type => 'unit', + desc => "The unit" }, { name => 'deletion_flag', type => 'boolean', desc => 'The new deletion flag of the unit' } ); @@ -164,242 +171,26 @@ HELP %invoke = ( code => <<'CODE' { - _gimp_unit_set_deletion_flag (gimp, unit_id, deletion_flag); + gimp_unit_set_deletion_flag (unit, deletion_flag); } CODE ); } -sub unit_get_identifier { - $blurb = "Returns the textual identifier of the unit."; - - $help = <<'HELP'; -This procedure returns the textual identifier of the unit. For built-in units -it will be the english singular form of the unit's name. For user-defined units -this should equal to the singular form. -HELP - - &mitch_pdb_misc('1999'); - - $lib_private = 1; - - @inargs = ( - { name => 'unit_id', type => 'unit', - desc => "The unit's integer ID" } - ); - - @outargs = ( - { name => 'identifier', type => 'string', - desc => "The unit's textual identifier" } - ); - - %invoke = ( - code => <<'CODE' -{ - identifier = g_strdup (_gimp_unit_get_identifier (gimp, unit_id)); -} -CODE - ); -} - -sub unit_get_factor { - $blurb = "Returns the factor of the unit."; - - $help = <<'HELP'; -This procedure returns the unit's factor which indicates how many units make up -an inch. Note that asking for the factor of "pixels" will produce an error. -HELP - - &mitch_pdb_misc('1999'); - - $lib_private = 1; - - @inargs = ( - { name => 'unit_id', type => 'unit', - desc => "The unit's integer ID" } - ); - - @outargs = ( - { name => 'factor', type => 'float', - desc => "The unit's factor" } - ); - - %invoke = ( - code => <<'CODE' -{ - factor = _gimp_unit_get_factor (gimp, unit_id); -} -CODE - ); -} - -sub unit_get_digits { - $blurb = "Returns the number of digits of the unit."; - - $help = <<'HELP'; -This procedure returns the number of digits you should provide in input or -output functions to get approximately the same accuracy as with two digits and -inches. Note that asking for the digits of "pixels" will produce an error. -HELP - - &mitch_pdb_misc('1999'); - - $lib_private = 1; - - @inargs = ( - { name => 'unit_id', type => 'unit', - desc => "The unit's integer ID" } - ); - - @outargs = ( - { name => 'digits', type => 'int32', - desc => "The unit's number of digits" } - ); - - %invoke = ( - code => <<'CODE' -{ - digits = _gimp_unit_get_digits (gimp, unit_id); -} -CODE - ); -} - -sub unit_get_symbol { - $blurb = "Returns the symbol of the unit."; - - $help = <<'HELP'; -This procedure returns the symbol of the unit ("''" for inches). -HELP - - &mitch_pdb_misc('1999'); - - $lib_private = 1; - - @inargs = ( - { name => 'unit_id', type => 'unit', - desc => "The unit's integer ID" } - ); - - @outargs = ( - { name => 'symbol', type => 'string', - desc => "The unit's symbol" } - ); - - %invoke = ( - code => <<'CODE' -{ - symbol = g_strdup (_gimp_unit_get_symbol (gimp, unit_id)); -} -CODE - ); -} - -sub unit_get_abbreviation { - $blurb = "Returns the abbreviation of the unit."; - - $help = <<'HELP'; -This procedure returns the abbreviation of the unit ("in" for inches). -HELP - - &mitch_pdb_misc('1999'); - - $lib_private = 1; - - @inargs = ( - { name => 'unit_id', type => 'unit', - desc => "The unit's integer ID" } - ); - - @outargs = ( - { name => 'abbreviation', type => 'string', - desc => "The unit's abbreviation" } - ); - - %invoke = ( - code => <<'CODE' -{ - abbreviation = g_strdup (_gimp_unit_get_abbreviation (gimp, unit_id)); -} -CODE - ); -} - -sub unit_get_singular { - $blurb = "Returns the singular form of the unit."; - $help = 'This procedure returns the singular form of the unit.'; - - &mitch_pdb_misc('1999'); - - $lib_private = 1; - - @inargs = ( - { name => 'unit_id', type => 'unit', - desc => "The unit's integer ID" } - ); - - @outargs = ( - { name => 'singular', type => 'string', - desc => "The unit's singular form" } - ); - - %invoke = ( - code => <<'CODE' -{ - singular = g_strdup (_gimp_unit_get_singular (gimp, unit_id)); -} -CODE - ); -} - -sub unit_get_plural { - $blurb = "Returns the plural form of the unit."; - $help = 'This procedure returns the plural form of the unit.'; - - &mitch_pdb_misc('1999'); - - $lib_private = 1; - - @inargs = ( - { name => 'unit_id', type => 'unit', - desc => "The unit's integer ID" } - ); - - @outargs = ( - { name => 'plural', type => 'string', - desc => "The unit's plural form" } - ); - - %invoke = ( - code => <<'CODE' -{ - plural = g_strdup (_gimp_unit_get_plural (gimp, unit_id)); -} -CODE - ); -} - - @headers = qw("libgimpbase/gimpbase.h" + "core/gimp.h" "core/gimpunit.h"); -@procs = qw(unit_get_number_of_units - unit_get_number_of_built_in_units - unit_new +@procs = qw(unit_new + unit_get_data unit_get_deletion_flag - unit_set_deletion_flag - unit_get_identifier - unit_get_factor - unit_get_digits - unit_get_symbol - unit_get_abbreviation - unit_get_singular - unit_get_plural); + unit_set_deletion_flag); %exports = (app => [@procs], lib => [@procs]); $desc = 'Units'; - -$lib_private = 1; +$doc_title = 'gimpunit'; +$doc_short_desc = 'Operations on units.'; +$doc_long_desc = 'Provides operations on units, a collection of predefined units and functions to create new units.'; 1; diff --git a/pdb/pdb.pl b/pdb/pdb.pl index 90c5f51bea..9151b7c49a 100644 --- a/pdb/pdb.pl +++ b/pdb/pdb.pl @@ -484,14 +484,15 @@ package Gimp::CodeGen::pdb; unit => { name => 'UNIT', gtype => 'GIMP_TYPE_UNIT', - type => 'GimpUnit ', - const_type => 'GimpUnit ', - init_value => 'GIMP_UNIT_PIXEL', + type => 'GimpUnit *', + const_type => 'GimpUnit *', + init_value => 'NULL', out_annotate => '(transfer none)', - get_value_func => '$var = g_value_get_int ($value)', - dup_value_func => '$var = GIMP_VALUES_GET_INT ($value)', - set_value_func => 'g_value_set_int ($value, $var)', - take_value_func => 'g_value_set_int ($value, $var)' }, + get_value_func => '$var = g_value_get_object ($value)', + dup_value_func => '$var = GIMP_VALUES_GET_UNIT ($value)', + set_value_func => 'g_value_set_object ($value, $var)', + take_value_func => 'g_value_set_object ($value, $var)', + headers => [ qw("libgimpbase/gimpbase.h") ] }, resource => { name => 'RESOURCE', gtype => 'GIMP_TYPE_RESOURCE', diff --git a/plug-ins/common/border-average.c b/plug-ins/common/border-average.c index 155e143cb0..f723ccf716 100644 --- a/plug-ins/common/border-average.c +++ b/plug-ins/common/border-average.c @@ -145,7 +145,7 @@ border_average_create_procedure (GimpPlugIn *plug_in, gimp_procedure_add_unit_aux_argument (procedure, "thickness-unit", _("Thickness unit of measure"), _("Border size unit of measure"), - TRUE, TRUE, GIMP_UNIT_PIXEL, + TRUE, TRUE, gimp_unit_pixel (), GIMP_PARAM_READWRITE); gimp_procedure_add_choice_argument (procedure, "bucket-exponent", _("Bucket Si_ze"), diff --git a/plug-ins/common/checkerboard.c b/plug-ins/common/checkerboard.c index ba5a761e48..52af2b1a3e 100644 --- a/plug-ins/common/checkerboard.c +++ b/plug-ins/common/checkerboard.c @@ -148,7 +148,7 @@ checkerboard_create_procedure (GimpPlugIn *plug_in, gimp_procedure_add_unit_aux_argument (procedure, "check-size-unit", _("Check size unit of measure"), _("Check size unit of measure"), - TRUE, TRUE, GIMP_UNIT_PIXEL, + TRUE, TRUE, gimp_unit_pixel (), GIMP_PARAM_READWRITE); } diff --git a/plug-ins/common/file-pdf-export.c b/plug-ins/common/file-pdf-export.c index ed4c2570b2..73b1ecfbf0 100644 --- a/plug-ins/common/file-pdf-export.c +++ b/plug-ins/common/file-pdf-export.c @@ -1522,7 +1522,7 @@ drawText (GimpLayer *layer, gint y; GeglColor *color; gdouble rgb[3]; - GimpUnit unit; + GimpUnit *unit; gdouble size; GimpTextHintStyle hinting; GimpTextJustification j; diff --git a/plug-ins/common/file-pdf-load.c b/plug-ins/common/file-pdf-load.c index 27a6e011f9..6c418f8b61 100644 --- a/plug-ins/common/file-pdf-load.c +++ b/plug-ins/common/file-pdf-load.c @@ -333,8 +333,8 @@ pdf_extract (GimpProcedure *procedure, extracted_dimensions->width = width; extracted_dimensions->height = height; - extracted_dimensions->width_unit = GIMP_UNIT_POINT; - extracted_dimensions->height_unit = GIMP_UNIT_POINT; + extracted_dimensions->width_unit = gimp_unit_point (); + extracted_dimensions->height_unit = gimp_unit_point (); extracted_dimensions->exact_width = TRUE; extracted_dimensions->exact_height = TRUE; extracted_dimensions->correct_ratio = TRUE; @@ -535,7 +535,7 @@ pdf_load_thumb (GimpProcedure *procedure, } /* Thumbnail resolution: 100.0. */ - scale = 100.0 / gimp_unit_get_factor (GIMP_UNIT_POINT); + scale = 100.0 / gimp_unit_get_factor (gimp_unit_point ()); width *= scale; height *= scale; diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c index 5f96e79e3c..1ee4d60b55 100644 --- a/plug-ins/common/file-png.c +++ b/plug-ins/common/file-png.c @@ -985,7 +985,7 @@ load_image (GFile *file, gimp_image_set_resolution ((GimpImage *) image, (gdouble) xres * 0.0254, (gdouble) yres * 0.0254); - gimp_image_set_unit ((GimpImage *) image, GIMP_UNIT_MM); + gimp_image_set_unit ((GimpImage *) image, gimp_unit_mm ()); *resolution_loaded = TRUE; break; diff --git a/plug-ins/common/file-ps.c b/plug-ins/common/file-ps.c index d84707fd6f..7a781de130 100644 --- a/plug-ins/common/file-ps.c +++ b/plug-ins/common/file-ps.c @@ -618,8 +618,8 @@ ps_extract (GimpProcedure *procedure, { extracted_dimensions->width = (gdouble) bbox_x1 - bbox_x0; extracted_dimensions->height = (gdouble) bbox_y1 - bbox_y0; - extracted_dimensions->width_unit = GIMP_UNIT_POINT; - extracted_dimensions->height_unit = GIMP_UNIT_POINT; + extracted_dimensions->width_unit = gimp_unit_point (); + extracted_dimensions->height_unit = gimp_unit_point (); extracted_dimensions->exact_width = TRUE; extracted_dimensions->exact_height = TRUE; extracted_dimensions->correct_ratio = TRUE; @@ -1564,10 +1564,10 @@ static void ps_set_save_size (GObject *config, GimpImage *image) { - gdouble xres, yres, factor, iw, ih; - guint width, height; - GimpUnit unit; - gboolean unit_mm = FALSE; + gdouble xres, yres, factor, iw, ih; + guint width, height; + GimpUnit *unit; + gboolean unit_mm = FALSE; gimp_image_get_resolution (image, &xres, &yres); diff --git a/plug-ins/common/file-svg.c b/plug-ins/common/file-svg.c index 3fc7292ade..54b9a945ca 100644 --- a/plug-ins/common/file-svg.c +++ b/plug-ins/common/file-svg.c @@ -74,6 +74,7 @@ static GList * svg_query_procedures (GimpPlugIn *plug_in); static GimpProcedure * svg_create_procedure (GimpPlugIn *plug_in, const gchar *name); +static GimpUnit * svg_rsvg_to_gimp_unit (RsvgUnit unit); static gboolean svg_extract (GimpProcedure *procedure, GimpRunMode run_mode, GFile *file, @@ -197,29 +198,29 @@ svg_create_procedure (GimpPlugIn *plug_in, return procedure; } -static GimpUnit -svg_rsvg_unit_to_gimp_unit (RsvgUnit unit) +static GimpUnit * +svg_rsvg_to_gimp_unit (RsvgUnit unit) { switch (unit) { case RSVG_UNIT_PERCENT: - return GIMP_UNIT_PERCENT; + return gimp_unit_percent (); case RSVG_UNIT_PX: - return GIMP_UNIT_PIXEL; + return gimp_unit_pixel (); case RSVG_UNIT_IN: - return GIMP_UNIT_INCH; + return gimp_unit_inch (); case RSVG_UNIT_MM: - return GIMP_UNIT_MM; + return gimp_unit_mm (); case RSVG_UNIT_PT: - return GIMP_UNIT_POINT; + return gimp_unit_point (); case RSVG_UNIT_PC: - return GIMP_UNIT_PICA; + return gimp_unit_pica (); case RSVG_UNIT_CM: case RSVG_UNIT_EM: case RSVG_UNIT_EX: /*case RSVG_UNIT_CH:*/ default: - return -1; + return NULL; } } @@ -355,14 +356,14 @@ svg_extract (GimpProcedure *procedure, /* "width" and "height" present: the viewbox has no importance (it's only * a coordinate remapping. */ - if (svg_rsvg_unit_to_gimp_unit (out_width.unit) != -1 && - svg_rsvg_unit_to_gimp_unit (out_height.unit) != -1) + if (svg_rsvg_to_gimp_unit (out_width.unit) != NULL && + svg_rsvg_to_gimp_unit (out_height.unit) != NULL) { /* Best case scenario: we know all these units. */ extracted_dimensions->width = out_width.length; - extracted_dimensions->width_unit = svg_rsvg_unit_to_gimp_unit (out_width.unit); + extracted_dimensions->width_unit = svg_rsvg_to_gimp_unit (out_width.unit); extracted_dimensions->height = out_height.length; - extracted_dimensions->height_unit = svg_rsvg_unit_to_gimp_unit (out_height.unit); + extracted_dimensions->height_unit = svg_rsvg_to_gimp_unit (out_height.unit); extracted_dimensions->exact_width = TRUE; extracted_dimensions->exact_height = TRUE; @@ -377,8 +378,8 @@ svg_extract (GimpProcedure *procedure, &extracted_dimensions->width, &extracted_dimensions->height)) { - extracted_dimensions->width_unit = GIMP_UNIT_PIXEL; - extracted_dimensions->height_unit = GIMP_UNIT_PIXEL; + extracted_dimensions->width_unit = gimp_unit_pixel (); + extracted_dimensions->height_unit = gimp_unit_pixel (); extracted_dimensions->exact_width = FALSE; extracted_dimensions->exact_height = FALSE; } @@ -390,8 +391,8 @@ svg_extract (GimpProcedure *procedure, &extracted_dimensions->width, &extracted_dimensions->height)) { - extracted_dimensions->width_unit = GIMP_UNIT_PERCENT; - extracted_dimensions->height_unit = GIMP_UNIT_PERCENT; + extracted_dimensions->width_unit = gimp_unit_percent (); + extracted_dimensions->height_unit = gimp_unit_percent (); } else if (out_width.unit == out_height.unit) { @@ -400,8 +401,8 @@ svg_extract (GimpProcedure *procedure, */ extracted_dimensions->width = out_width.length; extracted_dimensions->height = out_height.length; - extracted_dimensions->width_unit = GIMP_UNIT_PERCENT; - extracted_dimensions->height_unit = GIMP_UNIT_PERCENT; + extracted_dimensions->width_unit = gimp_unit_percent (); + extracted_dimensions->height_unit = gimp_unit_percent (); } else { @@ -423,10 +424,10 @@ svg_extract (GimpProcedure *procedure, { /* Only a viewbox, so dimensions have a ratio, but no units. */ extracted_dimensions->width = out_width.length; - extracted_dimensions->width_unit = GIMP_UNIT_PERCENT; + extracted_dimensions->width_unit = gimp_unit_percent (); extracted_dimensions->exact_width = FALSE; extracted_dimensions->height = out_height.length; - extracted_dimensions->height_unit = GIMP_UNIT_PERCENT; + extracted_dimensions->height_unit = gimp_unit_percent (); extracted_dimensions->exact_height = FALSE; extracted_dimensions->correct_ratio = TRUE; } diff --git a/plug-ins/common/file-wmf.c b/plug-ins/common/file-wmf.c index 117e5375e5..78c41cc621 100644 --- a/plug-ins/common/file-wmf.c +++ b/plug-ins/common/file-wmf.c @@ -241,10 +241,10 @@ wmf_extract (GimpProcedure *procedure, } extracted_dimensions->width = width; - extracted_dimensions->width_unit = GIMP_UNIT_PERCENT; + extracted_dimensions->width_unit = gimp_unit_percent (); extracted_dimensions->exact_width = guessed ? FALSE : TRUE; extracted_dimensions->height = height; - extracted_dimensions->height_unit = GIMP_UNIT_PERCENT; + extracted_dimensions->height_unit = gimp_unit_percent (); extracted_dimensions->exact_height = guessed ? FALSE : TRUE; extracted_dimensions->correct_ratio = guessed ? FALSE : TRUE; diff --git a/plug-ins/common/grid.c b/plug-ins/common/grid.c index 3419b7cd9f..99447eeb14 100644 --- a/plug-ins/common/grid.c +++ b/plug-ins/common/grid.c @@ -770,7 +770,7 @@ dialog (GimpImage *image, GtkWidget *space; GtkWidget *offset; GtkWidget *chain_button; - GimpUnit unit; + GimpUnit *unit; gint d_width; gint d_height; gdouble xres; @@ -867,7 +867,7 @@ dialog (GimpImage *image, gtk_widget_show (width); /* set the unit back to pixels, since most times we will want pixels */ - gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (width), GIMP_UNIT_PIXEL); + gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (width), gimp_unit_pixel ()); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 0, xres, TRUE); @@ -938,7 +938,7 @@ dialog (GimpImage *image, gtk_box_pack_start (GTK_BOX (vbox), space, FALSE, FALSE, 0); gtk_widget_show (space); - gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (space), GIMP_UNIT_PIXEL); + gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (space), gimp_unit_pixel ()); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 0, xres, TRUE); @@ -1003,7 +1003,7 @@ dialog (GimpImage *image, gtk_box_pack_start (GTK_BOX (vbox), offset, FALSE, FALSE, 0); gtk_widget_show (offset); - gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (offset), GIMP_UNIT_PIXEL); + gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (offset), gimp_unit_pixel ()); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 0, xres, TRUE); diff --git a/plug-ins/common/smooth-palette.c b/plug-ins/common/smooth-palette.c index e9b86c3ba9..9c50ed8fec 100644 --- a/plug-ins/common/smooth-palette.c +++ b/plug-ins/common/smooth-palette.c @@ -468,7 +468,7 @@ dialog (GimpProcedure *procedure, GtkWidget *dlg; GtkWidget *sizeentry; GimpImage *image; - GimpUnit unit; + GimpUnit *unit; gdouble xres, yres; gint width; gint height; diff --git a/plug-ins/common/unit-editor.c b/plug-ins/common/unit-editor.c index b1984265cc..572f68caa6 100644 --- a/plug-ins/common/unit-editor.c +++ b/plug-ins/common/unit-editor.c @@ -78,8 +78,8 @@ static GimpValueArray * editor_run (GimpProcedure *procedure GimpProcedureConfig *config, gpointer run_data); -static GimpUnit new_unit_dialog (GtkWindow *main_window, - GimpUnit template); +static GimpUnit * new_unit_dialog (GtkWindow *main_window, + GimpUnit *template); static void on_app_activate (GApplication *gapp, gpointer user_data); @@ -218,7 +218,7 @@ on_app_activate (GApplication *gapp, gpointer user_data) G_TYPE_STRING, /* ABBREVIATION */ G_TYPE_STRING, /* SINGULAR */ G_TYPE_STRING, /* PLURAL */ - GIMP_TYPE_UNIT, /* UNIT */ + G_TYPE_OBJECT, /* UNIT */ G_TYPE_BOOLEAN); /* USER_UNIT */ self->tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store)); @@ -409,9 +409,9 @@ editor_run (GimpProcedure *procedure, return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL); } -static GimpUnit +static GimpUnit * new_unit_dialog (GtkWindow *main_window, - GimpUnit template) + GimpUnit *template) { GtkWidget *dialog; GtkWidget *grid; @@ -426,7 +426,7 @@ new_unit_dialog (GtkWindow *main_window, GtkWidget *singular_entry; GtkWidget *plural_entry; - GimpUnit unit = GIMP_UNIT_PIXEL; + GimpUnit *unit = NULL; dialog = gimp_dialog_new (_("Add a New Unit"), PLUG_IN_ROLE, GTK_WIDGET (main_window), GTK_DIALOG_MODAL, @@ -451,7 +451,7 @@ new_unit_dialog (GtkWindow *main_window, gtk_widget_show (grid); entry = identifier_entry = gtk_entry_new (); - if (template != GIMP_UNIT_PIXEL) + if (template != gimp_unit_pixel ()) { gtk_entry_set_text (GTK_ENTRY (entry), gimp_unit_get_identifier (template)); @@ -462,7 +462,7 @@ new_unit_dialog (GtkWindow *main_window, gimp_help_set_help_data (entry, gettext (columns[IDENTIFIER].help), NULL); - factor_adj = gtk_adjustment_new ((template != GIMP_UNIT_PIXEL) ? + factor_adj = gtk_adjustment_new ((template != gimp_unit_pixel ()) ? gimp_unit_get_factor (template) : 1.0, GIMP_MIN_RESOLUTION, GIMP_MAX_RESOLUTION, 0.01, 0.1, 0.0); @@ -474,7 +474,7 @@ new_unit_dialog (GtkWindow *main_window, gimp_help_set_help_data (spinbutton, gettext (columns[FACTOR].help), NULL); - digits_adj = gtk_adjustment_new ((template != GIMP_UNIT_PIXEL) ? + digits_adj = gtk_adjustment_new ((template != gimp_unit_pixel ()) ? gimp_unit_get_digits (template) : 2.0, 0, 5, 1, 1, 0); spinbutton = gimp_spin_button_new (digits_adj, 0, 0); @@ -486,7 +486,7 @@ new_unit_dialog (GtkWindow *main_window, gimp_help_set_help_data (spinbutton, gettext (columns[DIGITS].help), NULL); entry = symbol_entry = gtk_entry_new (); - if (template != GIMP_UNIT_PIXEL) + if (template != gimp_unit_pixel ()) { gtk_entry_set_text (GTK_ENTRY (entry), gimp_unit_get_symbol (template)); @@ -498,7 +498,7 @@ new_unit_dialog (GtkWindow *main_window, gimp_help_set_help_data (entry, gettext (columns[SYMBOL].help), NULL); entry = abbreviation_entry = gtk_entry_new (); - if (template != GIMP_UNIT_PIXEL) + if (template != gimp_unit_pixel ()) { gtk_entry_set_text (GTK_ENTRY (entry), gimp_unit_get_abbreviation (template)); @@ -510,7 +510,7 @@ new_unit_dialog (GtkWindow *main_window, gimp_help_set_help_data (entry, gettext (columns[ABBREVIATION].help), NULL); entry = singular_entry = gtk_entry_new (); - if (template != GIMP_UNIT_PIXEL) + if (template != gimp_unit_pixel ()) { gtk_entry_set_text (GTK_ENTRY (entry), gimp_unit_get_singular (template)); @@ -522,7 +522,7 @@ new_unit_dialog (GtkWindow *main_window, gimp_help_set_help_data (entry, gettext (columns[SINGULAR].help), NULL); entry = plural_entry = gtk_entry_new (); - if (template != GIMP_UNIT_PIXEL) + if (template != gimp_unit_pixel ()) { gtk_entry_set_text (GTK_ENTRY (entry), gimp_unit_get_plural (template)); @@ -605,11 +605,11 @@ new_unit_action (GSimpleAction *action, gpointer user_data) { GimpUnitEditor *self = GIMP_UNIT_EDITOR (user_data); - GimpUnit unit; + GimpUnit *unit; - unit = new_unit_dialog (self->window, GIMP_UNIT_PIXEL); + unit = new_unit_dialog (self->window, gimp_unit_pixel ()); - if (unit != GIMP_UNIT_PIXEL) + if (unit != gimp_unit_pixel ()) { GtkTreeModel *model; GtkTreeIter iter; @@ -620,7 +620,7 @@ new_unit_action (GSimpleAction *action, if (gtk_tree_model_get_iter_first (model, &iter) && gtk_tree_model_iter_nth_child (model, &iter, - NULL, unit - GIMP_UNIT_INCH)) + NULL, gimp_unit_get_id (unit) - GIMP_UNIT_INCH)) { GtkTreeSelection *selection; GtkAdjustment *adj; @@ -649,15 +649,15 @@ duplicate_unit_action (GSimpleAction *action, if (gtk_tree_selection_get_selected (sel, NULL, &iter)) { - GimpUnit unit; + GimpUnit *unit; gtk_tree_model_get (model, &iter, - UNIT, &unit, + UNIT, &unit, -1); unit = new_unit_dialog (self->window, unit); - if (unit != GIMP_UNIT_PIXEL) + if (unit != NULL) { GtkTreeIter iter; @@ -665,7 +665,7 @@ duplicate_unit_action (GSimpleAction *action, if (gtk_tree_model_get_iter_first (model, &iter) && gtk_tree_model_iter_nth_child (model, &iter, - NULL, unit - GIMP_UNIT_INCH)) + NULL, gimp_unit_get_id (unit) - GIMP_UNIT_INCH)) { GtkAdjustment *adj; @@ -696,7 +696,7 @@ saved_toggled_callback (GtkCellRendererToggle *celltoggle, GtkTreePath *path; GtkTreeIter iter; gboolean saved; - GimpUnit unit; + GimpUnit *unit; path = gtk_tree_path_new_from_string (path_string); @@ -712,7 +712,7 @@ saved_toggled_callback (GtkCellRendererToggle *celltoggle, UNIT, &unit, -1); - if (unit >= gimp_unit_get_number_of_built_in_units ()) + if (! gimp_unit_is_built_in (unit)) { gimp_unit_set_deletion_flag (unit, saved); gtk_list_store_set (GTK_LIST_STORE (list_store), &iter, @@ -726,19 +726,15 @@ unit_list_init (GtkTreeView *tv) { GtkListStore *list_store; GtkTreeIter iter; - gint num_units; - GimpUnit unit; + GimpUnit *unit = gimp_unit_get_by_id (GIMP_UNIT_INCH); + gint i = GIMP_UNIT_INCH + 1; list_store = GTK_LIST_STORE (gtk_tree_view_get_model (tv)); gtk_list_store_clear (list_store); - num_units = gimp_unit_get_number_of_units (); - - for (unit = GIMP_UNIT_INCH; unit < num_units; unit++) + while (unit != NULL) { - gboolean user_unit = (unit >= gimp_unit_get_number_of_built_in_units ()); - gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, SAVE, ! gimp_unit_get_deletion_flag (unit), @@ -750,8 +746,10 @@ unit_list_init (GtkTreeView *tv) SINGULAR, gimp_unit_get_singular (unit), PLURAL, gimp_unit_get_plural (unit), UNIT, unit, - USER_UNIT, user_unit, + USER_UNIT, ! gimp_unit_is_built_in (unit), -1); + + unit = gimp_unit_get_by_id (i++); } if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter)) diff --git a/plug-ins/file-jpeg/jpeg-load.c b/plug-ins/file-jpeg/jpeg-load.c index de2d3bec86..d11985d170 100644 --- a/plug-ins/file-jpeg/jpeg-load.c +++ b/plug-ins/file-jpeg/jpeg-load.c @@ -543,7 +543,7 @@ jpeg_load_resolution (GimpImage *image, case 2: /* dots per cm */ xresolution *= 2.54; yresolution *= 2.54; - gimp_image_set_unit (image, GIMP_UNIT_MM); + gimp_image_set_unit (image, gimp_unit_mm ()); break; default: diff --git a/plug-ins/file-psd/psd-export.c b/plug-ins/file-psd/psd-export.c index f73262ac16..6602de8488 100644 --- a/plug-ins/file-psd/psd-export.c +++ b/plug-ins/file-psd/psd-export.c @@ -898,15 +898,15 @@ save_resources (GOutputStream *output, /* --------------- Write resolution data ------------------- */ { - gdouble xres = 0, yres = 0; - guint32 xres_fix, yres_fix; - GimpUnit g_unit; - gint16 psd_unit; + gdouble xres = 0, yres = 0; + guint32 xres_fix, yres_fix; + GimpUnit *g_unit; + gint16 psd_unit; g_unit = gimp_image_get_unit (image); gimp_image_get_resolution (image, &xres, &yres); - if (g_unit == GIMP_UNIT_MM) + if (g_unit == gimp_unit_mm ()) { psd_unit = PSD_UNIT_CM; } diff --git a/plug-ins/file-psd/psd-image-res-load.c b/plug-ins/file-psd/psd-image-res-load.c index 982411a4e5..65581611c8 100644 --- a/plug-ins/file-psd/psd-image-res-load.c +++ b/plug-ins/file-psd/psd-image-res-load.c @@ -573,8 +573,8 @@ load_resource_1005 (const PSDimageres *res_a, /* FIXME width unit and height unit unused at present */ - ResolutionInfo res_info; - GimpUnit image_unit; + ResolutionInfo res_info; + GimpUnit *image_unit; IFDBG(2) g_debug ("Process image resource block 1005: Resolution Info"); @@ -613,13 +613,13 @@ load_resource_1005 (const PSDimageres *res_a, switch (res_info.hResUnit) { case PSD_RES_INCH: - image_unit = GIMP_UNIT_INCH; + image_unit = gimp_unit_inch (); break; case PSD_RES_CM: - image_unit = GIMP_UNIT_MM; + image_unit = gimp_unit_mm (); break; default: - image_unit = GIMP_UNIT_INCH; + image_unit = gimp_unit_inch (); } gimp_image_set_unit (image, image_unit); diff --git a/plug-ins/file-tiff/file-tiff-load.c b/plug-ins/file-tiff/file-tiff-load.c index d29998e2b6..32e934f6a3 100644 --- a/plug-ins/file-tiff/file-tiff-load.c +++ b/plug-ins/file-tiff/file-tiff-load.c @@ -1295,8 +1295,8 @@ load_image (GimpProcedure *procedure, { gdouble xres = 72.0; gdouble yres = 72.0; - gushort read_unit; - GimpUnit unit = GIMP_UNIT_PIXEL; /* invalid unit */ + gushort read_unit; + GimpUnit *unit = gimp_unit_pixel (); /* invalid unit */ if (TIFFGetField (tif, TIFFTAG_XRESOLUTION, &xres)) { @@ -1312,13 +1312,13 @@ load_image (GimpProcedure *procedure, break; case RESUNIT_INCH: - unit = GIMP_UNIT_INCH; + unit = gimp_unit_inch (); break; case RESUNIT_CENTIMETER: xres *= 2.54; yres *= 2.54; - unit = GIMP_UNIT_MM; /* this is our default metric unit */ + unit = gimp_unit_mm (); /* this is our default metric unit */ break; default: @@ -1366,7 +1366,7 @@ load_image (GimpProcedure *procedure, else { gimp_image_set_resolution (*image, xres, yres); - if (unit != GIMP_UNIT_PIXEL) + if (unit != gimp_unit_pixel ()) gimp_image_set_unit (*image, unit); *resolution_loaded = TRUE; diff --git a/plug-ins/print/print-settings.c b/plug-ins/print/print-settings.c index bab69fb95d..e96cda4d26 100644 --- a/plug-ins/print/print-settings.c +++ b/plug-ins/print/print-settings.c @@ -87,7 +87,7 @@ print_settings_save (PrintData *data) gimp_image_get_resolution (data->image, &xres, &yres); g_key_file_set_integer (key_file, "image-setup", - "unit", data->unit); + "unit", gimp_unit_get_id (data->unit)); /* Do not save the print resolution when it is the expected image * resolution so that changing it (i.e. in "print size" dialog) * is not overridden by any previous prints. @@ -250,8 +250,8 @@ print_settings_load_from_key_file (PrintData *data, if (g_key_file_has_key (key_file, "image-setup", "unit", NULL)) { - data->unit = g_key_file_get_integer (key_file, "image-setup", - "unit", NULL); + data->unit = gimp_unit_get_by_id (g_key_file_get_integer (key_file, "image-setup", + "unit", NULL)); } if (g_key_file_has_key (key_file, "image-setup", "x-resolution", NULL) && diff --git a/plug-ins/print/print.h b/plug-ins/print/print.h index db084c6a6b..e4fd42a0f1 100644 --- a/plug-ins/print/print.h +++ b/plug-ins/print/print.h @@ -41,12 +41,12 @@ typedef struct { GimpImage *image; GimpDrawable *drawable; - GimpUnit unit; + GimpUnit *unit; gdouble xres; gdouble yres; gdouble min_xres; gdouble min_yres; - GimpUnit image_unit; + GimpUnit *image_unit; gdouble offset_x; gdouble offset_y; PrintCenterMode center; diff --git a/plug-ins/twain/twain.c b/plug-ins/twain/twain.c index 08ae6dbbba..70cb1b8c32 100644 --- a/plug-ins/twain/twain.c +++ b/plug-ins/twain/twain.c @@ -633,7 +633,7 @@ beginTransferCallback (pTW_IMAGEINFO imageInfo, gimp_image_set_resolution (theClientData->image, FIX32ToFloat (imageInfo->XResolution), FIX32ToFloat (imageInfo->YResolution)); - gimp_image_set_unit (theClientData->image, GIMP_UNIT_INCH); + gimp_image_set_unit (theClientData->image, gimp_unit_inch ()); /* Create a layer */ theClientData->layer = gimp_layer_new (theClientData->image,