/*
5 * Authors: see git history
7 * Copyright (C) 2018 Authors
8 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
32 styleelem->document->getRoot()->emitModified(SP_OBJECT_MODIFIED_CASCADE);
40 child.addObserver(styleelem->textNodeObserver());
50 child.removeObserver(styleelem->textNodeObserver());
79 is_css = ( g_ascii_strncasecmp(value,
"text/css", 8) == 0
80 && ( value[8] ==
'\0' ||
88 parse_media(style_elem, value);
102 if ((flags & SP_OBJECT_WRITE_BUILD) && !
repr) {
106 if (flags & SP_OBJECT_WRITE_BUILD) {
107 g_warning(
"nyi: Forming <style> content for SP_OBJECT_WRITE_BUILD.");
148 static constexpr unsigned ParseTmp_magic = 0x23474397;
149 unsigned const magic = ParseTmp_magic;
161 ParseTmp(ParseTmp
const &) =
delete;
170 assert(a_handler && a_handler->app_data);
171 auto self =
static_cast<ParseTmp *
>(a_handler->app_data);
172 assert(self->magic == ParseTmp_magic);
187 g_return_if_fail(a_handler && a_uri);
188 auto &parse_tmp = *ParseTmp::cast(a_handler);
192 std::cerr <<
"import_style_cb: No document!" << std::endl;
196 std::cerr <<
"import_style_cb: Document filename is NULL" << std::endl;
206 ParseTmp parse_new(stylesheet, document);
209 if (parse_status ==
CR_OK) {
210 g_assert(parse_tmp.stylesheet);
211 g_assert(parse_tmp.stylesheet != stylesheet);
216 parse_tmp.stylesheet->statements =
cr_statement_append(parse_tmp.stylesheet->statements, ruleset);
218 std::cerr <<
"import_style_cb: Could not parse: " << import_file << std::endl;
227 g_return_if_fail(a_handler && a_sel_list);
228 auto &parse_tmp = *ParseTmp::cast(a_handler);
230 if ( (parse_tmp.currStmt !=
nullptr)
231 || (parse_tmp.stmtType !=
NO_STMT) ) {
232 g_warning(
"Expecting currStmt==NULL and stmtType==0 (NO_STMT) at start of ruleset, but found currStmt=%p, stmtType=%u",
233 static_cast<void *
>(parse_tmp.currStmt),
unsigned(parse_tmp.stmtType));
239 parse_tmp.currStmt = ruleset;
246 g_return_if_fail(a_handler && a_sel_list);
247 auto &parse_tmp = *ParseTmp::cast(a_handler);
258 g_warning(
"Found stmtType=%u, stmt=%p, stmt.type=%u, ruleset.sel_list=%p, a_sel_list=%p.",
259 unsigned(parse_tmp.stmtType),
261 unsigned(ruleset->
type),
265 parse_tmp.currStmt =
nullptr;
273 auto &parse_tmp = *ParseTmp::cast(a_handler);
275 if (parse_tmp.stmtType !=
NO_STMT || parse_tmp.currStmt !=
nullptr) {
276 g_warning(
"Expecting currStmt==NULL and stmtType==0 (NO_STMT) at start of @font-face, but found currStmt=%p, stmtType=%u",
277 static_cast<void *
>(parse_tmp.currStmt),
unsigned(parse_tmp.stmtType));
283 parse_tmp.currStmt = font_face_rule;
289 auto &parse_tmp = *ParseTmp::cast(a_handler);
291 CRStatement *
const font_face_rule = parse_tmp.currStmt;
299 g_warning(
"Found stmtType=%u, stmt=%p, stmt.type=%u.",
300 unsigned(parse_tmp.stmtType),
302 unsigned(font_face_rule->
type));
305 g_warning(
"end_font_face_cb: font face rule limited support.");
307 std::cerr << std::endl;
312 std::cerr <<
"end_font_face_cb: No document!" << std::endl;
316 std::cerr <<
"end_font_face_cb: Document filename is NULL" << std::endl;
324 cur->property->stryng &&
325 cur->property->stryng->str &&
326 strcmp(cur->property->stryng->str,
"src") == 0 ) {
335 if (value.rfind(
"ttf") == (value.length() - 3) ||
336 value.rfind(
"otf") == (value.length() - 3)) {
339 Glib::ustring ttf_file =
342 if (!ttf_file.empty()) {
344 g_info(
"end_font_face_cb: Added font: %s", ttf_file.c_str());
348 g_warning(
"end_font_face_cb: Failed to add: %s", value.c_str());
355 parse_tmp.currStmt =
nullptr;
363 CRTerm *
const a_value, gboolean
const a_important)
366 g_return_if_fail(a_handler && a_name);
367 auto &parse_tmp = *ParseTmp::cast(a_handler);
370 g_return_if_fail(ruleset);
373 g_return_if_fail(decl);
376 switch (parse_tmp.stmtType) {
381 g_return_if_fail (append_status ==
CR_OK);
387 g_return_if_fail (new_decls);
392 g_warning (
"property_cb: Unhandled stmtType: %u", parse_tmp.stmtType);
399 , stylesheet(stylesheet)
403 sac_handler->app_data =
this;
420 std::vector<std::unique_ptr<SPStyle>> styles;
424 for (
int x = 0; x < count; ++x) {
427 styles.back()->mergeStatement(statement);
453 }
else if (!topsheet) {
476 if (!(text.find_first_not_of(
" \t\r\n") != std::string::npos)) {
482 if (parse_status ==
CR_OK) {
499 g_printerr(
"parsing error code=%u\n",
unsigned(parse_status));
505 SP_OBJECT_MODIFIED_FLAG);
Lookup dictionary for attributes/properties.
constexpr auto cast
Equivalent to dynamic_cast<T [const] *>(...) where the const is deduced.
void AddFontFile(char const *utf8file)
Add a an additional font.
static FontFactory & get(Args &&... args)
Interface for refcounted XML nodes.
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
virtual Node * firstChild()=0
Get the first child of this node.
virtual char const * content() const =0
Get the content of a text or comment node.
virtual void addObserver(NodeObserver &observer)=0
Add an object that will be notified of the changes to this node.
virtual void removeObserver(NodeObserver &observer)=0
Remove an object from the list of observers.
Typed SVG document implementation.
SPRoot * getRoot()
Returns our SPRoot.
char const * getDocumentFilename() const
CRCascade * getStyleCascade()
Inkscape::XML::Node * repr
virtual void set(SPAttr key, const char *value)
virtual Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags)
void readAttr(char const *key)
Read value of key attribute from XML node into object.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
virtual void build(SPDocument *doc, Inkscape::XML::Node *repr)
void requestDisplayUpdate(unsigned int flags)
Queues an deferred update of this object's display.
void notifyChildRemoved(Inkscape::XML::Node &, Inkscape::XML::Node &, Inkscape::XML::Node *) final
Child removal callback.
void notifyChildAdded(Inkscape::XML::Node &, Inkscape::XML::Node &, Inkscape::XML::Node *) final
Child addition callback.
void notifyChildOrderChanged(Inkscape::XML::Node &, Inkscape::XML::Node &, Inkscape::XML::Node *, Inkscape::XML::Node *) final
Child order change callback.
void notifyContentChanged(Inkscape::XML::Node &, Inkscape::Util::ptr_shared, Inkscape::Util::ptr_shared) final
Content change callback.
SPStyleElemNodeObserver & nodeObserver()
CRStyleSheet * style_sheet
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
SPStyleElemTextNodeObserver & textNodeObserver()
void read_content() override
Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags) override
std::vector< std::unique_ptr< SPStyle > > get_styles() const
Get the list of styles.
void set(SPAttr key, char const *value) override
enum CRStatus cr_cascade_set_sheet(CRCascade *a_this, CRStyleSheet *a_sheet, enum CRStyleOrigin a_origin)
CRStyleSheet * cr_cascade_get_sheet(CRCascade *a_this, enum CRStyleOrigin a_origin)
CRDeclaration * cr_declaration_append(CRDeclaration *a_this, CRDeclaration *a_new)
void cr_declaration_dump(CRDeclaration const *a_this, FILE *a_fp, glong a_indent, gboolean a_one_per_line)
CRDeclaration * cr_declaration_new(CRStatement *a_statement, CRString *a_property, CRTerm *a_value)
CRDocHandler * cr_doc_handler_new(void)
typedefG_BEGIN_DECLS struct _CRDocHandler CRDocHandler
gboolean cr_doc_handler_unref(CRDocHandler *a_this)
The declaration file of the CRParser class.
enum CRStatus cr_parser_parse_file(CRParser *a_this, const guchar *a_file_uri, enum CREncoding a_enc)
enum CRStatus cr_parser_parse_buf(CRParser *a_this, const guchar *a_buf, gulong a_len, enum CREncoding a_enc)
void cr_parser_destroy(CRParser *a_this)
CRParser * cr_parser_new(CRTknzr *a_tknzr)
enum CRStatus cr_parser_set_sac_handler(CRParser *a_this, CRDocHandler *a_handler)
typedefG_BEGIN_DECLS struct _CRSelector CRSelector
CRStatement * cr_statement_new_at_font_face_rule(CRStyleSheet *a_sheet, CRDeclaration *a_font_decls)
CRStatement * cr_statement_new_ruleset(CRStyleSheet *a_sheet, CRSelector *a_sel_list, CRDeclaration *a_decl_list, CRStatement *a_media_rule)
@ AT_FONT_FACE_RULE_STMT
A css2 font face rule.
CRStatement * cr_statement_new_at_import_rule(CRStyleSheet *a_container_sheet, CRString *a_url, GList *a_media_list, CRStyleSheet *a_imported_sheet)
CRStatement * cr_statement_append(CRStatement *a_this, CRStatement *a_new)
enum CRStatus cr_statement_ruleset_append_decl(CRStatement *a_this, CRDeclaration *a_decl)
typedefG_BEGIN_DECLS struct _CRString CRString
CRString * cr_string_dup(CRString const *a_this)
CRStyleSheet * cr_stylesheet_unlink(CRStyleSheet *a_this)
CRStatement * cr_stylesheet_statement_get_from_list(CRStyleSheet *a_this, int itemnr)
gint cr_stylesheet_nr_rules(CRStyleSheet const *a_this)
void cr_stylesheet_destroy(CRStyleSheet *a_this)
CRStyleSheet * cr_stylesheet_append_stylesheet(CRStyleSheet *a_this, CRStyleSheet *a_new_stylesheet)
gboolean cr_stylesheet_unref(CRStyleSheet *a_this)
CRStyleSheet * cr_stylesheet_new(CRStatement *a_stmts)
CRStatus
The status type returned by the methods of the croco library.
TODO: insert short description here.
std::string get_filename(Type type, char const *filename, bool localized, bool silent)
@ TEXT_NODE
Text node, e.g. "Some text" in <group>Some text</group> is represented by a text node.
static cairo_user_data_key_t key
Inkscape::IO::Resource - simple resource API.
SPRoot: SVG <svg> implementation.
static void property_cb(CRDocHandler *const a_handler, CRString *const a_name, CRTerm *const a_value, gboolean const a_important)
static void import_style_cb(CRDocHandler *a_handler, GList *a_media_list, CRString *a_uri, CRString *a_uri_default_ns, CRParsingLocation *a_location)
static Glib::ustring concat_children(Inkscape::XML::Node const &repr)
Returns the concatenation of the content of the text children of the specified object.
static void start_selector_cb(CRDocHandler *a_handler, CRSelector *a_sel_list)
static void clear_style_sheet(SPStyleElem &self)
Remove style_sheet from the document style cascade and destroy it.
static void start_font_face_cb(CRDocHandler *a_handler, CRParsingLocation *)
static void end_selector_cb(CRDocHandler *a_handler, CRSelector *a_sel_list)
static void end_font_face_cb(CRDocHandler *a_handler)
TODO: insert short description here.
Interface for XML documents.
virtual Node * createElement(char const *name)=0
CRDeclaration * decl_list
CRString *CRTerm * value
The property.
The implementation of the SAC parser.
CRSelector * sel_list
A list of instances of #CRSimpeSel.
The abstraction of css statement as defined in the chapter 4 and appendix D.1 of the css2 spec.
CRAtFontFaceRule * font_face_rule
union _CRStatement::@6 kind
enum CRStatementType type
The type of the statement.
An abstraction of a css stylesheet as defined by the css2 spec in chapter 4.
enum CRStyleOrigin origin
CRStyleSheet * next
A link to the next stylesheet.
An abstraction of a css2 term as defined in the CSS2 spec in appendix D.1: term ::= [ NUMBER S* | PER...
union _CRTerm::@7 content
The content of the term.
SPStyle - a style object for SPItem objects.
Interface for XML documents.