From 685c583d51d21c403947e02191a43cbe923a664e Mon Sep 17 00:00:00 2001 From: Tomas Frydrych Date: Tue, 23 Jan 2007 11:48:04 +0000 Subject: [PATCH] more fixed point work --- ChangeLog | 15 +++++++++++++++ clutter/clutter-fixed.c | 22 ++++++++++++++++++---- clutter/pango/pangoclutter-font.c | 13 ++++++++++--- clutter/pango/pangoclutter-private.h | 13 +++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6a3c89746..9f08e0846 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-01-23 Tomas Frydrych + + * 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 * clutter/clutter-fixed.c: (clutter_sqrti): diff --git a/clutter/clutter-fixed.c b/clutter/clutter-fixed.c index c0ac9075f..80d3fd239 100644 --- a/clutter/clutter-fixed.c +++ b/clutter/clutter-fixed.c @@ -538,8 +538,15 @@ const double _magic = 68719476736.0*1.5; ClutterFixed _clutter_double_to_fixed (double val) { - val = val + _magic; - return ((gint32*)&val)[_CFX_MAN]; + union + { + 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 _clutter_double_to_int (double val) { - val = val + _magic; - return ((gint32*)&val)[_CFX_MAN] >> 16; + union + { + double d; + unsigned int i[2]; + } dbl; + + dbl.d = val; + dbl.d = dbl.d + _magic; + return dbl.i[0] >> 16; } #undef _CFX_MAN diff --git a/clutter/pango/pangoclutter-font.c b/clutter/pango/pangoclutter-font.c index 87ec2994c..c57cc100a 100644 --- a/clutter/pango/pangoclutter-font.c +++ b/clutter/pango/pangoclutter-font.c @@ -70,7 +70,7 @@ _pango_clutter_font_new (PangoClutterFontMap *fontmap_, FcPattern *pattern) PangoFontMap *fontmap = PANGO_FONT_MAP (fontmap_); PangoClutterFont *font; double d; - + g_return_val_if_fail (fontmap != NULL, NULL); g_return_val_if_fail (pattern != NULL, NULL); @@ -79,8 +79,15 @@ _pango_clutter_font_new (PangoClutterFontMap *fontmap_, FcPattern *pattern) NULL); 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; } diff --git a/clutter/pango/pangoclutter-private.h b/clutter/pango/pangoclutter-private.h index 0f049f601..1d375e7d7 100644 --- a/clutter/pango/pangoclutter-private.h +++ b/clutter/pango/pangoclutter-private.h @@ -29,10 +29,23 @@ /* Defines duped */ #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) \ (((d) >= 0) ? \ ((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_TYPE_CLUTTER_FONT (pango_clutter_font_get_type ())