Gitweb links: ...log http://git.netsurf-browser.org/libcss.git/shortlog/ecf42afc3329b03ee642ede84f9ba224d2aff1e1 ...commit http://git.netsurf-browser.org/libcss.git/commit/ecf42afc3329b03ee642ede84f9ba224d2aff1e1 ...tree http://git.netsurf-browser.org/libcss.git/tree/ecf42afc3329b03ee642ede84f9ba224d2aff1e1
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=ecf42afc3329b03ee642ede84f9ba224d2aff1e1 commit ecf42afc3329b03ee642ede84f9ba224d2aff1e1 Author: Michael Drake <t...@netsurf-browser.org> Commit: Michael Drake <t...@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=65d4fd6e83d421e7fa7a8c7df44d01797e3c69ae commit 65d4fd6e83d421e7fa7a8c7df44d01797e3c69ae Author: Michael Drake <t...@netsurf-browser.org> Commit: Michael Drake <t...@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 <j...@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=6cd205329373efe5a1629518c2875724cc79dce3 commit 6cd205329373efe5a1629518c2875724cc79dce3 Author: Michael Drake <t...@netsurf-browser.org> Commit: Michael Drake <t...@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 <t...@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 <t...@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=0cf10a040aea028c7dc81cf353da7a7af5331076 commit 0cf10a040aea028c7dc81cf353da7a7af5331076 Author: Michael Drake <t...@netsurf-browser.org> Commit: Michael Drake <t...@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 _______________________________________________ netsurf-commits mailing list -- netsurf-commits@netsurf-browser.org To unsubscribe send an email to netsurf-commits-le...@netsurf-browser.org