diff options
author | Dodji Seketeli <dodji@src.gnome.org> | 2003-06-08 20:51:08 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2003-06-08 20:51:08 +0000 |
commit | aba3d6844be54f028b33c3f4aa66274a35fb1bdc (patch) | |
tree | c9608fda0fc6a8239c3dec10da961bf7e822f2f1 | |
parent | 269fa26e3274b94427877ac8fa1ca3d5a5120ed9 (diff) | |
download | libcroco-aba3d6844be54f028b33c3f4aa66274a35fb1bdc.tar.gz |
went forward in the font properties gathering.
* src/seleng/cr-style.[ch]: went forward in the font properties
gathering.
* src/parser/cr-tknzr.[ch]: fixed some 'const" related compilation
warnings.
* src/parser/cr-parser.[ch]: exported the declaration parsing api
so that cr_declaration_parse () can use it.
* src/parser/cr-declaration.[ch]:
added cr_declaration_parse () api. Not tested yet.
Dodji.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | src/parser/cr-declaration.c | 73 | ||||
-rw-r--r-- | src/parser/cr-declaration.h | 5 | ||||
-rw-r--r-- | src/parser/cr-num.h | 2 | ||||
-rw-r--r-- | src/parser/cr-parser.c | 6 | ||||
-rw-r--r-- | src/parser/cr-parser.h | 6 | ||||
-rw-r--r-- | src/parser/cr-tknzr.c | 16 | ||||
-rw-r--r-- | src/parser/cr-tknzr.h | 4 | ||||
-rw-r--r-- | src/seleng/cr-style.c | 164 | ||||
-rw-r--r-- | tests/test7-main.c | 1 |
10 files changed, 267 insertions, 22 deletions
@@ -1,5 +1,17 @@ 2003-06-09 Dodji <dodji@seketeli.org> + * src/seleng/cr-style.[ch]: went forward in the font properties + gathering. + + * src/parser/cr-tknzr.[ch]: fixed some 'const" related compilation + warnings. + + * src/parser/cr-parser.[ch]: exported the declaration parsing api + so that cr_declaration_parse () can use it. + + * src/parser/cr-declaration.[ch]: + added cr_declaration_parse () api. Not tested yet. + * tests/test7-main.c: updated the test to reflect all the changes that happened today. diff --git a/src/parser/cr-declaration.c b/src/parser/cr-declaration.c index 3f822d6..66f0d99 100644 --- a/src/parser/cr-declaration.c +++ b/src/parser/cr-declaration.c @@ -27,6 +27,7 @@ #include <string.h> #include "cr-declaration.h" #include "cr-statement.h" +#include "cr-parser.h" /** *@file @@ -141,6 +142,77 @@ cr_declaration_new (CRStatement *a_statement, return result ; } + +/** + *Parses a text buffer that contains + *a css declaration. + * + *@param a_statement the parent css2 statement of this + *this declaration. Must be non NULL and of type + *RULESET_STMT (must be a ruleset). + *@param a_str the string that contains the statement. + *@param a_enc the encoding of a_str. + *@return the parsed declaration, or NULL in case of error. + */ +CRDeclaration * +cr_declaration_parse (CRStatement *a_statement, + const guchar *a_str, + enum CREncoding a_enc) +{ + enum CRStatus status = CR_OK ; + CRTerm *value = NULL ; + GString *property = NULL; + CRDeclaration *result = NULL ; + CRParser * parser = NULL ; + + g_return_val_if_fail (a_statement + && a_statement->type == RULESET_STMT + && a_str, NULL); + + parser = cr_parser_new_from_buf (a_str, + strlen (a_str), + a_enc, FALSE) ; + g_return_val_if_fail (parser, NULL) ; + + status = cr_parser_try_to_skip_spaces_and_comments (parser) ; + if (status != CR_OK) + goto cleanup ; + + status = cr_parser_parse_declaration (parser, &property, + &value) ; + if (status != CR_OK || !property) + goto cleanup ; + + result = cr_declaration_new (a_statement, property, value) ; + if (result) + { + property = NULL ; + value = NULL ; + } + + cleanup: + + if (parser) + { + cr_parser_destroy (parser) ; + parser = NULL ; + } + + if (property) + { + g_string_free (property, TRUE) ; + property = NULL ; + } + + if (value) + { + cr_term_destroy (value) ; + value = NULL ; + } + + return result ; +} + /** *Appends a new declaration to the current declarations list. *@param a_this the current declaration list. @@ -248,6 +320,7 @@ cr_declaration_dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent, } } + /** *Increases the ref count of the current instance of #CRDeclaration. *@param a_this the current instance of #CRDeclaration. diff --git a/src/parser/cr-declaration.h b/src/parser/cr-declaration.h index ff512a0..748b313 100644 --- a/src/parser/cr-declaration.h +++ b/src/parser/cr-declaration.h @@ -73,6 +73,11 @@ cr_declaration_new (CRStatement *a_statement, GString *a_property, CRTerm *a_value) ; + +CRDeclaration * +cr_declaration_parse (CRStatement *a_statement, + const guchar *a_str, + enum CREncoding a_enc) ; CRDeclaration * cr_declaration_append (CRDeclaration *a_this, CRDeclaration *a_new) ; diff --git a/src/parser/cr-num.h b/src/parser/cr-num.h index 16452ff..a84cd30 100644 --- a/src/parser/cr-num.h +++ b/src/parser/cr-num.h @@ -50,7 +50,7 @@ G_BEGIN_DECLS enum CRNumType { NUM_AUTO = 0, - NUM_GENERIC, + NUM_GENERIC, NUM_LENGTH_EM, NUM_LENGTH_EX, NUM_LENGTH_PX, diff --git a/src/parser/cr-parser.c b/src/parser/cr-parser.c index f321652..8d96c56 100644 --- a/src/parser/cr-parser.c +++ b/src/parser/cr-parser.c @@ -340,8 +340,6 @@ status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, \ a_token_ptr) ; \ ENSURE_PARSING_COND (status == CR_OK) ; -static enum CRStatus -cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) ; #ifdef WITH_UNICODE_ESCAPE_AND_RANGE static enum CRStatus @@ -694,7 +692,7 @@ cr_parser_clear_errors (CRParser *a_this) *@param a_this the current instance of #CRParser. *@return CR_OK upon successfull completion, an error code otherwise. */ -static enum CRStatus +enum CRStatus cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) { enum CRStatus status = CR_ERROR ; @@ -1874,7 +1872,7 @@ cr_parser_parse_any_core (CRParser *a_this) *The caller *must* free the returned pointer. *@return CR_OK upon successfull completion, an error code otherwise. */ -static enum CRStatus +enum CRStatus cr_parser_parse_declaration (CRParser *a_this, GString **a_property, CRTerm **a_expr) { diff --git a/src/parser/cr-parser.h b/src/parser/cr-parser.h index 49a0d97..dc5d881 100644 --- a/src/parser/cr-parser.h +++ b/src/parser/cr-parser.h @@ -75,6 +75,12 @@ cr_parser_set_tknzr (CRParser *a_this, CRTknzr *a_tknzr) ; enum CRStatus +cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) ; + +enum CRStatus +cr_parser_parse_declaration (CRParser *a_this, GString **a_property, + CRTerm **a_expr) ; +enum CRStatus cr_parser_set_sac_handler (CRParser *a_this, CRDocHandler *a_handler) ; diff --git a/src/parser/cr-tknzr.c b/src/parser/cr-tknzr.c index a56e94a..be6c972 100644 --- a/src/parser/cr-tknzr.c +++ b/src/parser/cr-tknzr.c @@ -1737,7 +1737,7 @@ cr_tknzr_new (CRInput *a_input) CRTknzr * -cr_tknzr_new_from_buf (guchar *a_buf, gulong a_len, +cr_tknzr_new_from_buf (const guchar *a_buf, gulong a_len, enum CREncoding a_enc, gboolean a_free_at_destroy) { @@ -1755,7 +1755,7 @@ cr_tknzr_new_from_buf (guchar *a_buf, gulong a_len, } CRTknzr * -cr_tknzr_new_from_uri (guchar *a_file_uri, +cr_tknzr_new_from_uri (const guchar *a_file_uri, enum CREncoding a_enc) { CRTknzr * result = NULL ; @@ -2412,16 +2412,8 @@ cr_tknzr_get_next_token (CRTknzr *a_this, CRToken **a_tk) goto done ; } break ; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': + + case '0' ... '9': case '.': { CRNum *num = NULL ; diff --git a/src/parser/cr-tknzr.h b/src/parser/cr-tknzr.h index 4dd66e3..b3c26bb 100644 --- a/src/parser/cr-tknzr.h +++ b/src/parser/cr-tknzr.h @@ -51,11 +51,11 @@ CRTknzr * cr_tknzr_new (CRInput *a_input) ; CRTknzr * -cr_tknzr_new_from_uri (guchar *a_file_uri, +cr_tknzr_new_from_uri (const guchar *a_file_uri, enum CREncoding a_enc) ; CRTknzr * -cr_tknzr_new_from_buf (guchar *a_buf, gulong a_len, +cr_tknzr_new_from_buf (const guchar *a_buf, gulong a_len, enum CREncoding a_enc, gboolean a_free_at_destroy) ; diff --git a/src/seleng/cr-style.c b/src/seleng/cr-style.c index 5901834..b021b51 100644 --- a/src/seleng/cr-style.c +++ b/src/seleng/cr-style.c @@ -84,7 +84,8 @@ enum CRPropertyID PROP_ID_BACKGROUND_COLOR, PROP_ID_FONT_FAMILY, PROP_ID_FONT_SIZE, - + PROP_ID_FONT_STYLE, + PROP_ID_FONT_WEIGHT, /*should be the last one.*/ NB_PROP_IDS } ; @@ -136,7 +137,8 @@ static CRPropertyDesc gv_prop_table [] = {"background-color", PROP_ID_BACKGROUND_COLOR}, {"font-family", PROP_ID_FONT_FAMILY}, {"font-size", PROP_ID_FONT_SIZE}, - + {"font-style", PROP_ID_FONT_STYLE}, + {"font-weight", PROP_ID_FONT_WEIGHT}, /*must be the last one*/ {NULL, 0} } ; @@ -244,6 +246,12 @@ set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) ; static enum CRStatus +set_prop_font_style_from_value (CRStyle *a_style, CRTerm *a_value) ; + +static enum CRStatus +set_prop_font_weight_from_value (CRStyle *a_style, CRTerm *a_value) ; + +static enum CRStatus cr_style_init_properties (void) { @@ -1664,6 +1672,148 @@ set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) return CR_OK ; } +static enum CRStatus +set_prop_font_style_from_value (CRStyle *a_style, CRTerm *a_value) +{ + enum CRStatus status = CR_OK ; + + g_return_val_if_fail (a_style && a_value, + CR_BAD_PARAM_ERROR) ; + + switch (a_value->type) + { + case TERM_IDENT: + if (a_value->content.str && a_value->content.str->str) + { + if (!strcmp (a_value->content.str->str, "normal")) + { + a_style->font_style = FONT_STYLE_NORMAL ; + } + else if (!strcmp (a_value->content.str->str, "italic")) + { + a_style->font_style = FONT_STYLE_ITALIC ; + } + else if (!strcmp (a_value->content.str->str, "oblique")) + { + a_style->font_style = FONT_STYLE_OBLIQUE ; + } + else if (!strcmp (a_value->content.str->str, "inherit")) + { + if (!a_style->font_style) + a_style->font_style = FONT_STYLE_NORMAL; + else + a_style->font_style = + a_style->parent_style-> + font_style ; + } + else + { + status = CR_UNKNOWN_PROP_VAL_ERROR ; + } + } + break ; + + default: + status = CR_UNKNOWN_PROP_VAL_ERROR ; + break ; + } + + return status ; +} + +static enum CRStatus +set_prop_font_weight_from_value (CRStyle *a_style, CRTerm *a_value) +{ + enum CRStatus status = CR_OK ; + + g_return_val_if_fail (a_style && a_value, + CR_BAD_PARAM_ERROR) ; + + switch (a_value->type) + { + case TERM_IDENT: + if (a_value->content.str && a_value->content.str->str) + { + if (!strcmp (a_value->content.str->str, + "normal")) + { + a_style->font_weight = FONT_WEIGHT_BOLD ; + } + else if (!strcmp (a_value->content.str->str, + "bold")) + { + a_style->font_weight = FONT_WEIGHT_BOLD ; + } + else if (!strcmp (a_value->content.str->str, + "bolder")) + { + a_style->font_weight = FONT_WEIGHT_BOLDER ; + } + else if (!strcmp (a_value->content.str->str, + "lighter")) + { + a_style->font_weight = FONT_WEIGHT_LIGHTER ; + } + else + { + status = CR_UNKNOWN_PROP_VAL_ERROR ; + } + + } + break ; + + case TERM_NUMBER: + if (a_value->content.num + && (a_value->content.num->type == NUM_GENERIC + ||a_value->content.num->type == NUM_AUTO)) + { + if (a_value->content.num->val <= 150) + { + a_style->font_weight = FONT_WEIGHT_100 ; + } + else if (a_value->content.num->val <= 250) + { + a_style->font_weight = FONT_WEIGHT_200 ; + } + else if (a_value->content.num->val <= 350) + { + a_style->font_weight = FONT_WEIGHT_300 ; + } + else if (a_value->content.num->val <= 450) + { + a_style->font_weight = FONT_WEIGHT_400 ; + } + else if (a_value->content.num->val <= 550) + { + a_style->font_weight = FONT_WEIGHT_500 ; + } + else if (a_value->content.num->val <= 650) + { + a_style->font_weight = FONT_WEIGHT_600 ; + } + else if (a_value->content.num->val <= 750) + { + a_style->font_weight = FONT_WEIGHT_700 ; + } + else if (a_value->content.num->val <= 850) + { + a_style->font_weight = FONT_WEIGHT_800 ; + } + else + { + a_style->font_weight = FONT_WEIGHT_900 ; + } + } + break ; + + default: + status = CR_UNKNOWN_PROP_VAL_ERROR ; + break ; + } + + return status ; +} + /****************** *Public methods ******************/ @@ -1929,6 +2079,16 @@ cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl) set_prop_font_size_from_value (a_this, value) ; break ; + case PROP_ID_FONT_STYLE: + status = + set_prop_font_style_from_value (a_this, value) ; + break ; + + case PROP_ID_FONT_WEIGHT: + status = + set_prop_font_weight_from_value (a_this, value) ; + break ; + default: return CR_UNKNOWN_TYPE_ERROR ; diff --git a/tests/test7-main.c b/tests/test7-main.c index 5bc4d84..ab94ab6 100644 --- a/tests/test7-main.c +++ b/tests/test7-main.c @@ -148,7 +148,6 @@ delete_event_cb (GtkWidget *a_widget, GdkEvent *a_event, static enum CRStatus test_layout_box (void) { - enum CRStatus status = CR_OK ; CRBoxView *box_view = NULL ; GtkWidget *window = NULL, *scroll = NULL ; |