From caa3b9f4bf2b18ebefa8cf142b8ba03165e1121e Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 18 Mar 2011 21:34:27 +0100 Subject: [PATCH] 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(+) diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def index 2a6359a262..88e18e7d9a 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 470b245a48..cbd4aa9fe4 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 49f1c4e726..1b4db69237 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