summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2004-04-11 00:35:24 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2004-04-11 00:35:24 +0000
commit67fce3b8013bebbade61e7bec5c6b8bc573bbd84 (patch)
treedaad5c12a4f4b6aed893a11acd6a2f947903314d /render
parent076b8c8a964b990a10d796415bd0e36d93b58b2a (diff)
downloadnetsurf-67fce3b8013bebbade61e7bec5c6b8bc573bbd84.tar.gz
netsurf-67fce3b8013bebbade61e7bec5c6b8bc573bbd84.tar.bz2
[project @ 2004-04-11 00:35:24 by jmb]
Retain aspect ratio of boxes if only one of width/height are specified (eg <img src="blah" width="123"> would scale height to be 123/image_width * image_height) NB: This does /not/ work for %age widths as %age heights do nothing as yet svn path=/import/netsurf/; revision=750
Diffstat (limited to 'render')
-rw-r--r--render/html.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/render/html.c b/render/html.c
index 5f1b81953..999cd4e48 100644
--- a/render/html.c
+++ b/render/html.c
@@ -582,6 +582,27 @@ void html_object_callback(content_msg msg, struct content *object,
case CONTENT_MSG_DONE:
LOG(("got object '%s'", object->url));
box->object = object;
+ /* retain aspect ratio of box content */
+ if ((box->style->width.width == CSS_WIDTH_LENGTH /*||
+ box->style->width.width == CSS_WIDTH_PERCENT*/) &&
+ box->style->height.height == CSS_HEIGHT_AUTO) {
+ box->style->height.height = CSS_HEIGHT_LENGTH;
+ box->style->height.length.unit = CSS_UNIT_PX;
+ if (box->style->width.width == CSS_WIDTH_LENGTH) {
+ box->style->height.length.value = object->height * (box->style->width.value.length.value / object->width);
+ }
+ /*else {
+ box->style->height.length.value = object->height * (box->style->width.value.percent / 100);
+ }*/
+ box->height = box->style->height.length.value;
+ }
+ if (box->style->height.height == CSS_HEIGHT_LENGTH &&
+ box->style->width.width == CSS_WIDTH_AUTO) {
+ box->style->width.width = CSS_WIDTH_LENGTH;
+ box->style->width.value.length.unit = CSS_UNIT_PX;
+ box->style->width.value.length.value = object->width * (box->style->height.length.value / object->height);
+ box->min_width = box->max_width = box->width = box->style->width.value.length.value;
+ }
/* set dimensions to object dimensions if auto */
if (box->style->width.width == CSS_WIDTH_AUTO) {
box->style->width.width = CSS_WIDTH_LENGTH;