netsurf: branch master updated. release/3.10-76-g833c995
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/833c9957a1137f77e5ab6...
...commit http://git.netsurf-browser.org/netsurf.git/commit/833c9957a1137f77e5ab647...
...tree http://git.netsurf-browser.org/netsurf.git/tree/833c9957a1137f77e5ab647ee...
The branch, master has been updated
via 833c9957a1137f77e5ab647eeb1a9cf53798fd12 (commit)
from 511f4cc8001ed09d361651186aad67fcf098b1c6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=833c9957a1137f77e5a...
commit 833c9957a1137f77e5ab647eeb1a9cf53798fd12
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
treeview: Squash warnings about enum value conversion.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 27be737..feb1a7c 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -952,6 +952,34 @@ static void treeview__search_cancel(treeview *tree, bool drop_focus)
treeview__cw_invalidate_area(tree, &r);
}
+/**
+ * Convert from treeview drag to core window drag type.
+ *
+ * \param[in] tree A treeview.
+ * \return Core window drag type.
+ */
+static core_window_drag_status treeview__get_cw_drag_type(
+ const treeview *tree)
+{
+ assert(tree != NULL);
+
+ switch (tree->drag.type) {
+ case TV_DRAG_NONE:
+ return CORE_WINDOW_DRAG_NONE;
+
+ case TV_DRAG_SELECTION:
+ return CORE_WINDOW_DRAG_SELECTION;
+
+ case TV_DRAG_TEXTAREA: /* Fall through.*/
+ case TV_DRAG_SEARCH:
+ return CORE_WINDOW_DRAG_TEXT_SELECTION;
+
+ case TV_DRAG_MOVE:
+ return CORE_WINDOW_DRAG_MOVE;
+ }
+
+ return CORE_WINDOW_DRAG_NONE;
+}
/**
* Callback for textarea_create, in desktop/treeview.h
@@ -978,7 +1006,8 @@ static void treeview_textarea_search_callback(void *data,
/* Textarea drag started */
tree->drag.type = TV_DRAG_SEARCH;
}
- treeview__cw_drag_status(tree, tree->drag.type);
+ treeview__cw_drag_status(tree,
+ treeview__get_cw_drag_type(tree));
break;
case TEXTAREA_MSG_REDRAW_REQUEST:
@@ -4217,7 +4246,8 @@ static void treeview_textarea_callback(void *data, struct textarea_msg *msg)
/* Textarea drag started */
tree->drag.type = TV_DRAG_TEXTAREA;
}
- treeview__cw_drag_status(tree, tree->drag.type);
+ treeview__cw_drag_status(tree,
+ treeview__get_cw_drag_type(tree));
break;
case TEXTAREA_MSG_REDRAW_REQUEST:
-----------------------------------------------------------------------
Summary of changes:
desktop/treeview.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 27be737..feb1a7c 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -952,6 +952,34 @@ static void treeview__search_cancel(treeview *tree, bool drop_focus)
treeview__cw_invalidate_area(tree, &r);
}
+/**
+ * Convert from treeview drag to core window drag type.
+ *
+ * \param[in] tree A treeview.
+ * \return Core window drag type.
+ */
+static core_window_drag_status treeview__get_cw_drag_type(
+ const treeview *tree)
+{
+ assert(tree != NULL);
+
+ switch (tree->drag.type) {
+ case TV_DRAG_NONE:
+ return CORE_WINDOW_DRAG_NONE;
+
+ case TV_DRAG_SELECTION:
+ return CORE_WINDOW_DRAG_SELECTION;
+
+ case TV_DRAG_TEXTAREA: /* Fall through.*/
+ case TV_DRAG_SEARCH:
+ return CORE_WINDOW_DRAG_TEXT_SELECTION;
+
+ case TV_DRAG_MOVE:
+ return CORE_WINDOW_DRAG_MOVE;
+ }
+
+ return CORE_WINDOW_DRAG_NONE;
+}
/**
* Callback for textarea_create, in desktop/treeview.h
@@ -978,7 +1006,8 @@ static void treeview_textarea_search_callback(void *data,
/* Textarea drag started */
tree->drag.type = TV_DRAG_SEARCH;
}
- treeview__cw_drag_status(tree, tree->drag.type);
+ treeview__cw_drag_status(tree,
+ treeview__get_cw_drag_type(tree));
break;
case TEXTAREA_MSG_REDRAW_REQUEST:
@@ -4217,7 +4246,8 @@ static void treeview_textarea_callback(void *data, struct textarea_msg *msg)
/* Textarea drag started */
tree->drag.type = TV_DRAG_TEXTAREA;
}
- treeview__cw_drag_status(tree, tree->drag.type);
+ treeview__cw_drag_status(tree,
+ treeview__get_cw_drag_type(tree));
break;
case TEXTAREA_MSG_REDRAW_REQUEST:
--
NetSurf Browser
2 years, 11 months
netsurf: branch master updated. release/3.10-75-g511f4cc
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/511f4cc8001ed09d36165...
...commit http://git.netsurf-browser.org/netsurf.git/commit/511f4cc8001ed09d3616511...
...tree http://git.netsurf-browser.org/netsurf.git/tree/511f4cc8001ed09d361651186...
The branch, master has been updated
via 511f4cc8001ed09d361651186aad67fcf098b1c6 (commit)
via 12fba46d3e738ad6b865500012f85cb0c35cd45d (commit)
from 06c721c5bb6cd06fc35bd0a36a98415758501df8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=511f4cc8001ed09d361...
commit 511f4cc8001ed09d361651186aad67fcf098b1c6
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Add missing include
diff --git a/frontends/amiga/clipboard.c b/frontends/amiga/clipboard.c
index 00dba2d..05a8360 100644
--- a/frontends/amiga/clipboard.c
+++ b/frontends/amiga/clipboard.c
@@ -17,6 +17,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include <proto/iffparse.h>
#include <proto/intuition.h>
#include <proto/exec.h>
diff --git a/frontends/amiga/dt_picture.c b/frontends/amiga/dt_picture.c
index 2e5d155..ed1272b 100644
--- a/frontends/amiga/dt_picture.c
+++ b/frontends/amiga/dt_picture.c
@@ -25,6 +25,7 @@
#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
#include <proto/datatypes.h>
#include <proto/dos.h>
#include <proto/intuition.h>
diff --git a/frontends/amiga/dt_sound.c b/frontends/amiga/dt_sound.c
index 8b63d6a..16b4f7c 100644
--- a/frontends/amiga/dt_sound.c
+++ b/frontends/amiga/dt_sound.c
@@ -23,6 +23,8 @@
#ifdef WITH_AMIGA_DATATYPES
#include "amiga/os3support.h"
+#include <string.h>
+
#include <proto/datatypes.h>
#include <proto/dos.h>
#include <proto/intuition.h>
diff --git a/frontends/amiga/file.c b/frontends/amiga/file.c
index 2fe7d66..79acb1a 100644
--- a/frontends/amiga/file.c
+++ b/frontends/amiga/file.c
@@ -22,6 +22,8 @@
#include <proto/icon.h>
#include <workbench/icon.h>
+#include <string.h>
+
#include "utils/utils.h"
#include "utils/nsoption.h"
#include "utils/file.h"
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=12fba46d3e738ad6b86...
commit 12fba46d3e738ad6b865500012f85cb0c35cd45d
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Cache codesets structure ourselves
attempt to speed up conversion as apparently codesets is being very slow
diff --git a/frontends/amiga/utf8.c b/frontends/amiga/utf8.c
index f16cbba..af5af12 100755
--- a/frontends/amiga/utf8.c
+++ b/frontends/amiga/utf8.c
@@ -36,21 +36,35 @@ static nserror ami_utf8_codesets(const char *string, size_t len, char **result,
{
char *out;
ULONG utf8_tag, local_tag;
+ static struct codeset *utf8_cs = NULL;
+ static struct codeset *local_cs = NULL;
+
+ if(local_cs == NULL) CodesetsFind(NULL,
+#ifdef __amigaos4__
+ CSA_MIBenum, nsoption_int(local_codeset),
+#else
+ NULL,
+#endif
+ TAG_DONE);
+
+ if(utf8_cs == NULL) CodesetsFind(NULL,
+ CSA_MIBenum, CS_MIBENUM_UTF_8,
+ TAG_DONE);
if(to_local == false) {
- local_tag = CSA_SourceMIBenum;
- utf8_tag = CSA_DestMIBenum;
+ local_tag = CSA_SourceCodeset;
+ utf8_tag = CSA_DestCodeset;
} else {
- utf8_tag = CSA_SourceMIBenum;
- local_tag = CSA_DestMIBenum;
+ utf8_tag = CSA_SourceCodeset;
+ local_tag = CSA_DestCodeset;
}
out = CodesetsConvertStr(CSA_Source, string,
CSA_SourceLen, len,
#ifdef __amigaos4__
- local_tag, nsoption_int(local_codeset),
+ local_tag, local_cs,
#endif
- utf8_tag, CS_MIBENUM_UTF_8,
+ utf8_tag, utf8_cs,
CSA_MapForeignChars, TRUE,
TAG_DONE);
-----------------------------------------------------------------------
Summary of changes:
frontends/amiga/clipboard.c | 1 +
frontends/amiga/dt_picture.c | 1 +
frontends/amiga/dt_sound.c | 2 ++
frontends/amiga/file.c | 2 ++
frontends/amiga/utf8.c | 26 ++++++++++++++++++++------
5 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/frontends/amiga/clipboard.c b/frontends/amiga/clipboard.c
index 00dba2d..05a8360 100644
--- a/frontends/amiga/clipboard.c
+++ b/frontends/amiga/clipboard.c
@@ -17,6 +17,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include <proto/iffparse.h>
#include <proto/intuition.h>
#include <proto/exec.h>
diff --git a/frontends/amiga/dt_picture.c b/frontends/amiga/dt_picture.c
index 2e5d155..ed1272b 100644
--- a/frontends/amiga/dt_picture.c
+++ b/frontends/amiga/dt_picture.c
@@ -25,6 +25,7 @@
#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
#include <proto/datatypes.h>
#include <proto/dos.h>
#include <proto/intuition.h>
diff --git a/frontends/amiga/dt_sound.c b/frontends/amiga/dt_sound.c
index 8b63d6a..16b4f7c 100644
--- a/frontends/amiga/dt_sound.c
+++ b/frontends/amiga/dt_sound.c
@@ -23,6 +23,8 @@
#ifdef WITH_AMIGA_DATATYPES
#include "amiga/os3support.h"
+#include <string.h>
+
#include <proto/datatypes.h>
#include <proto/dos.h>
#include <proto/intuition.h>
diff --git a/frontends/amiga/file.c b/frontends/amiga/file.c
index 2fe7d66..79acb1a 100644
--- a/frontends/amiga/file.c
+++ b/frontends/amiga/file.c
@@ -22,6 +22,8 @@
#include <proto/icon.h>
#include <workbench/icon.h>
+#include <string.h>
+
#include "utils/utils.h"
#include "utils/nsoption.h"
#include "utils/file.h"
diff --git a/frontends/amiga/utf8.c b/frontends/amiga/utf8.c
index f16cbba..af5af12 100755
--- a/frontends/amiga/utf8.c
+++ b/frontends/amiga/utf8.c
@@ -36,21 +36,35 @@ static nserror ami_utf8_codesets(const char *string, size_t len, char **result,
{
char *out;
ULONG utf8_tag, local_tag;
+ static struct codeset *utf8_cs = NULL;
+ static struct codeset *local_cs = NULL;
+
+ if(local_cs == NULL) CodesetsFind(NULL,
+#ifdef __amigaos4__
+ CSA_MIBenum, nsoption_int(local_codeset),
+#else
+ NULL,
+#endif
+ TAG_DONE);
+
+ if(utf8_cs == NULL) CodesetsFind(NULL,
+ CSA_MIBenum, CS_MIBENUM_UTF_8,
+ TAG_DONE);
if(to_local == false) {
- local_tag = CSA_SourceMIBenum;
- utf8_tag = CSA_DestMIBenum;
+ local_tag = CSA_SourceCodeset;
+ utf8_tag = CSA_DestCodeset;
} else {
- utf8_tag = CSA_SourceMIBenum;
- local_tag = CSA_DestMIBenum;
+ utf8_tag = CSA_SourceCodeset;
+ local_tag = CSA_DestCodeset;
}
out = CodesetsConvertStr(CSA_Source, string,
CSA_SourceLen, len,
#ifdef __amigaos4__
- local_tag, nsoption_int(local_codeset),
+ local_tag, local_cs,
#endif
- utf8_tag, CS_MIBENUM_UTF_8,
+ utf8_tag, utf8_cs,
CSA_MapForeignChars, TRUE,
TAG_DONE);
--
NetSurf Browser
2 years, 11 months
netsurf-wiki: branch master updated. 81c0ac1383d17959403a6885700963c17d6dbb98
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf-wiki.git/shortlog/81c0ac1383d17959...
...commit http://git.netsurf-browser.org/netsurf-wiki.git/commit/81c0ac1383d1795940...
...tree http://git.netsurf-browser.org/netsurf-wiki.git/tree/81c0ac1383d17959403a...
The branch, master has been updated
via 81c0ac1383d17959403a6885700963c17d6dbb98 (commit)
from 3210b9c7ec8c92ef27e7cd1728b5cf8d3a8bee70 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf-wiki.git/commit/?id=81c0ac1383d179...
commit 81c0ac1383d17959403a6885700963c17d6dbb98
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
Octorber hack weekend: Add thougts on calc().
diff --git a/developer-weekend/oct-2020.mdwn b/developer-weekend/oct-2020.mdwn
index d4fef43..2ccab48 100644
--- a/developer-weekend/oct-2020.mdwn
+++ b/developer-weekend/oct-2020.mdwn
@@ -45,6 +45,42 @@ Vince
* Added support to LibSVGTiny for paths using arcs.
* Added a chart renderer to NetSurf.
+Notes
+=====
+
+Thoughts around `calc()`
+------------------------
+
+> Currently the `tlsa/calc` branch contains our work-to-date
+
+Remaining work
+
+> Thought:
+>
+> In theory we could make the calculation bytecode be stored as a lwc_string, which means we already have mechanisms for deduplication, identity checking, etc. in libcss.
+
+1. Maybe update generator to construct valid/invalid UNIT types for each property as a table for use later.
+ * This would involve repeating the validation expressions present in `LENGTH_UNIT:()` in `properties.gen` or perhaps reworking that bit too.
+ * This is probably an array, indexed by property, whose values are a bitfield of permitted unit types.
+2. Implementing the cascade
+ * Mostly in the common code.
+ * Should be able to type-check here (property-specific part).
+ * In theory type-check could happen in the parser, but once `var()` gets involved it'll have to be in the cascade, so we may as well put it here from the start.
+3. Reworking the computed style to have a calc section
+ * By this, we mean that the computed styles should have a representation which means "Use calculation N" in the current packed content, and then in the less compact struct we can have calculation bytecode for each unique calculation needed to support the style.
+ * Also consider how this impacts computed style internment / sharing.
+4. Rework API for computed styles to support client functions so that calc can run
+ * This is were we implement doing the calculation.
+ * May need care in the case of invalid results in calc
+ * May permit simplification of things like percentage units.
+ * Maybe the context structure should carry simple values like available width/height viewport width/height, etc. But have a callback for things like relative font sizes etc.
+ * Probably change so all widths emerge from libcss in px.
+5. Write selection tests involving `calc()`
+ * Will involve fixing `dump_computed.h` to the new API
+
+
+After all that, NetSurf needs updating to the new API, which should simplify the CSS client code in NetSurf quite a bit.
+
Next time
=========
-----------------------------------------------------------------------
Summary of changes:
developer-weekend/oct-2020.mdwn | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/developer-weekend/oct-2020.mdwn b/developer-weekend/oct-2020.mdwn
index d4fef43..2ccab48 100644
--- a/developer-weekend/oct-2020.mdwn
+++ b/developer-weekend/oct-2020.mdwn
@@ -45,6 +45,42 @@ Vince
* Added support to LibSVGTiny for paths using arcs.
* Added a chart renderer to NetSurf.
+Notes
+=====
+
+Thoughts around `calc()`
+------------------------
+
+> Currently the `tlsa/calc` branch contains our work-to-date
+
+Remaining work
+
+> Thought:
+>
+> In theory we could make the calculation bytecode be stored as a lwc_string, which means we already have mechanisms for deduplication, identity checking, etc. in libcss.
+
+1. Maybe update generator to construct valid/invalid UNIT types for each property as a table for use later.
+ * This would involve repeating the validation expressions present in `LENGTH_UNIT:()` in `properties.gen` or perhaps reworking that bit too.
+ * This is probably an array, indexed by property, whose values are a bitfield of permitted unit types.
+2. Implementing the cascade
+ * Mostly in the common code.
+ * Should be able to type-check here (property-specific part).
+ * In theory type-check could happen in the parser, but once `var()` gets involved it'll have to be in the cascade, so we may as well put it here from the start.
+3. Reworking the computed style to have a calc section
+ * By this, we mean that the computed styles should have a representation which means "Use calculation N" in the current packed content, and then in the less compact struct we can have calculation bytecode for each unique calculation needed to support the style.
+ * Also consider how this impacts computed style internment / sharing.
+4. Rework API for computed styles to support client functions so that calc can run
+ * This is were we implement doing the calculation.
+ * May need care in the case of invalid results in calc
+ * May permit simplification of things like percentage units.
+ * Maybe the context structure should carry simple values like available width/height viewport width/height, etc. But have a callback for things like relative font sizes etc.
+ * Probably change so all widths emerge from libcss in px.
+5. Write selection tests involving `calc()`
+ * Will involve fixing `dump_computed.h` to the new API
+
+
+After all that, NetSurf needs updating to the new API, which should simplify the CSS client code in NetSurf quite a bit.
+
Next time
=========
--
NetSurf Developer Wiki Backing Store
2 years, 11 months
netsurf-wiki: branch master updated. 3210b9c7ec8c92ef27e7cd1728b5cf8d3a8bee70
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf-wiki.git/shortlog/3210b9c7ec8c92ef...
...commit http://git.netsurf-browser.org/netsurf-wiki.git/commit/3210b9c7ec8c92ef27...
...tree http://git.netsurf-browser.org/netsurf-wiki.git/tree/3210b9c7ec8c92ef27e7...
The branch, master has been updated
via 3210b9c7ec8c92ef27e7cd1728b5cf8d3a8bee70 (commit)
from cc5abbb2532b4f1bebb8ca05ec74caae75401871 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf-wiki.git/commit/?id=3210b9c7ec8c92...
commit 3210b9c7ec8c92ef27e7cd1728b5cf8d3a8bee70
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
Add October hack weekend report.
diff --git a/developer-weekend/oct-2020.mdwn b/developer-weekend/oct-2020.mdwn
new file mode 100644
index 0000000..d4fef43
--- /dev/null
+++ b/developer-weekend/oct-2020.mdwn
@@ -0,0 +1,51 @@
+[[!meta title="Developer Weekend (Oct 2020)"]]
+[[!meta author="NetSurf Developers"]]
+[[!meta date="2020-10-22 09:00:00"]]
+
+[[!toc]]
+
+Attendees
+=========
+
+* Michael Drake
+* Vincent Sanders
+* Daniel Silverstone
+
+Outstanding work (from May)
+===========================
+
+* General
+ - Forms cleanup.
+* Text layout
+ - Continue implementing.
+
+Still outstanding after October developer weekend.
+
+Activity
+========
+
+Mostly individual activity here
+
+Michael
+-------
+
+* Worked with Daniel on CSS `calc()` support in LibCSS.
+
+Daniel
+------
+
+* Worked with Michael on CSS `calc()` support in LibCSS.
+* Fixed GTK path plotter translation table. (Fixes svgtiny rendering offset.)
+* Fixed LibDOM fuzz testing issue.
+* Fixed various crashes from the long internet tests.
+
+Vince
+-----
+
+* Added support to LibSVGTiny for paths using arcs.
+* Added a chart renderer to NetSurf.
+
+Next time
+=========
+
+* Undecided.
-----------------------------------------------------------------------
Summary of changes:
developer-weekend/oct-2020.mdwn | 51 +++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 developer-weekend/oct-2020.mdwn
diff --git a/developer-weekend/oct-2020.mdwn b/developer-weekend/oct-2020.mdwn
new file mode 100644
index 0000000..d4fef43
--- /dev/null
+++ b/developer-weekend/oct-2020.mdwn
@@ -0,0 +1,51 @@
+[[!meta title="Developer Weekend (Oct 2020)"]]
+[[!meta author="NetSurf Developers"]]
+[[!meta date="2020-10-22 09:00:00"]]
+
+[[!toc]]
+
+Attendees
+=========
+
+* Michael Drake
+* Vincent Sanders
+* Daniel Silverstone
+
+Outstanding work (from May)
+===========================
+
+* General
+ - Forms cleanup.
+* Text layout
+ - Continue implementing.
+
+Still outstanding after October developer weekend.
+
+Activity
+========
+
+Mostly individual activity here
+
+Michael
+-------
+
+* Worked with Daniel on CSS `calc()` support in LibCSS.
+
+Daniel
+------
+
+* Worked with Michael on CSS `calc()` support in LibCSS.
+* Fixed GTK path plotter translation table. (Fixes svgtiny rendering offset.)
+* Fixed LibDOM fuzz testing issue.
+* Fixed various crashes from the long internet tests.
+
+Vince
+-----
+
+* Added support to LibSVGTiny for paths using arcs.
+* Added a chart renderer to NetSurf.
+
+Next time
+=========
+
+* Undecided.
--
NetSurf Developer Wiki Backing Store
2 years, 11 months
netsurf: branch master updated. release/3.10-73-g06c721c
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/06c721c5bb6cd06fc35bd...
...commit http://git.netsurf-browser.org/netsurf.git/commit/06c721c5bb6cd06fc35bd0a...
...tree http://git.netsurf-browser.org/netsurf.git/tree/06c721c5bb6cd06fc35bd0a36...
The branch, master has been updated
via 06c721c5bb6cd06fc35bd0a36a98415758501df8 (commit)
from 32d52bf055dabb33e777a9ffa5ef918c4916adb9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=06c721c5bb6cd06fc35...
commit 06c721c5bb6cd06fc35bd0a36a98415758501df8
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
add simple chart generator and use it from the imagecache
diff --git a/content/fetchers/about/Makefile b/content/fetchers/about/Makefile
index 10c9a6a..4f12a06 100644
--- a/content/fetchers/about/Makefile
+++ b/content/fetchers/about/Makefile
@@ -4,6 +4,7 @@ S_FETCHER_ABOUT := \
about.c \
blank.c \
certificate.c \
+ chart.c \
choices.c \
config.c \
imagecache.c \
diff --git a/content/fetchers/about/about.c b/content/fetchers/about/about.c
index fe9eba7..6518942 100644
--- a/content/fetchers/about/about.c
+++ b/content/fetchers/about/about.c
@@ -49,6 +49,7 @@
#include "blank.h"
#include "certificate.h"
#include "config.h"
+#include "chart.h"
#include "choices.h"
#include "imagecache.h"
#include "nscolours.h"
@@ -442,6 +443,14 @@ struct about_handlers about_handler_list[] = {
true
},
{
+ /* chart generator */
+ "chart",
+ SLEN("chart"),
+ NULL,
+ fetch_about_chart_handler,
+ true
+ },
+ {
"query/auth",
SLEN("query/auth"),
NULL,
diff --git a/content/fetchers/about/chart.c b/content/fetchers/about/chart.c
new file mode 100644
index 0000000..1565c54
--- /dev/null
+++ b/content/fetchers/about/chart.c
@@ -0,0 +1,628 @@
+/*
+ * Copyright 2020 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf.
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * content generator for the about scheme chart page
+ *
+ * A chart consists of the figure area in which a chart a title and a
+ * key are placed.
+ *
+ *
+ */
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "netsurf/inttypes.h"
+#include "utils/utils.h"
+#include "utils/errors.h"
+#include "utils/nsurl.h"
+
+#include "private.h"
+#include "chart.h"
+
+/** minimum figure dimension */
+#define FIGURE_MIN_WIDTH 150
+#define FIGURE_MIN_HEIGHT 100
+
+enum chart_type {
+ CHART_TYPE_UNKNOWN,
+ CHART_TYPE_PIE,
+};
+
+/* type of chart key */
+enum key_type {
+ CHART_KEY_UNSET,
+ CHART_KEY_NONE,
+ CHART_KEY_LEFT,
+ CHART_KEY_RIGHT,
+ CHART_KEY_TOP,
+ CHART_KEY_BOT,
+ CHART_KEY_END
+};
+
+
+struct chart_label {
+ char *title; /* label title */
+ unsigned int colour; /* colour */
+};
+
+struct chart_series {
+ unsigned int len; /* number of values in the series */
+ float *value; /* array of values */
+};
+
+#define MAX_SERIES 4
+
+struct chart_data {
+ unsigned int series_len;
+ struct chart_series series[MAX_SERIES];
+
+ unsigned int label_len; /* number of labels */
+ struct chart_label *label;
+
+};
+
+/**
+ * parameters for a chart figure
+ */
+struct chart_param {
+ enum chart_type type;
+ enum key_type key; /* what type of key to use */
+ unsigned int width; /* width of figure */
+ unsigned int height; /* height of figure */
+ char *title; /* title */
+ struct {
+ unsigned int x;
+ unsigned int y;
+ unsigned int width;
+ unsigned int height;
+ } area; /* chart area within figure */
+ struct chart_data data;
+};
+
+#define DEF_COLOUR_NUM 8
+/** default colour series */
+static unsigned int colour_series[DEF_COLOUR_NUM] =
+ {
+ 0x00ff00, /* green */
+ 0x0000ff, /* blue */
+ 0xff0000, /* red */
+ 0xffff00, /* yellow */
+ 0x00ffff, /* cyan */
+ 0xff00ff, /* pink */
+ 0x777777, /* grey */
+ 0x000000, /* black */
+ };
+
+
+/* ensures there are labels present for every value */
+static nserror ensure_label_count(struct chart_param *chart, unsigned int count)
+{
+ unsigned int lidx;
+ int deltac;
+ struct chart_label *nlabels;
+
+ deltac = count - chart->data.label_len;
+ if (deltac <= 0) {
+ /* there are enough labels */
+ return NSERROR_OK;
+ }
+
+ nlabels = realloc(chart->data.label,
+ count * sizeof(struct chart_label));
+ if (nlabels == NULL) {
+ return NSERROR_NOMEM;
+ }
+ chart->data.label = nlabels;
+
+ for (lidx = chart->data.label_len; lidx < count; lidx++) {
+ chart->data.label[lidx].title = calloc(1, 20);
+ snprintf(chart->data.label[lidx].title, 19, "item %d", lidx + 1);
+ chart->data.label[lidx].colour = colour_series[lidx % DEF_COLOUR_NUM];
+ }
+
+ chart->data.label_len = count;
+
+ return NSERROR_OK;
+}
+
+/**
+ * extract values for a series
+ */
+static nserror
+extract_series_values(struct chart_param *chart,
+ unsigned int series_num,
+ const char *valstr,
+ size_t valstrlen)
+{
+ nserror res;
+ unsigned int valcur;
+ size_t valstart;/* value start in valstr */
+ size_t vallen; /* value end in valstr */
+ struct chart_series *series;
+
+ series = chart->data.series + series_num;
+
+ /* ensure we do not leak any data in this series */
+ if (series->value != NULL) {
+ free(series->value);
+ }
+
+ /* count how many values present */
+ for (series->len = 1, valstart=0; valstart < valstrlen; valstart++) {
+ if (valstr[valstart] == ',') {
+ series->len++;
+ }
+ }
+
+ /* allocate storage for values */
+ series->value = calloc(series->len, sizeof(float));
+ if (series->value == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ /* extract values from query string */
+ for (valcur = 0, vallen = 0, valstart = 0;
+ (valstart < valstrlen) && (valcur < series->len);
+ valstart += vallen, valcur++) {
+ /* get query section length */
+ vallen = 0;
+ while (((valstart + vallen) < valstrlen) &&
+ (valstr[valstart + vallen] != ',')) {
+ vallen++;
+ }
+
+ series->value[valcur] = strtof(valstr + valstart, NULL);
+ vallen++; /* account for , separator */
+ }
+
+ res = ensure_label_count(chart, series->len);
+
+ return res;
+}
+
+
+/**
+ * extract values for next series
+ */
+static nserror
+extract_next_series_values(struct chart_param *chart,
+ const char *valstr,
+ size_t valstrlen)
+{
+ nserror res;
+
+ if (chart->data.series_len >= MAX_SERIES) {
+ return NSERROR_NOSPACE;
+ }
+
+ res = extract_series_values(chart,
+ chart->data.series_len,
+ valstr,
+ valstrlen);
+ if (res == NSERROR_OK) {
+ chart->data.series_len++;
+ }
+
+ return res;
+}
+
+
+/**
+ * extract label title
+ */
+static nserror
+extract_series_labels(struct chart_param *chart,
+ const char *valstr,
+ size_t valstrlen)
+{
+ nserror res;
+ unsigned int valcount; /* count of values in valstr */
+ unsigned int valcur;
+ size_t valstart;/* value start in valstr */
+ size_t vallen; /* value end in valstr */
+
+ for (valcount = 1, valstart=0; valstart < valstrlen; valstart++) {
+ if (valstr[valstart] == ',') {
+ valcount++;
+ }
+ }
+
+ res = ensure_label_count(chart, valcount);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+
+ for (valcur = 0, vallen = 0, valstart = 0;
+ (valstart < valstrlen) && (valcur < chart->data.label_len);
+ valstart += vallen, valcur++) {
+ /* get query section length */
+ vallen = 0;
+ while (((valstart + vallen) < valstrlen) &&
+ (valstr[valstart + vallen] != ',')) {
+ vallen++;
+ }
+
+ chart->data.label[valcur].title = strndup(valstr + valstart, vallen);
+ vallen++; /* account for , separator */
+ }
+ return NSERROR_OK;
+}
+
+
+/**
+ * extract labels colour
+ */
+static nserror
+extract_series_colours(struct chart_param *chart,
+ const char *valstr,
+ size_t valstrlen)
+{
+ return NSERROR_OK;
+}
+
+/**
+ * process a part of a query
+ */
+static nserror
+process_query_section(const char *str, size_t len, struct chart_param *chart)
+{
+ nserror res = NSERROR_OK;
+
+ if ((len > 6) &&
+ (strncmp(str, "width=", 6) == 0)) {
+ /* figure width */
+ chart->width = strtoul(str + 6, NULL, 10);
+ } else if ((len > 7) &&
+ (strncmp(str, "height=", 7) == 0)) {
+ /* figure height */
+ chart->height = strtoul(str + 7, NULL, 10);
+ } else if ((len > 8) &&
+ (strncmp(str, "cawidth=", 8) == 0)) {
+ /* chart area width */
+ chart->area.width = strtoul(str + 8, NULL, 10);
+ } else if ((len > 9) &&
+ (strncmp(str, "caheight=", 9) == 0)) {
+ /* chart area height */
+ chart->area.height = strtoul(str + 9, NULL, 10);
+ } else if ((len > 4) &&
+ (strncmp(str, "key=", 4) == 0)) {
+ /* figure has key */
+ chart->key = strtoul(str + 4, NULL, 10);
+ } else if ((len > 6) &&
+ (strncmp(str, "title=", 6) == 0)) {
+ chart->title = strndup(str + 6, len - 6);
+ } else if ((len > 5) &&
+ (strncmp(str, "type=", 5) == 0)) {
+ if (strncmp(str + 5, "pie", len - 5) == 0) {
+ chart->type = CHART_TYPE_PIE;
+ } else {
+ chart->type = CHART_TYPE_UNKNOWN;
+ }
+ } else if ((len > 7) &&
+ (strncmp(str, "values=", 7) == 0)) {
+ res = extract_next_series_values(chart, str + 7, len - 7);
+ } else if ((len > 7) &&
+ (strncmp(str, "labels=", 7) == 0)) {
+ res = extract_series_labels(chart, str + 7, len - 7);
+ } else if ((len > 8) &&
+ (strncmp(str, "colours=", 8) == 0)) {
+ res = extract_series_colours(chart, str + 8, len - 8);
+ }
+
+ return res;
+}
+
+
+
+static nserror
+chart_from_query(struct nsurl *url, struct chart_param *chart)
+{
+ nserror res;
+ char *querystr;
+ size_t querylen;
+ size_t kvstart;/* key value start */
+ size_t kvlen; /* key value end */
+
+ res = nsurl_get(url, NSURL_QUERY, &querystr, &querylen);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+ for (kvlen = 0, kvstart = 0; kvstart < querylen; kvstart += kvlen) {
+ /* get query section length */
+ kvlen = 0;
+ while (((kvstart + kvlen) < querylen) &&
+ (querystr[kvstart + kvlen] != '&')) {
+ kvlen++;
+ }
+
+ res = process_query_section(querystr + kvstart, kvlen, chart);
+ if (res != NSERROR_OK) {
+ break;
+ }
+ kvlen++; /* account for & separator */
+ }
+ free(querystr);
+
+ /* sanity check dimensions */
+ if (chart->width < FIGURE_MIN_WIDTH) {
+ /* bad width - check height */
+ if (chart->height < FIGURE_MIN_HEIGHT) {
+ /* both bad set to defaults */
+ chart->width = FIGURE_MIN_WIDTH;
+ chart->height = FIGURE_MIN_HEIGHT;
+ } else {
+ /* base width on valid height */
+ chart->width = (chart->height * 3) / 2;
+ }
+ } else {
+ /* good width check height */
+ if (chart->height < FIGURE_MIN_HEIGHT) {
+ /* base height on valid width */
+ chart->height = (chart->width * 2) / 3;
+ }
+ }
+
+ /* ensure legend type correct */
+ if ((chart->key == CHART_KEY_UNSET) ||
+ (chart->key >= CHART_KEY_END )) {
+ /* default to putting key on right */
+ chart->key = CHART_KEY_RIGHT;
+ }
+
+ return NSERROR_OK;
+}
+
+
+static nserror
+output_pie_legend(struct fetch_about_context *ctx, struct chart_param *chart)
+{
+ nserror res;
+ unsigned int lblidx;
+ unsigned int legend_width;
+ unsigned int legend_height;
+ unsigned int vertical_spacing;
+
+ switch (chart->key) {
+
+ case CHART_KEY_NONE:
+ break;
+ case CHART_KEY_RIGHT:
+ legend_width = chart->width - chart->area.width - chart->area.x;
+ legend_width -= 10; /* margin */
+ legend_height = chart->height;
+ vertical_spacing = legend_height / (chart->data.label_len + 1);
+
+ for(lblidx = 0; lblidx < chart->data.label_len ; lblidx++) {
+ res = fetch_about_ssenddataf(ctx,
+ "<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"#%06x\" />",
+ chart->width - legend_width,
+ (vertical_spacing * lblidx) + (vertical_spacing/2),
+ vertical_spacing * 2 / 3,
+ vertical_spacing * 2 / 3,
+ chart->data.label[lblidx].colour);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+ res = fetch_about_ssenddataf(ctx,
+ "<text x=\"%d\" y=\"%d\" fill=\"#%06x\" >%s</text>",
+ chart->width - legend_width + vertical_spacing,
+ vertical_spacing * (lblidx+1),
+ chart->data.label[lblidx].colour,
+ chart->data.label[lblidx].title);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ return NSERROR_OK;
+}
+
+static float
+compute_series_total(struct chart_param *chart, unsigned int series)
+{
+ float total;
+ unsigned int curdata;
+
+ for (total = 0, curdata = 0;
+ curdata < chart->data.series[series].len;
+ curdata++) {
+ total += chart->data.series[series].value[curdata];
+ }
+ return total;
+}
+
+/**
+ * render the data as a pie chart svg
+ */
+static bool
+pie_chart(struct fetch_about_context *ctx, struct chart_param *chart)
+{
+ nserror res;
+ float ra; /* pie a radius */
+ float rb; /* pie b radius */
+ float series_total;
+ unsigned int curdata; /* current data point index */
+ float last_x, last_y;
+ float end_x, end_y;
+ float start;
+ float extent;
+ bool large;
+ float circle_centre_x, circle_centre_y;
+
+ /* ensure there is data to render */
+ if ((chart->data.series_len < 1) || (chart->data.series[0].len < 2)) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /* get the first series total value */
+ series_total = compute_series_total(chart, 0);
+ if (series_total == 0) {
+ /* dividing by zero is embarasing */
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /*
+ * need to ensure the chart area is setup correctly
+ *
+ * this is left to each chart type as different charts
+ * have differnt requirements
+ */
+ if ((chart->area.width == 0) || (chart->area.height == 0)) {
+ /*
+ * pie chart defaults to square of smaller of figure
+ * width and height
+ */
+ if (chart->width > chart->height) {
+ chart->area.width = chart->area.height = (chart->height - chart->area.x);
+ } else {
+ chart->area.width = chart->area.height = (chart->width - chart->area.y);
+ }
+ }
+
+ /* content is going to return ok */
+ fetch_about_set_http_code(ctx, 200);
+
+ /* content type */
+ if (fetch_about_send_header(ctx,
+ "Content-Type: image/svg; charset=utf-8")) {
+ goto aborted;
+ }
+
+ /* get the pie charts elipse radii */
+ ra = chart->area.width / 2;
+ rb = chart->area.height / 2;
+
+ /* get the offset to the circle centre */
+ circle_centre_x = chart->area.x + ra;
+ circle_centre_y = chart->area.y + rb;
+
+
+ /* svg header */
+ res = fetch_about_ssenddataf(ctx,
+ "<svg width=\"%u\" height=\"%u\" "
+ "xmlns=\"http://www.w3.org/2000/svg\">\n",
+ chart->width, chart->height);
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+
+ /* generate the legend */
+ res = output_pie_legend(ctx, chart);
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+
+ /* plot the arcs */
+ start = -M_PI_2;
+ last_x = (ra * cos(start));
+ last_y = (rb * sin(start));
+
+ /* iterate over each data point creating a slice o pie */
+ for (curdata=0; curdata < chart->data.series[0].len; curdata++) {
+ extent = ((chart->data.series[0].value[curdata] / series_total) * 2 * M_PI);
+ end_x = (ra * cos(start + extent));
+ end_y = (rb * sin(start + extent));
+
+ if (extent > M_PI) {
+ large = true;
+ } else {
+ large = false;
+ }
+
+ res = fetch_about_ssenddataf(
+ ctx,
+ "<path d=\"M %g %g\n"
+ "A %g %g 0 %d 1 %g %g\n"
+ "L %g %g Z\" fill=\"#%06x\" />\n",
+ circle_centre_x + last_x,
+ circle_centre_y + last_y,
+ ra, rb, large?1:0,
+ circle_centre_x + end_x,
+ circle_centre_y + end_y,
+ circle_centre_x,
+ circle_centre_y,
+ chart->data.label[curdata].colour);
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+ last_x = end_x;
+ last_y = end_y;
+ start +=extent;
+ }
+
+ res = fetch_about_ssenddataf(ctx, "</svg>\n");
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+
+ fetch_about_send_finished(ctx);
+
+ return true;
+
+ aborted:
+
+ return false;
+
+}
+
+/**
+ * Handler to generate about scheme chart page.
+ *
+ * generates an svg chart
+ *
+ * \param ctx The fetcher context.
+ * \return true if handled false if aborted.
+ */
+bool fetch_about_chart_handler(struct fetch_about_context *ctx)
+{
+ nserror res;
+ struct chart_param chart;
+ memset(&chart, 0, sizeof(struct chart_param));
+
+ res = chart_from_query(fetch_about_get_url(ctx), &chart);
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+
+ switch (chart.type) {
+ case CHART_TYPE_PIE:
+ return pie_chart(ctx, &chart);
+
+
+ default:
+ break;
+ }
+
+aborted:
+
+ return false;
+
+}
diff --git a/content/fetchers/about/chart.h b/content/fetchers/about/chart.h
new file mode 100644
index 0000000..4eb7e78
--- /dev/null
+++ b/content/fetchers/about/chart.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2020 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf.
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * about scheme chart handler interface
+ */
+
+#ifndef NETSURF_CONTENT_FETCHERS_ABOUT_CHART_H
+#define NETSURF_CONTENT_FETCHERS_ABOUT_CHART_H
+
+/**
+ * Handler to generate about scheme chart page.
+ *
+ * generates an svg chart
+ *
+ * \param ctx The fetcher context.
+ * \return true if handled false if aborted.
+ */
+bool fetch_about_chart_handler(struct fetch_about_context *ctx);
+
+#endif
diff --git a/content/fetchers/about/imagecache.c b/content/fetchers/about/imagecache.c
index 5e2abcb..23d3ef4 100644
--- a/content/fetchers/about/imagecache.c
+++ b/content/fetchers/about/imagecache.c
@@ -70,9 +70,23 @@ bool fetch_about_imagecache_handler(struct fetch_about_context *ctx)
"<p>Peak size %f (in %g)</p>\n"
"<p>Peak image count %h (size %i)</p>\n"
"<p>Cache total/hit/miss/fail (counts) %j/%k/%l/%m "
- "(%pj%%/%pk%%/%pl%%/%pm%%)</p>\n"
+ "(%pj%%/%pk%%/%pl%%/%pm%%)"
+ "<img width=200 height=100 src=\"about:chart?type=pie&width=200&height=100&labels=hit,miss,fail&values=%k,%l,%m\" />"
+ "</p>\n");
+ if (slen >= (int) (sizeof(buffer))) {
+ goto fetch_about_imagecache_handler_aborted; /* overflow */
+ }
+
+ res = fetch_about_senddata(ctx, (const uint8_t *)buffer, slen);
+ if (res != NSERROR_OK) {
+ goto fetch_about_imagecache_handler_aborted;
+ }
+
+ /* image cache summary */
+ slen = image_cache_snsummaryf(buffer, sizeof(buffer),
"<p>Cache total/hit/miss/fail (size) %n/%o/%q/%r "
- "(%pn%%/%po%%/%pq%%/%pr%%)</p>\n"
+ "(%pn%%/%po%%/%pq%%/%pr%%)"
+ "<img width=200 height=100 src=\"about:chart?type=pie&width=200&height=100&labels=hit,miss,fail&values=%o,%q,%r\" /></p>\n"
"<p>Total images never rendered: %s "
"(includes %t that were converted)</p>\n"
"<p>Total number of excessive conversions: %u "
-----------------------------------------------------------------------
Summary of changes:
content/fetchers/about/Makefile | 1 +
content/fetchers/about/about.c | 9 +
content/fetchers/about/chart.c | 628 +++++++++++++++++++++++++++
content/fetchers/about/{blank.h => chart.h} | 12 +-
content/fetchers/about/imagecache.c | 18 +-
5 files changed, 661 insertions(+), 7 deletions(-)
create mode 100644 content/fetchers/about/chart.c
copy content/fetchers/about/{blank.h => chart.h} (74%)
diff --git a/content/fetchers/about/Makefile b/content/fetchers/about/Makefile
index 10c9a6a..4f12a06 100644
--- a/content/fetchers/about/Makefile
+++ b/content/fetchers/about/Makefile
@@ -4,6 +4,7 @@ S_FETCHER_ABOUT := \
about.c \
blank.c \
certificate.c \
+ chart.c \
choices.c \
config.c \
imagecache.c \
diff --git a/content/fetchers/about/about.c b/content/fetchers/about/about.c
index fe9eba7..6518942 100644
--- a/content/fetchers/about/about.c
+++ b/content/fetchers/about/about.c
@@ -49,6 +49,7 @@
#include "blank.h"
#include "certificate.h"
#include "config.h"
+#include "chart.h"
#include "choices.h"
#include "imagecache.h"
#include "nscolours.h"
@@ -442,6 +443,14 @@ struct about_handlers about_handler_list[] = {
true
},
{
+ /* chart generator */
+ "chart",
+ SLEN("chart"),
+ NULL,
+ fetch_about_chart_handler,
+ true
+ },
+ {
"query/auth",
SLEN("query/auth"),
NULL,
diff --git a/content/fetchers/about/chart.c b/content/fetchers/about/chart.c
new file mode 100644
index 0000000..1565c54
--- /dev/null
+++ b/content/fetchers/about/chart.c
@@ -0,0 +1,628 @@
+/*
+ * Copyright 2020 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf.
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * content generator for the about scheme chart page
+ *
+ * A chart consists of the figure area in which a chart a title and a
+ * key are placed.
+ *
+ *
+ */
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "netsurf/inttypes.h"
+#include "utils/utils.h"
+#include "utils/errors.h"
+#include "utils/nsurl.h"
+
+#include "private.h"
+#include "chart.h"
+
+/** minimum figure dimension */
+#define FIGURE_MIN_WIDTH 150
+#define FIGURE_MIN_HEIGHT 100
+
+enum chart_type {
+ CHART_TYPE_UNKNOWN,
+ CHART_TYPE_PIE,
+};
+
+/* type of chart key */
+enum key_type {
+ CHART_KEY_UNSET,
+ CHART_KEY_NONE,
+ CHART_KEY_LEFT,
+ CHART_KEY_RIGHT,
+ CHART_KEY_TOP,
+ CHART_KEY_BOT,
+ CHART_KEY_END
+};
+
+
+struct chart_label {
+ char *title; /* label title */
+ unsigned int colour; /* colour */
+};
+
+struct chart_series {
+ unsigned int len; /* number of values in the series */
+ float *value; /* array of values */
+};
+
+#define MAX_SERIES 4
+
+struct chart_data {
+ unsigned int series_len;
+ struct chart_series series[MAX_SERIES];
+
+ unsigned int label_len; /* number of labels */
+ struct chart_label *label;
+
+};
+
+/**
+ * parameters for a chart figure
+ */
+struct chart_param {
+ enum chart_type type;
+ enum key_type key; /* what type of key to use */
+ unsigned int width; /* width of figure */
+ unsigned int height; /* height of figure */
+ char *title; /* title */
+ struct {
+ unsigned int x;
+ unsigned int y;
+ unsigned int width;
+ unsigned int height;
+ } area; /* chart area within figure */
+ struct chart_data data;
+};
+
+#define DEF_COLOUR_NUM 8
+/** default colour series */
+static unsigned int colour_series[DEF_COLOUR_NUM] =
+ {
+ 0x00ff00, /* green */
+ 0x0000ff, /* blue */
+ 0xff0000, /* red */
+ 0xffff00, /* yellow */
+ 0x00ffff, /* cyan */
+ 0xff00ff, /* pink */
+ 0x777777, /* grey */
+ 0x000000, /* black */
+ };
+
+
+/* ensures there are labels present for every value */
+static nserror ensure_label_count(struct chart_param *chart, unsigned int count)
+{
+ unsigned int lidx;
+ int deltac;
+ struct chart_label *nlabels;
+
+ deltac = count - chart->data.label_len;
+ if (deltac <= 0) {
+ /* there are enough labels */
+ return NSERROR_OK;
+ }
+
+ nlabels = realloc(chart->data.label,
+ count * sizeof(struct chart_label));
+ if (nlabels == NULL) {
+ return NSERROR_NOMEM;
+ }
+ chart->data.label = nlabels;
+
+ for (lidx = chart->data.label_len; lidx < count; lidx++) {
+ chart->data.label[lidx].title = calloc(1, 20);
+ snprintf(chart->data.label[lidx].title, 19, "item %d", lidx + 1);
+ chart->data.label[lidx].colour = colour_series[lidx % DEF_COLOUR_NUM];
+ }
+
+ chart->data.label_len = count;
+
+ return NSERROR_OK;
+}
+
+/**
+ * extract values for a series
+ */
+static nserror
+extract_series_values(struct chart_param *chart,
+ unsigned int series_num,
+ const char *valstr,
+ size_t valstrlen)
+{
+ nserror res;
+ unsigned int valcur;
+ size_t valstart;/* value start in valstr */
+ size_t vallen; /* value end in valstr */
+ struct chart_series *series;
+
+ series = chart->data.series + series_num;
+
+ /* ensure we do not leak any data in this series */
+ if (series->value != NULL) {
+ free(series->value);
+ }
+
+ /* count how many values present */
+ for (series->len = 1, valstart=0; valstart < valstrlen; valstart++) {
+ if (valstr[valstart] == ',') {
+ series->len++;
+ }
+ }
+
+ /* allocate storage for values */
+ series->value = calloc(series->len, sizeof(float));
+ if (series->value == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ /* extract values from query string */
+ for (valcur = 0, vallen = 0, valstart = 0;
+ (valstart < valstrlen) && (valcur < series->len);
+ valstart += vallen, valcur++) {
+ /* get query section length */
+ vallen = 0;
+ while (((valstart + vallen) < valstrlen) &&
+ (valstr[valstart + vallen] != ',')) {
+ vallen++;
+ }
+
+ series->value[valcur] = strtof(valstr + valstart, NULL);
+ vallen++; /* account for , separator */
+ }
+
+ res = ensure_label_count(chart, series->len);
+
+ return res;
+}
+
+
+/**
+ * extract values for next series
+ */
+static nserror
+extract_next_series_values(struct chart_param *chart,
+ const char *valstr,
+ size_t valstrlen)
+{
+ nserror res;
+
+ if (chart->data.series_len >= MAX_SERIES) {
+ return NSERROR_NOSPACE;
+ }
+
+ res = extract_series_values(chart,
+ chart->data.series_len,
+ valstr,
+ valstrlen);
+ if (res == NSERROR_OK) {
+ chart->data.series_len++;
+ }
+
+ return res;
+}
+
+
+/**
+ * extract label title
+ */
+static nserror
+extract_series_labels(struct chart_param *chart,
+ const char *valstr,
+ size_t valstrlen)
+{
+ nserror res;
+ unsigned int valcount; /* count of values in valstr */
+ unsigned int valcur;
+ size_t valstart;/* value start in valstr */
+ size_t vallen; /* value end in valstr */
+
+ for (valcount = 1, valstart=0; valstart < valstrlen; valstart++) {
+ if (valstr[valstart] == ',') {
+ valcount++;
+ }
+ }
+
+ res = ensure_label_count(chart, valcount);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+
+ for (valcur = 0, vallen = 0, valstart = 0;
+ (valstart < valstrlen) && (valcur < chart->data.label_len);
+ valstart += vallen, valcur++) {
+ /* get query section length */
+ vallen = 0;
+ while (((valstart + vallen) < valstrlen) &&
+ (valstr[valstart + vallen] != ',')) {
+ vallen++;
+ }
+
+ chart->data.label[valcur].title = strndup(valstr + valstart, vallen);
+ vallen++; /* account for , separator */
+ }
+ return NSERROR_OK;
+}
+
+
+/**
+ * extract labels colour
+ */
+static nserror
+extract_series_colours(struct chart_param *chart,
+ const char *valstr,
+ size_t valstrlen)
+{
+ return NSERROR_OK;
+}
+
+/**
+ * process a part of a query
+ */
+static nserror
+process_query_section(const char *str, size_t len, struct chart_param *chart)
+{
+ nserror res = NSERROR_OK;
+
+ if ((len > 6) &&
+ (strncmp(str, "width=", 6) == 0)) {
+ /* figure width */
+ chart->width = strtoul(str + 6, NULL, 10);
+ } else if ((len > 7) &&
+ (strncmp(str, "height=", 7) == 0)) {
+ /* figure height */
+ chart->height = strtoul(str + 7, NULL, 10);
+ } else if ((len > 8) &&
+ (strncmp(str, "cawidth=", 8) == 0)) {
+ /* chart area width */
+ chart->area.width = strtoul(str + 8, NULL, 10);
+ } else if ((len > 9) &&
+ (strncmp(str, "caheight=", 9) == 0)) {
+ /* chart area height */
+ chart->area.height = strtoul(str + 9, NULL, 10);
+ } else if ((len > 4) &&
+ (strncmp(str, "key=", 4) == 0)) {
+ /* figure has key */
+ chart->key = strtoul(str + 4, NULL, 10);
+ } else if ((len > 6) &&
+ (strncmp(str, "title=", 6) == 0)) {
+ chart->title = strndup(str + 6, len - 6);
+ } else if ((len > 5) &&
+ (strncmp(str, "type=", 5) == 0)) {
+ if (strncmp(str + 5, "pie", len - 5) == 0) {
+ chart->type = CHART_TYPE_PIE;
+ } else {
+ chart->type = CHART_TYPE_UNKNOWN;
+ }
+ } else if ((len > 7) &&
+ (strncmp(str, "values=", 7) == 0)) {
+ res = extract_next_series_values(chart, str + 7, len - 7);
+ } else if ((len > 7) &&
+ (strncmp(str, "labels=", 7) == 0)) {
+ res = extract_series_labels(chart, str + 7, len - 7);
+ } else if ((len > 8) &&
+ (strncmp(str, "colours=", 8) == 0)) {
+ res = extract_series_colours(chart, str + 8, len - 8);
+ }
+
+ return res;
+}
+
+
+
+static nserror
+chart_from_query(struct nsurl *url, struct chart_param *chart)
+{
+ nserror res;
+ char *querystr;
+ size_t querylen;
+ size_t kvstart;/* key value start */
+ size_t kvlen; /* key value end */
+
+ res = nsurl_get(url, NSURL_QUERY, &querystr, &querylen);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+ for (kvlen = 0, kvstart = 0; kvstart < querylen; kvstart += kvlen) {
+ /* get query section length */
+ kvlen = 0;
+ while (((kvstart + kvlen) < querylen) &&
+ (querystr[kvstart + kvlen] != '&')) {
+ kvlen++;
+ }
+
+ res = process_query_section(querystr + kvstart, kvlen, chart);
+ if (res != NSERROR_OK) {
+ break;
+ }
+ kvlen++; /* account for & separator */
+ }
+ free(querystr);
+
+ /* sanity check dimensions */
+ if (chart->width < FIGURE_MIN_WIDTH) {
+ /* bad width - check height */
+ if (chart->height < FIGURE_MIN_HEIGHT) {
+ /* both bad set to defaults */
+ chart->width = FIGURE_MIN_WIDTH;
+ chart->height = FIGURE_MIN_HEIGHT;
+ } else {
+ /* base width on valid height */
+ chart->width = (chart->height * 3) / 2;
+ }
+ } else {
+ /* good width check height */
+ if (chart->height < FIGURE_MIN_HEIGHT) {
+ /* base height on valid width */
+ chart->height = (chart->width * 2) / 3;
+ }
+ }
+
+ /* ensure legend type correct */
+ if ((chart->key == CHART_KEY_UNSET) ||
+ (chart->key >= CHART_KEY_END )) {
+ /* default to putting key on right */
+ chart->key = CHART_KEY_RIGHT;
+ }
+
+ return NSERROR_OK;
+}
+
+
+static nserror
+output_pie_legend(struct fetch_about_context *ctx, struct chart_param *chart)
+{
+ nserror res;
+ unsigned int lblidx;
+ unsigned int legend_width;
+ unsigned int legend_height;
+ unsigned int vertical_spacing;
+
+ switch (chart->key) {
+
+ case CHART_KEY_NONE:
+ break;
+ case CHART_KEY_RIGHT:
+ legend_width = chart->width - chart->area.width - chart->area.x;
+ legend_width -= 10; /* margin */
+ legend_height = chart->height;
+ vertical_spacing = legend_height / (chart->data.label_len + 1);
+
+ for(lblidx = 0; lblidx < chart->data.label_len ; lblidx++) {
+ res = fetch_about_ssenddataf(ctx,
+ "<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"#%06x\" />",
+ chart->width - legend_width,
+ (vertical_spacing * lblidx) + (vertical_spacing/2),
+ vertical_spacing * 2 / 3,
+ vertical_spacing * 2 / 3,
+ chart->data.label[lblidx].colour);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+ res = fetch_about_ssenddataf(ctx,
+ "<text x=\"%d\" y=\"%d\" fill=\"#%06x\" >%s</text>",
+ chart->width - legend_width + vertical_spacing,
+ vertical_spacing * (lblidx+1),
+ chart->data.label[lblidx].colour,
+ chart->data.label[lblidx].title);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ return NSERROR_OK;
+}
+
+static float
+compute_series_total(struct chart_param *chart, unsigned int series)
+{
+ float total;
+ unsigned int curdata;
+
+ for (total = 0, curdata = 0;
+ curdata < chart->data.series[series].len;
+ curdata++) {
+ total += chart->data.series[series].value[curdata];
+ }
+ return total;
+}
+
+/**
+ * render the data as a pie chart svg
+ */
+static bool
+pie_chart(struct fetch_about_context *ctx, struct chart_param *chart)
+{
+ nserror res;
+ float ra; /* pie a radius */
+ float rb; /* pie b radius */
+ float series_total;
+ unsigned int curdata; /* current data point index */
+ float last_x, last_y;
+ float end_x, end_y;
+ float start;
+ float extent;
+ bool large;
+ float circle_centre_x, circle_centre_y;
+
+ /* ensure there is data to render */
+ if ((chart->data.series_len < 1) || (chart->data.series[0].len < 2)) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /* get the first series total value */
+ series_total = compute_series_total(chart, 0);
+ if (series_total == 0) {
+ /* dividing by zero is embarasing */
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /*
+ * need to ensure the chart area is setup correctly
+ *
+ * this is left to each chart type as different charts
+ * have differnt requirements
+ */
+ if ((chart->area.width == 0) || (chart->area.height == 0)) {
+ /*
+ * pie chart defaults to square of smaller of figure
+ * width and height
+ */
+ if (chart->width > chart->height) {
+ chart->area.width = chart->area.height = (chart->height - chart->area.x);
+ } else {
+ chart->area.width = chart->area.height = (chart->width - chart->area.y);
+ }
+ }
+
+ /* content is going to return ok */
+ fetch_about_set_http_code(ctx, 200);
+
+ /* content type */
+ if (fetch_about_send_header(ctx,
+ "Content-Type: image/svg; charset=utf-8")) {
+ goto aborted;
+ }
+
+ /* get the pie charts elipse radii */
+ ra = chart->area.width / 2;
+ rb = chart->area.height / 2;
+
+ /* get the offset to the circle centre */
+ circle_centre_x = chart->area.x + ra;
+ circle_centre_y = chart->area.y + rb;
+
+
+ /* svg header */
+ res = fetch_about_ssenddataf(ctx,
+ "<svg width=\"%u\" height=\"%u\" "
+ "xmlns=\"http://www.w3.org/2000/svg\">\n",
+ chart->width, chart->height);
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+
+ /* generate the legend */
+ res = output_pie_legend(ctx, chart);
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+
+ /* plot the arcs */
+ start = -M_PI_2;
+ last_x = (ra * cos(start));
+ last_y = (rb * sin(start));
+
+ /* iterate over each data point creating a slice o pie */
+ for (curdata=0; curdata < chart->data.series[0].len; curdata++) {
+ extent = ((chart->data.series[0].value[curdata] / series_total) * 2 * M_PI);
+ end_x = (ra * cos(start + extent));
+ end_y = (rb * sin(start + extent));
+
+ if (extent > M_PI) {
+ large = true;
+ } else {
+ large = false;
+ }
+
+ res = fetch_about_ssenddataf(
+ ctx,
+ "<path d=\"M %g %g\n"
+ "A %g %g 0 %d 1 %g %g\n"
+ "L %g %g Z\" fill=\"#%06x\" />\n",
+ circle_centre_x + last_x,
+ circle_centre_y + last_y,
+ ra, rb, large?1:0,
+ circle_centre_x + end_x,
+ circle_centre_y + end_y,
+ circle_centre_x,
+ circle_centre_y,
+ chart->data.label[curdata].colour);
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+ last_x = end_x;
+ last_y = end_y;
+ start +=extent;
+ }
+
+ res = fetch_about_ssenddataf(ctx, "</svg>\n");
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+
+ fetch_about_send_finished(ctx);
+
+ return true;
+
+ aborted:
+
+ return false;
+
+}
+
+/**
+ * Handler to generate about scheme chart page.
+ *
+ * generates an svg chart
+ *
+ * \param ctx The fetcher context.
+ * \return true if handled false if aborted.
+ */
+bool fetch_about_chart_handler(struct fetch_about_context *ctx)
+{
+ nserror res;
+ struct chart_param chart;
+ memset(&chart, 0, sizeof(struct chart_param));
+
+ res = chart_from_query(fetch_about_get_url(ctx), &chart);
+ if (res != NSERROR_OK) {
+ goto aborted;
+ }
+
+ switch (chart.type) {
+ case CHART_TYPE_PIE:
+ return pie_chart(ctx, &chart);
+
+
+ default:
+ break;
+ }
+
+aborted:
+
+ return false;
+
+}
diff --git a/content/fetchers/about/blank.h b/content/fetchers/about/chart.h
similarity index 74%
copy from content/fetchers/about/blank.h
copy to content/fetchers/about/chart.h
index 09dcc1f..4eb7e78 100644
--- a/content/fetchers/about/blank.h
+++ b/content/fetchers/about/chart.h
@@ -18,18 +18,20 @@
/**
* \file
- * about scheme blank handler interface
+ * about scheme chart handler interface
*/
-#ifndef NETSURF_CONTENT_FETCHERS_ABOUT_BLANK_H
-#define NETSURF_CONTENT_FETCHERS_ABOUT_BLANK_H
+#ifndef NETSURF_CONTENT_FETCHERS_ABOUT_CHART_H
+#define NETSURF_CONTENT_FETCHERS_ABOUT_CHART_H
/**
- * Handler to generate about scheme blank page.
+ * Handler to generate about scheme chart page.
+ *
+ * generates an svg chart
*
* \param ctx The fetcher context.
* \return true if handled false if aborted.
*/
-bool fetch_about_blank_handler(struct fetch_about_context *ctx);
+bool fetch_about_chart_handler(struct fetch_about_context *ctx);
#endif
diff --git a/content/fetchers/about/imagecache.c b/content/fetchers/about/imagecache.c
index 5e2abcb..23d3ef4 100644
--- a/content/fetchers/about/imagecache.c
+++ b/content/fetchers/about/imagecache.c
@@ -70,9 +70,23 @@ bool fetch_about_imagecache_handler(struct fetch_about_context *ctx)
"<p>Peak size %f (in %g)</p>\n"
"<p>Peak image count %h (size %i)</p>\n"
"<p>Cache total/hit/miss/fail (counts) %j/%k/%l/%m "
- "(%pj%%/%pk%%/%pl%%/%pm%%)</p>\n"
+ "(%pj%%/%pk%%/%pl%%/%pm%%)"
+ "<img width=200 height=100 src=\"about:chart?type=pie&width=200&height=100&labels=hit,miss,fail&values=%k,%l,%m\" />"
+ "</p>\n");
+ if (slen >= (int) (sizeof(buffer))) {
+ goto fetch_about_imagecache_handler_aborted; /* overflow */
+ }
+
+ res = fetch_about_senddata(ctx, (const uint8_t *)buffer, slen);
+ if (res != NSERROR_OK) {
+ goto fetch_about_imagecache_handler_aborted;
+ }
+
+ /* image cache summary */
+ slen = image_cache_snsummaryf(buffer, sizeof(buffer),
"<p>Cache total/hit/miss/fail (size) %n/%o/%q/%r "
- "(%pn%%/%po%%/%pq%%/%pr%%)</p>\n"
+ "(%pn%%/%po%%/%pq%%/%pr%%)"
+ "<img width=200 height=100 src=\"about:chart?type=pie&width=200&height=100&labels=hit,miss,fail&values=%o,%q,%r\" /></p>\n"
"<p>Total images never rendered: %s "
"(includes %t that were converted)</p>\n"
"<p>Total number of excessive conversions: %u "
--
NetSurf Browser
2 years, 11 months
netsurf: branch master updated. release/3.10-72-g32d52bf
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/32d52bf055dabb33e777a...
...commit http://git.netsurf-browser.org/netsurf.git/commit/32d52bf055dabb33e777a9f...
...tree http://git.netsurf-browser.org/netsurf.git/tree/32d52bf055dabb33e777a9ffa...
The branch, master has been updated
via 32d52bf055dabb33e777a9ffa5ef918c4916adb9 (commit)
from 58fee8749ffe41b0bb7c71456eddb808cbde8821 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=32d52bf055dabb33e77...
commit 32d52bf055dabb33e777a9ffa5ef918c4916adb9
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
gtk: In path plotter, maintain cairo transformation offset
Signed-off-by: Daniel Silverstone <dsilvers(a)digital-scurf.org>
diff --git a/frontends/gtk/plotters.c b/frontends/gtk/plotters.c
index 4a5ef51..110dcff 100644
--- a/frontends/gtk/plotters.c
+++ b/frontends/gtk/plotters.c
@@ -432,8 +432,8 @@ nsgtk_plot_path(const struct redraw_context *ctx,
n_ctm.yx = transform[1];
n_ctm.xy = transform[2];
n_ctm.yy = transform[3];
- n_ctm.x0 = transform[4];
- n_ctm.y0 = transform[5];
+ n_ctm.x0 = transform[4] + old_ctm.x0;
+ n_ctm.y0 = transform[5] + old_ctm.y0;
cairo_set_matrix(current_cr, &n_ctm);
-----------------------------------------------------------------------
Summary of changes:
frontends/gtk/plotters.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/frontends/gtk/plotters.c b/frontends/gtk/plotters.c
index 4a5ef51..110dcff 100644
--- a/frontends/gtk/plotters.c
+++ b/frontends/gtk/plotters.c
@@ -432,8 +432,8 @@ nsgtk_plot_path(const struct redraw_context *ctx,
n_ctm.yx = transform[1];
n_ctm.xy = transform[2];
n_ctm.yy = transform[3];
- n_ctm.x0 = transform[4];
- n_ctm.y0 = transform[5];
+ n_ctm.x0 = transform[4] + old_ctm.x0;
+ n_ctm.y0 = transform[5] + old_ctm.y0;
cairo_set_matrix(current_cr, &n_ctm);
--
NetSurf Browser
2 years, 11 months
libcss: branch tlsa/calc updated. release/0.9.1-4-g384495b
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/384495b311e287affacd59...
...commit http://git.netsurf-browser.org/libcss.git/commit/384495b311e287affacd5923...
...tree http://git.netsurf-browser.org/libcss.git/tree/384495b311e287affacd59238b...
The branch, tlsa/calc has been updated
via 384495b311e287affacd59238b2159fdd8cfff6b (commit)
via 709b6c7b5db034edb9b7d2f3b989916180dbf1e1 (commit)
from e3583052459e8cb7ecabaa25784ce85c5ab7421d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=384495b311e287affacd...
commit 384495b311e287affacd59238b2159fdd8cfff6b
Author: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
Commit: Michael Drake <Michael Drake tlsa(a)netsurf-browser.org>
parse: Tests and fixes for calc() parser.
Co-authored-by: Michael Drake <michael.drake(a)netsurf-browser.org>
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 93f01d1..2dff97c 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -24,12 +24,13 @@ enum flag {
};
enum calc_opcodes {
- CALC_PUSH_VALUE = 'V',
- CALC_ADD = '+',
- CALC_SUBTRACT = '-',
- CALC_MULTIPLY = '*',
- CALC_DIVIDE = '/',
- CALC_FINISH = '=',
+ CALC_PUSH_NUMBER = 'N',
+ CALC_PUSH_VALUE = 'V',
+ CALC_ADD = '+',
+ CALC_SUBTRACT = '-',
+ CALC_MULTIPLY = '*',
+ CALC_DIVIDE = '/',
+ CALC_FINISH = '=',
};
typedef enum unit {
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index a0fc786..ddb488f 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1365,6 +1365,31 @@ css__parse_calc_sum(css_language *c,
css_style *result);
static css_error
+css__parse_calc_number(
+ const parserutils_vector *vector, int *ctx,
+ css_style *result)
+{
+ const css_token *token;
+ css_fixed num;
+ size_t consumed;
+
+ /* Consume the number token */
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token == NULL || token->type != CSS_TOKEN_NUMBER) {
+ return CSS_INVALID;
+ }
+
+ num = css__number_from_string((const uint8_t *)lwc_string_data(token->idata),
+ lwc_string_length(token->idata), false, &consumed);
+
+ if (consumed != lwc_string_length(token->idata)) {
+ return CSS_INVALID;
+ }
+
+ return css__stylesheet_style_vappend(result, 2, (css_code_t) CALC_PUSH_NUMBER, (css_code_t)num);
+}
+
+static css_error
css__parse_calc_value(css_language *c,
const parserutils_vector *vector, int *ctx,
css_style *result)
@@ -1377,6 +1402,7 @@ css__parse_calc_value(css_language *c,
token = parserutils_vector_peek(vector, *ctx);
if (tokenIsChar(token, '(')) {
parserutils_vector_iterate(vector, ctx);
+ consumeWhitespace(vector, ctx);
error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
@@ -1389,7 +1415,12 @@ css__parse_calc_value(css_language *c,
/* Consume the close-paren to complete this value */
parserutils_vector_iterate(vector, ctx);
} else switch (token->type) {
- case CSS_TOKEN_NUMBER: /* Fall through */
+ case CSS_TOKEN_NUMBER:
+ error = css__parse_calc_number(vector, ctx, result);
+ if (error != CSS_OK) {
+ return error;
+ }
+ break;
case CSS_TOKEN_DIMENSION: /* Fall through */
case CSS_TOKEN_PERCENTAGE:
{
@@ -1412,11 +1443,7 @@ css__parse_calc_value(css_language *c,
break;
}
- token = parserutils_vector_peek(vector, *ctx);
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
+ consumeWhitespace(vector, ctx);
return error;
}
@@ -1462,14 +1489,15 @@ css__parse_calc_product(css_language *c,
}
/* Consume that * or / now */
parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
+ consumeWhitespace(vector, ctx);
+
+ if (multiplication) {
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result);
+ } else {
+ error = css__parse_calc_number(vector, ctx, result);
}
- /* parse another value */
- error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK)
break;
@@ -1516,12 +1544,7 @@ css__parse_calc_sum(css_language *c,
}
/* Consume that + or - now */
parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
-
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
+ consumeWhitespace(vector, ctx);
/* parse another product */
error = css__parse_calc_product(c, vector, ctx, result);
@@ -1547,17 +1570,14 @@ css_error css__parse_calc(css_language *c,
css_error error = CSS_OK;
css_style *calc_style = NULL;
+ consumeWhitespace(vector, ctx);
+
token = parserutils_vector_peek(vector, *ctx);
if (token == NULL) {
*ctx = orig_ctx;
return CSS_INVALID;
}
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
-
error = css__stylesheet_style_create(c->sheet, &calc_style);
if (error != CSS_OK)
goto cleanup;
@@ -1574,11 +1594,8 @@ css_error css__parse_calc(css_language *c,
if (error != CSS_OK)
goto cleanup;
+ consumeWhitespace(vector, ctx);
token = parserutils_vector_peek(vector, *ctx);
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
if (!tokenIsChar(token, ')')) {
/* If we don't get a close-paren, give up now */
error = CSS_INVALID;
diff --git a/test/data/parse2/calc.dat b/test/data/parse2/calc.dat
index 95abf6c..e9d176d 100644
--- a/test/data/parse2/calc.dat
+++ b/test/data/parse2/calc.dat
@@ -4,4 +4,154 @@
#expected
| *
| height: /* -> 0px */ calc(50vh 10px + =)
-#reset
\ No newline at end of file
+#reset
+
+#data
+* { line-height: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| line-height: /* -> 0any */ calc(50vh 10px + =)
+#reset
+
+#data
+* { line-height: calc( / 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { line-height: calc( + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { line-height: calc(2 / 2px)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(50vh 10px + =)
+#reset
+
+#data
+* { z-index: calc(2 * 3)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(2 3 * =)
+#reset
+
+#data
+* { z-index: calc(50vh + 10px / 9)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(50vh 10px 9 / + =)
+#reset
+
+#data
+* { z-index: calc(1 + 2 + 3 + 4)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + 3 + 4 + =)
+#reset
+
+#data
+* { z-index: calc(1 + 2 * 3 + 4)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 3 * + 4 + =)
+#reset
+
+#data
+* { z-index: calc((1 + 2) * (3 + 4))}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + 3 4 + * =)
+#reset
+
+#data
+* { z-index: calc(1 + 2}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc (1 + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(1)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 =)
+#reset
+
+#data
+* { z-index: calc()}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc((1 + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(((1 + 2)))}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + =)
+#reset
+
+#data
+* { z-index: calc( ( ( 1 + 2 ) ) )}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + =)
+#reset
+
+#data
+* { z-index: calc( ( 3 / ( 1 + 2 ) ) )}
+#errors
+#expected
+| *
+#reset
diff --git a/test/dump.h b/test/dump.h
index 7ad84d9..71d2801 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -834,6 +834,13 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
dump_unit(num, unit, ptr);
*ptr += sprintf(*ptr, " ");
break;
+ case CALC_PUSH_NUMBER: {
+ css_fixed num = *((css_fixed *)bytecode);
+ ADVANCE(sizeof(num));
+ dump_number(num, ptr);
+ *ptr += sprintf(*ptr, " ");
+ break;
+ }
}
default:
*ptr += sprintf(*ptr, "??%d ", calc_opcode);
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=709b6c7b5db034edb9b7...
commit 709b6c7b5db034edb9b7d2f3b989916180dbf1e1
Author: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
Commit: Michael Drake <Michael Drake tlsa(a)netsurf-browser.org>
parse: calc() test and fixup.
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 2267542..93f01d1 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -23,6 +23,15 @@ enum flag {
FLAG_INHERIT = (1<<1)
};
+enum calc_opcodes {
+ CALC_PUSH_VALUE = 'V',
+ CALC_ADD = '+',
+ CALC_SUBTRACT = '-',
+ CALC_MULTIPLY = '*',
+ CALC_DIVIDE = '/',
+ CALC_FINISH = '=',
+};
+
typedef enum unit {
UNIT_PX = 0,
UNIT_EX = 1,
@@ -108,6 +117,12 @@ static inline bool isInherit(css_code_t OPV)
return getFlags(OPV) & 0x2;
}
+static inline bool isCalc(css_code_t OPV)
+{
+ /* Note, this relies on all _CALC values being the same ultimately */
+ return getValue(OPV) == 0x7f;
+}
+
#endif
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 36a1daf..e68ad55 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -310,7 +310,7 @@ void output_calc(FILE *outputf, struct keyval *parseid, struct keyval_list *kvli
kind = ckv->key;
fprintf(outputf,
- "if ((token->type == CSS_TOKEN_IDENT) && "
+ "if ((token->type == CSS_TOKEN_FUNCTION) && "
"(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
" {\n"
"\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s), %s);\n"
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 11b7f72..a0fc786 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1373,8 +1373,10 @@ css__parse_calc_value(css_language *c,
int orig_ctx = *ctx;
const css_token *token;
- token = parserutils_vector_iterate(vector, ctx);
+ /* On entry, we are already pointing at the value to parse, so peek it */
+ token = parserutils_vector_peek(vector, *ctx);
if (tokenIsChar(token, '(')) {
+ parserutils_vector_iterate(vector, ctx);
error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
@@ -1384,7 +1386,8 @@ css__parse_calc_value(css_language *c,
if (!tokenIsChar(token, ')')) {
return CSS_INVALID;
}
-
+ /* Consume the close-paren to complete this value */
+ parserutils_vector_iterate(vector, ctx);
} else switch (token->type) {
case CSS_TOKEN_NUMBER: /* Fall through */
case CSS_TOKEN_DIMENSION: /* Fall through */
@@ -1400,7 +1403,7 @@ css__parse_calc_value(css_language *c,
return error;
}
- error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'V', length, unit);
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) CALC_PUSH_VALUE, length, unit);
}
break;
@@ -1409,6 +1412,11 @@ css__parse_calc_value(css_language *c,
break;
}
+ token = parserutils_vector_peek(vector, *ctx);
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
return error;
}
@@ -1439,7 +1447,10 @@ css__parse_calc_product(css_language *c,
if (token == NULL) {
error = CSS_INVALID;
break;
- } else if (tokenIsChar(token, ')'))
+ } else if (
+ tokenIsChar(token, ')') ||
+ tokenIsChar(token, '+') ||
+ tokenIsChar(token, '-'))
break;
else if (tokenIsChar(token, '*'))
multiplication = true;
@@ -1450,15 +1461,21 @@ css__parse_calc_product(css_language *c,
break;
}
/* Consume that * or / now */
- token = parserutils_vector_iterate(vector, ctx);
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
/* parse another value */
error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK)
break;
/* emit the multiplication/division operator */
- error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
+ error = css__stylesheet_style_append(result,
+ (css_code_t) (multiplication ? CALC_MULTIPLY : CALC_DIVIDE));
} while (1);
/* We've fallen off, either we had an error or we're left with ')' */
return error;
@@ -1498,7 +1515,13 @@ css__parse_calc_sum(css_language *c,
break;
}
/* Consume that + or - now */
- token = parserutils_vector_iterate(vector, ctx);
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
/* parse another product */
error = css__parse_calc_product(c, vector, ctx, result);
@@ -1506,7 +1529,7 @@ css__parse_calc_sum(css_language *c,
break;
/* emit the addition/subtraction operator */
- error = css__stylesheet_style_append(result, (css_code_t) (addition ? '+' : '-'));
+ error = css__stylesheet_style_append(result, (css_code_t) (addition ? CALC_ADD : CALC_SUBTRACT));
} while (1);
/* We've fallen off, either we had an error or we're left with ')' */
return error;
@@ -1524,16 +1547,15 @@ css_error css__parse_calc(css_language *c,
css_error error = CSS_OK;
css_style *calc_style = NULL;
- token = parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
if (token == NULL) {
*ctx = orig_ctx;
return CSS_INVALID;
}
- if (!tokenIsChar(token, '(')) {
- /* If we don't get an open-paren, give up now */
- *ctx = orig_ctx;
- return CSS_INVALID;
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
}
error = css__stylesheet_style_create(c->sheet, &calc_style);
@@ -1545,27 +1567,33 @@ css_error css__parse_calc(css_language *c,
goto cleanup;
error = css__stylesheet_style_append(calc_style, (css_code_t) unit);
+ if (error != CSS_OK)
+ goto cleanup;
error = css__parse_calc_sum(c, vector, ctx, calc_style);
if (error != CSS_OK)
goto cleanup;
- token = parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
if (!tokenIsChar(token, ')')) {
/* If we don't get a close-paren, give up now */
error = CSS_INVALID;
goto cleanup;
}
+ /* Swallow that close paren */
+ parserutils_vector_iterate(vector, ctx);
+
/* Append the indicator that the calc is finished */
- error = css__stylesheet_style_append(calc_style, (css_code_t) '=');
+ error = css__stylesheet_style_append(calc_style, (css_code_t) CALC_FINISH);
if (error != CSS_OK)
goto cleanup;
- /* TODO: Once we're OK to do so, merge the style */
- (void)result;
- /* error = css__stylesheet_style_merge_style(result, calc_style); */
-
+ error = css__stylesheet_merge_style(result, calc_style);
cleanup:
css__stylesheet_style_destroy(calc_style);
if (error != CSS_OK) {
diff --git a/test/data/parse2/INDEX b/test/data/parse2/INDEX
index 331cf5c..bb2a79b 100644
--- a/test/data/parse2/INDEX
+++ b/test/data/parse2/INDEX
@@ -23,3 +23,4 @@ multicol.dat Multi-column layout property tests
flexbox.dat Flexbox properties and shorthands tests
units.dat Length unit tests
dodgy-media-block.dat Media block with incomplete ruleset
+calc.dat calc() tests
diff --git a/test/data/parse2/calc.dat b/test/data/parse2/calc.dat
new file mode 100644
index 0000000..95abf6c
--- /dev/null
+++ b/test/data/parse2/calc.dat
@@ -0,0 +1,7 @@
+#data
+* { height: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| height: /* -> 0px */ calc(50vh 10px + =)
+#reset
\ No newline at end of file
diff --git a/test/dump.h b/test/dump.h
index d67bb2a..7ad84d9 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -647,6 +647,12 @@ static void dump_unit(css_fixed val, uint32_t unit, char **ptr)
case UNIT_KHZ:
*ptr += sprintf(*ptr, "kHz");
break;
+ case UNIT_CALC_ANY:
+ *ptr += sprintf(*ptr, "any");
+ break;
+ case UNIT_CALC_NUMBER:
+ *ptr += sprintf(*ptr, "number");
+ break;
}
}
@@ -797,6 +803,45 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
if (isInherit(opv)) {
*ptr += sprintf(*ptr, "inherit");
+ } else if (isCalc(opv)) {
+ /* First entry is a unit */
+ uint32_t unit = *((uint32_t *)bytecode);
+ ADVANCE(sizeof(unit));
+ *ptr += sprintf(*ptr, "/* -> ");
+ dump_unit(0, unit, ptr);
+ *ptr += sprintf(*ptr, " */ calc(");
+ css_code_t calc_opcode;
+ while ((calc_opcode = *((css_code_t *)bytecode)) != CALC_FINISH) {
+ ADVANCE(sizeof(calc_opcode));
+ switch (calc_opcode) {
+ case CALC_ADD:
+ *ptr += sprintf(*ptr, "+ ");
+ break;
+ case CALC_SUBTRACT:
+ *ptr += sprintf(*ptr, "- ");
+ break;
+ case CALC_MULTIPLY:
+ *ptr += sprintf(*ptr, "* ");
+ break;
+ case CALC_DIVIDE:
+ *ptr += sprintf(*ptr, "/ ");
+ break;
+ case CALC_PUSH_VALUE: {
+ css_fixed num = *((css_fixed *)bytecode);
+ ADVANCE(sizeof(num));
+ uint32_t unit = *((uint32_t *)bytecode);
+ ADVANCE(sizeof(unit));
+ dump_unit(num, unit, ptr);
+ *ptr += sprintf(*ptr, " ");
+ break;
+ }
+ default:
+ *ptr += sprintf(*ptr, "??%d ", calc_opcode);
+ break;
+ }
+ }
+ ADVANCE(sizeof(calc_opcode));
+ *ptr += sprintf(*ptr, "=)");
} else {
value = getValue(opv);
-----------------------------------------------------------------------
Summary of changes:
src/bytecode/bytecode.h | 16 +++
src/parse/properties/css_property_parser_gen.c | 2 +-
src/parse/properties/utils.c | 93 ++++++++++----
test/data/parse2/INDEX | 1 +
test/data/parse2/calc.dat | 157 ++++++++++++++++++++++++
test/dump.h | 52 ++++++++
6 files changed, 296 insertions(+), 25 deletions(-)
create mode 100644 test/data/parse2/calc.dat
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 2267542..2dff97c 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -23,6 +23,16 @@ enum flag {
FLAG_INHERIT = (1<<1)
};
+enum calc_opcodes {
+ CALC_PUSH_NUMBER = 'N',
+ CALC_PUSH_VALUE = 'V',
+ CALC_ADD = '+',
+ CALC_SUBTRACT = '-',
+ CALC_MULTIPLY = '*',
+ CALC_DIVIDE = '/',
+ CALC_FINISH = '=',
+};
+
typedef enum unit {
UNIT_PX = 0,
UNIT_EX = 1,
@@ -108,6 +118,12 @@ static inline bool isInherit(css_code_t OPV)
return getFlags(OPV) & 0x2;
}
+static inline bool isCalc(css_code_t OPV)
+{
+ /* Note, this relies on all _CALC values being the same ultimately */
+ return getValue(OPV) == 0x7f;
+}
+
#endif
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 36a1daf..e68ad55 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -310,7 +310,7 @@ void output_calc(FILE *outputf, struct keyval *parseid, struct keyval_list *kvli
kind = ckv->key;
fprintf(outputf,
- "if ((token->type == CSS_TOKEN_IDENT) && "
+ "if ((token->type == CSS_TOKEN_FUNCTION) && "
"(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
" {\n"
"\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s), %s);\n"
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 11b7f72..ddb488f 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1365,6 +1365,31 @@ css__parse_calc_sum(css_language *c,
css_style *result);
static css_error
+css__parse_calc_number(
+ const parserutils_vector *vector, int *ctx,
+ css_style *result)
+{
+ const css_token *token;
+ css_fixed num;
+ size_t consumed;
+
+ /* Consume the number token */
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token == NULL || token->type != CSS_TOKEN_NUMBER) {
+ return CSS_INVALID;
+ }
+
+ num = css__number_from_string((const uint8_t *)lwc_string_data(token->idata),
+ lwc_string_length(token->idata), false, &consumed);
+
+ if (consumed != lwc_string_length(token->idata)) {
+ return CSS_INVALID;
+ }
+
+ return css__stylesheet_style_vappend(result, 2, (css_code_t) CALC_PUSH_NUMBER, (css_code_t)num);
+}
+
+static css_error
css__parse_calc_value(css_language *c,
const parserutils_vector *vector, int *ctx,
css_style *result)
@@ -1373,8 +1398,11 @@ css__parse_calc_value(css_language *c,
int orig_ctx = *ctx;
const css_token *token;
- token = parserutils_vector_iterate(vector, ctx);
+ /* On entry, we are already pointing at the value to parse, so peek it */
+ token = parserutils_vector_peek(vector, *ctx);
if (tokenIsChar(token, '(')) {
+ parserutils_vector_iterate(vector, ctx);
+ consumeWhitespace(vector, ctx);
error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
@@ -1384,9 +1412,15 @@ css__parse_calc_value(css_language *c,
if (!tokenIsChar(token, ')')) {
return CSS_INVALID;
}
-
+ /* Consume the close-paren to complete this value */
+ parserutils_vector_iterate(vector, ctx);
} else switch (token->type) {
- case CSS_TOKEN_NUMBER: /* Fall through */
+ case CSS_TOKEN_NUMBER:
+ error = css__parse_calc_number(vector, ctx, result);
+ if (error != CSS_OK) {
+ return error;
+ }
+ break;
case CSS_TOKEN_DIMENSION: /* Fall through */
case CSS_TOKEN_PERCENTAGE:
{
@@ -1400,7 +1434,7 @@ css__parse_calc_value(css_language *c,
return error;
}
- error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'V', length, unit);
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) CALC_PUSH_VALUE, length, unit);
}
break;
@@ -1409,6 +1443,7 @@ css__parse_calc_value(css_language *c,
break;
}
+ consumeWhitespace(vector, ctx);
return error;
}
@@ -1439,7 +1474,10 @@ css__parse_calc_product(css_language *c,
if (token == NULL) {
error = CSS_INVALID;
break;
- } else if (tokenIsChar(token, ')'))
+ } else if (
+ tokenIsChar(token, ')') ||
+ tokenIsChar(token, '+') ||
+ tokenIsChar(token, '-'))
break;
else if (tokenIsChar(token, '*'))
multiplication = true;
@@ -1450,15 +1488,22 @@ css__parse_calc_product(css_language *c,
break;
}
/* Consume that * or / now */
- token = parserutils_vector_iterate(vector, ctx);
+ parserutils_vector_iterate(vector, ctx);
- /* parse another value */
- error = css__parse_calc_value(c, vector, ctx, result);
+ consumeWhitespace(vector, ctx);
+
+ if (multiplication) {
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result);
+ } else {
+ error = css__parse_calc_number(vector, ctx, result);
+ }
if (error != CSS_OK)
break;
/* emit the multiplication/division operator */
- error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
+ error = css__stylesheet_style_append(result,
+ (css_code_t) (multiplication ? CALC_MULTIPLY : CALC_DIVIDE));
} while (1);
/* We've fallen off, either we had an error or we're left with ')' */
return error;
@@ -1498,7 +1543,8 @@ css__parse_calc_sum(css_language *c,
break;
}
/* Consume that + or - now */
- token = parserutils_vector_iterate(vector, ctx);
+ parserutils_vector_iterate(vector, ctx);
+ consumeWhitespace(vector, ctx);
/* parse another product */
error = css__parse_calc_product(c, vector, ctx, result);
@@ -1506,7 +1552,7 @@ css__parse_calc_sum(css_language *c,
break;
/* emit the addition/subtraction operator */
- error = css__stylesheet_style_append(result, (css_code_t) (addition ? '+' : '-'));
+ error = css__stylesheet_style_append(result, (css_code_t) (addition ? CALC_ADD : CALC_SUBTRACT));
} while (1);
/* We've fallen off, either we had an error or we're left with ')' */
return error;
@@ -1524,14 +1570,10 @@ css_error css__parse_calc(css_language *c,
css_error error = CSS_OK;
css_style *calc_style = NULL;
- token = parserutils_vector_iterate(vector, ctx);
- if (token == NULL) {
- *ctx = orig_ctx;
- return CSS_INVALID;
- }
+ consumeWhitespace(vector, ctx);
- if (!tokenIsChar(token, '(')) {
- /* If we don't get an open-paren, give up now */
+ token = parserutils_vector_peek(vector, *ctx);
+ if (token == NULL) {
*ctx = orig_ctx;
return CSS_INVALID;
}
@@ -1545,27 +1587,30 @@ css_error css__parse_calc(css_language *c,
goto cleanup;
error = css__stylesheet_style_append(calc_style, (css_code_t) unit);
+ if (error != CSS_OK)
+ goto cleanup;
error = css__parse_calc_sum(c, vector, ctx, calc_style);
if (error != CSS_OK)
goto cleanup;
- token = parserutils_vector_iterate(vector, ctx);
+ consumeWhitespace(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
if (!tokenIsChar(token, ')')) {
/* If we don't get a close-paren, give up now */
error = CSS_INVALID;
goto cleanup;
}
+ /* Swallow that close paren */
+ parserutils_vector_iterate(vector, ctx);
+
/* Append the indicator that the calc is finished */
- error = css__stylesheet_style_append(calc_style, (css_code_t) '=');
+ error = css__stylesheet_style_append(calc_style, (css_code_t) CALC_FINISH);
if (error != CSS_OK)
goto cleanup;
- /* TODO: Once we're OK to do so, merge the style */
- (void)result;
- /* error = css__stylesheet_style_merge_style(result, calc_style); */
-
+ error = css__stylesheet_merge_style(result, calc_style);
cleanup:
css__stylesheet_style_destroy(calc_style);
if (error != CSS_OK) {
diff --git a/test/data/parse2/INDEX b/test/data/parse2/INDEX
index 331cf5c..bb2a79b 100644
--- a/test/data/parse2/INDEX
+++ b/test/data/parse2/INDEX
@@ -23,3 +23,4 @@ multicol.dat Multi-column layout property tests
flexbox.dat Flexbox properties and shorthands tests
units.dat Length unit tests
dodgy-media-block.dat Media block with incomplete ruleset
+calc.dat calc() tests
diff --git a/test/data/parse2/calc.dat b/test/data/parse2/calc.dat
new file mode 100644
index 0000000..e9d176d
--- /dev/null
+++ b/test/data/parse2/calc.dat
@@ -0,0 +1,157 @@
+#data
+* { height: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| height: /* -> 0px */ calc(50vh 10px + =)
+#reset
+
+#data
+* { line-height: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| line-height: /* -> 0any */ calc(50vh 10px + =)
+#reset
+
+#data
+* { line-height: calc( / 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { line-height: calc( + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { line-height: calc(2 / 2px)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(50vh 10px + =)
+#reset
+
+#data
+* { z-index: calc(2 * 3)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(2 3 * =)
+#reset
+
+#data
+* { z-index: calc(50vh + 10px / 9)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(50vh 10px 9 / + =)
+#reset
+
+#data
+* { z-index: calc(1 + 2 + 3 + 4)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + 3 + 4 + =)
+#reset
+
+#data
+* { z-index: calc(1 + 2 * 3 + 4)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 3 * + 4 + =)
+#reset
+
+#data
+* { z-index: calc((1 + 2) * (3 + 4))}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + 3 4 + * =)
+#reset
+
+#data
+* { z-index: calc(1 + 2}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc (1 + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(1)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 =)
+#reset
+
+#data
+* { z-index: calc()}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc((1 + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(((1 + 2)))}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + =)
+#reset
+
+#data
+* { z-index: calc( ( ( 1 + 2 ) ) )}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + =)
+#reset
+
+#data
+* { z-index: calc( ( 3 / ( 1 + 2 ) ) )}
+#errors
+#expected
+| *
+#reset
diff --git a/test/dump.h b/test/dump.h
index d67bb2a..71d2801 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -647,6 +647,12 @@ static void dump_unit(css_fixed val, uint32_t unit, char **ptr)
case UNIT_KHZ:
*ptr += sprintf(*ptr, "kHz");
break;
+ case UNIT_CALC_ANY:
+ *ptr += sprintf(*ptr, "any");
+ break;
+ case UNIT_CALC_NUMBER:
+ *ptr += sprintf(*ptr, "number");
+ break;
}
}
@@ -797,6 +803,52 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
if (isInherit(opv)) {
*ptr += sprintf(*ptr, "inherit");
+ } else if (isCalc(opv)) {
+ /* First entry is a unit */
+ uint32_t unit = *((uint32_t *)bytecode);
+ ADVANCE(sizeof(unit));
+ *ptr += sprintf(*ptr, "/* -> ");
+ dump_unit(0, unit, ptr);
+ *ptr += sprintf(*ptr, " */ calc(");
+ css_code_t calc_opcode;
+ while ((calc_opcode = *((css_code_t *)bytecode)) != CALC_FINISH) {
+ ADVANCE(sizeof(calc_opcode));
+ switch (calc_opcode) {
+ case CALC_ADD:
+ *ptr += sprintf(*ptr, "+ ");
+ break;
+ case CALC_SUBTRACT:
+ *ptr += sprintf(*ptr, "- ");
+ break;
+ case CALC_MULTIPLY:
+ *ptr += sprintf(*ptr, "* ");
+ break;
+ case CALC_DIVIDE:
+ *ptr += sprintf(*ptr, "/ ");
+ break;
+ case CALC_PUSH_VALUE: {
+ css_fixed num = *((css_fixed *)bytecode);
+ ADVANCE(sizeof(num));
+ uint32_t unit = *((uint32_t *)bytecode);
+ ADVANCE(sizeof(unit));
+ dump_unit(num, unit, ptr);
+ *ptr += sprintf(*ptr, " ");
+ break;
+ case CALC_PUSH_NUMBER: {
+ css_fixed num = *((css_fixed *)bytecode);
+ ADVANCE(sizeof(num));
+ dump_number(num, ptr);
+ *ptr += sprintf(*ptr, " ");
+ break;
+ }
+ }
+ default:
+ *ptr += sprintf(*ptr, "??%d ", calc_opcode);
+ break;
+ }
+ }
+ ADVANCE(sizeof(calc_opcode));
+ *ptr += sprintf(*ptr, "=)");
} else {
value = getValue(opv);
--
Cascading Style Sheets library
2 years, 11 months
libcss: branch tlsa/calc updated. release/0.9.1-2-ge358305
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/e3583052459e8cb7ecabaa...
...commit http://git.netsurf-browser.org/libcss.git/commit/e3583052459e8cb7ecabaa25...
...tree http://git.netsurf-browser.org/libcss.git/tree/e3583052459e8cb7ecabaa2578...
The branch, tlsa/calc has been updated
via e3583052459e8cb7ecabaa25784ce85c5ab7421d (commit)
from 62dc80851eef3e256ef522dd68346672f30b7375 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=e3583052459e8cb7ecab...
commit e3583052459e8cb7ecabaa25784ce85c5ab7421d
Author: Michael Drake <Michael Drake tlsa(a)netsurf-browser.org>
Commit: Michael Drake <Michael Drake tlsa(a)netsurf-browser.org>
parse: Update parser generator to support calc() details.
Co-authored-by: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 22703f7..2267542 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -66,6 +66,10 @@ typedef enum unit {
UNIT_DPI = (1 << 12) + 0,
UNIT_DPCM = (1 << 12) + 1,
UNIT_DPPX = (1 << 12) + 2,
+
+ /* These are special only to the CALC bytecodes */
+ UNIT_CALC_ANY = (1 << 20),
+ UNIT_CALC_NUMBER = (1 << 20) + 1,
} unit;
typedef uint32_t colour;
diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h
index 82bf75f..d728831 100644
--- a/src/bytecode/opcodes.h
+++ b/src/bytecode/opcodes.h
@@ -119,6 +119,7 @@ enum op_border_style {
};
enum op_border_width {
+ BORDER_WIDTH_CALC = 0x007f,
BORDER_WIDTH_SET = 0x0080,
BORDER_WIDTH_THIN = 0x0000,
BORDER_WIDTH_MEDIUM = 0x0001,
@@ -126,6 +127,7 @@ enum op_border_width {
};
enum op_bottom {
+ BOTTOM_CALC = 0x007f,
BOTTOM_SET = 0x0080,
BOTTOM_AUTO = 0x0000
};
@@ -198,6 +200,7 @@ enum op_color {
enum op_column_count {
COLUMN_COUNT_AUTO = 0x0000,
+ COLUMN_COUNT_CALC = 0x007f,
COLUMN_COUNT_SET = 0x0080
};
@@ -208,6 +211,7 @@ enum op_column_fill {
enum op_column_gap {
COLUMN_GAP_NORMAL = 0x0000,
+ COLUMN_GAP_CALC = 0x007f,
COLUMN_GAP_SET = 0x0080
};
@@ -231,6 +235,7 @@ enum op_column_rule_style {
};
enum op_column_rule_width {
+ COLUMN_RULE_WIDTH_CALC = BORDER_WIDTH_CALC,
COLUMN_RULE_WIDTH_SET = BORDER_WIDTH_SET,
COLUMN_RULE_WIDTH_THIN = BORDER_WIDTH_THIN,
COLUMN_RULE_WIDTH_MEDIUM = BORDER_WIDTH_MEDIUM,
@@ -244,6 +249,7 @@ enum op_column_span {
enum op_column_width {
COLUMN_WIDTH_AUTO = 0x0000,
+ COLUMN_WIDTH_CALC = 0x007f,
COLUMN_WIDTH_SET = 0x0080
};
@@ -352,6 +358,7 @@ enum op_empty_cells {
enum op_flex_basis {
FLEX_BASIS_AUTO = 0x0000,
FLEX_BASIS_CONTENT = 0x0001,
+ FLEX_BASIS_CALC = 0x007f,
FLEX_BASIS_SET = 0x0080
};
@@ -363,10 +370,12 @@ enum op_flex_direction {
};
enum op_flex_grow {
+ FLEX_GROW_CALC = 0x007f,
FLEX_GROW_SET = 0x0080
};
enum op_flex_shrink {
+ FLEX_SHRINK_CALC = 0x007f,
FLEX_SHRINK_SET = 0x0080
};
@@ -396,6 +405,7 @@ enum op_font_family {
};
enum op_font_size {
+ FONT_SIZE_CALC = 0x007f,
FONT_SIZE_DIMENSION = 0x0080,
FONT_SIZE_XX_SMALL = 0x0000,
@@ -437,6 +447,7 @@ enum op_font_weight {
};
enum op_height {
+ HEIGHT_CALC = 0x007f,
HEIGHT_SET = 0x0080,
HEIGHT_AUTO = 0x0000
};
@@ -451,16 +462,19 @@ enum op_justify_content {
};
enum op_left {
+ LEFT_CALC = BOTTOM_CALC,
LEFT_SET = BOTTOM_SET,
LEFT_AUTO = BOTTOM_AUTO
};
enum op_letter_spacing {
+ LETTER_SPACING_CALC = 0x007f,
LETTER_SPACING_SET = 0x0080,
LETTER_SPACING_NORMAL = 0x0000
};
enum op_line_height {
+ LINE_HEIGHT_CALC = 0x007f,
LINE_HEIGHT_NUMBER = 0x0080,
LINE_HEIGHT_DIMENSION = 0x0081,
LINE_HEIGHT_NORMAL = 0x0000
@@ -495,26 +509,31 @@ enum op_list_style_type {
};
enum op_margin {
+ MARGIN_CALC = 0x007f,
MARGIN_SET = 0x0080,
MARGIN_AUTO = 0x0000
};
enum op_max_height {
+ MAX_HEIGHT_CALC = 0x007f,
MAX_HEIGHT_SET = 0x0080,
MAX_HEIGHT_NONE = 0x0000
};
enum op_max_width {
+ MAX_WIDTH_CALC = 0x007f,
MAX_WIDTH_SET = 0x0080,
MAX_WIDTH_NONE = 0x0000
};
enum op_min_height {
+ MIN_HEIGHT_CALC = 0x007f,
MIN_HEIGHT_SET = 0x0080,
MIN_HEIGHT_AUTO = 0x0000
};
enum op_min_width {
+ MIN_WIDTH_CALC = 0x007f,
MIN_WIDTH_SET = 0x0080,
MIN_WIDTH_AUTO = 0x0000
};
@@ -524,10 +543,12 @@ enum op_opacity {
};
enum op_order {
+ ORDER_CALC = 0x007f,
ORDER_SET = 0x0080
};
enum op_orphans {
+ ORPHANS_CALC = 0x007f,
ORPHANS_SET = 0x0080
};
@@ -566,6 +587,7 @@ enum op_overflow {
};
enum op_padding {
+ PADDING_CALC = 0x007f,
PADDING_SET = 0x0080
};
@@ -591,18 +613,22 @@ enum op_page_break_inside {
};
enum op_pause_after {
+ PAUSE_AFTER_CALC = 0x007f,
PAUSE_AFTER_SET = 0x0080
};
enum op_pause_before {
+ PAUSE_BEFORE_CALC = 0x007f,
PAUSE_BEFORE_SET = 0x0080
};
enum op_pitch_range {
+ PITCH_RANGE_CALC = 0x007f,
PITCH_RANGE_SET = 0x0080
};
enum op_pitch {
+ PITCH_CALC = 0x007f,
PITCH_FREQUENCY = 0x0080,
PITCH_X_LOW = 0x0000,
@@ -636,6 +662,7 @@ enum op_quotes {
};
enum op_richness {
+ RICHNESS_CALC = 0x007f,
RICHNESS_SET = 0x0080
};
@@ -666,6 +693,7 @@ enum op_speak {
};
enum op_speech_rate {
+ SPEECH_RATE_CALC = 0x007f,
SPEECH_RATE_SET = 0x0080,
SPEECH_RATE_X_SLOW = 0x0000,
@@ -678,6 +706,7 @@ enum op_speech_rate {
};
enum op_stress {
+ STRESS_CALC = 0x007f,
STRESS_SET = 0x0080
};
@@ -706,6 +735,7 @@ enum op_text_decoration {
};
enum op_text_indent {
+ TEXT_INDENT_CALC = 0x007f,
TEXT_INDENT_SET = 0x0080
};
@@ -717,6 +747,7 @@ enum op_text_transform {
};
enum op_top {
+ TOP_CALC = BOTTOM_CALC,
TOP_SET = BOTTOM_SET,
TOP_AUTO = BOTTOM_AUTO
};
@@ -728,6 +759,7 @@ enum op_unicode_bidi {
};
enum op_vertical_align {
+ VERTICAL_ALIGN_CALC = 0x007f,
VERTICAL_ALIGN_SET = 0x0080,
VERTICAL_ALIGN_BASELINE = 0x0000,
@@ -758,6 +790,7 @@ enum op_voice_family {
};
enum op_volume {
+ VOLUME_CALC = 0x007f,
VOLUME_NUMBER = 0x0080,
VOLUME_DIMENSION = 0x0081,
@@ -778,16 +811,19 @@ enum op_white_space {
};
enum op_widows {
+ WIDOWS_CALC = 0x007f,
WIDOWS_SET = 0x0080
};
enum op_width {
+ WIDTH_CALC = 0x007f,
WIDTH_SET = 0x0080,
WIDTH_AUTO = 0x0000
};
enum op_word_spacing {
+ WORD_SPACING_CALC = 0x007f,
WORD_SPACING_SET = 0x0080,
WORD_SPACING_NORMAL = 0x0000
@@ -800,6 +836,7 @@ enum op_writing_mode {
};
enum op_z_index {
+ Z_INDEX_CALC = 0x007f,
Z_INDEX_SET = 0x0080,
Z_INDEX_AUTO = 0x0000
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 838f2b6..36a1daf 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -19,6 +19,12 @@
* list_style_position:CSS_PROP_LIST_STYLE_POSITION IDENT:( INHERIT: INSIDE:0,LIST_STYLE_POSITION_INSIDE OUTSIDE:0,LIST_STYLE_POSITION_OUTSIDE IDENT:)
*/
+typedef enum {
+ CALC_ANY,
+ CALC_NUMBER,
+ CALC_UNIT,
+} calc_kind;
+
struct keyval {
char *key;
char *val;
@@ -291,21 +297,34 @@ void output_color(FILE *outputf, struct keyval *parseid, struct keyval_list *kvl
parseid->val);
}
-void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
+void output_calc(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
{
struct keyval *ckv = kvlist->item[0];
- int ident_count;
+ const char *kind;
+
+ if (strcmp(ckv->key, "NUMBER") == 0)
+ kind = "UNIT_CALC_NUMBER";
+ else if (strcmp(ckv->key, "ANY") == 0)
+ kind = "UNIT_CALC_ANY";
+ else
+ kind = ckv->key;
fprintf(outputf,
"if ((token->type == CSS_TOKEN_IDENT) && "
"(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
" {\n"
- "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s /* _CALC */), %s);\n"
+ "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s), %s);\n"
"\t} else ",
parseid->val,
ckv->val,
- ckv->key
+ kind
);
+}
+
+void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
+{
+ struct keyval *ckv = kvlist->item[0];
+ int ident_count;
fprintf(outputf,
"{\n"
@@ -494,6 +513,7 @@ int main(int argc, char **argv)
struct keyval_list WRAP;
struct keyval_list NUMBER;
struct keyval_list COLOR;
+ struct keyval_list CALC;
if (argc < 2) {
@@ -526,6 +546,7 @@ int main(int argc, char **argv)
COLOR.count = 0;
LENGTH_UNIT.count = 0;
IDENT_LIST.count = 0;
+ CALC.count = 0;
curlist = &base;
@@ -541,7 +562,7 @@ int main(int argc, char **argv)
if (strcmp(rkv->key, "WRAP") == 0) {
WRAP.item[WRAP.count++] = rkv;
only_ident = false;
- } else if (strcmp(rkv->key, "NUMBER") == 0) {
+ } else if (curlist == &base && strcmp(rkv->key, "NUMBER") == 0) {
if (rkv->val[0] == '(') {
curlist = &NUMBER;
} else if (rkv->val[0] == ')') {
@@ -572,6 +593,14 @@ int main(int argc, char **argv)
}
only_ident = false;
do_token_check = false;
+ } else if (strcmp(rkv->key, "CALC") == 0) {
+ if (rkv->val[0] == '(') {
+ curlist = &CALC;
+ } else if (rkv->val[0] == ')') {
+ curlist = &base;
+ }
+ only_ident = false;
+ do_token_check = false;
} else if (strcmp(rkv->key, "COLOR") == 0) {
COLOR.item[COLOR.count++] = rkv;
do_token_check = false;
@@ -595,7 +624,7 @@ int main(int argc, char **argv)
/* header */
-output_header(outputf, descriptor, base.item[0], is_generic);
+ output_header(outputf, descriptor, base.item[0], is_generic);
if (WRAP.count > 0) {
output_wrap(outputf, base.item[0], &WRAP);
@@ -609,6 +638,10 @@ output_header(outputf, descriptor, base.item[0], is_generic);
if (URI.count > 0)
output_uri(outputf, base.item[0], &URI);
+ if (CALC.count > 0) {
+ output_calc(outputf, base.item[0], &CALC);
+ }
+
if (NUMBER.count > 0)
output_number(outputf, base.item[0], &NUMBER);
diff --git a/src/parse/properties/properties.gen b/src/parse/properties/properties.gen
index 61dcd5e..33df482 100644
--- a/src/parse/properties/properties.gen
+++ b/src/parse/properties/properties.gen
@@ -6,6 +6,13 @@
#property:CSS_PROP_ENUM IDENT:( INHERIT: IDENT:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY ALLOW: DISALLOW: RANGE:<0 LENGTH_UNIT:)
#property:CSS_PROP_ENUM WRAP:
+# When a property takes a NUMBER and/or LENGTH_UNIT you may add calc() support:
+# In the below, PROPERTY_FOO_CALC is the opcode enum for the set-but-calculated value bytecode.
+# e.g. HEIGHT_SET (for a LENGTH_UNIT) would be HEIGHT_CALC here.
+# CALC:( UNIT_??:PROPERTY_FOO_CALC CALC:) <-- When a default unit must be considered
+# CALC:( NUMBER:PROPERTY_FOO_CALC CALC:) <-- When a number must be produced (not a dimension)
+# CALC:( ANY:PROPERTY_FOO_CALC CALC:) <-- When a number or dimension is valid (e.g. line-height)
+
background_repeat:CSS_PROP_BACKGROUND_REPEAT IDENT:( INHERIT: NO_REPEAT:0,BACKGROUND_REPEAT_NO_REPEAT REPEAT_X:0,BACKGROUND_REPEAT_REPEAT_X REPEAT_Y:0,BACKGROUND_REPEAT_REPEAT_Y REPEAT:0,BACKGROUND_REPEAT_REPEAT IDENT:)
border_collapse:CSS_PROP_BORDER_COLLAPSE IDENT:( INHERIT: COLLAPSE:0,BORDER_COLLAPSE_COLLAPSE SEPARATE:0,BORDER_COLLAPSE_SEPARATE IDENT:)
@@ -22,35 +29,35 @@ empty_cells:CSS_PROP_EMPTY_CELLS IDENT:( INHERIT: SHOW:0,EMPTY_CELLS_SHOW HIDE:0
float:CSS_PROP_FLOAT IDENT:( INHERIT: LEFT:0,FLOAT_LEFT RIGHT:0,FLOAT_RIGHT NONE:0,FLOAT_NONE IDENT:)
-font_size:CSS_PROP_FONT_SIZE IDENT:( INHERIT: XX_SMALL:0,FONT_SIZE_XX_SMALL X_SMALL:0,FONT_SIZE_X_SMALL SMALL:0,FONT_SIZE_SMALL MEDIUM:0,FONT_SIZE_MEDIUM LARGE:0,FONT_SIZE_LARGE X_LARGE:0,FONT_SIZE_X_LARGE XX_LARGE:0,FONT_SIZE_XX_LARGE LARGER:0,FONT_SIZE_LARGER SMALLER:0,FONT_SIZE_SMALLER IDENT:) LENGTH_UNIT:( UNIT_PX:FONT_SIZE_DIMENSION DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+font_size:CSS_PROP_FONT_SIZE IDENT:( INHERIT: XX_SMALL:0,FONT_SIZE_XX_SMALL X_SMALL:0,FONT_SIZE_X_SMALL SMALL:0,FONT_SIZE_SMALL MEDIUM:0,FONT_SIZE_MEDIUM LARGE:0,FONT_SIZE_LARGE X_LARGE:0,FONT_SIZE_X_LARGE XX_LARGE:0,FONT_SIZE_XX_LARGE LARGER:0,FONT_SIZE_LARGER SMALLER:0,FONT_SIZE_SMALLER IDENT:) CALC:( UNIT_PX:FONT_SIZE_CALC CALC:) LENGTH_UNIT:( UNIT_PX:FONT_SIZE_DIMENSION DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
font_style:CSS_PROP_FONT_STYLE IDENT:( INHERIT: NORMAL:0,FONT_STYLE_NORMAL ITALIC:0,FONT_STYLE_ITALIC OBLIQUE:0,FONT_STYLE_OBLIQUE IDENT:)
font_variant:CSS_PROP_FONT_VARIANT IDENT:( INHERIT: NORMAL:0,FONT_VARIANT_NORMAL SMALL_CAPS:0,FONT_VARIANT_SMALL_CAPS IDENT:)
-height:CSS_PROP_HEIGHT IDENT:( INHERIT: AUTO:0,HEIGHT_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+height:CSS_PROP_HEIGHT IDENT:( INHERIT: AUTO:0,HEIGHT_AUTO IDENT:) CALC:( UNIT_PX:HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-letter_spacing:CSS_PROP_LETTER_SPACING IDENT:( INHERIT: NORMAL:0,LETTER_SPACING_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:LETTER_SPACING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
+letter_spacing:CSS_PROP_LETTER_SPACING IDENT:( INHERIT: NORMAL:0,LETTER_SPACING_NORMAL IDENT:) CALC:( UNIT_PX:LETTER_SPACING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:LETTER_SPACING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
-line_height:CSS_PROP_LINE_HEIGHT IDENT:( INHERIT: NORMAL:0,LINE_HEIGHT_NORMAL IDENT:) NUMBER:( false:LINE_HEIGHT_NUMBER RANGE:num<0 NUMBER:) LENGTH_UNIT:( UNIT_PX:LINE_HEIGHT_DIMENSION DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+line_height:CSS_PROP_LINE_HEIGHT IDENT:( INHERIT: NORMAL:0,LINE_HEIGHT_NORMAL IDENT:) CALC:( ANY:LINE_HEIGHT_CALC CALC:) NUMBER:( false:LINE_HEIGHT_NUMBER RANGE:num<0 NUMBER:) LENGTH_UNIT:( UNIT_PX:LINE_HEIGHT_DIMENSION DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
border_top:BORDER_SIDE_TOP WRAP:css__parse_border_side
border_bottom:BORDER_SIDE_BOTTOM WRAP:css__parse_border_side
border_left:BORDER_SIDE_LEFT WRAP:css__parse_border_side
border_right:BORDER_SIDE_RIGHT WRAP:css__parse_border_side
-max_height:CSS_PROP_MAX_HEIGHT IDENT:( INHERIT: NONE:0,MAX_HEIGHT_NONE IDENT:) LENGTH_UNIT:( UNIT_PX:MAX_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+max_height:CSS_PROP_MAX_HEIGHT IDENT:( INHERIT: NONE:0,MAX_HEIGHT_NONE IDENT:) CALC:( UNIT_PX:MAX_HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MAX_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-max_width:CSS_PROP_MAX_WIDTH IDENT:( INHERIT: NONE:0,MAX_WIDTH_NONE IDENT:) LENGTH_UNIT:( UNIT_PX:MAX_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+max_width:CSS_PROP_MAX_WIDTH IDENT:( INHERIT: NONE:0,MAX_WIDTH_NONE IDENT:) CALC:( UNIT_PX:MAX_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MAX_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-min_height:CSS_PROP_MIN_HEIGHT IDENT:( INHERIT: AUTO:0,MIN_HEIGHT_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+min_height:CSS_PROP_MIN_HEIGHT IDENT:( INHERIT: AUTO:0,MIN_HEIGHT_AUTO IDENT:) CALC:( UNIT_PX:MIN_HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-min_width:CSS_PROP_MIN_WIDTH IDENT:( INHERIT: AUTO:0,MIN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+min_width:CSS_PROP_MIN_WIDTH IDENT:( INHERIT: AUTO:0,MIN_WIDTH_AUTO IDENT:) CALC:( UNIT_PX:MIN_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
color:CSS_PROP_COLOR IDENT:INHERIT COLOR:COLOR_SET
#generic for padding_{top, bottom, left, right}.c
-padding_side:op GENERIC: IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:PADDING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+padding_side:op GENERIC: IDENT:INHERIT CALC:( UNIT_PX:PADDING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:PADDING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
padding_bottom:CSS_PROP_PADDING_BOTTOM WRAP:css__parse_padding_side
padding_left:CSS_PROP_PADDING_LEFT WRAP:css__parse_padding_side
@@ -59,7 +66,7 @@ padding_right:CSS_PROP_PADDING_RIGHT WRAP:css__parse_padding_side
#generic for margin_{top, bottom, left, right}.c
-margin_side:op GENERIC IDENT:( INHERIT: AUTO:0,MARGIN_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MARGIN_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
+margin_side:op GENERIC IDENT:( INHERIT: AUTO:0,MARGIN_AUTO IDENT:) CALC:( UNIT_PX:MARGIN_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MARGIN_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
margin_top:CSS_PROP_MARGIN_TOP WRAP:css__parse_margin_side
margin_bottom:CSS_PROP_MARGIN_BOTTOM WRAP:css__parse_margin_side
@@ -67,7 +74,7 @@ margin_left:CSS_PROP_MARGIN_LEFT WRAP:css__parse_margin_side
margin_right:CSS_PROP_MARGIN_RIGHT WRAP:css__parse_margin_side
#generic for {top, bottom, left, right}.c
-side:op GENERIC: IDENT:( INHERIT: AUTO:0,BOTTOM_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:BOTTOM_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
+side:op GENERIC: IDENT:( INHERIT: AUTO:0,BOTTOM_AUTO IDENT:) CALC:( UNIT_PX:BOTTOM_CALC CALC:) LENGTH_UNIT:( UNIT_PX:BOTTOM_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
top:CSS_PROP_TOP WRAP:css__parse_side
bottom:CSS_PROP_BOTTOM WRAP:css__parse_side
@@ -76,7 +83,7 @@ right:CSS_PROP_RIGHT WRAP:css__parse_side
#generic for border_{top, bottom, left, right}_width.c
-border_side_width:op GENERIC: IDENT:( INHERIT: THIN:0,BORDER_WIDTH_THIN MEDIUM:0,BORDER_WIDTH_MEDIUM THICK:0,BORDER_WIDTH_THICK IDENT:) LENGTH_UNIT:( UNIT_PX:BORDER_WIDTH_SET DISALLOW:unit==UNIT_PCT||unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+border_side_width:op GENERIC: IDENT:( INHERIT: THIN:0,BORDER_WIDTH_THIN MEDIUM:0,BORDER_WIDTH_MEDIUM THICK:0,BORDER_WIDTH_THICK IDENT:) CALC:( UNIT_PX:BORDER_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:BORDER_WIDTH_SET DISALLOW:unit==UNIT_PCT||unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
border_top_width:CSS_PROP_BORDER_TOP_WIDTH WRAP:css__parse_border_side_width
border_bottom_width:CSS_PROP_BORDER_BOTTOM_WIDTH WRAP:css__parse_border_side_width
@@ -120,7 +127,7 @@ list_style_image:CSS_PROP_LIST_STYLE_IMAGE IDENT:( INHERIT: NONE:0,LIST_STYLE_IM
list_style_position:CSS_PROP_LIST_STYLE_POSITION IDENT:( INHERIT: INSIDE:0,LIST_STYLE_POSITION_INSIDE OUTSIDE:0,LIST_STYLE_POSITION_OUTSIDE IDENT:)
-orphans:CSS_PROP_ORPHANS IDENT:INHERIT NUMBER:( true:ORPHANS_SET RANGE:num<0 NUMBER:)
+orphans:CSS_PROP_ORPHANS IDENT:INHERIT CALC:( NUMBER:ORPHANS_CALC CALC:) NUMBER:( true:ORPHANS_SET RANGE:num<0 NUMBER:)
outline_color:CSS_PROP_OUTLINE_COLOR IDENT:( INHERIT: INVERT:0,OUTLINE_COLOR_INVERT IDENT:) COLOR:OUTLINE_COLOR_SET
@@ -140,17 +147,17 @@ page_break_before:CSS_PROP_PAGE_BREAK_BEFORE IDENT:( INHERIT: AUTO:0,PAGE_BREAK_
page_break_inside:CSS_PROP_PAGE_BREAK_INSIDE IDENT:( INHERIT: AUTO:0,PAGE_BREAK_INSIDE_AUTO AVOID:0,PAGE_BREAK_INSIDE_AVOID IDENT:)
-pause_after:CSS_PROP_PAUSE_AFTER IDENT:INHERIT LENGTH_UNIT:( UNIT_S:PAUSE_AFTER_SET DISALLOW:(unit&UNIT_TIME)==false&&(unit&UNIT_PCT)==false RANGE:<0 LENGTH_UNIT:)
+pause_after:CSS_PROP_PAUSE_AFTER IDENT:INHERIT CALC:( UNIT_S:PAUSE_AFTER_CALC CALC:) LENGTH_UNIT:( UNIT_S:PAUSE_AFTER_SET DISALLOW:(unit&UNIT_TIME)==false&&(unit&UNIT_PCT)==false RANGE:<0 LENGTH_UNIT:)
-pause_before:CSS_PROP_PAUSE_BEFORE IDENT:INHERIT LENGTH_UNIT:( UNIT_S:PAUSE_BEFORE_SET DISALLOW:(unit&UNIT_TIME)==false&&(unit&UNIT_PCT)==false RANGE:<0 LENGTH_UNIT:)
+pause_before:CSS_PROP_PAUSE_BEFORE IDENT:INHERIT CALC:( UNIT_S:PAUSE_BEFORE_CALC CALC:) LENGTH_UNIT:( UNIT_S:PAUSE_BEFORE_SET DISALLOW:(unit&UNIT_TIME)==false&&(unit&UNIT_PCT)==false RANGE:<0 LENGTH_UNIT:)
-pitch:CSS_PROP_PITCH IDENT:( INHERIT: X_LOW:0,PITCH_X_LOW LOW:0,PITCH_LOW MEDIUM:0,PITCH_MEDIUM HIGH:0,PITCH_HIGH X_HIGH:0,PITCH_X_HIGH IDENT:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY ALLOW:unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+pitch:CSS_PROP_PITCH IDENT:( INHERIT: X_LOW:0,PITCH_X_LOW LOW:0,PITCH_LOW MEDIUM:0,PITCH_MEDIUM HIGH:0,PITCH_HIGH X_HIGH:0,PITCH_X_HIGH IDENT:) CALC:( UNIT_HZ:PITCH_CALC CALC:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY ALLOW:unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-pitch_range:CSS_PROP_PITCH_RANGE IDENT:INHERIT NUMBER:( false:PITCH_RANGE_SET RANGE:num<0||num>F_100 NUMBER:)
+pitch_range:CSS_PROP_PITCH_RANGE IDENT:INHERIT CALC:( NUMBER:PITCH_RANGE_CALC CALC:) NUMBER:( false:PITCH_RANGE_SET RANGE:num<0||num>F_100 NUMBER:)
position:CSS_PROP_POSITION IDENT:( INHERIT: LIBCSS_STATIC:0,POSITION_STATIC RELATIVE:0,POSITION_RELATIVE ABSOLUTE:0,POSITION_ABSOLUTE FIXED:0,POSITION_FIXED IDENT:)
-richness:CSS_PROP_RICHNESS IDENT:INHERIT NUMBER:( false:RICHNESS_SET RANGE:num<0||num>F_100 NUMBER:)
+richness:CSS_PROP_RICHNESS IDENT:INHERIT CALC:( NUMBER:RICHNESS_CALC CALC:) NUMBER:( false:RICHNESS_SET RANGE:num<0||num>F_100 NUMBER:)
speak:CSS_PROP_SPEAK IDENT:( INHERIT: NORMAL:0,SPEAK_NORMAL NONE:0,SPEAK_NONE SPELL_OUT:0,SPEAK_SPELL_OUT IDENT:)
@@ -160,36 +167,36 @@ speak_numeral:CSS_PROP_SPEAK_NUMERAL IDENT:( INHERIT: DIGITS:0,SPEAK_NUMERAL_DIG
speak_punctuation:CSS_PROP_SPEAK_PUNCTUATION IDENT:( INHERIT: CODE:0,SPEAK_PUNCTUATION_CODE NONE:0,SPEAK_PUNCTUATION_NONE IDENT:)
-speech_rate:CSS_PROP_SPEECH_RATE IDENT:( INHERIT: X_SLOW:0,SPEECH_RATE_X_SLOW SLOW:0,SPEECH_RATE_SLOW MEDIUM:0,SPEECH_RATE_MEDIUM FAST:0,SPEECH_RATE_FAST X_FAST:0,SPEECH_RATE_X_FAST FASTER:0,SPEECH_RATE_FASTER SLOWER:0,SPEECH_RATE_SLOWER IDENT:) NUMBER:( false:SPEECH_RATE_SET RANGE:num<0 NUMBER:)
+speech_rate:CSS_PROP_SPEECH_RATE IDENT:( INHERIT: X_SLOW:0,SPEECH_RATE_X_SLOW SLOW:0,SPEECH_RATE_SLOW MEDIUM:0,SPEECH_RATE_MEDIUM FAST:0,SPEECH_RATE_FAST X_FAST:0,SPEECH_RATE_X_FAST FASTER:0,SPEECH_RATE_FASTER SLOWER:0,SPEECH_RATE_SLOWER IDENT:) CALC:( NUMBER:SPEECH_RATE_CALC CALC:) NUMBER:( false:SPEECH_RATE_SET RANGE:num<0 NUMBER:)
-stress:CSS_PROP_STRESS IDENT:INHERIT NUMBER:( false:STRESS_SET RANGE:num<0||num>INTTOFIX(100) NUMBER:)
+stress:CSS_PROP_STRESS IDENT:INHERIT CALC:( NUMBER:STRESS_CALC CALC:) NUMBER:( false:STRESS_SET RANGE:num<0||num>INTTOFIX(100) NUMBER:)
table_layout:CSS_PROP_TABLE_LAYOUT IDENT:( INHERIT: AUTO:0,TABLE_LAYOUT_AUTO FIXED:0,TABLE_LAYOUT_FIXED IDENT:)
text_align:CSS_PROP_TEXT_ALIGN IDENT:( INHERIT: LEFT:0,TEXT_ALIGN_LEFT RIGHT:0,TEXT_ALIGN_RIGHT CENTER:0,TEXT_ALIGN_CENTER JUSTIFY:0,TEXT_ALIGN_JUSTIFY LIBCSS_LEFT:0,TEXT_ALIGN_LIBCSS_LEFT LIBCSS_CENTER:0,TEXT_ALIGN_LIBCSS_CENTER LIBCSS_RIGHT:0,TEXT_ALIGN_LIBCSS_RIGHT IDENT:)
-text_indent:CSS_PROP_TEXT_INDENT IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:TEXT_INDENT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
+text_indent:CSS_PROP_TEXT_INDENT IDENT:INHERIT CALC:( UNIT_PX:TEXT_INDENT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:TEXT_INDENT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
text_transform:CSS_PROP_TEXT_TRANSFORM IDENT:( INHERIT: CAPITALIZE:0,TEXT_TRANSFORM_CAPITALIZE UPPERCASE:0,TEXT_TRANSFORM_UPPERCASE LOWERCASE:0,TEXT_TRANSFORM_LOWERCASE NONE:0,TEXT_TRANSFORM_NONE IDENT:)
unicode_bidi:CSS_PROP_UNICODE_BIDI IDENT:( INHERIT: NORMAL:0,UNICODE_BIDI_NORMAL EMBED:0,UNICODE_BIDI_EMBED BIDI_OVERRIDE:0,UNICODE_BIDI_BIDI_OVERRIDE IDENT:)
-vertical_align:CSS_PROP_VERTICAL_ALIGN IDENT:( INHERIT: BASELINE:0,VERTICAL_ALIGN_BASELINE SUB:0,VERTICAL_ALIGN_SUB SUPER:0,VERTICAL_ALIGN_SUPER TOP:0,VERTICAL_ALIGN_TOP TEXT_TOP:0,VERTICAL_ALIGN_TEXT_TOP MIDDLE:0,VERTICAL_ALIGN_MIDDLE BOTTOM:0,VERTICAL_ALIGN_BOTTOM TEXT_BOTTOM:0,VERTICAL_ALIGN_TEXT_BOTTOM IDENT:) LENGTH_UNIT:( UNIT_PX:VERTICAL_ALIGN_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
+vertical_align:CSS_PROP_VERTICAL_ALIGN IDENT:( INHERIT: BASELINE:0,VERTICAL_ALIGN_BASELINE SUB:0,VERTICAL_ALIGN_SUB SUPER:0,VERTICAL_ALIGN_SUPER TOP:0,VERTICAL_ALIGN_TOP TEXT_TOP:0,VERTICAL_ALIGN_TEXT_TOP MIDDLE:0,VERTICAL_ALIGN_MIDDLE BOTTOM:0,VERTICAL_ALIGN_BOTTOM TEXT_BOTTOM:0,VERTICAL_ALIGN_TEXT_BOTTOM IDENT:) CALC:( UNIT_PX:VERTICAL_ALIGN_CALC CALC:) LENGTH_UNIT:( UNIT_PX:VERTICAL_ALIGN_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
visibility:CSS_PROP_VISIBILITY IDENT:( INHERIT: VISIBLE:0,VISIBILITY_VISIBLE HIDDEN:0,VISIBILITY_HIDDEN COLLAPSE:0,VISIBILITY_COLLAPSE IDENT:)
-volume:CSS_PROP_VOLUME IDENT:( INHERIT: SILENT:0,VOLUME_SILENT X_SOFT:0,VOLUME_X_SOFT SOFT:0,VOLUME_SOFT MEDIUM:0,VOLUME_MEDIUM LOUD:0,VOLUME_LOUD X_LOUD:0,VOLUME_X_LOUD IDENT:) NUMBER:( false:VOLUME_NUMBER RANGE:num<0||num>F_100 NUMBER:) LENGTH_UNIT:( UNIT_PX:VOLUME_DIMENSION ALLOW:unit&UNIT_PCT RANGE:<0 LENGTH_UNIT:)
+volume:CSS_PROP_VOLUME IDENT:( INHERIT: SILENT:0,VOLUME_SILENT X_SOFT:0,VOLUME_X_SOFT SOFT:0,VOLUME_SOFT MEDIUM:0,VOLUME_MEDIUM LOUD:0,VOLUME_LOUD X_LOUD:0,VOLUME_X_LOUD IDENT:) CALC:( ANY:VOLUME_CALC CALC:) NUMBER:( false:VOLUME_NUMBER RANGE:num<0||num>F_100 NUMBER:) LENGTH_UNIT:( UNIT_PX:VOLUME_DIMENSION ALLOW:unit&UNIT_PCT RANGE:<0 LENGTH_UNIT:)
white_space:CSS_PROP_WHITE_SPACE IDENT:( INHERIT: NORMAL:0,WHITE_SPACE_NORMAL PRE:0,WHITE_SPACE_PRE NOWRAP:0,WHITE_SPACE_NOWRAP PRE_WRAP:0,WHITE_SPACE_PRE_WRAP PRE_LINE:0,WHITE_SPACE_PRE_LINE IDENT:)
-widows:CSS_PROP_WIDOWS IDENT:INHERIT NUMBER:( true:WIDOWS_SET RANGE:num<0 NUMBER:)
+widows:CSS_PROP_WIDOWS IDENT:INHERIT CALC:( NUMBER:WIDOWS_CALC CALC:) NUMBER:( true:WIDOWS_SET RANGE:num<0 NUMBER:)
-width:CSS_PROP_WIDTH IDENT:( INHERIT: AUTO:0,WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+width:CSS_PROP_WIDTH IDENT:( INHERIT: AUTO:0,WIDTH_AUTO IDENT:) CALC:( UNIT_PX:WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-word_spacing:CSS_PROP_WORD_SPACING IDENT:( INHERIT: NORMAL:0,WORD_SPACING_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:WORD_SPACING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
+word_spacing:CSS_PROP_WORD_SPACING IDENT:( INHERIT: NORMAL:0,WORD_SPACING_NORMAL IDENT:) CALC:( UNIT_PX:WORD_SPACING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:WORD_SPACING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
-z_index:CSS_PROP_Z_INDEX IDENT:( INHERIT: AUTO:0,Z_INDEX_AUTO IDENT:) NUMBER:( true:Z_INDEX_SET NUMBER:)
+z_index:CSS_PROP_Z_INDEX IDENT:( INHERIT: AUTO:0,Z_INDEX_AUTO IDENT:) CALC:( NUMBER:Z_INDEX_CALC CALC:) NUMBER:( true:Z_INDEX_SET NUMBER:)
break_after:CSS_PROP_BREAK_AFTER IDENT:( INHERIT: AUTO:0,BREAK_AFTER_AUTO ALWAYS:0,BREAK_AFTER_ALWAYS AVOID:0,BREAK_AFTER_AVOID LEFT:0,BREAK_AFTER_LEFT RIGHT:0,BREAK_AFTER_RIGHT PAGE:0,BREAK_AFTER_PAGE COLUMN:0,BREAK_AFTER_COLUMN AVOID_PAGE:0,BREAK_AFTER_AVOID_PAGE AVOID_COLUMN:0,BREAK_AFTER_AVOID_COLUMN IDENT:)
@@ -198,11 +205,11 @@ break_before:CSS_PROP_BREAK_BEFORE IDENT:( INHERIT: AUTO:0,BREAK_BEFORE_AUTO ALW
break_inside:CSS_PROP_BREAK_INSIDE IDENT:( INHERIT: AUTO:0,BREAK_INSIDE_AUTO AVOID:0,BREAK_INSIDE_AVOID AVOID_PAGE:0,BREAK_INSIDE_AVOID_PAGE AVOID_COLUMN:0,BREAK_INSIDE_AVOID_COLUMN IDENT:)
-column_count:CSS_PROP_COLUMN_COUNT IDENT:( INHERIT: AUTO:0,COLUMN_COUNT_AUTO IDENT:) NUMBER:( true:COLUMN_COUNT_SET RANGE:num<0 NUMBER:)
+column_count:CSS_PROP_COLUMN_COUNT IDENT:( INHERIT: AUTO:0,COLUMN_COUNT_AUTO IDENT: CALC:( NUMBER:COLUMN_COUNT_CALC CALC:)) NUMBER:( true:COLUMN_COUNT_SET RANGE:num<0 NUMBER:)
column_fill:CSS_PROP_COLUMN_FILL IDENT:( INHERIT: BALANCE:0,COLUMN_FILL_BALANCE AUTO:0,COLUMN_FILL_AUTO IDENT:)
-column_gap:CSS_PROP_COLUMN_GAP IDENT:( INHERIT: NORMAL:0,COLUMN_GAP_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_GAP_SET RANGE:<0 DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
+column_gap:CSS_PROP_COLUMN_GAP IDENT:( INHERIT: NORMAL:0,COLUMN_GAP_NORMAL IDENT:) CALC:( UNIT_PX:COLUMN_GAP_CALC CALC:) LENGTH_UNIT:( UNIT_PX:COLUMN_GAP_SET RANGE:<0 DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
column_rule_color:CSS_PROP_COLUMN_RULE_COLOR IDENT:( INHERIT: IDENT:) COLOR:COLUMN_RULE_COLOR_SET
@@ -212,7 +219,7 @@ column_rule_width:CSS_PROP_COLUMN_RULE_WIDTH WRAP:css__parse_border_side_width
column_span:CSS_PROP_COLUMN_SPAN IDENT:( INHERIT: NONE:0,COLUMN_SPAN_NONE ALL:0,COLUMN_SPAN_ALL IDENT:)
-column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
+column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) CALC:( UNIT_PX:COLUMN_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
writing_mode:CSS_PROP_WRITING_MODE IDENT:( INHERIT: HORIZONTAL_TB:0,WRITING_MODE_HORIZONTAL_TB VERTICAL_RL:0,WRITING_MODE_VERTICAL_RL VERTICAL_LR:0,WRITING_MODE_VERTICAL_LR IDENT:)
@@ -224,16 +231,16 @@ align_items:CSS_PROP_ALIGN_ITEMS IDENT:( INHERIT: STRETCH:0,ALIGN_ITEMS_STRETCH
align_self:CSS_PROP_ALIGN_SELF IDENT:( INHERIT: STRETCH:0,ALIGN_SELF_STRETCH FLEX_START:0,ALIGN_SELF_FLEX_START FLEX_END:0,ALIGN_SELF_FLEX_END CENTER:0,ALIGN_SELF_CENTER BASELINE:0,ALIGN_SELF_BASELINE AUTO:0,ALIGN_SELF_AUTO IDENT:)
-flex_basis:CSS_PROP_FLEX_BASIS IDENT:( INHERIT: AUTO:0,FLEX_BASIS_AUTO CONTENT:0,FLEX_BASIS_CONTENT IDENT:) LENGTH_UNIT:( UNIT_PX:FLEX_BASIS_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+flex_basis:CSS_PROP_FLEX_BASIS IDENT:( INHERIT: AUTO:0,FLEX_BASIS_AUTO CONTENT:0,FLEX_BASIS_CONTENT IDENT:) CALC:( UNIT_PX:FLEX_BASIS_CALC CALC:) LENGTH_UNIT:( UNIT_PX:FLEX_BASIS_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
flex_direction:CSS_PROP_FLEX_DIRECTION IDENT:( INHERIT: ROW:0,FLEX_DIRECTION_ROW ROW_REVERSE:0,FLEX_DIRECTION_ROW_REVERSE COLUMN:0,FLEX_DIRECTION_COLUMN COLUMN_REVERSE:0,FLEX_DIRECTION_COLUMN_REVERSE IDENT:)
-flex_grow:CSS_PROP_FLEX_GROW IDENT:INHERIT NUMBER:( false:FLEX_GROW_SET RANGE:num<0 NUMBER:)
+flex_grow:CSS_PROP_FLEX_GROW IDENT:INHERIT CALC:( NUMBER:FLEX_GROW_CALC CALC:) NUMBER:( false:FLEX_GROW_SET RANGE:num<0 NUMBER:)
-flex_shrink:CSS_PROP_FLEX_SHRINK IDENT:INHERIT NUMBER:( false:FLEX_SHRINK_SET RANGE:num<0 NUMBER:)
+flex_shrink:CSS_PROP_FLEX_SHRINK IDENT:INHERIT CALC:( NUMBER:FLEX_SHRINK_CALC CALC:) NUMBER:( false:FLEX_SHRINK_SET RANGE:num<0 NUMBER:)
flex_wrap:CSS_PROP_FLEX_WRAP IDENT:( INHERIT: NOWRAP:0,FLEX_WRAP_NOWRAP WRAP_STRING:0,FLEX_WRAP_WRAP WRAP_REVERSE:0,FLEX_WRAP_WRAP_REVERSE IDENT:)
justify_content:CSS_PROP_JUSTIFY_CONTENT IDENT:( INHERIT: FLEX_START:0,JUSTIFY_CONTENT_FLEX_START FLEX_END:0,JUSTIFY_CONTENT_FLEX_END CENTER:0,JUSTIFY_CONTENT_CENTER SPACE_BETWEEN:0,JUSTIFY_CONTENT_SPACE_BETWEEN SPACE_AROUND:0,JUSTIFY_CONTENT_SPACE_AROUND SPACE_EVENLY:0,JUSTIFY_CONTENT_SPACE_EVENLY IDENT:)
-order:CSS_PROP_ORDER IDENT:INHERIT NUMBER:( true:ORDER_SET NUMBER:)
+order:CSS_PROP_ORDER IDENT:INHERIT CALC:( NUMBER:ORDER_CALC CALC:) NUMBER:( true:ORDER_SET NUMBER:)
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index b1864cb..11b7f72 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1351,9 +1351,9 @@ cleanup:
*
*
* calc(10px + (4rem / 2)) =>
- * U 10 px
- * U 4 rem
- * N 2
+ * V 10 px
+ * V 4 rem
+ * V 2 NUMBER
* /
* +
* =
@@ -1362,14 +1362,12 @@ cleanup:
static css_error
css__parse_calc_sum(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit);
+ css_style *result);
static css_error
css__parse_calc_value(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t default_unit)
+ css_style *result)
{
css_error error;
int orig_ctx = *ctx;
@@ -1377,7 +1375,7 @@ css__parse_calc_value(css_language *c,
token = parserutils_vector_iterate(vector, ctx);
if (tokenIsChar(token, '(')) {
- error = css__parse_calc_sum(c, vector, ctx, result, default_unit);
+ error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1396,13 +1394,13 @@ css__parse_calc_value(css_language *c,
uint32_t unit = 0;
*ctx = orig_ctx;
- error = css__parse_unit_specifier(c, vector, ctx, default_unit, &length, &unit);
+ error = css__parse_unit_specifier(c, vector, ctx, UNIT_CALC_NUMBER, &length, &unit);
if (error != CSS_OK) {
*ctx = orig_ctx;
return error;
}
- error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'U', length, unit);
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'V', length, unit);
}
break;
@@ -1422,8 +1420,7 @@ css__parse_calc_value(css_language *c,
static css_error
css__parse_calc_product(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit)
+ css_style *result)
{
css_error error = CSS_OK;
const css_token *token;
@@ -1431,7 +1428,7 @@ css__parse_calc_product(css_language *c,
/* First parse a value */
- error = css__parse_calc_value(c, vector, ctx, result, unit);
+ error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1455,33 +1452,10 @@ css__parse_calc_product(css_language *c,
/* Consume that * or / now */
token = parserutils_vector_iterate(vector, ctx);
- if (multiplication) {
- /* parse another value */
- error = css__parse_calc_value(c, vector, ctx, result, unit);
- if (error != CSS_OK)
- break;
- } else {
- css_fixed num;
- size_t consumed;
-
- token = parserutils_vector_iterate(vector, ctx);
- if (token->type != CSS_TOKEN_NUMBER) {
- error = CSS_INVALID;
- break;
- }
- num = css__number_from_lwc_string(token->idata, false, &consumed);
- if (consumed != lwc_string_length(token->idata)) {
- error = CSS_INVALID;
- break;
- }
-
- error = css__stylesheet_style_append(result, (css_code_t) 'N');
- if (error != CSS_OK)
- break;
- error = css__stylesheet_style_append(result, (css_code_t) num);
- if (error != CSS_OK)
- break;
- }
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result);
+ if (error != CSS_OK)
+ break;
/* emit the multiplication/division operator */
error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
@@ -1494,8 +1468,7 @@ css__parse_calc_product(css_language *c,
css_error
css__parse_calc_sum(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit)
+ css_style *result)
{
css_error error = CSS_OK;
const css_token *token;
@@ -1503,7 +1476,7 @@ css__parse_calc_sum(css_language *c,
/* First parse a product */
- error = css__parse_calc_product(c, vector, ctx, result, unit);
+ error = css__parse_calc_product(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1528,7 +1501,7 @@ css__parse_calc_sum(css_language *c,
token = parserutils_vector_iterate(vector, ctx);
/* parse another product */
- error = css__parse_calc_product(c, vector, ctx, result, unit);
+ error = css__parse_calc_product(c, vector, ctx, result);
if (error != CSS_OK)
break;
@@ -1570,8 +1543,10 @@ css_error css__parse_calc(css_language *c,
error = css__stylesheet_style_append(calc_style, property);
if (error != CSS_OK)
goto cleanup;
+
+ error = css__stylesheet_style_append(calc_style, (css_code_t) unit);
- error = css__parse_calc_sum(c, vector, ctx, calc_style, unit);
+ error = css__parse_calc_sum(c, vector, ctx, calc_style);
if (error != CSS_OK)
goto cleanup;
-----------------------------------------------------------------------
Summary of changes:
src/bytecode/bytecode.h | 4 ++
src/bytecode/opcodes.h | 37 ++++++++++++
src/parse/properties/css_property_parser_gen.c | 45 ++++++++++++--
src/parse/properties/properties.gen | 75 +++++++++++++-----------
src/parse/properties/utils.c | 65 +++++++-------------
5 files changed, 141 insertions(+), 85 deletions(-)
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 22703f7..2267542 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -66,6 +66,10 @@ typedef enum unit {
UNIT_DPI = (1 << 12) + 0,
UNIT_DPCM = (1 << 12) + 1,
UNIT_DPPX = (1 << 12) + 2,
+
+ /* These are special only to the CALC bytecodes */
+ UNIT_CALC_ANY = (1 << 20),
+ UNIT_CALC_NUMBER = (1 << 20) + 1,
} unit;
typedef uint32_t colour;
diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h
index 82bf75f..d728831 100644
--- a/src/bytecode/opcodes.h
+++ b/src/bytecode/opcodes.h
@@ -119,6 +119,7 @@ enum op_border_style {
};
enum op_border_width {
+ BORDER_WIDTH_CALC = 0x007f,
BORDER_WIDTH_SET = 0x0080,
BORDER_WIDTH_THIN = 0x0000,
BORDER_WIDTH_MEDIUM = 0x0001,
@@ -126,6 +127,7 @@ enum op_border_width {
};
enum op_bottom {
+ BOTTOM_CALC = 0x007f,
BOTTOM_SET = 0x0080,
BOTTOM_AUTO = 0x0000
};
@@ -198,6 +200,7 @@ enum op_color {
enum op_column_count {
COLUMN_COUNT_AUTO = 0x0000,
+ COLUMN_COUNT_CALC = 0x007f,
COLUMN_COUNT_SET = 0x0080
};
@@ -208,6 +211,7 @@ enum op_column_fill {
enum op_column_gap {
COLUMN_GAP_NORMAL = 0x0000,
+ COLUMN_GAP_CALC = 0x007f,
COLUMN_GAP_SET = 0x0080
};
@@ -231,6 +235,7 @@ enum op_column_rule_style {
};
enum op_column_rule_width {
+ COLUMN_RULE_WIDTH_CALC = BORDER_WIDTH_CALC,
COLUMN_RULE_WIDTH_SET = BORDER_WIDTH_SET,
COLUMN_RULE_WIDTH_THIN = BORDER_WIDTH_THIN,
COLUMN_RULE_WIDTH_MEDIUM = BORDER_WIDTH_MEDIUM,
@@ -244,6 +249,7 @@ enum op_column_span {
enum op_column_width {
COLUMN_WIDTH_AUTO = 0x0000,
+ COLUMN_WIDTH_CALC = 0x007f,
COLUMN_WIDTH_SET = 0x0080
};
@@ -352,6 +358,7 @@ enum op_empty_cells {
enum op_flex_basis {
FLEX_BASIS_AUTO = 0x0000,
FLEX_BASIS_CONTENT = 0x0001,
+ FLEX_BASIS_CALC = 0x007f,
FLEX_BASIS_SET = 0x0080
};
@@ -363,10 +370,12 @@ enum op_flex_direction {
};
enum op_flex_grow {
+ FLEX_GROW_CALC = 0x007f,
FLEX_GROW_SET = 0x0080
};
enum op_flex_shrink {
+ FLEX_SHRINK_CALC = 0x007f,
FLEX_SHRINK_SET = 0x0080
};
@@ -396,6 +405,7 @@ enum op_font_family {
};
enum op_font_size {
+ FONT_SIZE_CALC = 0x007f,
FONT_SIZE_DIMENSION = 0x0080,
FONT_SIZE_XX_SMALL = 0x0000,
@@ -437,6 +447,7 @@ enum op_font_weight {
};
enum op_height {
+ HEIGHT_CALC = 0x007f,
HEIGHT_SET = 0x0080,
HEIGHT_AUTO = 0x0000
};
@@ -451,16 +462,19 @@ enum op_justify_content {
};
enum op_left {
+ LEFT_CALC = BOTTOM_CALC,
LEFT_SET = BOTTOM_SET,
LEFT_AUTO = BOTTOM_AUTO
};
enum op_letter_spacing {
+ LETTER_SPACING_CALC = 0x007f,
LETTER_SPACING_SET = 0x0080,
LETTER_SPACING_NORMAL = 0x0000
};
enum op_line_height {
+ LINE_HEIGHT_CALC = 0x007f,
LINE_HEIGHT_NUMBER = 0x0080,
LINE_HEIGHT_DIMENSION = 0x0081,
LINE_HEIGHT_NORMAL = 0x0000
@@ -495,26 +509,31 @@ enum op_list_style_type {
};
enum op_margin {
+ MARGIN_CALC = 0x007f,
MARGIN_SET = 0x0080,
MARGIN_AUTO = 0x0000
};
enum op_max_height {
+ MAX_HEIGHT_CALC = 0x007f,
MAX_HEIGHT_SET = 0x0080,
MAX_HEIGHT_NONE = 0x0000
};
enum op_max_width {
+ MAX_WIDTH_CALC = 0x007f,
MAX_WIDTH_SET = 0x0080,
MAX_WIDTH_NONE = 0x0000
};
enum op_min_height {
+ MIN_HEIGHT_CALC = 0x007f,
MIN_HEIGHT_SET = 0x0080,
MIN_HEIGHT_AUTO = 0x0000
};
enum op_min_width {
+ MIN_WIDTH_CALC = 0x007f,
MIN_WIDTH_SET = 0x0080,
MIN_WIDTH_AUTO = 0x0000
};
@@ -524,10 +543,12 @@ enum op_opacity {
};
enum op_order {
+ ORDER_CALC = 0x007f,
ORDER_SET = 0x0080
};
enum op_orphans {
+ ORPHANS_CALC = 0x007f,
ORPHANS_SET = 0x0080
};
@@ -566,6 +587,7 @@ enum op_overflow {
};
enum op_padding {
+ PADDING_CALC = 0x007f,
PADDING_SET = 0x0080
};
@@ -591,18 +613,22 @@ enum op_page_break_inside {
};
enum op_pause_after {
+ PAUSE_AFTER_CALC = 0x007f,
PAUSE_AFTER_SET = 0x0080
};
enum op_pause_before {
+ PAUSE_BEFORE_CALC = 0x007f,
PAUSE_BEFORE_SET = 0x0080
};
enum op_pitch_range {
+ PITCH_RANGE_CALC = 0x007f,
PITCH_RANGE_SET = 0x0080
};
enum op_pitch {
+ PITCH_CALC = 0x007f,
PITCH_FREQUENCY = 0x0080,
PITCH_X_LOW = 0x0000,
@@ -636,6 +662,7 @@ enum op_quotes {
};
enum op_richness {
+ RICHNESS_CALC = 0x007f,
RICHNESS_SET = 0x0080
};
@@ -666,6 +693,7 @@ enum op_speak {
};
enum op_speech_rate {
+ SPEECH_RATE_CALC = 0x007f,
SPEECH_RATE_SET = 0x0080,
SPEECH_RATE_X_SLOW = 0x0000,
@@ -678,6 +706,7 @@ enum op_speech_rate {
};
enum op_stress {
+ STRESS_CALC = 0x007f,
STRESS_SET = 0x0080
};
@@ -706,6 +735,7 @@ enum op_text_decoration {
};
enum op_text_indent {
+ TEXT_INDENT_CALC = 0x007f,
TEXT_INDENT_SET = 0x0080
};
@@ -717,6 +747,7 @@ enum op_text_transform {
};
enum op_top {
+ TOP_CALC = BOTTOM_CALC,
TOP_SET = BOTTOM_SET,
TOP_AUTO = BOTTOM_AUTO
};
@@ -728,6 +759,7 @@ enum op_unicode_bidi {
};
enum op_vertical_align {
+ VERTICAL_ALIGN_CALC = 0x007f,
VERTICAL_ALIGN_SET = 0x0080,
VERTICAL_ALIGN_BASELINE = 0x0000,
@@ -758,6 +790,7 @@ enum op_voice_family {
};
enum op_volume {
+ VOLUME_CALC = 0x007f,
VOLUME_NUMBER = 0x0080,
VOLUME_DIMENSION = 0x0081,
@@ -778,16 +811,19 @@ enum op_white_space {
};
enum op_widows {
+ WIDOWS_CALC = 0x007f,
WIDOWS_SET = 0x0080
};
enum op_width {
+ WIDTH_CALC = 0x007f,
WIDTH_SET = 0x0080,
WIDTH_AUTO = 0x0000
};
enum op_word_spacing {
+ WORD_SPACING_CALC = 0x007f,
WORD_SPACING_SET = 0x0080,
WORD_SPACING_NORMAL = 0x0000
@@ -800,6 +836,7 @@ enum op_writing_mode {
};
enum op_z_index {
+ Z_INDEX_CALC = 0x007f,
Z_INDEX_SET = 0x0080,
Z_INDEX_AUTO = 0x0000
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 838f2b6..36a1daf 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -19,6 +19,12 @@
* list_style_position:CSS_PROP_LIST_STYLE_POSITION IDENT:( INHERIT: INSIDE:0,LIST_STYLE_POSITION_INSIDE OUTSIDE:0,LIST_STYLE_POSITION_OUTSIDE IDENT:)
*/
+typedef enum {
+ CALC_ANY,
+ CALC_NUMBER,
+ CALC_UNIT,
+} calc_kind;
+
struct keyval {
char *key;
char *val;
@@ -291,21 +297,34 @@ void output_color(FILE *outputf, struct keyval *parseid, struct keyval_list *kvl
parseid->val);
}
-void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
+void output_calc(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
{
struct keyval *ckv = kvlist->item[0];
- int ident_count;
+ const char *kind;
+
+ if (strcmp(ckv->key, "NUMBER") == 0)
+ kind = "UNIT_CALC_NUMBER";
+ else if (strcmp(ckv->key, "ANY") == 0)
+ kind = "UNIT_CALC_ANY";
+ else
+ kind = ckv->key;
fprintf(outputf,
"if ((token->type == CSS_TOKEN_IDENT) && "
"(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
" {\n"
- "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s /* _CALC */), %s);\n"
+ "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s), %s);\n"
"\t} else ",
parseid->val,
ckv->val,
- ckv->key
+ kind
);
+}
+
+void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
+{
+ struct keyval *ckv = kvlist->item[0];
+ int ident_count;
fprintf(outputf,
"{\n"
@@ -494,6 +513,7 @@ int main(int argc, char **argv)
struct keyval_list WRAP;
struct keyval_list NUMBER;
struct keyval_list COLOR;
+ struct keyval_list CALC;
if (argc < 2) {
@@ -526,6 +546,7 @@ int main(int argc, char **argv)
COLOR.count = 0;
LENGTH_UNIT.count = 0;
IDENT_LIST.count = 0;
+ CALC.count = 0;
curlist = &base;
@@ -541,7 +562,7 @@ int main(int argc, char **argv)
if (strcmp(rkv->key, "WRAP") == 0) {
WRAP.item[WRAP.count++] = rkv;
only_ident = false;
- } else if (strcmp(rkv->key, "NUMBER") == 0) {
+ } else if (curlist == &base && strcmp(rkv->key, "NUMBER") == 0) {
if (rkv->val[0] == '(') {
curlist = &NUMBER;
} else if (rkv->val[0] == ')') {
@@ -572,6 +593,14 @@ int main(int argc, char **argv)
}
only_ident = false;
do_token_check = false;
+ } else if (strcmp(rkv->key, "CALC") == 0) {
+ if (rkv->val[0] == '(') {
+ curlist = &CALC;
+ } else if (rkv->val[0] == ')') {
+ curlist = &base;
+ }
+ only_ident = false;
+ do_token_check = false;
} else if (strcmp(rkv->key, "COLOR") == 0) {
COLOR.item[COLOR.count++] = rkv;
do_token_check = false;
@@ -595,7 +624,7 @@ int main(int argc, char **argv)
/* header */
-output_header(outputf, descriptor, base.item[0], is_generic);
+ output_header(outputf, descriptor, base.item[0], is_generic);
if (WRAP.count > 0) {
output_wrap(outputf, base.item[0], &WRAP);
@@ -609,6 +638,10 @@ output_header(outputf, descriptor, base.item[0], is_generic);
if (URI.count > 0)
output_uri(outputf, base.item[0], &URI);
+ if (CALC.count > 0) {
+ output_calc(outputf, base.item[0], &CALC);
+ }
+
if (NUMBER.count > 0)
output_number(outputf, base.item[0], &NUMBER);
diff --git a/src/parse/properties/properties.gen b/src/parse/properties/properties.gen
index 61dcd5e..33df482 100644
--- a/src/parse/properties/properties.gen
+++ b/src/parse/properties/properties.gen
@@ -6,6 +6,13 @@
#property:CSS_PROP_ENUM IDENT:( INHERIT: IDENT:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY ALLOW: DISALLOW: RANGE:<0 LENGTH_UNIT:)
#property:CSS_PROP_ENUM WRAP:
+# When a property takes a NUMBER and/or LENGTH_UNIT you may add calc() support:
+# In the below, PROPERTY_FOO_CALC is the opcode enum for the set-but-calculated value bytecode.
+# e.g. HEIGHT_SET (for a LENGTH_UNIT) would be HEIGHT_CALC here.
+# CALC:( UNIT_??:PROPERTY_FOO_CALC CALC:) <-- When a default unit must be considered
+# CALC:( NUMBER:PROPERTY_FOO_CALC CALC:) <-- When a number must be produced (not a dimension)
+# CALC:( ANY:PROPERTY_FOO_CALC CALC:) <-- When a number or dimension is valid (e.g. line-height)
+
background_repeat:CSS_PROP_BACKGROUND_REPEAT IDENT:( INHERIT: NO_REPEAT:0,BACKGROUND_REPEAT_NO_REPEAT REPEAT_X:0,BACKGROUND_REPEAT_REPEAT_X REPEAT_Y:0,BACKGROUND_REPEAT_REPEAT_Y REPEAT:0,BACKGROUND_REPEAT_REPEAT IDENT:)
border_collapse:CSS_PROP_BORDER_COLLAPSE IDENT:( INHERIT: COLLAPSE:0,BORDER_COLLAPSE_COLLAPSE SEPARATE:0,BORDER_COLLAPSE_SEPARATE IDENT:)
@@ -22,35 +29,35 @@ empty_cells:CSS_PROP_EMPTY_CELLS IDENT:( INHERIT: SHOW:0,EMPTY_CELLS_SHOW HIDE:0
float:CSS_PROP_FLOAT IDENT:( INHERIT: LEFT:0,FLOAT_LEFT RIGHT:0,FLOAT_RIGHT NONE:0,FLOAT_NONE IDENT:)
-font_size:CSS_PROP_FONT_SIZE IDENT:( INHERIT: XX_SMALL:0,FONT_SIZE_XX_SMALL X_SMALL:0,FONT_SIZE_X_SMALL SMALL:0,FONT_SIZE_SMALL MEDIUM:0,FONT_SIZE_MEDIUM LARGE:0,FONT_SIZE_LARGE X_LARGE:0,FONT_SIZE_X_LARGE XX_LARGE:0,FONT_SIZE_XX_LARGE LARGER:0,FONT_SIZE_LARGER SMALLER:0,FONT_SIZE_SMALLER IDENT:) LENGTH_UNIT:( UNIT_PX:FONT_SIZE_DIMENSION DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+font_size:CSS_PROP_FONT_SIZE IDENT:( INHERIT: XX_SMALL:0,FONT_SIZE_XX_SMALL X_SMALL:0,FONT_SIZE_X_SMALL SMALL:0,FONT_SIZE_SMALL MEDIUM:0,FONT_SIZE_MEDIUM LARGE:0,FONT_SIZE_LARGE X_LARGE:0,FONT_SIZE_X_LARGE XX_LARGE:0,FONT_SIZE_XX_LARGE LARGER:0,FONT_SIZE_LARGER SMALLER:0,FONT_SIZE_SMALLER IDENT:) CALC:( UNIT_PX:FONT_SIZE_CALC CALC:) LENGTH_UNIT:( UNIT_PX:FONT_SIZE_DIMENSION DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
font_style:CSS_PROP_FONT_STYLE IDENT:( INHERIT: NORMAL:0,FONT_STYLE_NORMAL ITALIC:0,FONT_STYLE_ITALIC OBLIQUE:0,FONT_STYLE_OBLIQUE IDENT:)
font_variant:CSS_PROP_FONT_VARIANT IDENT:( INHERIT: NORMAL:0,FONT_VARIANT_NORMAL SMALL_CAPS:0,FONT_VARIANT_SMALL_CAPS IDENT:)
-height:CSS_PROP_HEIGHT IDENT:( INHERIT: AUTO:0,HEIGHT_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+height:CSS_PROP_HEIGHT IDENT:( INHERIT: AUTO:0,HEIGHT_AUTO IDENT:) CALC:( UNIT_PX:HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-letter_spacing:CSS_PROP_LETTER_SPACING IDENT:( INHERIT: NORMAL:0,LETTER_SPACING_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:LETTER_SPACING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
+letter_spacing:CSS_PROP_LETTER_SPACING IDENT:( INHERIT: NORMAL:0,LETTER_SPACING_NORMAL IDENT:) CALC:( UNIT_PX:LETTER_SPACING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:LETTER_SPACING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
-line_height:CSS_PROP_LINE_HEIGHT IDENT:( INHERIT: NORMAL:0,LINE_HEIGHT_NORMAL IDENT:) NUMBER:( false:LINE_HEIGHT_NUMBER RANGE:num<0 NUMBER:) LENGTH_UNIT:( UNIT_PX:LINE_HEIGHT_DIMENSION DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+line_height:CSS_PROP_LINE_HEIGHT IDENT:( INHERIT: NORMAL:0,LINE_HEIGHT_NORMAL IDENT:) CALC:( ANY:LINE_HEIGHT_CALC CALC:) NUMBER:( false:LINE_HEIGHT_NUMBER RANGE:num<0 NUMBER:) LENGTH_UNIT:( UNIT_PX:LINE_HEIGHT_DIMENSION DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
border_top:BORDER_SIDE_TOP WRAP:css__parse_border_side
border_bottom:BORDER_SIDE_BOTTOM WRAP:css__parse_border_side
border_left:BORDER_SIDE_LEFT WRAP:css__parse_border_side
border_right:BORDER_SIDE_RIGHT WRAP:css__parse_border_side
-max_height:CSS_PROP_MAX_HEIGHT IDENT:( INHERIT: NONE:0,MAX_HEIGHT_NONE IDENT:) LENGTH_UNIT:( UNIT_PX:MAX_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+max_height:CSS_PROP_MAX_HEIGHT IDENT:( INHERIT: NONE:0,MAX_HEIGHT_NONE IDENT:) CALC:( UNIT_PX:MAX_HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MAX_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-max_width:CSS_PROP_MAX_WIDTH IDENT:( INHERIT: NONE:0,MAX_WIDTH_NONE IDENT:) LENGTH_UNIT:( UNIT_PX:MAX_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+max_width:CSS_PROP_MAX_WIDTH IDENT:( INHERIT: NONE:0,MAX_WIDTH_NONE IDENT:) CALC:( UNIT_PX:MAX_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MAX_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-min_height:CSS_PROP_MIN_HEIGHT IDENT:( INHERIT: AUTO:0,MIN_HEIGHT_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+min_height:CSS_PROP_MIN_HEIGHT IDENT:( INHERIT: AUTO:0,MIN_HEIGHT_AUTO IDENT:) CALC:( UNIT_PX:MIN_HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-min_width:CSS_PROP_MIN_WIDTH IDENT:( INHERIT: AUTO:0,MIN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+min_width:CSS_PROP_MIN_WIDTH IDENT:( INHERIT: AUTO:0,MIN_WIDTH_AUTO IDENT:) CALC:( UNIT_PX:MIN_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
color:CSS_PROP_COLOR IDENT:INHERIT COLOR:COLOR_SET
#generic for padding_{top, bottom, left, right}.c
-padding_side:op GENERIC: IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:PADDING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+padding_side:op GENERIC: IDENT:INHERIT CALC:( UNIT_PX:PADDING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:PADDING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
padding_bottom:CSS_PROP_PADDING_BOTTOM WRAP:css__parse_padding_side
padding_left:CSS_PROP_PADDING_LEFT WRAP:css__parse_padding_side
@@ -59,7 +66,7 @@ padding_right:CSS_PROP_PADDING_RIGHT WRAP:css__parse_padding_side
#generic for margin_{top, bottom, left, right}.c
-margin_side:op GENERIC IDENT:( INHERIT: AUTO:0,MARGIN_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MARGIN_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
+margin_side:op GENERIC IDENT:( INHERIT: AUTO:0,MARGIN_AUTO IDENT:) CALC:( UNIT_PX:MARGIN_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MARGIN_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
margin_top:CSS_PROP_MARGIN_TOP WRAP:css__parse_margin_side
margin_bottom:CSS_PROP_MARGIN_BOTTOM WRAP:css__parse_margin_side
@@ -67,7 +74,7 @@ margin_left:CSS_PROP_MARGIN_LEFT WRAP:css__parse_margin_side
margin_right:CSS_PROP_MARGIN_RIGHT WRAP:css__parse_margin_side
#generic for {top, bottom, left, right}.c
-side:op GENERIC: IDENT:( INHERIT: AUTO:0,BOTTOM_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:BOTTOM_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
+side:op GENERIC: IDENT:( INHERIT: AUTO:0,BOTTOM_AUTO IDENT:) CALC:( UNIT_PX:BOTTOM_CALC CALC:) LENGTH_UNIT:( UNIT_PX:BOTTOM_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
top:CSS_PROP_TOP WRAP:css__parse_side
bottom:CSS_PROP_BOTTOM WRAP:css__parse_side
@@ -76,7 +83,7 @@ right:CSS_PROP_RIGHT WRAP:css__parse_side
#generic for border_{top, bottom, left, right}_width.c
-border_side_width:op GENERIC: IDENT:( INHERIT: THIN:0,BORDER_WIDTH_THIN MEDIUM:0,BORDER_WIDTH_MEDIUM THICK:0,BORDER_WIDTH_THICK IDENT:) LENGTH_UNIT:( UNIT_PX:BORDER_WIDTH_SET DISALLOW:unit==UNIT_PCT||unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+border_side_width:op GENERIC: IDENT:( INHERIT: THIN:0,BORDER_WIDTH_THIN MEDIUM:0,BORDER_WIDTH_MEDIUM THICK:0,BORDER_WIDTH_THICK IDENT:) CALC:( UNIT_PX:BORDER_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:BORDER_WIDTH_SET DISALLOW:unit==UNIT_PCT||unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
border_top_width:CSS_PROP_BORDER_TOP_WIDTH WRAP:css__parse_border_side_width
border_bottom_width:CSS_PROP_BORDER_BOTTOM_WIDTH WRAP:css__parse_border_side_width
@@ -120,7 +127,7 @@ list_style_image:CSS_PROP_LIST_STYLE_IMAGE IDENT:( INHERIT: NONE:0,LIST_STYLE_IM
list_style_position:CSS_PROP_LIST_STYLE_POSITION IDENT:( INHERIT: INSIDE:0,LIST_STYLE_POSITION_INSIDE OUTSIDE:0,LIST_STYLE_POSITION_OUTSIDE IDENT:)
-orphans:CSS_PROP_ORPHANS IDENT:INHERIT NUMBER:( true:ORPHANS_SET RANGE:num<0 NUMBER:)
+orphans:CSS_PROP_ORPHANS IDENT:INHERIT CALC:( NUMBER:ORPHANS_CALC CALC:) NUMBER:( true:ORPHANS_SET RANGE:num<0 NUMBER:)
outline_color:CSS_PROP_OUTLINE_COLOR IDENT:( INHERIT: INVERT:0,OUTLINE_COLOR_INVERT IDENT:) COLOR:OUTLINE_COLOR_SET
@@ -140,17 +147,17 @@ page_break_before:CSS_PROP_PAGE_BREAK_BEFORE IDENT:( INHERIT: AUTO:0,PAGE_BREAK_
page_break_inside:CSS_PROP_PAGE_BREAK_INSIDE IDENT:( INHERIT: AUTO:0,PAGE_BREAK_INSIDE_AUTO AVOID:0,PAGE_BREAK_INSIDE_AVOID IDENT:)
-pause_after:CSS_PROP_PAUSE_AFTER IDENT:INHERIT LENGTH_UNIT:( UNIT_S:PAUSE_AFTER_SET DISALLOW:(unit&UNIT_TIME)==false&&(unit&UNIT_PCT)==false RANGE:<0 LENGTH_UNIT:)
+pause_after:CSS_PROP_PAUSE_AFTER IDENT:INHERIT CALC:( UNIT_S:PAUSE_AFTER_CALC CALC:) LENGTH_UNIT:( UNIT_S:PAUSE_AFTER_SET DISALLOW:(unit&UNIT_TIME)==false&&(unit&UNIT_PCT)==false RANGE:<0 LENGTH_UNIT:)
-pause_before:CSS_PROP_PAUSE_BEFORE IDENT:INHERIT LENGTH_UNIT:( UNIT_S:PAUSE_BEFORE_SET DISALLOW:(unit&UNIT_TIME)==false&&(unit&UNIT_PCT)==false RANGE:<0 LENGTH_UNIT:)
+pause_before:CSS_PROP_PAUSE_BEFORE IDENT:INHERIT CALC:( UNIT_S:PAUSE_BEFORE_CALC CALC:) LENGTH_UNIT:( UNIT_S:PAUSE_BEFORE_SET DISALLOW:(unit&UNIT_TIME)==false&&(unit&UNIT_PCT)==false RANGE:<0 LENGTH_UNIT:)
-pitch:CSS_PROP_PITCH IDENT:( INHERIT: X_LOW:0,PITCH_X_LOW LOW:0,PITCH_LOW MEDIUM:0,PITCH_MEDIUM HIGH:0,PITCH_HIGH X_HIGH:0,PITCH_X_HIGH IDENT:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY ALLOW:unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+pitch:CSS_PROP_PITCH IDENT:( INHERIT: X_LOW:0,PITCH_X_LOW LOW:0,PITCH_LOW MEDIUM:0,PITCH_MEDIUM HIGH:0,PITCH_HIGH X_HIGH:0,PITCH_X_HIGH IDENT:) CALC:( UNIT_HZ:PITCH_CALC CALC:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY ALLOW:unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-pitch_range:CSS_PROP_PITCH_RANGE IDENT:INHERIT NUMBER:( false:PITCH_RANGE_SET RANGE:num<0||num>F_100 NUMBER:)
+pitch_range:CSS_PROP_PITCH_RANGE IDENT:INHERIT CALC:( NUMBER:PITCH_RANGE_CALC CALC:) NUMBER:( false:PITCH_RANGE_SET RANGE:num<0||num>F_100 NUMBER:)
position:CSS_PROP_POSITION IDENT:( INHERIT: LIBCSS_STATIC:0,POSITION_STATIC RELATIVE:0,POSITION_RELATIVE ABSOLUTE:0,POSITION_ABSOLUTE FIXED:0,POSITION_FIXED IDENT:)
-richness:CSS_PROP_RICHNESS IDENT:INHERIT NUMBER:( false:RICHNESS_SET RANGE:num<0||num>F_100 NUMBER:)
+richness:CSS_PROP_RICHNESS IDENT:INHERIT CALC:( NUMBER:RICHNESS_CALC CALC:) NUMBER:( false:RICHNESS_SET RANGE:num<0||num>F_100 NUMBER:)
speak:CSS_PROP_SPEAK IDENT:( INHERIT: NORMAL:0,SPEAK_NORMAL NONE:0,SPEAK_NONE SPELL_OUT:0,SPEAK_SPELL_OUT IDENT:)
@@ -160,36 +167,36 @@ speak_numeral:CSS_PROP_SPEAK_NUMERAL IDENT:( INHERIT: DIGITS:0,SPEAK_NUMERAL_DIG
speak_punctuation:CSS_PROP_SPEAK_PUNCTUATION IDENT:( INHERIT: CODE:0,SPEAK_PUNCTUATION_CODE NONE:0,SPEAK_PUNCTUATION_NONE IDENT:)
-speech_rate:CSS_PROP_SPEECH_RATE IDENT:( INHERIT: X_SLOW:0,SPEECH_RATE_X_SLOW SLOW:0,SPEECH_RATE_SLOW MEDIUM:0,SPEECH_RATE_MEDIUM FAST:0,SPEECH_RATE_FAST X_FAST:0,SPEECH_RATE_X_FAST FASTER:0,SPEECH_RATE_FASTER SLOWER:0,SPEECH_RATE_SLOWER IDENT:) NUMBER:( false:SPEECH_RATE_SET RANGE:num<0 NUMBER:)
+speech_rate:CSS_PROP_SPEECH_RATE IDENT:( INHERIT: X_SLOW:0,SPEECH_RATE_X_SLOW SLOW:0,SPEECH_RATE_SLOW MEDIUM:0,SPEECH_RATE_MEDIUM FAST:0,SPEECH_RATE_FAST X_FAST:0,SPEECH_RATE_X_FAST FASTER:0,SPEECH_RATE_FASTER SLOWER:0,SPEECH_RATE_SLOWER IDENT:) CALC:( NUMBER:SPEECH_RATE_CALC CALC:) NUMBER:( false:SPEECH_RATE_SET RANGE:num<0 NUMBER:)
-stress:CSS_PROP_STRESS IDENT:INHERIT NUMBER:( false:STRESS_SET RANGE:num<0||num>INTTOFIX(100) NUMBER:)
+stress:CSS_PROP_STRESS IDENT:INHERIT CALC:( NUMBER:STRESS_CALC CALC:) NUMBER:( false:STRESS_SET RANGE:num<0||num>INTTOFIX(100) NUMBER:)
table_layout:CSS_PROP_TABLE_LAYOUT IDENT:( INHERIT: AUTO:0,TABLE_LAYOUT_AUTO FIXED:0,TABLE_LAYOUT_FIXED IDENT:)
text_align:CSS_PROP_TEXT_ALIGN IDENT:( INHERIT: LEFT:0,TEXT_ALIGN_LEFT RIGHT:0,TEXT_ALIGN_RIGHT CENTER:0,TEXT_ALIGN_CENTER JUSTIFY:0,TEXT_ALIGN_JUSTIFY LIBCSS_LEFT:0,TEXT_ALIGN_LIBCSS_LEFT LIBCSS_CENTER:0,TEXT_ALIGN_LIBCSS_CENTER LIBCSS_RIGHT:0,TEXT_ALIGN_LIBCSS_RIGHT IDENT:)
-text_indent:CSS_PROP_TEXT_INDENT IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:TEXT_INDENT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
+text_indent:CSS_PROP_TEXT_INDENT IDENT:INHERIT CALC:( UNIT_PX:TEXT_INDENT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:TEXT_INDENT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
text_transform:CSS_PROP_TEXT_TRANSFORM IDENT:( INHERIT: CAPITALIZE:0,TEXT_TRANSFORM_CAPITALIZE UPPERCASE:0,TEXT_TRANSFORM_UPPERCASE LOWERCASE:0,TEXT_TRANSFORM_LOWERCASE NONE:0,TEXT_TRANSFORM_NONE IDENT:)
unicode_bidi:CSS_PROP_UNICODE_BIDI IDENT:( INHERIT: NORMAL:0,UNICODE_BIDI_NORMAL EMBED:0,UNICODE_BIDI_EMBED BIDI_OVERRIDE:0,UNICODE_BIDI_BIDI_OVERRIDE IDENT:)
-vertical_align:CSS_PROP_VERTICAL_ALIGN IDENT:( INHERIT: BASELINE:0,VERTICAL_ALIGN_BASELINE SUB:0,VERTICAL_ALIGN_SUB SUPER:0,VERTICAL_ALIGN_SUPER TOP:0,VERTICAL_ALIGN_TOP TEXT_TOP:0,VERTICAL_ALIGN_TEXT_TOP MIDDLE:0,VERTICAL_ALIGN_MIDDLE BOTTOM:0,VERTICAL_ALIGN_BOTTOM TEXT_BOTTOM:0,VERTICAL_ALIGN_TEXT_BOTTOM IDENT:) LENGTH_UNIT:( UNIT_PX:VERTICAL_ALIGN_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
+vertical_align:CSS_PROP_VERTICAL_ALIGN IDENT:( INHERIT: BASELINE:0,VERTICAL_ALIGN_BASELINE SUB:0,VERTICAL_ALIGN_SUB SUPER:0,VERTICAL_ALIGN_SUPER TOP:0,VERTICAL_ALIGN_TOP TEXT_TOP:0,VERTICAL_ALIGN_TEXT_TOP MIDDLE:0,VERTICAL_ALIGN_MIDDLE BOTTOM:0,VERTICAL_ALIGN_BOTTOM TEXT_BOTTOM:0,VERTICAL_ALIGN_TEXT_BOTTOM IDENT:) CALC:( UNIT_PX:VERTICAL_ALIGN_CALC CALC:) LENGTH_UNIT:( UNIT_PX:VERTICAL_ALIGN_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ LENGTH_UNIT:)
visibility:CSS_PROP_VISIBILITY IDENT:( INHERIT: VISIBLE:0,VISIBILITY_VISIBLE HIDDEN:0,VISIBILITY_HIDDEN COLLAPSE:0,VISIBILITY_COLLAPSE IDENT:)
-volume:CSS_PROP_VOLUME IDENT:( INHERIT: SILENT:0,VOLUME_SILENT X_SOFT:0,VOLUME_X_SOFT SOFT:0,VOLUME_SOFT MEDIUM:0,VOLUME_MEDIUM LOUD:0,VOLUME_LOUD X_LOUD:0,VOLUME_X_LOUD IDENT:) NUMBER:( false:VOLUME_NUMBER RANGE:num<0||num>F_100 NUMBER:) LENGTH_UNIT:( UNIT_PX:VOLUME_DIMENSION ALLOW:unit&UNIT_PCT RANGE:<0 LENGTH_UNIT:)
+volume:CSS_PROP_VOLUME IDENT:( INHERIT: SILENT:0,VOLUME_SILENT X_SOFT:0,VOLUME_X_SOFT SOFT:0,VOLUME_SOFT MEDIUM:0,VOLUME_MEDIUM LOUD:0,VOLUME_LOUD X_LOUD:0,VOLUME_X_LOUD IDENT:) CALC:( ANY:VOLUME_CALC CALC:) NUMBER:( false:VOLUME_NUMBER RANGE:num<0||num>F_100 NUMBER:) LENGTH_UNIT:( UNIT_PX:VOLUME_DIMENSION ALLOW:unit&UNIT_PCT RANGE:<0 LENGTH_UNIT:)
white_space:CSS_PROP_WHITE_SPACE IDENT:( INHERIT: NORMAL:0,WHITE_SPACE_NORMAL PRE:0,WHITE_SPACE_PRE NOWRAP:0,WHITE_SPACE_NOWRAP PRE_WRAP:0,WHITE_SPACE_PRE_WRAP PRE_LINE:0,WHITE_SPACE_PRE_LINE IDENT:)
-widows:CSS_PROP_WIDOWS IDENT:INHERIT NUMBER:( true:WIDOWS_SET RANGE:num<0 NUMBER:)
+widows:CSS_PROP_WIDOWS IDENT:INHERIT CALC:( NUMBER:WIDOWS_CALC CALC:) NUMBER:( true:WIDOWS_SET RANGE:num<0 NUMBER:)
-width:CSS_PROP_WIDTH IDENT:( INHERIT: AUTO:0,WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+width:CSS_PROP_WIDTH IDENT:( INHERIT: AUTO:0,WIDTH_AUTO IDENT:) CALC:( UNIT_PX:WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
-word_spacing:CSS_PROP_WORD_SPACING IDENT:( INHERIT: NORMAL:0,WORD_SPACING_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:WORD_SPACING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
+word_spacing:CSS_PROP_WORD_SPACING IDENT:( INHERIT: NORMAL:0,WORD_SPACING_NORMAL IDENT:) CALC:( UNIT_PX:WORD_SPACING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:WORD_SPACING_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
-z_index:CSS_PROP_Z_INDEX IDENT:( INHERIT: AUTO:0,Z_INDEX_AUTO IDENT:) NUMBER:( true:Z_INDEX_SET NUMBER:)
+z_index:CSS_PROP_Z_INDEX IDENT:( INHERIT: AUTO:0,Z_INDEX_AUTO IDENT:) CALC:( NUMBER:Z_INDEX_CALC CALC:) NUMBER:( true:Z_INDEX_SET NUMBER:)
break_after:CSS_PROP_BREAK_AFTER IDENT:( INHERIT: AUTO:0,BREAK_AFTER_AUTO ALWAYS:0,BREAK_AFTER_ALWAYS AVOID:0,BREAK_AFTER_AVOID LEFT:0,BREAK_AFTER_LEFT RIGHT:0,BREAK_AFTER_RIGHT PAGE:0,BREAK_AFTER_PAGE COLUMN:0,BREAK_AFTER_COLUMN AVOID_PAGE:0,BREAK_AFTER_AVOID_PAGE AVOID_COLUMN:0,BREAK_AFTER_AVOID_COLUMN IDENT:)
@@ -198,11 +205,11 @@ break_before:CSS_PROP_BREAK_BEFORE IDENT:( INHERIT: AUTO:0,BREAK_BEFORE_AUTO ALW
break_inside:CSS_PROP_BREAK_INSIDE IDENT:( INHERIT: AUTO:0,BREAK_INSIDE_AUTO AVOID:0,BREAK_INSIDE_AVOID AVOID_PAGE:0,BREAK_INSIDE_AVOID_PAGE AVOID_COLUMN:0,BREAK_INSIDE_AVOID_COLUMN IDENT:)
-column_count:CSS_PROP_COLUMN_COUNT IDENT:( INHERIT: AUTO:0,COLUMN_COUNT_AUTO IDENT:) NUMBER:( true:COLUMN_COUNT_SET RANGE:num<0 NUMBER:)
+column_count:CSS_PROP_COLUMN_COUNT IDENT:( INHERIT: AUTO:0,COLUMN_COUNT_AUTO IDENT: CALC:( NUMBER:COLUMN_COUNT_CALC CALC:)) NUMBER:( true:COLUMN_COUNT_SET RANGE:num<0 NUMBER:)
column_fill:CSS_PROP_COLUMN_FILL IDENT:( INHERIT: BALANCE:0,COLUMN_FILL_BALANCE AUTO:0,COLUMN_FILL_AUTO IDENT:)
-column_gap:CSS_PROP_COLUMN_GAP IDENT:( INHERIT: NORMAL:0,COLUMN_GAP_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_GAP_SET RANGE:<0 DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
+column_gap:CSS_PROP_COLUMN_GAP IDENT:( INHERIT: NORMAL:0,COLUMN_GAP_NORMAL IDENT:) CALC:( UNIT_PX:COLUMN_GAP_CALC CALC:) LENGTH_UNIT:( UNIT_PX:COLUMN_GAP_SET RANGE:<0 DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
column_rule_color:CSS_PROP_COLUMN_RULE_COLOR IDENT:( INHERIT: IDENT:) COLOR:COLUMN_RULE_COLOR_SET
@@ -212,7 +219,7 @@ column_rule_width:CSS_PROP_COLUMN_RULE_WIDTH WRAP:css__parse_border_side_width
column_span:CSS_PROP_COLUMN_SPAN IDENT:( INHERIT: NONE:0,COLUMN_SPAN_NONE ALL:0,COLUMN_SPAN_ALL IDENT:)
-column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
+column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) CALC:( UNIT_PX:COLUMN_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
writing_mode:CSS_PROP_WRITING_MODE IDENT:( INHERIT: HORIZONTAL_TB:0,WRITING_MODE_HORIZONTAL_TB VERTICAL_RL:0,WRITING_MODE_VERTICAL_RL VERTICAL_LR:0,WRITING_MODE_VERTICAL_LR IDENT:)
@@ -224,16 +231,16 @@ align_items:CSS_PROP_ALIGN_ITEMS IDENT:( INHERIT: STRETCH:0,ALIGN_ITEMS_STRETCH
align_self:CSS_PROP_ALIGN_SELF IDENT:( INHERIT: STRETCH:0,ALIGN_SELF_STRETCH FLEX_START:0,ALIGN_SELF_FLEX_START FLEX_END:0,ALIGN_SELF_FLEX_END CENTER:0,ALIGN_SELF_CENTER BASELINE:0,ALIGN_SELF_BASELINE AUTO:0,ALIGN_SELF_AUTO IDENT:)
-flex_basis:CSS_PROP_FLEX_BASIS IDENT:( INHERIT: AUTO:0,FLEX_BASIS_AUTO CONTENT:0,FLEX_BASIS_CONTENT IDENT:) LENGTH_UNIT:( UNIT_PX:FLEX_BASIS_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
+flex_basis:CSS_PROP_FLEX_BASIS IDENT:( INHERIT: AUTO:0,FLEX_BASIS_AUTO CONTENT:0,FLEX_BASIS_CONTENT IDENT:) CALC:( UNIT_PX:FLEX_BASIS_CALC CALC:) LENGTH_UNIT:( UNIT_PX:FLEX_BASIS_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:)
flex_direction:CSS_PROP_FLEX_DIRECTION IDENT:( INHERIT: ROW:0,FLEX_DIRECTION_ROW ROW_REVERSE:0,FLEX_DIRECTION_ROW_REVERSE COLUMN:0,FLEX_DIRECTION_COLUMN COLUMN_REVERSE:0,FLEX_DIRECTION_COLUMN_REVERSE IDENT:)
-flex_grow:CSS_PROP_FLEX_GROW IDENT:INHERIT NUMBER:( false:FLEX_GROW_SET RANGE:num<0 NUMBER:)
+flex_grow:CSS_PROP_FLEX_GROW IDENT:INHERIT CALC:( NUMBER:FLEX_GROW_CALC CALC:) NUMBER:( false:FLEX_GROW_SET RANGE:num<0 NUMBER:)
-flex_shrink:CSS_PROP_FLEX_SHRINK IDENT:INHERIT NUMBER:( false:FLEX_SHRINK_SET RANGE:num<0 NUMBER:)
+flex_shrink:CSS_PROP_FLEX_SHRINK IDENT:INHERIT CALC:( NUMBER:FLEX_SHRINK_CALC CALC:) NUMBER:( false:FLEX_SHRINK_SET RANGE:num<0 NUMBER:)
flex_wrap:CSS_PROP_FLEX_WRAP IDENT:( INHERIT: NOWRAP:0,FLEX_WRAP_NOWRAP WRAP_STRING:0,FLEX_WRAP_WRAP WRAP_REVERSE:0,FLEX_WRAP_WRAP_REVERSE IDENT:)
justify_content:CSS_PROP_JUSTIFY_CONTENT IDENT:( INHERIT: FLEX_START:0,JUSTIFY_CONTENT_FLEX_START FLEX_END:0,JUSTIFY_CONTENT_FLEX_END CENTER:0,JUSTIFY_CONTENT_CENTER SPACE_BETWEEN:0,JUSTIFY_CONTENT_SPACE_BETWEEN SPACE_AROUND:0,JUSTIFY_CONTENT_SPACE_AROUND SPACE_EVENLY:0,JUSTIFY_CONTENT_SPACE_EVENLY IDENT:)
-order:CSS_PROP_ORDER IDENT:INHERIT NUMBER:( true:ORDER_SET NUMBER:)
+order:CSS_PROP_ORDER IDENT:INHERIT CALC:( NUMBER:ORDER_CALC CALC:) NUMBER:( true:ORDER_SET NUMBER:)
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index b1864cb..11b7f72 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1351,9 +1351,9 @@ cleanup:
*
*
* calc(10px + (4rem / 2)) =>
- * U 10 px
- * U 4 rem
- * N 2
+ * V 10 px
+ * V 4 rem
+ * V 2 NUMBER
* /
* +
* =
@@ -1362,14 +1362,12 @@ cleanup:
static css_error
css__parse_calc_sum(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit);
+ css_style *result);
static css_error
css__parse_calc_value(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t default_unit)
+ css_style *result)
{
css_error error;
int orig_ctx = *ctx;
@@ -1377,7 +1375,7 @@ css__parse_calc_value(css_language *c,
token = parserutils_vector_iterate(vector, ctx);
if (tokenIsChar(token, '(')) {
- error = css__parse_calc_sum(c, vector, ctx, result, default_unit);
+ error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1396,13 +1394,13 @@ css__parse_calc_value(css_language *c,
uint32_t unit = 0;
*ctx = orig_ctx;
- error = css__parse_unit_specifier(c, vector, ctx, default_unit, &length, &unit);
+ error = css__parse_unit_specifier(c, vector, ctx, UNIT_CALC_NUMBER, &length, &unit);
if (error != CSS_OK) {
*ctx = orig_ctx;
return error;
}
- error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'U', length, unit);
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'V', length, unit);
}
break;
@@ -1422,8 +1420,7 @@ css__parse_calc_value(css_language *c,
static css_error
css__parse_calc_product(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit)
+ css_style *result)
{
css_error error = CSS_OK;
const css_token *token;
@@ -1431,7 +1428,7 @@ css__parse_calc_product(css_language *c,
/* First parse a value */
- error = css__parse_calc_value(c, vector, ctx, result, unit);
+ error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1455,33 +1452,10 @@ css__parse_calc_product(css_language *c,
/* Consume that * or / now */
token = parserutils_vector_iterate(vector, ctx);
- if (multiplication) {
- /* parse another value */
- error = css__parse_calc_value(c, vector, ctx, result, unit);
- if (error != CSS_OK)
- break;
- } else {
- css_fixed num;
- size_t consumed;
-
- token = parserutils_vector_iterate(vector, ctx);
- if (token->type != CSS_TOKEN_NUMBER) {
- error = CSS_INVALID;
- break;
- }
- num = css__number_from_lwc_string(token->idata, false, &consumed);
- if (consumed != lwc_string_length(token->idata)) {
- error = CSS_INVALID;
- break;
- }
-
- error = css__stylesheet_style_append(result, (css_code_t) 'N');
- if (error != CSS_OK)
- break;
- error = css__stylesheet_style_append(result, (css_code_t) num);
- if (error != CSS_OK)
- break;
- }
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result);
+ if (error != CSS_OK)
+ break;
/* emit the multiplication/division operator */
error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
@@ -1494,8 +1468,7 @@ css__parse_calc_product(css_language *c,
css_error
css__parse_calc_sum(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit)
+ css_style *result)
{
css_error error = CSS_OK;
const css_token *token;
@@ -1503,7 +1476,7 @@ css__parse_calc_sum(css_language *c,
/* First parse a product */
- error = css__parse_calc_product(c, vector, ctx, result, unit);
+ error = css__parse_calc_product(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1528,7 +1501,7 @@ css__parse_calc_sum(css_language *c,
token = parserutils_vector_iterate(vector, ctx);
/* parse another product */
- error = css__parse_calc_product(c, vector, ctx, result, unit);
+ error = css__parse_calc_product(c, vector, ctx, result);
if (error != CSS_OK)
break;
@@ -1570,8 +1543,10 @@ css_error css__parse_calc(css_language *c,
error = css__stylesheet_style_append(calc_style, property);
if (error != CSS_OK)
goto cleanup;
+
+ error = css__stylesheet_style_append(calc_style, (css_code_t) unit);
- error = css__parse_calc_sum(c, vector, ctx, calc_style, unit);
+ error = css__parse_calc_sum(c, vector, ctx, calc_style);
if (error != CSS_OK)
goto cleanup;
--
Cascading Style Sheets library
2 years, 11 months
libcss: branch tlsa/calc created. release/0.9.1-1-g62dc808
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/62dc80851eef3e256ef522...
...commit http://git.netsurf-browser.org/libcss.git/commit/62dc80851eef3e256ef522dd...
...tree http://git.netsurf-browser.org/libcss.git/tree/62dc80851eef3e256ef522dd68...
The branch, tlsa/calc has been created
at 62dc80851eef3e256ef522dd68346672f30b7375 (commit)
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=62dc80851eef3e256ef5...
commit 62dc80851eef3e256ef522dd68346672f30b7375
Author: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
Commit: Michael Drake <Michael Drake tlsa(a)netsurf-browser.org>
parse: Add calc() parser.
Co-authored-by: Michael Drake <michael.drake(a)netsurf-browser.org>
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 0e6ce72..838f2b6 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -296,6 +296,16 @@ void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_lis
struct keyval *ckv = kvlist->item[0];
int ident_count;
+ fprintf(outputf,
+ "if ((token->type == CSS_TOKEN_IDENT) && "
+ "(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
+ " {\n"
+ "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s /* _CALC */), %s);\n"
+ "\t} else ",
+ parseid->val,
+ ckv->val,
+ ckv->key
+ );
fprintf(outputf,
"{\n"
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 0e49853..b1864cb 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1334,3 +1334,268 @@ cleanup:
return error;
}
+/******************************************************************************/
+
+/* CALC
+ *
+ * calc( <calc-sum> )
+ *
+ * where
+ * <calc-sum> = <calc-product> [ [ '+' | '-' ] <calc-product> ]*
+ *
+ * where
+ * <calc-product> = <calc-value> [ '*' <calc-value> | '/' <number> ]*
+ *
+ * where
+ * <calc-value> = <number> | <dimension> | <percentage> | ( <calc-sum> )
+ *
+ *
+ * calc(10px + (4rem / 2)) =>
+ * U 10 px
+ * U 4 rem
+ * N 2
+ * /
+ * +
+ * =
+ */
+
+static css_error
+css__parse_calc_sum(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t unit);
+
+static css_error
+css__parse_calc_value(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t default_unit)
+{
+ css_error error;
+ int orig_ctx = *ctx;
+ const css_token *token;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (tokenIsChar(token, '(')) {
+ error = css__parse_calc_sum(c, vector, ctx, result, default_unit);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ token = parserutils_vector_peek(vector, *ctx);
+ if (!tokenIsChar(token, ')')) {
+ return CSS_INVALID;
+ }
+
+ } else switch (token->type) {
+ case CSS_TOKEN_NUMBER: /* Fall through */
+ case CSS_TOKEN_DIMENSION: /* Fall through */
+ case CSS_TOKEN_PERCENTAGE:
+ {
+ css_fixed length = 0;
+ uint32_t unit = 0;
+ *ctx = orig_ctx;
+
+ error = css__parse_unit_specifier(c, vector, ctx, default_unit, &length, &unit);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ return error;
+ }
+
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'U', length, unit);
+ }
+ break;
+
+ default:
+ error = CSS_INVALID;
+ break;
+ }
+
+ return error;
+}
+
+/* Both this, and css_parse_calc_sum must stop when it encounters a close-paren.
+ * If it hasn't had any useful tokens before that, it's an error. It does not
+ * need to restore ctx before returning an error but it does need to ensure that
+ * the close paren has not been consumed
+ */
+static css_error
+css__parse_calc_product(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t unit)
+{
+ css_error error = CSS_OK;
+ const css_token *token;
+ bool multiplication;
+
+
+ /* First parse a value */
+ error = css__parse_calc_value(c, vector, ctx, result, unit);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ do {
+ /* What is our next token? */
+ token = parserutils_vector_peek(vector, *ctx);
+ if (token == NULL) {
+ error = CSS_INVALID;
+ break;
+ } else if (tokenIsChar(token, ')'))
+ break;
+ else if (tokenIsChar(token, '*'))
+ multiplication = true;
+ else if (tokenIsChar(token, '/'))
+ multiplication = false;
+ else {
+ error = CSS_INVALID;
+ break;
+ }
+ /* Consume that * or / now */
+ token = parserutils_vector_iterate(vector, ctx);
+
+ if (multiplication) {
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result, unit);
+ if (error != CSS_OK)
+ break;
+ } else {
+ css_fixed num;
+ size_t consumed;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token->type != CSS_TOKEN_NUMBER) {
+ error = CSS_INVALID;
+ break;
+ }
+ num = css__number_from_lwc_string(token->idata, false, &consumed);
+ if (consumed != lwc_string_length(token->idata)) {
+ error = CSS_INVALID;
+ break;
+ }
+
+ error = css__stylesheet_style_append(result, (css_code_t) 'N');
+ if (error != CSS_OK)
+ break;
+ error = css__stylesheet_style_append(result, (css_code_t) num);
+ if (error != CSS_OK)
+ break;
+ }
+
+ /* emit the multiplication/division operator */
+ error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
+ } while (1);
+ /* We've fallen off, either we had an error or we're left with ')' */
+ return error;
+}
+
+
+css_error
+css__parse_calc_sum(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t unit)
+{
+ css_error error = CSS_OK;
+ const css_token *token;
+ bool addition;
+
+
+ /* First parse a product */
+ error = css__parse_calc_product(c, vector, ctx, result, unit);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ do {
+ /* What is our next token? */
+ token = parserutils_vector_peek(vector, *ctx);
+ if (token == NULL) {
+ error = CSS_INVALID;
+ break;
+ } else if (tokenIsChar(token, ')'))
+ break;
+ else if (tokenIsChar(token, '+'))
+ addition = true;
+ else if (tokenIsChar(token, '-'))
+ addition = false;
+ else {
+ error = CSS_INVALID;
+ break;
+ }
+ /* Consume that + or - now */
+ token = parserutils_vector_iterate(vector, ctx);
+
+ /* parse another product */
+ error = css__parse_calc_product(c, vector, ctx, result, unit);
+ if (error != CSS_OK)
+ break;
+
+ /* emit the addition/subtraction operator */
+ error = css__stylesheet_style_append(result, (css_code_t) (addition ? '+' : '-'));
+ } while (1);
+ /* We've fallen off, either we had an error or we're left with ')' */
+ return error;
+}
+
+/* Documented in utils.h */
+css_error css__parse_calc(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ css_code_t property,
+ uint32_t unit)
+{
+ int orig_ctx = *ctx;
+ const css_token *token;
+ css_error error = CSS_OK;
+ css_style *calc_style = NULL;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token == NULL) {
+ *ctx = orig_ctx;
+ return CSS_INVALID;
+ }
+
+ if (!tokenIsChar(token, '(')) {
+ /* If we don't get an open-paren, give up now */
+ *ctx = orig_ctx;
+ return CSS_INVALID;
+ }
+
+ error = css__stylesheet_style_create(c->sheet, &calc_style);
+ if (error != CSS_OK)
+ goto cleanup;
+
+ error = css__stylesheet_style_append(calc_style, property);
+ if (error != CSS_OK)
+ goto cleanup;
+
+ error = css__parse_calc_sum(c, vector, ctx, calc_style, unit);
+ if (error != CSS_OK)
+ goto cleanup;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (!tokenIsChar(token, ')')) {
+ /* If we don't get a close-paren, give up now */
+ error = CSS_INVALID;
+ goto cleanup;
+ }
+
+ /* Append the indicator that the calc is finished */
+ error = css__stylesheet_style_append(calc_style, (css_code_t) '=');
+ if (error != CSS_OK)
+ goto cleanup;
+
+ /* TODO: Once we're OK to do so, merge the style */
+ (void)result;
+ /* error = css__stylesheet_style_merge_style(result, calc_style); */
+
+cleanup:
+ css__stylesheet_style_destroy(calc_style);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ }
+
+ return error;
+}
\ No newline at end of file
diff --git a/src/parse/properties/utils.h b/src/parse/properties/utils.h
index e4c97c7..e5331d2 100644
--- a/src/parse/properties/utils.h
+++ b/src/parse/properties/utils.h
@@ -199,4 +199,28 @@ css_error css__comma_list_to_style(css_language *c,
bool first),
css_style *result);
+/**
+ * Parse a CSS calc() invocation
+ *
+ * Calc can generate a number of kinds of units, so we have to tell the
+ * parser the kind of unit we're aiming for (e.g. UNIT_PX, UNIT_ANGLE, etc.)
+ *
+ * \param[in] c Parsing context
+ * \param[in] vector Vector of tokens to process
+ * \param[in] ctx Pointer to vector iteration context
+ * \param[in] result Pointer to location to receive resulting style
+ * \param[in] property The CSS property we are calculating for
+ * \param[in] unit The kind of unit which we want to come out of this calc()
+ * \return CSS_OK on success,
+ * CSS_NOMEM on memory exhaustion,
+ CSS_INVALID if the input is not valid
+ *
+ * Post condition: \a *ctx is updated with the next token to process
+ * If the input is invalid, then \a *ctx remains unchanged.
+ */
+css_error css__parse_calc(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ css_code_t property,
+ uint32_t unit);
#endif
diff --git a/src/parse/propstrings.c b/src/parse/propstrings.c
index 3c9401b..0156ea4 100644
--- a/src/parse/propstrings.c
+++ b/src/parse/propstrings.c
@@ -443,6 +443,7 @@ const stringmap_entry stringmap[LAST_KNOWN] = {
{ "or", SLEN("or") },
{ "only", SLEN("only") },
{ "infinite", SLEN("infinite") },
+ { "calc", SLEN("calc") },
{ "aliceblue", SLEN("aliceblue") },
{ "antiquewhite", SLEN("antiquewhite") },
diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h
index 24b681b..c5dd113 100644
--- a/src/parse/propstrings.h
+++ b/src/parse/propstrings.h
@@ -101,7 +101,7 @@ enum {
AVOID_PAGE, AVOID_COLUMN, BALANCE, HORIZONTAL_TB, VERTICAL_RL,
VERTICAL_LR, CONTENT_BOX, BORDER_BOX, STRETCH, INLINE_FLEX, FLEX_START,
FLEX_END, SPACE_BETWEEN, SPACE_AROUND, SPACE_EVENLY, ROW, ROW_REVERSE,
- COLUMN_REVERSE, WRAP_STRING, WRAP_REVERSE, AND, OR, ONLY, INFINITE,
+ COLUMN_REVERSE, WRAP_STRING, WRAP_REVERSE, AND, OR, ONLY, INFINITE, CALC,
/* Named colours */
FIRST_COLOUR,
-----------------------------------------------------------------------
--
Cascading Style Sheets library
2 years, 11 months
libsvgtiny: branch master updated. release/0.1.7-1-gf66051c
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libsvgtiny.git/shortlog/f66051cab457438eef...
...commit http://git.netsurf-browser.org/libsvgtiny.git/commit/f66051cab457438eefd2...
...tree http://git.netsurf-browser.org/libsvgtiny.git/tree/f66051cab457438eefd23e...
The branch, master has been updated
via f66051cab457438eefd23e1e2c6e2197894b2d52 (commit)
from e31a20a97c6cd957ac4d858318f5819b90d97f77 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libsvgtiny.git/commit/?id=f66051cab457438e...
commit f66051cab457438eefd23e1e2c6e2197894b2d52
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
implement svg path arc correctly
diff --git a/src/svgtiny.c b/src/svgtiny.c
index 8831b92..ee0c59c 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -23,12 +23,21 @@
/* Source file generated by `gperf`. */
#include "autogenerated_colors.c"
+#define TAU 6.28318530717958647692
+
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
+#ifndef M_PI_2
+#define M_PI_2 1.57079632679489661923
+#endif
+
#define KAPPA 0.5522847498
+#define degToRad(angleInDegrees) ((angleInDegrees) * M_PI / 180.0)
+#define radToDeg(angleInRadians) ((angleInRadians) * 180.0 / M_PI)
+
static svgtiny_code svgtiny_parse_svg(dom_element *svg,
struct svgtiny_parse_state state);
static svgtiny_code svgtiny_parse_path(dom_element *path,
@@ -61,6 +70,449 @@ static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
struct svgtiny_parse_state *state);
/**
+ * rotate midpoint vector
+ */
+static void
+rotate_midpoint_vector(float ax, float ay,
+ float bx, float by,
+ double radangle,
+ double *x_out, double *y_out)
+{
+ double dx2; /* midpoint x coordinate */
+ double dy2; /* midpoint y coordinate */
+ double cosangle; /* cosine of rotation angle */
+ double sinangle; /* sine of rotation angle */
+
+ /* compute the sin and cos of the angle */
+ cosangle = cos(radangle);
+ sinangle = sin(radangle);
+
+ /* compute the midpoint between start and end points */
+ dx2 = (ax - bx) / 2.0;
+ dy2 = (ay - by) / 2.0;
+
+ /* rotate vector to remove angle */
+ *x_out = ((cosangle * dx2) + (sinangle * dy2));
+ *y_out = ((-sinangle * dx2) + (cosangle * dy2));
+}
+
+
+/**
+ * ensure the arc radii are large enough and scale as appropriate
+ *
+ * the radii need to be large enough if they are not they must be
+ * adjusted. This allows for elimination of differences between
+ * implementations especialy with rounding.
+ */
+static void
+ensure_radii_scale(double x1_sq, double y1_sq,
+ float *rx, float *ry,
+ double *rx_sq, double *ry_sq)
+{
+ double radiisum;
+ double radiiscale;
+
+ /* set radii square values */
+ (*rx_sq) = (*rx) * (*rx);
+ (*ry_sq) = (*ry) * (*ry);
+
+ radiisum = (x1_sq / (*rx_sq)) + (y1_sq / (*ry_sq));
+ if (radiisum > 0.99999) {
+ /* need to scale radii */
+ radiiscale = sqrt(radiisum) * 1.00001;
+ *rx = (float)(radiiscale * (*rx));
+ *ry = (float)(radiiscale * (*ry));
+ /* update squares too */
+ (*rx_sq) = (*rx) * (*rx);
+ (*ry_sq) = (*ry) * (*ry);
+ }
+}
+
+
+/**
+ * compute the transformed centre point
+ */
+static void
+compute_transformed_centre_point(double sign, float rx, float ry,
+ double rx_sq, double ry_sq,
+ double x1, double y1,
+ double x1_sq, double y1_sq,
+ double *cx1, double *cy1)
+{
+ double sq;
+ double coef;
+ sq = ((rx_sq * ry_sq) - (rx_sq * y1_sq) - (ry_sq * x1_sq)) /
+ ((rx_sq * y1_sq) + (ry_sq * x1_sq));
+ sq = (sq < 0) ? 0 : sq;
+
+ coef = (sign * sqrt(sq));
+
+ *cx1 = coef * ((rx * y1) / ry);
+ *cy1 = coef * -((ry * x1) / rx);
+}
+
+
+/**
+ * compute untransformed centre point
+ *
+ * \param ax The first point x coordinate
+ * \param ay The first point y coordinate
+ * \param bx The second point x coordinate
+ * \param ay The second point y coordinate
+ */
+static void
+compute_centre_point(float ax, float ay,
+ float bx, float by,
+ double cx1, double cy1,
+ double radangle,
+ double *x_out, double *y_out)
+{
+ double sx2;
+ double sy2;
+ double cosangle; /* cosine of rotation angle */
+ double sinangle; /* sine of rotation angle */
+
+ /* compute the sin and cos of the angle */
+ cosangle = cos(radangle);
+ sinangle = sin(radangle);
+
+ sx2 = (ax + bx) / 2.0;
+ sy2 = (ay + by) / 2.0;
+
+ *x_out = sx2 + (cosangle * cx1 - sinangle * cy1);
+ *y_out = sy2 + (sinangle * cx1 + cosangle * cy1);
+}
+
+
+/**
+ * compute the angle start and extent
+ */
+static void
+compute_angle_start_extent(float rx, float ry,
+ double x1, double y1,
+ double cx1, double cy1,
+ double *start, double *extent)
+{
+ double sign;
+ double ux;
+ double uy;
+ double vx;
+ double vy;
+ double p, n;
+ double actmp;
+
+ /*
+ * Angle betwen two vectors is +/- acos( u.v / len(u) * len(v))
+ * Where:
+ * '.' is the dot product.
+ * +/- is calculated from the sign of the cross product (u x v)
+ */
+
+ ux = (x1 - cx1) / rx;
+ uy = (y1 - cy1) / ry;
+ vx = (-x1 - cx1) / rx;
+ vy = (-y1 - cy1) / ry;
+
+ /* compute the start angle */
+ /* The angle between (ux, uy) and the 0 angle */
+
+ /* len(u) * len(1,0) == len(u) */
+ n = sqrt((ux * ux) + (uy * uy));
+ /* u.v == (ux,uy).(1,0) == (1 * ux) + (0 * uy) == ux */
+ p = ux;
+ /* u x v == (1 * uy - ux * 0) == uy */
+ sign = (uy < 0) ? -1.0 : 1.0;
+ /* (p >= n) so safe */
+ *start = sign * acos(p / n);
+
+ /* compute the extent angle */
+ n = sqrt(((ux * ux) + (uy * uy)) * ((vx * vx) + (vy * vy)));
+ p = (ux * vx) + (uy * vy);
+ sign = ((ux * vy) - (uy * vx) < 0) ? -1.0f : 1.0f;
+
+ /* arc cos must operate between -1 and 1 */
+ actmp = p / n;
+ if (actmp < -1.0) {
+ *extent = sign * M_PI;
+ } else if (actmp > 1.0) {
+ *extent = 0;
+ } else {
+ *extent = sign * acos(actmp);
+ }
+}
+
+
+/**
+ * converts a circle centered unit circle arc to a series of bezier curves
+ *
+ * Each bezier is stored as six values of three pairs of coordinates
+ *
+ * The beziers are stored without their start point as that is assumed
+ * to be the preceding elements end point.
+ *
+ * \param start The start angle of the arc (in radians)
+ * \param extent The size of the arc (in radians)
+ * \param bzpt The array to store the bezier values in
+ * \return The number of bezier segments output (max 4)
+ */
+static int
+circle_arc_to_bezier(double start, double extent, double *bzpt)
+{
+ int bzsegments;
+ double increment;
+ double controllen;
+ int pos = 0;
+ int segment;
+ double angle;
+ double dx, dy;
+
+ bzsegments = (int) ceil(fabs(extent) / M_PI_2);
+ increment = extent / bzsegments;
+ controllen = 4.0 / 3.0 * sin(increment / 2.0) / (1.0 + cos(increment / 2.0));
+
+ for (segment = 0; segment < bzsegments; segment++) {
+ /* first control point */
+ angle = start + (segment * increment);
+ dx = cos(angle);
+ dy = sin(angle);
+ bzpt[pos++] = dx - controllen * dy;
+ bzpt[pos++] = dy + controllen * dx;
+ /* second control point */
+ angle+=increment;
+ dx = cos(angle);
+ dy = sin(angle);
+ bzpt[pos++] = dx + controllen * dy;
+ bzpt[pos++] = dy - controllen * dx;
+ /* endpoint */
+ bzpt[pos++] = dx;
+ bzpt[pos++] = dy;
+
+ }
+ return bzsegments;
+}
+
+
+/**
+ * transform coordinate list
+ *
+ * perform a scale, rotate and translate on list of coordinates
+ *
+ * scale(rx,ry)
+ * rotate(an)
+ * translate (cx, cy)
+ *
+ * homogeneous transforms
+ *
+ * scaling
+ * | rx 0 0 |
+ * S = | 0 ry 0 |
+ * | 0 0 1 |
+ *
+ * rotate
+ * | cos(an) -sin(an) 0 |
+ * R = | sin(an) cos(an) 0 |
+ * | 0 0 1 |
+ *
+ * {{cos(a), -sin(a) 0}, {sin(a), cos(a),0}, {0,0,1}}
+ *
+ * translate
+ * | 1 0 cx |
+ * T = | 0 1 cy |
+ * | 0 0 1 |
+ *
+ * note order is significat here and the combined matrix is
+ * M = T.R.S
+ *
+ * | cos(an) -sin(an) cx |
+ * T.R = | sin(an) cos(an) cy |
+ * | 0 0 1 |
+ *
+ * | rx * cos(an) ry * -sin(an) cx |
+ * T.R.S = | rx * sin(an) ry * cos(an) cy |
+ * | 0 0 1 |
+ *
+ * {{Cos[a], -Sin[a], c}, {Sin[a], Cos[a], d}, {0, 0, 1}} . {{r, 0, 0}, {0, s, 0}, {0, 0, 1}}
+ *
+ * Each point
+ * | x1 |
+ * P = | y1 |
+ * | 1 |
+ *
+ * output
+ * | x2 |
+ * | y2 | = M . P
+ * | 1 |
+ *
+ * x2 = cx + (rx * x1 * cos(a)) + (ry * y1 * -1 * sin(a))
+ * y2 = cy + (ry * y1 * cos(a)) + (rx * x1 * sin(a))
+ *
+ *
+ * \param rx X scaling to apply
+ * \param ry Y scaling to apply
+ * \param radangle rotation to apply (in radians)
+ * \param cx X translation to apply
+ * \param cy Y translation to apply
+ * \param points The size of the bzpoints array
+ * \param bzpoints an array of x,y values to apply the transform to
+ */
+static void
+scale_rotate_translate_points(double rx, double ry,
+ double radangle,
+ double cx, double cy,
+ int pntsize,
+ double *points)
+{
+ int pnt;
+ double cosangle; /* cosine of rotation angle */
+ double sinangle; /* sine of rotation angle */
+ double rxcosangle, rxsinangle, rycosangle, rynsinangle;
+ double x2,y2;
+
+ /* compute the sin and cos of the angle */
+ cosangle = cos(radangle);
+ sinangle = sin(radangle);
+
+ rxcosangle = rx * cosangle;
+ rxsinangle = rx * sinangle;
+ rycosangle = ry * cosangle;
+ rynsinangle = ry * -1 * sinangle;
+
+ for (pnt = 0; pnt < pntsize; pnt+=2) {
+ x2 = cx + (points[pnt] * rxcosangle) + (points[pnt + 1] * rynsinangle);
+ y2 = cy + (points[pnt + 1] * rycosangle) + (points[pnt] * rxsinangle);
+ points[pnt] = x2;
+ points[pnt + 1] = y2;
+ }
+}
+
+
+/**
+ * convert an svg path arc to a bezier curve
+ *
+ * This function perfoms a transform on the nine arc parameters
+ * (coordinate pairs for start and end together with the radii of the
+ * elipse, the rotation angle and which of the four arcs to draw)
+ * which generates the parameters (coordinate pairs for start,
+ * end and their control points) for a set of up to four bezier curves.
+ *
+ * Obviously the start and end coordinates are not altered between
+ * representations so the aim is to calculate the coordinate pairs for
+ * the bezier control points.
+ *
+ * \param bzpoints the array to fill with bezier curves
+ * \return the number of bezier segments generated or -1 for a line
+ */
+static int
+svgarc_to_bezier(float start_x,
+ float start_y,
+ float end_x,
+ float end_y,
+ float rx,
+ float ry,
+ float angle,
+ bool largearc,
+ bool sweep,
+ double *bzpoints)
+{
+ double radangle; /* normalised elipsis rotation angle in radians */
+ double rx_sq; /* x radius squared */
+ double ry_sq; /* y radius squared */
+ double x1, y1; /* rotated midpoint vector */
+ double x1_sq, y1_sq; /* x1 vector squared */
+ double cx1,cy1; /* transformed circle center */
+ double cx,cy; /* circle center */
+ double start, extent;
+ int bzsegments;
+
+ if ((start_x == end_x) && (start_y == end_y)) {
+ /*
+ * if the start and end coordinates are the same the
+ * svg spec says this is equivalent to having no segment
+ * at all
+ */
+ return 0;
+ }
+
+ if ((rx == 0) || (ry == 0)) {
+ /*
+ * if either radii is zero the specified behaviour is a line
+ */
+ return -1;
+ }
+
+ /* obtain the absolute values of the radii */
+ rx = fabsf(rx);
+ ry = fabsf(ry);
+
+ /* convert normalised angle to radians */
+ radangle = degToRad(fmod(angle, 360.0));
+
+ /* step 1 */
+ /* x1,x2 is the midpoint vector rotated to remove the arc angle */
+ rotate_midpoint_vector(start_x, start_y, end_x, end_y, radangle, &x1, &y1);
+
+ /* step 2 */
+ /* get squared x1 values */
+ x1_sq = x1 * x1;
+ y1_sq = y1 * y1;
+
+ /* ensure radii are correctly scaled */
+ ensure_radii_scale(x1_sq, y1_sq, &rx, &ry, &rx_sq, &ry_sq);
+
+ /* compute the transformed centre point */
+ compute_transformed_centre_point(largearc == sweep?-1:1,
+ rx, ry,
+ rx_sq, ry_sq,
+ x1, y1,
+ x1_sq, y1_sq,
+ &cx1, &cy1);
+
+ /* step 3 */
+ /* get the untransformed centre point */
+ compute_centre_point(start_x, start_y,
+ end_x, end_y,
+ cx1, cy1,
+ radangle,
+ &cx, &cy);
+
+ /* step 4 */
+ /* compute anglestart and extent */
+ compute_angle_start_extent(rx,ry,
+ x1,y1,
+ cx1, cy1,
+ &start, &extent);
+
+ /* extent of 0 is a straight line */
+ if (extent == 0) {
+ return -1;
+ }
+
+ /* take account of sweep */
+ if (!sweep && extent > 0) {
+ extent -= TAU;
+ } else if (sweep && extent < 0) {
+ extent += TAU;
+ }
+
+ /* normalise start and extent */
+ extent = fmod(extent, TAU);
+ start = fmod(start, TAU);
+
+ /* convert the arc to unit circle bezier curves */
+ bzsegments = circle_arc_to_bezier(start, extent, bzpoints);
+
+ /* transform the bezier curves */
+ scale_rotate_translate_points(rx, ry,
+ radangle,
+ cx, cy,
+ bzsegments * 6,
+ bzpoints);
+
+ return bzsegments;
+}
+
+
+/**
* Call this to ref the strings in a gradient state.
*/
static void svgtiny_grad_string_ref(struct svgtiny_parse_state_gradient *grad)
@@ -692,17 +1144,46 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&rx, &ry, &rotation, &large_arc, &sweep,
&x, &y, &n) == 8) {
do {
- ALLOC_PATH_ELEMENTS(3);
+ int bzsegments;
+ double bzpoints[6*4]; /* allow for up to four bezier segments per arc */
- p[i++] = svgtiny_PATH_LINE;
if (*command == 'a') {
x += last_x;
y += last_y;
}
- p[i++] = last_cubic_x = last_quad_x = last_x
- = x;
- p[i++] = last_cubic_y = last_quad_y = last_y
- = y;
+
+ bzsegments = svgarc_to_bezier(last_x, last_y,
+ x, y,
+ rx, ry,
+ rotation,
+ large_arc,
+ sweep,
+ bzpoints);
+ if (bzsegments == -1) {
+ /* draw a line */
+ ALLOC_PATH_ELEMENTS(3);
+ p[i++] = svgtiny_PATH_LINE;
+ p[i++] = x;
+ p[i++] = y;
+ } else if (bzsegments > 0) {
+ int bzpnt;
+ ALLOC_PATH_ELEMENTS((unsigned int)bzsegments * 7);
+ for (bzpnt = 0;bzpnt < (bzsegments * 6); bzpnt+=6) {
+ p[i++] = svgtiny_PATH_BEZIER;
+ p[i++] = bzpoints[bzpnt];
+ p[i++] = bzpoints[bzpnt+1];
+ p[i++] = bzpoints[bzpnt+2];
+ p[i++] = bzpoints[bzpnt+3];
+ p[i++] = bzpoints[bzpnt+4];
+ p[i++] = bzpoints[bzpnt+5];
+ }
+ }
+ if (bzsegments != 0) {
+ last_cubic_x = last_quad_x = last_x = p[i-2];
+ last_cubic_y = last_quad_y = last_y = p[i-1];
+ }
+
+
s += n;
} while (sscanf(s, "%f %f %f %f %f %f %f %n",
&rx, &ry, &rotation, &large_arc, &sweep,
@@ -893,7 +1374,7 @@ svgtiny_code svgtiny_parse_circle(dom_element *circle,
err = svgtiny_add_path(p, 32, &state);
svgtiny_cleanup_state_local(&state);
-
+
return err;
}
@@ -1006,7 +1487,7 @@ svgtiny_code svgtiny_parse_ellipse(dom_element *ellipse,
p[29] = x + rx;
p[30] = y;
p[31] = svgtiny_PATH_CLOSE;
-
+
err = svgtiny_add_path(p, 32, &state);
svgtiny_cleanup_state_local(&state);
@@ -1116,14 +1597,14 @@ svgtiny_code svgtiny_parse_poly(dom_element *poly,
svgtiny_parse_paint_attributes(poly, &state);
svgtiny_parse_transform_attributes(poly, &state);
-
+
exc = dom_element_get_attribute(poly, state.interned_points,
&points_str);
if (exc != DOM_NO_ERR) {
svgtiny_cleanup_state_local(&state);
return svgtiny_LIBDOM_ERROR;
}
-
+
if (points_str == NULL) {
state.diagram->error_line = -1; /* poly->line; */
state.diagram->error_message =
@@ -1166,7 +1647,7 @@ svgtiny_code svgtiny_parse_poly(dom_element *poly,
p[i++] = y;
s += n;
} else {
- break;
+ break;
}
}
if (polygon)
@@ -1203,12 +1684,12 @@ svgtiny_code svgtiny_parse_text(dom_element *text,
px = state.ctm.a * x + state.ctm.c * y + state.ctm.e;
py = state.ctm.b * x + state.ctm.d * y + state.ctm.f;
-/* state.ctm.e = px - state.origin_x; */
-/* state.ctm.f = py - state.origin_y; */
+/* state.ctm.e = px - state.origin_x; */
+/* state.ctm.f = py - state.origin_y; */
/*struct css_style style = state.style;
style.font_size.value.length.value *= state.ctm.a;*/
-
+
exc = dom_node_get_first_child(text, &child);
if (exc != DOM_NO_ERR) {
return svgtiny_LIBDOM_ERROR;
@@ -1385,7 +1866,7 @@ void svgtiny_parse_paint_attributes(dom_element *node,
{
dom_string *attr;
dom_exception exc;
-
+
exc = dom_element_get_attribute(node, state->interned_fill, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
svgtiny_parse_color(attr, &state->fill, &state->fill_grad, state);
@@ -1557,7 +2038,7 @@ void svgtiny_parse_transform_attributes(dom_element *node,
char *transform;
dom_string *attr;
dom_exception exc;
-
+
exc = dom_element_get_attribute(node, state->interned_transform,
&attr);
if (exc == DOM_NO_ERR && attr != NULL) {
@@ -1761,7 +2242,7 @@ void svgtiny_free(struct svgtiny_diagram *svg)
free(svg->shape[i].path);
free(svg->shape[i].text);
}
-
+
free(svg->shape);
free(svg);
@@ -1786,4 +2267,3 @@ char *svgtiny_strndup(const char *s, size_t n)
return s2;
}
#endif
-
diff --git a/test/data/arc-path.svg b/test/data/arc-path.svg
new file mode 100644
index 0000000..6f0fd0b
--- /dev/null
+++ b/test/data/arc-path.svg
@@ -0,0 +1,14 @@
+<svg width="325" height="325" xmlns="http://www.w3.org/2000/svg">
+ <path d="M 80 80
+ A 45 45, 0, 0, 0, 125 125
+ L 125 80 Z" fill="green"/>
+ <path d="M 230 80
+ A 45 45, 0, 1, 0, 275 125
+ L 275 80 Z" fill="red"/>
+ <path d="M 80 230
+ A 45 45, 0, 0, 1, 125 275
+ L 125 230 Z" fill="purple"/>
+ <path d="M 230 230
+ A 45 45, 0, 1, 1, 275 275
+ L 275 230 Z" fill="blue"/>
+</svg>
-----------------------------------------------------------------------
Summary of changes:
src/svgtiny.c | 516 ++++++++++++++++++++++++++++++++++++++++++++++--
test/data/arc-path.svg | 14 ++
2 files changed, 512 insertions(+), 18 deletions(-)
create mode 100644 test/data/arc-path.svg
diff --git a/src/svgtiny.c b/src/svgtiny.c
index 8831b92..ee0c59c 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -23,12 +23,21 @@
/* Source file generated by `gperf`. */
#include "autogenerated_colors.c"
+#define TAU 6.28318530717958647692
+
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
+#ifndef M_PI_2
+#define M_PI_2 1.57079632679489661923
+#endif
+
#define KAPPA 0.5522847498
+#define degToRad(angleInDegrees) ((angleInDegrees) * M_PI / 180.0)
+#define radToDeg(angleInRadians) ((angleInRadians) * 180.0 / M_PI)
+
static svgtiny_code svgtiny_parse_svg(dom_element *svg,
struct svgtiny_parse_state state);
static svgtiny_code svgtiny_parse_path(dom_element *path,
@@ -61,6 +70,449 @@ static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
struct svgtiny_parse_state *state);
/**
+ * rotate midpoint vector
+ */
+static void
+rotate_midpoint_vector(float ax, float ay,
+ float bx, float by,
+ double radangle,
+ double *x_out, double *y_out)
+{
+ double dx2; /* midpoint x coordinate */
+ double dy2; /* midpoint y coordinate */
+ double cosangle; /* cosine of rotation angle */
+ double sinangle; /* sine of rotation angle */
+
+ /* compute the sin and cos of the angle */
+ cosangle = cos(radangle);
+ sinangle = sin(radangle);
+
+ /* compute the midpoint between start and end points */
+ dx2 = (ax - bx) / 2.0;
+ dy2 = (ay - by) / 2.0;
+
+ /* rotate vector to remove angle */
+ *x_out = ((cosangle * dx2) + (sinangle * dy2));
+ *y_out = ((-sinangle * dx2) + (cosangle * dy2));
+}
+
+
+/**
+ * ensure the arc radii are large enough and scale as appropriate
+ *
+ * the radii need to be large enough if they are not they must be
+ * adjusted. This allows for elimination of differences between
+ * implementations especialy with rounding.
+ */
+static void
+ensure_radii_scale(double x1_sq, double y1_sq,
+ float *rx, float *ry,
+ double *rx_sq, double *ry_sq)
+{
+ double radiisum;
+ double radiiscale;
+
+ /* set radii square values */
+ (*rx_sq) = (*rx) * (*rx);
+ (*ry_sq) = (*ry) * (*ry);
+
+ radiisum = (x1_sq / (*rx_sq)) + (y1_sq / (*ry_sq));
+ if (radiisum > 0.99999) {
+ /* need to scale radii */
+ radiiscale = sqrt(radiisum) * 1.00001;
+ *rx = (float)(radiiscale * (*rx));
+ *ry = (float)(radiiscale * (*ry));
+ /* update squares too */
+ (*rx_sq) = (*rx) * (*rx);
+ (*ry_sq) = (*ry) * (*ry);
+ }
+}
+
+
+/**
+ * compute the transformed centre point
+ */
+static void
+compute_transformed_centre_point(double sign, float rx, float ry,
+ double rx_sq, double ry_sq,
+ double x1, double y1,
+ double x1_sq, double y1_sq,
+ double *cx1, double *cy1)
+{
+ double sq;
+ double coef;
+ sq = ((rx_sq * ry_sq) - (rx_sq * y1_sq) - (ry_sq * x1_sq)) /
+ ((rx_sq * y1_sq) + (ry_sq * x1_sq));
+ sq = (sq < 0) ? 0 : sq;
+
+ coef = (sign * sqrt(sq));
+
+ *cx1 = coef * ((rx * y1) / ry);
+ *cy1 = coef * -((ry * x1) / rx);
+}
+
+
+/**
+ * compute untransformed centre point
+ *
+ * \param ax The first point x coordinate
+ * \param ay The first point y coordinate
+ * \param bx The second point x coordinate
+ * \param ay The second point y coordinate
+ */
+static void
+compute_centre_point(float ax, float ay,
+ float bx, float by,
+ double cx1, double cy1,
+ double radangle,
+ double *x_out, double *y_out)
+{
+ double sx2;
+ double sy2;
+ double cosangle; /* cosine of rotation angle */
+ double sinangle; /* sine of rotation angle */
+
+ /* compute the sin and cos of the angle */
+ cosangle = cos(radangle);
+ sinangle = sin(radangle);
+
+ sx2 = (ax + bx) / 2.0;
+ sy2 = (ay + by) / 2.0;
+
+ *x_out = sx2 + (cosangle * cx1 - sinangle * cy1);
+ *y_out = sy2 + (sinangle * cx1 + cosangle * cy1);
+}
+
+
+/**
+ * compute the angle start and extent
+ */
+static void
+compute_angle_start_extent(float rx, float ry,
+ double x1, double y1,
+ double cx1, double cy1,
+ double *start, double *extent)
+{
+ double sign;
+ double ux;
+ double uy;
+ double vx;
+ double vy;
+ double p, n;
+ double actmp;
+
+ /*
+ * Angle betwen two vectors is +/- acos( u.v / len(u) * len(v))
+ * Where:
+ * '.' is the dot product.
+ * +/- is calculated from the sign of the cross product (u x v)
+ */
+
+ ux = (x1 - cx1) / rx;
+ uy = (y1 - cy1) / ry;
+ vx = (-x1 - cx1) / rx;
+ vy = (-y1 - cy1) / ry;
+
+ /* compute the start angle */
+ /* The angle between (ux, uy) and the 0 angle */
+
+ /* len(u) * len(1,0) == len(u) */
+ n = sqrt((ux * ux) + (uy * uy));
+ /* u.v == (ux,uy).(1,0) == (1 * ux) + (0 * uy) == ux */
+ p = ux;
+ /* u x v == (1 * uy - ux * 0) == uy */
+ sign = (uy < 0) ? -1.0 : 1.0;
+ /* (p >= n) so safe */
+ *start = sign * acos(p / n);
+
+ /* compute the extent angle */
+ n = sqrt(((ux * ux) + (uy * uy)) * ((vx * vx) + (vy * vy)));
+ p = (ux * vx) + (uy * vy);
+ sign = ((ux * vy) - (uy * vx) < 0) ? -1.0f : 1.0f;
+
+ /* arc cos must operate between -1 and 1 */
+ actmp = p / n;
+ if (actmp < -1.0) {
+ *extent = sign * M_PI;
+ } else if (actmp > 1.0) {
+ *extent = 0;
+ } else {
+ *extent = sign * acos(actmp);
+ }
+}
+
+
+/**
+ * converts a circle centered unit circle arc to a series of bezier curves
+ *
+ * Each bezier is stored as six values of three pairs of coordinates
+ *
+ * The beziers are stored without their start point as that is assumed
+ * to be the preceding elements end point.
+ *
+ * \param start The start angle of the arc (in radians)
+ * \param extent The size of the arc (in radians)
+ * \param bzpt The array to store the bezier values in
+ * \return The number of bezier segments output (max 4)
+ */
+static int
+circle_arc_to_bezier(double start, double extent, double *bzpt)
+{
+ int bzsegments;
+ double increment;
+ double controllen;
+ int pos = 0;
+ int segment;
+ double angle;
+ double dx, dy;
+
+ bzsegments = (int) ceil(fabs(extent) / M_PI_2);
+ increment = extent / bzsegments;
+ controllen = 4.0 / 3.0 * sin(increment / 2.0) / (1.0 + cos(increment / 2.0));
+
+ for (segment = 0; segment < bzsegments; segment++) {
+ /* first control point */
+ angle = start + (segment * increment);
+ dx = cos(angle);
+ dy = sin(angle);
+ bzpt[pos++] = dx - controllen * dy;
+ bzpt[pos++] = dy + controllen * dx;
+ /* second control point */
+ angle+=increment;
+ dx = cos(angle);
+ dy = sin(angle);
+ bzpt[pos++] = dx + controllen * dy;
+ bzpt[pos++] = dy - controllen * dx;
+ /* endpoint */
+ bzpt[pos++] = dx;
+ bzpt[pos++] = dy;
+
+ }
+ return bzsegments;
+}
+
+
+/**
+ * transform coordinate list
+ *
+ * perform a scale, rotate and translate on list of coordinates
+ *
+ * scale(rx,ry)
+ * rotate(an)
+ * translate (cx, cy)
+ *
+ * homogeneous transforms
+ *
+ * scaling
+ * | rx 0 0 |
+ * S = | 0 ry 0 |
+ * | 0 0 1 |
+ *
+ * rotate
+ * | cos(an) -sin(an) 0 |
+ * R = | sin(an) cos(an) 0 |
+ * | 0 0 1 |
+ *
+ * {{cos(a), -sin(a) 0}, {sin(a), cos(a),0}, {0,0,1}}
+ *
+ * translate
+ * | 1 0 cx |
+ * T = | 0 1 cy |
+ * | 0 0 1 |
+ *
+ * note order is significat here and the combined matrix is
+ * M = T.R.S
+ *
+ * | cos(an) -sin(an) cx |
+ * T.R = | sin(an) cos(an) cy |
+ * | 0 0 1 |
+ *
+ * | rx * cos(an) ry * -sin(an) cx |
+ * T.R.S = | rx * sin(an) ry * cos(an) cy |
+ * | 0 0 1 |
+ *
+ * {{Cos[a], -Sin[a], c}, {Sin[a], Cos[a], d}, {0, 0, 1}} . {{r, 0, 0}, {0, s, 0}, {0, 0, 1}}
+ *
+ * Each point
+ * | x1 |
+ * P = | y1 |
+ * | 1 |
+ *
+ * output
+ * | x2 |
+ * | y2 | = M . P
+ * | 1 |
+ *
+ * x2 = cx + (rx * x1 * cos(a)) + (ry * y1 * -1 * sin(a))
+ * y2 = cy + (ry * y1 * cos(a)) + (rx * x1 * sin(a))
+ *
+ *
+ * \param rx X scaling to apply
+ * \param ry Y scaling to apply
+ * \param radangle rotation to apply (in radians)
+ * \param cx X translation to apply
+ * \param cy Y translation to apply
+ * \param points The size of the bzpoints array
+ * \param bzpoints an array of x,y values to apply the transform to
+ */
+static void
+scale_rotate_translate_points(double rx, double ry,
+ double radangle,
+ double cx, double cy,
+ int pntsize,
+ double *points)
+{
+ int pnt;
+ double cosangle; /* cosine of rotation angle */
+ double sinangle; /* sine of rotation angle */
+ double rxcosangle, rxsinangle, rycosangle, rynsinangle;
+ double x2,y2;
+
+ /* compute the sin and cos of the angle */
+ cosangle = cos(radangle);
+ sinangle = sin(radangle);
+
+ rxcosangle = rx * cosangle;
+ rxsinangle = rx * sinangle;
+ rycosangle = ry * cosangle;
+ rynsinangle = ry * -1 * sinangle;
+
+ for (pnt = 0; pnt < pntsize; pnt+=2) {
+ x2 = cx + (points[pnt] * rxcosangle) + (points[pnt + 1] * rynsinangle);
+ y2 = cy + (points[pnt + 1] * rycosangle) + (points[pnt] * rxsinangle);
+ points[pnt] = x2;
+ points[pnt + 1] = y2;
+ }
+}
+
+
+/**
+ * convert an svg path arc to a bezier curve
+ *
+ * This function perfoms a transform on the nine arc parameters
+ * (coordinate pairs for start and end together with the radii of the
+ * elipse, the rotation angle and which of the four arcs to draw)
+ * which generates the parameters (coordinate pairs for start,
+ * end and their control points) for a set of up to four bezier curves.
+ *
+ * Obviously the start and end coordinates are not altered between
+ * representations so the aim is to calculate the coordinate pairs for
+ * the bezier control points.
+ *
+ * \param bzpoints the array to fill with bezier curves
+ * \return the number of bezier segments generated or -1 for a line
+ */
+static int
+svgarc_to_bezier(float start_x,
+ float start_y,
+ float end_x,
+ float end_y,
+ float rx,
+ float ry,
+ float angle,
+ bool largearc,
+ bool sweep,
+ double *bzpoints)
+{
+ double radangle; /* normalised elipsis rotation angle in radians */
+ double rx_sq; /* x radius squared */
+ double ry_sq; /* y radius squared */
+ double x1, y1; /* rotated midpoint vector */
+ double x1_sq, y1_sq; /* x1 vector squared */
+ double cx1,cy1; /* transformed circle center */
+ double cx,cy; /* circle center */
+ double start, extent;
+ int bzsegments;
+
+ if ((start_x == end_x) && (start_y == end_y)) {
+ /*
+ * if the start and end coordinates are the same the
+ * svg spec says this is equivalent to having no segment
+ * at all
+ */
+ return 0;
+ }
+
+ if ((rx == 0) || (ry == 0)) {
+ /*
+ * if either radii is zero the specified behaviour is a line
+ */
+ return -1;
+ }
+
+ /* obtain the absolute values of the radii */
+ rx = fabsf(rx);
+ ry = fabsf(ry);
+
+ /* convert normalised angle to radians */
+ radangle = degToRad(fmod(angle, 360.0));
+
+ /* step 1 */
+ /* x1,x2 is the midpoint vector rotated to remove the arc angle */
+ rotate_midpoint_vector(start_x, start_y, end_x, end_y, radangle, &x1, &y1);
+
+ /* step 2 */
+ /* get squared x1 values */
+ x1_sq = x1 * x1;
+ y1_sq = y1 * y1;
+
+ /* ensure radii are correctly scaled */
+ ensure_radii_scale(x1_sq, y1_sq, &rx, &ry, &rx_sq, &ry_sq);
+
+ /* compute the transformed centre point */
+ compute_transformed_centre_point(largearc == sweep?-1:1,
+ rx, ry,
+ rx_sq, ry_sq,
+ x1, y1,
+ x1_sq, y1_sq,
+ &cx1, &cy1);
+
+ /* step 3 */
+ /* get the untransformed centre point */
+ compute_centre_point(start_x, start_y,
+ end_x, end_y,
+ cx1, cy1,
+ radangle,
+ &cx, &cy);
+
+ /* step 4 */
+ /* compute anglestart and extent */
+ compute_angle_start_extent(rx,ry,
+ x1,y1,
+ cx1, cy1,
+ &start, &extent);
+
+ /* extent of 0 is a straight line */
+ if (extent == 0) {
+ return -1;
+ }
+
+ /* take account of sweep */
+ if (!sweep && extent > 0) {
+ extent -= TAU;
+ } else if (sweep && extent < 0) {
+ extent += TAU;
+ }
+
+ /* normalise start and extent */
+ extent = fmod(extent, TAU);
+ start = fmod(start, TAU);
+
+ /* convert the arc to unit circle bezier curves */
+ bzsegments = circle_arc_to_bezier(start, extent, bzpoints);
+
+ /* transform the bezier curves */
+ scale_rotate_translate_points(rx, ry,
+ radangle,
+ cx, cy,
+ bzsegments * 6,
+ bzpoints);
+
+ return bzsegments;
+}
+
+
+/**
* Call this to ref the strings in a gradient state.
*/
static void svgtiny_grad_string_ref(struct svgtiny_parse_state_gradient *grad)
@@ -692,17 +1144,46 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&rx, &ry, &rotation, &large_arc, &sweep,
&x, &y, &n) == 8) {
do {
- ALLOC_PATH_ELEMENTS(3);
+ int bzsegments;
+ double bzpoints[6*4]; /* allow for up to four bezier segments per arc */
- p[i++] = svgtiny_PATH_LINE;
if (*command == 'a') {
x += last_x;
y += last_y;
}
- p[i++] = last_cubic_x = last_quad_x = last_x
- = x;
- p[i++] = last_cubic_y = last_quad_y = last_y
- = y;
+
+ bzsegments = svgarc_to_bezier(last_x, last_y,
+ x, y,
+ rx, ry,
+ rotation,
+ large_arc,
+ sweep,
+ bzpoints);
+ if (bzsegments == -1) {
+ /* draw a line */
+ ALLOC_PATH_ELEMENTS(3);
+ p[i++] = svgtiny_PATH_LINE;
+ p[i++] = x;
+ p[i++] = y;
+ } else if (bzsegments > 0) {
+ int bzpnt;
+ ALLOC_PATH_ELEMENTS((unsigned int)bzsegments * 7);
+ for (bzpnt = 0;bzpnt < (bzsegments * 6); bzpnt+=6) {
+ p[i++] = svgtiny_PATH_BEZIER;
+ p[i++] = bzpoints[bzpnt];
+ p[i++] = bzpoints[bzpnt+1];
+ p[i++] = bzpoints[bzpnt+2];
+ p[i++] = bzpoints[bzpnt+3];
+ p[i++] = bzpoints[bzpnt+4];
+ p[i++] = bzpoints[bzpnt+5];
+ }
+ }
+ if (bzsegments != 0) {
+ last_cubic_x = last_quad_x = last_x = p[i-2];
+ last_cubic_y = last_quad_y = last_y = p[i-1];
+ }
+
+
s += n;
} while (sscanf(s, "%f %f %f %f %f %f %f %n",
&rx, &ry, &rotation, &large_arc, &sweep,
@@ -893,7 +1374,7 @@ svgtiny_code svgtiny_parse_circle(dom_element *circle,
err = svgtiny_add_path(p, 32, &state);
svgtiny_cleanup_state_local(&state);
-
+
return err;
}
@@ -1006,7 +1487,7 @@ svgtiny_code svgtiny_parse_ellipse(dom_element *ellipse,
p[29] = x + rx;
p[30] = y;
p[31] = svgtiny_PATH_CLOSE;
-
+
err = svgtiny_add_path(p, 32, &state);
svgtiny_cleanup_state_local(&state);
@@ -1116,14 +1597,14 @@ svgtiny_code svgtiny_parse_poly(dom_element *poly,
svgtiny_parse_paint_attributes(poly, &state);
svgtiny_parse_transform_attributes(poly, &state);
-
+
exc = dom_element_get_attribute(poly, state.interned_points,
&points_str);
if (exc != DOM_NO_ERR) {
svgtiny_cleanup_state_local(&state);
return svgtiny_LIBDOM_ERROR;
}
-
+
if (points_str == NULL) {
state.diagram->error_line = -1; /* poly->line; */
state.diagram->error_message =
@@ -1166,7 +1647,7 @@ svgtiny_code svgtiny_parse_poly(dom_element *poly,
p[i++] = y;
s += n;
} else {
- break;
+ break;
}
}
if (polygon)
@@ -1203,12 +1684,12 @@ svgtiny_code svgtiny_parse_text(dom_element *text,
px = state.ctm.a * x + state.ctm.c * y + state.ctm.e;
py = state.ctm.b * x + state.ctm.d * y + state.ctm.f;
-/* state.ctm.e = px - state.origin_x; */
-/* state.ctm.f = py - state.origin_y; */
+/* state.ctm.e = px - state.origin_x; */
+/* state.ctm.f = py - state.origin_y; */
/*struct css_style style = state.style;
style.font_size.value.length.value *= state.ctm.a;*/
-
+
exc = dom_node_get_first_child(text, &child);
if (exc != DOM_NO_ERR) {
return svgtiny_LIBDOM_ERROR;
@@ -1385,7 +1866,7 @@ void svgtiny_parse_paint_attributes(dom_element *node,
{
dom_string *attr;
dom_exception exc;
-
+
exc = dom_element_get_attribute(node, state->interned_fill, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
svgtiny_parse_color(attr, &state->fill, &state->fill_grad, state);
@@ -1557,7 +2038,7 @@ void svgtiny_parse_transform_attributes(dom_element *node,
char *transform;
dom_string *attr;
dom_exception exc;
-
+
exc = dom_element_get_attribute(node, state->interned_transform,
&attr);
if (exc == DOM_NO_ERR && attr != NULL) {
@@ -1761,7 +2242,7 @@ void svgtiny_free(struct svgtiny_diagram *svg)
free(svg->shape[i].path);
free(svg->shape[i].text);
}
-
+
free(svg->shape);
free(svg);
@@ -1786,4 +2267,3 @@ char *svgtiny_strndup(const char *s, size_t n)
return s2;
}
#endif
-
diff --git a/test/data/arc-path.svg b/test/data/arc-path.svg
new file mode 100644
index 0000000..6f0fd0b
--- /dev/null
+++ b/test/data/arc-path.svg
@@ -0,0 +1,14 @@
+<svg width="325" height="325" xmlns="http://www.w3.org/2000/svg">
+ <path d="M 80 80
+ A 45 45, 0, 0, 0, 125 125
+ L 125 80 Z" fill="green"/>
+ <path d="M 230 80
+ A 45 45, 0, 1, 0, 275 125
+ L 275 80 Z" fill="red"/>
+ <path d="M 80 230
+ A 45 45, 0, 0, 1, 125 275
+ L 125 230 Z" fill="purple"/>
+ <path d="M 230 230
+ A 45 45, 0, 1, 1, 275 275
+ L 275 230 Z" fill="blue"/>
+</svg>
--
NetSurf SVG decoder
2 years, 11 months