force max width on all images in nudus-*

This commit is contained in:
Martin Rotter 2023-12-07 15:06:26 +01:00
parent 4be2dcc2d9
commit 8c4d9bdf1b
5 changed files with 43 additions and 28 deletions

View file

@ -391,7 +391,7 @@ summary {
} }
} }
.rssguard-mbody img { img {
// Needs to be `!important` when max-width is defined by image style // Needs to be `!important` when max-width is defined by image style
// <img src="https://....png" alt="alt" style="max-width: 100%;"> // <img src="https://....png" alt="alt" style="max-width: 100%;">
//max-width: 450px !important; //max-width: 450px !important;

View file

@ -253,7 +253,7 @@ summary:focus {
.rssguard-mwrapper .rssguard-mhead .mlinks .mwrapurl a[href=""], .rssguard-mwrapper .rssguard-mhead .mlinks .mwrapurl a[href=""] + span { .rssguard-mwrapper .rssguard-mhead .mlinks .mwrapurl a[href=""], .rssguard-mwrapper .rssguard-mhead .mlinks .mwrapurl a[href=""] + span {
display: none; } display: none; }
@media only screen and (max-width: 800px) { @media only screen and (max-width: 800px) {
.rssguard-mwrapper .rssguard-mbody img { .rssguard-mwrapper img {
max-width: 100% !important; } } max-width: 100% !important; } }
.rssguard-mbody { .rssguard-mbody {

View file

@ -253,7 +253,7 @@ summary:focus {
.rssguard-mwrapper .rssguard-mhead .mlinks .mwrapurl a[href=""], .rssguard-mwrapper .rssguard-mhead .mlinks .mwrapurl a[href=""] + span { .rssguard-mwrapper .rssguard-mhead .mlinks .mwrapurl a[href=""], .rssguard-mwrapper .rssguard-mhead .mlinks .mwrapurl a[href=""] + span {
display: none; } display: none; }
@media only screen and (max-width: 800px) { @media only screen and (max-width: 800px) {
.rssguard-mwrapper .rssguard-mbody img { .rssguard-mwrapper img {
max-width: 100% !important; } } max-width: 100% !important; } }
.rssguard-mbody { .rssguard-mbody {

View file

@ -264,7 +264,8 @@ PreparedHtml SkinFactory::generateHtmlOfArticles(const QList<Message>& messages,
enclosure_images += enclosure_images +=
skin.m_enclosureImageMarkup.arg(enclosure.m_url, skin.m_enclosureImageMarkup.arg(enclosure.m_url,
enclosure.m_mimeType, enclosure.m_mimeType,
forced_img_height <= 0 ? QString() : QString::number(forced_img_height)); forced_img_height <= 0 ? QString::number(-1)
: QString::number(forced_img_height));
} }
} }
} }
@ -315,6 +316,10 @@ PreparedHtml SkinFactory::generateHtmlOfArticles(const QList<Message>& messages,
} }
} }
#if !defined(NDEBUG)
IOFactory::writeFile("c.html", msg_contents.toUtf8());
#endif
return {msg_contents, base_url}; return {msg_contents, base_url};
} }

View file

@ -263,6 +263,7 @@ QString WebFactory::unescapeHtml(const QString& html) {
QString WebFactory::limitSizeOfHtmlImages(const QString& html, int desired_width, int desired_max_height) const { QString WebFactory::limitSizeOfHtmlImages(const QString& html, int desired_width, int desired_max_height) const {
static QRegularExpression exp_image_tag(QSL("<img ([^>]+)>")); static QRegularExpression exp_image_tag(QSL("<img ([^>]+)>"));
static QRegularExpression exp_image_attrs(QSL("(\\w+)=\"([^\"]+)\"")); static QRegularExpression exp_image_attrs(QSL("(\\w+)=\"([^\"]+)\""));
static bool is_lite = qApp->usingLite();
// Replace too big pictures. What it exactly does: // Replace too big pictures. What it exactly does:
// - find all <img> tags and check for existence of height/width attributes: // - find all <img> tags and check for existence of height/width attributes:
@ -275,7 +276,9 @@ QString WebFactory::limitSizeOfHtmlImages(const QString& html, int desired_width
QString my_html = html; QString my_html = html;
QElapsedTimer tmr; QElapsedTimer tmr;
#if !defined(NDEBUG)
// IOFactory::writeFile("a.html", html.toUtf8()); // IOFactory::writeFile("a.html", html.toUtf8());
#endif
tmr.start(); tmr.start();
@ -300,6 +303,9 @@ QString WebFactory::limitSizeOfHtmlImages(const QString& html, int desired_width
attrs.insert(attr_name, attr_value); attrs.insert(attr_name, attr_value);
} }
// Now, we edit height/width differently, depending whether this is
// simpler HTML (lite) viewer, or WebEngine full-blown viewer.
if (is_lite) {
if (attrs.contains("height") && attrs.contains("width")) { if (attrs.contains("height") && attrs.contains("width")) {
double ratio = attrs.value("width").toDouble() / attrs.value("height").toDouble(); double ratio = attrs.value("width").toDouble() / attrs.value("height").toDouble();
@ -326,12 +332,14 @@ QString WebFactory::limitSizeOfHtmlImages(const QString& html, int desired_width
if (desired_max_height > 0) { if (desired_max_height > 0) {
attrs.insert("height", QString::number(desired_max_height)); attrs.insert("height", QString::number(desired_max_height));
} }
/* }
}
else { else {
// We do not know image dimensions and size limitting is not there. attrs.remove("width");
attrs.insert("width", QString::number(desired_width / 2)); attrs.remove("height");
}cd if (desired_max_height > 0) {
*/ attrs.insert("style", QSL("max-height: %1px !important;").arg(desired_max_height));
}
} }
// Re-insert all attributes. // Re-insert all attributes.
@ -359,7 +367,9 @@ QString WebFactory::limitSizeOfHtmlImages(const QString& html, int desired_width
match_offset = exp_match.capturedStart() + img_reconstructed.size(); match_offset = exp_match.capturedStart() + img_reconstructed.size();
} }
#if !defined(NDEBUG)
// IOFactory::writeFile("b.html", my_html.toUtf8()); // IOFactory::writeFile("b.html", my_html.toUtf8());
#endif
qDebugNN << LOGSEC_GUI << "HTML image resizing took" << NONQUOTE_W_SPACE(tmr.elapsed()) << "miliseconds."; qDebugNN << LOGSEC_GUI << "HTML image resizing took" << NONQUOTE_W_SPACE(tmr.elapsed()) << "miliseconds.";
return my_html; return my_html;