Re: Weirdly scaled images (again)
August Karlstrom <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <[email protected]> |
On 2015-08-19 23:40, Johannes Hofmann wrote: > On Wed, Aug 19, 2015 at 09:58:51PM +0200, August Karlstrom wrote: >> On 2015-08-19 17:32, Johannes Hofmann wrote: >>> as it was mentioned in this thread already the image scaling issue >>> is fixed for quite some time in the main line of the dillo repo. >> >> I have downloaded and installed the latest Dillo version 3.1-dev. With >> the test file below the two images have the same size despite setting >> width to 25 percent on the second image. Do you get the same result? > > yes, I get the same result. Interestingly it works ok without the > enclosing <div> If anyone running Dillo 3.0.4 is interested I have made a patch which fixes the image scaling issue (see attachment). With the test document below, the Dillo logo should keep its aspect ratio when the Dillo browser window is resized. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test</title> </head> <body> <div><img src="http://www.dillo.org/db1.png" alt="Dillo logo" width="50%" /></div> </body> </html> -- August _______________________________________________ Dillo-dev mailing list [email protected] http://lists.dillo.org/cgi-bin/mailman/listinfo/dillo-dev
image-scaling.patch
(text/x-patch, 2.3 KB)
diff -r 90e1529b14cc configure.ac
--- a/configure.ac Mon Sep 14 16:11:03 2015 +0200
+++ b/configure.ac Fri Sep 18 11:16:15 2015 +0200
@@ -1,6 +1,6 @@
dnl Process this file with aclocal, autoconf and automake.
-AC_INIT([dillo], [3.0.4])
+AC_INIT([dillo], [3.0.4-patched])
dnl Detect the canonical target build environment
AC_CANONICAL_TARGET
@@ -479,7 +479,7 @@
dnl
if eval "test x$GCC = xyes"; then
- CXXFLAGS="$CXXFLAGS -Wall -W -Wno-unused-parameter -fno-rtti -fno-exceptions"
+ CXXFLAGS="$CXXFLAGS -Wall -W -Wno-unused-parameter -fno-exceptions"
fi
AC_SUBST(LIBJPEG_LIBS)
diff -r 90e1529b14cc dw/textblock.cc
--- a/dw/textblock.cc Mon Sep 14 16:11:03 2015 +0200
+++ b/dw/textblock.cc Fri Sep 18 11:16:15 2015 +0200
@@ -19,6 +19,7 @@
#include "textblock.hh"
+#include "image.hh"
#include "../lout/msg.h"
#include "../lout/misc.hh"
#include "../lout/unicode.hh"
@@ -887,6 +888,7 @@
core::Requisition requisition;
int availWidth, availAscent, availDescent;
core::style::Style *wstyle = widget->getStyle();
+ double scaleFactor;
/* We ignore line1_offset[_eff]. */
availWidth = this->availWidth - getStyle()->boxDiffWidth () - innerPadding;
@@ -929,6 +931,22 @@
size->descent =
core::style::multiplyWithPerLength (wstyle->height, availDescent);
}
+
+ /*scale images uniformly if only one of height and width is specified and the unit is percent*/
+ if (dynamic_cast<dw::Image*> (widget) != NULL) {
+ if (core::style::isPerLength(wstyle->width)
+ && (wstyle->height == core::style::LENGTH_AUTO)
+ && (requisition.width > 0)) {
+ scaleFactor = ((double) size->width) / ((double) requisition.width);
+ size->ascent = (int) (((double) size->ascent) * scaleFactor);
+ size->descent = (int) (((double) size->descent) * scaleFactor);
+ } else if (core::style::isPerLength(wstyle->height)
+ && (wstyle->width == core::style::LENGTH_AUTO)
+ && (requisition.ascent > 0)) {
+ scaleFactor = ((double) size->ascent) / ((double) requisition.ascent);
+ size->width = (int) (((double) size->width) * scaleFactor);
+ }
+ }
}
/* ascent and descent in words do not contain margins. */