changeset 486:55719bfa903d

Implemented natural image scaling when only one dimenssion is given.
author Jorge Arellano Cid <jcid@dillo.org>
date Sat, 10 Jan 2009 11:26:28 -0300
parents cdfdb006f193
children 2e35e2d95115
files dw/image.cc
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/dw/image.cc	Mon Jan 05 17:12:43 2009 -0300
+++ b/dw/image.cc	Sat Jan 10 11:26:28 2009 -0300
@@ -144,8 +144,24 @@
 void Image::sizeRequestImpl (core::Requisition *requisition)
 {
    if (buffer) {
-      requisition->width = buffer->getRootWidth ();
-      requisition->ascent = buffer->getRootHeight ();
+      if (getStyle ()->height == core::style::LENGTH_AUTO &&
+          core::style::isAbsLength (getStyle ()->width) &&
+          buffer->getRootWidth () > 0) {
+         // preserve aspect ratio when only width is given
+         requisition->width = core::style::absLengthVal (getStyle ()->width);
+         requisition->ascent = buffer->getRootHeight () *
+                               requisition->width / buffer->getRootWidth ();
+      } else if (getStyle ()->width == core::style::LENGTH_AUTO &&
+                 core::style::isAbsLength (getStyle ()->height) &&
+                 buffer->getRootHeight () > 0) {
+         // preserve aspect ratio when only height is given
+         requisition->ascent = core::style::absLengthVal (getStyle ()->height);
+         requisition->width = buffer->getRootWidth () *
+                               requisition->ascent / buffer->getRootHeight ();
+      } else {
+         requisition->width = buffer->getRootWidth ();
+         requisition->ascent = buffer->getRootHeight ();
+      }
       requisition->descent = 0;
    } else {
       if(altText && altText[0]) {