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.
This commit is contained in:
parent
ecbfb4a9e8
commit
caa3b9f4bf
3 changed files with 31 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue