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
// <img src="https://....png" alt="alt" style="max-width: 100%;">
//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 {
display: none; }
@media only screen and (max-width: 800px) {
.rssguard-mwrapper .rssguard-mbody img {
.rssguard-mwrapper img {
max-width: 100% !important; } }
.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 {
display: none; }
@media only screen and (max-width: 800px) {
.rssguard-mwrapper .rssguard-mbody img {
.rssguard-mwrapper img {
max-width: 100% !important; } }
.rssguard-mbody {

View File

@ -264,7 +264,8 @@ PreparedHtml SkinFactory::generateHtmlOfArticles(const QList<Message>& messages,
enclosure_images +=
skin.m_enclosureImageMarkup.arg(enclosure.m_url,
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};
}

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 {
static QRegularExpression exp_image_tag(QSL("<img ([^>]+)>"));
static QRegularExpression exp_image_attrs(QSL("(\\w+)=\"([^\"]+)\""));
static bool is_lite = qApp->usingLite();
// Replace too big pictures. What it exactly does:
// - 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;
QElapsedTimer tmr;
#if !defined(NDEBUG)
// IOFactory::writeFile("a.html", html.toUtf8());
#endif
tmr.start();
@ -300,38 +303,43 @@ QString WebFactory::limitSizeOfHtmlImages(const QString& html, int desired_width
attrs.insert(attr_name, attr_value);
}
if (attrs.contains("height") && attrs.contains("width")) {
double ratio = attrs.value("width").toDouble() / attrs.value("height").toDouble();
// 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")) {
double ratio = attrs.value("width").toDouble() / attrs.value("height").toDouble();
if (desired_max_height > 0) {
// We limit height.
attrs.insert("height", QString::number(desired_max_height));
attrs.insert("width", QString::number(int(ratio * desired_max_height)));
}
if (desired_max_height > 0) {
// We limit height.
attrs.insert("height", QString::number(desired_max_height));
attrs.insert("width", QString::number(int(ratio * desired_max_height)));
}
// We fit width.
if (attrs.value("width").toInt() > desired_width) {
attrs.insert("width", QString::number(desired_width));
attrs.insert("height", QString::number(int(desired_width / ratio)));
// We fit width.
if (attrs.value("width").toInt() > desired_width) {
attrs.insert("width", QString::number(desired_width));
attrs.insert("height", QString::number(int(desired_width / ratio)));
}
}
}
else if (attrs.contains("width")) {
// Only width.
if (attrs.value("width").toInt() > desired_width) {
attrs.insert("width", QString::number(desired_width));
else if (attrs.contains("width")) {
// Only width.
if (attrs.value("width").toInt() > desired_width) {
attrs.insert("width", QString::number(desired_width));
}
}
else {
// No dimensions given or just height.
if (desired_max_height > 0) {
attrs.insert("height", QString::number(desired_max_height));
}
}
}
else {
// No dimensions given or just height.
attrs.remove("width");
attrs.remove("height");
if (desired_max_height > 0) {
attrs.insert("height", QString::number(desired_max_height));
attrs.insert("style", QSL("max-height: %1px !important;").arg(desired_max_height));
}
/*
else {
// We do not know image dimensions and size limitting is not there.
attrs.insert("width", QString::number(desired_width / 2));
}cd
*/
}
// 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();
}
#if !defined(NDEBUG)
// IOFactory::writeFile("b.html", my_html.toUtf8());
#endif
qDebugNN << LOGSEC_GUI << "HTML image resizing took" << NONQUOTE_W_SPACE(tmr.elapsed()) << "miliseconds.";
return my_html;