The only tricky part of the patch is to remember that 1cm is 10mm.
Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
}
static gfloat
+units_cm_to_pixels (gfloat cm)
+{
+ return units_mm_to_pixels (cm * 10);
+}
+
+static gfloat
units_pt_to_pixels (gfloat pt)
{
ClutterBackend *backend;
}
/**
+ * clutter_units_from_cm:
+ * @units: a #ClutterUnits
+ * @cm: centimeters
+ *
+ * Stores a value in centimeters inside @units
+ *
+ * Since: 1.2
+ */
+void
+clutter_units_from_cm (ClutterUnits *units,
+ gfloat cm)
+{
+ g_return_if_fail (units != NULL);
+
+ units->unit_type = CLUTTER_UNIT_CM;
+ units->value = cm;
+ units->pixels = units_cm_to_pixels (cm);
+ units->pixels_set = TRUE;
+}
+
+/**
* clutter_units_from_pt:
* @units: a #ClutterUnits
* @pt: typographic points
units->pixels = units_mm_to_pixels (units->value);
break;
+ case CLUTTER_UNIT_CM:
+ units->pixels = units_cm_to_pixels (units->value);
+ break;
+
case CLUTTER_UNIT_POINT:
units->pixels = units_pt_to_pixels (units->value);
break;
* |[
* units: wsp* unit-value wsp* unit-name? wsp*
* unit-value: number
- * unit-name: 'px' | 'pt' | 'mm' | 'em'
+ * unit-name: 'px' | 'pt' | 'mm' | 'em' | 'cm'
* number: digit+
* | digit* sep digit+
* sep: '.' | ','
unit_type = CLUTTER_UNIT_MM;
str += 2;
}
+ else if (strncmp (str, "cm", 2) == 0)
+ {
+ unit_type = CLUTTER_UNIT_CM;
+ str += 2;
+ }
else if (strncmp (str, "pt", 2) == 0)
{
unit_type = CLUTTER_UNIT_POINT;
case CLUTTER_UNIT_MM:
return "mm";
+ case CLUTTER_UNIT_CM:
+ return "cm";
+
case CLUTTER_UNIT_POINT:
return "pt";
* examples of output
*
* <note>Fractional values are truncated to the second decimal
- * position for em and mm, and to the first decimal position for
+ * position for em, mm and cm, and to the first decimal position for
* typographic points. Pixels are integers.</note>
*
* Return value: a newly allocated string containing the encoded
fmt = "%.2f";
break;
+ case CLUTTER_UNIT_CM:
+ unit_name = "cm";
+ fmt = "%.2f";
+ break;
+
case CLUTTER_UNIT_POINT:
unit_name = "pt";
fmt = "%.1f";
* @CLUTTER_UNIT_EM: Unit expressed in em
* @CLUTTER_UNIT_MM: Unit expressed in millimeters
* @CLUTTER_UNIT_POINT: Unit expressed in points
+ * @CLUTTER_UNIT_CM: Unit expressed in centimeters
*
* The type of unit in which a value is expressed
*
CLUTTER_UNIT_PIXEL,
CLUTTER_UNIT_EM,
CLUTTER_UNIT_MM,
- CLUTTER_UNIT_POINT
+ CLUTTER_UNIT_POINT,
+ CLUTTER_UNIT_CM
} ClutterUnitType;
/**
gfloat em);
void clutter_units_from_mm (ClutterUnits *units,
gfloat mm);
+void clutter_units_from_cm (ClutterUnits *units,
+ gfloat cm);
void clutter_units_from_pt (ClutterUnits *units,
gfloat pt);
#define clutter_units_em clutter_units_from_em
#define clutter_units_em_for_font clutter_units_from_em_for_font
#define clutter_units_mm clutter_units_from_mm
+#define clutter_units_cm clutter_units_from_cm
#define clutter_units_pt clutter_units_from_pt
#define CLUTTER_TYPE_UNITS (clutter_units_get_type ())
ClutterUnitType
ClutterUnits
clutter_units_from_mm
+clutter_units_from_cm
clutter_units_from_pt
clutter_units_from_em
clutter_units_from_em_for_font
test_units_constructors (TestConformSimpleFixture *fixture,
gconstpointer data)
{
- ClutterUnits units;
+ ClutterUnits units, units_cm;
clutter_units_from_pixels (&units, 100);
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.0);
g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, 5.0);
+
+ clutter_units_from_cm (&units_cm, 5.0);
+ g_assert (clutter_units_get_unit_type (&units_cm) == CLUTTER_UNIT_CM);
+ g_assert_cmpfloat (clutter_units_get_unit_value (&units_cm), ==, 5.0);
+ g_assert_cmpfloat (clutter_units_to_pixels (&units_cm), !=, 5.0);
+
+ clutter_units_from_mm (&units, 50.0);
+ g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
+ g_assert_cmpfloat (clutter_units_to_pixels (&units),
+ ==,
+ clutter_units_to_pixels (&units_cm));
}
void
g_assert (clutter_units_from_string (&units, " 32 em garbage") == FALSE);
- g_assert (clutter_units_from_string (&units, "5.1mm") == TRUE);
- g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
+ g_assert (clutter_units_from_string (&units, "5.1cm") == TRUE);
+ g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_CM);
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.1f);
g_assert (clutter_units_from_string (&units, "5,mm") == FALSE);