From 67fce3b8013bebbade61e7bec5c6b8bc573bbd84 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 11 Apr 2004 00:35:24 +0000 Subject: [project @ 2004-04-11 00:35:24 by jmb] Retain aspect ratio of boxes if only one of width/height are specified (eg 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 --- render/html.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'render/html.c') 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; -- cgit v1.2.3