mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-22 22:41:30 +03:00
Saturated maths in css fixed point
svn path=/trunk/netsurf/; revision=11975
This commit is contained in:
parent
bdb05fa08a
commit
74f108ee4d
12
css/select.c
12
css/select.c
@ -328,9 +328,9 @@ css_error nscss_compute_font_size(void *pw, const css_hint *parent,
|
||||
|
||||
/* Grab parent size, defaulting to medium if none */
|
||||
if (parent == NULL) {
|
||||
parent_size.value = FDIVI(
|
||||
FMULI(factors[CSS_FONT_SIZE_MEDIUM - 1],
|
||||
option_font_size), 10);
|
||||
parent_size.value = FDIV(FMUL(factors[CSS_FONT_SIZE_MEDIUM - 1],
|
||||
INTTOFIX(option_font_size)),
|
||||
INTTOFIX(10));
|
||||
parent_size.unit = CSS_UNIT_PT;
|
||||
} else {
|
||||
assert(parent->status == CSS_FONT_SIZE_DIMENSION);
|
||||
@ -345,9 +345,9 @@ css_error nscss_compute_font_size(void *pw, const css_hint *parent,
|
||||
|
||||
if (size->status < CSS_FONT_SIZE_LARGER) {
|
||||
/* Keyword -- simple */
|
||||
size->data.length.value = FDIVI(
|
||||
FMULI(factors[size->status - 1],
|
||||
option_font_size), 10);
|
||||
size->data.length.value = FDIV(FMUL(factors[size->status - 1],
|
||||
INTTOFIX(option_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 */
|
||||
|
27
css/utils.c
27
css/utils.c
@ -25,7 +25,7 @@
|
||||
#include "utils/log.h"
|
||||
|
||||
/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
|
||||
css_fixed nscss_screen_dpi = INTTOFIX(90);
|
||||
css_fixed nscss_screen_dpi = F_90;
|
||||
|
||||
/**
|
||||
* Convert an absolute CSS length to points.
|
||||
@ -42,18 +42,18 @@ css_fixed nscss_len2pt(css_fixed length, css_unit 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(FMULI(length, 72), nscss_screen_dpi);
|
||||
case CSS_UNIT_PX: return FDIV(FMUL(length, F_72), nscss_screen_dpi);
|
||||
/* 1in = 72pt */
|
||||
case CSS_UNIT_IN: return FMULI(length, 72);
|
||||
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(INTTOFIX(72), FLTTOFIX(2.54)));
|
||||
FDIV(F_72, FLTTOFIX(2.54)));
|
||||
/* 1in = 25.4mm => 1mm = (72/25.4)pt */
|
||||
case CSS_UNIT_MM: return FMUL(length,
|
||||
FDIV(INTTOFIX(72), FLTTOFIX(25.4)));
|
||||
FDIV(F_72, FLTTOFIX(25.4)));
|
||||
case CSS_UNIT_PT: return length;
|
||||
/* 1pc = 12pt */
|
||||
case CSS_UNIT_PC: return FMULI(length, 12);
|
||||
case CSS_UNIT_PC: return FMUL(length, INTTOFIX(12));
|
||||
default: break;
|
||||
}
|
||||
|
||||
@ -91,14 +91,13 @@ css_fixed nscss_len2px(css_fixed length, css_unit unit,
|
||||
font_size = nscss_len2pt(font_size, font_unit);
|
||||
|
||||
/* Clamp to configured minimum */
|
||||
if (font_size < FDIVI(INTTOFIX(option_font_min_size), 10)) {
|
||||
font_size = FDIVI(INTTOFIX(option_font_min_size), 10);
|
||||
if (font_size < FDIV(INTTOFIX(option_font_min_size), F_10)) {
|
||||
font_size = FDIV(INTTOFIX(option_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, nscss_screen_dpi),
|
||||
INTTOFIX(72));
|
||||
px_per_unit = FDIV(FMUL(font_size, nscss_screen_dpi), F_72);
|
||||
|
||||
/* Scale ex units: we use a fixed ratio of 1ex = 0.6em */
|
||||
if (unit == CSS_UNIT_EX)
|
||||
@ -106,7 +105,7 @@ css_fixed nscss_len2px(css_fixed length, css_unit unit,
|
||||
}
|
||||
break;
|
||||
case CSS_UNIT_PX:
|
||||
px_per_unit = INTTOFIX(1);
|
||||
px_per_unit = F_1;
|
||||
break;
|
||||
/* 1in = DPIpx */
|
||||
case CSS_UNIT_IN:
|
||||
@ -122,7 +121,7 @@ css_fixed nscss_len2px(css_fixed length, css_unit unit,
|
||||
break;
|
||||
/* 1in = 72pt => 1pt = (DPI/72)px */
|
||||
case CSS_UNIT_PT:
|
||||
px_per_unit = FDIV(nscss_screen_dpi, INTTOFIX(72));
|
||||
px_per_unit = FDIV(nscss_screen_dpi, F_72);
|
||||
break;
|
||||
/* 1pc = 12pt => 1in = 6pc => 1pc = (DPI/6)px */
|
||||
case CSS_UNIT_PC:
|
||||
@ -135,9 +134,9 @@ css_fixed nscss_len2px(css_fixed length, css_unit unit,
|
||||
|
||||
/* Ensure we round px_per_unit to the nearest whole number of pixels:
|
||||
* the use of FIXTOINT() below will truncate. */
|
||||
px_per_unit += FLTTOFIX(0.5);
|
||||
px_per_unit += F_0_5;
|
||||
|
||||
/* Calculate total number of pixels */
|
||||
return FMULI(length, FIXTOINT(px_per_unit));
|
||||
return FMUL(length, TRUNCATEFIX(px_per_unit));
|
||||
}
|
||||
|
||||
|
@ -68,11 +68,12 @@ bool print_basic_run(hlcache_handle *content,
|
||||
|
||||
assert(content != NULL && printer != NULL && settings != NULL);
|
||||
|
||||
if (!print_set_up(content, printer, settings, NULL))
|
||||
ret = false;
|
||||
if (print_set_up(content, printer, settings, NULL))
|
||||
return false;
|
||||
|
||||
while (ret && (done_height < content_get_height(printed_content)) )
|
||||
while (ret && (done_height < content_get_height(printed_content)) ) {
|
||||
ret = print_draw_next_page(printer, settings);
|
||||
}
|
||||
|
||||
print_cleanup(content, printer, settings);
|
||||
|
||||
@ -95,7 +96,7 @@ bool print_set_up(hlcache_handle *content,
|
||||
{
|
||||
printed_content = print_init(content, settings);
|
||||
|
||||
if (!printed_content)
|
||||
if (printed_content == NULL)
|
||||
return false;
|
||||
|
||||
print_apply_settings(printed_content, settings);
|
||||
|
@ -178,9 +178,7 @@ struct text_area *textarea_create(int width, int height,
|
||||
|
||||
ret->fstyle = *style;
|
||||
|
||||
ret->line_height = FIXTOINT(FDIVI((FMUL(FLTTOFIX(1.2),
|
||||
FMULI(nscss_screen_dpi,
|
||||
(style->size / FONT_SIZE_SCALE)))), 72));
|
||||
ret->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2), FMUL(nscss_screen_dpi, INTTOFIX((style->size / FONT_SIZE_SCALE))))), F_72));
|
||||
|
||||
ret->caret_pos.line = ret->caret_pos.char_off = 0;
|
||||
ret->caret_x = MARGIN_LEFT;
|
||||
|
@ -45,8 +45,8 @@ void font_plot_style_from_css(const css_computed_style *css,
|
||||
css_computed_font_family(css, &families));
|
||||
|
||||
css_computed_font_size(css, &length, &unit);
|
||||
fstyle->size = FIXTOINT(FMULI(nscss_len2pt(length, unit),
|
||||
FONT_SIZE_SCALE));
|
||||
fstyle->size = FIXTOINT(FMUL(nscss_len2pt(length, unit),
|
||||
INTTOFIX(FONT_SIZE_SCALE)));
|
||||
|
||||
/* Clamp font size to configured minimum */
|
||||
if (fstyle->size < (option_font_min_size * FONT_SIZE_SCALE) / 10)
|
||||
|
@ -900,10 +900,7 @@ bool form_open_select_menu(void *client_data,
|
||||
&fstyle);
|
||||
menu->f_size = fstyle.size;
|
||||
|
||||
menu->line_height =
|
||||
FIXTOINT(FDIVI((FMUL(FLTTOFIX(1.2),
|
||||
FMULI(nscss_screen_dpi,
|
||||
(fstyle.size / FONT_SIZE_SCALE)))), 72));
|
||||
menu->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2), FMUL(nscss_screen_dpi, INTTOFIX((fstyle.size / FONT_SIZE_SCALE))))), F_72));
|
||||
|
||||
line_height_with_spacing = menu->line_height +
|
||||
menu->line_height *
|
||||
|
@ -59,7 +59,7 @@
|
||||
#define AUTO INT_MIN
|
||||
|
||||
/* Fixed point value percentage of an integer, to an integer */
|
||||
#define FPCT_OF_INT_TOINT(a, b) FIXTOINT(FMULI(FDIVI(a, 100), b))
|
||||
#define FPCT_OF_INT_TOINT(a, b) FIXTOINT(FMUL(FDIV(a, F_100), INTTOFIX(b)))
|
||||
|
||||
|
||||
static bool layout_block_context(struct box *block, int viewport_height,
|
||||
@ -1889,7 +1889,7 @@ int line_height(const css_computed_style *style)
|
||||
line_height = nscss_len2px(lhvalue, CSS_UNIT_EM, style);
|
||||
|
||||
if (lhtype != CSS_LINE_HEIGHT_NUMBER)
|
||||
line_height = FDIVI(line_height, 100);
|
||||
line_height = FDIV(line_height, F_100);
|
||||
} else {
|
||||
assert(lhunit != CSS_UNIT_PCT);
|
||||
|
||||
@ -3790,7 +3790,7 @@ void calculate_mbp_width(const css_computed_style *style, unsigned int side,
|
||||
type = margin_funcs[side](style, &value, &unit);
|
||||
if (type == CSS_MARGIN_SET) {
|
||||
if (unit == CSS_UNIT_PCT) {
|
||||
*frac += FIXTOINT(FDIVI(value, 100));
|
||||
*frac += FIXTOINT(FDIV(value, F_100));
|
||||
} else {
|
||||
*fixed += FIXTOINT(nscss_len2px(value, unit,
|
||||
style));
|
||||
@ -3812,7 +3812,7 @@ void calculate_mbp_width(const css_computed_style *style, unsigned int side,
|
||||
if (padding) {
|
||||
padding_funcs[side](style, &value, &unit);
|
||||
if (unit == CSS_UNIT_PCT) {
|
||||
*frac += FIXTOINT(FDIVI(value, 100));
|
||||
*frac += FIXTOINT(FDIV(value, F_100));
|
||||
} else {
|
||||
*fixed += FIXTOINT(nscss_len2px(value, unit, style));
|
||||
}
|
||||
|
@ -994,8 +994,7 @@ float textplain_line_height(void)
|
||||
/* Size is in points, so convert to pixels.
|
||||
* Then use a constant line height of 1.2 x font size.
|
||||
*/
|
||||
return FIXTOFLT(FDIVI((FMUL(FLTTOFIX(1.2),
|
||||
FMULI(nscss_screen_dpi,
|
||||
(textplain_style.size / FONT_SIZE_SCALE)))), 72));
|
||||
return FIXTOFLT(FDIV((FMUL(FLTTOFIX(1.2), FMUL(nscss_screen_dpi,
|
||||
INTTOFIX((textplain_style.size / FONT_SIZE_SCALE))))), F_72));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user