Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsUnitConversion.h File Reference
#include "nscore.h"
#include "nsCoord.h"
#include <math.h>
#include <float.h>

Go to the source code of this file.

Defines

#define FLT_EPSILON   1.19209290e-7f
#define TWIPS_PER_POINT_INT   20
 handy constants
#define TWIPS_PER_POINT_FLOAT   20.0f
#define ROUND_CONST_FLOAT   0.5f
#define CEIL_CONST_FLOAT   (1.0f - 0.5f*FLT_EPSILON)
#define NS_INCHES_TO_TWIPS(x)   NSUnitsToTwips((x), 72.0f)
 Unit conversion macros.
#define NS_FEET_TO_TWIPS(x)   NSUnitsToTwips((x), (72.0f * 12.0f))
#define NS_MILES_TO_TWIPS(x)   NSUnitsToTwips((x), (72.0f * 12.0f * 5280.0f))
#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_PICAS_TO_TWIPS(x)   NSUnitsToTwips((x), 12.0f)
#define NS_DIDOTS_TO_TWIPS(x)   NSUnitsToTwips((x), (16.0f / 15.0f))
#define NS_CICEROS_TO_TWIPS(x)   NSUnitsToTwips((x), (12.0f * (16.0f / 15.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_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_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)))

Functions

nscoord NSToCoordFloor (float aValue)
nscoord NSToCoordCeil (float aValue)
nscoord NSToCoordRound (float aValue)
PRInt32 NSToIntFloor (float aValue)
PRInt32 NSToIntCeil (float aValue)
PRInt32 NSToIntRound (float aValue)
nscoord NSFloatPointsToTwips (float aPoints)
nscoord NSIntPointsToTwips (PRInt32 aPoints)
PRInt32 NSTwipsToIntPoints (nscoord aTwips)
PRInt32 NSTwipsToFloorIntPoints (nscoord aTwips)
PRInt32 NSTwipsToCeilIntPoints (nscoord aTwips)
float NSTwipsToFloatPoints (nscoord aTwips)
nscoord NSFloatPixelsToTwips (float aPixels, float aTwipsPerPixel)
nscoord NSIntPixelsToTwips (PRInt32 aPixels, float aTwipsPerPixel)
float NSTwipsToFloatPixels (nscoord aTwips, float aPixelsPerTwip)
PRInt32 NSTwipsToIntPixels (nscoord aTwips, float aPixelsPerTwip)
nscoord NSUnitsToTwips (float aValue, float aPointsPerUnit)
float NSTwipsToUnits (nscoord aTwips, float aUnitsPerPoint)

Define Documentation

#define CEIL_CONST_FLOAT   (1.0f - 0.5f*FLT_EPSILON)

Definition at line 53 of file nsUnitConversion.h.

#define FLT_EPSILON   1.19209290e-7f

Definition at line 47 of file nsUnitConversion.h.

#define NS_CENTIMETERS_TO_TWIPS (   x)    NSUnitsToTwips((x), (72.0f * 0.3937f))

Definition at line 191 of file nsUnitConversion.h.

#define NS_CICEROS_TO_TWIPS (   x)    NSUnitsToTwips((x), (12.0f * (16.0f / 15.0f)))

Definition at line 197 of file nsUnitConversion.h.

#define NS_DIDOTS_TO_TWIPS (   x)    NSUnitsToTwips((x), (16.0f / 15.0f))

Definition at line 196 of file nsUnitConversion.h.

#define NS_FEET_TO_TWIPS (   x)    NSUnitsToTwips((x), (72.0f * 12.0f))

Definition at line 187 of file nsUnitConversion.h.

#define NS_INCHES_TO_TWIPS (   x)    NSUnitsToTwips((x), 72.0f)

Unit conversion macros.

Definition at line 186 of file nsUnitConversion.h.

#define NS_KILOMETERS_TO_TWIPS (   x)    NSUnitsToTwips((x), (72.0f * 39370.0f))

Definition at line 193 of file nsUnitConversion.h.

#define NS_METERS_TO_TWIPS (   x)    NSUnitsToTwips((x), (72.0f * 39.37f))

Definition at line 192 of file nsUnitConversion.h.

#define NS_MILES_TO_TWIPS (   x)    NSUnitsToTwips((x), (72.0f * 12.0f * 5280.0f))

Definition at line 188 of file nsUnitConversion.h.

#define NS_MILLIMETERS_TO_TWIPS (   x)    NSUnitsToTwips((x), (72.0f * 0.03937f))

Definition at line 190 of file nsUnitConversion.h.

#define NS_PICAS_TO_TWIPS (   x)    NSUnitsToTwips((x), 12.0f)

Definition at line 195 of file nsUnitConversion.h.

#define NS_TWIPS_TO_CENTIMETERS (   x)    NSTwipsToUnits((x), 1.0f / (72.0f * 0.3937f))

Definition at line 205 of file nsUnitConversion.h.

#define NS_TWIPS_TO_CICEROS (   x)    NSTwipsToUnits((x), 1.0f / (12.0f * (16.0f / 15.0f)))

Definition at line 211 of file nsUnitConversion.h.

#define NS_TWIPS_TO_DIDOTS (   x)    NSTwipsToUnits((x), 1.0f / (16.0f / 15.0f))

Definition at line 210 of file nsUnitConversion.h.

#define NS_TWIPS_TO_FEET (   x)    NSTwipsToUnits((x), 1.0f / (72.0f * 12.0f))

Definition at line 201 of file nsUnitConversion.h.

#define NS_TWIPS_TO_INCHES (   x)    NSTwipsToUnits((x), 1.0f / 72.0f)

Definition at line 200 of file nsUnitConversion.h.

#define NS_TWIPS_TO_KILOMETERS (   x)    NSTwipsToUnits((x), 1.0f / (72.0f * 39370.0f))

Definition at line 207 of file nsUnitConversion.h.

#define NS_TWIPS_TO_METERS (   x)    NSTwipsToUnits((x), 1.0f / (72.0f * 39.37f))

Definition at line 206 of file nsUnitConversion.h.

#define NS_TWIPS_TO_MILES (   x)    NSTwipsToUnits((x), 1.0f / (72.0f * 12.0f * 5280.0f))

Definition at line 202 of file nsUnitConversion.h.

#define NS_TWIPS_TO_MILLIMETERS (   x)    NSTwipsToUnits((x), 1.0f / (72.0f * 0.03937f))

Definition at line 204 of file nsUnitConversion.h.

#define NS_TWIPS_TO_PICAS (   x)    NSTwipsToUnits((x), 1.0f / 12.0f)

Definition at line 209 of file nsUnitConversion.h.

Definition at line 52 of file nsUnitConversion.h.

Definition at line 51 of file nsUnitConversion.h.

handy constants

Definition at line 50 of file nsUnitConversion.h.


Function Documentation

nscoord NSFloatPixelsToTwips ( float  aPixels,
float  aTwipsPerPixel 
) [inline]

Definition at line 142 of file nsUnitConversion.h.

{
  nscoord r = NSToCoordRound(aPixels * aTwipsPerPixel);
  VERIFY_COORD(r);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nscoord NSFloatPointsToTwips ( float  aPoints) [inline]

Definition at line 107 of file nsUnitConversion.h.

{
  return NSToCoordRound(aPoints * TWIPS_PER_POINT_FLOAT);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nscoord NSIntPixelsToTwips ( PRInt32  aPixels,
float  aTwipsPerPixel 
) [inline]

Definition at line 149 of file nsUnitConversion.h.

{
#ifdef NS_COORD_IS_FLOAT
  nscoord r = aPixels * aTwipsPerPixel;
#else
  nscoord r = NSToCoordRound(float(aPixels) * aTwipsPerPixel);
#endif
  VERIFY_COORD(r);
  return r;
}

Here is the call graph for this function:

nscoord NSIntPointsToTwips ( PRInt32  aPoints) [inline]

Definition at line 112 of file nsUnitConversion.h.

{
  // If nscoord is a float, do the multiplication as float to avoid
  // overflow
  return nscoord(aPoints) * TWIPS_PER_POINT_INT;
}

Here is the caller graph for this function:

nscoord NSToCoordCeil ( float  aValue) [inline]

Definition at line 68 of file nsUnitConversion.h.

{
#ifdef NS_COORD_IS_FLOAT
  return ceilf(aValue);
#else
  return ((0.0f <= aValue) ? nscoord(aValue + CEIL_CONST_FLOAT) : nscoord(aValue));
#endif
}

Here is the caller graph for this function:

nscoord NSToCoordFloor ( float  aValue) [inline]

Definition at line 59 of file nsUnitConversion.h.

{
#ifdef NS_COORD_IS_FLOAT
  return floorf(aValue);
#else
  return ((0.0f <= aValue) ? nscoord(aValue) : nscoord(aValue - CEIL_CONST_FLOAT));
#endif
}

Here is the caller graph for this function:

nscoord NSToCoordRound ( float  aValue) [inline]

Definition at line 77 of file nsUnitConversion.h.

{
#ifdef NS_COORD_IS_FLOAT
  return floorf(aValue + ROUND_CONST_FLOAT);
#else
  return ((0.0f <= aValue) ? nscoord(aValue + ROUND_CONST_FLOAT) : nscoord(aValue - ROUND_CONST_FLOAT));
#endif
}
PRInt32 NSToIntCeil ( float  aValue) [inline]

Definition at line 94 of file nsUnitConversion.h.

{
  return ((0.0f <= aValue) ? PRInt32(aValue + CEIL_CONST_FLOAT) : PRInt32(aValue));
}

Here is the caller graph for this function:

PRInt32 NSToIntFloor ( float  aValue) [inline]

Definition at line 89 of file nsUnitConversion.h.

{
  return ((0.0f <= aValue) ? PRInt32(aValue) : PRInt32(aValue - CEIL_CONST_FLOAT));
}

Here is the caller graph for this function:

PRInt32 NSToIntRound ( float  aValue) [inline]

Definition at line 99 of file nsUnitConversion.h.

PRInt32 NSTwipsToCeilIntPoints ( nscoord  aTwips) [inline]

Definition at line 129 of file nsUnitConversion.h.

{
  return NSToIntCeil(aTwips / TWIPS_PER_POINT_FLOAT);
}

Here is the call graph for this function:

float NSTwipsToFloatPixels ( nscoord  aTwips,
float  aPixelsPerTwip 
) [inline]

Definition at line 160 of file nsUnitConversion.h.

{
  return (float(aTwips) * aPixelsPerTwip);
}

Here is the caller graph for this function:

float NSTwipsToFloatPoints ( nscoord  aTwips) [inline]

Definition at line 134 of file nsUnitConversion.h.

{
  return (float(aTwips) / TWIPS_PER_POINT_FLOAT);
}

Here is the caller graph for this function:

PRInt32 NSTwipsToFloorIntPoints ( nscoord  aTwips) [inline]

Definition at line 124 of file nsUnitConversion.h.

{
  return NSToIntFloor(aTwips / TWIPS_PER_POINT_FLOAT);
}

Here is the call graph for this function:

PRInt32 NSTwipsToIntPixels ( nscoord  aTwips,
float  aPixelsPerTwip 
) [inline]

Definition at line 165 of file nsUnitConversion.h.

{
  return NSToIntRound(float(aTwips) * aPixelsPerTwip);
}

Here is the call graph for this function:

PRInt32 NSTwipsToIntPoints ( nscoord  aTwips) [inline]

Definition at line 119 of file nsUnitConversion.h.

{
  return NSToIntRound(aTwips / TWIPS_PER_POINT_FLOAT);
}

Here is the call graph for this function:

Here is the caller graph for this function:

float NSTwipsToUnits ( nscoord  aTwips,
float  aUnitsPerPoint 
) [inline]

Definition at line 178 of file nsUnitConversion.h.

{
  return (aTwips * (aUnitsPerPoint / TWIPS_PER_POINT_FLOAT));
}
nscoord NSUnitsToTwips ( float  aValue,
float  aPointsPerUnit 
) [inline]

Definition at line 173 of file nsUnitConversion.h.

{
  return NSToCoordRound(aValue * aPointsPerUnit * TWIPS_PER_POINT_FLOAT);
}

Here is the call graph for this function: