1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ 2 /* 3 * go-format.h : 4 * 5 * Copyright (C) 2003-2005 Jody Goldberg (jody@gnome.org) 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) version 3. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 20 * USA 21 */ 22 #ifndef GO_FORMAT_H 23 #define GO_FORMAT_H 24 25 #include <goffice/goffice.h> 26 #include <gsf/gsf-libxml.h> 27 28 G_BEGIN_DECLS 29 30 #define GO_SUPERSCRIPT_SCALE PANGO_SCALE_SMALL 31 #define GO_SUBSCRIPT_SCALE PANGO_SCALE_SMALL 32 #define GO_SUPERSCRIPT_RISE 5000 33 #define GO_SUBSCRIPT_RISE -5000 34 35 36 /* Keep these sequential. */ 37 typedef enum { 38 GO_FORMAT_UNKNOWN = -1, 39 40 GO_FORMAT_GENERAL = 0, 41 GO_FORMAT_NUMBER = 1, 42 GO_FORMAT_CURRENCY = 2, 43 GO_FORMAT_ACCOUNTING = 3, 44 GO_FORMAT_DATE = 4, 45 GO_FORMAT_TIME = 5, 46 GO_FORMAT_PERCENTAGE = 6, 47 GO_FORMAT_FRACTION = 7, 48 GO_FORMAT_SCIENTIFIC = 8, 49 GO_FORMAT_TEXT = 9, 50 GO_FORMAT_SPECIAL = 10, 51 52 /* <private> */ 53 GO_FORMAT_MARKUP = 11 /* Internal use only */ 54 } GOFormatFamily; 55 56 typedef enum { 57 GO_FORMAT_MAGIC_NONE = 0, 58 GO_FORMAT_MAGIC_LONG_DATE = 0xf800, /* Official */ 59 GO_FORMAT_MAGIC_MEDIUM_DATE = 0xf8f1, 60 GO_FORMAT_MAGIC_SHORT_DATE = 0xf8f2, 61 GO_FORMAT_MAGIC_SHORT_DATETIME = 0xf8fa, 62 GO_FORMAT_MAGIC_LONG_TIME = 0xf400, /* Official */ 63 GO_FORMAT_MAGIC_MEDIUM_TIME = 0xf4f1, 64 GO_FORMAT_MAGIC_SHORT_TIME = 0xf4f2 65 } GOFormatMagic; 66 67 typedef enum { 68 GO_FORMAT_NUMBER_OK = 0, 69 GO_FORMAT_NUMBER_INVALID_FORMAT, 70 GO_FORMAT_NUMBER_DATE_ERROR 71 } GOFormatNumberError; 72 73 typedef struct { 74 gchar const *symbol; 75 gchar const *description; 76 gboolean precedes; 77 gboolean has_space; 78 } GOFormatCurrency; 79 80 GType go_format_currency_get_type (void); 81 82 typedef struct { 83 GOFormatFamily family; 84 GOFormatMagic magic; 85 86 /* NUMBER, SCIENTIFIC, CURRENCY, ACCOUNTING, FRACTION, PERCENTAGE: */ 87 int min_digits; 88 int num_decimals; 89 90 /* NUMBER, CURRENCY, ACCOUNTING, PERCENTAGE: */ 91 gboolean thousands_sep; 92 93 /* NUMBER, CURRENCY, ACCOUNTING, PERCENTAGE: */ 94 gboolean negative_red; 95 gboolean negative_paren; 96 97 /* CURRENCY, ACCOUNTING: */ 98 GOFormatCurrency const *currency; 99 100 /* CURRENCY: */ 101 gboolean force_quoted; 102 103 /* SCIENTIFIC: */ 104 int exponent_step; 105 int exponent_digits; 106 gboolean exponent_sign_forced; 107 gboolean use_markup; 108 gboolean simplify_mantissa; 109 gboolean append_SI; 110 gchar *appended_SI_unit; 111 int scale; 112 113 /* FRACTION: */ 114 gboolean automatic_denominator; 115 gboolean split_fraction; 116 gboolean pi_scale; 117 int numerator_min_digits; 118 int denominator_min_digits; 119 int denominator_max_digits; 120 int denominator; 121 122 /* <private> */ 123 int expansion[30]; /* what is this for? */ 124 unsigned int ref_count; 125 } GOFormatDetails; 126 127 GType go_format_details_get_type (void); 128 /*************************************************************************/ 129 130 gboolean go_format_allow_ee_markup (void); 131 gboolean go_format_allow_si (void); 132 gboolean go_format_allow_pi_slash (void); 133 134 /*************************************************************************/ 135 136 typedef int (*GOFormatMeasure) (const GString *str, PangoLayout *layout); 137 int go_format_measure_zero (const GString *str, PangoLayout *layout); 138 int go_format_measure_pango (const GString *str, PangoLayout *layout); 139 int go_format_measure_strlen (const GString *str, PangoLayout *layout); 140 141 void go_render_general (PangoLayout *layout, GString *str, 142 GOFormatMeasure measure, 143 const GOFontMetrics *metrics, 144 double val, 145 int col_width, 146 gboolean unicode_minus, 147 guint numeral_shape, 148 guint custom_shape_flags); 149 #ifdef GOFFICE_WITH_LONG_DOUBLE 150 void go_render_generall (PangoLayout *layout, GString *str, 151 GOFormatMeasure measure, 152 const GOFontMetrics *metrics, 153 long double val, 154 int col_width, 155 gboolean unicode_minus, 156 guint numeral_shape, 157 guint custom_shape_flags); 158 #endif 159 160 /*************************************************************************/ 161 162 GType go_format_get_type (void); 163 GOFormat *go_format_new_from_XL (char const *str); 164 GOFormat *go_format_new_markup (PangoAttrList *markup, gboolean add_ref); 165 166 /* these do not add a reference to the result */ 167 GOFormat *go_format_general (void); 168 GOFormat *go_format_empty (void); 169 GOFormat *go_format_default_date (void); 170 GOFormat *go_format_default_time (void); 171 GOFormat *go_format_default_date_time (void); 172 GOFormat *go_format_default_percentage (void); 173 GOFormat *go_format_default_money (void); 174 GOFormat *go_format_default_accounting (void); 175 176 void go_format_generate_number_str (GString *dst, 177 int min_digits, 178 int num_decimals, 179 gboolean thousands_sep, 180 gboolean negative_red, 181 gboolean negative_paren, 182 const char *prefix, 183 const char *postfix); 184 GOFormatDetails *go_format_details_new (GOFormatFamily family); 185 void go_format_details_finalize (GOFormatDetails *details); 186 void go_format_details_free (GOFormatDetails *details); 187 void go_format_details_init (GOFormatDetails *details, 188 GOFormatFamily family); 189 void go_format_generate_str (GString *dst, 190 GOFormatDetails const *details); 191 192 char *go_format_str_localize (char const *str); 193 char *go_format_str_delocalize (char const *str); 194 const char* go_format_as_XL (GOFormat const *fmt); 195 196 GOFormat *go_format_ref (GOFormat const *fmt); 197 void go_format_unref (GOFormat const *fmt); 198 199 gboolean go_format_is_invalid (GOFormat const *fmt); 200 gboolean go_format_is_general (GOFormat const *fmt); 201 gboolean go_format_is_markup (GOFormat const *fmt); 202 gboolean go_format_is_text (GOFormat const *fmt); 203 gboolean go_format_is_var_width (GOFormat const *fmt); 204 int go_format_is_date (GOFormat const *fmt); 205 int go_format_is_time (GOFormat const *fmt); 206 207 int go_format_month_before_day (GOFormat const *fmt); 208 gboolean go_format_has_year (GOFormat const *fmt); 209 gboolean go_format_has_month (GOFormat const *fmt); 210 gboolean go_format_has_day (GOFormat const *fmt); 211 212 gboolean go_format_has_hour (GOFormat const *fmt); 213 gboolean go_format_has_minute (GOFormat const *fmt); 214 215 GOFormatMagic go_format_get_magic (GOFormat const *fmt); 216 GOFormat *go_format_new_magic (GOFormatMagic m); 217 218 const GOFormat *go_format_specialize (GOFormat const *fmt, 219 double val, char type, 220 gboolean *inhibit_minus); 221 #ifdef GOFFICE_WITH_LONG_DOUBLE 222 const GOFormat *go_format_specializel (GOFormat const *fmt, 223 long double val, char type, 224 gboolean *inhibit_minus); 225 #endif 226 227 GOFormatFamily go_format_get_family (GOFormat const *fmt); 228 229 void go_format_get_details (GOFormat const *fmt, 230 GOFormatDetails *dst, 231 gboolean *exact); 232 233 const PangoAttrList *go_format_get_markup (GOFormat const *fmt); 234 235 gboolean go_format_is_simple (GOFormat const *fmt); 236 237 GOFormatNumberError 238 go_format_value_gstring (PangoLayout *layout, GString *str, 239 const GOFormatMeasure measure, 240 const GOFontMetrics *metrics, 241 GOFormat const *fmt, 242 double val, char type, const char *sval, 243 GOColor *go_color, 244 int col_width, 245 GODateConventions const *date_conv, 246 gboolean unicode_minus); 247 char *go_format_value (GOFormat const *fmt, double val); 248 #ifdef GOFFICE_WITH_LONG_DOUBLE 249 GOFormatNumberError 250 go_format_value_gstringl (PangoLayout *layout, GString *str, 251 const GOFormatMeasure measure, 252 const GOFontMetrics *metrics, 253 GOFormat const *fmt, 254 long double val, char type, const char *sval, 255 GOColor *go_color, 256 int col_width, 257 GODateConventions const *date_conv, 258 gboolean unicode_minus); 259 char *go_format_valuel (GOFormat const *fmt, long double val); 260 #endif 261 262 gboolean go_format_eq (GOFormat const *a, GOFormat const *b); 263 GOFormat *go_format_inc_precision (GOFormat const *fmt); 264 GOFormat *go_format_dec_precision (GOFormat const *fmt); 265 GOFormat *go_format_toggle_1000sep (GOFormat const *fmt); 266 267 268 269 /******************* GOFormat ODF Support ********************************/ 270 271 char *go_format_odf_style_map (GOFormat const *fmt, int cond_part); 272 gboolean go_format_output_to_odf (GsfXMLOut *xout, GOFormat const *fmt, 273 int cond_part, char const *name, 274 gboolean with_extension); 275 void go_format_foreach (GHFunc func, gpointer user_data); 276 277 /*************************************************************************/ 278 279 char const * const *_go_format_builtins(GOFormatFamily fam); 280 GOFormatCurrency const *_go_format_currencies (void); 281 282 GOFormatCurrency const *go_format_locale_currency (void); 283 284 /*************************************************************************/ 285 286 GOColor go_format_palette_color_of_index (int i); 287 int go_format_palette_index_from_color (GOColor c); 288 char *go_format_palette_name_of_index (int i); 289 290 /*************************************************************************/ 291 292 void _go_number_format_init (void); 293 void _go_number_format_shutdown (void); 294 void _go_currency_date_format_init (void); 295 void _go_currency_date_format_shutdown (void); 296 297 G_END_DECLS 298 299 #endif /* GO_FORMAT_H */ 300