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().
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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 :)
Michael Drake [Thu, 20 Apr 2017 09:51:07 +0000 (10:51 +0100)]
Build: Include gperf-generated code directly.
Previously we built the generated code separatly and then linked to
it. However, this caused problems with certain compilers and gperf
versions. This change includes the generated code directly in
svgtiny.c instead, which is the only place its used.
from getting its fill gradient details trampled when we reset the
gradient for the the missing bar gadient definition. Note, we only
handle linearGradient on the fill anyway.
The svg was causing more path elements to be generated in the internal
representation than space was allocated for and overrunning heap
blocks.
The path element parsing was using a fixed size allocation for the
path elements and never bounds checked. Further it did not cope with
zero length paths (which the spec says are permitted). It was also
grossly overallocating for the common case.
This changes the path element array to be bounds checked and then
extended if required, the initial allocation is generally sufficient
and in testing very few resizes occurred.
The reallocation strategy grows the element storage by 2.5 each time
this means even in the degenerate case very few reallocations are
required. In testing no more than a single reallocation has been
observed.
The final path element array will always be reallocted to the minimum
required size. This reduces overall memory usage which is useful with
complex scenes.
Vincent Sanders [Thu, 23 Oct 2014 21:18:16 +0000 (22:18 +0100)]
fix parsing of whitespace in transform operators
The SVG spec for the transform attribute allows whitespace in places
that were causing the %n specifier in the ssanf to return 0 as the
match failed before it completed the parse.
Paul Mecklenburg [Fri, 10 Oct 2014 22:13:02 +0000 (23:13 +0100)]
Fix relative move commands following a path close.
Both 'M' and 'm' are moves and therefore start a new (sub)path. In
either case the location should be cached so that a later 'close path'
(z or Z) knows the location it is returning to. The location is not
written to 'p', since it is assumed that the client code remembers. If
the next move is relative (lowercase), then it's important that last_x,
last_y were correctly updated while processing Z/z.
Chris Young [Sat, 5 Jan 2013 21:11:31 +0000 (21:11 +0000)]
Explicitly check if r0 or r1 are NaN, as if they are, on x86 the function evaluates as 0 (which is already handled), but on PPC the function evaluates to a negative value, causing the following for loop to become infinite.