Bug 537890. Part 8: Define MM_PER_INCH_FLOAT. r=dbaron

This commit is contained in:
Robert O'Callahan 2010-08-13 21:57:57 +12:00
parent 4d8488759d
commit af7fdb42ac
8 changed files with 19 additions and 15 deletions

View File

@ -207,7 +207,7 @@ nsSVGLength2::GetMMPerPixel(nsIFrame *aNonSVGFrame)
nsPresContext* presContext = aNonSVGFrame->PresContext(); nsPresContext* presContext = aNonSVGFrame->PresContext();
float pixelsPerInch = float pixelsPerInch =
presContext->AppUnitsToFloatCSSPixels(presContext->AppUnitsPerInch()); presContext->AppUnitsToFloatCSSPixels(presContext->AppUnitsPerInch());
return 25.4f/pixelsPerInch; return MM_PER_INCH_FLOAT/pixelsPerInch;
} }
static float static float
@ -277,11 +277,11 @@ nsSVGLength2::GetUnitScaleFactor(nsSVGSVGElement *aCtx, PRUint8 aUnitType) const
case nsIDOMSVGLength::SVG_LENGTHTYPE_CM: case nsIDOMSVGLength::SVG_LENGTHTYPE_CM:
return GetMMPerPixel(aCtx) / 10.0f; return GetMMPerPixel(aCtx) / 10.0f;
case nsIDOMSVGLength::SVG_LENGTHTYPE_IN: case nsIDOMSVGLength::SVG_LENGTHTYPE_IN:
return GetMMPerPixel(aCtx) / 25.4f; return GetMMPerPixel(aCtx) / MM_PER_INCH_FLOAT;
case nsIDOMSVGLength::SVG_LENGTHTYPE_PT: 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: 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: case nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE:
return 100.0f / GetAxisLength(aCtx); return 100.0f / GetAxisLength(aCtx);
case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS: case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS:
@ -310,11 +310,11 @@ nsSVGLength2::GetUnitScaleFactor(nsIFrame *aFrame, PRUint8 aUnitType) const
case nsIDOMSVGLength::SVG_LENGTHTYPE_CM: case nsIDOMSVGLength::SVG_LENGTHTYPE_CM:
return GetMMPerPixel(aFrame) / 10.0f; return GetMMPerPixel(aFrame) / 10.0f;
case nsIDOMSVGLength::SVG_LENGTHTYPE_IN: case nsIDOMSVGLength::SVG_LENGTHTYPE_IN:
return GetMMPerPixel(aFrame) / 25.4f; return GetMMPerPixel(aFrame) / MM_PER_INCH_FLOAT;
case nsIDOMSVGLength::SVG_LENGTHTYPE_PT: 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: 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: case nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE:
return 100.0f / GetAxisLength(aFrame); return 100.0f / GetAxisLength(aFrame);
case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS: case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS:

View File

@ -317,7 +317,8 @@ nsSVGSVGElement::GetPixelUnitToMillimeterX(float *aPixelUnitToMillimeterX)
return NS_OK; return NS_OK;
} }
*aPixelUnitToMillimeterX = 25.4f / nsPresContext::AppUnitsToIntCSSPixels(context->AppUnitsPerInch()); *aPixelUnitToMillimeterX = MM_PER_INCH_FLOAT /
nsPresContext::AppUnitsToIntCSSPixels(context->AppUnitsPerInch());
return NS_OK; return NS_OK;
} }
@ -340,7 +341,7 @@ nsSVGSVGElement::GetScreenPixelToMillimeterX(float *aScreenPixelToMillimeterX)
return NS_OK; return NS_OK;
} }
*aScreenPixelToMillimeterX = 25.4f / *aScreenPixelToMillimeterX = MM_PER_INCH_FLOAT /
nsPresContext::AppUnitsToIntCSSPixels(context->AppUnitsPerInch()); nsPresContext::AppUnitsToIntCSSPixels(context->AppUnitsPerInch());
return NS_OK; return NS_OK;
} }

View File

@ -448,6 +448,8 @@ inline float NSCoordScale(nscoord aCoord, PRInt32 aFromAPP, PRInt32 aToAPP)
#define TWIPS_PER_POINT_FLOAT 20.0f #define TWIPS_PER_POINT_FLOAT 20.0f
#define POINTS_PER_INCH_INT 72 #define POINTS_PER_INCH_INT 72
#define POINTS_PER_INCH_FLOAT 72.0f #define POINTS_PER_INCH_FLOAT 72.0f
#define CM_PER_INCH_FLOAT 2.54f
#define MM_PER_INCH_FLOAT 25.4f
/* /*
* Twips/unit conversions * Twips/unit conversions

View File

@ -313,12 +313,12 @@ nsROCSSPrimitiveValue::GetFloatValue(PRUint16 aUnitType, float* aReturn)
case CSS_CM : case CSS_CM :
if (mType != CSS_PX) if (mType != CSS_PX)
return NS_ERROR_DOM_INVALID_ACCESS_ERR; return NS_ERROR_DOM_INVALID_ACCESS_ERR;
*aReturn = mValue.mAppUnits * 2.54f / float(mAppUnitsPerInch); *aReturn = mValue.mAppUnits * CM_PER_INCH_FLOAT / float(mAppUnitsPerInch);
break; break;
case CSS_MM : case CSS_MM :
if (mType != CSS_PX) if (mType != CSS_PX)
return NS_ERROR_DOM_INVALID_ACCESS_ERR; return NS_ERROR_DOM_INVALID_ACCESS_ERR;
*aReturn = mValue.mAppUnits * 25.4f / float(mAppUnitsPerInch); *aReturn = mValue.mAppUnits * MM_PER_INCH_FLOAT / float(mAppUnitsPerInch);
break; break;
case CSS_IN : case CSS_IN :
if (mType != CSS_PX) if (mType != CSS_PX)

View File

@ -980,7 +980,7 @@ nsChildView::GetDPI()
// userSpaceScaleFactor screen pixels. So divide the screen height // userSpaceScaleFactor screen pixels. So divide the screen height
// by userSpaceScaleFactor to get the number of "device pixels" // by userSpaceScaleFactor to get the number of "device pixels"
// available. // available.
return (heightPx / scaleFactor) / (heightMM / 25.4f); return (heightPx / scaleFactor) / (heightMM / MM_PER_INCH_FLOAT);
} }
LayerManager* LayerManager*

View File

@ -40,13 +40,14 @@
#include "nsPaperPS.h" #include "nsPaperPS.h"
#include "plstr.h" #include "plstr.h"
#include "nsCoord.h"
#define COUNTOF(x) (sizeof(x) / sizeof((x)[0])) #define COUNTOF(x) (sizeof(x) / sizeof((x)[0]))
const nsPaperSizePS_ nsPaperSizePS::mList[] = const nsPaperSizePS_ nsPaperSizePS::mList[] =
{ {
#define SIZE_MM(x) (x) #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 }, { "A5", SIZE_MM(148), SIZE_MM(210), PR_TRUE },
{ "A4", SIZE_MM(210), SIZE_MM(297), PR_TRUE }, { "A4", SIZE_MM(210), SIZE_MM(297), PR_TRUE },
{ "A3", SIZE_MM(297), SIZE_MM(420), PR_TRUE }, { "A3", SIZE_MM(297), SIZE_MM(420), PR_TRUE },

View File

@ -826,7 +826,7 @@ nsWindow::GetDPI()
{ {
Display *dpy = GDK_DISPLAY(); Display *dpy = GDK_DISPLAY();
int defaultScreen = DefaultScreen(dpy); int defaultScreen = DefaultScreen(dpy);
double heightInches = DisplayHeightMM(dpy, defaultScreen)/25.4; double heightInches = DisplayHeightMM(dpy, defaultScreen)/MM_PER_INCH_FLOAT;
if (heightInches < 0.25) { if (heightInches < 0.25) {
// Something's broken, but we'd better not crash. // Something's broken, but we'd better not crash.
return 96.0f; return 96.0f;

View File

@ -1062,7 +1062,7 @@ float nsWindow::GetDPI()
if (!dc) if (!dc)
return 96.0f; return 96.0f;
double heightInches = ::GetDeviceCaps(dc, VERTSIZE)/25.4; double heightInches = ::GetDeviceCaps(dc, VERTSIZE)/MM_PER_INCH_FLOAT;
int heightPx = ::GetDeviceCaps(dc, VERTRES); int heightPx = ::GetDeviceCaps(dc, VERTRES);
::ReleaseDC(mWnd, dc); ::ReleaseDC(mWnd, dc);
if (heightInches < 0.25) { if (heightInches < 0.25) {