diff options
author | Daniel Silverstone <dsilvers@netsurf-browser.org> | 2007-08-19 10:08:49 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@netsurf-browser.org> | 2007-08-19 10:08:49 +0000 |
commit | d1382c6d0effae8b54928c36786c621ea4395374 (patch) | |
tree | a9c0901e05018a6d03ecf85cc591642751018901 | |
parent | 3c435ccef84e465ea68224881a65b0a8a65863da (diff) | |
download | netsurf-d1382c6d0effae8b54928c36786c621ea4395374.tar.gz netsurf-d1382c6d0effae8b54928c36786c621ea4395374.tar.bz2 |
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
-rw-r--r-- | css/css.c | 26 | ||||
-rw-r--r-- | css/css.h | 1 | ||||
-rw-r--r-- | render/layout.c | 4 |
3 files changed, 19 insertions, 12 deletions
@@ -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; @@ -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 diff --git a/render/layout.c b/render/layout.c index 26786f4f3..95b734433 100644 --- a/render/layout.c +++ b/render/layout.c @@ -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: |