Author: dsilvers
Date: Sun Aug 19 11:08:49 2007
New Revision: 3528
URL:
http://source.netsurf-browser.org?rev=3528&view=rev
Log:
Provide the facility to set the DPI of the display by removing the assumptions of 90.0 dpi
from the CSS and layout engines.
Modified:
trunk/netsurf/css/css.c
trunk/netsurf/css/css.h
trunk/netsurf/render/layout.c
Modified: trunk/netsurf/css/css.c
URL:
http://source.netsurf-browser.org/trunk/netsurf/css/css.c?rev=3528&r1...
==============================================================================
--- trunk/netsurf/css/css.c (original)
+++ trunk/netsurf/css/css.c Sun Aug 19 11:08:49 2007
@@ -388,6 +388,16 @@
{ 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 @@
/**
* 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 @@
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 @@
/**
* 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 @@
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;
Modified: trunk/netsurf/css/css.h
URL:
http://source.netsurf-browser.org/trunk/netsurf/css/css.h?rev=3528&r1...
==============================================================================
--- trunk/netsurf/css/css.h (original)
+++ trunk/netsurf/css/css.h Sun Aug 19 11:08:49 2007
@@ -502,6 +502,7 @@
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
Modified: trunk/netsurf/render/layout.c
URL:
http://source.netsurf-browser.org/trunk/netsurf/render/layout.c?rev=3528&...
==============================================================================
--- trunk/netsurf/render/layout.c (original)
+++ trunk/netsurf/render/layout.c Sun Aug 19 11:08:49 2007
@@ -967,8 +967,8 @@
/* 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: