diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2017-08-07 09:02:54 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2017-08-07 09:02:54 +0000 |
| commit | 47a1d5ea05d7a526371f18fec5491a7e4b38aca6 (patch) | |
| tree | 7856b2ba264e7878ef926a932eb7e21b968b799f /src | |
| parent | fix set_set_ (diff) | |
| download | inkscape-47a1d5ea05d7a526371f18fec5491a7e4b38aca6.tar.gz inkscape-47a1d5ea05d7a526371f18fec5491a7e4b38aca6.zip | |
Add support for more than one style sheet in a document and imported style sheets.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcroco/cr-sel-eng.c | 124 | ||||
| -rw-r--r-- | src/libcroco/cr-stylesheet.c | 91 | ||||
| -rw-r--r-- | src/libcroco/cr-stylesheet.h | 16 |
3 files changed, 183 insertions, 48 deletions
diff --git a/src/libcroco/cr-sel-eng.c b/src/libcroco/cr-sel-eng.c index 6f496df2f..665ba4daf 100644 --- a/src/libcroco/cr-sel-eng.c +++ b/src/libcroco/cr-sel-eng.c @@ -1395,6 +1395,83 @@ cr_sel_eng_get_matched_rulesets (CRSelEng * a_this, return status; } +enum CRStatus +cr_sel_eng_process_stylesheet ( CRSelEng * a_eng, + CRXMLNodePtr a_node, + CRStyleSheet * a_stylesheet, + CRStatement *** stmts_tab, + gulong * tab_size, + gulong * tab_len, + gulong * index) +{ + enum CRStatus status = CR_OK; + CRStyleSheet *cur = NULL; + gushort stmts_chunck_size = 8; + + // Process imported stylesheets first + for (cur = a_stylesheet->import ; cur ; cur = cur->next) { + cr_sel_eng_process_stylesheet( a_eng, a_node, cur, stmts_tab, tab_size, tab_len, index ); + } + + // Process this stylesheet + if (*tab_size - *index < 1) { + *stmts_tab = (CRStatement **) g_try_realloc + (*stmts_tab, (*tab_size + stmts_chunck_size) + * sizeof (CRStatement *)); + if (!*stmts_tab) { + cr_utils_trace_info ("Out of memory"); + status = CR_ERROR; + goto cleanup; + } + *tab_size += stmts_chunck_size; + /* + *compute the max size left for + *cr_sel_eng_get_matched_rulesets_real()'s output tab + */ + *tab_len = *tab_size - *index; + } + while ((status = cr_sel_eng_get_matched_rulesets_real + (a_eng, a_stylesheet, a_node, *stmts_tab + *index, tab_len)) + == CR_OUTPUT_TOO_SHORT_ERROR) { + *stmts_tab = (CRStatement **) g_try_realloc + (*stmts_tab, (*tab_size + stmts_chunck_size) + * sizeof (CRStatement *)); + if (!*stmts_tab) { + cr_utils_trace_info ("Out of memory"); + status = CR_ERROR; + goto cleanup; + } + *tab_size += stmts_chunck_size; + *index += *tab_len; + /* + *compute the max size left for + *cr_sel_eng_get_matched_rulesets_real()'s output tab + */ + *tab_len = *tab_size - *index; + } + if (status != CR_OK) { + cr_utils_trace_info ("Error while running " + "selector engine"); + goto cleanup; + } + *index += *tab_len; + *tab_len = *tab_size - *index; + + // Process other document stylesheets last + for (cur = a_stylesheet->next ; cur ; cur = cur->next) { + cr_sel_eng_process_stylesheet( a_eng, a_node, cur, stmts_tab, tab_size, tab_len, index ); + } + + return status; + + cleanup: + if (*stmts_tab) { + g_free (*stmts_tab); + *stmts_tab = NULL; + } + + return status; +} enum CRStatus cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, @@ -1420,48 +1497,13 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, sheet = cr_cascade_get_sheet (a_cascade, origin); if (!sheet) continue; - if (tab_size - index < 1) { - stmts_tab = (CRStatement **) g_try_realloc - (stmts_tab, (tab_size + stmts_chunck_size) - * sizeof (CRStatement *)); - if (!stmts_tab) { - cr_utils_trace_info ("Out of memory"); - status = CR_ERROR; - goto cleanup; - } - tab_size += stmts_chunck_size; - /* - *compute the max size left for - *cr_sel_eng_get_matched_rulesets_real()'s output tab - */ - tab_len = tab_size - index; - } - while ((status = cr_sel_eng_get_matched_rulesets_real - (a_this, sheet, a_node, stmts_tab + index, &tab_len)) - == CR_OUTPUT_TOO_SHORT_ERROR) { - stmts_tab = (CRStatement **) g_try_realloc - (stmts_tab, (tab_size + stmts_chunck_size) - * sizeof (CRStatement *)); - if (!stmts_tab) { - cr_utils_trace_info ("Out of memory"); - status = CR_ERROR; - goto cleanup; - } - tab_size += stmts_chunck_size; - index += tab_len; - /* - *compute the max size left for - *cr_sel_eng_get_matched_rulesets_real()'s output tab - */ - tab_len = tab_size - index; - } + + status = cr_sel_eng_process_stylesheet (a_this, a_node, sheet, &stmts_tab, &tab_size, &tab_len, &index); if (status != CR_OK) { cr_utils_trace_info ("Error while running " "selector engine"); - goto cleanup; + return status; } - index += tab_len; - tab_len = tab_size - index; } /* @@ -1472,7 +1514,6 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, */ for (i = 0; i < index; i++) { CRStatement *stmt = stmts_tab[i]; - if (!stmt) continue; switch (stmt->type) { @@ -1488,11 +1529,6 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, } status = CR_OK ; - cleanup: - if (stmts_tab) { - g_free (stmts_tab); - stmts_tab = NULL; - } return status; } diff --git a/src/libcroco/cr-stylesheet.c b/src/libcroco/cr-stylesheet.c index cb5de6958..a2cfc20c9 100644 --- a/src/libcroco/cr-stylesheet.c +++ b/src/libcroco/cr-stylesheet.c @@ -62,13 +62,23 @@ cr_stylesheet_to_string (CRStyleSheet const *a_this) gchar *str = NULL; GString *stringue = NULL; CRStatement const *cur_stmt = NULL; + CRStyleSheet *cur = NULL; g_return_val_if_fail (a_this, NULL); - if (a_this->statements) { - stringue = g_string_new (NULL) ; - g_return_val_if_fail (stringue, NULL) ; - } + stringue = g_string_new (NULL) ; + g_return_val_if_fail (stringue, NULL) ; + + if (a_this->import) { + str = cr_stylesheet_to_string (a_this->import); + if (str) { + g_string_append (stringue, str) ; + g_free (str) ; + g_string_append (stringue, "\n") ; + str = NULL ; + } + } + for (cur_stmt = a_this->statements; cur_stmt; cur_stmt = cur_stmt->next) { if (cur_stmt->prev) { @@ -81,6 +91,17 @@ cr_stylesheet_to_string (CRStyleSheet const *a_this) str = NULL ; } } + + if (a_this->next) { + str = cr_stylesheet_to_string (a_this->next); + if (str) { + g_string_append (stringue, "\n") ; + g_string_append (stringue, str) ; + g_free (str) ; + str = NULL ; + } + } + if (stringue) { str = stringue->str ; g_string_free (stringue, FALSE) ; @@ -137,6 +158,59 @@ cr_stylesheet_statement_get_from_list (CRStyleSheet * a_this, int itemnr) return cr_statement_get_from_list (a_this->statements, itemnr); } +/** + *Appends a new stylesheet to the current list of #CRStylesheet. + * + *@param a_this the "this pointer" of the current instance + *of #CRStylesheet . + *@param a_new_stylesheet the stylesheet to append. + *@return the list of stylesheets with the a_new_stylesheet appended to it. + */ +CRStyleSheet * +cr_stylesheet_append_stylesheet (CRStyleSheet * a_this, CRStyleSheet * a_new_stylesheet) +{ + CRStyleSheet *cur = NULL; + + g_return_val_if_fail (a_new_stylesheet, NULL); + + if (a_this == NULL) + return a_new_stylesheet; + + for (cur = a_this; cur->next; cur = cur->next) ; + + cur->next = a_new_stylesheet; + + return a_this; +} + + +/** + *Appends a new import stylesheet to the current list of imports. + * + *@param a_this the "this pointer" of the current instance + *of #CRStylesheet . + *@param a_new_stylesheet the import stylesheet to append. + *@return the list of stylesheets with the a_new_import appended to it. + */ +CRStyleSheet * +cr_stylesheet_append_import (CRStyleSheet * a_this, CRStyleSheet * a_new_import) +{ + CRStyleSheet *cur = NULL; + + g_return_val_if_fail (a_new_import, NULL); + + if (a_this->import == NULL) + a_this->import = a_new_import; + return a_this; + + for (cur = a_this->import; cur->next; cur = cur->next) ; + + cur->next = a_new_import; + + return a_this; +} + + void cr_stylesheet_ref (CRStyleSheet * a_this) { @@ -174,5 +248,14 @@ cr_stylesheet_destroy (CRStyleSheet * a_this) cr_statement_destroy (a_this->statements); a_this->statements = NULL; } + + if (a_this->import) { + cr_stylesheet_destroy (a_this->import); + } + + if (a_this->next) { + cr_stylesheet_destroy (a_this->next); + } + g_free (a_this); } diff --git a/src/libcroco/cr-stylesheet.h b/src/libcroco/cr-stylesheet.h index f35c94e37..7ebaf7a60 100644 --- a/src/libcroco/cr-stylesheet.h +++ b/src/libcroco/cr-stylesheet.h @@ -80,17 +80,33 @@ struct _CRStyleSheet *and cr_stylesheet_unref() instead. */ gulong ref_count ; + + /** + * A link to an imported stylesheet + * (can have more than one). + */ + CRStyleSheet *import; + + /** + * A link to the next stylesheet. + */ + CRStyleSheet *next; } ; CRStyleSheet * cr_stylesheet_new (CRStatement *a_stmts) ; gchar * cr_stylesheet_to_string (CRStyleSheet const *a_this) ; + void cr_stylesheet_dump (CRStyleSheet const *a_this, FILE *a_fp) ; gint cr_stylesheet_nr_rules (CRStyleSheet const *a_this) ; CRStatement * cr_stylesheet_statement_get_from_list (CRStyleSheet *a_this, int itemnr) ; +CRStyleSheet * cr_stylesheet_append_import (CRStyleSheet *a_this, CRStyleSheet *a_new_import) ; + +CRStyleSheet * cr_stylesheet_append_stylesheet (CRStyleSheet *a_this, CRStyleSheet *a_new_stylesheet) ; + void cr_stylesheet_ref (CRStyleSheet *a_this) ; gboolean cr_stylesheet_unref (CRStyleSheet *a_this) ; |
