diff options
author | Dom Lachowicz <cinamod@hotmail.com> | 2006-04-29 13:07:54 +0000 |
---|---|---|
committer | Dom Lachowicz <doml@src.gnome.org> | 2006-04-29 13:07:54 +0000 |
commit | 1f46ad42193a2dd17bccaf69f2f50df2279dc2f5 (patch) | |
tree | 845b871ce26bd841d2d592d25c04a7bfb626bbd1 /src | |
parent | 9712f747ed9607acf51badb29aa2009729e3b13b (diff) | |
download | libcroco-1f46ad42193a2dd17bccaf69f2f50df2279dc2f5.tar.gz |
Revert my previous change and instead use Inkscape's patch in bug #306823,
2006-04-29 Dom Lachowicz <cinamod@hotmail.com>
* src/cr-tknzr.c: Revert my previous change and instead use Inkscape's
patch in bug #306823, as it improves precision
* src/cr-utils.[ch]: Ditto
Diffstat (limited to 'src')
-rw-r--r-- | src/cr-tknzr.c | 41 | ||||
-rw-r--r-- | src/cr-utils.c | 13 | ||||
-rw-r--r-- | src/cr-utils.h | 3 |
3 files changed, 19 insertions, 38 deletions
diff --git a/src/cr-tknzr.c b/src/cr-tknzr.c index 34f0b4c..e3e254e 100644 --- a/src/cr-tknzr.c +++ b/src/cr-tknzr.c @@ -1484,13 +1484,12 @@ cr_tknzr_parse_num (CRTknzr * a_this, { enum CRStatus status = CR_PARSING_ERROR; enum CRNumType val_type = NUM_GENERIC; - gboolean parsing_dec = FALSE, - parsed = FALSE; + gboolean parsing_dec, /* true iff seen decimal point. */ + parsed; /* true iff the substring seen so far is a valid CSS + number, i.e. `[0-9]+|[0-9]*\.[0-9]+'. */ guint32 cur_char = 0, - int_part = 0, - dec_part = 0, - next_char = 0, - decimal_places = 0; + next_char = 0; + gdouble numerator, denominator = 1; CRInputPos init_pos; CRParsingLocation location = {0} ; @@ -1500,12 +1499,14 @@ cr_tknzr_parse_num (CRTknzr * a_this, RECORD_INITIAL_POS (a_this, &init_pos); READ_NEXT_CHAR (a_this, &cur_char); - if (IS_NUM (cur_char) == TRUE) { - int_part = int_part * 10 + (cur_char - '0'); - + if (IS_NUM (cur_char)) { + numerator = (cur_char - '0'); + parsing_dec = FALSE; parsed = TRUE; } else if (cur_char == '.') { + numerator = 0; parsing_dec = TRUE; + parsed = FALSE; } else { status = CR_PARSING_ERROR; goto error; @@ -1520,30 +1521,29 @@ cr_tknzr_parse_num (CRTknzr * a_this, break; } if (next_char == '.') { - if (parsing_dec == TRUE) { + if (parsing_dec) { status = CR_PARSING_ERROR; goto error; } READ_NEXT_CHAR (a_this, &cur_char); parsing_dec = TRUE; - parsed = TRUE; - } else if (IS_NUM (next_char) == TRUE) { + parsed = FALSE; /* In CSS, there must be at least + one digit after `.'. */ + } else if (IS_NUM (next_char)) { READ_NEXT_CHAR (a_this, &cur_char); parsed = TRUE; - if (parsing_dec == FALSE) { - int_part = int_part * 10 + (cur_char - '0'); - } else { - decimal_places++; - dec_part = dec_part * 10 + (cur_char - '0'); + numerator = numerator * 10 + (cur_char - '0'); + if (parsing_dec) { + denominator *= 10; } } else { break; } } - if (parsed == FALSE) { + if (!parsed) { status = CR_PARSING_ERROR; } @@ -1551,10 +1551,7 @@ cr_tknzr_parse_num (CRTknzr * a_this, *Now, set the output param values. */ if (status == CR_OK) { - gdouble val = 0.0; - - val = int_part; - val += cr_utils_n_to_0_dot_n (dec_part, decimal_places); + gdouble val = numerator / denominator; if (*a_num == NULL) { *a_num = cr_num_new_with_val (val, val_type); diff --git a/src/cr-utils.c b/src/cr-utils.c index 8690b85..36d1d9c 100644 --- a/src/cr-utils.c +++ b/src/cr-utils.c @@ -1292,19 +1292,6 @@ cr_utils_dump_n_chars2 (guchar a_char, GString * a_string, glong a_nb) } } -gdouble -cr_utils_n_to_0_dot_n (glong a_n, glong decimal_places) -{ - gdouble result = a_n; - - while (decimal_places > 0) { - result = result / 10; - decimal_places--; - } - - return result; -} - /** *Duplicates a list of GString instances. *@return the duplicated list of GString instances or NULL if diff --git a/src/cr-utils.h b/src/cr-utils.h index 6f03946..5230780 100644 --- a/src/cr-utils.h +++ b/src/cr-utils.h @@ -235,9 +235,6 @@ void cr_utils_dump_n_chars2 (guchar a_char, GString *a_string, glong a_nb) ; -gdouble -cr_utils_n_to_0_dot_n (glong a_n, glong decimal_places) ; - GList * cr_utils_dup_glist_of_string (GList *a_list) ; |