summaryrefslogtreecommitdiffstats
path: root/src/helper
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-10-03 20:51:05 +0000
committerjabiertxof <info@marker.es>2016-10-03 20:51:05 +0000
commit4db35e8a6706ddece9e977e5f26d4a6867ff8cbe (patch)
treef9711f260f694d96e26bf3216fb64f2b38611b2b /src/helper
parentupdate to trunk (diff)
parentMerge in jabiertxof's hover information for measure tool (diff)
downloadinkscape-4db35e8a6706ddece9e977e5f26d4a6867ff8cbe.tar.gz
inkscape-4db35e8a6706ddece9e977e5f26d4a6867ff8cbe.zip
Update to trunk
(bzr r15017.1.35)
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/Makefile_insert45
-rw-r--r--src/helper/action-context.cpp1
-rw-r--r--src/helper/action.cpp2
-rw-r--r--src/helper/geom-nodetype.cpp2
-rw-r--r--src/helper/geom-pathstroke.cpp4
-rw-r--r--src/helper/geom.cpp7
-rw-r--r--src/helper/pixbuf-ops.cpp10
-rw-r--r--src/helper/png-write.cpp85
-rw-r--r--src/helper/png-write.h6
-rw-r--r--src/helper/stock-items.cpp30
10 files changed, 69 insertions, 123 deletions
diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert
deleted file mode 100644
index e59fcfb70..000000000
--- a/src/helper/Makefile_insert
+++ /dev/null
@@ -1,45 +0,0 @@
-## Makefile.am fragment sourced by src/Makefile.am.
-
-helper/unit-menu.$(OBJEXT): helper/sp-marshal.h
-
-ink_common_sources += \
- helper/action.cpp \
- helper/action.h \
- helper/action-context.cpp \
- helper/action-context.h \
- helper/geom.cpp \
- helper/geom.h \
- helper/geom-curves.h \
- helper/geom-nodetype.cpp \
- helper/geom-nodetype.h \
- helper/geom-pathstroke.cpp \
- helper/geom-pathstroke.h \
- helper/gnome-utils.cpp \
- helper/gnome-utils.h \
- helper/mathfns.h \
- helper/png-write.cpp \
- helper/png-write.h \
- helper/sp-marshal.cpp \
- helper/sp-marshal.h \
- helper/window.cpp \
- helper/window.h \
- helper/stock-items.cpp \
- helper/stock-items.h
-
-# cmp exits with status 0 when there are no differences. "if" executes the commands
-# after "then" when the exit status of the if command is 0 (this is crazy).
-helper/sp-marshal.h: helper/sp-marshal.list
- glib-genmarshal --prefix=sp_marshal --header $(srcdir)/helper/sp-marshal.list > helper/tmp.sp-marshal.h
- if cmp -s helper/sp-marshal.h helper/tmp.sp-marshal.h; \
- then rm helper/tmp.sp-marshal.h; \
- else mv helper/tmp.sp-marshal.h helper/sp-marshal.h; fi
-
-helper/sp-marshal.cpp: helper/sp-marshal.list helper/sp-marshal.h
- ( echo '#include "helper/sp-marshal.h"' && \
- glib-genmarshal --prefix=sp_marshal --body $(srcdir)/helper/sp-marshal.list ) \
- > helper/tmp.sp-marshal.cpp; \
- if cmp -s helper/sp-marshal.cpp helper/tmp.sp-marshal.cpp; \
- then rm helper/tmp.sp-marshal.cpp; \
- else mv helper/tmp.sp-marshal.cpp helper/sp-marshal.cpp; fi
-
-helper/sp-marshal.cpp helper/sp-marshal.h: helper/sp-marshal.list
diff --git a/src/helper/action-context.cpp b/src/helper/action-context.cpp
index d52e43d96..1ea12776b 100644
--- a/src/helper/action-context.cpp
+++ b/src/helper/action-context.cpp
@@ -14,7 +14,6 @@
#include "layer-model.h"
#include "selection.h"
#include "helper/action-context.h"
-#include "ui/view/view.h"
namespace Inkscape {
diff --git a/src/helper/action.cpp b/src/helper/action.cpp
index 060bf317c..e37575a9c 100644
--- a/src/helper/action.cpp
+++ b/src/helper/action.cpp
@@ -9,8 +9,6 @@
* This code is in public domain
*/
-#include <string.h>
-
#include "debug/logger.h"
#include "debug/timestamp.h"
#include "debug/simple-event.h"
diff --git a/src/helper/geom-nodetype.cpp b/src/helper/geom-nodetype.cpp
index fe8e8af0e..da620b3fd 100644
--- a/src/helper/geom-nodetype.cpp
+++ b/src/helper/geom-nodetype.cpp
@@ -12,8 +12,6 @@
#include "helper/geom-nodetype.h"
#include <2geom/curve.h>
-#include <2geom/point.h>
-#include <vector>
namespace Geom {
diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp
index d2e9f9a1b..10641692d 100644
--- a/src/helper/geom-pathstroke.cpp
+++ b/src/helper/geom-pathstroke.cpp
@@ -9,13 +9,9 @@
#include <iomanip>
#include <2geom/path-sink.h>
-#include <2geom/point.h>
-#include <2geom/bezier-curve.h>
-#include <2geom/elliptical-arc.h>
#include <2geom/sbasis-to-bezier.h> // cubicbezierpath_from_sbasis
#include <2geom/path-intersection.h>
#include <2geom/circle.h>
-#include <math.h>
#include "helper/geom-pathstroke.h"
diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp
index ecb330b01..42c494c00 100644
--- a/src/helper/geom.cpp
+++ b/src/helper/geom.cpp
@@ -12,15 +12,8 @@
#include <algorithm>
#include "helper/geom.h"
#include "helper/geom-curves.h"
-#include <typeinfo>
-#include <2geom/pathvector.h>
-#include <2geom/path.h>
#include <2geom/curves.h>
-#include <2geom/transforms.h>
-#include <2geom/rect.h>
-#include <2geom/coord.h>
#include <2geom/sbasis-to-bezier.h>
-#include <math.h> // for M_PI
using Geom::X;
using Geom::Y;
diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp
index 9639096fb..bab998fdb 100644
--- a/src/helper/pixbuf-ops.cpp
+++ b/src/helper/pixbuf-ops.cpp
@@ -12,10 +12,9 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
-#include <png.h>
#include <boost/scoped_ptr.hpp>
#include <2geom/transforms.h>
@@ -24,11 +23,8 @@
#include "display/cairo-utils.h"
#include "display/drawing.h"
#include "display/drawing-context.h"
-#include "display/drawing-item.h"
#include "document.h"
-#include "sp-item.h"
#include "sp-root.h"
-#include "sp-use.h"
#include "sp-defs.h"
#include "util/units.h"
@@ -53,8 +49,8 @@ static void hide_other_items_recursively(SPObject *o, GSList *list, unsigned dke
// recurse
if (!g_slist_find(list, o)) {
- for ( SPObject *child = o->firstChild() ; child; child = child->getNext() ) {
- hide_other_items_recursively(child, list, dkey);
+ for (auto& child: o->children) {
+ hide_other_items_recursively(&child, list, dkey);
}
}
}
diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp
index 9430feeff..2433e2777 100644
--- a/src/helper/png-write.cpp
+++ b/src/helper/png-write.cpp
@@ -14,19 +14,17 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
#include <png.h>
#include "ui/interface.h"
#include <2geom/rect.h>
#include <2geom/transforms.h>
-#include <glib.h>
#include "png-write.h"
#include "io/sys.h"
#include "display/drawing.h"
#include "display/drawing-context.h"
-#include "display/drawing-item.h"
#include "document.h"
#include "sp-item.h"
#include "sp-root.h"
@@ -125,8 +123,8 @@ void PngTextList::add(gchar const* key, gchar const* text)
static bool
sp_png_write_rgba_striped(SPDocument *doc,
gchar const *filename, unsigned long int width, unsigned long int height, double xdpi, double ydpi,
- int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data),
- void *data)
+ int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth),
+ void *data, bool interlace, int color_type, int bit_depth, int zlib)
{
g_return_val_if_fail(filename != NULL, false);
g_return_val_if_fail(data != NULL, false);
@@ -186,22 +184,28 @@ sp_png_write_rgba_striped(SPDocument *doc,
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
*/
+
+ png_set_compression_level(png_ptr, zlib);
+
png_set_IHDR(png_ptr, info_ptr,
width,
height,
- 8, /* bit_depth */
- PNG_COLOR_TYPE_RGB_ALPHA,
- PNG_INTERLACE_NONE,
+ bit_depth,
+ color_type,
+ interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
- /* otherwise, if we are dealing with a color image then */
- sig_bit.red = 8;
- sig_bit.green = 8;
- sig_bit.blue = 8;
- /* if the image has an alpha channel then */
- sig_bit.alpha = 8;
- png_set_sBIT(png_ptr, info_ptr, &sig_bit);
+ if ((color_type&2) && bit_depth == 16) {
+ // otherwise, if we are dealing with a color image then
+ sig_bit.red = 8;
+ sig_bit.green = 8;
+ sig_bit.blue = 8;
+ // if the image has an alpha channel then
+ if (color_type&4)
+ sig_bit.alpha = 8;
+ png_set_sBIT(png_ptr, info_ptr, &sig_bit);
+ }
PngTextList textList;
@@ -250,7 +254,10 @@ sp_png_write_rgba_striped(SPDocument *doc,
/* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */
/* note that if sRGB is present the cHRM chunk must be ignored
* on read and must be written in accordance with the sRGB profile */
- png_set_pHYs(png_ptr, info_ptr, unsigned(xdpi / 0.0254 + 0.5), unsigned(ydpi / 0.0254 + 0.5), PNG_RESOLUTION_METER);
+ if(xdpi < 0.0254 ) xdpi = 0.0255;
+ if(ydpi < 0.0254 ) ydpi = 0.0255;
+
+ png_set_pHYs(png_ptr, info_ptr, unsigned(xdpi / 0.0254 ), unsigned(ydpi / 0.0254 ), PNG_RESOLUTION_METER);
/* Write the file header information. REQUIRED */
png_write_info(png_ptr, info_ptr);
@@ -273,15 +280,18 @@ sp_png_write_rgba_striped(SPDocument *doc,
*/
png_bytep* row_pointers = new png_bytep[ebp->sheight];
-
- r = 0;
- while (r < static_cast<png_uint_32>(height)) {
- void *to_free;
- int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data);
- if (!n) break;
- png_write_rows(png_ptr, row_pointers, n);
- g_free(to_free);
- r += n;
+ int number_of_passes = interlace ? png_set_interlace_handling(png_ptr) : 1;
+
+ for(int i=0;i<number_of_passes; ++i){
+ r = 0;
+ while (r < static_cast<png_uint_32>(height)) {
+ void *to_free;
+ int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data, color_type, bit_depth);
+ if (!n) break;
+ png_write_rows(png_ptr, row_pointers, n);
+ g_free(to_free);
+ r += n;
+ }
}
delete[] row_pointers;
@@ -310,7 +320,7 @@ sp_png_write_rgba_striped(SPDocument *doc,
*
*/
static int
-sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data)
+sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth)
{
struct SPEBP *ebp = (struct SPEBP *) data;
@@ -345,15 +355,14 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v
ebp->drawing->render(dc, bbox);
cairo_surface_destroy(s);
- *to_free = px;
-
// PNG stores data as unpremultiplied big-endian RGBA, which means
// it's identical to the GdkPixbuf format.
convert_pixels_argb32_to_pixbuf(px, ebp->width, num_rows, stride);
-
- for (int r = 0; r < num_rows; r++) {
- rows[r] = px + r * stride;
- }
+
+ // If a custom bit depth or color type is asked, then convert rgb to grayscale, etc.
+ const guchar* new_data = pixbuf_to_png(rows, px, num_rows, ebp->width, stride, color_type, bit_depth);
+ *to_free = (void*) new_data;
+ free(px);
return num_rows;
}
@@ -374,8 +383,8 @@ static void hide_other_items_recursively(SPObject *o, const std::vector<SPItem*>
// recurse
if (list.end()==find(list.begin(),list.end(),o)) {
- for ( SPObject *child = o->firstChild() ; child; child = child->getNext() ) {
- hide_other_items_recursively(child, list, dkey);
+ for (auto& child: o->children) {
+ hide_other_items_recursively(&child, list, dkey);
}
}
}
@@ -387,10 +396,10 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename,
unsigned long bgcolor,
unsigned int (*status) (float, void *),
void *data, bool force_overwrite,
- const std::vector<SPItem*> &items_only)
+ const std::vector<SPItem*> &items_only, bool interlace, int color_type, int bit_depth, int zlib)
{
return sp_export_png_file(doc, filename, Geom::Rect(Geom::Point(x0,y0),Geom::Point(x1,y1)),
- width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only);
+ width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only, interlace, color_type, bit_depth, zlib);
}
ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename,
@@ -399,7 +408,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename,
unsigned long bgcolor,
unsigned (*status)(float, void *),
void *data, bool force_overwrite,
- const std::vector<SPItem*> &items_only)
+ const std::vector<SPItem*> &items_only, bool interlace, int color_type, int bit_depth, int zlib)
{
g_return_val_if_fail(doc != NULL, EXPORT_ERROR);
g_return_val_if_fail(filename != NULL, EXPORT_ERROR);
@@ -470,7 +479,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename,
ebp.px = g_try_new(guchar, 4 * ebp.sheight * width);
if (ebp.px) {
- write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp);
+ write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp, interlace, color_type, bit_depth, zlib);
g_free(ebp.px);
}
diff --git a/src/helper/png-write.h b/src/helper/png-write.h
index 2657fb635..e47f01743 100644
--- a/src/helper/png-write.h
+++ b/src/helper/png-write.h
@@ -34,12 +34,14 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename,
double x0, double y0, double x1, double y1,
unsigned long int width, unsigned long int height, double xdpi, double ydpi,
unsigned long bgcolor,
- unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector<SPItem*> &items_only = std::vector<SPItem*>());
+ unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector<SPItem*> &items_only = std::vector<SPItem*>(),
+ bool interlace = false, int color_type = 6, int bit_depth = 8, int zlib = 6);
ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename,
Geom::Rect const &area,
unsigned long int width, unsigned long int height, double xdpi, double ydpi,
unsigned long bgcolor,
- unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector<SPItem*> &items_only = std::vector<SPItem*>());
+ unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector<SPItem*> &items_only = std::vector<SPItem*>(),
+ bool interlace = false, int color_type = 6, int bit_depth = 8, int zlib = 6);
#endif // SEEN_SP_PNG_WRITE_H
diff --git a/src/helper/stock-items.cpp b/src/helper/stock-items.cpp
index 5a56b89ff..647e42916 100644
--- a/src/helper/stock-items.cpp
+++ b/src/helper/stock-items.cpp
@@ -204,37 +204,37 @@ SPObject *get_stock_item(gchar const *urn, gboolean stock)
}
SPObject *object = NULL;
if (!strcmp(base, "marker") && !stock) {
- for ( SPObject *child = defs->firstChild(); child; child = child->getNext() )
+ for (auto& child: defs->children)
{
- if (child->getRepr()->attribute("inkscape:stockid") &&
- !strcmp(name_p, child->getRepr()->attribute("inkscape:stockid")) &&
- SP_IS_MARKER(child))
+ if (child.getRepr()->attribute("inkscape:stockid") &&
+ !strcmp(name_p, child.getRepr()->attribute("inkscape:stockid")) &&
+ SP_IS_MARKER(&child))
{
- object = child;
+ object = &child;
}
}
}
else if (!strcmp(base,"pattern") && !stock) {
- for ( SPObject *child = defs->firstChild() ; child; child = child->getNext() )
+ for (auto& child: defs->children)
{
- if (child->getRepr()->attribute("inkscape:stockid") &&
- !strcmp(name_p, child->getRepr()->attribute("inkscape:stockid")) &&
- SP_IS_PATTERN(child))
+ if (child.getRepr()->attribute("inkscape:stockid") &&
+ !strcmp(name_p, child.getRepr()->attribute("inkscape:stockid")) &&
+ SP_IS_PATTERN(&child))
{
- object = child;
+ object = &child;
}
}
}
else if (!strcmp(base,"gradient") && !stock) {
- for ( SPObject *child = defs->firstChild(); child; child = child->getNext() )
+ for (auto& child: defs->children)
{
- if (child->getRepr()->attribute("inkscape:stockid") &&
- !strcmp(name_p, child->getRepr()->attribute("inkscape:stockid")) &&
- SP_IS_GRADIENT(child))
+ if (child.getRepr()->attribute("inkscape:stockid") &&
+ !strcmp(name_p, child.getRepr()->attribute("inkscape:stockid")) &&
+ SP_IS_GRADIENT(&child))
{
- object = child;
+ object = &child;
}
}