]> gitweb.michael.orlitzky.com - libsvgtiny.git/log
libsvgtiny.git
3 months agosrc/svgtiny_css.c: change lwc_string_destroy -> lwc_string_unref libcss
Michael Orlitzky [Fri, 26 Jan 2024 12:35:16 +0000 (07:35 -0500)]
src/svgtiny_css.c: change lwc_string_destroy -> lwc_string_unref

In the node_is_lang() callback, we're interning "lang" and later
destroying it. But "lang" is already interned at that point (in
libcss), so we are destroying a copy that doesn't belong to us. It
should be unref'd instead. Valgrind detected the error. Thanks to
Michael Drake for the pointer.

3 months agosrc/svgtiny_css.c: initialize an attr_val pointer to NULL
Michael Orlitzky [Fri, 26 Jan 2024 12:17:39 +0000 (07:17 -0500)]
src/svgtiny_css.c: initialize an attr_val pointer to NULL

We later compare it to NULL, and valgrind says that it's potentially
uninitialized at that point, so let's initialize it.

3 months agosrc/svgtiny_css.c: add prototype for svgtiny_resolve_url()
Michael Orlitzky [Fri, 26 Jan 2024 01:33:21 +0000 (20:33 -0500)]
src/svgtiny_css.c: add prototype for svgtiny_resolve_url()

This fixes a warning with -Wmissing-prototypes.

3 months agosrc/svgtiny_css.c: add a missing break statement
Michael Orlitzky [Fri, 26 Jan 2024 01:20:59 +0000 (20:20 -0500)]
src/svgtiny_css.c: add a missing break statement

Otherwise, we fall through to an assert(false) in the default
case. Thanks to Michael Drake for the suggestion.

3 months agosrc/svgtiny_css.c: fix lwc/dom string comparison in node_has_name()
Michael Orlitzky [Fri, 26 Jan 2024 01:12:22 +0000 (20:12 -0500)]
src/svgtiny_css.c: fix lwc/dom string comparison in node_has_name()

The node_has_name() function was calling lwc_string_isequal() to test
the universal selector (a dom_string) against the given node name (an
lwc_string). Instead, it should be using dom_string_lwc_isequal(),
which is designed to do exactly that. Thanks to Michael Drake for the
suggestion.

3 months agosrc/svgtiny.c: drop unused fill_ and stroke_opacity_type variables
Michael Orlitzky [Fri, 26 Jan 2024 00:53:57 +0000 (19:53 -0500)]
src/svgtiny.c: drop unused fill_ and stroke_opacity_type variables

This eliminates two -Wunused-but-set-variable warnings. Thanks to
Michael Drake for the suggestion.

5 months agosrc/svgtiny.c: whitespace cleanup (spaces to tabs)
Michael Orlitzky [Mon, 20 Nov 2023 16:53:25 +0000 (11:53 -0500)]
src/svgtiny.c: whitespace cleanup (spaces to tabs)

5 months agosrc/svgtiny_css.c: clean trailing newlines
Michael Orlitzky [Mon, 20 Nov 2023 16:45:04 +0000 (11:45 -0500)]
src/svgtiny_css.c: clean trailing newlines

5 months agotest/css: add some visually-verified test cases for our new features
Michael Orlitzky [Thu, 16 Nov 2023 15:55:11 +0000 (10:55 -0500)]
test/css: add some visually-verified test cases for our new features

It's helpful to have some test cases for our CSS handling, but
unfortunately, it's not all that easy to write them. How should we
compare the actual output to the expected output?

For now we settle for a visual comparison. You can render the test
diagrams using the example program examples/svgtiny_display_x11, and
also open them in another SVG viewer. Do they look the same? Great.
The test cases should be simple enough that _subtle_ visual mismatches
are not possible.

Automating this is not an impossible problem: for example, we could
render the parsed diagram to a bitmap image using cairo and then
compare it to what we get using librsvg which is also cairo-based. But
that has downsides too (like the portability of librsvg) that we don't
want to address right now.

5 months agosrc/svgtiny.c: use case-sensitive comparisons for SVG element names
Michael Orlitzky [Sun, 19 Nov 2023 16:39:13 +0000 (11:39 -0500)]
src/svgtiny.c: use case-sensitive comparisons for SVG element names

SVG is XML and its element names are therefore case-sensitive. We
switch to case-sensitive comparisons to avoid rendering elements
(e.g. <RECT />) that other SVG clients (e.g. Firefox) will not.

5 months agoexamples/.gitignore: ignore the compiled example program
Michael Orlitzky [Sun, 19 Nov 2023 13:47:38 +0000 (08:47 -0500)]
examples/.gitignore: ignore the compiled example program

5 months agoexamples/svgtiny_display_x11.c: update build instructions
Michael Orlitzky [Sun, 19 Nov 2023 13:45:32 +0000 (08:45 -0500)]
examples/svgtiny_display_x11.c: update build instructions

First, tell people to run "make" instead of giving them the full "gcc"
command-line. Then elaborate on how one can modify the build process
to use a development copy of libsvgtiny.

5 months agoexamples/GNUmakefile: add a GNUmakefile for the example program
Michael Orlitzky [Sun, 19 Nov 2023 13:32:01 +0000 (08:32 -0500)]
examples/GNUmakefile: add a GNUmakefile for the example program

This should simplify building it a bit, both against the system copy
and against a development repo. We use the name GNUmakefile (as
opposed to Makefile) to avoid interacting with the netsurf build
system.

5 months agosrc/svgtiny.c: remove parent == NULL hack
Michael Orlitzky [Sat, 18 Nov 2023 19:58:20 +0000 (14:58 -0500)]
src/svgtiny.c: remove parent == NULL hack

Now that we're providing some (unused!) default user-agent properties,
this code path is apparently no longer reached. Never look a gift
horse in the mouth, is an insane saying. But everything works great
without the NULL check, so let's remove it.

5 months agosrc/svgtiny_css.c: add some default user-agent properties after all
Michael Orlitzky [Sat, 18 Nov 2023 19:55:13 +0000 (14:55 -0500)]
src/svgtiny_css.c: add some default user-agent properties after all

We tried to avoid populating ua_default_for_property() with any
default properties, but it looks like some are "required." Without
them, the style-composition process gets crashy while trying to set
initial values. Thanks to the libcss example program for the idea.

5 months agosrc/svgtiny.c: implement composition of parent styles
Michael Orlitzky [Thu, 16 Nov 2023 16:11:41 +0000 (11:11 -0500)]
src/svgtiny.c: implement composition of parent styles

5 months agosrc/svgtiny*.{c,h}: move the libcss unit context into the parser state
Michael Orlitzky [Thu, 16 Nov 2023 20:34:37 +0000 (15:34 -0500)]
src/svgtiny*.{c,h}: move the libcss unit context into the parser state

This will make it easier to use the same unit context for style
composition that we do for style computation.

5 months agosrc/svgtiny_internal.h: add parent style to the parser state
Michael Orlitzky [Thu, 16 Nov 2023 16:10:37 +0000 (11:10 -0500)]
src/svgtiny_internal.h: add parent style to the parser state

This will come in handy when we want to compose the current (child)
node's styles with its parent's styles.

5 months agosrc/svgtiny.c: use separate function for style application
Michael Orlitzky [Thu, 16 Nov 2023 14:52:59 +0000 (09:52 -0500)]
src/svgtiny.c: use separate function for style application

We've been doing CSS in svgtiny_parse_paint_attributes(), because we
only support CSS paint attributes at the moment. But ultimately that
won't be right. Let's separate it out now into its own function,
svgtiny_parse_styles().

5 months agosrc/svgtiny.c: update the docstring for svgtiny_parse_svg()
Michael Orlitzky [Thu, 16 Nov 2023 13:54:20 +0000 (08:54 -0500)]
src/svgtiny.c: update the docstring for svgtiny_parse_svg()

The svgtiny_parse_svg() function not only parses <svg> and <g>
elements; it also parses <a> elements.

5 months agoexamples/svgtiny_display_x11.c: use opacity information
Michael Orlitzky [Thu, 16 Nov 2023 01:39:28 +0000 (20:39 -0500)]
examples/svgtiny_display_x11.c: use opacity information

5 months agosrc/svgtiny.c: set shape opacities from the parser state
Michael Orlitzky [Thu, 16 Nov 2023 01:39:06 +0000 (20:39 -0500)]
src/svgtiny.c: set shape opacities from the parser state

Record the "active" fill and stroke opacity from the parser state
in each shape that we create.

5 months agoinclude/svgtiny.h: add fill_opacity and stroke_opacity to svgtiny_shape
Michael Orlitzky [Thu, 16 Nov 2023 01:37:57 +0000 (20:37 -0500)]
include/svgtiny.h: add fill_opacity and stroke_opacity to svgtiny_shape

We already have fields for the fill and stroke opacity in the parser
state, but we have no way to record those values in the shapes we're
creating as we parse. Here we make room to do that.

5 months agosrc/svgtiny.c: parse styles in svgtiny_parse_paint_attributes()
Michael Orlitzky [Wed, 18 Oct 2023 00:09:42 +0000 (20:09 -0400)]
src/svgtiny.c: parse styles in svgtiny_parse_paint_attributes()

Now that the scaffolding is in place, we do the work to parse our two
supported CSS paint attributes, fill-opacity and stroke-opacity. This
amounts to,

  * Calling svgtiny_select_style(), which is just a wrapper around
    css_select_style()
  * Passing the result to css_computed_foo_opacity() to get the
    computed styles
  * Populating fill_opacity and stroke_opacity in the parser state
    if the corresponding styles exist

There's also a temporary hack to avoid crashing on the root node that
later goes away when we implement parent/child style composition.

5 months agotest/decode_svg.c: handle svgtiny_LIBCSS_ERROR
Michael Orlitzky [Wed, 15 Nov 2023 17:32:23 +0000 (12:32 -0500)]
test/decode_svg.c: handle svgtiny_LIBCSS_ERROR

This test program has a switch statement to handle errors, with one
case for each svgtiny_code. Now that svgtiny_LIBCSS_ERROR belongs to
that enum, we add it to the list of cases.

5 months agoexamples/svgtiny_display_x11.c: handle svgtiny_LIBCSS_ERROR
Michael Orlitzky [Wed, 15 Nov 2023 17:32:06 +0000 (12:32 -0500)]
examples/svgtiny_display_x11.c: handle svgtiny_LIBCSS_ERROR

This example program has a switch statement to handle errors, with one
case for each svgtiny_code. Now that svgtiny_LIBCSS_ERROR belongs to
that enum, we add it to the list of cases.

5 months agosrc/svgtiny.c: eliminate pointless NULL check
Michael Orlitzky [Wed, 15 Nov 2023 16:55:18 +0000 (11:55 -0500)]
src/svgtiny.c: eliminate pointless NULL check

We initialize the entire struct to zero a few lines earlier.

5 months agosrc/svgtiny_internal.h: add fill/stroke_opacity to the parse state struct
Michael Orlitzky [Tue, 17 Oct 2023 23:47:00 +0000 (19:47 -0400)]
src/svgtiny_internal.h: add fill/stroke_opacity to the parse state struct

5 months agosrc/svgtiny_internal.h: add svgtiny_select_style() to the header
Michael Orlitzky [Wed, 18 Oct 2023 00:08:55 +0000 (20:08 -0400)]
src/svgtiny_internal.h: add svgtiny_select_style() to the header

We'll need a prototype in order to use that function in svgtiny.c.

5 months agosrc/svgtiny_css.c: add svgtiny_select_style() wrapper
Michael Orlitzky [Tue, 17 Oct 2023 21:43:35 +0000 (17:43 -0400)]
src/svgtiny_css.c: add svgtiny_select_style() wrapper

Some boilerplate will be needed when we call css_select_style() during
parsing. In preparation for (avoiding) that, we factor it out into a
convenience function called svgtiny_select_style().

5 months agosrc/svgtiny_css.c: use our userdata handler in set_libcss_node_data()
Michael Orlitzky [Tue, 17 Oct 2023 21:04:07 +0000 (17:04 -0400)]
src/svgtiny_css.c: use our userdata handler in set_libcss_node_data()

This was a missing part of the implementation that had to wait until
our css_select_handler vtable was defined.

5 months agosrc/svgtiny_css.c: add user handler function
Michael Orlitzky [Tue, 17 Oct 2023 15:35:13 +0000 (11:35 -0400)]
src/svgtiny_css.c: add user handler function

This function needs to be passed to dom_node_set_user_data() in
set_libcss_node_data(), but we couldn't implement it before our
css_select_handler was defined, because it passes the address of
that select handler to css_libcss_node_data_handler().

5 months agosrc/svgtiny_css.c: define a css_select_handler
Michael Orlitzky [Tue, 17 Oct 2023 20:55:03 +0000 (16:55 -0400)]
src/svgtiny_css.c: define a css_select_handler

We define a css_select_handler structure full of all of the select
handlers we've just implemented. This is the big piece of the puzzle
that we need before we can call css_select_style().

5 months agosrc/svgtiny_css.c: implement named_ancestor_node() select handler
Michael Orlitzky [Tue, 17 Oct 2023 20:41:37 +0000 (16:41 -0400)]
src/svgtiny_css.c: implement named_ancestor_node() select handler

5 months agosrc/svgtiny_css.c: implement node_presentational_hint() select handler
Michael Orlitzky [Tue, 17 Oct 2023 15:07:33 +0000 (11:07 -0400)]
src/svgtiny_css.c: implement node_presentational_hint() select handler

5 months agosrc/svgtiny_css.c: implement get_libcss_node_data() select handler
Michael Orlitzky [Tue, 17 Oct 2023 14:36:08 +0000 (10:36 -0400)]
src/svgtiny_css.c: implement get_libcss_node_data() select handler

5 months agosrc/svgtiny_css.c: implement set_libcss_node_data() select handler
Michael Orlitzky [Tue, 17 Oct 2023 14:29:52 +0000 (10:29 -0400)]
src/svgtiny_css.c: implement set_libcss_node_data() select handler

5 months agosrc/svgtiny_strings.h: intern a "userdata" key string
Michael Orlitzky [Tue, 17 Oct 2023 14:22:35 +0000 (10:22 -0400)]
src/svgtiny_strings.h: intern a "userdata" key string

To implement libcss's select handler API, we need to implement two
functions that get/set "userdata" on a node. The corresponding libdom
API allows you to set arbitrary data in the form of key->value pairs;
so to identify THIS particular data, we need to use the same string
each time. For that reason we intern "_libcss_user_data" and call it
the "userdata_key".

5 months agosrc/svgtiny_css.c: implement node_is_visited() select handler
Michael Orlitzky [Tue, 17 Oct 2023 02:08:28 +0000 (22:08 -0400)]
src/svgtiny_css.c: implement node_is_visited() select handler

5 months agosrc/svgtiny_css.c: implement ua_default_for_property() select handler
Michael Orlitzky [Tue, 17 Oct 2023 02:04:15 +0000 (22:04 -0400)]
src/svgtiny_css.c: implement ua_default_for_property() select handler

5 months agosrc/svgtiny_css.c: implement node_is_lang() select handler
Michael Orlitzky [Tue, 17 Oct 2023 01:22:28 +0000 (21:22 -0400)]
src/svgtiny_css.c: implement node_is_lang() select handler

5 months agosrc/svgtiny_css.c: case-insensitivity for node_has_attribute_substring()
Michael Orlitzky [Tue, 17 Oct 2023 01:19:04 +0000 (21:19 -0400)]
src/svgtiny_css.c: case-insensitivity for node_has_attribute_substring()

All of the CSS attribute selectors take a flag to make the comparison
case-insensitive. Libcss doesn't support that yet, but in the case of
node_has_attribute_substring(), factoring out the implementation and
letting it take an "insensitive" flag will be of use to us when we
implement the node_is_lang() select handler.

5 months agosrc/svgtiny_css.c: implement node_is_target() select handler
Michael Orlitzky [Mon, 16 Oct 2023 23:42:09 +0000 (19:42 -0400)]
src/svgtiny_css.c: implement node_is_target() select handler

5 months agosrc/svgtiny_css.c: implement node_is_checked() select handler
Michael Orlitzky [Mon, 16 Oct 2023 23:37:00 +0000 (19:37 -0400)]
src/svgtiny_css.c: implement node_is_checked() select handler

5 months agosrc/svgtiny_css.c: implement node_is_disabled() select handler
Michael Orlitzky [Sat, 14 Oct 2023 23:53:52 +0000 (19:53 -0400)]
src/svgtiny_css.c: implement node_is_disabled() select handler

5 months agosrc/svgtiny_css.c: implement node_is_enabled() select handler
Michael Orlitzky [Sat, 14 Oct 2023 23:49:16 +0000 (19:49 -0400)]
src/svgtiny_css.c: implement node_is_enabled() select handler

5 months agosrc/svgtiny_css.c: implement node_is_focus() select handler
Michael Orlitzky [Sat, 14 Oct 2023 23:36:39 +0000 (19:36 -0400)]
src/svgtiny_css.c: implement node_is_focus() select handler

5 months agosrc/svgtiny_css.c: implement node_is_active() select handler
Michael Orlitzky [Sat, 14 Oct 2023 23:30:15 +0000 (19:30 -0400)]
src/svgtiny_css.c: implement node_is_active() select handler

5 months agosrc/svgtiny_css.c: implement node_is_hover() select handler
Michael Orlitzky [Sat, 14 Oct 2023 23:27:56 +0000 (19:27 -0400)]
src/svgtiny_css.c: implement node_is_hover() select handler

5 months agosrc/svgtiny_css.c: implement node_is_link() select handler
Michael Orlitzky [Sat, 14 Oct 2023 17:13:45 +0000 (13:13 -0400)]
src/svgtiny_css.c: implement node_is_link() select handler

5 months agosrc/svgtiny_css.c: implement node_is_empty() select handler
Michael Orlitzky [Sat, 14 Oct 2023 15:39:20 +0000 (11:39 -0400)]
src/svgtiny_css.c: implement node_is_empty() select handler

5 months agosrc/svgtiny_css.c: implement node_count_siblings() select handler
Michael Orlitzky [Sat, 14 Oct 2023 14:31:14 +0000 (10:31 -0400)]
src/svgtiny_css.c: implement node_count_siblings() select handler

5 months agosrc/svgtiny_css.c: implement node_is_root() select handler
Michael Orlitzky [Sat, 14 Oct 2023 00:42:35 +0000 (20:42 -0400)]
src/svgtiny_css.c: implement node_is_root() select handler

5 months agosrc/svgtiny_css.c: implement node_has_attribute_substring() select handler
Michael Orlitzky [Sat, 14 Oct 2023 00:22:49 +0000 (20:22 -0400)]
src/svgtiny_css.c: implement node_has_attribute_substring() select handler

5 months agosrc/svgtiny_css.c: implement node_has_attribute_suffix() select handler
Michael Orlitzky [Fri, 13 Oct 2023 23:53:16 +0000 (19:53 -0400)]
src/svgtiny_css.c: implement node_has_attribute_suffix() select handler

5 months agosrc/svgtiny_css.c: implement node_has_attribute_prefix() select handler
Michael Orlitzky [Fri, 13 Oct 2023 23:33:06 +0000 (19:33 -0400)]
src/svgtiny_css.c: implement node_has_attribute_prefix() select handler

5 months agosrc/svgtiny_css.c: implement node_has_attribute_includes() select handler
Michael Orlitzky [Fri, 13 Oct 2023 01:40:34 +0000 (21:40 -0400)]
src/svgtiny_css.c: implement node_has_attribute_includes() select handler

5 months agosrc/svgtiny_css.c: implement node_has_attribute_dashmatch() select handler
Michael Orlitzky [Fri, 13 Oct 2023 01:00:53 +0000 (21:00 -0400)]
src/svgtiny_css.c: implement node_has_attribute_dashmatch() select handler

5 months agosrc/svgtiny_css.c: implement node_has_attribute_equal() select handler
Michael Orlitzky [Thu, 12 Oct 2023 23:42:45 +0000 (19:42 -0400)]
src/svgtiny_css.c: implement node_has_attribute_equal() select handler

5 months agosrc/svgtiny_css.c: implement node_has_attribute() select handler
Michael Orlitzky [Thu, 12 Oct 2023 22:38:45 +0000 (18:38 -0400)]
src/svgtiny_css.c: implement node_has_attribute() select handler

5 months agosrc/svgtiny_css.c: implement node_has_id() select handler
Michael Orlitzky [Thu, 12 Oct 2023 22:28:40 +0000 (18:28 -0400)]
src/svgtiny_css.c: implement node_has_id() select handler

5 months agosrc/svgtiny_css.c: implement node_has_class() select handler
Michael Orlitzky [Thu, 12 Oct 2023 22:18:30 +0000 (18:18 -0400)]
src/svgtiny_css.c: implement node_has_class() select handler

5 months agosrc/svgtiny_css.c: implement node_has_name() select handler
Michael Orlitzky [Thu, 12 Oct 2023 22:10:05 +0000 (18:10 -0400)]
src/svgtiny_css.c: implement node_has_name() select handler

5 months agosrc/svgtiny_strings.h: intern the universal selector string "*"
Michael Orlitzky [Thu, 12 Oct 2023 22:07:44 +0000 (18:07 -0400)]
src/svgtiny_strings.h: intern the universal selector string "*"

This is a prerequisite for implementing the node_has_name() select
handler.

5 months agosrc/svgtiny_css.c: implement sibling_node() select handler
Michael Orlitzky [Thu, 12 Oct 2023 18:43:39 +0000 (14:43 -0400)]
src/svgtiny_css.c: implement sibling_node() select handler

5 months agosrc/svgtiny_css.c: implement parent_node() select handler
Michael Orlitzky [Thu, 12 Oct 2023 18:20:05 +0000 (14:20 -0400)]
src/svgtiny_css.c: implement parent_node() select handler

5 months agosrc/svgtiny_css.c: implement named_generic_sibling_node() select handler
Michael Orlitzky [Thu, 12 Oct 2023 18:07:44 +0000 (14:07 -0400)]
src/svgtiny_css.c: implement named_generic_sibling_node() select handler

5 months agosrc/svgtiny_css.c: implement named_sibling_node() select handler
Michael Orlitzky [Thu, 12 Oct 2023 12:17:45 +0000 (08:17 -0400)]
src/svgtiny_css.c: implement named_sibling_node() select handler

5 months agosrc/svgtiny_css.c: implement named_parent_node() select handler
Michael Orlitzky [Thu, 12 Oct 2023 11:42:02 +0000 (07:42 -0400)]
src/svgtiny_css.c: implement named_parent_node() select handler

5 months agosrc/svgtiny_css.c: implement node_id() select handler
Michael Orlitzky [Thu, 12 Oct 2023 02:25:00 +0000 (22:25 -0400)]
src/svgtiny_css.c: implement node_id() select handler

5 months agosrc/svgtiny_strings.h: intern "id" for libcss
Michael Orlitzky [Thu, 12 Oct 2023 02:17:34 +0000 (22:17 -0400)]
src/svgtiny_strings.h: intern "id" for libcss

As a prerequisite for implementing a libcss node_id() select handler,
we intern the string "id" that it will need access to.

5 months agosrc/svgtiny_css.c: implement node_classes() select handler
Michael Orlitzky [Wed, 11 Oct 2023 23:57:56 +0000 (19:57 -0400)]
src/svgtiny_css.c: implement node_classes() select handler

5 months agosrc/svgtiny_css.c: implement node_name() select handler
Michael Orlitzky [Wed, 11 Oct 2023 23:40:08 +0000 (19:40 -0400)]
src/svgtiny_css.c: implement node_name() select handler

5 months agosrc/svgtiny{.c,_internal.h}: intern SVG's XML namespace URI
Michael Orlitzky [Thu, 12 Oct 2023 02:04:53 +0000 (22:04 -0400)]
src/svgtiny{.c,_internal.h}: intern SVG's XML namespace URI

Intern the string "http://www.w3.org/2000/svg" in the parser state for
later use in libcss's node_name() select handler.

5 months agosrc/svgtiny.c: parse inline stylesheet in svgtiny_parse_paint_attributes()
Michael Orlitzky [Wed, 11 Oct 2023 19:17:08 +0000 (15:17 -0400)]
src/svgtiny.c: parse inline stylesheet in svgtiny_parse_paint_attributes()

...and do nothing with it, for the moment. We are able to parse the
inline style="..." attributes right now but more scaffolding is needed
before we can utilize css_select_style().

5 months agosrc/svgtiny.c: add svgtiny_parse_style_inline() function
Michael Orlitzky [Wed, 11 Oct 2023 16:09:57 +0000 (12:09 -0400)]
src/svgtiny.c: add svgtiny_parse_style_inline() function

This function parses the contents of an inline style="..." attribute
into a libcss stylesheet, or NULL if anything went wrong.

5 months agosrc/svgtiny_internal.h: drop svgtiny_resolve_url() prototype
Michael Orlitzky [Wed, 11 Oct 2023 12:44:54 +0000 (08:44 -0400)]
src/svgtiny_internal.h: drop svgtiny_resolve_url() prototype

This is no longer needed now that svgtiny_resolve_url() lives in the
same file as its sole consumer, svgtiny_create_stylesheet().

5 months agosrc/svgtiny.c: use svgtiny_create_stylesheet() to parse <style>
Michael Orlitzky [Wed, 11 Oct 2023 12:41:51 +0000 (08:41 -0400)]
src/svgtiny.c: use svgtiny_create_stylesheet() to parse <style>

The new function handles all of the boilerplate parameter creation
that was originally done in svgtiny_parse_style_element().

5 months agosrc/svgtiny_internal.h: add svgtiny_create_stylesheet() prototype
Michael Orlitzky [Wed, 11 Oct 2023 12:40:51 +0000 (08:40 -0400)]
src/svgtiny_internal.h: add svgtiny_create_stylesheet() prototype

Needed to let src/svgtiny.c know about the new function.

5 months agosrc/svgtiny_css.c: new function svgtiny_create_stylesheet()
Michael Orlitzky [Wed, 11 Oct 2023 12:27:22 +0000 (08:27 -0400)]
src/svgtiny_css.c: new function svgtiny_create_stylesheet()

We add a function to handle the creation of a new stylesheet with the
default set of parameters. This is in preparation for parsing the
inline styles, which a priori would involve copy/pasting a lot of

  params.foo = bar;

lines from svgtiny_parse_style_element(). The goal is to factor the
common bits out of both the <style> and style= implementations.

5 months agosrc/svgtiny.c: add svgtiny_parse_style_element() function and use it
Michael Orlitzky [Wed, 4 Oct 2023 12:20:40 +0000 (08:20 -0400)]
src/svgtiny.c: add svgtiny_parse_style_element() function and use it

The new function parses the contents of a <style> element. We add a
call to it in svgtiny_preparse_styles() where previously a placeholder
was left.

7 months agosrc/Makefile: add the new svgtiny_css.c to the list of sources
Michael Orlitzky [Wed, 4 Oct 2023 12:30:37 +0000 (08:30 -0400)]
src/Makefile: add the new svgtiny_css.c to the list of sources

7 months agosrc/svgtiny_internal.h: add svgtiny_resolve_url() prototype
Michael Orlitzky [Wed, 4 Oct 2023 12:30:09 +0000 (08:30 -0400)]
src/svgtiny_internal.h: add svgtiny_resolve_url() prototype

7 months agosrc/svgtiny_css.c: new file with new svgtiny_resolve_url() function
Michael Orlitzky [Wed, 4 Oct 2023 12:27:28 +0000 (08:27 -0400)]
src/svgtiny_css.c: new file with new svgtiny_resolve_url() function

Define a stub relative-URL resolver that assumes all URLs are absolute
and returns them unmodified. Some method of doing this is required by
libcss. At the moment, libcss does not support any SVG properties that
take url() values, so not much is lost.

7 months agosrc/svgtiny.c: add impotent svgtiny_preparse_styles() function
Michael Orlitzky [Wed, 4 Oct 2023 11:49:17 +0000 (07:49 -0400)]
src/svgtiny.c: add impotent svgtiny_preparse_styles() function

We declare and add the svgtiny_preparse_styles() function that will be
used to make a first pass through the SVG document and parse all of
the <style> elements. At the moment it is only half implemented:
once we find a <style> element, we do nothing with it. A separate
function will be used to parse a <style> once we have it.

7 months agosrc/svgtiny.c: initialize the libcss context in svgtiny_parse()
Michael Orlitzky [Wed, 4 Oct 2023 04:11:11 +0000 (00:11 -0400)]
src/svgtiny.c: initialize the libcss context in svgtiny_parse()

Before we begin parsing, we have to initialize our new css_select_ctx
by calling css_select_ctx_create(). Later, when parsing is complete,
we css_select_ctx_destroy() it.

7 months agoREADME: document the new svgtiny_LIBCSS_ERROR code
Michael Orlitzky [Wed, 4 Oct 2023 03:51:14 +0000 (23:51 -0400)]
README: document the new svgtiny_LIBCSS_ERROR code

7 months agoinclude/svgtiny.h: add new error constant svgtiny_LIBCSS_ERROR
Michael Orlitzky [Wed, 4 Oct 2023 03:50:00 +0000 (23:50 -0400)]
include/svgtiny.h: add new error constant svgtiny_LIBCSS_ERROR

Analogous to svgtiny_LIBDOM_ERROR, we add svgtiny_LIBCSS_ERROR to
indicate an error related to CSS.

7 months agosrc/svgtiny_strings.h: add "media" to the list of strings
Michael Orlitzky [Wed, 4 Oct 2023 03:03:30 +0000 (23:03 -0400)]
src/svgtiny_strings.h: add "media" to the list of strings

The "media" attribute is arguably the only meaningful attribute a
<style> element has within an SVG document. Here we intern the string
"media" in preparation for parsing <style>. Libcss can at least store
the media information even if we decide not to use it.

7 months agosrc/svgtiny_internal.h: add CSS context to parser state
Michael Orlitzky [Wed, 4 Oct 2023 02:51:38 +0000 (22:51 -0400)]
src/svgtiny_internal.h: add CSS context to parser state

Add a css_select_ctx pointer to the svgtiny_parse_state that is
threaded through each phase of SVG parsing. This will allow us to
populate the context with any <style> sheets we find; later, we can
consult those stylesheets while constructing our svgtiny_diagram (the
abstract representation into which we parse an SVG).

7 months agoREADME: mention that libcss is required
Michael Orlitzky [Wed, 4 Oct 2023 03:12:37 +0000 (23:12 -0400)]
README: mention that libcss is required

7 months agoMakefile: build against libcss
Michael Orlitzky [Wed, 4 Oct 2023 02:03:29 +0000 (22:03 -0400)]
Makefile: build against libcss

The first step towards adding libcss support is to build against
libcss. For now that means getting its "cflags" and "libs" from
pkg-config and putting them into CFLAGS and LDFLAGS.

7 months agosrc/svgtiny.c: remove old misleading libcss comments
Michael Orlitzky [Wed, 4 Oct 2023 00:13:53 +0000 (20:13 -0400)]
src/svgtiny.c: remove old misleading libcss comments

There were a few comments in this file suggesting some future libcss
integration. However, now that we are beginning that integration (much
later), it is probably best to start with a clean slate. So, we remove
those comments.

7 months agosrc/svgtiny_internal.h: removed commented libcss stub
Michael Orlitzky [Wed, 4 Oct 2023 00:10:13 +0000 (20:10 -0400)]
src/svgtiny_internal.h: removed commented libcss stub

This files once thought about declaring,

  /*struct css_style style;*/

as a member of the svgtiny_parse_state struct. We delete that comment
now so that we can begin libcss integration with a clean slate.

9 months agoexamples/svgtiny_display_x11.c: include the system copy of svgtiny.h master
Michael Orlitzky [Sun, 6 Aug 2023 00:36:05 +0000 (20:36 -0400)]
examples/svgtiny_display_x11.c: include the system copy of svgtiny.h

The header of this file includes instructions for how to build it:

  Compile using:
    gcc -g -W -Wall -o svgtiny_display_x11 svgtiny_display_x11.c \
            `pkg-config --cflags --libs libsvgtiny cairo` -lX11

That pkg-config command will generate the flags to link against the
installed copy of libsvgtiny. The line,

  #include "svgtiny.h"

on the other hand, attempts to use a local header. This commit changes
that line to,

  #include <svgtiny.h>

which will use the corresponding system header from whatever include
directory pkg-config hands us for libsvgtiny.

9 months agoexamples/svgtiny_display_x11.c: add missing stdlib.h include
Michael Orlitzky [Sun, 6 Aug 2023 00:36:04 +0000 (20:36 -0400)]
examples/svgtiny_display_x11.c: add missing stdlib.h include

This file uses malloc(), free(), and exit() -- all of which are
defined in stdlib.h. GCC seems unhappy about the situation, so we now
include it. This allows the file to be compiled once again.

9 months agoexamples/svgtiny_display_x11.c: update LIBXML -> LIBDOM
Michael Orlitzky [Sun, 6 Aug 2023 00:36:03 +0000 (20:36 -0400)]
examples/svgtiny_display_x11.c: update LIBXML -> LIBDOM

The svgtiny_LIBXML_ERROR constant was changed to throughout the
codebase to svgtiny_LIBDOM_ERROR a long time ago, in 9275ab308, but
this example was missed, probably because it isn't built by default.

9 months agoREADME: update LIBXML -> LIBDOM
Michael Orlitzky [Sun, 6 Aug 2023 00:36:02 +0000 (20:36 -0400)]
README: update LIBXML -> LIBDOM

This constant svgtiny_LIBXML_ERROR was changed throughout the codebase
to svgtiny_LIBDOM_ERROR a long time ago, in 9275ab308, but the README
was missed because nobody reads the documentation :)

3 years agoimplement svg path arc correctly
Vincent Sanders [Sat, 3 Oct 2020 14:12:30 +0000 (15:12 +0100)]
implement svg path arc correctly

5 years agoUpdate component version for release
Vincent Sanders [Tue, 28 Aug 2018 10:18:37 +0000 (11:18 +0100)]
Update component version for release