[gimp] libgimpbase: add gimp_units_to_points()



commit caa3b9f4bf2b18ebefa8cf142b8ba03165e1121e
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 18 21:34:27 2011 +0100

    libgimpbase: add gimp_units_to_points()
    
    because points is used in quite some external APIs (like Pango), and
    having one conversion from gimp units is better than duplicating the
    code.

 libgimpbase/gimpbase.def |    1 +
 libgimpbase/gimpunit.c   |   27 +++++++++++++++++++++++++++
 libgimpbase/gimpunit.h   |    3 +++
 3 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index 2a6359a..88e18e7 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -120,6 +120,7 @@ EXPORTS
 	gimp_unit_new
 	gimp_unit_set_deletion_flag
 	gimp_units_to_pixels
+	gimp_units_to_points
 	gimp_user_directory
 	gimp_user_directory_get_type
 	gimp_utf8_strtrim
diff --git a/libgimpbase/gimpunit.c b/libgimpbase/gimpunit.c
index 470b245..cbd4aa9 100644
--- a/libgimpbase/gimpunit.c
+++ b/libgimpbase/gimpunit.c
@@ -654,3 +654,30 @@ gimp_units_to_pixels (gdouble  value,
 
   return value * resolution / gimp_unit_get_factor (unit);
 }
+
+/**
+ * gimp_units_to_points:
+ * @value:      value in units
+ * @unit:       unit of @value
+ * @resolution: resloution in DPI
+ *
+ * Converts a @value specified in @unit to points.
+ *
+ * Returns: @value converted to points.
+ *
+ * Since: GIMP 2.8
+ **/
+gdouble
+gimp_units_to_points (gdouble  value,
+                      GimpUnit unit,
+                      gdouble  resolution)
+{
+  if (unit == GIMP_UNIT_POINT)
+    return value;
+
+  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));
+}
diff --git a/libgimpbase/gimpunit.h b/libgimpbase/gimpunit.h
index 49f1c4e..1b4db69 100644
--- a/libgimpbase/gimpunit.h
+++ b/libgimpbase/gimpunit.h
@@ -92,6 +92,9 @@ gdouble       gimp_pixels_to_units          (gdouble      pixels,
 gdouble       gimp_units_to_pixels          (gdouble      value,
                                              GimpUnit     unit,
                                              gdouble      resolution);
+gdouble       gimp_units_to_points          (gdouble      value,
+                                             GimpUnit     unit,
+                                             gdouble      resolution);
 
 
 G_END_DECLS



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]