1 /* AbiSource Program Utilities 2 * Copyright (C) 1998 AbiSource, Inc. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 * 02110-1301 USA. 18 */ 19 20 #ifndef UT_UNITS_H 21 #define UT_UNITS_H 22 23 /* pre-emptive dismissal; ut_types.h is needed by just about everything, 24 * so even if it's commented out in-file that's still a lot of work for 25 * the preprocessor to do... 26 */ 27 #ifndef UT_TYPES_H 28 #include "ut_types.h" 29 #endif 30 31 G_BEGIN_DECLS 32 33 #define UT_PAPER_UNITS_PER_INCH 100 34 /* Units of UT_LAYOUT_RESOLUTION = dots per inch */ 35 #define UT_LAYOUT_RESOLUTION 1440 36 37 /* 2^31 -1 */ 38 39 #define UT_INT_MAX 2147483647 40 41 typedef enum _ut_dimension { DIM_IN, DIM_CM, DIM_MM, DIM_PI, DIM_PT, DIM_PX, DIM_PERCENT, DIM_STAR, DIM_none } UT_Dimension; 42 43 /* 44 * DIM_IN := inches 45 * DIM_CM := centimeters 46 * DIM_MM := millimeters 47 * DIM_PI := picas 48 * DIM_PT := points 49 * DIM_PX := pixels 50 */ 51 52 ABI_EXPORT double UT_convertToInches(const char* s); 53 ABI_EXPORT double UT_convertDimToInches (double f, UT_Dimension dim); 54 ABI_EXPORT double UT_convertDimensions(double f, UT_Dimension from, UT_Dimension to); 55 ABI_EXPORT double UT_convertToPoints(const char* s); 56 ABI_EXPORT double UT_convertToDimension(const char* s, UT_Dimension dim); 57 ABI_EXPORT UT_sint32 UT_convertToLogicalUnits(const char* s); 58 ABI_EXPORT UT_sint32 UT_convertSizeToLayoutUnits(double Value, UT_Dimension dim); 59 ABI_EXPORT double UT_convertDimensionless(const char * sz); 60 ABI_EXPORT double UT_convertInchesToDimension(double inches, UT_Dimension dim); 61 62 ABI_EXPORT UT_sint32 UT_paperUnits(const char * sz); 63 ABI_EXPORT double UT_inchesFromPaperUnits(UT_sint32 iPaperUnits); 64 ABI_EXPORT UT_sint32 UT_paperUnitsFromInches(double dInches); 65 66 ABI_EXPORT const char * UT_incrementDimString(const char * dimString, double inc); 67 ABI_EXPORT const char * UT_multiplyDimString(const char * dimString, double mult); 68 ABI_EXPORT UT_Dimension UT_determineDimension(const char * sz, UT_Dimension fallback = DIM_IN); 69 ABI_EXPORT const char * UT_dimensionName(UT_Dimension dim); 70 ABI_EXPORT const char * UT_convertInchesToDimensionString(UT_Dimension, double valueInInches, const char * szPrecision = NULL); 71 ABI_EXPORT const char * UT_formatDimensionString(UT_Dimension, double value, const char * szPrecision = NULL); 72 ABI_EXPORT const char * UT_reformatDimensionString(UT_Dimension dim, const char *sz, const char * szPrecision = NULL); 73 ABI_EXPORT const char * UT_convertToDimensionlessString(double value, const char * szPrecision = NULL); 74 ABI_EXPORT const char * UT_formatDimensionedValue(double value, const char * szUnits, const char * szPrecision = NULL); 75 76 ABI_EXPORT bool UT_hasDimensionComponent(const char * sz); 77 ABI_EXPORT bool UT_isValidDimensionString(const char * sz, size_t max_length = 0); 78 79 ABI_EXPORT UT_uint32 UT_getDimensionPrecisicion (UT_Dimension dim); 80 ABI_EXPORT double UT_getDimensionResolution (UT_Dimension dim); 81 ABI_EXPORT double UT_convertFraction(const char * sz); 82 83 G_END_DECLS 84 85 #endif /* UT_UNITS_H */ 86