libdom: branch master updated. release/0.4.1-7-g720668e
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/720668e90e02bf408d344e...
...commit http://git.netsurf-browser.org/libdom.git/commit/720668e90e02bf408d344e8b...
...tree http://git.netsurf-browser.org/libdom.git/tree/720668e90e02bf408d344e8b1d...
The branch, master has been updated
via 720668e90e02bf408d344e8b1d83fb16638c8605 (commit)
from a2ffae698d4c12d9457c62b79eddd4342e2e213c (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/libdom.git/commit/?id=720668e90e02bf408d34...
commit 720668e90e02bf408d344e8b1d83fb16638c8605
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
node: Constify get user data parameters.
diff --git a/include/dom/core/node.h b/include/dom/core/node.h
index 5058c78..90026a1 100644
--- a/include/dom/core/node.h
+++ b/include/dom/core/node.h
@@ -169,8 +169,8 @@ typedef struct dom_node_vtable {
dom_exception (*dom_node_set_user_data)(dom_node_internal *node,
dom_string *key, void *data,
dom_user_data_handler handler, void **result);
- dom_exception (*dom_node_get_user_data)(dom_node_internal *node,
- dom_string *key, void **result);
+ dom_exception (*dom_node_get_user_data)(const dom_node_internal *node,
+ const dom_string *key, void **result);
} dom_node_vtable;
/* The ref/unref methods define */
@@ -567,8 +567,8 @@ static inline dom_exception dom_node_set_user_data(struct dom_node *node,
(dom_node *) (n), (k), (void *) (d), \
(dom_user_data_handler) h, (void **) (r))
-static inline dom_exception dom_node_get_user_data(struct dom_node *node,
- dom_string *key, void **result)
+static inline dom_exception dom_node_get_user_data(const struct dom_node *node,
+ const dom_string *key, void **result)
{
return ((dom_node_vtable *) node->vtable)->dom_node_get_user_data(
(dom_node_internal *) node, key, result);
diff --git a/src/core/node.c b/src/core/node.c
index f8b8def..1218742 100644
--- a/src/core/node.c
+++ b/src/core/node.c
@@ -1827,8 +1827,8 @@ dom_exception _dom_node_set_user_data(dom_node_internal *node,
* \param result Pointer to location to receive result
* \return DOM_NO_ERR.
*/
-dom_exception _dom_node_get_user_data(dom_node_internal *node,
- dom_string *key, void **result)
+dom_exception _dom_node_get_user_data(const dom_node_internal *node,
+ const dom_string *key, void **result)
{
struct dom_user_data *ud = NULL;
diff --git a/src/core/node.h b/src/core/node.h
index 36d0ec1..36cdd7d 100644
--- a/src/core/node.h
+++ b/src/core/node.h
@@ -182,8 +182,8 @@ dom_exception _dom_node_get_feature(dom_node_internal *node,
dom_exception _dom_node_set_user_data(dom_node_internal *node,
dom_string *key, void *data,
dom_user_data_handler handler, void **result);
-dom_exception _dom_node_get_user_data(dom_node_internal *node,
- dom_string *key, void **result);
+dom_exception _dom_node_get_user_data(const dom_node_internal *node,
+ const dom_string *key, void **result);
#define DOM_NODE_EVENT_TARGET_VTABLE \
_dom_node_add_event_listener, \
-----------------------------------------------------------------------
Summary of changes:
include/dom/core/node.h | 8 ++++----
src/core/node.c | 4 ++--
src/core/node.h | 4 ++--
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/dom/core/node.h b/include/dom/core/node.h
index 5058c78..90026a1 100644
--- a/include/dom/core/node.h
+++ b/include/dom/core/node.h
@@ -169,8 +169,8 @@ typedef struct dom_node_vtable {
dom_exception (*dom_node_set_user_data)(dom_node_internal *node,
dom_string *key, void *data,
dom_user_data_handler handler, void **result);
- dom_exception (*dom_node_get_user_data)(dom_node_internal *node,
- dom_string *key, void **result);
+ dom_exception (*dom_node_get_user_data)(const dom_node_internal *node,
+ const dom_string *key, void **result);
} dom_node_vtable;
/* The ref/unref methods define */
@@ -567,8 +567,8 @@ static inline dom_exception dom_node_set_user_data(struct dom_node *node,
(dom_node *) (n), (k), (void *) (d), \
(dom_user_data_handler) h, (void **) (r))
-static inline dom_exception dom_node_get_user_data(struct dom_node *node,
- dom_string *key, void **result)
+static inline dom_exception dom_node_get_user_data(const struct dom_node *node,
+ const dom_string *key, void **result)
{
return ((dom_node_vtable *) node->vtable)->dom_node_get_user_data(
(dom_node_internal *) node, key, result);
diff --git a/src/core/node.c b/src/core/node.c
index f8b8def..1218742 100644
--- a/src/core/node.c
+++ b/src/core/node.c
@@ -1827,8 +1827,8 @@ dom_exception _dom_node_set_user_data(dom_node_internal *node,
* \param result Pointer to location to receive result
* \return DOM_NO_ERR.
*/
-dom_exception _dom_node_get_user_data(dom_node_internal *node,
- dom_string *key, void **result)
+dom_exception _dom_node_get_user_data(const dom_node_internal *node,
+ const dom_string *key, void **result)
{
struct dom_user_data *ud = NULL;
diff --git a/src/core/node.h b/src/core/node.h
index 36d0ec1..36cdd7d 100644
--- a/src/core/node.h
+++ b/src/core/node.h
@@ -182,8 +182,8 @@ dom_exception _dom_node_get_feature(dom_node_internal *node,
dom_exception _dom_node_set_user_data(dom_node_internal *node,
dom_string *key, void *data,
dom_user_data_handler handler, void **result);
-dom_exception _dom_node_get_user_data(dom_node_internal *node,
- dom_string *key, void **result);
+dom_exception _dom_node_get_user_data(const dom_node_internal *node,
+ const dom_string *key, void **result);
#define DOM_NODE_EVENT_TARGET_VTABLE \
_dom_node_add_event_listener, \
--
Document Object Model library
1 year, 12 months
libcss: branch master updated. release/0.9.1-10-g35f499b
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/35f499b333d1f97c47ac55...
...commit http://git.netsurf-browser.org/libcss.git/commit/35f499b333d1f97c47ac5581...
...tree http://git.netsurf-browser.org/libcss.git/tree/35f499b333d1f97c47ac558114...
The branch, master has been updated
via 35f499b333d1f97c47ac5581143ce9806d1c3536 (commit)
from 1c76ee6efeab2e9307d0a8aafa6666ca9db83128 (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=35f499b333d1f97c47ac...
commit 35f499b333d1f97c47ac5581143ce9806d1c3536
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
add cyclic system to list style formatting
diff --git a/src/select/format_list_style.c b/src/select/format_list_style.c
index 07d028b..4a2fee5 100644
--- a/src/select/format_list_style.c
+++ b/src/select/format_list_style.c
@@ -137,7 +137,7 @@ map_aval_to_symbols(char *buf, const size_t buflen,
* \param ares Buffer to recive the converted values
* \param alen the length of \a ares buffer
* \param value The value to convert
- * \param slen The number of symbols in the alphabet
+ * \param cstyle The counter style in use
* \return The length a complete conversion which may be larger than \a alen
*/
static size_t
@@ -179,6 +179,36 @@ calc_numeric_system(uint8_t *ares,
/**
+ * generate cyclic symbol values
+ *
+ * fills array with cyclic values that represent the input value
+ *
+ * \param ares Buffer to recive the converted values
+ * \param alen the length of \a ares buffer
+ * \param value The value to convert
+ * \param cstyle The counter style in use
+ * \return The length a complete conversion which may be larger than \a alen
+ */
+static size_t
+calc_cyclic_system(uint8_t *ares,
+ const size_t alen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ if (alen == 0) {
+ return 0;
+ }
+ if (cstyle->items == 1) {
+ /* there is only one symbol so select it */
+ ares[0] = 0;
+ } else {
+ ares[0] = (value - 1) % cstyle->items;
+ }
+ return 1;
+}
+
+
+/**
* generate addative symbol values
*
* fills array with numeric values that represent the input value
@@ -472,13 +502,40 @@ static const struct list_counter_style lcs_lower_roman = {
.calc = calc_roman_system,
};
+static const symbol_t disc_symbols[] = { "\xE2\x80\xA2"}; /* 2022 BULLET */
+static const struct list_counter_style lcs_disc = {
+ .name = "disc",
+ .symbols = disc_symbols,
+ .items = (sizeof(disc_symbols) / SYMBOL_SIZE),
+ .postfix = " ",
+ .calc = calc_cyclic_system,
+};
+
+static const symbol_t circle_symbols[] = { "\342\227\213"}; /* 25CB WHITE CIRCLE */
+static const struct list_counter_style lcs_circle = {
+ .name = "circle",
+ .symbols = circle_symbols,
+ .items = (sizeof(circle_symbols) / SYMBOL_SIZE),
+ .postfix = " ",
+ .calc = calc_cyclic_system,
+};
+
+static const symbol_t square_symbols[] = { "\342\226\252"}; /* 25AA BLACK SMALL SQUARE */
+static const struct list_counter_style lcs_square = {
+ .name = "square",
+ .symbols = square_symbols,
+ .items = (sizeof(square_symbols) / SYMBOL_SIZE),
+ .postfix = " ",
+ .calc = calc_cyclic_system,
+};
+
#if 0
static const symbol_t lower_hexidecimal_symbols[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f"
};
static const struct list_counter_style lcs_lower_hexidecimal = {
- .name = "lower_hexidecimal",
+ .name = "lower-hexidecimal",
.symbols = lower_hexidecimal_symbols,
.items = (sizeof(lower_hexidecimal_symbols) / SYMBOL_SIZE),
.calc = calc_numeric_system,
@@ -535,6 +592,22 @@ css_error css_computed_format_list_style(
cstyle = &lcs_georgian;
break;
+ case CSS_LIST_STYLE_TYPE_DISC:
+ cstyle = &lcs_disc;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_CIRCLE:
+ cstyle = &lcs_circle;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_SQUARE:
+ cstyle = &lcs_square;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_NONE:
+ *format_length = 0;
+ return CSS_OK;
+
case CSS_LIST_STYLE_TYPE_DECIMAL:
default:
cstyle = &lcs_decimal;
-----------------------------------------------------------------------
Summary of changes:
src/select/format_list_style.c | 77 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 75 insertions(+), 2 deletions(-)
diff --git a/src/select/format_list_style.c b/src/select/format_list_style.c
index 07d028b..4a2fee5 100644
--- a/src/select/format_list_style.c
+++ b/src/select/format_list_style.c
@@ -137,7 +137,7 @@ map_aval_to_symbols(char *buf, const size_t buflen,
* \param ares Buffer to recive the converted values
* \param alen the length of \a ares buffer
* \param value The value to convert
- * \param slen The number of symbols in the alphabet
+ * \param cstyle The counter style in use
* \return The length a complete conversion which may be larger than \a alen
*/
static size_t
@@ -179,6 +179,36 @@ calc_numeric_system(uint8_t *ares,
/**
+ * generate cyclic symbol values
+ *
+ * fills array with cyclic values that represent the input value
+ *
+ * \param ares Buffer to recive the converted values
+ * \param alen the length of \a ares buffer
+ * \param value The value to convert
+ * \param cstyle The counter style in use
+ * \return The length a complete conversion which may be larger than \a alen
+ */
+static size_t
+calc_cyclic_system(uint8_t *ares,
+ const size_t alen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ if (alen == 0) {
+ return 0;
+ }
+ if (cstyle->items == 1) {
+ /* there is only one symbol so select it */
+ ares[0] = 0;
+ } else {
+ ares[0] = (value - 1) % cstyle->items;
+ }
+ return 1;
+}
+
+
+/**
* generate addative symbol values
*
* fills array with numeric values that represent the input value
@@ -472,13 +502,40 @@ static const struct list_counter_style lcs_lower_roman = {
.calc = calc_roman_system,
};
+static const symbol_t disc_symbols[] = { "\xE2\x80\xA2"}; /* 2022 BULLET */
+static const struct list_counter_style lcs_disc = {
+ .name = "disc",
+ .symbols = disc_symbols,
+ .items = (sizeof(disc_symbols) / SYMBOL_SIZE),
+ .postfix = " ",
+ .calc = calc_cyclic_system,
+};
+
+static const symbol_t circle_symbols[] = { "\342\227\213"}; /* 25CB WHITE CIRCLE */
+static const struct list_counter_style lcs_circle = {
+ .name = "circle",
+ .symbols = circle_symbols,
+ .items = (sizeof(circle_symbols) / SYMBOL_SIZE),
+ .postfix = " ",
+ .calc = calc_cyclic_system,
+};
+
+static const symbol_t square_symbols[] = { "\342\226\252"}; /* 25AA BLACK SMALL SQUARE */
+static const struct list_counter_style lcs_square = {
+ .name = "square",
+ .symbols = square_symbols,
+ .items = (sizeof(square_symbols) / SYMBOL_SIZE),
+ .postfix = " ",
+ .calc = calc_cyclic_system,
+};
+
#if 0
static const symbol_t lower_hexidecimal_symbols[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f"
};
static const struct list_counter_style lcs_lower_hexidecimal = {
- .name = "lower_hexidecimal",
+ .name = "lower-hexidecimal",
.symbols = lower_hexidecimal_symbols,
.items = (sizeof(lower_hexidecimal_symbols) / SYMBOL_SIZE),
.calc = calc_numeric_system,
@@ -535,6 +592,22 @@ css_error css_computed_format_list_style(
cstyle = &lcs_georgian;
break;
+ case CSS_LIST_STYLE_TYPE_DISC:
+ cstyle = &lcs_disc;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_CIRCLE:
+ cstyle = &lcs_circle;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_SQUARE:
+ cstyle = &lcs_square;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_NONE:
+ *format_length = 0;
+ return CSS_OK;
+
case CSS_LIST_STYLE_TYPE_DECIMAL:
default:
cstyle = &lcs_decimal;
--
Cascading Style Sheets library
1 year, 12 months
netsurf-test: branch master updated. 0ed395f733752fb58a77c7cc20922dedba2944f2
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf-test.git/shortlog/0ed395f733752fb5...
...commit http://git.netsurf-browser.org/netsurf-test.git/commit/0ed395f733752fb58a...
...tree http://git.netsurf-browser.org/netsurf-test.git/tree/0ed395f733752fb58a77...
The branch, master has been updated
via 0ed395f733752fb58a77c7cc20922dedba2944f2 (commit)
from 37e0afc97d64c0c73fa38c06dadf7de4659147be (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-test.git/commit/?id=0ed395f733752f...
commit 0ed395f733752fb58a77c7cc20922dedba2944f2
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
open source taml files as utf-8 encoded text
diff --git a/cgi-bin/monkey-index.cgi b/cgi-bin/monkey-index.cgi
index 4ae41f6..3ccb313 100755
--- a/cgi-bin/monkey-index.cgi
+++ b/cgi-bin/monkey-index.cgi
@@ -48,7 +48,7 @@ def main():
# load all test plan yaml files
for fname in sorted(flist):
- with open(os.path.join(testroot, fname), "r") as file_handle:
+ with open(os.path.join(testroot, fname), "rt", encoding='utf8') as file_handle:
files[fname] = yaml.load(file_handle, Loader=yaml.CSafeLoader)
if division + '/index.yaml' not in files:
-----------------------------------------------------------------------
Summary of changes:
cgi-bin/monkey-index.cgi | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cgi-bin/monkey-index.cgi b/cgi-bin/monkey-index.cgi
index 4ae41f6..3ccb313 100755
--- a/cgi-bin/monkey-index.cgi
+++ b/cgi-bin/monkey-index.cgi
@@ -48,7 +48,7 @@ def main():
# load all test plan yaml files
for fname in sorted(flist):
- with open(os.path.join(testroot, fname), "r") as file_handle:
+ with open(os.path.join(testroot, fname), "rt", encoding='utf8') as file_handle:
files[fname] = yaml.load(file_handle, Loader=yaml.CSafeLoader)
if division + '/index.yaml' not in files:
--
NetSurf test cases
1 year, 12 months
netsurf: branch master updated. release/3.10-101-gdcec1d0
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/dcec1d0cd58343f64d4dd...
...commit http://git.netsurf-browser.org/netsurf.git/commit/dcec1d0cd58343f64d4dd0b...
...tree http://git.netsurf-browser.org/netsurf.git/tree/dcec1d0cd58343f64d4dd0b7d...
The branch, master has been updated
via dcec1d0cd58343f64d4dd0b7d52e2c5d6193dfe8 (commit)
from a091dc3603c18ff3633a206b346891b4381cf323 (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=dcec1d0cd58343f64d4...
commit dcec1d0cd58343f64d4dd0b7d52e2c5d6193dfe8
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
undo debug driver change
diff --git a/test/monkey_driver.py b/test/monkey_driver.py
index a6c7546..9b810d2 100755
--- a/test/monkey_driver.py
+++ b/test/monkey_driver.py
@@ -217,7 +217,7 @@ def run_test_step_action_launch(ctx, step):
ctx['browser'] = DriverBrowser(
monkey_cmd=monkey_cmd,
monkey_env=monkey_env,
- quiet=False,
+ quiet=True,
wrapper=ctx.get("wrapper"))
assert_browser(ctx)
ctx['windows'] = dict()
-----------------------------------------------------------------------
Summary of changes:
test/monkey_driver.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/monkey_driver.py b/test/monkey_driver.py
index a6c7546..9b810d2 100755
--- a/test/monkey_driver.py
+++ b/test/monkey_driver.py
@@ -217,7 +217,7 @@ def run_test_step_action_launch(ctx, step):
ctx['browser'] = DriverBrowser(
monkey_cmd=monkey_cmd,
monkey_env=monkey_env,
- quiet=False,
+ quiet=True,
wrapper=ctx.get("wrapper"))
assert_browser(ctx)
ctx['windows'] = dict()
--
NetSurf Browser
1 year, 12 months
netsurf-test: branch master updated. 37e0afc97d64c0c73fa38c06dadf7de4659147be
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf-test.git/shortlog/37e0afc97d64c0c7...
...commit http://git.netsurf-browser.org/netsurf-test.git/commit/37e0afc97d64c0c73f...
...tree http://git.netsurf-browser.org/netsurf-test.git/tree/37e0afc97d64c0c73fa3...
The branch, master has been updated
via 37e0afc97d64c0c73fa38c06dadf7de4659147be (commit)
from affedad2a5fe033099e9cf76b9a2188a1e9c9225 (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-test.git/commit/?id=37e0afc97d64c0...
commit 37e0afc97d64c0c73fa38c06dadf7de4659147be
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
add test for list styles
diff --git a/monkey-test/ns-infrastructure/index.yaml b/monkey-test/ns-infrastructure/index.yaml
index eb4612e..3b3070e 100644
--- a/monkey-test/ns-infrastructure/index.yaml
+++ b/monkey-test/ns-infrastructure/index.yaml
@@ -15,3 +15,6 @@
- group: jquery
description: Basic jQuery tests
+
+- group: list-style
+ description: Test list styles
diff --git a/monkey-test/ns-infrastructure/list-style.yaml b/monkey-test/ns-infrastructure/list-style.yaml
new file mode 100644
index 0000000..79e1fa7
--- /dev/null
+++ b/monkey-test/ns-infrastructure/list-style.yaml
@@ -0,0 +1,93 @@
+title: Test list styling
+group: list-style
+steps:
+- action: launch
+ language: en
+- action: window-new
+ tag: win1
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=decim...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 1."
+ - text-contains: "9999 9999."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=lower...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 i."
+ - text-contains: "3999 mmmcmxcix."
+ - text-contains: "4000 4000."
+ - text-contains: "9999 9999."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=upper...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 I."
+ - text-contains: "3999 MMMCMXCIX."
+ - text-contains: "4000 4000."
+ - text-contains: "9999 9999."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=lower...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 a."
+ - text-contains: "9999 nto."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=upper...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 A."
+ - text-contains: "9999 NTO."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=lower...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 ��."
+ - text-contains: "9999 ������."
+- action: window-close
+ window: win1
+- action: quit
+
-----------------------------------------------------------------------
Summary of changes:
monkey-test/ns-infrastructure/index.yaml | 3 +
monkey-test/ns-infrastructure/list-style.yaml | 93 +++++++++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100644 monkey-test/ns-infrastructure/list-style.yaml
diff --git a/monkey-test/ns-infrastructure/index.yaml b/monkey-test/ns-infrastructure/index.yaml
index eb4612e..3b3070e 100644
--- a/monkey-test/ns-infrastructure/index.yaml
+++ b/monkey-test/ns-infrastructure/index.yaml
@@ -15,3 +15,6 @@
- group: jquery
description: Basic jQuery tests
+
+- group: list-style
+ description: Test list styles
diff --git a/monkey-test/ns-infrastructure/list-style.yaml b/monkey-test/ns-infrastructure/list-style.yaml
new file mode 100644
index 0000000..79e1fa7
--- /dev/null
+++ b/monkey-test/ns-infrastructure/list-style.yaml
@@ -0,0 +1,93 @@
+title: Test list styling
+group: list-style
+steps:
+- action: launch
+ language: en
+- action: window-new
+ tag: win1
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=decim...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 1."
+ - text-contains: "9999 9999."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=lower...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 i."
+ - text-contains: "3999 mmmcmxcix."
+ - text-contains: "4000 4000."
+ - text-contains: "9999 9999."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=upper...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 I."
+ - text-contains: "3999 MMMCMXCIX."
+ - text-contains: "4000 4000."
+ - text-contains: "9999 9999."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=lower...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 a."
+ - text-contains: "9999 nto."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=upper...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 A."
+ - text-contains: "9999 NTO."
+- action: navigate
+ window: win1
+ url: https://test.netsurf-browser.org/cgi-bin/ordered-list.cgi?liststyle=lower...
+- action: block
+ conditions:
+ - window: win1
+ status: complete
+- action: plot-check
+ window: win1
+ area: extent
+ checks:
+ - text-contains: "1 ��."
+ - text-contains: "9999 ������."
+- action: window-close
+ window: win1
+- action: quit
+
--
NetSurf test cases
1 year, 12 months
netsurf: branch master updated. release/3.10-100-ga091dc3
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/a091dc3603c18ff3633a2...
...commit http://git.netsurf-browser.org/netsurf.git/commit/a091dc3603c18ff3633a206...
...tree http://git.netsurf-browser.org/netsurf.git/tree/a091dc3603c18ff3633a206b3...
The branch, master has been updated
via a091dc3603c18ff3633a206b346891b4381cf323 (commit)
from ff225194f338519a4856f24b1196ded583ff51af (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=a091dc3603c18ff3633...
commit a091dc3603c18ff3633a206b346891b4381cf323
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
allow monkey tests to specify a redraw area for plot-check steps
diff --git a/docs/integration-testing.md b/docs/integration-testing.md
index da93343..03b4130 100644
--- a/docs/integration-testing.md
+++ b/docs/integration-testing.md
@@ -400,9 +400,14 @@ The window to be rendered is identified with the `window` key, the
value of this must be a previously created window identifier or an
assert will occur.
+The `area` key allows control of the area to be redraw. The parameters are on two forms:
+
+ * A sequence of four numbers in the form `x0 y0 x1 y1`
+ * The keyword extent which attempt to plot the entire extent of the canvas
+
An optional list of checks may be specified with the `checks` key. If
any check is not satisfied an assert will occur and the test will
-fail.
+fail. Multiple checks can be specified and all most pass successfully.
The checks available are:
@@ -416,8 +421,10 @@ The checks available are:
- action: plot-check
window: win1
+ area: extent
checks:
- text-contains: NetSurf
+ - text-contains: Browser
- text-not-contains: Chrome
- bitmap-count: 1
diff --git a/test/monkey_driver.py b/test/monkey_driver.py
index 606530e..a6c7546 100755
--- a/test/monkey_driver.py
+++ b/test/monkey_driver.py
@@ -217,7 +217,7 @@ def run_test_step_action_launch(ctx, step):
ctx['browser'] = DriverBrowser(
monkey_cmd=monkey_cmd,
monkey_env=monkey_env,
- quiet=True,
+ quiet=False,
wrapper=ctx.get("wrapper"))
assert_browser(ctx)
ctx['windows'] = dict()
@@ -436,13 +436,26 @@ def run_test_step_action_plot_check(ctx, step):
print(get_indent(ctx) + "Action: " + step["action"])
assert_browser(ctx)
win = ctx['windows'][step['window']]
+
+ if 'area' in step.keys():
+ if step["area"] == "extent":
+ # ought to capture the extent updates and use that, instead use a
+ # big area and have the browser clip it
+ area=["0","0","1000","1000000"]
+ else:
+ area = [step["area"]]
+ else:
+ area = None
+
+ # get the list of checks
if 'checks' in step.keys():
checks = step['checks']
else:
checks = {}
+
all_text_list = []
bitmaps = []
- for plot in win.redraw():
+ for plot in win.redraw(coords=area):
if plot[0] == 'TEXT':
all_text_list.extend(plot[6:])
if plot[0] == 'BITMAP':
-----------------------------------------------------------------------
Summary of changes:
docs/integration-testing.md | 9 ++++++++-
test/monkey_driver.py | 17 +++++++++++++++--
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/docs/integration-testing.md b/docs/integration-testing.md
index da93343..03b4130 100644
--- a/docs/integration-testing.md
+++ b/docs/integration-testing.md
@@ -400,9 +400,14 @@ The window to be rendered is identified with the `window` key, the
value of this must be a previously created window identifier or an
assert will occur.
+The `area` key allows control of the area to be redraw. The parameters are on two forms:
+
+ * A sequence of four numbers in the form `x0 y0 x1 y1`
+ * The keyword extent which attempt to plot the entire extent of the canvas
+
An optional list of checks may be specified with the `checks` key. If
any check is not satisfied an assert will occur and the test will
-fail.
+fail. Multiple checks can be specified and all most pass successfully.
The checks available are:
@@ -416,8 +421,10 @@ The checks available are:
- action: plot-check
window: win1
+ area: extent
checks:
- text-contains: NetSurf
+ - text-contains: Browser
- text-not-contains: Chrome
- bitmap-count: 1
diff --git a/test/monkey_driver.py b/test/monkey_driver.py
index 606530e..a6c7546 100755
--- a/test/monkey_driver.py
+++ b/test/monkey_driver.py
@@ -217,7 +217,7 @@ def run_test_step_action_launch(ctx, step):
ctx['browser'] = DriverBrowser(
monkey_cmd=monkey_cmd,
monkey_env=monkey_env,
- quiet=True,
+ quiet=False,
wrapper=ctx.get("wrapper"))
assert_browser(ctx)
ctx['windows'] = dict()
@@ -436,13 +436,26 @@ def run_test_step_action_plot_check(ctx, step):
print(get_indent(ctx) + "Action: " + step["action"])
assert_browser(ctx)
win = ctx['windows'][step['window']]
+
+ if 'area' in step.keys():
+ if step["area"] == "extent":
+ # ought to capture the extent updates and use that, instead use a
+ # big area and have the browser clip it
+ area=["0","0","1000","1000000"]
+ else:
+ area = [step["area"]]
+ else:
+ area = None
+
+ # get the list of checks
if 'checks' in step.keys():
checks = step['checks']
else:
checks = {}
+
all_text_list = []
bitmaps = []
- for plot in win.redraw():
+ for plot in win.redraw(coords=area):
if plot[0] == 'TEXT':
all_text_list.extend(plot[6:])
if plot[0] == 'BITMAP':
--
NetSurf Browser
1 year, 12 months
netsurf: branch master updated. release/3.10-99-gff22519
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/ff225194f338519a4856f...
...commit http://git.netsurf-browser.org/netsurf.git/commit/ff225194f338519a4856f24...
...tree http://git.netsurf-browser.org/netsurf.git/tree/ff225194f338519a4856f24b1...
The branch, master has been updated
via ff225194f338519a4856f24b1196ded583ff51af (commit)
from 55fadc802ac80286e4f7266866ad789c78f57483 (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=ff225194f338519a485...
commit ff225194f338519a4856f24b1196ded583ff51af
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
use list style formatting from libcss
diff --git a/content/handlers/html/Makefile b/content/handlers/html/Makefile
index 968c96f..8bb329b 100644
--- a/content/handlers/html/Makefile
+++ b/content/handlers/html/Makefile
@@ -16,7 +16,6 @@ S_HTML := box_construct.c \
imagemap.c \
interaction.c \
layout.c \
- list_counter_style.c \
object.c \
redraw.c \
redraw_border.c \
diff --git a/content/handlers/html/box_construct.c b/content/handlers/html/box_construct.c
index 6c6fc24..a133578 100644
--- a/content/handlers/html/box_construct.c
+++ b/content/handlers/html/box_construct.c
@@ -47,7 +47,6 @@
#include "html/box_special.h"
#include "html/box_normalise.h"
#include "html/form_internal.h"
-#include "html/list_counter_style.h"
/**
* Context for box tree construction
@@ -424,6 +423,7 @@ box_construct_marker(struct box *box,
struct box *marker;
enum css_list_style_type_e list_style_type;
size_t counter_len;
+ css_error css_res;
marker = box_create(NULL, box->style, false, NULL, NULL, title,
NULL, ctx->bctx);
@@ -467,25 +467,36 @@ box_construct_marker(struct box *box,
return false;
}
- counter_len = list_counter_style_value(marker->text,
- LIST_MARKER_SIZE,
- list_style_type,
- marker->rows);
- if (counter_len > LIST_MARKER_SIZE) {
- /* use computed size as marker did not fit allocation */
- marker->text = talloc_realloc(ctx->bctx,
- marker->text,
- char,
- counter_len);
- if (marker->text == NULL) {
- return false;
- }
- counter_len = list_counter_style_value(marker->text,
+ css_res = css_computed_format_list_style(box->style,
+ marker->rows,
+ marker->text,
+ LIST_MARKER_SIZE,
+ &counter_len);
+ if (css_res == CSS_OK) {
+ if (counter_len > LIST_MARKER_SIZE) {
+ /*
+ * use computed size as marker did not fit
+ * in default allocation
+ */
+ marker->text = talloc_realloc(ctx->bctx,
+ marker->text,
+ char,
+ counter_len);
+ if (marker->text == NULL) {
+ return false;
+ }
+ css_computed_format_list_style(box->style,
+ marker->rows,
+ marker->text,
counter_len,
- list_style_type,
- marker->rows);
+ &counter_len);
+ }
+ marker->length = counter_len;
+ } else {
+ /* failed to format marker so use none type */
+ marker->text = NULL;
+ marker->length = 0;
}
- marker->length = counter_len;
break;
}
diff --git a/content/handlers/html/list_counter_style.c b/content/handlers/html/list_counter_style.c
deleted file mode 100644
index 81d9aa3..0000000
--- a/content/handlers/html/list_counter_style.c
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * Copyright 2021 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * 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
- * Implementation of css list counter styling
- */
-
-#include <stddef.h>
-
-#include "css/select.h"
-
-#include "html/list_counter_style.h"
-
-
-#define SYMBOL_SIZE 4
-typedef char symbol_t[SYMBOL_SIZE];
-
-struct list_counter_style {
- const char *name; /**< style name for debug purposes */
- struct {
- const int start; /**< first acceptable value for this style */
- const int end; /**< last acceptable value for this style */
- } range;
- struct {
- const unsigned int length;
- const symbol_t value;
- } pad;
- const char *prefix;
- const char *postfix;
- const symbol_t *symbols; /**< array of symbols which represent this style */
- const int *weights; /**< symbol weights for additive schemes */
- const size_t items; /**< items in symbol and weight table */
- size_t (*calc)(uint8_t *ares, const size_t alen, int value, const struct list_counter_style *cstyle); /**< function to calculate the system */
-};
-
-/**
- * Copy a null-terminated UTF-8 string to buffer at offset, if there is space
- *
- * \param[in] buf The output buffer
- * \param[in] buflen The length of \a buf
- * \param[in] pos Current position in \a buf
- * \param[in] str The string to copy into \a buf
- * \return The number of bytes needed in the output buffer which may be
- * larger than \a buflen but the buffer will not be overrun
- */
-static inline size_t
-copy_string(char *buf, const size_t buflen, size_t pos, const char *str)
-{
- size_t sidx = 0; /* current string index */
-
- while (str[sidx] != '\0') {
- if (pos < buflen) {
- buf[pos] = str[sidx];
- }
- pos++;
- sidx++;
- }
-
- return sidx;
-}
-
-/**
- * Copy a UTF-8 symbol to buffer at offset, if there is space
- *
- * \param[in] buf The output buffer
- * \param[in] buflen The length of \a buf
- * \param[in] pos Current position in \a buf
- * \param[in] symbol The symbol to copy into \a buf
- * \return The number of bytes needed in the output buffer which may be
- * larger than \a buflen but the buffer will not be overrun
- */
-static inline size_t
-copy_symbol(char *buf, const size_t buflen, size_t pos, const symbol_t symbol)
-{
- size_t sidx = 0; /* current symbol index */
-
- while ((sidx < sizeof(symbol_t)) && (symbol[sidx] != '\0')) {
- if (pos < buflen) {
- buf[pos] = symbol[sidx];
- }
- pos++;
- sidx++;
- }
-
- return sidx;
-}
-
-/**
- * maps alphabet values to output values with a symbol table
- *
- * Takes a list of alphabet values and for each one outputs the
- * compete symbol (in utf8) to an output buffer.
- *
- * \param buf The oputput buffer
- * \param buflen the length of \a buf
- * \param aval array of alphabet values
- * \param alen The number of values in \a alen
- * \param symtab The symbol table
- * \param symtablen The number of symbols in \a symtab
- * \return The number of bytes needed in the output buffer whichmay be
- * larger than \a buflen but the buffer will not be overrun
- */
-static size_t
-map_aval_to_symbols(char *buf, const size_t buflen,
- const uint8_t *aval, const size_t alen,
- const struct list_counter_style *cstyle)
-{
- size_t oidx = 0;
- size_t aidx; /* numeral index */
- const symbol_t postfix = "."; /* default postfix string */
-
- /* add padding if required */
- if (alen < cstyle->pad.length) {
- size_t pidx; /* padding index */
- for (pidx=cstyle->pad.length - alen; pidx > 0; pidx--) {
- oidx += copy_symbol(buf, buflen, oidx,
- cstyle->pad.value);
- }
- }
-
- /* map symbols */
- for (aidx=0; aidx < alen; aidx++) {
- oidx += copy_symbol(buf, buflen, oidx,
- cstyle->symbols[aval[aidx]]);
- }
-
- /* postfix */
- oidx += copy_string(buf, buflen, oidx,
- (cstyle->postfix != NULL) ?
- cstyle->postfix : postfix);
-
- return oidx;
-}
-
-
-/**
- * generate numeric symbol values
- *
- * fills array with numeric values that represent the input value
- *
- * \param ares Buffer to recive the converted values
- * \param alen the length of \a ares buffer
- * \param value The value to convert
- * \param slen The number of symbols in the alphabet
- * \return The length a complete conversion which may be larger than \a alen
- */
-static size_t
-calc_numeric_system(uint8_t *ares,
- const size_t alen,
- int value,
- const struct list_counter_style *cstyle)
-{
- size_t idx = 0;
- uint8_t *first;
- uint8_t *last;
-
- /* generate alphabet values in ascending order */
- while (value > 0) {
- if (idx < alen) {
- ares[idx] = value % cstyle->items;
- }
- idx++;
- value = value / cstyle->items;
- }
-
- /* put the values in decending order */
- first = ares;
- if (idx < alen) {
- last = first + (idx - 1);
- } else {
- last = first + (alen - 1);
- }
- while (first < last) {
- *first ^= *last;
- *last ^= *first;
- *first ^= *last;
- first++;
- last--;
- }
-
- return idx;
-}
-
-
-/**
- * generate addative symbol values
- *
- * fills array with numeric values that represent the input value
- *
- * \param ares Buffer to recive the converted values
- * \param alen the length of \a ares buffer
- * \param value The value to convert
- * \param wlen The number of weights
- * \return The length a complete conversion which may be larger than \a alen
- */
-static size_t
-calc_additive_system(uint8_t *ares,
- const size_t alen,
- int value,
- const struct list_counter_style *cstyle)
-{
- size_t widx; /* weight index */
- size_t aidx = 0;
- size_t idx;
- size_t times; /* number of times a weight occours */
-
- /* iterate over the available weights */
- for (widx = 0; widx < cstyle->items;widx++) {
- times = value / cstyle->weights[widx];
- if (times > 0) {
- for (idx=0;idx < times;idx++) {
- if (aidx < alen) {
- ares[aidx] = widx;
- }
- aidx++;
- }
-
- value -= times * cstyle->weights[widx];
- }
- }
-
- return aidx;
-}
-
-
-/**
- * generate alphabet symbol values for latin and greek labelling
- *
- * fills array with alphabet values suitable for the input value
- *
- * \param ares Buffer to recive the converted values
- * \param alen the length of \a ares buffer
- * \param value The value to convert
- * \param slen The number of symbols in the alphabet
- * \return The length a complete conversion which may be larger than \a alen
- */
-static size_t
-calc_alphabet_system(uint8_t *ares,
- const size_t alen,
- int value,
- const struct list_counter_style *cstyle)
-{
- size_t idx = 0;
- uint8_t *first;
- uint8_t *last;
-
- /* generate alphabet values in ascending order */
- while (value > 0) {
- --value;
- if (idx < alen) {
- ares[idx] = value % cstyle->items;
- }
- idx++;
- value = value / cstyle->items;
- }
-
- /* put the values in decending order */
- first = ares;
- if (idx < alen) {
- last = first + (idx - 1);
- } else {
- last = first + (alen - 1);
- }
- while (first < last) {
- *first ^= *last;
- *last ^= *first;
- *first ^= *last;
- first++;
- last--;
- }
-
- return idx;
-}
-
-
-/**
- * Roman numeral conversion
- *
- * \return The number of numerals that are nesesary for full output
- */
-static size_t
-calc_roman_system(uint8_t *buf,
- const size_t maxlen,
- int value,
- const struct list_counter_style *cstyle)
-{
- const int S[] = { 0, 2, 4, 2, 4, 2, 4 };
- const int D[] = { 1000, 500, 100, 50, 10, 5, 1 };
- const size_t L = sizeof(D) / sizeof(int) - 1;
- size_t k = 0; /* index into output buffer */
- unsigned int i = 0; /* index into maps */
- int r, r2;
-
- assert(cstyle->items == 7);
-
- while (value > 0) {
- if (D[i] <= value) {
- r = value / D[i];
- value = value - (r * D[i]);
- if (i < L) {
- /* lookahead */
- r2 = value / D[i+1];
- }
- if (i < L && r2 >= S[i+1]) {
- /* will violate repeat boundary on next pass */
- value = value - (r2 * D[i+1]);
- if (k < maxlen) buf[k++] = i+1;
- if (k < maxlen) buf[k++] = i-1;
- } else if (S[i] && r >= S[i]) {
- /* violated repeat boundary on this pass */
- if (k < maxlen) buf[k++] = i;
- if (k < maxlen) buf[k++] = i-1;
- } else {
- while (r-- > 0 && k < maxlen) {
- buf[k++] = i;
- }
- }
- }
- i++;
- }
- if (k < maxlen) {
- buf[k] = '\0';
- }
- return k;
-}
-
-
-/* tables for all the counter styles */
-
-
-static const symbol_t georgian_symbols[] = {
- "���",
- "���", "���", "���", "���", "���", "���", "���", "���", "���",
- "���", "���", "���", "���", "���", "���", "���", "���", "���",
- "���", "���", "���", "���", "���", "���", "���", "���", "���",
- "���", "���", "���", "���", "���", "���", "���", "���", "���",
-};
-static const int georgian_weights[] = {
- 10000,
- 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000,
- 900, 800, 700, 600, 500, 400, 300, 200, 100,
- 90, 80, 70, 60, 50, 40, 30, 20, 10,
- 9, 8, 7, 6, 5, 4, 3, 2, 1
-};
-static struct list_counter_style lcs_georgian = {
- .name="georgian",
- .range.start = 1,
- .range.end = 19999,
- .symbols = georgian_symbols,
- .weights = georgian_weights,
- .items = (sizeof(georgian_symbols) / SYMBOL_SIZE),
- .calc = calc_additive_system,
-};
-
-
-static const symbol_t armenian_symbols[] = {
- "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��", "��", "��", "��", "��", "��"
-};
-static const int armenian_weights[] = {
- 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000,
- 900, 800, 700, 600, 500, 400, 300, 200, 100,
- 90, 80, 70, 60, 50, 40, 30, 20, 10,
- 9, 8, 7, 6, 5, 4, 3, 2, 1
-};
-static struct list_counter_style lcs_armenian = {
- .name = "armenian",
- .range.start = 1,
- .range.end = 9999,
- .symbols = armenian_symbols,
- .weights = armenian_weights,
- .items = (sizeof(armenian_symbols) / SYMBOL_SIZE),
- .calc = calc_additive_system,
-};
-
-
-static const symbol_t decimal_symbols[] = {
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
-};
-static struct list_counter_style lcs_decimal = {
- .name = "decimal",
- .symbols = decimal_symbols,
- .items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
- .calc = calc_numeric_system,
-};
-
-
-static struct list_counter_style lcs_decimal_leading_zero = {
- .name = "decimal-leading-zero",
- .pad.length = 2,
- .pad.value = "0",
- .symbols = decimal_symbols,
- .items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
- .calc = calc_numeric_system,
-};
-
-
-static const symbol_t lower_greek_symbols[] = {
- "��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��"
-};
-static struct list_counter_style lcs_lower_greek = {
- .name="lower-greek",
- .symbols = lower_greek_symbols,
- .items = (sizeof(lower_greek_symbols) / SYMBOL_SIZE),
- .calc = calc_alphabet_system,
-};
-
-
-static const symbol_t upper_alpha_symbols[] = {
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
- "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
- "U", "V", "W", "X", "Y", "Z"
-};
-static struct list_counter_style lcs_upper_alpha = {
- .name="upper-alpha",
- .symbols = upper_alpha_symbols,
- .items = (sizeof(upper_alpha_symbols) / SYMBOL_SIZE),
- .calc = calc_alphabet_system,
-};
-
-
-static const symbol_t lower_alpha_symbols[] = {
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
- "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
- "u", "v", "w", "x", "y", "z"
-};
-static struct list_counter_style lcs_lower_alpha = {
- .name="lower-alpha",
- .symbols = lower_alpha_symbols,
- .items = (sizeof(lower_alpha_symbols) / SYMBOL_SIZE),
- .calc = calc_alphabet_system,
-};
-
-
-static const symbol_t upper_roman_symbols[] = {
- "M", "D", "C", "L", "X", "V", "I"
-};
-static struct list_counter_style lcs_upper_roman = {
- .name="upper-roman",
- .symbols = upper_roman_symbols,
- .items = (sizeof(upper_roman_symbols) / SYMBOL_SIZE),
- .calc = calc_roman_system,
-};
-
-
-static const symbol_t lower_roman_symbols[] = {
- "m", "d", "c", "l", "x", "v", "i"
-};
-static struct list_counter_style lcs_lower_roman = {
- .name="lower-roman",
- .symbols = lower_roman_symbols,
- .items = (sizeof(lower_roman_symbols) / SYMBOL_SIZE),
- .calc = calc_roman_system,
-};
-
-#if 0
-static const symbol_t lower_hexidecimal_symbols[] = {
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
- "a", "b", "c", "d", "e", "f"
-};
-static struct list_counter_style lcs_lower_hexidecimal = {
- .name="lower_hexidecimal",
- .symbols = lower_hexidecimal_symbols,
- .items = (sizeof(lower_hexidecimal_symbols) / SYMBOL_SIZE),
- .calc = calc_numeric_system,
-};
-#endif
-
-
-/* exported interface defined in html/list_counter_style.h */
-size_t
-list_counter_style_value(char *text,
- size_t text_len,
- enum css_list_style_type_e list_style_type,
- int value)
-{
- size_t alen;
- uint8_t aval[20];
- struct list_counter_style *cstyle;
-
- switch (list_style_type) {
- case CSS_LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO:
- cstyle = &lcs_decimal_leading_zero;
- break;
-
- case CSS_LIST_STYLE_TYPE_LOWER_ROMAN:
- cstyle = &lcs_lower_roman;
- break;
-
- case CSS_LIST_STYLE_TYPE_UPPER_ROMAN:
- cstyle = &lcs_upper_roman;
- break;
-
- case CSS_LIST_STYLE_TYPE_LOWER_ALPHA:
- case CSS_LIST_STYLE_TYPE_LOWER_LATIN:
- cstyle = &lcs_lower_alpha;
- break;
-
- case CSS_LIST_STYLE_TYPE_UPPER_ALPHA:
- case CSS_LIST_STYLE_TYPE_UPPER_LATIN:
- cstyle = &lcs_upper_alpha;
- break;
-
- case CSS_LIST_STYLE_TYPE_LOWER_GREEK:
- cstyle = &lcs_lower_greek;
- break;
-
- case CSS_LIST_STYLE_TYPE_ARMENIAN:
- cstyle = &lcs_armenian;
- break;
-
- case CSS_LIST_STYLE_TYPE_GEORGIAN:
- cstyle = &lcs_georgian;
- break;
-
- case CSS_LIST_STYLE_TYPE_DECIMAL:
- default:
- cstyle = &lcs_decimal;
- break;
- }
-
- alen = cstyle->calc(aval, sizeof(aval), value, cstyle);
-
- /* ensure it is possible to calculate with the selected system */
- if ((alen == 0) || (alen >= sizeof(aval))) {
- /* retry in decimal */
- alen = lcs_decimal.calc(aval, sizeof(aval), value, &lcs_decimal);
- if ((alen == 0) || (alen >= sizeof(aval))) {
- /* failed in decimal, give up */
- return 0;
- }
- }
-
- return map_aval_to_symbols(text, text_len, aval, alen, cstyle);
-}
diff --git a/content/handlers/html/list_counter_style.h b/content/handlers/html/list_counter_style.h
deleted file mode 100644
index 2b1e79a..0000000
--- a/content/handlers/html/list_counter_style.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2021 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * 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
- * List counter style handling
- *
- * These functions provide font related services. They all work on
- * UTF-8 strings with lengths given.
- */
-
-#ifndef NETSURF_HTML_LIST_COUNTER_STYLE_H
-#define NETSURF_HTML_LIST_COUNTER_STYLE_H
-
-/**
- * format value into a list marker with a style
- *
- * \param text buffer to recive the result
- * \param text_len The length of the \a text buffer
- * \param list_style_type the css list style.
- * \param value The value to format.
- * \return The length of the complete output which may exceed \a text_len
- */
-size_t
-list_counter_style_value(char *text,
- size_t text_len,
- enum css_list_style_type_e list_style_type,
- int value);
-
-#endif
-----------------------------------------------------------------------
Summary of changes:
content/handlers/html/Makefile | 1 -
content/handlers/html/box_construct.c | 47 ++-
content/handlers/html/list_counter_style.c | 555 ----------------------------
content/handlers/html/list_counter_style.h | 45 ---
4 files changed, 29 insertions(+), 619 deletions(-)
delete mode 100644 content/handlers/html/list_counter_style.c
delete mode 100644 content/handlers/html/list_counter_style.h
diff --git a/content/handlers/html/Makefile b/content/handlers/html/Makefile
index 968c96f..8bb329b 100644
--- a/content/handlers/html/Makefile
+++ b/content/handlers/html/Makefile
@@ -16,7 +16,6 @@ S_HTML := box_construct.c \
imagemap.c \
interaction.c \
layout.c \
- list_counter_style.c \
object.c \
redraw.c \
redraw_border.c \
diff --git a/content/handlers/html/box_construct.c b/content/handlers/html/box_construct.c
index 6c6fc24..a133578 100644
--- a/content/handlers/html/box_construct.c
+++ b/content/handlers/html/box_construct.c
@@ -47,7 +47,6 @@
#include "html/box_special.h"
#include "html/box_normalise.h"
#include "html/form_internal.h"
-#include "html/list_counter_style.h"
/**
* Context for box tree construction
@@ -424,6 +423,7 @@ box_construct_marker(struct box *box,
struct box *marker;
enum css_list_style_type_e list_style_type;
size_t counter_len;
+ css_error css_res;
marker = box_create(NULL, box->style, false, NULL, NULL, title,
NULL, ctx->bctx);
@@ -467,25 +467,36 @@ box_construct_marker(struct box *box,
return false;
}
- counter_len = list_counter_style_value(marker->text,
- LIST_MARKER_SIZE,
- list_style_type,
- marker->rows);
- if (counter_len > LIST_MARKER_SIZE) {
- /* use computed size as marker did not fit allocation */
- marker->text = talloc_realloc(ctx->bctx,
- marker->text,
- char,
- counter_len);
- if (marker->text == NULL) {
- return false;
- }
- counter_len = list_counter_style_value(marker->text,
+ css_res = css_computed_format_list_style(box->style,
+ marker->rows,
+ marker->text,
+ LIST_MARKER_SIZE,
+ &counter_len);
+ if (css_res == CSS_OK) {
+ if (counter_len > LIST_MARKER_SIZE) {
+ /*
+ * use computed size as marker did not fit
+ * in default allocation
+ */
+ marker->text = talloc_realloc(ctx->bctx,
+ marker->text,
+ char,
+ counter_len);
+ if (marker->text == NULL) {
+ return false;
+ }
+ css_computed_format_list_style(box->style,
+ marker->rows,
+ marker->text,
counter_len,
- list_style_type,
- marker->rows);
+ &counter_len);
+ }
+ marker->length = counter_len;
+ } else {
+ /* failed to format marker so use none type */
+ marker->text = NULL;
+ marker->length = 0;
}
- marker->length = counter_len;
break;
}
diff --git a/content/handlers/html/list_counter_style.c b/content/handlers/html/list_counter_style.c
deleted file mode 100644
index 81d9aa3..0000000
--- a/content/handlers/html/list_counter_style.c
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * Copyright 2021 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * 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
- * Implementation of css list counter styling
- */
-
-#include <stddef.h>
-
-#include "css/select.h"
-
-#include "html/list_counter_style.h"
-
-
-#define SYMBOL_SIZE 4
-typedef char symbol_t[SYMBOL_SIZE];
-
-struct list_counter_style {
- const char *name; /**< style name for debug purposes */
- struct {
- const int start; /**< first acceptable value for this style */
- const int end; /**< last acceptable value for this style */
- } range;
- struct {
- const unsigned int length;
- const symbol_t value;
- } pad;
- const char *prefix;
- const char *postfix;
- const symbol_t *symbols; /**< array of symbols which represent this style */
- const int *weights; /**< symbol weights for additive schemes */
- const size_t items; /**< items in symbol and weight table */
- size_t (*calc)(uint8_t *ares, const size_t alen, int value, const struct list_counter_style *cstyle); /**< function to calculate the system */
-};
-
-/**
- * Copy a null-terminated UTF-8 string to buffer at offset, if there is space
- *
- * \param[in] buf The output buffer
- * \param[in] buflen The length of \a buf
- * \param[in] pos Current position in \a buf
- * \param[in] str The string to copy into \a buf
- * \return The number of bytes needed in the output buffer which may be
- * larger than \a buflen but the buffer will not be overrun
- */
-static inline size_t
-copy_string(char *buf, const size_t buflen, size_t pos, const char *str)
-{
- size_t sidx = 0; /* current string index */
-
- while (str[sidx] != '\0') {
- if (pos < buflen) {
- buf[pos] = str[sidx];
- }
- pos++;
- sidx++;
- }
-
- return sidx;
-}
-
-/**
- * Copy a UTF-8 symbol to buffer at offset, if there is space
- *
- * \param[in] buf The output buffer
- * \param[in] buflen The length of \a buf
- * \param[in] pos Current position in \a buf
- * \param[in] symbol The symbol to copy into \a buf
- * \return The number of bytes needed in the output buffer which may be
- * larger than \a buflen but the buffer will not be overrun
- */
-static inline size_t
-copy_symbol(char *buf, const size_t buflen, size_t pos, const symbol_t symbol)
-{
- size_t sidx = 0; /* current symbol index */
-
- while ((sidx < sizeof(symbol_t)) && (symbol[sidx] != '\0')) {
- if (pos < buflen) {
- buf[pos] = symbol[sidx];
- }
- pos++;
- sidx++;
- }
-
- return sidx;
-}
-
-/**
- * maps alphabet values to output values with a symbol table
- *
- * Takes a list of alphabet values and for each one outputs the
- * compete symbol (in utf8) to an output buffer.
- *
- * \param buf The oputput buffer
- * \param buflen the length of \a buf
- * \param aval array of alphabet values
- * \param alen The number of values in \a alen
- * \param symtab The symbol table
- * \param symtablen The number of symbols in \a symtab
- * \return The number of bytes needed in the output buffer whichmay be
- * larger than \a buflen but the buffer will not be overrun
- */
-static size_t
-map_aval_to_symbols(char *buf, const size_t buflen,
- const uint8_t *aval, const size_t alen,
- const struct list_counter_style *cstyle)
-{
- size_t oidx = 0;
- size_t aidx; /* numeral index */
- const symbol_t postfix = "."; /* default postfix string */
-
- /* add padding if required */
- if (alen < cstyle->pad.length) {
- size_t pidx; /* padding index */
- for (pidx=cstyle->pad.length - alen; pidx > 0; pidx--) {
- oidx += copy_symbol(buf, buflen, oidx,
- cstyle->pad.value);
- }
- }
-
- /* map symbols */
- for (aidx=0; aidx < alen; aidx++) {
- oidx += copy_symbol(buf, buflen, oidx,
- cstyle->symbols[aval[aidx]]);
- }
-
- /* postfix */
- oidx += copy_string(buf, buflen, oidx,
- (cstyle->postfix != NULL) ?
- cstyle->postfix : postfix);
-
- return oidx;
-}
-
-
-/**
- * generate numeric symbol values
- *
- * fills array with numeric values that represent the input value
- *
- * \param ares Buffer to recive the converted values
- * \param alen the length of \a ares buffer
- * \param value The value to convert
- * \param slen The number of symbols in the alphabet
- * \return The length a complete conversion which may be larger than \a alen
- */
-static size_t
-calc_numeric_system(uint8_t *ares,
- const size_t alen,
- int value,
- const struct list_counter_style *cstyle)
-{
- size_t idx = 0;
- uint8_t *first;
- uint8_t *last;
-
- /* generate alphabet values in ascending order */
- while (value > 0) {
- if (idx < alen) {
- ares[idx] = value % cstyle->items;
- }
- idx++;
- value = value / cstyle->items;
- }
-
- /* put the values in decending order */
- first = ares;
- if (idx < alen) {
- last = first + (idx - 1);
- } else {
- last = first + (alen - 1);
- }
- while (first < last) {
- *first ^= *last;
- *last ^= *first;
- *first ^= *last;
- first++;
- last--;
- }
-
- return idx;
-}
-
-
-/**
- * generate addative symbol values
- *
- * fills array with numeric values that represent the input value
- *
- * \param ares Buffer to recive the converted values
- * \param alen the length of \a ares buffer
- * \param value The value to convert
- * \param wlen The number of weights
- * \return The length a complete conversion which may be larger than \a alen
- */
-static size_t
-calc_additive_system(uint8_t *ares,
- const size_t alen,
- int value,
- const struct list_counter_style *cstyle)
-{
- size_t widx; /* weight index */
- size_t aidx = 0;
- size_t idx;
- size_t times; /* number of times a weight occours */
-
- /* iterate over the available weights */
- for (widx = 0; widx < cstyle->items;widx++) {
- times = value / cstyle->weights[widx];
- if (times > 0) {
- for (idx=0;idx < times;idx++) {
- if (aidx < alen) {
- ares[aidx] = widx;
- }
- aidx++;
- }
-
- value -= times * cstyle->weights[widx];
- }
- }
-
- return aidx;
-}
-
-
-/**
- * generate alphabet symbol values for latin and greek labelling
- *
- * fills array with alphabet values suitable for the input value
- *
- * \param ares Buffer to recive the converted values
- * \param alen the length of \a ares buffer
- * \param value The value to convert
- * \param slen The number of symbols in the alphabet
- * \return The length a complete conversion which may be larger than \a alen
- */
-static size_t
-calc_alphabet_system(uint8_t *ares,
- const size_t alen,
- int value,
- const struct list_counter_style *cstyle)
-{
- size_t idx = 0;
- uint8_t *first;
- uint8_t *last;
-
- /* generate alphabet values in ascending order */
- while (value > 0) {
- --value;
- if (idx < alen) {
- ares[idx] = value % cstyle->items;
- }
- idx++;
- value = value / cstyle->items;
- }
-
- /* put the values in decending order */
- first = ares;
- if (idx < alen) {
- last = first + (idx - 1);
- } else {
- last = first + (alen - 1);
- }
- while (first < last) {
- *first ^= *last;
- *last ^= *first;
- *first ^= *last;
- first++;
- last--;
- }
-
- return idx;
-}
-
-
-/**
- * Roman numeral conversion
- *
- * \return The number of numerals that are nesesary for full output
- */
-static size_t
-calc_roman_system(uint8_t *buf,
- const size_t maxlen,
- int value,
- const struct list_counter_style *cstyle)
-{
- const int S[] = { 0, 2, 4, 2, 4, 2, 4 };
- const int D[] = { 1000, 500, 100, 50, 10, 5, 1 };
- const size_t L = sizeof(D) / sizeof(int) - 1;
- size_t k = 0; /* index into output buffer */
- unsigned int i = 0; /* index into maps */
- int r, r2;
-
- assert(cstyle->items == 7);
-
- while (value > 0) {
- if (D[i] <= value) {
- r = value / D[i];
- value = value - (r * D[i]);
- if (i < L) {
- /* lookahead */
- r2 = value / D[i+1];
- }
- if (i < L && r2 >= S[i+1]) {
- /* will violate repeat boundary on next pass */
- value = value - (r2 * D[i+1]);
- if (k < maxlen) buf[k++] = i+1;
- if (k < maxlen) buf[k++] = i-1;
- } else if (S[i] && r >= S[i]) {
- /* violated repeat boundary on this pass */
- if (k < maxlen) buf[k++] = i;
- if (k < maxlen) buf[k++] = i-1;
- } else {
- while (r-- > 0 && k < maxlen) {
- buf[k++] = i;
- }
- }
- }
- i++;
- }
- if (k < maxlen) {
- buf[k] = '\0';
- }
- return k;
-}
-
-
-/* tables for all the counter styles */
-
-
-static const symbol_t georgian_symbols[] = {
- "���",
- "���", "���", "���", "���", "���", "���", "���", "���", "���",
- "���", "���", "���", "���", "���", "���", "���", "���", "���",
- "���", "���", "���", "���", "���", "���", "���", "���", "���",
- "���", "���", "���", "���", "���", "���", "���", "���", "���",
-};
-static const int georgian_weights[] = {
- 10000,
- 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000,
- 900, 800, 700, 600, 500, 400, 300, 200, 100,
- 90, 80, 70, 60, 50, 40, 30, 20, 10,
- 9, 8, 7, 6, 5, 4, 3, 2, 1
-};
-static struct list_counter_style lcs_georgian = {
- .name="georgian",
- .range.start = 1,
- .range.end = 19999,
- .symbols = georgian_symbols,
- .weights = georgian_weights,
- .items = (sizeof(georgian_symbols) / SYMBOL_SIZE),
- .calc = calc_additive_system,
-};
-
-
-static const symbol_t armenian_symbols[] = {
- "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��", "��", "��", "��", "��", "��"
-};
-static const int armenian_weights[] = {
- 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000,
- 900, 800, 700, 600, 500, 400, 300, 200, 100,
- 90, 80, 70, 60, 50, 40, 30, 20, 10,
- 9, 8, 7, 6, 5, 4, 3, 2, 1
-};
-static struct list_counter_style lcs_armenian = {
- .name = "armenian",
- .range.start = 1,
- .range.end = 9999,
- .symbols = armenian_symbols,
- .weights = armenian_weights,
- .items = (sizeof(armenian_symbols) / SYMBOL_SIZE),
- .calc = calc_additive_system,
-};
-
-
-static const symbol_t decimal_symbols[] = {
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
-};
-static struct list_counter_style lcs_decimal = {
- .name = "decimal",
- .symbols = decimal_symbols,
- .items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
- .calc = calc_numeric_system,
-};
-
-
-static struct list_counter_style lcs_decimal_leading_zero = {
- .name = "decimal-leading-zero",
- .pad.length = 2,
- .pad.value = "0",
- .symbols = decimal_symbols,
- .items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
- .calc = calc_numeric_system,
-};
-
-
-static const symbol_t lower_greek_symbols[] = {
- "��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
- "��", "��", "��", "��"
-};
-static struct list_counter_style lcs_lower_greek = {
- .name="lower-greek",
- .symbols = lower_greek_symbols,
- .items = (sizeof(lower_greek_symbols) / SYMBOL_SIZE),
- .calc = calc_alphabet_system,
-};
-
-
-static const symbol_t upper_alpha_symbols[] = {
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
- "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
- "U", "V", "W", "X", "Y", "Z"
-};
-static struct list_counter_style lcs_upper_alpha = {
- .name="upper-alpha",
- .symbols = upper_alpha_symbols,
- .items = (sizeof(upper_alpha_symbols) / SYMBOL_SIZE),
- .calc = calc_alphabet_system,
-};
-
-
-static const symbol_t lower_alpha_symbols[] = {
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
- "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
- "u", "v", "w", "x", "y", "z"
-};
-static struct list_counter_style lcs_lower_alpha = {
- .name="lower-alpha",
- .symbols = lower_alpha_symbols,
- .items = (sizeof(lower_alpha_symbols) / SYMBOL_SIZE),
- .calc = calc_alphabet_system,
-};
-
-
-static const symbol_t upper_roman_symbols[] = {
- "M", "D", "C", "L", "X", "V", "I"
-};
-static struct list_counter_style lcs_upper_roman = {
- .name="upper-roman",
- .symbols = upper_roman_symbols,
- .items = (sizeof(upper_roman_symbols) / SYMBOL_SIZE),
- .calc = calc_roman_system,
-};
-
-
-static const symbol_t lower_roman_symbols[] = {
- "m", "d", "c", "l", "x", "v", "i"
-};
-static struct list_counter_style lcs_lower_roman = {
- .name="lower-roman",
- .symbols = lower_roman_symbols,
- .items = (sizeof(lower_roman_symbols) / SYMBOL_SIZE),
- .calc = calc_roman_system,
-};
-
-#if 0
-static const symbol_t lower_hexidecimal_symbols[] = {
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
- "a", "b", "c", "d", "e", "f"
-};
-static struct list_counter_style lcs_lower_hexidecimal = {
- .name="lower_hexidecimal",
- .symbols = lower_hexidecimal_symbols,
- .items = (sizeof(lower_hexidecimal_symbols) / SYMBOL_SIZE),
- .calc = calc_numeric_system,
-};
-#endif
-
-
-/* exported interface defined in html/list_counter_style.h */
-size_t
-list_counter_style_value(char *text,
- size_t text_len,
- enum css_list_style_type_e list_style_type,
- int value)
-{
- size_t alen;
- uint8_t aval[20];
- struct list_counter_style *cstyle;
-
- switch (list_style_type) {
- case CSS_LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO:
- cstyle = &lcs_decimal_leading_zero;
- break;
-
- case CSS_LIST_STYLE_TYPE_LOWER_ROMAN:
- cstyle = &lcs_lower_roman;
- break;
-
- case CSS_LIST_STYLE_TYPE_UPPER_ROMAN:
- cstyle = &lcs_upper_roman;
- break;
-
- case CSS_LIST_STYLE_TYPE_LOWER_ALPHA:
- case CSS_LIST_STYLE_TYPE_LOWER_LATIN:
- cstyle = &lcs_lower_alpha;
- break;
-
- case CSS_LIST_STYLE_TYPE_UPPER_ALPHA:
- case CSS_LIST_STYLE_TYPE_UPPER_LATIN:
- cstyle = &lcs_upper_alpha;
- break;
-
- case CSS_LIST_STYLE_TYPE_LOWER_GREEK:
- cstyle = &lcs_lower_greek;
- break;
-
- case CSS_LIST_STYLE_TYPE_ARMENIAN:
- cstyle = &lcs_armenian;
- break;
-
- case CSS_LIST_STYLE_TYPE_GEORGIAN:
- cstyle = &lcs_georgian;
- break;
-
- case CSS_LIST_STYLE_TYPE_DECIMAL:
- default:
- cstyle = &lcs_decimal;
- break;
- }
-
- alen = cstyle->calc(aval, sizeof(aval), value, cstyle);
-
- /* ensure it is possible to calculate with the selected system */
- if ((alen == 0) || (alen >= sizeof(aval))) {
- /* retry in decimal */
- alen = lcs_decimal.calc(aval, sizeof(aval), value, &lcs_decimal);
- if ((alen == 0) || (alen >= sizeof(aval))) {
- /* failed in decimal, give up */
- return 0;
- }
- }
-
- return map_aval_to_symbols(text, text_len, aval, alen, cstyle);
-}
diff --git a/content/handlers/html/list_counter_style.h b/content/handlers/html/list_counter_style.h
deleted file mode 100644
index 2b1e79a..0000000
--- a/content/handlers/html/list_counter_style.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2021 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * 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
- * List counter style handling
- *
- * These functions provide font related services. They all work on
- * UTF-8 strings with lengths given.
- */
-
-#ifndef NETSURF_HTML_LIST_COUNTER_STYLE_H
-#define NETSURF_HTML_LIST_COUNTER_STYLE_H
-
-/**
- * format value into a list marker with a style
- *
- * \param text buffer to recive the result
- * \param text_len The length of the \a text buffer
- * \param list_style_type the css list style.
- * \param value The value to format.
- * \return The length of the complete output which may exceed \a text_len
- */
-size_t
-list_counter_style_value(char *text,
- size_t text_len,
- enum css_list_style_type_e list_style_type,
- int value);
-
-#endif
--
NetSurf Browser
1 year, 12 months
libcss: branch master updated. release/0.9.1-9-g1c76ee6
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/1c76ee6efeab2e9307d0a8...
...commit http://git.netsurf-browser.org/libcss.git/commit/1c76ee6efeab2e9307d0a8aa...
...tree http://git.netsurf-browser.org/libcss.git/tree/1c76ee6efeab2e9307d0a8aafa...
The branch, master has been updated
via 1c76ee6efeab2e9307d0a8aafa6666ca9db83128 (commit)
from b1e7643b3ebf75cf98236f1464ec4715e2d16ddb (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=1c76ee6efeab2e9307d0...
commit 1c76ee6efeab2e9307d0a8aafa6666ca9db83128
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
make roman numeral list style obey range limit and fix decimal fallback
diff --git a/src/select/format_list_style.c b/src/select/format_list_style.c
index 3457e41..07d028b 100644
--- a/src/select/format_list_style.c
+++ b/src/select/format_list_style.c
@@ -281,27 +281,32 @@ calc_roman_system(uint8_t *buf,
const struct list_counter_style *cstyle)
{
const int S[] = { 0, 2, 4, 2, 4, 2, 4 };
- const int D[] = { 1000, 500, 100, 50, 10, 5, 1 };
- const size_t L = sizeof(D) / sizeof(int) - 1;
size_t k = 0; /* index into output buffer */
unsigned int i = 0; /* index into maps */
- int r, r2;
-
- UNUSED(cstyle);
+ int r;
+ int r2 = 0;
+ size_t L;
assert(cstyle->items == 7);
+ /* ensure value is within acceptable range of this system */
+ if ((value < cstyle->range.start) || (value > cstyle->range.end)) {
+ return 0;
+ }
+
+ L = cstyle->items - 1;
+
while (value > 0) {
- if (D[i] <= value) {
- r = value / D[i];
- value = value - (r * D[i]);
+ if (cstyle->weights[i] <= value) {
+ r = value / cstyle->weights[i];
+ value = value - (r * cstyle->weights[i]);
if (i < L) {
/* lookahead */
- r2 = value / D[i+1];
+ r2 = value / cstyle->weights[i+1];
}
if (i < L && r2 >= S[i+1]) {
/* will violate repeat boundary on next pass */
- value = value - (r2 * D[i+1]);
+ value = value - (r2 * cstyle->weights[i+1]);
if (k < maxlen) buf[k++] = i+1;
if (k < maxlen) buf[k++] = i-1;
} else if (S[i] && r >= S[i]) {
@@ -316,9 +321,7 @@ calc_roman_system(uint8_t *buf,
}
i++;
}
- if (k < maxlen) {
- buf[k] = '\0';
- }
+
return k;
}
@@ -437,12 +440,19 @@ static struct list_counter_style lcs_lower_alpha = {
};
+static const int roman_weights[] = {
+ 1000, 500, 100, 50, 10, 5, 1
+};
static const symbol_t upper_roman_symbols[] = {
"M", "D", "C", "L", "X", "V", "I"
};
static const struct list_counter_style lcs_upper_roman = {
.name = "upper-roman",
+ .range = {
+ .start = 1,
+ .end = 3999,},
.symbols = upper_roman_symbols,
+ .weights = roman_weights,
.items = (sizeof(upper_roman_symbols) / SYMBOL_SIZE),
.calc = calc_roman_system,
};
@@ -453,7 +463,11 @@ static const symbol_t lower_roman_symbols[] = {
};
static const struct list_counter_style lcs_lower_roman = {
.name = "lower-roman",
+ .range = {
+ .start = 1,
+ .end = 3999,},
.symbols = lower_roman_symbols,
+ .weights = roman_weights,
.items = (sizeof(lower_roman_symbols) / SYMBOL_SIZE),
.calc = calc_roman_system,
};
@@ -532,10 +546,12 @@ css_error css_computed_format_list_style(
/* ensure it is possible to calculate with the selected system */
if ((alen == 0) || (alen >= sizeof(aval))) {
/* retry in decimal */
- alen = lcs_decimal.calc(aval, sizeof(aval), value, &lcs_decimal);
+ cstyle = &lcs_decimal;
+
+ alen = cstyle->calc(aval, sizeof(aval), value, cstyle);
if ((alen == 0) || (alen >= sizeof(aval))) {
/* failed in decimal, give up */
- return 0;
+ return CSS_INVALID;
}
}
-----------------------------------------------------------------------
Summary of changes:
src/select/format_list_style.c | 46 +++++++++++++++++++++++++++-------------
1 file changed, 31 insertions(+), 15 deletions(-)
diff --git a/src/select/format_list_style.c b/src/select/format_list_style.c
index 3457e41..07d028b 100644
--- a/src/select/format_list_style.c
+++ b/src/select/format_list_style.c
@@ -281,27 +281,32 @@ calc_roman_system(uint8_t *buf,
const struct list_counter_style *cstyle)
{
const int S[] = { 0, 2, 4, 2, 4, 2, 4 };
- const int D[] = { 1000, 500, 100, 50, 10, 5, 1 };
- const size_t L = sizeof(D) / sizeof(int) - 1;
size_t k = 0; /* index into output buffer */
unsigned int i = 0; /* index into maps */
- int r, r2;
-
- UNUSED(cstyle);
+ int r;
+ int r2 = 0;
+ size_t L;
assert(cstyle->items == 7);
+ /* ensure value is within acceptable range of this system */
+ if ((value < cstyle->range.start) || (value > cstyle->range.end)) {
+ return 0;
+ }
+
+ L = cstyle->items - 1;
+
while (value > 0) {
- if (D[i] <= value) {
- r = value / D[i];
- value = value - (r * D[i]);
+ if (cstyle->weights[i] <= value) {
+ r = value / cstyle->weights[i];
+ value = value - (r * cstyle->weights[i]);
if (i < L) {
/* lookahead */
- r2 = value / D[i+1];
+ r2 = value / cstyle->weights[i+1];
}
if (i < L && r2 >= S[i+1]) {
/* will violate repeat boundary on next pass */
- value = value - (r2 * D[i+1]);
+ value = value - (r2 * cstyle->weights[i+1]);
if (k < maxlen) buf[k++] = i+1;
if (k < maxlen) buf[k++] = i-1;
} else if (S[i] && r >= S[i]) {
@@ -316,9 +321,7 @@ calc_roman_system(uint8_t *buf,
}
i++;
}
- if (k < maxlen) {
- buf[k] = '\0';
- }
+
return k;
}
@@ -437,12 +440,19 @@ static struct list_counter_style lcs_lower_alpha = {
};
+static const int roman_weights[] = {
+ 1000, 500, 100, 50, 10, 5, 1
+};
static const symbol_t upper_roman_symbols[] = {
"M", "D", "C", "L", "X", "V", "I"
};
static const struct list_counter_style lcs_upper_roman = {
.name = "upper-roman",
+ .range = {
+ .start = 1,
+ .end = 3999,},
.symbols = upper_roman_symbols,
+ .weights = roman_weights,
.items = (sizeof(upper_roman_symbols) / SYMBOL_SIZE),
.calc = calc_roman_system,
};
@@ -453,7 +463,11 @@ static const symbol_t lower_roman_symbols[] = {
};
static const struct list_counter_style lcs_lower_roman = {
.name = "lower-roman",
+ .range = {
+ .start = 1,
+ .end = 3999,},
.symbols = lower_roman_symbols,
+ .weights = roman_weights,
.items = (sizeof(lower_roman_symbols) / SYMBOL_SIZE),
.calc = calc_roman_system,
};
@@ -532,10 +546,12 @@ css_error css_computed_format_list_style(
/* ensure it is possible to calculate with the selected system */
if ((alen == 0) || (alen >= sizeof(aval))) {
/* retry in decimal */
- alen = lcs_decimal.calc(aval, sizeof(aval), value, &lcs_decimal);
+ cstyle = &lcs_decimal;
+
+ alen = cstyle->calc(aval, sizeof(aval), value, cstyle);
if ((alen == 0) || (alen >= sizeof(aval))) {
/* failed in decimal, give up */
- return 0;
+ return CSS_INVALID;
}
}
--
Cascading Style Sheets library
1 year, 12 months
libcss: branch master updated. release/0.9.1-8-gb1e7643
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/b1e7643b3ebf75cf98236f...
...commit http://git.netsurf-browser.org/libcss.git/commit/b1e7643b3ebf75cf98236f14...
...tree http://git.netsurf-browser.org/libcss.git/tree/b1e7643b3ebf75cf98236f1464...
The branch, master has been updated
via b1e7643b3ebf75cf98236f1464ec4715e2d16ddb (commit)
from 131bb27e3bf9d117ede308dd968814204f72e64c (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=b1e7643b3ebf75cf9823...
commit b1e7643b3ebf75cf98236f1464ec4715e2d16ddb
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
make list stle structures const and fix initialisation for older compilers
diff --git a/src/select/format_list_style.c b/src/select/format_list_style.c
index 8fff04a..3457e41 100644
--- a/src/select/format_list_style.c
+++ b/src/select/format_list_style.c
@@ -340,10 +340,11 @@ static const int georgian_weights[] = {
90, 80, 70, 60, 50, 40, 30, 20, 10,
9, 8, 7, 6, 5, 4, 3, 2, 1
};
-static struct list_counter_style lcs_georgian = {
+static const struct list_counter_style lcs_georgian = {
.name="georgian",
- .range.start = 1,
- .range.end = 19999,
+ .range = {
+ .start = 1,
+ .end = 19999,},
.symbols = georgian_symbols,
.weights = georgian_weights,
.items = (sizeof(georgian_symbols) / SYMBOL_SIZE),
@@ -363,10 +364,11 @@ static const int armenian_weights[] = {
90, 80, 70, 60, 50, 40, 30, 20, 10,
9, 8, 7, 6, 5, 4, 3, 2, 1
};
-static struct list_counter_style lcs_armenian = {
+static const struct list_counter_style lcs_armenian = {
.name = "armenian",
- .range.start = 1,
- .range.end = 9999,
+ .range = {
+ .start = 1,
+ .end = 9999,},
.symbols = armenian_symbols,
.weights = armenian_weights,
.items = (sizeof(armenian_symbols) / SYMBOL_SIZE),
@@ -377,7 +379,7 @@ static struct list_counter_style lcs_armenian = {
static const symbol_t decimal_symbols[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
};
-static struct list_counter_style lcs_decimal = {
+static const struct list_counter_style lcs_decimal = {
.name = "decimal",
.symbols = decimal_symbols,
.items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
@@ -385,10 +387,11 @@ static struct list_counter_style lcs_decimal = {
};
-static struct list_counter_style lcs_decimal_leading_zero = {
+static const struct list_counter_style lcs_decimal_leading_zero = {
.name = "decimal-leading-zero",
- .pad.length = 2,
- .pad.value = "0",
+ .pad = {
+ .length = 2,
+ .value = "0",},
.symbols = decimal_symbols,
.items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
.calc = calc_numeric_system,
@@ -400,8 +403,8 @@ static const symbol_t lower_greek_symbols[] = {
"��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
"��", "��", "��", "��"
};
-static struct list_counter_style lcs_lower_greek = {
- .name="lower-greek",
+static const struct list_counter_style lcs_lower_greek = {
+ .name = "lower-greek",
.symbols = lower_greek_symbols,
.items = (sizeof(lower_greek_symbols) / SYMBOL_SIZE),
.calc = calc_alphabet_system,
@@ -413,8 +416,8 @@ static const symbol_t upper_alpha_symbols[] = {
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"
};
-static struct list_counter_style lcs_upper_alpha = {
- .name="upper-alpha",
+static const struct list_counter_style lcs_upper_alpha = {
+ .name = "upper-alpha",
.symbols = upper_alpha_symbols,
.items = (sizeof(upper_alpha_symbols) / SYMBOL_SIZE),
.calc = calc_alphabet_system,
@@ -427,7 +430,7 @@ static const symbol_t lower_alpha_symbols[] = {
"u", "v", "w", "x", "y", "z"
};
static struct list_counter_style lcs_lower_alpha = {
- .name="lower-alpha",
+ .name = "lower-alpha",
.symbols = lower_alpha_symbols,
.items = (sizeof(lower_alpha_symbols) / SYMBOL_SIZE),
.calc = calc_alphabet_system,
@@ -437,8 +440,8 @@ static struct list_counter_style lcs_lower_alpha = {
static const symbol_t upper_roman_symbols[] = {
"M", "D", "C", "L", "X", "V", "I"
};
-static struct list_counter_style lcs_upper_roman = {
- .name="upper-roman",
+static const struct list_counter_style lcs_upper_roman = {
+ .name = "upper-roman",
.symbols = upper_roman_symbols,
.items = (sizeof(upper_roman_symbols) / SYMBOL_SIZE),
.calc = calc_roman_system,
@@ -448,8 +451,8 @@ static struct list_counter_style lcs_upper_roman = {
static const symbol_t lower_roman_symbols[] = {
"m", "d", "c", "l", "x", "v", "i"
};
-static struct list_counter_style lcs_lower_roman = {
- .name="lower-roman",
+static const struct list_counter_style lcs_lower_roman = {
+ .name = "lower-roman",
.symbols = lower_roman_symbols,
.items = (sizeof(lower_roman_symbols) / SYMBOL_SIZE),
.calc = calc_roman_system,
@@ -460,8 +463,8 @@ static const symbol_t lower_hexidecimal_symbols[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f"
};
-static struct list_counter_style lcs_lower_hexidecimal = {
- .name="lower_hexidecimal",
+static const struct list_counter_style lcs_lower_hexidecimal = {
+ .name = "lower_hexidecimal",
.symbols = lower_hexidecimal_symbols,
.items = (sizeof(lower_hexidecimal_symbols) / SYMBOL_SIZE),
.calc = calc_numeric_system,
@@ -481,7 +484,7 @@ css_error css_computed_format_list_style(
size_t alen;
uint8_t aval[20];
- struct list_counter_style *cstyle;
+ const struct list_counter_style *cstyle;
switch (type) {
case CSS_LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO:
-----------------------------------------------------------------------
Summary of changes:
src/select/format_list_style.c | 47 +++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 22 deletions(-)
diff --git a/src/select/format_list_style.c b/src/select/format_list_style.c
index 8fff04a..3457e41 100644
--- a/src/select/format_list_style.c
+++ b/src/select/format_list_style.c
@@ -340,10 +340,11 @@ static const int georgian_weights[] = {
90, 80, 70, 60, 50, 40, 30, 20, 10,
9, 8, 7, 6, 5, 4, 3, 2, 1
};
-static struct list_counter_style lcs_georgian = {
+static const struct list_counter_style lcs_georgian = {
.name="georgian",
- .range.start = 1,
- .range.end = 19999,
+ .range = {
+ .start = 1,
+ .end = 19999,},
.symbols = georgian_symbols,
.weights = georgian_weights,
.items = (sizeof(georgian_symbols) / SYMBOL_SIZE),
@@ -363,10 +364,11 @@ static const int armenian_weights[] = {
90, 80, 70, 60, 50, 40, 30, 20, 10,
9, 8, 7, 6, 5, 4, 3, 2, 1
};
-static struct list_counter_style lcs_armenian = {
+static const struct list_counter_style lcs_armenian = {
.name = "armenian",
- .range.start = 1,
- .range.end = 9999,
+ .range = {
+ .start = 1,
+ .end = 9999,},
.symbols = armenian_symbols,
.weights = armenian_weights,
.items = (sizeof(armenian_symbols) / SYMBOL_SIZE),
@@ -377,7 +379,7 @@ static struct list_counter_style lcs_armenian = {
static const symbol_t decimal_symbols[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
};
-static struct list_counter_style lcs_decimal = {
+static const struct list_counter_style lcs_decimal = {
.name = "decimal",
.symbols = decimal_symbols,
.items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
@@ -385,10 +387,11 @@ static struct list_counter_style lcs_decimal = {
};
-static struct list_counter_style lcs_decimal_leading_zero = {
+static const struct list_counter_style lcs_decimal_leading_zero = {
.name = "decimal-leading-zero",
- .pad.length = 2,
- .pad.value = "0",
+ .pad = {
+ .length = 2,
+ .value = "0",},
.symbols = decimal_symbols,
.items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
.calc = calc_numeric_system,
@@ -400,8 +403,8 @@ static const symbol_t lower_greek_symbols[] = {
"��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
"��", "��", "��", "��"
};
-static struct list_counter_style lcs_lower_greek = {
- .name="lower-greek",
+static const struct list_counter_style lcs_lower_greek = {
+ .name = "lower-greek",
.symbols = lower_greek_symbols,
.items = (sizeof(lower_greek_symbols) / SYMBOL_SIZE),
.calc = calc_alphabet_system,
@@ -413,8 +416,8 @@ static const symbol_t upper_alpha_symbols[] = {
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"
};
-static struct list_counter_style lcs_upper_alpha = {
- .name="upper-alpha",
+static const struct list_counter_style lcs_upper_alpha = {
+ .name = "upper-alpha",
.symbols = upper_alpha_symbols,
.items = (sizeof(upper_alpha_symbols) / SYMBOL_SIZE),
.calc = calc_alphabet_system,
@@ -427,7 +430,7 @@ static const symbol_t lower_alpha_symbols[] = {
"u", "v", "w", "x", "y", "z"
};
static struct list_counter_style lcs_lower_alpha = {
- .name="lower-alpha",
+ .name = "lower-alpha",
.symbols = lower_alpha_symbols,
.items = (sizeof(lower_alpha_symbols) / SYMBOL_SIZE),
.calc = calc_alphabet_system,
@@ -437,8 +440,8 @@ static struct list_counter_style lcs_lower_alpha = {
static const symbol_t upper_roman_symbols[] = {
"M", "D", "C", "L", "X", "V", "I"
};
-static struct list_counter_style lcs_upper_roman = {
- .name="upper-roman",
+static const struct list_counter_style lcs_upper_roman = {
+ .name = "upper-roman",
.symbols = upper_roman_symbols,
.items = (sizeof(upper_roman_symbols) / SYMBOL_SIZE),
.calc = calc_roman_system,
@@ -448,8 +451,8 @@ static struct list_counter_style lcs_upper_roman = {
static const symbol_t lower_roman_symbols[] = {
"m", "d", "c", "l", "x", "v", "i"
};
-static struct list_counter_style lcs_lower_roman = {
- .name="lower-roman",
+static const struct list_counter_style lcs_lower_roman = {
+ .name = "lower-roman",
.symbols = lower_roman_symbols,
.items = (sizeof(lower_roman_symbols) / SYMBOL_SIZE),
.calc = calc_roman_system,
@@ -460,8 +463,8 @@ static const symbol_t lower_hexidecimal_symbols[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f"
};
-static struct list_counter_style lcs_lower_hexidecimal = {
- .name="lower_hexidecimal",
+static const struct list_counter_style lcs_lower_hexidecimal = {
+ .name = "lower_hexidecimal",
.symbols = lower_hexidecimal_symbols,
.items = (sizeof(lower_hexidecimal_symbols) / SYMBOL_SIZE),
.calc = calc_numeric_system,
@@ -481,7 +484,7 @@ css_error css_computed_format_list_style(
size_t alen;
uint8_t aval[20];
- struct list_counter_style *cstyle;
+ const struct list_counter_style *cstyle;
switch (type) {
case CSS_LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO:
--
Cascading Style Sheets library
1 year, 12 months
libcss: branch master updated. release/0.9.1-7-g131bb27
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/131bb27e3bf9d117ede308...
...commit http://git.netsurf-browser.org/libcss.git/commit/131bb27e3bf9d117ede308dd...
...tree http://git.netsurf-browser.org/libcss.git/tree/131bb27e3bf9d117ede308dd96...
The branch, master has been updated
via 131bb27e3bf9d117ede308dd968814204f72e64c (commit)
from e8238ac2dab2a9c8cd31e7f66504218cf90c4d23 (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=131bb27e3bf9d117ede3...
commit 131bb27e3bf9d117ede308dd968814204f72e64c
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
add text formatting of values with list styles
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index af40abf..f4b3e21 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -88,7 +88,30 @@ css_error css_computed_style_compose(
css_computed_style **restrict result);
/******************************************************************************
- * Property accessors below here *
+ * speciality formatters *
+ ******************************************************************************/
+
+/**
+ * Format a value into a text string controled by a list style
+ *
+ * \param[in] style The computed style to use for formatting
+ * \param[in] value The value to format
+ * \param[out] buffer The buffer to recive the formatted result
+ * \param[in] buffer_length The length of the buffer
+ * \param[out] format_length The complete length of the formatted result which
+ * may exceed buffer_length in which case the
+ * buffer data will not be complete.
+ * \return CSS_OK on success and the buffer and format_length updated
+ */
+css_error css_computed_format_list_style(
+ const css_computed_style *style,
+ int value,
+ char *buffer,
+ size_t buffer_length,
+ size_t *format_length);
+
+/******************************************************************************
+ * Property accessors *
******************************************************************************/
uint8_t css_computed_letter_spacing(
diff --git a/src/select/Makefile b/src/select/Makefile
index 025ad39..8b47673 100644
--- a/src/select/Makefile
+++ b/src/select/Makefile
@@ -2,6 +2,6 @@
select_generator:
python3 src/select/select_generator.py
-DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c font_face.c
+DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c font_face.c format_list_style.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/select/format_list_style.c b/src/select/format_list_style.c
new file mode 100644
index 0000000..8fff04a
--- /dev/null
+++ b/src/select/format_list_style.c
@@ -0,0 +1,542 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2021 Vincent Sanders <vince(a)netsurf-browser.org>
+ */
+
+#include "select/propget.h"
+#include "utils/utils.h"
+
+#define SYMBOL_SIZE 5
+typedef char symbol_t[SYMBOL_SIZE];
+
+struct list_counter_style {
+ const char *name; /**< style name for debug purposes */
+ struct {
+ const int start; /**< first acceptable value for this style */
+ const int end; /**< last acceptable value for this style */
+ } range;
+ struct {
+ const unsigned int length;
+ const symbol_t value;
+ } pad;
+ const char *prefix;
+ const char *postfix;
+ const symbol_t *symbols; /**< array of symbols which represent this style */
+ const int *weights; /**< symbol weights for additive schemes */
+ const size_t items; /**< items in symbol and weight table */
+ size_t (*calc)(uint8_t *ares, const size_t alen, int value, const struct list_counter_style *cstyle); /**< function to calculate the system */
+};
+
+/**
+ * Copy a null-terminated UTF-8 string to buffer at offset, if there is space
+ *
+ * \param[in] buf The output buffer
+ * \param[in] buflen The length of \a buf
+ * \param[in] pos Current position in \a buf
+ * \param[in] str The string to copy into \a buf
+ * \return The number of bytes needed in the output buffer which may be
+ * larger than \a buflen but the buffer will not be overrun
+ */
+static inline size_t
+copy_string(char *buf, const size_t buflen, size_t pos, const char *str)
+{
+ size_t sidx = 0; /* current string index */
+
+ while (str[sidx] != '\0') {
+ if (pos < buflen) {
+ buf[pos] = str[sidx];
+ }
+ pos++;
+ sidx++;
+ }
+
+ return sidx;
+}
+
+/**
+ * Copy a UTF-8 symbol to buffer at offset, if there is space
+ *
+ * \param[in] buf The output buffer
+ * \param[in] buflen The length of \a buf
+ * \param[in] pos Current position in \a buf
+ * \param[in] symbol The symbol to copy into \a buf
+ * \return The number of bytes needed in the output buffer which may be
+ * larger than \a buflen but the buffer will not be overrun
+ */
+static inline size_t
+copy_symbol(char *buf, const size_t buflen, size_t pos, const symbol_t symbol)
+{
+ size_t sidx = 0; /* current symbol index */
+
+ while ((sidx < sizeof(symbol_t)) && (symbol[sidx] != '\0')) {
+ if (pos < buflen) {
+ buf[pos] = symbol[sidx];
+ }
+ pos++;
+ sidx++;
+ }
+
+ return sidx;
+}
+
+/**
+ * maps alphabet values to output values with a symbol table
+ *
+ * Takes a list of alphabet values and for each one outputs the
+ * compete symbol (in utf8) to an output buffer.
+ *
+ * \param buf The oputput buffer
+ * \param buflen the length of \a buf
+ * \param aval array of alphabet values
+ * \param alen The number of values in \a alen
+ * \param symtab The symbol table
+ * \param symtablen The number of symbols in \a symtab
+ * \return The number of bytes needed in the output buffer whichmay be
+ * larger than \a buflen but the buffer will not be overrun
+ */
+static size_t
+map_aval_to_symbols(char *buf, const size_t buflen,
+ const uint8_t *aval, const size_t alen,
+ const struct list_counter_style *cstyle)
+{
+ size_t oidx = 0;
+ size_t aidx; /* numeral index */
+ const symbol_t postfix = "."; /* default postfix string */
+
+ /* add padding if required */
+ if (alen < cstyle->pad.length) {
+ size_t pidx; /* padding index */
+ for (pidx=cstyle->pad.length - alen; pidx > 0; pidx--) {
+ oidx += copy_symbol(buf, buflen, oidx,
+ cstyle->pad.value);
+ }
+ }
+
+ /* map symbols */
+ for (aidx=0; aidx < alen; aidx++) {
+ oidx += copy_symbol(buf, buflen, oidx,
+ cstyle->symbols[aval[aidx]]);
+ }
+
+ /* postfix */
+ oidx += copy_string(buf, buflen, oidx,
+ (cstyle->postfix != NULL) ?
+ cstyle->postfix : postfix);
+
+ return oidx;
+}
+
+
+/**
+ * generate numeric symbol values
+ *
+ * fills array with numeric values that represent the input value
+ *
+ * \param ares Buffer to recive the converted values
+ * \param alen the length of \a ares buffer
+ * \param value The value to convert
+ * \param slen The number of symbols in the alphabet
+ * \return The length a complete conversion which may be larger than \a alen
+ */
+static size_t
+calc_numeric_system(uint8_t *ares,
+ const size_t alen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ size_t idx = 0;
+ uint8_t *first;
+ uint8_t *last;
+
+ /* generate alphabet values in ascending order */
+ while (value > 0) {
+ if (idx < alen) {
+ ares[idx] = value % cstyle->items;
+ }
+ idx++;
+ value = value / cstyle->items;
+ }
+
+ /* put the values in decending order */
+ first = ares;
+ if (idx < alen) {
+ last = first + (idx - 1);
+ } else {
+ last = first + (alen - 1);
+ }
+ while (first < last) {
+ *first ^= *last;
+ *last ^= *first;
+ *first ^= *last;
+ first++;
+ last--;
+ }
+
+ return idx;
+}
+
+
+/**
+ * generate addative symbol values
+ *
+ * fills array with numeric values that represent the input value
+ *
+ * \param ares Buffer to recive the converted values
+ * \param alen the length of \a ares buffer
+ * \param value The value to convert
+ * \param wlen The number of weights
+ * \return The length a complete conversion which may be larger than \a alen
+ */
+static size_t
+calc_additive_system(uint8_t *ares,
+ const size_t alen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ size_t widx; /* weight index */
+ size_t aidx = 0;
+ size_t idx;
+ size_t times; /* number of times a weight occours */
+
+ /* iterate over the available weights */
+ for (widx = 0; widx < cstyle->items;widx++) {
+ times = value / cstyle->weights[widx];
+ if (times > 0) {
+ for (idx=0;idx < times;idx++) {
+ if (aidx < alen) {
+ ares[aidx] = widx;
+ }
+ aidx++;
+ }
+
+ value -= times * cstyle->weights[widx];
+ }
+ }
+
+ return aidx;
+}
+
+
+/**
+ * generate alphabet symbol values for latin and greek labelling
+ *
+ * fills array with alphabet values suitable for the input value
+ *
+ * \param ares Buffer to recive the converted values
+ * \param alen the length of \a ares buffer
+ * \param value The value to convert
+ * \param slen The number of symbols in the alphabet
+ * \return The length a complete conversion which may be larger than \a alen
+ */
+static size_t
+calc_alphabet_system(uint8_t *ares,
+ const size_t alen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ size_t idx = 0;
+ uint8_t *first;
+ uint8_t *last;
+
+ /* generate alphabet values in ascending order */
+ while (value > 0) {
+ --value;
+ if (idx < alen) {
+ ares[idx] = value % cstyle->items;
+ }
+ idx++;
+ value = value / cstyle->items;
+ }
+
+ /* put the values in decending order */
+ first = ares;
+ if (idx < alen) {
+ last = first + (idx - 1);
+ } else {
+ last = first + (alen - 1);
+ }
+ while (first < last) {
+ *first ^= *last;
+ *last ^= *first;
+ *first ^= *last;
+ first++;
+ last--;
+ }
+
+ return idx;
+}
+
+
+/**
+ * Roman numeral conversion
+ *
+ * \return The number of numerals that are nesesary for full output
+ */
+static size_t
+calc_roman_system(uint8_t *buf,
+ const size_t maxlen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ const int S[] = { 0, 2, 4, 2, 4, 2, 4 };
+ const int D[] = { 1000, 500, 100, 50, 10, 5, 1 };
+ const size_t L = sizeof(D) / sizeof(int) - 1;
+ size_t k = 0; /* index into output buffer */
+ unsigned int i = 0; /* index into maps */
+ int r, r2;
+
+ UNUSED(cstyle);
+
+ assert(cstyle->items == 7);
+
+ while (value > 0) {
+ if (D[i] <= value) {
+ r = value / D[i];
+ value = value - (r * D[i]);
+ if (i < L) {
+ /* lookahead */
+ r2 = value / D[i+1];
+ }
+ if (i < L && r2 >= S[i+1]) {
+ /* will violate repeat boundary on next pass */
+ value = value - (r2 * D[i+1]);
+ if (k < maxlen) buf[k++] = i+1;
+ if (k < maxlen) buf[k++] = i-1;
+ } else if (S[i] && r >= S[i]) {
+ /* violated repeat boundary on this pass */
+ if (k < maxlen) buf[k++] = i;
+ if (k < maxlen) buf[k++] = i-1;
+ } else {
+ while (r-- > 0 && k < maxlen) {
+ buf[k++] = i;
+ }
+ }
+ }
+ i++;
+ }
+ if (k < maxlen) {
+ buf[k] = '\0';
+ }
+ return k;
+}
+
+
+/* tables for all the counter styles */
+
+
+static const symbol_t georgian_symbols[] = {
+ "���",
+ "���", "���", "���", "���", "���", "���", "���", "���", "���",
+ "���", "���", "���", "���", "���", "���", "���", "���", "���",
+ "���", "���", "���", "���", "���", "���", "���", "���", "���",
+ "���", "���", "���", "���", "���", "���", "���", "���", "���",
+};
+static const int georgian_weights[] = {
+ 10000,
+ 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000,
+ 900, 800, 700, 600, 500, 400, 300, 200, 100,
+ 90, 80, 70, 60, 50, 40, 30, 20, 10,
+ 9, 8, 7, 6, 5, 4, 3, 2, 1
+};
+static struct list_counter_style lcs_georgian = {
+ .name="georgian",
+ .range.start = 1,
+ .range.end = 19999,
+ .symbols = georgian_symbols,
+ .weights = georgian_weights,
+ .items = (sizeof(georgian_symbols) / SYMBOL_SIZE),
+ .calc = calc_additive_system,
+};
+
+
+static const symbol_t armenian_symbols[] = {
+ "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��", "��", "��", "��", "��", "��"
+};
+static const int armenian_weights[] = {
+ 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000,
+ 900, 800, 700, 600, 500, 400, 300, 200, 100,
+ 90, 80, 70, 60, 50, 40, 30, 20, 10,
+ 9, 8, 7, 6, 5, 4, 3, 2, 1
+};
+static struct list_counter_style lcs_armenian = {
+ .name = "armenian",
+ .range.start = 1,
+ .range.end = 9999,
+ .symbols = armenian_symbols,
+ .weights = armenian_weights,
+ .items = (sizeof(armenian_symbols) / SYMBOL_SIZE),
+ .calc = calc_additive_system,
+};
+
+
+static const symbol_t decimal_symbols[] = {
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
+};
+static struct list_counter_style lcs_decimal = {
+ .name = "decimal",
+ .symbols = decimal_symbols,
+ .items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
+ .calc = calc_numeric_system,
+};
+
+
+static struct list_counter_style lcs_decimal_leading_zero = {
+ .name = "decimal-leading-zero",
+ .pad.length = 2,
+ .pad.value = "0",
+ .symbols = decimal_symbols,
+ .items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
+ .calc = calc_numeric_system,
+};
+
+
+static const symbol_t lower_greek_symbols[] = {
+ "��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��"
+};
+static struct list_counter_style lcs_lower_greek = {
+ .name="lower-greek",
+ .symbols = lower_greek_symbols,
+ .items = (sizeof(lower_greek_symbols) / SYMBOL_SIZE),
+ .calc = calc_alphabet_system,
+};
+
+
+static const symbol_t upper_alpha_symbols[] = {
+ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
+ "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
+ "U", "V", "W", "X", "Y", "Z"
+};
+static struct list_counter_style lcs_upper_alpha = {
+ .name="upper-alpha",
+ .symbols = upper_alpha_symbols,
+ .items = (sizeof(upper_alpha_symbols) / SYMBOL_SIZE),
+ .calc = calc_alphabet_system,
+};
+
+
+static const symbol_t lower_alpha_symbols[] = {
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
+ "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
+ "u", "v", "w", "x", "y", "z"
+};
+static struct list_counter_style lcs_lower_alpha = {
+ .name="lower-alpha",
+ .symbols = lower_alpha_symbols,
+ .items = (sizeof(lower_alpha_symbols) / SYMBOL_SIZE),
+ .calc = calc_alphabet_system,
+};
+
+
+static const symbol_t upper_roman_symbols[] = {
+ "M", "D", "C", "L", "X", "V", "I"
+};
+static struct list_counter_style lcs_upper_roman = {
+ .name="upper-roman",
+ .symbols = upper_roman_symbols,
+ .items = (sizeof(upper_roman_symbols) / SYMBOL_SIZE),
+ .calc = calc_roman_system,
+};
+
+
+static const symbol_t lower_roman_symbols[] = {
+ "m", "d", "c", "l", "x", "v", "i"
+};
+static struct list_counter_style lcs_lower_roman = {
+ .name="lower-roman",
+ .symbols = lower_roman_symbols,
+ .items = (sizeof(lower_roman_symbols) / SYMBOL_SIZE),
+ .calc = calc_roman_system,
+};
+
+#if 0
+static const symbol_t lower_hexidecimal_symbols[] = {
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
+ "a", "b", "c", "d", "e", "f"
+};
+static struct list_counter_style lcs_lower_hexidecimal = {
+ .name="lower_hexidecimal",
+ .symbols = lower_hexidecimal_symbols,
+ .items = (sizeof(lower_hexidecimal_symbols) / SYMBOL_SIZE),
+ .calc = calc_numeric_system,
+};
+#endif
+
+
+/* exported interface defined in select.h */
+css_error css_computed_format_list_style(
+ const css_computed_style *style,
+ int value,
+ char *buffer,
+ size_t buffer_length,
+ size_t *format_length)
+{
+ uint8_t type = get_list_style_type(style);
+
+ size_t alen;
+ uint8_t aval[20];
+ struct list_counter_style *cstyle;
+
+ switch (type) {
+ case CSS_LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO:
+ cstyle = &lcs_decimal_leading_zero;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_LOWER_ROMAN:
+ cstyle = &lcs_lower_roman;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_UPPER_ROMAN:
+ cstyle = &lcs_upper_roman;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_LOWER_ALPHA:
+ case CSS_LIST_STYLE_TYPE_LOWER_LATIN:
+ cstyle = &lcs_lower_alpha;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_UPPER_ALPHA:
+ case CSS_LIST_STYLE_TYPE_UPPER_LATIN:
+ cstyle = &lcs_upper_alpha;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_LOWER_GREEK:
+ cstyle = &lcs_lower_greek;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_ARMENIAN:
+ cstyle = &lcs_armenian;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_GEORGIAN:
+ cstyle = &lcs_georgian;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_DECIMAL:
+ default:
+ cstyle = &lcs_decimal;
+ break;
+ }
+
+ alen = cstyle->calc(aval, sizeof(aval), value, cstyle);
+
+ /* ensure it is possible to calculate with the selected system */
+ if ((alen == 0) || (alen >= sizeof(aval))) {
+ /* retry in decimal */
+ alen = lcs_decimal.calc(aval, sizeof(aval), value, &lcs_decimal);
+ if ((alen == 0) || (alen >= sizeof(aval))) {
+ /* failed in decimal, give up */
+ return 0;
+ }
+ }
+
+ *format_length = map_aval_to_symbols(buffer, buffer_length, aval, alen, cstyle);
+
+ return CSS_OK;
+}
-----------------------------------------------------------------------
Summary of changes:
include/libcss/computed.h | 25 +-
src/select/Makefile | 2 +-
src/select/format_list_style.c | 542 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 567 insertions(+), 2 deletions(-)
create mode 100644 src/select/format_list_style.c
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index af40abf..f4b3e21 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -88,7 +88,30 @@ css_error css_computed_style_compose(
css_computed_style **restrict result);
/******************************************************************************
- * Property accessors below here *
+ * speciality formatters *
+ ******************************************************************************/
+
+/**
+ * Format a value into a text string controled by a list style
+ *
+ * \param[in] style The computed style to use for formatting
+ * \param[in] value The value to format
+ * \param[out] buffer The buffer to recive the formatted result
+ * \param[in] buffer_length The length of the buffer
+ * \param[out] format_length The complete length of the formatted result which
+ * may exceed buffer_length in which case the
+ * buffer data will not be complete.
+ * \return CSS_OK on success and the buffer and format_length updated
+ */
+css_error css_computed_format_list_style(
+ const css_computed_style *style,
+ int value,
+ char *buffer,
+ size_t buffer_length,
+ size_t *format_length);
+
+/******************************************************************************
+ * Property accessors *
******************************************************************************/
uint8_t css_computed_letter_spacing(
diff --git a/src/select/Makefile b/src/select/Makefile
index 025ad39..8b47673 100644
--- a/src/select/Makefile
+++ b/src/select/Makefile
@@ -2,6 +2,6 @@
select_generator:
python3 src/select/select_generator.py
-DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c font_face.c
+DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c font_face.c format_list_style.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/select/format_list_style.c b/src/select/format_list_style.c
new file mode 100644
index 0000000..8fff04a
--- /dev/null
+++ b/src/select/format_list_style.c
@@ -0,0 +1,542 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2021 Vincent Sanders <vince(a)netsurf-browser.org>
+ */
+
+#include "select/propget.h"
+#include "utils/utils.h"
+
+#define SYMBOL_SIZE 5
+typedef char symbol_t[SYMBOL_SIZE];
+
+struct list_counter_style {
+ const char *name; /**< style name for debug purposes */
+ struct {
+ const int start; /**< first acceptable value for this style */
+ const int end; /**< last acceptable value for this style */
+ } range;
+ struct {
+ const unsigned int length;
+ const symbol_t value;
+ } pad;
+ const char *prefix;
+ const char *postfix;
+ const symbol_t *symbols; /**< array of symbols which represent this style */
+ const int *weights; /**< symbol weights for additive schemes */
+ const size_t items; /**< items in symbol and weight table */
+ size_t (*calc)(uint8_t *ares, const size_t alen, int value, const struct list_counter_style *cstyle); /**< function to calculate the system */
+};
+
+/**
+ * Copy a null-terminated UTF-8 string to buffer at offset, if there is space
+ *
+ * \param[in] buf The output buffer
+ * \param[in] buflen The length of \a buf
+ * \param[in] pos Current position in \a buf
+ * \param[in] str The string to copy into \a buf
+ * \return The number of bytes needed in the output buffer which may be
+ * larger than \a buflen but the buffer will not be overrun
+ */
+static inline size_t
+copy_string(char *buf, const size_t buflen, size_t pos, const char *str)
+{
+ size_t sidx = 0; /* current string index */
+
+ while (str[sidx] != '\0') {
+ if (pos < buflen) {
+ buf[pos] = str[sidx];
+ }
+ pos++;
+ sidx++;
+ }
+
+ return sidx;
+}
+
+/**
+ * Copy a UTF-8 symbol to buffer at offset, if there is space
+ *
+ * \param[in] buf The output buffer
+ * \param[in] buflen The length of \a buf
+ * \param[in] pos Current position in \a buf
+ * \param[in] symbol The symbol to copy into \a buf
+ * \return The number of bytes needed in the output buffer which may be
+ * larger than \a buflen but the buffer will not be overrun
+ */
+static inline size_t
+copy_symbol(char *buf, const size_t buflen, size_t pos, const symbol_t symbol)
+{
+ size_t sidx = 0; /* current symbol index */
+
+ while ((sidx < sizeof(symbol_t)) && (symbol[sidx] != '\0')) {
+ if (pos < buflen) {
+ buf[pos] = symbol[sidx];
+ }
+ pos++;
+ sidx++;
+ }
+
+ return sidx;
+}
+
+/**
+ * maps alphabet values to output values with a symbol table
+ *
+ * Takes a list of alphabet values and for each one outputs the
+ * compete symbol (in utf8) to an output buffer.
+ *
+ * \param buf The oputput buffer
+ * \param buflen the length of \a buf
+ * \param aval array of alphabet values
+ * \param alen The number of values in \a alen
+ * \param symtab The symbol table
+ * \param symtablen The number of symbols in \a symtab
+ * \return The number of bytes needed in the output buffer whichmay be
+ * larger than \a buflen but the buffer will not be overrun
+ */
+static size_t
+map_aval_to_symbols(char *buf, const size_t buflen,
+ const uint8_t *aval, const size_t alen,
+ const struct list_counter_style *cstyle)
+{
+ size_t oidx = 0;
+ size_t aidx; /* numeral index */
+ const symbol_t postfix = "."; /* default postfix string */
+
+ /* add padding if required */
+ if (alen < cstyle->pad.length) {
+ size_t pidx; /* padding index */
+ for (pidx=cstyle->pad.length - alen; pidx > 0; pidx--) {
+ oidx += copy_symbol(buf, buflen, oidx,
+ cstyle->pad.value);
+ }
+ }
+
+ /* map symbols */
+ for (aidx=0; aidx < alen; aidx++) {
+ oidx += copy_symbol(buf, buflen, oidx,
+ cstyle->symbols[aval[aidx]]);
+ }
+
+ /* postfix */
+ oidx += copy_string(buf, buflen, oidx,
+ (cstyle->postfix != NULL) ?
+ cstyle->postfix : postfix);
+
+ return oidx;
+}
+
+
+/**
+ * generate numeric symbol values
+ *
+ * fills array with numeric values that represent the input value
+ *
+ * \param ares Buffer to recive the converted values
+ * \param alen the length of \a ares buffer
+ * \param value The value to convert
+ * \param slen The number of symbols in the alphabet
+ * \return The length a complete conversion which may be larger than \a alen
+ */
+static size_t
+calc_numeric_system(uint8_t *ares,
+ const size_t alen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ size_t idx = 0;
+ uint8_t *first;
+ uint8_t *last;
+
+ /* generate alphabet values in ascending order */
+ while (value > 0) {
+ if (idx < alen) {
+ ares[idx] = value % cstyle->items;
+ }
+ idx++;
+ value = value / cstyle->items;
+ }
+
+ /* put the values in decending order */
+ first = ares;
+ if (idx < alen) {
+ last = first + (idx - 1);
+ } else {
+ last = first + (alen - 1);
+ }
+ while (first < last) {
+ *first ^= *last;
+ *last ^= *first;
+ *first ^= *last;
+ first++;
+ last--;
+ }
+
+ return idx;
+}
+
+
+/**
+ * generate addative symbol values
+ *
+ * fills array with numeric values that represent the input value
+ *
+ * \param ares Buffer to recive the converted values
+ * \param alen the length of \a ares buffer
+ * \param value The value to convert
+ * \param wlen The number of weights
+ * \return The length a complete conversion which may be larger than \a alen
+ */
+static size_t
+calc_additive_system(uint8_t *ares,
+ const size_t alen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ size_t widx; /* weight index */
+ size_t aidx = 0;
+ size_t idx;
+ size_t times; /* number of times a weight occours */
+
+ /* iterate over the available weights */
+ for (widx = 0; widx < cstyle->items;widx++) {
+ times = value / cstyle->weights[widx];
+ if (times > 0) {
+ for (idx=0;idx < times;idx++) {
+ if (aidx < alen) {
+ ares[aidx] = widx;
+ }
+ aidx++;
+ }
+
+ value -= times * cstyle->weights[widx];
+ }
+ }
+
+ return aidx;
+}
+
+
+/**
+ * generate alphabet symbol values for latin and greek labelling
+ *
+ * fills array with alphabet values suitable for the input value
+ *
+ * \param ares Buffer to recive the converted values
+ * \param alen the length of \a ares buffer
+ * \param value The value to convert
+ * \param slen The number of symbols in the alphabet
+ * \return The length a complete conversion which may be larger than \a alen
+ */
+static size_t
+calc_alphabet_system(uint8_t *ares,
+ const size_t alen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ size_t idx = 0;
+ uint8_t *first;
+ uint8_t *last;
+
+ /* generate alphabet values in ascending order */
+ while (value > 0) {
+ --value;
+ if (idx < alen) {
+ ares[idx] = value % cstyle->items;
+ }
+ idx++;
+ value = value / cstyle->items;
+ }
+
+ /* put the values in decending order */
+ first = ares;
+ if (idx < alen) {
+ last = first + (idx - 1);
+ } else {
+ last = first + (alen - 1);
+ }
+ while (first < last) {
+ *first ^= *last;
+ *last ^= *first;
+ *first ^= *last;
+ first++;
+ last--;
+ }
+
+ return idx;
+}
+
+
+/**
+ * Roman numeral conversion
+ *
+ * \return The number of numerals that are nesesary for full output
+ */
+static size_t
+calc_roman_system(uint8_t *buf,
+ const size_t maxlen,
+ int value,
+ const struct list_counter_style *cstyle)
+{
+ const int S[] = { 0, 2, 4, 2, 4, 2, 4 };
+ const int D[] = { 1000, 500, 100, 50, 10, 5, 1 };
+ const size_t L = sizeof(D) / sizeof(int) - 1;
+ size_t k = 0; /* index into output buffer */
+ unsigned int i = 0; /* index into maps */
+ int r, r2;
+
+ UNUSED(cstyle);
+
+ assert(cstyle->items == 7);
+
+ while (value > 0) {
+ if (D[i] <= value) {
+ r = value / D[i];
+ value = value - (r * D[i]);
+ if (i < L) {
+ /* lookahead */
+ r2 = value / D[i+1];
+ }
+ if (i < L && r2 >= S[i+1]) {
+ /* will violate repeat boundary on next pass */
+ value = value - (r2 * D[i+1]);
+ if (k < maxlen) buf[k++] = i+1;
+ if (k < maxlen) buf[k++] = i-1;
+ } else if (S[i] && r >= S[i]) {
+ /* violated repeat boundary on this pass */
+ if (k < maxlen) buf[k++] = i;
+ if (k < maxlen) buf[k++] = i-1;
+ } else {
+ while (r-- > 0 && k < maxlen) {
+ buf[k++] = i;
+ }
+ }
+ }
+ i++;
+ }
+ if (k < maxlen) {
+ buf[k] = '\0';
+ }
+ return k;
+}
+
+
+/* tables for all the counter styles */
+
+
+static const symbol_t georgian_symbols[] = {
+ "���",
+ "���", "���", "���", "���", "���", "���", "���", "���", "���",
+ "���", "���", "���", "���", "���", "���", "���", "���", "���",
+ "���", "���", "���", "���", "���", "���", "���", "���", "���",
+ "���", "���", "���", "���", "���", "���", "���", "���", "���",
+};
+static const int georgian_weights[] = {
+ 10000,
+ 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000,
+ 900, 800, 700, 600, 500, 400, 300, 200, 100,
+ 90, 80, 70, 60, 50, 40, 30, 20, 10,
+ 9, 8, 7, 6, 5, 4, 3, 2, 1
+};
+static struct list_counter_style lcs_georgian = {
+ .name="georgian",
+ .range.start = 1,
+ .range.end = 19999,
+ .symbols = georgian_symbols,
+ .weights = georgian_weights,
+ .items = (sizeof(georgian_symbols) / SYMBOL_SIZE),
+ .calc = calc_additive_system,
+};
+
+
+static const symbol_t armenian_symbols[] = {
+ "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��", "��", "��", "��", "��", "��"
+};
+static const int armenian_weights[] = {
+ 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000,
+ 900, 800, 700, 600, 500, 400, 300, 200, 100,
+ 90, 80, 70, 60, 50, 40, 30, 20, 10,
+ 9, 8, 7, 6, 5, 4, 3, 2, 1
+};
+static struct list_counter_style lcs_armenian = {
+ .name = "armenian",
+ .range.start = 1,
+ .range.end = 9999,
+ .symbols = armenian_symbols,
+ .weights = armenian_weights,
+ .items = (sizeof(armenian_symbols) / SYMBOL_SIZE),
+ .calc = calc_additive_system,
+};
+
+
+static const symbol_t decimal_symbols[] = {
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
+};
+static struct list_counter_style lcs_decimal = {
+ .name = "decimal",
+ .symbols = decimal_symbols,
+ .items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
+ .calc = calc_numeric_system,
+};
+
+
+static struct list_counter_style lcs_decimal_leading_zero = {
+ .name = "decimal-leading-zero",
+ .pad.length = 2,
+ .pad.value = "0",
+ .symbols = decimal_symbols,
+ .items = (sizeof(decimal_symbols) / SYMBOL_SIZE),
+ .calc = calc_numeric_system,
+};
+
+
+static const symbol_t lower_greek_symbols[] = {
+ "��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��", "��", "��", "��", "��", "��", "��",
+ "��", "��", "��", "��"
+};
+static struct list_counter_style lcs_lower_greek = {
+ .name="lower-greek",
+ .symbols = lower_greek_symbols,
+ .items = (sizeof(lower_greek_symbols) / SYMBOL_SIZE),
+ .calc = calc_alphabet_system,
+};
+
+
+static const symbol_t upper_alpha_symbols[] = {
+ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
+ "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
+ "U", "V", "W", "X", "Y", "Z"
+};
+static struct list_counter_style lcs_upper_alpha = {
+ .name="upper-alpha",
+ .symbols = upper_alpha_symbols,
+ .items = (sizeof(upper_alpha_symbols) / SYMBOL_SIZE),
+ .calc = calc_alphabet_system,
+};
+
+
+static const symbol_t lower_alpha_symbols[] = {
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
+ "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
+ "u", "v", "w", "x", "y", "z"
+};
+static struct list_counter_style lcs_lower_alpha = {
+ .name="lower-alpha",
+ .symbols = lower_alpha_symbols,
+ .items = (sizeof(lower_alpha_symbols) / SYMBOL_SIZE),
+ .calc = calc_alphabet_system,
+};
+
+
+static const symbol_t upper_roman_symbols[] = {
+ "M", "D", "C", "L", "X", "V", "I"
+};
+static struct list_counter_style lcs_upper_roman = {
+ .name="upper-roman",
+ .symbols = upper_roman_symbols,
+ .items = (sizeof(upper_roman_symbols) / SYMBOL_SIZE),
+ .calc = calc_roman_system,
+};
+
+
+static const symbol_t lower_roman_symbols[] = {
+ "m", "d", "c", "l", "x", "v", "i"
+};
+static struct list_counter_style lcs_lower_roman = {
+ .name="lower-roman",
+ .symbols = lower_roman_symbols,
+ .items = (sizeof(lower_roman_symbols) / SYMBOL_SIZE),
+ .calc = calc_roman_system,
+};
+
+#if 0
+static const symbol_t lower_hexidecimal_symbols[] = {
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
+ "a", "b", "c", "d", "e", "f"
+};
+static struct list_counter_style lcs_lower_hexidecimal = {
+ .name="lower_hexidecimal",
+ .symbols = lower_hexidecimal_symbols,
+ .items = (sizeof(lower_hexidecimal_symbols) / SYMBOL_SIZE),
+ .calc = calc_numeric_system,
+};
+#endif
+
+
+/* exported interface defined in select.h */
+css_error css_computed_format_list_style(
+ const css_computed_style *style,
+ int value,
+ char *buffer,
+ size_t buffer_length,
+ size_t *format_length)
+{
+ uint8_t type = get_list_style_type(style);
+
+ size_t alen;
+ uint8_t aval[20];
+ struct list_counter_style *cstyle;
+
+ switch (type) {
+ case CSS_LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO:
+ cstyle = &lcs_decimal_leading_zero;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_LOWER_ROMAN:
+ cstyle = &lcs_lower_roman;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_UPPER_ROMAN:
+ cstyle = &lcs_upper_roman;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_LOWER_ALPHA:
+ case CSS_LIST_STYLE_TYPE_LOWER_LATIN:
+ cstyle = &lcs_lower_alpha;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_UPPER_ALPHA:
+ case CSS_LIST_STYLE_TYPE_UPPER_LATIN:
+ cstyle = &lcs_upper_alpha;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_LOWER_GREEK:
+ cstyle = &lcs_lower_greek;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_ARMENIAN:
+ cstyle = &lcs_armenian;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_GEORGIAN:
+ cstyle = &lcs_georgian;
+ break;
+
+ case CSS_LIST_STYLE_TYPE_DECIMAL:
+ default:
+ cstyle = &lcs_decimal;
+ break;
+ }
+
+ alen = cstyle->calc(aval, sizeof(aval), value, cstyle);
+
+ /* ensure it is possible to calculate with the selected system */
+ if ((alen == 0) || (alen >= sizeof(aval))) {
+ /* retry in decimal */
+ alen = lcs_decimal.calc(aval, sizeof(aval), value, &lcs_decimal);
+ if ((alen == 0) || (alen >= sizeof(aval))) {
+ /* failed in decimal, give up */
+ return 0;
+ }
+ }
+
+ *format_length = map_aval_to_symbols(buffer, buffer_length, aval, alen, cstyle);
+
+ return CSS_OK;
+}
--
Cascading Style Sheets library
2 years