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.
This commit is contained in:
Michael Natterer 2013-10-12 18:54:34 +02:00
parent 54ead10b57
commit f473653889
3 changed files with 36 additions and 0 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -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