diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-10 11:26:28 -0300 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-10 11:26:28 -0300 |
commit | 08ca8a9857b54f2e647a555fd4f531c415adf042 (patch) | |
tree | f340a0236cad5395ed441e82015cf388ef9e5aaa /dw | |
parent | f7fc073ac0de5326cffee25fd3e94c4d0b385136 (diff) |
Implemented natural image scaling when only one dimenssion is given.
Diffstat (limited to 'dw')
-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]) { |