diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2009-01-10 11:26:28 -0300 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2009-01-10 11:26:28 -0300 |
commit | 8750914d97e4a4e96a8d28c028f37eaf3904aedc (patch) | |
tree | f340a0236cad5395ed441e82015cf388ef9e5aaa | |
parent | f7fc073ac0de5326cffee25fd3e94c4d0b385136 (diff) |
Implemented natural image scaling when only one dimenssion is given.
-rw-r--r-- | dw/image.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/dw/image.cc b/dw/image.cc index ce54f561..56d6a4ec 100644 --- a/dw/image.cc +++ b/dw/image.cc @@ -144,8 +144,24 @@ Image::~Image() 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]) { |