summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-03-31 13:45:04 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-03-31 13:45:04 +0300
commitb8f2e677b094dfe4e09f7971ef01316f6b3c21a7 (patch)
tree24f7351933a6588867e80ca2780821c876c7a588 /plugins
parentf9bd37d742a2f8851d4afc98eb207b9ee26fa42b (diff)
fixes #4320 (NewStory: problem with small images' preview)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/NewStory/src/history_control.h3
-rw-r--r--plugins/NewStory/src/main.cpp2
-rw-r--r--plugins/NewStory/src/stdafx.h4
-rw-r--r--plugins/NewStory/src/templates.cpp16
-rw-r--r--plugins/NewStory/src/webpage.cpp54
5 files changed, 52 insertions, 27 deletions
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h
index 038a3af366..0a679ff00b 100644
--- a/plugins/NewStory/src/history_control.h
+++ b/plugins/NewStory/src/history_control.h
@@ -85,6 +85,9 @@ public:
~NSWebPage();
COLORREF clText = -1, clBack = -1;
+
+ Bitmap* find_image(const wchar_t *pwszUrl);
+ Bitmap* load_image(const wchar_t *pwszUrl);
};
struct NewstoryListData : public MZeroedObject
diff --git a/plugins/NewStory/src/main.cpp b/plugins/NewStory/src/main.cpp
index 6917eb31ff..a74019cffb 100644
--- a/plugins/NewStory/src/main.cpp
+++ b/plugins/NewStory/src/main.cpp
@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
+#pragma comment(lib, "gdiplus.lib")
+
CMPlugin g_plugin;
CMOption<bool> g_bOptGrouping(MODULENAME, "MessageGrouping", false);
diff --git a/plugins/NewStory/src/stdafx.h b/plugins/NewStory/src/stdafx.h
index f48693cc29..f89220c3ca 100644
--- a/plugins/NewStory/src/stdafx.h
+++ b/plugins/NewStory/src/stdafx.h
@@ -31,6 +31,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <Shlwapi.h>
#include <malloc.h>
+#undef Translate
+#include <gdiplus.h>
+using namespace Gdiplus;
+
#include <map>
#include <set>
diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp
index 809cba555a..900b3b3557 100644
--- a/plugins/NewStory/src/templates.cpp
+++ b/plugins/NewStory/src/templates.cpp
@@ -45,7 +45,7 @@ static wchar_t* font2html(LOGFONTA &lf, wchar_t *dest)
return dest;
}
-static void AppendString(CMStringW &buf, const wchar_t *p)
+static void AppendString(CMStringW &buf, const wchar_t *p, ItemData *pItem)
{
bool wasSpace = false;
@@ -122,7 +122,15 @@ static void AppendString(CMStringW &buf, const wchar_t *p)
if (auto *p2 = wcsstr(p1, L"[/img]")) {
CMStringW wszDescr(p1, int(p2 - p1));
- buf.AppendFormat(L"<img style=\"width: 300;\" src=\"%s\" title=\"%s\" alt=\"%s\"/><br>", wszUrl.c_str(), wszDescr.c_str(), wszDescr.c_str());
+
+ int iWidth = 300;
+ pItem->pOwner->webPage.load_image(wszUrl);
+ if (Bitmap *pImage = pItem->pOwner->webPage.find_image(wszUrl))
+ if (pImage->GetWidth() < 300)
+ iWidth = pImage->GetWidth();
+
+ buf.AppendFormat(L"<img style=\"width: %d;\" src=\"%s\" title=\"%s\" alt=\"%s\"/><br>",
+ iWidth, wszUrl.c_str(), wszDescr.c_str(), wszDescr.c_str());
p = p2 + 5;
}
}
@@ -168,7 +176,7 @@ CMStringW ItemData::formatHtml(const wchar_t *pwszStr)
if (qtext) {
str.Append(L"<div class=\"quote\">");
- AppendString(str, qtext);
+ AppendString(str, qtext, this);
str.Append(L"</div>\n");
}
@@ -186,7 +194,7 @@ CMStringW ItemData::formatHtml(const wchar_t *pwszStr)
CMStringW szBody(wszOrigText);
UrlAutodetect(szBody);
- AppendString(str, szBody);
+ AppendString(str, szBody, this);
if (spRes) {
int iOffset = 0;
for (int i = 0; i < (int)sp.numSmileys; i++) {
diff --git a/plugins/NewStory/src/webpage.cpp b/plugins/NewStory/src/webpage.cpp
index a2f6bf9043..7ffa2795da 100644
--- a/plugins/NewStory/src/webpage.cpp
+++ b/plugins/NewStory/src/webpage.cpp
@@ -18,12 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-#undef Translate
-#include <gdiplus.h>
-
-#pragma comment(lib, "gdiplus.lib")
-using namespace Gdiplus;
-
/////////////////////////////////////////////////////////////////////////////////////////
// Litehtml interface
@@ -293,6 +287,18 @@ void NSWebPage::make_url_utf8(const char *url, const char *basepath, std::wstrin
make_url(Utf2T(url), Utf2T(basepath), out);
}
+Bitmap* NSWebPage::load_image(const wchar_t *pwszUrl)
+{
+ mir_cslockfull lck(m_csImages);
+ auto img = m_images.find(pwszUrl);
+ if (img != m_images.end() && img->second)
+ return (Bitmap *)img->second;
+
+ uint_ptr newImg = get_image(pwszUrl, false);
+ add_image(pwszUrl, newImg);
+ return (Bitmap *)newImg;
+}
+
void NSWebPage::load_image(const char *src, const char *baseurl, bool redraw_on_ready)
{
std::wstring url;
@@ -313,19 +319,27 @@ void NSWebPage::add_image(LPCWSTR url, uint_ptr img)
m_images[url] = img;
}
+Bitmap* NSWebPage::find_image(const wchar_t *pwszUrl)
+{
+ mir_cslock lck(m_csImages);
+ auto img = m_images.find(pwszUrl);
+ if (img != m_images.end() && img->second)
+ return (Bitmap *)img->second;
+
+ return nullptr;
+}
+
void NSWebPage::get_image_size(const char *src, const char *baseurl, size &sz)
{
std::wstring url;
make_url_utf8(src, baseurl, url);
- sz.width = 0;
- sz.height = 0;
-
mir_cslock lck(m_csImages);
images_map::iterator img = m_images.find(url);
- if (img != m_images.end() && img->second) {
+ if (img != m_images.end() && img->second)
get_img_size(img->second, sz);
- }
+ else
+ sz.width = sz.height = 0;
}
void NSWebPage::clear_images()
@@ -346,9 +360,8 @@ void NSWebPage::set_clip(const position &pos, const border_radiuses &)
void NSWebPage::del_clip()
{
- if (!m_clips.empty()) {
+ if (!m_clips.empty())
m_clips.pop_back();
- }
}
void NSWebPage::apply_clip(HDC hdc)
@@ -486,17 +499,12 @@ void NSWebPage::draw_image(uint_ptr _hdc, const background_layer &bg, const std:
if (src.empty() || (!bg.clip_box.width && !bg.clip_box.height))
return;
- Bitmap *bgbmp;
std::wstring url;
make_url_utf8(src.c_str(), base_url.c_str(), url);
- {
- mir_cslock lck(m_csImages);
- images_map::iterator img = m_images.find(url);
- if (img != m_images.end() && img->second)
- bgbmp = (Bitmap *)img->second;
- else
- return;
- }
+
+ Bitmap *bgbmp = find_image(url.c_str());
+ if (!bgbmp)
+ return;
Graphics graphics((HDC)_hdc);
graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
@@ -506,7 +514,7 @@ void NSWebPage::draw_image(uint_ptr _hdc, const background_layer &bg, const std:
graphics.SetClip(&reg);
Bitmap *scaled_img = nullptr;
- if (bg.origin_box.width != bgbmp->GetWidth() || bg.origin_box.height != bgbmp->GetHeight()) {
+ if (bg.origin_box.width != (int)bgbmp->GetWidth() || bg.origin_box.height != (int)bgbmp->GetHeight()) {
scaled_img = new Bitmap(bg.origin_box.width, bg.origin_box.height);
Graphics gr(scaled_img);
gr.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);