Monday, 20 November 2023

Pull request: CSS support for libsvgtiny

As promised, and only a month late. My branch is available at,

https://gitweb.michael.orlitzky.com/libsvgtiny.git libcss

For best results, you should also apply the libcss patch I recently
posted that makes fill- and stroke-opacity inherited properties.

No major issues remain. There's a test suite in test/css consisting
of a bunch of SVG files that you can open side-by-side in the
libsvgtiny example program and your favorite image viewer. With the
libcss patch, they all pass (compared to firefox). Without it, two
fail.

If you recall, there was some concern about the licensing of the
select handlers. I think I spent enough time learning and rewriting
the handlers to alleviate those concerns; I ultimately did not copy
anything from NetSurf, although naturally many of the handlers look
similar (and of course I reimplemented them *after* looking at the
NetSurf handlers, so you be the judge).

A summary of the changes follows.

----------------------------------------------------------------
Michael Orlitzky (88):
src/svgtiny_internal.h: removed commented libcss stub
src/svgtiny.c: remove old misleading libcss comments
Makefile: build against libcss
README: mention that libcss is required
src/svgtiny_internal.h: add CSS context to parser state
src/svgtiny_strings.h: add "media" to the list of strings
include/svgtiny.h: add new error constant svgtiny_LIBCSS_ERROR
README: document the new svgtiny_LIBCSS_ERROR code
src/svgtiny.c: initialize the libcss context in svgtiny_parse()
src/svgtiny.c: add impotent svgtiny_preparse_styles() function
src/svgtiny_css.c: new file with new svgtiny_resolve_url() function
src/svgtiny_internal.h: add svgtiny_resolve_url() prototype
src/Makefile: add the new svgtiny_css.c to the list of sources
src/svgtiny.c: add svgtiny_parse_style_element() function and use it
src/svgtiny_css.c: new function svgtiny_create_stylesheet()
src/svgtiny_internal.h: add svgtiny_create_stylesheet() prototype
src/svgtiny.c: use svgtiny_create_stylesheet() to parse <style>
src/svgtiny_internal.h: drop svgtiny_resolve_url() prototype
src/svgtiny.c: add svgtiny_parse_style_inline() function
src/svgtiny.c: parse inline stylesheet in svgtiny_parse_paint_attributes()
src/svgtiny{.c,_internal.h}: intern SVG's XML namespace URI
src/svgtiny_css.c: implement node_name() select handler
src/svgtiny_css.c: implement node_classes() select handler
src/svgtiny_strings.h: intern "id" for libcss
src/svgtiny_css.c: implement node_id() select handler
src/svgtiny_css.c: implement named_parent_node() select handler
src/svgtiny_css.c: implement named_sibling_node() select handler
src/svgtiny_css.c: implement named_generic_sibling_node() select handler
src/svgtiny_css.c: implement parent_node() select handler
src/svgtiny_css.c: implement sibling_node() select handler
src/svgtiny_strings.h: intern the universal selector string "*"
src/svgtiny_css.c: implement node_has_name() select handler
src/svgtiny_css.c: implement node_has_class() select handler
src/svgtiny_css.c: implement node_has_id() select handler
src/svgtiny_css.c: implement node_has_attribute() select handler
src/svgtiny_css.c: implement node_has_attribute_equal() select handler
src/svgtiny_css.c: implement node_has_attribute_dashmatch() select handler
src/svgtiny_css.c: implement node_has_attribute_includes() select handler
src/svgtiny_css.c: implement node_has_attribute_prefix() select handler
src/svgtiny_css.c: implement node_has_attribute_suffix() select handler
src/svgtiny_css.c: implement node_has_attribute_substring() select handler
src/svgtiny_css.c: implement node_is_root() select handler
src/svgtiny_css.c: implement node_count_siblings() select handler
src/svgtiny_css.c: implement node_is_empty() select handler
src/svgtiny_css.c: implement node_is_link() select handler
src/svgtiny_css.c: implement node_is_hover() select handler
src/svgtiny_css.c: implement node_is_active() select handler
src/svgtiny_css.c: implement node_is_focus() select handler
src/svgtiny_css.c: implement node_is_enabled() select handler
src/svgtiny_css.c: implement node_is_disabled() select handler
src/svgtiny_css.c: implement node_is_checked() select handler
src/svgtiny_css.c: implement node_is_target() select handler
src/svgtiny_css.c: case-insensitivity for node_has_attribute_substring()
src/svgtiny_css.c: implement node_is_lang() select handler
src/svgtiny_css.c: implement ua_default_for_property() select handler
src/svgtiny_css.c: implement node_is_visited() select handler
src/svgtiny_strings.h: intern a "userdata" key string
src/svgtiny_css.c: implement set_libcss_node_data() select handler
src/svgtiny_css.c: implement get_libcss_node_data() select handler
src/svgtiny_css.c: implement node_presentational_hint() select handler
src/svgtiny_css.c: implement named_ancestor_node() select handler
src/svgtiny_css.c: define a css_select_handler
src/svgtiny_css.c: add user handler function
src/svgtiny_css.c: use our userdata handler in set_libcss_node_data()
src/svgtiny_css.c: add svgtiny_select_style() wrapper
src/svgtiny_internal.h: add svgtiny_select_style() to the header
src/svgtiny_internal.h: add fill/stroke_opacity to the parse state struct
src/svgtiny.c: eliminate pointless NULL check
examples/svgtiny_display_x11.c: handle svgtiny_LIBCSS_ERROR
test/decode_svg.c: handle svgtiny_LIBCSS_ERROR
src/svgtiny.c: parse styles in svgtiny_parse_paint_attributes()
include/svgtiny.h: add fill_opacity and stroke_opacity to svgtiny_shape
src/svgtiny.c: set shape opacities from the parser state
examples/svgtiny_display_x11.c: use opacity information
src/svgtiny.c: update the docstring for svgtiny_parse_svg()
src/svgtiny.c: use separate function for style application
src/svgtiny_internal.h: add parent style to the parser state
src/svgtiny*.{c,h}: move the libcss unit context into the parser state
src/svgtiny.c: implement composition of parent styles
src/svgtiny_css.c: add some default user-agent properties after all
src/svgtiny.c: remove parent == NULL hack
examples/GNUmakefile: add a GNUmakefile for the example program
examples/svgtiny_display_x11.c: update build instructions
examples/.gitignore: ignore the compiled example program
src/svgtiny.c: use case-sensitive comparisons for SVG element names
test/css: add some visually-verified test cases for our new features
src/svgtiny_css.c: clean trailing newlines
src/svgtiny.c: whitespace cleanup (spaces to tabs)

Makefile | 8 +-
README | 13 +-
examples/.gitignore | 2 +
examples/GNUmakefile | 20 +
examples/svgtiny_display_x11.c | 55 +-
include/svgtiny.h | 5 +-
src/Makefile | 2 +-
src/svgtiny.c | 494 ++++++++++--
src/svgtiny_css.c | 2069 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/svgtiny_internal.h | 37 +-
src/svgtiny_strings.h | 4 +
test/css/README | 11 +
test/css/attributes.svg | 94 +++
test/css/case-sensitive-elements.svg | 19 +
test/css/empty-pseudo-class.svg | 33 +
test/css/id-and-class.svg | 49 ++
test/css/inherit.svg | 43 ++
test/css/inline.svg | 31 +
test/css/lang.svg | 32 +
test/css/link-pseudo-class.svg | 36 +
test/css/node-name.svg | 40 +
test/css/nth-child.svg | 52 ++
test/css/root.svg | 25 +
test/css/siblings-and-descendants.svg | 64 ++
test/css/styles-at-end.svg | 29 +
test/decode_svg.c | 3 +
26 files changed, 3169 insertions(+), 101 deletions(-)
create mode 100644 examples/.gitignore
create mode 100644 examples/GNUmakefile
create mode 100644 src/svgtiny_css.c
create mode 100644 test/css/README
create mode 100644 test/css/attributes.svg
create mode 100644 test/css/case-sensitive-elements.svg
create mode 100644 test/css/empty-pseudo-class.svg
create mode 100644 test/css/id-and-class.svg
create mode 100644 test/css/inherit.svg
create mode 100644 test/css/inline.svg
create mode 100644 test/css/lang.svg
create mode 100644 test/css/link-pseudo-class.svg
create mode 100644 test/css/node-name.svg
create mode 100644 test/css/nth-child.svg
create mode 100644 test/css/root.svg
create mode 100644 test/css/siblings-and-descendants.svg
create mode 100644 test/css/styles-at-end.svg
_______________________________________________
netsurf-dev mailing list -- netsurf-dev@netsurf-browser.org
To unsubscribe send an email to netsurf-dev-leave@netsurf-browser.org

No comments:

Post a Comment