Switch to new libcss API for unit conversion.

This commit is contained in:
Michael Drake 2021-03-29 10:45:59 +01:00 committed by Michael Drake
parent 638a408dde
commit fa64d91d12
24 changed files with 542 additions and 883 deletions

View File

@ -1,4 +1,4 @@
# CSS sources
S_CSS := css.c dump.c internal.c hints.c select.c utils.c
S_CSS := css.c dump.c internal.c hints.c select.c

View File

@ -40,6 +40,9 @@
/* Define to trace import fetches */
#undef NSCSS_IMPORT_TRACE
/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
css_fixed nscss_screen_dpi = F_90;
struct content_css_data;
/**

View File

@ -91,10 +91,6 @@ static css_error set_libcss_node_data(void *pw, void *node,
static css_error get_libcss_node_data(void *pw, void *node,
void **libcss_node_data);
static css_error nscss_compute_font_size(void *pw, const css_hint *parent,
css_hint *size);
/**
* Selection callback table for libcss
*/
@ -135,9 +131,8 @@ static css_select_handler selection_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
nscss_compute_font_size,
set_libcss_node_data,
get_libcss_node_data
get_libcss_node_data,
};
/**
@ -250,12 +245,15 @@ static void nscss_dom_user_data_handler(dom_node_operation operation,
* \param ctx CSS selection context
* \param n Element to select for
* \param media Permitted media types
* \param unit_unit_len_ctx Unit length conversion context
* \param inline_style Inline style associated with element, or NULL
* \return Pointer to selection results (containing computed styles),
* or NULL on failure
*/
css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
const css_media *media, const css_stylesheet *inline_style)
const css_media *media,
const css_unit_ctx *unit_len_ctx,
const css_stylesheet *inline_style)
{
css_computed_style *composed;
css_select_results *styles;
@ -263,7 +261,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
css_error error;
/* Select style for node */
error = css_select_style(ctx->ctx, n, media, inline_style,
error = css_select_style(ctx->ctx, n, unit_len_ctx, media, inline_style,
&selection_handler, ctx, &styles);
if (error != CSS_OK || styles == NULL) {
@ -278,8 +276,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
* element's style */
error = css_computed_style_compose(ctx->parent_style,
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
nscss_compute_font_size, ctx,
&composed);
unit_len_ctx, &composed);
if (error != CSS_OK) {
css_select_results_destroy(styles);
return NULL;
@ -310,8 +307,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
error = css_computed_style_compose(
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
styles->styles[pseudo_element],
nscss_compute_font_size, ctx,
&composed);
unit_len_ctx, &composed);
if (error != CSS_OK) {
/* TODO: perhaps this shouldn't be quite so
* catastrophic? */
@ -330,11 +326,13 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
/**
* Get a blank style
*
* \param ctx CSS selection context
* \param parent Parent style to cascade inherited properties from
* \param ctx CSS selection context
* \param unit_unit_len_ctx Unit length conversion context
* \param parent Parent style to cascade inherited properties from
* \return Pointer to blank style, or NULL on failure
*/
css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
const css_unit_ctx *unit_len_ctx,
const css_computed_style *parent)
{
css_computed_style *partial, *composed;
@ -349,7 +347,7 @@ css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
/* TODO: Do we really need to compose? Initial style shouldn't
* have any inherited properties. */
error = css_computed_style_compose(parent, partial,
nscss_compute_font_size, ctx, &composed);
unit_len_ctx, &composed);
css_computed_style_destroy(partial);
if (error != CSS_OK) {
css_computed_style_destroy(composed);
@ -359,115 +357,6 @@ css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
return composed;
}
/**
* Font size computation callback for libcss
*
* \param pw Computation context
* \param parent Parent font size (absolute)
* \param size Font size to compute
* \return CSS_OK on success
*
* \post \a size will be an absolute font size
*/
css_error nscss_compute_font_size(void *pw, const css_hint *parent,
css_hint *size)
{
/**
* Table of font-size keyword scale factors
*
* These are multiplied by the configured default font size
* to produce an absolute size for the relevant keyword
*/
static const css_fixed factors[] = {
FLTTOFIX(0.5625), /* xx-small */
FLTTOFIX(0.6250), /* x-small */
FLTTOFIX(0.8125), /* small */
FLTTOFIX(1.0000), /* medium */
FLTTOFIX(1.1250), /* large */
FLTTOFIX(1.5000), /* x-large */
FLTTOFIX(2.0000) /* xx-large */
};
css_hint_length parent_size;
/* Grab parent size, defaulting to medium if none */
if (parent == NULL) {
parent_size.value = FDIV(FMUL(factors[CSS_FONT_SIZE_MEDIUM - 1],
INTTOFIX(nsoption_int(font_size))),
INTTOFIX(10));
parent_size.unit = CSS_UNIT_PT;
} else {
assert(parent->status == CSS_FONT_SIZE_DIMENSION);
assert(parent->data.length.unit != CSS_UNIT_EM);
assert(parent->data.length.unit != CSS_UNIT_EX);
assert(parent->data.length.unit != CSS_UNIT_PCT);
parent_size = parent->data.length;
}
assert(size->status != CSS_FONT_SIZE_INHERIT);
if (size->status < CSS_FONT_SIZE_LARGER) {
/* Keyword -- simple */
size->data.length.value = FDIV(FMUL(factors[size->status - 1],
INTTOFIX(nsoption_int(font_size))), F_10);
size->data.length.unit = CSS_UNIT_PT;
} else if (size->status == CSS_FONT_SIZE_LARGER) {
/** \todo Step within table, if appropriate */
size->data.length.value =
FMUL(parent_size.value, FLTTOFIX(1.2));
size->data.length.unit = parent_size.unit;
} else if (size->status == CSS_FONT_SIZE_SMALLER) {
/** \todo Step within table, if appropriate */
size->data.length.value =
FDIV(parent_size.value, FLTTOFIX(1.2));
size->data.length.unit = parent_size.unit;
} else if (size->data.length.unit == CSS_UNIT_EM ||
size->data.length.unit == CSS_UNIT_EX ||
size->data.length.unit == CSS_UNIT_CH) {
size->data.length.value =
FMUL(size->data.length.value, parent_size.value);
switch (size->data.length.unit) {
case CSS_UNIT_EX:
/* 1ex = 0.6em in NetSurf */
size->data.length.value = FMUL(size->data.length.value,
FLTTOFIX(0.6));
break;
case CSS_UNIT_CH:
/* Width of '0'. 1ch = 0.4em in NetSurf. */
size->data.length.value = FMUL(size->data.length.value,
FLTTOFIX(0.4));
break;
default:
/* No scaling required for EM. */
break;
}
size->data.length.unit = parent_size.unit;
} else if (size->data.length.unit == CSS_UNIT_PCT) {
size->data.length.value = FDIV(FMUL(size->data.length.value,
parent_size.value), INTTOFIX(100));
size->data.length.unit = parent_size.unit;
} else if (size->data.length.unit == CSS_UNIT_REM) {
nscss_select_ctx *ctx = pw;
if (parent == NULL) {
size->data.length.value = parent_size.value;
size->data.length.unit = parent_size.unit;
} else {
css_computed_font_size(ctx->root_style,
&parent_size.value,
&size->data.length.unit);
size->data.length.value = FMUL(
size->data.length.value,
parent_size.value);
}
}
size->status = CSS_FONT_SIZE_DIMENSION;
return CSS_OK;
}
/******************************************************************************
* Style selection callbacks *
******************************************************************************/

View File

@ -45,9 +45,12 @@ css_stylesheet *nscss_create_inline_style(const uint8_t *data, size_t len,
const char *charset, const char *url, bool allow_quirks);
css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
const css_media *media, const css_stylesheet *inline_style);
const css_media *media,
const css_unit_ctx *unit_len_ctx,
const css_stylesheet *inline_style);
css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
const css_unit_ctx *unit_len_ctx,
const css_computed_style *parent);

View File

@ -1,242 +0,0 @@
/*
* Copyright 2004 James Bursa <james@netsurf-browser.org>
* Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include "utils/nsoption.h"
#include "utils/log.h"
#include "css/utils.h"
/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
css_fixed nscss_screen_dpi = F_90;
/** Medium screen density for device viewing distance. */
css_fixed nscss_baseline_pixel_density = F_96;
/**
* Map viewport-relative length units to either vh or vw.
*
* Non-viewport-relative units are unchanged.
*
* \param[in] ctx Length conversion context.
* \param[in] unit Unit to map.
* \return the mapped unit.
*/
static inline css_unit css_utils__fudge_viewport_units(
const nscss_len_ctx *ctx,
css_unit unit)
{
switch (unit) {
case CSS_UNIT_VI:
assert(ctx->root_style != NULL);
if (css_computed_writing_mode(ctx->root_style) ==
CSS_WRITING_MODE_HORIZONTAL_TB) {
unit = CSS_UNIT_VW;
} else {
unit = CSS_UNIT_VH;
}
break;
case CSS_UNIT_VB:
assert(ctx->root_style != NULL);
if (css_computed_writing_mode(ctx->root_style) ==
CSS_WRITING_MODE_HORIZONTAL_TB) {
unit = CSS_UNIT_VH;
} else {
unit = CSS_UNIT_VW;
}
break;
case CSS_UNIT_VMIN:
if (ctx->vh < ctx->vw) {
unit = CSS_UNIT_VH;
} else {
unit = CSS_UNIT_VW;
}
break;
case CSS_UNIT_VMAX:
if (ctx->vh > ctx->vw) {
unit = CSS_UNIT_VH;
} else {
unit = CSS_UNIT_VW;
}
break;
default: break;
}
return unit;
}
/* exported interface documented in content/handlers/css/utils.h */
css_fixed nscss_len2pt(
const nscss_len_ctx *ctx,
css_fixed length,
css_unit unit)
{
/* Length must not be relative */
assert(unit != CSS_UNIT_EM &&
unit != CSS_UNIT_EX &&
unit != CSS_UNIT_CH &&
unit != CSS_UNIT_REM);
unit = css_utils__fudge_viewport_units(ctx, unit);
switch (unit) {
/* We assume the screen and any other output has the same dpi */
/* 1in = DPIpx => 1px = (72/DPI)pt */
case CSS_UNIT_PX: return FDIV(FMUL(length, F_72), F_96);
/* 1in = 72pt */
case CSS_UNIT_IN: return FMUL(length, F_72);
/* 1in = 2.54cm => 1cm = (72/2.54)pt */
case CSS_UNIT_CM: return FMUL(length,
FDIV(F_72, FLTTOFIX(2.54)));
/* 1in = 25.4mm => 1mm = (72/25.4)pt */
case CSS_UNIT_MM: return FMUL(length,
FDIV(F_72, FLTTOFIX(25.4)));
/* 1in = 101.6q => 1mm = (72/101.6)pt */
case CSS_UNIT_Q: return FMUL(length,
FDIV(F_72, FLTTOFIX(101.6)));
case CSS_UNIT_PT: return length;
/* 1pc = 12pt */
case CSS_UNIT_PC: return FMUL(length, INTTOFIX(12));
case CSS_UNIT_VH: return FDIV(FMUL(FDIV(FMUL(length, ctx->vh), F_100), F_72), F_96);
case CSS_UNIT_VW: return FDIV(FMUL(FDIV(FMUL(length,ctx->vw), F_100), F_72), F_96);
default: break;
}
return 0;
}
/* exported interface documented in content/handlers/css/utils.h */
css_fixed nscss_len2px(
const nscss_len_ctx *ctx,
css_fixed length,
css_unit unit,
const css_computed_style *style)
{
/* We assume the screen and any other output has the same dpi */
css_fixed px_per_unit;
unit = css_utils__fudge_viewport_units(ctx, unit);
switch (unit) {
case CSS_UNIT_EM:
case CSS_UNIT_EX:
case CSS_UNIT_CH:
{
css_fixed font_size = 0;
css_unit font_unit = CSS_UNIT_PT;
assert(style != NULL);
css_computed_font_size(style, &font_size, &font_unit);
/* Convert to points */
font_size = nscss_len2pt(ctx, font_size, font_unit);
/* Clamp to configured minimum */
if (font_size < FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)) {
font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10);
}
/* Convert to pixels (manually, to maximise precision)
* 1in = 72pt => 1pt = (DPI/72)px */
px_per_unit = FDIV(FMUL(font_size, F_96), F_72);
/* Scale non-em units to em. We have fixed ratios. */
switch (unit) {
case CSS_UNIT_EX:
px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
break;
case CSS_UNIT_CH:
px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
break;
default: break;
}
}
break;
case CSS_UNIT_PX:
px_per_unit = F_1;
break;
/* 1in = 96 CSS pixels */
case CSS_UNIT_IN:
px_per_unit = F_96;
break;
/* 1in = 2.54cm => 1cm = (DPI/2.54)px */
case CSS_UNIT_CM:
px_per_unit = FDIV(F_96, FLTTOFIX(2.54));
break;
/* 1in = 25.4mm => 1mm = (DPI/25.4)px */
case CSS_UNIT_MM:
px_per_unit = FDIV(F_96, FLTTOFIX(25.4));
break;
/* 1in = 101.6q => 1q = (DPI/101.6)px */
case CSS_UNIT_Q:
px_per_unit = FDIV(F_96, FLTTOFIX(101.6));
break;
/* 1in = 72pt => 1pt = (DPI/72)px */
case CSS_UNIT_PT:
px_per_unit = FDIV(F_96, F_72);
break;
/* 1pc = 12pt => 1in = 6pc => 1pc = (DPI/6)px */
case CSS_UNIT_PC:
px_per_unit = FDIV(F_96, INTTOFIX(6));
break;
case CSS_UNIT_REM:
{
css_fixed font_size = 0;
css_unit font_unit = CSS_UNIT_PT;
assert(ctx->root_style != NULL);
css_computed_font_size(ctx->root_style,
&font_size, &font_unit);
/* Convert to points */
font_size = nscss_len2pt(ctx, font_size, font_unit);
/* Clamp to configured minimum */
if (font_size < FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)) {
font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10);
}
/* Convert to pixels (manually, to maximise precision)
* 1in = 72pt => 1pt = (DPI/72)px */
px_per_unit = FDIV(FMUL(font_size, F_96), F_72);
break;
}
case CSS_UNIT_VH:
px_per_unit = FDIV(ctx->vh, F_100);
break;
case CSS_UNIT_VW:
px_per_unit = FDIV(ctx->vw, F_100);
break;
default:
px_per_unit = 0;
break;
}
px_per_unit = nscss_pixels_css_to_physical(px_per_unit);
/* Ensure we round px_per_unit to the nearest whole number of pixels:
* the use of FIXTOINT() below will truncate. */
px_per_unit += F_0_5;
/* Calculate total number of pixels */
return FMUL(length, TRUNCATEFIX(px_per_unit));
}

View File

@ -26,85 +26,6 @@
/** DPI of the screen, in fixed point units */
extern css_fixed nscss_screen_dpi;
/** Medium screen density for device viewing distance. */
extern css_fixed nscss_baseline_pixel_density;
/**
* Length conversion context data.
*/
typedef struct nscss_len_ctx {
/**
* Viewport width in px.
* Only used if unit is vh, vw, vi, vb, vmin, or vmax.
*/
int vw;
/**
* Viewport height in px.
* Only used if unit is vh, vw, vi, vb, vmin, or vmax.
*/
int vh;
/**
* Computed style for the document root element.
* May be NULL if unit is not rem, or rlh.
*/
const css_computed_style *root_style;
} nscss_len_ctx;
/**
* Convert an absolute CSS length to points.
*
* \param[in] ctx Length conversion context.
* \param[in] length Absolute CSS length.
* \param[in] unit Unit of the length.
* \return length in points
*/
css_fixed nscss_len2pt(
const nscss_len_ctx *ctx,
css_fixed length,
css_unit unit);
/**
* Convert a CSS length to pixels.
*
* \param[in] ctx Length conversion context.
* \param[in] length Length to convert.
* \param[in] unit Corresponding unit.
* \param[in] style Computed style applying to length.
* May be NULL if unit is not em, ex, cap, ch, or ic.
* \return length in pixels
*/
css_fixed nscss_len2px(
const nscss_len_ctx *ctx,
css_fixed length,
css_unit unit,
const css_computed_style *style);
/**
* Convert css pixels to physical pixels.
*
* \param[in] css_pixels Length in css pixels.
* \return length in physical pixels
*/
static inline css_fixed nscss_pixels_css_to_physical(
css_fixed css_pixels)
{
return FDIV(FMUL(css_pixels, nscss_screen_dpi),
nscss_baseline_pixel_density);
}
/**
* Convert physical pixels to css pixels.
*
* \param[in] physical_pixels Length in physical pixels.
* \return length in css pixels
*/
static inline css_fixed nscss_pixels_physical_to_css(
css_fixed physical_pixels)
{
return FDIV(FMUL(physical_pixels, nscss_baseline_pixel_density),
nscss_screen_dpi);
}
/**
* Temporary helper wrappers for for libcss computed style getter, while
* we don't support flexbox related property values.

View File

@ -282,7 +282,8 @@ box_get_style(html_content *c,
ctx.parent_style = parent_style;
/* Select style for element */
styles = nscss_get_style(&ctx, n, &c->media, inline_style);
styles = nscss_get_style(&ctx, n, &c->media, &c->unit_len_ctx,
inline_style);
/* No longer need inline style */
if (inline_style != NULL)

View File

@ -56,7 +56,7 @@ enum box_walk_dir {
/**
* Determine if a point lies within a box.
*
* \param[in] len_ctx CSS length conversion context to use.
* \param[in] unit_len_ctx CSS length conversion context to use.
* \param[in] box Box to consider
* \param[in] x Coordinate relative to box
* \param[in] y Coordinate relative to box
@ -71,7 +71,7 @@ enum box_walk_dir {
* This is a helper function for box_at_point().
*/
static bool
box_contains_point(const nscss_len_ctx *len_ctx,
box_contains_point(const css_unit_ctx *unit_len_ctx,
const struct box *box,
int x,
int y,
@ -101,30 +101,34 @@ box_contains_point(const nscss_len_ctx *len_ctx,
/* Adjust rect to css clip region */
if (css_rect.left_auto == false) {
r.x0 += FIXTOINT(nscss_len2px(len_ctx,
css_rect.left,
css_rect.lunit,
box->style));
r.x0 += FIXTOINT(css_unit_len2device_px(
box->style,
unit_len_ctx,
css_rect.left,
css_rect.lunit));
}
if (css_rect.top_auto == false) {
r.y0 += FIXTOINT(nscss_len2px(len_ctx,
css_rect.top,
css_rect.tunit,
box->style));
r.y0 += FIXTOINT(css_unit_len2device_px(
box->style,
unit_len_ctx,
css_rect.top,
css_rect.tunit));
}
if (css_rect.right_auto == false) {
r.x1 = box->border[LEFT].width +
FIXTOINT(nscss_len2px(len_ctx,
css_rect.right,
css_rect.runit,
box->style));
FIXTOINT(css_unit_len2device_px(
box->style,
unit_len_ctx,
css_rect.right,
css_rect.runit));
}
if (css_rect.bottom_auto == false) {
r.y1 = box->border[TOP].width +
FIXTOINT(nscss_len2px(len_ctx,
css_rect.bottom,
css_rect.bunit,
box->style));
FIXTOINT(css_unit_len2device_px(
box->style,
unit_len_ctx,
css_rect.bottom,
css_rect.bunit));
}
/* Test if point is in clipped box */
@ -575,7 +579,7 @@ void box_bounds(struct box *box, struct rect *r)
/* Exported function documented in html/box.h */
struct box *
box_at_point(const nscss_len_ctx *len_ctx,
box_at_point(const css_unit_ctx *unit_len_ctx,
struct box *box,
const int x, const int y,
int *box_x, int *box_y)
@ -587,7 +591,7 @@ box_at_point(const nscss_len_ctx *len_ctx,
skip_children = false;
while ((box = box_next_xy(box, box_x, box_y, skip_children))) {
if (box_contains_point(len_ctx, box, x - *box_x, y - *box_y,
if (box_contains_point(unit_len_ctx, box, x - *box_x, y - *box_y,
&physically)) {
*box_x -= scrollbar_get_offset(box->scroll_x);
*box_y -= scrollbar_get_offset(box->scroll_y);

View File

@ -46,7 +46,7 @@ void box_bounds(struct box *box, struct rect *r);
/**
* Find the boxes at a point.
*
* \param len_ctx CSS length conversion context for document.
* \param unit_len_ctx CSS length conversion context for document.
* \param box box to search children of
* \param x point to find, in global document coordinates
* \param y point to find, in global document coordinates
@ -62,12 +62,12 @@ void box_bounds(struct box *box, struct rect *r);
* struct box *box = top_of_document_to_search;
* int box_x = 0, box_y = 0;
*
* while ((box = box_at_point(len_ctx, box, x, y, &box_x, &box_y))) {
* while ((box = box_at_point(unit_len_ctx, box, x, y, &box_x, &box_y))) {
* // process box
* }
* \endcode
*/
struct box *box_at_point(const nscss_len_ctx *len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
struct box *box_at_point(const css_unit_ctx *unit_len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
/**

View File

@ -190,7 +190,8 @@ box_normalise_table_row(struct box *row,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx, row->style);
style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
row->style);
if (style == NULL)
return false;
@ -326,7 +327,8 @@ box_normalise_table_row_group(struct box *row_group,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx, row_group->style);
style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
row_group->style);
if (style == NULL)
return false;
@ -402,7 +404,8 @@ box_normalise_table_row_group(struct box *row_group,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx, row_group->style);
style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
row_group->style);
if (style == NULL) {
return false;
}
@ -533,6 +536,7 @@ box_normalise_table_spans(struct box *table,
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx,
&c->unit_len_ctx,
table_row->style);
if (style == NULL)
return false;
@ -657,7 +661,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx, table->style);
style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
table->style);
if (style == NULL) {
free(col_info.spans);
return false;
@ -744,7 +749,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx, table->style);
style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
table->style);
if (style == NULL) {
free(col_info.spans);
return false;
@ -759,7 +765,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
}
row_group->type = BOX_TABLE_ROW_GROUP;
style = nscss_get_blank_style(&ctx, row_group->style);
style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
row_group->style);
if (style == NULL) {
box_free(row_group);
free(col_info.spans);
@ -948,7 +955,8 @@ box_normalise_block(struct box *block, const struct box *root, html_content *c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx, block->style);
style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
block->style);
if (style == NULL)
return false;

View File

@ -133,7 +133,7 @@ static plot_font_flags_t plot_font_flags(enum css_font_style_e style,
/* exported function documented in html/font.h */
void font_plot_style_from_css(
const nscss_len_ctx *len_ctx,
const css_unit_ctx *unit_len_ctx,
const css_computed_style *css,
plot_font_style_t *fstyle)
{
@ -147,7 +147,8 @@ void font_plot_style_from_css(
fstyle->families = families;
css_computed_font_size(css, &length, &unit);
fstyle->size = FIXTOINT(FMUL(nscss_len2pt(len_ctx, length, unit),
fstyle->size = FIXTOINT(FMUL(css_unit_font_size_len2pt(css,
unit_len_ctx, length, unit),
INTTOFIX(PLOT_STYLE_SCALE)));
/* Clamp font size to configured minimum */

View File

@ -32,11 +32,11 @@ struct plot_font_style;
/**
* Populate a font style using data from a computed CSS style
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param css Computed style to consider
* \param fstyle Font style to populate
*/
void font_plot_style_from_css(const nscss_len_ctx *len_ctx,
void font_plot_style_from_css(const css_unit_ctx *unit_len_ctx,
const css_computed_style *css,
struct plot_font_style *fstyle);

View File

@ -1594,12 +1594,12 @@ form_open_select_menu(void *client_data,
box->border[RIGHT].width + box->padding[RIGHT] +
box->border[LEFT].width + box->padding[LEFT];
font_plot_style_from_css(&html->len_ctx, control->box->style,
&fstyle);
font_plot_style_from_css(&html->unit_len_ctx,
control->box->style, &fstyle);
menu->f_size = fstyle.size;
menu->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2),
FMUL(nscss_screen_dpi,
FMUL(html->unit_len_ctx.device_dpi,
INTTOFIX(fstyle.size / PLOT_STYLE_SCALE)))),
F_72));

View File

@ -305,6 +305,9 @@ html_proceed_to_done(html_content *html)
static void html_get_dimensions(html_content *htmlc)
{
css_fixed device_dpi = nscss_screen_dpi;
unsigned f_size;
unsigned f_min;
unsigned w;
unsigned h;
union content_msg_data msg_data = {
@ -316,13 +319,22 @@ static void html_get_dimensions(html_content *htmlc)
content_broadcast(&htmlc->base, CONTENT_MSG_GETDIMS, &msg_data);
htmlc->media.width = nscss_pixels_physical_to_css(INTTOFIX(w));
htmlc->media.height = nscss_pixels_physical_to_css(INTTOFIX(h));
htmlc->media.client_font_size =
FDIV(INTTOFIX(nsoption_int(font_size)), F_10);
htmlc->media.client_line_height =
FMUL(nscss_len2px(NULL, htmlc->media.client_font_size,
CSS_UNIT_PT, NULL), FLTTOFIX(1.33));
w = css_unit_device2css_px(INTTOFIX(w), device_dpi);
h = css_unit_device2css_px(INTTOFIX(h), device_dpi);
htmlc->media.width = w;
htmlc->media.height = h;
htmlc->unit_len_ctx.viewport_width = w;
htmlc->unit_len_ctx.viewport_height = h;
htmlc->unit_len_ctx.device_dpi = device_dpi;
/** \todo Change nsoption font sizes to px. */
f_size = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_size)), F_10)), F_72);
f_min = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)), F_72);
htmlc->unit_len_ctx.font_size_default = f_size;
htmlc->unit_len_ctx.font_size_minimum = f_min;
}
/* exported function documented in html/html_internal.h */
@ -1035,9 +1047,11 @@ static void html_reformat(struct content *c, int width, int height)
htmlc->reflowing = true;
htmlc->len_ctx.vw = nscss_pixels_physical_to_css(INTTOFIX(width));
htmlc->len_ctx.vh = nscss_pixels_physical_to_css(INTTOFIX(height));
htmlc->len_ctx.root_style = htmlc->layout->style;
htmlc->unit_len_ctx.viewport_width = css_unit_device2css_px(
INTTOFIX(width), htmlc->unit_len_ctx.device_dpi);
htmlc->unit_len_ctx.viewport_height = css_unit_device2css_px(
INTTOFIX(height), htmlc->unit_len_ctx.device_dpi);
htmlc->unit_len_ctx.root_style = htmlc->layout->style;
layout_document(htmlc, width, height);
layout = htmlc->layout;
@ -1427,7 +1441,7 @@ html_get_contextual_content(struct content *c, int x, int y,
struct box *next;
int box_x = 0, box_y = 0;
while ((next = box_at_point(&html->len_ctx, box, x, y,
while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
@ -1508,7 +1522,7 @@ html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
/* TODO: invert order; visit deepest box first */
while ((next = box_at_point(&html->len_ctx, box, x, y,
while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
@ -1657,7 +1671,7 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
int box_x = 0, box_y = 0;
/* Scan box tree for boxes that can handle drop */
while ((next = box_at_point(&html->len_ctx, box, x, y,
while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;

View File

@ -211,7 +211,7 @@ static size_t html_selection_drag_end(struct html_content *html,
if (box) {
plot_font_style_t fstyle;
font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
guit->layout->position(&fstyle, box->text, box->length,
dx, &idx, &pixel_offset);
@ -424,7 +424,7 @@ mouse_action_drag_selection(html_content *html,
box = box_pick_text_box(html, x, y, dir, &dx, &dy);
if (box != NULL) {
font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
guit->layout->position(&fstyle,
box->text,
@ -805,7 +805,7 @@ get_mouse_action_node(html_content *html,
next_box:
/* iterate to next box */
box = box_at_point(&html->len_ctx, box, x, y, &box_x, &box_y);
box = box_at_point(&html->unit_len_ctx, box, x, y, &box_x, &box_y);
} while (box != NULL);
/* use of box_x, box_y, or content below this point is probably a
@ -1209,7 +1209,7 @@ default_mouse_action(html_content *html,
size_t idx;
plot_font_style_t fstyle;
font_plot_style_from_css(&html->len_ctx,
font_plot_style_from_css(&html->unit_len_ctx,
mas->text.box->style,
&fstyle);

File diff suppressed because it is too large Load Diff

View File

@ -265,18 +265,20 @@ html_object_callback(hlcache_handle *object,
if (hunit == CSS_UNIT_PCT) {
l = (width - w) * hpos / INTTOFIX(100);
} else {
l = FIXTOINT(nscss_len2px(&c->len_ctx,
hpos, hunit,
box->style));
l = FIXTOINT(css_unit_len2device_px(
box->style,
&c->unit_len_ctx,
hpos, hunit));
}
h = content_get_height(box->background);
if (vunit == CSS_UNIT_PCT) {
t = (height - h) * vpos / INTTOFIX(100);
} else {
t = FIXTOINT(nscss_len2px(&c->len_ctx,
vpos, vunit,
box->style));
t = FIXTOINT(css_unit_len2device_px(
box->style,
&c->unit_len_ctx,
vpos, vunit));
}
/* Redraw area depends on background-repeat */

View File

@ -112,9 +112,6 @@ typedef struct html_content {
/** Base target */
char *base_target;
/** CSS length conversion context for document. */
nscss_len_ctx len_ctx;
/** Content has been aborted in the LOADING state */
bool aborted;
@ -162,6 +159,8 @@ typedef struct html_content {
css_select_ctx *select_ctx;
/**< Style selection media specification */
css_media media;
/** CSS length conversion context for document. */
css_unit_ctx unit_len_ctx;
/**< Universal selector */
lwc_string *universal;

View File

@ -528,14 +528,14 @@ static bool html_redraw_radio(int x, int y, int width, int height,
* \param box box of input
* \param scale scale for redraw
* \param background_colour current background colour
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
static bool html_redraw_file(int x, int y, int width, int height,
struct box *box, float scale, colour background_colour,
const nscss_len_ctx *len_ctx,
const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
int text_width;
@ -544,7 +544,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
plot_font_style_t fstyle;
nserror res;
font_plot_style_from_css(len_ctx, box->style, &fstyle);
font_plot_style_from_css(unit_len_ctx, box->style, &fstyle);
fstyle.background = background_colour;
if (box->gadget->value) {
@ -587,7 +587,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
* \param clip current clip rectangle
* \param background_colour current background colour
* \param background box containing background details (usually \a box)
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
@ -595,7 +595,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
static bool html_redraw_background(int x, int y, struct box *box, float scale,
const struct rect *clip, colour *background_colour,
struct box *background,
const nscss_len_ctx *len_ctx,
const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
bool repeat_x = false;
@ -672,8 +672,9 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
content_get_width(background->background)) *
scale * FIXTOFLT(hpos) / 100.;
} else {
x += (int) (FIXTOFLT(nscss_len2px(len_ctx, hpos, hunit,
background->style)) * scale);
x += (int) (FIXTOFLT(css_unit_len2device_px(
background->style, unit_len_ctx,
hpos, hunit)) * scale);
}
if (vunit == CSS_UNIT_PCT) {
@ -681,8 +682,9 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
content_get_height(background->background)) *
scale * FIXTOFLT(vpos) / 100.;
} else {
y += (int) (FIXTOFLT(nscss_len2px(len_ctx, vpos, vunit,
background->style)) * scale);
y += (int) (FIXTOFLT(css_unit_len2device_px(
background->style, unit_len_ctx,
vpos, vunit)) * scale);
}
}
@ -814,7 +816,7 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
* \param first true if this is the first rectangle associated with the inline
* \param last true if this is the last rectangle associated with the inline
* \param background_colour updated to current background colour if plotted
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
@ -822,7 +824,7 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
static bool html_redraw_inline_background(int x, int y, struct box *box,
float scale, const struct rect *clip, struct rect b,
bool first, bool last, colour *background_colour,
const nscss_len_ctx *len_ctx,
const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
struct rect r = *clip;
@ -883,8 +885,9 @@ static bool html_redraw_inline_background(int x, int y, struct box *box,
plot_content = false;
}
} else {
x += (int) (FIXTOFLT(nscss_len2px(len_ctx, hpos, hunit,
box->style)) * scale);
x += (int) (FIXTOFLT(css_unit_len2device_px(
box->style, unit_len_ctx,
hpos, hunit)) * scale);
}
if (vunit == CSS_UNIT_PCT) {
@ -892,8 +895,9 @@ static bool html_redraw_inline_background(int x, int y, struct box *box,
content_get_height(box->background) *
scale) * FIXTOFLT(vpos) / 100.;
} else {
y += (int) (FIXTOFLT(nscss_len2px(len_ctx, vpos, vunit,
box->style)) * scale);
y += (int) (FIXTOFLT(css_unit_len2device_px(
box->style, unit_len_ctx,
vpos, vunit)) * scale);
}
}
@ -1134,7 +1138,7 @@ static bool html_redraw_text_box(const html_content *html, struct box *box,
bool excluded = (box->object != NULL);
plot_font_style_t fstyle;
font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
fstyle.background = current_background_color;
if (!text_redraw(box->text,
@ -1405,28 +1409,24 @@ bool html_redraw_box(const html_content *html, struct box *box,
CSS_CLIP_RECT) {
/* We have an absolutly positioned box with a clip rect */
if (css_rect.left_auto == false)
r.x0 = x - border_left + FIXTOINT(nscss_len2px(
&html->len_ctx,
css_rect.left, css_rect.lunit,
box->style));
r.x0 = x - border_left + FIXTOINT(css_unit_len2device_px(
box->style, &html->unit_len_ctx,
css_rect.left, css_rect.lunit));
if (css_rect.top_auto == false)
r.y0 = y - border_top + FIXTOINT(nscss_len2px(
&html->len_ctx,
css_rect.top, css_rect.tunit,
box->style));
r.y0 = y - border_top + FIXTOINT(css_unit_len2device_px(
box->style, &html->unit_len_ctx,
css_rect.top, css_rect.tunit));
if (css_rect.right_auto == false)
r.x1 = x - border_left + FIXTOINT(nscss_len2px(
&html->len_ctx,
css_rect.right, css_rect.runit,
box->style));
r.x1 = x - border_left + FIXTOINT(css_unit_len2device_px(
box->style, &html->unit_len_ctx,
css_rect.right, css_rect.runit));
if (css_rect.bottom_auto == false)
r.y1 = y - border_top + FIXTOINT(nscss_len2px(
&html->len_ctx,
css_rect.bottom, css_rect.bunit,
box->style));
r.y1 = y - border_top + FIXTOINT(css_unit_len2device_px(
box->style, &html->unit_len_ctx,
css_rect.bottom, css_rect.bunit));
/* find intersection of clip rectangle and box */
if (r.x0 < clip->x0) r.x0 = clip->x0;
@ -1515,7 +1515,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
/* plot background */
if (!html_redraw_background(x, y, box, scale, &p,
&current_background_color, bg_box,
&html->len_ctx, ctx))
&html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@ -1595,7 +1595,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
x, y, box, scale, &p, b,
first, false,
&current_background_color,
&html->len_ctx, ctx))
&html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@ -1628,7 +1628,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
* the inline */
if (!html_redraw_inline_background(x, ib_y, box, scale, &p, b,
first, true, &current_background_color,
&html->len_ctx, ctx))
&html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@ -1843,7 +1843,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
} else if (box->gadget && box->gadget->type == GADGET_FILE) {
if (!html_redraw_file(x + padding_left, y + padding_top,
width, height, box, scale,
current_background_color, &html->len_ctx, ctx))
current_background_color, &html->unit_len_ctx, ctx))
return false;
} else if (box->gadget &&

View File

@ -50,7 +50,7 @@ struct border {
/**
* Determine if a border style is more eyecatching than another
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param a Reference border style
* \param a_src Source of \a a
* \param b Candidate border style
@ -58,7 +58,7 @@ struct border {
* \return True if \a b is more eyecatching than \a a
*/
static bool
table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
table_border_is_more_eyecatching(const css_unit_ctx *unit_len_ctx,
const struct border *a,
box_type a_src,
const struct border *b,
@ -83,8 +83,8 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
* if they've come from a computed style. */
assert(a->unit != CSS_UNIT_EM && a->unit != CSS_UNIT_EX);
assert(b->unit != CSS_UNIT_EM && b->unit != CSS_UNIT_EX);
awidth = nscss_len2px(len_ctx, a->width, a->unit, NULL);
bwidth = nscss_len2px(len_ctx, b->width, b->unit, NULL);
awidth = css_unit_len2device_px(NULL, unit_len_ctx, a->width, a->unit);
bwidth = css_unit_len2device_px(NULL, unit_len_ctx, b->width, b->unit);
if (awidth < bwidth)
return true;
@ -160,7 +160,7 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
/**
* Process a table
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param table Table to process
* \param a Current border style for cell
* \param a_src Source of \a a
@ -169,7 +169,7 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static void
table_cell_top_process_table(const nscss_len_ctx *len_ctx,
table_cell_top_process_table(const css_unit_ctx *unit_len_ctx,
struct box *table,
struct border *a,
box_type *a_src)
@ -181,11 +181,12 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(table->style);
b.color = css_computed_border_top_color(table->style, &b.c);
css_computed_border_top_width(table->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
b.width = css_unit_len2device_px(table->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@ -195,7 +196,7 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
/**
* Process a row
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param cell Cell being considered
* \param row Row to process
* \param a Current border style for cell
@ -206,7 +207,7 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static bool
table_cell_top_process_row(const nscss_len_ctx *len_ctx,
table_cell_top_process_row(const css_unit_ctx *unit_len_ctx,
struct box *cell,
struct box *row,
struct border *a,
@ -219,11 +220,12 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(row->style);
b.color = css_computed_border_bottom_color(row->style, &b.c);
css_computed_border_bottom_width(row->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
b.width = css_unit_len2device_px(row->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@ -233,11 +235,12 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(row->style);
b.color = css_computed_border_top_color(row->style, &b.c);
css_computed_border_top_width(row->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
b.width = css_unit_len2device_px(row->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
@ -272,14 +275,13 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
c->style, &b.c);
css_computed_border_bottom_width(c->style,
&b.width, &b.unit);
b.width = nscss_len2px(len_ctx,
b.width,
b.unit,
c->style);
b.width = css_unit_len2device_px(
c->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_CELL;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
a,
*a_src,
&b,
@ -305,7 +307,7 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
/**
* Process a group
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param cell Cell being considered
* \param group Group to process
* \param a Current border style for cell
@ -316,7 +318,7 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static bool
table_cell_top_process_group(const nscss_len_ctx *len_ctx,
table_cell_top_process_group(const css_unit_ctx *unit_len_ctx,
struct box *cell,
struct box *group,
struct border *a,
@ -329,11 +331,12 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(group->style);
b.color = css_computed_border_bottom_color(group->style, &b.c);
css_computed_border_bottom_width(group->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
b.width = css_unit_len2device_px(group->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@ -342,7 +345,7 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
/* Process rows in group, starting with last */
struct box *row = group->last;
while (table_cell_top_process_row(len_ctx, cell, row,
while (table_cell_top_process_row(unit_len_ctx, cell, row,
a, a_src) == false) {
if (row->prev == NULL) {
return false;
@ -355,11 +358,12 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(group->style);
b.color = css_computed_border_top_color(group->style, &b.c);
css_computed_border_top_width(group->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
b.width = css_unit_len2device_px(group->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
@ -375,11 +379,11 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
/**
* Calculate used values of border-left-{style,color,width}
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
table_used_left_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@ -390,7 +394,8 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_left_style(cell->style);
a.color = css_computed_border_left_color(cell->style, &a.c);
css_computed_border_left_width(cell->style, &a.width, &a.unit);
a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@ -423,11 +428,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_right_style(prev->style);
b.color = css_computed_border_right_color(prev->style, &b.c);
css_computed_border_right_width(prev->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, prev->style);
b.width = css_unit_len2device_px(prev->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_CELL;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@ -446,12 +452,13 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
row->style, &b.c);
css_computed_border_left_width(
row->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx,
b.width, b.unit, row->style);
b.width = css_unit_len2device_px(
row->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@ -466,11 +473,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_left_style(group->style);
b.color = css_computed_border_left_color(group->style, &b.c);
css_computed_border_left_width(group->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
b.width = css_unit_len2device_px(group->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@ -480,11 +488,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_left_style(table->style);
b.color = css_computed_border_left_color(table->style, &b.c);
css_computed_border_left_width(table->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
b.width = css_unit_len2device_px(table->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@ -494,21 +503,19 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used left border for the cell */
cell->border[LEFT].style = a.style;
cell->border[LEFT].c = a.c;
cell->border[LEFT].width = FIXTOINT(nscss_len2px(len_ctx,
a.width,
a.unit,
cell->style));
cell->border[LEFT].width = FIXTOINT(css_unit_len2device_px(
cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-top-{style,color,width}
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
table_used_top_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@ -519,7 +526,8 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_top_style(cell->style);
css_computed_border_top_color(cell->style, &a.c);
css_computed_border_top_width(cell->style, &a.width, &a.unit);
a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@ -527,18 +535,19 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_top_style(row->style);
css_computed_border_top_color(row->style, &b.c);
css_computed_border_top_width(row->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
b.width = css_unit_len2device_px(row->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
if (table_border_is_more_eyecatching(len_ctx, &a, a_src, &b, b_src)) {
if (table_border_is_more_eyecatching(unit_len_ctx, &a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
}
if (row->prev != NULL) {
/* Consider row(s) above */
while (table_cell_top_process_row(len_ctx, cell, row->prev,
while (table_cell_top_process_row(unit_len_ctx, cell, row->prev,
&a, &a_src) == false) {
if (row->prev->prev == NULL) {
/* Consider row group */
@ -559,11 +568,12 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_top_style(group->style);
b.color = css_computed_border_top_color(group->style, &b.c);
css_computed_border_top_width(group->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
b.width = css_unit_len2device_px(group->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@ -571,16 +581,16 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
if (group->prev == NULL) {
/* Top border of table */
table_cell_top_process_table(len_ctx,
table_cell_top_process_table(unit_len_ctx,
group->parent, &a, &a_src);
} else {
/* Process previous group(s) */
while (table_cell_top_process_group(len_ctx,
while (table_cell_top_process_group(unit_len_ctx,
cell, group->prev,
&a, &a_src) == false) {
if (group->prev->prev == NULL) {
/* Top border of table */
table_cell_top_process_table(len_ctx,
table_cell_top_process_table(unit_len_ctx,
group->parent,
&a, &a_src);
break;
@ -594,20 +604,18 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used top border for the cell */
cell->border[TOP].style = a.style;
cell->border[TOP].c = a.c;
cell->border[TOP].width = FIXTOINT(nscss_len2px(len_ctx,
a.width,
a.unit,
cell->style));
cell->border[TOP].width = FIXTOINT(css_unit_len2device_px(
cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-right-{style,color,width}
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
table_used_right_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@ -618,7 +626,8 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_right_style(cell->style);
css_computed_border_right_color(cell->style, &a.c);
css_computed_border_right_width(cell->style, &a.width, &a.unit);
a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@ -643,14 +652,13 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
css_computed_border_right_width(row->style,
&b.width,
&b.unit);
b.width = nscss_len2px(len_ctx,
b.width,
b.unit,
row->style);
b.width = css_unit_len2device_px(
row->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src,
&b, b_src)) {
a = b;
@ -667,11 +675,12 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.color = css_computed_border_right_color(group->style, &b.c);
css_computed_border_right_width(group->style,
&b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
b.width = css_unit_len2device_px(group->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@ -682,11 +691,12 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.color = css_computed_border_right_color(table->style, &b.c);
css_computed_border_right_width(table->style,
&b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
b.width = css_unit_len2device_px(table->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src,
&b, b_src)) {
a = b;
@ -697,21 +707,19 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used right border for the cell */
cell->border[RIGHT].style = a.style;
cell->border[RIGHT].c = a.c;
cell->border[RIGHT].width = FIXTOINT(nscss_len2px(len_ctx,
a.width,
a.unit,
cell->style));
cell->border[RIGHT].width = FIXTOINT(css_unit_len2device_px(
cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-bottom-{style,color,width}
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
table_used_bottom_border_for_cell(const css_unit_ctx *unit_len_ctx,
struct box *cell)
{
struct border a, b;
@ -723,7 +731,8 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
a.style = css_computed_border_bottom_style(cell->style);
css_computed_border_bottom_color(cell->style, &a.c);
css_computed_border_bottom_width(cell->style, &a.width, &a.unit);
a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@ -747,11 +756,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(row->style);
b.color = css_computed_border_bottom_color(row->style, &b.c);
css_computed_border_bottom_width(row->style, &b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
b.width = css_unit_len2device_px(row->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@ -762,11 +772,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.color = css_computed_border_bottom_color(group->style, &b.c);
css_computed_border_bottom_width(group->style,
&b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
b.width = css_unit_len2device_px(group->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@ -777,11 +788,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.color = css_computed_border_bottom_color(table->style, &b.c);
css_computed_border_bottom_width(table->style,
&b.width, &b.unit);
b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
b.width = css_unit_len2device_px(table->style, unit_len_ctx,
b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
if (table_border_is_more_eyecatching(len_ctx,
if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
}
@ -790,14 +802,14 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
/* a now contains the used bottom border for the cell */
cell->border[BOTTOM].style = a.style;
cell->border[BOTTOM].c = a.c;
cell->border[BOTTOM].width = FIXTOINT(nscss_len2px(len_ctx,
a.width, a.unit, cell->style));
cell->border[BOTTOM].width = FIXTOINT(css_unit_len2device_px(
cell->style, unit_len_ctx, a.width, a.unit));
}
/* exported interface documented in html/table.h */
bool
table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
table_calculate_column_types(const css_unit_ctx *unit_len_ctx, struct box *table)
{
unsigned int i, j;
struct column *col;
@ -845,8 +857,10 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
if (col[i].type != COLUMN_WIDTH_FIXED &&
type == CSS_WIDTH_SET && unit != CSS_UNIT_PCT) {
col[i].type = COLUMN_WIDTH_FIXED;
col[i].width = FIXTOINT(nscss_len2px(len_ctx,
value, unit, cell->style));
col[i].width = FIXTOINT(css_unit_len2device_px(
cell->style,
unit_len_ctx,
value, unit));
if (col[i].width < 0)
col[i].width = 0;
continue;
@ -911,9 +925,11 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
if (type == CSS_WIDTH_SET && unit != CSS_UNIT_PCT &&
fixed_columns + unknown_columns ==
cell->columns) {
int width = (FIXTOFLT(nscss_len2px(len_ctx, value, unit,
cell->style)) - fixed_width) /
unknown_columns;
int width = (FIXTOFLT(css_unit_len2device_px(
cell->style,
unit_len_ctx,
value, unit)) -
fixed_width) / unknown_columns;
if (width < 0)
width = 0;
for (j = 0; j != cell->columns; j++) {
@ -968,7 +984,7 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
/* exported interface documented in html/table.h */
void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
void table_used_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
int side;
@ -986,8 +1002,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[LEFT].c);
css_computed_border_left_width(cell->style, &width, &unit);
cell->border[LEFT].width =
FIXTOINT(nscss_len2px(len_ctx,
width, unit, cell->style));
FIXTOINT(css_unit_len2device_px(
cell->style, unit_len_ctx,
width, unit));
/* Top border */
cell->border[TOP].style =
@ -996,8 +1013,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[TOP].c);
css_computed_border_top_width(cell->style, &width, &unit);
cell->border[TOP].width =
FIXTOINT(nscss_len2px(len_ctx,
width, unit, cell->style));
FIXTOINT(css_unit_len2device_px(
cell->style, unit_len_ctx,
width, unit));
/* Right border */
cell->border[RIGHT].style =
@ -1006,8 +1024,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[RIGHT].c);
css_computed_border_right_width(cell->style, &width, &unit);
cell->border[RIGHT].width =
FIXTOINT(nscss_len2px(len_ctx,
width, unit, cell->style));
FIXTOINT(css_unit_len2device_px(
cell->style, unit_len_ctx,
width, unit));
/* Bottom border */
cell->border[BOTTOM].style =
@ -1016,20 +1035,21 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[BOTTOM].c);
css_computed_border_bottom_width(cell->style, &width, &unit);
cell->border[BOTTOM].width =
FIXTOINT(nscss_len2px(len_ctx,
width, unit, cell->style));
FIXTOINT(css_unit_len2device_px(
cell->style, unit_len_ctx,
width, unit));
} else {
/* Left border */
table_used_left_border_for_cell(len_ctx, cell);
table_used_left_border_for_cell(unit_len_ctx, cell);
/* Top border */
table_used_top_border_for_cell(len_ctx, cell);
table_used_top_border_for_cell(unit_len_ctx, cell);
/* Right border */
table_used_right_border_for_cell(len_ctx, cell);
table_used_right_border_for_cell(unit_len_ctx, cell);
/* Bottom border */
table_used_bottom_border_for_cell(len_ctx, cell);
table_used_bottom_border_for_cell(unit_len_ctx, cell);
}
/* Finally, ensure that any borders configured as

View File

@ -33,24 +33,24 @@ struct box;
/**
* Determine the column width types for a table.
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param table box of type BOX_TABLE
* \return true on success, false on memory exhaustion
*
* The table->col array is allocated and type and width are filled in for each
* column.
*/
bool table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table);
bool table_calculate_column_types(const css_unit_ctx *unit_len_ctx, struct box *table);
/**
* Calculate used values of border-{trbl}-{style,color,width} for table cells.
*
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*
* \post \a cell's border array is populated
*/
void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell);
void table_used_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell);
#endif

View File

@ -240,7 +240,7 @@ coords_from_range(struct box *box,
* \param text pointer to text being added, or NULL for newline
* \param length length of text to be appended (bytes)
* \param box pointer to text box, or NULL if from textplain
* \param len_ctx Length conversion context
* \param unit_len_ctx Length conversion context
* \param handle selection string to append to
* \param whitespace_text whitespace to place before text for formatting
* may be NULL
@ -251,7 +251,7 @@ static nserror
selection_copy_box(const char *text,
size_t length,
struct box *box,
const nscss_len_ctx *len_ctx,
const css_unit_ctx *unit_len_ctx,
struct selection_string *handle,
const char *whitespace_text,
size_t whitespace_length)
@ -278,7 +278,7 @@ selection_copy_box(const char *text,
if (box->style != NULL) {
/* Override default font style */
font_plot_style_from_css(len_ctx, box->style, &style);
font_plot_style_from_css(unit_len_ctx, box->style, &style);
pstyle = &style;
} else {
/* If there's no style, there must be no text */
@ -300,7 +300,7 @@ selection_copy_box(const char *text,
* boxes that lie (partially) within the given range
*
* \param box box subtree
* \param len_ctx Length conversion context.
* \param unit_len_ctx Length conversion context.
* \param start_idx start of range within textual representation (bytes)
* \param end_idx end of range
* \param handler handler function to call
@ -312,7 +312,7 @@ selection_copy_box(const char *text,
*/
static nserror
selection_copy(struct box *box,
const nscss_len_ctx *len_ctx,
const css_unit_ctx *unit_len_ctx,
unsigned start_idx,
unsigned end_idx,
struct selection_string *selstr,
@ -340,7 +340,7 @@ selection_copy(struct box *box,
/* do the marker box before continuing with the rest of the
* list element */
res = selection_copy(box->list_marker,
len_ctx,
unit_len_ctx,
start_idx,
end_idx,
selstr,
@ -383,7 +383,7 @@ selection_copy(struct box *box,
res = selection_copy_box(box->text + start_off,
min(box->length, end_off) - start_off,
box,
len_ctx,
unit_len_ctx,
selstr,
whitespace_text,
whitespace_length);
@ -415,7 +415,7 @@ selection_copy(struct box *box,
struct box *next = child->next;
res = selection_copy(child,
len_ctx,
unit_len_ctx,
start_idx,
end_idx,
selstr,
@ -518,7 +518,7 @@ html_textselection_copy(struct content *c,
}
return selection_copy(html->layout,
&html->len_ctx,
&html->unit_len_ctx,
start_idx,
end_idx,
selstr,

View File

@ -27,12 +27,12 @@
#include "content/handlers/css/utils.h"
#define LOCAL_HISTORY_WIDTH \
(FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(116))))
(FIXTOINT(css_unit_css2device_px(INTTOFIX(116), nscss_screen_dpi)))
#define LOCAL_HISTORY_HEIGHT \
(FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(100))))
(FIXTOINT(css_unit_css2device_px(INTTOFIX(100), nscss_screen_dpi)))
#define LOCAL_HISTORY_RIGHT_MARGIN \
(FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(50))))
(FIXTOINT(css_unit_css2device_px(INTTOFIX( 50), nscss_screen_dpi)))
#define LOCAL_HISTORY_BOTTOM_MARGIN \
(FIXTOINT(nscss_pixels_css_to_physical(INTTOFIX(30))))
(FIXTOINT(css_unit_css2device_px(INTTOFIX( 30), nscss_screen_dpi)))
#endif

View File

@ -257,9 +257,9 @@ struct print_settings *print_make_settings(print_configuration configuration,
struct print_settings *settings;
css_fixed length = 0;
css_unit unit = CSS_UNIT_MM;
nscss_len_ctx len_ctx = {
.vw = DEFAULT_PAGE_WIDTH,
.vh = DEFAULT_PAGE_HEIGHT,
css_unit_ctx unit_len_ctx = {
.viewport_width = DEFAULT_PAGE_WIDTH,
.viewport_height = DEFAULT_PAGE_HEIGHT,
.root_style = NULL,
};
@ -277,17 +277,17 @@ struct print_settings *print_make_settings(print_configuration configuration,
settings->scale = DEFAULT_EXPORT_SCALE;
length = INTTOFIX(DEFAULT_MARGIN_LEFT_MM);
settings->margins[MARGINLEFT] = nscss_len2px(
&len_ctx, length, unit, NULL);
settings->margins[MARGINLEFT] = css_unit_len2device_px(
NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(DEFAULT_MARGIN_RIGHT_MM);
settings->margins[MARGINRIGHT] = nscss_len2px(
&len_ctx, length, unit, NULL);
settings->margins[MARGINRIGHT] = css_unit_len2device_px(
NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(DEFAULT_MARGIN_TOP_MM);
settings->margins[MARGINTOP] = nscss_len2px(
&len_ctx, length, unit, NULL);
settings->margins[MARGINTOP] = css_unit_len2device_px(
NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(DEFAULT_MARGIN_BOTTOM_MM);
settings->margins[MARGINBOTTOM] = nscss_len2px(
&len_ctx, length, unit, NULL);
settings->margins[MARGINBOTTOM] = css_unit_len2device_px(
NULL, &unit_len_ctx, length, unit);
break;
/* use settings from the Export options tab */
case PRINT_OPTIONS:
@ -303,17 +303,17 @@ struct print_settings *print_make_settings(print_configuration configuration,
settings->scale = (float)nsoption_int(export_scale) / 100;
length = INTTOFIX(nsoption_int(margin_left));
settings->margins[MARGINLEFT] = nscss_len2px(
&len_ctx, length, unit, NULL);
settings->margins[MARGINLEFT] = css_unit_len2device_px(
NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(nsoption_int(margin_right));
settings->margins[MARGINRIGHT] = nscss_len2px(
&len_ctx, length, unit, NULL);
settings->margins[MARGINRIGHT] = css_unit_len2device_px(
NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(nsoption_int(margin_top));
settings->margins[MARGINTOP] = nscss_len2px(
&len_ctx, length, unit, NULL);
settings->margins[MARGINTOP] = css_unit_len2device_px(
NULL, &unit_len_ctx, length, unit);
length = INTTOFIX(nsoption_int(margin_bottom));
settings->margins[MARGINBOTTOM] = nscss_len2px(
&len_ctx, length, unit, NULL);
settings->margins[MARGINBOTTOM] = css_unit_len2device_px(
NULL, &unit_len_ctx, length, unit);
break;
default:
return NULL;