When dumping a ClutterUnits structure to a string we are using a bare
g_strdup_printf(), which unfortunately is locale dependant. So, for
instance, a type of CLUTTER_UNIT_EM and a value of 42 are stringified
as:
C: 42.00 em
en_GB 42.00 em
it_IT 42,00 em
fr_FR 42,00 em
This would not be a problem -- clutter_units_from_string() allows both
'.' and ',' as fractionary part delimiters. The test suite, on the
other hand, does not know that, and it checks for exact matches with
the C locale.
Calling setlocale(LC_ALL,"C") at the beginning of the conformance test
suite is not a good idea, because it would prevent external testing; and
it's a lame cop out from doing exactly what we have to do -- pick a format
and stick with it.
Like other platforms, languages and frameworks before us, we opt to
be less liberal in what we create; so, we choose to always stringify
ClutterUnits with fractionary parts using '.' as the delimiter.
Fixes bug:
http://bugzilla.openedhand.com/show_bug.cgi?id=1763
We should follow the convention for boxed types initializers of:
<type_name>_from_<another_type> (boxed, value)
For ClutterUnits as well; so:
clutter_units_pixels -> clutter_units_from_pixels
clutter_units_em -> clutter_units_from_em
...
We should still keep the short-hand version as a macro, though.
When declaring a property using ClutterParamSpecUnits we pass a
default type to limit the type of units we accept as valid values
for the property.
This means that we need to add the unit type check as part of the
validation process.
Units as they have been implemented since Clutter 0.4 have always been
misdefined as "logical distance unit", while they were just pixels with
fractionary bits.
Units should be reworked to be opaque structures to hold a value and
its unit type, that can be then converted into pixels when Clutter needs
to paint or compute size requisitions and perform allocations.
The previous API should be completely removed to avoid collisions, and
a new type:
ClutterUnits
should be added; the ability to install GObject properties using
ClutterUnits should be maintained.
Currently, the conversion from em to units is done by using the
default font name inside the backend. For actors using their own
font/text layout we need a way to specify the font name along
with the quantity we wish to transform.
A GValue containing a ClutterUnit should be transformable into a
GValue holding an integer, a floating point value or a fixed point
value.
This means adding more transformation functions when registering
the ClutterUnit GType.
The GValue and GParamSpec integration of ClutterUnit was still
using the old, fixed-point based logic.
Storing ClutterUnits in a GValue should use floating point values,
and ClutterParamSpecUnit should follow suit.
Instead of recomputing the number of units needed to fit in
an em each time clutter_units_em() is called, we can store this
value into the default Backend along with the resolution and
font name. The value should also be updated each time the
resolution and font are changed, to keep it up to date.
An em is a unit of measurement in typography, equal to the point
size of the current font.
It should be possible to convert a value expressed in em to
ClutterUnits by using the current font and the current DPI as
stored by the default backend.
The stage-with/height-percentage converters had been broken by
the multiple-stages support of Clutter 0.8. They are also made
useless by the fact that Units are now floating point values.
The millimeters and typographic points converters also depended
on the default stage, but they can be reworked to use the default
DPI coming from the default Backend instead.
Bug #902 - Support transform from G_TYPE_INT to ClutterUnit
* clutter/clutter-units.c:
(clutter_value_transform_int_unit),
(clutter_unit_get_type): Add GValue transformation function from
integer values to ClutterUnit. (#902)
(param_unit_validate): Fix validation for ClutterParamSpecUnit;
this allows writable ClutterUnit properties.
* clutter/clutter-fixed.c:
(clutter_value_transform_int_fixed),
(clutter_value_transform_double_fixed),
(clutter_value_transform_float_fixed): Add GValue transformation
functions from native types (int, double, float) to ClutterFixed.
(clutter_fixed_get_type): Register the new transformation functions.
(param_fixed_validate): Fix validation for ClutterParamSpecUnit;
this allows writable ClutterFixed properties.
* clutter/clutter-units.c (param_unit_init): Use the right
macros to set the default minimum and maximum values.
* clutter/clutter-fixed.c (param_fixed_init): Ditto as above.
* clutter/clutter-fixed.c:
(clutter_value_transform_fixed_int),
(clutter_value_transform_fixed_double),
(clutter_value_transform_fixed_float),
(clutter_fixed_get_type): Add GValue transformation functions
for ClutterFixed; copying a CLUTTER_TYPE_FIXED GValue into
a G_TYPE_FLOAT/G_TYPE_DOUBLE one will automatically transform
the fixed point representation into a floating point one. Also
add the G_TYPE_INT transformation function to do a plain
fixed->int copy.
* clutter/clutter-units.c:
(clutter_value_transform_unit_int),
(clutter_unit_get_type): Add a unit->int transformation function.
* clutter/Makefile.am: Add clutter-units.c
* clutter/clutter-units.[ch]: Add a ClutterUnit fundamental
type, and wrappers for storing it into GValues; also add a
GParamSpec subclass for defining parameters holding ClutterUnit
values. This allows creating GObject properties using units.
* doc/reference/clutter-sections.txt: Document the newly
added API.