libcss: branch tlsa/calc updated. release/0.9.1-28-gdd8090b
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/dd8090b7223322c6f80990...
...commit http://git.netsurf-browser.org/libcss.git/commit/dd8090b7223322c6f8099032...
...tree http://git.netsurf-browser.org/libcss.git/tree/dd8090b7223322c6f80990327e...
The branch, tlsa/calc has been updated
discards 7805a9ee0c89cca40097aefb5cbc8ec98a7c927a (commit)
discards 684726f5189e29f9d610766365a17f754368b80b (commit)
discards 9a541ac916223694238bafd262b067a0a59a41e7 (commit)
discards 817b43a06afc93e459ff09afdb0e007f76ba6cbe (commit)
discards 05a064fc07a4cea3dd8307c10b8a2aad3a670211 (commit)
discards ce2155ea14a93327bd320d90f434da2fdb1ab66d (commit)
discards 307b71ec3001bcd8cacc875ddd09138744eb7ee1 (commit)
discards e7a7b547c370d0fa51e8e55282aceb2fe9f19039 (commit)
via dd8090b7223322c6f80990327e88e574fa3885ce (commit)
via db28a2dba7e411e4959152c3cf0e394cde94c57b (commit)
via 314d4ded8a89e891c191792894b660a853e0b8fe (commit)
via 0933e7f8717bdbac3b91debff44ec86afaf1ec84 (commit)
via ecf42afc3329b03ee642ede84f9ba224d2aff1e1 (commit)
via 65d4fd6e83d421e7fa7a8c7df44d01797e3c69ae (commit)
via 6cd205329373efe5a1629518c2875724cc79dce3 (commit)
via 0cf10a040aea028c7dc81cf353da7a7af5331076 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (7805a9ee0c89cca40097aefb5cbc8ec98a7c927a)
\
N -- N -- N (dd8090b7223322c6f80990327e88e574fa3885ce)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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=dd8090b7223322c6f809...
commit dd8090b7223322c6f80990327e88e574fa3885ce
Author: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
parse: Tests and fixes for calc() parser.
Co-authored-by: Michael Drake <michael.drake(a)netsurf-browser.org>
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index be163b1..70c8b01 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -24,12 +24,13 @@ enum flag {
};
enum calc_opcodes {
- CALC_PUSH_VALUE = 'V',
- CALC_ADD = '+',
- CALC_SUBTRACT = '-',
- CALC_MULTIPLY = '*',
- CALC_DIVIDE = '/',
- CALC_FINISH = '=',
+ CALC_PUSH_NUMBER = 'N',
+ CALC_PUSH_VALUE = 'V',
+ CALC_ADD = '+',
+ CALC_SUBTRACT = '-',
+ CALC_MULTIPLY = '*',
+ CALC_DIVIDE = '/',
+ CALC_FINISH = '=',
};
typedef enum unit {
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 7f9d9d2..fe5ee6b 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1365,6 +1365,31 @@ css__parse_calc_sum(css_language *c,
css_style *result);
static css_error
+css__parse_calc_number(
+ const parserutils_vector *vector, int *ctx,
+ css_style *result)
+{
+ const css_token *token;
+ css_fixed num;
+ size_t consumed;
+
+ /* Consume the number token */
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token == NULL || token->type != CSS_TOKEN_NUMBER) {
+ return CSS_INVALID;
+ }
+
+ num = css__number_from_string((const uint8_t *)lwc_string_data(token->idata),
+ lwc_string_length(token->idata), false, &consumed);
+
+ if (consumed != lwc_string_length(token->idata)) {
+ return CSS_INVALID;
+ }
+
+ return css__stylesheet_style_vappend(result, 2, (css_code_t) CALC_PUSH_NUMBER, (css_code_t)num);
+}
+
+static css_error
css__parse_calc_value(css_language *c,
const parserutils_vector *vector, int *ctx,
css_style *result)
@@ -1377,6 +1402,7 @@ css__parse_calc_value(css_language *c,
token = parserutils_vector_peek(vector, *ctx);
if (tokenIsChar(token, '(')) {
parserutils_vector_iterate(vector, ctx);
+ consumeWhitespace(vector, ctx);
error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
@@ -1389,7 +1415,12 @@ css__parse_calc_value(css_language *c,
/* Consume the close-paren to complete this value */
parserutils_vector_iterate(vector, ctx);
} else switch (token->type) {
- case CSS_TOKEN_NUMBER: /* Fall through */
+ case CSS_TOKEN_NUMBER:
+ error = css__parse_calc_number(vector, ctx, result);
+ if (error != CSS_OK) {
+ return error;
+ }
+ break;
case CSS_TOKEN_DIMENSION: /* Fall through */
case CSS_TOKEN_PERCENTAGE:
{
@@ -1412,11 +1443,7 @@ css__parse_calc_value(css_language *c,
break;
}
- token = parserutils_vector_peek(vector, *ctx);
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
+ consumeWhitespace(vector, ctx);
return error;
}
@@ -1462,14 +1489,15 @@ css__parse_calc_product(css_language *c,
}
/* Consume that * or / now */
parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
+ consumeWhitespace(vector, ctx);
+
+ if (multiplication) {
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result);
+ } else {
+ error = css__parse_calc_number(vector, ctx, result);
}
- /* parse another value */
- error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK)
break;
@@ -1516,12 +1544,7 @@ css__parse_calc_sum(css_language *c,
}
/* Consume that + or - now */
parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
-
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
+ consumeWhitespace(vector, ctx);
/* parse another product */
error = css__parse_calc_product(c, vector, ctx, result);
@@ -1547,17 +1570,14 @@ css_error css__parse_calc(css_language *c,
css_error error = CSS_OK;
css_style *calc_style = NULL;
+ consumeWhitespace(vector, ctx);
+
token = parserutils_vector_peek(vector, *ctx);
if (token == NULL) {
*ctx = orig_ctx;
return CSS_INVALID;
}
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
-
error = css__stylesheet_style_create(c->sheet, &calc_style);
if (error != CSS_OK)
goto cleanup;
@@ -1574,11 +1594,8 @@ css_error css__parse_calc(css_language *c,
if (error != CSS_OK)
goto cleanup;
+ consumeWhitespace(vector, ctx);
token = parserutils_vector_peek(vector, *ctx);
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
if (!tokenIsChar(token, ')')) {
/* If we don't get a close-paren, give up now */
error = CSS_INVALID;
diff --git a/test/data/parse2/calc.dat b/test/data/parse2/calc.dat
index 95abf6c..e9d176d 100644
--- a/test/data/parse2/calc.dat
+++ b/test/data/parse2/calc.dat
@@ -4,4 +4,154 @@
#expected
| *
| height: /* -> 0px */ calc(50vh 10px + =)
-#reset
\ No newline at end of file
+#reset
+
+#data
+* { line-height: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| line-height: /* -> 0any */ calc(50vh 10px + =)
+#reset
+
+#data
+* { line-height: calc( / 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { line-height: calc( + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { line-height: calc(2 / 2px)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(50vh 10px + =)
+#reset
+
+#data
+* { z-index: calc(2 * 3)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(2 3 * =)
+#reset
+
+#data
+* { z-index: calc(50vh + 10px / 9)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(50vh 10px 9 / + =)
+#reset
+
+#data
+* { z-index: calc(1 + 2 + 3 + 4)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + 3 + 4 + =)
+#reset
+
+#data
+* { z-index: calc(1 + 2 * 3 + 4)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 3 * + 4 + =)
+#reset
+
+#data
+* { z-index: calc((1 + 2) * (3 + 4))}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + 3 4 + * =)
+#reset
+
+#data
+* { z-index: calc(1 + 2}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc (1 + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(1)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 =)
+#reset
+
+#data
+* { z-index: calc()}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc((1 + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(((1 + 2)))}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + =)
+#reset
+
+#data
+* { z-index: calc( ( ( 1 + 2 ) ) )}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + =)
+#reset
+
+#data
+* { z-index: calc( ( 3 / ( 1 + 2 ) ) )}
+#errors
+#expected
+| *
+#reset
diff --git a/test/dump.h b/test/dump.h
index 852de84..f320e67 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -825,6 +825,13 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
dump_unit(num, unit, ptr);
*ptr += sprintf(*ptr, " ");
break;
+ case CALC_PUSH_NUMBER: {
+ css_fixed num = *((css_fixed *)bytecode);
+ ADVANCE(sizeof(num));
+ dump_number(num, ptr);
+ *ptr += sprintf(*ptr, " ");
+ break;
+ }
}
default:
*ptr += sprintf(*ptr, "??%d ", calc_opcode);
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=db28a2dba7e411e49591...
commit db28a2dba7e411e4959152c3cf0e394cde94c57b
Author: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
parse: calc() test and fixup.
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 041050f..be163b1 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -23,6 +23,14 @@ enum flag {
FLAG_INHERIT = (1<<1)
};
+enum calc_opcodes {
+ CALC_PUSH_VALUE = 'V',
+ CALC_ADD = '+',
+ CALC_SUBTRACT = '-',
+ CALC_MULTIPLY = '*',
+ CALC_DIVIDE = '/',
+ CALC_FINISH = '=',
+};
typedef enum unit {
UNIT_LENGTH = (1u << 8),
@@ -107,6 +115,12 @@ static inline bool isInherit(css_code_t OPV)
return getFlags(OPV) & 0x2;
}
+static inline bool isCalc(css_code_t OPV)
+{
+ /* Note, this relies on all _CALC values being the same ultimately */
+ return getValue(OPV) == 0x7f;
+}
+
#endif
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 1cdb27f..08f3f12 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -310,7 +310,7 @@ void output_calc(FILE *outputf, struct keyval *parseid, struct keyval_list *kvli
kind = ckv->key;
fprintf(outputf,
- "if ((token->type == CSS_TOKEN_IDENT) && "
+ "if ((token->type == CSS_TOKEN_FUNCTION) && "
"(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
" {\n"
"\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s), %s);\n"
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index cce9717..7f9d9d2 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1373,8 +1373,10 @@ css__parse_calc_value(css_language *c,
int orig_ctx = *ctx;
const css_token *token;
- token = parserutils_vector_iterate(vector, ctx);
+ /* On entry, we are already pointing at the value to parse, so peek it */
+ token = parserutils_vector_peek(vector, *ctx);
if (tokenIsChar(token, '(')) {
+ parserutils_vector_iterate(vector, ctx);
error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
@@ -1384,7 +1386,8 @@ css__parse_calc_value(css_language *c,
if (!tokenIsChar(token, ')')) {
return CSS_INVALID;
}
-
+ /* Consume the close-paren to complete this value */
+ parserutils_vector_iterate(vector, ctx);
} else switch (token->type) {
case CSS_TOKEN_NUMBER: /* Fall through */
case CSS_TOKEN_DIMENSION: /* Fall through */
@@ -1400,7 +1403,7 @@ css__parse_calc_value(css_language *c,
return error;
}
- error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'V', length, unit);
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) CALC_PUSH_VALUE, length, unit);
}
break;
@@ -1409,6 +1412,11 @@ css__parse_calc_value(css_language *c,
break;
}
+ token = parserutils_vector_peek(vector, *ctx);
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
return error;
}
@@ -1439,7 +1447,10 @@ css__parse_calc_product(css_language *c,
if (token == NULL) {
error = CSS_INVALID;
break;
- } else if (tokenIsChar(token, ')'))
+ } else if (
+ tokenIsChar(token, ')') ||
+ tokenIsChar(token, '+') ||
+ tokenIsChar(token, '-'))
break;
else if (tokenIsChar(token, '*'))
multiplication = true;
@@ -1450,15 +1461,21 @@ css__parse_calc_product(css_language *c,
break;
}
/* Consume that * or / now */
- token = parserutils_vector_iterate(vector, ctx);
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
/* parse another value */
error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK)
break;
/* emit the multiplication/division operator */
- error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
+ error = css__stylesheet_style_append(result,
+ (css_code_t) (multiplication ? CALC_MULTIPLY : CALC_DIVIDE));
} while (1);
/* We've fallen off, either we had an error or we're left with ')' */
return error;
@@ -1498,7 +1515,13 @@ css__parse_calc_sum(css_language *c,
break;
}
/* Consume that + or - now */
- token = parserutils_vector_iterate(vector, ctx);
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
/* parse another product */
error = css__parse_calc_product(c, vector, ctx, result);
@@ -1506,7 +1529,7 @@ css__parse_calc_sum(css_language *c,
break;
/* emit the addition/subtraction operator */
- error = css__stylesheet_style_append(result, (css_code_t) (addition ? '+' : '-'));
+ error = css__stylesheet_style_append(result, (css_code_t) (addition ? CALC_ADD : CALC_SUBTRACT));
} while (1);
/* We've fallen off, either we had an error or we're left with ')' */
return error;
@@ -1524,16 +1547,15 @@ css_error css__parse_calc(css_language *c,
css_error error = CSS_OK;
css_style *calc_style = NULL;
- token = parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
if (token == NULL) {
*ctx = orig_ctx;
return CSS_INVALID;
}
- if (!tokenIsChar(token, '(')) {
- /* If we don't get an open-paren, give up now */
- *ctx = orig_ctx;
- return CSS_INVALID;
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
}
error = css__stylesheet_style_create(c->sheet, &calc_style);
@@ -1545,27 +1567,33 @@ css_error css__parse_calc(css_language *c,
goto cleanup;
error = css__stylesheet_style_append(calc_style, (css_code_t) unit);
+ if (error != CSS_OK)
+ goto cleanup;
error = css__parse_calc_sum(c, vector, ctx, calc_style);
if (error != CSS_OK)
goto cleanup;
- token = parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
if (!tokenIsChar(token, ')')) {
/* If we don't get a close-paren, give up now */
error = CSS_INVALID;
goto cleanup;
}
+ /* Swallow that close paren */
+ parserutils_vector_iterate(vector, ctx);
+
/* Append the indicator that the calc is finished */
- error = css__stylesheet_style_append(calc_style, (css_code_t) '=');
+ error = css__stylesheet_style_append(calc_style, (css_code_t) CALC_FINISH);
if (error != CSS_OK)
goto cleanup;
- /* TODO: Once we're OK to do so, merge the style */
- (void)result;
- /* error = css__stylesheet_style_merge_style(result, calc_style); */
-
+ error = css__stylesheet_merge_style(result, calc_style);
cleanup:
css__stylesheet_style_destroy(calc_style);
if (error != CSS_OK) {
diff --git a/test/data/parse2/INDEX b/test/data/parse2/INDEX
index 331cf5c..bb2a79b 100644
--- a/test/data/parse2/INDEX
+++ b/test/data/parse2/INDEX
@@ -23,3 +23,4 @@ multicol.dat Multi-column layout property tests
flexbox.dat Flexbox properties and shorthands tests
units.dat Length unit tests
dodgy-media-block.dat Media block with incomplete ruleset
+calc.dat calc() tests
diff --git a/test/data/parse2/calc.dat b/test/data/parse2/calc.dat
new file mode 100644
index 0000000..95abf6c
--- /dev/null
+++ b/test/data/parse2/calc.dat
@@ -0,0 +1,7 @@
+#data
+* { height: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| height: /* -> 0px */ calc(50vh 10px + =)
+#reset
\ No newline at end of file
diff --git a/test/dump.h b/test/dump.h
index 79819e0..852de84 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -638,6 +638,12 @@ static void dump_unit(css_fixed val, uint32_t unit, char **ptr)
case UNIT_KHZ:
*ptr += sprintf(*ptr, "kHz");
break;
+ case UNIT_CALC_ANY:
+ *ptr += sprintf(*ptr, "any");
+ break;
+ case UNIT_CALC_NUMBER:
+ *ptr += sprintf(*ptr, "number");
+ break;
}
}
@@ -788,6 +794,45 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
if (isInherit(opv)) {
*ptr += sprintf(*ptr, "inherit");
+ } else if (isCalc(opv)) {
+ /* First entry is a unit */
+ uint32_t unit = *((uint32_t *)bytecode);
+ ADVANCE(sizeof(unit));
+ *ptr += sprintf(*ptr, "/* -> ");
+ dump_unit(0, unit, ptr);
+ *ptr += sprintf(*ptr, " */ calc(");
+ css_code_t calc_opcode;
+ while ((calc_opcode = *((css_code_t *)bytecode)) != CALC_FINISH) {
+ ADVANCE(sizeof(calc_opcode));
+ switch (calc_opcode) {
+ case CALC_ADD:
+ *ptr += sprintf(*ptr, "+ ");
+ break;
+ case CALC_SUBTRACT:
+ *ptr += sprintf(*ptr, "- ");
+ break;
+ case CALC_MULTIPLY:
+ *ptr += sprintf(*ptr, "* ");
+ break;
+ case CALC_DIVIDE:
+ *ptr += sprintf(*ptr, "/ ");
+ break;
+ case CALC_PUSH_VALUE: {
+ css_fixed num = *((css_fixed *)bytecode);
+ ADVANCE(sizeof(num));
+ uint32_t unit = *((uint32_t *)bytecode);
+ ADVANCE(sizeof(unit));
+ dump_unit(num, unit, ptr);
+ *ptr += sprintf(*ptr, " ");
+ break;
+ }
+ default:
+ *ptr += sprintf(*ptr, "??%d ", calc_opcode);
+ break;
+ }
+ }
+ ADVANCE(sizeof(calc_opcode));
+ *ptr += sprintf(*ptr, "=)");
} else {
value = getValue(opv);
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=314d4ded8a89e891c191...
commit 314d4ded8a89e891c191792894b660a853e0b8fe
Author: Michael Drake <Michael Drake tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
parse: Update parser generator to support calc() details.
Co-authored-by: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 7f5ea9d..041050f 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -65,6 +65,10 @@ typedef enum unit {
UNIT_DPI = (1 << 13) + 0,
UNIT_DPCM = (1 << 13) + 1,
UNIT_DPPX = (1 << 13) + 2,
+
+ /* These are special only to the CALC bytecodes */
+ UNIT_CALC_ANY = (1 << 20),
+ UNIT_CALC_NUMBER = (1 << 20) + 1,
} unit;
typedef uint32_t colour;
diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h
index 01ea25a..607c87b 100644
--- a/src/bytecode/opcodes.h
+++ b/src/bytecode/opcodes.h
@@ -119,6 +119,7 @@ enum op_border_style {
};
enum op_border_width {
+ BORDER_WIDTH_CALC = 0x007f,
BORDER_WIDTH_SET = 0x0080,
BORDER_WIDTH_THIN = 0x0000,
BORDER_WIDTH_MEDIUM = 0x0001,
@@ -126,6 +127,7 @@ enum op_border_width {
};
enum op_bottom {
+ BOTTOM_CALC = 0x007f,
BOTTOM_SET = 0x0080,
BOTTOM_AUTO = 0x0000
};
@@ -198,6 +200,7 @@ enum op_color {
enum op_column_count {
COLUMN_COUNT_AUTO = 0x0000,
+ COLUMN_COUNT_CALC = 0x007f,
COLUMN_COUNT_SET = 0x0080
};
@@ -208,6 +211,7 @@ enum op_column_fill {
enum op_column_gap {
COLUMN_GAP_NORMAL = 0x0000,
+ COLUMN_GAP_CALC = 0x007f,
COLUMN_GAP_SET = 0x0080
};
@@ -231,6 +235,7 @@ enum op_column_rule_style {
};
enum op_column_rule_width {
+ COLUMN_RULE_WIDTH_CALC = BORDER_WIDTH_CALC,
COLUMN_RULE_WIDTH_SET = BORDER_WIDTH_SET,
COLUMN_RULE_WIDTH_THIN = BORDER_WIDTH_THIN,
COLUMN_RULE_WIDTH_MEDIUM = BORDER_WIDTH_MEDIUM,
@@ -244,6 +249,7 @@ enum op_column_span {
enum op_column_width {
COLUMN_WIDTH_AUTO = 0x0000,
+ COLUMN_WIDTH_CALC = 0x007f,
COLUMN_WIDTH_SET = 0x0080
};
@@ -352,6 +358,7 @@ enum op_empty_cells {
enum op_flex_basis {
FLEX_BASIS_AUTO = 0x0000,
FLEX_BASIS_CONTENT = 0x0001,
+ FLEX_BASIS_CALC = 0x007f,
FLEX_BASIS_SET = 0x0080
};
@@ -363,10 +370,12 @@ enum op_flex_direction {
};
enum op_flex_grow {
+ FLEX_GROW_CALC = 0x007f,
FLEX_GROW_SET = 0x0080
};
enum op_flex_shrink {
+ FLEX_SHRINK_CALC = 0x007f,
FLEX_SHRINK_SET = 0x0080
};
@@ -396,6 +405,7 @@ enum op_font_family {
};
enum op_font_size {
+ FONT_SIZE_CALC = 0x007f,
FONT_SIZE_DIMENSION = 0x0080,
FONT_SIZE_XX_SMALL = 0x0000,
@@ -437,6 +447,7 @@ enum op_font_weight {
};
enum op_height {
+ HEIGHT_CALC = 0x007f,
HEIGHT_SET = 0x0080,
HEIGHT_AUTO = 0x0000
};
@@ -451,16 +462,19 @@ enum op_justify_content {
};
enum op_left {
+ LEFT_CALC = BOTTOM_CALC,
LEFT_SET = BOTTOM_SET,
LEFT_AUTO = BOTTOM_AUTO
};
enum op_letter_spacing {
+ LETTER_SPACING_CALC = 0x007f,
LETTER_SPACING_SET = 0x0080,
LETTER_SPACING_NORMAL = 0x0000
};
enum op_line_height {
+ LINE_HEIGHT_CALC = 0x007f,
LINE_HEIGHT_NUMBER = 0x0080,
LINE_HEIGHT_DIMENSION = 0x0081,
LINE_HEIGHT_NORMAL = 0x0000
@@ -532,26 +546,31 @@ enum op_list_style_type {
};
enum op_margin {
+ MARGIN_CALC = 0x007f,
MARGIN_SET = 0x0080,
MARGIN_AUTO = 0x0000
};
enum op_max_height {
+ MAX_HEIGHT_CALC = 0x007f,
MAX_HEIGHT_SET = 0x0080,
MAX_HEIGHT_NONE = 0x0000
};
enum op_max_width {
+ MAX_WIDTH_CALC = 0x007f,
MAX_WIDTH_SET = 0x0080,
MAX_WIDTH_NONE = 0x0000
};
enum op_min_height {
+ MIN_HEIGHT_CALC = 0x007f,
MIN_HEIGHT_SET = 0x0080,
MIN_HEIGHT_AUTO = 0x0000
};
enum op_min_width {
+ MIN_WIDTH_CALC = 0x007f,
MIN_WIDTH_SET = 0x0080,
MIN_WIDTH_AUTO = 0x0000
};
@@ -561,10 +580,12 @@ enum op_opacity {
};
enum op_order {
+ ORDER_CALC = 0x007f,
ORDER_SET = 0x0080
};
enum op_orphans {
+ ORPHANS_CALC = 0x007f,
ORPHANS_SET = 0x0080
};
@@ -603,6 +624,7 @@ enum op_overflow {
};
enum op_padding {
+ PADDING_CALC = 0x007f,
PADDING_SET = 0x0080
};
@@ -628,18 +650,22 @@ enum op_page_break_inside {
};
enum op_pause_after {
+ PAUSE_AFTER_CALC = 0x007f,
PAUSE_AFTER_SET = 0x0080
};
enum op_pause_before {
+ PAUSE_BEFORE_CALC = 0x007f,
PAUSE_BEFORE_SET = 0x0080
};
enum op_pitch_range {
+ PITCH_RANGE_CALC = 0x007f,
PITCH_RANGE_SET = 0x0080
};
enum op_pitch {
+ PITCH_CALC = 0x007f,
PITCH_FREQUENCY = 0x0080,
PITCH_X_LOW = 0x0000,
@@ -673,6 +699,7 @@ enum op_quotes {
};
enum op_richness {
+ RICHNESS_CALC = 0x007f,
RICHNESS_SET = 0x0080
};
@@ -703,6 +730,7 @@ enum op_speak {
};
enum op_speech_rate {
+ SPEECH_RATE_CALC = 0x007f,
SPEECH_RATE_SET = 0x0080,
SPEECH_RATE_X_SLOW = 0x0000,
@@ -715,6 +743,7 @@ enum op_speech_rate {
};
enum op_stress {
+ STRESS_CALC = 0x007f,
STRESS_SET = 0x0080
};
@@ -743,6 +772,7 @@ enum op_text_decoration {
};
enum op_text_indent {
+ TEXT_INDENT_CALC = 0x007f,
TEXT_INDENT_SET = 0x0080
};
@@ -754,6 +784,7 @@ enum op_text_transform {
};
enum op_top {
+ TOP_CALC = BOTTOM_CALC,
TOP_SET = BOTTOM_SET,
TOP_AUTO = BOTTOM_AUTO
};
@@ -765,6 +796,7 @@ enum op_unicode_bidi {
};
enum op_vertical_align {
+ VERTICAL_ALIGN_CALC = 0x007f,
VERTICAL_ALIGN_SET = 0x0080,
VERTICAL_ALIGN_BASELINE = 0x0000,
@@ -795,6 +827,7 @@ enum op_voice_family {
};
enum op_volume {
+ VOLUME_CALC = 0x007f,
VOLUME_NUMBER = 0x0080,
VOLUME_DIMENSION = 0x0081,
@@ -815,16 +848,19 @@ enum op_white_space {
};
enum op_widows {
+ WIDOWS_CALC = 0x007f,
WIDOWS_SET = 0x0080
};
enum op_width {
+ WIDTH_CALC = 0x007f,
WIDTH_SET = 0x0080,
WIDTH_AUTO = 0x0000
};
enum op_word_spacing {
+ WORD_SPACING_CALC = 0x007f,
WORD_SPACING_SET = 0x0080,
WORD_SPACING_NORMAL = 0x0000
@@ -837,6 +873,7 @@ enum op_writing_mode {
};
enum op_z_index {
+ Z_INDEX_CALC = 0x007f,
Z_INDEX_SET = 0x0080,
Z_INDEX_AUTO = 0x0000
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 3d88cef..1cdb27f 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -19,6 +19,12 @@
* list_style_position:CSS_PROP_LIST_STYLE_POSITION IDENT:( INHERIT: INSIDE:0,LIST_STYLE_POSITION_INSIDE OUTSIDE:0,LIST_STYLE_POSITION_OUTSIDE IDENT:)
*/
+typedef enum {
+ CALC_ANY,
+ CALC_NUMBER,
+ CALC_UNIT,
+} calc_kind;
+
struct keyval {
char *key;
char *val;
@@ -291,21 +297,34 @@ void output_color(FILE *outputf, struct keyval *parseid, struct keyval_list *kvl
parseid->val);
}
-void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
+void output_calc(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
{
struct keyval *ckv = kvlist->item[0];
- int ident_count;
+ const char *kind;
+
+ if (strcmp(ckv->key, "NUMBER") == 0)
+ kind = "UNIT_CALC_NUMBER";
+ else if (strcmp(ckv->key, "ANY") == 0)
+ kind = "UNIT_CALC_ANY";
+ else
+ kind = ckv->key;
fprintf(outputf,
"if ((token->type == CSS_TOKEN_IDENT) && "
"(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
" {\n"
- "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s /* _CALC */), %s);\n"
+ "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s), %s);\n"
"\t} else ",
parseid->val,
ckv->val,
- ckv->key
+ kind
);
+}
+
+void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
+{
+ struct keyval *ckv = kvlist->item[0];
+ int ident_count;
fprintf(outputf,
"{\n"
@@ -501,6 +520,7 @@ int main(int argc, char **argv)
struct keyval_list WRAP;
struct keyval_list NUMBER;
struct keyval_list COLOR;
+ struct keyval_list CALC;
if (argc < 2) {
@@ -533,6 +553,7 @@ int main(int argc, char **argv)
COLOR.count = 0;
LENGTH_UNIT.count = 0;
IDENT_LIST.count = 0;
+ CALC.count = 0;
curlist = &base;
@@ -548,7 +569,7 @@ int main(int argc, char **argv)
if (strcmp(rkv->key, "WRAP") == 0) {
WRAP.item[WRAP.count++] = rkv;
only_ident = false;
- } else if (strcmp(rkv->key, "NUMBER") == 0) {
+ } else if (curlist == &base && strcmp(rkv->key, "NUMBER") == 0) {
if (rkv->val[0] == '(') {
curlist = &NUMBER;
} else if (rkv->val[0] == ')') {
@@ -579,6 +600,14 @@ int main(int argc, char **argv)
}
only_ident = false;
do_token_check = false;
+ } else if (strcmp(rkv->key, "CALC") == 0) {
+ if (rkv->val[0] == '(') {
+ curlist = &CALC;
+ } else if (rkv->val[0] == ')') {
+ curlist = &base;
+ }
+ only_ident = false;
+ do_token_check = false;
} else if (strcmp(rkv->key, "COLOR") == 0) {
COLOR.item[COLOR.count++] = rkv;
do_token_check = false;
@@ -602,7 +631,7 @@ int main(int argc, char **argv)
/* header */
-output_header(outputf, descriptor, base.item[0], is_generic);
+ output_header(outputf, descriptor, base.item[0], is_generic);
if (WRAP.count > 0) {
output_wrap(outputf, base.item[0], &WRAP);
@@ -616,6 +645,10 @@ output_header(outputf, descriptor, base.item[0], is_generic);
if (URI.count > 0)
output_uri(outputf, base.item[0], &URI);
+ if (CALC.count > 0) {
+ output_calc(outputf, base.item[0], &CALC);
+ }
+
if (NUMBER.count > 0)
output_number(outputf, base.item[0], &NUMBER);
diff --git a/src/parse/properties/properties.gen b/src/parse/properties/properties.gen
index e729285..9830ce4 100644
--- a/src/parse/properties/properties.gen
+++ b/src/parse/properties/properties.gen
@@ -6,6 +6,13 @@
#property:CSS_PROP_ENUM IDENT:( INHERIT: IDENT:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY ALLOW: DISALLOW: RANGE:<0 LENGTH_UNIT:)
#property:CSS_PROP_ENUM WRAP:
+# When a property takes a NUMBER and/or LENGTH_UNIT you may add calc() support:
+# In the below, PROPERTY_FOO_CALC is the opcode enum for the set-but-calculated value bytecode.
+# e.g. HEIGHT_SET (for a LENGTH_UNIT) would be HEIGHT_CALC here.
+# CALC:( UNIT_??:PROPERTY_FOO_CALC CALC:) <-- When a default unit must be considered
+# CALC:( NUMBER:PROPERTY_FOO_CALC CALC:) <-- When a number must be produced (not a dimension)
+# CALC:( ANY:PROPERTY_FOO_CALC CALC:) <-- When a number or dimension is valid (e.g. line-height)
+
background_repeat:CSS_PROP_BACKGROUND_REPEAT IDENT:( INHERIT: NO_REPEAT:0,BACKGROUND_REPEAT_NO_REPEAT REPEAT_X:0,BACKGROUND_REPEAT_REPEAT_X REPEAT_Y:0,BACKGROUND_REPEAT_REPEAT_Y REPEAT:0,BACKGROUND_REPEAT_REPEAT IDENT:)
border_collapse:CSS_PROP_BORDER_COLLAPSE IDENT:( INHERIT: COLLAPSE:0,BORDER_COLLAPSE_COLLAPSE SEPARATE:0,BORDER_COLLAPSE_SEPARATE IDENT:)
@@ -22,35 +29,35 @@ empty_cells:CSS_PROP_EMPTY_CELLS IDENT:( INHERIT: SHOW:0,EMPTY_CELLS_SHOW HIDE:0
float:CSS_PROP_FLOAT IDENT:( INHERIT: LEFT:0,FLOAT_LEFT RIGHT:0,FLOAT_RIGHT NONE:0,FLOAT_NONE IDENT:)
-font_size:CSS_PROP_FONT_SIZE IDENT:( INHERIT: XX_SMALL:0,FONT_SIZE_XX_SMALL X_SMALL:0,FONT_SIZE_X_SMALL SMALL:0,FONT_SIZE_SMALL MEDIUM:0,FONT_SIZE_MEDIUM LARGE:0,FONT_SIZE_LARGE X_LARGE:0,FONT_SIZE_X_LARGE XX_LARGE:0,FONT_SIZE_XX_LARGE LARGER:0,FONT_SIZE_LARGER SMALLER:0,FONT_SIZE_SMALLER IDENT:) LENGTH_UNIT:( UNIT_PX:FONT_SIZE_DIMENSION MASK:UNIT_MASK_FONT_SIZE RANGE:<0 LENGTH_UNIT:)
+font_size:CSS_PROP_FONT_SIZE IDENT:( INHERIT: XX_SMALL:0,FONT_SIZE_XX_SMALL X_SMALL:0,FONT_SIZE_X_SMALL SMALL:0,FONT_SIZE_SMALL MEDIUM:0,FONT_SIZE_MEDIUM LARGE:0,FONT_SIZE_LARGE X_LARGE:0,FONT_SIZE_X_LARGE XX_LARGE:0,FONT_SIZE_XX_LARGE LARGER:0,FONT_SIZE_LARGER SMALLER:0,FONT_SIZE_SMALLER IDENT:) CALC:( UNIT_PX:FONT_SIZE_CALC CALC:) LENGTH_UNIT:( UNIT_PX:FONT_SIZE_DIMENSION MASK:UNIT_MASK_FONT_SIZE RANGE:<0 LENGTH_UNIT:)
font_style:CSS_PROP_FONT_STYLE IDENT:( INHERIT: NORMAL:0,FONT_STYLE_NORMAL ITALIC:0,FONT_STYLE_ITALIC OBLIQUE:0,FONT_STYLE_OBLIQUE IDENT:)
font_variant:CSS_PROP_FONT_VARIANT IDENT:( INHERIT: NORMAL:0,FONT_VARIANT_NORMAL SMALL_CAPS:0,FONT_VARIANT_SMALL_CAPS IDENT:)
-height:CSS_PROP_HEIGHT IDENT:( INHERIT: AUTO:0,HEIGHT_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:HEIGHT_SET MASK:UNIT_MASK_HEIGHT RANGE:<0 LENGTH_UNIT:)
+height:CSS_PROP_HEIGHT IDENT:( INHERIT: AUTO:0,HEIGHT_AUTO IDENT:) CALC:( UNIT_PX:HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:HEIGHT_SET MASK:UNIT_MASK_HEIGHT RANGE:<0 LENGTH_UNIT:)
-letter_spacing:CSS_PROP_LETTER_SPACING IDENT:( INHERIT: NORMAL:0,LETTER_SPACING_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:LETTER_SPACING_SET MASK:UNIT_MASK_LETTER_SPACING LENGTH_UNIT:)
+letter_spacing:CSS_PROP_LETTER_SPACING IDENT:( INHERIT: NORMAL:0,LETTER_SPACING_NORMAL IDENT:) CALC:( UNIT_PX:LETTER_SPACING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:LETTER_SPACING_SET MASK:UNIT_MASK_LETTER_SPACING LENGTH_UNIT:)
-line_height:CSS_PROP_LINE_HEIGHT IDENT:( INHERIT: NORMAL:0,LINE_HEIGHT_NORMAL IDENT:) NUMBER:( false:LINE_HEIGHT_NUMBER RANGE:num<0 NUMBER:) LENGTH_UNIT:( UNIT_PX:LINE_HEIGHT_DIMENSION MASK:UNIT_MASK_LINE_HEIGHT RANGE:<0 LENGTH_UNIT:)
+line_height:CSS_PROP_LINE_HEIGHT IDENT:( INHERIT: NORMAL:0,LINE_HEIGHT_NORMAL IDENT:) CALC:( ANY:LINE_HEIGHT_CALC CALC:) NUMBER:( false:LINE_HEIGHT_NUMBER RANGE:num<0 NUMBER:) LENGTH_UNIT:( UNIT_PX:LINE_HEIGHT_DIMENSION MASK:UNIT_MASK_LINE_HEIGHT RANGE:<0 LENGTH_UNIT:)
border_top:BORDER_SIDE_TOP WRAP:css__parse_border_side
border_bottom:BORDER_SIDE_BOTTOM WRAP:css__parse_border_side
border_left:BORDER_SIDE_LEFT WRAP:css__parse_border_side
border_right:BORDER_SIDE_RIGHT WRAP:css__parse_border_side
-max_height:CSS_PROP_MAX_HEIGHT IDENT:( INHERIT: NONE:0,MAX_HEIGHT_NONE IDENT:) LENGTH_UNIT:( UNIT_PX:MAX_HEIGHT_SET MASK:UNIT_MASK_MAX_HEIGHT RANGE:<0 LENGTH_UNIT:)
+max_height:CSS_PROP_MAX_HEIGHT IDENT:( INHERIT: NONE:0,MAX_HEIGHT_NONE IDENT:) CALC:( UNIT_PX:MAX_HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MAX_HEIGHT_SET MASK:UNIT_MASK_MAX_HEIGHT RANGE:<0 LENGTH_UNIT:)
-max_width:CSS_PROP_MAX_WIDTH IDENT:( INHERIT: NONE:0,MAX_WIDTH_NONE IDENT:) LENGTH_UNIT:( UNIT_PX:MAX_WIDTH_SET MASK:UNIT_MASK_MAX_WIDTH RANGE:<0 LENGTH_UNIT:)
+max_width:CSS_PROP_MAX_WIDTH IDENT:( INHERIT: NONE:0,MAX_WIDTH_NONE IDENT:) CALC:( UNIT_PX:MAX_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MAX_WIDTH_SET MASK:UNIT_MASK_MAX_WIDTH RANGE:<0 LENGTH_UNIT:)
-min_height:CSS_PROP_MIN_HEIGHT IDENT:( INHERIT: AUTO:0,MIN_HEIGHT_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET MASK:UNIT_MASK_MIN_HEIGHT RANGE:<0 LENGTH_UNIT:)
+min_height:CSS_PROP_MIN_HEIGHT IDENT:( INHERIT: AUTO:0,MIN_HEIGHT_AUTO IDENT:) CALC:( UNIT_PX:MIN_HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET MASK:UNIT_MASK_MIN_HEIGHT RANGE:<0 LENGTH_UNIT:)
-min_width:CSS_PROP_MIN_WIDTH IDENT:( INHERIT: AUTO:0,MIN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET MASK:UNIT_MASK_MIN_WIDTH RANGE:<0 LENGTH_UNIT:)
+min_width:CSS_PROP_MIN_WIDTH IDENT:( INHERIT: AUTO:0,MIN_WIDTH_AUTO IDENT:) CALC:( UNIT_PX:MIN_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET MASK:UNIT_MASK_MIN_WIDTH RANGE:<0 LENGTH_UNIT:)
color:CSS_PROP_COLOR IDENT:INHERIT COLOR:COLOR_SET
#generic for padding_{top, bottom, left, right}.c
-padding_side:op GENERIC: IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:PADDING_SET MASK:UNIT_MASK_PADDING_SIDE RANGE:<0 LENGTH_UNIT:)
+padding_side:op GENERIC: IDENT:INHERIT CALC:( UNIT_PX:PADDING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:PADDING_SET MASK:UNIT_MASK_PADDING_SIDE RANGE:<0 LENGTH_UNIT:)
padding_bottom:CSS_PROP_PADDING_BOTTOM WRAP:css__parse_padding_side
padding_left:CSS_PROP_PADDING_LEFT WRAP:css__parse_padding_side
@@ -59,7 +66,7 @@ padding_right:CSS_PROP_PADDING_RIGHT WRAP:css__parse_padding_side
#generic for margin_{top, bottom, left, right}.c
-margin_side:op GENERIC IDENT:( INHERIT: AUTO:0,MARGIN_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MARGIN_SET MASK:UNIT_MASK_MARGIN_SIDE LENGTH_UNIT:)
+margin_side:op GENERIC IDENT:( INHERIT: AUTO:0,MARGIN_AUTO IDENT:) CALC:( UNIT_PX:MARGIN_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MARGIN_SET MASK:UNIT_MASK_MARGIN_SIDE LENGTH_UNIT:)
margin_top:CSS_PROP_MARGIN_TOP WRAP:css__parse_margin_side
margin_bottom:CSS_PROP_MARGIN_BOTTOM WRAP:css__parse_margin_side
@@ -67,7 +74,7 @@ margin_left:CSS_PROP_MARGIN_LEFT WRAP:css__parse_margin_side
margin_right:CSS_PROP_MARGIN_RIGHT WRAP:css__parse_margin_side
#generic for {top, bottom, left, right}.c
-side:op GENERIC: IDENT:( INHERIT: AUTO:0,BOTTOM_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:BOTTOM_SET ALLOW:unit&(UNIT_LENGTH|UNIT_PCT) LENGTH_UNIT:)
+side:op GENERIC: IDENT:( INHERIT: AUTO:0,BOTTOM_AUTO IDENT:) CALC:( UNIT_PX:BOTTOM_CALC CALC:) LENGTH_UNIT:( UNIT_PX:BOTTOM_SET ALLOW:unit&(UNIT_LENGTH|UNIT_PCT) LENGTH_UNIT:)
top:CSS_PROP_TOP WRAP:css__parse_side
bottom:CSS_PROP_BOTTOM WRAP:css__parse_side
@@ -76,7 +83,7 @@ right:CSS_PROP_RIGHT WRAP:css__parse_side
#generic for border_{top, bottom, left, right}_width.c
-border_side_width:op GENERIC: IDENT:( INHERIT: THIN:0,BORDER_WIDTH_THIN MEDIUM:0,BORDER_WIDTH_MEDIUM THICK:0,BORDER_WIDTH_THICK IDENT:) LENGTH_UNIT:( UNIT_PX:BORDER_WIDTH_SET MASK:UNIT_MASK_BORDER_SIDE_WIDTH RANGE:<0 LENGTH_UNIT:)
+border_side_width:op GENERIC: IDENT:( INHERIT: THIN:0,BORDER_WIDTH_THIN MEDIUM:0,BORDER_WIDTH_MEDIUM THICK:0,BORDER_WIDTH_THICK IDENT:) CALC:( UNIT_PX:BORDER_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:BORDER_WIDTH_SET MASK:UNIT_MASK_BORDER_SIDE_WIDTH RANGE:<0 LENGTH_UNIT:)
border_top_width:CSS_PROP_BORDER_TOP_WIDTH WRAP:css__parse_border_side_width
border_bottom_width:CSS_PROP_BORDER_BOTTOM_WIDTH WRAP:css__parse_border_side_width
@@ -120,7 +127,7 @@ list_style_image:CSS_PROP_LIST_STYLE_IMAGE IDENT:( INHERIT: NONE:0,LIST_STYLE_IM
list_style_position:CSS_PROP_LIST_STYLE_POSITION IDENT:( INHERIT: INSIDE:0,LIST_STYLE_POSITION_INSIDE OUTSIDE:0,LIST_STYLE_POSITION_OUTSIDE IDENT:)
-orphans:CSS_PROP_ORPHANS IDENT:INHERIT NUMBER:( true:ORPHANS_SET RANGE:num<0 NUMBER:)
+orphans:CSS_PROP_ORPHANS IDENT:INHERIT CALC:( NUMBER:ORPHANS_CALC CALC:) NUMBER:( true:ORPHANS_SET RANGE:num<0 NUMBER:)
outline_color:CSS_PROP_OUTLINE_COLOR IDENT:( INHERIT: INVERT:0,OUTLINE_COLOR_INVERT IDENT:) COLOR:OUTLINE_COLOR_SET
@@ -140,17 +147,17 @@ page_break_before:CSS_PROP_PAGE_BREAK_BEFORE IDENT:( INHERIT: AUTO:0,PAGE_BREAK_
page_break_inside:CSS_PROP_PAGE_BREAK_INSIDE IDENT:( INHERIT: AUTO:0,PAGE_BREAK_INSIDE_AUTO AVOID:0,PAGE_BREAK_INSIDE_AVOID IDENT:)
-pause_after:CSS_PROP_PAUSE_AFTER IDENT:INHERIT LENGTH_UNIT:( UNIT_S:PAUSE_AFTER_SET MASK:UNIT_MASK_PAUSE_AFTER RANGE:<0 LENGTH_UNIT:)
+pause_after:CSS_PROP_PAUSE_AFTER IDENT:INHERIT CALC:( UNIT_S:PAUSE_AFTER_CALC CALC:) LENGTH_UNIT:( UNIT_S:PAUSE_AFTER_SET MASK:UNIT_MASK_PAUSE_AFTER RANGE:<0 LENGTH_UNIT:)
-pause_before:CSS_PROP_PAUSE_BEFORE IDENT:INHERIT LENGTH_UNIT:( UNIT_S:PAUSE_BEFORE_SET MASK:UNIT_MASK_PAUSE_BEFORE RANGE:<0 LENGTH_UNIT:)
+pause_before:CSS_PROP_PAUSE_BEFORE IDENT:INHERIT CALC:( UNIT_S:PAUSE_BEFORE_CALC CALC:) LENGTH_UNIT:( UNIT_S:PAUSE_BEFORE_SET MASK:UNIT_MASK_PAUSE_BEFORE RANGE:<0 LENGTH_UNIT:)
-pitch:CSS_PROP_PITCH IDENT:( INHERIT: X_LOW:0,PITCH_X_LOW LOW:0,PITCH_LOW MEDIUM:0,PITCH_MEDIUM HIGH:0,PITCH_HIGH X_HIGH:0,PITCH_X_HIGH IDENT:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY MASK:UNIT_MASK_PITCH RANGE:<0 LENGTH_UNIT:)
+pitch:CSS_PROP_PITCH IDENT:( INHERIT: X_LOW:0,PITCH_X_LOW LOW:0,PITCH_LOW MEDIUM:0,PITCH_MEDIUM HIGH:0,PITCH_HIGH X_HIGH:0,PITCH_X_HIGH IDENT:) CALC:( UNIT_HZ:PITCH_CALC CALC:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY MASK:UNIT_MASK_PITCH RANGE:<0 LENGTH_UNIT:)
-pitch_range:CSS_PROP_PITCH_RANGE IDENT:INHERIT NUMBER:( false:PITCH_RANGE_SET RANGE:num<0||num>F_100 NUMBER:)
+pitch_range:CSS_PROP_PITCH_RANGE IDENT:INHERIT CALC:( NUMBER:PITCH_RANGE_CALC CALC:) NUMBER:( false:PITCH_RANGE_SET RANGE:num<0||num>F_100 NUMBER:)
position:CSS_PROP_POSITION IDENT:( INHERIT: LIBCSS_STATIC:0,POSITION_STATIC RELATIVE:0,POSITION_RELATIVE ABSOLUTE:0,POSITION_ABSOLUTE FIXED:0,POSITION_FIXED IDENT:)
-richness:CSS_PROP_RICHNESS IDENT:INHERIT NUMBER:( false:RICHNESS_SET RANGE:num<0||num>F_100 NUMBER:)
+richness:CSS_PROP_RICHNESS IDENT:INHERIT CALC:( NUMBER:RICHNESS_CALC CALC:) NUMBER:( false:RICHNESS_SET RANGE:num<0||num>F_100 NUMBER:)
speak:CSS_PROP_SPEAK IDENT:( INHERIT: NORMAL:0,SPEAK_NORMAL NONE:0,SPEAK_NONE SPELL_OUT:0,SPEAK_SPELL_OUT IDENT:)
@@ -160,37 +167,35 @@ speak_numeral:CSS_PROP_SPEAK_NUMERAL IDENT:( INHERIT: DIGITS:0,SPEAK_NUMERAL_DIG
speak_punctuation:CSS_PROP_SPEAK_PUNCTUATION IDENT:( INHERIT: CODE:0,SPEAK_PUNCTUATION_CODE NONE:0,SPEAK_PUNCTUATION_NONE IDENT:)
-speech_rate:CSS_PROP_SPEECH_RATE IDENT:( INHERIT: X_SLOW:0,SPEECH_RATE_X_SLOW SLOW:0,SPEECH_RATE_SLOW MEDIUM:0,SPEECH_RATE_MEDIUM FAST:0,SPEECH_RATE_FAST X_FAST:0,SPEECH_RATE_X_FAST FASTER:0,SPEECH_RATE_FASTER SLOWER:0,SPEECH_RATE_SLOWER IDENT:) NUMBER:( false:SPEECH_RATE_SET RANGE:num<0 NUMBER:)
+speech_rate:CSS_PROP_SPEECH_RATE IDENT:( INHERIT: X_SLOW:0,SPEECH_RATE_X_SLOW SLOW:0,SPEECH_RATE_SLOW MEDIUM:0,SPEECH_RATE_MEDIUM FAST:0,SPEECH_RATE_FAST X_FAST:0,SPEECH_RATE_X_FAST FASTER:0,SPEECH_RATE_FASTER SLOWER:0,SPEECH_RATE_SLOWER IDENT:) CALC:( NUMBER:SPEECH_RATE_CALC CALC:) NUMBER:( false:SPEECH_RATE_SET RANGE:num<0 NUMBER:)
-stress:CSS_PROP_STRESS IDENT:INHERIT NUMBER:( false:STRESS_SET RANGE:num<0||num>INTTOFIX(100) NUMBER:)
+stress:CSS_PROP_STRESS IDENT:INHERIT CALC:( NUMBER:STRESS_CALC CALC:) NUMBER:( false:STRESS_SET RANGE:num<0||num>INTTOFIX(100) NUMBER:)
table_layout:CSS_PROP_TABLE_LAYOUT IDENT:( INHERIT: AUTO:0,TABLE_LAYOUT_AUTO FIXED:0,TABLE_LAYOUT_FIXED IDENT:)
text_align:CSS_PROP_TEXT_ALIGN IDENT:( INHERIT: LEFT:0,TEXT_ALIGN_LEFT RIGHT:0,TEXT_ALIGN_RIGHT CENTER:0,TEXT_ALIGN_CENTER JUSTIFY:0,TEXT_ALIGN_JUSTIFY LIBCSS_LEFT:0,TEXT_ALIGN_LIBCSS_LEFT LIBCSS_CENTER:0,TEXT_ALIGN_LIBCSS_CENTER LIBCSS_RIGHT:0,TEXT_ALIGN_LIBCSS_RIGHT IDENT:)
-text_indent:CSS_PROP_TEXT_INDENT IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:TEXT_INDENT_SET MASK:UNIT_MASK_TEXT_INDENT LENGTH_UNIT:)
+text_indent:CSS_PROP_TEXT_INDENT IDENT:INHERIT CALC:( UNIT_PX:TEXT_INDENT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:TEXT_INDENT_SET MASK:UNIT_MASK_TEXT_INDENT LENGTH_UNIT:)
text_transform:CSS_PROP_TEXT_TRANSFORM IDENT:( INHERIT: CAPITALIZE:0,TEXT_TRANSFORM_CAPITALIZE UPPERCASE:0,TEXT_TRANSFORM_UPPERCASE LOWERCASE:0,TEXT_TRANSFORM_LOWERCASE NONE:0,TEXT_TRANSFORM_NONE IDENT:)
unicode_bidi:CSS_PROP_UNICODE_BIDI IDENT:( INHERIT: NORMAL:0,UNICODE_BIDI_NORMAL EMBED:0,UNICODE_BIDI_EMBED BIDI_OVERRIDE:0,UNICODE_BIDI_BIDI_OVERRIDE IDENT:)
-vertical_align:CSS_PROP_VERTICAL_ALIGN IDENT:( INHERIT: BASELINE:0,VERTICAL_ALIGN_BASELINE SUB:0,VERTICAL_ALIGN_SUB SUPER:0,VERTICAL_ALIGN_SUPER TOP:0,VERTICAL_ALIGN_TOP TEXT_TOP:0,VERTICAL_ALIGN_TEXT_TOP MIDDLE:0,VERTICAL_ALIGN_MIDDLE BOTTOM:0,VERTICAL_ALIGN_BOTTOM TEXT_BOTTOM:0,VERTICAL_ALIGN_TEXT_BOTTOM IDENT:) LENGTH_UNIT:( UNIT_PX:VERTICAL_ALIGN_SET MASK:UNIT_MASK_VERTICAL_ALIGN LENGTH_UNIT:)
+vertical_align:CSS_PROP_VERTICAL_ALIGN IDENT:( INHERIT: BASELINE:0,VERTICAL_ALIGN_BASELINE SUB:0,VERTICAL_ALIGN_SUB SUPER:0,VERTICAL_ALIGN_SUPER TOP:0,VERTICAL_ALIGN_TOP TEXT_TOP:0,VERTICAL_ALIGN_TEXT_TOP MIDDLE:0,VERTICAL_ALIGN_MIDDLE BOTTOM:0,VERTICAL_ALIGN_BOTTOM TEXT_BOTTOM:0,VERTICAL_ALIGN_TEXT_BOTTOM IDENT:) CALC:( UNIT_PX:VERTICAL_ALIGN_CALC CALC:) LENGTH_UNIT:( UNIT_PX:VERTICAL_ALIGN_SET MASK:UNIT_MASK_VERTICAL_ALIGN LENGTH_UNIT:)
visibility:CSS_PROP_VISIBILITY IDENT:( INHERIT: VISIBLE:0,VISIBILITY_VISIBLE HIDDEN:0,VISIBILITY_HIDDEN COLLAPSE:0,VISIBILITY_COLLAPSE IDENT:)
-volume:CSS_PROP_VOLUME IDENT:( INHERIT: SILENT:0,VOLUME_SILENT X_SOFT:0,VOLUME_X_SOFT SOFT:0,VOLUME_SOFT MEDIUM:0,VOLUME_MEDIUM LOUD:0,VOLUME_LOUD X_LOUD:0,VOLUME_X_LOUD IDENT:) NUMBER:( false:VOLUME_NUMBER RANGE:num<0||num>F_100 NUMBER:) LENGTH_UNIT:( UNIT_PX:VOLUME_DIMENSION MASK:UNIT_MASK_VOLUME RANGE:<0 LENGTH_UNIT:)
+volume:CSS_PROP_VOLUME IDENT:( INHERIT: SILENT:0,VOLUME_SILENT X_SOFT:0,VOLUME_X_SOFT SOFT:0,VOLUME_SOFT MEDIUM:0,VOLUME_MEDIUM LOUD:0,VOLUME_LOUD X_LOUD:0,VOLUME_X_LOUD IDENT:) CALC:( ANY:VOLUME_CALC CALC:) NUMBER:( false:VOLUME_NUMBER RANGE:num<0||num>F_100 NUMBER:) LENGTH_UNIT:( UNIT_PX:VOLUME_DIMENSION MASK:UNIT_MASK_VOLUME RANGE:<0 LENGTH_UNIT:)
white_space:CSS_PROP_WHITE_SPACE IDENT:( INHERIT: NORMAL:0,WHITE_SPACE_NORMAL PRE:0,WHITE_SPACE_PRE NOWRAP:0,WHITE_SPACE_NOWRAP PRE_WRAP:0,WHITE_SPACE_PRE_WRAP PRE_LINE:0,WHITE_SPACE_PRE_LINE IDENT:)
-widows:CSS_PROP_WIDOWS IDENT:INHERIT NUMBER:( true:WIDOWS_SET RANGE:num<0 NUMBER:)
-
-
-width:CSS_PROP_WIDTH IDENT:( INHERIT: AUTO:0,WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:WIDTH_SET MASK:UNIT_MASK_WIDTH RANGE:<0 LENGTH_UNIT:)
+widows:CSS_PROP_WIDOWS IDENT:INHERIT CALC:( NUMBER:WIDOWS_CALC CALC:) NUMBER:( true:WIDOWS_SET RANGE:num<0 NUMBER:)
-word_spacing:CSS_PROP_WORD_SPACING IDENT:( INHERIT: NORMAL:0,WORD_SPACING_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:WORD_SPACING_SET MASK:UNIT_MASK_WORD_SPACING LENGTH_UNIT:)
+width:CSS_PROP_WIDTH IDENT:( INHERIT: AUTO:0,WIDTH_AUTO IDENT:) CALC:( UNIT_PX:WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:WIDTH_SET MASK:UNIT_MASK_WIDTH RANGE:<0 LENGTH_UNIT:)
-z_index:CSS_PROP_Z_INDEX IDENT:( INHERIT: AUTO:0,Z_INDEX_AUTO IDENT:) NUMBER:( true:Z_INDEX_SET NUMBER:)
+word_spacing:CSS_PROP_WORD_SPACING IDENT:( INHERIT: NORMAL:0,WORD_SPACING_NORMAL IDENT:) CALC:( UNIT_PX:WORD_SPACING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:WORD_SPACING_SET MASK:UNIT_MASK_WORD_SPACING LENGTH_UNIT:)
+z_index:CSS_PROP_Z_INDEX IDENT:( INHERIT: AUTO:0,Z_INDEX_AUTO IDENT:) CALC:( NUMBER:Z_INDEX_CALC CALC:) NUMBER:( true:Z_INDEX_SET NUMBER:)
break_after:CSS_PROP_BREAK_AFTER IDENT:( INHERIT: AUTO:0,BREAK_AFTER_AUTO ALWAYS:0,BREAK_AFTER_ALWAYS AVOID:0,BREAK_AFTER_AVOID LEFT:0,BREAK_AFTER_LEFT RIGHT:0,BREAK_AFTER_RIGHT PAGE:0,BREAK_AFTER_PAGE COLUMN:0,BREAK_AFTER_COLUMN AVOID_PAGE:0,BREAK_AFTER_AVOID_PAGE AVOID_COLUMN:0,BREAK_AFTER_AVOID_COLUMN IDENT:)
@@ -198,11 +203,11 @@ break_before:CSS_PROP_BREAK_BEFORE IDENT:( INHERIT: AUTO:0,BREAK_BEFORE_AUTO ALW
break_inside:CSS_PROP_BREAK_INSIDE IDENT:( INHERIT: AUTO:0,BREAK_INSIDE_AUTO AVOID:0,BREAK_INSIDE_AVOID AVOID_PAGE:0,BREAK_INSIDE_AVOID_PAGE AVOID_COLUMN:0,BREAK_INSIDE_AVOID_COLUMN IDENT:)
-column_count:CSS_PROP_COLUMN_COUNT IDENT:( INHERIT: AUTO:0,COLUMN_COUNT_AUTO IDENT:) NUMBER:( true:COLUMN_COUNT_SET RANGE:num<0 NUMBER:)
+column_count:CSS_PROP_COLUMN_COUNT IDENT:( INHERIT: AUTO:0,COLUMN_COUNT_AUTO IDENT: CALC:( NUMBER:COLUMN_COUNT_CALC CALC:)) NUMBER:( true:COLUMN_COUNT_SET RANGE:num<0 NUMBER:)
column_fill:CSS_PROP_COLUMN_FILL IDENT:( INHERIT: BALANCE:0,COLUMN_FILL_BALANCE AUTO:0,COLUMN_FILL_AUTO IDENT:)
-column_gap:CSS_PROP_COLUMN_GAP IDENT:( INHERIT: NORMAL:0,COLUMN_GAP_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_GAP_SET RANGE:<0 MASK:UNIT_MASK_COLUMN_GAP LENGTH_UNIT:)
+column_gap:CSS_PROP_COLUMN_GAP IDENT:( INHERIT: NORMAL:0,COLUMN_GAP_NORMAL IDENT:) CALC:( UNIT_PX:COLUMN_GAP_CALC CALC:) LENGTH_UNIT:( UNIT_PX:COLUMN_GAP_SET RANGE:<0 MASK:UNIT_MASK_COLUMN_GAP LENGTH_UNIT:)
column_rule_color:CSS_PROP_COLUMN_RULE_COLOR IDENT:( INHERIT: IDENT:) COLOR:COLUMN_RULE_COLOR_SET
@@ -212,7 +217,7 @@ column_rule_width:CSS_PROP_COLUMN_RULE_WIDTH WRAP:css__parse_border_side_width
column_span:CSS_PROP_COLUMN_SPAN IDENT:( INHERIT: NONE:0,COLUMN_SPAN_NONE ALL:0,COLUMN_SPAN_ALL IDENT:)
-column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET MASK:UNIT_MASK_COLUMN_WIDTH LENGTH_UNIT:)
+column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) CALC:( UNIT_PX:COLUMN_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET MASK:UNIT_MASK_COLUMN_WIDTH LENGTH_UNIT:)
writing_mode:CSS_PROP_WRITING_MODE IDENT:( INHERIT: HORIZONTAL_TB:0,WRITING_MODE_HORIZONTAL_TB VERTICAL_RL:0,WRITING_MODE_VERTICAL_RL VERTICAL_LR:0,WRITING_MODE_VERTICAL_LR IDENT:)
@@ -224,16 +229,16 @@ align_items:CSS_PROP_ALIGN_ITEMS IDENT:( INHERIT: STRETCH:0,ALIGN_ITEMS_STRETCH
align_self:CSS_PROP_ALIGN_SELF IDENT:( INHERIT: STRETCH:0,ALIGN_SELF_STRETCH FLEX_START:0,ALIGN_SELF_FLEX_START FLEX_END:0,ALIGN_SELF_FLEX_END CENTER:0,ALIGN_SELF_CENTER BASELINE:0,ALIGN_SELF_BASELINE AUTO:0,ALIGN_SELF_AUTO IDENT:)
-flex_basis:CSS_PROP_FLEX_BASIS IDENT:( INHERIT: AUTO:0,FLEX_BASIS_AUTO CONTENT:0,FLEX_BASIS_CONTENT IDENT:) LENGTH_UNIT:( UNIT_PX:FLEX_BASIS_SET MASK:UNIT_MASK_FLEX_BASIS RANGE:<0 LENGTH_UNIT:)
+flex_basis:CSS_PROP_FLEX_BASIS IDENT:( INHERIT: AUTO:0,FLEX_BASIS_AUTO CONTENT:0,FLEX_BASIS_CONTENT IDENT:) CALC:( UNIT_PX:FLEX_BASIS_CALC CALC:) LENGTH_UNIT:( UNIT_PX:FLEX_BASIS_SET MASK:UNIT_MASK_FLEX_BASIS RANGE:<0 LENGTH_UNIT:)
flex_direction:CSS_PROP_FLEX_DIRECTION IDENT:( INHERIT: ROW:0,FLEX_DIRECTION_ROW ROW_REVERSE:0,FLEX_DIRECTION_ROW_REVERSE COLUMN:0,FLEX_DIRECTION_COLUMN COLUMN_REVERSE:0,FLEX_DIRECTION_COLUMN_REVERSE IDENT:)
-flex_grow:CSS_PROP_FLEX_GROW IDENT:INHERIT NUMBER:( false:FLEX_GROW_SET RANGE:num<0 NUMBER:)
+flex_grow:CSS_PROP_FLEX_GROW IDENT:INHERIT CALC:( NUMBER:FLEX_GROW_CALC CALC:) NUMBER:( false:FLEX_GROW_SET RANGE:num<0 NUMBER:)
-flex_shrink:CSS_PROP_FLEX_SHRINK IDENT:INHERIT NUMBER:( false:FLEX_SHRINK_SET RANGE:num<0 NUMBER:)
+flex_shrink:CSS_PROP_FLEX_SHRINK IDENT:INHERIT CALC:( NUMBER:FLEX_SHRINK_CALC CALC:) NUMBER:( false:FLEX_SHRINK_SET RANGE:num<0 NUMBER:)
flex_wrap:CSS_PROP_FLEX_WRAP IDENT:( INHERIT: NOWRAP:0,FLEX_WRAP_NOWRAP WRAP_STRING:0,FLEX_WRAP_WRAP WRAP_REVERSE:0,FLEX_WRAP_WRAP_REVERSE IDENT:)
justify_content:CSS_PROP_JUSTIFY_CONTENT IDENT:( INHERIT: FLEX_START:0,JUSTIFY_CONTENT_FLEX_START FLEX_END:0,JUSTIFY_CONTENT_FLEX_END CENTER:0,JUSTIFY_CONTENT_CENTER SPACE_BETWEEN:0,JUSTIFY_CONTENT_SPACE_BETWEEN SPACE_AROUND:0,JUSTIFY_CONTENT_SPACE_AROUND SPACE_EVENLY:0,JUSTIFY_CONTENT_SPACE_EVENLY IDENT:)
-order:CSS_PROP_ORDER IDENT:INHERIT NUMBER:( true:ORDER_SET NUMBER:)
+order:CSS_PROP_ORDER IDENT:INHERIT CALC:( NUMBER:ORDER_CALC CALC:) NUMBER:( true:ORDER_SET NUMBER:)
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 4739486..cce9717 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1351,9 +1351,9 @@ cleanup:
*
*
* calc(10px + (4rem / 2)) =>
- * U 10 px
- * U 4 rem
- * N 2
+ * V 10 px
+ * V 4 rem
+ * V 2 NUMBER
* /
* +
* =
@@ -1362,14 +1362,12 @@ cleanup:
static css_error
css__parse_calc_sum(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit);
+ css_style *result);
static css_error
css__parse_calc_value(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t default_unit)
+ css_style *result)
{
css_error error;
int orig_ctx = *ctx;
@@ -1377,7 +1375,7 @@ css__parse_calc_value(css_language *c,
token = parserutils_vector_iterate(vector, ctx);
if (tokenIsChar(token, '(')) {
- error = css__parse_calc_sum(c, vector, ctx, result, default_unit);
+ error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1396,13 +1394,13 @@ css__parse_calc_value(css_language *c,
uint32_t unit = 0;
*ctx = orig_ctx;
- error = css__parse_unit_specifier(c, vector, ctx, default_unit, &length, &unit);
+ error = css__parse_unit_specifier(c, vector, ctx, UNIT_CALC_NUMBER, &length, &unit);
if (error != CSS_OK) {
*ctx = orig_ctx;
return error;
}
- error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'U', length, unit);
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'V', length, unit);
}
break;
@@ -1422,8 +1420,7 @@ css__parse_calc_value(css_language *c,
static css_error
css__parse_calc_product(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit)
+ css_style *result)
{
css_error error = CSS_OK;
const css_token *token;
@@ -1431,7 +1428,7 @@ css__parse_calc_product(css_language *c,
/* First parse a value */
- error = css__parse_calc_value(c, vector, ctx, result, unit);
+ error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1455,33 +1452,10 @@ css__parse_calc_product(css_language *c,
/* Consume that * or / now */
token = parserutils_vector_iterate(vector, ctx);
- if (multiplication) {
- /* parse another value */
- error = css__parse_calc_value(c, vector, ctx, result, unit);
- if (error != CSS_OK)
- break;
- } else {
- css_fixed num;
- size_t consumed;
-
- token = parserutils_vector_iterate(vector, ctx);
- if (token->type != CSS_TOKEN_NUMBER) {
- error = CSS_INVALID;
- break;
- }
- num = css__number_from_lwc_string(token->idata, false, &consumed);
- if (consumed != lwc_string_length(token->idata)) {
- error = CSS_INVALID;
- break;
- }
-
- error = css__stylesheet_style_append(result, (css_code_t) 'N');
- if (error != CSS_OK)
- break;
- error = css__stylesheet_style_append(result, (css_code_t) num);
- if (error != CSS_OK)
- break;
- }
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result);
+ if (error != CSS_OK)
+ break;
/* emit the multiplication/division operator */
error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
@@ -1494,8 +1468,7 @@ css__parse_calc_product(css_language *c,
css_error
css__parse_calc_sum(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit)
+ css_style *result)
{
css_error error = CSS_OK;
const css_token *token;
@@ -1503,7 +1476,7 @@ css__parse_calc_sum(css_language *c,
/* First parse a product */
- error = css__parse_calc_product(c, vector, ctx, result, unit);
+ error = css__parse_calc_product(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1528,7 +1501,7 @@ css__parse_calc_sum(css_language *c,
token = parserutils_vector_iterate(vector, ctx);
/* parse another product */
- error = css__parse_calc_product(c, vector, ctx, result, unit);
+ error = css__parse_calc_product(c, vector, ctx, result);
if (error != CSS_OK)
break;
@@ -1570,8 +1543,10 @@ css_error css__parse_calc(css_language *c,
error = css__stylesheet_style_append(calc_style, property);
if (error != CSS_OK)
goto cleanup;
+
+ error = css__stylesheet_style_append(calc_style, (css_code_t) unit);
- error = css__parse_calc_sum(c, vector, ctx, calc_style, unit);
+ error = css__parse_calc_sum(c, vector, ctx, calc_style);
if (error != CSS_OK)
goto cleanup;
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=0933e7f8717bdbac3b91...
commit 0933e7f8717bdbac3b91debff44ec86afaf1ec84
Author: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
parse: Add calc() parser.
Co-authored-by: Michael Drake <michael.drake(a)netsurf-browser.org>
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 24cc536..3d88cef 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -296,6 +296,16 @@ void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_lis
struct keyval *ckv = kvlist->item[0];
int ident_count;
+ fprintf(outputf,
+ "if ((token->type == CSS_TOKEN_IDENT) && "
+ "(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
+ " {\n"
+ "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s /* _CALC */), %s);\n"
+ "\t} else ",
+ parseid->val,
+ ckv->val,
+ ckv->key
+ );
fprintf(outputf,
"{\n"
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 1e184f8..4739486 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1333,3 +1333,269 @@ cleanup:
return error;
}
+
+/******************************************************************************/
+
+/* CALC
+ *
+ * calc( <calc-sum> )
+ *
+ * where
+ * <calc-sum> = <calc-product> [ [ '+' | '-' ] <calc-product> ]*
+ *
+ * where
+ * <calc-product> = <calc-value> [ '*' <calc-value> | '/' <number> ]*
+ *
+ * where
+ * <calc-value> = <number> | <dimension> | <percentage> | ( <calc-sum> )
+ *
+ *
+ * calc(10px + (4rem / 2)) =>
+ * U 10 px
+ * U 4 rem
+ * N 2
+ * /
+ * +
+ * =
+ */
+
+static css_error
+css__parse_calc_sum(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t unit);
+
+static css_error
+css__parse_calc_value(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t default_unit)
+{
+ css_error error;
+ int orig_ctx = *ctx;
+ const css_token *token;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (tokenIsChar(token, '(')) {
+ error = css__parse_calc_sum(c, vector, ctx, result, default_unit);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ token = parserutils_vector_peek(vector, *ctx);
+ if (!tokenIsChar(token, ')')) {
+ return CSS_INVALID;
+ }
+
+ } else switch (token->type) {
+ case CSS_TOKEN_NUMBER: /* Fall through */
+ case CSS_TOKEN_DIMENSION: /* Fall through */
+ case CSS_TOKEN_PERCENTAGE:
+ {
+ css_fixed length = 0;
+ uint32_t unit = 0;
+ *ctx = orig_ctx;
+
+ error = css__parse_unit_specifier(c, vector, ctx, default_unit, &length, &unit);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ return error;
+ }
+
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'U', length, unit);
+ }
+ break;
+
+ default:
+ error = CSS_INVALID;
+ break;
+ }
+
+ return error;
+}
+
+/* Both this, and css_parse_calc_sum must stop when it encounters a close-paren.
+ * If it hasn't had any useful tokens before that, it's an error. It does not
+ * need to restore ctx before returning an error but it does need to ensure that
+ * the close paren has not been consumed
+ */
+static css_error
+css__parse_calc_product(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t unit)
+{
+ css_error error = CSS_OK;
+ const css_token *token;
+ bool multiplication;
+
+
+ /* First parse a value */
+ error = css__parse_calc_value(c, vector, ctx, result, unit);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ do {
+ /* What is our next token? */
+ token = parserutils_vector_peek(vector, *ctx);
+ if (token == NULL) {
+ error = CSS_INVALID;
+ break;
+ } else if (tokenIsChar(token, ')'))
+ break;
+ else if (tokenIsChar(token, '*'))
+ multiplication = true;
+ else if (tokenIsChar(token, '/'))
+ multiplication = false;
+ else {
+ error = CSS_INVALID;
+ break;
+ }
+ /* Consume that * or / now */
+ token = parserutils_vector_iterate(vector, ctx);
+
+ if (multiplication) {
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result, unit);
+ if (error != CSS_OK)
+ break;
+ } else {
+ css_fixed num;
+ size_t consumed;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token->type != CSS_TOKEN_NUMBER) {
+ error = CSS_INVALID;
+ break;
+ }
+ num = css__number_from_lwc_string(token->idata, false, &consumed);
+ if (consumed != lwc_string_length(token->idata)) {
+ error = CSS_INVALID;
+ break;
+ }
+
+ error = css__stylesheet_style_append(result, (css_code_t) 'N');
+ if (error != CSS_OK)
+ break;
+ error = css__stylesheet_style_append(result, (css_code_t) num);
+ if (error != CSS_OK)
+ break;
+ }
+
+ /* emit the multiplication/division operator */
+ error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
+ } while (1);
+ /* We've fallen off, either we had an error or we're left with ')' */
+ return error;
+}
+
+
+css_error
+css__parse_calc_sum(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t unit)
+{
+ css_error error = CSS_OK;
+ const css_token *token;
+ bool addition;
+
+
+ /* First parse a product */
+ error = css__parse_calc_product(c, vector, ctx, result, unit);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ do {
+ /* What is our next token? */
+ token = parserutils_vector_peek(vector, *ctx);
+ if (token == NULL) {
+ error = CSS_INVALID;
+ break;
+ } else if (tokenIsChar(token, ')'))
+ break;
+ else if (tokenIsChar(token, '+'))
+ addition = true;
+ else if (tokenIsChar(token, '-'))
+ addition = false;
+ else {
+ error = CSS_INVALID;
+ break;
+ }
+ /* Consume that + or - now */
+ token = parserutils_vector_iterate(vector, ctx);
+
+ /* parse another product */
+ error = css__parse_calc_product(c, vector, ctx, result, unit);
+ if (error != CSS_OK)
+ break;
+
+ /* emit the addition/subtraction operator */
+ error = css__stylesheet_style_append(result, (css_code_t) (addition ? '+' : '-'));
+ } while (1);
+ /* We've fallen off, either we had an error or we're left with ')' */
+ return error;
+}
+
+/* Documented in utils.h */
+css_error css__parse_calc(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ css_code_t property,
+ uint32_t unit)
+{
+ int orig_ctx = *ctx;
+ const css_token *token;
+ css_error error = CSS_OK;
+ css_style *calc_style = NULL;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token == NULL) {
+ *ctx = orig_ctx;
+ return CSS_INVALID;
+ }
+
+ if (!tokenIsChar(token, '(')) {
+ /* If we don't get an open-paren, give up now */
+ *ctx = orig_ctx;
+ return CSS_INVALID;
+ }
+
+ error = css__stylesheet_style_create(c->sheet, &calc_style);
+ if (error != CSS_OK)
+ goto cleanup;
+
+ error = css__stylesheet_style_append(calc_style, property);
+ if (error != CSS_OK)
+ goto cleanup;
+
+ error = css__parse_calc_sum(c, vector, ctx, calc_style, unit);
+ if (error != CSS_OK)
+ goto cleanup;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (!tokenIsChar(token, ')')) {
+ /* If we don't get a close-paren, give up now */
+ error = CSS_INVALID;
+ goto cleanup;
+ }
+
+ /* Append the indicator that the calc is finished */
+ error = css__stylesheet_style_append(calc_style, (css_code_t) '=');
+ if (error != CSS_OK)
+ goto cleanup;
+
+ /* TODO: Once we're OK to do so, merge the style */
+ (void)result;
+ /* error = css__stylesheet_style_merge_style(result, calc_style); */
+
+cleanup:
+ css__stylesheet_style_destroy(calc_style);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ }
+
+ return error;
+}
diff --git a/src/parse/properties/utils.h b/src/parse/properties/utils.h
index e4c97c7..e5331d2 100644
--- a/src/parse/properties/utils.h
+++ b/src/parse/properties/utils.h
@@ -199,4 +199,28 @@ css_error css__comma_list_to_style(css_language *c,
bool first),
css_style *result);
+/**
+ * Parse a CSS calc() invocation
+ *
+ * Calc can generate a number of kinds of units, so we have to tell the
+ * parser the kind of unit we're aiming for (e.g. UNIT_PX, UNIT_ANGLE, etc.)
+ *
+ * \param[in] c Parsing context
+ * \param[in] vector Vector of tokens to process
+ * \param[in] ctx Pointer to vector iteration context
+ * \param[in] result Pointer to location to receive resulting style
+ * \param[in] property The CSS property we are calculating for
+ * \param[in] unit The kind of unit which we want to come out of this calc()
+ * \return CSS_OK on success,
+ * CSS_NOMEM on memory exhaustion,
+ CSS_INVALID if the input is not valid
+ *
+ * Post condition: \a *ctx is updated with the next token to process
+ * If the input is invalid, then \a *ctx remains unchanged.
+ */
+css_error css__parse_calc(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ css_code_t property,
+ uint32_t unit);
#endif
diff --git a/src/parse/propstrings.c b/src/parse/propstrings.c
index 7d723e1..b102be9 100644
--- a/src/parse/propstrings.c
+++ b/src/parse/propstrings.c
@@ -484,6 +484,7 @@ const stringmap_entry stringmap[LAST_KNOWN] = {
SMAP("or"),
SMAP("only"),
SMAP("infinite"),
+ SMAP("calc"),
SMAP("aliceblue"),
SMAP("antiquewhite"),
diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h
index fd24a47..a098202 100644
--- a/src/parse/propstrings.h
+++ b/src/parse/propstrings.h
@@ -108,7 +108,7 @@ enum {
AVOID_PAGE, AVOID_COLUMN, BALANCE, HORIZONTAL_TB, VERTICAL_RL,
VERTICAL_LR, CONTENT_BOX, BORDER_BOX, STRETCH, INLINE_FLEX, FLEX_START,
FLEX_END, SPACE_BETWEEN, SPACE_AROUND, SPACE_EVENLY, ROW, ROW_REVERSE,
- COLUMN_REVERSE, WRAP_STRING, WRAP_REVERSE, AND, OR, ONLY, INFINITE,
+ COLUMN_REVERSE, WRAP_STRING, WRAP_REVERSE, AND, OR, ONLY, INFINITE, CALC,
/* Named colours */
FIRST_COLOUR,
-----------------------------------------------------------------------
Summary of changes:
--
Cascading Style Sheets library
2 years
netsurf: branch master updated. release/3.10-139-gfa64d91
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/fa64d91d12c94c9aa230c...
...commit http://git.netsurf-browser.org/netsurf.git/commit/fa64d91d12c94c9aa230cd2...
...tree http://git.netsurf-browser.org/netsurf.git/tree/fa64d91d12c94c9aa230cd231...
The branch, master has been updated
via fa64d91d12c94c9aa230cd231b1d2e16054b41f2 (commit)
via 638a408ddee7329f8de2a6e550b7fcc2a4baa4a3 (commit)
from a6e825833d5ad2f79ed12aedbcb75773de52ca43 (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=fa64d91d12c94c9aa23...
commit fa64d91d12c94c9aa230cd231b1d2e16054b41f2
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Switch to new libcss API for unit conversion.
diff --git a/content/handlers/css/Makefile b/content/handlers/css/Makefile
index bbfc8d7..d5cf166 100644
--- a/content/handlers/css/Makefile
+++ b/content/handlers/css/Makefile
@@ -1,4 +1,4 @@
# CSS sources
-S_CSS := css.c dump.c internal.c hints.c select.c utils.c
+S_CSS := css.c dump.c internal.c hints.c select.c
diff --git a/content/handlers/css/css.c b/content/handlers/css/css.c
index be945fb..f9197dd 100644
--- a/content/handlers/css/css.c
+++ b/content/handlers/css/css.c
@@ -40,6 +40,9 @@
/* Define to trace import fetches */
#undef NSCSS_IMPORT_TRACE
+/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
+css_fixed nscss_screen_dpi = F_90;
+
struct content_css_data;
/**
diff --git a/content/handlers/css/select.c b/content/handlers/css/select.c
index cfefb2a..6dc1d9b 100644
--- a/content/handlers/css/select.c
+++ b/content/handlers/css/select.c
@@ -91,10 +91,6 @@ static css_error set_libcss_node_data(void *pw, void *node,
static css_error get_libcss_node_data(void *pw, void *node,
void **libcss_node_data);
-static css_error nscss_compute_font_size(void *pw, const css_hint *parent,
- css_hint *size);
-
-
/**
* Selection callback table for libcss
*/
@@ -135,9 +131,8 @@ static css_select_handler selection_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
- nscss_compute_font_size,
set_libcss_node_data,
- get_libcss_node_data
+ get_libcss_node_data,
};
/**
@@ -250,12 +245,15 @@ static void nscss_dom_user_data_handler(dom_node_operation operation,
* \param ctx CSS selection context
* \param n Element to select for
* \param media Permitted media types
+ * \param unit_unit_len_ctx Unit length conversion context
* \param inline_style Inline style associated with element, or NULL
* \return Pointer to selection results (containing computed styles),
* or NULL on failure
*/
css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
- const css_media *media, const css_stylesheet *inline_style)
+ const css_media *media,
+ const css_unit_ctx *unit_len_ctx,
+ const css_stylesheet *inline_style)
{
css_computed_style *composed;
css_select_results *styles;
@@ -263,7 +261,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
css_error error;
/* Select style for node */
- error = css_select_style(ctx->ctx, n, media, inline_style,
+ error = css_select_style(ctx->ctx, n, unit_len_ctx, media, inline_style,
&selection_handler, ctx, &styles);
if (error != CSS_OK || styles == NULL) {
@@ -278,8 +276,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
* element's style */
error = css_computed_style_compose(ctx->parent_style,
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
- nscss_compute_font_size, ctx,
- &composed);
+ unit_len_ctx, &composed);
if (error != CSS_OK) {
css_select_results_destroy(styles);
return NULL;
@@ -310,8 +307,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
error = css_computed_style_compose(
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
styles->styles[pseudo_element],
- nscss_compute_font_size, ctx,
- &composed);
+ unit_len_ctx, &composed);
if (error != CSS_OK) {
/* TODO: perhaps this shouldn't be quite so
* catastrophic? */
@@ -330,11 +326,13 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
/**
* Get a blank style
*
- * \param ctx CSS selection context
- * \param parent Parent style to cascade inherited properties from
+ * \param ctx CSS selection context
+ * \param unit_unit_len_ctx Unit length conversion context
+ * \param parent Parent style to cascade inherited properties from
* \return Pointer to blank style, or NULL on failure
*/
css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *parent)
{
css_computed_style *partial, *composed;
@@ -349,7 +347,7 @@ css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
/* TODO: Do we really need to compose? Initial style shouldn't
* have any inherited properties. */
error = css_computed_style_compose(parent, partial,
- nscss_compute_font_size, ctx, &composed);
+ unit_len_ctx, &composed);
css_computed_style_destroy(partial);
if (error != CSS_OK) {
css_computed_style_destroy(composed);
@@ -359,115 +357,6 @@ css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
return composed;
}
-/**
- * Font size computation callback for libcss
- *
- * \param pw Computation context
- * \param parent Parent font size (absolute)
- * \param size Font size to compute
- * \return CSS_OK on success
- *
- * \post \a size will be an absolute font size
- */
-css_error nscss_compute_font_size(void *pw, const css_hint *parent,
- css_hint *size)
-{
- /**
- * Table of font-size keyword scale factors
- *
- * These are multiplied by the configured default font size
- * to produce an absolute size for the relevant keyword
- */
- static const css_fixed factors[] = {
- FLTTOFIX(0.5625), /* xx-small */
- FLTTOFIX(0.6250), /* x-small */
- FLTTOFIX(0.8125), /* small */
- FLTTOFIX(1.0000), /* medium */
- FLTTOFIX(1.1250), /* large */
- FLTTOFIX(1.5000), /* x-large */
- FLTTOFIX(2.0000) /* xx-large */
- };
- css_hint_length parent_size;
-
- /* Grab parent size, defaulting to medium if none */
- if (parent == NULL) {
- parent_size.value = FDIV(FMUL(factors[CSS_FONT_SIZE_MEDIUM - 1],
- INTTOFIX(nsoption_int(font_size))),
- INTTOFIX(10));
- parent_size.unit = CSS_UNIT_PT;
- } else {
- assert(parent->status == CSS_FONT_SIZE_DIMENSION);
- assert(parent->data.length.unit != CSS_UNIT_EM);
- assert(parent->data.length.unit != CSS_UNIT_EX);
- assert(parent->data.length.unit != CSS_UNIT_PCT);
-
- parent_size = parent->data.length;
- }
-
- assert(size->status != CSS_FONT_SIZE_INHERIT);
-
- if (size->status < CSS_FONT_SIZE_LARGER) {
- /* Keyword -- simple */
- size->data.length.value = FDIV(FMUL(factors[size->status - 1],
- INTTOFIX(nsoption_int(font_size))), F_10);
- size->data.length.unit = CSS_UNIT_PT;
- } else if (size->status == CSS_FONT_SIZE_LARGER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size.value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size.unit;
- } else if (size->status == CSS_FONT_SIZE_SMALLER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FDIV(parent_size.value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size.unit;
- } else if (size->data.length.unit == CSS_UNIT_EM ||
- size->data.length.unit == CSS_UNIT_EX ||
- size->data.length.unit == CSS_UNIT_CH) {
- size->data.length.value =
- FMUL(size->data.length.value, parent_size.value);
-
- switch (size->data.length.unit) {
- case CSS_UNIT_EX:
- /* 1ex = 0.6em in NetSurf */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.6));
- break;
- case CSS_UNIT_CH:
- /* Width of '0'. 1ch = 0.4em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.4));
- break;
- default:
- /* No scaling required for EM. */
- break;
- }
-
- size->data.length.unit = parent_size.unit;
- } else if (size->data.length.unit == CSS_UNIT_PCT) {
- size->data.length.value = FDIV(FMUL(size->data.length.value,
- parent_size.value), INTTOFIX(100));
- size->data.length.unit = parent_size.unit;
- } else if (size->data.length.unit == CSS_UNIT_REM) {
- nscss_select_ctx *ctx = pw;
- if (parent == NULL) {
- size->data.length.value = parent_size.value;
- size->data.length.unit = parent_size.unit;
- } else {
- css_computed_font_size(ctx->root_style,
- &parent_size.value,
- &size->data.length.unit);
- size->data.length.value = FMUL(
- size->data.length.value,
- parent_size.value);
- }
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
/******************************************************************************
* Style selection callbacks *
******************************************************************************/
diff --git a/content/handlers/css/select.h b/content/handlers/css/select.h
index b45d1ed..c17caad 100644
--- a/content/handlers/css/select.h
+++ b/content/handlers/css/select.h
@@ -45,9 +45,12 @@ css_stylesheet *nscss_create_inline_style(const uint8_t *data, size_t len,
const char *charset, const char *url, bool allow_quirks);
css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
- const css_media *media, const css_stylesheet *inline_style);
+ const css_media *media,
+ const css_unit_ctx *unit_len_ctx,
+ const css_stylesheet *inline_style);
css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *parent);
diff --git a/content/handlers/css/utils.c b/content/handlers/css/utils.c
deleted file mode 100644
index 24ba443..0000000
--- a/content/handlers/css/utils.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Copyright 2004 James Bursa <james(a)netsurf-browser.org>
- * Copyright 2009 John-Mark Bell <jmb(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/>.
- */
-
-#include <assert.h>
-
-#include "utils/nsoption.h"
-#include "utils/log.h"
-
-#include "css/utils.h"
-
-/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
-css_fixed nscss_screen_dpi = F_90;
-
-/** Medium screen density for device viewing distance. */
-css_fixed nscss_baseline_pixel_density = F_96;
-
-/**
- * Map viewport-relative length units to either vh or vw.
- *
- * Non-viewport-relative units are unchanged.
- *
- * \param[in] ctx Length conversion context.
- * \param[in] unit Unit to map.
- * \return the mapped unit.
- */
-static inline css_unit css_utils__fudge_viewport_units(
- const nscss_len_ctx *ctx,
- css_unit unit)
-{
- switch (unit) {
- case CSS_UNIT_VI:
- assert(ctx->root_style != NULL);
- if (css_computed_writing_mode(ctx->root_style) ==
- CSS_WRITING_MODE_HORIZONTAL_TB) {
- unit = CSS_UNIT_VW;
- } else {
- unit = CSS_UNIT_VH;
- }
- break;
- case CSS_UNIT_VB:
- assert(ctx->root_style != NULL);
- if (css_computed_writing_mode(ctx->root_style) ==
- CSS_WRITING_MODE_HORIZONTAL_TB) {
- unit = CSS_UNIT_VH;
- } else {
- unit = CSS_UNIT_VW;
- }
- break;
- case CSS_UNIT_VMIN:
- if (ctx->vh < ctx->vw) {
- unit = CSS_UNIT_VH;
- } else {
- unit = CSS_UNIT_VW;
- }
- break;
- case CSS_UNIT_VMAX:
- if (ctx->vh > ctx->vw) {
- unit = CSS_UNIT_VH;
- } else {
- unit = CSS_UNIT_VW;
- }
- break;
- default: break;
- }
-
- return unit;
-}
-
-/* exported interface documented in content/handlers/css/utils.h */
-css_fixed nscss_len2pt(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit)
-{
- /* Length must not be relative */
- assert(unit != CSS_UNIT_EM &&
- unit != CSS_UNIT_EX &&
- unit != CSS_UNIT_CH &&
- unit != CSS_UNIT_REM);
-
- unit = css_utils__fudge_viewport_units(ctx, unit);
-
- switch (unit) {
- /* We assume the screen and any other output has the same dpi */
- /* 1in = DPIpx => 1px = (72/DPI)pt */
- case CSS_UNIT_PX: return FDIV(FMUL(length, F_72), F_96);
- /* 1in = 72pt */
- case CSS_UNIT_IN: return FMUL(length, F_72);
- /* 1in = 2.54cm => 1cm = (72/2.54)pt */
- case CSS_UNIT_CM: return FMUL(length,
- FDIV(F_72, FLTTOFIX(2.54)));
- /* 1in = 25.4mm => 1mm = (72/25.4)pt */
- case CSS_UNIT_MM: return FMUL(length,
- FDIV(F_72, FLTTOFIX(25.4)));
- /* 1in = 101.6q => 1mm = (72/101.6)pt */
- case CSS_UNIT_Q: return FMUL(length,
- FDIV(F_72, FLTTOFIX(101.6)));
- case CSS_UNIT_PT: return length;
- /* 1pc = 12pt */
- case CSS_UNIT_PC: return FMUL(length, INTTOFIX(12));
- case CSS_UNIT_VH: return FDIV(FMUL(FDIV(FMUL(length, ctx->vh), F_100), F_72), F_96);
- case CSS_UNIT_VW: return FDIV(FMUL(FDIV(FMUL(length,ctx->vw), F_100), F_72), F_96);
- default: break;
- }
-
- return 0;
-}
-
-/* exported interface documented in content/handlers/css/utils.h */
-css_fixed nscss_len2px(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit,
- const css_computed_style *style)
-{
- /* We assume the screen and any other output has the same dpi */
- css_fixed px_per_unit;
-
- unit = css_utils__fudge_viewport_units(ctx, unit);
-
- switch (unit) {
- case CSS_UNIT_EM:
- case CSS_UNIT_EX:
- case CSS_UNIT_CH:
- {
- css_fixed font_size = 0;
- css_unit font_unit = CSS_UNIT_PT;
-
- assert(style != NULL);
-
- css_computed_font_size(style, &font_size, &font_unit);
-
- /* Convert to points */
- font_size = nscss_len2pt(ctx, font_size, font_unit);
-
- /* Clamp to configured minimum */
- if (font_size < FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)) {
- font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10);
- }
-
- /* Convert to pixels (manually, to maximise precision)
- * 1in = 72pt => 1pt = (DPI/72)px */
- px_per_unit = FDIV(FMUL(font_size, F_96), F_72);
-
- /* Scale non-em units to em. We have fixed ratios. */
- switch (unit) {
- case CSS_UNIT_EX:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
- break;
- case CSS_UNIT_CH:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
- break;
- default: break;
- }
- }
- break;
- case CSS_UNIT_PX:
- px_per_unit = F_1;
- break;
- /* 1in = 96 CSS pixels */
- case CSS_UNIT_IN:
- px_per_unit = F_96;
- break;
- /* 1in = 2.54cm => 1cm = (DPI/2.54)px */
- case CSS_UNIT_CM:
- px_per_unit = FDIV(F_96, FLTTOFIX(2.54));
- break;
- /* 1in = 25.4mm => 1mm = (DPI/25.4)px */
- case CSS_UNIT_MM:
- px_per_unit = FDIV(F_96, FLTTOFIX(25.4));
- break;
- /* 1in = 101.6q => 1q = (DPI/101.6)px */
- case CSS_UNIT_Q:
- px_per_unit = FDIV(F_96, FLTTOFIX(101.6));
- break;
- /* 1in = 72pt => 1pt = (DPI/72)px */
- case CSS_UNIT_PT:
- px_per_unit = FDIV(F_96, F_72);
- break;
- /* 1pc = 12pt => 1in = 6pc => 1pc = (DPI/6)px */
- case CSS_UNIT_PC:
- px_per_unit = FDIV(F_96, INTTOFIX(6));
- break;
- case CSS_UNIT_REM:
- {
- css_fixed font_size = 0;
- css_unit font_unit = CSS_UNIT_PT;
-
- assert(ctx->root_style != NULL);
-
- css_computed_font_size(ctx->root_style,
- &font_size, &font_unit);
-
- /* Convert to points */
- font_size = nscss_len2pt(ctx, font_size, font_unit);
-
- /* Clamp to configured minimum */
- if (font_size < FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)) {
- font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10);
- }
-
- /* Convert to pixels (manually, to maximise precision)
- * 1in = 72pt => 1pt = (DPI/72)px */
- px_per_unit = FDIV(FMUL(font_size, F_96), F_72);
- break;
- }
- case CSS_UNIT_VH:
- px_per_unit = FDIV(ctx->vh, F_100);
- break;
- case CSS_UNIT_VW:
- px_per_unit = FDIV(ctx->vw, F_100);
- break;
- default:
- px_per_unit = 0;
- break;
- }
-
- px_per_unit = nscss_pixels_css_to_physical(px_per_unit);
-
- /* Ensure we round px_per_unit to the nearest whole number of pixels:
- * the use of FIXTOINT() below will truncate. */
- px_per_unit += F_0_5;
-
- /* Calculate total number of pixels */
- return FMUL(length, TRUNCATEFIX(px_per_unit));
-}
diff --git a/content/handlers/css/utils.h b/content/handlers/css/utils.h
index e35a660..541677a 100644
--- a/content/handlers/css/utils.h
+++ b/content/handlers/css/utils.h
@@ -26,85 +26,6 @@
/** DPI of the screen, in fixed point units */
extern css_fixed nscss_screen_dpi;
-/** Medium screen density for device viewing distance. */
-extern css_fixed nscss_baseline_pixel_density;
-
-/**
- * Length conversion context data.
- */
-typedef struct nscss_len_ctx {
- /**
- * Viewport width in px.
- * Only used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- int vw;
- /**
- * Viewport height in px.
- * Only used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- int vh;
- /**
- * Computed style for the document root element.
- * May be NULL if unit is not rem, or rlh.
- */
- const css_computed_style *root_style;
-} nscss_len_ctx;
-
-/**
- * Convert an absolute CSS length to points.
- *
- * \param[in] ctx Length conversion context.
- * \param[in] length Absolute CSS length.
- * \param[in] unit Unit of the length.
- * \return length in points
- */
-css_fixed nscss_len2pt(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit);
-
-/**
- * Convert a CSS length to pixels.
- *
- * \param[in] ctx Length conversion context.
- * \param[in] length Length to convert.
- * \param[in] unit Corresponding unit.
- * \param[in] style Computed style applying to length.
- * May be NULL if unit is not em, ex, cap, ch, or ic.
- * \return length in pixels
- */
-css_fixed nscss_len2px(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit,
- const css_computed_style *style);
-
-/**
- * Convert css pixels to physical pixels.
- *
- * \param[in] css_pixels Length in css pixels.
- * \return length in physical pixels
- */
-static inline css_fixed nscss_pixels_css_to_physical(
- css_fixed css_pixels)
-{
- return FDIV(FMUL(css_pixels, nscss_screen_dpi),
- nscss_baseline_pixel_density);
-}
-
-/**
- * Convert physical pixels to css pixels.
- *
- * \param[in] physical_pixels Length in physical pixels.
- * \return length in css pixels
- */
-static inline css_fixed nscss_pixels_physical_to_css(
- css_fixed physical_pixels)
-{
- return FDIV(FMUL(physical_pixels, nscss_baseline_pixel_density),
- nscss_screen_dpi);
-}
-
/**
* Temporary helper wrappers for for libcss computed style getter, while
* we don't support flexbox related property values.
diff --git a/content/handlers/html/box_construct.c b/content/handlers/html/box_construct.c
index 7bfc35e..12d9df8 100644
--- a/content/handlers/html/box_construct.c
+++ b/content/handlers/html/box_construct.c
@@ -282,7 +282,8 @@ box_get_style(html_content *c,
ctx.parent_style = parent_style;
/* Select style for element */
- styles = nscss_get_style(&ctx, n, &c->media, inline_style);
+ styles = nscss_get_style(&ctx, n, &c->media, &c->unit_len_ctx,
+ inline_style);
/* No longer need inline style */
if (inline_style != NULL)
diff --git a/content/handlers/html/box_inspect.c b/content/handlers/html/box_inspect.c
index df9a1b4..b4b1394 100644
--- a/content/handlers/html/box_inspect.c
+++ b/content/handlers/html/box_inspect.c
@@ -56,7 +56,7 @@ enum box_walk_dir {
/**
* Determine if a point lies within a box.
*
- * \param[in] len_ctx CSS length conversion context to use.
+ * \param[in] unit_len_ctx CSS length conversion context to use.
* \param[in] box Box to consider
* \param[in] x Coordinate relative to box
* \param[in] y Coordinate relative to box
@@ -71,7 +71,7 @@ enum box_walk_dir {
* This is a helper function for box_at_point().
*/
static bool
-box_contains_point(const nscss_len_ctx *len_ctx,
+box_contains_point(const css_unit_ctx *unit_len_ctx,
const struct box *box,
int x,
int y,
@@ -101,30 +101,34 @@ box_contains_point(const nscss_len_ctx *len_ctx,
/* Adjust rect to css clip region */
if (css_rect.left_auto == false) {
- r.x0 += FIXTOINT(nscss_len2px(len_ctx,
- css_rect.left,
- css_rect.lunit,
- box->style));
+ r.x0 += FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.left,
+ css_rect.lunit));
}
if (css_rect.top_auto == false) {
- r.y0 += FIXTOINT(nscss_len2px(len_ctx,
- css_rect.top,
- css_rect.tunit,
- box->style));
+ r.y0 += FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.top,
+ css_rect.tunit));
}
if (css_rect.right_auto == false) {
r.x1 = box->border[LEFT].width +
- FIXTOINT(nscss_len2px(len_ctx,
- css_rect.right,
- css_rect.runit,
- box->style));
+ FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.right,
+ css_rect.runit));
}
if (css_rect.bottom_auto == false) {
r.y1 = box->border[TOP].width +
- FIXTOINT(nscss_len2px(len_ctx,
- css_rect.bottom,
- css_rect.bunit,
- box->style));
+ FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.bottom,
+ css_rect.bunit));
}
/* Test if point is in clipped box */
@@ -575,7 +579,7 @@ void box_bounds(struct box *box, struct rect *r)
/* Exported function documented in html/box.h */
struct box *
-box_at_point(const nscss_len_ctx *len_ctx,
+box_at_point(const css_unit_ctx *unit_len_ctx,
struct box *box,
const int x, const int y,
int *box_x, int *box_y)
@@ -587,7 +591,7 @@ box_at_point(const nscss_len_ctx *len_ctx,
skip_children = false;
while ((box = box_next_xy(box, box_x, box_y, skip_children))) {
- if (box_contains_point(len_ctx, box, x - *box_x, y - *box_y,
+ if (box_contains_point(unit_len_ctx, box, x - *box_x, y - *box_y,
&physically)) {
*box_x -= scrollbar_get_offset(box->scroll_x);
*box_y -= scrollbar_get_offset(box->scroll_y);
diff --git a/content/handlers/html/box_inspect.h b/content/handlers/html/box_inspect.h
index d50b848..b9161f1 100644
--- a/content/handlers/html/box_inspect.h
+++ b/content/handlers/html/box_inspect.h
@@ -46,7 +46,7 @@ void box_bounds(struct box *box, struct rect *r);
/**
* Find the boxes at a point.
*
- * \param len_ctx CSS length conversion context for document.
+ * \param unit_len_ctx CSS length conversion context for document.
* \param box box to search children of
* \param x point to find, in global document coordinates
* \param y point to find, in global document coordinates
@@ -62,12 +62,12 @@ void box_bounds(struct box *box, struct rect *r);
* struct box *box = top_of_document_to_search;
* int box_x = 0, box_y = 0;
*
- * while ((box = box_at_point(len_ctx, box, x, y, &box_x, &box_y))) {
+ * while ((box = box_at_point(unit_len_ctx, box, x, y, &box_x, &box_y))) {
* // process box
* }
* \endcode
*/
-struct box *box_at_point(const nscss_len_ctx *len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
+struct box *box_at_point(const css_unit_ctx *unit_len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
/**
diff --git a/content/handlers/html/box_normalise.c b/content/handlers/html/box_normalise.c
index b7032da..1b6a345 100644
--- a/content/handlers/html/box_normalise.c
+++ b/content/handlers/html/box_normalise.c
@@ -190,7 +190,8 @@ box_normalise_table_row(struct box *row,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, row->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row->style);
if (style == NULL)
return false;
@@ -326,7 +327,8 @@ box_normalise_table_row_group(struct box *row_group,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, row_group->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row_group->style);
if (style == NULL)
return false;
@@ -402,7 +404,8 @@ box_normalise_table_row_group(struct box *row_group,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, row_group->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row_group->style);
if (style == NULL) {
return false;
}
@@ -533,6 +536,7 @@ box_normalise_table_spans(struct box *table,
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx,
+ &c->unit_len_ctx,
table_row->style);
if (style == NULL)
return false;
@@ -657,7 +661,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, table->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ table->style);
if (style == NULL) {
free(col_info.spans);
return false;
@@ -744,7 +749,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, table->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ table->style);
if (style == NULL) {
free(col_info.spans);
return false;
@@ -759,7 +765,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
}
row_group->type = BOX_TABLE_ROW_GROUP;
- style = nscss_get_blank_style(&ctx, row_group->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row_group->style);
if (style == NULL) {
box_free(row_group);
free(col_info.spans);
@@ -948,7 +955,8 @@ box_normalise_block(struct box *block, const struct box *root, html_content *c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, block->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ block->style);
if (style == NULL)
return false;
diff --git a/content/handlers/html/font.c b/content/handlers/html/font.c
index 7ebe168..4a64759 100644
--- a/content/handlers/html/font.c
+++ b/content/handlers/html/font.c
@@ -133,7 +133,7 @@ static plot_font_flags_t plot_font_flags(enum css_font_style_e style,
/* exported function documented in html/font.h */
void font_plot_style_from_css(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *css,
plot_font_style_t *fstyle)
{
@@ -147,7 +147,8 @@ void font_plot_style_from_css(
fstyle->families = families;
css_computed_font_size(css, &length, &unit);
- fstyle->size = FIXTOINT(FMUL(nscss_len2pt(len_ctx, length, unit),
+ fstyle->size = FIXTOINT(FMUL(css_unit_font_size_len2pt(css,
+ unit_len_ctx, length, unit),
INTTOFIX(PLOT_STYLE_SCALE)));
/* Clamp font size to configured minimum */
diff --git a/content/handlers/html/font.h b/content/handlers/html/font.h
index 5f69ee7..26f5bf2 100644
--- a/content/handlers/html/font.h
+++ b/content/handlers/html/font.h
@@ -32,11 +32,11 @@ struct plot_font_style;
/**
* Populate a font style using data from a computed CSS style
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param css Computed style to consider
* \param fstyle Font style to populate
*/
-void font_plot_style_from_css(const nscss_len_ctx *len_ctx,
+void font_plot_style_from_css(const css_unit_ctx *unit_len_ctx,
const css_computed_style *css,
struct plot_font_style *fstyle);
diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c
index 01e6244..97ec195 100644
--- a/content/handlers/html/form.c
+++ b/content/handlers/html/form.c
@@ -1594,12 +1594,12 @@ form_open_select_menu(void *client_data,
box->border[RIGHT].width + box->padding[RIGHT] +
box->border[LEFT].width + box->padding[LEFT];
- font_plot_style_from_css(&html->len_ctx, control->box->style,
- &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx,
+ control->box->style, &fstyle);
menu->f_size = fstyle.size;
menu->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2),
- FMUL(nscss_screen_dpi,
+ FMUL(html->unit_len_ctx.device_dpi,
INTTOFIX(fstyle.size / PLOT_STYLE_SCALE)))),
F_72));
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index 5b74e42..c6a2872 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -305,6 +305,9 @@ html_proceed_to_done(html_content *html)
static void html_get_dimensions(html_content *htmlc)
{
+ css_fixed device_dpi = nscss_screen_dpi;
+ unsigned f_size;
+ unsigned f_min;
unsigned w;
unsigned h;
union content_msg_data msg_data = {
@@ -316,13 +319,22 @@ static void html_get_dimensions(html_content *htmlc)
content_broadcast(&htmlc->base, CONTENT_MSG_GETDIMS, &msg_data);
- htmlc->media.width = nscss_pixels_physical_to_css(INTTOFIX(w));
- htmlc->media.height = nscss_pixels_physical_to_css(INTTOFIX(h));
- htmlc->media.client_font_size =
- FDIV(INTTOFIX(nsoption_int(font_size)), F_10);
- htmlc->media.client_line_height =
- FMUL(nscss_len2px(NULL, htmlc->media.client_font_size,
- CSS_UNIT_PT, NULL), FLTTOFIX(1.33));
+
+ w = css_unit_device2css_px(INTTOFIX(w), device_dpi);
+ h = css_unit_device2css_px(INTTOFIX(h), device_dpi);
+
+ htmlc->media.width = w;
+ htmlc->media.height = h;
+ htmlc->unit_len_ctx.viewport_width = w;
+ htmlc->unit_len_ctx.viewport_height = h;
+ htmlc->unit_len_ctx.device_dpi = device_dpi;
+
+ /** \todo Change nsoption font sizes to px. */
+ f_size = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_size)), F_10)), F_72);
+ f_min = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)), F_72);
+
+ htmlc->unit_len_ctx.font_size_default = f_size;
+ htmlc->unit_len_ctx.font_size_minimum = f_min;
}
/* exported function documented in html/html_internal.h */
@@ -1035,9 +1047,11 @@ static void html_reformat(struct content *c, int width, int height)
htmlc->reflowing = true;
- htmlc->len_ctx.vw = nscss_pixels_physical_to_css(INTTOFIX(width));
- htmlc->len_ctx.vh = nscss_pixels_physical_to_css(INTTOFIX(height));
- htmlc->len_ctx.root_style = htmlc->layout->style;
+ htmlc->unit_len_ctx.viewport_width = css_unit_device2css_px(
+ INTTOFIX(width), htmlc->unit_len_ctx.device_dpi);
+ htmlc->unit_len_ctx.viewport_height = css_unit_device2css_px(
+ INTTOFIX(height), htmlc->unit_len_ctx.device_dpi);
+ htmlc->unit_len_ctx.root_style = htmlc->layout->style;
layout_document(htmlc, width, height);
layout = htmlc->layout;
@@ -1427,7 +1441,7 @@ html_get_contextual_content(struct content *c, int x, int y,
struct box *next;
int box_x = 0, box_y = 0;
- while ((next = box_at_point(&html->len_ctx, box, x, y,
+ while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
@@ -1508,7 +1522,7 @@ html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
/* TODO: invert order; visit deepest box first */
- while ((next = box_at_point(&html->len_ctx, box, x, y,
+ while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
@@ -1657,7 +1671,7 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
int box_x = 0, box_y = 0;
/* Scan box tree for boxes that can handle drop */
- while ((next = box_at_point(&html->len_ctx, box, x, y,
+ while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
diff --git a/content/handlers/html/interaction.c b/content/handlers/html/interaction.c
index 90e7b76..026ef1e 100644
--- a/content/handlers/html/interaction.c
+++ b/content/handlers/html/interaction.c
@@ -211,7 +211,7 @@ static size_t html_selection_drag_end(struct html_content *html,
if (box) {
plot_font_style_t fstyle;
- font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
guit->layout->position(&fstyle, box->text, box->length,
dx, &idx, &pixel_offset);
@@ -424,7 +424,7 @@ mouse_action_drag_selection(html_content *html,
box = box_pick_text_box(html, x, y, dir, &dx, &dy);
if (box != NULL) {
- font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
guit->layout->position(&fstyle,
box->text,
@@ -805,7 +805,7 @@ get_mouse_action_node(html_content *html,
next_box:
/* iterate to next box */
- box = box_at_point(&html->len_ctx, box, x, y, &box_x, &box_y);
+ box = box_at_point(&html->unit_len_ctx, box, x, y, &box_x, &box_y);
} while (box != NULL);
/* use of box_x, box_y, or content below this point is probably a
@@ -1209,7 +1209,7 @@ default_mouse_action(html_content *html,
size_t idx;
plot_font_style_t fstyle;
- font_plot_style_from_css(&html->len_ctx,
+ font_plot_style_from_css(&html->unit_len_ctx,
mas->text.box->style,
&fstyle);
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index c8c0127..c06fdf6 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -133,7 +133,6 @@ static void layout_minmax_block(
const struct gui_layout_table *font_func,
const html_content *content);
-
/**
* Compute the size of replaced boxes with auto dimensions, according to
* content.
@@ -246,7 +245,7 @@ layout_get_object_dimensions(struct box *box,
* \return length of indent
*/
static int layout_text_indent(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *style, int width)
{
css_fixed value = 0;
@@ -257,7 +256,8 @@ static int layout_text_indent(
if (unit == CSS_UNIT_PCT) {
return FPCT_OF_INT_TOINT(value, width);
} else {
- return FIXTOINT(nscss_len2px(len_ctx, value, unit, style));
+ return FIXTOINT(css_unit_len2device_px(style, unit_len_ctx,
+ value, unit));
}
}
@@ -265,7 +265,7 @@ static int layout_text_indent(
/**
* Determine width of margin, borders, and padding on one side of a box.
*
- * \param len_ctx CSS length conversion context for document
+ * \param unit_len_ctx CSS length conversion context for document
* \param style style to measure
* \param side side of box to measure
* \param margin whether margin width is required
@@ -275,7 +275,7 @@ static int layout_text_indent(
* \param frac increased by sum of fractional margin and padding
*/
static void
-calculate_mbp_width(const nscss_len_ctx *len_ctx,
+calculate_mbp_width(const css_unit_ctx *unit_len_ctx,
const css_computed_style *style,
unsigned int side,
bool margin,
@@ -298,8 +298,9 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
if (unit == CSS_UNIT_PCT) {
*frac += FIXTOINT(FDIV(value, F_100));
} else {
- *fixed += FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *fixed += FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
}
@@ -310,8 +311,9 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
CSS_BORDER_STYLE_NONE) {
border_width_funcs[side](style, &value, &unit);
- *fixed += FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *fixed += FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
@@ -321,8 +323,9 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
if (unit == CSS_UNIT_PCT) {
*frac += FIXTOINT(FDIV(value, F_100));
} else {
- *fixed += FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *fixed += FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
}
@@ -356,7 +359,7 @@ static void layout_minmax_table(struct box *table,
if (table->max_width != UNKNOWN_MAX_WIDTH)
return;
- if (table_calculate_column_types(&content->len_ctx, table) == false) {
+ if (table_calculate_column_types(&content->unit_len_ctx, table) == false) {
NSLOG(netsurf, WARNING,
"Could not establish table column types.");
return;
@@ -379,8 +382,10 @@ static void layout_minmax_table(struct box *table,
css_computed_border_spacing(table->style, &h, &hu, &v, &vu);
- border_spacing_h = FIXTOINT(nscss_len2px(&content->len_ctx,
- h, hu, table->style));
+ border_spacing_h = FIXTOINT(css_unit_len2device_px(
+ table->style,
+ &content->unit_len_ctx,
+ h, hu));
}
/* 1st pass: consider cells with colspan 1 only */
@@ -485,8 +490,10 @@ static void layout_minmax_table(struct box *table,
/* fixed width takes priority, unless it is too narrow */
wtype = css_computed_width(table->style, &value, &unit);
if (wtype == CSS_WIDTH_SET && unit != CSS_UNIT_PCT) {
- int width = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, table->style));
+ int width = FIXTOINT(css_unit_len2device_px(
+ table->style,
+ &content->unit_len_ctx,
+ value, unit));
if (table_min < width)
table_min = width;
if (table_max < width)
@@ -494,10 +501,10 @@ static void layout_minmax_table(struct box *table,
}
/* add margins, border, padding to min, max widths */
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
table->style, LEFT, true, true, true,
&extra_fixed, &extra_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
table->style, RIGHT, true, true, true,
&extra_fixed, &extra_frac);
if (extra_fixed < 0)
@@ -622,17 +629,17 @@ layout_minmax_line(struct box *first,
}
assert(b->style);
- font_plot_style_from_css(&content->len_ctx, b->style, &fstyle);
+ font_plot_style_from_css(&content->unit_len_ctx, b->style, &fstyle);
if (b->type == BOX_INLINE && !b->object &&
!(b->flags & REPLACE_DIM) &&
!(b->flags & IFRAME)) {
fixed = frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT, true, true, true,
&fixed, &frac);
if (!b->inline_end)
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -642,7 +649,7 @@ layout_minmax_line(struct box *first,
/* \todo update min width, consider fractional extra */
} else if (b->type == BOX_INLINE_END) {
fixed = frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->inline_end->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -760,16 +767,18 @@ layout_minmax_line(struct box *first,
if (unit == CSS_UNIT_PCT) {
width = AUTO;
} else {
- width = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, b->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx,
+ value, unit));
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
fixed = frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT,
false, true, true,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT,
false, true, true,
&fixed, &frac);
@@ -787,8 +796,10 @@ layout_minmax_line(struct box *first,
/* height */
htype = css_computed_height(b->style, &value, &unit);
if (htype == CSS_HEIGHT_SET) {
- height = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, b->style));
+ height = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx,
+ value, unit));
} else {
height = AUTO;
}
@@ -804,20 +815,20 @@ layout_minmax_line(struct box *first,
fixed = frac = 0;
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, false, false,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, false, false,
&fixed, &frac);
} else {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, true, true,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -831,20 +842,20 @@ layout_minmax_line(struct box *first,
fixed = frac = 0;
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, false, false,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, false, false,
&fixed, &frac);
} else {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, true, true,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -856,10 +867,10 @@ layout_minmax_line(struct box *first,
} else {
/* form control with no object */
if (width == AUTO)
- width = FIXTOINT(nscss_len2px(
- &content->len_ctx,
- INTTOFIX(1), CSS_UNIT_EM,
- b->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx,
+ INTTOFIX(1), CSS_UNIT_EM));
}
if (min < width && !box_has_percentage_max_width(b))
@@ -873,7 +884,7 @@ layout_minmax_line(struct box *first,
if (first_line) {
/* todo: handle percentage values properly */
/* todo: handle text-indent interaction with floats */
- int text_indent = layout_text_indent(&content->len_ctx,
+ int text_indent = layout_text_indent(&content->unit_len_ctx,
first->parent->parent->style, 100);
min = (min + text_indent < 0) ? 0 : min + text_indent;
max = (max + text_indent < 0) ? 0 : max + text_indent;
@@ -1006,8 +1017,8 @@ static void layout_minmax_block(
css_fixed size = INTTOFIX(10);
css_unit unit = CSS_UNIT_EM;
- min = max = FIXTOINT(nscss_len2px(&content->len_ctx,
- size, unit, block->style));
+ min = max = FIXTOINT(css_unit_len2device_px(block->style,
+ &content->unit_len_ctx, size, unit));
block->flags |= HAS_HEIGHT;
}
@@ -1020,8 +1031,8 @@ static void layout_minmax_block(
/* form checkbox or radio button
* if width is AUTO, set it to 1em */
- min = max = FIXTOINT(nscss_len2px(&content->len_ctx,
- size, unit, block->style));
+ min = max = FIXTOINT(css_unit_len2device_px(block->style,
+ &content->unit_len_ctx, size, unit));
block->flags |= HAS_HEIGHT;
}
@@ -1104,16 +1115,16 @@ static void layout_minmax_block(
/* fixed width takes priority */
if (block->type != BOX_TABLE_CELL && wtype == CSS_WIDTH_SET &&
wunit != CSS_UNIT_PCT) {
- min = max = FIXTOINT(nscss_len2px(&content->len_ctx,
- width, wunit, block->style));
+ min = max = FIXTOINT(css_unit_len2device_px(block->style,
+ &content->unit_len_ctx, width, wunit));
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
int border_box_fixed = 0;
float border_box_frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT,
false, true, true,
&border_box_fixed, &border_box_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT,
false, true, true,
&border_box_fixed, &border_box_frac);
@@ -1134,17 +1145,17 @@ static void layout_minmax_block(
* and paddings are wrong. */
if (bs == CSS_BOX_SIZING_BORDER_BOX && wtype == CSS_WIDTH_SET) {
/* Border and padding included in width, so just get margin */
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT, true, false, false,
&extra_fixed, &extra_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT, true, false, false,
&extra_fixed, &extra_frac);
} else {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT, true, true, true,
&extra_fixed, &extra_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT, true, true, true,
&extra_fixed, &extra_frac);
}
@@ -1175,7 +1186,7 @@ static void layout_minmax_block(
*
* This turns the specified dimension into a content-box dimension.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box gadget to adjust dimensions of
* \param available_width width of containing block
* \param setwidth set true if the dimension to be tweaked is a width,
@@ -1185,7 +1196,7 @@ static void layout_minmax_block(
* gadget properties.
*/
static void layout_handle_box_sizing(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
int available_width,
bool setwidth,
@@ -1202,10 +1213,10 @@ static void layout_handle_box_sizing(
int fixed = 0;
float frac = 0;
- calculate_mbp_width(len_ctx, box->style,
+ calculate_mbp_width(unit_len_ctx, box->style,
setwidth ? LEFT : TOP,
false, true, true, &fixed, &frac);
- calculate_mbp_width(len_ctx, box->style,
+ calculate_mbp_width(unit_len_ctx, box->style,
setwidth ? RIGHT : BOTTOM,
false, true, true, &fixed, &frac);
orig -= frac * available_width + fixed;
@@ -1217,7 +1228,7 @@ static void layout_handle_box_sizing(
/**
* Calculate width, height, and thickness of margins, paddings, and borders.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param available_width width of containing block
* \param viewport_height height of viewport in pixels or -ve if unknown
* \param box current box
@@ -1234,7 +1245,7 @@ static void layout_handle_box_sizing(
* \param border filled with border widths, may be NULL
*/
static void
-layout_find_dimensions(const nscss_len_ctx *len_ctx,
+layout_find_dimensions(const css_unit_ctx *unit_len_ctx,
int available_width,
int viewport_height,
struct box *box,
@@ -1264,15 +1275,16 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*width = FPCT_OF_INT_TOINT(
value, available_width);
} else {
- *width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
*width = AUTO;
}
if (*width != AUTO) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
true, width);
}
}
@@ -1352,15 +1364,16 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*height = AUTO;
}
} else {
- *height = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *height = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
*height = AUTO;
}
if (*height != AUTO) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
false, height);
}
}
@@ -1377,8 +1390,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*max_width = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- *max_width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *max_width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1386,7 +1400,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
}
if (*max_width != -1) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
true, max_width);
}
}
@@ -1403,8 +1417,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*min_width = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- *min_width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *min_width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1412,7 +1427,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
}
if (*min_width != 0) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
true, min_width);
}
}
@@ -1429,8 +1444,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/* TODO: handle percentage */
*max_height = -1;
} else {
- *max_height = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *max_height = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1450,8 +1466,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/* TODO: handle percentage */
*min_height = 0;
} else {
- *min_height = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *min_height = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1472,9 +1489,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
margin[i] = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- margin[i] = FIXTOINT(nscss_len2px(
- len_ctx,
- value, unit, style));
+ margin[i] = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
margin[i] = AUTO;
@@ -1491,8 +1508,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
padding[i] = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- padding[i] = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ padding[i] = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
@@ -1515,8 +1533,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/* spec unclear: following Mozilla */
border[i].width = 0;
else
- border[i].width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ border[i].width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
/* Special case for border-collapse: make all borders
* on table/table-row-group/table-row zero width. */
@@ -1534,7 +1553,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/**
* Find next block that current margin collapses to.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box to start tree-order search from (top margin is included)
* \param block box responsible for current block fromatting context
* \param viewport_height height of viewport in px
@@ -1543,7 +1562,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
* \return next box that current margin collapses to, or NULL if none.
*/
static struct box*
-layout_next_margin_block(const nscss_len_ctx *len_ctx,
+layout_next_margin_block(const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *block,
int viewport_height,
@@ -1563,7 +1582,7 @@ layout_next_margin_block(const nscss_len_ctx *len_ctx,
/* Get margins */
if (box->style) {
- layout_find_dimensions(len_ctx,
+ layout_find_dimensions(unit_len_ctx,
box->parent->width,
viewport_height, box,
box->style,
@@ -1638,7 +1657,7 @@ layout_next_margin_block(const nscss_len_ctx *len_ctx,
/* Get margins */
if (box->style) {
- layout_find_dimensions(len_ctx,
+ layout_find_dimensions(unit_len_ctx,
box->parent->width,
viewport_height, box,
box->style,
@@ -1875,7 +1894,7 @@ layout_solve_width(struct box *box,
* Compute dimensions of box, margins, paddings, and borders for a block-level
* element.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param available_width Max width available in pixels
* \param viewport_height Height of viewport in pixels or -ve if unknown
* \param lm min left margin required to avoid floats in px.
@@ -1888,7 +1907,7 @@ layout_solve_width(struct box *box,
* See CSS 2.1 10.3.3, 10.3.4, 10.6.2, and 10.6.3.
*/
static void
-layout_block_find_dimensions(const nscss_len_ctx *len_ctx,
+layout_block_find_dimensions(const css_unit_ctx *unit_len_ctx,
int available_width,
int viewport_height,
int lm,
@@ -1902,7 +1921,7 @@ layout_block_find_dimensions(const nscss_len_ctx *len_ctx,
struct box_border *border = box->border;
const css_computed_style *style = box->style;
- layout_find_dimensions(len_ctx, available_width, viewport_height, box,
+ layout_find_dimensions(unit_len_ctx, available_width, viewport_height, box,
style, &width, &height, &max_width, &min_width,
&max_height, &min_height, margin, padding, border);
@@ -2056,7 +2075,7 @@ static bool layout_table(struct box *table, int available_width,
memcpy(col, table->col, sizeof(col[0]) * columns);
/* find margins, paddings, and borders for table and cells */
- layout_find_dimensions(&content->len_ctx, available_width, -1, table,
+ layout_find_dimensions(&content->unit_len_ctx, available_width, -1, table,
style, 0, 0, 0, 0, 0, 0, table->margin, table->padding,
table->border);
for (row_group = table->children; row_group;
@@ -2068,8 +2087,8 @@ static bool layout_table(struct box *table, int available_width,
assert(c->style);
table_used_border_for_cell(
- &content->len_ctx, c);
- layout_find_dimensions(&content->len_ctx,
+ &content->unit_len_ctx, c);
+ layout_find_dimensions(&content->unit_len_ctx,
available_width, -1, c,
c->style, 0, 0, 0, 0, 0, 0,
0, c->padding, c->border);
@@ -2099,10 +2118,10 @@ static bool layout_table(struct box *table, int available_width,
css_computed_border_spacing(style, &h, &hu, &v, &vu);
- border_spacing_h = FIXTOINT(nscss_len2px(&content->len_ctx,
- h, hu, style));
- border_spacing_v = FIXTOINT(nscss_len2px(&content->len_ctx,
- v, vu, style));
+ border_spacing_h = FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx, h, hu));
+ border_spacing_v = FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx, v, vu));
}
/* find specified table width, or available width if auto-width */
@@ -2112,8 +2131,9 @@ static bool layout_table(struct box *table, int available_width,
table_width = FPCT_OF_INT_TOINT(value, available_width);
} else {
table_width =
- FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, style));
+ FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx,
+ value, unit));
}
/* specified width includes border */
@@ -2191,8 +2211,9 @@ static bool layout_table(struct box *table, int available_width,
} else {
/* This is the minimum height for the table
* (see 17.5.3) */
- min_height = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, style));
+ min_height = FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx,
+ value, unit));
}
}
@@ -2382,9 +2403,10 @@ static bool layout_table(struct box *table, int available_width,
htype = css_computed_height(row->style, &value, &unit);
if (htype == CSS_HEIGHT_SET && unit != CSS_UNIT_PCT) {
- row_height = FIXTOINT(nscss_len2px(
- &content->len_ctx,
- value, unit, row->style));
+ row_height = FIXTOINT(css_unit_len2device_px(
+ row->style,
+ &content->unit_len_ctx,
+ value, unit));
}
for (c = row->children; c; c = c->next) {
assert(c->style);
@@ -2421,9 +2443,10 @@ static bool layout_table(struct box *table, int available_width,
/* some sites use height="1" or similar
* to attempt to make cells as small as
* possible, so treat it as a minimum */
- int h = FIXTOINT(nscss_len2px(
- &content->len_ctx,
- value, unit, c->style));
+ int h = FIXTOINT(css_unit_len2device_px(
+ c->style,
+ &content->unit_len_ctx,
+ value, unit));
if (c->height < h)
c->height = h;
}
@@ -2567,14 +2590,14 @@ static bool layout_table(struct box *table, int available_width,
/**
* Manimpulate box height according to CSS min-height and max-height properties
*
- * \param len_ctx CSS length conversion context for document.
+ * \param unit_len_ctx CSS length conversion context for document.
* \param box block to modify with any min-height or max-height
* \param container containing block for absolutely positioned elements, or
* NULL for non absolutely positioned elements.
* \return whether the height has been changed
*/
static bool layout_apply_minmax_height(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *container)
{
@@ -2635,8 +2658,9 @@ static bool layout_apply_minmax_height(
}
}
} else {
- h = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ h = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
if (h < box->height) {
box->height = h;
updated = true;
@@ -2665,8 +2689,9 @@ static bool layout_apply_minmax_height(
}
}
} else {
- h = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ h = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
if (h > box->height) {
box->height = h;
updated = true;
@@ -2834,7 +2859,7 @@ layout_text_box_split(html_content *content,
* Compute dimensions of box, margins, paddings, and borders for a floating
* element using shrink-to-fit. Also used for inline-blocks.
*
- * \param len_ctx CSS length conversion context for document.
+ * \param unit_len_ctx CSS length conversion context for document.
* \param available_width Max width available in pixels
* \param style Box's style
* \param box Box for which to find dimensions
@@ -2843,7 +2868,7 @@ layout_text_box_split(html_content *content,
*/
static void
layout_float_find_dimensions(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
int available_width,
const css_computed_style *style,
struct box *box)
@@ -2863,7 +2888,7 @@ layout_float_find_dimensions(
overflow_y == CSS_OVERFLOW_AUTO) ?
SCROLLBAR_WIDTH : 0;
- layout_find_dimensions(len_ctx, available_width, -1, box, style,
+ layout_find_dimensions(unit_len_ctx, available_width, -1, box, style,
&width, &height, &max_width, &min_width,
&max_height, &min_height, margin, padding, border);
@@ -2899,26 +2924,30 @@ layout_float_find_dimensions(
box->gadget->type == GADGET_FILE) {
if (width == AUTO) {
size = INTTOFIX(10);
- width = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
if (box->gadget->type == GADGET_FILE &&
height == AUTO) {
size = FLTTOFIX(1.5);
- height = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ height = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
}
if (box->gadget->type == GADGET_TEXTAREA) {
if (width == AUTO) {
size = INTTOFIX(10);
- width = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
if (height == AUTO) {
size = INTTOFIX(4);
- height = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ height = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
}
} else if (width == AUTO) {
@@ -2939,9 +2968,9 @@ layout_float_find_dimensions(
* mbp as was used in layout_minmax_block() */
int fixed = 0;
float frac = 0;
- calculate_mbp_width(len_ctx, box->style, LEFT,
+ calculate_mbp_width(unit_len_ctx, box->style, LEFT,
true, true, true, &fixed, &frac);
- calculate_mbp_width(len_ctx, box->style, RIGHT,
+ calculate_mbp_width(unit_len_ctx, box->style, RIGHT,
true, true, true, &fixed, &frac);
if (fixed < 0)
fixed = 0;
@@ -2980,7 +3009,7 @@ static bool layout_float(struct box *b, int width, html_content *content)
{
assert(b->type == BOX_TABLE || b->type == BOX_BLOCK ||
b->type == BOX_INLINE_BLOCK);
- layout_float_find_dimensions(&content->len_ctx, width, b->style, b);
+ layout_float_find_dimensions(&content->unit_len_ctx, width, b->style, b);
if (b->type == BOX_TABLE) {
if (!layout_table(b, width, content))
return false;
@@ -3053,7 +3082,7 @@ place_float_below(struct box *c, int width, int cx, int y, struct box *cont)
* Calculate line height from a style.
*/
static int line_height(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *style)
{
enum css_line_height_e lhtype;
@@ -3072,16 +3101,16 @@ static int line_height(
if (lhtype == CSS_LINE_HEIGHT_NUMBER ||
lhunit == CSS_UNIT_PCT) {
- line_height = nscss_len2px(len_ctx,
- lhvalue, CSS_UNIT_EM, style);
+ line_height = css_unit_len2device_px(style, unit_len_ctx,
+ lhvalue, CSS_UNIT_EM);
if (lhtype != CSS_LINE_HEIGHT_NUMBER)
line_height = FDIV(line_height, F_100);
} else {
assert(lhunit != CSS_UNIT_PCT);
- line_height = nscss_len2px(len_ctx,
- lhvalue, lhunit, style);
+ line_height = css_unit_len2device_px(style, unit_len_ctx,
+ lhvalue, lhunit);
}
return FIXTOINT(line_height);
@@ -3153,7 +3182,7 @@ layout_line(struct box *first,
x1 -= cx;
if (indent)
- x0 += layout_text_indent(&content->len_ctx,
+ x0 += layout_text_indent(&content->unit_len_ctx,
first->parent->parent->style, *width);
if (x1 < x0)
@@ -3163,7 +3192,7 @@ layout_line(struct box *first,
* this is the line-height if there are text children and also in the
* case of an initially empty text input */
if (has_text_children || first->parent->parent->gadget)
- used_height = height = line_height(&content->len_ctx,
+ used_height = height = line_height(&content->unit_len_ctx,
first->parent->parent->style);
else
/* inline containers with no text are usually for layout and
@@ -3203,7 +3232,7 @@ layout_line(struct box *first,
continue;
assert(b->style != NULL);
- font_plot_style_from_css(&content->len_ctx, b->style, &fstyle);
+ font_plot_style_from_css(&content->unit_len_ctx, b->style, &fstyle);
x += space_after;
@@ -3227,7 +3256,7 @@ layout_line(struct box *first,
if (b->type == BOX_INLINE) {
/* calculate borders, margins, and padding */
- layout_find_dimensions(&content->len_ctx,
+ layout_find_dimensions(&content->unit_len_ctx,
*width, -1, b, b->style, 0, 0, 0, 0,
0, 0, b->margin, b->padding, b->border);
for (i = 0; i != 4; i++)
@@ -3262,7 +3291,7 @@ layout_line(struct box *first,
if (!b->object && !(b->flags & IFRAME) && !b->gadget &&
!(b->flags & REPLACE_DIM)) {
/* inline non-replaced, 10.3.1 and 10.6.1 */
- b->height = line_height(&content->len_ctx,
+ b->height = line_height(&content->unit_len_ctx,
b->style ? b->style :
b->parent->parent->style);
if (height < b->height)
@@ -3333,7 +3362,7 @@ layout_line(struct box *first,
/* inline replaced, 10.3.2 and 10.6.2 */
assert(b->style);
- layout_find_dimensions(&content->len_ctx,
+ layout_find_dimensions(&content->unit_len_ctx,
*width, -1, b, b->style,
&b->width, &b->height,
&max_width, &min_width,
@@ -3356,13 +3385,15 @@ layout_line(struct box *first,
} else {
/* form control with no object */
if (b->width == AUTO)
- b->width = FIXTOINT(nscss_len2px(
- &content->len_ctx, INTTOFIX(1),
- CSS_UNIT_EM, b->style));
+ b->width = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx, INTTOFIX(1),
+ CSS_UNIT_EM));
if (b->height == AUTO)
- b->height = FIXTOINT(nscss_len2px(
- &content->len_ctx, INTTOFIX(1),
- CSS_UNIT_EM, b->style));
+ b->height = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx, INTTOFIX(1),
+ CSS_UNIT_EM));
}
/* Reformat object to new box size */
@@ -3395,7 +3426,7 @@ layout_line(struct box *first,
x1 -= cx;
if (indent)
- x0 += layout_text_indent(&content->len_ctx,
+ x0 += layout_text_indent(&content->unit_len_ctx,
first->parent->parent->style, *width);
if (x1 < x0)
@@ -3454,7 +3485,7 @@ layout_line(struct box *first,
else if (b->text || b->type == BOX_INLINE_END) {
if (b->space == UNKNOWN_WIDTH) {
font_plot_style_from_css(
- &content->len_ctx,
+ &content->unit_len_ctx,
b->style, &fstyle);
/** \todo handle errors */
font_func->width(&fstyle, " ", 1,
@@ -3608,7 +3639,7 @@ layout_line(struct box *first,
!(split_box->flags & IFRAME) &&
!split_box->gadget && split_box->text) {
- font_plot_style_from_css(&content->len_ctx,
+ font_plot_style_from_css(&content->unit_len_ctx,
split_box->style, &fstyle);
/** \todo handle errors */
font_func->split(&fstyle,
@@ -3972,9 +4003,10 @@ layout_block_context(struct box *block,
gadget_unit = CSS_UNIT_EM;
gadget_size = INTTOFIX(1);
if (block->height == AUTO)
- block->height = FIXTOINT(nscss_len2px(
- &content->len_ctx, gadget_size,
- gadget_unit, block->style));
+ block->height = FIXTOINT(css_unit_len2device_px(
+ block->style,
+ &content->unit_len_ctx,
+ gadget_size, gadget_unit));
}
box = block->children;
@@ -4038,7 +4070,7 @@ layout_block_context(struct box *block,
* through to, find out. Update the pos/neg margin values. */
if (margin_collapse == NULL) {
margin_collapse = layout_next_margin_block(
- &content->len_ctx, box, block,
+ &content->unit_len_ctx, box, block,
viewport_height,
&max_pos_margin, &max_neg_margin);
/* We have a margin that has not yet been applied. */
@@ -4089,7 +4121,7 @@ layout_block_context(struct box *block,
box->parent->padding[RIGHT] -
x1;
}
- layout_block_find_dimensions(&content->len_ctx,
+ layout_block_find_dimensions(&content->unit_len_ctx,
box->parent->width,
viewport_height, lm, rm, box);
if (box->type == BOX_BLOCK && !(box->flags & IFRAME)) {
@@ -4330,7 +4362,7 @@ layout_block_context(struct box *block,
css_computed_position(box->style) !=
CSS_POSITION_ABSOLUTE &&
layout_apply_minmax_height(
- &content->len_ctx,
+ &content->unit_len_ctx,
box, NULL)) {
/* Height altered */
/* Set current cy */
@@ -4387,7 +4419,7 @@ layout_block_context(struct box *block,
if (block->style && css_computed_position(block->style) !=
CSS_POSITION_ABSOLUTE) {
/* Block is in normal flow */
- layout_apply_minmax_height(&content->len_ctx, block, NULL);
+ layout_apply_minmax_height(&content->unit_len_ctx, block, NULL);
}
if (block->gadget &&
@@ -4399,7 +4431,7 @@ layout_block_context(struct box *block,
block->padding[RIGHT];
int ta_height = block->padding[TOP] + block->height +
block->padding[BOTTOM];
- font_plot_style_from_css(&content->len_ctx,
+ font_plot_style_from_css(&content->unit_len_ctx,
block->style, &fstyle);
fstyle.background = NS_TRANSPARENT;
textarea_set_layout(block->gadget->data.text.ta,
@@ -4820,14 +4852,14 @@ layout_lists(const html_content *content, struct box *box)
marker->height =
content_get_height(marker->object);
marker->y = (line_height(
- &content->len_ctx,
+ &content->unit_len_ctx,
marker->style) -
marker->height) / 2;
} else if (marker->text) {
if (marker->width == UNKNOWN_WIDTH) {
plot_font_style_t fstyle;
font_plot_style_from_css(
- &content->len_ctx,
+ &content->unit_len_ctx,
marker->style,
&fstyle);
content->font_func->width(&fstyle,
@@ -4839,7 +4871,7 @@ layout_lists(const html_content *content, struct box *box)
marker->x = -marker->width;
marker->y = 0;
marker->height = line_height(
- &content->len_ctx,
+ &content->unit_len_ctx,
marker->style);
} else {
marker->x = 0;
@@ -4859,7 +4891,7 @@ layout_lists(const html_content *content, struct box *box)
* Compute box offsets for a relatively or absolutely positioned box with
* respect to a box.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box to compute offsets for
* \param containing_block box to compute percentages with respect to
* \param top updated to top offset, or AUTO
@@ -4870,7 +4902,7 @@ layout_lists(const html_content *content, struct box *box)
* See CSS 2.1 9.3.2. containing_block must have width and height.
*/
static void
-layout_compute_offsets(const nscss_len_ctx *len_ctx,
+layout_compute_offsets(const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *containing_block,
int *top,
@@ -4893,8 +4925,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*left = FPCT_OF_INT_TOINT(value,
containing_block->width);
} else {
- *left = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *left = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*left = AUTO;
@@ -4907,8 +4940,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*right = FPCT_OF_INT_TOINT(value,
containing_block->width);
} else {
- *right = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *right = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*right = AUTO;
@@ -4921,8 +4955,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*top = FPCT_OF_INT_TOINT(value,
containing_block->height);
} else {
- *top = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *top = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*top = AUTO;
@@ -4935,8 +4970,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*bottom = FPCT_OF_INT_TOINT(value,
containing_block->height);
} else {
- *bottom = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *bottom = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*bottom = AUTO;
@@ -4992,14 +5028,14 @@ layout_absolute(struct box *box,
/** \todo inline containers */
}
- layout_compute_offsets(&content->len_ctx, box, containing_block,
+ layout_compute_offsets(&content->unit_len_ctx, box, containing_block,
&top, &right, &bottom, &left);
/* Pass containing block into layout_find_dimensions via the float
* containing block box member. This is unused for absolutely positioned
* boxes because a box can't be floated and absolutely positioned. */
box->float_container = containing_block;
- layout_find_dimensions(&content->len_ctx, available_width, -1,
+ layout_find_dimensions(&content->unit_len_ctx, available_width, -1,
box, box->style, &width, &height,
&max_width, &min_width, 0, 0,
margin, padding, border);
@@ -5317,7 +5353,7 @@ layout_absolute(struct box *box,
/** \todo Inline ancestors */
}
box->height = height;
- layout_apply_minmax_height(&content->len_ctx, box, containing_block);
+ layout_apply_minmax_height(&content->unit_len_ctx, box, containing_block);
return true;
}
@@ -5394,13 +5430,13 @@ layout_position_absolute(struct box *box,
/**
* Compute a box's relative offset as per CSS 2.1 9.4.3
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box Box to compute relative offsets for.
* \param x Receives relative offset in x.
* \param y Receives relative offset in y.
*/
static void layout_compute_relative_offset(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
int *x,
int *y)
@@ -5420,7 +5456,7 @@ static void layout_compute_relative_offset(
containing_block = box->parent;
}
- layout_compute_offsets(len_ctx, box, containing_block,
+ layout_compute_offsets(unit_len_ctx, box, containing_block,
&top, &right, &bottom, &left);
if (left == AUTO && right == AUTO)
@@ -5468,7 +5504,7 @@ static void layout_compute_relative_offset(
/**
* Adjust positions of relatively positioned boxes.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param root box to adjust the position of
* \param fp box which forms the block formatting context for children of
* "root" which are floats
@@ -5481,7 +5517,7 @@ static void layout_compute_relative_offset(
*/
static void
layout_position_relative(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *root,
struct box *fp,
int fx,
@@ -5510,7 +5546,7 @@ layout_position_relative(
if (box->style && css_computed_position(box->style) ==
CSS_POSITION_RELATIVE)
layout_compute_relative_offset(
- len_ctx, box, &x, &y);
+ unit_len_ctx, box, &x, &y);
else
x = y = 0;
@@ -5546,7 +5582,7 @@ layout_position_relative(
}
/* recurse first */
- layout_position_relative(len_ctx, box, fn, fnx, fny);
+ layout_position_relative(unit_len_ctx, box, fn, fnx, fny);
/* Ignore things we're not interested in. */
if (!box->style || (box->style &&
@@ -5575,7 +5611,7 @@ layout_position_relative(
/**
* Find a box's bounding box relative to itself, i.e. the box's border edge box
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box find bounding box of
* \param desc_x0 updated to left of box's bbox
* \param desc_y0 updated to top of box's bbox
@@ -5584,7 +5620,7 @@ layout_position_relative(
*/
static void
layout_get_box_bbox(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
int *desc_x0, int *desc_y0,
int *desc_x1, int *desc_y1)
@@ -5607,8 +5643,8 @@ layout_get_box_bbox(
int text_height;
css_computed_font_size(box->style, &font_size, &font_unit);
- text_height = nscss_len2px(len_ctx, font_size, font_unit,
- box->style);
+ text_height = css_unit_len2device_px(box->style, unit_len_ctx,
+ font_size, font_unit);
text_height = FIXTOINT(text_height * 3 / 4);
*desc_y0 = (*desc_y0 < -text_height) ? *desc_y0 : -text_height;
}
@@ -5618,7 +5654,7 @@ layout_get_box_bbox(
/**
* Apply changes to box descendant_[xy][01] values due to given child.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box to update
* \param child a box, which may affect box's descendant bbox
* \param off_x offset to apply to child->x coord to treat as child of box
@@ -5626,7 +5662,7 @@ layout_get_box_bbox(
*/
static void
layout_update_descendant_bbox(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *child,
int off_x,
@@ -5650,7 +5686,7 @@ layout_update_descendant_bbox(
}
/* Get child's border edge */
- layout_get_box_bbox(len_ctx, child,
+ layout_get_box_bbox(unit_len_ctx, child,
&child_desc_x0, &child_desc_y0,
&child_desc_x1, &child_desc_y1);
@@ -5688,11 +5724,11 @@ layout_update_descendant_bbox(
* Recursively calculate the descendant_[xy][01] values for a laid-out box tree
* and inform iframe browser windows of their size and position.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box tree of boxes to update
*/
static void layout_calculate_descendant_bboxes(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box)
{
struct box *child;
@@ -5702,7 +5738,7 @@ static void layout_calculate_descendant_bboxes(
/* assert((box->width >= 0) && (box->height >= 0)); */
/* Initialise box's descendant box to border edge box */
- layout_get_box_bbox(len_ctx, box,
+ layout_get_box_bbox(unit_len_ctx, box,
&box->descendant_x0, &box->descendant_y0,
&box->descendant_x1, &box->descendant_y1);
@@ -5736,7 +5772,7 @@ static void layout_calculate_descendant_bboxes(
child->type == BOX_FLOAT_RIGHT)
continue;
- layout_update_descendant_bbox(len_ctx, box, child,
+ layout_update_descendant_bbox(unit_len_ctx, box, child,
box->x, box->y);
if (child == box->inline_end)
@@ -5754,7 +5790,7 @@ static void layout_calculate_descendant_bboxes(
child->type == BOX_FLOAT_RIGHT)
continue;
- layout_calculate_descendant_bboxes(len_ctx, child);
+ layout_calculate_descendant_bboxes(unit_len_ctx, child);
if (box->style && css_computed_overflow_x(box->style) ==
CSS_OVERFLOW_HIDDEN &&
@@ -5762,23 +5798,23 @@ static void layout_calculate_descendant_bboxes(
CSS_OVERFLOW_HIDDEN)
continue;
- layout_update_descendant_bbox(len_ctx, box, child, 0, 0);
+ layout_update_descendant_bbox(unit_len_ctx, box, child, 0, 0);
}
for (child = box->float_children; child; child = child->next_float) {
assert(child->type == BOX_FLOAT_LEFT ||
child->type == BOX_FLOAT_RIGHT);
- layout_calculate_descendant_bboxes(len_ctx, child);
+ layout_calculate_descendant_bboxes(unit_len_ctx, child);
- layout_update_descendant_bbox(len_ctx, box, child, 0, 0);
+ layout_update_descendant_bbox(unit_len_ctx, box, child, 0, 0);
}
if (box->list_marker) {
child = box->list_marker;
- layout_calculate_descendant_bboxes(len_ctx, child);
+ layout_calculate_descendant_bboxes(unit_len_ctx, child);
- layout_update_descendant_bbox(len_ctx, box, child, 0, 0);
+ layout_update_descendant_bbox(unit_len_ctx, box, child, 0, 0);
}
}
@@ -5796,7 +5832,7 @@ bool layout_document(html_content *content, int width, int height)
layout_minmax_block(doc, font_func, content);
- layout_block_find_dimensions(&content->len_ctx,
+ layout_block_find_dimensions(&content->unit_len_ctx,
width, height, 0, 0, doc);
doc->x = doc->margin[LEFT] + doc->border[LEFT].width;
doc->y = doc->margin[TOP] + doc->border[TOP].width;
@@ -5830,9 +5866,9 @@ bool layout_document(html_content *content, int width, int height)
layout_lists(content, doc);
layout_position_absolute(doc, doc, 0, 0, content);
- layout_position_relative(&content->len_ctx, doc, doc, 0, 0);
+ layout_position_relative(&content->unit_len_ctx, doc, doc, 0, 0);
- layout_calculate_descendant_bboxes(&content->len_ctx, doc);
+ layout_calculate_descendant_bboxes(&content->unit_len_ctx, doc);
return ret;
}
diff --git a/content/handlers/html/object.c b/content/handlers/html/object.c
index e6edf84..a1f020b 100644
--- a/content/handlers/html/object.c
+++ b/content/handlers/html/object.c
@@ -265,18 +265,20 @@ html_object_callback(hlcache_handle *object,
if (hunit == CSS_UNIT_PCT) {
l = (width - w) * hpos / INTTOFIX(100);
} else {
- l = FIXTOINT(nscss_len2px(&c->len_ctx,
- hpos, hunit,
- box->style));
+ l = FIXTOINT(css_unit_len2device_px(
+ box->style,
+ &c->unit_len_ctx,
+ hpos, hunit));
}
h = content_get_height(box->background);
if (vunit == CSS_UNIT_PCT) {
t = (height - h) * vpos / INTTOFIX(100);
} else {
- t = FIXTOINT(nscss_len2px(&c->len_ctx,
- vpos, vunit,
- box->style));
+ t = FIXTOINT(css_unit_len2device_px(
+ box->style,
+ &c->unit_len_ctx,
+ vpos, vunit));
}
/* Redraw area depends on background-repeat */
diff --git a/content/handlers/html/private.h b/content/handlers/html/private.h
index 2bd9cff..56cd957 100644
--- a/content/handlers/html/private.h
+++ b/content/handlers/html/private.h
@@ -112,9 +112,6 @@ typedef struct html_content {
/** Base target */
char *base_target;
- /** CSS length conversion context for document. */
- nscss_len_ctx len_ctx;
-
/** Content has been aborted in the LOADING state */
bool aborted;
@@ -162,6 +159,8 @@ typedef struct html_content {
css_select_ctx *select_ctx;
/**< Style selection media specification */
css_media media;
+ /** CSS length conversion context for document. */
+ css_unit_ctx unit_len_ctx;
/**< Universal selector */
lwc_string *universal;
diff --git a/content/handlers/html/redraw.c b/content/handlers/html/redraw.c
index 9807512..f770699 100644
--- a/content/handlers/html/redraw.c
+++ b/content/handlers/html/redraw.c
@@ -528,14 +528,14 @@ static bool html_redraw_radio(int x, int y, int width, int height,
* \param box box of input
* \param scale scale for redraw
* \param background_colour current background colour
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
static bool html_redraw_file(int x, int y, int width, int height,
struct box *box, float scale, colour background_colour,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
int text_width;
@@ -544,7 +544,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
plot_font_style_t fstyle;
nserror res;
- font_plot_style_from_css(len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(unit_len_ctx, box->style, &fstyle);
fstyle.background = background_colour;
if (box->gadget->value) {
@@ -587,7 +587,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
* \param clip current clip rectangle
* \param background_colour current background colour
* \param background box containing background details (usually \a box)
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
@@ -595,7 +595,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
static bool html_redraw_background(int x, int y, struct box *box, float scale,
const struct rect *clip, colour *background_colour,
struct box *background,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
bool repeat_x = false;
@@ -672,8 +672,9 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
content_get_width(background->background)) *
scale * FIXTOFLT(hpos) / 100.;
} else {
- x += (int) (FIXTOFLT(nscss_len2px(len_ctx, hpos, hunit,
- background->style)) * scale);
+ x += (int) (FIXTOFLT(css_unit_len2device_px(
+ background->style, unit_len_ctx,
+ hpos, hunit)) * scale);
}
if (vunit == CSS_UNIT_PCT) {
@@ -681,8 +682,9 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
content_get_height(background->background)) *
scale * FIXTOFLT(vpos) / 100.;
} else {
- y += (int) (FIXTOFLT(nscss_len2px(len_ctx, vpos, vunit,
- background->style)) * scale);
+ y += (int) (FIXTOFLT(css_unit_len2device_px(
+ background->style, unit_len_ctx,
+ vpos, vunit)) * scale);
}
}
@@ -814,7 +816,7 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
* \param first true if this is the first rectangle associated with the inline
* \param last true if this is the last rectangle associated with the inline
* \param background_colour updated to current background colour if plotted
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
@@ -822,7 +824,7 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
static bool html_redraw_inline_background(int x, int y, struct box *box,
float scale, const struct rect *clip, struct rect b,
bool first, bool last, colour *background_colour,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
struct rect r = *clip;
@@ -883,8 +885,9 @@ static bool html_redraw_inline_background(int x, int y, struct box *box,
plot_content = false;
}
} else {
- x += (int) (FIXTOFLT(nscss_len2px(len_ctx, hpos, hunit,
- box->style)) * scale);
+ x += (int) (FIXTOFLT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ hpos, hunit)) * scale);
}
if (vunit == CSS_UNIT_PCT) {
@@ -892,8 +895,9 @@ static bool html_redraw_inline_background(int x, int y, struct box *box,
content_get_height(box->background) *
scale) * FIXTOFLT(vpos) / 100.;
} else {
- y += (int) (FIXTOFLT(nscss_len2px(len_ctx, vpos, vunit,
- box->style)) * scale);
+ y += (int) (FIXTOFLT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ vpos, vunit)) * scale);
}
}
@@ -1134,7 +1138,7 @@ static bool html_redraw_text_box(const html_content *html, struct box *box,
bool excluded = (box->object != NULL);
plot_font_style_t fstyle;
- font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
fstyle.background = current_background_color;
if (!text_redraw(box->text,
@@ -1405,28 +1409,24 @@ bool html_redraw_box(const html_content *html, struct box *box,
CSS_CLIP_RECT) {
/* We have an absolutly positioned box with a clip rect */
if (css_rect.left_auto == false)
- r.x0 = x - border_left + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.left, css_rect.lunit,
- box->style));
+ r.x0 = x - border_left + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.left, css_rect.lunit));
if (css_rect.top_auto == false)
- r.y0 = y - border_top + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.top, css_rect.tunit,
- box->style));
+ r.y0 = y - border_top + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.top, css_rect.tunit));
if (css_rect.right_auto == false)
- r.x1 = x - border_left + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.right, css_rect.runit,
- box->style));
+ r.x1 = x - border_left + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.right, css_rect.runit));
if (css_rect.bottom_auto == false)
- r.y1 = y - border_top + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.bottom, css_rect.bunit,
- box->style));
+ r.y1 = y - border_top + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.bottom, css_rect.bunit));
/* find intersection of clip rectangle and box */
if (r.x0 < clip->x0) r.x0 = clip->x0;
@@ -1515,7 +1515,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
/* plot background */
if (!html_redraw_background(x, y, box, scale, &p,
¤t_background_color, bg_box,
- &html->len_ctx, ctx))
+ &html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@@ -1595,7 +1595,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
x, y, box, scale, &p, b,
first, false,
¤t_background_color,
- &html->len_ctx, ctx))
+ &html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@@ -1628,7 +1628,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
* the inline */
if (!html_redraw_inline_background(x, ib_y, box, scale, &p, b,
first, true, ¤t_background_color,
- &html->len_ctx, ctx))
+ &html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@@ -1843,7 +1843,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
} else if (box->gadget && box->gadget->type == GADGET_FILE) {
if (!html_redraw_file(x + padding_left, y + padding_top,
width, height, box, scale,
- current_background_color, &html->len_ctx, ctx))
+ current_background_color, &html->unit_len_ctx, ctx))
return false;
} else if (box->gadget &&
diff --git a/content/handlers/html/table.c b/content/handlers/html/table.c
index 263ddf1..4ffccea 100644
--- a/content/handlers/html/table.c
+++ b/content/handlers/html/table.c
@@ -50,7 +50,7 @@ struct border {
/**
* Determine if a border style is more eyecatching than another
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param a Reference border style
* \param a_src Source of \a a
* \param b Candidate border style
@@ -58,7 +58,7 @@ struct border {
* \return True if \a b is more eyecatching than \a a
*/
static bool
-table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
+table_border_is_more_eyecatching(const css_unit_ctx *unit_len_ctx,
const struct border *a,
box_type a_src,
const struct border *b,
@@ -83,8 +83,8 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
* if they've come from a computed style. */
assert(a->unit != CSS_UNIT_EM && a->unit != CSS_UNIT_EX);
assert(b->unit != CSS_UNIT_EM && b->unit != CSS_UNIT_EX);
- awidth = nscss_len2px(len_ctx, a->width, a->unit, NULL);
- bwidth = nscss_len2px(len_ctx, b->width, b->unit, NULL);
+ awidth = css_unit_len2device_px(NULL, unit_len_ctx, a->width, a->unit);
+ bwidth = css_unit_len2device_px(NULL, unit_len_ctx, b->width, b->unit);
if (awidth < bwidth)
return true;
@@ -160,7 +160,7 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
/**
* Process a table
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param table Table to process
* \param a Current border style for cell
* \param a_src Source of \a a
@@ -169,7 +169,7 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static void
-table_cell_top_process_table(const nscss_len_ctx *len_ctx,
+table_cell_top_process_table(const css_unit_ctx *unit_len_ctx,
struct box *table,
struct border *a,
box_type *a_src)
@@ -181,11 +181,12 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(table->style);
b.color = css_computed_border_top_color(table->style, &b.c);
css_computed_border_top_width(table->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@@ -195,7 +196,7 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
/**
* Process a row
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Cell being considered
* \param row Row to process
* \param a Current border style for cell
@@ -206,7 +207,7 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static bool
-table_cell_top_process_row(const nscss_len_ctx *len_ctx,
+table_cell_top_process_row(const css_unit_ctx *unit_len_ctx,
struct box *cell,
struct box *row,
struct border *a,
@@ -219,11 +220,12 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(row->style);
b.color = css_computed_border_bottom_color(row->style, &b.c);
css_computed_border_bottom_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@@ -233,11 +235,12 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(row->style);
b.color = css_computed_border_top_color(row->style, &b.c);
css_computed_border_top_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
@@ -272,14 +275,13 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
c->style, &b.c);
css_computed_border_bottom_width(c->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx,
- b.width,
- b.unit,
- c->style);
+ b.width = css_unit_len2device_px(
+ c->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_CELL;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
a,
*a_src,
&b,
@@ -305,7 +307,7 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
/**
* Process a group
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Cell being considered
* \param group Group to process
* \param a Current border style for cell
@@ -316,7 +318,7 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static bool
-table_cell_top_process_group(const nscss_len_ctx *len_ctx,
+table_cell_top_process_group(const css_unit_ctx *unit_len_ctx,
struct box *cell,
struct box *group,
struct border *a,
@@ -329,11 +331,12 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(group->style);
b.color = css_computed_border_bottom_color(group->style, &b.c);
css_computed_border_bottom_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@@ -342,7 +345,7 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
/* Process rows in group, starting with last */
struct box *row = group->last;
- while (table_cell_top_process_row(len_ctx, cell, row,
+ while (table_cell_top_process_row(unit_len_ctx, cell, row,
a, a_src) == false) {
if (row->prev == NULL) {
return false;
@@ -355,11 +358,12 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(group->style);
b.color = css_computed_border_top_color(group->style, &b.c);
css_computed_border_top_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
@@ -375,11 +379,11 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
/**
* Calculate used values of border-left-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+table_used_left_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@@ -390,7 +394,8 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_left_style(cell->style);
a.color = css_computed_border_left_color(cell->style, &a.c);
css_computed_border_left_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -423,11 +428,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_right_style(prev->style);
b.color = css_computed_border_right_color(prev->style, &b.c);
css_computed_border_right_width(prev->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, prev->style);
+ b.width = css_unit_len2device_px(prev->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_CELL;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -446,12 +452,13 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
row->style, &b.c);
css_computed_border_left_width(
row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx,
- b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(
+ row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -466,11 +473,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_left_style(group->style);
b.color = css_computed_border_left_color(group->style, &b.c);
css_computed_border_left_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -480,11 +488,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_left_style(table->style);
b.color = css_computed_border_left_color(table->style, &b.c);
css_computed_border_left_width(table->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -494,21 +503,19 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used left border for the cell */
cell->border[LEFT].style = a.style;
cell->border[LEFT].c = a.c;
- cell->border[LEFT].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width,
- a.unit,
- cell->style));
+ cell->border[LEFT].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-top-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+table_used_top_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@@ -519,7 +526,8 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_top_style(cell->style);
css_computed_border_top_color(cell->style, &a.c);
css_computed_border_top_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -527,18 +535,19 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_top_style(row->style);
css_computed_border_top_color(row->style, &b.c);
css_computed_border_top_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx, &a, a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, &a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
}
if (row->prev != NULL) {
/* Consider row(s) above */
- while (table_cell_top_process_row(len_ctx, cell, row->prev,
+ while (table_cell_top_process_row(unit_len_ctx, cell, row->prev,
&a, &a_src) == false) {
if (row->prev->prev == NULL) {
/* Consider row group */
@@ -559,11 +568,12 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_top_style(group->style);
b.color = css_computed_border_top_color(group->style, &b.c);
css_computed_border_top_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -571,16 +581,16 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
if (group->prev == NULL) {
/* Top border of table */
- table_cell_top_process_table(len_ctx,
+ table_cell_top_process_table(unit_len_ctx,
group->parent, &a, &a_src);
} else {
/* Process previous group(s) */
- while (table_cell_top_process_group(len_ctx,
+ while (table_cell_top_process_group(unit_len_ctx,
cell, group->prev,
&a, &a_src) == false) {
if (group->prev->prev == NULL) {
/* Top border of table */
- table_cell_top_process_table(len_ctx,
+ table_cell_top_process_table(unit_len_ctx,
group->parent,
&a, &a_src);
break;
@@ -594,20 +604,18 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used top border for the cell */
cell->border[TOP].style = a.style;
cell->border[TOP].c = a.c;
- cell->border[TOP].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width,
- a.unit,
- cell->style));
+ cell->border[TOP].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-right-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+table_used_right_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@@ -618,7 +626,8 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_right_style(cell->style);
css_computed_border_right_color(cell->style, &a.c);
css_computed_border_right_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -643,14 +652,13 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
css_computed_border_right_width(row->style,
&b.width,
&b.unit);
- b.width = nscss_len2px(len_ctx,
- b.width,
- b.unit,
- row->style);
+ b.width = css_unit_len2device_px(
+ row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src,
&b, b_src)) {
a = b;
@@ -667,11 +675,12 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.color = css_computed_border_right_color(group->style, &b.c);
css_computed_border_right_width(group->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -682,11 +691,12 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.color = css_computed_border_right_color(table->style, &b.c);
css_computed_border_right_width(table->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src,
&b, b_src)) {
a = b;
@@ -697,21 +707,19 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used right border for the cell */
cell->border[RIGHT].style = a.style;
cell->border[RIGHT].c = a.c;
- cell->border[RIGHT].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width,
- a.unit,
- cell->style));
+ cell->border[RIGHT].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-bottom-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
+table_used_bottom_border_for_cell(const css_unit_ctx *unit_len_ctx,
struct box *cell)
{
struct border a, b;
@@ -723,7 +731,8 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
a.style = css_computed_border_bottom_style(cell->style);
css_computed_border_bottom_color(cell->style, &a.c);
css_computed_border_bottom_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -747,11 +756,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(row->style);
b.color = css_computed_border_bottom_color(row->style, &b.c);
css_computed_border_bottom_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -762,11 +772,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.color = css_computed_border_bottom_color(group->style, &b.c);
css_computed_border_bottom_width(group->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -777,11 +788,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.color = css_computed_border_bottom_color(table->style, &b.c);
css_computed_border_bottom_width(table->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
}
@@ -790,14 +802,14 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
/* a now contains the used bottom border for the cell */
cell->border[BOTTOM].style = a.style;
cell->border[BOTTOM].c = a.c;
- cell->border[BOTTOM].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width, a.unit, cell->style));
+ cell->border[BOTTOM].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/* exported interface documented in html/table.h */
bool
-table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
+table_calculate_column_types(const css_unit_ctx *unit_len_ctx, struct box *table)
{
unsigned int i, j;
struct column *col;
@@ -845,8 +857,10 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
if (col[i].type != COLUMN_WIDTH_FIXED &&
type == CSS_WIDTH_SET && unit != CSS_UNIT_PCT) {
col[i].type = COLUMN_WIDTH_FIXED;
- col[i].width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, cell->style));
+ col[i].width = FIXTOINT(css_unit_len2device_px(
+ cell->style,
+ unit_len_ctx,
+ value, unit));
if (col[i].width < 0)
col[i].width = 0;
continue;
@@ -911,9 +925,11 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
if (type == CSS_WIDTH_SET && unit != CSS_UNIT_PCT &&
fixed_columns + unknown_columns ==
cell->columns) {
- int width = (FIXTOFLT(nscss_len2px(len_ctx, value, unit,
- cell->style)) - fixed_width) /
- unknown_columns;
+ int width = (FIXTOFLT(css_unit_len2device_px(
+ cell->style,
+ unit_len_ctx,
+ value, unit)) -
+ fixed_width) / unknown_columns;
if (width < 0)
width = 0;
for (j = 0; j != cell->columns; j++) {
@@ -968,7 +984,7 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
/* exported interface documented in html/table.h */
-void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+void table_used_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
int side;
@@ -986,8 +1002,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[LEFT].c);
css_computed_border_left_width(cell->style, &width, &unit);
cell->border[LEFT].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
/* Top border */
cell->border[TOP].style =
@@ -996,8 +1013,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[TOP].c);
css_computed_border_top_width(cell->style, &width, &unit);
cell->border[TOP].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
/* Right border */
cell->border[RIGHT].style =
@@ -1006,8 +1024,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[RIGHT].c);
css_computed_border_right_width(cell->style, &width, &unit);
cell->border[RIGHT].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
/* Bottom border */
cell->border[BOTTOM].style =
@@ -1016,20 +1035,21 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[BOTTOM].c);
css_computed_border_bottom_width(cell->style, &width, &unit);
cell->border[BOTTOM].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
} else {
/* Left border */
- table_used_left_border_for_cell(len_ctx, cell);
+ table_used_left_border_for_cell(unit_len_ctx, cell);
/* Top border */
- table_used_top_border_for_cell(len_ctx, cell);
+ table_used_top_border_for_cell(unit_len_ctx, cell);
/* Right border */
- table_used_right_border_for_cell(len_ctx, cell);
+ table_used_right_border_for_cell(unit_len_ctx, cell);
/* Bottom border */
- table_used_bottom_border_for_cell(len_ctx, cell);
+ table_used_bottom_border_for_cell(unit_len_ctx, cell);
}
/* Finally, ensure that any borders configured as
diff --git a/content/handlers/html/table.h b/content/handlers/html/table.h
index ac4af25..557032b 100644
--- a/content/handlers/html/table.h
+++ b/content/handlers/html/table.h
@@ -33,24 +33,24 @@ struct box;
/**
* Determine the column width types for a table.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param table box of type BOX_TABLE
* \return true on success, false on memory exhaustion
*
* The table->col array is allocated and type and width are filled in for each
* column.
*/
-bool table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table);
+bool table_calculate_column_types(const css_unit_ctx *unit_len_ctx, struct box *table);
/**
* Calculate used values of border-{trbl}-{style,color,width} for table cells.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*
* \post \a cell's border array is populated
*/
-void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell);
+void table_used_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell);
#endif
diff --git a/content/handlers/html/textselection.c b/content/handlers/html/textselection.c
index 9de7590..9b83e73 100644
--- a/content/handlers/html/textselection.c
+++ b/content/handlers/html/textselection.c
@@ -240,7 +240,7 @@ coords_from_range(struct box *box,
* \param text pointer to text being added, or NULL for newline
* \param length length of text to be appended (bytes)
* \param box pointer to text box, or NULL if from textplain
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param handle selection string to append to
* \param whitespace_text whitespace to place before text for formatting
* may be NULL
@@ -251,7 +251,7 @@ static nserror
selection_copy_box(const char *text,
size_t length,
struct box *box,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct selection_string *handle,
const char *whitespace_text,
size_t whitespace_length)
@@ -278,7 +278,7 @@ selection_copy_box(const char *text,
if (box->style != NULL) {
/* Override default font style */
- font_plot_style_from_css(len_ctx, box->style, &style);
+ font_plot_style_from_css(unit_len_ctx, box->style, &style);
pstyle = &style;
} else {
/* If there's no style, there must be no text */
@@ -300,7 +300,7 @@ selection_copy_box(const char *text,
* boxes that lie (partially) within the given range
*
* \param box box subtree
- * \param len_ctx Length conversion context.
+ * \param unit_len_ctx Length conversion context.
* \param start_idx start of range within textual representation (bytes)
* \param end_idx end of range
* \param handler handler function to call
@@ -312,7 +312,7 @@ selection_copy_box(const char *text,
*/
static nserror
selection_copy(struct box *box,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
unsigned start_idx,
unsigned end_idx,
struct selection_string *selstr,
@@ -340,7 +340,7 @@ selection_copy(struct box *box,
/* do the marker box before continuing with the rest of the
* list element */
res = selection_copy(box->list_marker,
- len_ctx,
+ unit_len_ctx,
start_idx,
end_idx,
selstr,
@@ -383,7 +383,7 @@ selection_copy(struct box *box,
res = selection_copy_box(box->text + start_off,
min(box->length, end_off) - start_off,
box,
- len_ctx,
+ unit_len_ctx,
selstr,
whitespace_text,
whitespace_length);
@@ -415,7 +415,7 @@ selection_copy(struct box *box,
struct box *next = child->next;
res = selection_copy(child,
- len_ctx,
+ unit_len_ctx,
start_idx,
end_idx,
selstr,
@@ -518,7 +518,7 @@ html_textselection_copy(struct content *c,
}
return selection_copy(html->layout,
- &html->len_ctx,
+ &html->unit_len_ctx,
start_idx,
end_idx,
selstr,
diff --git a/desktop/local_history_private.h b/desktop/local_history_private.h
index 0b74562..fd25ab4 100644
--- a/desktop/local_history_private.h
+++ b/desktop/local_history_private.h
@@ -27,12 +27,12 @@
#include "content/handlers/css/utils.h"
#define LOCAL_HISTORY_WIDTH \
- (FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(116))))
+ (FIXTOINT(css_unit_css2device_px(INTTOFIX(116), nscss_screen_dpi)))
#define LOCAL_HISTORY_HEIGHT \
- (FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(100))))
+ (FIXTOINT(css_unit_css2device_px(INTTOFIX(100), nscss_screen_dpi)))
#define LOCAL_HISTORY_RIGHT_MARGIN \
- (FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(50))))
+ (FIXTOINT(css_unit_css2device_px(INTTOFIX( 50), nscss_screen_dpi)))
#define LOCAL_HISTORY_BOTTOM_MARGIN \
- (FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(30))))
+ (FIXTOINT(css_unit_css2device_px(INTTOFIX( 30), nscss_screen_dpi)))
#endif
diff --git a/desktop/print.c b/desktop/print.c
index de579dc..e90e322 100644
--- a/desktop/print.c
+++ b/desktop/print.c
@@ -257,9 +257,9 @@ struct print_settings *print_make_settings(print_configuration configuration,
struct print_settings *settings;
css_fixed length = 0;
css_unit unit = CSS_UNIT_MM;
- nscss_len_ctx len_ctx = {
- .vw = DEFAULT_PAGE_WIDTH,
- .vh = DEFAULT_PAGE_HEIGHT,
+ css_unit_ctx unit_len_ctx = {
+ .viewport_width = DEFAULT_PAGE_WIDTH,
+ .viewport_height = DEFAULT_PAGE_HEIGHT,
.root_style = NULL,
};
@@ -277,17 +277,17 @@ struct print_settings *print_make_settings(print_configuration configuration,
settings->scale = DEFAULT_EXPORT_SCALE;
length = INTTOFIX(DEFAULT_MARGIN_LEFT_MM);
- settings->margins[MARGINLEFT] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINLEFT] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(DEFAULT_MARGIN_RIGHT_MM);
- settings->margins[MARGINRIGHT] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINRIGHT] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(DEFAULT_MARGIN_TOP_MM);
- settings->margins[MARGINTOP] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINTOP] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(DEFAULT_MARGIN_BOTTOM_MM);
- settings->margins[MARGINBOTTOM] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINBOTTOM] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
break;
/* use settings from the Export options tab */
case PRINT_OPTIONS:
@@ -303,17 +303,17 @@ struct print_settings *print_make_settings(print_configuration configuration,
settings->scale = (float)nsoption_int(export_scale) / 100;
length = INTTOFIX(nsoption_int(margin_left));
- settings->margins[MARGINLEFT] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINLEFT] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(nsoption_int(margin_right));
- settings->margins[MARGINRIGHT] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINRIGHT] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(nsoption_int(margin_top));
- settings->margins[MARGINTOP] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINTOP] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(nsoption_int(margin_bottom));
- settings->margins[MARGINBOTTOM] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINBOTTOM] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
break;
default:
return NULL;
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=638a408ddee7329f8de...
commit 638a408ddee7329f8de2a6e550b7fcc2a4baa4a3
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
CSS: Update to latest libcss: Remove weird units.
The 'rlh', 'ic' and 'cap' units were never implemented by anyone.
diff --git a/content/handlers/css/dump.c b/content/handlers/css/dump.c
index b12e1d9..1e448e0 100644
--- a/content/handlers/css/dump.c
+++ b/content/handlers/css/dump.c
@@ -113,24 +113,15 @@ static void dump_css_unit(FILE *stream, css_fixed val, css_unit unit)
case CSS_UNIT_KHZ:
fprintf(stream, "kHz");
break;
- case CSS_UNIT_CAP:
- fprintf(stream, "cap");
- break;
case CSS_UNIT_CH:
fprintf(stream, "ch");
break;
- case CSS_UNIT_IC:
- fprintf(stream, "ic");
- break;
case CSS_UNIT_REM:
fprintf(stream, "rem");
break;
case CSS_UNIT_LH:
fprintf(stream, "lh");
break;
- case CSS_UNIT_RLH:
- fprintf(stream, "rlh");
- break;
case CSS_UNIT_VH:
fprintf(stream, "vh");
break;
diff --git a/content/handlers/css/select.c b/content/handlers/css/select.c
index 99840e9..cfefb2a 100644
--- a/content/handlers/css/select.c
+++ b/content/handlers/css/select.c
@@ -423,9 +423,7 @@ css_error nscss_compute_font_size(void *pw, const css_hint *parent,
size->data.length.unit = parent_size.unit;
} else if (size->data.length.unit == CSS_UNIT_EM ||
size->data.length.unit == CSS_UNIT_EX ||
- size->data.length.unit == CSS_UNIT_CAP ||
- size->data.length.unit == CSS_UNIT_CH ||
- size->data.length.unit == CSS_UNIT_IC) {
+ size->data.length.unit == CSS_UNIT_CH) {
size->data.length.value =
FMUL(size->data.length.value, parent_size.value);
@@ -435,21 +433,11 @@ css_error nscss_compute_font_size(void *pw, const css_hint *parent,
size->data.length.value = FMUL(size->data.length.value,
FLTTOFIX(0.6));
break;
- case CSS_UNIT_CAP:
- /* Height of captals. 1cap = 0.9em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.9));
- break;
case CSS_UNIT_CH:
/* Width of '0'. 1ch = 0.4em in NetSurf. */
size->data.length.value = FMUL(size->data.length.value,
FLTTOFIX(0.4));
break;
- case CSS_UNIT_IC:
- /* Width of U+6C43. 1ic = 1.1em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(1.1));
- break;
default:
/* No scaling required for EM. */
break;
@@ -473,12 +461,6 @@ css_error nscss_compute_font_size(void *pw, const css_hint *parent,
size->data.length.value,
parent_size.value);
}
- } else if (size->data.length.unit == CSS_UNIT_RLH) {
- /** TODO: Convert root element line-height to absolute value. */
- size->data.length.value = FMUL(size->data.length.value, FDIV(
- INTTOFIX(nsoption_int(font_size)),
- INTTOFIX(10)));
- size->data.length.unit = CSS_UNIT_PT;
}
size->status = CSS_FONT_SIZE_DIMENSION;
diff --git a/content/handlers/css/utils.c b/content/handlers/css/utils.c
index cf48e89..24ba443 100644
--- a/content/handlers/css/utils.c
+++ b/content/handlers/css/utils.c
@@ -91,11 +91,8 @@ css_fixed nscss_len2pt(
/* Length must not be relative */
assert(unit != CSS_UNIT_EM &&
unit != CSS_UNIT_EX &&
- unit != CSS_UNIT_CAP &&
unit != CSS_UNIT_CH &&
- unit != CSS_UNIT_IC &&
- unit != CSS_UNIT_REM &&
- unit != CSS_UNIT_RLH);
+ unit != CSS_UNIT_REM);
unit = css_utils__fudge_viewport_units(ctx, unit);
@@ -140,9 +137,7 @@ css_fixed nscss_len2px(
switch (unit) {
case CSS_UNIT_EM:
case CSS_UNIT_EX:
- case CSS_UNIT_CAP:
case CSS_UNIT_CH:
- case CSS_UNIT_IC:
{
css_fixed font_size = 0;
css_unit font_unit = CSS_UNIT_PT;
@@ -168,15 +163,9 @@ css_fixed nscss_len2px(
case CSS_UNIT_EX:
px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
break;
- case CSS_UNIT_CAP:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.9));
- break;
case CSS_UNIT_CH:
px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
break;
- case CSS_UNIT_IC:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(1.1));
- break;
default: break;
}
}
@@ -231,12 +220,6 @@ css_fixed nscss_len2px(
px_per_unit = FDIV(FMUL(font_size, F_96), F_72);
break;
}
- /* 1rlh = <user_font_size>pt => 1rlh = (DPI/user_font_size)px */
- case CSS_UNIT_RLH:
- px_per_unit = FDIV(F_96, FDIV(
- INTTOFIX(nsoption_int(font_size)),
- INTTOFIX(10)));
- break;
case CSS_UNIT_VH:
px_per_unit = FDIV(ctx->vh, F_100);
break;
-----------------------------------------------------------------------
Summary of changes:
content/handlers/css/Makefile | 2 +-
content/handlers/css/css.c | 3 +
content/handlers/css/dump.c | 9 -
content/handlers/css/select.c | 155 +-----------
content/handlers/css/select.h | 5 +-
content/handlers/css/utils.c | 259 --------------------
content/handlers/css/utils.h | 79 ------
content/handlers/html/box_construct.c | 3 +-
content/handlers/html/box_inspect.c | 44 ++--
content/handlers/html/box_inspect.h | 6 +-
content/handlers/html/box_normalise.c | 22 +-
content/handlers/html/font.c | 5 +-
content/handlers/html/font.h | 4 +-
content/handlers/html/form.c | 6 +-
content/handlers/html/html.c | 40 ++-
content/handlers/html/interaction.c | 8 +-
content/handlers/html/layout.c | 430 ++++++++++++++++++---------------
content/handlers/html/object.c | 14 +-
content/handlers/html/private.h | 5 +-
content/handlers/html/redraw.c | 72 +++---
content/handlers/html/table.c | 226 +++++++++--------
content/handlers/html/table.h | 8 +-
content/handlers/html/textselection.c | 18 +-
desktop/local_history_private.h | 8 +-
desktop/print.c | 38 +--
25 files changed, 542 insertions(+), 927 deletions(-)
delete mode 100644 content/handlers/css/utils.c
diff --git a/content/handlers/css/Makefile b/content/handlers/css/Makefile
index bbfc8d7..d5cf166 100644
--- a/content/handlers/css/Makefile
+++ b/content/handlers/css/Makefile
@@ -1,4 +1,4 @@
# CSS sources
-S_CSS := css.c dump.c internal.c hints.c select.c utils.c
+S_CSS := css.c dump.c internal.c hints.c select.c
diff --git a/content/handlers/css/css.c b/content/handlers/css/css.c
index be945fb..f9197dd 100644
--- a/content/handlers/css/css.c
+++ b/content/handlers/css/css.c
@@ -40,6 +40,9 @@
/* Define to trace import fetches */
#undef NSCSS_IMPORT_TRACE
+/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
+css_fixed nscss_screen_dpi = F_90;
+
struct content_css_data;
/**
diff --git a/content/handlers/css/dump.c b/content/handlers/css/dump.c
index b12e1d9..1e448e0 100644
--- a/content/handlers/css/dump.c
+++ b/content/handlers/css/dump.c
@@ -113,24 +113,15 @@ static void dump_css_unit(FILE *stream, css_fixed val, css_unit unit)
case CSS_UNIT_KHZ:
fprintf(stream, "kHz");
break;
- case CSS_UNIT_CAP:
- fprintf(stream, "cap");
- break;
case CSS_UNIT_CH:
fprintf(stream, "ch");
break;
- case CSS_UNIT_IC:
- fprintf(stream, "ic");
- break;
case CSS_UNIT_REM:
fprintf(stream, "rem");
break;
case CSS_UNIT_LH:
fprintf(stream, "lh");
break;
- case CSS_UNIT_RLH:
- fprintf(stream, "rlh");
- break;
case CSS_UNIT_VH:
fprintf(stream, "vh");
break;
diff --git a/content/handlers/css/select.c b/content/handlers/css/select.c
index 99840e9..6dc1d9b 100644
--- a/content/handlers/css/select.c
+++ b/content/handlers/css/select.c
@@ -91,10 +91,6 @@ static css_error set_libcss_node_data(void *pw, void *node,
static css_error get_libcss_node_data(void *pw, void *node,
void **libcss_node_data);
-static css_error nscss_compute_font_size(void *pw, const css_hint *parent,
- css_hint *size);
-
-
/**
* Selection callback table for libcss
*/
@@ -135,9 +131,8 @@ static css_select_handler selection_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
- nscss_compute_font_size,
set_libcss_node_data,
- get_libcss_node_data
+ get_libcss_node_data,
};
/**
@@ -250,12 +245,15 @@ static void nscss_dom_user_data_handler(dom_node_operation operation,
* \param ctx CSS selection context
* \param n Element to select for
* \param media Permitted media types
+ * \param unit_unit_len_ctx Unit length conversion context
* \param inline_style Inline style associated with element, or NULL
* \return Pointer to selection results (containing computed styles),
* or NULL on failure
*/
css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
- const css_media *media, const css_stylesheet *inline_style)
+ const css_media *media,
+ const css_unit_ctx *unit_len_ctx,
+ const css_stylesheet *inline_style)
{
css_computed_style *composed;
css_select_results *styles;
@@ -263,7 +261,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
css_error error;
/* Select style for node */
- error = css_select_style(ctx->ctx, n, media, inline_style,
+ error = css_select_style(ctx->ctx, n, unit_len_ctx, media, inline_style,
&selection_handler, ctx, &styles);
if (error != CSS_OK || styles == NULL) {
@@ -278,8 +276,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
* element's style */
error = css_computed_style_compose(ctx->parent_style,
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
- nscss_compute_font_size, ctx,
- &composed);
+ unit_len_ctx, &composed);
if (error != CSS_OK) {
css_select_results_destroy(styles);
return NULL;
@@ -310,8 +307,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
error = css_computed_style_compose(
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
styles->styles[pseudo_element],
- nscss_compute_font_size, ctx,
- &composed);
+ unit_len_ctx, &composed);
if (error != CSS_OK) {
/* TODO: perhaps this shouldn't be quite so
* catastrophic? */
@@ -330,11 +326,13 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
/**
* Get a blank style
*
- * \param ctx CSS selection context
- * \param parent Parent style to cascade inherited properties from
+ * \param ctx CSS selection context
+ * \param unit_unit_len_ctx Unit length conversion context
+ * \param parent Parent style to cascade inherited properties from
* \return Pointer to blank style, or NULL on failure
*/
css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *parent)
{
css_computed_style *partial, *composed;
@@ -349,7 +347,7 @@ css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
/* TODO: Do we really need to compose? Initial style shouldn't
* have any inherited properties. */
error = css_computed_style_compose(parent, partial,
- nscss_compute_font_size, ctx, &composed);
+ unit_len_ctx, &composed);
css_computed_style_destroy(partial);
if (error != CSS_OK) {
css_computed_style_destroy(composed);
@@ -359,133 +357,6 @@ css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
return composed;
}
-/**
- * Font size computation callback for libcss
- *
- * \param pw Computation context
- * \param parent Parent font size (absolute)
- * \param size Font size to compute
- * \return CSS_OK on success
- *
- * \post \a size will be an absolute font size
- */
-css_error nscss_compute_font_size(void *pw, const css_hint *parent,
- css_hint *size)
-{
- /**
- * Table of font-size keyword scale factors
- *
- * These are multiplied by the configured default font size
- * to produce an absolute size for the relevant keyword
- */
- static const css_fixed factors[] = {
- FLTTOFIX(0.5625), /* xx-small */
- FLTTOFIX(0.6250), /* x-small */
- FLTTOFIX(0.8125), /* small */
- FLTTOFIX(1.0000), /* medium */
- FLTTOFIX(1.1250), /* large */
- FLTTOFIX(1.5000), /* x-large */
- FLTTOFIX(2.0000) /* xx-large */
- };
- css_hint_length parent_size;
-
- /* Grab parent size, defaulting to medium if none */
- if (parent == NULL) {
- parent_size.value = FDIV(FMUL(factors[CSS_FONT_SIZE_MEDIUM - 1],
- INTTOFIX(nsoption_int(font_size))),
- INTTOFIX(10));
- parent_size.unit = CSS_UNIT_PT;
- } else {
- assert(parent->status == CSS_FONT_SIZE_DIMENSION);
- assert(parent->data.length.unit != CSS_UNIT_EM);
- assert(parent->data.length.unit != CSS_UNIT_EX);
- assert(parent->data.length.unit != CSS_UNIT_PCT);
-
- parent_size = parent->data.length;
- }
-
- assert(size->status != CSS_FONT_SIZE_INHERIT);
-
- if (size->status < CSS_FONT_SIZE_LARGER) {
- /* Keyword -- simple */
- size->data.length.value = FDIV(FMUL(factors[size->status - 1],
- INTTOFIX(nsoption_int(font_size))), F_10);
- size->data.length.unit = CSS_UNIT_PT;
- } else if (size->status == CSS_FONT_SIZE_LARGER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size.value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size.unit;
- } else if (size->status == CSS_FONT_SIZE_SMALLER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FDIV(parent_size.value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size.unit;
- } else if (size->data.length.unit == CSS_UNIT_EM ||
- size->data.length.unit == CSS_UNIT_EX ||
- size->data.length.unit == CSS_UNIT_CAP ||
- size->data.length.unit == CSS_UNIT_CH ||
- size->data.length.unit == CSS_UNIT_IC) {
- size->data.length.value =
- FMUL(size->data.length.value, parent_size.value);
-
- switch (size->data.length.unit) {
- case CSS_UNIT_EX:
- /* 1ex = 0.6em in NetSurf */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.6));
- break;
- case CSS_UNIT_CAP:
- /* Height of captals. 1cap = 0.9em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.9));
- break;
- case CSS_UNIT_CH:
- /* Width of '0'. 1ch = 0.4em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.4));
- break;
- case CSS_UNIT_IC:
- /* Width of U+6C43. 1ic = 1.1em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(1.1));
- break;
- default:
- /* No scaling required for EM. */
- break;
- }
-
- size->data.length.unit = parent_size.unit;
- } else if (size->data.length.unit == CSS_UNIT_PCT) {
- size->data.length.value = FDIV(FMUL(size->data.length.value,
- parent_size.value), INTTOFIX(100));
- size->data.length.unit = parent_size.unit;
- } else if (size->data.length.unit == CSS_UNIT_REM) {
- nscss_select_ctx *ctx = pw;
- if (parent == NULL) {
- size->data.length.value = parent_size.value;
- size->data.length.unit = parent_size.unit;
- } else {
- css_computed_font_size(ctx->root_style,
- &parent_size.value,
- &size->data.length.unit);
- size->data.length.value = FMUL(
- size->data.length.value,
- parent_size.value);
- }
- } else if (size->data.length.unit == CSS_UNIT_RLH) {
- /** TODO: Convert root element line-height to absolute value. */
- size->data.length.value = FMUL(size->data.length.value, FDIV(
- INTTOFIX(nsoption_int(font_size)),
- INTTOFIX(10)));
- size->data.length.unit = CSS_UNIT_PT;
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
/******************************************************************************
* Style selection callbacks *
******************************************************************************/
diff --git a/content/handlers/css/select.h b/content/handlers/css/select.h
index b45d1ed..c17caad 100644
--- a/content/handlers/css/select.h
+++ b/content/handlers/css/select.h
@@ -45,9 +45,12 @@ css_stylesheet *nscss_create_inline_style(const uint8_t *data, size_t len,
const char *charset, const char *url, bool allow_quirks);
css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
- const css_media *media, const css_stylesheet *inline_style);
+ const css_media *media,
+ const css_unit_ctx *unit_len_ctx,
+ const css_stylesheet *inline_style);
css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *parent);
diff --git a/content/handlers/css/utils.c b/content/handlers/css/utils.c
deleted file mode 100644
index cf48e89..0000000
--- a/content/handlers/css/utils.c
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright 2004 James Bursa <james(a)netsurf-browser.org>
- * Copyright 2009 John-Mark Bell <jmb(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/>.
- */
-
-#include <assert.h>
-
-#include "utils/nsoption.h"
-#include "utils/log.h"
-
-#include "css/utils.h"
-
-/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
-css_fixed nscss_screen_dpi = F_90;
-
-/** Medium screen density for device viewing distance. */
-css_fixed nscss_baseline_pixel_density = F_96;
-
-/**
- * Map viewport-relative length units to either vh or vw.
- *
- * Non-viewport-relative units are unchanged.
- *
- * \param[in] ctx Length conversion context.
- * \param[in] unit Unit to map.
- * \return the mapped unit.
- */
-static inline css_unit css_utils__fudge_viewport_units(
- const nscss_len_ctx *ctx,
- css_unit unit)
-{
- switch (unit) {
- case CSS_UNIT_VI:
- assert(ctx->root_style != NULL);
- if (css_computed_writing_mode(ctx->root_style) ==
- CSS_WRITING_MODE_HORIZONTAL_TB) {
- unit = CSS_UNIT_VW;
- } else {
- unit = CSS_UNIT_VH;
- }
- break;
- case CSS_UNIT_VB:
- assert(ctx->root_style != NULL);
- if (css_computed_writing_mode(ctx->root_style) ==
- CSS_WRITING_MODE_HORIZONTAL_TB) {
- unit = CSS_UNIT_VH;
- } else {
- unit = CSS_UNIT_VW;
- }
- break;
- case CSS_UNIT_VMIN:
- if (ctx->vh < ctx->vw) {
- unit = CSS_UNIT_VH;
- } else {
- unit = CSS_UNIT_VW;
- }
- break;
- case CSS_UNIT_VMAX:
- if (ctx->vh > ctx->vw) {
- unit = CSS_UNIT_VH;
- } else {
- unit = CSS_UNIT_VW;
- }
- break;
- default: break;
- }
-
- return unit;
-}
-
-/* exported interface documented in content/handlers/css/utils.h */
-css_fixed nscss_len2pt(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit)
-{
- /* Length must not be relative */
- assert(unit != CSS_UNIT_EM &&
- unit != CSS_UNIT_EX &&
- unit != CSS_UNIT_CAP &&
- unit != CSS_UNIT_CH &&
- unit != CSS_UNIT_IC &&
- unit != CSS_UNIT_REM &&
- unit != CSS_UNIT_RLH);
-
- unit = css_utils__fudge_viewport_units(ctx, unit);
-
- switch (unit) {
- /* We assume the screen and any other output has the same dpi */
- /* 1in = DPIpx => 1px = (72/DPI)pt */
- case CSS_UNIT_PX: return FDIV(FMUL(length, F_72), F_96);
- /* 1in = 72pt */
- case CSS_UNIT_IN: return FMUL(length, F_72);
- /* 1in = 2.54cm => 1cm = (72/2.54)pt */
- case CSS_UNIT_CM: return FMUL(length,
- FDIV(F_72, FLTTOFIX(2.54)));
- /* 1in = 25.4mm => 1mm = (72/25.4)pt */
- case CSS_UNIT_MM: return FMUL(length,
- FDIV(F_72, FLTTOFIX(25.4)));
- /* 1in = 101.6q => 1mm = (72/101.6)pt */
- case CSS_UNIT_Q: return FMUL(length,
- FDIV(F_72, FLTTOFIX(101.6)));
- case CSS_UNIT_PT: return length;
- /* 1pc = 12pt */
- case CSS_UNIT_PC: return FMUL(length, INTTOFIX(12));
- case CSS_UNIT_VH: return FDIV(FMUL(FDIV(FMUL(length, ctx->vh), F_100), F_72), F_96);
- case CSS_UNIT_VW: return FDIV(FMUL(FDIV(FMUL(length,ctx->vw), F_100), F_72), F_96);
- default: break;
- }
-
- return 0;
-}
-
-/* exported interface documented in content/handlers/css/utils.h */
-css_fixed nscss_len2px(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit,
- const css_computed_style *style)
-{
- /* We assume the screen and any other output has the same dpi */
- css_fixed px_per_unit;
-
- unit = css_utils__fudge_viewport_units(ctx, unit);
-
- switch (unit) {
- case CSS_UNIT_EM:
- case CSS_UNIT_EX:
- case CSS_UNIT_CAP:
- case CSS_UNIT_CH:
- case CSS_UNIT_IC:
- {
- css_fixed font_size = 0;
- css_unit font_unit = CSS_UNIT_PT;
-
- assert(style != NULL);
-
- css_computed_font_size(style, &font_size, &font_unit);
-
- /* Convert to points */
- font_size = nscss_len2pt(ctx, font_size, font_unit);
-
- /* Clamp to configured minimum */
- if (font_size < FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)) {
- font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10);
- }
-
- /* Convert to pixels (manually, to maximise precision)
- * 1in = 72pt => 1pt = (DPI/72)px */
- px_per_unit = FDIV(FMUL(font_size, F_96), F_72);
-
- /* Scale non-em units to em. We have fixed ratios. */
- switch (unit) {
- case CSS_UNIT_EX:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
- break;
- case CSS_UNIT_CAP:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.9));
- break;
- case CSS_UNIT_CH:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
- break;
- case CSS_UNIT_IC:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(1.1));
- break;
- default: break;
- }
- }
- break;
- case CSS_UNIT_PX:
- px_per_unit = F_1;
- break;
- /* 1in = 96 CSS pixels */
- case CSS_UNIT_IN:
- px_per_unit = F_96;
- break;
- /* 1in = 2.54cm => 1cm = (DPI/2.54)px */
- case CSS_UNIT_CM:
- px_per_unit = FDIV(F_96, FLTTOFIX(2.54));
- break;
- /* 1in = 25.4mm => 1mm = (DPI/25.4)px */
- case CSS_UNIT_MM:
- px_per_unit = FDIV(F_96, FLTTOFIX(25.4));
- break;
- /* 1in = 101.6q => 1q = (DPI/101.6)px */
- case CSS_UNIT_Q:
- px_per_unit = FDIV(F_96, FLTTOFIX(101.6));
- break;
- /* 1in = 72pt => 1pt = (DPI/72)px */
- case CSS_UNIT_PT:
- px_per_unit = FDIV(F_96, F_72);
- break;
- /* 1pc = 12pt => 1in = 6pc => 1pc = (DPI/6)px */
- case CSS_UNIT_PC:
- px_per_unit = FDIV(F_96, INTTOFIX(6));
- break;
- case CSS_UNIT_REM:
- {
- css_fixed font_size = 0;
- css_unit font_unit = CSS_UNIT_PT;
-
- assert(ctx->root_style != NULL);
-
- css_computed_font_size(ctx->root_style,
- &font_size, &font_unit);
-
- /* Convert to points */
- font_size = nscss_len2pt(ctx, font_size, font_unit);
-
- /* Clamp to configured minimum */
- if (font_size < FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)) {
- font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10);
- }
-
- /* Convert to pixels (manually, to maximise precision)
- * 1in = 72pt => 1pt = (DPI/72)px */
- px_per_unit = FDIV(FMUL(font_size, F_96), F_72);
- break;
- }
- /* 1rlh = <user_font_size>pt => 1rlh = (DPI/user_font_size)px */
- case CSS_UNIT_RLH:
- px_per_unit = FDIV(F_96, FDIV(
- INTTOFIX(nsoption_int(font_size)),
- INTTOFIX(10)));
- break;
- case CSS_UNIT_VH:
- px_per_unit = FDIV(ctx->vh, F_100);
- break;
- case CSS_UNIT_VW:
- px_per_unit = FDIV(ctx->vw, F_100);
- break;
- default:
- px_per_unit = 0;
- break;
- }
-
- px_per_unit = nscss_pixels_css_to_physical(px_per_unit);
-
- /* Ensure we round px_per_unit to the nearest whole number of pixels:
- * the use of FIXTOINT() below will truncate. */
- px_per_unit += F_0_5;
-
- /* Calculate total number of pixels */
- return FMUL(length, TRUNCATEFIX(px_per_unit));
-}
diff --git a/content/handlers/css/utils.h b/content/handlers/css/utils.h
index e35a660..541677a 100644
--- a/content/handlers/css/utils.h
+++ b/content/handlers/css/utils.h
@@ -26,85 +26,6 @@
/** DPI of the screen, in fixed point units */
extern css_fixed nscss_screen_dpi;
-/** Medium screen density for device viewing distance. */
-extern css_fixed nscss_baseline_pixel_density;
-
-/**
- * Length conversion context data.
- */
-typedef struct nscss_len_ctx {
- /**
- * Viewport width in px.
- * Only used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- int vw;
- /**
- * Viewport height in px.
- * Only used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- int vh;
- /**
- * Computed style for the document root element.
- * May be NULL if unit is not rem, or rlh.
- */
- const css_computed_style *root_style;
-} nscss_len_ctx;
-
-/**
- * Convert an absolute CSS length to points.
- *
- * \param[in] ctx Length conversion context.
- * \param[in] length Absolute CSS length.
- * \param[in] unit Unit of the length.
- * \return length in points
- */
-css_fixed nscss_len2pt(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit);
-
-/**
- * Convert a CSS length to pixels.
- *
- * \param[in] ctx Length conversion context.
- * \param[in] length Length to convert.
- * \param[in] unit Corresponding unit.
- * \param[in] style Computed style applying to length.
- * May be NULL if unit is not em, ex, cap, ch, or ic.
- * \return length in pixels
- */
-css_fixed nscss_len2px(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit,
- const css_computed_style *style);
-
-/**
- * Convert css pixels to physical pixels.
- *
- * \param[in] css_pixels Length in css pixels.
- * \return length in physical pixels
- */
-static inline css_fixed nscss_pixels_css_to_physical(
- css_fixed css_pixels)
-{
- return FDIV(FMUL(css_pixels, nscss_screen_dpi),
- nscss_baseline_pixel_density);
-}
-
-/**
- * Convert physical pixels to css pixels.
- *
- * \param[in] physical_pixels Length in physical pixels.
- * \return length in css pixels
- */
-static inline css_fixed nscss_pixels_physical_to_css(
- css_fixed physical_pixels)
-{
- return FDIV(FMUL(physical_pixels, nscss_baseline_pixel_density),
- nscss_screen_dpi);
-}
-
/**
* Temporary helper wrappers for for libcss computed style getter, while
* we don't support flexbox related property values.
diff --git a/content/handlers/html/box_construct.c b/content/handlers/html/box_construct.c
index 7bfc35e..12d9df8 100644
--- a/content/handlers/html/box_construct.c
+++ b/content/handlers/html/box_construct.c
@@ -282,7 +282,8 @@ box_get_style(html_content *c,
ctx.parent_style = parent_style;
/* Select style for element */
- styles = nscss_get_style(&ctx, n, &c->media, inline_style);
+ styles = nscss_get_style(&ctx, n, &c->media, &c->unit_len_ctx,
+ inline_style);
/* No longer need inline style */
if (inline_style != NULL)
diff --git a/content/handlers/html/box_inspect.c b/content/handlers/html/box_inspect.c
index df9a1b4..b4b1394 100644
--- a/content/handlers/html/box_inspect.c
+++ b/content/handlers/html/box_inspect.c
@@ -56,7 +56,7 @@ enum box_walk_dir {
/**
* Determine if a point lies within a box.
*
- * \param[in] len_ctx CSS length conversion context to use.
+ * \param[in] unit_len_ctx CSS length conversion context to use.
* \param[in] box Box to consider
* \param[in] x Coordinate relative to box
* \param[in] y Coordinate relative to box
@@ -71,7 +71,7 @@ enum box_walk_dir {
* This is a helper function for box_at_point().
*/
static bool
-box_contains_point(const nscss_len_ctx *len_ctx,
+box_contains_point(const css_unit_ctx *unit_len_ctx,
const struct box *box,
int x,
int y,
@@ -101,30 +101,34 @@ box_contains_point(const nscss_len_ctx *len_ctx,
/* Adjust rect to css clip region */
if (css_rect.left_auto == false) {
- r.x0 += FIXTOINT(nscss_len2px(len_ctx,
- css_rect.left,
- css_rect.lunit,
- box->style));
+ r.x0 += FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.left,
+ css_rect.lunit));
}
if (css_rect.top_auto == false) {
- r.y0 += FIXTOINT(nscss_len2px(len_ctx,
- css_rect.top,
- css_rect.tunit,
- box->style));
+ r.y0 += FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.top,
+ css_rect.tunit));
}
if (css_rect.right_auto == false) {
r.x1 = box->border[LEFT].width +
- FIXTOINT(nscss_len2px(len_ctx,
- css_rect.right,
- css_rect.runit,
- box->style));
+ FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.right,
+ css_rect.runit));
}
if (css_rect.bottom_auto == false) {
r.y1 = box->border[TOP].width +
- FIXTOINT(nscss_len2px(len_ctx,
- css_rect.bottom,
- css_rect.bunit,
- box->style));
+ FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.bottom,
+ css_rect.bunit));
}
/* Test if point is in clipped box */
@@ -575,7 +579,7 @@ void box_bounds(struct box *box, struct rect *r)
/* Exported function documented in html/box.h */
struct box *
-box_at_point(const nscss_len_ctx *len_ctx,
+box_at_point(const css_unit_ctx *unit_len_ctx,
struct box *box,
const int x, const int y,
int *box_x, int *box_y)
@@ -587,7 +591,7 @@ box_at_point(const nscss_len_ctx *len_ctx,
skip_children = false;
while ((box = box_next_xy(box, box_x, box_y, skip_children))) {
- if (box_contains_point(len_ctx, box, x - *box_x, y - *box_y,
+ if (box_contains_point(unit_len_ctx, box, x - *box_x, y - *box_y,
&physically)) {
*box_x -= scrollbar_get_offset(box->scroll_x);
*box_y -= scrollbar_get_offset(box->scroll_y);
diff --git a/content/handlers/html/box_inspect.h b/content/handlers/html/box_inspect.h
index d50b848..b9161f1 100644
--- a/content/handlers/html/box_inspect.h
+++ b/content/handlers/html/box_inspect.h
@@ -46,7 +46,7 @@ void box_bounds(struct box *box, struct rect *r);
/**
* Find the boxes at a point.
*
- * \param len_ctx CSS length conversion context for document.
+ * \param unit_len_ctx CSS length conversion context for document.
* \param box box to search children of
* \param x point to find, in global document coordinates
* \param y point to find, in global document coordinates
@@ -62,12 +62,12 @@ void box_bounds(struct box *box, struct rect *r);
* struct box *box = top_of_document_to_search;
* int box_x = 0, box_y = 0;
*
- * while ((box = box_at_point(len_ctx, box, x, y, &box_x, &box_y))) {
+ * while ((box = box_at_point(unit_len_ctx, box, x, y, &box_x, &box_y))) {
* // process box
* }
* \endcode
*/
-struct box *box_at_point(const nscss_len_ctx *len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
+struct box *box_at_point(const css_unit_ctx *unit_len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
/**
diff --git a/content/handlers/html/box_normalise.c b/content/handlers/html/box_normalise.c
index b7032da..1b6a345 100644
--- a/content/handlers/html/box_normalise.c
+++ b/content/handlers/html/box_normalise.c
@@ -190,7 +190,8 @@ box_normalise_table_row(struct box *row,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, row->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row->style);
if (style == NULL)
return false;
@@ -326,7 +327,8 @@ box_normalise_table_row_group(struct box *row_group,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, row_group->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row_group->style);
if (style == NULL)
return false;
@@ -402,7 +404,8 @@ box_normalise_table_row_group(struct box *row_group,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, row_group->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row_group->style);
if (style == NULL) {
return false;
}
@@ -533,6 +536,7 @@ box_normalise_table_spans(struct box *table,
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx,
+ &c->unit_len_ctx,
table_row->style);
if (style == NULL)
return false;
@@ -657,7 +661,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, table->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ table->style);
if (style == NULL) {
free(col_info.spans);
return false;
@@ -744,7 +749,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, table->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ table->style);
if (style == NULL) {
free(col_info.spans);
return false;
@@ -759,7 +765,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
}
row_group->type = BOX_TABLE_ROW_GROUP;
- style = nscss_get_blank_style(&ctx, row_group->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row_group->style);
if (style == NULL) {
box_free(row_group);
free(col_info.spans);
@@ -948,7 +955,8 @@ box_normalise_block(struct box *block, const struct box *root, html_content *c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, block->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ block->style);
if (style == NULL)
return false;
diff --git a/content/handlers/html/font.c b/content/handlers/html/font.c
index 7ebe168..4a64759 100644
--- a/content/handlers/html/font.c
+++ b/content/handlers/html/font.c
@@ -133,7 +133,7 @@ static plot_font_flags_t plot_font_flags(enum css_font_style_e style,
/* exported function documented in html/font.h */
void font_plot_style_from_css(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *css,
plot_font_style_t *fstyle)
{
@@ -147,7 +147,8 @@ void font_plot_style_from_css(
fstyle->families = families;
css_computed_font_size(css, &length, &unit);
- fstyle->size = FIXTOINT(FMUL(nscss_len2pt(len_ctx, length, unit),
+ fstyle->size = FIXTOINT(FMUL(css_unit_font_size_len2pt(css,
+ unit_len_ctx, length, unit),
INTTOFIX(PLOT_STYLE_SCALE)));
/* Clamp font size to configured minimum */
diff --git a/content/handlers/html/font.h b/content/handlers/html/font.h
index 5f69ee7..26f5bf2 100644
--- a/content/handlers/html/font.h
+++ b/content/handlers/html/font.h
@@ -32,11 +32,11 @@ struct plot_font_style;
/**
* Populate a font style using data from a computed CSS style
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param css Computed style to consider
* \param fstyle Font style to populate
*/
-void font_plot_style_from_css(const nscss_len_ctx *len_ctx,
+void font_plot_style_from_css(const css_unit_ctx *unit_len_ctx,
const css_computed_style *css,
struct plot_font_style *fstyle);
diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c
index 01e6244..97ec195 100644
--- a/content/handlers/html/form.c
+++ b/content/handlers/html/form.c
@@ -1594,12 +1594,12 @@ form_open_select_menu(void *client_data,
box->border[RIGHT].width + box->padding[RIGHT] +
box->border[LEFT].width + box->padding[LEFT];
- font_plot_style_from_css(&html->len_ctx, control->box->style,
- &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx,
+ control->box->style, &fstyle);
menu->f_size = fstyle.size;
menu->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2),
- FMUL(nscss_screen_dpi,
+ FMUL(html->unit_len_ctx.device_dpi,
INTTOFIX(fstyle.size / PLOT_STYLE_SCALE)))),
F_72));
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index 5b74e42..c6a2872 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -305,6 +305,9 @@ html_proceed_to_done(html_content *html)
static void html_get_dimensions(html_content *htmlc)
{
+ css_fixed device_dpi = nscss_screen_dpi;
+ unsigned f_size;
+ unsigned f_min;
unsigned w;
unsigned h;
union content_msg_data msg_data = {
@@ -316,13 +319,22 @@ static void html_get_dimensions(html_content *htmlc)
content_broadcast(&htmlc->base, CONTENT_MSG_GETDIMS, &msg_data);
- htmlc->media.width = nscss_pixels_physical_to_css(INTTOFIX(w));
- htmlc->media.height = nscss_pixels_physical_to_css(INTTOFIX(h));
- htmlc->media.client_font_size =
- FDIV(INTTOFIX(nsoption_int(font_size)), F_10);
- htmlc->media.client_line_height =
- FMUL(nscss_len2px(NULL, htmlc->media.client_font_size,
- CSS_UNIT_PT, NULL), FLTTOFIX(1.33));
+
+ w = css_unit_device2css_px(INTTOFIX(w), device_dpi);
+ h = css_unit_device2css_px(INTTOFIX(h), device_dpi);
+
+ htmlc->media.width = w;
+ htmlc->media.height = h;
+ htmlc->unit_len_ctx.viewport_width = w;
+ htmlc->unit_len_ctx.viewport_height = h;
+ htmlc->unit_len_ctx.device_dpi = device_dpi;
+
+ /** \todo Change nsoption font sizes to px. */
+ f_size = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_size)), F_10)), F_72);
+ f_min = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)), F_72);
+
+ htmlc->unit_len_ctx.font_size_default = f_size;
+ htmlc->unit_len_ctx.font_size_minimum = f_min;
}
/* exported function documented in html/html_internal.h */
@@ -1035,9 +1047,11 @@ static void html_reformat(struct content *c, int width, int height)
htmlc->reflowing = true;
- htmlc->len_ctx.vw = nscss_pixels_physical_to_css(INTTOFIX(width));
- htmlc->len_ctx.vh = nscss_pixels_physical_to_css(INTTOFIX(height));
- htmlc->len_ctx.root_style = htmlc->layout->style;
+ htmlc->unit_len_ctx.viewport_width = css_unit_device2css_px(
+ INTTOFIX(width), htmlc->unit_len_ctx.device_dpi);
+ htmlc->unit_len_ctx.viewport_height = css_unit_device2css_px(
+ INTTOFIX(height), htmlc->unit_len_ctx.device_dpi);
+ htmlc->unit_len_ctx.root_style = htmlc->layout->style;
layout_document(htmlc, width, height);
layout = htmlc->layout;
@@ -1427,7 +1441,7 @@ html_get_contextual_content(struct content *c, int x, int y,
struct box *next;
int box_x = 0, box_y = 0;
- while ((next = box_at_point(&html->len_ctx, box, x, y,
+ while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
@@ -1508,7 +1522,7 @@ html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
/* TODO: invert order; visit deepest box first */
- while ((next = box_at_point(&html->len_ctx, box, x, y,
+ while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
@@ -1657,7 +1671,7 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
int box_x = 0, box_y = 0;
/* Scan box tree for boxes that can handle drop */
- while ((next = box_at_point(&html->len_ctx, box, x, y,
+ while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
diff --git a/content/handlers/html/interaction.c b/content/handlers/html/interaction.c
index 90e7b76..026ef1e 100644
--- a/content/handlers/html/interaction.c
+++ b/content/handlers/html/interaction.c
@@ -211,7 +211,7 @@ static size_t html_selection_drag_end(struct html_content *html,
if (box) {
plot_font_style_t fstyle;
- font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
guit->layout->position(&fstyle, box->text, box->length,
dx, &idx, &pixel_offset);
@@ -424,7 +424,7 @@ mouse_action_drag_selection(html_content *html,
box = box_pick_text_box(html, x, y, dir, &dx, &dy);
if (box != NULL) {
- font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
guit->layout->position(&fstyle,
box->text,
@@ -805,7 +805,7 @@ get_mouse_action_node(html_content *html,
next_box:
/* iterate to next box */
- box = box_at_point(&html->len_ctx, box, x, y, &box_x, &box_y);
+ box = box_at_point(&html->unit_len_ctx, box, x, y, &box_x, &box_y);
} while (box != NULL);
/* use of box_x, box_y, or content below this point is probably a
@@ -1209,7 +1209,7 @@ default_mouse_action(html_content *html,
size_t idx;
plot_font_style_t fstyle;
- font_plot_style_from_css(&html->len_ctx,
+ font_plot_style_from_css(&html->unit_len_ctx,
mas->text.box->style,
&fstyle);
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index c8c0127..c06fdf6 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -133,7 +133,6 @@ static void layout_minmax_block(
const struct gui_layout_table *font_func,
const html_content *content);
-
/**
* Compute the size of replaced boxes with auto dimensions, according to
* content.
@@ -246,7 +245,7 @@ layout_get_object_dimensions(struct box *box,
* \return length of indent
*/
static int layout_text_indent(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *style, int width)
{
css_fixed value = 0;
@@ -257,7 +256,8 @@ static int layout_text_indent(
if (unit == CSS_UNIT_PCT) {
return FPCT_OF_INT_TOINT(value, width);
} else {
- return FIXTOINT(nscss_len2px(len_ctx, value, unit, style));
+ return FIXTOINT(css_unit_len2device_px(style, unit_len_ctx,
+ value, unit));
}
}
@@ -265,7 +265,7 @@ static int layout_text_indent(
/**
* Determine width of margin, borders, and padding on one side of a box.
*
- * \param len_ctx CSS length conversion context for document
+ * \param unit_len_ctx CSS length conversion context for document
* \param style style to measure
* \param side side of box to measure
* \param margin whether margin width is required
@@ -275,7 +275,7 @@ static int layout_text_indent(
* \param frac increased by sum of fractional margin and padding
*/
static void
-calculate_mbp_width(const nscss_len_ctx *len_ctx,
+calculate_mbp_width(const css_unit_ctx *unit_len_ctx,
const css_computed_style *style,
unsigned int side,
bool margin,
@@ -298,8 +298,9 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
if (unit == CSS_UNIT_PCT) {
*frac += FIXTOINT(FDIV(value, F_100));
} else {
- *fixed += FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *fixed += FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
}
@@ -310,8 +311,9 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
CSS_BORDER_STYLE_NONE) {
border_width_funcs[side](style, &value, &unit);
- *fixed += FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *fixed += FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
@@ -321,8 +323,9 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
if (unit == CSS_UNIT_PCT) {
*frac += FIXTOINT(FDIV(value, F_100));
} else {
- *fixed += FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *fixed += FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
}
@@ -356,7 +359,7 @@ static void layout_minmax_table(struct box *table,
if (table->max_width != UNKNOWN_MAX_WIDTH)
return;
- if (table_calculate_column_types(&content->len_ctx, table) == false) {
+ if (table_calculate_column_types(&content->unit_len_ctx, table) == false) {
NSLOG(netsurf, WARNING,
"Could not establish table column types.");
return;
@@ -379,8 +382,10 @@ static void layout_minmax_table(struct box *table,
css_computed_border_spacing(table->style, &h, &hu, &v, &vu);
- border_spacing_h = FIXTOINT(nscss_len2px(&content->len_ctx,
- h, hu, table->style));
+ border_spacing_h = FIXTOINT(css_unit_len2device_px(
+ table->style,
+ &content->unit_len_ctx,
+ h, hu));
}
/* 1st pass: consider cells with colspan 1 only */
@@ -485,8 +490,10 @@ static void layout_minmax_table(struct box *table,
/* fixed width takes priority, unless it is too narrow */
wtype = css_computed_width(table->style, &value, &unit);
if (wtype == CSS_WIDTH_SET && unit != CSS_UNIT_PCT) {
- int width = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, table->style));
+ int width = FIXTOINT(css_unit_len2device_px(
+ table->style,
+ &content->unit_len_ctx,
+ value, unit));
if (table_min < width)
table_min = width;
if (table_max < width)
@@ -494,10 +501,10 @@ static void layout_minmax_table(struct box *table,
}
/* add margins, border, padding to min, max widths */
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
table->style, LEFT, true, true, true,
&extra_fixed, &extra_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
table->style, RIGHT, true, true, true,
&extra_fixed, &extra_frac);
if (extra_fixed < 0)
@@ -622,17 +629,17 @@ layout_minmax_line(struct box *first,
}
assert(b->style);
- font_plot_style_from_css(&content->len_ctx, b->style, &fstyle);
+ font_plot_style_from_css(&content->unit_len_ctx, b->style, &fstyle);
if (b->type == BOX_INLINE && !b->object &&
!(b->flags & REPLACE_DIM) &&
!(b->flags & IFRAME)) {
fixed = frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT, true, true, true,
&fixed, &frac);
if (!b->inline_end)
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -642,7 +649,7 @@ layout_minmax_line(struct box *first,
/* \todo update min width, consider fractional extra */
} else if (b->type == BOX_INLINE_END) {
fixed = frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->inline_end->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -760,16 +767,18 @@ layout_minmax_line(struct box *first,
if (unit == CSS_UNIT_PCT) {
width = AUTO;
} else {
- width = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, b->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx,
+ value, unit));
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
fixed = frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT,
false, true, true,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT,
false, true, true,
&fixed, &frac);
@@ -787,8 +796,10 @@ layout_minmax_line(struct box *first,
/* height */
htype = css_computed_height(b->style, &value, &unit);
if (htype == CSS_HEIGHT_SET) {
- height = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, b->style));
+ height = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx,
+ value, unit));
} else {
height = AUTO;
}
@@ -804,20 +815,20 @@ layout_minmax_line(struct box *first,
fixed = frac = 0;
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, false, false,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, false, false,
&fixed, &frac);
} else {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, true, true,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -831,20 +842,20 @@ layout_minmax_line(struct box *first,
fixed = frac = 0;
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, false, false,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, false, false,
&fixed, &frac);
} else {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, true, true,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -856,10 +867,10 @@ layout_minmax_line(struct box *first,
} else {
/* form control with no object */
if (width == AUTO)
- width = FIXTOINT(nscss_len2px(
- &content->len_ctx,
- INTTOFIX(1), CSS_UNIT_EM,
- b->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx,
+ INTTOFIX(1), CSS_UNIT_EM));
}
if (min < width && !box_has_percentage_max_width(b))
@@ -873,7 +884,7 @@ layout_minmax_line(struct box *first,
if (first_line) {
/* todo: handle percentage values properly */
/* todo: handle text-indent interaction with floats */
- int text_indent = layout_text_indent(&content->len_ctx,
+ int text_indent = layout_text_indent(&content->unit_len_ctx,
first->parent->parent->style, 100);
min = (min + text_indent < 0) ? 0 : min + text_indent;
max = (max + text_indent < 0) ? 0 : max + text_indent;
@@ -1006,8 +1017,8 @@ static void layout_minmax_block(
css_fixed size = INTTOFIX(10);
css_unit unit = CSS_UNIT_EM;
- min = max = FIXTOINT(nscss_len2px(&content->len_ctx,
- size, unit, block->style));
+ min = max = FIXTOINT(css_unit_len2device_px(block->style,
+ &content->unit_len_ctx, size, unit));
block->flags |= HAS_HEIGHT;
}
@@ -1020,8 +1031,8 @@ static void layout_minmax_block(
/* form checkbox or radio button
* if width is AUTO, set it to 1em */
- min = max = FIXTOINT(nscss_len2px(&content->len_ctx,
- size, unit, block->style));
+ min = max = FIXTOINT(css_unit_len2device_px(block->style,
+ &content->unit_len_ctx, size, unit));
block->flags |= HAS_HEIGHT;
}
@@ -1104,16 +1115,16 @@ static void layout_minmax_block(
/* fixed width takes priority */
if (block->type != BOX_TABLE_CELL && wtype == CSS_WIDTH_SET &&
wunit != CSS_UNIT_PCT) {
- min = max = FIXTOINT(nscss_len2px(&content->len_ctx,
- width, wunit, block->style));
+ min = max = FIXTOINT(css_unit_len2device_px(block->style,
+ &content->unit_len_ctx, width, wunit));
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
int border_box_fixed = 0;
float border_box_frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT,
false, true, true,
&border_box_fixed, &border_box_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT,
false, true, true,
&border_box_fixed, &border_box_frac);
@@ -1134,17 +1145,17 @@ static void layout_minmax_block(
* and paddings are wrong. */
if (bs == CSS_BOX_SIZING_BORDER_BOX && wtype == CSS_WIDTH_SET) {
/* Border and padding included in width, so just get margin */
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT, true, false, false,
&extra_fixed, &extra_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT, true, false, false,
&extra_fixed, &extra_frac);
} else {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT, true, true, true,
&extra_fixed, &extra_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT, true, true, true,
&extra_fixed, &extra_frac);
}
@@ -1175,7 +1186,7 @@ static void layout_minmax_block(
*
* This turns the specified dimension into a content-box dimension.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box gadget to adjust dimensions of
* \param available_width width of containing block
* \param setwidth set true if the dimension to be tweaked is a width,
@@ -1185,7 +1196,7 @@ static void layout_minmax_block(
* gadget properties.
*/
static void layout_handle_box_sizing(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
int available_width,
bool setwidth,
@@ -1202,10 +1213,10 @@ static void layout_handle_box_sizing(
int fixed = 0;
float frac = 0;
- calculate_mbp_width(len_ctx, box->style,
+ calculate_mbp_width(unit_len_ctx, box->style,
setwidth ? LEFT : TOP,
false, true, true, &fixed, &frac);
- calculate_mbp_width(len_ctx, box->style,
+ calculate_mbp_width(unit_len_ctx, box->style,
setwidth ? RIGHT : BOTTOM,
false, true, true, &fixed, &frac);
orig -= frac * available_width + fixed;
@@ -1217,7 +1228,7 @@ static void layout_handle_box_sizing(
/**
* Calculate width, height, and thickness of margins, paddings, and borders.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param available_width width of containing block
* \param viewport_height height of viewport in pixels or -ve if unknown
* \param box current box
@@ -1234,7 +1245,7 @@ static void layout_handle_box_sizing(
* \param border filled with border widths, may be NULL
*/
static void
-layout_find_dimensions(const nscss_len_ctx *len_ctx,
+layout_find_dimensions(const css_unit_ctx *unit_len_ctx,
int available_width,
int viewport_height,
struct box *box,
@@ -1264,15 +1275,16 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*width = FPCT_OF_INT_TOINT(
value, available_width);
} else {
- *width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
*width = AUTO;
}
if (*width != AUTO) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
true, width);
}
}
@@ -1352,15 +1364,16 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*height = AUTO;
}
} else {
- *height = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *height = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
*height = AUTO;
}
if (*height != AUTO) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
false, height);
}
}
@@ -1377,8 +1390,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*max_width = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- *max_width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *max_width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1386,7 +1400,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
}
if (*max_width != -1) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
true, max_width);
}
}
@@ -1403,8 +1417,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*min_width = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- *min_width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *min_width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1412,7 +1427,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
}
if (*min_width != 0) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
true, min_width);
}
}
@@ -1429,8 +1444,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/* TODO: handle percentage */
*max_height = -1;
} else {
- *max_height = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *max_height = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1450,8 +1466,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/* TODO: handle percentage */
*min_height = 0;
} else {
- *min_height = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *min_height = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1472,9 +1489,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
margin[i] = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- margin[i] = FIXTOINT(nscss_len2px(
- len_ctx,
- value, unit, style));
+ margin[i] = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
margin[i] = AUTO;
@@ -1491,8 +1508,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
padding[i] = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- padding[i] = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ padding[i] = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
@@ -1515,8 +1533,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/* spec unclear: following Mozilla */
border[i].width = 0;
else
- border[i].width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ border[i].width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
/* Special case for border-collapse: make all borders
* on table/table-row-group/table-row zero width. */
@@ -1534,7 +1553,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/**
* Find next block that current margin collapses to.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box to start tree-order search from (top margin is included)
* \param block box responsible for current block fromatting context
* \param viewport_height height of viewport in px
@@ -1543,7 +1562,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
* \return next box that current margin collapses to, or NULL if none.
*/
static struct box*
-layout_next_margin_block(const nscss_len_ctx *len_ctx,
+layout_next_margin_block(const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *block,
int viewport_height,
@@ -1563,7 +1582,7 @@ layout_next_margin_block(const nscss_len_ctx *len_ctx,
/* Get margins */
if (box->style) {
- layout_find_dimensions(len_ctx,
+ layout_find_dimensions(unit_len_ctx,
box->parent->width,
viewport_height, box,
box->style,
@@ -1638,7 +1657,7 @@ layout_next_margin_block(const nscss_len_ctx *len_ctx,
/* Get margins */
if (box->style) {
- layout_find_dimensions(len_ctx,
+ layout_find_dimensions(unit_len_ctx,
box->parent->width,
viewport_height, box,
box->style,
@@ -1875,7 +1894,7 @@ layout_solve_width(struct box *box,
* Compute dimensions of box, margins, paddings, and borders for a block-level
* element.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param available_width Max width available in pixels
* \param viewport_height Height of viewport in pixels or -ve if unknown
* \param lm min left margin required to avoid floats in px.
@@ -1888,7 +1907,7 @@ layout_solve_width(struct box *box,
* See CSS 2.1 10.3.3, 10.3.4, 10.6.2, and 10.6.3.
*/
static void
-layout_block_find_dimensions(const nscss_len_ctx *len_ctx,
+layout_block_find_dimensions(const css_unit_ctx *unit_len_ctx,
int available_width,
int viewport_height,
int lm,
@@ -1902,7 +1921,7 @@ layout_block_find_dimensions(const nscss_len_ctx *len_ctx,
struct box_border *border = box->border;
const css_computed_style *style = box->style;
- layout_find_dimensions(len_ctx, available_width, viewport_height, box,
+ layout_find_dimensions(unit_len_ctx, available_width, viewport_height, box,
style, &width, &height, &max_width, &min_width,
&max_height, &min_height, margin, padding, border);
@@ -2056,7 +2075,7 @@ static bool layout_table(struct box *table, int available_width,
memcpy(col, table->col, sizeof(col[0]) * columns);
/* find margins, paddings, and borders for table and cells */
- layout_find_dimensions(&content->len_ctx, available_width, -1, table,
+ layout_find_dimensions(&content->unit_len_ctx, available_width, -1, table,
style, 0, 0, 0, 0, 0, 0, table->margin, table->padding,
table->border);
for (row_group = table->children; row_group;
@@ -2068,8 +2087,8 @@ static bool layout_table(struct box *table, int available_width,
assert(c->style);
table_used_border_for_cell(
- &content->len_ctx, c);
- layout_find_dimensions(&content->len_ctx,
+ &content->unit_len_ctx, c);
+ layout_find_dimensions(&content->unit_len_ctx,
available_width, -1, c,
c->style, 0, 0, 0, 0, 0, 0,
0, c->padding, c->border);
@@ -2099,10 +2118,10 @@ static bool layout_table(struct box *table, int available_width,
css_computed_border_spacing(style, &h, &hu, &v, &vu);
- border_spacing_h = FIXTOINT(nscss_len2px(&content->len_ctx,
- h, hu, style));
- border_spacing_v = FIXTOINT(nscss_len2px(&content->len_ctx,
- v, vu, style));
+ border_spacing_h = FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx, h, hu));
+ border_spacing_v = FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx, v, vu));
}
/* find specified table width, or available width if auto-width */
@@ -2112,8 +2131,9 @@ static bool layout_table(struct box *table, int available_width,
table_width = FPCT_OF_INT_TOINT(value, available_width);
} else {
table_width =
- FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, style));
+ FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx,
+ value, unit));
}
/* specified width includes border */
@@ -2191,8 +2211,9 @@ static bool layout_table(struct box *table, int available_width,
} else {
/* This is the minimum height for the table
* (see 17.5.3) */
- min_height = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, style));
+ min_height = FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx,
+ value, unit));
}
}
@@ -2382,9 +2403,10 @@ static bool layout_table(struct box *table, int available_width,
htype = css_computed_height(row->style, &value, &unit);
if (htype == CSS_HEIGHT_SET && unit != CSS_UNIT_PCT) {
- row_height = FIXTOINT(nscss_len2px(
- &content->len_ctx,
- value, unit, row->style));
+ row_height = FIXTOINT(css_unit_len2device_px(
+ row->style,
+ &content->unit_len_ctx,
+ value, unit));
}
for (c = row->children; c; c = c->next) {
assert(c->style);
@@ -2421,9 +2443,10 @@ static bool layout_table(struct box *table, int available_width,
/* some sites use height="1" or similar
* to attempt to make cells as small as
* possible, so treat it as a minimum */
- int h = FIXTOINT(nscss_len2px(
- &content->len_ctx,
- value, unit, c->style));
+ int h = FIXTOINT(css_unit_len2device_px(
+ c->style,
+ &content->unit_len_ctx,
+ value, unit));
if (c->height < h)
c->height = h;
}
@@ -2567,14 +2590,14 @@ static bool layout_table(struct box *table, int available_width,
/**
* Manimpulate box height according to CSS min-height and max-height properties
*
- * \param len_ctx CSS length conversion context for document.
+ * \param unit_len_ctx CSS length conversion context for document.
* \param box block to modify with any min-height or max-height
* \param container containing block for absolutely positioned elements, or
* NULL for non absolutely positioned elements.
* \return whether the height has been changed
*/
static bool layout_apply_minmax_height(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *container)
{
@@ -2635,8 +2658,9 @@ static bool layout_apply_minmax_height(
}
}
} else {
- h = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ h = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
if (h < box->height) {
box->height = h;
updated = true;
@@ -2665,8 +2689,9 @@ static bool layout_apply_minmax_height(
}
}
} else {
- h = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ h = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
if (h > box->height) {
box->height = h;
updated = true;
@@ -2834,7 +2859,7 @@ layout_text_box_split(html_content *content,
* Compute dimensions of box, margins, paddings, and borders for a floating
* element using shrink-to-fit. Also used for inline-blocks.
*
- * \param len_ctx CSS length conversion context for document.
+ * \param unit_len_ctx CSS length conversion context for document.
* \param available_width Max width available in pixels
* \param style Box's style
* \param box Box for which to find dimensions
@@ -2843,7 +2868,7 @@ layout_text_box_split(html_content *content,
*/
static void
layout_float_find_dimensions(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
int available_width,
const css_computed_style *style,
struct box *box)
@@ -2863,7 +2888,7 @@ layout_float_find_dimensions(
overflow_y == CSS_OVERFLOW_AUTO) ?
SCROLLBAR_WIDTH : 0;
- layout_find_dimensions(len_ctx, available_width, -1, box, style,
+ layout_find_dimensions(unit_len_ctx, available_width, -1, box, style,
&width, &height, &max_width, &min_width,
&max_height, &min_height, margin, padding, border);
@@ -2899,26 +2924,30 @@ layout_float_find_dimensions(
box->gadget->type == GADGET_FILE) {
if (width == AUTO) {
size = INTTOFIX(10);
- width = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
if (box->gadget->type == GADGET_FILE &&
height == AUTO) {
size = FLTTOFIX(1.5);
- height = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ height = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
}
if (box->gadget->type == GADGET_TEXTAREA) {
if (width == AUTO) {
size = INTTOFIX(10);
- width = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
if (height == AUTO) {
size = INTTOFIX(4);
- height = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ height = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
}
} else if (width == AUTO) {
@@ -2939,9 +2968,9 @@ layout_float_find_dimensions(
* mbp as was used in layout_minmax_block() */
int fixed = 0;
float frac = 0;
- calculate_mbp_width(len_ctx, box->style, LEFT,
+ calculate_mbp_width(unit_len_ctx, box->style, LEFT,
true, true, true, &fixed, &frac);
- calculate_mbp_width(len_ctx, box->style, RIGHT,
+ calculate_mbp_width(unit_len_ctx, box->style, RIGHT,
true, true, true, &fixed, &frac);
if (fixed < 0)
fixed = 0;
@@ -2980,7 +3009,7 @@ static bool layout_float(struct box *b, int width, html_content *content)
{
assert(b->type == BOX_TABLE || b->type == BOX_BLOCK ||
b->type == BOX_INLINE_BLOCK);
- layout_float_find_dimensions(&content->len_ctx, width, b->style, b);
+ layout_float_find_dimensions(&content->unit_len_ctx, width, b->style, b);
if (b->type == BOX_TABLE) {
if (!layout_table(b, width, content))
return false;
@@ -3053,7 +3082,7 @@ place_float_below(struct box *c, int width, int cx, int y, struct box *cont)
* Calculate line height from a style.
*/
static int line_height(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *style)
{
enum css_line_height_e lhtype;
@@ -3072,16 +3101,16 @@ static int line_height(
if (lhtype == CSS_LINE_HEIGHT_NUMBER ||
lhunit == CSS_UNIT_PCT) {
- line_height = nscss_len2px(len_ctx,
- lhvalue, CSS_UNIT_EM, style);
+ line_height = css_unit_len2device_px(style, unit_len_ctx,
+ lhvalue, CSS_UNIT_EM);
if (lhtype != CSS_LINE_HEIGHT_NUMBER)
line_height = FDIV(line_height, F_100);
} else {
assert(lhunit != CSS_UNIT_PCT);
- line_height = nscss_len2px(len_ctx,
- lhvalue, lhunit, style);
+ line_height = css_unit_len2device_px(style, unit_len_ctx,
+ lhvalue, lhunit);
}
return FIXTOINT(line_height);
@@ -3153,7 +3182,7 @@ layout_line(struct box *first,
x1 -= cx;
if (indent)
- x0 += layout_text_indent(&content->len_ctx,
+ x0 += layout_text_indent(&content->unit_len_ctx,
first->parent->parent->style, *width);
if (x1 < x0)
@@ -3163,7 +3192,7 @@ layout_line(struct box *first,
* this is the line-height if there are text children and also in the
* case of an initially empty text input */
if (has_text_children || first->parent->parent->gadget)
- used_height = height = line_height(&content->len_ctx,
+ used_height = height = line_height(&content->unit_len_ctx,
first->parent->parent->style);
else
/* inline containers with no text are usually for layout and
@@ -3203,7 +3232,7 @@ layout_line(struct box *first,
continue;
assert(b->style != NULL);
- font_plot_style_from_css(&content->len_ctx, b->style, &fstyle);
+ font_plot_style_from_css(&content->unit_len_ctx, b->style, &fstyle);
x += space_after;
@@ -3227,7 +3256,7 @@ layout_line(struct box *first,
if (b->type == BOX_INLINE) {
/* calculate borders, margins, and padding */
- layout_find_dimensions(&content->len_ctx,
+ layout_find_dimensions(&content->unit_len_ctx,
*width, -1, b, b->style, 0, 0, 0, 0,
0, 0, b->margin, b->padding, b->border);
for (i = 0; i != 4; i++)
@@ -3262,7 +3291,7 @@ layout_line(struct box *first,
if (!b->object && !(b->flags & IFRAME) && !b->gadget &&
!(b->flags & REPLACE_DIM)) {
/* inline non-replaced, 10.3.1 and 10.6.1 */
- b->height = line_height(&content->len_ctx,
+ b->height = line_height(&content->unit_len_ctx,
b->style ? b->style :
b->parent->parent->style);
if (height < b->height)
@@ -3333,7 +3362,7 @@ layout_line(struct box *first,
/* inline replaced, 10.3.2 and 10.6.2 */
assert(b->style);
- layout_find_dimensions(&content->len_ctx,
+ layout_find_dimensions(&content->unit_len_ctx,
*width, -1, b, b->style,
&b->width, &b->height,
&max_width, &min_width,
@@ -3356,13 +3385,15 @@ layout_line(struct box *first,
} else {
/* form control with no object */
if (b->width == AUTO)
- b->width = FIXTOINT(nscss_len2px(
- &content->len_ctx, INTTOFIX(1),
- CSS_UNIT_EM, b->style));
+ b->width = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx, INTTOFIX(1),
+ CSS_UNIT_EM));
if (b->height == AUTO)
- b->height = FIXTOINT(nscss_len2px(
- &content->len_ctx, INTTOFIX(1),
- CSS_UNIT_EM, b->style));
+ b->height = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx, INTTOFIX(1),
+ CSS_UNIT_EM));
}
/* Reformat object to new box size */
@@ -3395,7 +3426,7 @@ layout_line(struct box *first,
x1 -= cx;
if (indent)
- x0 += layout_text_indent(&content->len_ctx,
+ x0 += layout_text_indent(&content->unit_len_ctx,
first->parent->parent->style, *width);
if (x1 < x0)
@@ -3454,7 +3485,7 @@ layout_line(struct box *first,
else if (b->text || b->type == BOX_INLINE_END) {
if (b->space == UNKNOWN_WIDTH) {
font_plot_style_from_css(
- &content->len_ctx,
+ &content->unit_len_ctx,
b->style, &fstyle);
/** \todo handle errors */
font_func->width(&fstyle, " ", 1,
@@ -3608,7 +3639,7 @@ layout_line(struct box *first,
!(split_box->flags & IFRAME) &&
!split_box->gadget && split_box->text) {
- font_plot_style_from_css(&content->len_ctx,
+ font_plot_style_from_css(&content->unit_len_ctx,
split_box->style, &fstyle);
/** \todo handle errors */
font_func->split(&fstyle,
@@ -3972,9 +4003,10 @@ layout_block_context(struct box *block,
gadget_unit = CSS_UNIT_EM;
gadget_size = INTTOFIX(1);
if (block->height == AUTO)
- block->height = FIXTOINT(nscss_len2px(
- &content->len_ctx, gadget_size,
- gadget_unit, block->style));
+ block->height = FIXTOINT(css_unit_len2device_px(
+ block->style,
+ &content->unit_len_ctx,
+ gadget_size, gadget_unit));
}
box = block->children;
@@ -4038,7 +4070,7 @@ layout_block_context(struct box *block,
* through to, find out. Update the pos/neg margin values. */
if (margin_collapse == NULL) {
margin_collapse = layout_next_margin_block(
- &content->len_ctx, box, block,
+ &content->unit_len_ctx, box, block,
viewport_height,
&max_pos_margin, &max_neg_margin);
/* We have a margin that has not yet been applied. */
@@ -4089,7 +4121,7 @@ layout_block_context(struct box *block,
box->parent->padding[RIGHT] -
x1;
}
- layout_block_find_dimensions(&content->len_ctx,
+ layout_block_find_dimensions(&content->unit_len_ctx,
box->parent->width,
viewport_height, lm, rm, box);
if (box->type == BOX_BLOCK && !(box->flags & IFRAME)) {
@@ -4330,7 +4362,7 @@ layout_block_context(struct box *block,
css_computed_position(box->style) !=
CSS_POSITION_ABSOLUTE &&
layout_apply_minmax_height(
- &content->len_ctx,
+ &content->unit_len_ctx,
box, NULL)) {
/* Height altered */
/* Set current cy */
@@ -4387,7 +4419,7 @@ layout_block_context(struct box *block,
if (block->style && css_computed_position(block->style) !=
CSS_POSITION_ABSOLUTE) {
/* Block is in normal flow */
- layout_apply_minmax_height(&content->len_ctx, block, NULL);
+ layout_apply_minmax_height(&content->unit_len_ctx, block, NULL);
}
if (block->gadget &&
@@ -4399,7 +4431,7 @@ layout_block_context(struct box *block,
block->padding[RIGHT];
int ta_height = block->padding[TOP] + block->height +
block->padding[BOTTOM];
- font_plot_style_from_css(&content->len_ctx,
+ font_plot_style_from_css(&content->unit_len_ctx,
block->style, &fstyle);
fstyle.background = NS_TRANSPARENT;
textarea_set_layout(block->gadget->data.text.ta,
@@ -4820,14 +4852,14 @@ layout_lists(const html_content *content, struct box *box)
marker->height =
content_get_height(marker->object);
marker->y = (line_height(
- &content->len_ctx,
+ &content->unit_len_ctx,
marker->style) -
marker->height) / 2;
} else if (marker->text) {
if (marker->width == UNKNOWN_WIDTH) {
plot_font_style_t fstyle;
font_plot_style_from_css(
- &content->len_ctx,
+ &content->unit_len_ctx,
marker->style,
&fstyle);
content->font_func->width(&fstyle,
@@ -4839,7 +4871,7 @@ layout_lists(const html_content *content, struct box *box)
marker->x = -marker->width;
marker->y = 0;
marker->height = line_height(
- &content->len_ctx,
+ &content->unit_len_ctx,
marker->style);
} else {
marker->x = 0;
@@ -4859,7 +4891,7 @@ layout_lists(const html_content *content, struct box *box)
* Compute box offsets for a relatively or absolutely positioned box with
* respect to a box.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box to compute offsets for
* \param containing_block box to compute percentages with respect to
* \param top updated to top offset, or AUTO
@@ -4870,7 +4902,7 @@ layout_lists(const html_content *content, struct box *box)
* See CSS 2.1 9.3.2. containing_block must have width and height.
*/
static void
-layout_compute_offsets(const nscss_len_ctx *len_ctx,
+layout_compute_offsets(const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *containing_block,
int *top,
@@ -4893,8 +4925,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*left = FPCT_OF_INT_TOINT(value,
containing_block->width);
} else {
- *left = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *left = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*left = AUTO;
@@ -4907,8 +4940,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*right = FPCT_OF_INT_TOINT(value,
containing_block->width);
} else {
- *right = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *right = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*right = AUTO;
@@ -4921,8 +4955,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*top = FPCT_OF_INT_TOINT(value,
containing_block->height);
} else {
- *top = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *top = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*top = AUTO;
@@ -4935,8 +4970,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*bottom = FPCT_OF_INT_TOINT(value,
containing_block->height);
} else {
- *bottom = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *bottom = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*bottom = AUTO;
@@ -4992,14 +5028,14 @@ layout_absolute(struct box *box,
/** \todo inline containers */
}
- layout_compute_offsets(&content->len_ctx, box, containing_block,
+ layout_compute_offsets(&content->unit_len_ctx, box, containing_block,
&top, &right, &bottom, &left);
/* Pass containing block into layout_find_dimensions via the float
* containing block box member. This is unused for absolutely positioned
* boxes because a box can't be floated and absolutely positioned. */
box->float_container = containing_block;
- layout_find_dimensions(&content->len_ctx, available_width, -1,
+ layout_find_dimensions(&content->unit_len_ctx, available_width, -1,
box, box->style, &width, &height,
&max_width, &min_width, 0, 0,
margin, padding, border);
@@ -5317,7 +5353,7 @@ layout_absolute(struct box *box,
/** \todo Inline ancestors */
}
box->height = height;
- layout_apply_minmax_height(&content->len_ctx, box, containing_block);
+ layout_apply_minmax_height(&content->unit_len_ctx, box, containing_block);
return true;
}
@@ -5394,13 +5430,13 @@ layout_position_absolute(struct box *box,
/**
* Compute a box's relative offset as per CSS 2.1 9.4.3
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box Box to compute relative offsets for.
* \param x Receives relative offset in x.
* \param y Receives relative offset in y.
*/
static void layout_compute_relative_offset(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
int *x,
int *y)
@@ -5420,7 +5456,7 @@ static void layout_compute_relative_offset(
containing_block = box->parent;
}
- layout_compute_offsets(len_ctx, box, containing_block,
+ layout_compute_offsets(unit_len_ctx, box, containing_block,
&top, &right, &bottom, &left);
if (left == AUTO && right == AUTO)
@@ -5468,7 +5504,7 @@ static void layout_compute_relative_offset(
/**
* Adjust positions of relatively positioned boxes.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param root box to adjust the position of
* \param fp box which forms the block formatting context for children of
* "root" which are floats
@@ -5481,7 +5517,7 @@ static void layout_compute_relative_offset(
*/
static void
layout_position_relative(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *root,
struct box *fp,
int fx,
@@ -5510,7 +5546,7 @@ layout_position_relative(
if (box->style && css_computed_position(box->style) ==
CSS_POSITION_RELATIVE)
layout_compute_relative_offset(
- len_ctx, box, &x, &y);
+ unit_len_ctx, box, &x, &y);
else
x = y = 0;
@@ -5546,7 +5582,7 @@ layout_position_relative(
}
/* recurse first */
- layout_position_relative(len_ctx, box, fn, fnx, fny);
+ layout_position_relative(unit_len_ctx, box, fn, fnx, fny);
/* Ignore things we're not interested in. */
if (!box->style || (box->style &&
@@ -5575,7 +5611,7 @@ layout_position_relative(
/**
* Find a box's bounding box relative to itself, i.e. the box's border edge box
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box find bounding box of
* \param desc_x0 updated to left of box's bbox
* \param desc_y0 updated to top of box's bbox
@@ -5584,7 +5620,7 @@ layout_position_relative(
*/
static void
layout_get_box_bbox(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
int *desc_x0, int *desc_y0,
int *desc_x1, int *desc_y1)
@@ -5607,8 +5643,8 @@ layout_get_box_bbox(
int text_height;
css_computed_font_size(box->style, &font_size, &font_unit);
- text_height = nscss_len2px(len_ctx, font_size, font_unit,
- box->style);
+ text_height = css_unit_len2device_px(box->style, unit_len_ctx,
+ font_size, font_unit);
text_height = FIXTOINT(text_height * 3 / 4);
*desc_y0 = (*desc_y0 < -text_height) ? *desc_y0 : -text_height;
}
@@ -5618,7 +5654,7 @@ layout_get_box_bbox(
/**
* Apply changes to box descendant_[xy][01] values due to given child.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box to update
* \param child a box, which may affect box's descendant bbox
* \param off_x offset to apply to child->x coord to treat as child of box
@@ -5626,7 +5662,7 @@ layout_get_box_bbox(
*/
static void
layout_update_descendant_bbox(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *child,
int off_x,
@@ -5650,7 +5686,7 @@ layout_update_descendant_bbox(
}
/* Get child's border edge */
- layout_get_box_bbox(len_ctx, child,
+ layout_get_box_bbox(unit_len_ctx, child,
&child_desc_x0, &child_desc_y0,
&child_desc_x1, &child_desc_y1);
@@ -5688,11 +5724,11 @@ layout_update_descendant_bbox(
* Recursively calculate the descendant_[xy][01] values for a laid-out box tree
* and inform iframe browser windows of their size and position.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box tree of boxes to update
*/
static void layout_calculate_descendant_bboxes(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box)
{
struct box *child;
@@ -5702,7 +5738,7 @@ static void layout_calculate_descendant_bboxes(
/* assert((box->width >= 0) && (box->height >= 0)); */
/* Initialise box's descendant box to border edge box */
- layout_get_box_bbox(len_ctx, box,
+ layout_get_box_bbox(unit_len_ctx, box,
&box->descendant_x0, &box->descendant_y0,
&box->descendant_x1, &box->descendant_y1);
@@ -5736,7 +5772,7 @@ static void layout_calculate_descendant_bboxes(
child->type == BOX_FLOAT_RIGHT)
continue;
- layout_update_descendant_bbox(len_ctx, box, child,
+ layout_update_descendant_bbox(unit_len_ctx, box, child,
box->x, box->y);
if (child == box->inline_end)
@@ -5754,7 +5790,7 @@ static void layout_calculate_descendant_bboxes(
child->type == BOX_FLOAT_RIGHT)
continue;
- layout_calculate_descendant_bboxes(len_ctx, child);
+ layout_calculate_descendant_bboxes(unit_len_ctx, child);
if (box->style && css_computed_overflow_x(box->style) ==
CSS_OVERFLOW_HIDDEN &&
@@ -5762,23 +5798,23 @@ static void layout_calculate_descendant_bboxes(
CSS_OVERFLOW_HIDDEN)
continue;
- layout_update_descendant_bbox(len_ctx, box, child, 0, 0);
+ layout_update_descendant_bbox(unit_len_ctx, box, child, 0, 0);
}
for (child = box->float_children; child; child = child->next_float) {
assert(child->type == BOX_FLOAT_LEFT ||
child->type == BOX_FLOAT_RIGHT);
- layout_calculate_descendant_bboxes(len_ctx, child);
+ layout_calculate_descendant_bboxes(unit_len_ctx, child);
- layout_update_descendant_bbox(len_ctx, box, child, 0, 0);
+ layout_update_descendant_bbox(unit_len_ctx, box, child, 0, 0);
}
if (box->list_marker) {
child = box->list_marker;
- layout_calculate_descendant_bboxes(len_ctx, child);
+ layout_calculate_descendant_bboxes(unit_len_ctx, child);
- layout_update_descendant_bbox(len_ctx, box, child, 0, 0);
+ layout_update_descendant_bbox(unit_len_ctx, box, child, 0, 0);
}
}
@@ -5796,7 +5832,7 @@ bool layout_document(html_content *content, int width, int height)
layout_minmax_block(doc, font_func, content);
- layout_block_find_dimensions(&content->len_ctx,
+ layout_block_find_dimensions(&content->unit_len_ctx,
width, height, 0, 0, doc);
doc->x = doc->margin[LEFT] + doc->border[LEFT].width;
doc->y = doc->margin[TOP] + doc->border[TOP].width;
@@ -5830,9 +5866,9 @@ bool layout_document(html_content *content, int width, int height)
layout_lists(content, doc);
layout_position_absolute(doc, doc, 0, 0, content);
- layout_position_relative(&content->len_ctx, doc, doc, 0, 0);
+ layout_position_relative(&content->unit_len_ctx, doc, doc, 0, 0);
- layout_calculate_descendant_bboxes(&content->len_ctx, doc);
+ layout_calculate_descendant_bboxes(&content->unit_len_ctx, doc);
return ret;
}
diff --git a/content/handlers/html/object.c b/content/handlers/html/object.c
index e6edf84..a1f020b 100644
--- a/content/handlers/html/object.c
+++ b/content/handlers/html/object.c
@@ -265,18 +265,20 @@ html_object_callback(hlcache_handle *object,
if (hunit == CSS_UNIT_PCT) {
l = (width - w) * hpos / INTTOFIX(100);
} else {
- l = FIXTOINT(nscss_len2px(&c->len_ctx,
- hpos, hunit,
- box->style));
+ l = FIXTOINT(css_unit_len2device_px(
+ box->style,
+ &c->unit_len_ctx,
+ hpos, hunit));
}
h = content_get_height(box->background);
if (vunit == CSS_UNIT_PCT) {
t = (height - h) * vpos / INTTOFIX(100);
} else {
- t = FIXTOINT(nscss_len2px(&c->len_ctx,
- vpos, vunit,
- box->style));
+ t = FIXTOINT(css_unit_len2device_px(
+ box->style,
+ &c->unit_len_ctx,
+ vpos, vunit));
}
/* Redraw area depends on background-repeat */
diff --git a/content/handlers/html/private.h b/content/handlers/html/private.h
index 2bd9cff..56cd957 100644
--- a/content/handlers/html/private.h
+++ b/content/handlers/html/private.h
@@ -112,9 +112,6 @@ typedef struct html_content {
/** Base target */
char *base_target;
- /** CSS length conversion context for document. */
- nscss_len_ctx len_ctx;
-
/** Content has been aborted in the LOADING state */
bool aborted;
@@ -162,6 +159,8 @@ typedef struct html_content {
css_select_ctx *select_ctx;
/**< Style selection media specification */
css_media media;
+ /** CSS length conversion context for document. */
+ css_unit_ctx unit_len_ctx;
/**< Universal selector */
lwc_string *universal;
diff --git a/content/handlers/html/redraw.c b/content/handlers/html/redraw.c
index 9807512..f770699 100644
--- a/content/handlers/html/redraw.c
+++ b/content/handlers/html/redraw.c
@@ -528,14 +528,14 @@ static bool html_redraw_radio(int x, int y, int width, int height,
* \param box box of input
* \param scale scale for redraw
* \param background_colour current background colour
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
static bool html_redraw_file(int x, int y, int width, int height,
struct box *box, float scale, colour background_colour,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
int text_width;
@@ -544,7 +544,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
plot_font_style_t fstyle;
nserror res;
- font_plot_style_from_css(len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(unit_len_ctx, box->style, &fstyle);
fstyle.background = background_colour;
if (box->gadget->value) {
@@ -587,7 +587,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
* \param clip current clip rectangle
* \param background_colour current background colour
* \param background box containing background details (usually \a box)
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
@@ -595,7 +595,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
static bool html_redraw_background(int x, int y, struct box *box, float scale,
const struct rect *clip, colour *background_colour,
struct box *background,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
bool repeat_x = false;
@@ -672,8 +672,9 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
content_get_width(background->background)) *
scale * FIXTOFLT(hpos) / 100.;
} else {
- x += (int) (FIXTOFLT(nscss_len2px(len_ctx, hpos, hunit,
- background->style)) * scale);
+ x += (int) (FIXTOFLT(css_unit_len2device_px(
+ background->style, unit_len_ctx,
+ hpos, hunit)) * scale);
}
if (vunit == CSS_UNIT_PCT) {
@@ -681,8 +682,9 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
content_get_height(background->background)) *
scale * FIXTOFLT(vpos) / 100.;
} else {
- y += (int) (FIXTOFLT(nscss_len2px(len_ctx, vpos, vunit,
- background->style)) * scale);
+ y += (int) (FIXTOFLT(css_unit_len2device_px(
+ background->style, unit_len_ctx,
+ vpos, vunit)) * scale);
}
}
@@ -814,7 +816,7 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
* \param first true if this is the first rectangle associated with the inline
* \param last true if this is the last rectangle associated with the inline
* \param background_colour updated to current background colour if plotted
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
@@ -822,7 +824,7 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
static bool html_redraw_inline_background(int x, int y, struct box *box,
float scale, const struct rect *clip, struct rect b,
bool first, bool last, colour *background_colour,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
struct rect r = *clip;
@@ -883,8 +885,9 @@ static bool html_redraw_inline_background(int x, int y, struct box *box,
plot_content = false;
}
} else {
- x += (int) (FIXTOFLT(nscss_len2px(len_ctx, hpos, hunit,
- box->style)) * scale);
+ x += (int) (FIXTOFLT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ hpos, hunit)) * scale);
}
if (vunit == CSS_UNIT_PCT) {
@@ -892,8 +895,9 @@ static bool html_redraw_inline_background(int x, int y, struct box *box,
content_get_height(box->background) *
scale) * FIXTOFLT(vpos) / 100.;
} else {
- y += (int) (FIXTOFLT(nscss_len2px(len_ctx, vpos, vunit,
- box->style)) * scale);
+ y += (int) (FIXTOFLT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ vpos, vunit)) * scale);
}
}
@@ -1134,7 +1138,7 @@ static bool html_redraw_text_box(const html_content *html, struct box *box,
bool excluded = (box->object != NULL);
plot_font_style_t fstyle;
- font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
fstyle.background = current_background_color;
if (!text_redraw(box->text,
@@ -1405,28 +1409,24 @@ bool html_redraw_box(const html_content *html, struct box *box,
CSS_CLIP_RECT) {
/* We have an absolutly positioned box with a clip rect */
if (css_rect.left_auto == false)
- r.x0 = x - border_left + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.left, css_rect.lunit,
- box->style));
+ r.x0 = x - border_left + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.left, css_rect.lunit));
if (css_rect.top_auto == false)
- r.y0 = y - border_top + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.top, css_rect.tunit,
- box->style));
+ r.y0 = y - border_top + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.top, css_rect.tunit));
if (css_rect.right_auto == false)
- r.x1 = x - border_left + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.right, css_rect.runit,
- box->style));
+ r.x1 = x - border_left + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.right, css_rect.runit));
if (css_rect.bottom_auto == false)
- r.y1 = y - border_top + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.bottom, css_rect.bunit,
- box->style));
+ r.y1 = y - border_top + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.bottom, css_rect.bunit));
/* find intersection of clip rectangle and box */
if (r.x0 < clip->x0) r.x0 = clip->x0;
@@ -1515,7 +1515,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
/* plot background */
if (!html_redraw_background(x, y, box, scale, &p,
¤t_background_color, bg_box,
- &html->len_ctx, ctx))
+ &html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@@ -1595,7 +1595,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
x, y, box, scale, &p, b,
first, false,
¤t_background_color,
- &html->len_ctx, ctx))
+ &html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@@ -1628,7 +1628,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
* the inline */
if (!html_redraw_inline_background(x, ib_y, box, scale, &p, b,
first, true, ¤t_background_color,
- &html->len_ctx, ctx))
+ &html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@@ -1843,7 +1843,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
} else if (box->gadget && box->gadget->type == GADGET_FILE) {
if (!html_redraw_file(x + padding_left, y + padding_top,
width, height, box, scale,
- current_background_color, &html->len_ctx, ctx))
+ current_background_color, &html->unit_len_ctx, ctx))
return false;
} else if (box->gadget &&
diff --git a/content/handlers/html/table.c b/content/handlers/html/table.c
index 263ddf1..4ffccea 100644
--- a/content/handlers/html/table.c
+++ b/content/handlers/html/table.c
@@ -50,7 +50,7 @@ struct border {
/**
* Determine if a border style is more eyecatching than another
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param a Reference border style
* \param a_src Source of \a a
* \param b Candidate border style
@@ -58,7 +58,7 @@ struct border {
* \return True if \a b is more eyecatching than \a a
*/
static bool
-table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
+table_border_is_more_eyecatching(const css_unit_ctx *unit_len_ctx,
const struct border *a,
box_type a_src,
const struct border *b,
@@ -83,8 +83,8 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
* if they've come from a computed style. */
assert(a->unit != CSS_UNIT_EM && a->unit != CSS_UNIT_EX);
assert(b->unit != CSS_UNIT_EM && b->unit != CSS_UNIT_EX);
- awidth = nscss_len2px(len_ctx, a->width, a->unit, NULL);
- bwidth = nscss_len2px(len_ctx, b->width, b->unit, NULL);
+ awidth = css_unit_len2device_px(NULL, unit_len_ctx, a->width, a->unit);
+ bwidth = css_unit_len2device_px(NULL, unit_len_ctx, b->width, b->unit);
if (awidth < bwidth)
return true;
@@ -160,7 +160,7 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
/**
* Process a table
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param table Table to process
* \param a Current border style for cell
* \param a_src Source of \a a
@@ -169,7 +169,7 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static void
-table_cell_top_process_table(const nscss_len_ctx *len_ctx,
+table_cell_top_process_table(const css_unit_ctx *unit_len_ctx,
struct box *table,
struct border *a,
box_type *a_src)
@@ -181,11 +181,12 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(table->style);
b.color = css_computed_border_top_color(table->style, &b.c);
css_computed_border_top_width(table->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@@ -195,7 +196,7 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
/**
* Process a row
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Cell being considered
* \param row Row to process
* \param a Current border style for cell
@@ -206,7 +207,7 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static bool
-table_cell_top_process_row(const nscss_len_ctx *len_ctx,
+table_cell_top_process_row(const css_unit_ctx *unit_len_ctx,
struct box *cell,
struct box *row,
struct border *a,
@@ -219,11 +220,12 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(row->style);
b.color = css_computed_border_bottom_color(row->style, &b.c);
css_computed_border_bottom_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@@ -233,11 +235,12 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(row->style);
b.color = css_computed_border_top_color(row->style, &b.c);
css_computed_border_top_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
@@ -272,14 +275,13 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
c->style, &b.c);
css_computed_border_bottom_width(c->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx,
- b.width,
- b.unit,
- c->style);
+ b.width = css_unit_len2device_px(
+ c->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_CELL;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
a,
*a_src,
&b,
@@ -305,7 +307,7 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
/**
* Process a group
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Cell being considered
* \param group Group to process
* \param a Current border style for cell
@@ -316,7 +318,7 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static bool
-table_cell_top_process_group(const nscss_len_ctx *len_ctx,
+table_cell_top_process_group(const css_unit_ctx *unit_len_ctx,
struct box *cell,
struct box *group,
struct border *a,
@@ -329,11 +331,12 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(group->style);
b.color = css_computed_border_bottom_color(group->style, &b.c);
css_computed_border_bottom_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@@ -342,7 +345,7 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
/* Process rows in group, starting with last */
struct box *row = group->last;
- while (table_cell_top_process_row(len_ctx, cell, row,
+ while (table_cell_top_process_row(unit_len_ctx, cell, row,
a, a_src) == false) {
if (row->prev == NULL) {
return false;
@@ -355,11 +358,12 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(group->style);
b.color = css_computed_border_top_color(group->style, &b.c);
css_computed_border_top_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
@@ -375,11 +379,11 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
/**
* Calculate used values of border-left-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+table_used_left_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@@ -390,7 +394,8 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_left_style(cell->style);
a.color = css_computed_border_left_color(cell->style, &a.c);
css_computed_border_left_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -423,11 +428,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_right_style(prev->style);
b.color = css_computed_border_right_color(prev->style, &b.c);
css_computed_border_right_width(prev->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, prev->style);
+ b.width = css_unit_len2device_px(prev->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_CELL;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -446,12 +452,13 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
row->style, &b.c);
css_computed_border_left_width(
row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx,
- b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(
+ row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -466,11 +473,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_left_style(group->style);
b.color = css_computed_border_left_color(group->style, &b.c);
css_computed_border_left_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -480,11 +488,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_left_style(table->style);
b.color = css_computed_border_left_color(table->style, &b.c);
css_computed_border_left_width(table->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -494,21 +503,19 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used left border for the cell */
cell->border[LEFT].style = a.style;
cell->border[LEFT].c = a.c;
- cell->border[LEFT].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width,
- a.unit,
- cell->style));
+ cell->border[LEFT].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-top-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+table_used_top_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@@ -519,7 +526,8 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_top_style(cell->style);
css_computed_border_top_color(cell->style, &a.c);
css_computed_border_top_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -527,18 +535,19 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_top_style(row->style);
css_computed_border_top_color(row->style, &b.c);
css_computed_border_top_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx, &a, a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, &a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
}
if (row->prev != NULL) {
/* Consider row(s) above */
- while (table_cell_top_process_row(len_ctx, cell, row->prev,
+ while (table_cell_top_process_row(unit_len_ctx, cell, row->prev,
&a, &a_src) == false) {
if (row->prev->prev == NULL) {
/* Consider row group */
@@ -559,11 +568,12 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_top_style(group->style);
b.color = css_computed_border_top_color(group->style, &b.c);
css_computed_border_top_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -571,16 +581,16 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
if (group->prev == NULL) {
/* Top border of table */
- table_cell_top_process_table(len_ctx,
+ table_cell_top_process_table(unit_len_ctx,
group->parent, &a, &a_src);
} else {
/* Process previous group(s) */
- while (table_cell_top_process_group(len_ctx,
+ while (table_cell_top_process_group(unit_len_ctx,
cell, group->prev,
&a, &a_src) == false) {
if (group->prev->prev == NULL) {
/* Top border of table */
- table_cell_top_process_table(len_ctx,
+ table_cell_top_process_table(unit_len_ctx,
group->parent,
&a, &a_src);
break;
@@ -594,20 +604,18 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used top border for the cell */
cell->border[TOP].style = a.style;
cell->border[TOP].c = a.c;
- cell->border[TOP].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width,
- a.unit,
- cell->style));
+ cell->border[TOP].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-right-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+table_used_right_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@@ -618,7 +626,8 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_right_style(cell->style);
css_computed_border_right_color(cell->style, &a.c);
css_computed_border_right_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -643,14 +652,13 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
css_computed_border_right_width(row->style,
&b.width,
&b.unit);
- b.width = nscss_len2px(len_ctx,
- b.width,
- b.unit,
- row->style);
+ b.width = css_unit_len2device_px(
+ row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src,
&b, b_src)) {
a = b;
@@ -667,11 +675,12 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.color = css_computed_border_right_color(group->style, &b.c);
css_computed_border_right_width(group->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -682,11 +691,12 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.color = css_computed_border_right_color(table->style, &b.c);
css_computed_border_right_width(table->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src,
&b, b_src)) {
a = b;
@@ -697,21 +707,19 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used right border for the cell */
cell->border[RIGHT].style = a.style;
cell->border[RIGHT].c = a.c;
- cell->border[RIGHT].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width,
- a.unit,
- cell->style));
+ cell->border[RIGHT].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-bottom-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
+table_used_bottom_border_for_cell(const css_unit_ctx *unit_len_ctx,
struct box *cell)
{
struct border a, b;
@@ -723,7 +731,8 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
a.style = css_computed_border_bottom_style(cell->style);
css_computed_border_bottom_color(cell->style, &a.c);
css_computed_border_bottom_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -747,11 +756,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(row->style);
b.color = css_computed_border_bottom_color(row->style, &b.c);
css_computed_border_bottom_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -762,11 +772,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.color = css_computed_border_bottom_color(group->style, &b.c);
css_computed_border_bottom_width(group->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -777,11 +788,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.color = css_computed_border_bottom_color(table->style, &b.c);
css_computed_border_bottom_width(table->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
}
@@ -790,14 +802,14 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
/* a now contains the used bottom border for the cell */
cell->border[BOTTOM].style = a.style;
cell->border[BOTTOM].c = a.c;
- cell->border[BOTTOM].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width, a.unit, cell->style));
+ cell->border[BOTTOM].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/* exported interface documented in html/table.h */
bool
-table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
+table_calculate_column_types(const css_unit_ctx *unit_len_ctx, struct box *table)
{
unsigned int i, j;
struct column *col;
@@ -845,8 +857,10 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
if (col[i].type != COLUMN_WIDTH_FIXED &&
type == CSS_WIDTH_SET && unit != CSS_UNIT_PCT) {
col[i].type = COLUMN_WIDTH_FIXED;
- col[i].width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, cell->style));
+ col[i].width = FIXTOINT(css_unit_len2device_px(
+ cell->style,
+ unit_len_ctx,
+ value, unit));
if (col[i].width < 0)
col[i].width = 0;
continue;
@@ -911,9 +925,11 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
if (type == CSS_WIDTH_SET && unit != CSS_UNIT_PCT &&
fixed_columns + unknown_columns ==
cell->columns) {
- int width = (FIXTOFLT(nscss_len2px(len_ctx, value, unit,
- cell->style)) - fixed_width) /
- unknown_columns;
+ int width = (FIXTOFLT(css_unit_len2device_px(
+ cell->style,
+ unit_len_ctx,
+ value, unit)) -
+ fixed_width) / unknown_columns;
if (width < 0)
width = 0;
for (j = 0; j != cell->columns; j++) {
@@ -968,7 +984,7 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
/* exported interface documented in html/table.h */
-void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+void table_used_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
int side;
@@ -986,8 +1002,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[LEFT].c);
css_computed_border_left_width(cell->style, &width, &unit);
cell->border[LEFT].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
/* Top border */
cell->border[TOP].style =
@@ -996,8 +1013,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[TOP].c);
css_computed_border_top_width(cell->style, &width, &unit);
cell->border[TOP].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
/* Right border */
cell->border[RIGHT].style =
@@ -1006,8 +1024,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[RIGHT].c);
css_computed_border_right_width(cell->style, &width, &unit);
cell->border[RIGHT].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
/* Bottom border */
cell->border[BOTTOM].style =
@@ -1016,20 +1035,21 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[BOTTOM].c);
css_computed_border_bottom_width(cell->style, &width, &unit);
cell->border[BOTTOM].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
} else {
/* Left border */
- table_used_left_border_for_cell(len_ctx, cell);
+ table_used_left_border_for_cell(unit_len_ctx, cell);
/* Top border */
- table_used_top_border_for_cell(len_ctx, cell);
+ table_used_top_border_for_cell(unit_len_ctx, cell);
/* Right border */
- table_used_right_border_for_cell(len_ctx, cell);
+ table_used_right_border_for_cell(unit_len_ctx, cell);
/* Bottom border */
- table_used_bottom_border_for_cell(len_ctx, cell);
+ table_used_bottom_border_for_cell(unit_len_ctx, cell);
}
/* Finally, ensure that any borders configured as
diff --git a/content/handlers/html/table.h b/content/handlers/html/table.h
index ac4af25..557032b 100644
--- a/content/handlers/html/table.h
+++ b/content/handlers/html/table.h
@@ -33,24 +33,24 @@ struct box;
/**
* Determine the column width types for a table.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param table box of type BOX_TABLE
* \return true on success, false on memory exhaustion
*
* The table->col array is allocated and type and width are filled in for each
* column.
*/
-bool table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table);
+bool table_calculate_column_types(const css_unit_ctx *unit_len_ctx, struct box *table);
/**
* Calculate used values of border-{trbl}-{style,color,width} for table cells.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*
* \post \a cell's border array is populated
*/
-void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell);
+void table_used_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell);
#endif
diff --git a/content/handlers/html/textselection.c b/content/handlers/html/textselection.c
index 9de7590..9b83e73 100644
--- a/content/handlers/html/textselection.c
+++ b/content/handlers/html/textselection.c
@@ -240,7 +240,7 @@ coords_from_range(struct box *box,
* \param text pointer to text being added, or NULL for newline
* \param length length of text to be appended (bytes)
* \param box pointer to text box, or NULL if from textplain
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param handle selection string to append to
* \param whitespace_text whitespace to place before text for formatting
* may be NULL
@@ -251,7 +251,7 @@ static nserror
selection_copy_box(const char *text,
size_t length,
struct box *box,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct selection_string *handle,
const char *whitespace_text,
size_t whitespace_length)
@@ -278,7 +278,7 @@ selection_copy_box(const char *text,
if (box->style != NULL) {
/* Override default font style */
- font_plot_style_from_css(len_ctx, box->style, &style);
+ font_plot_style_from_css(unit_len_ctx, box->style, &style);
pstyle = &style;
} else {
/* If there's no style, there must be no text */
@@ -300,7 +300,7 @@ selection_copy_box(const char *text,
* boxes that lie (partially) within the given range
*
* \param box box subtree
- * \param len_ctx Length conversion context.
+ * \param unit_len_ctx Length conversion context.
* \param start_idx start of range within textual representation (bytes)
* \param end_idx end of range
* \param handler handler function to call
@@ -312,7 +312,7 @@ selection_copy_box(const char *text,
*/
static nserror
selection_copy(struct box *box,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
unsigned start_idx,
unsigned end_idx,
struct selection_string *selstr,
@@ -340,7 +340,7 @@ selection_copy(struct box *box,
/* do the marker box before continuing with the rest of the
* list element */
res = selection_copy(box->list_marker,
- len_ctx,
+ unit_len_ctx,
start_idx,
end_idx,
selstr,
@@ -383,7 +383,7 @@ selection_copy(struct box *box,
res = selection_copy_box(box->text + start_off,
min(box->length, end_off) - start_off,
box,
- len_ctx,
+ unit_len_ctx,
selstr,
whitespace_text,
whitespace_length);
@@ -415,7 +415,7 @@ selection_copy(struct box *box,
struct box *next = child->next;
res = selection_copy(child,
- len_ctx,
+ unit_len_ctx,
start_idx,
end_idx,
selstr,
@@ -518,7 +518,7 @@ html_textselection_copy(struct content *c,
}
return selection_copy(html->layout,
- &html->len_ctx,
+ &html->unit_len_ctx,
start_idx,
end_idx,
selstr,
diff --git a/desktop/local_history_private.h b/desktop/local_history_private.h
index 0b74562..fd25ab4 100644
--- a/desktop/local_history_private.h
+++ b/desktop/local_history_private.h
@@ -27,12 +27,12 @@
#include "content/handlers/css/utils.h"
#define LOCAL_HISTORY_WIDTH \
- (FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(116))))
+ (FIXTOINT(css_unit_css2device_px(INTTOFIX(116), nscss_screen_dpi)))
#define LOCAL_HISTORY_HEIGHT \
- (FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(100))))
+ (FIXTOINT(css_unit_css2device_px(INTTOFIX(100), nscss_screen_dpi)))
#define LOCAL_HISTORY_RIGHT_MARGIN \
- (FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(50))))
+ (FIXTOINT(css_unit_css2device_px(INTTOFIX( 50), nscss_screen_dpi)))
#define LOCAL_HISTORY_BOTTOM_MARGIN \
- (FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(30))))
+ (FIXTOINT(css_unit_css2device_px(INTTOFIX( 30), nscss_screen_dpi)))
#endif
diff --git a/desktop/print.c b/desktop/print.c
index de579dc..e90e322 100644
--- a/desktop/print.c
+++ b/desktop/print.c
@@ -257,9 +257,9 @@ struct print_settings *print_make_settings(print_configuration configuration,
struct print_settings *settings;
css_fixed length = 0;
css_unit unit = CSS_UNIT_MM;
- nscss_len_ctx len_ctx = {
- .vw = DEFAULT_PAGE_WIDTH,
- .vh = DEFAULT_PAGE_HEIGHT,
+ css_unit_ctx unit_len_ctx = {
+ .viewport_width = DEFAULT_PAGE_WIDTH,
+ .viewport_height = DEFAULT_PAGE_HEIGHT,
.root_style = NULL,
};
@@ -277,17 +277,17 @@ struct print_settings *print_make_settings(print_configuration configuration,
settings->scale = DEFAULT_EXPORT_SCALE;
length = INTTOFIX(DEFAULT_MARGIN_LEFT_MM);
- settings->margins[MARGINLEFT] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINLEFT] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(DEFAULT_MARGIN_RIGHT_MM);
- settings->margins[MARGINRIGHT] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINRIGHT] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(DEFAULT_MARGIN_TOP_MM);
- settings->margins[MARGINTOP] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINTOP] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(DEFAULT_MARGIN_BOTTOM_MM);
- settings->margins[MARGINBOTTOM] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINBOTTOM] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
break;
/* use settings from the Export options tab */
case PRINT_OPTIONS:
@@ -303,17 +303,17 @@ struct print_settings *print_make_settings(print_configuration configuration,
settings->scale = (float)nsoption_int(export_scale) / 100;
length = INTTOFIX(nsoption_int(margin_left));
- settings->margins[MARGINLEFT] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINLEFT] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(nsoption_int(margin_right));
- settings->margins[MARGINRIGHT] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINRIGHT] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(nsoption_int(margin_top));
- settings->margins[MARGINTOP] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINTOP] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(nsoption_int(margin_bottom));
- settings->margins[MARGINBOTTOM] = nscss_len2px(
- &len_ctx, length, unit, NULL);
+ settings->margins[MARGINBOTTOM] = css_unit_len2device_px(
+ NULL, &unit_len_ctx, length, unit);
break;
default:
return NULL;
--
NetSurf Browser
2 years
libcss: branch master updated. release/0.9.1-24-gecf42af
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/ecf42afc3329b03ee642ed...
...commit http://git.netsurf-browser.org/libcss.git/commit/ecf42afc3329b03ee642ede8...
...tree http://git.netsurf-browser.org/libcss.git/tree/ecf42afc3329b03ee642ede84f...
The branch, master has been updated
via ecf42afc3329b03ee642ede84f9ba224d2aff1e1 (commit)
via 65d4fd6e83d421e7fa7a8c7df44d01797e3c69ae (commit)
via 6cd205329373efe5a1629518c2875724cc79dce3 (commit)
via 0cf10a040aea028c7dc81cf353da7a7af5331076 (commit)
from 57fa3608e13accc24a45e5d7801a381212c2ff22 (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 -----------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes:
Makefile | 1 +
docs/Bytecode | 23 +-
examples/example1.c | 79 ++-----
include/libcss/computed.h | 6 +-
include/libcss/select.h | 9 +-
include/libcss/types.h | 29 +--
include/libcss/unit.h | 156 +++++++++++++
src/bytecode/bytecode.h | 23 +-
src/parse/properties/font.c | 3 -
src/parse/properties/utils.c | 6 -
src/select/Makefile | 2 +-
src/select/computed.c | 34 +--
src/select/computed.h | 6 +-
src/select/hash.c | 14 +-
src/select/hash.h | 2 +
src/select/helpers.h | 3 -
src/select/mq.h | 165 ++++----------
src/select/select.c | 39 +++-
src/select/select.h | 1 +
src/select/unit.c | 511 ++++++++++++++++++++++++++++++++++++++++++
src/select/unit.h | 42 ++++
test/data/parse2/units.dat | 24 --
test/data/select/tests1.dat | 258 ++++++++++-----------
test/dump.h | 9 -
test/dump_computed.h | 9 -
test/select.c | 85 ++-----
26 files changed, 1011 insertions(+), 528 deletions(-)
create mode 100644 include/libcss/unit.h
create mode 100644 src/select/unit.c
create mode 100644 src/select/unit.h
diff --git a/Makefile b/Makefile
index 0835c8f..86d6641 100644
--- a/Makefile
+++ b/Makefile
@@ -65,5 +65,6 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/properties.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/select.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/stylesheet.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/types.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/unit.h
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR)/pkgconfig:lib$(COMPONENT).pc.in
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR):$(OUTPUT)
diff --git a/docs/Bytecode b/docs/Bytecode
index d691923..4914e65 100644
--- a/docs/Bytecode
+++ b/docs/Bytecode
@@ -44,19 +44,16 @@ Length is a 32bit numeric value (as described above) and unit is as follows:
00000101 => mm
00000110 => pt
00000111 => pc
- 00001000 => cap
- 00001001 => ch
- 00001010 => ic
- 00001011 => rem
- 00001100 => lh
- 00001101 => rlh
- 00001110 => vh
- 00001111 => vw
- 00010000 => vi
- 00010001 => vb
- 00010010 => vmin
- 00010011 => vmax
- 00010100 => q
+ 00001000 => ch
+ 00001001 => rem
+ 00001010 => lh
+ 00001011 => vh
+ 00001100 => vw
+ 00001101 => vi
+ 00001110 => vb
+ 00001111 => vmin
+ 00010000 => vmax
+ 00010001 => q
bit 9 set => percentage unit
bits 9-31: MBZ
diff --git a/examples/example1.c b/examples/example1.c
index c36a94d..1d2462c 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -98,13 +98,22 @@ static css_error node_presentational_hint(void *pw, void *node,
uint32_t *nhints, css_hint **hints);
static css_error ua_default_for_property(void *pw, uint32_t property,
css_hint *hint);
-static css_error compute_font_size(void *pw, const css_hint *parent,
- css_hint *size);
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data);
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
+static css_unit_ctx uint_len_ctx = {
+ .viewport_width = 800 * (1 << CSS_RADIX_POINT),
+ .viewport_height = 600 * (1 << CSS_RADIX_POINT),
+ .font_size_default = 16 * (1 << CSS_RADIX_POINT),
+ .font_size_minimum = 6 * (1 << CSS_RADIX_POINT),
+ .device_dpi = 96 * (1 << CSS_RADIX_POINT),
+ .root_style = NULL, /* We don't have a root node yet. */
+ .pw = NULL, /* We're not implementing measure callback */
+ .measure = NULL, /* We're not implementing measure callback */
+};
+
/* Table of function pointers for the LibCSS Select API. */
static css_select_handler select_handler = {
CSS_SELECT_HANDLER_VERSION_1,
@@ -143,9 +152,8 @@ static css_select_handler select_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
- compute_font_size,
set_libcss_node_data,
- get_libcss_node_data
+ get_libcss_node_data,
};
@@ -237,6 +245,7 @@ int main(int argc, char **argv)
lwc_intern_string(element, strlen(element), &element_name);
code = css_select_style(select_ctx, element_name,
+ &uint_len_ctx,
&media, NULL,
&select_handler, 0,
&style);
@@ -662,68 +671,6 @@ css_error ua_default_for_property(void *pw, uint32_t property, css_hint *hint)
return CSS_OK;
}
-css_error compute_font_size(void *pw, const css_hint *parent, css_hint *size)
-{
- static css_hint_length sizes[] = {
- { FLTTOFIX(6.75), CSS_UNIT_PT },
- { FLTTOFIX(7.50), CSS_UNIT_PT },
- { FLTTOFIX(9.75), CSS_UNIT_PT },
- { FLTTOFIX(12.0), CSS_UNIT_PT },
- { FLTTOFIX(13.5), CSS_UNIT_PT },
- { FLTTOFIX(18.0), CSS_UNIT_PT },
- { FLTTOFIX(24.0), CSS_UNIT_PT }
- };
- const css_hint_length *parent_size;
-
- UNUSED(pw);
-
- /* Grab parent size, defaulting to medium if none */
- if (parent == NULL) {
- parent_size = &sizes[CSS_FONT_SIZE_MEDIUM - 1];
- } else {
- assert(parent->status == CSS_FONT_SIZE_DIMENSION);
- assert(parent->data.length.unit != CSS_UNIT_EM);
- assert(parent->data.length.unit != CSS_UNIT_EX);
- parent_size = &parent->data.length;
- }
-
- assert(size->status != CSS_FONT_SIZE_INHERIT);
-
- if (size->status < CSS_FONT_SIZE_LARGER) {
- /* Keyword -- simple */
- size->data.length = sizes[size->status - 1];
- } else if (size->status == CSS_FONT_SIZE_LARGER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->status == CSS_FONT_SIZE_SMALLER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_EM ||
- size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value =
- FMUL(size->data.length.value, parent_size->value);
-
- if (size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.6));
- }
-
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_PCT) {
- size->data.length.value = FDIV(FMUL(size->data.length.value,
- parent_size->value), FLTTOFIX(100));
- size->data.length.unit = parent_size->unit;
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data)
{
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index f4b3e21..30e369b 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -19,6 +19,7 @@ extern "C"
#include <libcss/functypes.h>
#include <libcss/properties.h>
#include <libcss/types.h>
+#include <libcss/unit.h>
struct css_hint;
struct css_select_handler;
@@ -81,10 +82,7 @@ css_error css_computed_style_destroy(css_computed_style *style);
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- css_error (*compute_font_size)(void *pw,
- const struct css_hint *parent,
- struct css_hint *size),
- void *pw,
+ const css_unit_ctx *unit_ctx,
css_computed_style **restrict result);
/******************************************************************************
diff --git a/include/libcss/select.h b/include/libcss/select.h
index ca57456..25317e5 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -18,6 +18,7 @@ extern "C"
#include <libcss/hint.h>
#include <libcss/types.h>
#include <libcss/computed.h>
+#include <libcss/unit.h>
typedef enum css_pseudo_element {
CSS_PSEUDO_ELEMENT_NONE = 0,
@@ -123,9 +124,6 @@ typedef struct css_select_handler {
css_error (*ua_default_for_property)(void *pw, uint32_t property,
css_hint *hint);
- css_error (*compute_font_size)(void *pw, const css_hint *parent,
- css_hint *size);
-
/**
* Set libcss_node_data on a DOM node.
*
@@ -221,13 +219,16 @@ css_error css_select_default_style(css_select_ctx *ctx,
css_select_handler *handler, void *pw,
css_computed_style **style);
css_error css_select_style(css_select_ctx *ctx, void *node,
+ const css_unit_ctx *unit_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result);
css_error css_select_results_destroy(css_select_results *results);
css_error css_select_font_faces(css_select_ctx *ctx,
- const css_media *media, lwc_string *font_family,
+ const css_media *media,
+ const css_unit_ctx *unit_ctx,
+ lwc_string *font_family,
css_select_font_faces_results **result);
css_error css_select_font_faces_results_destroy(
css_select_font_faces_results *results);
diff --git a/include/libcss/types.h b/include/libcss/types.h
index d8ac494..2b0dfb7 100644
--- a/include/libcss/types.h
+++ b/include/libcss/types.h
@@ -88,19 +88,16 @@ typedef enum css_unit {
CSS_UNIT_MM = 0x05,
CSS_UNIT_PT = 0x06,
CSS_UNIT_PC = 0x07,
- CSS_UNIT_CAP = 0x08,
- CSS_UNIT_CH = 0x09,
- CSS_UNIT_IC = 0x0a,
- CSS_UNIT_REM = 0x0b,
- CSS_UNIT_LH = 0x0c,
- CSS_UNIT_RLH = 0x0d,
- CSS_UNIT_VH = 0x0e,
- CSS_UNIT_VW = 0x0f,
- CSS_UNIT_VI = 0x10,
- CSS_UNIT_VB = 0x11,
- CSS_UNIT_VMIN = 0x12,
- CSS_UNIT_VMAX = 0x13,
- CSS_UNIT_Q = 0x14,
+ CSS_UNIT_CH = 0x08,
+ CSS_UNIT_REM = 0x09,
+ CSS_UNIT_LH = 0x0a,
+ CSS_UNIT_VH = 0x0b,
+ CSS_UNIT_VW = 0x0c,
+ CSS_UNIT_VI = 0x0d,
+ CSS_UNIT_VB = 0x0e,
+ CSS_UNIT_VMIN = 0x0f,
+ CSS_UNIT_VMAX = 0x10,
+ CSS_UNIT_Q = 0x11,
CSS_UNIT_PCT = 0x15, /* Percentage */
@@ -116,7 +113,7 @@ typedef enum css_unit {
} css_unit;
/**
- * Media orienations
+ * Media orientations
*/
typedef enum css_media_orientation {
CSS_MEDIA_ORIENTATION_PORTRAIT = 0,
@@ -237,10 +234,6 @@ typedef struct css_media {
/* Scripting media features */
css_media_scripting scripting;
-
- /* Client details for length conversion */
- css_fixed client_font_size; /* In pt */
- css_fixed client_line_height; /* In css pixels */
} css_media;
/**
diff --git a/include/libcss/unit.h b/include/libcss/unit.h
new file mode 100644
index 0000000..67194c1
--- /dev/null
+++ b/include/libcss/unit.h
@@ -0,0 +1,156 @@
+/*
+ * This file is part of LibCSS.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef libcss_unit_h_
+#define libcss_unit_h_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libcss/types.h>
+
+/**
+ * Client callback for font measuring.
+ *
+ * \param[in] pw Client data.
+ * \param[in] style Style to measure font for, or NULL.
+ * \param[in] unit Either CSS_UNIT_EX, or CSS_UNIT_CH.
+ * \return length in CSS pixels.
+ */
+typedef css_fixed (*css_unit_len_measure)(
+ void *pw,
+ const css_computed_style *style,
+ const css_unit unit);
+
+/**
+ * LibCSS unit conversion context.
+ *
+ * The client callback is optional. It is used for measuring "ch"
+ * (glyph '0' advance) and "ex" (height of the letter 'x') units.
+ * If a NULL pointer is given, LibCSS will use a fixed scaling of
+ * the "em" unit.
+ */
+typedef struct css_unit_ctx {
+ /**
+ * Viewport width in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_width;
+ /**
+ * Viewport height in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_height;
+ /**
+ * Client default font size in CSS pixels.
+ */
+ css_fixed font_size_default;
+ /**
+ * Client minimum font size in CSS pixels. May be zero.
+ */
+ css_fixed font_size_minimum;
+ /**
+ * DPI of the device the style is selected for.
+ */
+ css_fixed device_dpi;
+ /**
+ * Computed style for the document root element, needed for rem units.
+ * May be NULL, in which case font_size_default is used instead, as
+ * would be the case if rem unit is used on the root element.
+ */
+ const css_computed_style *root_style;
+ /**
+ * Optional client private word for measure callback.
+ */
+ void *pw;
+ /**
+ * Optional client callback for font measuring.
+ */
+ const css_unit_len_measure measure;
+} css_unit_ctx;
+
+/**
+ * Convert css pixels to physical pixels.
+ *
+ * \param[in] css_pixels Length in css pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in device pixels.
+ */
+static inline css_fixed css_unit_css2device_px(
+ const css_fixed css_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(css_pixels, device_dpi), F_96);
+}
+
+/**
+ * Convert device pixels to css pixels.
+ *
+ * \param[in] device_pixels Length in physical pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in css pixels.
+ */
+static inline css_fixed css_unit_device2css_px(
+ const css_fixed device_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(device_pixels, F_96), device_dpi);
+}
+
+/**
+ * Convert a length to points (pt).
+ *
+ * \param[in] style Style to perform conversion for or NULL.
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in points.
+ */
+css_fixed css_unit_font_size_len2pt(
+ const css_computed_style *style,
+ const css_unit_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to CSS pixels.
+ *
+ * \param[in] style Style to perform conversion for or NULL.
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in CSS pixels.
+ */
+css_fixed css_unit_len2css_px(
+ const css_computed_style *style,
+ const css_unit_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to device pixels.
+ *
+ * \param[in] style Style to perform conversion for or NULL.
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in device pixels.
+ */
+css_fixed css_unit_len2device_px(
+ const css_computed_style *style,
+ const css_unit_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 7518281..7f5ea9d 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -34,19 +34,16 @@ typedef enum unit {
UNIT_MM = (1u << 8) + 5,
UNIT_PT = (1u << 8) + 6,
UNIT_PC = (1u << 8) + 7,
- UNIT_CAP = (1u << 8) + 8,
- UNIT_CH = (1u << 8) + 9,
- UNIT_IC = (1u << 8) + 10,
- UNIT_REM = (1u << 8) + 11,
- UNIT_LH = (1u << 8) + 12,
- UNIT_RLH = (1u << 8) + 13,
- UNIT_VH = (1u << 8) + 14,
- UNIT_VW = (1u << 8) + 15,
- UNIT_VI = (1u << 8) + 16,
- UNIT_VB = (1u << 8) + 17,
- UNIT_VMIN = (1u << 8) + 18,
- UNIT_VMAX = (1u << 8) + 19,
- UNIT_Q = (1u << 8) + 20,
+ UNIT_CH = (1u << 8) + 8,
+ UNIT_REM = (1u << 8) + 9,
+ UNIT_LH = (1u << 8) + 10,
+ UNIT_VH = (1u << 8) + 11,
+ UNIT_VW = (1u << 8) + 12,
+ UNIT_VI = (1u << 8) + 13,
+ UNIT_VB = (1u << 8) + 14,
+ UNIT_VMIN = (1u << 8) + 15,
+ UNIT_VMAX = (1u << 8) + 16,
+ UNIT_Q = (1u << 8) + 17,
UNIT_PCT = (1 << 9),
diff --git a/src/parse/properties/font.c b/src/parse/properties/font.c
index 681c613..5010242 100644
--- a/src/parse/properties/font.c
+++ b/src/parse/properties/font.c
@@ -27,12 +27,9 @@ static inline uint32_t css__to_parse_unit(css_unit u)
case CSS_UNIT_MM: return UNIT_MM;
case CSS_UNIT_PT: return UNIT_PT;
case CSS_UNIT_PC: return UNIT_PC;
- case CSS_UNIT_CAP: return UNIT_CAP;
case CSS_UNIT_CH: return UNIT_CH;
- case CSS_UNIT_IC: return UNIT_IC;
case CSS_UNIT_REM: return UNIT_REM;
case CSS_UNIT_LH: return UNIT_LH;
- case CSS_UNIT_RLH: return UNIT_RLH;
case CSS_UNIT_VH: return UNIT_VH;
case CSS_UNIT_VW: return UNIT_VW;
case CSS_UNIT_VI: return UNIT_VI;
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 707a22b..1e184f8 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1032,12 +1032,8 @@ css_error css__parse_unit_keyword(const char *ptr, size_t len, uint32_t *unit)
*unit = UNIT_DEG;
else if (strncasecmp(ptr, "rad", 3) == 0)
*unit = UNIT_RAD;
- else if (strncasecmp(ptr, "cap", 3) == 0)
- *unit = UNIT_CAP;
else if (strncasecmp(ptr, "rem", 3) == 0)
*unit = UNIT_REM;
- else if (strncasecmp(ptr, "rlh", 3) == 0)
- *unit = UNIT_RLH;
else if (strncasecmp(ptr, "dpi", 3) == 0)
*unit = UNIT_DPI;
else
@@ -1065,8 +1061,6 @@ css_error css__parse_unit_keyword(const char *ptr, size_t len, uint32_t *unit)
*unit = UNIT_PC;
else if (strncasecmp(ptr, "ch", 2) == 0)
*unit = UNIT_CH;
- else if (strncasecmp(ptr, "ic", 2) == 0)
- *unit = UNIT_IC;
else if (strncasecmp(ptr, "lh", 2) == 0)
*unit = UNIT_LH;
else if (strncasecmp(ptr, "vh", 2) == 0)
diff --git a/src/select/Makefile b/src/select/Makefile
index 8b47673..f5ddb18 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 format_list_style.c
+DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c font_face.c format_list_style.c unit.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/select/computed.c b/src/select/computed.c
index a1b345b..c019590 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -12,6 +12,7 @@
#include "select/dispatch.h"
#include "select/propget.h"
#include "select/propset.h"
+#include "select/unit.h"
#include "utils/utils.h"
static css_error compute_absolute_color(css_computed_style *style,
@@ -247,9 +248,7 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw,
+ const css_unit_ctx *unit_ctx,
css_computed_style **restrict result)
{
css_computed_style *composed;
@@ -275,8 +274,7 @@ css_error css_computed_style_compose(
}
/* Finally, compute absolute values for everything */
- error = css__compute_absolute_values(parent, composed,
- compute_font_size, pw);
+ error = css__compute_absolute_values(parent, composed, unit_ctx);
if (error != CSS_OK) {
return error;
}
@@ -1087,31 +1085,36 @@ uint8_t css_computed_order(const css_computed_style *style,
*
* \param parent Parent style, or NULL for tree root
* \param style Computed style to process
- * \param compute_font_size Callback to calculate an absolute font-size
- * \param pw Private word for callback
+ * \param unit_ctx Client length conversion context.
* \return CSS_OK on success.
*/
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw)
+ const css_unit_ctx *unit_ctx)
{
+ css_hint_length *ref_length = NULL;
css_hint psize, size, ex_size;
css_error error;
- /* Ensure font-size is absolute */
+ /* Get reference font-size for relative sizes. */
if (parent != NULL) {
psize.status = get_font_size(parent,
&psize.data.length.value,
&psize.data.length.unit);
+ if (psize.status != CSS_FONT_SIZE_DIMENSION) {
+ return CSS_BADPARM;
+ }
+ ref_length = &psize.data.length;
}
size.status = get_font_size(style,
&size.data.length.value,
&size.data.length.unit);
- error = compute_font_size(pw, parent != NULL ? &psize : NULL, &size);
+ error = css_unit_compute_absolute_font_size(ref_length,
+ unit_ctx->root_style,
+ unit_ctx->font_size_default,
+ &size);
if (error != CSS_OK)
return error;
@@ -1125,7 +1128,12 @@ css_error css__compute_absolute_values(const css_computed_style *parent,
ex_size.status = CSS_FONT_SIZE_DIMENSION;
ex_size.data.length.value = INTTOFIX(1);
ex_size.data.length.unit = CSS_UNIT_EX;
- error = compute_font_size(pw, &size, &ex_size);
+
+ error = css_unit_compute_absolute_font_size(
+ &size.data.length,
+ unit_ctx->root_style,
+ unit_ctx->font_size_default,
+ &ex_size);
if (error != CSS_OK)
return error;
diff --git a/src/select/computed.h b/src/select/computed.h
index c926cec..a4bd23d 100644
--- a/src/select/computed.h
+++ b/src/select/computed.h
@@ -10,6 +10,8 @@
#include <libcss/computed.h>
#include <libcss/hint.h>
+#include <libcss/unit.h>
+
#include "autogenerated_computed.h"
/**
@@ -35,8 +37,6 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw);
+ const css_unit_ctx *unit_ctx);
#endif
diff --git a/src/select/hash.c b/src/select/hash.c
index 4b11702..16aebf7 100644
--- a/src/select/hash.c
+++ b/src/select/hash.c
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <string.h>
+#include <libcss/hint.h>
+
#include "stylesheet.h"
#include "select/hash.h"
#include "select/mq.h"
@@ -368,7 +370,7 @@ css_error css__selector_hash_find(css_selector_hash *hash,
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
@@ -447,6 +449,7 @@ css_error css__selector_hash_find_by_class(css_selector_hash *hash,
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -527,6 +530,7 @@ css_error css__selector_hash_find_by_id(css_selector_hash *hash,
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -577,7 +581,7 @@ css_error css__selector_hash_find_universal(css_selector_hash *hash,
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
@@ -920,7 +924,7 @@ css_error _iterate_elements(
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
@@ -980,6 +984,7 @@ css_error _iterate_classes(
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -1041,6 +1046,7 @@ css_error _iterate_ids(
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -1084,7 +1090,7 @@ css_error _iterate_universal(
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
diff --git a/src/select/hash.h b/src/select/hash.h
index aecf15a..df4102f 100644
--- a/src/select/hash.h
+++ b/src/select/hash.h
@@ -10,6 +10,7 @@
#include <libwapcaplet/libwapcaplet.h>
+#include <libcss/unit.h>
#include <libcss/errors.h>
#include <libcss/functypes.h>
@@ -26,6 +27,7 @@ struct css_hash_selection_requirments {
lwc_string *id; /* Name of id, or NULL */
lwc_string *uni; /* Universal element string "*" */
const css_media *media; /* Media spec we're selecting for */
+ const css_unit_ctx *unit_ctx; /* Document unit conversion context. */
const css_bloom *node_bloom; /* Node's bloom filter */
};
diff --git a/src/select/helpers.h b/src/select/helpers.h
index ba2e3be..19ff7de 100644
--- a/src/select/helpers.h
+++ b/src/select/helpers.h
@@ -22,12 +22,9 @@ static inline css_unit css__to_css_unit(uint32_t u)
case UNIT_MM: return CSS_UNIT_MM;
case UNIT_PT: return CSS_UNIT_PT;
case UNIT_PC: return CSS_UNIT_PC;
- case UNIT_CAP: return CSS_UNIT_CAP;
case UNIT_CH: return CSS_UNIT_CH;
- case UNIT_IC: return CSS_UNIT_IC;
case UNIT_REM: return CSS_UNIT_REM;
case UNIT_LH: return CSS_UNIT_LH;
- case UNIT_RLH: return CSS_UNIT_RLH;
case UNIT_VH: return CSS_UNIT_VH;
case UNIT_VW: return CSS_UNIT_VW;
case UNIT_VI: return CSS_UNIT_VI;
diff --git a/src/select/mq.h b/src/select/mq.h
index 79303e9..a012a7b 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -10,113 +10,13 @@
#define css_select_mq_h_
#include "select/helpers.h"
-
-static inline css_fixed css_len2px(
- css_fixed length,
- css_unit unit,
- const css_media *media)
-{
- css_fixed px_per_unit;
-
- switch (unit) {
- case CSS_UNIT_VI:
- /* TODO: Assumes writing mode. */
- unit = CSS_UNIT_VW;
- break;
- case CSS_UNIT_VB:
- /* TODO: Assumes writing mode. */
- unit = CSS_UNIT_VH;
- break;
- case CSS_UNIT_VMIN:
- unit = (media->height < media->width) ?
- CSS_UNIT_VH : CSS_UNIT_VW;
- break;
- case CSS_UNIT_VMAX:
- unit = (media->width > media->height) ?
- CSS_UNIT_VH : CSS_UNIT_VW;
- break;
- default:
- break;
- }
-
- switch (unit) {
- case CSS_UNIT_EM:
- case CSS_UNIT_EX:
- case CSS_UNIT_CAP:
- case CSS_UNIT_CH:
- case CSS_UNIT_IC:
- {
- px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
-
- /* TODO: Handling these as fixed ratios of CSS_UNIT_EM. */
- switch (unit) {
- case CSS_UNIT_EX:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
- break;
- case CSS_UNIT_CAP:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.9));
- break;
- case CSS_UNIT_CH:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
- break;
- case CSS_UNIT_IC:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(1.1));
- break;
- default:
- break;
- }
- }
- break;
- case CSS_UNIT_PX:
- return length;
- case CSS_UNIT_IN:
- px_per_unit = F_96;
- break;
- case CSS_UNIT_CM:
- px_per_unit = FDIV(F_96, FLTTOFIX(2.54));
- break;
- case CSS_UNIT_MM:
- px_per_unit = FDIV(F_96, FLTTOFIX(25.4));
- break;
- case CSS_UNIT_Q:
- px_per_unit = FDIV(F_96, FLTTOFIX(101.6));
- break;
- case CSS_UNIT_PT:
- px_per_unit = FDIV(F_96, F_72);
- break;
- case CSS_UNIT_PC:
- px_per_unit = FDIV(F_96, INTTOFIX(6));
- break;
- case CSS_UNIT_REM:
- px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
- break;
- case CSS_UNIT_RLH:
- px_per_unit = media->client_line_height;
- break;
- case CSS_UNIT_VH:
- px_per_unit = FDIV(media->height, F_100);
- break;
- case CSS_UNIT_VW:
- px_per_unit = FDIV(media->width, F_100);
- break;
- default:
- px_per_unit = 0;
- break;
- }
-
- /* Ensure we round px_per_unit to the nearest whole number of pixels:
- * the use of FIXTOINT() below will truncate. */
- px_per_unit += F_0_5;
-
- /* Calculate total number of pixels */
- return FMUL(length, TRUNCATEFIX(px_per_unit));
-}
+#include "select/unit.h"
static inline bool mq_match_feature_range_length_op1(
css_mq_feature_op op,
const css_mq_value *value,
const css_fixed client_len,
- const css_media *media)
+ const css_unit_ctx *unit_ctx)
{
css_fixed v;
@@ -125,9 +25,9 @@ static inline bool mq_match_feature_range_length_op1(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_len2px(value->data.dim.len,
- css__to_css_unit(value->data.dim.unit),
- media);
+ v = css_unit_len2px_mq(unit_ctx,
+ value->data.dim.len,
+ css__to_css_unit(value->data.dim.unit));
} else {
v = value->data.dim.len;
}
@@ -148,7 +48,7 @@ static inline bool mq_match_feature_range_length_op2(
css_mq_feature_op op,
const css_mq_value *value,
const css_fixed client_len,
- const css_media *media)
+ const css_unit_ctx *unit_ctx)
{
css_fixed v;
@@ -160,9 +60,9 @@ static inline bool mq_match_feature_range_length_op2(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_len2px(value->data.dim.len,
- css__to_css_unit(value->data.dim.unit),
- media);
+ v = css_unit_len2px_mq(unit_ctx,
+ value->data.dim.len,
+ css__to_css_unit(value->data.dim.unit));
} else {
v = value->data.dim.len;
}
@@ -181,31 +81,33 @@ static inline bool mq_match_feature_range_length_op2(
/**
* Match media query features.
*
- * \param[in] feat Condition to match.
- * \param[in] media Current media spec, to check against feat.
+ * \param[in] feat Condition to match.
+ * \param[in] unit_ctx Current unit conversion context.
+ * \param[in] media Current media spec, to check against feat.
* \return true if condition matches, otherwise false.
*/
static inline bool mq_match_feature(
const css_mq_feature *feat,
+ const css_unit_ctx *unit_ctx,
const css_media *media)
{
/* TODO: Use interned string for comparison. */
if (strcmp(lwc_string_data(feat->name), "width") == 0) {
if (!mq_match_feature_range_length_op1(feat->op, &feat->value,
- media->width, media)) {
+ media->width, unit_ctx)) {
return false;
}
return mq_match_feature_range_length_op2(feat->op2,
- &feat->value2, media->width, media);
+ &feat->value2, media->width, unit_ctx);
} else if (strcmp(lwc_string_data(feat->name), "height") == 0) {
if (!mq_match_feature_range_length_op1(feat->op, &feat->value,
- media->height, media)) {
+ media->height, unit_ctx)) {
return false;
}
return mq_match_feature_range_length_op2(feat->op2,
- &feat->value2, media->height, media);
+ &feat->value2, media->height, unit_ctx);
}
/* TODO: Look at other feature names. */
@@ -216,12 +118,14 @@ static inline bool mq_match_feature(
/**
* Match media query conditions.
*
- * \param[in] cond Condition to match.
- * \param[in] media Current media spec, to check against cond.
+ * \param[in] cond Condition to match.
+ * \param[in] unit_ctx Current unit conversion context.
+ * \param[in] media Current media spec, to check against cond.
* \return true if condition matches, otherwise false.
*/
static inline bool mq_match_condition(
const css_mq_cond *cond,
+ const css_unit_ctx *unit_ctx,
const css_media *media)
{
bool matched = !cond->op;
@@ -230,11 +134,13 @@ static inline bool mq_match_condition(
bool part_matched;
if (cond->parts[i]->type == CSS_MQ_FEATURE) {
part_matched = mq_match_feature(
- cond->parts[i]->data.feat, media);
+ cond->parts[i]->data.feat,
+ unit_ctx, media);
} else {
assert(cond->parts[i]->type == CSS_MQ_COND);
part_matched = mq_match_condition(
- cond->parts[i]->data.cond, media);
+ cond->parts[i]->data.cond,
+ unit_ctx, media);
}
if (cond->op) {
@@ -261,19 +167,22 @@ static inline bool mq_match_condition(
* If anything in the list matches, the list matches. If none match
* it doesn't match.
*
- * \param[in] m Media query list.
- * \param[in] media Current media spec, to check against m.
+ * \param[in] m Media query list.
+ * \param[in] unit_ctx Current unit conversion context.
+ * \param[in] media Current media spec, to check against m.
* \return true if media query list matches media
*/
static inline bool mq__list_match(
const css_mq_query *m,
+ const css_unit_ctx *unit_ctx,
const css_media *media)
{
for (; m != NULL; m = m->next) {
/* Check type */
if (!!(m->type & media->type) != m->negate_type) {
if (m->cond == NULL ||
- mq_match_condition(m->cond, media)) {
+ mq_match_condition(m->cond,
+ unit_ctx, media)) {
/* We have a match, no need to look further. */
return true;
}
@@ -286,11 +195,15 @@ static inline bool mq__list_match(
/**
* Test whether the rule applies for current media.
*
- * \param rule Rule to test
- * \param media Current media spec
+ * \param rule Rule to test
+ * \param unit_ctx Current unit conversion context.
+ * \param media Current media spec
* \return true iff chain's rule applies for media
*/
-static inline bool mq_rule_good_for_media(const css_rule *rule, const css_media *media)
+static inline bool mq_rule_good_for_media(
+ const css_rule *rule,
+ const css_unit_ctx *unit_ctx,
+ const css_media *media)
{
bool applies = true;
const css_rule *ancestor = rule;
@@ -299,7 +212,7 @@ static inline bool mq_rule_good_for_media(const css_rule *rule, const css_media
const css_rule_media *m = (const css_rule_media *) ancestor;
if (ancestor->type == CSS_RULE_MEDIA) {
- applies = mq__list_match(m->media, media);
+ applies = mq__list_match(m->media, unit_ctx, media);
if (applies == false) {
break;
}
diff --git a/src/select/select.c b/src/select/select.c
index f6efbfe..b050c0c 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -23,6 +23,7 @@
#include "select/propset.h"
#include "select/font_face.h"
#include "select/select.h"
+#include "select/unit.h"
#include "utils/parserutilserror.h"
#include "utils/utils.h"
@@ -98,6 +99,7 @@ typedef struct css_select_font_faces_list {
typedef struct css_select_font_faces_state {
lwc_string *font_family;
const css_media *media;
+ const css_unit_ctx *unit_ctx;
css_select_font_faces_list ua_font_faces;
css_select_font_faces_list user_font_faces;
@@ -1051,12 +1053,13 @@ static void css_select__finalise_selection_state(
/**
* Initialise a selection state.
*
- * \param[in] state The selection state to initialise
- * \param[in] node The node we are selecting for.
- * \param[in] parent The node's parent node, or NULL.
- * \param[in] media The media specification we're selecting for.
- * \param[in] handler The client selection callback table.
- * \param[in] pw The client private data, passsed out to callbacks.
+ * \param[in] state The selection state to initialise
+ * \param[in] node The node we are selecting for.
+ * \param[in] parent The node's parent node, or NULL.
+ * \param[in] media The media specification we're selecting for.
+ * \param[in] unit_ctx Unit conversion context.
+ * \param[in] handler The client selection callback table.
+ * \param[in] pw The client private data, passsed out to callbacks.
* \return CSS_OK or appropriate error otherwise.
*/
static css_error css_select__initialise_selection_state(
@@ -1064,6 +1067,7 @@ static css_error css_select__initialise_selection_state(
void *node,
void *parent,
const css_media *media,
+ const css_unit_ctx *unit_ctx,
css_select_handler *handler,
void *pw)
{
@@ -1074,6 +1078,7 @@ static css_error css_select__initialise_selection_state(
memset(state, 0, sizeof(*state));
state->node = node;
state->media = media;
+ state->unit_ctx = unit_ctx;
state->handler = handler;
state->pw = pw;
state->next_reject = state->reject_cache +
@@ -1164,6 +1169,7 @@ failed:
*
* \param ctx Selection context to use
* \param node Node to select style for
+ * \param unit_ctx Context for length unit conversions.
* \param media Currently active media specification
* \param inline_style Corresponding inline style for node, or NULL
* \param handler Dispatch table of handler functions
@@ -1181,6 +1187,7 @@ failed:
* update the fully computed style for a node when layout changes.
*/
css_error css_select_style(css_select_ctx *ctx, void *node,
+ const css_unit_ctx *unit_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result)
@@ -1201,7 +1208,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
return error;
error = css_select__initialise_selection_state(
- &state, node, parent, media, handler, pw);
+ &state, node, parent, media, unit_ctx, handler, pw);
if (error != CSS_OK)
return error;
@@ -1266,7 +1273,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if (mq__list_match(s.media, media) &&
+ if (mq__list_match(s.media, unit_ctx, media) &&
s.sheet->disabled == false) {
error = select_from_sheet(ctx, s.sheet,
s.origin, &state);
@@ -1353,7 +1360,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
/* Only compute absolute values for the base element */
error = css__compute_absolute_values(NULL,
state.results->styles[CSS_PSEUDO_ELEMENT_NONE],
- handler->compute_font_size, pw);
+ unit_ctx);
if (error != CSS_OK)
goto cleanup;
}
@@ -1417,12 +1424,15 @@ css_error css_select_results_destroy(css_select_results *results)
*
* \param ctx Selection context
* \param media Currently active media spec
+ * \param unit_ctx Current unit conversion context.
* \param font_family Font family to search for
* \param result Pointer to location to receive result
* \return CSS_OK on success, appropriate error otherwise.
*/
css_error css_select_font_faces(css_select_ctx *ctx,
- const css_media *media, lwc_string *font_family,
+ const css_media *media,
+ const css_unit_ctx *unit_ctx,
+ lwc_string *font_family,
css_select_font_faces_results **result)
{
uint32_t i;
@@ -1436,6 +1446,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
memset(&state, 0, sizeof(css_select_font_faces_state));
state.font_family = font_family;
state.media = media;
+ state.unit_ctx = unit_ctx;
/* Iterate through the top-level stylesheets, selecting font-faces
* from those which apply to our current media requirements and
@@ -1443,7 +1454,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if (mq__list_match(s.media, media) &&
+ if (mq__list_match(s.media, unit_ctx, media) &&
s.sheet->disabled == false) {
error = select_font_faces_from_sheet(s.sheet,
s.origin, &state);
@@ -1843,6 +1854,7 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
if (import->sheet != NULL &&
mq__list_match(import->media,
+ state->unit_ctx,
state->media)) {
/* It's applicable, so process it */
if (sp >= IMPORT_STACK_SIZE)
@@ -1886,7 +1898,8 @@ static css_error _select_font_face_from_rule(
const css_rule_font_face *rule, css_origin origin,
css_select_font_faces_state *state)
{
- if (mq_rule_good_for_media((const css_rule *) rule, state->media)) {
+ if (mq_rule_good_for_media((const css_rule *) rule,
+ state->unit_ctx, state->media)) {
bool correct_family = false;
if (lwc_string_isequal(
@@ -1951,6 +1964,7 @@ static css_error select_font_faces_from_sheet(
if (import->sheet != NULL &&
mq__list_match(import->media,
+ state->unit_ctx,
state->media)) {
/* It's applicable, so process it */
if (sp >= IMPORT_STACK_SIZE)
@@ -2098,6 +2112,7 @@ css_error match_selectors_in_sheet(css_select_ctx *ctx,
/* Set up general selector chain requirments */
req.media = state->media;
+ req.unit_ctx = state->unit_ctx;
req.node_bloom = state->node_data->bloom;
req.uni = ctx->universal;
diff --git a/src/select/select.h b/src/select/select.h
index dc9aa4a..0a16b12 100644
--- a/src/select/select.h
+++ b/src/select/select.h
@@ -64,6 +64,7 @@ struct css_node_data {
typedef struct css_select_state {
void *node; /* Node we're selecting for */
const css_media *media; /* Currently active media spec */
+ const css_unit_ctx *unit_ctx; /* Unit conversion context. */
css_select_results *results; /* Result set to populate */
css_pseudo_element current_pseudo; /* Current pseudo element */
diff --git a/src/select/unit.c b/src/select/unit.c
new file mode 100644
index 0000000..9129d72
--- /dev/null
+++ b/src/select/unit.c
@@ -0,0 +1,511 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include <libcss/stylesheet.h>
+
+#include "utils/utils.h"
+
+#include "propget.h"
+#include "unit.h"
+
+/**
+ * Map viewport-relative length units to either vh or vw.
+ *
+ * Non-viewport-relative units are unchanged.
+ *
+ * \param[in] style Reference style.
+ * \param[in] viewport_height Viewport height in px.
+ * \param[in] viewport_width Viewport width in px.
+ * \param[in] unit Unit to map.
+ * \return the mapped unit.
+ */
+static inline css_unit css_unit__map_viewport_units(
+ const css_computed_style *style,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width,
+ const css_unit unit)
+{
+ switch (unit) {
+ case CSS_UNIT_VI:
+ return (style != NULL && get_writing_mode(style) !=
+ CSS_WRITING_MODE_HORIZONTAL_TB) ?
+ CSS_UNIT_VH : CSS_UNIT_VW;
+
+ case CSS_UNIT_VB:
+ return (style != NULL && get_writing_mode(style) !=
+ CSS_WRITING_MODE_HORIZONTAL_TB) ?
+ CSS_UNIT_VW : CSS_UNIT_VH;
+
+ case CSS_UNIT_VMIN:
+ return (viewport_height < viewport_width) ?
+ CSS_UNIT_VH : CSS_UNIT_VW;
+
+ case CSS_UNIT_VMAX:
+ return (viewport_height > viewport_width) ?
+ CSS_UNIT_VH : CSS_UNIT_VW;
+
+ default:
+ return unit;
+ }
+}
+
+/**
+ * Convert an absolute length to points (pt).
+ *
+ * \param[in] style Style to get font-size from, or NULL.
+ * \param[in] viewport_height Client viewport height.
+ * \param[in] viewport_width Client viewport width.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return length in points (pt).
+ */
+static inline css_fixed css_unit__absolute_len2pt(
+ const css_computed_style *style,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width,
+ const css_fixed length,
+ const css_unit unit)
+{
+ /* Length must not be relative */
+ assert(unit != CSS_UNIT_EM &&
+ unit != CSS_UNIT_EX &&
+ unit != CSS_UNIT_CH &&
+ unit != CSS_UNIT_REM);
+
+ switch (css_unit__map_viewport_units(style,
+ viewport_height,
+ viewport_width,
+ unit)) {
+ case CSS_UNIT_PX:
+ return FDIV(FMUL(length, F_72), F_96);
+
+ case CSS_UNIT_IN:
+ return FMUL(length, F_72);
+
+ case CSS_UNIT_CM:
+ return FMUL(length, FDIV(F_72, FLTTOFIX(2.54)));
+
+ case CSS_UNIT_MM:
+ return FMUL(length, FDIV(F_72, FLTTOFIX(25.4)));
+
+ case CSS_UNIT_Q:
+ return FMUL(length, FDIV(F_72, FLTTOFIX(101.6)));
+
+ case CSS_UNIT_PT:
+ return length;
+
+ case CSS_UNIT_PC:
+ return FMUL(length, INTTOFIX(12));
+
+ case CSS_UNIT_VH:
+ return FDIV(FMUL(FDIV(FMUL(length, viewport_height), F_100),
+ F_72), F_96);
+
+ case CSS_UNIT_VW:
+ return FDIV(FMUL(FDIV(FMUL(length, viewport_width), F_100),
+ F_72), F_96);
+
+ default:
+ return 0;
+ }
+}
+
+/* Exported function, documented in libcss/unit.h. */
+css_fixed css_unit_font_size_len2pt(
+ const css_computed_style *style,
+ const css_unit_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ return css_unit__absolute_len2pt(
+ style,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ length,
+ unit);
+}
+
+/**
+ * Get font size from a style in CSS pixels.
+ *
+ * The style should have font size in absolute units.
+ *
+ * \param[in] style Style to get font-size from, or NULL.
+ * \param[in] font_size_default Client font size for NULL style.
+ * \param[in] font_size_minimum Client minimum font size clamp.
+ * \param[in] viewport_height Client viewport height.
+ * \param[in] viewport_width Client viewport width.
+ * \return font-size in CSS pixels.
+ */
+static inline css_fixed css_unit__font_size_px(
+ const css_computed_style *style,
+ const css_fixed font_size_default,
+ const css_fixed font_size_minimum,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width)
+{
+ css_fixed font_length = 0;
+ css_unit font_unit = CSS_UNIT_PT;
+
+ if (style == NULL) {
+ return font_size_default;
+ }
+
+ get_font_size(style, &font_length, &font_unit);
+
+ if (font_unit != CSS_UNIT_PX) {
+ font_length = css_unit__absolute_len2pt(style,
+ viewport_height,
+ viewport_width,
+ font_length,
+ font_unit);
+
+ /* Convert from pt to CSS pixels.*/
+ font_length = FDIV(FMUL(font_length, F_96), F_72);
+ }
+
+ /* Clamp to configured minimum */
+ if (font_length < font_size_minimum) {
+ font_length = font_size_minimum;
+ }
+
+ return font_length;
+}
+
+/**
+ * Get the number of CSS pixels for a given unit.
+ *
+ * \param[in] measure Client callback for font measuring.
+ * \param[in] ref_style Reference style. (Element or parent, or NULL).
+ * \param[in] root_style Root element style or NULL.
+ * \param[in] font_size_default Client default font size in CSS pixels.
+ * \param[in] font_size_minimum Client minimum font size in CSS pixels.
+ * \param[in] viewport_height Viewport height in CSS pixels.
+ * \param[in] viewport_width Viewport width in CSS pixels.
+ * \param[in] unit The unit to convert from.
+ * \param[in] pw Client private word for measure callback.
+ * \return Number of CSS pixels equivalent to the given unit.
+ */
+static inline css_fixed css_unit__px_per_unit(
+ const css_unit_len_measure measure,
+ const css_computed_style *ref_style,
+ const css_computed_style *root_style,
+ const css_fixed font_size_default,
+ const css_fixed font_size_minimum,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width,
+ const css_unit unit,
+ void *pw)
+{
+ switch (css_unit__map_viewport_units(
+ ref_style,
+ viewport_height,
+ viewport_width,
+ unit)) {
+ case CSS_UNIT_EM:
+ return css_unit__font_size_px(
+ ref_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width);
+
+ case CSS_UNIT_EX:
+ if (measure != NULL) {
+ return measure(pw, ref_style, CSS_UNIT_EX);
+ }
+ return FMUL(css_unit__font_size_px(
+ ref_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width), FLTTOFIX(0.6));
+
+ case CSS_UNIT_CH:
+ if (measure != NULL) {
+ return measure(pw, ref_style, CSS_UNIT_CH);
+ }
+ return FMUL(css_unit__font_size_px(
+ ref_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width), FLTTOFIX(0.4));
+
+ case CSS_UNIT_PX:
+ return F_1;
+
+ case CSS_UNIT_IN:
+ return F_96;
+
+ case CSS_UNIT_CM:
+ return FDIV(F_96, FLTTOFIX(2.54));
+
+ case CSS_UNIT_MM:
+ return FDIV(F_96, FLTTOFIX(25.4));
+
+ case CSS_UNIT_Q:
+ return FDIV(F_96, FLTTOFIX(101.6));
+
+ case CSS_UNIT_PT:
+ return FDIV(F_96, F_72);
+
+ case CSS_UNIT_PC:
+ return FDIV(F_96, INTTOFIX(6));
+
+ case CSS_UNIT_REM:
+ return css_unit__font_size_px(
+ root_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width);
+
+ case CSS_UNIT_VH:
+ return FDIV(viewport_width, F_100);
+
+ case CSS_UNIT_VW:
+ return FDIV(viewport_height, F_100);
+
+ default:
+ return 0;
+ }
+}
+
+/* Exported function, documented in unit.h. */
+css_fixed css_unit_len2px_mq(
+ const css_unit_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ /* In the media query context there is no reference or root element
+ * style, so these are hard-coded to NULL. */
+ css_fixed px_per_unit = css_unit__px_per_unit(
+ ctx->measure,
+ NULL,
+ NULL,
+ ctx->font_size_default,
+ ctx->font_size_minimum,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ unit,
+ ctx->pw);
+
+ /* Ensure we round px_per_unit to the nearest whole number of pixels:
+ * the use of FIXTOINT() below will truncate. */
+ px_per_unit += F_0_5;
+
+ /* Calculate total number of pixels */
+ return FMUL(length, TRUNCATEFIX(px_per_unit));
+}
+
+/* Exported function, documented in libcss/unit.h. */
+css_fixed css_unit_len2css_px(
+ const css_computed_style *style,
+ const css_unit_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ css_fixed px_per_unit = css_unit__px_per_unit(
+ ctx->measure,
+ style,
+ ctx->root_style,
+ ctx->font_size_default,
+ ctx->font_size_minimum,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ unit,
+ ctx->pw);
+
+ /* Ensure we round px_per_unit to the nearest whole number of pixels:
+ * the use of FIXTOINT() below will truncate. */
+ px_per_unit += F_0_5;
+
+ /* Calculate total number of pixels */
+ return FMUL(length, TRUNCATEFIX(px_per_unit));
+}
+
+/* Exported function, documented in libcss/unit.h. */
+css_fixed css_unit_len2device_px(
+ const css_computed_style *style,
+ const css_unit_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ css_fixed px_per_unit = css_unit__px_per_unit(
+ ctx->measure,
+ style,
+ ctx->root_style,
+ ctx->font_size_default,
+ ctx->font_size_minimum,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ unit,
+ ctx->pw);
+
+ px_per_unit = css_unit_css2device_px(px_per_unit, ctx->device_dpi);
+
+ /* Ensure we round px_per_unit to the nearest whole number of pixels:
+ * the use of FIXTOINT() below will truncate. */
+ px_per_unit += F_0_5;
+
+ /* Calculate total number of pixels */
+ return FMUL(length, TRUNCATEFIX(px_per_unit));
+}
+
+/**
+ * Get font size from a computed style.
+ *
+ * The computed style will have font-size with an absolute unit.
+ * If no computed style is given, the client default font-size will be returned.
+ *
+ * \param[in] style Reference style. (Element or parent, or NULL).
+ * \param[in] font_size_default Client default font size in CSS pixels.
+ * \return The font size in absolute units.
+ */
+static inline css_hint_length css_unit__get_font_size(
+ const css_computed_style *style,
+ css_fixed font_size_default)
+{
+ css_hint_length size;
+
+ if (style == NULL) {
+ size.value = font_size_default;
+ size.unit = CSS_UNIT_PX;
+ } else {
+ enum css_font_size_e status = get_font_size(
+ style, &size.value, &size.unit);
+
+ UNUSED(status);
+
+ assert(status == CSS_FONT_SIZE_DIMENSION);
+ assert(size.unit != CSS_UNIT_EM);
+ assert(size.unit != CSS_UNIT_EX);
+ assert(size.unit != CSS_UNIT_PCT);
+ }
+
+ return size;
+}
+
+/* Exported function, documented in unit.h. */
+css_error css_unit_compute_absolute_font_size(
+ const css_hint_length *ref_length,
+ const css_computed_style *root_style,
+ css_fixed font_size_default,
+ css_hint *size)
+{
+ css_hint_length ref_len = {
+ .value = font_size_default,
+ .unit = CSS_UNIT_PX,
+ };
+
+ if (ref_length != NULL) {
+ /* Must be absolute. */
+ assert(ref_length->unit != CSS_UNIT_EM);
+ assert(ref_length->unit != CSS_UNIT_EX);
+ assert(ref_length->unit != CSS_UNIT_PCT);
+
+ ref_len = *ref_length;
+ }
+
+ assert(size->status != CSS_FONT_SIZE_INHERIT);
+
+ switch (size->status) {
+ case CSS_FONT_SIZE_XX_SMALL: /* Fall-through. */
+ case CSS_FONT_SIZE_X_SMALL: /* Fall-through. */
+ case CSS_FONT_SIZE_SMALL: /* Fall-through. */
+ case CSS_FONT_SIZE_MEDIUM: /* Fall-through. */
+ case CSS_FONT_SIZE_LARGE: /* Fall-through. */
+ case CSS_FONT_SIZE_X_LARGE: /* Fall-through. */
+ case CSS_FONT_SIZE_XX_LARGE:
+ {
+ static const css_fixed factors[CSS_FONT_SIZE_XX_LARGE] = {
+ [CSS_FONT_SIZE_XX_SMALL - 1] = FLTTOFIX(0.5625),
+ [CSS_FONT_SIZE_X_SMALL - 1] = FLTTOFIX(0.6250),
+ [CSS_FONT_SIZE_SMALL - 1] = FLTTOFIX(0.8125),
+ [CSS_FONT_SIZE_MEDIUM - 1] = FLTTOFIX(1.0000),
+ [CSS_FONT_SIZE_LARGE - 1] = FLTTOFIX(1.1250),
+ [CSS_FONT_SIZE_X_LARGE - 1] = FLTTOFIX(1.5000),
+ [CSS_FONT_SIZE_XX_LARGE - 1] = FLTTOFIX(2.0000),
+ };
+ assert(CSS_FONT_SIZE_INHERIT == 0);
+ assert(CSS_FONT_SIZE_XX_SMALL == 1);
+
+ size->data.length.value = FMUL(factors[size->status - 1],
+ font_size_default);
+ size->data.length.unit = CSS_UNIT_PX;
+ size->status = CSS_FONT_SIZE_DIMENSION;
+ break;
+ }
+ case CSS_FONT_SIZE_LARGER:
+ size->data.length.value = FMUL(ref_len.value, FLTTOFIX(1.2));
+ size->data.length.unit = ref_len.unit;
+ size->status = CSS_FONT_SIZE_DIMENSION;
+ break;
+
+ case CSS_FONT_SIZE_SMALLER:
+ size->data.length.value = FDIV(ref_len.value, FLTTOFIX(1.2));
+ size->data.length.unit = ref_len.unit;
+ size->status = CSS_FONT_SIZE_DIMENSION;
+ break;
+
+ case CSS_FONT_SIZE_DIMENSION:
+ /* Convert any relative units to absolute. */
+ switch (size->data.length.unit) {
+ case CSS_UNIT_PCT:
+ size->data.length.value = FDIV(FMUL(
+ size->data.length.value,
+ ref_len.value), INTTOFIX(100));
+ size->data.length.unit = ref_len.unit;
+ break;
+
+ case CSS_UNIT_EM: /* Fall-through */
+ case CSS_UNIT_EX: /* Fall-through */
+ case CSS_UNIT_CH:
+ /* Parent relative units. */
+ size->data.length.value = FMUL(
+ size->data.length.value, ref_len.value);
+
+ switch (size->data.length.unit) {
+ case CSS_UNIT_EX:
+ size->data.length.value = FMUL(
+ size->data.length.value,
+ FLTTOFIX(0.6));
+ break;
+
+ case CSS_UNIT_CH:
+ size->data.length.value = FMUL(
+ size->data.length.value,
+ FLTTOFIX(0.4));
+ break;
+
+ default:
+ break;
+ }
+ size->data.length.unit = ref_len.unit;
+ break;
+
+ case CSS_UNIT_REM:
+ /* Root element relative units. */
+ ref_len = css_unit__get_font_size(root_style,
+ font_size_default);
+
+ size->data.length.unit = ref_len.unit;
+ size->data.length.value = FMUL(
+ size->data.length.value, ref_len.value);
+ break;
+
+ default:
+ break;
+ }
+ default:
+ break;
+ }
+
+ return CSS_OK;
+}
diff --git a/src/select/unit.h b/src/select/unit.h
new file mode 100644
index 0000000..6a677b6
--- /dev/null
+++ b/src/select/unit.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#ifndef css_select_unit_h_
+#define css_select_unit_h_
+
+#include <libcss/unit.h>
+
+/**
+ * Convert a length to CSS pixels for a media query context.
+ *
+ * \param[in] ctx Document unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in CSS pixels.
+ */
+css_fixed css_unit_len2px_mq(
+ const css_unit_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert relative font size units to absolute units.
+ *
+ * \param[in] ref_length Reference font-size length or NULL.
+ * \param[in] root_style Root element style or NULL.
+ * \param[in] font_size_default Client default font size in CSS pixels.
+ * \param[in,out] size The length to convert.
+ * \return CSS_OK on success, or appropriate error otherwise.
+ */
+css_error css_unit_compute_absolute_font_size(
+ const css_hint_length *ref_length,
+ const css_computed_style *root_style,
+ css_fixed font_size_default,
+ css_hint *size);
+
+#endif
diff --git a/test/data/parse2/units.dat b/test/data/parse2/units.dat
index 1052dc5..800df75 100644
--- a/test/data/parse2/units.dat
+++ b/test/data/parse2/units.dat
@@ -70,14 +70,6 @@
#reset
#data
-* { width: 10cap; }
-#errors
-#expected
-| *
-| width: 10cap
-#reset
-
-#data
* { width: 10ch; }
#errors
#expected
@@ -86,14 +78,6 @@
#reset
#data
-* { width: 10ic; }
-#errors
-#expected
-| *
-| width: 10ic
-#reset
-
-#data
* { width: 10rem; }
#errors
#expected
@@ -110,14 +94,6 @@
#reset
#data
-* { width: 10rlh; }
-#errors
-#expected
-| *
-| width: 10rlh
-#reset
-
-#data
* { width: 10vh; }
#errors
#expected
diff --git a/test/data/select/tests1.dat b/test/data/select/tests1.dat
index 1a91e82..295ab2e 100644
--- a/test/data/select/tests1.dat
+++ b/test/data/select/tests1.dat
@@ -59,7 +59,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -173,7 +173,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -291,7 +291,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -410,7 +410,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -529,7 +529,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -648,7 +648,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -757,7 +757,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -867,7 +867,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -977,7 +977,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1086,7 +1086,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1200,7 +1200,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1314,7 +1314,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1429,7 +1429,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1547,7 +1547,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1664,7 +1664,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1787,7 +1787,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1910,7 +1910,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2033,7 +2033,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2160,7 +2160,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2286,7 +2286,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2410,7 +2410,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2533,7 +2533,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2656,7 +2656,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2779,7 +2779,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2902,7 +2902,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3025,7 +3025,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3148,7 +3148,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3271,7 +3271,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3394,7 +3394,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3517,7 +3517,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3640,7 +3640,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 10.600pt
+font-size: 13.342px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3763,7 +3763,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 14.391pt
+font-size: 19.187px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3886,7 +3886,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 24pt
+font-size: 32px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4009,7 +4009,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 18pt
+font-size: 24px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4132,7 +4132,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 13.500pt
+font-size: 18px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4255,7 +4255,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4378,7 +4378,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 9.750pt
+font-size: 13px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4501,7 +4501,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 7.500pt
+font-size: 10px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4624,7 +4624,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 6.750pt
+font-size: 9px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4870,7 +4870,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4986,7 +4986,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5102,7 +5102,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5218,7 +5218,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5331,7 +5331,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5445,7 +5445,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5559,7 +5559,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5673,7 +5673,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5783,7 +5783,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5894,7 +5894,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6004,7 +6004,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6114,7 +6114,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6224,7 +6224,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6334,7 +6334,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6444,7 +6444,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6556,7 +6556,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6666,7 +6666,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6776,7 +6776,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6887,7 +6887,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6997,7 +6997,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7107,7 +7107,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7217,7 +7217,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7327,7 +7327,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7437,7 +7437,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7547,7 +7547,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7657,7 +7657,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7766,7 +7766,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7875,7 +7875,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7984,7 +7984,7 @@ flex-shrink: 30.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8095,7 +8095,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8206,7 +8206,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8315,7 +8315,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8426,7 +8426,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8537,7 +8537,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8648,7 +8648,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8757,7 +8757,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8866,7 +8866,7 @@ flex-shrink: 1.000
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8975,7 +8975,7 @@ flex-shrink: 1.000
flex-wrap: wrap-reverse
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9084,7 +9084,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9193,7 +9193,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9302,7 +9302,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9411,7 +9411,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9520,7 +9520,7 @@ flex-shrink: 1.000
flex-wrap: wrap-reverse
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9631,7 +9631,7 @@ flex-shrink: 1.000
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9742,7 +9742,7 @@ flex-shrink: 1.000
flex-wrap: wrap-reverse
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9851,7 +9851,7 @@ flex-shrink: 0.899
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9960,7 +9960,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10069,7 +10069,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10178,7 +10178,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10287,7 +10287,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10396,7 +10396,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10505,7 +10505,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10616,7 +10616,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10727,7 +10727,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10836,7 +10836,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10945,7 +10945,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11054,7 +11054,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11165,7 +11165,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11274,7 +11274,7 @@ flex-shrink: 3.780
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11385,7 +11385,7 @@ flex-shrink: 3.780
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11494,7 +11494,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11603,7 +11603,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11712,7 +11712,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11821,7 +11821,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11930,7 +11930,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12039,7 +12039,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12148,7 +12148,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12257,7 +12257,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12366,7 +12366,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12419,7 +12419,7 @@ z-index: auto
#tree
| div*
#ua
-div { width: 10cap; }
+div { width: 10em; }
#errors
#expected
align-content: stretch
@@ -12475,7 +12475,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12519,7 +12519,7 @@ unicode-bidi: normal
vertical-align: baseline
visibility: visible
white-space: normal
-width: 10cap
+width: 10em
word-spacing: normal
writing-mode: horizontal-tb
z-index: auto
@@ -12584,7 +12584,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12637,7 +12637,7 @@ z-index: auto
#tree
| div*
#ua
-div { width: 10ic; }
+div { width: 10ch; }
#errors
#expected
align-content: stretch
@@ -12693,7 +12693,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12737,7 +12737,7 @@ unicode-bidi: normal
vertical-align: baseline
visibility: visible
white-space: normal
-width: 10ic
+width: 10ch
word-spacing: normal
writing-mode: horizontal-tb
z-index: auto
@@ -12802,7 +12802,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12911,7 +12911,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12964,7 +12964,7 @@ z-index: auto
#tree
| div*
#ua
-div { width: 10rlh; }
+div { width: 10rem; }
#errors
#expected
align-content: stretch
@@ -13020,7 +13020,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13064,7 +13064,7 @@ unicode-bidi: normal
vertical-align: baseline
visibility: visible
white-space: normal
-width: 10rlh
+width: 10rem
word-spacing: normal
writing-mode: horizontal-tb
z-index: auto
@@ -13129,7 +13129,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13238,7 +13238,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13347,7 +13347,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13456,7 +13456,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13565,7 +13565,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13674,7 +13674,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13783,7 +13783,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13892,7 +13892,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -14020,7 +14020,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
diff --git a/test/dump.h b/test/dump.h
index d67bb2a..79819e0 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -584,24 +584,15 @@ static void dump_unit(css_fixed val, uint32_t unit, char **ptr)
case UNIT_PC:
*ptr += sprintf(*ptr, "pc");
break;
- case UNIT_CAP:
- *ptr += sprintf(*ptr, "cap");
- break;
case UNIT_CH:
*ptr += sprintf(*ptr, "ch");
break;
- case UNIT_IC:
- *ptr += sprintf(*ptr, "ic");
- break;
case UNIT_REM:
*ptr += sprintf(*ptr, "rem");
break;
case UNIT_LH:
*ptr += sprintf(*ptr, "lh");
break;
- case UNIT_RLH:
- *ptr += sprintf(*ptr, "rlh");
- break;
case UNIT_VH:
*ptr += sprintf(*ptr, "vh");
break;
diff --git a/test/dump_computed.h b/test/dump_computed.h
index b0c8bda..8ac6424 100644
--- a/test/dump_computed.h
+++ b/test/dump_computed.h
@@ -105,24 +105,15 @@ static size_t dump_css_unit(css_fixed val, css_unit unit, char *ptr, size_t len)
case CSS_UNIT_PC:
ret += snprintf(ptr + ret, len - ret, "pc");
break;
- case CSS_UNIT_CAP:
- ret += snprintf(ptr + ret, len - ret, "cap");
- break;
case CSS_UNIT_CH:
ret += snprintf(ptr + ret, len - ret, "ch");
break;
- case CSS_UNIT_IC:
- ret += snprintf(ptr + ret, len - ret, "ic");
- break;
case CSS_UNIT_REM:
ret += snprintf(ptr + ret, len - ret, "rem");
break;
case CSS_UNIT_LH:
ret += snprintf(ptr + ret, len - ret, "lh");
break;
- case CSS_UNIT_RLH:
- ret += snprintf(ptr + ret, len - ret, "rlh");
- break;
case CSS_UNIT_VH:
ret += snprintf(ptr + ret, len - ret, "vh");
break;
diff --git a/test/select.c b/test/select.c
index 33f31dd..c104b38 100644
--- a/test/select.c
+++ b/test/select.c
@@ -159,13 +159,15 @@ static css_error node_presentational_hint(void *pw, void *node,
uint32_t *nhints, css_hint **hints);
static css_error ua_default_for_property(void *pw, uint32_t property,
css_hint *hints);
-static css_error compute_font_size(void *pw, const css_hint *parent,
- css_hint *size);
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data);
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
+static css_unit_ctx unit_ctx = {
+ .font_size_default = 16 * (1 << CSS_RADIX_POINT),
+};
+
static css_select_handler select_handler = {
CSS_SELECT_HANDLER_VERSION_1,
@@ -203,9 +205,9 @@ static css_select_handler select_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
- compute_font_size,
+
set_libcss_node_data,
- get_libcss_node_data
+ get_libcss_node_data,
};
static css_error resolve_url(void *pw,
@@ -798,7 +800,12 @@ static void run_test_select_tree(css_select_ctx *select,
css_select_results *sr;
struct node *n = NULL;
- assert(css_select_style(select, node, &ctx->media, NULL,
+ if (node->parent == NULL) {
+ unit_ctx.root_style = NULL;
+ }
+
+
+ assert(css_select_style(select, node, &unit_ctx, &ctx->media, NULL,
&select_handler, ctx, &sr) == CSS_OK);
if (node->parent != NULL) {
@@ -806,7 +813,7 @@ static void run_test_select_tree(css_select_ctx *select,
assert(css_computed_style_compose(
node->parent->sr->styles[ctx->pseudo_element],
sr->styles[ctx->pseudo_element],
- compute_font_size, NULL,
+ &unit_ctx,
&composed) == CSS_OK);
css_computed_style_destroy(sr->styles[ctx->pseudo_element]);
sr->styles[ctx->pseudo_element] = composed;
@@ -819,6 +826,10 @@ static void run_test_select_tree(css_select_ctx *select,
buf, buflen);
}
+ if (node->parent == NULL) {
+ unit_ctx.root_style = node->sr->styles[ctx->pseudo_element];
+ }
+
for (n = node->children; n != NULL; n = n->next) {
run_test_select_tree(select, n, ctx, buf, buflen);
}
@@ -1639,68 +1650,6 @@ css_error ua_default_for_property(void *pw, uint32_t property, css_hint *hint)
return CSS_OK;
}
-css_error compute_font_size(void *pw, const css_hint *parent, css_hint *size)
-{
- static css_hint_length sizes[] = {
- { FLTTOFIX(6.75), CSS_UNIT_PT },
- { FLTTOFIX(7.50), CSS_UNIT_PT },
- { FLTTOFIX(9.75), CSS_UNIT_PT },
- { FLTTOFIX(12.0), CSS_UNIT_PT },
- { FLTTOFIX(13.5), CSS_UNIT_PT },
- { FLTTOFIX(18.0), CSS_UNIT_PT },
- { FLTTOFIX(24.0), CSS_UNIT_PT }
- };
- const css_hint_length *parent_size;
-
- UNUSED(pw);
-
- /* Grab parent size, defaulting to medium if none */
- if (parent == NULL) {
- parent_size = &sizes[CSS_FONT_SIZE_MEDIUM - 1];
- } else {
- assert(parent->status == CSS_FONT_SIZE_DIMENSION);
- assert(parent->data.length.unit != CSS_UNIT_EM);
- assert(parent->data.length.unit != CSS_UNIT_EX);
- parent_size = &parent->data.length;
- }
-
- assert(size->status != CSS_FONT_SIZE_INHERIT);
-
- if (size->status < CSS_FONT_SIZE_LARGER) {
- /* Keyword -- simple */
- size->data.length = sizes[size->status - 1];
- } else if (size->status == CSS_FONT_SIZE_LARGER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->status == CSS_FONT_SIZE_SMALLER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FDIV(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_EM ||
- size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value =
- FMUL(size->data.length.value, parent_size->value);
-
- if (size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.6));
- }
-
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_PCT) {
- size->data.length.value = FDIV(FMUL(size->data.length.value,
- parent_size->value), FLTTOFIX(100));
- size->data.length.unit = parent_size->unit;
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data)
{
--
Cascading Style Sheets library
2 years
libhubbub: branch master updated. release/0.3.7-19-g873ed6e
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libhubbub.git/shortlog/873ed6e236f7669afd3...
...commit http://git.netsurf-browser.org/libhubbub.git/commit/873ed6e236f7669afd3ef...
...tree http://git.netsurf-browser.org/libhubbub.git/tree/873ed6e236f7669afd3ef44...
The branch, master has been updated
discards 3b1a68ac7d1c4a4d9687adb9b63faa8e615d95f2 (commit)
discards 2736db051303e6904995b5f62cc0f68105dcb2d0 (commit)
discards 1c07ad25d8e3902360162ee85bf2f7f2c303c2e2 (commit)
discards ec520a5d84c0af8fb02f419047427cab19d20ceb (commit)
via 873ed6e236f7669afd3ef44259c34addc6dc95b6 (commit)
via d88075747d5d300254c97ad7c572ed483230c7f9 (commit)
via 15781e565dd7f436c7056939d6d33831b63b78fb (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (3b1a68ac7d1c4a4d9687adb9b63faa8e615d95f2)
\
N -- N -- N (873ed6e236f7669afd3ef44259c34addc6dc95b6)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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/libhubbub.git/commit/?id=873ed6e236f7669af...
commit 873ed6e236f7669afd3ef44259c34addc6dc95b6
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
treebuilder: Fix debug build variant with new element_type_to_name().
This uses the gperf-generated wordlist.
diff --git a/src/treebuilder/element-type.c b/src/treebuilder/element-type.c
index f6d3247..7e2772c 100644
--- a/src/treebuilder/element-type.c
+++ b/src/treebuilder/element-type.c
@@ -28,3 +28,22 @@ element_type element_type_from_name(
return value->type;
}
+
+/**
+ * Convert an element type to a name
+ *
+ * \param type The element type
+ * \return Pointer to name
+ */
+const char *element_type_to_name(element_type type)
+{
+ size_t i;
+
+ for (i = 0; i < sizeof(wordlist) / sizeof(wordlist[0]); i++) {
+ if (wordlist[i].type == type) {
+ return wordlist[i].name;
+ }
+ }
+
+ return "UNKNOWN";
+}
diff --git a/src/treebuilder/element-type.h b/src/treebuilder/element-type.h
index 93b168c..75612fd 100644
--- a/src/treebuilder/element-type.h
+++ b/src/treebuilder/element-type.h
@@ -53,5 +53,13 @@ element_type element_type_from_name(
hubbub_treebuilder *treebuilder,
const hubbub_string *tag_name);
+/**
+ * Convert an element type to a name
+ *
+ * \param type The element type
+ * \return Pointer to name
+ */
+const char *element_type_to_name(element_type type);
+
#endif
diff --git a/src/treebuilder/treebuilder.c b/src/treebuilder/treebuilder.c
index 2d2d047..f11875e 100644
--- a/src/treebuilder/treebuilder.c
+++ b/src/treebuilder/treebuilder.c
@@ -1397,24 +1397,5 @@ void formatting_list_dump(hubbub_treebuilder *treebuilder, FILE *fp)
}
}
-/**
- * Convert an element type to a name
- *
- * \param type The element type
- * \return Pointer to name
- */
-const char *element_type_to_name(element_type type)
-{
- size_t i;
-
- for (i = 0;
- i < sizeof(name_type_map) / sizeof(name_type_map[0]);
- i++) {
- if (name_type_map[i].type == type)
- return name_type_map[i].name;
- }
-
- return "UNKNOWN";
-}
#endif
commitdiff http://git.netsurf-browser.org/libhubbub.git/commit/?id=d88075747d5d30025...
commit d88075747d5d300254c97ad7c572ed483230c7f9
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
treebuilder: Add global table option to allow reuse of wordlist.
diff --git a/src/treebuilder/element-type.gperf b/src/treebuilder/element-type.gperf
index ab43b3d..c0980d3 100644
--- a/src/treebuilder/element-type.gperf
+++ b/src/treebuilder/element-type.gperf
@@ -8,6 +8,7 @@
%language=ANSI-C
%compare-strncmp
%readonly-tables
+%global-table
%ignore-case
%struct-type
%switch=1
commitdiff http://git.netsurf-browser.org/libhubbub.git/commit/?id=15781e565dd7f436c...
commit 15781e565dd7f436c7056939d6d33831b63b78fb
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
treebuilder: Return to running gperf at build time.
Now we include the generated C file directly, in a new C file.
diff --git a/src/treebuilder/Makefile b/src/treebuilder/Makefile
index ae2d9c4..77459f1 100644
--- a/src/treebuilder/Makefile
+++ b/src/treebuilder/Makefile
@@ -6,6 +6,16 @@ DIR_SOURCES := treebuilder.c \
in_cell.c in_select.c in_select_in_table.c \
in_foreign_content.c after_body.c in_frameset.c \
after_frameset.c after_after_body.c after_after_frameset.c \
- generic_rcdata.c autogenerated-element-type.c
+ generic_rcdata.c element-type.c
+
+$(DIR)autogenerated-element-type.c: $(DIR)element-type.gperf
+ $(VQ)$(ECHO) " GPERF: $<"
+ $(Q)gperf --output-file=$@.tmp $<
+ $(Q)$(SED) -e 's/^\(const struct element_type_map\)/static \1/' $@.tmp >$@
+ $(Q)$(RM) $@.tmp
+
+PRE_TARGETS := $(DIR)autogenerated-element-type.c
+
+CLEAN_ITEMS := $(DIR)autogenerated-element-type.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/treebuilder/autogenerated-element-type.c b/src/treebuilder/autogenerated-element-type.c
deleted file mode 100644
index f3b4f30..0000000
--- a/src/treebuilder/autogenerated-element-type.c
+++ /dev/null
@@ -1,705 +0,0 @@
-/* ANSI-C code produced by gperf version 3.1 */
-/* Command-line: gperf --output-file=src/treebuilder/autogenerated-element-type.c src/treebuilder/element-type.gperf */
-/* Computed positions: -k'1-2,$' */
-
-#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
- && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
- && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
- && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
- && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
- && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
- && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
- && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
- && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
- && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
- && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
- && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
- && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
- && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
- && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
- && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
- && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
- && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
- && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
- && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
- && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
- && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
- && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
-/* The character set is not based on ISO-646. */
-#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf(a)gnu.org>."
-#endif
-
-#line 17 "src/treebuilder/element-type.gperf"
-
-#include <string.h>
-
-#include "treebuilder/element-type.h"
-
-#line 24 "src/treebuilder/element-type.gperf"
-struct element_type_map;
-
-#define TOTAL_KEYWORDS 106
-#define MIN_WORD_LENGTH 1
-#define MAX_WORD_LENGTH 14
-#define MIN_HASH_VALUE 1
-#define MAX_HASH_VALUE 219
-/* maximum key range = 219, duplicates = 0 */
-
-#ifndef GPERF_DOWNCASE
-#define GPERF_DOWNCASE 1
-static unsigned char gperf_downcase[256] =
- {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
- 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
- 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
- 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
- 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
- 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
- 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
- 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
- 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
- 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
- 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
- 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
- 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
- 255
- };
-#endif
-
-#ifndef GPERF_CASE_STRNCMP
-#define GPERF_CASE_STRNCMP 1
-static int
-gperf_case_strncmp (register const char *s1, register const char *s2, register size_t n)
-{
- for (; n > 0;)
- {
- unsigned char c1 = gperf_downcase[(unsigned char)*s1++];
- unsigned char c2 = gperf_downcase[(unsigned char)*s2++];
- if (c1 != 0 && c1 == c2)
- {
- n--;
- continue;
- }
- return (int)c1 - (int)c2;
- }
- return 0;
-}
-#endif
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static unsigned int
-hubbub_element_type_hash (register const char *str, register size_t len)
-{
- static const unsigned char asso_values[] =
- {
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 60,
- 20, 70, 105, 50, 10, 50, 5, 220, 220, 220,
- 220, 220, 220, 220, 220, 0, 95, 40, 20, 10,
- 5, 35, 35, 60, 70, 15, 55, 5, 15, 70,
- 35, 0, 0, 10, 0, 100, 125, 40, 10, 65,
- 220, 220, 220, 220, 220, 220, 220, 0, 95, 40,
- 20, 10, 5, 35, 35, 60, 70, 15, 55, 5,
- 15, 70, 35, 0, 0, 10, 0, 100, 125, 40,
- 10, 65, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220
- };
- register unsigned int hval = len;
-
- switch (hval)
- {
- default:
- hval += asso_values[(unsigned char)str[1]+2];
- /*FALLTHROUGH*/
- case 1:
- hval += asso_values[(unsigned char)str[0]];
- break;
- }
- return hval + asso_values[(unsigned char)str[len - 1]];
-}
-
-const struct element_type_map *
-hubbub_element_type_lookup (register const char *str, register size_t len)
-{
- static const struct element_type_map wordlist[] =
- {
-#line 26 "src/treebuilder/element-type.gperf"
- {"a", A},
-#line 126 "src/treebuilder/element-type.gperf"
- {"tr", TR},
-#line 30 "src/treebuilder/element-type.gperf"
- {"area", AREA},
-#line 29 "src/treebuilder/element-type.gperf"
- {"applet", APPLET},
-#line 60 "src/treebuilder/element-type.gperf"
- {"font", FONT},
-#line 61 "src/treebuilder/element-type.gperf"
- {"footer", FOOTER},
-#line 65 "src/treebuilder/element-type.gperf"
- {"frameset", FRAMESET},
-#line 63 "src/treebuilder/element-type.gperf"
- {"form", FORM},
-#line 112 "src/treebuilder/element-type.gperf"
- {"spacer", SPACER},
-#line 31 "src/treebuilder/element-type.gperf"
- {"article", ARTICLE},
-#line 62 "src/treebuilder/element-type.gperf"
- {"foreignobject", FOREIGNOBJECT},
-#line 95 "src/treebuilder/element-type.gperf"
- {"nobr", NOBR},
-#line 64 "src/treebuilder/element-type.gperf"
- {"frame", FRAME},
-#line 108 "src/treebuilder/element-type.gperf"
- {"s", S},
-#line 27 "src/treebuilder/element-type.gperf"
- {"address", ADDRESS},
-#line 98 "src/treebuilder/element-type.gperf"
- {"noscript", NOSCRIPT},
-#line 109 "src/treebuilder/element-type.gperf"
- {"script", SCRIPT},
-#line 120 "src/treebuilder/element-type.gperf"
- {"td", TD},
-#line 57 "src/treebuilder/element-type.gperf"
- {"fieldset", FIELDSET},
-#line 125 "src/treebuilder/element-type.gperf"
- {"title", TITLE},
-#line 97 "src/treebuilder/element-type.gperf"
- {"noframes", NOFRAMES},
-#line 59 "src/treebuilder/element-type.gperf"
- {"figure", FIGURE},
-#line 73 "src/treebuilder/element-type.gperf"
- {"hr", HR},
-#line 51 "src/treebuilder/element-type.gperf"
- {"dir", DIR},
-#line 122 "src/treebuilder/element-type.gperf"
- {"tfoot", TFOOT},
-#line 96 "src/treebuilder/element-type.gperf"
- {"noembed", NOEMBED},
-#line 121 "src/treebuilder/element-type.gperf"
- {"textarea", TEXTAREA},
-#line 88 "src/treebuilder/element-type.gperf"
- {"meta", META},
-#line 58 "src/treebuilder/element-type.gperf"
- {"figcaption", FIGCAPTION},
-#line 47 "src/treebuilder/element-type.gperf"
- {"dd", DD},
-#line 107 "src/treebuilder/element-type.gperf"
- {"pre", PRE},
-#line 110 "src/treebuilder/element-type.gperf"
- {"select", SELECT},
-#line 71 "src/treebuilder/element-type.gperf"
- {"h6", H6},
-#line 118 "src/treebuilder/element-type.gperf"
- {"table", TABLE},
-#line 91 "src/treebuilder/element-type.gperf"
- {"mn", MN},
-#line 117 "src/treebuilder/element-type.gperf"
- {"svg", SVG},
-#line 106 "src/treebuilder/element-type.gperf"
- {"plaintext", PLAINTEXT},
-#line 85 "src/treebuilder/element-type.gperf"
- {"marquee", MARQUEE},
-#line 130 "src/treebuilder/element-type.gperf"
- {"wbr", WBR},
-#line 46 "src/treebuilder/element-type.gperf"
- {"command", COMMAND},
-#line 84 "src/treebuilder/element-type.gperf"
- {"malignmark", MALIGNMARK},
-#line 104 "src/treebuilder/element-type.gperf"
- {"p", P},
-#line 49 "src/treebuilder/element-type.gperf"
- {"details", DETAILS},
-#line 50 "src/treebuilder/element-type.gperf"
- {"dialog", DIALOG},
-#line 92 "src/treebuilder/element-type.gperf"
- {"mo", MO},
-#line 43 "src/treebuilder/element-type.gperf"
- {"center", CENTER},
-#line 90 "src/treebuilder/element-type.gperf"
- {"mi", MI},
-#line 45 "src/treebuilder/element-type.gperf"
- {"colgroup", COLGROUP},
-#line 86 "src/treebuilder/element-type.gperf"
- {"math", MATH},
-#line 105 "src/treebuilder/element-type.gperf"
- {"param", PARAM},
-#line 55 "src/treebuilder/element-type.gperf"
- {"em", EM},
-#line 82 "src/treebuilder/element-type.gperf"
- {"link", LINK},
-#line 119 "src/treebuilder/element-type.gperf"
- {"tbody", TBODY},
-#line 102 "src/treebuilder/element-type.gperf"
- {"option", OPTION},
-#line 53 "src/treebuilder/element-type.gperf"
- {"dl", DL},
-#line 72 "src/treebuilder/element-type.gperf"
- {"head", HEAD},
-#line 124 "src/treebuilder/element-type.gperf"
- {"thead", THEAD},
-#line 99 "src/treebuilder/element-type.gperf"
- {"object", OBJECT},
-#line 40 "src/treebuilder/element-type.gperf"
- {"br", BR},
-#line 44 "src/treebuilder/element-type.gperf"
- {"col", COL},
-#line 48 "src/treebuilder/element-type.gperf"
- {"desc", DESC},
-#line 79 "src/treebuilder/element-type.gperf"
- {"input", INPUT},
-#line 42 "src/treebuilder/element-type.gperf"
- {"caption", CAPTION},
-#line 28 "src/treebuilder/element-type.gperf"
- {"annotation-xml", ANNOTATION_XML},
-#line 56 "src/treebuilder/element-type.gperf"
- {"embed", EMBED},
-#line 89 "src/treebuilder/element-type.gperf"
- {"mglyph", MGLYPH},
-#line 123 "src/treebuilder/element-type.gperf"
- {"th", TH},
-#line 76 "src/treebuilder/element-type.gperf"
- {"iframe", IFRAME},
-#line 83 "src/treebuilder/element-type.gperf"
- {"listing", LISTING},
-#line 101 "src/treebuilder/element-type.gperf"
- {"optgroup", OPTGROUP},
-#line 32 "src/treebuilder/element-type.gperf"
- {"aside", ASIDE},
-#line 103 "src/treebuilder/element-type.gperf"
- {"output", OUTPUT},
-#line 93 "src/treebuilder/element-type.gperf"
- {"ms", MS},
-#line 131 "src/treebuilder/element-type.gperf"
- {"xmp", XMP},
-#line 75 "src/treebuilder/element-type.gperf"
- {"i", I},
-#line 116 "src/treebuilder/element-type.gperf"
- {"summary", SUMMARY},
-#line 127 "src/treebuilder/element-type.gperf"
- {"tt", TT},
-#line 38 "src/treebuilder/element-type.gperf"
- {"blockquote", BLOCKQUOTE},
-#line 81 "src/treebuilder/element-type.gperf"
- {"li", LI},
-#line 94 "src/treebuilder/element-type.gperf"
- {"mtext", MTEXT},
-#line 70 "src/treebuilder/element-type.gperf"
- {"h5", H5},
-#line 111 "src/treebuilder/element-type.gperf"
- {"small", SMALL},
-#line 100 "src/treebuilder/element-type.gperf"
- {"ol", OL},
-#line 35 "src/treebuilder/element-type.gperf"
- {"basefont", BASEFONT},
-#line 87 "src/treebuilder/element-type.gperf"
- {"menu", MENU},
-#line 77 "src/treebuilder/element-type.gperf"
- {"image", IMAGE},
-#line 54 "src/treebuilder/element-type.gperf"
- {"dt", DT},
-#line 37 "src/treebuilder/element-type.gperf"
- {"big", BIG},
-#line 34 "src/treebuilder/element-type.gperf"
- {"base", BASE},
-#line 115 "src/treebuilder/element-type.gperf"
- {"style", STYLE},
-#line 113 "src/treebuilder/element-type.gperf"
- {"strike", STRIKE},
-#line 69 "src/treebuilder/element-type.gperf"
- {"h4", H4},
-#line 41 "src/treebuilder/element-type.gperf"
- {"button", BUTTON},
-#line 68 "src/treebuilder/element-type.gperf"
- {"h3", H3},
-#line 67 "src/treebuilder/element-type.gperf"
- {"h2", H2},
-#line 52 "src/treebuilder/element-type.gperf"
- {"div", DIV},
-#line 39 "src/treebuilder/element-type.gperf"
- {"body", BODY},
-#line 66 "src/treebuilder/element-type.gperf"
- {"h1", H1},
-#line 78 "src/treebuilder/element-type.gperf"
- {"img", IMG},
-#line 129 "src/treebuilder/element-type.gperf"
- {"ul", UL},
-#line 114 "src/treebuilder/element-type.gperf"
- {"strong", STRONG},
-#line 80 "src/treebuilder/element-type.gperf"
- {"isindex", ISINDEX},
-#line 36 "src/treebuilder/element-type.gperf"
- {"bgsound", BGSOUND},
-#line 33 "src/treebuilder/element-type.gperf"
- {"b", B},
-#line 128 "src/treebuilder/element-type.gperf"
- {"u", U},
-#line 74 "src/treebuilder/element-type.gperf"
- {"html", HTML}
- };
-
- if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
- {
- register unsigned int key = hubbub_element_type_hash (str, len);
-
- if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
- {
- register const struct element_type_map *resword;
-
- switch (key - 1)
- {
- case 0:
- resword = &wordlist[0];
- goto compare;
- case 1:
- resword = &wordlist[1];
- goto compare;
- case 3:
- resword = &wordlist[2];
- goto compare;
- case 5:
- resword = &wordlist[3];
- goto compare;
- case 8:
- resword = &wordlist[4];
- goto compare;
- case 10:
- resword = &wordlist[5];
- goto compare;
- case 12:
- resword = &wordlist[6];
- goto compare;
- case 13:
- resword = &wordlist[7];
- goto compare;
- case 15:
- resword = &wordlist[8];
- goto compare;
- case 16:
- resword = &wordlist[9];
- goto compare;
- case 17:
- resword = &wordlist[10];
- goto compare;
- case 18:
- resword = &wordlist[11];
- goto compare;
- case 19:
- resword = &wordlist[12];
- goto compare;
- case 20:
- resword = &wordlist[13];
- goto compare;
- case 21:
- resword = &wordlist[14];
- goto compare;
- case 22:
- resword = &wordlist[15];
- goto compare;
- case 25:
- resword = &wordlist[16];
- goto compare;
- case 26:
- resword = &wordlist[17];
- goto compare;
- case 27:
- resword = &wordlist[18];
- goto compare;
- case 29:
- resword = &wordlist[19];
- goto compare;
- case 32:
- resword = &wordlist[20];
- goto compare;
- case 35:
- resword = &wordlist[21];
- goto compare;
- case 36:
- resword = &wordlist[22];
- goto compare;
- case 37:
- resword = &wordlist[23];
- goto compare;
- case 39:
- resword = &wordlist[24];
- goto compare;
- case 41:
- resword = &wordlist[25];
- goto compare;
- case 42:
- resword = &wordlist[26];
- goto compare;
- case 43:
- resword = &wordlist[27];
- goto compare;
- case 44:
- resword = &wordlist[28];
- goto compare;
- case 46:
- resword = &wordlist[29];
- goto compare;
- case 47:
- resword = &wordlist[30];
- goto compare;
- case 50:
- resword = &wordlist[31];
- goto compare;
- case 51:
- resword = &wordlist[32];
- goto compare;
- case 54:
- resword = &wordlist[33];
- goto compare;
- case 56:
- resword = &wordlist[34];
- goto compare;
- case 57:
- resword = &wordlist[35];
- goto compare;
- case 58:
- resword = &wordlist[36];
- goto compare;
- case 61:
- resword = &wordlist[37];
- goto compare;
- case 62:
- resword = &wordlist[38];
- goto compare;
- case 66:
- resword = &wordlist[39];
- goto compare;
- case 69:
- resword = &wordlist[40];
- goto compare;
- case 70:
- resword = &wordlist[41];
- goto compare;
- case 71:
- resword = &wordlist[42];
- goto compare;
- case 75:
- resword = &wordlist[43];
- goto compare;
- case 76:
- resword = &wordlist[44];
- goto compare;
- case 80:
- resword = &wordlist[45];
- goto compare;
- case 81:
- resword = &wordlist[46];
- goto compare;
- case 82:
- resword = &wordlist[47];
- goto compare;
- case 83:
- resword = &wordlist[48];
- goto compare;
- case 84:
- resword = &wordlist[49];
- goto compare;
- case 86:
- resword = &wordlist[50];
- goto compare;
- case 88:
- resword = &wordlist[51];
- goto compare;
- case 89:
- resword = &wordlist[52];
- goto compare;
- case 90:
- resword = &wordlist[53];
- goto compare;
- case 91:
- resword = &wordlist[54];
- goto compare;
- case 93:
- resword = &wordlist[55];
- goto compare;
- case 94:
- resword = &wordlist[56];
- goto compare;
- case 95:
- resword = &wordlist[57];
- goto compare;
- case 96:
- resword = &wordlist[58];
- goto compare;
- case 97:
- resword = &wordlist[59];
- goto compare;
- case 98:
- resword = &wordlist[60];
- goto compare;
- case 99:
- resword = &wordlist[61];
- goto compare;
- case 101:
- resword = &wordlist[62];
- goto compare;
- case 103:
- resword = &wordlist[63];
- goto compare;
- case 104:
- resword = &wordlist[64];
- goto compare;
- case 105:
- resword = &wordlist[65];
- goto compare;
- case 106:
- resword = &wordlist[66];
- goto compare;
- case 110:
- resword = &wordlist[67];
- goto compare;
- case 111:
- resword = &wordlist[68];
- goto compare;
- case 112:
- resword = &wordlist[69];
- goto compare;
- case 114:
- resword = &wordlist[70];
- goto compare;
- case 115:
- resword = &wordlist[71];
- goto compare;
- case 116:
- resword = &wordlist[72];
- goto compare;
- case 117:
- resword = &wordlist[73];
- goto compare;
- case 120:
- resword = &wordlist[74];
- goto compare;
- case 121:
- resword = &wordlist[75];
- goto compare;
- case 126:
- resword = &wordlist[76];
- goto compare;
- case 129:
- resword = &wordlist[77];
- goto compare;
- case 131:
- resword = &wordlist[78];
- goto compare;
- case 134:
- resword = &wordlist[79];
- goto compare;
- case 136:
- resword = &wordlist[80];
- goto compare;
- case 139:
- resword = &wordlist[81];
- goto compare;
- case 141:
- resword = &wordlist[82];
- goto compare;
- case 142:
- resword = &wordlist[83];
- goto compare;
- case 143:
- resword = &wordlist[84];
- goto compare;
- case 144:
- resword = &wordlist[85];
- goto compare;
- case 146:
- resword = &wordlist[86];
- goto compare;
- case 147:
- resword = &wordlist[87];
- goto compare;
- case 148:
- resword = &wordlist[88];
- goto compare;
- case 149:
- resword = &wordlist[89];
- goto compare;
- case 150:
- resword = &wordlist[90];
- goto compare;
- case 151:
- resword = &wordlist[91];
- goto compare;
- case 155:
- resword = &wordlist[92];
- goto compare;
- case 156:
- resword = &wordlist[93];
- goto compare;
- case 161:
- resword = &wordlist[94];
- goto compare;
- case 162:
- resword = &wordlist[95];
- goto compare;
- case 163:
- resword = &wordlist[96];
- goto compare;
- case 166:
- resword = &wordlist[97];
- goto compare;
- case 167:
- resword = &wordlist[98];
- goto compare;
- case 171:
- resword = &wordlist[99];
- goto compare;
- case 175:
- resword = &wordlist[100];
- goto compare;
- case 176:
- resword = &wordlist[101];
- goto compare;
- case 181:
- resword = &wordlist[102];
- goto compare;
- case 190:
- resword = &wordlist[103];
- goto compare;
- case 200:
- resword = &wordlist[104];
- goto compare;
- case 218:
- resword = &wordlist[105];
- goto compare;
- }
- return 0;
- compare:
- {
- register const char *s = resword->name;
-
- if ((((unsigned char)*str ^ (unsigned char)*s) & ~32) == 0 && !gperf_case_strncmp (str, s, len) && s[len] == '\0')
- return resword;
- }
- }
- }
- return 0;
-}
diff --git a/src/treebuilder/element-type.c b/src/treebuilder/element-type.c
new file mode 100644
index 0000000..f6d3247
--- /dev/null
+++ b/src/treebuilder/element-type.c
@@ -0,0 +1,30 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include "treebuilder/element-type.h"
+
+/* Auto-generated by `gperf`. */
+#include "treebuilder/autogenerated-element-type.c"
+
+/* Exported function, documented in element-type.h */
+element_type element_type_from_name(
+ hubbub_treebuilder *treebuilder,
+ const hubbub_string *tag_name)
+{
+ const struct element_type_map *value;
+
+ UNUSED(treebuilder);
+
+ value = hubbub_element_type_generated_lookup(
+ (const char *)tag_name->ptr,
+ tag_name->len);
+ if (value == NULL) {
+ return UNKNOWN;
+ }
+
+ return value->type;
+}
diff --git a/src/treebuilder/element-type.gperf b/src/treebuilder/element-type.gperf
index d4f2aa2..ab43b3d 100644
--- a/src/treebuilder/element-type.gperf
+++ b/src/treebuilder/element-type.gperf
@@ -11,8 +11,8 @@
%ignore-case
%struct-type
%switch=1
-%define hash-function-name hubbub_element_type_hash
-%define lookup-function-name hubbub_element_type_lookup
+%define hash-function-name hubbub_element_type_generated_hash
+%define lookup-function-name hubbub_element_type_generated_lookup
%{
#include <string.h>
diff --git a/src/treebuilder/element-type.h b/src/treebuilder/element-type.h
index a8e33d9..93b168c 100644
--- a/src/treebuilder/element-type.h
+++ b/src/treebuilder/element-type.h
@@ -42,11 +42,6 @@ struct element_type_map {
element_type type;
};
-/* Generated by gperf */
-const struct element_type_map *hubbub_element_type_lookup(
- register const char *str,
- register size_t len);
-
/**
* Convert an element name into an element type
*
@@ -54,22 +49,9 @@ const struct element_type_map *hubbub_element_type_lookup(
* \param tag_name The tag name to consider
* \return The corresponding element type
*/
-static inline element_type element_type_from_name(
+element_type element_type_from_name(
hubbub_treebuilder *treebuilder,
- const hubbub_string *tag_name)
-{
- const struct element_type_map *value;
-
- UNUSED(treebuilder);
-
- value = hubbub_element_type_lookup((const char *)tag_name->ptr,
- tag_name->len);
- if (value == NULL) {
- return UNKNOWN;
- }
-
- return value->type;
-}
+ const hubbub_string *tag_name);
#endif
-----------------------------------------------------------------------
Summary of changes:
--
HTML5 parser library
2 years
libhubbub: branch master updated. release/0.3.7-20-g3b1a68a
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libhubbub.git/shortlog/3b1a68ac7d1c4a4d968...
...commit http://git.netsurf-browser.org/libhubbub.git/commit/3b1a68ac7d1c4a4d9687a...
...tree http://git.netsurf-browser.org/libhubbub.git/tree/3b1a68ac7d1c4a4d9687adb...
The branch, master has been updated
via 3b1a68ac7d1c4a4d9687adb9b63faa8e615d95f2 (commit)
via 2736db051303e6904995b5f62cc0f68105dcb2d0 (commit)
via 1c07ad25d8e3902360162ee85bf2f7f2c303c2e2 (commit)
via ec520a5d84c0af8fb02f419047427cab19d20ceb (commit)
from 0f2caec353bc7302168cdc2c0575441e43b44c3e (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/libhubbub.git/commit/?id=3b1a68ac7d1c4a4d9...
commit 3b1a68ac7d1c4a4d9687adb9b63faa8e615d95f2
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
treebuilder: Fix debug build variant with new element_type_to_name().
This uses the gperf-generated wordlist.
diff --git a/src/treebuilder/element-type.c b/src/treebuilder/element-type.c
index f6d3247..7e2772c 100644
--- a/src/treebuilder/element-type.c
+++ b/src/treebuilder/element-type.c
@@ -28,3 +28,22 @@ element_type element_type_from_name(
return value->type;
}
+
+/**
+ * Convert an element type to a name
+ *
+ * \param type The element type
+ * \return Pointer to name
+ */
+const char *element_type_to_name(element_type type)
+{
+ size_t i;
+
+ for (i = 0; i < sizeof(wordlist) / sizeof(wordlist[0]); i++) {
+ if (wordlist[i].type == type) {
+ return wordlist[i].name;
+ }
+ }
+
+ return "UNKNOWN";
+}
diff --git a/src/treebuilder/element-type.h b/src/treebuilder/element-type.h
index 93b168c..75612fd 100644
--- a/src/treebuilder/element-type.h
+++ b/src/treebuilder/element-type.h
@@ -53,5 +53,13 @@ element_type element_type_from_name(
hubbub_treebuilder *treebuilder,
const hubbub_string *tag_name);
+/**
+ * Convert an element type to a name
+ *
+ * \param type The element type
+ * \return Pointer to name
+ */
+const char *element_type_to_name(element_type type);
+
#endif
diff --git a/src/treebuilder/treebuilder.c b/src/treebuilder/treebuilder.c
index 2d2d047..f11875e 100644
--- a/src/treebuilder/treebuilder.c
+++ b/src/treebuilder/treebuilder.c
@@ -1397,24 +1397,5 @@ void formatting_list_dump(hubbub_treebuilder *treebuilder, FILE *fp)
}
}
-/**
- * Convert an element type to a name
- *
- * \param type The element type
- * \return Pointer to name
- */
-const char *element_type_to_name(element_type type)
-{
- size_t i;
-
- for (i = 0;
- i < sizeof(name_type_map) / sizeof(name_type_map[0]);
- i++) {
- if (name_type_map[i].type == type)
- return name_type_map[i].name;
- }
-
- return "UNKNOWN";
-}
#endif
commitdiff http://git.netsurf-browser.org/libhubbub.git/commit/?id=2736db051303e6904...
commit 2736db051303e6904995b5f62cc0f68105dcb2d0
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
treebuilder: Add global table option to allow reuse of wordlist.
diff --git a/src/treebuilder/element-type.gperf b/src/treebuilder/element-type.gperf
index ab43b3d..c0980d3 100644
--- a/src/treebuilder/element-type.gperf
+++ b/src/treebuilder/element-type.gperf
@@ -8,6 +8,7 @@
%language=ANSI-C
%compare-strncmp
%readonly-tables
+%global-table
%ignore-case
%struct-type
%switch=1
commitdiff http://git.netsurf-browser.org/libhubbub.git/commit/?id=1c07ad25d8e390236...
commit 1c07ad25d8e3902360162ee85bf2f7f2c303c2e2
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
f
diff --git a/src/treebuilder/element-type.c b/src/treebuilder/element-type.c
new file mode 100644
index 0000000..f6d3247
--- /dev/null
+++ b/src/treebuilder/element-type.c
@@ -0,0 +1,30 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include "treebuilder/element-type.h"
+
+/* Auto-generated by `gperf`. */
+#include "treebuilder/autogenerated-element-type.c"
+
+/* Exported function, documented in element-type.h */
+element_type element_type_from_name(
+ hubbub_treebuilder *treebuilder,
+ const hubbub_string *tag_name)
+{
+ const struct element_type_map *value;
+
+ UNUSED(treebuilder);
+
+ value = hubbub_element_type_generated_lookup(
+ (const char *)tag_name->ptr,
+ tag_name->len);
+ if (value == NULL) {
+ return UNKNOWN;
+ }
+
+ return value->type;
+}
commitdiff http://git.netsurf-browser.org/libhubbub.git/commit/?id=ec520a5d84c0af8fb...
commit ec520a5d84c0af8fb02f419047427cab19d20ceb
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
treebuilder: Return to running gperf at build time.
Now we include the generated C file directly, in a new C file.
diff --git a/src/treebuilder/Makefile b/src/treebuilder/Makefile
index ae2d9c4..77459f1 100644
--- a/src/treebuilder/Makefile
+++ b/src/treebuilder/Makefile
@@ -6,6 +6,16 @@ DIR_SOURCES := treebuilder.c \
in_cell.c in_select.c in_select_in_table.c \
in_foreign_content.c after_body.c in_frameset.c \
after_frameset.c after_after_body.c after_after_frameset.c \
- generic_rcdata.c autogenerated-element-type.c
+ generic_rcdata.c element-type.c
+
+$(DIR)autogenerated-element-type.c: $(DIR)element-type.gperf
+ $(VQ)$(ECHO) " GPERF: $<"
+ $(Q)gperf --output-file=$@.tmp $<
+ $(Q)$(SED) -e 's/^\(const struct element_type_map\)/static \1/' $@.tmp >$@
+ $(Q)$(RM) $@.tmp
+
+PRE_TARGETS := $(DIR)autogenerated-element-type.c
+
+CLEAN_ITEMS := $(DIR)autogenerated-element-type.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/treebuilder/autogenerated-element-type.c b/src/treebuilder/autogenerated-element-type.c
deleted file mode 100644
index f3b4f30..0000000
--- a/src/treebuilder/autogenerated-element-type.c
+++ /dev/null
@@ -1,705 +0,0 @@
-/* ANSI-C code produced by gperf version 3.1 */
-/* Command-line: gperf --output-file=src/treebuilder/autogenerated-element-type.c src/treebuilder/element-type.gperf */
-/* Computed positions: -k'1-2,$' */
-
-#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
- && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
- && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
- && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
- && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
- && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
- && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
- && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
- && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
- && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
- && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
- && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
- && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
- && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
- && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
- && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
- && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
- && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
- && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
- && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
- && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
- && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
- && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
-/* The character set is not based on ISO-646. */
-#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf(a)gnu.org>."
-#endif
-
-#line 17 "src/treebuilder/element-type.gperf"
-
-#include <string.h>
-
-#include "treebuilder/element-type.h"
-
-#line 24 "src/treebuilder/element-type.gperf"
-struct element_type_map;
-
-#define TOTAL_KEYWORDS 106
-#define MIN_WORD_LENGTH 1
-#define MAX_WORD_LENGTH 14
-#define MIN_HASH_VALUE 1
-#define MAX_HASH_VALUE 219
-/* maximum key range = 219, duplicates = 0 */
-
-#ifndef GPERF_DOWNCASE
-#define GPERF_DOWNCASE 1
-static unsigned char gperf_downcase[256] =
- {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
- 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
- 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
- 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
- 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
- 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
- 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
- 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
- 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
- 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
- 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
- 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
- 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
- 255
- };
-#endif
-
-#ifndef GPERF_CASE_STRNCMP
-#define GPERF_CASE_STRNCMP 1
-static int
-gperf_case_strncmp (register const char *s1, register const char *s2, register size_t n)
-{
- for (; n > 0;)
- {
- unsigned char c1 = gperf_downcase[(unsigned char)*s1++];
- unsigned char c2 = gperf_downcase[(unsigned char)*s2++];
- if (c1 != 0 && c1 == c2)
- {
- n--;
- continue;
- }
- return (int)c1 - (int)c2;
- }
- return 0;
-}
-#endif
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static unsigned int
-hubbub_element_type_hash (register const char *str, register size_t len)
-{
- static const unsigned char asso_values[] =
- {
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 60,
- 20, 70, 105, 50, 10, 50, 5, 220, 220, 220,
- 220, 220, 220, 220, 220, 0, 95, 40, 20, 10,
- 5, 35, 35, 60, 70, 15, 55, 5, 15, 70,
- 35, 0, 0, 10, 0, 100, 125, 40, 10, 65,
- 220, 220, 220, 220, 220, 220, 220, 0, 95, 40,
- 20, 10, 5, 35, 35, 60, 70, 15, 55, 5,
- 15, 70, 35, 0, 0, 10, 0, 100, 125, 40,
- 10, 65, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220
- };
- register unsigned int hval = len;
-
- switch (hval)
- {
- default:
- hval += asso_values[(unsigned char)str[1]+2];
- /*FALLTHROUGH*/
- case 1:
- hval += asso_values[(unsigned char)str[0]];
- break;
- }
- return hval + asso_values[(unsigned char)str[len - 1]];
-}
-
-const struct element_type_map *
-hubbub_element_type_lookup (register const char *str, register size_t len)
-{
- static const struct element_type_map wordlist[] =
- {
-#line 26 "src/treebuilder/element-type.gperf"
- {"a", A},
-#line 126 "src/treebuilder/element-type.gperf"
- {"tr", TR},
-#line 30 "src/treebuilder/element-type.gperf"
- {"area", AREA},
-#line 29 "src/treebuilder/element-type.gperf"
- {"applet", APPLET},
-#line 60 "src/treebuilder/element-type.gperf"
- {"font", FONT},
-#line 61 "src/treebuilder/element-type.gperf"
- {"footer", FOOTER},
-#line 65 "src/treebuilder/element-type.gperf"
- {"frameset", FRAMESET},
-#line 63 "src/treebuilder/element-type.gperf"
- {"form", FORM},
-#line 112 "src/treebuilder/element-type.gperf"
- {"spacer", SPACER},
-#line 31 "src/treebuilder/element-type.gperf"
- {"article", ARTICLE},
-#line 62 "src/treebuilder/element-type.gperf"
- {"foreignobject", FOREIGNOBJECT},
-#line 95 "src/treebuilder/element-type.gperf"
- {"nobr", NOBR},
-#line 64 "src/treebuilder/element-type.gperf"
- {"frame", FRAME},
-#line 108 "src/treebuilder/element-type.gperf"
- {"s", S},
-#line 27 "src/treebuilder/element-type.gperf"
- {"address", ADDRESS},
-#line 98 "src/treebuilder/element-type.gperf"
- {"noscript", NOSCRIPT},
-#line 109 "src/treebuilder/element-type.gperf"
- {"script", SCRIPT},
-#line 120 "src/treebuilder/element-type.gperf"
- {"td", TD},
-#line 57 "src/treebuilder/element-type.gperf"
- {"fieldset", FIELDSET},
-#line 125 "src/treebuilder/element-type.gperf"
- {"title", TITLE},
-#line 97 "src/treebuilder/element-type.gperf"
- {"noframes", NOFRAMES},
-#line 59 "src/treebuilder/element-type.gperf"
- {"figure", FIGURE},
-#line 73 "src/treebuilder/element-type.gperf"
- {"hr", HR},
-#line 51 "src/treebuilder/element-type.gperf"
- {"dir", DIR},
-#line 122 "src/treebuilder/element-type.gperf"
- {"tfoot", TFOOT},
-#line 96 "src/treebuilder/element-type.gperf"
- {"noembed", NOEMBED},
-#line 121 "src/treebuilder/element-type.gperf"
- {"textarea", TEXTAREA},
-#line 88 "src/treebuilder/element-type.gperf"
- {"meta", META},
-#line 58 "src/treebuilder/element-type.gperf"
- {"figcaption", FIGCAPTION},
-#line 47 "src/treebuilder/element-type.gperf"
- {"dd", DD},
-#line 107 "src/treebuilder/element-type.gperf"
- {"pre", PRE},
-#line 110 "src/treebuilder/element-type.gperf"
- {"select", SELECT},
-#line 71 "src/treebuilder/element-type.gperf"
- {"h6", H6},
-#line 118 "src/treebuilder/element-type.gperf"
- {"table", TABLE},
-#line 91 "src/treebuilder/element-type.gperf"
- {"mn", MN},
-#line 117 "src/treebuilder/element-type.gperf"
- {"svg", SVG},
-#line 106 "src/treebuilder/element-type.gperf"
- {"plaintext", PLAINTEXT},
-#line 85 "src/treebuilder/element-type.gperf"
- {"marquee", MARQUEE},
-#line 130 "src/treebuilder/element-type.gperf"
- {"wbr", WBR},
-#line 46 "src/treebuilder/element-type.gperf"
- {"command", COMMAND},
-#line 84 "src/treebuilder/element-type.gperf"
- {"malignmark", MALIGNMARK},
-#line 104 "src/treebuilder/element-type.gperf"
- {"p", P},
-#line 49 "src/treebuilder/element-type.gperf"
- {"details", DETAILS},
-#line 50 "src/treebuilder/element-type.gperf"
- {"dialog", DIALOG},
-#line 92 "src/treebuilder/element-type.gperf"
- {"mo", MO},
-#line 43 "src/treebuilder/element-type.gperf"
- {"center", CENTER},
-#line 90 "src/treebuilder/element-type.gperf"
- {"mi", MI},
-#line 45 "src/treebuilder/element-type.gperf"
- {"colgroup", COLGROUP},
-#line 86 "src/treebuilder/element-type.gperf"
- {"math", MATH},
-#line 105 "src/treebuilder/element-type.gperf"
- {"param", PARAM},
-#line 55 "src/treebuilder/element-type.gperf"
- {"em", EM},
-#line 82 "src/treebuilder/element-type.gperf"
- {"link", LINK},
-#line 119 "src/treebuilder/element-type.gperf"
- {"tbody", TBODY},
-#line 102 "src/treebuilder/element-type.gperf"
- {"option", OPTION},
-#line 53 "src/treebuilder/element-type.gperf"
- {"dl", DL},
-#line 72 "src/treebuilder/element-type.gperf"
- {"head", HEAD},
-#line 124 "src/treebuilder/element-type.gperf"
- {"thead", THEAD},
-#line 99 "src/treebuilder/element-type.gperf"
- {"object", OBJECT},
-#line 40 "src/treebuilder/element-type.gperf"
- {"br", BR},
-#line 44 "src/treebuilder/element-type.gperf"
- {"col", COL},
-#line 48 "src/treebuilder/element-type.gperf"
- {"desc", DESC},
-#line 79 "src/treebuilder/element-type.gperf"
- {"input", INPUT},
-#line 42 "src/treebuilder/element-type.gperf"
- {"caption", CAPTION},
-#line 28 "src/treebuilder/element-type.gperf"
- {"annotation-xml", ANNOTATION_XML},
-#line 56 "src/treebuilder/element-type.gperf"
- {"embed", EMBED},
-#line 89 "src/treebuilder/element-type.gperf"
- {"mglyph", MGLYPH},
-#line 123 "src/treebuilder/element-type.gperf"
- {"th", TH},
-#line 76 "src/treebuilder/element-type.gperf"
- {"iframe", IFRAME},
-#line 83 "src/treebuilder/element-type.gperf"
- {"listing", LISTING},
-#line 101 "src/treebuilder/element-type.gperf"
- {"optgroup", OPTGROUP},
-#line 32 "src/treebuilder/element-type.gperf"
- {"aside", ASIDE},
-#line 103 "src/treebuilder/element-type.gperf"
- {"output", OUTPUT},
-#line 93 "src/treebuilder/element-type.gperf"
- {"ms", MS},
-#line 131 "src/treebuilder/element-type.gperf"
- {"xmp", XMP},
-#line 75 "src/treebuilder/element-type.gperf"
- {"i", I},
-#line 116 "src/treebuilder/element-type.gperf"
- {"summary", SUMMARY},
-#line 127 "src/treebuilder/element-type.gperf"
- {"tt", TT},
-#line 38 "src/treebuilder/element-type.gperf"
- {"blockquote", BLOCKQUOTE},
-#line 81 "src/treebuilder/element-type.gperf"
- {"li", LI},
-#line 94 "src/treebuilder/element-type.gperf"
- {"mtext", MTEXT},
-#line 70 "src/treebuilder/element-type.gperf"
- {"h5", H5},
-#line 111 "src/treebuilder/element-type.gperf"
- {"small", SMALL},
-#line 100 "src/treebuilder/element-type.gperf"
- {"ol", OL},
-#line 35 "src/treebuilder/element-type.gperf"
- {"basefont", BASEFONT},
-#line 87 "src/treebuilder/element-type.gperf"
- {"menu", MENU},
-#line 77 "src/treebuilder/element-type.gperf"
- {"image", IMAGE},
-#line 54 "src/treebuilder/element-type.gperf"
- {"dt", DT},
-#line 37 "src/treebuilder/element-type.gperf"
- {"big", BIG},
-#line 34 "src/treebuilder/element-type.gperf"
- {"base", BASE},
-#line 115 "src/treebuilder/element-type.gperf"
- {"style", STYLE},
-#line 113 "src/treebuilder/element-type.gperf"
- {"strike", STRIKE},
-#line 69 "src/treebuilder/element-type.gperf"
- {"h4", H4},
-#line 41 "src/treebuilder/element-type.gperf"
- {"button", BUTTON},
-#line 68 "src/treebuilder/element-type.gperf"
- {"h3", H3},
-#line 67 "src/treebuilder/element-type.gperf"
- {"h2", H2},
-#line 52 "src/treebuilder/element-type.gperf"
- {"div", DIV},
-#line 39 "src/treebuilder/element-type.gperf"
- {"body", BODY},
-#line 66 "src/treebuilder/element-type.gperf"
- {"h1", H1},
-#line 78 "src/treebuilder/element-type.gperf"
- {"img", IMG},
-#line 129 "src/treebuilder/element-type.gperf"
- {"ul", UL},
-#line 114 "src/treebuilder/element-type.gperf"
- {"strong", STRONG},
-#line 80 "src/treebuilder/element-type.gperf"
- {"isindex", ISINDEX},
-#line 36 "src/treebuilder/element-type.gperf"
- {"bgsound", BGSOUND},
-#line 33 "src/treebuilder/element-type.gperf"
- {"b", B},
-#line 128 "src/treebuilder/element-type.gperf"
- {"u", U},
-#line 74 "src/treebuilder/element-type.gperf"
- {"html", HTML}
- };
-
- if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
- {
- register unsigned int key = hubbub_element_type_hash (str, len);
-
- if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
- {
- register const struct element_type_map *resword;
-
- switch (key - 1)
- {
- case 0:
- resword = &wordlist[0];
- goto compare;
- case 1:
- resword = &wordlist[1];
- goto compare;
- case 3:
- resword = &wordlist[2];
- goto compare;
- case 5:
- resword = &wordlist[3];
- goto compare;
- case 8:
- resword = &wordlist[4];
- goto compare;
- case 10:
- resword = &wordlist[5];
- goto compare;
- case 12:
- resword = &wordlist[6];
- goto compare;
- case 13:
- resword = &wordlist[7];
- goto compare;
- case 15:
- resword = &wordlist[8];
- goto compare;
- case 16:
- resword = &wordlist[9];
- goto compare;
- case 17:
- resword = &wordlist[10];
- goto compare;
- case 18:
- resword = &wordlist[11];
- goto compare;
- case 19:
- resword = &wordlist[12];
- goto compare;
- case 20:
- resword = &wordlist[13];
- goto compare;
- case 21:
- resword = &wordlist[14];
- goto compare;
- case 22:
- resword = &wordlist[15];
- goto compare;
- case 25:
- resword = &wordlist[16];
- goto compare;
- case 26:
- resword = &wordlist[17];
- goto compare;
- case 27:
- resword = &wordlist[18];
- goto compare;
- case 29:
- resword = &wordlist[19];
- goto compare;
- case 32:
- resword = &wordlist[20];
- goto compare;
- case 35:
- resword = &wordlist[21];
- goto compare;
- case 36:
- resword = &wordlist[22];
- goto compare;
- case 37:
- resword = &wordlist[23];
- goto compare;
- case 39:
- resword = &wordlist[24];
- goto compare;
- case 41:
- resword = &wordlist[25];
- goto compare;
- case 42:
- resword = &wordlist[26];
- goto compare;
- case 43:
- resword = &wordlist[27];
- goto compare;
- case 44:
- resword = &wordlist[28];
- goto compare;
- case 46:
- resword = &wordlist[29];
- goto compare;
- case 47:
- resword = &wordlist[30];
- goto compare;
- case 50:
- resword = &wordlist[31];
- goto compare;
- case 51:
- resword = &wordlist[32];
- goto compare;
- case 54:
- resword = &wordlist[33];
- goto compare;
- case 56:
- resword = &wordlist[34];
- goto compare;
- case 57:
- resword = &wordlist[35];
- goto compare;
- case 58:
- resword = &wordlist[36];
- goto compare;
- case 61:
- resword = &wordlist[37];
- goto compare;
- case 62:
- resword = &wordlist[38];
- goto compare;
- case 66:
- resword = &wordlist[39];
- goto compare;
- case 69:
- resword = &wordlist[40];
- goto compare;
- case 70:
- resword = &wordlist[41];
- goto compare;
- case 71:
- resword = &wordlist[42];
- goto compare;
- case 75:
- resword = &wordlist[43];
- goto compare;
- case 76:
- resword = &wordlist[44];
- goto compare;
- case 80:
- resword = &wordlist[45];
- goto compare;
- case 81:
- resword = &wordlist[46];
- goto compare;
- case 82:
- resword = &wordlist[47];
- goto compare;
- case 83:
- resword = &wordlist[48];
- goto compare;
- case 84:
- resword = &wordlist[49];
- goto compare;
- case 86:
- resword = &wordlist[50];
- goto compare;
- case 88:
- resword = &wordlist[51];
- goto compare;
- case 89:
- resword = &wordlist[52];
- goto compare;
- case 90:
- resword = &wordlist[53];
- goto compare;
- case 91:
- resword = &wordlist[54];
- goto compare;
- case 93:
- resword = &wordlist[55];
- goto compare;
- case 94:
- resword = &wordlist[56];
- goto compare;
- case 95:
- resword = &wordlist[57];
- goto compare;
- case 96:
- resword = &wordlist[58];
- goto compare;
- case 97:
- resword = &wordlist[59];
- goto compare;
- case 98:
- resword = &wordlist[60];
- goto compare;
- case 99:
- resword = &wordlist[61];
- goto compare;
- case 101:
- resword = &wordlist[62];
- goto compare;
- case 103:
- resword = &wordlist[63];
- goto compare;
- case 104:
- resword = &wordlist[64];
- goto compare;
- case 105:
- resword = &wordlist[65];
- goto compare;
- case 106:
- resword = &wordlist[66];
- goto compare;
- case 110:
- resword = &wordlist[67];
- goto compare;
- case 111:
- resword = &wordlist[68];
- goto compare;
- case 112:
- resword = &wordlist[69];
- goto compare;
- case 114:
- resword = &wordlist[70];
- goto compare;
- case 115:
- resword = &wordlist[71];
- goto compare;
- case 116:
- resword = &wordlist[72];
- goto compare;
- case 117:
- resword = &wordlist[73];
- goto compare;
- case 120:
- resword = &wordlist[74];
- goto compare;
- case 121:
- resword = &wordlist[75];
- goto compare;
- case 126:
- resword = &wordlist[76];
- goto compare;
- case 129:
- resword = &wordlist[77];
- goto compare;
- case 131:
- resword = &wordlist[78];
- goto compare;
- case 134:
- resword = &wordlist[79];
- goto compare;
- case 136:
- resword = &wordlist[80];
- goto compare;
- case 139:
- resword = &wordlist[81];
- goto compare;
- case 141:
- resword = &wordlist[82];
- goto compare;
- case 142:
- resword = &wordlist[83];
- goto compare;
- case 143:
- resword = &wordlist[84];
- goto compare;
- case 144:
- resword = &wordlist[85];
- goto compare;
- case 146:
- resword = &wordlist[86];
- goto compare;
- case 147:
- resword = &wordlist[87];
- goto compare;
- case 148:
- resword = &wordlist[88];
- goto compare;
- case 149:
- resword = &wordlist[89];
- goto compare;
- case 150:
- resword = &wordlist[90];
- goto compare;
- case 151:
- resword = &wordlist[91];
- goto compare;
- case 155:
- resword = &wordlist[92];
- goto compare;
- case 156:
- resword = &wordlist[93];
- goto compare;
- case 161:
- resword = &wordlist[94];
- goto compare;
- case 162:
- resword = &wordlist[95];
- goto compare;
- case 163:
- resword = &wordlist[96];
- goto compare;
- case 166:
- resword = &wordlist[97];
- goto compare;
- case 167:
- resword = &wordlist[98];
- goto compare;
- case 171:
- resword = &wordlist[99];
- goto compare;
- case 175:
- resword = &wordlist[100];
- goto compare;
- case 176:
- resword = &wordlist[101];
- goto compare;
- case 181:
- resword = &wordlist[102];
- goto compare;
- case 190:
- resword = &wordlist[103];
- goto compare;
- case 200:
- resword = &wordlist[104];
- goto compare;
- case 218:
- resword = &wordlist[105];
- goto compare;
- }
- return 0;
- compare:
- {
- register const char *s = resword->name;
-
- if ((((unsigned char)*str ^ (unsigned char)*s) & ~32) == 0 && !gperf_case_strncmp (str, s, len) && s[len] == '\0')
- return resword;
- }
- }
- }
- return 0;
-}
diff --git a/src/treebuilder/element-type.gperf b/src/treebuilder/element-type.gperf
index d4f2aa2..ab43b3d 100644
--- a/src/treebuilder/element-type.gperf
+++ b/src/treebuilder/element-type.gperf
@@ -11,8 +11,8 @@
%ignore-case
%struct-type
%switch=1
-%define hash-function-name hubbub_element_type_hash
-%define lookup-function-name hubbub_element_type_lookup
+%define hash-function-name hubbub_element_type_generated_hash
+%define lookup-function-name hubbub_element_type_generated_lookup
%{
#include <string.h>
diff --git a/src/treebuilder/element-type.h b/src/treebuilder/element-type.h
index a8e33d9..93b168c 100644
--- a/src/treebuilder/element-type.h
+++ b/src/treebuilder/element-type.h
@@ -42,11 +42,6 @@ struct element_type_map {
element_type type;
};
-/* Generated by gperf */
-const struct element_type_map *hubbub_element_type_lookup(
- register const char *str,
- register size_t len);
-
/**
* Convert an element name into an element type
*
@@ -54,22 +49,9 @@ const struct element_type_map *hubbub_element_type_lookup(
* \param tag_name The tag name to consider
* \return The corresponding element type
*/
-static inline element_type element_type_from_name(
+element_type element_type_from_name(
hubbub_treebuilder *treebuilder,
- const hubbub_string *tag_name)
-{
- const struct element_type_map *value;
-
- UNUSED(treebuilder);
-
- value = hubbub_element_type_lookup((const char *)tag_name->ptr,
- tag_name->len);
- if (value == NULL) {
- return UNKNOWN;
- }
-
- return value->type;
-}
+ const hubbub_string *tag_name);
#endif
-----------------------------------------------------------------------
Summary of changes:
src/treebuilder/Makefile | 12 +-
src/treebuilder/autogenerated-element-type.c | 705 --------------------------
src/treebuilder/element-type.c | 49 ++
src/treebuilder/element-type.gperf | 5 +-
src/treebuilder/element-type.h | 28 +-
src/treebuilder/treebuilder.c | 19 -
6 files changed, 72 insertions(+), 746 deletions(-)
delete mode 100644 src/treebuilder/autogenerated-element-type.c
create mode 100644 src/treebuilder/element-type.c
diff --git a/src/treebuilder/Makefile b/src/treebuilder/Makefile
index ae2d9c4..77459f1 100644
--- a/src/treebuilder/Makefile
+++ b/src/treebuilder/Makefile
@@ -6,6 +6,16 @@ DIR_SOURCES := treebuilder.c \
in_cell.c in_select.c in_select_in_table.c \
in_foreign_content.c after_body.c in_frameset.c \
after_frameset.c after_after_body.c after_after_frameset.c \
- generic_rcdata.c autogenerated-element-type.c
+ generic_rcdata.c element-type.c
+
+$(DIR)autogenerated-element-type.c: $(DIR)element-type.gperf
+ $(VQ)$(ECHO) " GPERF: $<"
+ $(Q)gperf --output-file=$@.tmp $<
+ $(Q)$(SED) -e 's/^\(const struct element_type_map\)/static \1/' $@.tmp >$@
+ $(Q)$(RM) $@.tmp
+
+PRE_TARGETS := $(DIR)autogenerated-element-type.c
+
+CLEAN_ITEMS := $(DIR)autogenerated-element-type.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/treebuilder/autogenerated-element-type.c b/src/treebuilder/autogenerated-element-type.c
deleted file mode 100644
index f3b4f30..0000000
--- a/src/treebuilder/autogenerated-element-type.c
+++ /dev/null
@@ -1,705 +0,0 @@
-/* ANSI-C code produced by gperf version 3.1 */
-/* Command-line: gperf --output-file=src/treebuilder/autogenerated-element-type.c src/treebuilder/element-type.gperf */
-/* Computed positions: -k'1-2,$' */
-
-#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
- && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
- && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
- && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
- && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
- && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
- && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
- && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
- && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
- && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
- && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
- && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
- && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
- && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
- && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
- && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
- && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
- && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
- && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
- && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
- && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
- && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
- && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
-/* The character set is not based on ISO-646. */
-#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf(a)gnu.org>."
-#endif
-
-#line 17 "src/treebuilder/element-type.gperf"
-
-#include <string.h>
-
-#include "treebuilder/element-type.h"
-
-#line 24 "src/treebuilder/element-type.gperf"
-struct element_type_map;
-
-#define TOTAL_KEYWORDS 106
-#define MIN_WORD_LENGTH 1
-#define MAX_WORD_LENGTH 14
-#define MIN_HASH_VALUE 1
-#define MAX_HASH_VALUE 219
-/* maximum key range = 219, duplicates = 0 */
-
-#ifndef GPERF_DOWNCASE
-#define GPERF_DOWNCASE 1
-static unsigned char gperf_downcase[256] =
- {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
- 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
- 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
- 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
- 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
- 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
- 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
- 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
- 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
- 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
- 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
- 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
- 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
- 255
- };
-#endif
-
-#ifndef GPERF_CASE_STRNCMP
-#define GPERF_CASE_STRNCMP 1
-static int
-gperf_case_strncmp (register const char *s1, register const char *s2, register size_t n)
-{
- for (; n > 0;)
- {
- unsigned char c1 = gperf_downcase[(unsigned char)*s1++];
- unsigned char c2 = gperf_downcase[(unsigned char)*s2++];
- if (c1 != 0 && c1 == c2)
- {
- n--;
- continue;
- }
- return (int)c1 - (int)c2;
- }
- return 0;
-}
-#endif
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static unsigned int
-hubbub_element_type_hash (register const char *str, register size_t len)
-{
- static const unsigned char asso_values[] =
- {
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 60,
- 20, 70, 105, 50, 10, 50, 5, 220, 220, 220,
- 220, 220, 220, 220, 220, 0, 95, 40, 20, 10,
- 5, 35, 35, 60, 70, 15, 55, 5, 15, 70,
- 35, 0, 0, 10, 0, 100, 125, 40, 10, 65,
- 220, 220, 220, 220, 220, 220, 220, 0, 95, 40,
- 20, 10, 5, 35, 35, 60, 70, 15, 55, 5,
- 15, 70, 35, 0, 0, 10, 0, 100, 125, 40,
- 10, 65, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
- 220, 220, 220, 220, 220, 220, 220, 220
- };
- register unsigned int hval = len;
-
- switch (hval)
- {
- default:
- hval += asso_values[(unsigned char)str[1]+2];
- /*FALLTHROUGH*/
- case 1:
- hval += asso_values[(unsigned char)str[0]];
- break;
- }
- return hval + asso_values[(unsigned char)str[len - 1]];
-}
-
-const struct element_type_map *
-hubbub_element_type_lookup (register const char *str, register size_t len)
-{
- static const struct element_type_map wordlist[] =
- {
-#line 26 "src/treebuilder/element-type.gperf"
- {"a", A},
-#line 126 "src/treebuilder/element-type.gperf"
- {"tr", TR},
-#line 30 "src/treebuilder/element-type.gperf"
- {"area", AREA},
-#line 29 "src/treebuilder/element-type.gperf"
- {"applet", APPLET},
-#line 60 "src/treebuilder/element-type.gperf"
- {"font", FONT},
-#line 61 "src/treebuilder/element-type.gperf"
- {"footer", FOOTER},
-#line 65 "src/treebuilder/element-type.gperf"
- {"frameset", FRAMESET},
-#line 63 "src/treebuilder/element-type.gperf"
- {"form", FORM},
-#line 112 "src/treebuilder/element-type.gperf"
- {"spacer", SPACER},
-#line 31 "src/treebuilder/element-type.gperf"
- {"article", ARTICLE},
-#line 62 "src/treebuilder/element-type.gperf"
- {"foreignobject", FOREIGNOBJECT},
-#line 95 "src/treebuilder/element-type.gperf"
- {"nobr", NOBR},
-#line 64 "src/treebuilder/element-type.gperf"
- {"frame", FRAME},
-#line 108 "src/treebuilder/element-type.gperf"
- {"s", S},
-#line 27 "src/treebuilder/element-type.gperf"
- {"address", ADDRESS},
-#line 98 "src/treebuilder/element-type.gperf"
- {"noscript", NOSCRIPT},
-#line 109 "src/treebuilder/element-type.gperf"
- {"script", SCRIPT},
-#line 120 "src/treebuilder/element-type.gperf"
- {"td", TD},
-#line 57 "src/treebuilder/element-type.gperf"
- {"fieldset", FIELDSET},
-#line 125 "src/treebuilder/element-type.gperf"
- {"title", TITLE},
-#line 97 "src/treebuilder/element-type.gperf"
- {"noframes", NOFRAMES},
-#line 59 "src/treebuilder/element-type.gperf"
- {"figure", FIGURE},
-#line 73 "src/treebuilder/element-type.gperf"
- {"hr", HR},
-#line 51 "src/treebuilder/element-type.gperf"
- {"dir", DIR},
-#line 122 "src/treebuilder/element-type.gperf"
- {"tfoot", TFOOT},
-#line 96 "src/treebuilder/element-type.gperf"
- {"noembed", NOEMBED},
-#line 121 "src/treebuilder/element-type.gperf"
- {"textarea", TEXTAREA},
-#line 88 "src/treebuilder/element-type.gperf"
- {"meta", META},
-#line 58 "src/treebuilder/element-type.gperf"
- {"figcaption", FIGCAPTION},
-#line 47 "src/treebuilder/element-type.gperf"
- {"dd", DD},
-#line 107 "src/treebuilder/element-type.gperf"
- {"pre", PRE},
-#line 110 "src/treebuilder/element-type.gperf"
- {"select", SELECT},
-#line 71 "src/treebuilder/element-type.gperf"
- {"h6", H6},
-#line 118 "src/treebuilder/element-type.gperf"
- {"table", TABLE},
-#line 91 "src/treebuilder/element-type.gperf"
- {"mn", MN},
-#line 117 "src/treebuilder/element-type.gperf"
- {"svg", SVG},
-#line 106 "src/treebuilder/element-type.gperf"
- {"plaintext", PLAINTEXT},
-#line 85 "src/treebuilder/element-type.gperf"
- {"marquee", MARQUEE},
-#line 130 "src/treebuilder/element-type.gperf"
- {"wbr", WBR},
-#line 46 "src/treebuilder/element-type.gperf"
- {"command", COMMAND},
-#line 84 "src/treebuilder/element-type.gperf"
- {"malignmark", MALIGNMARK},
-#line 104 "src/treebuilder/element-type.gperf"
- {"p", P},
-#line 49 "src/treebuilder/element-type.gperf"
- {"details", DETAILS},
-#line 50 "src/treebuilder/element-type.gperf"
- {"dialog", DIALOG},
-#line 92 "src/treebuilder/element-type.gperf"
- {"mo", MO},
-#line 43 "src/treebuilder/element-type.gperf"
- {"center", CENTER},
-#line 90 "src/treebuilder/element-type.gperf"
- {"mi", MI},
-#line 45 "src/treebuilder/element-type.gperf"
- {"colgroup", COLGROUP},
-#line 86 "src/treebuilder/element-type.gperf"
- {"math", MATH},
-#line 105 "src/treebuilder/element-type.gperf"
- {"param", PARAM},
-#line 55 "src/treebuilder/element-type.gperf"
- {"em", EM},
-#line 82 "src/treebuilder/element-type.gperf"
- {"link", LINK},
-#line 119 "src/treebuilder/element-type.gperf"
- {"tbody", TBODY},
-#line 102 "src/treebuilder/element-type.gperf"
- {"option", OPTION},
-#line 53 "src/treebuilder/element-type.gperf"
- {"dl", DL},
-#line 72 "src/treebuilder/element-type.gperf"
- {"head", HEAD},
-#line 124 "src/treebuilder/element-type.gperf"
- {"thead", THEAD},
-#line 99 "src/treebuilder/element-type.gperf"
- {"object", OBJECT},
-#line 40 "src/treebuilder/element-type.gperf"
- {"br", BR},
-#line 44 "src/treebuilder/element-type.gperf"
- {"col", COL},
-#line 48 "src/treebuilder/element-type.gperf"
- {"desc", DESC},
-#line 79 "src/treebuilder/element-type.gperf"
- {"input", INPUT},
-#line 42 "src/treebuilder/element-type.gperf"
- {"caption", CAPTION},
-#line 28 "src/treebuilder/element-type.gperf"
- {"annotation-xml", ANNOTATION_XML},
-#line 56 "src/treebuilder/element-type.gperf"
- {"embed", EMBED},
-#line 89 "src/treebuilder/element-type.gperf"
- {"mglyph", MGLYPH},
-#line 123 "src/treebuilder/element-type.gperf"
- {"th", TH},
-#line 76 "src/treebuilder/element-type.gperf"
- {"iframe", IFRAME},
-#line 83 "src/treebuilder/element-type.gperf"
- {"listing", LISTING},
-#line 101 "src/treebuilder/element-type.gperf"
- {"optgroup", OPTGROUP},
-#line 32 "src/treebuilder/element-type.gperf"
- {"aside", ASIDE},
-#line 103 "src/treebuilder/element-type.gperf"
- {"output", OUTPUT},
-#line 93 "src/treebuilder/element-type.gperf"
- {"ms", MS},
-#line 131 "src/treebuilder/element-type.gperf"
- {"xmp", XMP},
-#line 75 "src/treebuilder/element-type.gperf"
- {"i", I},
-#line 116 "src/treebuilder/element-type.gperf"
- {"summary", SUMMARY},
-#line 127 "src/treebuilder/element-type.gperf"
- {"tt", TT},
-#line 38 "src/treebuilder/element-type.gperf"
- {"blockquote", BLOCKQUOTE},
-#line 81 "src/treebuilder/element-type.gperf"
- {"li", LI},
-#line 94 "src/treebuilder/element-type.gperf"
- {"mtext", MTEXT},
-#line 70 "src/treebuilder/element-type.gperf"
- {"h5", H5},
-#line 111 "src/treebuilder/element-type.gperf"
- {"small", SMALL},
-#line 100 "src/treebuilder/element-type.gperf"
- {"ol", OL},
-#line 35 "src/treebuilder/element-type.gperf"
- {"basefont", BASEFONT},
-#line 87 "src/treebuilder/element-type.gperf"
- {"menu", MENU},
-#line 77 "src/treebuilder/element-type.gperf"
- {"image", IMAGE},
-#line 54 "src/treebuilder/element-type.gperf"
- {"dt", DT},
-#line 37 "src/treebuilder/element-type.gperf"
- {"big", BIG},
-#line 34 "src/treebuilder/element-type.gperf"
- {"base", BASE},
-#line 115 "src/treebuilder/element-type.gperf"
- {"style", STYLE},
-#line 113 "src/treebuilder/element-type.gperf"
- {"strike", STRIKE},
-#line 69 "src/treebuilder/element-type.gperf"
- {"h4", H4},
-#line 41 "src/treebuilder/element-type.gperf"
- {"button", BUTTON},
-#line 68 "src/treebuilder/element-type.gperf"
- {"h3", H3},
-#line 67 "src/treebuilder/element-type.gperf"
- {"h2", H2},
-#line 52 "src/treebuilder/element-type.gperf"
- {"div", DIV},
-#line 39 "src/treebuilder/element-type.gperf"
- {"body", BODY},
-#line 66 "src/treebuilder/element-type.gperf"
- {"h1", H1},
-#line 78 "src/treebuilder/element-type.gperf"
- {"img", IMG},
-#line 129 "src/treebuilder/element-type.gperf"
- {"ul", UL},
-#line 114 "src/treebuilder/element-type.gperf"
- {"strong", STRONG},
-#line 80 "src/treebuilder/element-type.gperf"
- {"isindex", ISINDEX},
-#line 36 "src/treebuilder/element-type.gperf"
- {"bgsound", BGSOUND},
-#line 33 "src/treebuilder/element-type.gperf"
- {"b", B},
-#line 128 "src/treebuilder/element-type.gperf"
- {"u", U},
-#line 74 "src/treebuilder/element-type.gperf"
- {"html", HTML}
- };
-
- if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
- {
- register unsigned int key = hubbub_element_type_hash (str, len);
-
- if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
- {
- register const struct element_type_map *resword;
-
- switch (key - 1)
- {
- case 0:
- resword = &wordlist[0];
- goto compare;
- case 1:
- resword = &wordlist[1];
- goto compare;
- case 3:
- resword = &wordlist[2];
- goto compare;
- case 5:
- resword = &wordlist[3];
- goto compare;
- case 8:
- resword = &wordlist[4];
- goto compare;
- case 10:
- resword = &wordlist[5];
- goto compare;
- case 12:
- resword = &wordlist[6];
- goto compare;
- case 13:
- resword = &wordlist[7];
- goto compare;
- case 15:
- resword = &wordlist[8];
- goto compare;
- case 16:
- resword = &wordlist[9];
- goto compare;
- case 17:
- resword = &wordlist[10];
- goto compare;
- case 18:
- resword = &wordlist[11];
- goto compare;
- case 19:
- resword = &wordlist[12];
- goto compare;
- case 20:
- resword = &wordlist[13];
- goto compare;
- case 21:
- resword = &wordlist[14];
- goto compare;
- case 22:
- resword = &wordlist[15];
- goto compare;
- case 25:
- resword = &wordlist[16];
- goto compare;
- case 26:
- resword = &wordlist[17];
- goto compare;
- case 27:
- resword = &wordlist[18];
- goto compare;
- case 29:
- resword = &wordlist[19];
- goto compare;
- case 32:
- resword = &wordlist[20];
- goto compare;
- case 35:
- resword = &wordlist[21];
- goto compare;
- case 36:
- resword = &wordlist[22];
- goto compare;
- case 37:
- resword = &wordlist[23];
- goto compare;
- case 39:
- resword = &wordlist[24];
- goto compare;
- case 41:
- resword = &wordlist[25];
- goto compare;
- case 42:
- resword = &wordlist[26];
- goto compare;
- case 43:
- resword = &wordlist[27];
- goto compare;
- case 44:
- resword = &wordlist[28];
- goto compare;
- case 46:
- resword = &wordlist[29];
- goto compare;
- case 47:
- resword = &wordlist[30];
- goto compare;
- case 50:
- resword = &wordlist[31];
- goto compare;
- case 51:
- resword = &wordlist[32];
- goto compare;
- case 54:
- resword = &wordlist[33];
- goto compare;
- case 56:
- resword = &wordlist[34];
- goto compare;
- case 57:
- resword = &wordlist[35];
- goto compare;
- case 58:
- resword = &wordlist[36];
- goto compare;
- case 61:
- resword = &wordlist[37];
- goto compare;
- case 62:
- resword = &wordlist[38];
- goto compare;
- case 66:
- resword = &wordlist[39];
- goto compare;
- case 69:
- resword = &wordlist[40];
- goto compare;
- case 70:
- resword = &wordlist[41];
- goto compare;
- case 71:
- resword = &wordlist[42];
- goto compare;
- case 75:
- resword = &wordlist[43];
- goto compare;
- case 76:
- resword = &wordlist[44];
- goto compare;
- case 80:
- resword = &wordlist[45];
- goto compare;
- case 81:
- resword = &wordlist[46];
- goto compare;
- case 82:
- resword = &wordlist[47];
- goto compare;
- case 83:
- resword = &wordlist[48];
- goto compare;
- case 84:
- resword = &wordlist[49];
- goto compare;
- case 86:
- resword = &wordlist[50];
- goto compare;
- case 88:
- resword = &wordlist[51];
- goto compare;
- case 89:
- resword = &wordlist[52];
- goto compare;
- case 90:
- resword = &wordlist[53];
- goto compare;
- case 91:
- resword = &wordlist[54];
- goto compare;
- case 93:
- resword = &wordlist[55];
- goto compare;
- case 94:
- resword = &wordlist[56];
- goto compare;
- case 95:
- resword = &wordlist[57];
- goto compare;
- case 96:
- resword = &wordlist[58];
- goto compare;
- case 97:
- resword = &wordlist[59];
- goto compare;
- case 98:
- resword = &wordlist[60];
- goto compare;
- case 99:
- resword = &wordlist[61];
- goto compare;
- case 101:
- resword = &wordlist[62];
- goto compare;
- case 103:
- resword = &wordlist[63];
- goto compare;
- case 104:
- resword = &wordlist[64];
- goto compare;
- case 105:
- resword = &wordlist[65];
- goto compare;
- case 106:
- resword = &wordlist[66];
- goto compare;
- case 110:
- resword = &wordlist[67];
- goto compare;
- case 111:
- resword = &wordlist[68];
- goto compare;
- case 112:
- resword = &wordlist[69];
- goto compare;
- case 114:
- resword = &wordlist[70];
- goto compare;
- case 115:
- resword = &wordlist[71];
- goto compare;
- case 116:
- resword = &wordlist[72];
- goto compare;
- case 117:
- resword = &wordlist[73];
- goto compare;
- case 120:
- resword = &wordlist[74];
- goto compare;
- case 121:
- resword = &wordlist[75];
- goto compare;
- case 126:
- resword = &wordlist[76];
- goto compare;
- case 129:
- resword = &wordlist[77];
- goto compare;
- case 131:
- resword = &wordlist[78];
- goto compare;
- case 134:
- resword = &wordlist[79];
- goto compare;
- case 136:
- resword = &wordlist[80];
- goto compare;
- case 139:
- resword = &wordlist[81];
- goto compare;
- case 141:
- resword = &wordlist[82];
- goto compare;
- case 142:
- resword = &wordlist[83];
- goto compare;
- case 143:
- resword = &wordlist[84];
- goto compare;
- case 144:
- resword = &wordlist[85];
- goto compare;
- case 146:
- resword = &wordlist[86];
- goto compare;
- case 147:
- resword = &wordlist[87];
- goto compare;
- case 148:
- resword = &wordlist[88];
- goto compare;
- case 149:
- resword = &wordlist[89];
- goto compare;
- case 150:
- resword = &wordlist[90];
- goto compare;
- case 151:
- resword = &wordlist[91];
- goto compare;
- case 155:
- resword = &wordlist[92];
- goto compare;
- case 156:
- resword = &wordlist[93];
- goto compare;
- case 161:
- resword = &wordlist[94];
- goto compare;
- case 162:
- resword = &wordlist[95];
- goto compare;
- case 163:
- resword = &wordlist[96];
- goto compare;
- case 166:
- resword = &wordlist[97];
- goto compare;
- case 167:
- resword = &wordlist[98];
- goto compare;
- case 171:
- resword = &wordlist[99];
- goto compare;
- case 175:
- resword = &wordlist[100];
- goto compare;
- case 176:
- resword = &wordlist[101];
- goto compare;
- case 181:
- resword = &wordlist[102];
- goto compare;
- case 190:
- resword = &wordlist[103];
- goto compare;
- case 200:
- resword = &wordlist[104];
- goto compare;
- case 218:
- resword = &wordlist[105];
- goto compare;
- }
- return 0;
- compare:
- {
- register const char *s = resword->name;
-
- if ((((unsigned char)*str ^ (unsigned char)*s) & ~32) == 0 && !gperf_case_strncmp (str, s, len) && s[len] == '\0')
- return resword;
- }
- }
- }
- return 0;
-}
diff --git a/src/treebuilder/element-type.c b/src/treebuilder/element-type.c
new file mode 100644
index 0000000..7e2772c
--- /dev/null
+++ b/src/treebuilder/element-type.c
@@ -0,0 +1,49 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include "treebuilder/element-type.h"
+
+/* Auto-generated by `gperf`. */
+#include "treebuilder/autogenerated-element-type.c"
+
+/* Exported function, documented in element-type.h */
+element_type element_type_from_name(
+ hubbub_treebuilder *treebuilder,
+ const hubbub_string *tag_name)
+{
+ const struct element_type_map *value;
+
+ UNUSED(treebuilder);
+
+ value = hubbub_element_type_generated_lookup(
+ (const char *)tag_name->ptr,
+ tag_name->len);
+ if (value == NULL) {
+ return UNKNOWN;
+ }
+
+ return value->type;
+}
+
+/**
+ * Convert an element type to a name
+ *
+ * \param type The element type
+ * \return Pointer to name
+ */
+const char *element_type_to_name(element_type type)
+{
+ size_t i;
+
+ for (i = 0; i < sizeof(wordlist) / sizeof(wordlist[0]); i++) {
+ if (wordlist[i].type == type) {
+ return wordlist[i].name;
+ }
+ }
+
+ return "UNKNOWN";
+}
diff --git a/src/treebuilder/element-type.gperf b/src/treebuilder/element-type.gperf
index d4f2aa2..c0980d3 100644
--- a/src/treebuilder/element-type.gperf
+++ b/src/treebuilder/element-type.gperf
@@ -8,11 +8,12 @@
%language=ANSI-C
%compare-strncmp
%readonly-tables
+%global-table
%ignore-case
%struct-type
%switch=1
-%define hash-function-name hubbub_element_type_hash
-%define lookup-function-name hubbub_element_type_lookup
+%define hash-function-name hubbub_element_type_generated_hash
+%define lookup-function-name hubbub_element_type_generated_lookup
%{
#include <string.h>
diff --git a/src/treebuilder/element-type.h b/src/treebuilder/element-type.h
index a8e33d9..75612fd 100644
--- a/src/treebuilder/element-type.h
+++ b/src/treebuilder/element-type.h
@@ -42,11 +42,6 @@ struct element_type_map {
element_type type;
};
-/* Generated by gperf */
-const struct element_type_map *hubbub_element_type_lookup(
- register const char *str,
- register size_t len);
-
/**
* Convert an element name into an element type
*
@@ -54,22 +49,17 @@ const struct element_type_map *hubbub_element_type_lookup(
* \param tag_name The tag name to consider
* \return The corresponding element type
*/
-static inline element_type element_type_from_name(
+element_type element_type_from_name(
hubbub_treebuilder *treebuilder,
- const hubbub_string *tag_name)
-{
- const struct element_type_map *value;
-
- UNUSED(treebuilder);
-
- value = hubbub_element_type_lookup((const char *)tag_name->ptr,
- tag_name->len);
- if (value == NULL) {
- return UNKNOWN;
- }
+ const hubbub_string *tag_name);
- return value->type;
-}
+/**
+ * Convert an element type to a name
+ *
+ * \param type The element type
+ * \return Pointer to name
+ */
+const char *element_type_to_name(element_type type);
#endif
diff --git a/src/treebuilder/treebuilder.c b/src/treebuilder/treebuilder.c
index 2d2d047..f11875e 100644
--- a/src/treebuilder/treebuilder.c
+++ b/src/treebuilder/treebuilder.c
@@ -1397,24 +1397,5 @@ void formatting_list_dump(hubbub_treebuilder *treebuilder, FILE *fp)
}
}
-/**
- * Convert an element type to a name
- *
- * \param type The element type
- * \return Pointer to name
- */
-const char *element_type_to_name(element_type type)
-{
- size_t i;
-
- for (i = 0;
- i < sizeof(name_type_map) / sizeof(name_type_map[0]);
- i++) {
- if (name_type_map[i].type == type)
- return name_type_map[i].name;
- }
-
- return "UNKNOWN";
-}
#endif
--
HTML5 parser library
2 years
libhubbub: branch master updated. release/0.3.7-16-g0f2caec
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libhubbub.git/shortlog/0f2caec353bc7302168...
...commit http://git.netsurf-browser.org/libhubbub.git/commit/0f2caec353bc7302168cd...
...tree http://git.netsurf-browser.org/libhubbub.git/tree/0f2caec353bc7302168cdc2...
The branch, master has been updated
via 0f2caec353bc7302168cdc2c0575441e43b44c3e (commit)
via 0c89880420c45548b3461e0dab6f8b9720a2b6da (commit)
from c4039d355598c9fabbdcc7ef5a663571ef40211d (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/libhubbub.git/commit/?id=0f2caec353bc73021...
commit 0f2caec353bc7302168cdc2c0575441e43b44c3e
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
treebuilder: Include generated element type lookup source.
Previously this source was generated at build time, however
there was variance in the versions of gperf on all the
platforms that we support.
The comment at the top of the generated source file contains
a command that can be used to regenerate it manually.
diff --git a/src/treebuilder/Makefile b/src/treebuilder/Makefile
index ce00a4c..ae2d9c4 100644
--- a/src/treebuilder/Makefile
+++ b/src/treebuilder/Makefile
@@ -6,12 +6,6 @@ DIR_SOURCES := treebuilder.c \
in_cell.c in_select.c in_select_in_table.c \
in_foreign_content.c after_body.c in_frameset.c \
after_frameset.c after_after_body.c after_after_frameset.c \
- generic_rcdata.c element-type.c
-
-$(DIR)element-type.c: $(DIR)element-type.gperf
- $(VQ)$(ECHO) " GPERF: $<"
- $(Q)gperf --output-file=$@ $<
-
-CLEAN_ITEMS := $(DIR)element-type.c
+ generic_rcdata.c autogenerated-element-type.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/treebuilder/autogenerated-element-type.c b/src/treebuilder/autogenerated-element-type.c
new file mode 100644
index 0000000..f3b4f30
--- /dev/null
+++ b/src/treebuilder/autogenerated-element-type.c
@@ -0,0 +1,705 @@
+/* ANSI-C code produced by gperf version 3.1 */
+/* Command-line: gperf --output-file=src/treebuilder/autogenerated-element-type.c src/treebuilder/element-type.gperf */
+/* Computed positions: -k'1-2,$' */
+
+#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
+ && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
+ && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
+ && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
+ && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
+ && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
+ && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
+ && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
+ && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
+ && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
+ && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
+ && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
+ && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
+ && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
+ && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
+ && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
+ && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
+ && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
+ && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
+ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
+ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
+ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
+/* The character set is not based on ISO-646. */
+#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf(a)gnu.org>."
+#endif
+
+#line 17 "src/treebuilder/element-type.gperf"
+
+#include <string.h>
+
+#include "treebuilder/element-type.h"
+
+#line 24 "src/treebuilder/element-type.gperf"
+struct element_type_map;
+
+#define TOTAL_KEYWORDS 106
+#define MIN_WORD_LENGTH 1
+#define MAX_WORD_LENGTH 14
+#define MIN_HASH_VALUE 1
+#define MAX_HASH_VALUE 219
+/* maximum key range = 219, duplicates = 0 */
+
+#ifndef GPERF_DOWNCASE
+#define GPERF_DOWNCASE 1
+static unsigned char gperf_downcase[256] =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
+ 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
+ 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
+ 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
+ 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
+ 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
+ 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
+ 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
+ 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
+ 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
+ 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
+ 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
+ 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
+ 255
+ };
+#endif
+
+#ifndef GPERF_CASE_STRNCMP
+#define GPERF_CASE_STRNCMP 1
+static int
+gperf_case_strncmp (register const char *s1, register const char *s2, register size_t n)
+{
+ for (; n > 0;)
+ {
+ unsigned char c1 = gperf_downcase[(unsigned char)*s1++];
+ unsigned char c2 = gperf_downcase[(unsigned char)*s2++];
+ if (c1 != 0 && c1 == c2)
+ {
+ n--;
+ continue;
+ }
+ return (int)c1 - (int)c2;
+ }
+ return 0;
+}
+#endif
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static unsigned int
+hubbub_element_type_hash (register const char *str, register size_t len)
+{
+ static const unsigned char asso_values[] =
+ {
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 60,
+ 20, 70, 105, 50, 10, 50, 5, 220, 220, 220,
+ 220, 220, 220, 220, 220, 0, 95, 40, 20, 10,
+ 5, 35, 35, 60, 70, 15, 55, 5, 15, 70,
+ 35, 0, 0, 10, 0, 100, 125, 40, 10, 65,
+ 220, 220, 220, 220, 220, 220, 220, 0, 95, 40,
+ 20, 10, 5, 35, 35, 60, 70, 15, 55, 5,
+ 15, 70, 35, 0, 0, 10, 0, 100, 125, 40,
+ 10, 65, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220
+ };
+ register unsigned int hval = len;
+
+ switch (hval)
+ {
+ default:
+ hval += asso_values[(unsigned char)str[1]+2];
+ /*FALLTHROUGH*/
+ case 1:
+ hval += asso_values[(unsigned char)str[0]];
+ break;
+ }
+ return hval + asso_values[(unsigned char)str[len - 1]];
+}
+
+const struct element_type_map *
+hubbub_element_type_lookup (register const char *str, register size_t len)
+{
+ static const struct element_type_map wordlist[] =
+ {
+#line 26 "src/treebuilder/element-type.gperf"
+ {"a", A},
+#line 126 "src/treebuilder/element-type.gperf"
+ {"tr", TR},
+#line 30 "src/treebuilder/element-type.gperf"
+ {"area", AREA},
+#line 29 "src/treebuilder/element-type.gperf"
+ {"applet", APPLET},
+#line 60 "src/treebuilder/element-type.gperf"
+ {"font", FONT},
+#line 61 "src/treebuilder/element-type.gperf"
+ {"footer", FOOTER},
+#line 65 "src/treebuilder/element-type.gperf"
+ {"frameset", FRAMESET},
+#line 63 "src/treebuilder/element-type.gperf"
+ {"form", FORM},
+#line 112 "src/treebuilder/element-type.gperf"
+ {"spacer", SPACER},
+#line 31 "src/treebuilder/element-type.gperf"
+ {"article", ARTICLE},
+#line 62 "src/treebuilder/element-type.gperf"
+ {"foreignobject", FOREIGNOBJECT},
+#line 95 "src/treebuilder/element-type.gperf"
+ {"nobr", NOBR},
+#line 64 "src/treebuilder/element-type.gperf"
+ {"frame", FRAME},
+#line 108 "src/treebuilder/element-type.gperf"
+ {"s", S},
+#line 27 "src/treebuilder/element-type.gperf"
+ {"address", ADDRESS},
+#line 98 "src/treebuilder/element-type.gperf"
+ {"noscript", NOSCRIPT},
+#line 109 "src/treebuilder/element-type.gperf"
+ {"script", SCRIPT},
+#line 120 "src/treebuilder/element-type.gperf"
+ {"td", TD},
+#line 57 "src/treebuilder/element-type.gperf"
+ {"fieldset", FIELDSET},
+#line 125 "src/treebuilder/element-type.gperf"
+ {"title", TITLE},
+#line 97 "src/treebuilder/element-type.gperf"
+ {"noframes", NOFRAMES},
+#line 59 "src/treebuilder/element-type.gperf"
+ {"figure", FIGURE},
+#line 73 "src/treebuilder/element-type.gperf"
+ {"hr", HR},
+#line 51 "src/treebuilder/element-type.gperf"
+ {"dir", DIR},
+#line 122 "src/treebuilder/element-type.gperf"
+ {"tfoot", TFOOT},
+#line 96 "src/treebuilder/element-type.gperf"
+ {"noembed", NOEMBED},
+#line 121 "src/treebuilder/element-type.gperf"
+ {"textarea", TEXTAREA},
+#line 88 "src/treebuilder/element-type.gperf"
+ {"meta", META},
+#line 58 "src/treebuilder/element-type.gperf"
+ {"figcaption", FIGCAPTION},
+#line 47 "src/treebuilder/element-type.gperf"
+ {"dd", DD},
+#line 107 "src/treebuilder/element-type.gperf"
+ {"pre", PRE},
+#line 110 "src/treebuilder/element-type.gperf"
+ {"select", SELECT},
+#line 71 "src/treebuilder/element-type.gperf"
+ {"h6", H6},
+#line 118 "src/treebuilder/element-type.gperf"
+ {"table", TABLE},
+#line 91 "src/treebuilder/element-type.gperf"
+ {"mn", MN},
+#line 117 "src/treebuilder/element-type.gperf"
+ {"svg", SVG},
+#line 106 "src/treebuilder/element-type.gperf"
+ {"plaintext", PLAINTEXT},
+#line 85 "src/treebuilder/element-type.gperf"
+ {"marquee", MARQUEE},
+#line 130 "src/treebuilder/element-type.gperf"
+ {"wbr", WBR},
+#line 46 "src/treebuilder/element-type.gperf"
+ {"command", COMMAND},
+#line 84 "src/treebuilder/element-type.gperf"
+ {"malignmark", MALIGNMARK},
+#line 104 "src/treebuilder/element-type.gperf"
+ {"p", P},
+#line 49 "src/treebuilder/element-type.gperf"
+ {"details", DETAILS},
+#line 50 "src/treebuilder/element-type.gperf"
+ {"dialog", DIALOG},
+#line 92 "src/treebuilder/element-type.gperf"
+ {"mo", MO},
+#line 43 "src/treebuilder/element-type.gperf"
+ {"center", CENTER},
+#line 90 "src/treebuilder/element-type.gperf"
+ {"mi", MI},
+#line 45 "src/treebuilder/element-type.gperf"
+ {"colgroup", COLGROUP},
+#line 86 "src/treebuilder/element-type.gperf"
+ {"math", MATH},
+#line 105 "src/treebuilder/element-type.gperf"
+ {"param", PARAM},
+#line 55 "src/treebuilder/element-type.gperf"
+ {"em", EM},
+#line 82 "src/treebuilder/element-type.gperf"
+ {"link", LINK},
+#line 119 "src/treebuilder/element-type.gperf"
+ {"tbody", TBODY},
+#line 102 "src/treebuilder/element-type.gperf"
+ {"option", OPTION},
+#line 53 "src/treebuilder/element-type.gperf"
+ {"dl", DL},
+#line 72 "src/treebuilder/element-type.gperf"
+ {"head", HEAD},
+#line 124 "src/treebuilder/element-type.gperf"
+ {"thead", THEAD},
+#line 99 "src/treebuilder/element-type.gperf"
+ {"object", OBJECT},
+#line 40 "src/treebuilder/element-type.gperf"
+ {"br", BR},
+#line 44 "src/treebuilder/element-type.gperf"
+ {"col", COL},
+#line 48 "src/treebuilder/element-type.gperf"
+ {"desc", DESC},
+#line 79 "src/treebuilder/element-type.gperf"
+ {"input", INPUT},
+#line 42 "src/treebuilder/element-type.gperf"
+ {"caption", CAPTION},
+#line 28 "src/treebuilder/element-type.gperf"
+ {"annotation-xml", ANNOTATION_XML},
+#line 56 "src/treebuilder/element-type.gperf"
+ {"embed", EMBED},
+#line 89 "src/treebuilder/element-type.gperf"
+ {"mglyph", MGLYPH},
+#line 123 "src/treebuilder/element-type.gperf"
+ {"th", TH},
+#line 76 "src/treebuilder/element-type.gperf"
+ {"iframe", IFRAME},
+#line 83 "src/treebuilder/element-type.gperf"
+ {"listing", LISTING},
+#line 101 "src/treebuilder/element-type.gperf"
+ {"optgroup", OPTGROUP},
+#line 32 "src/treebuilder/element-type.gperf"
+ {"aside", ASIDE},
+#line 103 "src/treebuilder/element-type.gperf"
+ {"output", OUTPUT},
+#line 93 "src/treebuilder/element-type.gperf"
+ {"ms", MS},
+#line 131 "src/treebuilder/element-type.gperf"
+ {"xmp", XMP},
+#line 75 "src/treebuilder/element-type.gperf"
+ {"i", I},
+#line 116 "src/treebuilder/element-type.gperf"
+ {"summary", SUMMARY},
+#line 127 "src/treebuilder/element-type.gperf"
+ {"tt", TT},
+#line 38 "src/treebuilder/element-type.gperf"
+ {"blockquote", BLOCKQUOTE},
+#line 81 "src/treebuilder/element-type.gperf"
+ {"li", LI},
+#line 94 "src/treebuilder/element-type.gperf"
+ {"mtext", MTEXT},
+#line 70 "src/treebuilder/element-type.gperf"
+ {"h5", H5},
+#line 111 "src/treebuilder/element-type.gperf"
+ {"small", SMALL},
+#line 100 "src/treebuilder/element-type.gperf"
+ {"ol", OL},
+#line 35 "src/treebuilder/element-type.gperf"
+ {"basefont", BASEFONT},
+#line 87 "src/treebuilder/element-type.gperf"
+ {"menu", MENU},
+#line 77 "src/treebuilder/element-type.gperf"
+ {"image", IMAGE},
+#line 54 "src/treebuilder/element-type.gperf"
+ {"dt", DT},
+#line 37 "src/treebuilder/element-type.gperf"
+ {"big", BIG},
+#line 34 "src/treebuilder/element-type.gperf"
+ {"base", BASE},
+#line 115 "src/treebuilder/element-type.gperf"
+ {"style", STYLE},
+#line 113 "src/treebuilder/element-type.gperf"
+ {"strike", STRIKE},
+#line 69 "src/treebuilder/element-type.gperf"
+ {"h4", H4},
+#line 41 "src/treebuilder/element-type.gperf"
+ {"button", BUTTON},
+#line 68 "src/treebuilder/element-type.gperf"
+ {"h3", H3},
+#line 67 "src/treebuilder/element-type.gperf"
+ {"h2", H2},
+#line 52 "src/treebuilder/element-type.gperf"
+ {"div", DIV},
+#line 39 "src/treebuilder/element-type.gperf"
+ {"body", BODY},
+#line 66 "src/treebuilder/element-type.gperf"
+ {"h1", H1},
+#line 78 "src/treebuilder/element-type.gperf"
+ {"img", IMG},
+#line 129 "src/treebuilder/element-type.gperf"
+ {"ul", UL},
+#line 114 "src/treebuilder/element-type.gperf"
+ {"strong", STRONG},
+#line 80 "src/treebuilder/element-type.gperf"
+ {"isindex", ISINDEX},
+#line 36 "src/treebuilder/element-type.gperf"
+ {"bgsound", BGSOUND},
+#line 33 "src/treebuilder/element-type.gperf"
+ {"b", B},
+#line 128 "src/treebuilder/element-type.gperf"
+ {"u", U},
+#line 74 "src/treebuilder/element-type.gperf"
+ {"html", HTML}
+ };
+
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
+ {
+ register unsigned int key = hubbub_element_type_hash (str, len);
+
+ if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
+ {
+ register const struct element_type_map *resword;
+
+ switch (key - 1)
+ {
+ case 0:
+ resword = &wordlist[0];
+ goto compare;
+ case 1:
+ resword = &wordlist[1];
+ goto compare;
+ case 3:
+ resword = &wordlist[2];
+ goto compare;
+ case 5:
+ resword = &wordlist[3];
+ goto compare;
+ case 8:
+ resword = &wordlist[4];
+ goto compare;
+ case 10:
+ resword = &wordlist[5];
+ goto compare;
+ case 12:
+ resword = &wordlist[6];
+ goto compare;
+ case 13:
+ resword = &wordlist[7];
+ goto compare;
+ case 15:
+ resword = &wordlist[8];
+ goto compare;
+ case 16:
+ resword = &wordlist[9];
+ goto compare;
+ case 17:
+ resword = &wordlist[10];
+ goto compare;
+ case 18:
+ resword = &wordlist[11];
+ goto compare;
+ case 19:
+ resword = &wordlist[12];
+ goto compare;
+ case 20:
+ resword = &wordlist[13];
+ goto compare;
+ case 21:
+ resword = &wordlist[14];
+ goto compare;
+ case 22:
+ resword = &wordlist[15];
+ goto compare;
+ case 25:
+ resword = &wordlist[16];
+ goto compare;
+ case 26:
+ resword = &wordlist[17];
+ goto compare;
+ case 27:
+ resword = &wordlist[18];
+ goto compare;
+ case 29:
+ resword = &wordlist[19];
+ goto compare;
+ case 32:
+ resword = &wordlist[20];
+ goto compare;
+ case 35:
+ resword = &wordlist[21];
+ goto compare;
+ case 36:
+ resword = &wordlist[22];
+ goto compare;
+ case 37:
+ resword = &wordlist[23];
+ goto compare;
+ case 39:
+ resword = &wordlist[24];
+ goto compare;
+ case 41:
+ resword = &wordlist[25];
+ goto compare;
+ case 42:
+ resword = &wordlist[26];
+ goto compare;
+ case 43:
+ resword = &wordlist[27];
+ goto compare;
+ case 44:
+ resword = &wordlist[28];
+ goto compare;
+ case 46:
+ resword = &wordlist[29];
+ goto compare;
+ case 47:
+ resword = &wordlist[30];
+ goto compare;
+ case 50:
+ resword = &wordlist[31];
+ goto compare;
+ case 51:
+ resword = &wordlist[32];
+ goto compare;
+ case 54:
+ resword = &wordlist[33];
+ goto compare;
+ case 56:
+ resword = &wordlist[34];
+ goto compare;
+ case 57:
+ resword = &wordlist[35];
+ goto compare;
+ case 58:
+ resword = &wordlist[36];
+ goto compare;
+ case 61:
+ resword = &wordlist[37];
+ goto compare;
+ case 62:
+ resword = &wordlist[38];
+ goto compare;
+ case 66:
+ resword = &wordlist[39];
+ goto compare;
+ case 69:
+ resword = &wordlist[40];
+ goto compare;
+ case 70:
+ resword = &wordlist[41];
+ goto compare;
+ case 71:
+ resword = &wordlist[42];
+ goto compare;
+ case 75:
+ resword = &wordlist[43];
+ goto compare;
+ case 76:
+ resword = &wordlist[44];
+ goto compare;
+ case 80:
+ resword = &wordlist[45];
+ goto compare;
+ case 81:
+ resword = &wordlist[46];
+ goto compare;
+ case 82:
+ resword = &wordlist[47];
+ goto compare;
+ case 83:
+ resword = &wordlist[48];
+ goto compare;
+ case 84:
+ resword = &wordlist[49];
+ goto compare;
+ case 86:
+ resword = &wordlist[50];
+ goto compare;
+ case 88:
+ resword = &wordlist[51];
+ goto compare;
+ case 89:
+ resword = &wordlist[52];
+ goto compare;
+ case 90:
+ resword = &wordlist[53];
+ goto compare;
+ case 91:
+ resword = &wordlist[54];
+ goto compare;
+ case 93:
+ resword = &wordlist[55];
+ goto compare;
+ case 94:
+ resword = &wordlist[56];
+ goto compare;
+ case 95:
+ resword = &wordlist[57];
+ goto compare;
+ case 96:
+ resword = &wordlist[58];
+ goto compare;
+ case 97:
+ resword = &wordlist[59];
+ goto compare;
+ case 98:
+ resword = &wordlist[60];
+ goto compare;
+ case 99:
+ resword = &wordlist[61];
+ goto compare;
+ case 101:
+ resword = &wordlist[62];
+ goto compare;
+ case 103:
+ resword = &wordlist[63];
+ goto compare;
+ case 104:
+ resword = &wordlist[64];
+ goto compare;
+ case 105:
+ resword = &wordlist[65];
+ goto compare;
+ case 106:
+ resword = &wordlist[66];
+ goto compare;
+ case 110:
+ resword = &wordlist[67];
+ goto compare;
+ case 111:
+ resword = &wordlist[68];
+ goto compare;
+ case 112:
+ resword = &wordlist[69];
+ goto compare;
+ case 114:
+ resword = &wordlist[70];
+ goto compare;
+ case 115:
+ resword = &wordlist[71];
+ goto compare;
+ case 116:
+ resword = &wordlist[72];
+ goto compare;
+ case 117:
+ resword = &wordlist[73];
+ goto compare;
+ case 120:
+ resword = &wordlist[74];
+ goto compare;
+ case 121:
+ resword = &wordlist[75];
+ goto compare;
+ case 126:
+ resword = &wordlist[76];
+ goto compare;
+ case 129:
+ resword = &wordlist[77];
+ goto compare;
+ case 131:
+ resword = &wordlist[78];
+ goto compare;
+ case 134:
+ resword = &wordlist[79];
+ goto compare;
+ case 136:
+ resword = &wordlist[80];
+ goto compare;
+ case 139:
+ resword = &wordlist[81];
+ goto compare;
+ case 141:
+ resword = &wordlist[82];
+ goto compare;
+ case 142:
+ resword = &wordlist[83];
+ goto compare;
+ case 143:
+ resword = &wordlist[84];
+ goto compare;
+ case 144:
+ resword = &wordlist[85];
+ goto compare;
+ case 146:
+ resword = &wordlist[86];
+ goto compare;
+ case 147:
+ resword = &wordlist[87];
+ goto compare;
+ case 148:
+ resword = &wordlist[88];
+ goto compare;
+ case 149:
+ resword = &wordlist[89];
+ goto compare;
+ case 150:
+ resword = &wordlist[90];
+ goto compare;
+ case 151:
+ resword = &wordlist[91];
+ goto compare;
+ case 155:
+ resword = &wordlist[92];
+ goto compare;
+ case 156:
+ resword = &wordlist[93];
+ goto compare;
+ case 161:
+ resword = &wordlist[94];
+ goto compare;
+ case 162:
+ resword = &wordlist[95];
+ goto compare;
+ case 163:
+ resword = &wordlist[96];
+ goto compare;
+ case 166:
+ resword = &wordlist[97];
+ goto compare;
+ case 167:
+ resword = &wordlist[98];
+ goto compare;
+ case 171:
+ resword = &wordlist[99];
+ goto compare;
+ case 175:
+ resword = &wordlist[100];
+ goto compare;
+ case 176:
+ resword = &wordlist[101];
+ goto compare;
+ case 181:
+ resword = &wordlist[102];
+ goto compare;
+ case 190:
+ resword = &wordlist[103];
+ goto compare;
+ case 200:
+ resword = &wordlist[104];
+ goto compare;
+ case 218:
+ resword = &wordlist[105];
+ goto compare;
+ }
+ return 0;
+ compare:
+ {
+ register const char *s = resword->name;
+
+ if ((((unsigned char)*str ^ (unsigned char)*s) & ~32) == 0 && !gperf_case_strncmp (str, s, len) && s[len] == '\0')
+ return resword;
+ }
+ }
+ }
+ return 0;
+}
commitdiff http://git.netsurf-browser.org/libhubbub.git/commit/?id=0c89880420c45548b...
commit 0c89880420c45548b3461e0dab6f8b9720a2b6da
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
tokeniser: Constify token through hubbub_tokeniser_emit_token().
diff --git a/src/tokeniser/tokeniser.c b/src/tokeniser/tokeniser.c
index 2d9c4ed..78eeee3 100644
--- a/src/tokeniser/tokeniser.c
+++ b/src/tokeniser/tokeniser.c
@@ -271,7 +271,7 @@ static inline hubbub_error emit_current_comment(hubbub_tokeniser *tokeniser);
static inline hubbub_error emit_current_doctype(hubbub_tokeniser *tokeniser,
bool force_quirks);
static hubbub_error hubbub_tokeniser_emit_token(hubbub_tokeniser *tokeniser,
- hubbub_token *token);
+ const hubbub_token *token);
/**
* Create a hubbub tokeniser
@@ -3365,7 +3365,7 @@ hubbub_error emit_current_doctype(hubbub_tokeniser *tokeniser,
* \param token Token to emit
*/
hubbub_error hubbub_tokeniser_emit_token(hubbub_tokeniser *tokeniser,
- hubbub_token *token)
+ const hubbub_token *token)
{
hubbub_error err = HUBBUB_OK;
-----------------------------------------------------------------------
Summary of changes:
src/tokeniser/tokeniser.c | 4 +-
src/treebuilder/Makefile | 8 +-
src/treebuilder/autogenerated-element-type.c | 705 ++++++++++++++++++++++++++
3 files changed, 708 insertions(+), 9 deletions(-)
create mode 100644 src/treebuilder/autogenerated-element-type.c
diff --git a/src/tokeniser/tokeniser.c b/src/tokeniser/tokeniser.c
index 2d9c4ed..78eeee3 100644
--- a/src/tokeniser/tokeniser.c
+++ b/src/tokeniser/tokeniser.c
@@ -271,7 +271,7 @@ static inline hubbub_error emit_current_comment(hubbub_tokeniser *tokeniser);
static inline hubbub_error emit_current_doctype(hubbub_tokeniser *tokeniser,
bool force_quirks);
static hubbub_error hubbub_tokeniser_emit_token(hubbub_tokeniser *tokeniser,
- hubbub_token *token);
+ const hubbub_token *token);
/**
* Create a hubbub tokeniser
@@ -3365,7 +3365,7 @@ hubbub_error emit_current_doctype(hubbub_tokeniser *tokeniser,
* \param token Token to emit
*/
hubbub_error hubbub_tokeniser_emit_token(hubbub_tokeniser *tokeniser,
- hubbub_token *token)
+ const hubbub_token *token)
{
hubbub_error err = HUBBUB_OK;
diff --git a/src/treebuilder/Makefile b/src/treebuilder/Makefile
index ce00a4c..ae2d9c4 100644
--- a/src/treebuilder/Makefile
+++ b/src/treebuilder/Makefile
@@ -6,12 +6,6 @@ DIR_SOURCES := treebuilder.c \
in_cell.c in_select.c in_select_in_table.c \
in_foreign_content.c after_body.c in_frameset.c \
after_frameset.c after_after_body.c after_after_frameset.c \
- generic_rcdata.c element-type.c
-
-$(DIR)element-type.c: $(DIR)element-type.gperf
- $(VQ)$(ECHO) " GPERF: $<"
- $(Q)gperf --output-file=$@ $<
-
-CLEAN_ITEMS := $(DIR)element-type.c
+ generic_rcdata.c autogenerated-element-type.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/treebuilder/autogenerated-element-type.c b/src/treebuilder/autogenerated-element-type.c
new file mode 100644
index 0000000..f3b4f30
--- /dev/null
+++ b/src/treebuilder/autogenerated-element-type.c
@@ -0,0 +1,705 @@
+/* ANSI-C code produced by gperf version 3.1 */
+/* Command-line: gperf --output-file=src/treebuilder/autogenerated-element-type.c src/treebuilder/element-type.gperf */
+/* Computed positions: -k'1-2,$' */
+
+#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
+ && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
+ && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
+ && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
+ && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
+ && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
+ && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
+ && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
+ && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
+ && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
+ && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
+ && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
+ && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
+ && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
+ && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
+ && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
+ && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
+ && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
+ && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
+ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
+ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
+ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
+/* The character set is not based on ISO-646. */
+#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf(a)gnu.org>."
+#endif
+
+#line 17 "src/treebuilder/element-type.gperf"
+
+#include <string.h>
+
+#include "treebuilder/element-type.h"
+
+#line 24 "src/treebuilder/element-type.gperf"
+struct element_type_map;
+
+#define TOTAL_KEYWORDS 106
+#define MIN_WORD_LENGTH 1
+#define MAX_WORD_LENGTH 14
+#define MIN_HASH_VALUE 1
+#define MAX_HASH_VALUE 219
+/* maximum key range = 219, duplicates = 0 */
+
+#ifndef GPERF_DOWNCASE
+#define GPERF_DOWNCASE 1
+static unsigned char gperf_downcase[256] =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
+ 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
+ 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
+ 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
+ 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
+ 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
+ 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
+ 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
+ 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
+ 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
+ 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
+ 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
+ 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
+ 255
+ };
+#endif
+
+#ifndef GPERF_CASE_STRNCMP
+#define GPERF_CASE_STRNCMP 1
+static int
+gperf_case_strncmp (register const char *s1, register const char *s2, register size_t n)
+{
+ for (; n > 0;)
+ {
+ unsigned char c1 = gperf_downcase[(unsigned char)*s1++];
+ unsigned char c2 = gperf_downcase[(unsigned char)*s2++];
+ if (c1 != 0 && c1 == c2)
+ {
+ n--;
+ continue;
+ }
+ return (int)c1 - (int)c2;
+ }
+ return 0;
+}
+#endif
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static unsigned int
+hubbub_element_type_hash (register const char *str, register size_t len)
+{
+ static const unsigned char asso_values[] =
+ {
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 60,
+ 20, 70, 105, 50, 10, 50, 5, 220, 220, 220,
+ 220, 220, 220, 220, 220, 0, 95, 40, 20, 10,
+ 5, 35, 35, 60, 70, 15, 55, 5, 15, 70,
+ 35, 0, 0, 10, 0, 100, 125, 40, 10, 65,
+ 220, 220, 220, 220, 220, 220, 220, 0, 95, 40,
+ 20, 10, 5, 35, 35, 60, 70, 15, 55, 5,
+ 15, 70, 35, 0, 0, 10, 0, 100, 125, 40,
+ 10, 65, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
+ 220, 220, 220, 220, 220, 220, 220, 220
+ };
+ register unsigned int hval = len;
+
+ switch (hval)
+ {
+ default:
+ hval += asso_values[(unsigned char)str[1]+2];
+ /*FALLTHROUGH*/
+ case 1:
+ hval += asso_values[(unsigned char)str[0]];
+ break;
+ }
+ return hval + asso_values[(unsigned char)str[len - 1]];
+}
+
+const struct element_type_map *
+hubbub_element_type_lookup (register const char *str, register size_t len)
+{
+ static const struct element_type_map wordlist[] =
+ {
+#line 26 "src/treebuilder/element-type.gperf"
+ {"a", A},
+#line 126 "src/treebuilder/element-type.gperf"
+ {"tr", TR},
+#line 30 "src/treebuilder/element-type.gperf"
+ {"area", AREA},
+#line 29 "src/treebuilder/element-type.gperf"
+ {"applet", APPLET},
+#line 60 "src/treebuilder/element-type.gperf"
+ {"font", FONT},
+#line 61 "src/treebuilder/element-type.gperf"
+ {"footer", FOOTER},
+#line 65 "src/treebuilder/element-type.gperf"
+ {"frameset", FRAMESET},
+#line 63 "src/treebuilder/element-type.gperf"
+ {"form", FORM},
+#line 112 "src/treebuilder/element-type.gperf"
+ {"spacer", SPACER},
+#line 31 "src/treebuilder/element-type.gperf"
+ {"article", ARTICLE},
+#line 62 "src/treebuilder/element-type.gperf"
+ {"foreignobject", FOREIGNOBJECT},
+#line 95 "src/treebuilder/element-type.gperf"
+ {"nobr", NOBR},
+#line 64 "src/treebuilder/element-type.gperf"
+ {"frame", FRAME},
+#line 108 "src/treebuilder/element-type.gperf"
+ {"s", S},
+#line 27 "src/treebuilder/element-type.gperf"
+ {"address", ADDRESS},
+#line 98 "src/treebuilder/element-type.gperf"
+ {"noscript", NOSCRIPT},
+#line 109 "src/treebuilder/element-type.gperf"
+ {"script", SCRIPT},
+#line 120 "src/treebuilder/element-type.gperf"
+ {"td", TD},
+#line 57 "src/treebuilder/element-type.gperf"
+ {"fieldset", FIELDSET},
+#line 125 "src/treebuilder/element-type.gperf"
+ {"title", TITLE},
+#line 97 "src/treebuilder/element-type.gperf"
+ {"noframes", NOFRAMES},
+#line 59 "src/treebuilder/element-type.gperf"
+ {"figure", FIGURE},
+#line 73 "src/treebuilder/element-type.gperf"
+ {"hr", HR},
+#line 51 "src/treebuilder/element-type.gperf"
+ {"dir", DIR},
+#line 122 "src/treebuilder/element-type.gperf"
+ {"tfoot", TFOOT},
+#line 96 "src/treebuilder/element-type.gperf"
+ {"noembed", NOEMBED},
+#line 121 "src/treebuilder/element-type.gperf"
+ {"textarea", TEXTAREA},
+#line 88 "src/treebuilder/element-type.gperf"
+ {"meta", META},
+#line 58 "src/treebuilder/element-type.gperf"
+ {"figcaption", FIGCAPTION},
+#line 47 "src/treebuilder/element-type.gperf"
+ {"dd", DD},
+#line 107 "src/treebuilder/element-type.gperf"
+ {"pre", PRE},
+#line 110 "src/treebuilder/element-type.gperf"
+ {"select", SELECT},
+#line 71 "src/treebuilder/element-type.gperf"
+ {"h6", H6},
+#line 118 "src/treebuilder/element-type.gperf"
+ {"table", TABLE},
+#line 91 "src/treebuilder/element-type.gperf"
+ {"mn", MN},
+#line 117 "src/treebuilder/element-type.gperf"
+ {"svg", SVG},
+#line 106 "src/treebuilder/element-type.gperf"
+ {"plaintext", PLAINTEXT},
+#line 85 "src/treebuilder/element-type.gperf"
+ {"marquee", MARQUEE},
+#line 130 "src/treebuilder/element-type.gperf"
+ {"wbr", WBR},
+#line 46 "src/treebuilder/element-type.gperf"
+ {"command", COMMAND},
+#line 84 "src/treebuilder/element-type.gperf"
+ {"malignmark", MALIGNMARK},
+#line 104 "src/treebuilder/element-type.gperf"
+ {"p", P},
+#line 49 "src/treebuilder/element-type.gperf"
+ {"details", DETAILS},
+#line 50 "src/treebuilder/element-type.gperf"
+ {"dialog", DIALOG},
+#line 92 "src/treebuilder/element-type.gperf"
+ {"mo", MO},
+#line 43 "src/treebuilder/element-type.gperf"
+ {"center", CENTER},
+#line 90 "src/treebuilder/element-type.gperf"
+ {"mi", MI},
+#line 45 "src/treebuilder/element-type.gperf"
+ {"colgroup", COLGROUP},
+#line 86 "src/treebuilder/element-type.gperf"
+ {"math", MATH},
+#line 105 "src/treebuilder/element-type.gperf"
+ {"param", PARAM},
+#line 55 "src/treebuilder/element-type.gperf"
+ {"em", EM},
+#line 82 "src/treebuilder/element-type.gperf"
+ {"link", LINK},
+#line 119 "src/treebuilder/element-type.gperf"
+ {"tbody", TBODY},
+#line 102 "src/treebuilder/element-type.gperf"
+ {"option", OPTION},
+#line 53 "src/treebuilder/element-type.gperf"
+ {"dl", DL},
+#line 72 "src/treebuilder/element-type.gperf"
+ {"head", HEAD},
+#line 124 "src/treebuilder/element-type.gperf"
+ {"thead", THEAD},
+#line 99 "src/treebuilder/element-type.gperf"
+ {"object", OBJECT},
+#line 40 "src/treebuilder/element-type.gperf"
+ {"br", BR},
+#line 44 "src/treebuilder/element-type.gperf"
+ {"col", COL},
+#line 48 "src/treebuilder/element-type.gperf"
+ {"desc", DESC},
+#line 79 "src/treebuilder/element-type.gperf"
+ {"input", INPUT},
+#line 42 "src/treebuilder/element-type.gperf"
+ {"caption", CAPTION},
+#line 28 "src/treebuilder/element-type.gperf"
+ {"annotation-xml", ANNOTATION_XML},
+#line 56 "src/treebuilder/element-type.gperf"
+ {"embed", EMBED},
+#line 89 "src/treebuilder/element-type.gperf"
+ {"mglyph", MGLYPH},
+#line 123 "src/treebuilder/element-type.gperf"
+ {"th", TH},
+#line 76 "src/treebuilder/element-type.gperf"
+ {"iframe", IFRAME},
+#line 83 "src/treebuilder/element-type.gperf"
+ {"listing", LISTING},
+#line 101 "src/treebuilder/element-type.gperf"
+ {"optgroup", OPTGROUP},
+#line 32 "src/treebuilder/element-type.gperf"
+ {"aside", ASIDE},
+#line 103 "src/treebuilder/element-type.gperf"
+ {"output", OUTPUT},
+#line 93 "src/treebuilder/element-type.gperf"
+ {"ms", MS},
+#line 131 "src/treebuilder/element-type.gperf"
+ {"xmp", XMP},
+#line 75 "src/treebuilder/element-type.gperf"
+ {"i", I},
+#line 116 "src/treebuilder/element-type.gperf"
+ {"summary", SUMMARY},
+#line 127 "src/treebuilder/element-type.gperf"
+ {"tt", TT},
+#line 38 "src/treebuilder/element-type.gperf"
+ {"blockquote", BLOCKQUOTE},
+#line 81 "src/treebuilder/element-type.gperf"
+ {"li", LI},
+#line 94 "src/treebuilder/element-type.gperf"
+ {"mtext", MTEXT},
+#line 70 "src/treebuilder/element-type.gperf"
+ {"h5", H5},
+#line 111 "src/treebuilder/element-type.gperf"
+ {"small", SMALL},
+#line 100 "src/treebuilder/element-type.gperf"
+ {"ol", OL},
+#line 35 "src/treebuilder/element-type.gperf"
+ {"basefont", BASEFONT},
+#line 87 "src/treebuilder/element-type.gperf"
+ {"menu", MENU},
+#line 77 "src/treebuilder/element-type.gperf"
+ {"image", IMAGE},
+#line 54 "src/treebuilder/element-type.gperf"
+ {"dt", DT},
+#line 37 "src/treebuilder/element-type.gperf"
+ {"big", BIG},
+#line 34 "src/treebuilder/element-type.gperf"
+ {"base", BASE},
+#line 115 "src/treebuilder/element-type.gperf"
+ {"style", STYLE},
+#line 113 "src/treebuilder/element-type.gperf"
+ {"strike", STRIKE},
+#line 69 "src/treebuilder/element-type.gperf"
+ {"h4", H4},
+#line 41 "src/treebuilder/element-type.gperf"
+ {"button", BUTTON},
+#line 68 "src/treebuilder/element-type.gperf"
+ {"h3", H3},
+#line 67 "src/treebuilder/element-type.gperf"
+ {"h2", H2},
+#line 52 "src/treebuilder/element-type.gperf"
+ {"div", DIV},
+#line 39 "src/treebuilder/element-type.gperf"
+ {"body", BODY},
+#line 66 "src/treebuilder/element-type.gperf"
+ {"h1", H1},
+#line 78 "src/treebuilder/element-type.gperf"
+ {"img", IMG},
+#line 129 "src/treebuilder/element-type.gperf"
+ {"ul", UL},
+#line 114 "src/treebuilder/element-type.gperf"
+ {"strong", STRONG},
+#line 80 "src/treebuilder/element-type.gperf"
+ {"isindex", ISINDEX},
+#line 36 "src/treebuilder/element-type.gperf"
+ {"bgsound", BGSOUND},
+#line 33 "src/treebuilder/element-type.gperf"
+ {"b", B},
+#line 128 "src/treebuilder/element-type.gperf"
+ {"u", U},
+#line 74 "src/treebuilder/element-type.gperf"
+ {"html", HTML}
+ };
+
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
+ {
+ register unsigned int key = hubbub_element_type_hash (str, len);
+
+ if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
+ {
+ register const struct element_type_map *resword;
+
+ switch (key - 1)
+ {
+ case 0:
+ resword = &wordlist[0];
+ goto compare;
+ case 1:
+ resword = &wordlist[1];
+ goto compare;
+ case 3:
+ resword = &wordlist[2];
+ goto compare;
+ case 5:
+ resword = &wordlist[3];
+ goto compare;
+ case 8:
+ resword = &wordlist[4];
+ goto compare;
+ case 10:
+ resword = &wordlist[5];
+ goto compare;
+ case 12:
+ resword = &wordlist[6];
+ goto compare;
+ case 13:
+ resword = &wordlist[7];
+ goto compare;
+ case 15:
+ resword = &wordlist[8];
+ goto compare;
+ case 16:
+ resword = &wordlist[9];
+ goto compare;
+ case 17:
+ resword = &wordlist[10];
+ goto compare;
+ case 18:
+ resword = &wordlist[11];
+ goto compare;
+ case 19:
+ resword = &wordlist[12];
+ goto compare;
+ case 20:
+ resword = &wordlist[13];
+ goto compare;
+ case 21:
+ resword = &wordlist[14];
+ goto compare;
+ case 22:
+ resword = &wordlist[15];
+ goto compare;
+ case 25:
+ resword = &wordlist[16];
+ goto compare;
+ case 26:
+ resword = &wordlist[17];
+ goto compare;
+ case 27:
+ resword = &wordlist[18];
+ goto compare;
+ case 29:
+ resword = &wordlist[19];
+ goto compare;
+ case 32:
+ resword = &wordlist[20];
+ goto compare;
+ case 35:
+ resword = &wordlist[21];
+ goto compare;
+ case 36:
+ resword = &wordlist[22];
+ goto compare;
+ case 37:
+ resword = &wordlist[23];
+ goto compare;
+ case 39:
+ resword = &wordlist[24];
+ goto compare;
+ case 41:
+ resword = &wordlist[25];
+ goto compare;
+ case 42:
+ resword = &wordlist[26];
+ goto compare;
+ case 43:
+ resword = &wordlist[27];
+ goto compare;
+ case 44:
+ resword = &wordlist[28];
+ goto compare;
+ case 46:
+ resword = &wordlist[29];
+ goto compare;
+ case 47:
+ resword = &wordlist[30];
+ goto compare;
+ case 50:
+ resword = &wordlist[31];
+ goto compare;
+ case 51:
+ resword = &wordlist[32];
+ goto compare;
+ case 54:
+ resword = &wordlist[33];
+ goto compare;
+ case 56:
+ resword = &wordlist[34];
+ goto compare;
+ case 57:
+ resword = &wordlist[35];
+ goto compare;
+ case 58:
+ resword = &wordlist[36];
+ goto compare;
+ case 61:
+ resword = &wordlist[37];
+ goto compare;
+ case 62:
+ resword = &wordlist[38];
+ goto compare;
+ case 66:
+ resword = &wordlist[39];
+ goto compare;
+ case 69:
+ resword = &wordlist[40];
+ goto compare;
+ case 70:
+ resword = &wordlist[41];
+ goto compare;
+ case 71:
+ resword = &wordlist[42];
+ goto compare;
+ case 75:
+ resword = &wordlist[43];
+ goto compare;
+ case 76:
+ resword = &wordlist[44];
+ goto compare;
+ case 80:
+ resword = &wordlist[45];
+ goto compare;
+ case 81:
+ resword = &wordlist[46];
+ goto compare;
+ case 82:
+ resword = &wordlist[47];
+ goto compare;
+ case 83:
+ resword = &wordlist[48];
+ goto compare;
+ case 84:
+ resword = &wordlist[49];
+ goto compare;
+ case 86:
+ resword = &wordlist[50];
+ goto compare;
+ case 88:
+ resword = &wordlist[51];
+ goto compare;
+ case 89:
+ resword = &wordlist[52];
+ goto compare;
+ case 90:
+ resword = &wordlist[53];
+ goto compare;
+ case 91:
+ resword = &wordlist[54];
+ goto compare;
+ case 93:
+ resword = &wordlist[55];
+ goto compare;
+ case 94:
+ resword = &wordlist[56];
+ goto compare;
+ case 95:
+ resword = &wordlist[57];
+ goto compare;
+ case 96:
+ resword = &wordlist[58];
+ goto compare;
+ case 97:
+ resword = &wordlist[59];
+ goto compare;
+ case 98:
+ resword = &wordlist[60];
+ goto compare;
+ case 99:
+ resword = &wordlist[61];
+ goto compare;
+ case 101:
+ resword = &wordlist[62];
+ goto compare;
+ case 103:
+ resword = &wordlist[63];
+ goto compare;
+ case 104:
+ resword = &wordlist[64];
+ goto compare;
+ case 105:
+ resword = &wordlist[65];
+ goto compare;
+ case 106:
+ resword = &wordlist[66];
+ goto compare;
+ case 110:
+ resword = &wordlist[67];
+ goto compare;
+ case 111:
+ resword = &wordlist[68];
+ goto compare;
+ case 112:
+ resword = &wordlist[69];
+ goto compare;
+ case 114:
+ resword = &wordlist[70];
+ goto compare;
+ case 115:
+ resword = &wordlist[71];
+ goto compare;
+ case 116:
+ resword = &wordlist[72];
+ goto compare;
+ case 117:
+ resword = &wordlist[73];
+ goto compare;
+ case 120:
+ resword = &wordlist[74];
+ goto compare;
+ case 121:
+ resword = &wordlist[75];
+ goto compare;
+ case 126:
+ resword = &wordlist[76];
+ goto compare;
+ case 129:
+ resword = &wordlist[77];
+ goto compare;
+ case 131:
+ resword = &wordlist[78];
+ goto compare;
+ case 134:
+ resword = &wordlist[79];
+ goto compare;
+ case 136:
+ resword = &wordlist[80];
+ goto compare;
+ case 139:
+ resword = &wordlist[81];
+ goto compare;
+ case 141:
+ resword = &wordlist[82];
+ goto compare;
+ case 142:
+ resword = &wordlist[83];
+ goto compare;
+ case 143:
+ resword = &wordlist[84];
+ goto compare;
+ case 144:
+ resword = &wordlist[85];
+ goto compare;
+ case 146:
+ resword = &wordlist[86];
+ goto compare;
+ case 147:
+ resword = &wordlist[87];
+ goto compare;
+ case 148:
+ resword = &wordlist[88];
+ goto compare;
+ case 149:
+ resword = &wordlist[89];
+ goto compare;
+ case 150:
+ resword = &wordlist[90];
+ goto compare;
+ case 151:
+ resword = &wordlist[91];
+ goto compare;
+ case 155:
+ resword = &wordlist[92];
+ goto compare;
+ case 156:
+ resword = &wordlist[93];
+ goto compare;
+ case 161:
+ resword = &wordlist[94];
+ goto compare;
+ case 162:
+ resword = &wordlist[95];
+ goto compare;
+ case 163:
+ resword = &wordlist[96];
+ goto compare;
+ case 166:
+ resword = &wordlist[97];
+ goto compare;
+ case 167:
+ resword = &wordlist[98];
+ goto compare;
+ case 171:
+ resword = &wordlist[99];
+ goto compare;
+ case 175:
+ resword = &wordlist[100];
+ goto compare;
+ case 176:
+ resword = &wordlist[101];
+ goto compare;
+ case 181:
+ resword = &wordlist[102];
+ goto compare;
+ case 190:
+ resword = &wordlist[103];
+ goto compare;
+ case 200:
+ resword = &wordlist[104];
+ goto compare;
+ case 218:
+ resword = &wordlist[105];
+ goto compare;
+ }
+ return 0;
+ compare:
+ {
+ register const char *s = resword->name;
+
+ if ((((unsigned char)*str ^ (unsigned char)*s) & ~32) == 0 && !gperf_case_strncmp (str, s, len) && s[len] == '\0')
+ return resword;
+ }
+ }
+ }
+ return 0;
+}
--
HTML5 parser library
2 years
netsurf-website: branch master updated. 731fe1475abf4b4b189eb06eaffa57943eebaeae
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf-website.git/shortlog/731fe1475abf4...
...commit http://git.netsurf-browser.org/netsurf-website.git/commit/731fe1475abf4b4...
...tree http://git.netsurf-browser.org/netsurf-website.git/tree/731fe1475abf4b4b1...
The branch, master has been updated
via 731fe1475abf4b4b189eb06eaffa57943eebaeae (commit)
via a735aa84a21dd07778f47b622c3bb05aad69053b (commit)
via 62c95721941f31a89e81819e3a64815463f1290c (commit)
from 2c178e0199f24a803cf5eb07aeb73541b88c5c67 (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-website.git/commit/?id=731fe1475ab...
commit 731fe1475abf4b4b189eb06eaffa57943eebaeae
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
Tiny change to mailing list prose.
diff --git a/contact/index.html b/contact/index.html
index 1033c95..50a100d 100644
--- a/contact/index.html
+++ b/contact/index.html
@@ -79,7 +79,7 @@
<dt><a href="http://www.netsurf-browser.org/lists/netsurf-dev">NetSurf Development</a></dt>
<dd>This mailing list is intended for developer and contributor discussion.</dd>
<dt><a href="http://www.netsurf-browser.org/lists/netsurf-commits">NetSurf Commits</a></dt>
-<dd>This mailing list is read only, but listed here for completeness. It reports checkin details. (If you want to comment on a post here, send your comment to the NetSurf Dev. list.)</dd>
+<dd>This mailing list is read only, but listed here for completeness. It reports checkin details. (If you want to comment on a post here, send your comment to the NetSurf Development list.)</dd>
</dl>
<h2 id="IRCChannel">IRC channel</h2>
commitdiff http://git.netsurf-browser.org/netsurf-website.git/commit/?id=a735aa84a21...
commit a735aa84a21dd07778f47b622c3bb05aad69053b
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
IRC channel moved to Libera.Chat.
diff --git a/contact/index.html b/contact/index.html
index 99c292a..1033c95 100644
--- a/contact/index.html
+++ b/contact/index.html
@@ -83,7 +83,7 @@
</dl>
<h2 id="IRCChannel">IRC channel</h2>
-<p>The <a href="irc://irc.freenode.net/netsurf">#netsurf</a> IRC channel on the <a href="http://freenode.net/">Freenode</a> network is used for discussion of NetSurf development. Developers are usually around on the IRC channel between 1000 and 0100 UTC.</p>
+<p>The <a href="ircs://irc.libera.chat:6697/netsurf">#netsurf</a> IRC channel on the <a href="https://libera.chat/">Libera.Chat</a> network is used for discussion of NetSurf development. Developers are usually around on the IRC channel between 1000 and 0100 UTC.</p>
<p>If you're new to IRC, don't ask if you can ask a question – just ask the question! Also, give people a chance to see your question and reply. Developers don't have their eyes glued to their IRC terminal but they'll have it open in the background while they do other things. If you disconnect two minutes after asking something noone may see until after you've gone.</p>
commitdiff http://git.netsurf-browser.org/netsurf-website.git/commit/?id=62c95721941...
commit 62c95721941f31a89e81819e3a64815463f1290c
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
About: Fix broken image.
diff --git a/about/index.html b/about/index.html
index c8a7055..2675b33 100644
--- a/about/index.html
+++ b/about/index.html
@@ -164,7 +164,7 @@
<p>The RISC OS front end is suitable for RISC OS 4 and greater. The AmigaOS front end is suitable for AmigaOS 4. The BeOS front end works on BeOS, Zeta and Haiku.</p>
-<div class="frontscreen"><p class="frontscreen"><a href="screenshots/images/gtk-bbc.png"><img src="screenshots/images/gtkthumb-bbc.png" alt="GTK NetSurf screenshot."></a> <span>NetSurf's GTK front end showing the <em>BBC Homepage</em>.</span></p></div>
+<div class="frontscreen"><p class="frontscreen"><a href="screenshots/images/gtk2-bbc.png"><img src="screenshots/images/gtk2thumb-bbc.png" alt="GTK NetSurf screenshot."></a> <span>NetSurf's GTK front end showing the <em>BBC Homepage</em>.</span></p></div>
<p>NetSurf's GTK front end works on Unix-like systems, including Linux, FreeBSD, NetBSD, Solaris and others. There are no complete native Windows ports of NetSurf at the moment, however the GTK front end can be built for those platforms. The GTK front end is available from the package repositories of many Linux distributions including Debian and Ubuntu.</p>
-----------------------------------------------------------------------
Summary of changes:
about/index.html | 2 +-
contact/index.html | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/about/index.html b/about/index.html
index c8a7055..2675b33 100644
--- a/about/index.html
+++ b/about/index.html
@@ -164,7 +164,7 @@
<p>The RISC OS front end is suitable for RISC OS 4 and greater. The AmigaOS front end is suitable for AmigaOS 4. The BeOS front end works on BeOS, Zeta and Haiku.</p>
-<div class="frontscreen"><p class="frontscreen"><a href="screenshots/images/gtk-bbc.png"><img src="screenshots/images/gtkthumb-bbc.png" alt="GTK NetSurf screenshot."></a> <span>NetSurf's GTK front end showing the <em>BBC Homepage</em>.</span></p></div>
+<div class="frontscreen"><p class="frontscreen"><a href="screenshots/images/gtk2-bbc.png"><img src="screenshots/images/gtk2thumb-bbc.png" alt="GTK NetSurf screenshot."></a> <span>NetSurf's GTK front end showing the <em>BBC Homepage</em>.</span></p></div>
<p>NetSurf's GTK front end works on Unix-like systems, including Linux, FreeBSD, NetBSD, Solaris and others. There are no complete native Windows ports of NetSurf at the moment, however the GTK front end can be built for those platforms. The GTK front end is available from the package repositories of many Linux distributions including Debian and Ubuntu.</p>
diff --git a/contact/index.html b/contact/index.html
index 99c292a..50a100d 100644
--- a/contact/index.html
+++ b/contact/index.html
@@ -79,11 +79,11 @@
<dt><a href="http://www.netsurf-browser.org/lists/netsurf-dev">NetSurf Development</a></dt>
<dd>This mailing list is intended for developer and contributor discussion.</dd>
<dt><a href="http://www.netsurf-browser.org/lists/netsurf-commits">NetSurf Commits</a></dt>
-<dd>This mailing list is read only, but listed here for completeness. It reports checkin details. (If you want to comment on a post here, send your comment to the NetSurf Dev. list.)</dd>
+<dd>This mailing list is read only, but listed here for completeness. It reports checkin details. (If you want to comment on a post here, send your comment to the NetSurf Development list.)</dd>
</dl>
<h2 id="IRCChannel">IRC channel</h2>
-<p>The <a href="irc://irc.freenode.net/netsurf">#netsurf</a> IRC channel on the <a href="http://freenode.net/">Freenode</a> network is used for discussion of NetSurf development. Developers are usually around on the IRC channel between 1000 and 0100 UTC.</p>
+<p>The <a href="ircs://irc.libera.chat:6697/netsurf">#netsurf</a> IRC channel on the <a href="https://libera.chat/">Libera.Chat</a> network is used for discussion of NetSurf development. Developers are usually around on the IRC channel between 1000 and 0100 UTC.</p>
<p>If you're new to IRC, don't ask if you can ask a question – just ask the question! Also, give people a chance to see your question and reply. Developers don't have their eyes glued to their IRC terminal but they'll have it open in the background while they do other things. If you disconnect two minutes after asking something noone may see until after you've gone.</p>
--
NetSurf website source for *.netsurf-browser.org
2 years
libcss: branch master updated. release/0.9.1-20-g57fa360
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/57fa3608e13accc24a45e5...
...commit http://git.netsurf-browser.org/libcss.git/commit/57fa3608e13accc24a45e5d7...
...tree http://git.netsurf-browser.org/libcss.git/tree/57fa3608e13accc24a45e5d780...
The branch, master has been updated
discards 7a9dc81e71de235646af716f4482dc713520109f (commit)
discards 9e46e0f245f242c6f1b707016670caca2b57d428 (commit)
discards d4fef3c6ff5339888c7519fe7a2071c8e28da8f5 (commit)
via 57fa3608e13accc24a45e5d7801a381212c2ff22 (commit)
via f752713d07424217170c6fbf85789bd58d92f924 (commit)
via a0a52eb724f62d0df68c104108526e84148710bb (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (7a9dc81e71de235646af716f4482dc713520109f)
\
N -- N -- N (57fa3608e13accc24a45e5d7801a381212c2ff22)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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 -----------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes:
--
Cascading Style Sheets library
2 years
libcss: branch tlsa/calc updated. release/0.9.1-28-g7805a9e
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/7805a9ee0c89cca40097ae...
...commit http://git.netsurf-browser.org/libcss.git/commit/7805a9ee0c89cca40097aefb...
...tree http://git.netsurf-browser.org/libcss.git/tree/7805a9ee0c89cca40097aefb5c...
The branch, tlsa/calc has been updated
discards 61689e1da66f115c5ed0bf3aba9210737f159b46 (commit)
discards b33fe829bd12cbb24e9ba6413508f54abd8f459f (commit)
discards 568a2dc1abfefd56ac9e65632ad1d17b2452f990 (commit)
discards 6e396a137102aadd1253b9eb1228d6419e6f3962 (commit)
discards 6447ae17840b3ca16588d1d4ac8edf17a086ba6e (commit)
discards 837b95918e19f4246f4810cbc9e6278b1e7c689c (commit)
discards 914e88c58b54a7d566fb9b0ec64fc2c0105da29f (commit)
discards f9add9b2e0209eb564b33c57008e4b3ab820e660 (commit)
discards 7a9dc81e71de235646af716f4482dc713520109f (commit)
discards 9e46e0f245f242c6f1b707016670caca2b57d428 (commit)
discards d4fef3c6ff5339888c7519fe7a2071c8e28da8f5 (commit)
via 7805a9ee0c89cca40097aefb5cbc8ec98a7c927a (commit)
via 684726f5189e29f9d610766365a17f754368b80b (commit)
via 9a541ac916223694238bafd262b067a0a59a41e7 (commit)
via 817b43a06afc93e459ff09afdb0e007f76ba6cbe (commit)
via 05a064fc07a4cea3dd8307c10b8a2aad3a670211 (commit)
via ce2155ea14a93327bd320d90f434da2fdb1ab66d (commit)
via 307b71ec3001bcd8cacc875ddd09138744eb7ee1 (commit)
via e7a7b547c370d0fa51e8e55282aceb2fe9f19039 (commit)
via 57fa3608e13accc24a45e5d7801a381212c2ff22 (commit)
via f752713d07424217170c6fbf85789bd58d92f924 (commit)
via a0a52eb724f62d0df68c104108526e84148710bb (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (61689e1da66f115c5ed0bf3aba9210737f159b46)
\
N -- N -- N (7805a9ee0c89cca40097aefb5cbc8ec98a7c927a)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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=7805a9ee0c89cca40097...
commit 7805a9ee0c89cca40097aefb5cbc8ec98a7c927a
Author: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
parse: Tests and fixes for calc() parser.
Co-authored-by: Michael Drake <michael.drake(a)netsurf-browser.org>
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index be163b1..70c8b01 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -24,12 +24,13 @@ enum flag {
};
enum calc_opcodes {
- CALC_PUSH_VALUE = 'V',
- CALC_ADD = '+',
- CALC_SUBTRACT = '-',
- CALC_MULTIPLY = '*',
- CALC_DIVIDE = '/',
- CALC_FINISH = '=',
+ CALC_PUSH_NUMBER = 'N',
+ CALC_PUSH_VALUE = 'V',
+ CALC_ADD = '+',
+ CALC_SUBTRACT = '-',
+ CALC_MULTIPLY = '*',
+ CALC_DIVIDE = '/',
+ CALC_FINISH = '=',
};
typedef enum unit {
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 7f9d9d2..fe5ee6b 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1365,6 +1365,31 @@ css__parse_calc_sum(css_language *c,
css_style *result);
static css_error
+css__parse_calc_number(
+ const parserutils_vector *vector, int *ctx,
+ css_style *result)
+{
+ const css_token *token;
+ css_fixed num;
+ size_t consumed;
+
+ /* Consume the number token */
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token == NULL || token->type != CSS_TOKEN_NUMBER) {
+ return CSS_INVALID;
+ }
+
+ num = css__number_from_string((const uint8_t *)lwc_string_data(token->idata),
+ lwc_string_length(token->idata), false, &consumed);
+
+ if (consumed != lwc_string_length(token->idata)) {
+ return CSS_INVALID;
+ }
+
+ return css__stylesheet_style_vappend(result, 2, (css_code_t) CALC_PUSH_NUMBER, (css_code_t)num);
+}
+
+static css_error
css__parse_calc_value(css_language *c,
const parserutils_vector *vector, int *ctx,
css_style *result)
@@ -1377,6 +1402,7 @@ css__parse_calc_value(css_language *c,
token = parserutils_vector_peek(vector, *ctx);
if (tokenIsChar(token, '(')) {
parserutils_vector_iterate(vector, ctx);
+ consumeWhitespace(vector, ctx);
error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
@@ -1389,7 +1415,12 @@ css__parse_calc_value(css_language *c,
/* Consume the close-paren to complete this value */
parserutils_vector_iterate(vector, ctx);
} else switch (token->type) {
- case CSS_TOKEN_NUMBER: /* Fall through */
+ case CSS_TOKEN_NUMBER:
+ error = css__parse_calc_number(vector, ctx, result);
+ if (error != CSS_OK) {
+ return error;
+ }
+ break;
case CSS_TOKEN_DIMENSION: /* Fall through */
case CSS_TOKEN_PERCENTAGE:
{
@@ -1412,11 +1443,7 @@ css__parse_calc_value(css_language *c,
break;
}
- token = parserutils_vector_peek(vector, *ctx);
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
+ consumeWhitespace(vector, ctx);
return error;
}
@@ -1462,14 +1489,15 @@ css__parse_calc_product(css_language *c,
}
/* Consume that * or / now */
parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
+ consumeWhitespace(vector, ctx);
+
+ if (multiplication) {
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result);
+ } else {
+ error = css__parse_calc_number(vector, ctx, result);
}
- /* parse another value */
- error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK)
break;
@@ -1516,12 +1544,7 @@ css__parse_calc_sum(css_language *c,
}
/* Consume that + or - now */
parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
-
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
+ consumeWhitespace(vector, ctx);
/* parse another product */
error = css__parse_calc_product(c, vector, ctx, result);
@@ -1547,17 +1570,14 @@ css_error css__parse_calc(css_language *c,
css_error error = CSS_OK;
css_style *calc_style = NULL;
+ consumeWhitespace(vector, ctx);
+
token = parserutils_vector_peek(vector, *ctx);
if (token == NULL) {
*ctx = orig_ctx;
return CSS_INVALID;
}
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
-
error = css__stylesheet_style_create(c->sheet, &calc_style);
if (error != CSS_OK)
goto cleanup;
@@ -1574,11 +1594,8 @@ css_error css__parse_calc(css_language *c,
if (error != CSS_OK)
goto cleanup;
+ consumeWhitespace(vector, ctx);
token = parserutils_vector_peek(vector, *ctx);
- while (token->type == CSS_TOKEN_S) {
- parserutils_vector_iterate(vector, ctx);
- token = parserutils_vector_peek(vector, *ctx);
- }
if (!tokenIsChar(token, ')')) {
/* If we don't get a close-paren, give up now */
error = CSS_INVALID;
diff --git a/test/data/parse2/calc.dat b/test/data/parse2/calc.dat
index 95abf6c..e9d176d 100644
--- a/test/data/parse2/calc.dat
+++ b/test/data/parse2/calc.dat
@@ -4,4 +4,154 @@
#expected
| *
| height: /* -> 0px */ calc(50vh 10px + =)
-#reset
\ No newline at end of file
+#reset
+
+#data
+* { line-height: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| line-height: /* -> 0any */ calc(50vh 10px + =)
+#reset
+
+#data
+* { line-height: calc( / 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { line-height: calc( + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { line-height: calc(2 / 2px)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(50vh 10px + =)
+#reset
+
+#data
+* { z-index: calc(2 * 3)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(2 3 * =)
+#reset
+
+#data
+* { z-index: calc(50vh + 10px / 9)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(50vh 10px 9 / + =)
+#reset
+
+#data
+* { z-index: calc(1 + 2 + 3 + 4)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + 3 + 4 + =)
+#reset
+
+#data
+* { z-index: calc(1 + 2 * 3 + 4)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 3 * + 4 + =)
+#reset
+
+#data
+* { z-index: calc((1 + 2) * (3 + 4))}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + 3 4 + * =)
+#reset
+
+#data
+* { z-index: calc(1 + 2}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc (1 + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(1)}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 =)
+#reset
+
+#data
+* { z-index: calc()}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc((1 + 2)}
+#errors
+#expected
+| *
+#reset
+
+#data
+* { z-index: calc(((1 + 2)))}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + =)
+#reset
+
+#data
+* { z-index: calc( ( ( 1 + 2 ) ) )}
+#errors
+#expected
+| *
+| z-index: /* -> 0number */ calc(1 2 + =)
+#reset
+
+#data
+* { z-index: calc( ( 3 / ( 1 + 2 ) ) )}
+#errors
+#expected
+| *
+#reset
diff --git a/test/dump.h b/test/dump.h
index 852de84..f320e67 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -825,6 +825,13 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
dump_unit(num, unit, ptr);
*ptr += sprintf(*ptr, " ");
break;
+ case CALC_PUSH_NUMBER: {
+ css_fixed num = *((css_fixed *)bytecode);
+ ADVANCE(sizeof(num));
+ dump_number(num, ptr);
+ *ptr += sprintf(*ptr, " ");
+ break;
+ }
}
default:
*ptr += sprintf(*ptr, "??%d ", calc_opcode);
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=684726f5189e29f9d610...
commit 684726f5189e29f9d610766365a17f754368b80b
Author: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
parse: calc() test and fixup.
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 041050f..be163b1 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -23,6 +23,14 @@ enum flag {
FLAG_INHERIT = (1<<1)
};
+enum calc_opcodes {
+ CALC_PUSH_VALUE = 'V',
+ CALC_ADD = '+',
+ CALC_SUBTRACT = '-',
+ CALC_MULTIPLY = '*',
+ CALC_DIVIDE = '/',
+ CALC_FINISH = '=',
+};
typedef enum unit {
UNIT_LENGTH = (1u << 8),
@@ -107,6 +115,12 @@ static inline bool isInherit(css_code_t OPV)
return getFlags(OPV) & 0x2;
}
+static inline bool isCalc(css_code_t OPV)
+{
+ /* Note, this relies on all _CALC values being the same ultimately */
+ return getValue(OPV) == 0x7f;
+}
+
#endif
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 1cdb27f..08f3f12 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -310,7 +310,7 @@ void output_calc(FILE *outputf, struct keyval *parseid, struct keyval_list *kvli
kind = ckv->key;
fprintf(outputf,
- "if ((token->type == CSS_TOKEN_IDENT) && "
+ "if ((token->type == CSS_TOKEN_FUNCTION) && "
"(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
" {\n"
"\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s), %s);\n"
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index cce9717..7f9d9d2 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1373,8 +1373,10 @@ css__parse_calc_value(css_language *c,
int orig_ctx = *ctx;
const css_token *token;
- token = parserutils_vector_iterate(vector, ctx);
+ /* On entry, we are already pointing at the value to parse, so peek it */
+ token = parserutils_vector_peek(vector, *ctx);
if (tokenIsChar(token, '(')) {
+ parserutils_vector_iterate(vector, ctx);
error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
@@ -1384,7 +1386,8 @@ css__parse_calc_value(css_language *c,
if (!tokenIsChar(token, ')')) {
return CSS_INVALID;
}
-
+ /* Consume the close-paren to complete this value */
+ parserutils_vector_iterate(vector, ctx);
} else switch (token->type) {
case CSS_TOKEN_NUMBER: /* Fall through */
case CSS_TOKEN_DIMENSION: /* Fall through */
@@ -1400,7 +1403,7 @@ css__parse_calc_value(css_language *c,
return error;
}
- error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'V', length, unit);
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) CALC_PUSH_VALUE, length, unit);
}
break;
@@ -1409,6 +1412,11 @@ css__parse_calc_value(css_language *c,
break;
}
+ token = parserutils_vector_peek(vector, *ctx);
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
return error;
}
@@ -1439,7 +1447,10 @@ css__parse_calc_product(css_language *c,
if (token == NULL) {
error = CSS_INVALID;
break;
- } else if (tokenIsChar(token, ')'))
+ } else if (
+ tokenIsChar(token, ')') ||
+ tokenIsChar(token, '+') ||
+ tokenIsChar(token, '-'))
break;
else if (tokenIsChar(token, '*'))
multiplication = true;
@@ -1450,15 +1461,21 @@ css__parse_calc_product(css_language *c,
break;
}
/* Consume that * or / now */
- token = parserutils_vector_iterate(vector, ctx);
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
/* parse another value */
error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK)
break;
/* emit the multiplication/division operator */
- error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
+ error = css__stylesheet_style_append(result,
+ (css_code_t) (multiplication ? CALC_MULTIPLY : CALC_DIVIDE));
} while (1);
/* We've fallen off, either we had an error or we're left with ')' */
return error;
@@ -1498,7 +1515,13 @@ css__parse_calc_sum(css_language *c,
break;
}
/* Consume that + or - now */
- token = parserutils_vector_iterate(vector, ctx);
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
/* parse another product */
error = css__parse_calc_product(c, vector, ctx, result);
@@ -1506,7 +1529,7 @@ css__parse_calc_sum(css_language *c,
break;
/* emit the addition/subtraction operator */
- error = css__stylesheet_style_append(result, (css_code_t) (addition ? '+' : '-'));
+ error = css__stylesheet_style_append(result, (css_code_t) (addition ? CALC_ADD : CALC_SUBTRACT));
} while (1);
/* We've fallen off, either we had an error or we're left with ')' */
return error;
@@ -1524,16 +1547,15 @@ css_error css__parse_calc(css_language *c,
css_error error = CSS_OK;
css_style *calc_style = NULL;
- token = parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
if (token == NULL) {
*ctx = orig_ctx;
return CSS_INVALID;
}
- if (!tokenIsChar(token, '(')) {
- /* If we don't get an open-paren, give up now */
- *ctx = orig_ctx;
- return CSS_INVALID;
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
}
error = css__stylesheet_style_create(c->sheet, &calc_style);
@@ -1545,27 +1567,33 @@ css_error css__parse_calc(css_language *c,
goto cleanup;
error = css__stylesheet_style_append(calc_style, (css_code_t) unit);
+ if (error != CSS_OK)
+ goto cleanup;
error = css__parse_calc_sum(c, vector, ctx, calc_style);
if (error != CSS_OK)
goto cleanup;
- token = parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ while (token->type == CSS_TOKEN_S) {
+ parserutils_vector_iterate(vector, ctx);
+ token = parserutils_vector_peek(vector, *ctx);
+ }
if (!tokenIsChar(token, ')')) {
/* If we don't get a close-paren, give up now */
error = CSS_INVALID;
goto cleanup;
}
+ /* Swallow that close paren */
+ parserutils_vector_iterate(vector, ctx);
+
/* Append the indicator that the calc is finished */
- error = css__stylesheet_style_append(calc_style, (css_code_t) '=');
+ error = css__stylesheet_style_append(calc_style, (css_code_t) CALC_FINISH);
if (error != CSS_OK)
goto cleanup;
- /* TODO: Once we're OK to do so, merge the style */
- (void)result;
- /* error = css__stylesheet_style_merge_style(result, calc_style); */
-
+ error = css__stylesheet_merge_style(result, calc_style);
cleanup:
css__stylesheet_style_destroy(calc_style);
if (error != CSS_OK) {
diff --git a/test/data/parse2/INDEX b/test/data/parse2/INDEX
index 331cf5c..bb2a79b 100644
--- a/test/data/parse2/INDEX
+++ b/test/data/parse2/INDEX
@@ -23,3 +23,4 @@ multicol.dat Multi-column layout property tests
flexbox.dat Flexbox properties and shorthands tests
units.dat Length unit tests
dodgy-media-block.dat Media block with incomplete ruleset
+calc.dat calc() tests
diff --git a/test/data/parse2/calc.dat b/test/data/parse2/calc.dat
new file mode 100644
index 0000000..95abf6c
--- /dev/null
+++ b/test/data/parse2/calc.dat
@@ -0,0 +1,7 @@
+#data
+* { height: calc(50vh + 10px)}
+#errors
+#expected
+| *
+| height: /* -> 0px */ calc(50vh 10px + =)
+#reset
\ No newline at end of file
diff --git a/test/dump.h b/test/dump.h
index 79819e0..852de84 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -638,6 +638,12 @@ static void dump_unit(css_fixed val, uint32_t unit, char **ptr)
case UNIT_KHZ:
*ptr += sprintf(*ptr, "kHz");
break;
+ case UNIT_CALC_ANY:
+ *ptr += sprintf(*ptr, "any");
+ break;
+ case UNIT_CALC_NUMBER:
+ *ptr += sprintf(*ptr, "number");
+ break;
}
}
@@ -788,6 +794,45 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
if (isInherit(opv)) {
*ptr += sprintf(*ptr, "inherit");
+ } else if (isCalc(opv)) {
+ /* First entry is a unit */
+ uint32_t unit = *((uint32_t *)bytecode);
+ ADVANCE(sizeof(unit));
+ *ptr += sprintf(*ptr, "/* -> ");
+ dump_unit(0, unit, ptr);
+ *ptr += sprintf(*ptr, " */ calc(");
+ css_code_t calc_opcode;
+ while ((calc_opcode = *((css_code_t *)bytecode)) != CALC_FINISH) {
+ ADVANCE(sizeof(calc_opcode));
+ switch (calc_opcode) {
+ case CALC_ADD:
+ *ptr += sprintf(*ptr, "+ ");
+ break;
+ case CALC_SUBTRACT:
+ *ptr += sprintf(*ptr, "- ");
+ break;
+ case CALC_MULTIPLY:
+ *ptr += sprintf(*ptr, "* ");
+ break;
+ case CALC_DIVIDE:
+ *ptr += sprintf(*ptr, "/ ");
+ break;
+ case CALC_PUSH_VALUE: {
+ css_fixed num = *((css_fixed *)bytecode);
+ ADVANCE(sizeof(num));
+ uint32_t unit = *((uint32_t *)bytecode);
+ ADVANCE(sizeof(unit));
+ dump_unit(num, unit, ptr);
+ *ptr += sprintf(*ptr, " ");
+ break;
+ }
+ default:
+ *ptr += sprintf(*ptr, "??%d ", calc_opcode);
+ break;
+ }
+ }
+ ADVANCE(sizeof(calc_opcode));
+ *ptr += sprintf(*ptr, "=)");
} else {
value = getValue(opv);
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=9a541ac916223694238b...
commit 9a541ac916223694238bafd262b067a0a59a41e7
Author: Michael Drake <Michael Drake tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
parse: Update parser generator to support calc() details.
Co-authored-by: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 7f5ea9d..041050f 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -65,6 +65,10 @@ typedef enum unit {
UNIT_DPI = (1 << 13) + 0,
UNIT_DPCM = (1 << 13) + 1,
UNIT_DPPX = (1 << 13) + 2,
+
+ /* These are special only to the CALC bytecodes */
+ UNIT_CALC_ANY = (1 << 20),
+ UNIT_CALC_NUMBER = (1 << 20) + 1,
} unit;
typedef uint32_t colour;
diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h
index 01ea25a..607c87b 100644
--- a/src/bytecode/opcodes.h
+++ b/src/bytecode/opcodes.h
@@ -119,6 +119,7 @@ enum op_border_style {
};
enum op_border_width {
+ BORDER_WIDTH_CALC = 0x007f,
BORDER_WIDTH_SET = 0x0080,
BORDER_WIDTH_THIN = 0x0000,
BORDER_WIDTH_MEDIUM = 0x0001,
@@ -126,6 +127,7 @@ enum op_border_width {
};
enum op_bottom {
+ BOTTOM_CALC = 0x007f,
BOTTOM_SET = 0x0080,
BOTTOM_AUTO = 0x0000
};
@@ -198,6 +200,7 @@ enum op_color {
enum op_column_count {
COLUMN_COUNT_AUTO = 0x0000,
+ COLUMN_COUNT_CALC = 0x007f,
COLUMN_COUNT_SET = 0x0080
};
@@ -208,6 +211,7 @@ enum op_column_fill {
enum op_column_gap {
COLUMN_GAP_NORMAL = 0x0000,
+ COLUMN_GAP_CALC = 0x007f,
COLUMN_GAP_SET = 0x0080
};
@@ -231,6 +235,7 @@ enum op_column_rule_style {
};
enum op_column_rule_width {
+ COLUMN_RULE_WIDTH_CALC = BORDER_WIDTH_CALC,
COLUMN_RULE_WIDTH_SET = BORDER_WIDTH_SET,
COLUMN_RULE_WIDTH_THIN = BORDER_WIDTH_THIN,
COLUMN_RULE_WIDTH_MEDIUM = BORDER_WIDTH_MEDIUM,
@@ -244,6 +249,7 @@ enum op_column_span {
enum op_column_width {
COLUMN_WIDTH_AUTO = 0x0000,
+ COLUMN_WIDTH_CALC = 0x007f,
COLUMN_WIDTH_SET = 0x0080
};
@@ -352,6 +358,7 @@ enum op_empty_cells {
enum op_flex_basis {
FLEX_BASIS_AUTO = 0x0000,
FLEX_BASIS_CONTENT = 0x0001,
+ FLEX_BASIS_CALC = 0x007f,
FLEX_BASIS_SET = 0x0080
};
@@ -363,10 +370,12 @@ enum op_flex_direction {
};
enum op_flex_grow {
+ FLEX_GROW_CALC = 0x007f,
FLEX_GROW_SET = 0x0080
};
enum op_flex_shrink {
+ FLEX_SHRINK_CALC = 0x007f,
FLEX_SHRINK_SET = 0x0080
};
@@ -396,6 +405,7 @@ enum op_font_family {
};
enum op_font_size {
+ FONT_SIZE_CALC = 0x007f,
FONT_SIZE_DIMENSION = 0x0080,
FONT_SIZE_XX_SMALL = 0x0000,
@@ -437,6 +447,7 @@ enum op_font_weight {
};
enum op_height {
+ HEIGHT_CALC = 0x007f,
HEIGHT_SET = 0x0080,
HEIGHT_AUTO = 0x0000
};
@@ -451,16 +462,19 @@ enum op_justify_content {
};
enum op_left {
+ LEFT_CALC = BOTTOM_CALC,
LEFT_SET = BOTTOM_SET,
LEFT_AUTO = BOTTOM_AUTO
};
enum op_letter_spacing {
+ LETTER_SPACING_CALC = 0x007f,
LETTER_SPACING_SET = 0x0080,
LETTER_SPACING_NORMAL = 0x0000
};
enum op_line_height {
+ LINE_HEIGHT_CALC = 0x007f,
LINE_HEIGHT_NUMBER = 0x0080,
LINE_HEIGHT_DIMENSION = 0x0081,
LINE_HEIGHT_NORMAL = 0x0000
@@ -532,26 +546,31 @@ enum op_list_style_type {
};
enum op_margin {
+ MARGIN_CALC = 0x007f,
MARGIN_SET = 0x0080,
MARGIN_AUTO = 0x0000
};
enum op_max_height {
+ MAX_HEIGHT_CALC = 0x007f,
MAX_HEIGHT_SET = 0x0080,
MAX_HEIGHT_NONE = 0x0000
};
enum op_max_width {
+ MAX_WIDTH_CALC = 0x007f,
MAX_WIDTH_SET = 0x0080,
MAX_WIDTH_NONE = 0x0000
};
enum op_min_height {
+ MIN_HEIGHT_CALC = 0x007f,
MIN_HEIGHT_SET = 0x0080,
MIN_HEIGHT_AUTO = 0x0000
};
enum op_min_width {
+ MIN_WIDTH_CALC = 0x007f,
MIN_WIDTH_SET = 0x0080,
MIN_WIDTH_AUTO = 0x0000
};
@@ -561,10 +580,12 @@ enum op_opacity {
};
enum op_order {
+ ORDER_CALC = 0x007f,
ORDER_SET = 0x0080
};
enum op_orphans {
+ ORPHANS_CALC = 0x007f,
ORPHANS_SET = 0x0080
};
@@ -603,6 +624,7 @@ enum op_overflow {
};
enum op_padding {
+ PADDING_CALC = 0x007f,
PADDING_SET = 0x0080
};
@@ -628,18 +650,22 @@ enum op_page_break_inside {
};
enum op_pause_after {
+ PAUSE_AFTER_CALC = 0x007f,
PAUSE_AFTER_SET = 0x0080
};
enum op_pause_before {
+ PAUSE_BEFORE_CALC = 0x007f,
PAUSE_BEFORE_SET = 0x0080
};
enum op_pitch_range {
+ PITCH_RANGE_CALC = 0x007f,
PITCH_RANGE_SET = 0x0080
};
enum op_pitch {
+ PITCH_CALC = 0x007f,
PITCH_FREQUENCY = 0x0080,
PITCH_X_LOW = 0x0000,
@@ -673,6 +699,7 @@ enum op_quotes {
};
enum op_richness {
+ RICHNESS_CALC = 0x007f,
RICHNESS_SET = 0x0080
};
@@ -703,6 +730,7 @@ enum op_speak {
};
enum op_speech_rate {
+ SPEECH_RATE_CALC = 0x007f,
SPEECH_RATE_SET = 0x0080,
SPEECH_RATE_X_SLOW = 0x0000,
@@ -715,6 +743,7 @@ enum op_speech_rate {
};
enum op_stress {
+ STRESS_CALC = 0x007f,
STRESS_SET = 0x0080
};
@@ -743,6 +772,7 @@ enum op_text_decoration {
};
enum op_text_indent {
+ TEXT_INDENT_CALC = 0x007f,
TEXT_INDENT_SET = 0x0080
};
@@ -754,6 +784,7 @@ enum op_text_transform {
};
enum op_top {
+ TOP_CALC = BOTTOM_CALC,
TOP_SET = BOTTOM_SET,
TOP_AUTO = BOTTOM_AUTO
};
@@ -765,6 +796,7 @@ enum op_unicode_bidi {
};
enum op_vertical_align {
+ VERTICAL_ALIGN_CALC = 0x007f,
VERTICAL_ALIGN_SET = 0x0080,
VERTICAL_ALIGN_BASELINE = 0x0000,
@@ -795,6 +827,7 @@ enum op_voice_family {
};
enum op_volume {
+ VOLUME_CALC = 0x007f,
VOLUME_NUMBER = 0x0080,
VOLUME_DIMENSION = 0x0081,
@@ -815,16 +848,19 @@ enum op_white_space {
};
enum op_widows {
+ WIDOWS_CALC = 0x007f,
WIDOWS_SET = 0x0080
};
enum op_width {
+ WIDTH_CALC = 0x007f,
WIDTH_SET = 0x0080,
WIDTH_AUTO = 0x0000
};
enum op_word_spacing {
+ WORD_SPACING_CALC = 0x007f,
WORD_SPACING_SET = 0x0080,
WORD_SPACING_NORMAL = 0x0000
@@ -837,6 +873,7 @@ enum op_writing_mode {
};
enum op_z_index {
+ Z_INDEX_CALC = 0x007f,
Z_INDEX_SET = 0x0080,
Z_INDEX_AUTO = 0x0000
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 3d88cef..1cdb27f 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -19,6 +19,12 @@
* list_style_position:CSS_PROP_LIST_STYLE_POSITION IDENT:( INHERIT: INSIDE:0,LIST_STYLE_POSITION_INSIDE OUTSIDE:0,LIST_STYLE_POSITION_OUTSIDE IDENT:)
*/
+typedef enum {
+ CALC_ANY,
+ CALC_NUMBER,
+ CALC_UNIT,
+} calc_kind;
+
struct keyval {
char *key;
char *val;
@@ -291,21 +297,34 @@ void output_color(FILE *outputf, struct keyval *parseid, struct keyval_list *kvl
parseid->val);
}
-void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
+void output_calc(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
{
struct keyval *ckv = kvlist->item[0];
- int ident_count;
+ const char *kind;
+
+ if (strcmp(ckv->key, "NUMBER") == 0)
+ kind = "UNIT_CALC_NUMBER";
+ else if (strcmp(ckv->key, "ANY") == 0)
+ kind = "UNIT_CALC_ANY";
+ else
+ kind = ckv->key;
fprintf(outputf,
"if ((token->type == CSS_TOKEN_IDENT) && "
"(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
" {\n"
- "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s /* _CALC */), %s);\n"
+ "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s), %s);\n"
"\t} else ",
parseid->val,
ckv->val,
- ckv->key
+ kind
);
+}
+
+void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist)
+{
+ struct keyval *ckv = kvlist->item[0];
+ int ident_count;
fprintf(outputf,
"{\n"
@@ -501,6 +520,7 @@ int main(int argc, char **argv)
struct keyval_list WRAP;
struct keyval_list NUMBER;
struct keyval_list COLOR;
+ struct keyval_list CALC;
if (argc < 2) {
@@ -533,6 +553,7 @@ int main(int argc, char **argv)
COLOR.count = 0;
LENGTH_UNIT.count = 0;
IDENT_LIST.count = 0;
+ CALC.count = 0;
curlist = &base;
@@ -548,7 +569,7 @@ int main(int argc, char **argv)
if (strcmp(rkv->key, "WRAP") == 0) {
WRAP.item[WRAP.count++] = rkv;
only_ident = false;
- } else if (strcmp(rkv->key, "NUMBER") == 0) {
+ } else if (curlist == &base && strcmp(rkv->key, "NUMBER") == 0) {
if (rkv->val[0] == '(') {
curlist = &NUMBER;
} else if (rkv->val[0] == ')') {
@@ -579,6 +600,14 @@ int main(int argc, char **argv)
}
only_ident = false;
do_token_check = false;
+ } else if (strcmp(rkv->key, "CALC") == 0) {
+ if (rkv->val[0] == '(') {
+ curlist = &CALC;
+ } else if (rkv->val[0] == ')') {
+ curlist = &base;
+ }
+ only_ident = false;
+ do_token_check = false;
} else if (strcmp(rkv->key, "COLOR") == 0) {
COLOR.item[COLOR.count++] = rkv;
do_token_check = false;
@@ -602,7 +631,7 @@ int main(int argc, char **argv)
/* header */
-output_header(outputf, descriptor, base.item[0], is_generic);
+ output_header(outputf, descriptor, base.item[0], is_generic);
if (WRAP.count > 0) {
output_wrap(outputf, base.item[0], &WRAP);
@@ -616,6 +645,10 @@ output_header(outputf, descriptor, base.item[0], is_generic);
if (URI.count > 0)
output_uri(outputf, base.item[0], &URI);
+ if (CALC.count > 0) {
+ output_calc(outputf, base.item[0], &CALC);
+ }
+
if (NUMBER.count > 0)
output_number(outputf, base.item[0], &NUMBER);
diff --git a/src/parse/properties/properties.gen b/src/parse/properties/properties.gen
index e729285..9830ce4 100644
--- a/src/parse/properties/properties.gen
+++ b/src/parse/properties/properties.gen
@@ -6,6 +6,13 @@
#property:CSS_PROP_ENUM IDENT:( INHERIT: IDENT:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY ALLOW: DISALLOW: RANGE:<0 LENGTH_UNIT:)
#property:CSS_PROP_ENUM WRAP:
+# When a property takes a NUMBER and/or LENGTH_UNIT you may add calc() support:
+# In the below, PROPERTY_FOO_CALC is the opcode enum for the set-but-calculated value bytecode.
+# e.g. HEIGHT_SET (for a LENGTH_UNIT) would be HEIGHT_CALC here.
+# CALC:( UNIT_??:PROPERTY_FOO_CALC CALC:) <-- When a default unit must be considered
+# CALC:( NUMBER:PROPERTY_FOO_CALC CALC:) <-- When a number must be produced (not a dimension)
+# CALC:( ANY:PROPERTY_FOO_CALC CALC:) <-- When a number or dimension is valid (e.g. line-height)
+
background_repeat:CSS_PROP_BACKGROUND_REPEAT IDENT:( INHERIT: NO_REPEAT:0,BACKGROUND_REPEAT_NO_REPEAT REPEAT_X:0,BACKGROUND_REPEAT_REPEAT_X REPEAT_Y:0,BACKGROUND_REPEAT_REPEAT_Y REPEAT:0,BACKGROUND_REPEAT_REPEAT IDENT:)
border_collapse:CSS_PROP_BORDER_COLLAPSE IDENT:( INHERIT: COLLAPSE:0,BORDER_COLLAPSE_COLLAPSE SEPARATE:0,BORDER_COLLAPSE_SEPARATE IDENT:)
@@ -22,35 +29,35 @@ empty_cells:CSS_PROP_EMPTY_CELLS IDENT:( INHERIT: SHOW:0,EMPTY_CELLS_SHOW HIDE:0
float:CSS_PROP_FLOAT IDENT:( INHERIT: LEFT:0,FLOAT_LEFT RIGHT:0,FLOAT_RIGHT NONE:0,FLOAT_NONE IDENT:)
-font_size:CSS_PROP_FONT_SIZE IDENT:( INHERIT: XX_SMALL:0,FONT_SIZE_XX_SMALL X_SMALL:0,FONT_SIZE_X_SMALL SMALL:0,FONT_SIZE_SMALL MEDIUM:0,FONT_SIZE_MEDIUM LARGE:0,FONT_SIZE_LARGE X_LARGE:0,FONT_SIZE_X_LARGE XX_LARGE:0,FONT_SIZE_XX_LARGE LARGER:0,FONT_SIZE_LARGER SMALLER:0,FONT_SIZE_SMALLER IDENT:) LENGTH_UNIT:( UNIT_PX:FONT_SIZE_DIMENSION MASK:UNIT_MASK_FONT_SIZE RANGE:<0 LENGTH_UNIT:)
+font_size:CSS_PROP_FONT_SIZE IDENT:( INHERIT: XX_SMALL:0,FONT_SIZE_XX_SMALL X_SMALL:0,FONT_SIZE_X_SMALL SMALL:0,FONT_SIZE_SMALL MEDIUM:0,FONT_SIZE_MEDIUM LARGE:0,FONT_SIZE_LARGE X_LARGE:0,FONT_SIZE_X_LARGE XX_LARGE:0,FONT_SIZE_XX_LARGE LARGER:0,FONT_SIZE_LARGER SMALLER:0,FONT_SIZE_SMALLER IDENT:) CALC:( UNIT_PX:FONT_SIZE_CALC CALC:) LENGTH_UNIT:( UNIT_PX:FONT_SIZE_DIMENSION MASK:UNIT_MASK_FONT_SIZE RANGE:<0 LENGTH_UNIT:)
font_style:CSS_PROP_FONT_STYLE IDENT:( INHERIT: NORMAL:0,FONT_STYLE_NORMAL ITALIC:0,FONT_STYLE_ITALIC OBLIQUE:0,FONT_STYLE_OBLIQUE IDENT:)
font_variant:CSS_PROP_FONT_VARIANT IDENT:( INHERIT: NORMAL:0,FONT_VARIANT_NORMAL SMALL_CAPS:0,FONT_VARIANT_SMALL_CAPS IDENT:)
-height:CSS_PROP_HEIGHT IDENT:( INHERIT: AUTO:0,HEIGHT_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:HEIGHT_SET MASK:UNIT_MASK_HEIGHT RANGE:<0 LENGTH_UNIT:)
+height:CSS_PROP_HEIGHT IDENT:( INHERIT: AUTO:0,HEIGHT_AUTO IDENT:) CALC:( UNIT_PX:HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:HEIGHT_SET MASK:UNIT_MASK_HEIGHT RANGE:<0 LENGTH_UNIT:)
-letter_spacing:CSS_PROP_LETTER_SPACING IDENT:( INHERIT: NORMAL:0,LETTER_SPACING_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:LETTER_SPACING_SET MASK:UNIT_MASK_LETTER_SPACING LENGTH_UNIT:)
+letter_spacing:CSS_PROP_LETTER_SPACING IDENT:( INHERIT: NORMAL:0,LETTER_SPACING_NORMAL IDENT:) CALC:( UNIT_PX:LETTER_SPACING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:LETTER_SPACING_SET MASK:UNIT_MASK_LETTER_SPACING LENGTH_UNIT:)
-line_height:CSS_PROP_LINE_HEIGHT IDENT:( INHERIT: NORMAL:0,LINE_HEIGHT_NORMAL IDENT:) NUMBER:( false:LINE_HEIGHT_NUMBER RANGE:num<0 NUMBER:) LENGTH_UNIT:( UNIT_PX:LINE_HEIGHT_DIMENSION MASK:UNIT_MASK_LINE_HEIGHT RANGE:<0 LENGTH_UNIT:)
+line_height:CSS_PROP_LINE_HEIGHT IDENT:( INHERIT: NORMAL:0,LINE_HEIGHT_NORMAL IDENT:) CALC:( ANY:LINE_HEIGHT_CALC CALC:) NUMBER:( false:LINE_HEIGHT_NUMBER RANGE:num<0 NUMBER:) LENGTH_UNIT:( UNIT_PX:LINE_HEIGHT_DIMENSION MASK:UNIT_MASK_LINE_HEIGHT RANGE:<0 LENGTH_UNIT:)
border_top:BORDER_SIDE_TOP WRAP:css__parse_border_side
border_bottom:BORDER_SIDE_BOTTOM WRAP:css__parse_border_side
border_left:BORDER_SIDE_LEFT WRAP:css__parse_border_side
border_right:BORDER_SIDE_RIGHT WRAP:css__parse_border_side
-max_height:CSS_PROP_MAX_HEIGHT IDENT:( INHERIT: NONE:0,MAX_HEIGHT_NONE IDENT:) LENGTH_UNIT:( UNIT_PX:MAX_HEIGHT_SET MASK:UNIT_MASK_MAX_HEIGHT RANGE:<0 LENGTH_UNIT:)
+max_height:CSS_PROP_MAX_HEIGHT IDENT:( INHERIT: NONE:0,MAX_HEIGHT_NONE IDENT:) CALC:( UNIT_PX:MAX_HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MAX_HEIGHT_SET MASK:UNIT_MASK_MAX_HEIGHT RANGE:<0 LENGTH_UNIT:)
-max_width:CSS_PROP_MAX_WIDTH IDENT:( INHERIT: NONE:0,MAX_WIDTH_NONE IDENT:) LENGTH_UNIT:( UNIT_PX:MAX_WIDTH_SET MASK:UNIT_MASK_MAX_WIDTH RANGE:<0 LENGTH_UNIT:)
+max_width:CSS_PROP_MAX_WIDTH IDENT:( INHERIT: NONE:0,MAX_WIDTH_NONE IDENT:) CALC:( UNIT_PX:MAX_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MAX_WIDTH_SET MASK:UNIT_MASK_MAX_WIDTH RANGE:<0 LENGTH_UNIT:)
-min_height:CSS_PROP_MIN_HEIGHT IDENT:( INHERIT: AUTO:0,MIN_HEIGHT_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET MASK:UNIT_MASK_MIN_HEIGHT RANGE:<0 LENGTH_UNIT:)
+min_height:CSS_PROP_MIN_HEIGHT IDENT:( INHERIT: AUTO:0,MIN_HEIGHT_AUTO IDENT:) CALC:( UNIT_PX:MIN_HEIGHT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET MASK:UNIT_MASK_MIN_HEIGHT RANGE:<0 LENGTH_UNIT:)
-min_width:CSS_PROP_MIN_WIDTH IDENT:( INHERIT: AUTO:0,MIN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET MASK:UNIT_MASK_MIN_WIDTH RANGE:<0 LENGTH_UNIT:)
+min_width:CSS_PROP_MIN_WIDTH IDENT:( INHERIT: AUTO:0,MIN_WIDTH_AUTO IDENT:) CALC:( UNIT_PX:MIN_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET MASK:UNIT_MASK_MIN_WIDTH RANGE:<0 LENGTH_UNIT:)
color:CSS_PROP_COLOR IDENT:INHERIT COLOR:COLOR_SET
#generic for padding_{top, bottom, left, right}.c
-padding_side:op GENERIC: IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:PADDING_SET MASK:UNIT_MASK_PADDING_SIDE RANGE:<0 LENGTH_UNIT:)
+padding_side:op GENERIC: IDENT:INHERIT CALC:( UNIT_PX:PADDING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:PADDING_SET MASK:UNIT_MASK_PADDING_SIDE RANGE:<0 LENGTH_UNIT:)
padding_bottom:CSS_PROP_PADDING_BOTTOM WRAP:css__parse_padding_side
padding_left:CSS_PROP_PADDING_LEFT WRAP:css__parse_padding_side
@@ -59,7 +66,7 @@ padding_right:CSS_PROP_PADDING_RIGHT WRAP:css__parse_padding_side
#generic for margin_{top, bottom, left, right}.c
-margin_side:op GENERIC IDENT:( INHERIT: AUTO:0,MARGIN_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MARGIN_SET MASK:UNIT_MASK_MARGIN_SIDE LENGTH_UNIT:)
+margin_side:op GENERIC IDENT:( INHERIT: AUTO:0,MARGIN_AUTO IDENT:) CALC:( UNIT_PX:MARGIN_CALC CALC:) LENGTH_UNIT:( UNIT_PX:MARGIN_SET MASK:UNIT_MASK_MARGIN_SIDE LENGTH_UNIT:)
margin_top:CSS_PROP_MARGIN_TOP WRAP:css__parse_margin_side
margin_bottom:CSS_PROP_MARGIN_BOTTOM WRAP:css__parse_margin_side
@@ -67,7 +74,7 @@ margin_left:CSS_PROP_MARGIN_LEFT WRAP:css__parse_margin_side
margin_right:CSS_PROP_MARGIN_RIGHT WRAP:css__parse_margin_side
#generic for {top, bottom, left, right}.c
-side:op GENERIC: IDENT:( INHERIT: AUTO:0,BOTTOM_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:BOTTOM_SET ALLOW:unit&(UNIT_LENGTH|UNIT_PCT) LENGTH_UNIT:)
+side:op GENERIC: IDENT:( INHERIT: AUTO:0,BOTTOM_AUTO IDENT:) CALC:( UNIT_PX:BOTTOM_CALC CALC:) LENGTH_UNIT:( UNIT_PX:BOTTOM_SET ALLOW:unit&(UNIT_LENGTH|UNIT_PCT) LENGTH_UNIT:)
top:CSS_PROP_TOP WRAP:css__parse_side
bottom:CSS_PROP_BOTTOM WRAP:css__parse_side
@@ -76,7 +83,7 @@ right:CSS_PROP_RIGHT WRAP:css__parse_side
#generic for border_{top, bottom, left, right}_width.c
-border_side_width:op GENERIC: IDENT:( INHERIT: THIN:0,BORDER_WIDTH_THIN MEDIUM:0,BORDER_WIDTH_MEDIUM THICK:0,BORDER_WIDTH_THICK IDENT:) LENGTH_UNIT:( UNIT_PX:BORDER_WIDTH_SET MASK:UNIT_MASK_BORDER_SIDE_WIDTH RANGE:<0 LENGTH_UNIT:)
+border_side_width:op GENERIC: IDENT:( INHERIT: THIN:0,BORDER_WIDTH_THIN MEDIUM:0,BORDER_WIDTH_MEDIUM THICK:0,BORDER_WIDTH_THICK IDENT:) CALC:( UNIT_PX:BORDER_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:BORDER_WIDTH_SET MASK:UNIT_MASK_BORDER_SIDE_WIDTH RANGE:<0 LENGTH_UNIT:)
border_top_width:CSS_PROP_BORDER_TOP_WIDTH WRAP:css__parse_border_side_width
border_bottom_width:CSS_PROP_BORDER_BOTTOM_WIDTH WRAP:css__parse_border_side_width
@@ -120,7 +127,7 @@ list_style_image:CSS_PROP_LIST_STYLE_IMAGE IDENT:( INHERIT: NONE:0,LIST_STYLE_IM
list_style_position:CSS_PROP_LIST_STYLE_POSITION IDENT:( INHERIT: INSIDE:0,LIST_STYLE_POSITION_INSIDE OUTSIDE:0,LIST_STYLE_POSITION_OUTSIDE IDENT:)
-orphans:CSS_PROP_ORPHANS IDENT:INHERIT NUMBER:( true:ORPHANS_SET RANGE:num<0 NUMBER:)
+orphans:CSS_PROP_ORPHANS IDENT:INHERIT CALC:( NUMBER:ORPHANS_CALC CALC:) NUMBER:( true:ORPHANS_SET RANGE:num<0 NUMBER:)
outline_color:CSS_PROP_OUTLINE_COLOR IDENT:( INHERIT: INVERT:0,OUTLINE_COLOR_INVERT IDENT:) COLOR:OUTLINE_COLOR_SET
@@ -140,17 +147,17 @@ page_break_before:CSS_PROP_PAGE_BREAK_BEFORE IDENT:( INHERIT: AUTO:0,PAGE_BREAK_
page_break_inside:CSS_PROP_PAGE_BREAK_INSIDE IDENT:( INHERIT: AUTO:0,PAGE_BREAK_INSIDE_AUTO AVOID:0,PAGE_BREAK_INSIDE_AVOID IDENT:)
-pause_after:CSS_PROP_PAUSE_AFTER IDENT:INHERIT LENGTH_UNIT:( UNIT_S:PAUSE_AFTER_SET MASK:UNIT_MASK_PAUSE_AFTER RANGE:<0 LENGTH_UNIT:)
+pause_after:CSS_PROP_PAUSE_AFTER IDENT:INHERIT CALC:( UNIT_S:PAUSE_AFTER_CALC CALC:) LENGTH_UNIT:( UNIT_S:PAUSE_AFTER_SET MASK:UNIT_MASK_PAUSE_AFTER RANGE:<0 LENGTH_UNIT:)
-pause_before:CSS_PROP_PAUSE_BEFORE IDENT:INHERIT LENGTH_UNIT:( UNIT_S:PAUSE_BEFORE_SET MASK:UNIT_MASK_PAUSE_BEFORE RANGE:<0 LENGTH_UNIT:)
+pause_before:CSS_PROP_PAUSE_BEFORE IDENT:INHERIT CALC:( UNIT_S:PAUSE_BEFORE_CALC CALC:) LENGTH_UNIT:( UNIT_S:PAUSE_BEFORE_SET MASK:UNIT_MASK_PAUSE_BEFORE RANGE:<0 LENGTH_UNIT:)
-pitch:CSS_PROP_PITCH IDENT:( INHERIT: X_LOW:0,PITCH_X_LOW LOW:0,PITCH_LOW MEDIUM:0,PITCH_MEDIUM HIGH:0,PITCH_HIGH X_HIGH:0,PITCH_X_HIGH IDENT:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY MASK:UNIT_MASK_PITCH RANGE:<0 LENGTH_UNIT:)
+pitch:CSS_PROP_PITCH IDENT:( INHERIT: X_LOW:0,PITCH_X_LOW LOW:0,PITCH_LOW MEDIUM:0,PITCH_MEDIUM HIGH:0,PITCH_HIGH X_HIGH:0,PITCH_X_HIGH IDENT:) CALC:( UNIT_HZ:PITCH_CALC CALC:) LENGTH_UNIT:( UNIT_HZ:PITCH_FREQUENCY MASK:UNIT_MASK_PITCH RANGE:<0 LENGTH_UNIT:)
-pitch_range:CSS_PROP_PITCH_RANGE IDENT:INHERIT NUMBER:( false:PITCH_RANGE_SET RANGE:num<0||num>F_100 NUMBER:)
+pitch_range:CSS_PROP_PITCH_RANGE IDENT:INHERIT CALC:( NUMBER:PITCH_RANGE_CALC CALC:) NUMBER:( false:PITCH_RANGE_SET RANGE:num<0||num>F_100 NUMBER:)
position:CSS_PROP_POSITION IDENT:( INHERIT: LIBCSS_STATIC:0,POSITION_STATIC RELATIVE:0,POSITION_RELATIVE ABSOLUTE:0,POSITION_ABSOLUTE FIXED:0,POSITION_FIXED IDENT:)
-richness:CSS_PROP_RICHNESS IDENT:INHERIT NUMBER:( false:RICHNESS_SET RANGE:num<0||num>F_100 NUMBER:)
+richness:CSS_PROP_RICHNESS IDENT:INHERIT CALC:( NUMBER:RICHNESS_CALC CALC:) NUMBER:( false:RICHNESS_SET RANGE:num<0||num>F_100 NUMBER:)
speak:CSS_PROP_SPEAK IDENT:( INHERIT: NORMAL:0,SPEAK_NORMAL NONE:0,SPEAK_NONE SPELL_OUT:0,SPEAK_SPELL_OUT IDENT:)
@@ -160,37 +167,35 @@ speak_numeral:CSS_PROP_SPEAK_NUMERAL IDENT:( INHERIT: DIGITS:0,SPEAK_NUMERAL_DIG
speak_punctuation:CSS_PROP_SPEAK_PUNCTUATION IDENT:( INHERIT: CODE:0,SPEAK_PUNCTUATION_CODE NONE:0,SPEAK_PUNCTUATION_NONE IDENT:)
-speech_rate:CSS_PROP_SPEECH_RATE IDENT:( INHERIT: X_SLOW:0,SPEECH_RATE_X_SLOW SLOW:0,SPEECH_RATE_SLOW MEDIUM:0,SPEECH_RATE_MEDIUM FAST:0,SPEECH_RATE_FAST X_FAST:0,SPEECH_RATE_X_FAST FASTER:0,SPEECH_RATE_FASTER SLOWER:0,SPEECH_RATE_SLOWER IDENT:) NUMBER:( false:SPEECH_RATE_SET RANGE:num<0 NUMBER:)
+speech_rate:CSS_PROP_SPEECH_RATE IDENT:( INHERIT: X_SLOW:0,SPEECH_RATE_X_SLOW SLOW:0,SPEECH_RATE_SLOW MEDIUM:0,SPEECH_RATE_MEDIUM FAST:0,SPEECH_RATE_FAST X_FAST:0,SPEECH_RATE_X_FAST FASTER:0,SPEECH_RATE_FASTER SLOWER:0,SPEECH_RATE_SLOWER IDENT:) CALC:( NUMBER:SPEECH_RATE_CALC CALC:) NUMBER:( false:SPEECH_RATE_SET RANGE:num<0 NUMBER:)
-stress:CSS_PROP_STRESS IDENT:INHERIT NUMBER:( false:STRESS_SET RANGE:num<0||num>INTTOFIX(100) NUMBER:)
+stress:CSS_PROP_STRESS IDENT:INHERIT CALC:( NUMBER:STRESS_CALC CALC:) NUMBER:( false:STRESS_SET RANGE:num<0||num>INTTOFIX(100) NUMBER:)
table_layout:CSS_PROP_TABLE_LAYOUT IDENT:( INHERIT: AUTO:0,TABLE_LAYOUT_AUTO FIXED:0,TABLE_LAYOUT_FIXED IDENT:)
text_align:CSS_PROP_TEXT_ALIGN IDENT:( INHERIT: LEFT:0,TEXT_ALIGN_LEFT RIGHT:0,TEXT_ALIGN_RIGHT CENTER:0,TEXT_ALIGN_CENTER JUSTIFY:0,TEXT_ALIGN_JUSTIFY LIBCSS_LEFT:0,TEXT_ALIGN_LIBCSS_LEFT LIBCSS_CENTER:0,TEXT_ALIGN_LIBCSS_CENTER LIBCSS_RIGHT:0,TEXT_ALIGN_LIBCSS_RIGHT IDENT:)
-text_indent:CSS_PROP_TEXT_INDENT IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:TEXT_INDENT_SET MASK:UNIT_MASK_TEXT_INDENT LENGTH_UNIT:)
+text_indent:CSS_PROP_TEXT_INDENT IDENT:INHERIT CALC:( UNIT_PX:TEXT_INDENT_CALC CALC:) LENGTH_UNIT:( UNIT_PX:TEXT_INDENT_SET MASK:UNIT_MASK_TEXT_INDENT LENGTH_UNIT:)
text_transform:CSS_PROP_TEXT_TRANSFORM IDENT:( INHERIT: CAPITALIZE:0,TEXT_TRANSFORM_CAPITALIZE UPPERCASE:0,TEXT_TRANSFORM_UPPERCASE LOWERCASE:0,TEXT_TRANSFORM_LOWERCASE NONE:0,TEXT_TRANSFORM_NONE IDENT:)
unicode_bidi:CSS_PROP_UNICODE_BIDI IDENT:( INHERIT: NORMAL:0,UNICODE_BIDI_NORMAL EMBED:0,UNICODE_BIDI_EMBED BIDI_OVERRIDE:0,UNICODE_BIDI_BIDI_OVERRIDE IDENT:)
-vertical_align:CSS_PROP_VERTICAL_ALIGN IDENT:( INHERIT: BASELINE:0,VERTICAL_ALIGN_BASELINE SUB:0,VERTICAL_ALIGN_SUB SUPER:0,VERTICAL_ALIGN_SUPER TOP:0,VERTICAL_ALIGN_TOP TEXT_TOP:0,VERTICAL_ALIGN_TEXT_TOP MIDDLE:0,VERTICAL_ALIGN_MIDDLE BOTTOM:0,VERTICAL_ALIGN_BOTTOM TEXT_BOTTOM:0,VERTICAL_ALIGN_TEXT_BOTTOM IDENT:) LENGTH_UNIT:( UNIT_PX:VERTICAL_ALIGN_SET MASK:UNIT_MASK_VERTICAL_ALIGN LENGTH_UNIT:)
+vertical_align:CSS_PROP_VERTICAL_ALIGN IDENT:( INHERIT: BASELINE:0,VERTICAL_ALIGN_BASELINE SUB:0,VERTICAL_ALIGN_SUB SUPER:0,VERTICAL_ALIGN_SUPER TOP:0,VERTICAL_ALIGN_TOP TEXT_TOP:0,VERTICAL_ALIGN_TEXT_TOP MIDDLE:0,VERTICAL_ALIGN_MIDDLE BOTTOM:0,VERTICAL_ALIGN_BOTTOM TEXT_BOTTOM:0,VERTICAL_ALIGN_TEXT_BOTTOM IDENT:) CALC:( UNIT_PX:VERTICAL_ALIGN_CALC CALC:) LENGTH_UNIT:( UNIT_PX:VERTICAL_ALIGN_SET MASK:UNIT_MASK_VERTICAL_ALIGN LENGTH_UNIT:)
visibility:CSS_PROP_VISIBILITY IDENT:( INHERIT: VISIBLE:0,VISIBILITY_VISIBLE HIDDEN:0,VISIBILITY_HIDDEN COLLAPSE:0,VISIBILITY_COLLAPSE IDENT:)
-volume:CSS_PROP_VOLUME IDENT:( INHERIT: SILENT:0,VOLUME_SILENT X_SOFT:0,VOLUME_X_SOFT SOFT:0,VOLUME_SOFT MEDIUM:0,VOLUME_MEDIUM LOUD:0,VOLUME_LOUD X_LOUD:0,VOLUME_X_LOUD IDENT:) NUMBER:( false:VOLUME_NUMBER RANGE:num<0||num>F_100 NUMBER:) LENGTH_UNIT:( UNIT_PX:VOLUME_DIMENSION MASK:UNIT_MASK_VOLUME RANGE:<0 LENGTH_UNIT:)
+volume:CSS_PROP_VOLUME IDENT:( INHERIT: SILENT:0,VOLUME_SILENT X_SOFT:0,VOLUME_X_SOFT SOFT:0,VOLUME_SOFT MEDIUM:0,VOLUME_MEDIUM LOUD:0,VOLUME_LOUD X_LOUD:0,VOLUME_X_LOUD IDENT:) CALC:( ANY:VOLUME_CALC CALC:) NUMBER:( false:VOLUME_NUMBER RANGE:num<0||num>F_100 NUMBER:) LENGTH_UNIT:( UNIT_PX:VOLUME_DIMENSION MASK:UNIT_MASK_VOLUME RANGE:<0 LENGTH_UNIT:)
white_space:CSS_PROP_WHITE_SPACE IDENT:( INHERIT: NORMAL:0,WHITE_SPACE_NORMAL PRE:0,WHITE_SPACE_PRE NOWRAP:0,WHITE_SPACE_NOWRAP PRE_WRAP:0,WHITE_SPACE_PRE_WRAP PRE_LINE:0,WHITE_SPACE_PRE_LINE IDENT:)
-widows:CSS_PROP_WIDOWS IDENT:INHERIT NUMBER:( true:WIDOWS_SET RANGE:num<0 NUMBER:)
-
-
-width:CSS_PROP_WIDTH IDENT:( INHERIT: AUTO:0,WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:WIDTH_SET MASK:UNIT_MASK_WIDTH RANGE:<0 LENGTH_UNIT:)
+widows:CSS_PROP_WIDOWS IDENT:INHERIT CALC:( NUMBER:WIDOWS_CALC CALC:) NUMBER:( true:WIDOWS_SET RANGE:num<0 NUMBER:)
-word_spacing:CSS_PROP_WORD_SPACING IDENT:( INHERIT: NORMAL:0,WORD_SPACING_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:WORD_SPACING_SET MASK:UNIT_MASK_WORD_SPACING LENGTH_UNIT:)
+width:CSS_PROP_WIDTH IDENT:( INHERIT: AUTO:0,WIDTH_AUTO IDENT:) CALC:( UNIT_PX:WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:WIDTH_SET MASK:UNIT_MASK_WIDTH RANGE:<0 LENGTH_UNIT:)
-z_index:CSS_PROP_Z_INDEX IDENT:( INHERIT: AUTO:0,Z_INDEX_AUTO IDENT:) NUMBER:( true:Z_INDEX_SET NUMBER:)
+word_spacing:CSS_PROP_WORD_SPACING IDENT:( INHERIT: NORMAL:0,WORD_SPACING_NORMAL IDENT:) CALC:( UNIT_PX:WORD_SPACING_CALC CALC:) LENGTH_UNIT:( UNIT_PX:WORD_SPACING_SET MASK:UNIT_MASK_WORD_SPACING LENGTH_UNIT:)
+z_index:CSS_PROP_Z_INDEX IDENT:( INHERIT: AUTO:0,Z_INDEX_AUTO IDENT:) CALC:( NUMBER:Z_INDEX_CALC CALC:) NUMBER:( true:Z_INDEX_SET NUMBER:)
break_after:CSS_PROP_BREAK_AFTER IDENT:( INHERIT: AUTO:0,BREAK_AFTER_AUTO ALWAYS:0,BREAK_AFTER_ALWAYS AVOID:0,BREAK_AFTER_AVOID LEFT:0,BREAK_AFTER_LEFT RIGHT:0,BREAK_AFTER_RIGHT PAGE:0,BREAK_AFTER_PAGE COLUMN:0,BREAK_AFTER_COLUMN AVOID_PAGE:0,BREAK_AFTER_AVOID_PAGE AVOID_COLUMN:0,BREAK_AFTER_AVOID_COLUMN IDENT:)
@@ -198,11 +203,11 @@ break_before:CSS_PROP_BREAK_BEFORE IDENT:( INHERIT: AUTO:0,BREAK_BEFORE_AUTO ALW
break_inside:CSS_PROP_BREAK_INSIDE IDENT:( INHERIT: AUTO:0,BREAK_INSIDE_AUTO AVOID:0,BREAK_INSIDE_AVOID AVOID_PAGE:0,BREAK_INSIDE_AVOID_PAGE AVOID_COLUMN:0,BREAK_INSIDE_AVOID_COLUMN IDENT:)
-column_count:CSS_PROP_COLUMN_COUNT IDENT:( INHERIT: AUTO:0,COLUMN_COUNT_AUTO IDENT:) NUMBER:( true:COLUMN_COUNT_SET RANGE:num<0 NUMBER:)
+column_count:CSS_PROP_COLUMN_COUNT IDENT:( INHERIT: AUTO:0,COLUMN_COUNT_AUTO IDENT: CALC:( NUMBER:COLUMN_COUNT_CALC CALC:)) NUMBER:( true:COLUMN_COUNT_SET RANGE:num<0 NUMBER:)
column_fill:CSS_PROP_COLUMN_FILL IDENT:( INHERIT: BALANCE:0,COLUMN_FILL_BALANCE AUTO:0,COLUMN_FILL_AUTO IDENT:)
-column_gap:CSS_PROP_COLUMN_GAP IDENT:( INHERIT: NORMAL:0,COLUMN_GAP_NORMAL IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_GAP_SET RANGE:<0 MASK:UNIT_MASK_COLUMN_GAP LENGTH_UNIT:)
+column_gap:CSS_PROP_COLUMN_GAP IDENT:( INHERIT: NORMAL:0,COLUMN_GAP_NORMAL IDENT:) CALC:( UNIT_PX:COLUMN_GAP_CALC CALC:) LENGTH_UNIT:( UNIT_PX:COLUMN_GAP_SET RANGE:<0 MASK:UNIT_MASK_COLUMN_GAP LENGTH_UNIT:)
column_rule_color:CSS_PROP_COLUMN_RULE_COLOR IDENT:( INHERIT: IDENT:) COLOR:COLUMN_RULE_COLOR_SET
@@ -212,7 +217,7 @@ column_rule_width:CSS_PROP_COLUMN_RULE_WIDTH WRAP:css__parse_border_side_width
column_span:CSS_PROP_COLUMN_SPAN IDENT:( INHERIT: NONE:0,COLUMN_SPAN_NONE ALL:0,COLUMN_SPAN_ALL IDENT:)
-column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET MASK:UNIT_MASK_COLUMN_WIDTH LENGTH_UNIT:)
+column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) CALC:( UNIT_PX:COLUMN_WIDTH_CALC CALC:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET MASK:UNIT_MASK_COLUMN_WIDTH LENGTH_UNIT:)
writing_mode:CSS_PROP_WRITING_MODE IDENT:( INHERIT: HORIZONTAL_TB:0,WRITING_MODE_HORIZONTAL_TB VERTICAL_RL:0,WRITING_MODE_VERTICAL_RL VERTICAL_LR:0,WRITING_MODE_VERTICAL_LR IDENT:)
@@ -224,16 +229,16 @@ align_items:CSS_PROP_ALIGN_ITEMS IDENT:( INHERIT: STRETCH:0,ALIGN_ITEMS_STRETCH
align_self:CSS_PROP_ALIGN_SELF IDENT:( INHERIT: STRETCH:0,ALIGN_SELF_STRETCH FLEX_START:0,ALIGN_SELF_FLEX_START FLEX_END:0,ALIGN_SELF_FLEX_END CENTER:0,ALIGN_SELF_CENTER BASELINE:0,ALIGN_SELF_BASELINE AUTO:0,ALIGN_SELF_AUTO IDENT:)
-flex_basis:CSS_PROP_FLEX_BASIS IDENT:( INHERIT: AUTO:0,FLEX_BASIS_AUTO CONTENT:0,FLEX_BASIS_CONTENT IDENT:) LENGTH_UNIT:( UNIT_PX:FLEX_BASIS_SET MASK:UNIT_MASK_FLEX_BASIS RANGE:<0 LENGTH_UNIT:)
+flex_basis:CSS_PROP_FLEX_BASIS IDENT:( INHERIT: AUTO:0,FLEX_BASIS_AUTO CONTENT:0,FLEX_BASIS_CONTENT IDENT:) CALC:( UNIT_PX:FLEX_BASIS_CALC CALC:) LENGTH_UNIT:( UNIT_PX:FLEX_BASIS_SET MASK:UNIT_MASK_FLEX_BASIS RANGE:<0 LENGTH_UNIT:)
flex_direction:CSS_PROP_FLEX_DIRECTION IDENT:( INHERIT: ROW:0,FLEX_DIRECTION_ROW ROW_REVERSE:0,FLEX_DIRECTION_ROW_REVERSE COLUMN:0,FLEX_DIRECTION_COLUMN COLUMN_REVERSE:0,FLEX_DIRECTION_COLUMN_REVERSE IDENT:)
-flex_grow:CSS_PROP_FLEX_GROW IDENT:INHERIT NUMBER:( false:FLEX_GROW_SET RANGE:num<0 NUMBER:)
+flex_grow:CSS_PROP_FLEX_GROW IDENT:INHERIT CALC:( NUMBER:FLEX_GROW_CALC CALC:) NUMBER:( false:FLEX_GROW_SET RANGE:num<0 NUMBER:)
-flex_shrink:CSS_PROP_FLEX_SHRINK IDENT:INHERIT NUMBER:( false:FLEX_SHRINK_SET RANGE:num<0 NUMBER:)
+flex_shrink:CSS_PROP_FLEX_SHRINK IDENT:INHERIT CALC:( NUMBER:FLEX_SHRINK_CALC CALC:) NUMBER:( false:FLEX_SHRINK_SET RANGE:num<0 NUMBER:)
flex_wrap:CSS_PROP_FLEX_WRAP IDENT:( INHERIT: NOWRAP:0,FLEX_WRAP_NOWRAP WRAP_STRING:0,FLEX_WRAP_WRAP WRAP_REVERSE:0,FLEX_WRAP_WRAP_REVERSE IDENT:)
justify_content:CSS_PROP_JUSTIFY_CONTENT IDENT:( INHERIT: FLEX_START:0,JUSTIFY_CONTENT_FLEX_START FLEX_END:0,JUSTIFY_CONTENT_FLEX_END CENTER:0,JUSTIFY_CONTENT_CENTER SPACE_BETWEEN:0,JUSTIFY_CONTENT_SPACE_BETWEEN SPACE_AROUND:0,JUSTIFY_CONTENT_SPACE_AROUND SPACE_EVENLY:0,JUSTIFY_CONTENT_SPACE_EVENLY IDENT:)
-order:CSS_PROP_ORDER IDENT:INHERIT NUMBER:( true:ORDER_SET NUMBER:)
+order:CSS_PROP_ORDER IDENT:INHERIT CALC:( NUMBER:ORDER_CALC CALC:) NUMBER:( true:ORDER_SET NUMBER:)
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 4739486..cce9717 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1351,9 +1351,9 @@ cleanup:
*
*
* calc(10px + (4rem / 2)) =>
- * U 10 px
- * U 4 rem
- * N 2
+ * V 10 px
+ * V 4 rem
+ * V 2 NUMBER
* /
* +
* =
@@ -1362,14 +1362,12 @@ cleanup:
static css_error
css__parse_calc_sum(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit);
+ css_style *result);
static css_error
css__parse_calc_value(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t default_unit)
+ css_style *result)
{
css_error error;
int orig_ctx = *ctx;
@@ -1377,7 +1375,7 @@ css__parse_calc_value(css_language *c,
token = parserutils_vector_iterate(vector, ctx);
if (tokenIsChar(token, '(')) {
- error = css__parse_calc_sum(c, vector, ctx, result, default_unit);
+ error = css__parse_calc_sum(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1396,13 +1394,13 @@ css__parse_calc_value(css_language *c,
uint32_t unit = 0;
*ctx = orig_ctx;
- error = css__parse_unit_specifier(c, vector, ctx, default_unit, &length, &unit);
+ error = css__parse_unit_specifier(c, vector, ctx, UNIT_CALC_NUMBER, &length, &unit);
if (error != CSS_OK) {
*ctx = orig_ctx;
return error;
}
- error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'U', length, unit);
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'V', length, unit);
}
break;
@@ -1422,8 +1420,7 @@ css__parse_calc_value(css_language *c,
static css_error
css__parse_calc_product(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit)
+ css_style *result)
{
css_error error = CSS_OK;
const css_token *token;
@@ -1431,7 +1428,7 @@ css__parse_calc_product(css_language *c,
/* First parse a value */
- error = css__parse_calc_value(c, vector, ctx, result, unit);
+ error = css__parse_calc_value(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1455,33 +1452,10 @@ css__parse_calc_product(css_language *c,
/* Consume that * or / now */
token = parserutils_vector_iterate(vector, ctx);
- if (multiplication) {
- /* parse another value */
- error = css__parse_calc_value(c, vector, ctx, result, unit);
- if (error != CSS_OK)
- break;
- } else {
- css_fixed num;
- size_t consumed;
-
- token = parserutils_vector_iterate(vector, ctx);
- if (token->type != CSS_TOKEN_NUMBER) {
- error = CSS_INVALID;
- break;
- }
- num = css__number_from_lwc_string(token->idata, false, &consumed);
- if (consumed != lwc_string_length(token->idata)) {
- error = CSS_INVALID;
- break;
- }
-
- error = css__stylesheet_style_append(result, (css_code_t) 'N');
- if (error != CSS_OK)
- break;
- error = css__stylesheet_style_append(result, (css_code_t) num);
- if (error != CSS_OK)
- break;
- }
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result);
+ if (error != CSS_OK)
+ break;
/* emit the multiplication/division operator */
error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
@@ -1494,8 +1468,7 @@ css__parse_calc_product(css_language *c,
css_error
css__parse_calc_sum(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style *result,
- uint32_t unit)
+ css_style *result)
{
css_error error = CSS_OK;
const css_token *token;
@@ -1503,7 +1476,7 @@ css__parse_calc_sum(css_language *c,
/* First parse a product */
- error = css__parse_calc_product(c, vector, ctx, result, unit);
+ error = css__parse_calc_product(c, vector, ctx, result);
if (error != CSS_OK) {
return error;
}
@@ -1528,7 +1501,7 @@ css__parse_calc_sum(css_language *c,
token = parserutils_vector_iterate(vector, ctx);
/* parse another product */
- error = css__parse_calc_product(c, vector, ctx, result, unit);
+ error = css__parse_calc_product(c, vector, ctx, result);
if (error != CSS_OK)
break;
@@ -1570,8 +1543,10 @@ css_error css__parse_calc(css_language *c,
error = css__stylesheet_style_append(calc_style, property);
if (error != CSS_OK)
goto cleanup;
+
+ error = css__stylesheet_style_append(calc_style, (css_code_t) unit);
- error = css__parse_calc_sum(c, vector, ctx, calc_style, unit);
+ error = css__parse_calc_sum(c, vector, ctx, calc_style);
if (error != CSS_OK)
goto cleanup;
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=817b43a06afc93e459ff...
commit 817b43a06afc93e459ff09afdb0e007f76ba6cbe
Author: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
parse: Add calc() parser.
Co-authored-by: Michael Drake <michael.drake(a)netsurf-browser.org>
diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c
index 24cc536..3d88cef 100644
--- a/src/parse/properties/css_property_parser_gen.c
+++ b/src/parse/properties/css_property_parser_gen.c
@@ -296,6 +296,16 @@ void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_lis
struct keyval *ckv = kvlist->item[0];
int ident_count;
+ fprintf(outputf,
+ "if ((token->type == CSS_TOKEN_IDENT) && "
+ "(lwc_string_caseless_isequal(token->idata, c->strings[CALC], &match) == lwc_error_ok && match))"
+ " {\n"
+ "\t\terror = css__parse_calc(c, vector, ctx, result, buildOPV(%s, 0, %s /* _CALC */), %s);\n"
+ "\t} else ",
+ parseid->val,
+ ckv->val,
+ ckv->key
+ );
fprintf(outputf,
"{\n"
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 1e184f8..4739486 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1333,3 +1333,269 @@ cleanup:
return error;
}
+
+/******************************************************************************/
+
+/* CALC
+ *
+ * calc( <calc-sum> )
+ *
+ * where
+ * <calc-sum> = <calc-product> [ [ '+' | '-' ] <calc-product> ]*
+ *
+ * where
+ * <calc-product> = <calc-value> [ '*' <calc-value> | '/' <number> ]*
+ *
+ * where
+ * <calc-value> = <number> | <dimension> | <percentage> | ( <calc-sum> )
+ *
+ *
+ * calc(10px + (4rem / 2)) =>
+ * U 10 px
+ * U 4 rem
+ * N 2
+ * /
+ * +
+ * =
+ */
+
+static css_error
+css__parse_calc_sum(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t unit);
+
+static css_error
+css__parse_calc_value(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t default_unit)
+{
+ css_error error;
+ int orig_ctx = *ctx;
+ const css_token *token;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (tokenIsChar(token, '(')) {
+ error = css__parse_calc_sum(c, vector, ctx, result, default_unit);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ token = parserutils_vector_peek(vector, *ctx);
+ if (!tokenIsChar(token, ')')) {
+ return CSS_INVALID;
+ }
+
+ } else switch (token->type) {
+ case CSS_TOKEN_NUMBER: /* Fall through */
+ case CSS_TOKEN_DIMENSION: /* Fall through */
+ case CSS_TOKEN_PERCENTAGE:
+ {
+ css_fixed length = 0;
+ uint32_t unit = 0;
+ *ctx = orig_ctx;
+
+ error = css__parse_unit_specifier(c, vector, ctx, default_unit, &length, &unit);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ return error;
+ }
+
+ error = css__stylesheet_style_vappend(result, 3, (css_code_t) 'U', length, unit);
+ }
+ break;
+
+ default:
+ error = CSS_INVALID;
+ break;
+ }
+
+ return error;
+}
+
+/* Both this, and css_parse_calc_sum must stop when it encounters a close-paren.
+ * If it hasn't had any useful tokens before that, it's an error. It does not
+ * need to restore ctx before returning an error but it does need to ensure that
+ * the close paren has not been consumed
+ */
+static css_error
+css__parse_calc_product(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t unit)
+{
+ css_error error = CSS_OK;
+ const css_token *token;
+ bool multiplication;
+
+
+ /* First parse a value */
+ error = css__parse_calc_value(c, vector, ctx, result, unit);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ do {
+ /* What is our next token? */
+ token = parserutils_vector_peek(vector, *ctx);
+ if (token == NULL) {
+ error = CSS_INVALID;
+ break;
+ } else if (tokenIsChar(token, ')'))
+ break;
+ else if (tokenIsChar(token, '*'))
+ multiplication = true;
+ else if (tokenIsChar(token, '/'))
+ multiplication = false;
+ else {
+ error = CSS_INVALID;
+ break;
+ }
+ /* Consume that * or / now */
+ token = parserutils_vector_iterate(vector, ctx);
+
+ if (multiplication) {
+ /* parse another value */
+ error = css__parse_calc_value(c, vector, ctx, result, unit);
+ if (error != CSS_OK)
+ break;
+ } else {
+ css_fixed num;
+ size_t consumed;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token->type != CSS_TOKEN_NUMBER) {
+ error = CSS_INVALID;
+ break;
+ }
+ num = css__number_from_lwc_string(token->idata, false, &consumed);
+ if (consumed != lwc_string_length(token->idata)) {
+ error = CSS_INVALID;
+ break;
+ }
+
+ error = css__stylesheet_style_append(result, (css_code_t) 'N');
+ if (error != CSS_OK)
+ break;
+ error = css__stylesheet_style_append(result, (css_code_t) num);
+ if (error != CSS_OK)
+ break;
+ }
+
+ /* emit the multiplication/division operator */
+ error = css__stylesheet_style_append(result, (css_code_t) (multiplication ? '*' : '/'));
+ } while (1);
+ /* We've fallen off, either we had an error or we're left with ')' */
+ return error;
+}
+
+
+css_error
+css__parse_calc_sum(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ uint32_t unit)
+{
+ css_error error = CSS_OK;
+ const css_token *token;
+ bool addition;
+
+
+ /* First parse a product */
+ error = css__parse_calc_product(c, vector, ctx, result, unit);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ do {
+ /* What is our next token? */
+ token = parserutils_vector_peek(vector, *ctx);
+ if (token == NULL) {
+ error = CSS_INVALID;
+ break;
+ } else if (tokenIsChar(token, ')'))
+ break;
+ else if (tokenIsChar(token, '+'))
+ addition = true;
+ else if (tokenIsChar(token, '-'))
+ addition = false;
+ else {
+ error = CSS_INVALID;
+ break;
+ }
+ /* Consume that + or - now */
+ token = parserutils_vector_iterate(vector, ctx);
+
+ /* parse another product */
+ error = css__parse_calc_product(c, vector, ctx, result, unit);
+ if (error != CSS_OK)
+ break;
+
+ /* emit the addition/subtraction operator */
+ error = css__stylesheet_style_append(result, (css_code_t) (addition ? '+' : '-'));
+ } while (1);
+ /* We've fallen off, either we had an error or we're left with ')' */
+ return error;
+}
+
+/* Documented in utils.h */
+css_error css__parse_calc(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ css_code_t property,
+ uint32_t unit)
+{
+ int orig_ctx = *ctx;
+ const css_token *token;
+ css_error error = CSS_OK;
+ css_style *calc_style = NULL;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (token == NULL) {
+ *ctx = orig_ctx;
+ return CSS_INVALID;
+ }
+
+ if (!tokenIsChar(token, '(')) {
+ /* If we don't get an open-paren, give up now */
+ *ctx = orig_ctx;
+ return CSS_INVALID;
+ }
+
+ error = css__stylesheet_style_create(c->sheet, &calc_style);
+ if (error != CSS_OK)
+ goto cleanup;
+
+ error = css__stylesheet_style_append(calc_style, property);
+ if (error != CSS_OK)
+ goto cleanup;
+
+ error = css__parse_calc_sum(c, vector, ctx, calc_style, unit);
+ if (error != CSS_OK)
+ goto cleanup;
+
+ token = parserutils_vector_iterate(vector, ctx);
+ if (!tokenIsChar(token, ')')) {
+ /* If we don't get a close-paren, give up now */
+ error = CSS_INVALID;
+ goto cleanup;
+ }
+
+ /* Append the indicator that the calc is finished */
+ error = css__stylesheet_style_append(calc_style, (css_code_t) '=');
+ if (error != CSS_OK)
+ goto cleanup;
+
+ /* TODO: Once we're OK to do so, merge the style */
+ (void)result;
+ /* error = css__stylesheet_style_merge_style(result, calc_style); */
+
+cleanup:
+ css__stylesheet_style_destroy(calc_style);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ }
+
+ return error;
+}
diff --git a/src/parse/properties/utils.h b/src/parse/properties/utils.h
index e4c97c7..e5331d2 100644
--- a/src/parse/properties/utils.h
+++ b/src/parse/properties/utils.h
@@ -199,4 +199,28 @@ css_error css__comma_list_to_style(css_language *c,
bool first),
css_style *result);
+/**
+ * Parse a CSS calc() invocation
+ *
+ * Calc can generate a number of kinds of units, so we have to tell the
+ * parser the kind of unit we're aiming for (e.g. UNIT_PX, UNIT_ANGLE, etc.)
+ *
+ * \param[in] c Parsing context
+ * \param[in] vector Vector of tokens to process
+ * \param[in] ctx Pointer to vector iteration context
+ * \param[in] result Pointer to location to receive resulting style
+ * \param[in] property The CSS property we are calculating for
+ * \param[in] unit The kind of unit which we want to come out of this calc()
+ * \return CSS_OK on success,
+ * CSS_NOMEM on memory exhaustion,
+ CSS_INVALID if the input is not valid
+ *
+ * Post condition: \a *ctx is updated with the next token to process
+ * If the input is invalid, then \a *ctx remains unchanged.
+ */
+css_error css__parse_calc(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result,
+ css_code_t property,
+ uint32_t unit);
#endif
diff --git a/src/parse/propstrings.c b/src/parse/propstrings.c
index 7d723e1..b102be9 100644
--- a/src/parse/propstrings.c
+++ b/src/parse/propstrings.c
@@ -484,6 +484,7 @@ const stringmap_entry stringmap[LAST_KNOWN] = {
SMAP("or"),
SMAP("only"),
SMAP("infinite"),
+ SMAP("calc"),
SMAP("aliceblue"),
SMAP("antiquewhite"),
diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h
index fd24a47..a098202 100644
--- a/src/parse/propstrings.h
+++ b/src/parse/propstrings.h
@@ -108,7 +108,7 @@ enum {
AVOID_PAGE, AVOID_COLUMN, BALANCE, HORIZONTAL_TB, VERTICAL_RL,
VERTICAL_LR, CONTENT_BOX, BORDER_BOX, STRETCH, INLINE_FLEX, FLEX_START,
FLEX_END, SPACE_BETWEEN, SPACE_AROUND, SPACE_EVENLY, ROW, ROW_REVERSE,
- COLUMN_REVERSE, WRAP_STRING, WRAP_REVERSE, AND, OR, ONLY, INFINITE,
+ COLUMN_REVERSE, WRAP_STRING, WRAP_REVERSE, AND, OR, ONLY, INFINITE, CALC,
/* Named colours */
FIRST_COLOUR,
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=05a064fc07a4cea3dd83...
commit 05a064fc07a4cea3dd8307c10b8a2aad3a670211
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Selection: Don't duplicate unit conversion members in media descriptor.
diff --git a/examples/example1.c b/examples/example1.c
index 6135793..1d2462c 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -103,7 +103,7 @@ static css_error set_libcss_node_data(void *pw, void *n,
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
-static css_unit_len_ctx uint_len_ctx = {
+static css_unit_ctx uint_len_ctx = {
.viewport_width = 800 * (1 << CSS_RADIX_POINT),
.viewport_height = 600 * (1 << CSS_RADIX_POINT),
.font_size_default = 16 * (1 << CSS_RADIX_POINT),
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index 1587d78..30e369b 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -82,7 +82,7 @@ css_error css_computed_style_destroy(css_computed_style *style);
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- const css_unit_len_ctx *unit_len_ctx,
+ const css_unit_ctx *unit_ctx,
css_computed_style **restrict result);
/******************************************************************************
diff --git a/include/libcss/select.h b/include/libcss/select.h
index bfaf531..25317e5 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -219,14 +219,16 @@ css_error css_select_default_style(css_select_ctx *ctx,
css_select_handler *handler, void *pw,
css_computed_style **style);
css_error css_select_style(css_select_ctx *ctx, void *node,
- const css_unit_len_ctx *unit_len_ctx,
+ const css_unit_ctx *unit_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result);
css_error css_select_results_destroy(css_select_results *results);
css_error css_select_font_faces(css_select_ctx *ctx,
- const css_media *media, lwc_string *font_family,
+ const css_media *media,
+ const css_unit_ctx *unit_ctx,
+ lwc_string *font_family,
css_select_font_faces_results **result);
css_error css_select_font_faces_results_destroy(
css_select_font_faces_results *results);
diff --git a/include/libcss/types.h b/include/libcss/types.h
index 1186c6f..2b0dfb7 100644
--- a/include/libcss/types.h
+++ b/include/libcss/types.h
@@ -234,10 +234,6 @@ typedef struct css_media {
/* Scripting media features */
css_media_scripting scripting;
-
- /* Client details for length conversion */
- css_fixed client_font_size; /* In pt */
- css_fixed client_line_height; /* In css pixels */
} css_media;
/**
diff --git a/include/libcss/unit.h b/include/libcss/unit.h
index a847077..67194c1 100644
--- a/include/libcss/unit.h
+++ b/include/libcss/unit.h
@@ -36,7 +36,7 @@ typedef css_fixed (*css_unit_len_measure)(
* If a NULL pointer is given, LibCSS will use a fixed scaling of
* the "em" unit.
*/
-typedef struct css_unit_len_ctx {
+typedef struct css_unit_ctx {
/**
* Viewport width in CSS pixels.
* Used if unit is vh, vw, vi, vb, vmin, or vmax.
@@ -73,7 +73,7 @@ typedef struct css_unit_len_ctx {
* Optional client callback for font measuring.
*/
const css_unit_len_measure measure;
-} css_unit_len_ctx;
+} css_unit_ctx;
/**
* Convert css pixels to physical pixels.
@@ -114,7 +114,7 @@ static inline css_fixed css_unit_device2css_px(
*/
css_fixed css_unit_font_size_len2pt(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit);
@@ -129,7 +129,7 @@ css_fixed css_unit_font_size_len2pt(
*/
css_fixed css_unit_len2css_px(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit);
@@ -144,7 +144,7 @@ css_fixed css_unit_len2css_px(
*/
css_fixed css_unit_len2device_px(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit);
diff --git a/src/select/computed.c b/src/select/computed.c
index d075af9..c019590 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -248,7 +248,7 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- const css_unit_len_ctx *unit_len_ctx,
+ const css_unit_ctx *unit_ctx,
css_computed_style **restrict result)
{
css_computed_style *composed;
@@ -274,7 +274,7 @@ css_error css_computed_style_compose(
}
/* Finally, compute absolute values for everything */
- error = css__compute_absolute_values(parent, composed, unit_len_ctx);
+ error = css__compute_absolute_values(parent, composed, unit_ctx);
if (error != CSS_OK) {
return error;
}
@@ -1085,12 +1085,12 @@ uint8_t css_computed_order(const css_computed_style *style,
*
* \param parent Parent style, or NULL for tree root
* \param style Computed style to process
- * \param unit_len_ctx Client length conversion context.
+ * \param unit_ctx Client length conversion context.
* \return CSS_OK on success.
*/
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- const css_unit_len_ctx *unit_len_ctx)
+ const css_unit_ctx *unit_ctx)
{
css_hint_length *ref_length = NULL;
css_hint psize, size, ex_size;
@@ -1112,8 +1112,8 @@ css_error css__compute_absolute_values(const css_computed_style *parent,
&size.data.length.unit);
error = css_unit_compute_absolute_font_size(ref_length,
- unit_len_ctx->root_style,
- unit_len_ctx->font_size_default,
+ unit_ctx->root_style,
+ unit_ctx->font_size_default,
&size);
if (error != CSS_OK)
return error;
@@ -1131,8 +1131,8 @@ css_error css__compute_absolute_values(const css_computed_style *parent,
error = css_unit_compute_absolute_font_size(
&size.data.length,
- unit_len_ctx->root_style,
- unit_len_ctx->font_size_default,
+ unit_ctx->root_style,
+ unit_ctx->font_size_default,
&ex_size);
if (error != CSS_OK)
return error;
diff --git a/src/select/computed.h b/src/select/computed.h
index 8b33405..a4bd23d 100644
--- a/src/select/computed.h
+++ b/src/select/computed.h
@@ -37,6 +37,6 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- const css_unit_len_ctx *unit_len_ctx);
+ const css_unit_ctx *unit_ctx);
#endif
diff --git a/src/select/hash.c b/src/select/hash.c
index 4dedec9..16aebf7 100644
--- a/src/select/hash.c
+++ b/src/select/hash.c
@@ -370,7 +370,7 @@ css_error css__selector_hash_find(css_selector_hash *hash,
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
@@ -449,6 +449,7 @@ css_error css__selector_hash_find_by_class(css_selector_hash *hash,
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -529,6 +530,7 @@ css_error css__selector_hash_find_by_id(css_selector_hash *hash,
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -579,7 +581,7 @@ css_error css__selector_hash_find_universal(css_selector_hash *hash,
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
@@ -922,7 +924,7 @@ css_error _iterate_elements(
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
@@ -982,6 +984,7 @@ css_error _iterate_classes(
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -1043,6 +1046,7 @@ css_error _iterate_ids(
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -1086,7 +1090,7 @@ css_error _iterate_universal(
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
diff --git a/src/select/hash.h b/src/select/hash.h
index aecf15a..df4102f 100644
--- a/src/select/hash.h
+++ b/src/select/hash.h
@@ -10,6 +10,7 @@
#include <libwapcaplet/libwapcaplet.h>
+#include <libcss/unit.h>
#include <libcss/errors.h>
#include <libcss/functypes.h>
@@ -26,6 +27,7 @@ struct css_hash_selection_requirments {
lwc_string *id; /* Name of id, or NULL */
lwc_string *uni; /* Universal element string "*" */
const css_media *media; /* Media spec we're selecting for */
+ const css_unit_ctx *unit_ctx; /* Document unit conversion context. */
const css_bloom *node_bloom; /* Node's bloom filter */
};
diff --git a/src/select/mq.h b/src/select/mq.h
index 080a6ba..a012a7b 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -16,7 +16,7 @@ static inline bool mq_match_feature_range_length_op1(
css_mq_feature_op op,
const css_mq_value *value,
const css_fixed client_len,
- const css_media *media)
+ const css_unit_ctx *unit_ctx)
{
css_fixed v;
@@ -25,7 +25,7 @@ static inline bool mq_match_feature_range_length_op1(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_unit_len2px_mq(media,
+ v = css_unit_len2px_mq(unit_ctx,
value->data.dim.len,
css__to_css_unit(value->data.dim.unit));
} else {
@@ -48,7 +48,7 @@ static inline bool mq_match_feature_range_length_op2(
css_mq_feature_op op,
const css_mq_value *value,
const css_fixed client_len,
- const css_media *media)
+ const css_unit_ctx *unit_ctx)
{
css_fixed v;
@@ -60,7 +60,7 @@ static inline bool mq_match_feature_range_length_op2(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_unit_len2px_mq(media,
+ v = css_unit_len2px_mq(unit_ctx,
value->data.dim.len,
css__to_css_unit(value->data.dim.unit));
} else {
@@ -81,31 +81,33 @@ static inline bool mq_match_feature_range_length_op2(
/**
* Match media query features.
*
- * \param[in] feat Condition to match.
- * \param[in] media Current media spec, to check against feat.
+ * \param[in] feat Condition to match.
+ * \param[in] unit_ctx Current unit conversion context.
+ * \param[in] media Current media spec, to check against feat.
* \return true if condition matches, otherwise false.
*/
static inline bool mq_match_feature(
const css_mq_feature *feat,
+ const css_unit_ctx *unit_ctx,
const css_media *media)
{
/* TODO: Use interned string for comparison. */
if (strcmp(lwc_string_data(feat->name), "width") == 0) {
if (!mq_match_feature_range_length_op1(feat->op, &feat->value,
- media->width, media)) {
+ media->width, unit_ctx)) {
return false;
}
return mq_match_feature_range_length_op2(feat->op2,
- &feat->value2, media->width, media);
+ &feat->value2, media->width, unit_ctx);
} else if (strcmp(lwc_string_data(feat->name), "height") == 0) {
if (!mq_match_feature_range_length_op1(feat->op, &feat->value,
- media->height, media)) {
+ media->height, unit_ctx)) {
return false;
}
return mq_match_feature_range_length_op2(feat->op2,
- &feat->value2, media->height, media);
+ &feat->value2, media->height, unit_ctx);
}
/* TODO: Look at other feature names. */
@@ -116,12 +118,14 @@ static inline bool mq_match_feature(
/**
* Match media query conditions.
*
- * \param[in] cond Condition to match.
- * \param[in] media Current media spec, to check against cond.
+ * \param[in] cond Condition to match.
+ * \param[in] unit_ctx Current unit conversion context.
+ * \param[in] media Current media spec, to check against cond.
* \return true if condition matches, otherwise false.
*/
static inline bool mq_match_condition(
const css_mq_cond *cond,
+ const css_unit_ctx *unit_ctx,
const css_media *media)
{
bool matched = !cond->op;
@@ -130,11 +134,13 @@ static inline bool mq_match_condition(
bool part_matched;
if (cond->parts[i]->type == CSS_MQ_FEATURE) {
part_matched = mq_match_feature(
- cond->parts[i]->data.feat, media);
+ cond->parts[i]->data.feat,
+ unit_ctx, media);
} else {
assert(cond->parts[i]->type == CSS_MQ_COND);
part_matched = mq_match_condition(
- cond->parts[i]->data.cond, media);
+ cond->parts[i]->data.cond,
+ unit_ctx, media);
}
if (cond->op) {
@@ -161,19 +167,22 @@ static inline bool mq_match_condition(
* If anything in the list matches, the list matches. If none match
* it doesn't match.
*
- * \param[in] m Media query list.
- * \param[in] media Current media spec, to check against m.
+ * \param[in] m Media query list.
+ * \param[in] unit_ctx Current unit conversion context.
+ * \param[in] media Current media spec, to check against m.
* \return true if media query list matches media
*/
static inline bool mq__list_match(
const css_mq_query *m,
+ const css_unit_ctx *unit_ctx,
const css_media *media)
{
for (; m != NULL; m = m->next) {
/* Check type */
if (!!(m->type & media->type) != m->negate_type) {
if (m->cond == NULL ||
- mq_match_condition(m->cond, media)) {
+ mq_match_condition(m->cond,
+ unit_ctx, media)) {
/* We have a match, no need to look further. */
return true;
}
@@ -186,11 +195,15 @@ static inline bool mq__list_match(
/**
* Test whether the rule applies for current media.
*
- * \param rule Rule to test
- * \param media Current media spec
+ * \param rule Rule to test
+ * \param unit_ctx Current unit conversion context.
+ * \param media Current media spec
* \return true iff chain's rule applies for media
*/
-static inline bool mq_rule_good_for_media(const css_rule *rule, const css_media *media)
+static inline bool mq_rule_good_for_media(
+ const css_rule *rule,
+ const css_unit_ctx *unit_ctx,
+ const css_media *media)
{
bool applies = true;
const css_rule *ancestor = rule;
@@ -199,7 +212,7 @@ static inline bool mq_rule_good_for_media(const css_rule *rule, const css_media
const css_rule_media *m = (const css_rule_media *) ancestor;
if (ancestor->type == CSS_RULE_MEDIA) {
- applies = mq__list_match(m->media, media);
+ applies = mq__list_match(m->media, unit_ctx, media);
if (applies == false) {
break;
}
diff --git a/src/select/select.c b/src/select/select.c
index 03a45fe..b050c0c 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -99,6 +99,7 @@ typedef struct css_select_font_faces_list {
typedef struct css_select_font_faces_state {
lwc_string *font_family;
const css_media *media;
+ const css_unit_ctx *unit_ctx;
css_select_font_faces_list ua_font_faces;
css_select_font_faces_list user_font_faces;
@@ -1052,12 +1053,13 @@ static void css_select__finalise_selection_state(
/**
* Initialise a selection state.
*
- * \param[in] state The selection state to initialise
- * \param[in] node The node we are selecting for.
- * \param[in] parent The node's parent node, or NULL.
- * \param[in] media The media specification we're selecting for.
- * \param[in] handler The client selection callback table.
- * \param[in] pw The client private data, passsed out to callbacks.
+ * \param[in] state The selection state to initialise
+ * \param[in] node The node we are selecting for.
+ * \param[in] parent The node's parent node, or NULL.
+ * \param[in] media The media specification we're selecting for.
+ * \param[in] unit_ctx Unit conversion context.
+ * \param[in] handler The client selection callback table.
+ * \param[in] pw The client private data, passsed out to callbacks.
* \return CSS_OK or appropriate error otherwise.
*/
static css_error css_select__initialise_selection_state(
@@ -1065,6 +1067,7 @@ static css_error css_select__initialise_selection_state(
void *node,
void *parent,
const css_media *media,
+ const css_unit_ctx *unit_ctx,
css_select_handler *handler,
void *pw)
{
@@ -1075,6 +1078,7 @@ static css_error css_select__initialise_selection_state(
memset(state, 0, sizeof(*state));
state->node = node;
state->media = media;
+ state->unit_ctx = unit_ctx;
state->handler = handler;
state->pw = pw;
state->next_reject = state->reject_cache +
@@ -1165,7 +1169,7 @@ failed:
*
* \param ctx Selection context to use
* \param node Node to select style for
- * \param unit_len_ctx Context for length unit conversions.
+ * \param unit_ctx Context for length unit conversions.
* \param media Currently active media specification
* \param inline_style Corresponding inline style for node, or NULL
* \param handler Dispatch table of handler functions
@@ -1183,7 +1187,7 @@ failed:
* update the fully computed style for a node when layout changes.
*/
css_error css_select_style(css_select_ctx *ctx, void *node,
- const css_unit_len_ctx *unit_len_ctx,
+ const css_unit_ctx *unit_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result)
@@ -1204,7 +1208,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
return error;
error = css_select__initialise_selection_state(
- &state, node, parent, media, handler, pw);
+ &state, node, parent, media, unit_ctx, handler, pw);
if (error != CSS_OK)
return error;
@@ -1269,7 +1273,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if (mq__list_match(s.media, media) &&
+ if (mq__list_match(s.media, unit_ctx, media) &&
s.sheet->disabled == false) {
error = select_from_sheet(ctx, s.sheet,
s.origin, &state);
@@ -1356,7 +1360,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
/* Only compute absolute values for the base element */
error = css__compute_absolute_values(NULL,
state.results->styles[CSS_PSEUDO_ELEMENT_NONE],
- unit_len_ctx);
+ unit_ctx);
if (error != CSS_OK)
goto cleanup;
}
@@ -1420,12 +1424,15 @@ css_error css_select_results_destroy(css_select_results *results)
*
* \param ctx Selection context
* \param media Currently active media spec
+ * \param unit_ctx Current unit conversion context.
* \param font_family Font family to search for
* \param result Pointer to location to receive result
* \return CSS_OK on success, appropriate error otherwise.
*/
css_error css_select_font_faces(css_select_ctx *ctx,
- const css_media *media, lwc_string *font_family,
+ const css_media *media,
+ const css_unit_ctx *unit_ctx,
+ lwc_string *font_family,
css_select_font_faces_results **result)
{
uint32_t i;
@@ -1439,6 +1446,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
memset(&state, 0, sizeof(css_select_font_faces_state));
state.font_family = font_family;
state.media = media;
+ state.unit_ctx = unit_ctx;
/* Iterate through the top-level stylesheets, selecting font-faces
* from those which apply to our current media requirements and
@@ -1446,7 +1454,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if (mq__list_match(s.media, media) &&
+ if (mq__list_match(s.media, unit_ctx, media) &&
s.sheet->disabled == false) {
error = select_font_faces_from_sheet(s.sheet,
s.origin, &state);
@@ -1846,6 +1854,7 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
if (import->sheet != NULL &&
mq__list_match(import->media,
+ state->unit_ctx,
state->media)) {
/* It's applicable, so process it */
if (sp >= IMPORT_STACK_SIZE)
@@ -1889,7 +1898,8 @@ static css_error _select_font_face_from_rule(
const css_rule_font_face *rule, css_origin origin,
css_select_font_faces_state *state)
{
- if (mq_rule_good_for_media((const css_rule *) rule, state->media)) {
+ if (mq_rule_good_for_media((const css_rule *) rule,
+ state->unit_ctx, state->media)) {
bool correct_family = false;
if (lwc_string_isequal(
@@ -1954,6 +1964,7 @@ static css_error select_font_faces_from_sheet(
if (import->sheet != NULL &&
mq__list_match(import->media,
+ state->unit_ctx,
state->media)) {
/* It's applicable, so process it */
if (sp >= IMPORT_STACK_SIZE)
@@ -2101,6 +2112,7 @@ css_error match_selectors_in_sheet(css_select_ctx *ctx,
/* Set up general selector chain requirments */
req.media = state->media;
+ req.unit_ctx = state->unit_ctx;
req.node_bloom = state->node_data->bloom;
req.uni = ctx->universal;
diff --git a/src/select/select.h b/src/select/select.h
index dc9aa4a..0a16b12 100644
--- a/src/select/select.h
+++ b/src/select/select.h
@@ -64,6 +64,7 @@ struct css_node_data {
typedef struct css_select_state {
void *node; /* Node we're selecting for */
const css_media *media; /* Currently active media spec */
+ const css_unit_ctx *unit_ctx; /* Unit conversion context. */
css_select_results *results; /* Result set to populate */
css_pseudo_element current_pseudo; /* Current pseudo element */
diff --git a/src/select/unit.c b/src/select/unit.c
index a279ec7..9129d72 100644
--- a/src/select/unit.c
+++ b/src/select/unit.c
@@ -118,7 +118,7 @@ static inline css_fixed css_unit__absolute_len2pt(
/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_font_size_len2pt(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
@@ -279,22 +279,22 @@ static inline css_fixed css_unit__px_per_unit(
/* Exported function, documented in unit.h. */
css_fixed css_unit_len2px_mq(
- const css_media *media,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
/* In the media query context there is no reference or root element
- * style, so these are hardcoded to NULL. */
+ * style, so these are hard-coded to NULL. */
css_fixed px_per_unit = css_unit__px_per_unit(
+ ctx->measure,
NULL,
NULL,
- NULL,
- media->client_font_size,
- INTTOFIX(0),
- media->height,
- media->width,
+ ctx->font_size_default,
+ ctx->font_size_minimum,
+ ctx->viewport_height,
+ ctx->viewport_width,
unit,
- NULL);
+ ctx->pw);
/* Ensure we round px_per_unit to the nearest whole number of pixels:
* the use of FIXTOINT() below will truncate. */
@@ -307,7 +307,7 @@ css_fixed css_unit_len2px_mq(
/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_len2css_px(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
@@ -333,7 +333,7 @@ css_fixed css_unit_len2css_px(
/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_len2device_px(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
diff --git a/src/select/unit.h b/src/select/unit.h
index e4d21da..6a677b6 100644
--- a/src/select/unit.h
+++ b/src/select/unit.h
@@ -14,13 +14,13 @@
/**
* Convert a length to CSS pixels for a media query context.
*
- * \param[in] media Client media specification.
+ * \param[in] ctx Document unit conversion context.
* \param[in] length Length to convert.
* \param[in] unit Current unit of length.
* \return A length in CSS pixels.
*/
css_fixed css_unit_len2px_mq(
- const css_media *media,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit);
diff --git a/test/select.c b/test/select.c
index a3319fe..c104b38 100644
--- a/test/select.c
+++ b/test/select.c
@@ -164,7 +164,7 @@ static css_error set_libcss_node_data(void *pw, void *n,
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
-static css_unit_len_ctx unit_len_ctx = {
+static css_unit_ctx unit_ctx = {
.font_size_default = 16 * (1 << CSS_RADIX_POINT),
};
@@ -801,11 +801,11 @@ static void run_test_select_tree(css_select_ctx *select,
struct node *n = NULL;
if (node->parent == NULL) {
- unit_len_ctx.root_style = NULL;
+ unit_ctx.root_style = NULL;
}
- assert(css_select_style(select, node, &unit_len_ctx, &ctx->media, NULL,
+ assert(css_select_style(select, node, &unit_ctx, &ctx->media, NULL,
&select_handler, ctx, &sr) == CSS_OK);
if (node->parent != NULL) {
@@ -813,7 +813,7 @@ static void run_test_select_tree(css_select_ctx *select,
assert(css_computed_style_compose(
node->parent->sr->styles[ctx->pseudo_element],
sr->styles[ctx->pseudo_element],
- &unit_len_ctx,
+ &unit_ctx,
&composed) == CSS_OK);
css_computed_style_destroy(sr->styles[ctx->pseudo_element]);
sr->styles[ctx->pseudo_element] = composed;
@@ -827,7 +827,7 @@ static void run_test_select_tree(css_select_ctx *select,
}
if (node->parent == NULL) {
- unit_len_ctx.root_style = node->sr->styles[ctx->pseudo_element];
+ unit_ctx.root_style = node->sr->styles[ctx->pseudo_element];
}
for (n = node->children; n != NULL; n = n->next) {
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=ce2155ea14a93327bd32...
commit ce2155ea14a93327bd320d90f434da2fdb1ab66d
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Selection: Remove client callback for unit conversion.
Now clients provide a unit conversion context and libcss provides
code to perform unit conversion.
This reduces the amount of common code that clients have to write.
diff --git a/Makefile b/Makefile
index 0835c8f..86d6641 100644
--- a/Makefile
+++ b/Makefile
@@ -65,5 +65,6 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/properties.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/select.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/stylesheet.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/types.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/unit.h
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR)/pkgconfig:lib$(COMPONENT).pc.in
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR):$(OUTPUT)
diff --git a/examples/example1.c b/examples/example1.c
index c36a94d..6135793 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -98,13 +98,22 @@ static css_error node_presentational_hint(void *pw, void *node,
uint32_t *nhints, css_hint **hints);
static css_error ua_default_for_property(void *pw, uint32_t property,
css_hint *hint);
-static css_error compute_font_size(void *pw, const css_hint *parent,
- css_hint *size);
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data);
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
+static css_unit_len_ctx uint_len_ctx = {
+ .viewport_width = 800 * (1 << CSS_RADIX_POINT),
+ .viewport_height = 600 * (1 << CSS_RADIX_POINT),
+ .font_size_default = 16 * (1 << CSS_RADIX_POINT),
+ .font_size_minimum = 6 * (1 << CSS_RADIX_POINT),
+ .device_dpi = 96 * (1 << CSS_RADIX_POINT),
+ .root_style = NULL, /* We don't have a root node yet. */
+ .pw = NULL, /* We're not implementing measure callback */
+ .measure = NULL, /* We're not implementing measure callback */
+};
+
/* Table of function pointers for the LibCSS Select API. */
static css_select_handler select_handler = {
CSS_SELECT_HANDLER_VERSION_1,
@@ -143,9 +152,8 @@ static css_select_handler select_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
- compute_font_size,
set_libcss_node_data,
- get_libcss_node_data
+ get_libcss_node_data,
};
@@ -237,6 +245,7 @@ int main(int argc, char **argv)
lwc_intern_string(element, strlen(element), &element_name);
code = css_select_style(select_ctx, element_name,
+ &uint_len_ctx,
&media, NULL,
&select_handler, 0,
&style);
@@ -662,68 +671,6 @@ css_error ua_default_for_property(void *pw, uint32_t property, css_hint *hint)
return CSS_OK;
}
-css_error compute_font_size(void *pw, const css_hint *parent, css_hint *size)
-{
- static css_hint_length sizes[] = {
- { FLTTOFIX(6.75), CSS_UNIT_PT },
- { FLTTOFIX(7.50), CSS_UNIT_PT },
- { FLTTOFIX(9.75), CSS_UNIT_PT },
- { FLTTOFIX(12.0), CSS_UNIT_PT },
- { FLTTOFIX(13.5), CSS_UNIT_PT },
- { FLTTOFIX(18.0), CSS_UNIT_PT },
- { FLTTOFIX(24.0), CSS_UNIT_PT }
- };
- const css_hint_length *parent_size;
-
- UNUSED(pw);
-
- /* Grab parent size, defaulting to medium if none */
- if (parent == NULL) {
- parent_size = &sizes[CSS_FONT_SIZE_MEDIUM - 1];
- } else {
- assert(parent->status == CSS_FONT_SIZE_DIMENSION);
- assert(parent->data.length.unit != CSS_UNIT_EM);
- assert(parent->data.length.unit != CSS_UNIT_EX);
- parent_size = &parent->data.length;
- }
-
- assert(size->status != CSS_FONT_SIZE_INHERIT);
-
- if (size->status < CSS_FONT_SIZE_LARGER) {
- /* Keyword -- simple */
- size->data.length = sizes[size->status - 1];
- } else if (size->status == CSS_FONT_SIZE_LARGER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->status == CSS_FONT_SIZE_SMALLER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_EM ||
- size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value =
- FMUL(size->data.length.value, parent_size->value);
-
- if (size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.6));
- }
-
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_PCT) {
- size->data.length.value = FDIV(FMUL(size->data.length.value,
- parent_size->value), FLTTOFIX(100));
- size->data.length.unit = parent_size->unit;
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data)
{
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index f4b3e21..1587d78 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -19,6 +19,7 @@ extern "C"
#include <libcss/functypes.h>
#include <libcss/properties.h>
#include <libcss/types.h>
+#include <libcss/unit.h>
struct css_hint;
struct css_select_handler;
@@ -81,10 +82,7 @@ css_error css_computed_style_destroy(css_computed_style *style);
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- css_error (*compute_font_size)(void *pw,
- const struct css_hint *parent,
- struct css_hint *size),
- void *pw,
+ const css_unit_len_ctx *unit_len_ctx,
css_computed_style **restrict result);
/******************************************************************************
diff --git a/include/libcss/select.h b/include/libcss/select.h
index ca57456..bfaf531 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -18,6 +18,7 @@ extern "C"
#include <libcss/hint.h>
#include <libcss/types.h>
#include <libcss/computed.h>
+#include <libcss/unit.h>
typedef enum css_pseudo_element {
CSS_PSEUDO_ELEMENT_NONE = 0,
@@ -123,9 +124,6 @@ typedef struct css_select_handler {
css_error (*ua_default_for_property)(void *pw, uint32_t property,
css_hint *hint);
- css_error (*compute_font_size)(void *pw, const css_hint *parent,
- css_hint *size);
-
/**
* Set libcss_node_data on a DOM node.
*
@@ -221,6 +219,7 @@ css_error css_select_default_style(css_select_ctx *ctx,
css_select_handler *handler, void *pw,
css_computed_style **style);
css_error css_select_style(css_select_ctx *ctx, void *node,
+ const css_unit_len_ctx *unit_len_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result);
diff --git a/include/libcss/unit.h b/include/libcss/unit.h
new file mode 100644
index 0000000..a847077
--- /dev/null
+++ b/include/libcss/unit.h
@@ -0,0 +1,156 @@
+/*
+ * This file is part of LibCSS.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef libcss_unit_h_
+#define libcss_unit_h_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libcss/types.h>
+
+/**
+ * Client callback for font measuring.
+ *
+ * \param[in] pw Client data.
+ * \param[in] style Style to measure font for, or NULL.
+ * \param[in] unit Either CSS_UNIT_EX, or CSS_UNIT_CH.
+ * \return length in CSS pixels.
+ */
+typedef css_fixed (*css_unit_len_measure)(
+ void *pw,
+ const css_computed_style *style,
+ const css_unit unit);
+
+/**
+ * LibCSS unit conversion context.
+ *
+ * The client callback is optional. It is used for measuring "ch"
+ * (glyph '0' advance) and "ex" (height of the letter 'x') units.
+ * If a NULL pointer is given, LibCSS will use a fixed scaling of
+ * the "em" unit.
+ */
+typedef struct css_unit_len_ctx {
+ /**
+ * Viewport width in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_width;
+ /**
+ * Viewport height in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_height;
+ /**
+ * Client default font size in CSS pixels.
+ */
+ css_fixed font_size_default;
+ /**
+ * Client minimum font size in CSS pixels. May be zero.
+ */
+ css_fixed font_size_minimum;
+ /**
+ * DPI of the device the style is selected for.
+ */
+ css_fixed device_dpi;
+ /**
+ * Computed style for the document root element, needed for rem units.
+ * May be NULL, in which case font_size_default is used instead, as
+ * would be the case if rem unit is used on the root element.
+ */
+ const css_computed_style *root_style;
+ /**
+ * Optional client private word for measure callback.
+ */
+ void *pw;
+ /**
+ * Optional client callback for font measuring.
+ */
+ const css_unit_len_measure measure;
+} css_unit_len_ctx;
+
+/**
+ * Convert css pixels to physical pixels.
+ *
+ * \param[in] css_pixels Length in css pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in device pixels.
+ */
+static inline css_fixed css_unit_css2device_px(
+ const css_fixed css_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(css_pixels, device_dpi), F_96);
+}
+
+/**
+ * Convert device pixels to css pixels.
+ *
+ * \param[in] device_pixels Length in physical pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in css pixels.
+ */
+static inline css_fixed css_unit_device2css_px(
+ const css_fixed device_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(device_pixels, F_96), device_dpi);
+}
+
+/**
+ * Convert a length to points (pt).
+ *
+ * \param[in] style Style to perform conversion for or NULL.
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in points.
+ */
+css_fixed css_unit_font_size_len2pt(
+ const css_computed_style *style,
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to CSS pixels.
+ *
+ * \param[in] style Style to perform conversion for or NULL.
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in CSS pixels.
+ */
+css_fixed css_unit_len2css_px(
+ const css_computed_style *style,
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to device pixels.
+ *
+ * \param[in] style Style to perform conversion for or NULL.
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in device pixels.
+ */
+css_fixed css_unit_len2device_px(
+ const css_computed_style *style,
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/src/select/computed.c b/src/select/computed.c
index a1b345b..d075af9 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -12,6 +12,7 @@
#include "select/dispatch.h"
#include "select/propget.h"
#include "select/propset.h"
+#include "select/unit.h"
#include "utils/utils.h"
static css_error compute_absolute_color(css_computed_style *style,
@@ -247,9 +248,7 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw,
+ const css_unit_len_ctx *unit_len_ctx,
css_computed_style **restrict result)
{
css_computed_style *composed;
@@ -275,8 +274,7 @@ css_error css_computed_style_compose(
}
/* Finally, compute absolute values for everything */
- error = css__compute_absolute_values(parent, composed,
- compute_font_size, pw);
+ error = css__compute_absolute_values(parent, composed, unit_len_ctx);
if (error != CSS_OK) {
return error;
}
@@ -1087,31 +1085,36 @@ uint8_t css_computed_order(const css_computed_style *style,
*
* \param parent Parent style, or NULL for tree root
* \param style Computed style to process
- * \param compute_font_size Callback to calculate an absolute font-size
- * \param pw Private word for callback
+ * \param unit_len_ctx Client length conversion context.
* \return CSS_OK on success.
*/
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw)
+ const css_unit_len_ctx *unit_len_ctx)
{
+ css_hint_length *ref_length = NULL;
css_hint psize, size, ex_size;
css_error error;
- /* Ensure font-size is absolute */
+ /* Get reference font-size for relative sizes. */
if (parent != NULL) {
psize.status = get_font_size(parent,
&psize.data.length.value,
&psize.data.length.unit);
+ if (psize.status != CSS_FONT_SIZE_DIMENSION) {
+ return CSS_BADPARM;
+ }
+ ref_length = &psize.data.length;
}
size.status = get_font_size(style,
&size.data.length.value,
&size.data.length.unit);
- error = compute_font_size(pw, parent != NULL ? &psize : NULL, &size);
+ error = css_unit_compute_absolute_font_size(ref_length,
+ unit_len_ctx->root_style,
+ unit_len_ctx->font_size_default,
+ &size);
if (error != CSS_OK)
return error;
@@ -1125,7 +1128,12 @@ css_error css__compute_absolute_values(const css_computed_style *parent,
ex_size.status = CSS_FONT_SIZE_DIMENSION;
ex_size.data.length.value = INTTOFIX(1);
ex_size.data.length.unit = CSS_UNIT_EX;
- error = compute_font_size(pw, &size, &ex_size);
+
+ error = css_unit_compute_absolute_font_size(
+ &size.data.length,
+ unit_len_ctx->root_style,
+ unit_len_ctx->font_size_default,
+ &ex_size);
if (error != CSS_OK)
return error;
diff --git a/src/select/computed.h b/src/select/computed.h
index c926cec..8b33405 100644
--- a/src/select/computed.h
+++ b/src/select/computed.h
@@ -10,6 +10,8 @@
#include <libcss/computed.h>
#include <libcss/hint.h>
+#include <libcss/unit.h>
+
#include "autogenerated_computed.h"
/**
@@ -35,8 +37,6 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw);
+ const css_unit_len_ctx *unit_len_ctx);
#endif
diff --git a/src/select/select.c b/src/select/select.c
index f6efbfe..03a45fe 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -23,6 +23,7 @@
#include "select/propset.h"
#include "select/font_face.h"
#include "select/select.h"
+#include "select/unit.h"
#include "utils/parserutilserror.h"
#include "utils/utils.h"
@@ -1164,6 +1165,7 @@ failed:
*
* \param ctx Selection context to use
* \param node Node to select style for
+ * \param unit_len_ctx Context for length unit conversions.
* \param media Currently active media specification
* \param inline_style Corresponding inline style for node, or NULL
* \param handler Dispatch table of handler functions
@@ -1181,6 +1183,7 @@ failed:
* update the fully computed style for a node when layout changes.
*/
css_error css_select_style(css_select_ctx *ctx, void *node,
+ const css_unit_len_ctx *unit_len_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result)
@@ -1353,7 +1356,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
/* Only compute absolute values for the base element */
error = css__compute_absolute_values(NULL,
state.results->styles[CSS_PSEUDO_ELEMENT_NONE],
- handler->compute_font_size, pw);
+ unit_len_ctx);
if (error != CSS_OK)
goto cleanup;
}
diff --git a/src/select/unit.c b/src/select/unit.c
index f9ecf83..a279ec7 100644
--- a/src/select/unit.c
+++ b/src/select/unit.c
@@ -115,14 +115,15 @@ static inline css_fixed css_unit__absolute_len2pt(
}
}
-/* Exported function, documented in unit.h. */
+/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_font_size_len2pt(
+ const css_computed_style *style,
const css_unit_len_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
return css_unit__absolute_len2pt(
- ctx->ref_style,
+ style,
ctx->viewport_height,
ctx->viewport_width,
length,
@@ -303,15 +304,16 @@ css_fixed css_unit_len2px_mq(
return FMUL(length, TRUNCATEFIX(px_per_unit));
}
-/* Exported function, documented in unit.h. */
+/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_len2css_px(
+ const css_computed_style *style,
const css_unit_len_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
css_fixed px_per_unit = css_unit__px_per_unit(
ctx->measure,
- ctx->ref_style,
+ style,
ctx->root_style,
ctx->font_size_default,
ctx->font_size_minimum,
@@ -328,15 +330,16 @@ css_fixed css_unit_len2css_px(
return FMUL(length, TRUNCATEFIX(px_per_unit));
}
-/* Exported function, documented in unit.h. */
+/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_len2device_px(
+ const css_computed_style *style,
const css_unit_len_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
css_fixed px_per_unit = css_unit__px_per_unit(
ctx->measure,
- ctx->ref_style,
+ style,
ctx->root_style,
ctx->font_size_default,
ctx->font_size_minimum,
@@ -361,18 +364,18 @@ css_fixed css_unit_len2device_px(
* The computed style will have font-size with an absolute unit.
* If no computed style is given, the client default font-size will be returned.
*
- * \param[in] ctx Length unit conversion context.
- * \param[in] style The style to get the font-size for, or NULL.
+ * \param[in] style Reference style. (Element or parent, or NULL).
+ * \param[in] font_size_default Client default font size in CSS pixels.
* \return The font size in absolute units.
*/
static inline css_hint_length css_unit__get_font_size(
- const css_unit_len_ctx *ctx,
- const css_computed_style *style)
+ const css_computed_style *style,
+ css_fixed font_size_default)
{
css_hint_length size;
if (style == NULL) {
- size.value = ctx->font_size_default;
+ size.value = font_size_default;
size.unit = CSS_UNIT_PX;
} else {
enum css_font_size_e status = get_font_size(
@@ -391,10 +394,24 @@ static inline css_hint_length css_unit__get_font_size(
/* Exported function, documented in unit.h. */
css_error css_unit_compute_absolute_font_size(
- const css_unit_len_ctx *ctx,
+ const css_hint_length *ref_length,
+ const css_computed_style *root_style,
+ css_fixed font_size_default,
css_hint *size)
{
- css_hint_length ref_len;
+ css_hint_length ref_len = {
+ .value = font_size_default,
+ .unit = CSS_UNIT_PX,
+ };
+
+ if (ref_length != NULL) {
+ /* Must be absolute. */
+ assert(ref_length->unit != CSS_UNIT_EM);
+ assert(ref_length->unit != CSS_UNIT_EX);
+ assert(ref_length->unit != CSS_UNIT_PCT);
+
+ ref_len = *ref_length;
+ }
assert(size->status != CSS_FONT_SIZE_INHERIT);
@@ -420,20 +437,18 @@ css_error css_unit_compute_absolute_font_size(
assert(CSS_FONT_SIZE_XX_SMALL == 1);
size->data.length.value = FMUL(factors[size->status - 1],
- ctx->font_size_default);
+ font_size_default);
size->data.length.unit = CSS_UNIT_PX;
size->status = CSS_FONT_SIZE_DIMENSION;
break;
}
case CSS_FONT_SIZE_LARGER:
- ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
size->data.length.value = FMUL(ref_len.value, FLTTOFIX(1.2));
size->data.length.unit = ref_len.unit;
size->status = CSS_FONT_SIZE_DIMENSION;
break;
case CSS_FONT_SIZE_SMALLER:
- ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
size->data.length.value = FDIV(ref_len.value, FLTTOFIX(1.2));
size->data.length.unit = ref_len.unit;
size->status = CSS_FONT_SIZE_DIMENSION;
@@ -443,9 +458,8 @@ css_error css_unit_compute_absolute_font_size(
/* Convert any relative units to absolute. */
switch (size->data.length.unit) {
case CSS_UNIT_PCT:
- ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
- size->data.length.value = FDIV(
- FMUL(size->data.length.value,
+ size->data.length.value = FDIV(FMUL(
+ size->data.length.value,
ref_len.value), INTTOFIX(100));
size->data.length.unit = ref_len.unit;
break;
@@ -454,11 +468,8 @@ css_error css_unit_compute_absolute_font_size(
case CSS_UNIT_EX: /* Fall-through */
case CSS_UNIT_CH:
/* Parent relative units. */
- ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
-
- size->data.length.unit = ref_len.unit;
- size->data.length.value = FMUL(size->data.length.value,
- ref_len.value);
+ size->data.length.value = FMUL(
+ size->data.length.value, ref_len.value);
switch (size->data.length.unit) {
case CSS_UNIT_EX:
@@ -476,15 +487,17 @@ css_error css_unit_compute_absolute_font_size(
default:
break;
}
+ size->data.length.unit = ref_len.unit;
break;
case CSS_UNIT_REM:
/* Root element relative units. */
- ref_len = css_unit__get_font_size(ctx, ctx->root_style);
+ ref_len = css_unit__get_font_size(root_style,
+ font_size_default);
size->data.length.unit = ref_len.unit;
- size->data.length.value = FMUL(size->data.length.value,
- ref_len.value);
+ size->data.length.value = FMUL(
+ size->data.length.value, ref_len.value);
break;
default:
diff --git a/src/select/unit.h b/src/select/unit.h
index 738c181..e4d21da 100644
--- a/src/select/unit.h
+++ b/src/select/unit.h
@@ -9,138 +9,7 @@
#ifndef css_select_unit_h_
#define css_select_unit_h_
-/**
- * Client callback for font measuring.
- *
- * \param[in] pw Client data.
- * \param[in] style Style to measure font for, or NULL.
- * \param[in] unit Either CSS_UNIT_EX, or CSS_UNIT_CH.
- * \return length in CSS pixels.
- */
-typedef css_fixed (*css_unit_len_measure)(
- void *pw,
- const css_computed_style *style,
- const css_unit unit);
-
-/**
- * LibCSS unit conversion context.
- *
- * The client callback is optional. It is used for measuring "ch"
- * (glyph '0' advance) and "ex" (height of the letter 'x') units.
- * If a NULL pointer is given, LibCSS will use a fixed scaling of
- * the "em" unit.
- */
-typedef struct css_unit_len_ctx {
- /**
- * Viewport width in CSS pixels.
- * Used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- css_fixed viewport_width;
- /**
- * Viewport height in CSS pixels.
- * Used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- css_fixed viewport_height;
- /**
- * Client default font size in CSS pixels.
- */
- css_fixed font_size_default;
- /**
- * Client minimum font size in CSS pixels. May be zero.
- */
- css_fixed font_size_minimum;
- /**
- * DPI of the device the style is selected for.
- */
- css_fixed device_dpi;
- /**
- * Reference style. Most of the time, this is the element's style.
- * When converting a length for a typographical property, such as
- * font-size, then this should be the parent node. If the node has
- * no parent then this may be NULL.
- */
- const css_computed_style *ref_style;
- /**
- * Computed style for the document root element.
- * May be NULL if unit is not rem.
- */
- const css_computed_style *root_style;
- /**
- * Client private word for measure callback.
- */
- void *pw;
- /**
- * Client callback for font measuring.
- */
- const css_unit_len_measure measure;
-} css_unit_len_ctx;
-
-/**
- * Convert css pixels to physical pixels.
- *
- * \param[in] css_pixels Length in css pixels.
- * \param[in] device_dpi Device dots per inch.
- * \return Length in device pixels.
- */
-static inline css_fixed css_unit_css2device_px(
- const css_fixed css_pixels,
- const css_fixed device_dpi)
-{
- return FDIV(FMUL(css_pixels, device_dpi), F_96);
-}
-
-/**
- * Convert device pixels to css pixels.
- *
- * \param[in] device_pixels Length in physical pixels.
- * \param[in] device_dpi Device dots per inch.
- * \return Length in css pixels.
- */
-static inline css_fixed css_unit_device2css_px(
- const css_fixed device_pixels,
- const css_fixed device_dpi)
-{
- return FDIV(FMUL(device_pixels, F_96), device_dpi);
-}
-
-/**
- * Convert a length to points (pt).
- *
- * \param[in] ctx Length unit conversion context.
- * \param[in] length Length to convert.
- * \param[in] unit Current unit of length.
- * \return A length in points.
- */
-css_fixed css_unit_font_size_len2pt(
- const css_unit_len_ctx *ctx,
- const css_fixed length,
- const css_unit unit);
-
-/**
- * Convert a length to CSS pixels.
- *
- * \param[in] ctx Length unit conversion context.
- * \param[in] length Length to convert.
- * \param[in] unit Current unit of length.
- * \return A length in CSS pixels.
- */
-css_fixed css_unit_len2css_px(
- const css_unit_len_ctx *ctx,
- const css_fixed length,
- const css_unit unit);
-
-/**
- * Convert a length to device pixels.
- *
- * \param[in] ctx Length unit conversion context.
- * \param[in] length Length to convert.
- * \param[in] unit Current unit of length.
- * \return A length in device pixels.
- */
-css_fixed css_unit_len2device_px(
- const css_unit_len_ctx *ctx,
- const css_fixed length,
- const css_unit unit);
+#include <libcss/unit.h>
/**
* Convert a length to CSS pixels for a media query context.
@@ -158,12 +27,16 @@ css_fixed css_unit_len2px_mq(
/**
* Convert relative font size units to absolute units.
*
- * \param[in] ctx Length unit conversion context.
- * \param[in,out] size The length to convert.
+ * \param[in] ref_length Reference font-size length or NULL.
+ * \param[in] root_style Root element style or NULL.
+ * \param[in] font_size_default Client default font size in CSS pixels.
+ * \param[in,out] size The length to convert.
* \return CSS_OK on success, or appropriate error otherwise.
*/
css_error css_unit_compute_absolute_font_size(
- const css_unit_len_ctx *ctx,
+ const css_hint_length *ref_length,
+ const css_computed_style *root_style,
+ css_fixed font_size_default,
css_hint *size);
#endif
diff --git a/test/data/select/tests1.dat b/test/data/select/tests1.dat
index eaf37d7..295ab2e 100644
--- a/test/data/select/tests1.dat
+++ b/test/data/select/tests1.dat
@@ -59,7 +59,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -173,7 +173,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -291,7 +291,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -410,7 +410,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -529,7 +529,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -648,7 +648,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -757,7 +757,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -867,7 +867,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -977,7 +977,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1086,7 +1086,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1200,7 +1200,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1314,7 +1314,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1429,7 +1429,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1547,7 +1547,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1664,7 +1664,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1787,7 +1787,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1910,7 +1910,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2033,7 +2033,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2160,7 +2160,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2286,7 +2286,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2410,7 +2410,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2533,7 +2533,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2656,7 +2656,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2779,7 +2779,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2902,7 +2902,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3025,7 +3025,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3148,7 +3148,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3271,7 +3271,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3394,7 +3394,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3517,7 +3517,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3640,7 +3640,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 10.600pt
+font-size: 13.342px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3763,7 +3763,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 14.391pt
+font-size: 19.187px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3886,7 +3886,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 24pt
+font-size: 32px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4009,7 +4009,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 18pt
+font-size: 24px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4132,7 +4132,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 13.500pt
+font-size: 18px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4255,7 +4255,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4378,7 +4378,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 9.750pt
+font-size: 13px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4501,7 +4501,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 7.500pt
+font-size: 10px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4624,7 +4624,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 6.750pt
+font-size: 9px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4870,7 +4870,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4986,7 +4986,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5102,7 +5102,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5218,7 +5218,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5331,7 +5331,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5445,7 +5445,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5559,7 +5559,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5673,7 +5673,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5783,7 +5783,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5894,7 +5894,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6004,7 +6004,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6114,7 +6114,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6224,7 +6224,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6334,7 +6334,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6444,7 +6444,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6556,7 +6556,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6666,7 +6666,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6776,7 +6776,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6887,7 +6887,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6997,7 +6997,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7107,7 +7107,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7217,7 +7217,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7327,7 +7327,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7437,7 +7437,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7547,7 +7547,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7657,7 +7657,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7766,7 +7766,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7875,7 +7875,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7984,7 +7984,7 @@ flex-shrink: 30.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8095,7 +8095,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8206,7 +8206,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8315,7 +8315,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8426,7 +8426,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8537,7 +8537,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8648,7 +8648,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8757,7 +8757,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8866,7 +8866,7 @@ flex-shrink: 1.000
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8975,7 +8975,7 @@ flex-shrink: 1.000
flex-wrap: wrap-reverse
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9084,7 +9084,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9193,7 +9193,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9302,7 +9302,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9411,7 +9411,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9520,7 +9520,7 @@ flex-shrink: 1.000
flex-wrap: wrap-reverse
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9631,7 +9631,7 @@ flex-shrink: 1.000
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9742,7 +9742,7 @@ flex-shrink: 1.000
flex-wrap: wrap-reverse
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9851,7 +9851,7 @@ flex-shrink: 0.899
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9960,7 +9960,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10069,7 +10069,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10178,7 +10178,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10287,7 +10287,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10396,7 +10396,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10505,7 +10505,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10616,7 +10616,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10727,7 +10727,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10836,7 +10836,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10945,7 +10945,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11054,7 +11054,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11165,7 +11165,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11274,7 +11274,7 @@ flex-shrink: 3.780
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11385,7 +11385,7 @@ flex-shrink: 3.780
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11494,7 +11494,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11603,7 +11603,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11712,7 +11712,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11821,7 +11821,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11930,7 +11930,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12039,7 +12039,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12148,7 +12148,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12257,7 +12257,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12366,7 +12366,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12475,7 +12475,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12584,7 +12584,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12693,7 +12693,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12802,7 +12802,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12911,7 +12911,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13020,7 +13020,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13129,7 +13129,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13238,7 +13238,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13347,7 +13347,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13456,7 +13456,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13565,7 +13565,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13674,7 +13674,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13783,7 +13783,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13892,7 +13892,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -14020,7 +14020,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
diff --git a/test/select.c b/test/select.c
index 33f31dd..a3319fe 100644
--- a/test/select.c
+++ b/test/select.c
@@ -159,13 +159,15 @@ static css_error node_presentational_hint(void *pw, void *node,
uint32_t *nhints, css_hint **hints);
static css_error ua_default_for_property(void *pw, uint32_t property,
css_hint *hints);
-static css_error compute_font_size(void *pw, const css_hint *parent,
- css_hint *size);
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data);
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
+static css_unit_len_ctx unit_len_ctx = {
+ .font_size_default = 16 * (1 << CSS_RADIX_POINT),
+};
+
static css_select_handler select_handler = {
CSS_SELECT_HANDLER_VERSION_1,
@@ -203,9 +205,9 @@ static css_select_handler select_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
- compute_font_size,
+
set_libcss_node_data,
- get_libcss_node_data
+ get_libcss_node_data,
};
static css_error resolve_url(void *pw,
@@ -798,7 +800,12 @@ static void run_test_select_tree(css_select_ctx *select,
css_select_results *sr;
struct node *n = NULL;
- assert(css_select_style(select, node, &ctx->media, NULL,
+ if (node->parent == NULL) {
+ unit_len_ctx.root_style = NULL;
+ }
+
+
+ assert(css_select_style(select, node, &unit_len_ctx, &ctx->media, NULL,
&select_handler, ctx, &sr) == CSS_OK);
if (node->parent != NULL) {
@@ -806,7 +813,7 @@ static void run_test_select_tree(css_select_ctx *select,
assert(css_computed_style_compose(
node->parent->sr->styles[ctx->pseudo_element],
sr->styles[ctx->pseudo_element],
- compute_font_size, NULL,
+ &unit_len_ctx,
&composed) == CSS_OK);
css_computed_style_destroy(sr->styles[ctx->pseudo_element]);
sr->styles[ctx->pseudo_element] = composed;
@@ -819,6 +826,10 @@ static void run_test_select_tree(css_select_ctx *select,
buf, buflen);
}
+ if (node->parent == NULL) {
+ unit_len_ctx.root_style = node->sr->styles[ctx->pseudo_element];
+ }
+
for (n = node->children; n != NULL; n = n->next) {
run_test_select_tree(select, n, ctx, buf, buflen);
}
@@ -1639,68 +1650,6 @@ css_error ua_default_for_property(void *pw, uint32_t property, css_hint *hint)
return CSS_OK;
}
-css_error compute_font_size(void *pw, const css_hint *parent, css_hint *size)
-{
- static css_hint_length sizes[] = {
- { FLTTOFIX(6.75), CSS_UNIT_PT },
- { FLTTOFIX(7.50), CSS_UNIT_PT },
- { FLTTOFIX(9.75), CSS_UNIT_PT },
- { FLTTOFIX(12.0), CSS_UNIT_PT },
- { FLTTOFIX(13.5), CSS_UNIT_PT },
- { FLTTOFIX(18.0), CSS_UNIT_PT },
- { FLTTOFIX(24.0), CSS_UNIT_PT }
- };
- const css_hint_length *parent_size;
-
- UNUSED(pw);
-
- /* Grab parent size, defaulting to medium if none */
- if (parent == NULL) {
- parent_size = &sizes[CSS_FONT_SIZE_MEDIUM - 1];
- } else {
- assert(parent->status == CSS_FONT_SIZE_DIMENSION);
- assert(parent->data.length.unit != CSS_UNIT_EM);
- assert(parent->data.length.unit != CSS_UNIT_EX);
- parent_size = &parent->data.length;
- }
-
- assert(size->status != CSS_FONT_SIZE_INHERIT);
-
- if (size->status < CSS_FONT_SIZE_LARGER) {
- /* Keyword -- simple */
- size->data.length = sizes[size->status - 1];
- } else if (size->status == CSS_FONT_SIZE_LARGER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->status == CSS_FONT_SIZE_SMALLER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FDIV(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_EM ||
- size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value =
- FMUL(size->data.length.value, parent_size->value);
-
- if (size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.6));
- }
-
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_PCT) {
- size->data.length.value = FDIV(FMUL(size->data.length.value,
- parent_size->value), FLTTOFIX(100));
- size->data.length.unit = parent_size->unit;
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data)
{
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=307b71ec3001bcd8cacc...
commit 307b71ec3001bcd8cacc875ddd09138744eb7ee1
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Units: Add support for length unit conversion to libcss.
Currently only used for unit conversion.
diff --git a/src/select/Makefile b/src/select/Makefile
index 8b47673..f5ddb18 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 format_list_style.c
+DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c font_face.c format_list_style.c unit.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/select/hash.c b/src/select/hash.c
index 4b11702..4dedec9 100644
--- a/src/select/hash.c
+++ b/src/select/hash.c
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <string.h>
+#include <libcss/hint.h>
+
#include "stylesheet.h"
#include "select/hash.h"
#include "select/mq.h"
diff --git a/src/select/mq.h b/src/select/mq.h
index 6f98387..080a6ba 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -10,96 +10,7 @@
#define css_select_mq_h_
#include "select/helpers.h"
-
-static inline css_fixed css_len2px(
- css_fixed length,
- css_unit unit,
- const css_media *media)
-{
- css_fixed px_per_unit;
-
- switch (unit) {
- case CSS_UNIT_VI:
- /* TODO: Assumes writing mode. */
- unit = CSS_UNIT_VW;
- break;
- case CSS_UNIT_VB:
- /* TODO: Assumes writing mode. */
- unit = CSS_UNIT_VH;
- break;
- case CSS_UNIT_VMIN:
- unit = (media->height < media->width) ?
- CSS_UNIT_VH : CSS_UNIT_VW;
- break;
- case CSS_UNIT_VMAX:
- unit = (media->width > media->height) ?
- CSS_UNIT_VH : CSS_UNIT_VW;
- break;
- default:
- break;
- }
-
- switch (unit) {
- case CSS_UNIT_EM:
- case CSS_UNIT_EX:
- case CSS_UNIT_CH:
- {
- px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
-
- /* TODO: Handling these as fixed ratios of CSS_UNIT_EM. */
- switch (unit) {
- case CSS_UNIT_EX:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
- break;
- case CSS_UNIT_CH:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
- break;
- default:
- break;
- }
- }
- break;
- case CSS_UNIT_PX:
- return length;
- case CSS_UNIT_IN:
- px_per_unit = F_96;
- break;
- case CSS_UNIT_CM:
- px_per_unit = FDIV(F_96, FLTTOFIX(2.54));
- break;
- case CSS_UNIT_MM:
- px_per_unit = FDIV(F_96, FLTTOFIX(25.4));
- break;
- case CSS_UNIT_Q:
- px_per_unit = FDIV(F_96, FLTTOFIX(101.6));
- break;
- case CSS_UNIT_PT:
- px_per_unit = FDIV(F_96, F_72);
- break;
- case CSS_UNIT_PC:
- px_per_unit = FDIV(F_96, INTTOFIX(6));
- break;
- case CSS_UNIT_REM:
- px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
- break;
- case CSS_UNIT_VH:
- px_per_unit = FDIV(media->height, F_100);
- break;
- case CSS_UNIT_VW:
- px_per_unit = FDIV(media->width, F_100);
- break;
- default:
- px_per_unit = 0;
- break;
- }
-
- /* Ensure we round px_per_unit to the nearest whole number of pixels:
- * the use of FIXTOINT() below will truncate. */
- px_per_unit += F_0_5;
-
- /* Calculate total number of pixels */
- return FMUL(length, TRUNCATEFIX(px_per_unit));
-}
+#include "select/unit.h"
static inline bool mq_match_feature_range_length_op1(
css_mq_feature_op op,
@@ -114,9 +25,9 @@ static inline bool mq_match_feature_range_length_op1(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_len2px(value->data.dim.len,
- css__to_css_unit(value->data.dim.unit),
- media);
+ v = css_unit_len2px_mq(media,
+ value->data.dim.len,
+ css__to_css_unit(value->data.dim.unit));
} else {
v = value->data.dim.len;
}
@@ -149,9 +60,9 @@ static inline bool mq_match_feature_range_length_op2(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_len2px(value->data.dim.len,
- css__to_css_unit(value->data.dim.unit),
- media);
+ v = css_unit_len2px_mq(media,
+ value->data.dim.len,
+ css__to_css_unit(value->data.dim.unit));
} else {
v = value->data.dim.len;
}
diff --git a/src/select/unit.c b/src/select/unit.c
new file mode 100644
index 0000000..f9ecf83
--- /dev/null
+++ b/src/select/unit.c
@@ -0,0 +1,498 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include <libcss/stylesheet.h>
+
+#include "utils/utils.h"
+
+#include "propget.h"
+#include "unit.h"
+
+/**
+ * Map viewport-relative length units to either vh or vw.
+ *
+ * Non-viewport-relative units are unchanged.
+ *
+ * \param[in] style Reference style.
+ * \param[in] viewport_height Viewport height in px.
+ * \param[in] viewport_width Viewport width in px.
+ * \param[in] unit Unit to map.
+ * \return the mapped unit.
+ */
+static inline css_unit css_unit__map_viewport_units(
+ const css_computed_style *style,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width,
+ const css_unit unit)
+{
+ switch (unit) {
+ case CSS_UNIT_VI:
+ return (style != NULL && get_writing_mode(style) !=
+ CSS_WRITING_MODE_HORIZONTAL_TB) ?
+ CSS_UNIT_VH : CSS_UNIT_VW;
+
+ case CSS_UNIT_VB:
+ return (style != NULL && get_writing_mode(style) !=
+ CSS_WRITING_MODE_HORIZONTAL_TB) ?
+ CSS_UNIT_VW : CSS_UNIT_VH;
+
+ case CSS_UNIT_VMIN:
+ return (viewport_height < viewport_width) ?
+ CSS_UNIT_VH : CSS_UNIT_VW;
+
+ case CSS_UNIT_VMAX:
+ return (viewport_height > viewport_width) ?
+ CSS_UNIT_VH : CSS_UNIT_VW;
+
+ default:
+ return unit;
+ }
+}
+
+/**
+ * Convert an absolute length to points (pt).
+ *
+ * \param[in] style Style to get font-size from, or NULL.
+ * \param[in] viewport_height Client viewport height.
+ * \param[in] viewport_width Client viewport width.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return length in points (pt).
+ */
+static inline css_fixed css_unit__absolute_len2pt(
+ const css_computed_style *style,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width,
+ const css_fixed length,
+ const css_unit unit)
+{
+ /* Length must not be relative */
+ assert(unit != CSS_UNIT_EM &&
+ unit != CSS_UNIT_EX &&
+ unit != CSS_UNIT_CH &&
+ unit != CSS_UNIT_REM);
+
+ switch (css_unit__map_viewport_units(style,
+ viewport_height,
+ viewport_width,
+ unit)) {
+ case CSS_UNIT_PX:
+ return FDIV(FMUL(length, F_72), F_96);
+
+ case CSS_UNIT_IN:
+ return FMUL(length, F_72);
+
+ case CSS_UNIT_CM:
+ return FMUL(length, FDIV(F_72, FLTTOFIX(2.54)));
+
+ case CSS_UNIT_MM:
+ return FMUL(length, FDIV(F_72, FLTTOFIX(25.4)));
+
+ case CSS_UNIT_Q:
+ return FMUL(length, FDIV(F_72, FLTTOFIX(101.6)));
+
+ case CSS_UNIT_PT:
+ return length;
+
+ case CSS_UNIT_PC:
+ return FMUL(length, INTTOFIX(12));
+
+ case CSS_UNIT_VH:
+ return FDIV(FMUL(FDIV(FMUL(length, viewport_height), F_100),
+ F_72), F_96);
+
+ case CSS_UNIT_VW:
+ return FDIV(FMUL(FDIV(FMUL(length, viewport_width), F_100),
+ F_72), F_96);
+
+ default:
+ return 0;
+ }
+}
+
+/* Exported function, documented in unit.h. */
+css_fixed css_unit_font_size_len2pt(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ return css_unit__absolute_len2pt(
+ ctx->ref_style,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ length,
+ unit);
+}
+
+/**
+ * Get font size from a style in CSS pixels.
+ *
+ * The style should have font size in absolute units.
+ *
+ * \param[in] style Style to get font-size from, or NULL.
+ * \param[in] font_size_default Client font size for NULL style.
+ * \param[in] font_size_minimum Client minimum font size clamp.
+ * \param[in] viewport_height Client viewport height.
+ * \param[in] viewport_width Client viewport width.
+ * \return font-size in CSS pixels.
+ */
+static inline css_fixed css_unit__font_size_px(
+ const css_computed_style *style,
+ const css_fixed font_size_default,
+ const css_fixed font_size_minimum,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width)
+{
+ css_fixed font_length = 0;
+ css_unit font_unit = CSS_UNIT_PT;
+
+ if (style == NULL) {
+ return font_size_default;
+ }
+
+ get_font_size(style, &font_length, &font_unit);
+
+ if (font_unit != CSS_UNIT_PX) {
+ font_length = css_unit__absolute_len2pt(style,
+ viewport_height,
+ viewport_width,
+ font_length,
+ font_unit);
+
+ /* Convert from pt to CSS pixels.*/
+ font_length = FDIV(FMUL(font_length, F_96), F_72);
+ }
+
+ /* Clamp to configured minimum */
+ if (font_length < font_size_minimum) {
+ font_length = font_size_minimum;
+ }
+
+ return font_length;
+}
+
+/**
+ * Get the number of CSS pixels for a given unit.
+ *
+ * \param[in] measure Client callback for font measuring.
+ * \param[in] ref_style Reference style. (Element or parent, or NULL).
+ * \param[in] root_style Root element style or NULL.
+ * \param[in] font_size_default Client default font size in CSS pixels.
+ * \param[in] font_size_minimum Client minimum font size in CSS pixels.
+ * \param[in] viewport_height Viewport height in CSS pixels.
+ * \param[in] viewport_width Viewport width in CSS pixels.
+ * \param[in] unit The unit to convert from.
+ * \param[in] pw Client private word for measure callback.
+ * \return Number of CSS pixels equivalent to the given unit.
+ */
+static inline css_fixed css_unit__px_per_unit(
+ const css_unit_len_measure measure,
+ const css_computed_style *ref_style,
+ const css_computed_style *root_style,
+ const css_fixed font_size_default,
+ const css_fixed font_size_minimum,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width,
+ const css_unit unit,
+ void *pw)
+{
+ switch (css_unit__map_viewport_units(
+ ref_style,
+ viewport_height,
+ viewport_width,
+ unit)) {
+ case CSS_UNIT_EM:
+ return css_unit__font_size_px(
+ ref_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width);
+
+ case CSS_UNIT_EX:
+ if (measure != NULL) {
+ return measure(pw, ref_style, CSS_UNIT_EX);
+ }
+ return FMUL(css_unit__font_size_px(
+ ref_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width), FLTTOFIX(0.6));
+
+ case CSS_UNIT_CH:
+ if (measure != NULL) {
+ return measure(pw, ref_style, CSS_UNIT_CH);
+ }
+ return FMUL(css_unit__font_size_px(
+ ref_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width), FLTTOFIX(0.4));
+
+ case CSS_UNIT_PX:
+ return F_1;
+
+ case CSS_UNIT_IN:
+ return F_96;
+
+ case CSS_UNIT_CM:
+ return FDIV(F_96, FLTTOFIX(2.54));
+
+ case CSS_UNIT_MM:
+ return FDIV(F_96, FLTTOFIX(25.4));
+
+ case CSS_UNIT_Q:
+ return FDIV(F_96, FLTTOFIX(101.6));
+
+ case CSS_UNIT_PT:
+ return FDIV(F_96, F_72);
+
+ case CSS_UNIT_PC:
+ return FDIV(F_96, INTTOFIX(6));
+
+ case CSS_UNIT_REM:
+ return css_unit__font_size_px(
+ root_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width);
+
+ case CSS_UNIT_VH:
+ return FDIV(viewport_width, F_100);
+
+ case CSS_UNIT_VW:
+ return FDIV(viewport_height, F_100);
+
+ default:
+ return 0;
+ }
+}
+
+/* Exported function, documented in unit.h. */
+css_fixed css_unit_len2px_mq(
+ const css_media *media,
+ const css_fixed length,
+ const css_unit unit)
+{
+ /* In the media query context there is no reference or root element
+ * style, so these are hardcoded to NULL. */
+ css_fixed px_per_unit = css_unit__px_per_unit(
+ NULL,
+ NULL,
+ NULL,
+ media->client_font_size,
+ INTTOFIX(0),
+ media->height,
+ media->width,
+ unit,
+ NULL);
+
+ /* Ensure we round px_per_unit to the nearest whole number of pixels:
+ * the use of FIXTOINT() below will truncate. */
+ px_per_unit += F_0_5;
+
+ /* Calculate total number of pixels */
+ return FMUL(length, TRUNCATEFIX(px_per_unit));
+}
+
+/* Exported function, documented in unit.h. */
+css_fixed css_unit_len2css_px(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ css_fixed px_per_unit = css_unit__px_per_unit(
+ ctx->measure,
+ ctx->ref_style,
+ ctx->root_style,
+ ctx->font_size_default,
+ ctx->font_size_minimum,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ unit,
+ ctx->pw);
+
+ /* Ensure we round px_per_unit to the nearest whole number of pixels:
+ * the use of FIXTOINT() below will truncate. */
+ px_per_unit += F_0_5;
+
+ /* Calculate total number of pixels */
+ return FMUL(length, TRUNCATEFIX(px_per_unit));
+}
+
+/* Exported function, documented in unit.h. */
+css_fixed css_unit_len2device_px(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ css_fixed px_per_unit = css_unit__px_per_unit(
+ ctx->measure,
+ ctx->ref_style,
+ ctx->root_style,
+ ctx->font_size_default,
+ ctx->font_size_minimum,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ unit,
+ ctx->pw);
+
+ px_per_unit = css_unit_css2device_px(px_per_unit, ctx->device_dpi);
+
+ /* Ensure we round px_per_unit to the nearest whole number of pixels:
+ * the use of FIXTOINT() below will truncate. */
+ px_per_unit += F_0_5;
+
+ /* Calculate total number of pixels */
+ return FMUL(length, TRUNCATEFIX(px_per_unit));
+}
+
+/**
+ * Get font size from a computed style.
+ *
+ * The computed style will have font-size with an absolute unit.
+ * If no computed style is given, the client default font-size will be returned.
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] style The style to get the font-size for, or NULL.
+ * \return The font size in absolute units.
+ */
+static inline css_hint_length css_unit__get_font_size(
+ const css_unit_len_ctx *ctx,
+ const css_computed_style *style)
+{
+ css_hint_length size;
+
+ if (style == NULL) {
+ size.value = ctx->font_size_default;
+ size.unit = CSS_UNIT_PX;
+ } else {
+ enum css_font_size_e status = get_font_size(
+ style, &size.value, &size.unit);
+
+ UNUSED(status);
+
+ assert(status == CSS_FONT_SIZE_DIMENSION);
+ assert(size.unit != CSS_UNIT_EM);
+ assert(size.unit != CSS_UNIT_EX);
+ assert(size.unit != CSS_UNIT_PCT);
+ }
+
+ return size;
+}
+
+/* Exported function, documented in unit.h. */
+css_error css_unit_compute_absolute_font_size(
+ const css_unit_len_ctx *ctx,
+ css_hint *size)
+{
+ css_hint_length ref_len;
+
+ assert(size->status != CSS_FONT_SIZE_INHERIT);
+
+ switch (size->status) {
+ case CSS_FONT_SIZE_XX_SMALL: /* Fall-through. */
+ case CSS_FONT_SIZE_X_SMALL: /* Fall-through. */
+ case CSS_FONT_SIZE_SMALL: /* Fall-through. */
+ case CSS_FONT_SIZE_MEDIUM: /* Fall-through. */
+ case CSS_FONT_SIZE_LARGE: /* Fall-through. */
+ case CSS_FONT_SIZE_X_LARGE: /* Fall-through. */
+ case CSS_FONT_SIZE_XX_LARGE:
+ {
+ static const css_fixed factors[CSS_FONT_SIZE_XX_LARGE] = {
+ [CSS_FONT_SIZE_XX_SMALL - 1] = FLTTOFIX(0.5625),
+ [CSS_FONT_SIZE_X_SMALL - 1] = FLTTOFIX(0.6250),
+ [CSS_FONT_SIZE_SMALL - 1] = FLTTOFIX(0.8125),
+ [CSS_FONT_SIZE_MEDIUM - 1] = FLTTOFIX(1.0000),
+ [CSS_FONT_SIZE_LARGE - 1] = FLTTOFIX(1.1250),
+ [CSS_FONT_SIZE_X_LARGE - 1] = FLTTOFIX(1.5000),
+ [CSS_FONT_SIZE_XX_LARGE - 1] = FLTTOFIX(2.0000),
+ };
+ assert(CSS_FONT_SIZE_INHERIT == 0);
+ assert(CSS_FONT_SIZE_XX_SMALL == 1);
+
+ size->data.length.value = FMUL(factors[size->status - 1],
+ ctx->font_size_default);
+ size->data.length.unit = CSS_UNIT_PX;
+ size->status = CSS_FONT_SIZE_DIMENSION;
+ break;
+ }
+ case CSS_FONT_SIZE_LARGER:
+ ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
+ size->data.length.value = FMUL(ref_len.value, FLTTOFIX(1.2));
+ size->data.length.unit = ref_len.unit;
+ size->status = CSS_FONT_SIZE_DIMENSION;
+ break;
+
+ case CSS_FONT_SIZE_SMALLER:
+ ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
+ size->data.length.value = FDIV(ref_len.value, FLTTOFIX(1.2));
+ size->data.length.unit = ref_len.unit;
+ size->status = CSS_FONT_SIZE_DIMENSION;
+ break;
+
+ case CSS_FONT_SIZE_DIMENSION:
+ /* Convert any relative units to absolute. */
+ switch (size->data.length.unit) {
+ case CSS_UNIT_PCT:
+ ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
+ size->data.length.value = FDIV(
+ FMUL(size->data.length.value,
+ ref_len.value), INTTOFIX(100));
+ size->data.length.unit = ref_len.unit;
+ break;
+
+ case CSS_UNIT_EM: /* Fall-through */
+ case CSS_UNIT_EX: /* Fall-through */
+ case CSS_UNIT_CH:
+ /* Parent relative units. */
+ ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
+
+ size->data.length.unit = ref_len.unit;
+ size->data.length.value = FMUL(size->data.length.value,
+ ref_len.value);
+
+ switch (size->data.length.unit) {
+ case CSS_UNIT_EX:
+ size->data.length.value = FMUL(
+ size->data.length.value,
+ FLTTOFIX(0.6));
+ break;
+
+ case CSS_UNIT_CH:
+ size->data.length.value = FMUL(
+ size->data.length.value,
+ FLTTOFIX(0.4));
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case CSS_UNIT_REM:
+ /* Root element relative units. */
+ ref_len = css_unit__get_font_size(ctx, ctx->root_style);
+
+ size->data.length.unit = ref_len.unit;
+ size->data.length.value = FMUL(size->data.length.value,
+ ref_len.value);
+ break;
+
+ default:
+ break;
+ }
+ default:
+ break;
+ }
+
+ return CSS_OK;
+}
diff --git a/src/select/unit.h b/src/select/unit.h
new file mode 100644
index 0000000..738c181
--- /dev/null
+++ b/src/select/unit.h
@@ -0,0 +1,169 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#ifndef css_select_unit_h_
+#define css_select_unit_h_
+
+/**
+ * Client callback for font measuring.
+ *
+ * \param[in] pw Client data.
+ * \param[in] style Style to measure font for, or NULL.
+ * \param[in] unit Either CSS_UNIT_EX, or CSS_UNIT_CH.
+ * \return length in CSS pixels.
+ */
+typedef css_fixed (*css_unit_len_measure)(
+ void *pw,
+ const css_computed_style *style,
+ const css_unit unit);
+
+/**
+ * LibCSS unit conversion context.
+ *
+ * The client callback is optional. It is used for measuring "ch"
+ * (glyph '0' advance) and "ex" (height of the letter 'x') units.
+ * If a NULL pointer is given, LibCSS will use a fixed scaling of
+ * the "em" unit.
+ */
+typedef struct css_unit_len_ctx {
+ /**
+ * Viewport width in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_width;
+ /**
+ * Viewport height in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_height;
+ /**
+ * Client default font size in CSS pixels.
+ */
+ css_fixed font_size_default;
+ /**
+ * Client minimum font size in CSS pixels. May be zero.
+ */
+ css_fixed font_size_minimum;
+ /**
+ * DPI of the device the style is selected for.
+ */
+ css_fixed device_dpi;
+ /**
+ * Reference style. Most of the time, this is the element's style.
+ * When converting a length for a typographical property, such as
+ * font-size, then this should be the parent node. If the node has
+ * no parent then this may be NULL.
+ */
+ const css_computed_style *ref_style;
+ /**
+ * Computed style for the document root element.
+ * May be NULL if unit is not rem.
+ */
+ const css_computed_style *root_style;
+ /**
+ * Client private word for measure callback.
+ */
+ void *pw;
+ /**
+ * Client callback for font measuring.
+ */
+ const css_unit_len_measure measure;
+} css_unit_len_ctx;
+
+/**
+ * Convert css pixels to physical pixels.
+ *
+ * \param[in] css_pixels Length in css pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in device pixels.
+ */
+static inline css_fixed css_unit_css2device_px(
+ const css_fixed css_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(css_pixels, device_dpi), F_96);
+}
+
+/**
+ * Convert device pixels to css pixels.
+ *
+ * \param[in] device_pixels Length in physical pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in css pixels.
+ */
+static inline css_fixed css_unit_device2css_px(
+ const css_fixed device_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(device_pixels, F_96), device_dpi);
+}
+
+/**
+ * Convert a length to points (pt).
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in points.
+ */
+css_fixed css_unit_font_size_len2pt(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to CSS pixels.
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in CSS pixels.
+ */
+css_fixed css_unit_len2css_px(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to device pixels.
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in device pixels.
+ */
+css_fixed css_unit_len2device_px(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to CSS pixels for a media query context.
+ *
+ * \param[in] media Client media specification.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in CSS pixels.
+ */
+css_fixed css_unit_len2px_mq(
+ const css_media *media,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert relative font size units to absolute units.
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in,out] size The length to convert.
+ * \return CSS_OK on success, or appropriate error otherwise.
+ */
+css_error css_unit_compute_absolute_font_size(
+ const css_unit_len_ctx *ctx,
+ css_hint *size);
+
+#endif
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=e7a7b547c370d0fa51e8...
commit e7a7b547c370d0fa51e8e55282aceb2fe9f19039
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Units: Remove units that nobody supports.
diff --git a/docs/Bytecode b/docs/Bytecode
index d691923..4914e65 100644
--- a/docs/Bytecode
+++ b/docs/Bytecode
@@ -44,19 +44,16 @@ Length is a 32bit numeric value (as described above) and unit is as follows:
00000101 => mm
00000110 => pt
00000111 => pc
- 00001000 => cap
- 00001001 => ch
- 00001010 => ic
- 00001011 => rem
- 00001100 => lh
- 00001101 => rlh
- 00001110 => vh
- 00001111 => vw
- 00010000 => vi
- 00010001 => vb
- 00010010 => vmin
- 00010011 => vmax
- 00010100 => q
+ 00001000 => ch
+ 00001001 => rem
+ 00001010 => lh
+ 00001011 => vh
+ 00001100 => vw
+ 00001101 => vi
+ 00001110 => vb
+ 00001111 => vmin
+ 00010000 => vmax
+ 00010001 => q
bit 9 set => percentage unit
bits 9-31: MBZ
diff --git a/include/libcss/types.h b/include/libcss/types.h
index d8ac494..1186c6f 100644
--- a/include/libcss/types.h
+++ b/include/libcss/types.h
@@ -88,19 +88,16 @@ typedef enum css_unit {
CSS_UNIT_MM = 0x05,
CSS_UNIT_PT = 0x06,
CSS_UNIT_PC = 0x07,
- CSS_UNIT_CAP = 0x08,
- CSS_UNIT_CH = 0x09,
- CSS_UNIT_IC = 0x0a,
- CSS_UNIT_REM = 0x0b,
- CSS_UNIT_LH = 0x0c,
- CSS_UNIT_RLH = 0x0d,
- CSS_UNIT_VH = 0x0e,
- CSS_UNIT_VW = 0x0f,
- CSS_UNIT_VI = 0x10,
- CSS_UNIT_VB = 0x11,
- CSS_UNIT_VMIN = 0x12,
- CSS_UNIT_VMAX = 0x13,
- CSS_UNIT_Q = 0x14,
+ CSS_UNIT_CH = 0x08,
+ CSS_UNIT_REM = 0x09,
+ CSS_UNIT_LH = 0x0a,
+ CSS_UNIT_VH = 0x0b,
+ CSS_UNIT_VW = 0x0c,
+ CSS_UNIT_VI = 0x0d,
+ CSS_UNIT_VB = 0x0e,
+ CSS_UNIT_VMIN = 0x0f,
+ CSS_UNIT_VMAX = 0x10,
+ CSS_UNIT_Q = 0x11,
CSS_UNIT_PCT = 0x15, /* Percentage */
@@ -116,7 +113,7 @@ typedef enum css_unit {
} css_unit;
/**
- * Media orienations
+ * Media orientations
*/
typedef enum css_media_orientation {
CSS_MEDIA_ORIENTATION_PORTRAIT = 0,
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 7518281..7f5ea9d 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -34,19 +34,16 @@ typedef enum unit {
UNIT_MM = (1u << 8) + 5,
UNIT_PT = (1u << 8) + 6,
UNIT_PC = (1u << 8) + 7,
- UNIT_CAP = (1u << 8) + 8,
- UNIT_CH = (1u << 8) + 9,
- UNIT_IC = (1u << 8) + 10,
- UNIT_REM = (1u << 8) + 11,
- UNIT_LH = (1u << 8) + 12,
- UNIT_RLH = (1u << 8) + 13,
- UNIT_VH = (1u << 8) + 14,
- UNIT_VW = (1u << 8) + 15,
- UNIT_VI = (1u << 8) + 16,
- UNIT_VB = (1u << 8) + 17,
- UNIT_VMIN = (1u << 8) + 18,
- UNIT_VMAX = (1u << 8) + 19,
- UNIT_Q = (1u << 8) + 20,
+ UNIT_CH = (1u << 8) + 8,
+ UNIT_REM = (1u << 8) + 9,
+ UNIT_LH = (1u << 8) + 10,
+ UNIT_VH = (1u << 8) + 11,
+ UNIT_VW = (1u << 8) + 12,
+ UNIT_VI = (1u << 8) + 13,
+ UNIT_VB = (1u << 8) + 14,
+ UNIT_VMIN = (1u << 8) + 15,
+ UNIT_VMAX = (1u << 8) + 16,
+ UNIT_Q = (1u << 8) + 17,
UNIT_PCT = (1 << 9),
diff --git a/src/parse/properties/font.c b/src/parse/properties/font.c
index 681c613..5010242 100644
--- a/src/parse/properties/font.c
+++ b/src/parse/properties/font.c
@@ -27,12 +27,9 @@ static inline uint32_t css__to_parse_unit(css_unit u)
case CSS_UNIT_MM: return UNIT_MM;
case CSS_UNIT_PT: return UNIT_PT;
case CSS_UNIT_PC: return UNIT_PC;
- case CSS_UNIT_CAP: return UNIT_CAP;
case CSS_UNIT_CH: return UNIT_CH;
- case CSS_UNIT_IC: return UNIT_IC;
case CSS_UNIT_REM: return UNIT_REM;
case CSS_UNIT_LH: return UNIT_LH;
- case CSS_UNIT_RLH: return UNIT_RLH;
case CSS_UNIT_VH: return UNIT_VH;
case CSS_UNIT_VW: return UNIT_VW;
case CSS_UNIT_VI: return UNIT_VI;
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 707a22b..1e184f8 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1032,12 +1032,8 @@ css_error css__parse_unit_keyword(const char *ptr, size_t len, uint32_t *unit)
*unit = UNIT_DEG;
else if (strncasecmp(ptr, "rad", 3) == 0)
*unit = UNIT_RAD;
- else if (strncasecmp(ptr, "cap", 3) == 0)
- *unit = UNIT_CAP;
else if (strncasecmp(ptr, "rem", 3) == 0)
*unit = UNIT_REM;
- else if (strncasecmp(ptr, "rlh", 3) == 0)
- *unit = UNIT_RLH;
else if (strncasecmp(ptr, "dpi", 3) == 0)
*unit = UNIT_DPI;
else
@@ -1065,8 +1061,6 @@ css_error css__parse_unit_keyword(const char *ptr, size_t len, uint32_t *unit)
*unit = UNIT_PC;
else if (strncasecmp(ptr, "ch", 2) == 0)
*unit = UNIT_CH;
- else if (strncasecmp(ptr, "ic", 2) == 0)
- *unit = UNIT_IC;
else if (strncasecmp(ptr, "lh", 2) == 0)
*unit = UNIT_LH;
else if (strncasecmp(ptr, "vh", 2) == 0)
diff --git a/src/select/helpers.h b/src/select/helpers.h
index ba2e3be..19ff7de 100644
--- a/src/select/helpers.h
+++ b/src/select/helpers.h
@@ -22,12 +22,9 @@ static inline css_unit css__to_css_unit(uint32_t u)
case UNIT_MM: return CSS_UNIT_MM;
case UNIT_PT: return CSS_UNIT_PT;
case UNIT_PC: return CSS_UNIT_PC;
- case UNIT_CAP: return CSS_UNIT_CAP;
case UNIT_CH: return CSS_UNIT_CH;
- case UNIT_IC: return CSS_UNIT_IC;
case UNIT_REM: return CSS_UNIT_REM;
case UNIT_LH: return CSS_UNIT_LH;
- case UNIT_RLH: return CSS_UNIT_RLH;
case UNIT_VH: return CSS_UNIT_VH;
case UNIT_VW: return CSS_UNIT_VW;
case UNIT_VI: return CSS_UNIT_VI;
diff --git a/src/select/mq.h b/src/select/mq.h
index 79303e9..6f98387 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -42,9 +42,7 @@ static inline css_fixed css_len2px(
switch (unit) {
case CSS_UNIT_EM:
case CSS_UNIT_EX:
- case CSS_UNIT_CAP:
case CSS_UNIT_CH:
- case CSS_UNIT_IC:
{
px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
@@ -53,15 +51,9 @@ static inline css_fixed css_len2px(
case CSS_UNIT_EX:
px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
break;
- case CSS_UNIT_CAP:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.9));
- break;
case CSS_UNIT_CH:
px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
break;
- case CSS_UNIT_IC:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(1.1));
- break;
default:
break;
}
@@ -90,9 +82,6 @@ static inline css_fixed css_len2px(
case CSS_UNIT_REM:
px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
break;
- case CSS_UNIT_RLH:
- px_per_unit = media->client_line_height;
- break;
case CSS_UNIT_VH:
px_per_unit = FDIV(media->height, F_100);
break;
diff --git a/test/data/parse2/units.dat b/test/data/parse2/units.dat
index 1052dc5..800df75 100644
--- a/test/data/parse2/units.dat
+++ b/test/data/parse2/units.dat
@@ -70,14 +70,6 @@
#reset
#data
-* { width: 10cap; }
-#errors
-#expected
-| *
-| width: 10cap
-#reset
-
-#data
* { width: 10ch; }
#errors
#expected
@@ -86,14 +78,6 @@
#reset
#data
-* { width: 10ic; }
-#errors
-#expected
-| *
-| width: 10ic
-#reset
-
-#data
* { width: 10rem; }
#errors
#expected
@@ -110,14 +94,6 @@
#reset
#data
-* { width: 10rlh; }
-#errors
-#expected
-| *
-| width: 10rlh
-#reset
-
-#data
* { width: 10vh; }
#errors
#expected
diff --git a/test/data/select/tests1.dat b/test/data/select/tests1.dat
index 1a91e82..eaf37d7 100644
--- a/test/data/select/tests1.dat
+++ b/test/data/select/tests1.dat
@@ -12419,7 +12419,7 @@ z-index: auto
#tree
| div*
#ua
-div { width: 10cap; }
+div { width: 10em; }
#errors
#expected
align-content: stretch
@@ -12519,7 +12519,7 @@ unicode-bidi: normal
vertical-align: baseline
visibility: visible
white-space: normal
-width: 10cap
+width: 10em
word-spacing: normal
writing-mode: horizontal-tb
z-index: auto
@@ -12637,7 +12637,7 @@ z-index: auto
#tree
| div*
#ua
-div { width: 10ic; }
+div { width: 10ch; }
#errors
#expected
align-content: stretch
@@ -12737,7 +12737,7 @@ unicode-bidi: normal
vertical-align: baseline
visibility: visible
white-space: normal
-width: 10ic
+width: 10ch
word-spacing: normal
writing-mode: horizontal-tb
z-index: auto
@@ -12964,7 +12964,7 @@ z-index: auto
#tree
| div*
#ua
-div { width: 10rlh; }
+div { width: 10rem; }
#errors
#expected
align-content: stretch
@@ -13064,7 +13064,7 @@ unicode-bidi: normal
vertical-align: baseline
visibility: visible
white-space: normal
-width: 10rlh
+width: 10rem
word-spacing: normal
writing-mode: horizontal-tb
z-index: auto
diff --git a/test/dump.h b/test/dump.h
index d67bb2a..79819e0 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -584,24 +584,15 @@ static void dump_unit(css_fixed val, uint32_t unit, char **ptr)
case UNIT_PC:
*ptr += sprintf(*ptr, "pc");
break;
- case UNIT_CAP:
- *ptr += sprintf(*ptr, "cap");
- break;
case UNIT_CH:
*ptr += sprintf(*ptr, "ch");
break;
- case UNIT_IC:
- *ptr += sprintf(*ptr, "ic");
- break;
case UNIT_REM:
*ptr += sprintf(*ptr, "rem");
break;
case UNIT_LH:
*ptr += sprintf(*ptr, "lh");
break;
- case UNIT_RLH:
- *ptr += sprintf(*ptr, "rlh");
- break;
case UNIT_VH:
*ptr += sprintf(*ptr, "vh");
break;
diff --git a/test/dump_computed.h b/test/dump_computed.h
index b0c8bda..8ac6424 100644
--- a/test/dump_computed.h
+++ b/test/dump_computed.h
@@ -105,24 +105,15 @@ static size_t dump_css_unit(css_fixed val, css_unit unit, char *ptr, size_t len)
case CSS_UNIT_PC:
ret += snprintf(ptr + ret, len - ret, "pc");
break;
- case CSS_UNIT_CAP:
- ret += snprintf(ptr + ret, len - ret, "cap");
- break;
case CSS_UNIT_CH:
ret += snprintf(ptr + ret, len - ret, "ch");
break;
- case CSS_UNIT_IC:
- ret += snprintf(ptr + ret, len - ret, "ic");
- break;
case CSS_UNIT_REM:
ret += snprintf(ptr + ret, len - ret, "rem");
break;
case CSS_UNIT_LH:
ret += snprintf(ptr + ret, len - ret, "lh");
break;
- case CSS_UNIT_RLH:
- ret += snprintf(ptr + ret, len - ret, "rlh");
- break;
case CSS_UNIT_VH:
ret += snprintf(ptr + ret, len - ret, "vh");
break;
-----------------------------------------------------------------------
Summary of changes:
--
Cascading Style Sheets library
2 years
libcss: branch tlsa/units updated. release/0.9.1-24-gecf42af
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/ecf42afc3329b03ee642ed...
...commit http://git.netsurf-browser.org/libcss.git/commit/ecf42afc3329b03ee642ede8...
...tree http://git.netsurf-browser.org/libcss.git/tree/ecf42afc3329b03ee642ede84f...
The branch, tlsa/units has been updated
discards 8e24e02b38b8189358e53aa8122abdbfe659e229 (commit)
discards d0e2e7e1466b55b777c7ad49f4d9d98e58fc9592 (commit)
discards aff5cc14f36b14590acc1974ed66529922bef134 (commit)
discards d850386d6a7a57e22b536c7e481ae9b8e38242a1 (commit)
discards 7a9dc81e71de235646af716f4482dc713520109f (commit)
discards 9e46e0f245f242c6f1b707016670caca2b57d428 (commit)
discards d4fef3c6ff5339888c7519fe7a2071c8e28da8f5 (commit)
via ecf42afc3329b03ee642ede84f9ba224d2aff1e1 (commit)
via 65d4fd6e83d421e7fa7a8c7df44d01797e3c69ae (commit)
via 6cd205329373efe5a1629518c2875724cc79dce3 (commit)
via 0cf10a040aea028c7dc81cf353da7a7af5331076 (commit)
via 57fa3608e13accc24a45e5d7801a381212c2ff22 (commit)
via f752713d07424217170c6fbf85789bd58d92f924 (commit)
via a0a52eb724f62d0df68c104108526e84148710bb (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (8e24e02b38b8189358e53aa8122abdbfe659e229)
\
N -- N -- N (ecf42afc3329b03ee642ede84f9ba224d2aff1e1)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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=ecf42afc3329b03ee642...
commit ecf42afc3329b03ee642ede84f9ba224d2aff1e1
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Selection: Don't duplicate unit conversion members in media descriptor.
diff --git a/examples/example1.c b/examples/example1.c
index 6135793..1d2462c 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -103,7 +103,7 @@ static css_error set_libcss_node_data(void *pw, void *n,
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
-static css_unit_len_ctx uint_len_ctx = {
+static css_unit_ctx uint_len_ctx = {
.viewport_width = 800 * (1 << CSS_RADIX_POINT),
.viewport_height = 600 * (1 << CSS_RADIX_POINT),
.font_size_default = 16 * (1 << CSS_RADIX_POINT),
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index 1587d78..30e369b 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -82,7 +82,7 @@ css_error css_computed_style_destroy(css_computed_style *style);
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- const css_unit_len_ctx *unit_len_ctx,
+ const css_unit_ctx *unit_ctx,
css_computed_style **restrict result);
/******************************************************************************
diff --git a/include/libcss/select.h b/include/libcss/select.h
index bfaf531..25317e5 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -219,14 +219,16 @@ css_error css_select_default_style(css_select_ctx *ctx,
css_select_handler *handler, void *pw,
css_computed_style **style);
css_error css_select_style(css_select_ctx *ctx, void *node,
- const css_unit_len_ctx *unit_len_ctx,
+ const css_unit_ctx *unit_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result);
css_error css_select_results_destroy(css_select_results *results);
css_error css_select_font_faces(css_select_ctx *ctx,
- const css_media *media, lwc_string *font_family,
+ const css_media *media,
+ const css_unit_ctx *unit_ctx,
+ lwc_string *font_family,
css_select_font_faces_results **result);
css_error css_select_font_faces_results_destroy(
css_select_font_faces_results *results);
diff --git a/include/libcss/types.h b/include/libcss/types.h
index 1186c6f..2b0dfb7 100644
--- a/include/libcss/types.h
+++ b/include/libcss/types.h
@@ -234,10 +234,6 @@ typedef struct css_media {
/* Scripting media features */
css_media_scripting scripting;
-
- /* Client details for length conversion */
- css_fixed client_font_size; /* In pt */
- css_fixed client_line_height; /* In css pixels */
} css_media;
/**
diff --git a/include/libcss/unit.h b/include/libcss/unit.h
index a847077..67194c1 100644
--- a/include/libcss/unit.h
+++ b/include/libcss/unit.h
@@ -36,7 +36,7 @@ typedef css_fixed (*css_unit_len_measure)(
* If a NULL pointer is given, LibCSS will use a fixed scaling of
* the "em" unit.
*/
-typedef struct css_unit_len_ctx {
+typedef struct css_unit_ctx {
/**
* Viewport width in CSS pixels.
* Used if unit is vh, vw, vi, vb, vmin, or vmax.
@@ -73,7 +73,7 @@ typedef struct css_unit_len_ctx {
* Optional client callback for font measuring.
*/
const css_unit_len_measure measure;
-} css_unit_len_ctx;
+} css_unit_ctx;
/**
* Convert css pixels to physical pixels.
@@ -114,7 +114,7 @@ static inline css_fixed css_unit_device2css_px(
*/
css_fixed css_unit_font_size_len2pt(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit);
@@ -129,7 +129,7 @@ css_fixed css_unit_font_size_len2pt(
*/
css_fixed css_unit_len2css_px(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit);
@@ -144,7 +144,7 @@ css_fixed css_unit_len2css_px(
*/
css_fixed css_unit_len2device_px(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit);
diff --git a/src/select/computed.c b/src/select/computed.c
index d075af9..c019590 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -248,7 +248,7 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- const css_unit_len_ctx *unit_len_ctx,
+ const css_unit_ctx *unit_ctx,
css_computed_style **restrict result)
{
css_computed_style *composed;
@@ -274,7 +274,7 @@ css_error css_computed_style_compose(
}
/* Finally, compute absolute values for everything */
- error = css__compute_absolute_values(parent, composed, unit_len_ctx);
+ error = css__compute_absolute_values(parent, composed, unit_ctx);
if (error != CSS_OK) {
return error;
}
@@ -1085,12 +1085,12 @@ uint8_t css_computed_order(const css_computed_style *style,
*
* \param parent Parent style, or NULL for tree root
* \param style Computed style to process
- * \param unit_len_ctx Client length conversion context.
+ * \param unit_ctx Client length conversion context.
* \return CSS_OK on success.
*/
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- const css_unit_len_ctx *unit_len_ctx)
+ const css_unit_ctx *unit_ctx)
{
css_hint_length *ref_length = NULL;
css_hint psize, size, ex_size;
@@ -1112,8 +1112,8 @@ css_error css__compute_absolute_values(const css_computed_style *parent,
&size.data.length.unit);
error = css_unit_compute_absolute_font_size(ref_length,
- unit_len_ctx->root_style,
- unit_len_ctx->font_size_default,
+ unit_ctx->root_style,
+ unit_ctx->font_size_default,
&size);
if (error != CSS_OK)
return error;
@@ -1131,8 +1131,8 @@ css_error css__compute_absolute_values(const css_computed_style *parent,
error = css_unit_compute_absolute_font_size(
&size.data.length,
- unit_len_ctx->root_style,
- unit_len_ctx->font_size_default,
+ unit_ctx->root_style,
+ unit_ctx->font_size_default,
&ex_size);
if (error != CSS_OK)
return error;
diff --git a/src/select/computed.h b/src/select/computed.h
index 8b33405..a4bd23d 100644
--- a/src/select/computed.h
+++ b/src/select/computed.h
@@ -37,6 +37,6 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- const css_unit_len_ctx *unit_len_ctx);
+ const css_unit_ctx *unit_ctx);
#endif
diff --git a/src/select/hash.c b/src/select/hash.c
index 4dedec9..16aebf7 100644
--- a/src/select/hash.c
+++ b/src/select/hash.c
@@ -370,7 +370,7 @@ css_error css__selector_hash_find(css_selector_hash *hash,
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
@@ -449,6 +449,7 @@ css_error css__selector_hash_find_by_class(css_selector_hash *hash,
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -529,6 +530,7 @@ css_error css__selector_hash_find_by_id(css_selector_hash *hash,
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -579,7 +581,7 @@ css_error css__selector_hash_find_universal(css_selector_hash *hash,
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
@@ -922,7 +924,7 @@ css_error _iterate_elements(
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
@@ -982,6 +984,7 @@ css_error _iterate_classes(
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -1043,6 +1046,7 @@ css_error _iterate_ids(
req->uni) &&
mq_rule_good_for_media(
head->sel->rule,
+ req->unit_ctx,
req->media)) {
/* Found a match */
break;
@@ -1086,7 +1090,7 @@ css_error _iterate_universal(
head->sel_chain_bloom,
req->node_bloom) &&
mq_rule_good_for_media(head->sel->rule,
- req->media)) {
+ req->unit_ctx, req->media)) {
/* Found a match */
break;
}
diff --git a/src/select/hash.h b/src/select/hash.h
index aecf15a..df4102f 100644
--- a/src/select/hash.h
+++ b/src/select/hash.h
@@ -10,6 +10,7 @@
#include <libwapcaplet/libwapcaplet.h>
+#include <libcss/unit.h>
#include <libcss/errors.h>
#include <libcss/functypes.h>
@@ -26,6 +27,7 @@ struct css_hash_selection_requirments {
lwc_string *id; /* Name of id, or NULL */
lwc_string *uni; /* Universal element string "*" */
const css_media *media; /* Media spec we're selecting for */
+ const css_unit_ctx *unit_ctx; /* Document unit conversion context. */
const css_bloom *node_bloom; /* Node's bloom filter */
};
diff --git a/src/select/mq.h b/src/select/mq.h
index 080a6ba..a012a7b 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -16,7 +16,7 @@ static inline bool mq_match_feature_range_length_op1(
css_mq_feature_op op,
const css_mq_value *value,
const css_fixed client_len,
- const css_media *media)
+ const css_unit_ctx *unit_ctx)
{
css_fixed v;
@@ -25,7 +25,7 @@ static inline bool mq_match_feature_range_length_op1(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_unit_len2px_mq(media,
+ v = css_unit_len2px_mq(unit_ctx,
value->data.dim.len,
css__to_css_unit(value->data.dim.unit));
} else {
@@ -48,7 +48,7 @@ static inline bool mq_match_feature_range_length_op2(
css_mq_feature_op op,
const css_mq_value *value,
const css_fixed client_len,
- const css_media *media)
+ const css_unit_ctx *unit_ctx)
{
css_fixed v;
@@ -60,7 +60,7 @@ static inline bool mq_match_feature_range_length_op2(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_unit_len2px_mq(media,
+ v = css_unit_len2px_mq(unit_ctx,
value->data.dim.len,
css__to_css_unit(value->data.dim.unit));
} else {
@@ -81,31 +81,33 @@ static inline bool mq_match_feature_range_length_op2(
/**
* Match media query features.
*
- * \param[in] feat Condition to match.
- * \param[in] media Current media spec, to check against feat.
+ * \param[in] feat Condition to match.
+ * \param[in] unit_ctx Current unit conversion context.
+ * \param[in] media Current media spec, to check against feat.
* \return true if condition matches, otherwise false.
*/
static inline bool mq_match_feature(
const css_mq_feature *feat,
+ const css_unit_ctx *unit_ctx,
const css_media *media)
{
/* TODO: Use interned string for comparison. */
if (strcmp(lwc_string_data(feat->name), "width") == 0) {
if (!mq_match_feature_range_length_op1(feat->op, &feat->value,
- media->width, media)) {
+ media->width, unit_ctx)) {
return false;
}
return mq_match_feature_range_length_op2(feat->op2,
- &feat->value2, media->width, media);
+ &feat->value2, media->width, unit_ctx);
} else if (strcmp(lwc_string_data(feat->name), "height") == 0) {
if (!mq_match_feature_range_length_op1(feat->op, &feat->value,
- media->height, media)) {
+ media->height, unit_ctx)) {
return false;
}
return mq_match_feature_range_length_op2(feat->op2,
- &feat->value2, media->height, media);
+ &feat->value2, media->height, unit_ctx);
}
/* TODO: Look at other feature names. */
@@ -116,12 +118,14 @@ static inline bool mq_match_feature(
/**
* Match media query conditions.
*
- * \param[in] cond Condition to match.
- * \param[in] media Current media spec, to check against cond.
+ * \param[in] cond Condition to match.
+ * \param[in] unit_ctx Current unit conversion context.
+ * \param[in] media Current media spec, to check against cond.
* \return true if condition matches, otherwise false.
*/
static inline bool mq_match_condition(
const css_mq_cond *cond,
+ const css_unit_ctx *unit_ctx,
const css_media *media)
{
bool matched = !cond->op;
@@ -130,11 +134,13 @@ static inline bool mq_match_condition(
bool part_matched;
if (cond->parts[i]->type == CSS_MQ_FEATURE) {
part_matched = mq_match_feature(
- cond->parts[i]->data.feat, media);
+ cond->parts[i]->data.feat,
+ unit_ctx, media);
} else {
assert(cond->parts[i]->type == CSS_MQ_COND);
part_matched = mq_match_condition(
- cond->parts[i]->data.cond, media);
+ cond->parts[i]->data.cond,
+ unit_ctx, media);
}
if (cond->op) {
@@ -161,19 +167,22 @@ static inline bool mq_match_condition(
* If anything in the list matches, the list matches. If none match
* it doesn't match.
*
- * \param[in] m Media query list.
- * \param[in] media Current media spec, to check against m.
+ * \param[in] m Media query list.
+ * \param[in] unit_ctx Current unit conversion context.
+ * \param[in] media Current media spec, to check against m.
* \return true if media query list matches media
*/
static inline bool mq__list_match(
const css_mq_query *m,
+ const css_unit_ctx *unit_ctx,
const css_media *media)
{
for (; m != NULL; m = m->next) {
/* Check type */
if (!!(m->type & media->type) != m->negate_type) {
if (m->cond == NULL ||
- mq_match_condition(m->cond, media)) {
+ mq_match_condition(m->cond,
+ unit_ctx, media)) {
/* We have a match, no need to look further. */
return true;
}
@@ -186,11 +195,15 @@ static inline bool mq__list_match(
/**
* Test whether the rule applies for current media.
*
- * \param rule Rule to test
- * \param media Current media spec
+ * \param rule Rule to test
+ * \param unit_ctx Current unit conversion context.
+ * \param media Current media spec
* \return true iff chain's rule applies for media
*/
-static inline bool mq_rule_good_for_media(const css_rule *rule, const css_media *media)
+static inline bool mq_rule_good_for_media(
+ const css_rule *rule,
+ const css_unit_ctx *unit_ctx,
+ const css_media *media)
{
bool applies = true;
const css_rule *ancestor = rule;
@@ -199,7 +212,7 @@ static inline bool mq_rule_good_for_media(const css_rule *rule, const css_media
const css_rule_media *m = (const css_rule_media *) ancestor;
if (ancestor->type == CSS_RULE_MEDIA) {
- applies = mq__list_match(m->media, media);
+ applies = mq__list_match(m->media, unit_ctx, media);
if (applies == false) {
break;
}
diff --git a/src/select/select.c b/src/select/select.c
index 03a45fe..b050c0c 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -99,6 +99,7 @@ typedef struct css_select_font_faces_list {
typedef struct css_select_font_faces_state {
lwc_string *font_family;
const css_media *media;
+ const css_unit_ctx *unit_ctx;
css_select_font_faces_list ua_font_faces;
css_select_font_faces_list user_font_faces;
@@ -1052,12 +1053,13 @@ static void css_select__finalise_selection_state(
/**
* Initialise a selection state.
*
- * \param[in] state The selection state to initialise
- * \param[in] node The node we are selecting for.
- * \param[in] parent The node's parent node, or NULL.
- * \param[in] media The media specification we're selecting for.
- * \param[in] handler The client selection callback table.
- * \param[in] pw The client private data, passsed out to callbacks.
+ * \param[in] state The selection state to initialise
+ * \param[in] node The node we are selecting for.
+ * \param[in] parent The node's parent node, or NULL.
+ * \param[in] media The media specification we're selecting for.
+ * \param[in] unit_ctx Unit conversion context.
+ * \param[in] handler The client selection callback table.
+ * \param[in] pw The client private data, passsed out to callbacks.
* \return CSS_OK or appropriate error otherwise.
*/
static css_error css_select__initialise_selection_state(
@@ -1065,6 +1067,7 @@ static css_error css_select__initialise_selection_state(
void *node,
void *parent,
const css_media *media,
+ const css_unit_ctx *unit_ctx,
css_select_handler *handler,
void *pw)
{
@@ -1075,6 +1078,7 @@ static css_error css_select__initialise_selection_state(
memset(state, 0, sizeof(*state));
state->node = node;
state->media = media;
+ state->unit_ctx = unit_ctx;
state->handler = handler;
state->pw = pw;
state->next_reject = state->reject_cache +
@@ -1165,7 +1169,7 @@ failed:
*
* \param ctx Selection context to use
* \param node Node to select style for
- * \param unit_len_ctx Context for length unit conversions.
+ * \param unit_ctx Context for length unit conversions.
* \param media Currently active media specification
* \param inline_style Corresponding inline style for node, or NULL
* \param handler Dispatch table of handler functions
@@ -1183,7 +1187,7 @@ failed:
* update the fully computed style for a node when layout changes.
*/
css_error css_select_style(css_select_ctx *ctx, void *node,
- const css_unit_len_ctx *unit_len_ctx,
+ const css_unit_ctx *unit_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result)
@@ -1204,7 +1208,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
return error;
error = css_select__initialise_selection_state(
- &state, node, parent, media, handler, pw);
+ &state, node, parent, media, unit_ctx, handler, pw);
if (error != CSS_OK)
return error;
@@ -1269,7 +1273,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if (mq__list_match(s.media, media) &&
+ if (mq__list_match(s.media, unit_ctx, media) &&
s.sheet->disabled == false) {
error = select_from_sheet(ctx, s.sheet,
s.origin, &state);
@@ -1356,7 +1360,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
/* Only compute absolute values for the base element */
error = css__compute_absolute_values(NULL,
state.results->styles[CSS_PSEUDO_ELEMENT_NONE],
- unit_len_ctx);
+ unit_ctx);
if (error != CSS_OK)
goto cleanup;
}
@@ -1420,12 +1424,15 @@ css_error css_select_results_destroy(css_select_results *results)
*
* \param ctx Selection context
* \param media Currently active media spec
+ * \param unit_ctx Current unit conversion context.
* \param font_family Font family to search for
* \param result Pointer to location to receive result
* \return CSS_OK on success, appropriate error otherwise.
*/
css_error css_select_font_faces(css_select_ctx *ctx,
- const css_media *media, lwc_string *font_family,
+ const css_media *media,
+ const css_unit_ctx *unit_ctx,
+ lwc_string *font_family,
css_select_font_faces_results **result)
{
uint32_t i;
@@ -1439,6 +1446,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
memset(&state, 0, sizeof(css_select_font_faces_state));
state.font_family = font_family;
state.media = media;
+ state.unit_ctx = unit_ctx;
/* Iterate through the top-level stylesheets, selecting font-faces
* from those which apply to our current media requirements and
@@ -1446,7 +1454,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if (mq__list_match(s.media, media) &&
+ if (mq__list_match(s.media, unit_ctx, media) &&
s.sheet->disabled == false) {
error = select_font_faces_from_sheet(s.sheet,
s.origin, &state);
@@ -1846,6 +1854,7 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
if (import->sheet != NULL &&
mq__list_match(import->media,
+ state->unit_ctx,
state->media)) {
/* It's applicable, so process it */
if (sp >= IMPORT_STACK_SIZE)
@@ -1889,7 +1898,8 @@ static css_error _select_font_face_from_rule(
const css_rule_font_face *rule, css_origin origin,
css_select_font_faces_state *state)
{
- if (mq_rule_good_for_media((const css_rule *) rule, state->media)) {
+ if (mq_rule_good_for_media((const css_rule *) rule,
+ state->unit_ctx, state->media)) {
bool correct_family = false;
if (lwc_string_isequal(
@@ -1954,6 +1964,7 @@ static css_error select_font_faces_from_sheet(
if (import->sheet != NULL &&
mq__list_match(import->media,
+ state->unit_ctx,
state->media)) {
/* It's applicable, so process it */
if (sp >= IMPORT_STACK_SIZE)
@@ -2101,6 +2112,7 @@ css_error match_selectors_in_sheet(css_select_ctx *ctx,
/* Set up general selector chain requirments */
req.media = state->media;
+ req.unit_ctx = state->unit_ctx;
req.node_bloom = state->node_data->bloom;
req.uni = ctx->universal;
diff --git a/src/select/select.h b/src/select/select.h
index dc9aa4a..0a16b12 100644
--- a/src/select/select.h
+++ b/src/select/select.h
@@ -64,6 +64,7 @@ struct css_node_data {
typedef struct css_select_state {
void *node; /* Node we're selecting for */
const css_media *media; /* Currently active media spec */
+ const css_unit_ctx *unit_ctx; /* Unit conversion context. */
css_select_results *results; /* Result set to populate */
css_pseudo_element current_pseudo; /* Current pseudo element */
diff --git a/src/select/unit.c b/src/select/unit.c
index a279ec7..9129d72 100644
--- a/src/select/unit.c
+++ b/src/select/unit.c
@@ -118,7 +118,7 @@ static inline css_fixed css_unit__absolute_len2pt(
/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_font_size_len2pt(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
@@ -279,22 +279,22 @@ static inline css_fixed css_unit__px_per_unit(
/* Exported function, documented in unit.h. */
css_fixed css_unit_len2px_mq(
- const css_media *media,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
/* In the media query context there is no reference or root element
- * style, so these are hardcoded to NULL. */
+ * style, so these are hard-coded to NULL. */
css_fixed px_per_unit = css_unit__px_per_unit(
+ ctx->measure,
NULL,
NULL,
- NULL,
- media->client_font_size,
- INTTOFIX(0),
- media->height,
- media->width,
+ ctx->font_size_default,
+ ctx->font_size_minimum,
+ ctx->viewport_height,
+ ctx->viewport_width,
unit,
- NULL);
+ ctx->pw);
/* Ensure we round px_per_unit to the nearest whole number of pixels:
* the use of FIXTOINT() below will truncate. */
@@ -307,7 +307,7 @@ css_fixed css_unit_len2px_mq(
/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_len2css_px(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
@@ -333,7 +333,7 @@ css_fixed css_unit_len2css_px(
/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_len2device_px(
const css_computed_style *style,
- const css_unit_len_ctx *ctx,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
diff --git a/src/select/unit.h b/src/select/unit.h
index e4d21da..6a677b6 100644
--- a/src/select/unit.h
+++ b/src/select/unit.h
@@ -14,13 +14,13 @@
/**
* Convert a length to CSS pixels for a media query context.
*
- * \param[in] media Client media specification.
+ * \param[in] ctx Document unit conversion context.
* \param[in] length Length to convert.
* \param[in] unit Current unit of length.
* \return A length in CSS pixels.
*/
css_fixed css_unit_len2px_mq(
- const css_media *media,
+ const css_unit_ctx *ctx,
const css_fixed length,
const css_unit unit);
diff --git a/test/select.c b/test/select.c
index a3319fe..c104b38 100644
--- a/test/select.c
+++ b/test/select.c
@@ -164,7 +164,7 @@ static css_error set_libcss_node_data(void *pw, void *n,
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
-static css_unit_len_ctx unit_len_ctx = {
+static css_unit_ctx unit_ctx = {
.font_size_default = 16 * (1 << CSS_RADIX_POINT),
};
@@ -801,11 +801,11 @@ static void run_test_select_tree(css_select_ctx *select,
struct node *n = NULL;
if (node->parent == NULL) {
- unit_len_ctx.root_style = NULL;
+ unit_ctx.root_style = NULL;
}
- assert(css_select_style(select, node, &unit_len_ctx, &ctx->media, NULL,
+ assert(css_select_style(select, node, &unit_ctx, &ctx->media, NULL,
&select_handler, ctx, &sr) == CSS_OK);
if (node->parent != NULL) {
@@ -813,7 +813,7 @@ static void run_test_select_tree(css_select_ctx *select,
assert(css_computed_style_compose(
node->parent->sr->styles[ctx->pseudo_element],
sr->styles[ctx->pseudo_element],
- &unit_len_ctx,
+ &unit_ctx,
&composed) == CSS_OK);
css_computed_style_destroy(sr->styles[ctx->pseudo_element]);
sr->styles[ctx->pseudo_element] = composed;
@@ -827,7 +827,7 @@ static void run_test_select_tree(css_select_ctx *select,
}
if (node->parent == NULL) {
- unit_len_ctx.root_style = node->sr->styles[ctx->pseudo_element];
+ unit_ctx.root_style = node->sr->styles[ctx->pseudo_element];
}
for (n = node->children; n != NULL; n = n->next) {
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=65d4fd6e83d421e7fa7a...
commit 65d4fd6e83d421e7fa7a8c7df44d01797e3c69ae
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Selection: Remove client callback for unit conversion.
Now clients provide a unit conversion context and libcss provides
code to perform unit conversion.
This reduces the amount of common code that clients have to write.
diff --git a/Makefile b/Makefile
index 0835c8f..86d6641 100644
--- a/Makefile
+++ b/Makefile
@@ -65,5 +65,6 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/properties.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/select.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/stylesheet.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/types.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libcss/unit.h
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR)/pkgconfig:lib$(COMPONENT).pc.in
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR):$(OUTPUT)
diff --git a/examples/example1.c b/examples/example1.c
index c36a94d..6135793 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -98,13 +98,22 @@ static css_error node_presentational_hint(void *pw, void *node,
uint32_t *nhints, css_hint **hints);
static css_error ua_default_for_property(void *pw, uint32_t property,
css_hint *hint);
-static css_error compute_font_size(void *pw, const css_hint *parent,
- css_hint *size);
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data);
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
+static css_unit_len_ctx uint_len_ctx = {
+ .viewport_width = 800 * (1 << CSS_RADIX_POINT),
+ .viewport_height = 600 * (1 << CSS_RADIX_POINT),
+ .font_size_default = 16 * (1 << CSS_RADIX_POINT),
+ .font_size_minimum = 6 * (1 << CSS_RADIX_POINT),
+ .device_dpi = 96 * (1 << CSS_RADIX_POINT),
+ .root_style = NULL, /* We don't have a root node yet. */
+ .pw = NULL, /* We're not implementing measure callback */
+ .measure = NULL, /* We're not implementing measure callback */
+};
+
/* Table of function pointers for the LibCSS Select API. */
static css_select_handler select_handler = {
CSS_SELECT_HANDLER_VERSION_1,
@@ -143,9 +152,8 @@ static css_select_handler select_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
- compute_font_size,
set_libcss_node_data,
- get_libcss_node_data
+ get_libcss_node_data,
};
@@ -237,6 +245,7 @@ int main(int argc, char **argv)
lwc_intern_string(element, strlen(element), &element_name);
code = css_select_style(select_ctx, element_name,
+ &uint_len_ctx,
&media, NULL,
&select_handler, 0,
&style);
@@ -662,68 +671,6 @@ css_error ua_default_for_property(void *pw, uint32_t property, css_hint *hint)
return CSS_OK;
}
-css_error compute_font_size(void *pw, const css_hint *parent, css_hint *size)
-{
- static css_hint_length sizes[] = {
- { FLTTOFIX(6.75), CSS_UNIT_PT },
- { FLTTOFIX(7.50), CSS_UNIT_PT },
- { FLTTOFIX(9.75), CSS_UNIT_PT },
- { FLTTOFIX(12.0), CSS_UNIT_PT },
- { FLTTOFIX(13.5), CSS_UNIT_PT },
- { FLTTOFIX(18.0), CSS_UNIT_PT },
- { FLTTOFIX(24.0), CSS_UNIT_PT }
- };
- const css_hint_length *parent_size;
-
- UNUSED(pw);
-
- /* Grab parent size, defaulting to medium if none */
- if (parent == NULL) {
- parent_size = &sizes[CSS_FONT_SIZE_MEDIUM - 1];
- } else {
- assert(parent->status == CSS_FONT_SIZE_DIMENSION);
- assert(parent->data.length.unit != CSS_UNIT_EM);
- assert(parent->data.length.unit != CSS_UNIT_EX);
- parent_size = &parent->data.length;
- }
-
- assert(size->status != CSS_FONT_SIZE_INHERIT);
-
- if (size->status < CSS_FONT_SIZE_LARGER) {
- /* Keyword -- simple */
- size->data.length = sizes[size->status - 1];
- } else if (size->status == CSS_FONT_SIZE_LARGER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->status == CSS_FONT_SIZE_SMALLER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_EM ||
- size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value =
- FMUL(size->data.length.value, parent_size->value);
-
- if (size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.6));
- }
-
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_PCT) {
- size->data.length.value = FDIV(FMUL(size->data.length.value,
- parent_size->value), FLTTOFIX(100));
- size->data.length.unit = parent_size->unit;
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data)
{
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index f4b3e21..1587d78 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -19,6 +19,7 @@ extern "C"
#include <libcss/functypes.h>
#include <libcss/properties.h>
#include <libcss/types.h>
+#include <libcss/unit.h>
struct css_hint;
struct css_select_handler;
@@ -81,10 +82,7 @@ css_error css_computed_style_destroy(css_computed_style *style);
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- css_error (*compute_font_size)(void *pw,
- const struct css_hint *parent,
- struct css_hint *size),
- void *pw,
+ const css_unit_len_ctx *unit_len_ctx,
css_computed_style **restrict result);
/******************************************************************************
diff --git a/include/libcss/select.h b/include/libcss/select.h
index ca57456..bfaf531 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -18,6 +18,7 @@ extern "C"
#include <libcss/hint.h>
#include <libcss/types.h>
#include <libcss/computed.h>
+#include <libcss/unit.h>
typedef enum css_pseudo_element {
CSS_PSEUDO_ELEMENT_NONE = 0,
@@ -123,9 +124,6 @@ typedef struct css_select_handler {
css_error (*ua_default_for_property)(void *pw, uint32_t property,
css_hint *hint);
- css_error (*compute_font_size)(void *pw, const css_hint *parent,
- css_hint *size);
-
/**
* Set libcss_node_data on a DOM node.
*
@@ -221,6 +219,7 @@ css_error css_select_default_style(css_select_ctx *ctx,
css_select_handler *handler, void *pw,
css_computed_style **style);
css_error css_select_style(css_select_ctx *ctx, void *node,
+ const css_unit_len_ctx *unit_len_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result);
diff --git a/include/libcss/unit.h b/include/libcss/unit.h
new file mode 100644
index 0000000..a847077
--- /dev/null
+++ b/include/libcss/unit.h
@@ -0,0 +1,156 @@
+/*
+ * This file is part of LibCSS.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef libcss_unit_h_
+#define libcss_unit_h_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libcss/types.h>
+
+/**
+ * Client callback for font measuring.
+ *
+ * \param[in] pw Client data.
+ * \param[in] style Style to measure font for, or NULL.
+ * \param[in] unit Either CSS_UNIT_EX, or CSS_UNIT_CH.
+ * \return length in CSS pixels.
+ */
+typedef css_fixed (*css_unit_len_measure)(
+ void *pw,
+ const css_computed_style *style,
+ const css_unit unit);
+
+/**
+ * LibCSS unit conversion context.
+ *
+ * The client callback is optional. It is used for measuring "ch"
+ * (glyph '0' advance) and "ex" (height of the letter 'x') units.
+ * If a NULL pointer is given, LibCSS will use a fixed scaling of
+ * the "em" unit.
+ */
+typedef struct css_unit_len_ctx {
+ /**
+ * Viewport width in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_width;
+ /**
+ * Viewport height in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_height;
+ /**
+ * Client default font size in CSS pixels.
+ */
+ css_fixed font_size_default;
+ /**
+ * Client minimum font size in CSS pixels. May be zero.
+ */
+ css_fixed font_size_minimum;
+ /**
+ * DPI of the device the style is selected for.
+ */
+ css_fixed device_dpi;
+ /**
+ * Computed style for the document root element, needed for rem units.
+ * May be NULL, in which case font_size_default is used instead, as
+ * would be the case if rem unit is used on the root element.
+ */
+ const css_computed_style *root_style;
+ /**
+ * Optional client private word for measure callback.
+ */
+ void *pw;
+ /**
+ * Optional client callback for font measuring.
+ */
+ const css_unit_len_measure measure;
+} css_unit_len_ctx;
+
+/**
+ * Convert css pixels to physical pixels.
+ *
+ * \param[in] css_pixels Length in css pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in device pixels.
+ */
+static inline css_fixed css_unit_css2device_px(
+ const css_fixed css_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(css_pixels, device_dpi), F_96);
+}
+
+/**
+ * Convert device pixels to css pixels.
+ *
+ * \param[in] device_pixels Length in physical pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in css pixels.
+ */
+static inline css_fixed css_unit_device2css_px(
+ const css_fixed device_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(device_pixels, F_96), device_dpi);
+}
+
+/**
+ * Convert a length to points (pt).
+ *
+ * \param[in] style Style to perform conversion for or NULL.
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in points.
+ */
+css_fixed css_unit_font_size_len2pt(
+ const css_computed_style *style,
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to CSS pixels.
+ *
+ * \param[in] style Style to perform conversion for or NULL.
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in CSS pixels.
+ */
+css_fixed css_unit_len2css_px(
+ const css_computed_style *style,
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to device pixels.
+ *
+ * \param[in] style Style to perform conversion for or NULL.
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in device pixels.
+ */
+css_fixed css_unit_len2device_px(
+ const css_computed_style *style,
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/src/select/computed.c b/src/select/computed.c
index a1b345b..d075af9 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -12,6 +12,7 @@
#include "select/dispatch.h"
#include "select/propget.h"
#include "select/propset.h"
+#include "select/unit.h"
#include "utils/utils.h"
static css_error compute_absolute_color(css_computed_style *style,
@@ -247,9 +248,7 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw,
+ const css_unit_len_ctx *unit_len_ctx,
css_computed_style **restrict result)
{
css_computed_style *composed;
@@ -275,8 +274,7 @@ css_error css_computed_style_compose(
}
/* Finally, compute absolute values for everything */
- error = css__compute_absolute_values(parent, composed,
- compute_font_size, pw);
+ error = css__compute_absolute_values(parent, composed, unit_len_ctx);
if (error != CSS_OK) {
return error;
}
@@ -1087,31 +1085,36 @@ uint8_t css_computed_order(const css_computed_style *style,
*
* \param parent Parent style, or NULL for tree root
* \param style Computed style to process
- * \param compute_font_size Callback to calculate an absolute font-size
- * \param pw Private word for callback
+ * \param unit_len_ctx Client length conversion context.
* \return CSS_OK on success.
*/
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw)
+ const css_unit_len_ctx *unit_len_ctx)
{
+ css_hint_length *ref_length = NULL;
css_hint psize, size, ex_size;
css_error error;
- /* Ensure font-size is absolute */
+ /* Get reference font-size for relative sizes. */
if (parent != NULL) {
psize.status = get_font_size(parent,
&psize.data.length.value,
&psize.data.length.unit);
+ if (psize.status != CSS_FONT_SIZE_DIMENSION) {
+ return CSS_BADPARM;
+ }
+ ref_length = &psize.data.length;
}
size.status = get_font_size(style,
&size.data.length.value,
&size.data.length.unit);
- error = compute_font_size(pw, parent != NULL ? &psize : NULL, &size);
+ error = css_unit_compute_absolute_font_size(ref_length,
+ unit_len_ctx->root_style,
+ unit_len_ctx->font_size_default,
+ &size);
if (error != CSS_OK)
return error;
@@ -1125,7 +1128,12 @@ css_error css__compute_absolute_values(const css_computed_style *parent,
ex_size.status = CSS_FONT_SIZE_DIMENSION;
ex_size.data.length.value = INTTOFIX(1);
ex_size.data.length.unit = CSS_UNIT_EX;
- error = compute_font_size(pw, &size, &ex_size);
+
+ error = css_unit_compute_absolute_font_size(
+ &size.data.length,
+ unit_len_ctx->root_style,
+ unit_len_ctx->font_size_default,
+ &ex_size);
if (error != CSS_OK)
return error;
diff --git a/src/select/computed.h b/src/select/computed.h
index c926cec..8b33405 100644
--- a/src/select/computed.h
+++ b/src/select/computed.h
@@ -10,6 +10,8 @@
#include <libcss/computed.h>
#include <libcss/hint.h>
+#include <libcss/unit.h>
+
#include "autogenerated_computed.h"
/**
@@ -35,8 +37,6 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw);
+ const css_unit_len_ctx *unit_len_ctx);
#endif
diff --git a/src/select/select.c b/src/select/select.c
index f6efbfe..03a45fe 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -23,6 +23,7 @@
#include "select/propset.h"
#include "select/font_face.h"
#include "select/select.h"
+#include "select/unit.h"
#include "utils/parserutilserror.h"
#include "utils/utils.h"
@@ -1164,6 +1165,7 @@ failed:
*
* \param ctx Selection context to use
* \param node Node to select style for
+ * \param unit_len_ctx Context for length unit conversions.
* \param media Currently active media specification
* \param inline_style Corresponding inline style for node, or NULL
* \param handler Dispatch table of handler functions
@@ -1181,6 +1183,7 @@ failed:
* update the fully computed style for a node when layout changes.
*/
css_error css_select_style(css_select_ctx *ctx, void *node,
+ const css_unit_len_ctx *unit_len_ctx,
const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result)
@@ -1353,7 +1356,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
/* Only compute absolute values for the base element */
error = css__compute_absolute_values(NULL,
state.results->styles[CSS_PSEUDO_ELEMENT_NONE],
- handler->compute_font_size, pw);
+ unit_len_ctx);
if (error != CSS_OK)
goto cleanup;
}
diff --git a/src/select/unit.c b/src/select/unit.c
index f9ecf83..a279ec7 100644
--- a/src/select/unit.c
+++ b/src/select/unit.c
@@ -115,14 +115,15 @@ static inline css_fixed css_unit__absolute_len2pt(
}
}
-/* Exported function, documented in unit.h. */
+/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_font_size_len2pt(
+ const css_computed_style *style,
const css_unit_len_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
return css_unit__absolute_len2pt(
- ctx->ref_style,
+ style,
ctx->viewport_height,
ctx->viewport_width,
length,
@@ -303,15 +304,16 @@ css_fixed css_unit_len2px_mq(
return FMUL(length, TRUNCATEFIX(px_per_unit));
}
-/* Exported function, documented in unit.h. */
+/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_len2css_px(
+ const css_computed_style *style,
const css_unit_len_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
css_fixed px_per_unit = css_unit__px_per_unit(
ctx->measure,
- ctx->ref_style,
+ style,
ctx->root_style,
ctx->font_size_default,
ctx->font_size_minimum,
@@ -328,15 +330,16 @@ css_fixed css_unit_len2css_px(
return FMUL(length, TRUNCATEFIX(px_per_unit));
}
-/* Exported function, documented in unit.h. */
+/* Exported function, documented in libcss/unit.h. */
css_fixed css_unit_len2device_px(
+ const css_computed_style *style,
const css_unit_len_ctx *ctx,
const css_fixed length,
const css_unit unit)
{
css_fixed px_per_unit = css_unit__px_per_unit(
ctx->measure,
- ctx->ref_style,
+ style,
ctx->root_style,
ctx->font_size_default,
ctx->font_size_minimum,
@@ -361,18 +364,18 @@ css_fixed css_unit_len2device_px(
* The computed style will have font-size with an absolute unit.
* If no computed style is given, the client default font-size will be returned.
*
- * \param[in] ctx Length unit conversion context.
- * \param[in] style The style to get the font-size for, or NULL.
+ * \param[in] style Reference style. (Element or parent, or NULL).
+ * \param[in] font_size_default Client default font size in CSS pixels.
* \return The font size in absolute units.
*/
static inline css_hint_length css_unit__get_font_size(
- const css_unit_len_ctx *ctx,
- const css_computed_style *style)
+ const css_computed_style *style,
+ css_fixed font_size_default)
{
css_hint_length size;
if (style == NULL) {
- size.value = ctx->font_size_default;
+ size.value = font_size_default;
size.unit = CSS_UNIT_PX;
} else {
enum css_font_size_e status = get_font_size(
@@ -391,10 +394,24 @@ static inline css_hint_length css_unit__get_font_size(
/* Exported function, documented in unit.h. */
css_error css_unit_compute_absolute_font_size(
- const css_unit_len_ctx *ctx,
+ const css_hint_length *ref_length,
+ const css_computed_style *root_style,
+ css_fixed font_size_default,
css_hint *size)
{
- css_hint_length ref_len;
+ css_hint_length ref_len = {
+ .value = font_size_default,
+ .unit = CSS_UNIT_PX,
+ };
+
+ if (ref_length != NULL) {
+ /* Must be absolute. */
+ assert(ref_length->unit != CSS_UNIT_EM);
+ assert(ref_length->unit != CSS_UNIT_EX);
+ assert(ref_length->unit != CSS_UNIT_PCT);
+
+ ref_len = *ref_length;
+ }
assert(size->status != CSS_FONT_SIZE_INHERIT);
@@ -420,20 +437,18 @@ css_error css_unit_compute_absolute_font_size(
assert(CSS_FONT_SIZE_XX_SMALL == 1);
size->data.length.value = FMUL(factors[size->status - 1],
- ctx->font_size_default);
+ font_size_default);
size->data.length.unit = CSS_UNIT_PX;
size->status = CSS_FONT_SIZE_DIMENSION;
break;
}
case CSS_FONT_SIZE_LARGER:
- ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
size->data.length.value = FMUL(ref_len.value, FLTTOFIX(1.2));
size->data.length.unit = ref_len.unit;
size->status = CSS_FONT_SIZE_DIMENSION;
break;
case CSS_FONT_SIZE_SMALLER:
- ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
size->data.length.value = FDIV(ref_len.value, FLTTOFIX(1.2));
size->data.length.unit = ref_len.unit;
size->status = CSS_FONT_SIZE_DIMENSION;
@@ -443,9 +458,8 @@ css_error css_unit_compute_absolute_font_size(
/* Convert any relative units to absolute. */
switch (size->data.length.unit) {
case CSS_UNIT_PCT:
- ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
- size->data.length.value = FDIV(
- FMUL(size->data.length.value,
+ size->data.length.value = FDIV(FMUL(
+ size->data.length.value,
ref_len.value), INTTOFIX(100));
size->data.length.unit = ref_len.unit;
break;
@@ -454,11 +468,8 @@ css_error css_unit_compute_absolute_font_size(
case CSS_UNIT_EX: /* Fall-through */
case CSS_UNIT_CH:
/* Parent relative units. */
- ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
-
- size->data.length.unit = ref_len.unit;
- size->data.length.value = FMUL(size->data.length.value,
- ref_len.value);
+ size->data.length.value = FMUL(
+ size->data.length.value, ref_len.value);
switch (size->data.length.unit) {
case CSS_UNIT_EX:
@@ -476,15 +487,17 @@ css_error css_unit_compute_absolute_font_size(
default:
break;
}
+ size->data.length.unit = ref_len.unit;
break;
case CSS_UNIT_REM:
/* Root element relative units. */
- ref_len = css_unit__get_font_size(ctx, ctx->root_style);
+ ref_len = css_unit__get_font_size(root_style,
+ font_size_default);
size->data.length.unit = ref_len.unit;
- size->data.length.value = FMUL(size->data.length.value,
- ref_len.value);
+ size->data.length.value = FMUL(
+ size->data.length.value, ref_len.value);
break;
default:
diff --git a/src/select/unit.h b/src/select/unit.h
index 738c181..e4d21da 100644
--- a/src/select/unit.h
+++ b/src/select/unit.h
@@ -9,138 +9,7 @@
#ifndef css_select_unit_h_
#define css_select_unit_h_
-/**
- * Client callback for font measuring.
- *
- * \param[in] pw Client data.
- * \param[in] style Style to measure font for, or NULL.
- * \param[in] unit Either CSS_UNIT_EX, or CSS_UNIT_CH.
- * \return length in CSS pixels.
- */
-typedef css_fixed (*css_unit_len_measure)(
- void *pw,
- const css_computed_style *style,
- const css_unit unit);
-
-/**
- * LibCSS unit conversion context.
- *
- * The client callback is optional. It is used for measuring "ch"
- * (glyph '0' advance) and "ex" (height of the letter 'x') units.
- * If a NULL pointer is given, LibCSS will use a fixed scaling of
- * the "em" unit.
- */
-typedef struct css_unit_len_ctx {
- /**
- * Viewport width in CSS pixels.
- * Used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- css_fixed viewport_width;
- /**
- * Viewport height in CSS pixels.
- * Used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- css_fixed viewport_height;
- /**
- * Client default font size in CSS pixels.
- */
- css_fixed font_size_default;
- /**
- * Client minimum font size in CSS pixels. May be zero.
- */
- css_fixed font_size_minimum;
- /**
- * DPI of the device the style is selected for.
- */
- css_fixed device_dpi;
- /**
- * Reference style. Most of the time, this is the element's style.
- * When converting a length for a typographical property, such as
- * font-size, then this should be the parent node. If the node has
- * no parent then this may be NULL.
- */
- const css_computed_style *ref_style;
- /**
- * Computed style for the document root element.
- * May be NULL if unit is not rem.
- */
- const css_computed_style *root_style;
- /**
- * Client private word for measure callback.
- */
- void *pw;
- /**
- * Client callback for font measuring.
- */
- const css_unit_len_measure measure;
-} css_unit_len_ctx;
-
-/**
- * Convert css pixels to physical pixels.
- *
- * \param[in] css_pixels Length in css pixels.
- * \param[in] device_dpi Device dots per inch.
- * \return Length in device pixels.
- */
-static inline css_fixed css_unit_css2device_px(
- const css_fixed css_pixels,
- const css_fixed device_dpi)
-{
- return FDIV(FMUL(css_pixels, device_dpi), F_96);
-}
-
-/**
- * Convert device pixels to css pixels.
- *
- * \param[in] device_pixels Length in physical pixels.
- * \param[in] device_dpi Device dots per inch.
- * \return Length in css pixels.
- */
-static inline css_fixed css_unit_device2css_px(
- const css_fixed device_pixels,
- const css_fixed device_dpi)
-{
- return FDIV(FMUL(device_pixels, F_96), device_dpi);
-}
-
-/**
- * Convert a length to points (pt).
- *
- * \param[in] ctx Length unit conversion context.
- * \param[in] length Length to convert.
- * \param[in] unit Current unit of length.
- * \return A length in points.
- */
-css_fixed css_unit_font_size_len2pt(
- const css_unit_len_ctx *ctx,
- const css_fixed length,
- const css_unit unit);
-
-/**
- * Convert a length to CSS pixels.
- *
- * \param[in] ctx Length unit conversion context.
- * \param[in] length Length to convert.
- * \param[in] unit Current unit of length.
- * \return A length in CSS pixels.
- */
-css_fixed css_unit_len2css_px(
- const css_unit_len_ctx *ctx,
- const css_fixed length,
- const css_unit unit);
-
-/**
- * Convert a length to device pixels.
- *
- * \param[in] ctx Length unit conversion context.
- * \param[in] length Length to convert.
- * \param[in] unit Current unit of length.
- * \return A length in device pixels.
- */
-css_fixed css_unit_len2device_px(
- const css_unit_len_ctx *ctx,
- const css_fixed length,
- const css_unit unit);
+#include <libcss/unit.h>
/**
* Convert a length to CSS pixels for a media query context.
@@ -158,12 +27,16 @@ css_fixed css_unit_len2px_mq(
/**
* Convert relative font size units to absolute units.
*
- * \param[in] ctx Length unit conversion context.
- * \param[in,out] size The length to convert.
+ * \param[in] ref_length Reference font-size length or NULL.
+ * \param[in] root_style Root element style or NULL.
+ * \param[in] font_size_default Client default font size in CSS pixels.
+ * \param[in,out] size The length to convert.
* \return CSS_OK on success, or appropriate error otherwise.
*/
css_error css_unit_compute_absolute_font_size(
- const css_unit_len_ctx *ctx,
+ const css_hint_length *ref_length,
+ const css_computed_style *root_style,
+ css_fixed font_size_default,
css_hint *size);
#endif
diff --git a/test/data/select/tests1.dat b/test/data/select/tests1.dat
index eaf37d7..295ab2e 100644
--- a/test/data/select/tests1.dat
+++ b/test/data/select/tests1.dat
@@ -59,7 +59,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -173,7 +173,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -291,7 +291,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -410,7 +410,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -529,7 +529,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -648,7 +648,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -757,7 +757,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -867,7 +867,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -977,7 +977,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1086,7 +1086,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1200,7 +1200,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1314,7 +1314,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1429,7 +1429,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1547,7 +1547,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1664,7 +1664,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1787,7 +1787,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -1910,7 +1910,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2033,7 +2033,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2160,7 +2160,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2286,7 +2286,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2410,7 +2410,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2533,7 +2533,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2656,7 +2656,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2779,7 +2779,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -2902,7 +2902,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3025,7 +3025,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3148,7 +3148,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3271,7 +3271,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3394,7 +3394,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3517,7 +3517,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3640,7 +3640,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 10.600pt
+font-size: 13.342px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3763,7 +3763,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 14.391pt
+font-size: 19.187px
font-style: normal
font-variant: normal
font-weight: normal
@@ -3886,7 +3886,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 24pt
+font-size: 32px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4009,7 +4009,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 18pt
+font-size: 24px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4132,7 +4132,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 13.500pt
+font-size: 18px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4255,7 +4255,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4378,7 +4378,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 9.750pt
+font-size: 13px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4501,7 +4501,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 7.500pt
+font-size: 10px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4624,7 +4624,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 6.750pt
+font-size: 9px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4870,7 +4870,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -4986,7 +4986,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5102,7 +5102,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5218,7 +5218,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5331,7 +5331,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5445,7 +5445,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5559,7 +5559,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5673,7 +5673,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5783,7 +5783,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -5894,7 +5894,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6004,7 +6004,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6114,7 +6114,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6224,7 +6224,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6334,7 +6334,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6444,7 +6444,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6556,7 +6556,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6666,7 +6666,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6776,7 +6776,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6887,7 +6887,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -6997,7 +6997,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7107,7 +7107,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7217,7 +7217,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7327,7 +7327,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7437,7 +7437,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7547,7 +7547,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7657,7 +7657,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7766,7 +7766,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7875,7 +7875,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -7984,7 +7984,7 @@ flex-shrink: 30.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8095,7 +8095,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8206,7 +8206,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8315,7 +8315,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8426,7 +8426,7 @@ flex-shrink: 0.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8537,7 +8537,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8648,7 +8648,7 @@ flex-shrink: 3.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8757,7 +8757,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8866,7 +8866,7 @@ flex-shrink: 1.000
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -8975,7 +8975,7 @@ flex-shrink: 1.000
flex-wrap: wrap-reverse
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9084,7 +9084,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9193,7 +9193,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9302,7 +9302,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9411,7 +9411,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9520,7 +9520,7 @@ flex-shrink: 1.000
flex-wrap: wrap-reverse
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9631,7 +9631,7 @@ flex-shrink: 1.000
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9742,7 +9742,7 @@ flex-shrink: 1.000
flex-wrap: wrap-reverse
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9851,7 +9851,7 @@ flex-shrink: 0.899
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -9960,7 +9960,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10069,7 +10069,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10178,7 +10178,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10287,7 +10287,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10396,7 +10396,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10505,7 +10505,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10616,7 +10616,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10727,7 +10727,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10836,7 +10836,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -10945,7 +10945,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11054,7 +11054,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11165,7 +11165,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11274,7 +11274,7 @@ flex-shrink: 3.780
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11385,7 +11385,7 @@ flex-shrink: 3.780
flex-wrap: wrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11494,7 +11494,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11603,7 +11603,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11712,7 +11712,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11821,7 +11821,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -11930,7 +11930,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12039,7 +12039,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12148,7 +12148,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12257,7 +12257,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12366,7 +12366,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12475,7 +12475,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12584,7 +12584,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12693,7 +12693,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12802,7 +12802,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -12911,7 +12911,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13020,7 +13020,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13129,7 +13129,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13238,7 +13238,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13347,7 +13347,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13456,7 +13456,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13565,7 +13565,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13674,7 +13674,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13783,7 +13783,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -13892,7 +13892,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
@@ -14020,7 +14020,7 @@ flex-shrink: 1.000
flex-wrap: nowrap
float: none
font-family: sans-serif
-font-size: 12pt
+font-size: 16px
font-style: normal
font-variant: normal
font-weight: normal
diff --git a/test/select.c b/test/select.c
index 33f31dd..a3319fe 100644
--- a/test/select.c
+++ b/test/select.c
@@ -159,13 +159,15 @@ static css_error node_presentational_hint(void *pw, void *node,
uint32_t *nhints, css_hint **hints);
static css_error ua_default_for_property(void *pw, uint32_t property,
css_hint *hints);
-static css_error compute_font_size(void *pw, const css_hint *parent,
- css_hint *size);
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data);
static css_error get_libcss_node_data(void *pw, void *n,
void **libcss_node_data);
+static css_unit_len_ctx unit_len_ctx = {
+ .font_size_default = 16 * (1 << CSS_RADIX_POINT),
+};
+
static css_select_handler select_handler = {
CSS_SELECT_HANDLER_VERSION_1,
@@ -203,9 +205,9 @@ static css_select_handler select_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
- compute_font_size,
+
set_libcss_node_data,
- get_libcss_node_data
+ get_libcss_node_data,
};
static css_error resolve_url(void *pw,
@@ -798,7 +800,12 @@ static void run_test_select_tree(css_select_ctx *select,
css_select_results *sr;
struct node *n = NULL;
- assert(css_select_style(select, node, &ctx->media, NULL,
+ if (node->parent == NULL) {
+ unit_len_ctx.root_style = NULL;
+ }
+
+
+ assert(css_select_style(select, node, &unit_len_ctx, &ctx->media, NULL,
&select_handler, ctx, &sr) == CSS_OK);
if (node->parent != NULL) {
@@ -806,7 +813,7 @@ static void run_test_select_tree(css_select_ctx *select,
assert(css_computed_style_compose(
node->parent->sr->styles[ctx->pseudo_element],
sr->styles[ctx->pseudo_element],
- compute_font_size, NULL,
+ &unit_len_ctx,
&composed) == CSS_OK);
css_computed_style_destroy(sr->styles[ctx->pseudo_element]);
sr->styles[ctx->pseudo_element] = composed;
@@ -819,6 +826,10 @@ static void run_test_select_tree(css_select_ctx *select,
buf, buflen);
}
+ if (node->parent == NULL) {
+ unit_len_ctx.root_style = node->sr->styles[ctx->pseudo_element];
+ }
+
for (n = node->children; n != NULL; n = n->next) {
run_test_select_tree(select, n, ctx, buf, buflen);
}
@@ -1639,68 +1650,6 @@ css_error ua_default_for_property(void *pw, uint32_t property, css_hint *hint)
return CSS_OK;
}
-css_error compute_font_size(void *pw, const css_hint *parent, css_hint *size)
-{
- static css_hint_length sizes[] = {
- { FLTTOFIX(6.75), CSS_UNIT_PT },
- { FLTTOFIX(7.50), CSS_UNIT_PT },
- { FLTTOFIX(9.75), CSS_UNIT_PT },
- { FLTTOFIX(12.0), CSS_UNIT_PT },
- { FLTTOFIX(13.5), CSS_UNIT_PT },
- { FLTTOFIX(18.0), CSS_UNIT_PT },
- { FLTTOFIX(24.0), CSS_UNIT_PT }
- };
- const css_hint_length *parent_size;
-
- UNUSED(pw);
-
- /* Grab parent size, defaulting to medium if none */
- if (parent == NULL) {
- parent_size = &sizes[CSS_FONT_SIZE_MEDIUM - 1];
- } else {
- assert(parent->status == CSS_FONT_SIZE_DIMENSION);
- assert(parent->data.length.unit != CSS_UNIT_EM);
- assert(parent->data.length.unit != CSS_UNIT_EX);
- parent_size = &parent->data.length;
- }
-
- assert(size->status != CSS_FONT_SIZE_INHERIT);
-
- if (size->status < CSS_FONT_SIZE_LARGER) {
- /* Keyword -- simple */
- size->data.length = sizes[size->status - 1];
- } else if (size->status == CSS_FONT_SIZE_LARGER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->status == CSS_FONT_SIZE_SMALLER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FDIV(parent_size->value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_EM ||
- size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value =
- FMUL(size->data.length.value, parent_size->value);
-
- if (size->data.length.unit == CSS_UNIT_EX) {
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.6));
- }
-
- size->data.length.unit = parent_size->unit;
- } else if (size->data.length.unit == CSS_UNIT_PCT) {
- size->data.length.value = FDIV(FMUL(size->data.length.value,
- parent_size->value), FLTTOFIX(100));
- size->data.length.unit = parent_size->unit;
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
static css_error set_libcss_node_data(void *pw, void *n,
void *libcss_node_data)
{
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=6cd205329373efe5a162...
commit 6cd205329373efe5a1629518c2875724cc79dce3
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Units: Add support for length unit conversion to libcss.
Currently only used for unit conversion.
diff --git a/src/select/Makefile b/src/select/Makefile
index 8b47673..f5ddb18 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 format_list_style.c
+DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c font_face.c format_list_style.c unit.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/select/hash.c b/src/select/hash.c
index 4b11702..4dedec9 100644
--- a/src/select/hash.c
+++ b/src/select/hash.c
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <string.h>
+#include <libcss/hint.h>
+
#include "stylesheet.h"
#include "select/hash.h"
#include "select/mq.h"
diff --git a/src/select/mq.h b/src/select/mq.h
index 6f98387..080a6ba 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -10,96 +10,7 @@
#define css_select_mq_h_
#include "select/helpers.h"
-
-static inline css_fixed css_len2px(
- css_fixed length,
- css_unit unit,
- const css_media *media)
-{
- css_fixed px_per_unit;
-
- switch (unit) {
- case CSS_UNIT_VI:
- /* TODO: Assumes writing mode. */
- unit = CSS_UNIT_VW;
- break;
- case CSS_UNIT_VB:
- /* TODO: Assumes writing mode. */
- unit = CSS_UNIT_VH;
- break;
- case CSS_UNIT_VMIN:
- unit = (media->height < media->width) ?
- CSS_UNIT_VH : CSS_UNIT_VW;
- break;
- case CSS_UNIT_VMAX:
- unit = (media->width > media->height) ?
- CSS_UNIT_VH : CSS_UNIT_VW;
- break;
- default:
- break;
- }
-
- switch (unit) {
- case CSS_UNIT_EM:
- case CSS_UNIT_EX:
- case CSS_UNIT_CH:
- {
- px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
-
- /* TODO: Handling these as fixed ratios of CSS_UNIT_EM. */
- switch (unit) {
- case CSS_UNIT_EX:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
- break;
- case CSS_UNIT_CH:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
- break;
- default:
- break;
- }
- }
- break;
- case CSS_UNIT_PX:
- return length;
- case CSS_UNIT_IN:
- px_per_unit = F_96;
- break;
- case CSS_UNIT_CM:
- px_per_unit = FDIV(F_96, FLTTOFIX(2.54));
- break;
- case CSS_UNIT_MM:
- px_per_unit = FDIV(F_96, FLTTOFIX(25.4));
- break;
- case CSS_UNIT_Q:
- px_per_unit = FDIV(F_96, FLTTOFIX(101.6));
- break;
- case CSS_UNIT_PT:
- px_per_unit = FDIV(F_96, F_72);
- break;
- case CSS_UNIT_PC:
- px_per_unit = FDIV(F_96, INTTOFIX(6));
- break;
- case CSS_UNIT_REM:
- px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
- break;
- case CSS_UNIT_VH:
- px_per_unit = FDIV(media->height, F_100);
- break;
- case CSS_UNIT_VW:
- px_per_unit = FDIV(media->width, F_100);
- break;
- default:
- px_per_unit = 0;
- break;
- }
-
- /* Ensure we round px_per_unit to the nearest whole number of pixels:
- * the use of FIXTOINT() below will truncate. */
- px_per_unit += F_0_5;
-
- /* Calculate total number of pixels */
- return FMUL(length, TRUNCATEFIX(px_per_unit));
-}
+#include "select/unit.h"
static inline bool mq_match_feature_range_length_op1(
css_mq_feature_op op,
@@ -114,9 +25,9 @@ static inline bool mq_match_feature_range_length_op1(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_len2px(value->data.dim.len,
- css__to_css_unit(value->data.dim.unit),
- media);
+ v = css_unit_len2px_mq(media,
+ value->data.dim.len,
+ css__to_css_unit(value->data.dim.unit));
} else {
v = value->data.dim.len;
}
@@ -149,9 +60,9 @@ static inline bool mq_match_feature_range_length_op2(
}
if (value->data.dim.unit != UNIT_PX) {
- v = css_len2px(value->data.dim.len,
- css__to_css_unit(value->data.dim.unit),
- media);
+ v = css_unit_len2px_mq(media,
+ value->data.dim.len,
+ css__to_css_unit(value->data.dim.unit));
} else {
v = value->data.dim.len;
}
diff --git a/src/select/unit.c b/src/select/unit.c
new file mode 100644
index 0000000..f9ecf83
--- /dev/null
+++ b/src/select/unit.c
@@ -0,0 +1,498 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include <libcss/stylesheet.h>
+
+#include "utils/utils.h"
+
+#include "propget.h"
+#include "unit.h"
+
+/**
+ * Map viewport-relative length units to either vh or vw.
+ *
+ * Non-viewport-relative units are unchanged.
+ *
+ * \param[in] style Reference style.
+ * \param[in] viewport_height Viewport height in px.
+ * \param[in] viewport_width Viewport width in px.
+ * \param[in] unit Unit to map.
+ * \return the mapped unit.
+ */
+static inline css_unit css_unit__map_viewport_units(
+ const css_computed_style *style,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width,
+ const css_unit unit)
+{
+ switch (unit) {
+ case CSS_UNIT_VI:
+ return (style != NULL && get_writing_mode(style) !=
+ CSS_WRITING_MODE_HORIZONTAL_TB) ?
+ CSS_UNIT_VH : CSS_UNIT_VW;
+
+ case CSS_UNIT_VB:
+ return (style != NULL && get_writing_mode(style) !=
+ CSS_WRITING_MODE_HORIZONTAL_TB) ?
+ CSS_UNIT_VW : CSS_UNIT_VH;
+
+ case CSS_UNIT_VMIN:
+ return (viewport_height < viewport_width) ?
+ CSS_UNIT_VH : CSS_UNIT_VW;
+
+ case CSS_UNIT_VMAX:
+ return (viewport_height > viewport_width) ?
+ CSS_UNIT_VH : CSS_UNIT_VW;
+
+ default:
+ return unit;
+ }
+}
+
+/**
+ * Convert an absolute length to points (pt).
+ *
+ * \param[in] style Style to get font-size from, or NULL.
+ * \param[in] viewport_height Client viewport height.
+ * \param[in] viewport_width Client viewport width.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return length in points (pt).
+ */
+static inline css_fixed css_unit__absolute_len2pt(
+ const css_computed_style *style,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width,
+ const css_fixed length,
+ const css_unit unit)
+{
+ /* Length must not be relative */
+ assert(unit != CSS_UNIT_EM &&
+ unit != CSS_UNIT_EX &&
+ unit != CSS_UNIT_CH &&
+ unit != CSS_UNIT_REM);
+
+ switch (css_unit__map_viewport_units(style,
+ viewport_height,
+ viewport_width,
+ unit)) {
+ case CSS_UNIT_PX:
+ return FDIV(FMUL(length, F_72), F_96);
+
+ case CSS_UNIT_IN:
+ return FMUL(length, F_72);
+
+ case CSS_UNIT_CM:
+ return FMUL(length, FDIV(F_72, FLTTOFIX(2.54)));
+
+ case CSS_UNIT_MM:
+ return FMUL(length, FDIV(F_72, FLTTOFIX(25.4)));
+
+ case CSS_UNIT_Q:
+ return FMUL(length, FDIV(F_72, FLTTOFIX(101.6)));
+
+ case CSS_UNIT_PT:
+ return length;
+
+ case CSS_UNIT_PC:
+ return FMUL(length, INTTOFIX(12));
+
+ case CSS_UNIT_VH:
+ return FDIV(FMUL(FDIV(FMUL(length, viewport_height), F_100),
+ F_72), F_96);
+
+ case CSS_UNIT_VW:
+ return FDIV(FMUL(FDIV(FMUL(length, viewport_width), F_100),
+ F_72), F_96);
+
+ default:
+ return 0;
+ }
+}
+
+/* Exported function, documented in unit.h. */
+css_fixed css_unit_font_size_len2pt(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ return css_unit__absolute_len2pt(
+ ctx->ref_style,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ length,
+ unit);
+}
+
+/**
+ * Get font size from a style in CSS pixels.
+ *
+ * The style should have font size in absolute units.
+ *
+ * \param[in] style Style to get font-size from, or NULL.
+ * \param[in] font_size_default Client font size for NULL style.
+ * \param[in] font_size_minimum Client minimum font size clamp.
+ * \param[in] viewport_height Client viewport height.
+ * \param[in] viewport_width Client viewport width.
+ * \return font-size in CSS pixels.
+ */
+static inline css_fixed css_unit__font_size_px(
+ const css_computed_style *style,
+ const css_fixed font_size_default,
+ const css_fixed font_size_minimum,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width)
+{
+ css_fixed font_length = 0;
+ css_unit font_unit = CSS_UNIT_PT;
+
+ if (style == NULL) {
+ return font_size_default;
+ }
+
+ get_font_size(style, &font_length, &font_unit);
+
+ if (font_unit != CSS_UNIT_PX) {
+ font_length = css_unit__absolute_len2pt(style,
+ viewport_height,
+ viewport_width,
+ font_length,
+ font_unit);
+
+ /* Convert from pt to CSS pixels.*/
+ font_length = FDIV(FMUL(font_length, F_96), F_72);
+ }
+
+ /* Clamp to configured minimum */
+ if (font_length < font_size_minimum) {
+ font_length = font_size_minimum;
+ }
+
+ return font_length;
+}
+
+/**
+ * Get the number of CSS pixels for a given unit.
+ *
+ * \param[in] measure Client callback for font measuring.
+ * \param[in] ref_style Reference style. (Element or parent, or NULL).
+ * \param[in] root_style Root element style or NULL.
+ * \param[in] font_size_default Client default font size in CSS pixels.
+ * \param[in] font_size_minimum Client minimum font size in CSS pixels.
+ * \param[in] viewport_height Viewport height in CSS pixels.
+ * \param[in] viewport_width Viewport width in CSS pixels.
+ * \param[in] unit The unit to convert from.
+ * \param[in] pw Client private word for measure callback.
+ * \return Number of CSS pixels equivalent to the given unit.
+ */
+static inline css_fixed css_unit__px_per_unit(
+ const css_unit_len_measure measure,
+ const css_computed_style *ref_style,
+ const css_computed_style *root_style,
+ const css_fixed font_size_default,
+ const css_fixed font_size_minimum,
+ const css_fixed viewport_height,
+ const css_fixed viewport_width,
+ const css_unit unit,
+ void *pw)
+{
+ switch (css_unit__map_viewport_units(
+ ref_style,
+ viewport_height,
+ viewport_width,
+ unit)) {
+ case CSS_UNIT_EM:
+ return css_unit__font_size_px(
+ ref_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width);
+
+ case CSS_UNIT_EX:
+ if (measure != NULL) {
+ return measure(pw, ref_style, CSS_UNIT_EX);
+ }
+ return FMUL(css_unit__font_size_px(
+ ref_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width), FLTTOFIX(0.6));
+
+ case CSS_UNIT_CH:
+ if (measure != NULL) {
+ return measure(pw, ref_style, CSS_UNIT_CH);
+ }
+ return FMUL(css_unit__font_size_px(
+ ref_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width), FLTTOFIX(0.4));
+
+ case CSS_UNIT_PX:
+ return F_1;
+
+ case CSS_UNIT_IN:
+ return F_96;
+
+ case CSS_UNIT_CM:
+ return FDIV(F_96, FLTTOFIX(2.54));
+
+ case CSS_UNIT_MM:
+ return FDIV(F_96, FLTTOFIX(25.4));
+
+ case CSS_UNIT_Q:
+ return FDIV(F_96, FLTTOFIX(101.6));
+
+ case CSS_UNIT_PT:
+ return FDIV(F_96, F_72);
+
+ case CSS_UNIT_PC:
+ return FDIV(F_96, INTTOFIX(6));
+
+ case CSS_UNIT_REM:
+ return css_unit__font_size_px(
+ root_style,
+ font_size_default,
+ font_size_minimum,
+ viewport_height,
+ viewport_width);
+
+ case CSS_UNIT_VH:
+ return FDIV(viewport_width, F_100);
+
+ case CSS_UNIT_VW:
+ return FDIV(viewport_height, F_100);
+
+ default:
+ return 0;
+ }
+}
+
+/* Exported function, documented in unit.h. */
+css_fixed css_unit_len2px_mq(
+ const css_media *media,
+ const css_fixed length,
+ const css_unit unit)
+{
+ /* In the media query context there is no reference or root element
+ * style, so these are hardcoded to NULL. */
+ css_fixed px_per_unit = css_unit__px_per_unit(
+ NULL,
+ NULL,
+ NULL,
+ media->client_font_size,
+ INTTOFIX(0),
+ media->height,
+ media->width,
+ unit,
+ NULL);
+
+ /* Ensure we round px_per_unit to the nearest whole number of pixels:
+ * the use of FIXTOINT() below will truncate. */
+ px_per_unit += F_0_5;
+
+ /* Calculate total number of pixels */
+ return FMUL(length, TRUNCATEFIX(px_per_unit));
+}
+
+/* Exported function, documented in unit.h. */
+css_fixed css_unit_len2css_px(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ css_fixed px_per_unit = css_unit__px_per_unit(
+ ctx->measure,
+ ctx->ref_style,
+ ctx->root_style,
+ ctx->font_size_default,
+ ctx->font_size_minimum,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ unit,
+ ctx->pw);
+
+ /* Ensure we round px_per_unit to the nearest whole number of pixels:
+ * the use of FIXTOINT() below will truncate. */
+ px_per_unit += F_0_5;
+
+ /* Calculate total number of pixels */
+ return FMUL(length, TRUNCATEFIX(px_per_unit));
+}
+
+/* Exported function, documented in unit.h. */
+css_fixed css_unit_len2device_px(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit)
+{
+ css_fixed px_per_unit = css_unit__px_per_unit(
+ ctx->measure,
+ ctx->ref_style,
+ ctx->root_style,
+ ctx->font_size_default,
+ ctx->font_size_minimum,
+ ctx->viewport_height,
+ ctx->viewport_width,
+ unit,
+ ctx->pw);
+
+ px_per_unit = css_unit_css2device_px(px_per_unit, ctx->device_dpi);
+
+ /* Ensure we round px_per_unit to the nearest whole number of pixels:
+ * the use of FIXTOINT() below will truncate. */
+ px_per_unit += F_0_5;
+
+ /* Calculate total number of pixels */
+ return FMUL(length, TRUNCATEFIX(px_per_unit));
+}
+
+/**
+ * Get font size from a computed style.
+ *
+ * The computed style will have font-size with an absolute unit.
+ * If no computed style is given, the client default font-size will be returned.
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] style The style to get the font-size for, or NULL.
+ * \return The font size in absolute units.
+ */
+static inline css_hint_length css_unit__get_font_size(
+ const css_unit_len_ctx *ctx,
+ const css_computed_style *style)
+{
+ css_hint_length size;
+
+ if (style == NULL) {
+ size.value = ctx->font_size_default;
+ size.unit = CSS_UNIT_PX;
+ } else {
+ enum css_font_size_e status = get_font_size(
+ style, &size.value, &size.unit);
+
+ UNUSED(status);
+
+ assert(status == CSS_FONT_SIZE_DIMENSION);
+ assert(size.unit != CSS_UNIT_EM);
+ assert(size.unit != CSS_UNIT_EX);
+ assert(size.unit != CSS_UNIT_PCT);
+ }
+
+ return size;
+}
+
+/* Exported function, documented in unit.h. */
+css_error css_unit_compute_absolute_font_size(
+ const css_unit_len_ctx *ctx,
+ css_hint *size)
+{
+ css_hint_length ref_len;
+
+ assert(size->status != CSS_FONT_SIZE_INHERIT);
+
+ switch (size->status) {
+ case CSS_FONT_SIZE_XX_SMALL: /* Fall-through. */
+ case CSS_FONT_SIZE_X_SMALL: /* Fall-through. */
+ case CSS_FONT_SIZE_SMALL: /* Fall-through. */
+ case CSS_FONT_SIZE_MEDIUM: /* Fall-through. */
+ case CSS_FONT_SIZE_LARGE: /* Fall-through. */
+ case CSS_FONT_SIZE_X_LARGE: /* Fall-through. */
+ case CSS_FONT_SIZE_XX_LARGE:
+ {
+ static const css_fixed factors[CSS_FONT_SIZE_XX_LARGE] = {
+ [CSS_FONT_SIZE_XX_SMALL - 1] = FLTTOFIX(0.5625),
+ [CSS_FONT_SIZE_X_SMALL - 1] = FLTTOFIX(0.6250),
+ [CSS_FONT_SIZE_SMALL - 1] = FLTTOFIX(0.8125),
+ [CSS_FONT_SIZE_MEDIUM - 1] = FLTTOFIX(1.0000),
+ [CSS_FONT_SIZE_LARGE - 1] = FLTTOFIX(1.1250),
+ [CSS_FONT_SIZE_X_LARGE - 1] = FLTTOFIX(1.5000),
+ [CSS_FONT_SIZE_XX_LARGE - 1] = FLTTOFIX(2.0000),
+ };
+ assert(CSS_FONT_SIZE_INHERIT == 0);
+ assert(CSS_FONT_SIZE_XX_SMALL == 1);
+
+ size->data.length.value = FMUL(factors[size->status - 1],
+ ctx->font_size_default);
+ size->data.length.unit = CSS_UNIT_PX;
+ size->status = CSS_FONT_SIZE_DIMENSION;
+ break;
+ }
+ case CSS_FONT_SIZE_LARGER:
+ ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
+ size->data.length.value = FMUL(ref_len.value, FLTTOFIX(1.2));
+ size->data.length.unit = ref_len.unit;
+ size->status = CSS_FONT_SIZE_DIMENSION;
+ break;
+
+ case CSS_FONT_SIZE_SMALLER:
+ ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
+ size->data.length.value = FDIV(ref_len.value, FLTTOFIX(1.2));
+ size->data.length.unit = ref_len.unit;
+ size->status = CSS_FONT_SIZE_DIMENSION;
+ break;
+
+ case CSS_FONT_SIZE_DIMENSION:
+ /* Convert any relative units to absolute. */
+ switch (size->data.length.unit) {
+ case CSS_UNIT_PCT:
+ ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
+ size->data.length.value = FDIV(
+ FMUL(size->data.length.value,
+ ref_len.value), INTTOFIX(100));
+ size->data.length.unit = ref_len.unit;
+ break;
+
+ case CSS_UNIT_EM: /* Fall-through */
+ case CSS_UNIT_EX: /* Fall-through */
+ case CSS_UNIT_CH:
+ /* Parent relative units. */
+ ref_len = css_unit__get_font_size(ctx, ctx->ref_style);
+
+ size->data.length.unit = ref_len.unit;
+ size->data.length.value = FMUL(size->data.length.value,
+ ref_len.value);
+
+ switch (size->data.length.unit) {
+ case CSS_UNIT_EX:
+ size->data.length.value = FMUL(
+ size->data.length.value,
+ FLTTOFIX(0.6));
+ break;
+
+ case CSS_UNIT_CH:
+ size->data.length.value = FMUL(
+ size->data.length.value,
+ FLTTOFIX(0.4));
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case CSS_UNIT_REM:
+ /* Root element relative units. */
+ ref_len = css_unit__get_font_size(ctx, ctx->root_style);
+
+ size->data.length.unit = ref_len.unit;
+ size->data.length.value = FMUL(size->data.length.value,
+ ref_len.value);
+ break;
+
+ default:
+ break;
+ }
+ default:
+ break;
+ }
+
+ return CSS_OK;
+}
diff --git a/src/select/unit.h b/src/select/unit.h
new file mode 100644
index 0000000..738c181
--- /dev/null
+++ b/src/select/unit.h
@@ -0,0 +1,169 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#ifndef css_select_unit_h_
+#define css_select_unit_h_
+
+/**
+ * Client callback for font measuring.
+ *
+ * \param[in] pw Client data.
+ * \param[in] style Style to measure font for, or NULL.
+ * \param[in] unit Either CSS_UNIT_EX, or CSS_UNIT_CH.
+ * \return length in CSS pixels.
+ */
+typedef css_fixed (*css_unit_len_measure)(
+ void *pw,
+ const css_computed_style *style,
+ const css_unit unit);
+
+/**
+ * LibCSS unit conversion context.
+ *
+ * The client callback is optional. It is used for measuring "ch"
+ * (glyph '0' advance) and "ex" (height of the letter 'x') units.
+ * If a NULL pointer is given, LibCSS will use a fixed scaling of
+ * the "em" unit.
+ */
+typedef struct css_unit_len_ctx {
+ /**
+ * Viewport width in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_width;
+ /**
+ * Viewport height in CSS pixels.
+ * Used if unit is vh, vw, vi, vb, vmin, or vmax.
+ */
+ css_fixed viewport_height;
+ /**
+ * Client default font size in CSS pixels.
+ */
+ css_fixed font_size_default;
+ /**
+ * Client minimum font size in CSS pixels. May be zero.
+ */
+ css_fixed font_size_minimum;
+ /**
+ * DPI of the device the style is selected for.
+ */
+ css_fixed device_dpi;
+ /**
+ * Reference style. Most of the time, this is the element's style.
+ * When converting a length for a typographical property, such as
+ * font-size, then this should be the parent node. If the node has
+ * no parent then this may be NULL.
+ */
+ const css_computed_style *ref_style;
+ /**
+ * Computed style for the document root element.
+ * May be NULL if unit is not rem.
+ */
+ const css_computed_style *root_style;
+ /**
+ * Client private word for measure callback.
+ */
+ void *pw;
+ /**
+ * Client callback for font measuring.
+ */
+ const css_unit_len_measure measure;
+} css_unit_len_ctx;
+
+/**
+ * Convert css pixels to physical pixels.
+ *
+ * \param[in] css_pixels Length in css pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in device pixels.
+ */
+static inline css_fixed css_unit_css2device_px(
+ const css_fixed css_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(css_pixels, device_dpi), F_96);
+}
+
+/**
+ * Convert device pixels to css pixels.
+ *
+ * \param[in] device_pixels Length in physical pixels.
+ * \param[in] device_dpi Device dots per inch.
+ * \return Length in css pixels.
+ */
+static inline css_fixed css_unit_device2css_px(
+ const css_fixed device_pixels,
+ const css_fixed device_dpi)
+{
+ return FDIV(FMUL(device_pixels, F_96), device_dpi);
+}
+
+/**
+ * Convert a length to points (pt).
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in points.
+ */
+css_fixed css_unit_font_size_len2pt(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to CSS pixels.
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in CSS pixels.
+ */
+css_fixed css_unit_len2css_px(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to device pixels.
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in device pixels.
+ */
+css_fixed css_unit_len2device_px(
+ const css_unit_len_ctx *ctx,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert a length to CSS pixels for a media query context.
+ *
+ * \param[in] media Client media specification.
+ * \param[in] length Length to convert.
+ * \param[in] unit Current unit of length.
+ * \return A length in CSS pixels.
+ */
+css_fixed css_unit_len2px_mq(
+ const css_media *media,
+ const css_fixed length,
+ const css_unit unit);
+
+/**
+ * Convert relative font size units to absolute units.
+ *
+ * \param[in] ctx Length unit conversion context.
+ * \param[in,out] size The length to convert.
+ * \return CSS_OK on success, or appropriate error otherwise.
+ */
+css_error css_unit_compute_absolute_font_size(
+ const css_unit_len_ctx *ctx,
+ css_hint *size);
+
+#endif
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=0cf10a040aea028c7dc8...
commit 0cf10a040aea028c7dc81cf353da7a7af5331076
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Units: Remove units that nobody supports.
diff --git a/docs/Bytecode b/docs/Bytecode
index d691923..4914e65 100644
--- a/docs/Bytecode
+++ b/docs/Bytecode
@@ -44,19 +44,16 @@ Length is a 32bit numeric value (as described above) and unit is as follows:
00000101 => mm
00000110 => pt
00000111 => pc
- 00001000 => cap
- 00001001 => ch
- 00001010 => ic
- 00001011 => rem
- 00001100 => lh
- 00001101 => rlh
- 00001110 => vh
- 00001111 => vw
- 00010000 => vi
- 00010001 => vb
- 00010010 => vmin
- 00010011 => vmax
- 00010100 => q
+ 00001000 => ch
+ 00001001 => rem
+ 00001010 => lh
+ 00001011 => vh
+ 00001100 => vw
+ 00001101 => vi
+ 00001110 => vb
+ 00001111 => vmin
+ 00010000 => vmax
+ 00010001 => q
bit 9 set => percentage unit
bits 9-31: MBZ
diff --git a/include/libcss/types.h b/include/libcss/types.h
index d8ac494..1186c6f 100644
--- a/include/libcss/types.h
+++ b/include/libcss/types.h
@@ -88,19 +88,16 @@ typedef enum css_unit {
CSS_UNIT_MM = 0x05,
CSS_UNIT_PT = 0x06,
CSS_UNIT_PC = 0x07,
- CSS_UNIT_CAP = 0x08,
- CSS_UNIT_CH = 0x09,
- CSS_UNIT_IC = 0x0a,
- CSS_UNIT_REM = 0x0b,
- CSS_UNIT_LH = 0x0c,
- CSS_UNIT_RLH = 0x0d,
- CSS_UNIT_VH = 0x0e,
- CSS_UNIT_VW = 0x0f,
- CSS_UNIT_VI = 0x10,
- CSS_UNIT_VB = 0x11,
- CSS_UNIT_VMIN = 0x12,
- CSS_UNIT_VMAX = 0x13,
- CSS_UNIT_Q = 0x14,
+ CSS_UNIT_CH = 0x08,
+ CSS_UNIT_REM = 0x09,
+ CSS_UNIT_LH = 0x0a,
+ CSS_UNIT_VH = 0x0b,
+ CSS_UNIT_VW = 0x0c,
+ CSS_UNIT_VI = 0x0d,
+ CSS_UNIT_VB = 0x0e,
+ CSS_UNIT_VMIN = 0x0f,
+ CSS_UNIT_VMAX = 0x10,
+ CSS_UNIT_Q = 0x11,
CSS_UNIT_PCT = 0x15, /* Percentage */
@@ -116,7 +113,7 @@ typedef enum css_unit {
} css_unit;
/**
- * Media orienations
+ * Media orientations
*/
typedef enum css_media_orientation {
CSS_MEDIA_ORIENTATION_PORTRAIT = 0,
diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h
index 7518281..7f5ea9d 100644
--- a/src/bytecode/bytecode.h
+++ b/src/bytecode/bytecode.h
@@ -34,19 +34,16 @@ typedef enum unit {
UNIT_MM = (1u << 8) + 5,
UNIT_PT = (1u << 8) + 6,
UNIT_PC = (1u << 8) + 7,
- UNIT_CAP = (1u << 8) + 8,
- UNIT_CH = (1u << 8) + 9,
- UNIT_IC = (1u << 8) + 10,
- UNIT_REM = (1u << 8) + 11,
- UNIT_LH = (1u << 8) + 12,
- UNIT_RLH = (1u << 8) + 13,
- UNIT_VH = (1u << 8) + 14,
- UNIT_VW = (1u << 8) + 15,
- UNIT_VI = (1u << 8) + 16,
- UNIT_VB = (1u << 8) + 17,
- UNIT_VMIN = (1u << 8) + 18,
- UNIT_VMAX = (1u << 8) + 19,
- UNIT_Q = (1u << 8) + 20,
+ UNIT_CH = (1u << 8) + 8,
+ UNIT_REM = (1u << 8) + 9,
+ UNIT_LH = (1u << 8) + 10,
+ UNIT_VH = (1u << 8) + 11,
+ UNIT_VW = (1u << 8) + 12,
+ UNIT_VI = (1u << 8) + 13,
+ UNIT_VB = (1u << 8) + 14,
+ UNIT_VMIN = (1u << 8) + 15,
+ UNIT_VMAX = (1u << 8) + 16,
+ UNIT_Q = (1u << 8) + 17,
UNIT_PCT = (1 << 9),
diff --git a/src/parse/properties/font.c b/src/parse/properties/font.c
index 681c613..5010242 100644
--- a/src/parse/properties/font.c
+++ b/src/parse/properties/font.c
@@ -27,12 +27,9 @@ static inline uint32_t css__to_parse_unit(css_unit u)
case CSS_UNIT_MM: return UNIT_MM;
case CSS_UNIT_PT: return UNIT_PT;
case CSS_UNIT_PC: return UNIT_PC;
- case CSS_UNIT_CAP: return UNIT_CAP;
case CSS_UNIT_CH: return UNIT_CH;
- case CSS_UNIT_IC: return UNIT_IC;
case CSS_UNIT_REM: return UNIT_REM;
case CSS_UNIT_LH: return UNIT_LH;
- case CSS_UNIT_RLH: return UNIT_RLH;
case CSS_UNIT_VH: return UNIT_VH;
case CSS_UNIT_VW: return UNIT_VW;
case CSS_UNIT_VI: return UNIT_VI;
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 707a22b..1e184f8 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -1032,12 +1032,8 @@ css_error css__parse_unit_keyword(const char *ptr, size_t len, uint32_t *unit)
*unit = UNIT_DEG;
else if (strncasecmp(ptr, "rad", 3) == 0)
*unit = UNIT_RAD;
- else if (strncasecmp(ptr, "cap", 3) == 0)
- *unit = UNIT_CAP;
else if (strncasecmp(ptr, "rem", 3) == 0)
*unit = UNIT_REM;
- else if (strncasecmp(ptr, "rlh", 3) == 0)
- *unit = UNIT_RLH;
else if (strncasecmp(ptr, "dpi", 3) == 0)
*unit = UNIT_DPI;
else
@@ -1065,8 +1061,6 @@ css_error css__parse_unit_keyword(const char *ptr, size_t len, uint32_t *unit)
*unit = UNIT_PC;
else if (strncasecmp(ptr, "ch", 2) == 0)
*unit = UNIT_CH;
- else if (strncasecmp(ptr, "ic", 2) == 0)
- *unit = UNIT_IC;
else if (strncasecmp(ptr, "lh", 2) == 0)
*unit = UNIT_LH;
else if (strncasecmp(ptr, "vh", 2) == 0)
diff --git a/src/select/helpers.h b/src/select/helpers.h
index ba2e3be..19ff7de 100644
--- a/src/select/helpers.h
+++ b/src/select/helpers.h
@@ -22,12 +22,9 @@ static inline css_unit css__to_css_unit(uint32_t u)
case UNIT_MM: return CSS_UNIT_MM;
case UNIT_PT: return CSS_UNIT_PT;
case UNIT_PC: return CSS_UNIT_PC;
- case UNIT_CAP: return CSS_UNIT_CAP;
case UNIT_CH: return CSS_UNIT_CH;
- case UNIT_IC: return CSS_UNIT_IC;
case UNIT_REM: return CSS_UNIT_REM;
case UNIT_LH: return CSS_UNIT_LH;
- case UNIT_RLH: return CSS_UNIT_RLH;
case UNIT_VH: return CSS_UNIT_VH;
case UNIT_VW: return CSS_UNIT_VW;
case UNIT_VI: return CSS_UNIT_VI;
diff --git a/src/select/mq.h b/src/select/mq.h
index 79303e9..6f98387 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -42,9 +42,7 @@ static inline css_fixed css_len2px(
switch (unit) {
case CSS_UNIT_EM:
case CSS_UNIT_EX:
- case CSS_UNIT_CAP:
case CSS_UNIT_CH:
- case CSS_UNIT_IC:
{
px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
@@ -53,15 +51,9 @@ static inline css_fixed css_len2px(
case CSS_UNIT_EX:
px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
break;
- case CSS_UNIT_CAP:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.9));
- break;
case CSS_UNIT_CH:
px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
break;
- case CSS_UNIT_IC:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(1.1));
- break;
default:
break;
}
@@ -90,9 +82,6 @@ static inline css_fixed css_len2px(
case CSS_UNIT_REM:
px_per_unit = FDIV(FMUL(media->client_font_size, F_96), F_72);
break;
- case CSS_UNIT_RLH:
- px_per_unit = media->client_line_height;
- break;
case CSS_UNIT_VH:
px_per_unit = FDIV(media->height, F_100);
break;
diff --git a/test/data/parse2/units.dat b/test/data/parse2/units.dat
index 1052dc5..800df75 100644
--- a/test/data/parse2/units.dat
+++ b/test/data/parse2/units.dat
@@ -70,14 +70,6 @@
#reset
#data
-* { width: 10cap; }
-#errors
-#expected
-| *
-| width: 10cap
-#reset
-
-#data
* { width: 10ch; }
#errors
#expected
@@ -86,14 +78,6 @@
#reset
#data
-* { width: 10ic; }
-#errors
-#expected
-| *
-| width: 10ic
-#reset
-
-#data
* { width: 10rem; }
#errors
#expected
@@ -110,14 +94,6 @@
#reset
#data
-* { width: 10rlh; }
-#errors
-#expected
-| *
-| width: 10rlh
-#reset
-
-#data
* { width: 10vh; }
#errors
#expected
diff --git a/test/data/select/tests1.dat b/test/data/select/tests1.dat
index 1a91e82..eaf37d7 100644
--- a/test/data/select/tests1.dat
+++ b/test/data/select/tests1.dat
@@ -12419,7 +12419,7 @@ z-index: auto
#tree
| div*
#ua
-div { width: 10cap; }
+div { width: 10em; }
#errors
#expected
align-content: stretch
@@ -12519,7 +12519,7 @@ unicode-bidi: normal
vertical-align: baseline
visibility: visible
white-space: normal
-width: 10cap
+width: 10em
word-spacing: normal
writing-mode: horizontal-tb
z-index: auto
@@ -12637,7 +12637,7 @@ z-index: auto
#tree
| div*
#ua
-div { width: 10ic; }
+div { width: 10ch; }
#errors
#expected
align-content: stretch
@@ -12737,7 +12737,7 @@ unicode-bidi: normal
vertical-align: baseline
visibility: visible
white-space: normal
-width: 10ic
+width: 10ch
word-spacing: normal
writing-mode: horizontal-tb
z-index: auto
@@ -12964,7 +12964,7 @@ z-index: auto
#tree
| div*
#ua
-div { width: 10rlh; }
+div { width: 10rem; }
#errors
#expected
align-content: stretch
@@ -13064,7 +13064,7 @@ unicode-bidi: normal
vertical-align: baseline
visibility: visible
white-space: normal
-width: 10rlh
+width: 10rem
word-spacing: normal
writing-mode: horizontal-tb
z-index: auto
diff --git a/test/dump.h b/test/dump.h
index d67bb2a..79819e0 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -584,24 +584,15 @@ static void dump_unit(css_fixed val, uint32_t unit, char **ptr)
case UNIT_PC:
*ptr += sprintf(*ptr, "pc");
break;
- case UNIT_CAP:
- *ptr += sprintf(*ptr, "cap");
- break;
case UNIT_CH:
*ptr += sprintf(*ptr, "ch");
break;
- case UNIT_IC:
- *ptr += sprintf(*ptr, "ic");
- break;
case UNIT_REM:
*ptr += sprintf(*ptr, "rem");
break;
case UNIT_LH:
*ptr += sprintf(*ptr, "lh");
break;
- case UNIT_RLH:
- *ptr += sprintf(*ptr, "rlh");
- break;
case UNIT_VH:
*ptr += sprintf(*ptr, "vh");
break;
diff --git a/test/dump_computed.h b/test/dump_computed.h
index b0c8bda..8ac6424 100644
--- a/test/dump_computed.h
+++ b/test/dump_computed.h
@@ -105,24 +105,15 @@ static size_t dump_css_unit(css_fixed val, css_unit unit, char *ptr, size_t len)
case CSS_UNIT_PC:
ret += snprintf(ptr + ret, len - ret, "pc");
break;
- case CSS_UNIT_CAP:
- ret += snprintf(ptr + ret, len - ret, "cap");
- break;
case CSS_UNIT_CH:
ret += snprintf(ptr + ret, len - ret, "ch");
break;
- case CSS_UNIT_IC:
- ret += snprintf(ptr + ret, len - ret, "ic");
- break;
case CSS_UNIT_REM:
ret += snprintf(ptr + ret, len - ret, "rem");
break;
case CSS_UNIT_LH:
ret += snprintf(ptr + ret, len - ret, "lh");
break;
- case CSS_UNIT_RLH:
- ret += snprintf(ptr + ret, len - ret, "rlh");
- break;
case CSS_UNIT_VH:
ret += snprintf(ptr + ret, len - ret, "vh");
break;
-----------------------------------------------------------------------
Summary of changes:
--
Cascading Style Sheets library
2 years