summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/filedialogimpl-gtkmm.cpp
diff options
context:
space:
mode:
authorLiam P. White <inkscapebrony@gmail.com>2014-10-08 02:22:03 +0000
committerLiam P. White <inkscapebrony@gmail.com>2014-10-08 02:22:03 +0000
commitf3840fe9d0d423f6ddf5a68d776a903d57ffb7b5 (patch)
treec8e28b27f5885928ccf866a69eb6cbc99fde599c /src/ui/dialog/filedialogimpl-gtkmm.cpp
parentUpdate to experimental r13565 (diff)
parentSome template cleanup... (diff)
downloadinkscape-f3840fe9d0d423f6ddf5a68d776a903d57ffb7b5.tar.gz
inkscape-f3840fe9d0d423f6ddf5a68d776a903d57ffb7b5.zip
Update to experimental r13598
(bzr r13341.5.17)
Diffstat (limited to 'src/ui/dialog/filedialogimpl-gtkmm.cpp')
-rw-r--r--src/ui/dialog/filedialogimpl-gtkmm.cpp44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp
index 310630f3e..17cf835cd 100644
--- a/src/ui/dialog/filedialogimpl-gtkmm.cpp
+++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp
@@ -21,9 +21,11 @@
#include <config.h>
#endif
+#include <iostream>
+
#include "filedialogimpl-gtkmm.h"
#include "ui/dialog-events.h"
-#include "interface.h"
+#include "ui/interface.h"
#include "io/sys.h"
#include "path-prefix.h"
#include "preferences.h"
@@ -40,6 +42,8 @@
#include <glibmm/i18n.h>
#include <glibmm/miscutils.h>
+#include <glibmm/regex.h>
+
#include "document.h"
#include "extension/input.h"
#include "extension/output.h"
@@ -191,6 +195,40 @@ void SVGPreview::showImage(Glib::ustring &theFileName)
{
Glib::ustring fileName = theFileName;
+ // Let's get real width and height from SVG file. These are template
+ // files so we assume they are well formed.
+
+ // std::cout << "SVGPreview::showImage: " << theFileName << std::endl;
+ std::ifstream input(theFileName.c_str());
+
+ std::string width;
+ std::string height;
+
+ if( !input ) {
+ std::cerr << "SVGPreview::showImage: Failed to open file: " << theFileName << std::endl;
+ } else {
+
+ std::string token;
+
+ Glib::MatchInfo match_info;
+ Glib::RefPtr<Glib::Regex> regex1 = Glib::Regex::create("width=\"(.*)\"");
+ Glib::RefPtr<Glib::Regex> regex2 = Glib::Regex::create("height=\"(.*)\"");
+
+ while( !input.eof() && (height.empty() || width.empty()) ) {
+
+ input >> token;
+ // std::cout << "|" << token << "|" << std::endl;
+
+ if (regex1->match(token, match_info)) {
+ width = match_info.fetch(1).raw();
+ }
+
+ if (regex2->match(token, match_info)) {
+ height = match_info.fetch(1).raw();
+ }
+
+ }
+ }
/*#####################################
# LET'S HAVE SOME FUN WITH SVG!
@@ -270,7 +308,7 @@ void SVGPreview::showImage(Glib::ustring &theFileName)
" style=\"font-size:24.000000;font-style:normal;font-weight:normal;"
" fill:#000000;fill-opacity:1.0000000;stroke:none;"
" font-family:Sans\"\n"
- " x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE
+ " x=\"10\" y=\"26\">%s x %s</text>\n" //# VALUES HERE
"</svg>\n\n";
// if (!Glib::get_charset()) //If we are not utf8
@@ -280,7 +318,7 @@ void SVGPreview::showImage(Glib::ustring &theFileName)
/* FIXME: Do proper XML quoting for fileName. */
gchar *xmlBuffer =
g_strdup_printf(xformat, previewWidth, previewHeight, imgX, imgY, scaledImgWidth, scaledImgHeight,
- fileName.c_str(), rectX, rectY, rectWidth, rectHeight, imgWidth, imgHeight);
+ fileName.c_str(), rectX, rectY, rectWidth, rectHeight, width.c_str(), height.c_str() );
// g_message("%s\n", xmlBuffer);