Provide the facility to set the DPI of the display by removing the assumptions of 90.0 dpi from the CSS and layout engines.

svn path=/trunk/netsurf/; revision=3528
This commit is contained in:
Daniel Silverstone 2007-08-19 10:08:49 +00:00
parent 3c435ccef8
commit d1382c6d0e
3 changed files with 19 additions and 12 deletions

View File

@ -388,6 +388,16 @@ const struct css_style css_blank_style = {
{ CSS_Z_INDEX_AUTO, 0 }
};
/** Dots per inch for the display device.
*
* This is the number of pixels per inch of the display device.
* This variable should be treated as constant during the runtime of
* the program unless the core can be persuaded to re-layout fully
* on change.
*
* We default to 90.0 because RISC OS defaults to 90.0 dpi.
*/
float css_screen_dpi = 90.0;
/**
* Convert a CONTENT_CSS for use.
@ -3012,8 +3022,6 @@ 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,
@ -3024,10 +3032,10 @@ float css_len2px(const struct css_length *length,
case CSS_UNIT_EM: return length->value * css_len2px(&style->font_size.value.length, 0);
case CSS_UNIT_EX: return length->value * css_len2px(&style->font_size.value.length, 0) * 0.6;
case CSS_UNIT_PX: return length->value;
/* RISC OS assumes 90dpi */
case CSS_UNIT_IN: return length->value * 90.0;
case CSS_UNIT_CM: return length->value * 35.43307087;
case CSS_UNIT_MM: return length->value * 3.543307087;
/* We assume the screen and any other output has the same dpi */
case CSS_UNIT_IN: return length->value * css_screen_dpi;
case CSS_UNIT_CM: return length->value * css_screen_dpi / 2.54;
case CSS_UNIT_MM: return length->value * css_screen_dpi / 25.4;
/* 1pt = 1in/72 */
case CSS_UNIT_PT: return length->value * 1.25;
/* 1pc = 1pt * 12 */
@ -3039,8 +3047,6 @@ float css_len2px(const struct css_length *length,
/**
* Convert a struct css_length to points.
*
* Note: This assumes 90dpi (if converting a pixel size)
*/
float css_len2pt(const struct css_length *length,
@ -3050,8 +3056,8 @@ float css_len2pt(const struct css_length *length,
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;
/* We assume the screen and any other output has the same dpi */
case CSS_UNIT_PX: return length->value * css_screen_dpi / 72;
/* 1pt = 1in/72 */
case CSS_UNIT_IN: return length->value * 72;
case CSS_UNIT_CM: return length->value * 28.452756;

View File

@ -502,6 +502,7 @@ struct content_css_data {
extern const struct css_style css_base_style;
extern const struct css_style css_empty_style;
extern const struct css_style css_blank_style;
extern float css_screen_dpi;
#ifdef CSS_INTERNALS

View File

@ -967,8 +967,8 @@ int line_height(struct css_style *style)
/* take account of minimum font size option */
if ((font_len = css_len2px(&style->font_size.value.length, 0)) <
option_font_min_size * 9.0 / 72.0)
font_len = option_font_min_size * 9.0 / 72.0;
option_font_min_size * css_screen_dpi / 720.0)
font_len = option_font_min_size * css_screen_dpi / 720.0;
switch (style->line_height.size) {
case CSS_LINE_HEIGHT_LENGTH: