summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/filedialogimpl-win32.cpp
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2017-03-01 21:34:26 +0000
committerEduard Braun <eduard.braun2@gmx.de>2017-03-01 21:34:26 +0000
commitd6a6b8a940f792f022bde8b0374cb59fd9a933bb (patch)
tree23694e3842b5a6492bd216bcbe388d11eccefd44 /src/ui/dialog/filedialogimpl-win32.cpp
parentFix encoding issues with title field in native Windows file save dialog. (diff)
downloadinkscape-d6a6b8a940f792f022bde8b0374cb59fd9a933bb.tar.gz
inkscape-d6a6b8a940f792f022bde8b0374cb59fd9a933bb.zip
Fix SVG file preview in Windows native file open dialog.
Fixed bugs: - https://launchpad.net/bugs/802904 (bzr r15558)
Diffstat (limited to 'src/ui/dialog/filedialogimpl-win32.cpp')
-rw-r--r--src/ui/dialog/filedialogimpl-win32.cpp135
1 files changed, 32 insertions, 103 deletions
diff --git a/src/ui/dialog/filedialogimpl-win32.cpp b/src/ui/dialog/filedialogimpl-win32.cpp
index d232a48e4..2f7dc3f8f 100644
--- a/src/ui/dialog/filedialogimpl-win32.cpp
+++ b/src/ui/dialog/filedialogimpl-win32.cpp
@@ -18,38 +18,23 @@
#endif
#include "filedialogimpl-win32.h"
//General includes
-#include <list>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <set>
+#include <cairomm/win32_surface.h>
#include <gdk/gdkwin32.h>
-#include <glib/gstdio.h>
-#include <glibmm/i18n.h>
+#include <gdkmm/general.h>
#include <glibmm/fileutils.h>
-#include <gtkmm/window.h>
+#include <glibmm/i18n.h>
//Inkscape includes
-#include "inkscape.h"
-#include "ui/dialog-events.h"
+#include "display/cairo-utils.h"
+#include "document.h"
+#include "extension/db.h"
#include "extension/input.h"
#include "extension/output.h"
-#include "extension/db.h"
-
-//#include "display/drawing-item.h"
-//#include "display/drawing.h"
-#include "sp-item.h"
-#include "display/canvas-arena.h"
-
#include "filedialog.h"
-
-#include "sp-root.h"
+#include "helper/pixbuf-ops.h"
#include "preferences.h"
+#include "util/units.h"
-#include <zlib.h>
-#include <cairomm/win32_surface.h>
-#include <cairomm/context.h>
-#include <gdkmm/general.h>
using namespace std;
using namespace Glib;
@@ -1020,15 +1005,11 @@ void FileOpenDialogImplWin32::free_preview()
bool FileOpenDialogImplWin32::set_svg_preview()
{
- return false;
- // NOTE: it's not worth the effort to fix this to use Cairo.
- // Native file dialogs are unmaintainable and should be removed anyway.
- #if 0
const int PreviewSize = 512;
gchar *utf8string = g_utf16_to_utf8((const gunichar2*)_path_string,
_MAX_PATH, NULL, NULL, NULL);
- SPDocument *svgDoc = SPDocument::createNewDoc (utf8string, true);
+ SPDocument *svgDoc = SPDocument::createNewDoc (utf8string, 0);
g_free(utf8string);
// Check the document loaded properly
@@ -1042,87 +1023,39 @@ bool FileOpenDialogImplWin32::set_svg_preview()
}
// Get the size of the document
- const double svgWidth = svgDoc->getWidth();
- const double svgHeight = svgDoc->getHeight();
+ Inkscape::Util::Quantity svgWidth = svgDoc->getWidth();
+ Inkscape::Util::Quantity svgHeight = svgDoc->getHeight();
+ const double svgWidth_px = svgWidth.value("px");
+ const double svgHeight_px = svgHeight.value("px");
// Find the minimum scale to fit the image inside the preview area
- const double scaleFactorX = PreviewSize / svgWidth;
- const double scaleFactorY = PreviewSize / svgHeight;
+ const double scaleFactorX = PreviewSize / svgWidth_px;
+ const double scaleFactorY = PreviewSize / svgHeight_px;
const double scaleFactor = (scaleFactorX > scaleFactorY) ? scaleFactorY : scaleFactorX;
// Now get the resized values
- const double scaledSvgWidth = scaleFactor * svgWidth;
- const double scaledSvgHeight = scaleFactor * svgHeight;
-
- Geom::Rect area(Geom::Point(0, 0), Geom::Point(scaledSvgWidth, scaledSvgHeight));
- NRRectL areaL = {0, 0, scaledSvgWidth, scaledSvgHeight};
- NRRectL bbox = {0, 0, scaledSvgWidth, scaledSvgHeight};
-
- // write object bbox to area
- svgDoc->ensureUpToDate();
- Geom::OptRect maybeArea = area | svgDoc->getRoot()->desktopVisualBounds();
-
- NRArena *const arena = NRArena::create();
-
- unsigned const key = SPItem::display_key_new(1);
-
- NRArenaItem *root = svgDoc->getRoot()->invoke_show(
- arena, key, SP_ITEM_SHOW_DISPLAY);
+ const int scaledSvgWidth = round(scaleFactor * svgWidth_px);
+ const int scaledSvgHeight = round(scaleFactor * svgHeight_px);
- NRGC gc(NULL);
- gc.transform = Geom::Affine(Geom::Scale(scaleFactor, scaleFactor));
-
- nr_arena_item_invoke_update (root, NULL, &gc,
- NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
-
- // Prepare a GDI compatible NRPixBlock
- NRPixBlock pixBlock;
- pixBlock.size = NR_PIXBLOCK_SIZE_BIG;
- pixBlock.mode = NR_PIXBLOCK_MODE_R8G8B8;
- pixBlock.empty = 1;
- pixBlock.visible_area.x0 = pixBlock.area.x0 = 0;
- pixBlock.visible_area.y0 = pixBlock.area.y0 = 0;
- pixBlock.visible_area.x1 = pixBlock.area.x1 = scaledSvgWidth;
- pixBlock.visible_area.y1 = pixBlock.area.y1 = scaledSvgHeight;
- pixBlock.rs = 4 * ((3 * (int)scaledSvgWidth + 3) / 4);
- pixBlock.data.px = g_try_new (unsigned char, pixBlock.rs * scaledSvgHeight);
-
- // Fail if the pixblock failed to allocate
- if(pixBlock.data.px == NULL)
- {
- svgDoc->doUnref();
- return false;
- }
-
- memset(pixBlock.data.px, 0xFF, pixBlock.rs * scaledSvgHeight);
-
- memcpy(&root->bbox, &areaL, sizeof(areaL));
-
- // Render the image
- nr_arena_item_invoke_render(NULL, root, &bbox, &pixBlock, /*0*/NR_ARENA_ITEM_RENDER_NO_CACHE);
+ const double dpi = 96*scaleFactor;
+ Inkscape::Pixbuf * pixbuf = sp_generate_internal_bitmap(svgDoc, NULL, 0, 0, svgWidth_px, svgHeight_px, scaledSvgWidth, scaledSvgHeight, dpi, dpi, (guint32) 0xffffff00, NULL);
// Tidy up
svgDoc->doUnref();
- svgDoc->getRoot()->invoke_hide(key);
- nr_object_unref((NRObject *) arena);
+ if (pixbuf == NULL) {
+ return false;
+ }
// Create the GDK pixbuf
_mutex->lock();
-
- _preview_bitmap_image = Gdk::Pixbuf::create_from_data(
- pixBlock.data.px, Gdk::COLORSPACE_RGB, false, 8,
- (int)scaledSvgWidth, (int)scaledSvgHeight, pixBlock.rs,
- sigc::ptr_fun(destroy_svg_rendering));
-
- _preview_document_width = scaledSvgWidth;
- _preview_document_height = scaledSvgHeight;
- _preview_image_width = svgWidth;
- _preview_image_height = svgHeight;
-
+ _preview_bitmap_image = Glib::wrap(pixbuf->getPixbufRaw());
+ _preview_document_width = svgWidth_px;
+ _preview_document_height = svgHeight_px;
+ _preview_image_width = scaledSvgWidth;
+ _preview_image_height = scaledSvgHeight;
_mutex->unlock();
return true;
- #endif
}
void FileOpenDialogImplWin32::destroy_svg_rendering(const guint8 *buffer)
@@ -1370,17 +1303,13 @@ void FileOpenDialogImplWin32::render_preview()
}
// Find the minimum scale to fit the image inside the preview area
- const double scaleFactorX =
- ((double)_preview_width - pagePadding * 2 - blurRadius) / _preview_document_width;
- const double scaleFactorY =
- ((double)_preview_height - pagePadding * 2
- - shaddowOffsetY - halfBlurRadius - captionHeight) / _preview_document_height;
- double scaleFactor = (scaleFactorX > scaleFactorY) ? scaleFactorY : scaleFactorX;
- scaleFactor = (scaleFactor > 1.0) ? 1.0 : scaleFactor;
+ const double scaleFactorX = ((double)_preview_width - pagePadding * 2 - blurRadius) / _preview_image_width;
+ const double scaleFactorY = ((double)_preview_height - pagePadding * 2 - shaddowOffsetY - halfBlurRadius - captionHeight) / _preview_image_height;
+ const double scaleFactor = (scaleFactorX > scaleFactorY) ? scaleFactorY : scaleFactorX;
// Now get the resized values
- const double scaledSvgWidth = scaleFactor * _preview_document_width;
- const double scaledSvgHeight = scaleFactor * _preview_document_height;
+ const double scaledSvgWidth = scaleFactor * _preview_image_width;
+ const double scaledSvgHeight = scaleFactor * _preview_image_height;
const int svgX = pagePadding + halfBlurRadius;
const int svgY = pagePadding;