summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src/webpage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewStory/src/webpage.cpp')
-rw-r--r--plugins/NewStory/src/webpage.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/plugins/NewStory/src/webpage.cpp b/plugins/NewStory/src/webpage.cpp
index a959fce923..1c74ea683c 100644
--- a/plugins/NewStory/src/webpage.cpp
+++ b/plugins/NewStory/src/webpage.cpp
@@ -17,15 +17,47 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
+#include "TxDIB.h"
/////////////////////////////////////////////////////////////////////////////////////////
// Litehtml interface
CRITICAL_SECTION cairo_font::m_sync;
-cairo_surface_t* NSWebPage::get_image(const std::string &)
+cairo_surface_t *dib_to_surface(CTxDIB &img)
{
- return 0;
+ cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, img.getWidth(), img.getHeight());
+ unsigned char *dst = cairo_image_surface_get_data(surface);
+ unsigned char *src = (unsigned char *)img.getBits();
+ int line_size = img.getWidth() * 4;
+ int dst_offset = img.getWidth() * (img.getHeight() - 1) * 4;
+ int src_offset = 0;
+ for (int i = 0; i < img.getHeight(); i++, src_offset += line_size, dst_offset -= line_size) {
+ memcpy(dst + dst_offset, src + src_offset, line_size);
+ }
+ cairo_surface_mark_dirty(surface);
+ return surface;
+}
+
+void NSWebPage::on_image_loaded(const wchar_t *file, const wchar_t *url, bool redraw_only)
+{
+ if (!mir_wstrncmp(file, L"file://", 7))
+ file += 7;
+
+ CTxDIB img;
+ if (img.load(file)) {
+ cairo_surface_t *surface = dib_to_surface(img);
+ m_images.add_image(T2Utf(url).get(), surface);
+
+ PostMessage(ctrl.m_hwnd, NSM_IMAGE_LOADED, redraw_only, 0);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+cairo_surface_t* NSWebPage::get_image(const std::string &url)
+{
+ return m_images.get_image(url);
}
void NSWebPage::get_client_rect(litehtml::position &pos) const
@@ -38,8 +70,11 @@ void NSWebPage::import_css(litehtml::string &, const litehtml::string &, litehtm
{
}
-void NSWebPage::load_image(const char *, const char *, bool)
+void NSWebPage::load_image(const char *src, const char */*baseUrl*/, bool redraw_on_ready)
{
+ Utf2T wszUrl(src);
+ if (m_images.reserve(src))
+ on_image_loaded(wszUrl, wszUrl, redraw_on_ready);
}
void NSWebPage::on_anchor_click(const char *pszUtl, const litehtml::element::ptr &)