more fixed point work

This commit is contained in:
Tomas Frydrych 2007-01-23 11:48:04 +00:00
parent b8b0d01c91
commit 685c583d51
4 changed files with 56 additions and 7 deletions

View File

@ -1,3 +1,18 @@
2007-01-23 Tomas Frydrych <tf@openedhand.com>
* clutter/clutter-fixed.c:
(_clutter_double_to_fixed):
(_clutter_double_to_int):
Fixed to avoid problems with punned pointers and gcc
optimatisation.
* clutter/pango/pangoclutter-private.h:
Simplified PANGO_PIXELS_26_6 macro.
* clutter/pango/pangoclutter-font.c:
(_pango_clutter_font_new):
Replace floating with fixed point math.
2007-01-19 Tomas Frydrych <tf@openedhand.com> 2007-01-19 Tomas Frydrych <tf@openedhand.com>
* clutter/clutter-fixed.c: (clutter_sqrti): * clutter/clutter-fixed.c: (clutter_sqrti):

View File

@ -538,8 +538,15 @@ const double _magic = 68719476736.0*1.5;
ClutterFixed ClutterFixed
_clutter_double_to_fixed (double val) _clutter_double_to_fixed (double val)
{ {
val = val + _magic; union
return ((gint32*)&val)[_CFX_MAN]; {
double d;
unsigned int i[2];
} dbl;
dbl.d = val;
dbl.d = dbl.d + _magic;
return dbl.i[0];
} }
/* /*
@ -556,8 +563,15 @@ _clutter_double_to_fixed (double val)
ClutterFixed ClutterFixed
_clutter_double_to_int (double val) _clutter_double_to_int (double val)
{ {
val = val + _magic; union
return ((gint32*)&val)[_CFX_MAN] >> 16; {
double d;
unsigned int i[2];
} dbl;
dbl.d = val;
dbl.d = dbl.d + _magic;
return dbl.i[0] >> 16;
} }
#undef _CFX_MAN #undef _CFX_MAN

View File

@ -79,7 +79,14 @@ _pango_clutter_font_new (PangoClutterFontMap *fontmap_, FcPattern *pattern)
NULL); NULL);
if (FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &d) == FcResultMatch) if (FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &d) == FcResultMatch)
font->size = d * PANGO_SCALE; {
/* Cannot use 16.16 fixed here, because multiplying by PANGO_SCALE
* could easily take us out of range, but we do not need the 16 bit
* precission for the fraction, so we use 20.12 fixed point here
*/
int f = CLUTTER_FLOAT_TO_FIXED (d) >> 4;
font->size = (f * PANGO_SCALE) >> 12;
}
return font; return font;
} }

View File

@ -29,10 +29,23 @@
/* Defines duped */ /* Defines duped */
#define PANGO_SCALE_26_6 (PANGO_SCALE / (1<<6)) #define PANGO_SCALE_26_6 (PANGO_SCALE / (1<<6))
/* We only use the PANGO_SCALE_26_6 macro for scaling font size.
* Font sizes are normally given in points with at most one single
* decimal place fraction. If we do not do the rounding here, we will
* be suffering from an error < 0.016pt, which is entirely negligeable
* as far as font sizes are concerned.
*/
#if 0
#define PANGO_PIXELS_26_6(d) \ #define PANGO_PIXELS_26_6(d) \
(((d) >= 0) ? \ (((d) >= 0) ? \
((d) + PANGO_SCALE_26_6 / 2) / PANGO_SCALE_26_6 : \ ((d) + PANGO_SCALE_26_6 / 2) / PANGO_SCALE_26_6 : \
((d) - PANGO_SCALE_26_6 / 2) / PANGO_SCALE_26_6) ((d) - PANGO_SCALE_26_6 / 2) / PANGO_SCALE_26_6)
#else
#define PANGO_PIXELS_26_6(d) \
(d / PANGO_SCALE_26_6)
#endif
#define PANGO_UNITS_26_6(d) (PANGO_SCALE_26_6 * (d)) #define PANGO_UNITS_26_6(d) (PANGO_SCALE_26_6 * (d))
#define PANGO_TYPE_CLUTTER_FONT (pango_clutter_font_get_type ()) #define PANGO_TYPE_CLUTTER_FONT (pango_clutter_font_get_type ())