summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <Michael Drake tlsa@netsurf-browser.org>2021-03-18 09:16:30 +0000
committerMichael Drake <Michael Drake tlsa@netsurf-browser.org>2021-03-20 11:50:25 +0000
commit0c5718ff8b5e94c8dcc175a1126eec8f3b598161 (patch)
tree19791a87cb9782e23605b307f1e41d1c2e9feed7
parent9db93fe7a99c757c5065d2a6c9738cffa269378e (diff)
downloadlibcss-tlsa/units.tar.gz
libcss-tlsa/units.tar.bz2
Selection: Remove client callback for unit conversion.tlsa/units
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.
-rw-r--r--Makefile1
-rw-r--r--examples/example1.c79
-rw-r--r--include/libcss/computed.h6
-rw-r--r--include/libcss/select.h5
-rw-r--r--include/libcss/unit.h156
-rw-r--r--src/select/computed.c34
-rw-r--r--src/select/computed.h6
-rw-r--r--src/select/select.c5
-rw-r--r--src/select/unit.c67
-rw-r--r--src/select/unit.h143
-rw-r--r--test/data/select/tests1.dat246
-rw-r--r--test/select.c85
12 files changed, 390 insertions, 443 deletions
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@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 ccce94d..919ca88 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 664994e..8226a8b 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,
@@ -765,7 +767,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) {
@@ -773,7 +780,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;
@@ -786,6 +793,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);
}
@@ -1606,68 +1617,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)
{