From 328fad57dbfb65e3bd31062021d5cc3081e68515 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Fri, 22 Jul 2011 04:09:27 +0200 Subject: Replace direct use of Cairo contexts and surfaces in the rendering tree with wrappers which keep some extra information about the surface, amd NRRect and NRRectL use with Geom::Rect and Geom::IntRect. Should simplify implementing filter primitive subregions. (bzr r10347.1.17) --- src/helper/pixbuf-ops.cpp | 19 +++++-------------- src/helper/png-write.cpp | 26 ++++++++++---------------- 2 files changed, 15 insertions(+), 30 deletions(-) (limited to 'src/helper') diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index e1ced31b4..df0a40858 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -23,6 +23,7 @@ #include "interface.h" #include "helper/png-write.h" #include "display/cairo-utils.h" +#include "display/drawing-context.h" #include "display/nr-arena-item.h" #include "display/nr-arena.h" #include "document.h" @@ -144,27 +145,17 @@ sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename*/, hide_other_items_recursively(doc->getRoot(), items_only, dkey); } - NRRectL final_bbox; - final_bbox.x0 = 0; - final_bbox.y0 = 0;//row; - final_bbox.x1 = width; - final_bbox.y1 = height;//row + num_rows; + Geom::IntRect final_bbox = Geom::IntRect::from_xywh(0, 0, width, height); - nr_arena_item_invoke_update(root, &final_bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE); + nr_arena_item_invoke_update(root, final_bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE); cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); if (cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS) { - cairo_t *ct = cairo_create(surface); - - // clear to background - ink_cairo_set_source_rgba32(ct, bgcolor); - cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); - cairo_paint(ct); - cairo_set_operator(ct, CAIRO_OPERATOR_OVER); + Inkscape::DrawingContext ct(surface, Geom::Point(0,0)); // render items - nr_arena_item_invoke_render(ct, root, &final_bbox, NULL, NR_ARENA_ITEM_RENDER_NO_CACHE ); + nr_arena_item_invoke_render(ct, root, final_bbox, NR_ARENA_ITEM_RENDER_NO_CACHE ); pixbuf = gdk_pixbuf_new_from_data(cairo_image_surface_get_data(surface), GDK_COLORSPACE_RGB, TRUE, diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 5a20ac363..f75f96afb 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -23,6 +23,7 @@ #include #include "png-write.h" #include "io/sys.h" +#include "display/drawing-context.h" #include "display/nr-arena-item.h" #include "display/nr-arena.h" #include "document.h" @@ -322,16 +323,13 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v // bbox is now set to the entire image to prevent discontinuities // in the image when blur is used (the borders may still be a bit // off, but that's less noticeable). - NRRectL bbox; - bbox.x0 = 0; - bbox.y0 = row; - bbox.x1 = ebp->width; - bbox.y1 = row + num_rows; + Geom::IntRect bbox = Geom::IntRect::from_xywh(0, row, ebp->width, num_rows); + /* Update to renderable state */ NRGC gc(NULL); gc.transform.setIdentity(); - nr_arena_item_invoke_update(ebp->root, &bbox, &gc, + nr_arena_item_invoke_update(ebp->root, bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, ebp->width); @@ -339,18 +337,14 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v cairo_surface_t *s = cairo_image_surface_create_for_data( px, CAIRO_FORMAT_ARGB32, ebp->width, num_rows, stride); - cairo_t *ct = cairo_create(s); - cairo_translate(ct, -bbox.x0, -bbox.y0); - - ink_cairo_set_source_rgba32(ct, ebp->background); - cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); - cairo_paint(ct); - cairo_set_operator(ct, CAIRO_OPERATOR_OVER); + Inkscape::DrawingContext ct(s, bbox.min()); + ct.setSource(ebp->background); + ct.setOperator(CAIRO_OPERATOR_SOURCE); + ct.paint(); + ct.setOperator(CAIRO_OPERATOR_OVER); /* Render */ - nr_arena_item_invoke_render(ct, ebp->root, &bbox, NULL, 0); - - cairo_destroy(ct); + nr_arena_item_invoke_render(ct, ebp->root, bbox, 0); cairo_surface_destroy(s); *to_free = px; -- cgit v1.2.3 From 4dd33aa4d5c57706c7f64f63391174954160a308 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 6 Aug 2011 14:18:32 +0200 Subject: Rewrite NRArenaItem hierarchy into C++ (bzr r10347.1.21) --- src/helper/Makefile_insert | 1 - src/helper/pixbuf-ops.cpp | 55 ++++++++++++++++++++++------------------------ src/helper/png-write.cpp | 15 +++++-------- 3 files changed, 32 insertions(+), 39 deletions(-) (limited to 'src/helper') diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 2ccec8d16..7110c2025 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -18,7 +18,6 @@ ink_common_sources += \ helper/recthull.h \ helper/sp-marshal.cpp \ helper/sp-marshal.h \ - helper/stlport.h \ helper/unit-menu.cpp \ helper/unit-menu.h \ helper/unit-tracker.cpp \ diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index c845da011..959007450 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -24,7 +24,7 @@ #include "helper/png-write.h" #include "display/cairo-utils.h" #include "display/drawing-context.h" -#include "display/nr-arena-item.h" +#include "display/drawing-item.h" #include "display/nr-arena.h" #include "document.h" #include "sp-item.h" @@ -111,43 +111,40 @@ sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename*/, { if (width == 0 || height == 0) return NULL; - GdkPixbuf* pixbuf = NULL; - /* Create new arena for offscreen rendering*/ - NRArena *arena = NRArena::create(); - nr_arena_set_renderoffscreen(arena); - unsigned dkey = SPItem::display_key_new(1); + GdkPixbuf* pixbuf = NULL; + /* Create new arena for offscreen rendering*/ + NRArena *arena = NRArena::create(); + nr_arena_set_renderoffscreen(arena); + unsigned dkey = SPItem::display_key_new(1); - doc->ensureUpToDate(); + doc->ensureUpToDate(); - Geom::Rect screen=Geom::Rect(Geom::Point(x0,y0), Geom::Point(x1, y1)); + Geom::Rect screen=Geom::Rect(Geom::Point(x0,y0), Geom::Point(x1, y1)); - double padding = 1.0; + double padding = 1.0; - Geom::Point origin(screen.min()[Geom::X], - doc->getHeight() - screen[Geom::Y].extent() - screen.min()[Geom::Y]); + Geom::Point origin(screen.min()[Geom::X], + doc->getHeight() - screen[Geom::Y].extent() - screen.min()[Geom::Y]); - origin[Geom::X] = origin[Geom::X] + (screen[Geom::X].extent() * ((1 - padding) / 2)); - origin[Geom::Y] = origin[Geom::Y] + (screen[Geom::Y].extent() * ((1 - padding) / 2)); + origin[Geom::X] = origin[Geom::X] + (screen[Geom::X].extent() * ((1 - padding) / 2)); + origin[Geom::Y] = origin[Geom::Y] + (screen[Geom::Y].extent() * ((1 - padding) / 2)); - Geom::Scale scale( (xdpi / PX_PER_IN), (ydpi / PX_PER_IN)); - Geom::Affine affine = scale * Geom::Translate(-origin * scale); + Geom::Scale scale( (xdpi / PX_PER_IN), (ydpi / PX_PER_IN)); + Geom::Affine affine = scale * Geom::Translate(-origin * scale); - /* Create ArenaItems and set transform */ - NRArenaItem *root = doc->getRoot()->invoke_show( arena, dkey, SP_ITEM_SHOW_DISPLAY); - nr_arena_item_set_transform(NR_ARENA_ITEM(root), affine); + /* Create ArenaItems and set transform */ + Inkscape::DrawingItem *root = doc->getRoot()->invoke_show( arena, dkey, SP_ITEM_SHOW_DISPLAY); + root->setTransform(affine); + Inkscape::UpdateContext ctx; - NRGC gc(NULL); - gc.transform.setIdentity(); - - // We show all and then hide all items we don't want, instead of showing only requested items, - // because that would not work if the shown item references something in defs - if (items_only) { - hide_other_items_recursively(doc->getRoot(), items_only, dkey); - } + // We show all and then hide all items we don't want, instead of showing only requested items, + // because that would not work if the shown item references something in defs + if (items_only) { + hide_other_items_recursively(doc->getRoot(), items_only, dkey); + } Geom::IntRect final_bbox = Geom::IntRect::from_xywh(0, 0, width, height); - - nr_arena_item_invoke_update(root, final_bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE); + root->update(final_bbox, ctx, Inkscape::DrawingItem::STATE_ALL, 0); cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); @@ -155,7 +152,7 @@ sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename*/, Inkscape::DrawingContext ct(surface, Geom::Point(0,0)); // render items - nr_arena_item_invoke_render(ct, root, final_bbox, NR_ARENA_ITEM_RENDER_NO_CACHE ); + root->render(ct, final_bbox, Inkscape::DrawingItem::RENDER_BYPASS_CACHE); pixbuf = gdk_pixbuf_new_from_data(cairo_image_surface_get_data(surface), GDK_COLORSPACE_RGB, TRUE, diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index d2983806a..7812969a0 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -24,7 +24,7 @@ #include "png-write.h" #include "io/sys.h" #include "display/drawing-context.h" -#include "display/nr-arena-item.h" +#include "display/drawing-item.h" #include "display/nr-arena.h" #include "document.h" #include "sp-item.h" @@ -51,7 +51,7 @@ static unsigned int const MAX_STRIPE_SIZE = 1024*1024; struct SPEBP { unsigned long int width, height, sheight; guint32 background; - NRArenaItem *root; // the root arena item to show; it is assumed that all unneeded items are hidden + Inkscape::DrawingItem *root; // the root arena item to show; it is assumed that all unneeded items are hidden guchar *px; unsigned (*status)(float, void *); void *data; @@ -326,11 +326,8 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v Geom::IntRect bbox = Geom::IntRect::from_xywh(0, row, ebp->width, num_rows); /* Update to renderable state */ - NRGC gc(NULL); - gc.transform.setIdentity(); - - nr_arena_item_invoke_update(ebp->root, bbox, &gc, - NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE); + Inkscape::UpdateContext ctx; + ebp->root->update(bbox, ctx, Inkscape::DrawingItem::STATE_ALL, 0); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, ebp->width); unsigned char *px = g_new(guchar, num_rows * stride); @@ -344,7 +341,7 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v ct.setOperator(CAIRO_OPERATOR_OVER); /* Render */ - nr_arena_item_invoke_render(ct, ebp->root, bbox, 0); + ebp->root->render(ct, bbox, 0); cairo_surface_destroy(s); *to_free = px; @@ -462,7 +459,7 @@ sp_export_png_file(SPDocument *doc, gchar const *filename, // Create ArenaItems and set transform ebp.root = doc->getRoot()->invoke_show(arena, dkey, SP_ITEM_SHOW_DISPLAY); - nr_arena_item_set_transform(NR_ARENA_ITEM(ebp.root), affine); + ebp.root->setTransform(affine); // We show all and then hide all items we don't want, instead of showing only requested items, // because that would not work if the shown item references something in defs -- cgit v1.2.3 From 75976ea07dba9b97186667524d0a76603de416af Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 7 Aug 2011 12:53:12 +0200 Subject: Rewrite NRArena -> Inkscape::Drawing. Call render and update methods on the Drawing rather than on the root DrawingItem. (bzr r10347.1.25) --- src/helper/pixbuf-ops.cpp | 19 +++++++++---------- src/helper/png-write.cpp | 24 ++++++++++-------------- 2 files changed, 19 insertions(+), 24 deletions(-) (limited to 'src/helper') diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index 959007450..3f987dc01 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -23,9 +23,9 @@ #include "interface.h" #include "helper/png-write.h" #include "display/cairo-utils.h" +#include "display/drawing.h" #include "display/drawing-context.h" #include "display/drawing-item.h" -#include "display/nr-arena.h" #include "document.h" #include "sp-item.h" #include "sp-root.h" @@ -112,9 +112,9 @@ sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename*/, if (width == 0 || height == 0) return NULL; GdkPixbuf* pixbuf = NULL; - /* Create new arena for offscreen rendering*/ - NRArena *arena = NRArena::create(); - nr_arena_set_renderoffscreen(arena); + /* Create new drawing for offscreen rendering*/ + Inkscape::Drawing drawing; + drawing.setExact(true); unsigned dkey = SPItem::display_key_new(1); doc->ensureUpToDate(); @@ -133,9 +133,9 @@ sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename*/, Geom::Affine affine = scale * Geom::Translate(-origin * scale); /* Create ArenaItems and set transform */ - Inkscape::DrawingItem *root = doc->getRoot()->invoke_show( arena, dkey, SP_ITEM_SHOW_DISPLAY); + Inkscape::DrawingItem *root = doc->getRoot()->invoke_show( drawing, dkey, SP_ITEM_SHOW_DISPLAY); root->setTransform(affine); - Inkscape::UpdateContext ctx; + drawing.setRoot(root); // We show all and then hide all items we don't want, instead of showing only requested items, // because that would not work if the shown item references something in defs @@ -144,7 +144,7 @@ sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename*/, } Geom::IntRect final_bbox = Geom::IntRect::from_xywh(0, 0, width, height); - root->update(final_bbox, ctx, Inkscape::DrawingItem::STATE_ALL, 0); + drawing.update(final_bbox); cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); @@ -152,7 +152,7 @@ sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename*/, Inkscape::DrawingContext ct(surface, Geom::Point(0,0)); // render items - root->render(ct, final_bbox, Inkscape::DrawingItem::RENDER_BYPASS_CACHE); + drawing.render(ct, final_bbox, Inkscape::DrawingItem::RENDER_BYPASS_CACHE); pixbuf = gdk_pixbuf_new_from_data(cairo_image_surface_get_data(surface), GDK_COLORSPACE_RGB, TRUE, @@ -167,8 +167,7 @@ sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename*/, g_warning("sp_generate_internal_bitmap: not enough memory to create pixel buffer. Need %lld.", size); cairo_surface_destroy(surface); } - doc->getRoot()->invoke_hide(dkey); - nr_object_unref((NRObject *) arena); + doc->getRoot()->invoke_hide(dkey); // gdk_pixbuf_save (pixbuf, "C:\\temp\\internal.jpg", "jpeg", NULL, "quality","100", NULL); diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 7812969a0..24da697c1 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -23,9 +23,9 @@ #include #include "png-write.h" #include "io/sys.h" +#include "display/drawing.h" #include "display/drawing-context.h" #include "display/drawing-item.h" -#include "display/nr-arena.h" #include "document.h" #include "sp-item.h" #include "sp-root.h" @@ -51,7 +51,7 @@ static unsigned int const MAX_STRIPE_SIZE = 1024*1024; struct SPEBP { unsigned long int width, height, sheight; guint32 background; - Inkscape::DrawingItem *root; // the root arena item to show; it is assumed that all unneeded items are hidden + Inkscape::Drawing *drawing; // it is assumed that all unneeded items are hidden guchar *px; unsigned (*status)(float, void *); void *data; @@ -326,8 +326,7 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v Geom::IntRect bbox = Geom::IntRect::from_xywh(0, row, ebp->width, num_rows); /* Update to renderable state */ - Inkscape::UpdateContext ctx; - ebp->root->update(bbox, ctx, Inkscape::DrawingItem::STATE_ALL, 0); + ebp->drawing->update(bbox); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, ebp->width); unsigned char *px = g_new(guchar, num_rows * stride); @@ -341,7 +340,7 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v ct.setOperator(CAIRO_OPERATOR_OVER); /* Render */ - ebp->root->render(ct, bbox, 0); + ebp->drawing->render(ct, bbox); cairo_surface_destroy(s); *to_free = px; @@ -451,15 +450,15 @@ sp_export_png_file(SPDocument *doc, gchar const *filename, ebp.height = height; ebp.background = bgcolor; - /* Create new arena */ - NRArena *const arena = NRArena::create(); - // export with maximum blur rendering quality - nr_arena_set_renderoffscreen(arena); + /* Create new drawing */ + Inkscape::Drawing drawing; + drawing.setExact(true); // export with maximum blur rendering quality unsigned const dkey = SPItem::display_key_new(1); // Create ArenaItems and set transform - ebp.root = doc->getRoot()->invoke_show(arena, dkey, SP_ITEM_SHOW_DISPLAY); - ebp.root->setTransform(affine); + drawing.setRoot(doc->getRoot()->invoke_show(drawing, dkey, SP_ITEM_SHOW_DISPLAY)); + drawing.root()->setTransform(affine); + ebp.drawing = &drawing; // We show all and then hide all items we don't want, instead of showing only requested items, // because that would not work if the shown item references something in defs @@ -483,9 +482,6 @@ sp_export_png_file(SPDocument *doc, gchar const *filename, // Hide items, this releases arenaitem doc->getRoot()->invoke_hide(dkey); - /* Free arena */ - nr_object_unref((NRObject *) arena); - return write_status; } -- cgit v1.2.3