1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
/************************************************************************/
/* */
/* Unit types and conversions between units. */
/* */
/************************************************************************/
# include "config.h"
# include "appUnit.h"
# include <debugon.h>
int appUnitTypeInt( const char * unitTypeString )
{
if ( ! strcmp( unitTypeString, "cm" ) )
{ return UNITtyCM; }
if ( ! strcmp( unitTypeString, "inch" ) ||
! strcmp( unitTypeString, "\"" ) )
{ return UNITtyINCH; }
if ( ! strcmp( unitTypeString, "points" ) ||
! strcmp( unitTypeString, "pt" ) )
{ return UNITtyPOINTS; }
if ( ! strcmp( unitTypeString, "picas" ) ||
! strcmp( unitTypeString, "pi" ) )
{ return UNITtyPICAS; }
if ( ! strcmp( unitTypeString, "mm" ) )
{ return UNITtyMM; }
return -1;
}
const char * appUnitTypeString( int unitTypeInt )
{
switch( unitTypeInt )
{
case UNITtyCM: return "cm";
case UNITtyINCH: return "\"";
case UNITtyPOINTS: return "pt";
case UNITtyPICAS: return "pi";
case UNITtyMM: return "mm";
default:
LDEB(unitTypeInt); return "?";
}
}
double appUnitFromTwips( int twips,
int unitTypeInt )
{
switch( unitTypeInt )
{
case UNITtyCM: return ( 2.54* twips )/ ( 20.0* 72 );
case UNITtyINCH: return twips/ ( 20.0* 72 );
case UNITtyPOINTS: return twips/ 20.0;
case UNITtyPICAS: return twips/ ( 20.0* 12 );
case UNITtyMM: return ( 25.4* twips )/ ( 20.0* 72 );
default:
LDEB(unitTypeInt); return -1;
}
}
double appUnitToTwips( double units,
int unitTypeInt )
{
switch( unitTypeInt )
{
case UNITtyCM: return ( 20.0* 72* units )/ 2.54;
case UNITtyINCH: return 20.0* 72* units;
case UNITtyPOINTS: return 20.0* units;
case UNITtyPICAS: return 20.0* 12* units;
case UNITtyMM: return ( 20.0* 72* units )/ 25.4;
default:
LDEB(unitTypeInt); return -1;
}
}
|