Commit 99de9377 authored by Dom Lachowicz's avatar Dom Lachowicz

bunch of work needed for optional libcroco support

parent 888c3074
2003-03-18 Dom Lachowicz <cinamod@hotmail.com>
* configure.in: Updates for optional libcroco support
* Makefile.am: ditto
* librsvg-2.0.pc.in: ditto
* rsvg-styles.c: ditto
2003-03-18 Dom Lachowicz <cinamod@hotmail.com> / Ross Alexander <ross.alexander@uk.neceur.com>
* configure.in: Bump version # to 2.3.0
......
......@@ -54,6 +54,7 @@ librsvginc_HEADERS = $(GSFHEADERS) \
librsvg-features.h
INCLUDES =$(LIBGSF_CFLAGS)\
$(LIBCROCO_CFLAGS)\
-I$(top_srcdir) \
-I$(top_builddir) \
$(LIBRSVG_CFLAGS) \
......@@ -68,6 +69,7 @@ INCLUDES =$(LIBGSF_CFLAGS)\
DEPS = $(top_builddir)/librsvg-2.la
LDADDS =$(LIBGSF_LIBS)\
$(LIBCROCO_LIBS)\
$(top_builddir)/librsvg-2.la \
$(LIBRSVG_LIBS) \
$(POPT_LIBS)
......
......@@ -97,6 +97,35 @@ AC_SUBST(LIBGSF_LIBS)
dnl ===========================================================================
dnl ===========================================================================
LIBCROCO_CFLAGS=""
LIBCROCO_LIBS=""
LIBCROCOPKG=""
test_croco=true
AC_ARG_WITH(croco,[ --with-croco Use libcroco for CSS parsing],[
if test "x$withval" = "xno"; then
test_croco=false
fi
])
if test "x$test_croco" = "xtrue"; then
PKG_CHECK_MODULES(LIBCROCO,[libcroco >= 0.1.0], test_croco=true, test_croco=false)
fi
if test "x$test_croco" = "xtrue"; then
LIBCROCO_CFLAGS="$LIBCROCO_CFLAGS -DHAVE_LIBCROCO=1"
LIBCROCOPKG="libgsf-1"
else
AC_MSG_WARN([LibCroco support disabled, as requested (Use --with-croco to enable)])
fi
AC_SUBST(LIBCROCOPKG)
AC_SUBST(LIBCROCO_CFLAGS)
AC_SUBST(LIBCROCO_LIBS)
dnl ===========================================================================
dnl Turn on the additional warnings last, so -Werror doesn't affect other tests.
AC_ARG_ENABLE(more-warnings,
......
......@@ -6,6 +6,6 @@ includedir=@includedir@
Name: librsvg
Description: library that renders svg files using libart and pango
Version: @VERSION@
Requires: glib-2.0 gdk-pixbuf-2.0 libart-2.0 libxml-2.0 pangoft2 @LIBGSFPKG@
Requires: glib-2.0 gdk-pixbuf-2.0 libart-2.0 libxml-2.0 pangoft2 @LIBGSFPKG@ @LIBCROCOPKG@
Libs: -L${libdir} -lrsvg-2
Cflags: -I${includedir}/librsvg-2
......@@ -352,22 +352,162 @@ rsvg_parse_style (RsvgHandle *ctx, RsvgState *state, const char *str)
}
}
/*
* Extremely poor man's CSS parser. Not robust. Not compliant.
* Should work well enough for our needs ;-)
* See also: http://www.w3.org/TR/REC-CSS2/syndata.html
* I should use that sometime in order to make a complaint parser
*/
void
rsvg_parse_cssbuffer (RsvgHandle *ctx, const char * buff, size_t buflen)
static void
rsvg_css_define_style (RsvgHandle *ctx, const char * style_name, const char * style_def)
{
GString * str = g_string_new (style_def);
char * existing = NULL;
/* push name/style pair into HT */
existing = (char *)g_hash_table_lookup (ctx->css_props, style_name);
if (existing != NULL)
g_string_append_len (str, existing, strlen (existing));
/* will destroy the existing key and value for us */
g_hash_table_insert (ctx->css_props, (gpointer)g_strdup (style_name), (gpointer)str->str);
g_string_free (str, FALSE);
}
#ifdef HAVE_LIBCROCO
#include <libcroco.h>
typedef struct _CSSUserData
{
RsvgHandle *ctx;
GString *def;
} CSSUserData;
static void
css_user_data_init (CSSUserData *user_data, RsvgHandle * ctx)
{
user_data->ctx = ctx;
user_data->def = NULL;
}
static void
ccss_start_selector (CRDocHandler *a_handler,
CRSelector *a_selector_list)
{
CSSUserData * user_data;
g_return_if_fail (a_handler);
user_data = (CSSUserData *)a_handler->app_data;
user_data->def = g_string_new (NULL);
}
static void
ccss_end_selector (CRDocHandler *a_handler,
CRSelector *a_selector_list)
{
CSSUserData * user_data;
CRSelector * list;
g_return_if_fail (a_handler);
user_data = (CSSUserData *)a_handler->app_data;
if (a_selector_list)
{
for (list = a_selector_list; list != NULL; list = list->next) {
/* iterate through the selector list, insert style into map - strdup it! */
rsvg_css_define_style (user_data->ctx, list->simple_sel->name->str, user_data->def->str);
}
}
g_string_free (user_data->def, TRUE);
}
static void
ccss_property (CRDocHandler *a_handler, GString *a_name, CRTerm *a_expr)
{
CSSUserData * user_data;
char * expr = NULL;
g_return_if_fail (a_handler);
user_data = (CSSUserData *)a_handler->app_data;
if (a_name && a_name->str)
{
if (a_expr)
{
expr = cr_term_to_string (a_expr);
g_string_append_len (user_data->def, expr, strlen (expr));
g_free (expr);
}
}
}
static void
init_sac_handler (CRDocHandler *a_handler)
{
a_handler->start_document = NULL;
a_handler->end_document = NULL;
a_handler->import_style = NULL;
a_handler->namespace_declaration = NULL;
a_handler->comment = NULL;
a_handler->start_selector = ccss_start_selector;
a_handler->end_selector = ccss_end_selector;
a_handler->property = ccss_property;
a_handler->start_font_face = NULL;
a_handler->end_font_face = NULL;
a_handler->start_media = NULL;
a_handler->end_media = NULL;
a_handler->start_page = NULL;
a_handler->end_page = NULL;
a_handler->ignorable_at_rule = NULL;
}
static void
rsvg_real_parse_cssbuffer (RsvgHandle *ctx, const char * buff, size_t buflen)
{
enum CRStatus status = CR_OK;
CRParser *parser = NULL;
CRDocHandler * css_handler = NULL;
CSSUserData user_data;
css_handler = cr_doc_handler_new ();
init_sac_handler (css_handler);
css_user_data_init (&user_data, ctx);
css_handler->app_data = &user_data;
/* TODO: fix libcroco to take in const strings */
parser = cr_parser_new_from_buf ((char *)buff, (long)buflen, CR_UTF_8, FALSE);
status = cr_parser_set_sac_handler (parser, css_handler);
if (status != CR_OK)
{
cr_parser_destroy (parser);
return;
}
status = cr_parser_set_use_core_grammar (parser, FALSE);
status = cr_parser_parse (parser);
cr_parser_destroy (parser);
}
#else /* !HAVE_LIBCROCO */
/* #warning Building without libcroco support. Will experience sub-optimal CSS parsing. */
static void
rsvg_real_parse_cssbuffer (RsvgHandle *ctx, const char * buff, size_t buflen)
{
/*
* Extremely poor man's CSS parser. Not robust. Not compliant.
* See also: http://www.w3.org/TR/REC-CSS2/syndata.html
*/
size_t loc = 0;
while (loc < buflen)
{
GString * style_name = g_string_new (NULL);
GString * style_props = g_string_new (NULL);
const char * existing = NULL;
/* advance to the style's name */
while (loc < buflen && g_ascii_isspace (buff[loc]))
......@@ -402,16 +542,9 @@ rsvg_parse_cssbuffer (RsvgHandle *ctx, const char * buff, size_t buflen)
}
}
/* push name/style pair into HT */
existing = (const char *)g_hash_table_lookup (ctx->css_props, style_name->str);
if (existing != NULL)
g_string_append_len (style_props, existing, strlen (existing));
/* will destroy the existing key and value for us */
g_hash_table_insert (ctx->css_props, style_name->str, style_props->str);
g_string_free (style_name, FALSE);
g_string_free (style_props, FALSE);
rsvg_css_define_style (ctx, style_name->str, style_props->str);
g_string_free (style_name, TRUE);
g_string_free (style_props, TRUE);
loc++;
while (loc < buflen && g_ascii_isspace (buff[loc]))
......@@ -419,6 +552,15 @@ rsvg_parse_cssbuffer (RsvgHandle *ctx, const char * buff, size_t buflen)
}
}
#endif /* HAVE_LIBCROCO */
void
rsvg_parse_cssbuffer (RsvgHandle *ctx, const char * buff, size_t buflen)
{
/* delegate off to the builtin or libcroco implementation */
rsvg_real_parse_cssbuffer (ctx, buff, buflen);
}
/* Parse an SVG transform string into an affine matrix. Reference: SVG
working draft dated 1999-07-06, section 8.5. Return TRUE on
success. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment