Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Defines | Enumerations | Functions
units.h File Reference
#include "scribusapi.h"
#include <qstring.h>
#include <qstringlist.h>

Go to the source code of this file.

Defines

#define UNITMIN   0
#define UNITMAX   5

Enumerations

enum  scUnit {
  SC_POINTS = 0, SC_PT = 0, SC_MILLIMETERS = 1, SC_MM = 1,
  SC_INCHES = 2, SC_IN = 2, SC_PICAS = 3, SC_P = 3,
  SC_CENTIMETERS = 4, SC_CM = 4, SC_CICERO = 5, SC_C = 5
}

Functions

const double SCRIBUS_API unitGetRatioFromIndex (const int index)
 Returns the ratio to points for the selected unit of measure.
const QString SCRIBUS_API unitGetStrFromIndex (const int index)
 Returns a general suffix for each of the units.
const QString SCRIBUS_API unitGetUntranslatedStrFromIndex (const int index)
 Returns a general untranslated suffix for each of the units.
const QString SCRIBUS_API unitGetSuffixFromIndex (const int index)
 Returns the suffix used in GUI widgets.
const int SCRIBUS_API unitGetDecimalsFromIndex (const int index)
 Returns the decimals for the units.
const int SCRIBUS_API unitGetPrecisionFromIndex (const int index)
 Returns the precision for the units.
const double SCRIBUS_API unitValueFromString (const QString &value)
 Strip the text from a value and return the double value for the unit.
const scUnit SCRIBUS_API unitIndexFromString (const QString &value)
 Strip the text from a value and return the Unit index for the value.
const QStringList SCRIBUS_API unitGetTextUnitList ()
 Returns a QStringList of the units for use in QComboBoxes etc.
const int SCRIBUS_API unitGetMaxIndex ()
 Returns the maximum index of the units we have now.
const double SCRIBUS_API mm2pts (double mm)
 Returns the pts value from the mm value supplied.
const double SCRIBUS_API in2pts (double in)
 Returns the pts value from the in value supplied.
const double SCRIBUS_API p2pts (double p)
 Returns the pts value from the pica value supplied.
const double SCRIBUS_API cm2pts (double cm)
 Returns the pts value from the cm value supplied.
const double SCRIBUS_API c2pts (double c)
 Returns the pts value from the cm value supplied.
const double SCRIBUS_API pts2mm (double pts)
 Returns the mm value from the pt value supplied.
const double SCRIBUS_API pts2in (double pts)
 Returns the in value from the pt value supplied.
const double SCRIBUS_API pts2p (double pts)
 Returns the pica value from the pt value supplied.
const double SCRIBUS_API pts2cm (double pts)
 Returns the cm value from the pt value supplied.
const double SCRIBUS_API pts2c (double pts)
 Returns the c value from the pt value supplied.
double SCRIBUS_API pts2value (double Val, int unit)
 Returns the value from the pt value supplied based on unit index.
double SCRIBUS_API value2pts (double unitValue, int unit)
 Returns the pt value from the value supplied based on unit index.
double SCRIBUS_API value2value (double unitValue, int primaryUnit, int secondaryUnit)
 Returns the secondary unit value from the value supplied based on primary unit.
double SCRIBUS_API unitRulerGetIter1FromIndex (const int index)
 Sets up iteration value 1 for vruler, hruler and tabruler.
double SCRIBUS_API unitRulerGetIter2FromIndex (const int index)
 Sets up iteration value 2 for vruler, hruler and tabruler.

Define Documentation

#define UNITMAX   5

Definition at line 30 of file units.h.

#define UNITMIN   0

Definition at line 29 of file units.h.


Enumeration Type Documentation

enum scUnit
Enumerator:
SC_POINTS 
SC_PT 
SC_MILLIMETERS 
SC_MM 
SC_INCHES 
SC_IN 
SC_PICAS 
SC_P 
SC_CENTIMETERS 
SC_CM 
SC_CICERO 
SC_C 

Definition at line 32 of file units.h.

            {
       SC_POINTS      = 0,
       SC_PT          = 0,
       SC_MILLIMETERS = 1,
       SC_MM          = 1,
       SC_INCHES      = 2,
       SC_IN          = 2,
       SC_PICAS       = 3,
       SC_P           = 3,
       SC_CENTIMETERS = 4,
       SC_CM          = 4,
       SC_CICERO      = 5,
       SC_C           = 5
};

Function Documentation

const double SCRIBUS_API c2pts ( double  c)

Returns the pts value from the cm value supplied.

Definition at line 229 of file units.cpp.

{
       return c / unitGetRatioFromIndex(SC_C);
}

Here is the call graph for this function:

const double SCRIBUS_API cm2pts ( double  cm)

Returns the pts value from the cm value supplied.

Definition at line 221 of file units.cpp.

{
       return cm / unitGetRatioFromIndex(SC_CM);
}

Here is the call graph for this function:

const double SCRIBUS_API in2pts ( double  in)

Returns the pts value from the in value supplied.

Definition at line 205 of file units.cpp.

{
       return in / unitGetRatioFromIndex(SC_IN);
}

Here is the call graph for this function:

const double SCRIBUS_API mm2pts ( double  mm)

Returns the pts value from the mm value supplied.

Definition at line 197 of file units.cpp.

{
       return mm / unitGetRatioFromIndex(SC_MM);
}

Here is the call graph for this function:

const double SCRIBUS_API p2pts ( double  p)

Returns the pts value from the pica value supplied.

Definition at line 213 of file units.cpp.

{
       return p / unitGetRatioFromIndex(SC_P);
}

Here is the call graph for this function:

const double SCRIBUS_API pts2c ( double  pts)

Returns the c value from the pt value supplied.

Definition at line 269 of file units.cpp.

{
       return pts * unitGetRatioFromIndex(SC_C);
}

Here is the call graph for this function:

const double SCRIBUS_API pts2cm ( double  pts)

Returns the cm value from the pt value supplied.

Definition at line 261 of file units.cpp.

{
       return pts * unitGetRatioFromIndex(SC_CM);
}

Here is the call graph for this function:

const double SCRIBUS_API pts2in ( double  pts)

Returns the in value from the pt value supplied.

Definition at line 245 of file units.cpp.

{
       return pts * unitGetRatioFromIndex(SC_IN);
}

Here is the call graph for this function:

const double SCRIBUS_API pts2mm ( double  pts)

Returns the mm value from the pt value supplied.

Definition at line 237 of file units.cpp.

{
       return pts * unitGetRatioFromIndex(SC_MM);
}

Here is the call graph for this function:

const double SCRIBUS_API pts2p ( double  pts)

Returns the pica value from the pt value supplied.

Definition at line 253 of file units.cpp.

{
       return pts * unitGetRatioFromIndex(SC_P);
}

Here is the call graph for this function:

double SCRIBUS_API pts2value ( double  Val,
int  unit 
)

Returns the value from the pt value supplied based on unit index.

Definition at line 277 of file units.cpp.

{
       double ret = 0.0;
       switch (unit)
       {
              case 0:
                     ret = unitValue; //dont multiply by 1
                     break;
              default:
                     ret = unitValue * unitGetRatioFromIndex(unit);
                     break;
       }
       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const int SCRIBUS_API unitGetDecimalsFromIndex ( const int  index)

Returns the decimals for the units.

Definition at line 150 of file units.cpp.

{
       if (index<UNITMIN || index>UNITMAX) 
              return 0;
       //                      PT,   MM,    IN,   P,    CM,   C
       int decimalPoints[] = {100, 1000, 10000, 100, 10000, 10000};
       return decimalPoints[index];
}

Here is the caller graph for this function:

Returns the maximum index of the units we have now.

Definition at line 189 of file units.cpp.

{
       return UNITMAX;
}

Here is the caller graph for this function:

const int SCRIBUS_API unitGetPrecisionFromIndex ( const int  index)

Returns the precision for the units.

Definition at line 162 of file units.cpp.

{
       if (index<UNITMIN || index>UNITMAX) 
              return 0;
       //                PT,MM,IN, P,CM, C
       int precision[] = {2, 3, 4, 2, 4, 4};
       return precision[index];
}
const double SCRIBUS_API unitGetRatioFromIndex ( const int  index)

Returns the ratio to points for the selected unit of measure.

Ratios are for: PT, MM, IN, P, CM, C

Definition at line 29 of file units.cpp.

{
       //PT, MM, IN, P, CM, C (Cicero)
       //NOTE: Calling functions that divide by this value will crash on divide by 0. They shouldnt be getting
       // a zero value if they are accessing here with a correct index.
       if (index<UNITMIN || index>UNITMAX)
              return 0;
       double ratio[] = { 1.0, 25.4/72.0, 1.0/72.0, 1.0/12.0, 2.54/72.0, 25.4/72.0/4.512 };
       return ratio[index];
}

Here is the caller graph for this function:

const QString SCRIBUS_API unitGetStrFromIndex ( const int  index)

Returns a general suffix for each of the units.

Definition at line 129 of file units.cpp.

{
       if (index<UNITMIN || index>UNITMAX) 
              return "";
       QString suffix[] = { QObject::tr("pt"), QObject::tr("mm"), QObject::tr("in"), QObject::tr("p"), QObject::tr("cm"), QObject::tr("c") };
       return suffix[index];
}

Here is the call graph for this function:

Here is the caller graph for this function:

const QString SCRIBUS_API unitGetSuffixFromIndex ( const int  index)

Returns the suffix used in GUI widgets.

Definition at line 117 of file units.cpp.

{
       //Could also return " "+unitGetStrFromIndex(indeX);
       if (index<UNITMIN || index>UNITMAX) 
              return "";
       QString suffix[] = { QObject::tr(" pt"), QObject::tr(" mm"), QObject::tr(" in"), QObject::tr(" p"), QObject::tr(" cm"), QObject::tr(" c") };
       return suffix[index];
}

Here is the call graph for this function:

Here is the caller graph for this function:

const QStringList SCRIBUS_API unitGetTextUnitList ( )

Returns a QStringList of the units for use in QComboBoxes etc.

Definition at line 174 of file units.cpp.

{
       QStringList suffixList;
       suffixList.append( QObject::tr( "Points (pt)" ) );
       suffixList.append( QObject::tr( "Millimeters (mm)" ) );
       suffixList.append( QObject::tr( "Inches (in)" ) );
       suffixList.append( QObject::tr( "Picas (p)" ) );
       suffixList.append( QObject::tr( "Centimeters (cm)" ) );
       suffixList.append( QObject::tr( "Cicero (c)" ) );
       return QStringList(suffixList);
}

Here is the call graph for this function:

const QString SCRIBUS_API unitGetUntranslatedStrFromIndex ( const int  index)

Returns a general untranslated suffix for each of the units.

Definition at line 140 of file units.cpp.

{
       if (index<UNITMIN || index>UNITMAX) 
              return "";
       QString suffix[] = { "pt", "mm", "in", "p", "cm", "c" };
       return suffix[index];
}
const scUnit SCRIBUS_API unitIndexFromString ( const QString &  value)

Strip the text from a value and return the Unit index for the value.

Definition at line 81 of file units.cpp.

{
       QString lowerValue = value.lower();
       scUnit retVal;
       if (lowerValue.find("pt") != -1)
       {
              retVal=SC_PT;
       }
       else if (lowerValue.find("mm") != -1)
       {
              retVal=SC_MM;
       }
       else if (lowerValue.find("in") != -1)
       {
              retVal=SC_IN;
       }
       else if (lowerValue.find("p") != -1)
       {
              retVal=SC_P;
       }
       else if (lowerValue.find("cm") != -1)
       {
              retVal=SC_CM;
       }
       else if (lowerValue.find("c") != -1)
       {
              retVal=SC_C;
       }      
       else
              retVal=SC_PT;
       return retVal;
}

Here is the caller graph for this function:

double SCRIBUS_API unitRulerGetIter1FromIndex ( const int  index)

Sets up iteration value 1 for vruler, hruler and tabruler.

Definition at line 328 of file units.cpp.

{
       if (index<UNITMIN || index>UNITMAX) 
              return 0;
       //                 PT,         MM,   IN,    P,        CM,               C
       double iter[] = {10.0, 720.0/25.4, 18.0, 12.0, 72.0/25.4, 72.0/25.4*4.512};
       return iter[index];
}
double SCRIBUS_API unitRulerGetIter2FromIndex ( const int  index)

Sets up iteration value 2 for vruler, hruler and tabruler.

Definition at line 340 of file units.cpp.

{
       if (index<UNITMIN || index>UNITMAX) 
              return 0;
       //                  PT,          MM,   IN,     P,         CM,                C
       double iter[] = {100.0, 7200.0/25.4, 72.0, 120.0, 720.0/25.4, 720.0/25.4*4.512};
       return iter[index];
}
const double SCRIBUS_API unitValueFromString ( const QString &  value)

Strip the text from a value and return the double value for the unit.

Definition at line 43 of file units.cpp.

{
       QString lowerValue = value.lower();
       QString dbl = "0.0";
       if (lowerValue.find("pt") != -1)
       {
              dbl = lowerValue.remove("pt");
       }
       else if (lowerValue.find("mm") != -1)
       {
              dbl = lowerValue.remove("mm");
       }
       else if (lowerValue.find("in") != -1)
       {
              dbl = lowerValue.remove("in");
       }
       else if (lowerValue.find("p") != -1)
       {
              dbl = lowerValue.remove("p");
       }
       else if (lowerValue.find("cm") != -1)
       {
              dbl = lowerValue.remove("cm");
       }
       else if (lowerValue.find("c") != -1)
       {
              dbl = lowerValue.remove("c");
       }
       else
              dbl = "0.0";

       dbl = dbl.stripWhiteSpace();
       return dbl.toDouble();
}
double SCRIBUS_API value2pts ( double  unitValue,
int  unit 
)

Returns the pt value from the value supplied based on unit index.

Definition at line 295 of file units.cpp.

{
       double ret = 0.0;
       switch (unit)
       {
              case 0:
                     ret = unitValue; // dont divide by 1
                     break;
              default:
                     ret = unitValue / unitGetRatioFromIndex(unit);
                     break;
       }
       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double SCRIBUS_API value2value ( double  unitValue,
int  primaryUnit,
int  secondaryUnit 
)

Returns the secondary unit value from the value supplied based on primary unit.

Definition at line 313 of file units.cpp.

{
       if (primaryUnit==secondaryUnit)
              return unitValue;
              
       double pts = 0.0, ret = 0.0;
       //Can make this not convert to points at a later stage, for now, the function exists and works.
       pts= primaryUnit==0 ? unitValue : unitValue / unitGetRatioFromIndex(primaryUnit);
       ret= secondaryUnit==0 ? pts : pts * unitGetRatioFromIndex(secondaryUnit);
       return ret;
}

Here is the call graph for this function: