Bug 389949, first patch: Use POINTS_PER_INCH_FLOAT in place of magic number '72.0f'. Basically cosmetic -- shouldn't change our behavior at all. r+sr=vlad, a=blocking1.9+
authordholbert@cs.stanford.edu
Mon, 07 Apr 2008 17:27:10 -0700
changeset 14015 370398bbdee8e0e7ffbe656e300436ba019f1932
parent 14014 03c24d4df2587117194948736311a6f842d00291
child 14016 df5d312d30f3fa4ddaa22d7c7f2beebc8f9713c0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-esr52@a95d42642281 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblocking1.9
bugs389949
milestone1.9pre
Bug 389949, first patch: Use POINTS_PER_INCH_FLOAT in place of magic number '72.0f'. Basically cosmetic -- shouldn't change our behavior at all. r+sr=vlad, a=blocking1.9+
content/svg/content/src/nsSVGLength.cpp
content/svg/content/src/nsSVGLength2.cpp
gfx/public/nsCoord.h
gfx/src/thebes/nsSystemFontsGTK2.cpp
layout/base/nsPresContext.h
layout/style/nsROCSSPrimitiveValue.cpp
--- a/content/svg/content/src/nsSVGLength.cpp
+++ b/content/svg/content/src/nsSVGLength.cpp
@@ -241,20 +241,22 @@ nsSVGLength::GetValue(float *aValue)
       break;
     case SVG_LENGTHTYPE_CM:
       *aValue = mValueInSpecifiedUnits * 10.0f / mmPerPixel();
       break;
     case SVG_LENGTHTYPE_IN:
       *aValue = mValueInSpecifiedUnits * 25.4f / mmPerPixel();
       break;
     case SVG_LENGTHTYPE_PT:
-      *aValue = mValueInSpecifiedUnits * 25.4f / 72.0f / mmPerPixel();
+      *aValue = mValueInSpecifiedUnits * 25.4f / POINTS_PER_INCH_FLOAT / 
+        mmPerPixel();
       break;
     case SVG_LENGTHTYPE_PC:
-      *aValue = mValueInSpecifiedUnits * 25.4f * 12.0f / 72.0f / mmPerPixel();
+      *aValue = mValueInSpecifiedUnits * 25.4f * 12.0f / POINTS_PER_INCH_FLOAT /
+        mmPerPixel();
       break;
     case SVG_LENGTHTYPE_PERCENTAGE:
       *aValue = mValueInSpecifiedUnits * AxisLength() / 100.0f;
       break;
     case SVG_LENGTHTYPE_EMS:
       *aValue = mValueInSpecifiedUnits * EmLength();
       break;
     case SVG_LENGTHTYPE_EXS:
@@ -285,20 +287,22 @@ nsSVGLength::SetValue(float aValue)
       break;
     case SVG_LENGTHTYPE_CM:
       mValueInSpecifiedUnits = aValue * mmPerPixel() / 10.0f;
       break;
     case SVG_LENGTHTYPE_IN:
       mValueInSpecifiedUnits = aValue * mmPerPixel() / 25.4f;
       break;
     case SVG_LENGTHTYPE_PT:
-      mValueInSpecifiedUnits = aValue * mmPerPixel() * 72.0f / 25.4f;
+      mValueInSpecifiedUnits = aValue * mmPerPixel() * POINTS_PER_INCH_FLOAT /
+        25.4f;
       break;
     case SVG_LENGTHTYPE_PC:
-      mValueInSpecifiedUnits = aValue * mmPerPixel() * 72.0f / 24.4f / 12.0f;
+      mValueInSpecifiedUnits = aValue * mmPerPixel() * POINTS_PER_INCH_FLOAT /
+        24.4f / 12.0f;
       break;
     case SVG_LENGTHTYPE_PERCENTAGE:
       mValueInSpecifiedUnits = aValue * 100.0f / AxisLength();
       break;
     case SVG_LENGTHTYPE_EMS:
       mValueInSpecifiedUnits = aValue / EmLength();
       break;
     case SVG_LENGTHTYPE_EXS:
--- a/content/svg/content/src/nsSVGLength2.cpp
+++ b/content/svg/content/src/nsSVGLength2.cpp
@@ -220,19 +220,19 @@ nsSVGLength2::GetUnitScaleFactor(nsSVGSV
     return 1;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_MM:
     return GetMMPerPixel(aCtx);
   case nsIDOMSVGLength::SVG_LENGTHTYPE_CM:
     return GetMMPerPixel(aCtx) / 10.0f;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_IN:
     return GetMMPerPixel(aCtx) / 25.4f;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PT:
-    return GetMMPerPixel(aCtx) * 72.0f / 25.4f;
+    return GetMMPerPixel(aCtx) * POINTS_PER_INCH_FLOAT / 25.4f;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PC:
-    return GetMMPerPixel(aCtx) * 72.0f / 24.4f / 12.0f;
+    return GetMMPerPixel(aCtx) * POINTS_PER_INCH_FLOAT / 24.4f / 12.0f;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE:
     return 100.0f / GetAxisLength(aCtx);
   case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS:
     return 1 / GetEmLength(aCtx);
   case nsIDOMSVGLength::SVG_LENGTHTYPE_EXS:
     return 1 / GetExLength(aCtx);
   default:
     NS_NOTREACHED("Unknown unit type");
--- a/gfx/public/nsCoord.h
+++ b/gfx/public/nsCoord.h
@@ -362,16 +362,18 @@ inline float NSAppUnitsToFloatPixels(nsc
 inline PRInt32 NSAppUnitsToIntPixels(nscoord aAppUnits, PRInt32 aAppUnitsPerPixel)
 {
   return NSToIntRound(float(aAppUnits) / aAppUnitsPerPixel);
 }
 
 /// handy constants
 #define TWIPS_PER_POINT_INT           20
 #define TWIPS_PER_POINT_FLOAT         20.0f
+#define POINTS_PER_INCH_INT           72
+#define POINTS_PER_INCH_FLOAT         72.0f
 
 /* 
  * Twips/unit conversions
  */
 inline nscoord NSUnitsToTwips(float aValue, float aPointsPerUnit)
 {
   return NSToCoordRound(aValue * aPointsPerUnit * TWIPS_PER_POINT_FLOAT);
 }
@@ -380,37 +382,37 @@ inline float NSTwipsToUnits(nscoord aTwi
 {
   return (aTwips * (aUnitsPerPoint / TWIPS_PER_POINT_FLOAT));
 }
 
 
 /// Unit conversion macros
 //@{
 #define NS_POINTS_TO_TWIPS(x)         NSUnitsToTwips((x), 1.0f)
-#define NS_INCHES_TO_TWIPS(x)         NSUnitsToTwips((x), 72.0f)                      // 72 points per inch
-#define NS_FEET_TO_TWIPS(x)           NSUnitsToTwips((x), (72.0f * 12.0f))            // 12 inches per foot
-#define NS_MILES_TO_TWIPS(x)          NSUnitsToTwips((x), (72.0f * 12.0f * 5280.0f))  // 5280 feet per mile
+#define NS_INCHES_TO_TWIPS(x)         NSUnitsToTwips((x), POINTS_PER_INCH_FLOAT)                      // 72 points per inch
+#define NS_FEET_TO_TWIPS(x)           NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 12.0f))            // 12 inches per foot
+#define NS_MILES_TO_TWIPS(x)          NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 12.0f * 5280.0f))  // 5280 feet per mile
 
-#define NS_MILLIMETERS_TO_TWIPS(x)    NSUnitsToTwips((x), (72.0f * 0.03937f))
-#define NS_CENTIMETERS_TO_TWIPS(x)    NSUnitsToTwips((x), (72.0f * 0.3937f))
-#define NS_METERS_TO_TWIPS(x)         NSUnitsToTwips((x), (72.0f * 39.37f))
-#define NS_KILOMETERS_TO_TWIPS(x)     NSUnitsToTwips((x), (72.0f * 39370.0f))
+#define NS_MILLIMETERS_TO_TWIPS(x)    NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 0.03937f))
+#define NS_CENTIMETERS_TO_TWIPS(x)    NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 0.3937f))
+#define NS_METERS_TO_TWIPS(x)         NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 39.37f))
+#define NS_KILOMETERS_TO_TWIPS(x)     NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 39370.0f))
 
 #define NS_PICAS_TO_TWIPS(x)          NSUnitsToTwips((x), 12.0f)                      // 12 points per pica
 #define NS_DIDOTS_TO_TWIPS(x)         NSUnitsToTwips((x), (16.0f / 15.0f))            // 15 didots per 16 points
 #define NS_CICEROS_TO_TWIPS(x)        NSUnitsToTwips((x), (12.0f * (16.0f / 15.0f)))  // 12 didots per cicero
 
 #define NS_TWIPS_TO_POINTS(x)         NSTwipsToUnits((x), 1.0f)
-#define NS_TWIPS_TO_INCHES(x)         NSTwipsToUnits((x), 1.0f / 72.0f)
-#define NS_TWIPS_TO_FEET(x)           NSTwipsToUnits((x), 1.0f / (72.0f * 12.0f))
-#define NS_TWIPS_TO_MILES(x)          NSTwipsToUnits((x), 1.0f / (72.0f * 12.0f * 5280.0f))
+#define NS_TWIPS_TO_INCHES(x)         NSTwipsToUnits((x), 1.0f / POINTS_PER_INCH_FLOAT)
+#define NS_TWIPS_TO_FEET(x)           NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 12.0f))
+#define NS_TWIPS_TO_MILES(x)          NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 12.0f * 5280.0f))
 
-#define NS_TWIPS_TO_MILLIMETERS(x)    NSTwipsToUnits((x), 1.0f / (72.0f * 0.03937f))
-#define NS_TWIPS_TO_CENTIMETERS(x)    NSTwipsToUnits((x), 1.0f / (72.0f * 0.3937f))
-#define NS_TWIPS_TO_METERS(x)         NSTwipsToUnits((x), 1.0f / (72.0f * 39.37f))
-#define NS_TWIPS_TO_KILOMETERS(x)     NSTwipsToUnits((x), 1.0f / (72.0f * 39370.0f))
+#define NS_TWIPS_TO_MILLIMETERS(x)    NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 0.03937f))
+#define NS_TWIPS_TO_CENTIMETERS(x)    NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 0.3937f))
+#define NS_TWIPS_TO_METERS(x)         NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 39.37f))
+#define NS_TWIPS_TO_KILOMETERS(x)     NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 39370.0f))
 
 #define NS_TWIPS_TO_PICAS(x)          NSTwipsToUnits((x), 1.0f / 12.0f)
 #define NS_TWIPS_TO_DIDOTS(x)         NSTwipsToUnits((x), 1.0f / (16.0f / 15.0f))
 #define NS_TWIPS_TO_CICEROS(x)        NSTwipsToUnits((x), 1.0f / (12.0f * (16.0f / 15.0f)))
 //@}
 
 #endif /* NSCOORD_H */
--- a/gfx/src/thebes/nsSystemFontsGTK2.cpp
+++ b/gfx/src/thebes/nsSystemFontsGTK2.cpp
@@ -211,17 +211,17 @@ nsSystemFontsGTK2::GetSystemFontInfo(Gtk
     aFontStyle->weight = pango_font_description_get_weight(desc);
 
     float size = float(pango_font_description_get_size(desc) / PANGO_SCALE);
 
     // |size| is now either pixels or pango-points (not Mozilla-points!)
 
     if (!MOZ_pango_font_description_get_size_is_absolute(desc)) {
         // |size| is in pango-points, so convert to pixels.
-        size *= float(gfxPlatformGtk::DPI()) / 72.0f;
+        size *= float(gfxPlatformGtk::DPI()) / POINTS_PER_INCH_FLOAT;
     }
 
     // |size| is now pixels
 
     aFontStyle->size = size;
   
     pango_font_description_free(desc);
 
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -527,19 +527,20 @@ public:
                     TwipsToAppUnits(marginInTwips.bottom)); }
 
   PRInt32 AppUnitsToTwips(nscoord aTwips) const
   { return NS_INCHES_TO_TWIPS((float)aTwips /
                               mDeviceContext->AppUnitsPerInch()); }
 
   nscoord PointsToAppUnits(float aPoints) const
   { return NSToCoordRound(aPoints * mDeviceContext->AppUnitsPerInch() /
-                          72.0f); }
+                          POINTS_PER_INCH_FLOAT); }
   float AppUnitsToPoints(nscoord aAppUnits) const
-  { return (float)aAppUnits / mDeviceContext->AppUnitsPerInch() * 72.0f; }
+  { return (float)aAppUnits / mDeviceContext->AppUnitsPerInch() *
+      POINTS_PER_INCH_FLOAT); }
 
   nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const
   { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); }
 
   /**
    * Get the language-specific transform type for the current document.
    * This tells us whether we need to perform special language-dependent
    * transformations such as Unicode U+005C (backslash) to Japanese
--- a/layout/style/nsROCSSPrimitiveValue.cpp
+++ b/layout/style/nsROCSSPrimitiveValue.cpp
@@ -356,17 +356,18 @@ nsROCSSPrimitiveValue::GetFloatValue(PRU
     case CSS_IN :
       if (mType != CSS_PX)
         return NS_ERROR_DOM_INVALID_ACCESS_ERR;
       *aReturn = mValue.mAppUnits / float(mAppUnitsPerInch);
       break;
     case CSS_PT :
       if (mType != CSS_PX)
         return NS_ERROR_DOM_INVALID_ACCESS_ERR;
-      *aReturn = mValue.mAppUnits * 72.0f / float(mAppUnitsPerInch);
+      *aReturn = mValue.mAppUnits * POINTS_PER_INCH_FLOAT / 
+        float(mAppUnitsPerInch);
       break;
     case CSS_PC :
       if (mType != CSS_PX)
         return NS_ERROR_DOM_INVALID_ACCESS_ERR;
       *aReturn = mValue.mAppUnits * 6.0f / float(mAppUnitsPerInch);
       break;
     case CSS_PERCENTAGE :
       if (mType != CSS_PERCENTAGE)