summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2021-02-08 23:42:44 +0000
committerVincent Sanders <vince@kyllikki.org>2021-02-08 23:42:44 +0000
commit35f499b333d1f97c47ac5581143ce9806d1c3536 (patch)
tree6b0bc5b3a1c6cb34a61b806d117c608e169bfbf2 /src
parent1c76ee6efeab2e9307d0a8aafa6666ca9db83128 (diff)
downloadlibcss-35f499b333d1f97c47ac5581143ce9806d1c3536.tar.gz
libcss-35f499b333d1f97c47ac5581143ce9806d1c3536.tar.bz2
add cyclic system to list style formatting
Diffstat (limited to 'src')
-rw-r--r--src/select/format_list_style.c77
1 files 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;