summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8e34c10)
raw | patch | inline | side by side (parent: 8e34c10)
author | Krzysztof Kosiński <tweenk.pl@gmail.com> | |
Fri, 5 Mar 2010 00:15:39 +0000 (01:15 +0100) | ||
committer | Krzysztof Kosiński <tweenk.pl@gmail.com> | |
Fri, 5 Mar 2010 00:15:39 +0000 (01:15 +0100) |
src/extension/internal/gdkpixbuf-input.cpp | patch | blob | history | |
src/selection-chemistry.cpp | patch | blob | history | |
src/sp-image.cpp | patch | blob | history | |
src/sp-image.h | patch | blob | history |
diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp
index 47cde4a5acbffd5cff24b3294fe70d6bee253c7a..4f91825e2904e0b7a08004b971564a091baf1b30 100644 (file)
#include "extension/system.h"
#include "gdkpixbuf-input.h"
#include "selection-chemistry.h"
+#include "sp-image.h"
namespace Inkscape {
sp_repr_set_svg_double(image_node, "height", height);
if (embed) {
- // Save pixbuf as JPEG or PNG for embedding
- gchar *data;
- gsize length;
- gdk_pixbuf_save_to_buffer(pb, &data, &length, is_lossy ? "jpeg" : "png", NULL, NULL);
-
- // Save base64 encoded data in image node
- // this formula taken from Glib docs
- guint needed_size = length * 4 / 3 + length * 4 / (3 * 72) + 7;
- needed_size += 5 + 8 + mime_type.size(); // 5 bytes for data:, 8 for ;base64,
-
- gchar *buffer = (gchar *) g_malloc(needed_size), *buf_work = buffer;
- buf_work += g_sprintf(buffer, "data:%s;base64,", mime_type.data());
-
- gint state = 0, save = 0;
- gsize written = 0;
- written += g_base64_encode_step((guchar*) data, length, TRUE, buf_work, &state, &save);
- written += g_base64_encode_close(TRUE, buf_work + written, &state, &save);
- buf_work[written] = 0; // null terminate
-
- image_node->setAttribute("xlink:href", buffer);
- g_free(buffer);
+ sp_embed_image(image_node, pb, mime_type);
} else {
// convert filename to uri
gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
index 3bfde6de969c08467cf6c8475f1ec1dd3807d731..7f8fafea5c4b89bfaea6f91dc037682949159ef8 100644 (file)
#include "sp-tref.h"
#include "sp-flowtext.h"
#include "sp-flowregion.h"
+#include "sp-image.h"
#include "text-editing.h"
#include "text-context.h"
#include "connector-context.h"
if (pb) {
// Create the repr for the image
Inkscape::XML::Node * repr = xml_doc->createElement("svg:image");
- {
- repr->setAttribute("sodipodi:absref", filepath);
- gchar *abs_base = Inkscape::XML::calc_abs_doc_base(document->base);
- repr->setAttribute("xlink:href", sp_relative_path_from_path(filepath, abs_base));
- g_free(abs_base);
- }
+ sp_embed_image(repr, pb, "image/png");
if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid
sp_repr_set_svg_double(repr, "width", width);
sp_repr_set_svg_double(repr, "height", height);
diff --git a/src/sp-image.cpp b/src/sp-image.cpp
index 22b83670359662d3922bd37dd997d5f8adf6907a..8ef7969cd10d877a45242ee8dcee530b64b8b8a8 100644 (file)
--- a/src/sp-image.cpp
+++ b/src/sp-image.cpp
return result;
}
+void
+sp_embed_image(Inkscape::XML::Node *image_node, GdkPixbuf *pb, Glib::ustring const &mime_in)
+{
+ Glib::ustring format, mime;
+ if (mime_in == "image/jpeg") {
+ mime = mime_in;
+ format = "jpeg";
+ } else {
+ mime = "image/png";
+ format = "png";
+ }
+
+ gchar *data;
+ gsize length;
+ gdk_pixbuf_save_to_buffer(pb, &data, &length, format.data(), NULL, NULL);
+
+ // Save base64 encoded data in image node
+ // this formula taken from Glib docs
+ guint needed_size = length * 4 / 3 + length * 4 / (3 * 72) + 7;
+ needed_size += 5 + 8 + mime.size(); // 5 bytes for data:, 8 for ;base64,
+
+ gchar *buffer = (gchar *) g_malloc(needed_size), *buf_work = buffer;
+ buf_work += g_sprintf(buffer, "data:%s;base64,", mime.data());
+
+ gint state = 0, save = 0;
+ gsize written = 0;
+ written += g_base64_encode_step((guchar*) data, length, TRUE, buf_work, &state, &save);
+ written += g_base64_encode_close(TRUE, buf_work + written, &state, &save);
+ buf_work[written] = 0; // null terminate
+
+ image_node->setAttribute("xlink:href", buffer);
+ g_free(buffer);
+}
+
void sp_image_refresh_if_outdated( SPImage* image )
{
if ( image->href && image->lastMod ) {
diff --git a/src/sp-image.h b/src/sp-image.h
index 7b00e0da360601240f871a23e8d2027b360ed6d0..172cd711885de1a1df04a4413d1c7bda8e33f4b1 100644 (file)
--- a/src/sp-image.h
+++ b/src/sp-image.h
/* SPImage */
#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <glibmm/ustring.h>
#include "svg/svg-length.h"
#include "sp-item.h"
#include "display/display-forward.h"
/* Return duplicate of curve or NULL */
SPCurve *sp_image_get_curve (SPImage *image);
-
+void sp_embed_image(Inkscape::XML::Node *imgnode, GdkPixbuf *pb, Glib::ustring const &mime);
void sp_image_refresh_if_outdated( SPImage* image );
#endif