summaryrefslogtreecommitdiffstats
path: root/src/extension
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-09-15 19:26:40 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-09-15 19:26:40 +0000
commitd0f046b0aff8b4404c852990886f9afeca6d5c0f (patch)
tree9f03e5af0f2126a7d9cd7a7d11d61b5b99e16a3a /src/extension
parentFix document unit change for disconnected connectors. (diff)
parentDutch translation update (diff)
downloadinkscape-d0f046b0aff8b4404c852990886f9afeca6d5c0f.tar.gz
inkscape-d0f046b0aff8b4404c852990886f9afeca6d5c0f.zip
Merge from trunk.
(bzr r12475.1.20)
Diffstat (limited to 'src/extension')
-rw-r--r--src/extension/internal/cairo-ps-out.cpp2
-rw-r--r--src/extension/internal/cairo-render-context.cpp47
-rw-r--r--src/extension/internal/cairo-renderer.cpp11
-rw-r--r--src/extension/internal/gdkpixbuf-input.cpp81
-rw-r--r--src/extension/internal/image-resolution.cpp18
5 files changed, 64 insertions, 95 deletions
diff --git a/src/extension/internal/cairo-ps-out.cpp b/src/extension/internal/cairo-ps-out.cpp
index e06c9f30d..5f535dc64 100644
--- a/src/extension/internal/cairo-ps-out.cpp
+++ b/src/extension/internal/cairo-ps-out.cpp
@@ -340,7 +340,7 @@ CairoPsOutput::init (void)
"<_option value=\"page\">" N_("Use document's page size") "</_option>"
"<_option value=\"drawing\">" N_("Use exported object's size") "</_option>"
"</param>"
- "<param name=\"bleed\" gui-text=\"" N_("Bleed/margin (mm)") "\" type=\"float\" min=\"-10000\" max=\"10000\">0</param>\n"
+ "<param name=\"bleed\" gui-text=\"" N_("Bleed/margin (mm):") "\" type=\"float\" min=\"-10000\" max=\"10000\">0</param>\n"
"<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID:") "\" type=\"string\"></param>\n"
"<output>\n"
"<extension>.ps</extension>\n"
diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp
index 3c222bd9e..a950fa177 100644
--- a/src/extension/internal/cairo-render-context.cpp
+++ b/src/extension/internal/cairo-render-context.cpp
@@ -1306,7 +1306,7 @@ CairoRenderContext::_setStrokeStyle(SPStyle const *style, Geom::OptRect const &p
{
cairo_set_dash(_cr, style->stroke_dash.dash, style->stroke_dash.n_dash, style->stroke_dash.offset);
} else {
- cairo_set_dash(_cr, NULL, 0, 0.0); // disable dashing
+ cairo_set_dash(_cr, NULL, 0, 0.0); // disable dashing
}
cairo_set_line_width(_cr, style->stroke_width.computed);
@@ -1314,30 +1314,30 @@ CairoRenderContext::_setStrokeStyle(SPStyle const *style, Geom::OptRect const &p
// set line join type
cairo_line_join_t join = CAIRO_LINE_JOIN_MITER;
switch (style->stroke_linejoin.computed) {
- case SP_STROKE_LINEJOIN_MITER:
- join = CAIRO_LINE_JOIN_MITER;
- break;
- case SP_STROKE_LINEJOIN_ROUND:
- join = CAIRO_LINE_JOIN_ROUND;
- break;
- case SP_STROKE_LINEJOIN_BEVEL:
- join = CAIRO_LINE_JOIN_BEVEL;
- break;
+ case SP_STROKE_LINEJOIN_MITER:
+ join = CAIRO_LINE_JOIN_MITER;
+ break;
+ case SP_STROKE_LINEJOIN_ROUND:
+ join = CAIRO_LINE_JOIN_ROUND;
+ break;
+ case SP_STROKE_LINEJOIN_BEVEL:
+ join = CAIRO_LINE_JOIN_BEVEL;
+ break;
}
cairo_set_line_join(_cr, join);
// set line cap type
cairo_line_cap_t cap = CAIRO_LINE_CAP_BUTT;
switch (style->stroke_linecap.computed) {
- case SP_STROKE_LINECAP_BUTT:
- cap = CAIRO_LINE_CAP_BUTT;
- break;
- case SP_STROKE_LINECAP_ROUND:
- cap = CAIRO_LINE_CAP_ROUND;
- break;
- case SP_STROKE_LINECAP_SQUARE:
- cap = CAIRO_LINE_CAP_SQUARE;
- break;
+ case SP_STROKE_LINECAP_BUTT:
+ cap = CAIRO_LINE_CAP_BUTT;
+ break;
+ case SP_STROKE_LINECAP_ROUND:
+ cap = CAIRO_LINE_CAP_ROUND;
+ break;
+ case SP_STROKE_LINECAP_SQUARE:
+ cap = CAIRO_LINE_CAP_SQUARE;
+ break;
}
cairo_set_line_cap(_cr, cap);
cairo_set_miter_limit(_cr, MAX(1, style->stroke_miterlimit.value));
@@ -1453,10 +1453,10 @@ bool CairoRenderContext::renderImage(GdkPixbuf *pb,
// TODO: reenable merge_opacity if useful
float opacity = _state->opacity;
- cairo_surface_t *image_surface = ink_cairo_surface_create_for_argb32_pixbuf(pb);
+ cairo_surface_t *image_surface = ink_cairo_surface_get_for_pixbuf(pb);
if (cairo_surface_status(image_surface)) {
TRACE(("Image surface creation failed:\n%s\n", cairo_status_to_string(cairo_surface_status(image_surface))));
- return false;
+ return false;
}
cairo_save(_cr);
@@ -1475,7 +1475,6 @@ bool CairoRenderContext::renderImage(GdkPixbuf *pb,
cairo_paint_with_alpha(_cr, opacity);
cairo_restore(_cr);
- cairo_surface_destroy(image_surface);
return true;
}
@@ -1676,9 +1675,9 @@ _write_callback(void *closure, const unsigned char *data, unsigned int length)
written = fwrite (data, 1, length, file);
if (written == length)
- return CAIRO_STATUS_SUCCESS;
+ return CAIRO_STATUS_SUCCESS;
else
- return CAIRO_STATUS_WRITE_ERROR;
+ return CAIRO_STATUS_WRITE_ERROR;
}
#include "clear-n_.h"
diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp
index 3ffd6b2ed..ac2fe5ba3 100644
--- a/src/extension/internal/cairo-renderer.cpp
+++ b/src/extension/internal/cairo-renderer.cpp
@@ -449,7 +449,7 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx)
Geom::OptRect bbox = item->desktopVisualBounds();
// no bbox, e.g. empty group
- if (!bbox) {
+ if (!bbox) {
return;
}
@@ -503,8 +503,13 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx)
if (pb) {
TEST(gdk_pixbuf_save( pb, "bitmap.png", "png", NULL, NULL ));
- // TODO this is stupid - we just converted to pixbuf format when generating the bitmap!
- convert_pixbuf_normal_to_argb32(pb);
+
+ /* TODO: find a way to avoid a duplicate conversion between
+ * Cairo and GdkPixbuf pixel formats here.
+ * Internally, generate_internal_bitmap creates a Cairo surface,
+ * but then converts it to pixbuf format. In turn, renderImage()
+ * below converts back to Cairo format.
+ */
ctx->renderImage(pb, t, item->style);
g_object_unref(pb);
pb = 0;
diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp
index 994258ccc..117c2fe39 100644
--- a/src/extension/internal/gdkpixbuf-input.cpp
+++ b/src/extension/internal/gdkpixbuf-input.cpp
@@ -19,23 +19,18 @@
namespace Inkscape {
namespace IO {
-GdkPixbuf* pixbuf_new_from_file( char const *utf8name, GError **error );
+// this is defined in sp-image.cpp
+GdkPixbuf* pixbuf_new_from_file(char const *filename, time_t &modTime, gchar*& pixPath);
}
namespace Extension {
namespace Internal {
-static std::set<Glib::ustring> create_lossy_set()
-{
- std::set<Glib::ustring> lossy;
- lossy.insert(".jpg");
- lossy.insert(".jpeg");
- return lossy;
-}
-
SPDocument *
GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
{
+ // determine whether the image should be embedded
+ // TODO: this logic seems very wrong
bool embed = false;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
Glib::ustring attr = prefs->getString("/dialogs/import/link");
@@ -52,27 +47,14 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
}
SPDocument *doc = NULL;
- GdkPixbuf *pb = Inkscape::IO::pixbuf_new_from_file( uri, NULL );
- static std::set<Glib::ustring> lossy = create_lossy_set();
-
- if (pb) { /* We are readable */
- // TODO revisit: bool is_lossy;
- Glib::ustring mime_type, ext;
- Glib::ustring u = uri;
- std::size_t dotpos = u.rfind('.');
- if (dotpos != Glib::ustring::npos) {
- ext = u.substr(dotpos, Glib::ustring::npos);
- }
+ gchar *pixpath = NULL;
+ time_t dummy;
+ GdkPixbuf *pb = Inkscape::IO::pixbuf_new_from_file(uri, dummy, pixpath);
- // HACK: replace with something better based on GIO
- if (!ext.empty() && lossy.find(ext) != lossy.end()) {
- // TODO revisit: is_lossy = true;
- mime_type = "image/jpeg";
- } else {
- // TODO revisit: is_lossy = false;
- mime_type = "image/png";
- }
+ // TODO: the pixbuf is created again from the base64-encoded attribute in SPImage.
+ // Find a way to create the pixbuf only once.
+ if (pb) {
doc = SPDocument::createNewDoc(NULL, TRUE, TRUE);
bool saved = DocumentUndo::getUndoSensitive(doc);
DocumentUndo::setUndoSensitive(doc, false); // no need to undo in this temporary document
@@ -85,40 +67,22 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
double xscale = 1;
double yscale = 1;
- gchar const *str = gdk_pixbuf_get_option( pb, "Inkscape::DpiX" );
- if ( str ) {
- gint dpi = atoi(str);
- if ( dpi > 0 && dpi != 72 ) {
- xscale = 72.0 / (double)dpi;
- }
- } else {
- if (!ir && !forcexdpi)
- ir = new ImageResolution(uri);
- if (ir && ir->ok())
- xscale = 900.0 / floor(10.*ir->x() + .5); // round-off to 0.1 dpi
- else
- xscale = 90.0 / defaultxdpi;
- }
- width *= xscale;
- str = gdk_pixbuf_get_option( pb, "Inkscape::DpiY" );
- if ( str ) {
- gint dpi = atoi(str);
- if ( dpi > 0 && dpi != 72 ) {
- yscale = 72.0 / (double)dpi;
- }
+ if (!ir && !forcexdpi) {
+ ir = new ImageResolution(uri);
+ }
+ if (ir && ir->ok()) {
+ xscale = 900.0 / floor(10.*ir->x() + .5); // round-off to 0.1 dpi
+ yscale = 900.0 / floor(10.*ir->y() + .5);
} else {
- if (!ir && !forcexdpi)
- ir = new ImageResolution(uri);
- if (ir && ir->ok())
- yscale = 900.0 / floor(10.*ir->y() + .5); // round-off to 0.1 dpi
- else
- yscale = 90.0 / defaultxdpi;
+ xscale = 90.0 / defaultxdpi;
+ yscale = 90.0 / defaultxdpi;
}
+
+ width *= xscale;
height *= yscale;
- if (ir)
- delete ir;
+ delete ir; // deleting NULL is safe
// Create image node
Inkscape::XML::Document *xml_doc = doc->getReprDoc();
@@ -127,7 +91,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
sp_repr_set_svg_double(image_node, "height", height);
if (embed) {
- sp_embed_image(image_node, pb, mime_type);
+ sp_embed_image(image_node, pb);
} else {
// convert filename to uri
gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
@@ -139,6 +103,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
}
}
+ g_object_set_data(G_OBJECT(pb), "cairo_surface", NULL);
g_object_unref(pb);
// Add it to the current layer
diff --git a/src/extension/internal/image-resolution.cpp b/src/extension/internal/image-resolution.cpp
index 3c254a59c..a9d33e831 100644
--- a/src/extension/internal/image-resolution.cpp
+++ b/src/extension/internal/image-resolution.cpp
@@ -14,13 +14,21 @@
#include "image-resolution.h"
#define IR_TRY_PNG 1
+#include <png.h>
+
#ifdef HAVE_EXIF
-#define IR_TRY_EXIF 1
+#include <math.h>
+#include <libexif/exif-data.h>
#endif
+
#define IR_TRY_EXIV 0
+
#ifdef HAVE_JPEG
#define IR_TRY_JFIF 1
+#include <jpeglib.h>
+#include <setjmp.h>
#endif
+
#ifdef WITH_IMAGE_MAGICK
#include <Magick++.h>
#endif
@@ -62,8 +70,6 @@ double ImageResolution::y() const {
#if IR_TRY_PNG
-
-#include <png.h>
static bool haspngheader(FILE *fp) {
unsigned char header[8];
@@ -133,9 +139,6 @@ void ImageResolution::readpng(char const *) {
#if IR_TRY_EXIF
-#include <math.h>
-#include <libexif/exif-data.h>
-
static double exifDouble(ExifEntry *entry, ExifByteOrder byte_order) {
switch (entry->format) {
case EXIF_FORMAT_BYTE: {
@@ -264,9 +267,6 @@ void ImageResolution::readexiv(char const *) {
#if IR_TRY_JFIF
-#include <jpeglib.h>
-#include <setjmp.h>
-
static void irjfif_error_exit(j_common_ptr cinfo) {
longjmp(*(jmp_buf*)cinfo->client_data, 1);
}