diff options
| author | Martin Owens <doctormo@gmail.com> | 2018-11-12 17:31:34 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2018-11-12 17:31:34 +0000 |
| commit | 9bef0dae62d338e20fe74e459f7343847691bf82 (patch) | |
| tree | 53c65717c1d21443056dfc4b7d1555f92972ae11 /src/object | |
| parent | Merge branch 'master' of gitlab.com:inkscape/inkscape (diff) | |
| download | inkscape-9bef0dae62d338e20fe74e459f7343847691bf82.tar.gz inkscape-9bef0dae62d338e20fe74e459f7343847691bf82.zip | |
Support multiple style sheets or style elements in an svg document
Diffstat (limited to 'src/object')
| -rw-r--r-- | src/object/sp-style-elem.cpp | 37 | ||||
| -rw-r--r-- | src/object/sp-style-elem.h | 3 |
2 files changed, 20 insertions, 20 deletions
diff --git a/src/object/sp-style-elem.cpp b/src/object/sp-style-elem.cpp index 745f421b0..14e4a8d90 100644 --- a/src/object/sp-style-elem.cpp +++ b/src/object/sp-style-elem.cpp @@ -29,6 +29,7 @@ using Inkscape::XML::TEXT_NODE; SPStyleElem::SPStyleElem() : SPObject() { media_set_all(this->media); this->is_css = false; + this->style_sheet = nullptr; } SPStyleElem::~SPStyleElem() = default; @@ -451,14 +452,11 @@ void update_style_recursively( SPObject *object ) { void SPStyleElem::read_content() { - // This won't work when we support multiple style sheets in a file. - // We'll need to identify which style sheet this element corresponds to - // and replace just that part of the total style sheet. (The first - // style element would correspond to document->style_sheet, while - // laters ones are chained on using style_sheet->next). - - document->style_sheet = cr_stylesheet_new (nullptr); - CRParser *parser = parser_init(document->style_sheet, document); + // First, create the style-sheet object and track it in this + // element so that it can be edited. It'll be combined with + // the document's style sheet later. + style_sheet = cr_stylesheet_new (nullptr); + CRParser *parser = parser_init(style_sheet, document); CRDocHandler *sac_handler = nullptr; cr_parser_get_sac_handler (parser, &sac_handler); @@ -469,22 +467,21 @@ void SPStyleElem::read_content() { CRStatus const parse_status = cr_parser_parse_buf (parser, reinterpret_cast<const guchar *>(text.c_str()), text.bytes(), CR_UTF_8); - // std::cout << "SPStyeElem::read_content: result:" << std::endl; - // const gchar* string = cr_stylesheet_to_string (document->style_sheet); - // std::cout << (string?string:"Null") << std::endl; - if (parse_status == CR_OK) { - // Also destroys old style sheet: - cr_cascade_set_sheet (document->style_cascade, document->style_sheet, ORIGIN_AUTHOR); + if(!document->style_sheet) { + // if the style is the first style sheet that we've seen, set the document's + // first style sheet to this style and create a cascade object with it. + document->style_sheet = style_sheet; + cr_cascade_set_sheet (document->style_cascade, document->style_sheet, ORIGIN_AUTHOR); + } else { + // If not the first, then chain up this style_sheet + cr_stylesheet_append_import (document->style_sheet, style_sheet); + } } else { - cr_stylesheet_destroy (document->style_sheet); - document->style_sheet = nullptr; + cr_stylesheet_destroy (style_sheet); + style_sheet = nullptr; if (parse_status != CR_PARSING_ERROR) { g_printerr("parsing error code=%u\n", unsigned(parse_status)); - /* Better than nothing. TODO: Improve libcroco's error handling. At a minimum, add a - strerror-like function so that we can give a string rather than an integer. */ - /* TODO: Improve error diagnosis stuff in inkscape. We'd like a panel showing the - errors/warnings/unsupported features of the current document. */ } } diff --git a/src/object/sp-style-elem.h b/src/object/sp-style-elem.h index e46ff51c2..b2c38f20b 100644 --- a/src/object/sp-style-elem.h +++ b/src/object/sp-style-elem.h @@ -18,6 +18,9 @@ public: SPStyleElem(); ~SPStyleElem() override; + // Container for the libcroco style sheet instance created on load. + CRStyleSheet *style_sheet; + Media media; bool is_css; |
