[project @ 2006-03-09 19:04:13 by dsilvers]
css.[ch]: Add css_len2pt to convert a CSS length to points for use on systems which actually recognise that DPI might not be 90 all the time. svn path=/import/netsurf/; revision=2114
This commit is contained in:
parent
4b3d4f97a8
commit
05b214a5d5
28
css/css.c
28
css/css.c
|
@ -2976,6 +2976,8 @@ unsigned int css_hash(const char *s, int length)
|
|||
|
||||
/**
|
||||
* Convert a struct css_length to pixels.
|
||||
*
|
||||
* Note: This assumes 90dpi (if converting from points)
|
||||
*/
|
||||
|
||||
float css_len2px(const struct css_length *length,
|
||||
|
@ -2999,6 +3001,32 @@ float css_len2px(const struct css_length *length,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a struct css_length to points.
|
||||
*
|
||||
* Note: This assumes 90dpi (if converting a pixel size)
|
||||
*/
|
||||
|
||||
float css_len2pt(const struct css_length *length,
|
||||
const struct css_style *style)
|
||||
{
|
||||
assert(!((length->unit == CSS_UNIT_EM || length->unit == CSS_UNIT_EX) && style == 0));
|
||||
switch (length->unit) {
|
||||
case CSS_UNIT_EM: return length->value * css_len2pt(&style->font_size.value.length, 0);
|
||||
case CSS_UNIT_EX: return length->value * css_len2pt(&style->font_size.value.length, 0) * 0.6;
|
||||
/* RISC OS assumes 90dpi */
|
||||
case CSS_UNIT_PX: return length->value / 1.25;
|
||||
/* 1pt = 1in/72 */
|
||||
case CSS_UNIT_IN: return length->value * 72;
|
||||
case CSS_UNIT_CM: return length->value * 28.452756;
|
||||
case CSS_UNIT_MM: return length->value * 2.8452756;
|
||||
case CSS_UNIT_PT: return length->value;
|
||||
/* 1pc = 1pt * 12 */
|
||||
case CSS_UNIT_PC: return length->value * 12.0;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the most 'eyecatching' border.
|
||||
|
|
|
@ -656,6 +656,8 @@ void css_dump_stylesheet(const struct css_stylesheet * stylesheet);
|
|||
|
||||
float css_len2px(const struct css_length *length,
|
||||
const struct css_style *style);
|
||||
float css_len2pt(const struct css_length *length,
|
||||
const struct css_style *style);
|
||||
struct css_border *css_eyecatching_border(struct css_border *test1,
|
||||
struct css_style *style1, struct css_border *test2,
|
||||
struct css_style *style2);
|
||||
|
|
Loading…
Reference in New Issue