libgimpbase: new gimp_unit_get_accurate_digits() API function.
This commit is contained in:
parent
e83383c320
commit
0c07ae3bbf
3 changed files with 34 additions and 0 deletions
|
|
@ -174,6 +174,7 @@ EXPORTS
|
|||
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
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
|
@ -255,6 +256,36 @@ gimp_unit_get_digits (GimpUnit unit)
|
|||
return _gimp_unit_vtable.unit_get_digits (unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_unit_get_scaled_digits:
|
||||
* @unit: The unit you want to know the digits.
|
||||
* @resolution: the resolution in PPI.
|
||||
*
|
||||
* Returns the number of digits a @unit field should provide to get
|
||||
* enough accuracy so that every pixel position shows a different
|
||||
* 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
|
||||
* 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)
|
||||
{
|
||||
gint digits;
|
||||
|
||||
g_return_val_if_fail (_gimp_unit_vtable.unit_get_digits != NULL, 2);
|
||||
|
||||
digits = ceil (log10 (1.0 /
|
||||
gimp_pixels_to_units (1.0, unit, resolution)));
|
||||
|
||||
return MAX (digits, gimp_unit_get_digits (unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_unit_get_identifier:
|
||||
* @unit: The unit you want to know the identifier of.
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ void gimp_unit_set_deletion_flag (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_identifier (GimpUnit unit);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue