Bug 537890. Part 8: Define MM_PER_INCH_FLOAT. r=dbaron
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 13 Aug 2010 21:57:57 +1200
changeset 50399 2b180ab7126feef8619ea6fd47a95a0f1318a707
parent 50398 a630caeec6be803dc6683ee852d87a55d14be5fd
child 50400 bd906544d7ba6628104b22959a8391daaac2a8a5
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs537890
milestone2.0b4pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 537890. Part 8: Define MM_PER_INCH_FLOAT. r=dbaron
content/svg/content/src/nsSVGLength2.cpp
content/svg/content/src/nsSVGSVGElement.cpp
gfx/src/nsCoord.h
layout/style/nsROCSSPrimitiveValue.cpp
widget/src/cocoa/nsChildView.mm
widget/src/gtk2/nsPaperPS.cpp
widget/src/gtk2/nsWindow.cpp
widget/src/windows/nsWindow.cpp
--- a/content/svg/content/src/nsSVGLength2.cpp
+++ b/content/svg/content/src/nsSVGLength2.cpp
@@ -202,17 +202,17 @@ nsSVGLength2::GetMMPerPixel(nsSVGSVGElem
 }
 
 /*static*/ float
 nsSVGLength2::GetMMPerPixel(nsIFrame *aNonSVGFrame)
 {
   nsPresContext* presContext = aNonSVGFrame->PresContext();
   float pixelsPerInch =
     presContext->AppUnitsToFloatCSSPixels(presContext->AppUnitsPerInch());
-  return 25.4f/pixelsPerInch;
+  return MM_PER_INCH_FLOAT/pixelsPerInch;
 }
 
 static float
 FixAxisLength(float aLength)
 {
   if (aLength == 0.0f) {
     NS_WARNING("zero axis length");
     return 1e-20f;
@@ -272,21 +272,21 @@ nsSVGLength2::GetUnitScaleFactor(nsSVGSV
   case nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER:
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PX:
     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;
+    return GetMMPerPixel(aCtx) / MM_PER_INCH_FLOAT;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PT:
-    return GetMMPerPixel(aCtx) * POINTS_PER_INCH_FLOAT / 25.4f;
+    return GetMMPerPixel(aCtx) * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PC:
-    return GetMMPerPixel(aCtx) * POINTS_PER_INCH_FLOAT / 24.4f / 12.0f;
+    return GetMMPerPixel(aCtx) * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT / 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");
@@ -305,21 +305,21 @@ nsSVGLength2::GetUnitScaleFactor(nsIFram
   case nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER:
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PX:
     return 1;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_MM:
     return GetMMPerPixel(aFrame);
   case nsIDOMSVGLength::SVG_LENGTHTYPE_CM:
     return GetMMPerPixel(aFrame) / 10.0f;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_IN:
-    return GetMMPerPixel(aFrame) / 25.4f;
+    return GetMMPerPixel(aFrame) / MM_PER_INCH_FLOAT;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PT:
-    return GetMMPerPixel(aFrame) * POINTS_PER_INCH_FLOAT / 25.4f;
+    return GetMMPerPixel(aFrame) * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PC:
-    return GetMMPerPixel(aFrame) * POINTS_PER_INCH_FLOAT / 24.4f / 12.0f;
+    return GetMMPerPixel(aFrame) * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT / 12.0f;
   case nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE:
     return 100.0f / GetAxisLength(aFrame);
   case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS:
     return 1 / GetEmLength(aFrame);
   case nsIDOMSVGLength::SVG_LENGTHTYPE_EXS:
     return 1 / GetExLength(aFrame);
   default:
     NS_NOTREACHED("Unknown unit type");
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -312,17 +312,18 @@ nsSVGSVGElement::GetPixelUnitToMillimete
   // to correctly determine this, the caller would need to pass in the
   // right PresContext...
   nsPresContext *context = nsContentUtils::GetContextForContent(this);
   if (!context) {
     *aPixelUnitToMillimeterX = 0.28f; // 90dpi
     return NS_OK;
   }
 
-  *aPixelUnitToMillimeterX = 25.4f / nsPresContext::AppUnitsToIntCSSPixels(context->AppUnitsPerInch());
+  *aPixelUnitToMillimeterX = MM_PER_INCH_FLOAT /
+      nsPresContext::AppUnitsToIntCSSPixels(context->AppUnitsPerInch());
   return NS_OK;
 }
 
 /* readonly attribute float pixelUnitToMillimeterY; */
 NS_IMETHODIMP
 nsSVGSVGElement::GetPixelUnitToMillimeterY(float *aPixelUnitToMillimeterY)
 {
   return GetPixelUnitToMillimeterX(aPixelUnitToMillimeterY);
@@ -335,17 +336,17 @@ nsSVGSVGElement::GetScreenPixelToMillime
   // to correctly determine this, the caller would need to pass in the
   // right PresContext...
   nsPresContext *context = nsContentUtils::GetContextForContent(this);
   if (!context) {
     *aScreenPixelToMillimeterX = 0.28f; // 90dpi
     return NS_OK;
   }
 
-  *aScreenPixelToMillimeterX = 25.4f /
+  *aScreenPixelToMillimeterX = MM_PER_INCH_FLOAT /
       nsPresContext::AppUnitsToIntCSSPixels(context->AppUnitsPerInch());
   return NS_OK;
 }
 
 /* readonly attribute float screenPixelToMillimeterY; */
 NS_IMETHODIMP
 nsSVGSVGElement::GetScreenPixelToMillimeterY(float *aScreenPixelToMillimeterY)
 {
--- a/gfx/src/nsCoord.h
+++ b/gfx/src/nsCoord.h
@@ -443,16 +443,18 @@ inline float NSCoordScale(nscoord aCoord
   return (NSCoordToFloat(aCoord) * aToAPP) / aFromAPP;
 }
 
 /// 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
+#define CM_PER_INCH_FLOAT             2.54f
+#define MM_PER_INCH_FLOAT             25.4f
 
 /* 
  * Twips/unit conversions
  */
 inline nscoord NSUnitsToTwips(float aValue, float aPointsPerUnit)
 {
   return NSToCoordRoundWithClamp(aValue * aPointsPerUnit * TWIPS_PER_POINT_FLOAT);
 }
--- a/layout/style/nsROCSSPrimitiveValue.cpp
+++ b/layout/style/nsROCSSPrimitiveValue.cpp
@@ -308,22 +308,22 @@ nsROCSSPrimitiveValue::GetFloatValue(PRU
     case CSS_PX :
       if (mType != CSS_PX)
         return NS_ERROR_DOM_INVALID_ACCESS_ERR;
       *aReturn = nsPresContext::AppUnitsToFloatCSSPixels(mValue.mAppUnits);
       break;
     case CSS_CM :
       if (mType != CSS_PX)
         return NS_ERROR_DOM_INVALID_ACCESS_ERR;
-      *aReturn = mValue.mAppUnits * 2.54f / float(mAppUnitsPerInch);
+      *aReturn = mValue.mAppUnits * CM_PER_INCH_FLOAT / float(mAppUnitsPerInch);
       break;
     case CSS_MM :
       if (mType != CSS_PX)
         return NS_ERROR_DOM_INVALID_ACCESS_ERR;
-      *aReturn = mValue.mAppUnits * 25.4f / float(mAppUnitsPerInch);
+      *aReturn = mValue.mAppUnits * MM_PER_INCH_FLOAT / float(mAppUnitsPerInch);
       break;
     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)
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -975,17 +975,17 @@ nsChildView::GetDPI()
   size_t heightPx = CGDisplayPixelsHigh(displayID);
   CGFloat scaleFactor = [window userSpaceScaleFactor];
 
   // Currently we don't do our own scaling to take account
   // of userSpaceScaleFactor, so every "pixel" we draw is actually
   // userSpaceScaleFactor screen pixels. So divide the screen height
   // by userSpaceScaleFactor to get the number of "device pixels"
   // available.
-  return (heightPx / scaleFactor) / (heightMM / 25.4f);
+  return (heightPx / scaleFactor) / (heightMM / MM_PER_INCH_FLOAT);
 }
 
 LayerManager*
 nsChildView::GetLayerManager()
 {
   nsCocoaWindow* window = GetXULWindowWidget();
   if (window && window->GetAcceleratedRendering() != mUseAcceleratedRendering) {
     mLayerManager = NULL;
--- a/widget/src/gtk2/nsPaperPS.cpp
+++ b/widget/src/gtk2/nsPaperPS.cpp
@@ -35,23 +35,24 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
  
 #include "nsPaperPS.h"
 #include "plstr.h"
+#include "nsCoord.h"
 
 #define COUNTOF(x) (sizeof(x) / sizeof((x)[0]))
 
 const nsPaperSizePS_ nsPaperSizePS::mList[] =
 {
 #define SIZE_MM(x)      (x)
-#define SIZE_INCH(x)    ((x) * 25.4)
+#define SIZE_INCH(x)    ((x) * MM_PER_INCH_FLOAT)
     { "A5",             SIZE_MM(148),   SIZE_MM(210),   PR_TRUE },
     { "A4",             SIZE_MM(210),   SIZE_MM(297),   PR_TRUE },
     { "A3",             SIZE_MM(297),   SIZE_MM(420),   PR_TRUE },
     { "Letter",         SIZE_INCH(8.5), SIZE_INCH(11),  PR_FALSE },
     { "Legal",          SIZE_INCH(8.5), SIZE_INCH(14),  PR_FALSE },
     { "Tabloid",        SIZE_INCH(11),  SIZE_INCH(17),  PR_FALSE },
     { "Executive",      SIZE_INCH(7.5), SIZE_INCH(10),  PR_FALSE },
 #undef SIZE_INCH
--- a/widget/src/gtk2/nsWindow.cpp
+++ b/widget/src/gtk2/nsWindow.cpp
@@ -821,17 +821,17 @@ nsWindow::GetParent(void)
     return mParent;
 }
 
 float
 nsWindow::GetDPI()
 {
     Display *dpy = GDK_DISPLAY();
     int defaultScreen = DefaultScreen(dpy);
-    double heightInches = DisplayHeightMM(dpy, defaultScreen)/25.4;
+    double heightInches = DisplayHeightMM(dpy, defaultScreen)/MM_PER_INCH_FLOAT;
     if (heightInches < 0.25) {
         // Something's broken, but we'd better not crash.
         return 96.0f;
     }
     return float(DisplayHeight(dpy, defaultScreen)/heightInches);
 }
 
 NS_IMETHODIMP
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -1057,17 +1057,17 @@ nsIWidget* nsWindow::GetParent(void)
 }
 
 float nsWindow::GetDPI()
 {
   HDC dc = ::GetDC(mWnd);
   if (!dc)
     return 96.0f;
 
-  double heightInches = ::GetDeviceCaps(dc, VERTSIZE)/25.4;
+  double heightInches = ::GetDeviceCaps(dc, VERTSIZE)/MM_PER_INCH_FLOAT;
   int heightPx = ::GetDeviceCaps(dc, VERTRES);
   ::ReleaseDC(mWnd, dc);
   if (heightInches < 0.25) {
     // Something's broken
     return 96.0f;
   }
   return float(heightPx/heightInches);
 }