[gimp] libgimpbase: add gimp_unit_is_metric()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpbase: add gimp_unit_is_metric()
- Date: Sat, 12 Oct 2013 16:56:15 +0000 (UTC)
commit f473653889a3ad193de8aad1adc7b4ec7a3fd9d5
Author: Michael Natterer <mitch gimp org>
Date: Sat Oct 12 18:54:34 2013 +0200
libgimpbase: add gimp_unit_is_metric()
which currently returns TRUE if the unit has a factor that matches mm,
cm, dm or m. Incomplete, but at least now extendable in one place,
just need to use the new function everywhere.
libgimpbase/gimpbase.def | 1 +
libgimpbase/gimpunit.c | 33 +++++++++++++++++++++++++++++++++
libgimpbase/gimpunit.h | 2 ++
3 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index 9eeb82b..a6330e0 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -120,6 +120,7 @@ EXPORTS
gimp_unit_get_singular
gimp_unit_get_symbol
gimp_unit_get_type
+ gimp_unit_is_metric
gimp_unit_new
gimp_unit_set_deletion_flag
gimp_units_to_pixels
diff --git a/libgimpbase/gimpunit.c b/libgimpbase/gimpunit.c
index 1f46209..a941c7d 100644
--- a/libgimpbase/gimpunit.c
+++ b/libgimpbase/gimpunit.c
@@ -687,3 +687,36 @@ gimp_units_to_points (gdouble value,
return (value *
gimp_unit_get_factor (GIMP_UNIT_POINT) / gimp_unit_get_factor (unit));
}
+
+/**
+ * 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: GIMP 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 (factor == 25.4 ||
+ factor == 2.54 ||
+ factor == 0.254 ||
+ factor == 0.0254);
+}
diff --git a/libgimpbase/gimpunit.h b/libgimpbase/gimpunit.h
index 2d1860e..2311a54 100644
--- a/libgimpbase/gimpunit.h
+++ b/libgimpbase/gimpunit.h
@@ -100,6 +100,8 @@ gdouble gimp_units_to_points (gdouble value,
GimpUnit unit,
gdouble resolution);
+gboolean gimp_unit_is_metric (GimpUnit unit);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]