[lasem/wip/emmanuel/css] wip



commit 3ed04640f4aa3f81a82ba7831b98c5d777bc82d0
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Sat Jun 13 22:06:36 2015 +0200

    wip

 docs/reference/lasem/Makefile.am         |    1 +
 src/Makefile.am                          |   10 +-
 src/lsm.h                                |    1 +
 src/lsmcss.c                             |  456 ++++++++++++++++++++++++++++++
 src/lsmcss.h                             |   66 +++++
 src/lsmproperties.c                      |   18 +-
 src/lsmproperties.h                      |   10 +-
 src/lsmstr.h                             |   28 ++
 src/lsmsvgstyle.c                        |    5 +-
 src/lsmtypes.h                           |    1 +
 tests/.gitignore                         |    1 +
 tests/Makefile.am                        |    6 +-
 tests/css.c                              |   16 +
 tests/data/svg/svg1.2/images/svgRef4.css |    8 +-
 14 files changed, 615 insertions(+), 12 deletions(-)
---
diff --git a/docs/reference/lasem/Makefile.am b/docs/reference/lasem/Makefile.am
index 75b668c..d864e0e 100644
--- a/docs/reference/lasem/Makefile.am
+++ b/docs/reference/lasem/Makefile.am
@@ -73,6 +73,7 @@ IGNORE_HFILES=\
        lsmproperties.h                         \
        lsmattributes.h                         \
        lsmitex.h                               \
+       lsmcss.h                                \
        lsmmathml.h                             \
        lsmmathmltypes.h                        \
        lsmmathmlenums.h                        \
diff --git a/src/Makefile.am b/src/Makefile.am
index bbfb1c0..90614d4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,6 +51,9 @@ LASEM_DOM_SRCS =                              \
        lsmdomparser.c                          \
        lsmdomimplementation.c
 
+LASEM_CSS_SRCS =                               \
+       lsmcss.c
+
 LASEM_DOM_BUILT_SRCS =                         \
        lsmdomenumtypes.c                       \
        lsmdomenumtypes.h
@@ -170,6 +173,9 @@ LASEM_DOM_HDRS =                            \
        lsmdomparser.h                          \
        lsmdomimplementation.h
 
+LASEM_CSS_HDRS =                               \
+       lsmcss.h
+
 LASEM_MATHML_HDRS =                            \
        lsmmathml.h                             \
        lsmmathmltypes.h                        \
@@ -266,9 +272,11 @@ LASEM_SVG_HDRS =                           \
 liblasem_ LASEM_API_VERSION@_ladir = $(includedir)/lasem- LASEM_API_VERSION@
 
 liblasem_ LASEM_API_VERSION@_la_SOURCES = $(LASEM_DOM_SRCS) $(LASEM_DOM_BUILT_SRCS) $(LASEM_MATHML_SRCS) 
$(LASEM_SVG_SRCS)
-liblasem_ LASEM_API_VERSION@_la_SOURCES +=  $(LASEM_MATHML_HDRS) $(LASEM_SVG_HDRS)
+liblasem_ LASEM_API_VERSION@_la_SOURCES += $(LASEM_MATHML_HDRS) $(LASEM_SVG_HDRS)
 liblasem_ LASEM_API_VERSION@_la_SOURCES += lsmmathmlenumtypes.h lsmsvgenumtypes.h
 
+liblasem_ LASEM_API_VERSION@_la_SOURCES += $(LASEM_CSS_SRCS) $(LASEM_CSS_HDRS)
+
 liblasem_ LASEM_API_VERSION@_la_HEADERS = $(LASEM_DOM_HDRS)
 liblasem_ LASEM_API_VERSION@_la_HEADERS += lsmdomenumtypes.h
 
diff --git a/src/lsm.h b/src/lsm.h
index 803d2b2..1b066a2 100644
--- a/src/lsm.h
+++ b/src/lsm.h
@@ -33,6 +33,7 @@
 #include <lsmattributes.h>
 #include <lsmproperties.h>
 #include <lsmitex.h>
+#include <lsmcss.h>
 
 void lsm_shutdown (void);
 
diff --git a/src/lsmcss.c b/src/lsmcss.c
new file mode 100644
index 0000000..a18eff5
--- /dev/null
+++ b/src/lsmcss.c
@@ -0,0 +1,456 @@
+/* Lasem
+ *
+ * Copyright © 2007-2010 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author:
+ *     Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+/**
+ * SECTION:lsmcss
+ * @short_description: CSS support class
+ */
+
+#include <lsmcss.h>
+#include <lsmstr.h>
+#include <gio/gio.h>
+#include <stdio.h>
+
+static GObjectClass *parent_class = NULL;
+
+enum {
+       LSM_CSS_PROPERTY_0,
+       LSM_CSS_PROPERTY_DATA
+} LsmCssProperties;
+
+struct _LsmCssPrivate {
+       int dummy;
+};
+
+/* LsmCss implementation */
+
+typedef struct {
+       char *name;
+       char *value;
+} LsmCssAttribute;
+
+typedef struct {
+       GSList *terms;
+} LsmCssSelector;
+
+typedef struct {
+       GSList *selectors;
+       GSList *attributes;
+} LsmCssRule;
+
+LsmCssAttribute *      lsm_css_attribute_new           (const char *name, const char *value);
+void                   lsm_css_attribute_free          (LsmCssAttribute *attribute);
+LsmCssSelector *       lsm_css_selector_new            (void);
+void                   lsm_css_selector_free           (LsmCssSelector *selector);
+LsmCssRule *           lsm_css_rule_new                (void);
+void                   lsm_css_rule_free               (LsmCssRule *rule);
+void                   lsm_css_rule_add_selector       (LsmCssRule *rule, LsmCssSelector *selector);
+void                   lsm_css_rule_add_attribute      (LsmCssRule *rule, const char *name, const char 
*value);
+
+LsmCssAttribute *
+lsm_css_attribute_new (const char *name, const char *value)
+{
+       LsmCssAttribute *attribute;
+
+       g_return_val_if_fail (name != NULL, NULL);
+       g_return_val_if_fail (value != NULL, NULL);
+
+       attribute = g_new0 (LsmCssAttribute, 1);
+       attribute->name = g_strdup (name);
+       attribute->value = g_strdup (value);
+
+       return attribute;
+}
+
+void
+lsm_css_attribute_free (LsmCssAttribute *attribute)
+{
+       g_return_if_fail (attribute != NULL);
+
+       g_free (attribute->name);
+       g_free (attribute->value);
+       g_free (attribute);
+}
+
+LsmCssSelector *
+lsm_css_selector_new (void)
+{
+       LsmCssSelector *selector;
+
+       selector = g_new0 (LsmCssSelector, 1);
+       return selector;
+}
+
+void
+lsm_css_selector_free (LsmCssSelector *selector)
+{
+       g_return_if_fail (selector != NULL);
+
+       g_slist_free_full (selector->terms, g_free);
+       g_free (selector);
+}
+
+LsmCssRule *
+lsm_css_rule_new (void)
+{
+       LsmCssRule *rule;
+
+       rule = g_new0 (LsmCssRule, 1);
+       
+       return rule;
+}
+
+void
+lsm_css_rule_free (LsmCssRule *rule)
+{
+       g_return_if_fail (rule != NULL);
+
+       g_slist_free_full (rule->selectors, (GDestroyNotify) lsm_css_selector_free);
+       g_slist_free_full (rule->attributes, (GDestroyNotify) lsm_css_attribute_free);
+       g_free (rule);
+}
+
+void
+lsm_css_rule_add_selector (LsmCssRule *rule, LsmCssSelector *selector)
+{
+       g_return_if_fail (rule != NULL);
+       g_return_if_fail (selector != NULL);
+
+       rule->selectors = g_slist_prepend (rule->selectors, selector);
+}
+
+void
+lsm_css_rule_add_attribute (LsmCssRule *rule, const char *name, const char *value)
+{
+       LsmCssAttribute *attribute;
+
+       g_return_if_fail (rule != NULL);
+
+       attribute = lsm_css_attribute_new (name, value);
+       g_return_if_fail (attribute != NULL);
+
+       rule->attributes = g_slist_prepend (rule->attributes, attribute);
+}
+
+#define LSM_CSS_PARSE_ERROR lsm_css_parse_error_quark ()
+
+static GQuark
+lsm_css_parse_error_quark (void)
+{
+       return g_quark_from_static_string ("lsm-css-parse-error-quark");
+}
+
+static void
+_skip_comment_space_line (char **str)
+{
+       char *ptr;
+
+       do {
+               ptr = *str;
+
+               lsm_str_skip_comment (str);
+               lsm_str_skip_spaces (str);
+               lsm_str_skip_line_separators (str);
+       } while (ptr != *str);
+}
+
+static char *
+_parse_element (char **str)
+{
+       char *start = *str;
+
+       if (**str == '.' ||
+           **str == '#' ||
+           g_ascii_isalnum (**str))
+               (*str)++;
+
+       while (g_ascii_isalnum (**str) ||
+              **str == '-' ||
+              **str == '_' ||
+              **str == ':')
+               (*str)++;
+
+       if (*str == start)
+               return NULL;
+
+       return g_strndup (start, *str - start);
+}
+
+static char *
+_parse_attribute_name (char **str)
+{
+       char *start = *str;
+
+       if (g_ascii_isalnum (**str))
+               (*str)++;
+
+       while (g_ascii_isalnum (**str) ||
+              **str == '-' ||
+              **str == '_')
+               (*str)++;
+
+       if (*str == start)
+               return NULL;
+
+       return g_strndup (start, *str - start);
+}
+
+static char *
+_parse_attribute_value (char **str)
+{
+       char *start = *str;
+       char *value;
+
+       while (**str != ';' &&
+              **str != '\0')
+               (*str)++;
+
+       if (*str == start)
+               return NULL;
+
+       value = g_strndup (start, *str - start);
+
+       if (**str == ';')
+               (*str)++;
+
+       return value;
+}
+
+static gboolean
+lsm_css_parse_buffer (LsmCss *css, const char *buffer, gsize size, GError **error)
+{
+       char *str = (char *) buffer;
+       GString *selector;
+       GError *local_error = NULL;
+
+       g_return_val_if_fail (LSM_IS_CSS (css), FALSE);
+
+       if (buffer == NULL)
+               return TRUE;
+
+       selector = g_string_new ("");
+
+       do {
+               do {
+                       g_string_assign (selector, "");
+
+                       do {
+                               char *element;
+
+                               _skip_comment_space_line (&str);
+                               element = _parse_element (&str);
+                               _skip_comment_space_line (&str);
+
+                               if (element != NULL)
+                                       g_string_append (selector, element);
+
+                               g_free (element);
+                       } while (*str != ',' &&
+                                *str != '{' &&
+                                *str != '\0' &&
+                                local_error == NULL);
+
+                       if (selector->len == 0 && *str != '\0') {
+                               local_error = g_error_new (LSM_CSS_PARSE_ERROR, 0, "Expected selector 
definition");
+                       } else if (*str != '\0')
+                               printf ("selector = %s\n", selector->str);
+
+               } while (*str != '{' && 
+                        *str != '\0' &&
+                        local_error == NULL);
+
+               if (*str == '{') {
+                       str++;
+
+                       do {
+                               char *attribute_name;
+
+                               _skip_comment_space_line (&str);
+                               attribute_name = _parse_attribute_name (&str);
+                               _skip_comment_space_line (&str);
+
+                               printf ("attr_name = '%s'\n", attribute_name);
+
+                               if (*str != ':') {
+                                       local_error = g_error_new (LSM_CSS_PARSE_ERROR, 0, "Missing colon");
+                               } else {
+                                       char *attribute_value;
+
+                                       str++;
+                                       _skip_comment_space_line (&str);
+                                       attribute_value = _parse_attribute_value (&str);
+                                       _skip_comment_space_line (&str);
+
+                                       printf ("attr_value = '%s'\n", attribute_value);
+
+                                       g_free (attribute_value);
+                               }
+
+                               g_free (attribute_name);
+                       } while (*str != '}' &&
+                                *str != '\0' &&
+                                local_error == NULL);
+
+                       if (*str != '}') {
+                               local_error = g_error_new (LSM_CSS_PARSE_ERROR, 0, "Missing closing curly 
brackets");
+                       } else
+                               str++;
+               }
+
+       } while (*str != '\0' && local_error == NULL);
+
+       g_string_free (selector, TRUE);
+
+       if (local_error != NULL) {
+               printf ("error: %s\n", local_error->message);
+               g_propagate_error (error, local_error);
+       }
+
+       return local_error == NULL;
+}
+
+LsmCss *
+lsm_css_new_from_memory  (const void *buffer, gssize size, GError **error)
+{
+       LsmCss *css;
+
+       css = g_object_new (LSM_TYPE_CSS, "data", buffer, NULL);
+
+       return css;
+}
+
+static LsmCss *
+lsm_css_new_from_file  (GFile *file, GError **error)
+{
+       LsmCss *css;
+       gsize size = 0;
+       char *contents = NULL;
+
+       if (!g_file_load_contents (file, NULL, &contents, &size, NULL, error))
+               return NULL;
+
+       css = lsm_css_new_from_memory (contents, size, error);
+
+       g_free (contents);
+
+       return css;
+}
+
+LsmCss *
+lsm_css_new_from_path (const char *path, GError **error)
+{
+       LsmCss *css;
+       GFile *file;
+
+       g_return_val_if_fail (path != NULL, NULL);
+
+       file = g_file_new_for_path (path);
+
+       css = lsm_css_new_from_file (file, error);
+
+       g_object_unref (file);
+
+       return css;
+}
+
+LsmCss *
+lsm_css_new_from_url (const char *url, GError **error)
+{
+       LsmCss *css;
+       GFile *file;
+
+       g_return_val_if_fail (url != NULL, NULL);
+
+       file = g_file_new_for_uri (url);
+
+       css = lsm_css_new_from_file (file, error);
+
+       g_object_unref (file);
+
+       return css;
+}
+
+static void
+_set_property (GObject * object, guint prop_id,
+              const GValue * value, GParamSpec * pspec)
+{
+       LsmCss *css = LSM_CSS (object);
+
+       switch (prop_id) {
+               case LSM_CSS_PROPERTY_DATA:
+                       lsm_css_parse_buffer (css, g_value_get_string (value), -1, NULL);
+                       break;
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+_get_property (GObject * object, guint prop_id,
+              GValue * value, GParamSpec * pspec)
+{
+       switch (prop_id) {
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+lsm_css_init (LsmCss *css)
+{
+       css->priv = G_TYPE_INSTANCE_GET_PRIVATE (css, LSM_TYPE_CSS, LsmCssPrivate);
+}
+
+static void
+_finalize (GObject *object)
+{
+       parent_class->finalize (object);
+}
+
+/* LsmCss class */
+
+static void
+lsm_css_class_init (LsmCssClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (klass, sizeof (LsmCssPrivate));
+
+       parent_class = g_type_class_peek_parent (klass);
+
+       object_class->finalize = _finalize;
+       object_class->set_property = _set_property;
+       object_class->get_property = _get_property;
+
+       g_object_class_install_property (
+               object_class, LSM_CSS_PROPERTY_DATA,
+               g_param_spec_string ("data", "Data",
+                                    "CSS data", "",
+                                    G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)
+               );
+}
+
+G_DEFINE_TYPE (LsmCss, lsm_css, G_TYPE_OBJECT)
+
diff --git a/src/lsmcss.h b/src/lsmcss.h
new file mode 100644
index 0000000..a45f478
--- /dev/null
+++ b/src/lsmcss.h
@@ -0,0 +1,66 @@
+/* Lasem
+ *
+ * Copyright © 20015 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author:
+ *     Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef LSM_CSS_H
+#define LSM_CSS_H
+
+#include <lsmtypes.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+       LSM_CSS_SPECIFITY_NAME_OR_PSEUDO_ELEMENT = 0x0001,
+       LSM_CSS_SPECIFITY_ATTRIBUTE_OR_PSEUDO_CLASS = 0x0010,
+       LSM_CSS_SPECIFITY_ID = 0x0100,
+       LSM_CSS_SPECIFITY_INLINE_STYLE = 0x1000
+} LsmCssSpecifity;
+
+#define LSM_TYPE_CSS             (lsm_css_get_type ())
+#define LSM_CSS(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_CSS, LsmCss))
+#define LSM_CSS_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_CSS, LsmCssClass))
+#define LSM_IS_CSS(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_CSS))
+#define LSM_IS_CSS_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_CSS))
+#define LSM_CSS_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_CSS, LsmCssClass))
+
+typedef struct _LsmCssPrivate LsmCssPrivate;
+typedef struct _LsmCssClass LsmCssClass;
+
+struct _LsmCss {
+       GObject object;
+
+       LsmCssPrivate *priv;
+};
+
+struct _LsmCssClass {
+       GObjectClass parent_class;
+};
+
+GType lsm_css_get_type (void);
+
+LsmCss *               lsm_css_new_from_memory         (const void *buffer, gssize size, GError **error);
+LsmCss *               lsm_css_new_from_path           (const char *path, GError **error);
+LsmCss *               lsm_css_new_from_url            (const char *url, GError **error);
+
+G_END_DECLS
+
+#endif
diff --git a/src/lsmproperties.c b/src/lsmproperties.c
index 4f78055..a64896f 100644
--- a/src/lsmproperties.c
+++ b/src/lsmproperties.c
@@ -34,6 +34,9 @@ struct _LsmPropertyManager {
        const LsmPropertyInfos *property_infos;
        GHashTable *            hash_by_name;
 
+       LsmPropertySpecificity  default_specificity;
+       LsmPropertySpecificity  inline_style_specificity;
+
        /* FIXME: Not thread safe */
        unsigned int *          property_check;
        unsigned int            property_check_count;
@@ -44,7 +47,9 @@ struct _LsmPropertyManager {
 G_DEFINE_BOXED_TYPE (LsmPropertyManager, lsm_property_manager, lsm_property_manager_ref, 
lsm_property_manager_unref)
 
 LsmPropertyManager *
-lsm_property_manager_new (unsigned int n_properties, const LsmPropertyInfos *property_infos)
+lsm_property_manager_new (unsigned int n_properties, const LsmPropertyInfos *property_infos,
+                         LsmPropertySpecificity default_specificity,
+                         LsmPropertySpecificity inline_style_specificity)
 {
        LsmPropertyManager *manager;
        guint16 i;
@@ -58,6 +63,8 @@ lsm_property_manager_new (unsigned int n_properties, const LsmPropertyInfos *pro
        manager->property_infos = property_infos;
        manager->property_check_count = 0;
        manager->property_check = g_new0 (unsigned int, n_properties);
+       manager->default_specificity = default_specificity;
+       manager->inline_style_specificity = inline_style_specificity;
        manager->ref_count = 1;
 
        for (i = 0; i < n_properties; i++) {
@@ -108,7 +115,9 @@ property_free (LsmProperty *property, const LsmTraitClass *trait_class)
 static gboolean
 _set_property (LsmPropertyManager *manager,
               LsmPropertyBag *property_bag,
-              const char *name, const char *value)
+              const char *name,
+              const char *value,
+              LsmPropertySpecificity specificity)
 {
        LsmProperty *property;
        const LsmPropertyInfos *property_infos;
@@ -126,6 +135,7 @@ _set_property (LsmPropertyManager *manager,
        property = g_slice_alloc0 (PROPERTY_SIZE (trait_class));
        property->id = property_infos->id;
        property->value = g_strdup (value);
+       property->specificity = specificity;
 
        if (trait_class->init)
                trait_class->init (PROPERTY_TRAIT (property), NULL);
@@ -160,7 +170,7 @@ lsm_property_manager_set_property (LsmPropertyManager *manager,
        g_return_val_if_fail (manager != NULL, FALSE);
        g_return_val_if_fail (name != NULL, FALSE);
 
-       property_found = _set_property (manager, property_bag, name, value);
+       property_found = _set_property (manager, property_bag, name, value, manager->default_specificity);
        if (property_found)
                return TRUE;
 
@@ -205,7 +215,7 @@ lsm_property_manager_set_property (LsmPropertyManager *manager,
                                        lsm_debug_dom ("[LsmPropertyManager::set_property] inline_style %s = 
%s",
                                                       name, value);
 
-                                       _set_property (manager, property_bag, name, value);
+                                       _set_property (manager, property_bag, name, value, 
manager->inline_style_specificity);
 
                                        *end_ptr = old_char;
 
diff --git a/src/lsmproperties.h b/src/lsmproperties.h
index 84c0325..cd99461 100644
--- a/src/lsmproperties.h
+++ b/src/lsmproperties.h
@@ -32,9 +32,11 @@ G_BEGIN_DECLS
 #define LSM_PROPERTY_OFFSET_TO_ID(structure,member) (offsetof (structure, member) / sizeof (void *))
 #define LSM_PROPERTY_ID_TO_OFFSET(id) ((id) * sizeof (void *))
 
+typedef guint32 LsmPropertySpecificity;
+
 typedef struct {
-       guint16 id;
-       guint16 flags;
+       guint32 id;
+       LsmPropertySpecificity specificity;
        char *  value;
 } LsmProperty;
 
@@ -56,7 +58,9 @@ typedef struct _LsmPropertyManager LsmPropertyManager;
 GType lsm_property_manager_get_type (void);
 
 LsmPropertyManager *   lsm_property_manager_new        (unsigned int n_properties,
-                                                        const LsmPropertyInfos *property_infos);
+                                                        const LsmPropertyInfos *property_infos,
+                                                        LsmPropertySpecificity default_specificity,
+                                                        LsmPropertySpecificity inline_style_specificity);
 LsmPropertyManager *   lsm_property_manager_ref        (LsmPropertyManager *manager);
 void                   lsm_property_manager_unref      (LsmPropertyManager *manager);
 
diff --git a/src/lsmstr.h b/src/lsmstr.h
index 466915d..b0268fd 100644
--- a/src/lsmstr.h
+++ b/src/lsmstr.h
@@ -71,6 +71,34 @@ lsm_str_skip_colon_and_spaces (char **str)
                (*str)++;
 }
 
+static inline void
+lsm_str_skip_line_separators (char **str)
+{
+       while (**str == '\r' || **str == '\n' || **str == '\f')
+               (*str)++;
+}
+
+static inline void
+lsm_str_skip_comment (char **str)
+{
+       do {
+               if (**str != '/' || *(*str + 1) != '*')
+                       return;
+
+               (*str)++;
+               (*str)++;
+
+               while (**str != '\0' && **str != '*' && *(*str + 1) != '/')
+                       (*str)++;
+
+               if (**str == '\0')
+                       return;
+
+               (*str)++;
+               (*str)++;
+       } while (TRUE);
+}
+
 /**
  * lsm_str_consolidate:
  * @str: a utf8 string
diff --git a/src/lsmsvgstyle.c b/src/lsmsvgstyle.c
index 79611d3..0d61fce 100644
--- a/src/lsmsvgstyle.c
+++ b/src/lsmsvgstyle.c
@@ -424,7 +424,10 @@ lsm_svg_get_property_manager (void)
        if (G_LIKELY (manager != NULL))
                return manager;
 
-       manager = lsm_property_manager_new (G_N_ELEMENTS (lsm_svg_property_infos), lsm_svg_property_infos);
+       manager = lsm_property_manager_new (G_N_ELEMENTS (lsm_svg_property_infos),
+                                           lsm_svg_property_infos,
+                                           LSM_CSS_SPECIFITY_INLINE_STYLE,
+                                           LSM_CSS_SPECIFITY_INLINE_STYLE);
 
        return manager;
 }
diff --git a/src/lsmtypes.h b/src/lsmtypes.h
index 655e420..c9a5c5a 100644
--- a/src/lsmtypes.h
+++ b/src/lsmtypes.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
 
 typedef struct _LsmExtents LsmExtents;
 typedef struct _LsmBox LsmBox;
+typedef struct _LsmCss LsmCss;
 
 G_END_DECLS
 
diff --git a/tests/.gitignore b/tests/.gitignore
index 21a68cd..a25d2dc 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,5 +1,6 @@
 dom
 str
 lsm-test
+css
 fuzz.*
 *-diff.png
diff --git a/tests/Makefile.am b/tests/Makefile.am
index be8b8e1..be2c2fc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,7 +14,7 @@ noinst_PROGRAMS = lsm-test
 lsm_test_SOURCES = lsmtest.c
 lsm_test_LDADD = $(test_progs_ldadd)
 
-TEST_PROGS += dom str suite
+TEST_PROGS += dom str suite css
 
 noinst_PROGRAMS += $(TEST_PROGS)
 
@@ -28,4 +28,8 @@ suite_SOURCES = suite.c
 suite_LDADD = $(test_progs_ldadd)
 suite_CFLAGS = -DSUITE_DATA_DIRECTORY="\"$(top_srcdir)/tests/data\"" 
-DSUITE_OPTION_FILE="\"$(top_srcdir)/tests/suite.ini\""
 
+css_SOURCES = css.c
+css_LDADD = $(test_progs_ldadd)
+css_CFLAGS = -DCSS_TEST_FILE="\"$(top_srcdir)/tests/data/svg/svg1.2/images/svgRef4.css\""
+
 EXTRA_DIST = suite.ini
diff --git a/tests/css.c b/tests/css.c
new file mode 100644
index 0000000..fe736b6
--- /dev/null
+++ b/tests/css.c
@@ -0,0 +1,16 @@
+#include <lsm.h>
+#include <stdlib.h>
+
+int
+main (int argc, char **argv)
+{
+       LsmCss *css;
+
+       printf ("%s\n", CSS_TEST_FILE);
+
+       css = lsm_css_new_from_path (CSS_TEST_FILE, NULL);
+
+       g_object_unref (css);
+
+       return EXIT_SUCCESS;
+}
diff --git a/tests/data/svg/svg1.2/images/svgRef4.css b/tests/data/svg/svg1.2/images/svgRef4.css
index e97a488..09a3ffe 100644
--- a/tests/data/svg/svg1.2/images/svgRef4.css
+++ b/tests/data/svg/svg1.2/images/svgRef4.css
@@ -1,4 +1,8 @@
-rect     {fill:red;}
+/* Test comment */
+
+/* Other comment */
+
+rect     { fill : red; /* Comment */ }
 circle   {fill:blue;}
 polygon  {fill:green;}
-ellipse  {fill:gold;}
\ No newline at end of file
+ellipse  {fill:gold;}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]