From 208e5a33acc4a8ad9d8c0488f047c260346f1258 Mon Sep 17 00:00:00 2001 From: pjrm Date: Sat, 29 Sep 2007 12:54:44 +0000 Subject: [PATCH] noop: CodingStyle: re-indent a few files that had mixtures of spaces & tabs for indentation. --- src/display/bezier-utils-work.txt | 12 +- src/display/canvas-arena.cpp | 688 +++++++++++----------- src/display/canvas-axonomgrid.cpp | 63 +-- src/display/canvas-bpath.cpp | 320 ++++++----- src/display/canvas-grid.cpp | 136 +++-- src/display/curve.cpp | 54 +- src/display/guideline.cpp | 58 +- src/display/nr-arena-glyphs.cpp | 16 +- src/display/nr-arena-group.cpp | 231 ++++---- src/display/nr-arena-group.h | 38 +- src/display/nr-arena-image.cpp | 419 +++++++------- src/display/nr-arena-image.h | 44 +- src/display/nr-arena-item.h | 134 +++-- src/display/nr-arena-shape.h | 366 ++++++------ src/display/nr-arena.cpp | 172 +++--- src/display/nr-filter-gaussian.cpp | 14 +- src/display/sodipodi-ctrl.cpp | 880 +++++++++++++++-------------- src/display/sodipodi-ctrl.h | 67 ++- src/display/sodipodi-ctrlrect.cpp | 9 +- src/display/sp-canvas-util.cpp | 170 +++--- src/display/sp-canvas.cpp | 84 +-- 21 files changed, 2065 insertions(+), 1910 deletions(-) diff --git a/src/display/bezier-utils-work.txt b/src/display/bezier-utils-work.txt index 8604c1207..75ec5be86 100644 --- a/src/display/bezier-utils-work.txt +++ b/src/display/bezier-utils-work.txt @@ -23,12 +23,12 @@ d H / d b[2].z = sum_i B2(u[i]) * (bez_pt(b, u[i]) - d[i]).z Solve for dH/db[2].z==0: --sum_i B2(u[i]) B2(u[i]) * b[2].z = sum_i B2(u[i]) * (B0(u[i]) * b[0] + - B1(u[i]) * b[1] + - B3(u[i]) * b[3] +-sum_i B2(u[i]) B2(u[i]) * b[2].z = sum_i B2(u[i]) * (B0(u[i]) * b[0] + + B1(u[i]) * b[1] + + B3(u[i]) * b[3] - d[i] ).z -b[2].z = ((sum_i B2(u[i]) * (B0(u[i]) * b[0] + - B1(u[i]) * b[1] + - B3(u[i]) * b[3] +b[2].z = ((sum_i B2(u[i]) * (B0(u[i]) * b[0] + + B1(u[i]) * b[1] + + B3(u[i]) * b[3] - d[i] ).z) / -sum_i (B2(u[i]))^2) diff --git a/src/display/canvas-arena.cpp b/src/display/canvas-arena.cpp index bb60cdc93..bb636a91a 100644 --- a/src/display/canvas-arena.cpp +++ b/src/display/canvas-arena.cpp @@ -24,8 +24,8 @@ #include enum { - ARENA_EVENT, - LAST_SIGNAL + ARENA_EVENT, + LAST_SIGNAL }; static void sp_canvas_arena_class_init(SPCanvasArenaClass *klass); @@ -43,9 +43,9 @@ static void sp_canvas_arena_request_update (NRArena *arena, NRArenaItem *item, v static void sp_canvas_arena_request_render (NRArena *arena, NRRectL *area, void *data); NRArenaEventVector carenaev = { - {NULL}, - sp_canvas_arena_request_update, - sp_canvas_arena_request_render + {NULL}, + sp_canvas_arena_request_update, + sp_canvas_arena_request_render }; static SPCanvasItemClass *parent_class; @@ -54,446 +54,460 @@ static guint signals[LAST_SIGNAL] = {0}; GtkType sp_canvas_arena_get_type (void) { - static GtkType type = 0; - if (!type) { - GtkTypeInfo info = { - "SPCanvasArena", - sizeof (SPCanvasArena), - sizeof (SPCanvasArenaClass), - (GtkClassInitFunc) sp_canvas_arena_class_init, - (GtkObjectInitFunc) sp_canvas_arena_init, - NULL, NULL, NULL - }; - type = gtk_type_unique (SP_TYPE_CANVAS_ITEM, &info); - } - return type; + static GtkType type = 0; + if (!type) { + GtkTypeInfo info = { + "SPCanvasArena", + sizeof (SPCanvasArena), + sizeof (SPCanvasArenaClass), + (GtkClassInitFunc) sp_canvas_arena_class_init, + (GtkObjectInitFunc) sp_canvas_arena_init, + NULL, NULL, NULL + }; + type = gtk_type_unique (SP_TYPE_CANVAS_ITEM, &info); + } + return type; } static void sp_canvas_arena_class_init (SPCanvasArenaClass *klass) { - GtkObjectClass *object_class; - SPCanvasItemClass *item_class; + GtkObjectClass *object_class; + SPCanvasItemClass *item_class; - object_class = (GtkObjectClass *) klass; - item_class = (SPCanvasItemClass *) klass; + object_class = (GtkObjectClass *) klass; + item_class = (SPCanvasItemClass *) klass; - parent_class = (SPCanvasItemClass*)gtk_type_class (SP_TYPE_CANVAS_ITEM); + parent_class = (SPCanvasItemClass*)gtk_type_class (SP_TYPE_CANVAS_ITEM); - signals[ARENA_EVENT] = gtk_signal_new ("arena_event", - GTK_RUN_LAST, - GTK_CLASS_TYPE(object_class), - GTK_SIGNAL_OFFSET (SPCanvasArenaClass, arena_event), - sp_marshal_INT__POINTER_POINTER, - GTK_TYPE_INT, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER); + signals[ARENA_EVENT] = gtk_signal_new ("arena_event", + GTK_RUN_LAST, + GTK_CLASS_TYPE(object_class), + GTK_SIGNAL_OFFSET (SPCanvasArenaClass, arena_event), + sp_marshal_INT__POINTER_POINTER, + GTK_TYPE_INT, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER); - object_class->destroy = sp_canvas_arena_destroy; + object_class->destroy = sp_canvas_arena_destroy; - item_class->update = sp_canvas_arena_update; - item_class->render = sp_canvas_arena_render; - item_class->point = sp_canvas_arena_point; - item_class->event = sp_canvas_arena_event; + item_class->update = sp_canvas_arena_update; + item_class->render = sp_canvas_arena_render; + item_class->point = sp_canvas_arena_point; + item_class->event = sp_canvas_arena_event; } static void sp_canvas_arena_init (SPCanvasArena *arena) { - arena->sticky = FALSE; + arena->sticky = FALSE; - arena->arena = NRArena::create(); - arena->arena->canvasarena = arena; - arena->root = NRArenaGroup::create(arena->arena); - nr_arena_group_set_transparent (NR_ARENA_GROUP (arena->root), TRUE); + arena->arena = NRArena::create(); + arena->arena->canvasarena = arena; + arena->root = NRArenaGroup::create(arena->arena); + nr_arena_group_set_transparent (NR_ARENA_GROUP (arena->root), TRUE); - arena->active = NULL; + arena->active = NULL; - nr_active_object_add_listener ((NRActiveObject *) arena->arena, (NRObjectEventVector *) &carenaev, sizeof (carenaev), arena); + nr_active_object_add_listener ((NRActiveObject *) arena->arena, (NRObjectEventVector *) &carenaev, sizeof (carenaev), arena); } static void sp_canvas_arena_destroy (GtkObject *object) { - SPCanvasArena *arena = SP_CANVAS_ARENA (object); + SPCanvasArena *arena = SP_CANVAS_ARENA (object); - if (arena->active) { - nr_object_unref ((NRObject *) arena->active); - arena->active = NULL; - } + if (arena->active) { + nr_object_unref ((NRObject *) arena->active); + arena->active = NULL; + } - if (arena->root) { - nr_arena_item_unref (arena->root); - arena->root = NULL; - } + if (arena->root) { + nr_arena_item_unref (arena->root); + arena->root = NULL; + } - if (arena->arena) { - nr_active_object_remove_listener_by_data ((NRActiveObject *) arena->arena, arena); + if (arena->arena) { + nr_active_object_remove_listener_by_data ((NRActiveObject *) arena->arena, arena); - nr_object_unref ((NRObject *) arena->arena); - arena->arena = NULL; - } + nr_object_unref ((NRObject *) arena->arena); + arena->arena = NULL; + } - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); + if (GTK_OBJECT_CLASS (parent_class)->destroy) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } static void sp_canvas_arena_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags) { - SPCanvasArena *arena = SP_CANVAS_ARENA (item); - - if (((SPCanvasItemClass *) parent_class)->update) - (* ((SPCanvasItemClass *) parent_class)->update) (item, affine, flags); - - arena->gc.transform = affine; - - guint reset; - reset = (flags & SP_CANVAS_UPDATE_AFFINE)? NR_ARENA_ITEM_STATE_ALL : NR_ARENA_ITEM_STATE_NONE; - - nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, NR_ARENA_ITEM_STATE_ALL, reset); - - item->x1 = arena->root->bbox.x0 - 1; - item->y1 = arena->root->bbox.y0 - 1; - item->x2 = arena->root->bbox.x1 + 1; - item->y2 = arena->root->bbox.y1 + 1; - - if (arena->cursor) { - /* Mess with enter/leave notifiers */ - NRArenaItem *new_arena = nr_arena_item_invoke_pick (arena->root, arena->c, arena->arena->delta, arena->sticky); - if (new_arena != arena->active) { - GdkEventCrossing ec; - ec.window = GTK_WIDGET (item->canvas)->window; - ec.send_event = TRUE; - ec.subwindow = ec.window; - ec.time = GDK_CURRENT_TIME; - ec.x = arena->c[NR::X]; - ec.y = arena->c[NR::Y]; - /* fixme: */ - if (arena->active) { - ec.type = GDK_LEAVE_NOTIFY; - sp_canvas_arena_send_event (arena, (GdkEvent *) &ec); - } - /* fixme: This is not optimal - better track ::destroy (Lauris) */ - if (arena->active) nr_object_unref ((NRObject *) arena->active); - arena->active = new_arena; - if (arena->active) nr_object_ref ((NRObject *) arena->active); - if (arena->active) { - ec.type = GDK_ENTER_NOTIFY; - sp_canvas_arena_send_event (arena, (GdkEvent *) &ec); - } - } - } + SPCanvasArena *arena = SP_CANVAS_ARENA (item); + + if (((SPCanvasItemClass *) parent_class)->update) + (* ((SPCanvasItemClass *) parent_class)->update) (item, affine, flags); + + arena->gc.transform = affine; + + guint reset; + reset = (flags & SP_CANVAS_UPDATE_AFFINE)? NR_ARENA_ITEM_STATE_ALL : NR_ARENA_ITEM_STATE_NONE; + + nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, NR_ARENA_ITEM_STATE_ALL, reset); + + item->x1 = arena->root->bbox.x0 - 1; + item->y1 = arena->root->bbox.y0 - 1; + item->x2 = arena->root->bbox.x1 + 1; + item->y2 = arena->root->bbox.y1 + 1; + + if (arena->cursor) { + /* Mess with enter/leave notifiers */ + NRArenaItem *new_arena = nr_arena_item_invoke_pick (arena->root, arena->c, arena->arena->delta, arena->sticky); + if (new_arena != arena->active) { + GdkEventCrossing ec; + ec.window = GTK_WIDGET (item->canvas)->window; + ec.send_event = TRUE; + ec.subwindow = ec.window; + ec.time = GDK_CURRENT_TIME; + ec.x = arena->c[NR::X]; + ec.y = arena->c[NR::Y]; + /* fixme: */ + if (arena->active) { + ec.type = GDK_LEAVE_NOTIFY; + sp_canvas_arena_send_event (arena, (GdkEvent *) &ec); + } + /* fixme: This is not optimal - better track ::destroy (Lauris) */ + if (arena->active) nr_object_unref ((NRObject *) arena->active); + arena->active = new_arena; + if (arena->active) nr_object_ref ((NRObject *) arena->active); + if (arena->active) { + ec.type = GDK_ENTER_NOTIFY; + sp_canvas_arena_send_event (arena, (GdkEvent *) &ec); + } + } + } } static void sp_canvas_arena_render (SPCanvasItem *item, SPCanvasBuf *buf) { - gint bw, bh, sw, sh; - gint x, y; - - SPCanvasArena *arena = SP_CANVAS_ARENA (item); - - nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, - NR_ARENA_ITEM_STATE_BBOX | NR_ARENA_ITEM_STATE_RENDER, - NR_ARENA_ITEM_STATE_NONE); - - sp_canvas_prepare_buffer(buf); - - bw = buf->rect.x1 - buf->rect.x0; - bh = buf->rect.y1 - buf->rect.y0; - if ((bw < 1) || (bh < 1)) return; - - // FIXME: currently this function is a huge waste. It receives a buffer but creates a new one and loops - // within the large one, doing arena painting in several blocks. This just makes no sense because the - // buf that we are given is already only a strip of the screen, created by one iteration of a loop in - // sp_canvas_paint_rect_internal. With the current numbers, this function's buffer is always 1/4 - // smaller than the one we get, because they both are the same number of bytes but - // buf uses 3 bytes per pixel (24bpp, packed) while the pixblock created here uses 4 bytes (32bpp). - // Eventually I want to switch buf to using 4 bytes (see comment in canvas.cpp) and then remove - // from here the sw/sh calculation, the loop, and creating the intermediate buffer, allowing arena - // just render into buf in one go. - - if (arena->arena->rendermode != RENDERMODE_OUTLINE) { // use 256K as a compromise to not slow down gradients - /* 256K is the cached buffer and we need 4 channels */ - if (bw * bh < 65536) { // 256K/4 - /* We can go with single buffer */ - sw = bw; - sh = bh; - } else if (bw <= 4096) { - /* Go with row buffer */ - sw = bw; - sh = 65536 / bw; - } else if (bh <= 4096) { - /* Go with column buffer */ - sw = 65536 / bh; - sh = bh; - } else { - sw = 256; - sh = 256; - } - } else { // paths only, so 1M works faster - /* 1M is the cached buffer and we need 4 channels */ - if (bw * bh < 262144) { // 1M/4 - /* We can go with single buffer */ - sw = bw; - sh = bh; - } else if (bw <= 8192) { - /* Go with row buffer */ - sw = bw; - sh = 262144 / bw; - } else if (bh <= 8192) { - /* Go with column buffer */ - sw = 262144 / bh; - sh = bh; - } else { - sw = 512; - sh = 512; - } - } + gint bw, bh, sw, sh; + gint x, y; + + SPCanvasArena *arena = SP_CANVAS_ARENA (item); + + nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, + NR_ARENA_ITEM_STATE_BBOX | NR_ARENA_ITEM_STATE_RENDER, + NR_ARENA_ITEM_STATE_NONE); + + sp_canvas_prepare_buffer(buf); + + bw = buf->rect.x1 - buf->rect.x0; + bh = buf->rect.y1 - buf->rect.y0; + if ((bw < 1) || (bh < 1)) return; + + // FIXME: currently this function is a huge waste. It receives a buffer but creates a new one and loops + // within the large one, doing arena painting in several blocks. This just makes no sense because the + // buf that we are given is already only a strip of the screen, created by one iteration of a loop in + // sp_canvas_paint_rect_internal. With the current numbers, this function's buffer is always 1/4 + // smaller than the one we get, because they both are the same number of bytes but + // buf uses 3 bytes per pixel (24bpp, packed) while the pixblock created here uses 4 bytes (32bpp). + // Eventually I want to switch buf to using 4 bytes (see comment in canvas.cpp) and then remove + // from here the sw/sh calculation, the loop, and creating the intermediate buffer, allowing arena + // just render into buf in one go. + + if (arena->arena->rendermode != RENDERMODE_OUTLINE) { // use 256K as a compromise to not slow down gradients + /* 256K is the cached buffer and we need 4 channels */ + if (bw * bh < 65536) { // 256K/4 + /* We can go with single buffer */ + sw = bw; + sh = bh; + } else if (bw <= 4096) { + /* Go with row buffer */ + sw = bw; + sh = 65536 / bw; + } else if (bh <= 4096) { + /* Go with column buffer */ + sw = 65536 / bh; + sh = bh; + } else { + sw = 256; + sh = 256; + } + } else { // paths only, so 1M works faster + /* 1M is the cached buffer and we need 4 channels */ + if (bw * bh < 262144) { // 1M/4 + /* We can go with single buffer */ + sw = bw; + sh = bh; + } else if (bw <= 8192) { + /* Go with row buffer */ + sw = bw; + sh = 262144 / bw; + } else if (bh <= 8192) { + /* Go with column buffer */ + sw = 262144 / bh; + sh = bh; + } else { + sw = 512; + sh = 512; + } + } /* -This define chooses between two modes: When on, arena renders into a temporary -32bpp buffer, and the result is then squished into the SPCanvasBuf. When off, arena -renders directly to SPCanvasBuf. However currently this gives no speed advantage, -perhaps because the lack of squishing is offset by the need for arena items to render -to the inconvenient (and probably slower) 24bpp buffer. When SPCanvasBuf is -switched to 32bpp and cairo drawing, however, this define should be removed to -streamline rendering. +This define chooses between two modes: When on, arena renders into a temporary +32bpp buffer, and the result is then squished into the SPCanvasBuf. When off, arena +renders directly to SPCanvasBuf. However currently this gives no speed advantage, +perhaps because the lack of squishing is offset by the need for arena items to render +to the inconvenient (and probably slower) 24bpp buffer. When SPCanvasBuf is +switched to 32bpp and cairo drawing, however, this define should be removed to +streamline rendering. */ #define STRICT_RGBA - for (y = buf->rect.y0; y < buf->rect.y1; y += sh) { - for (x = buf->rect.x0; x < buf->rect.x1; x += sw) { - NRRectL area; + for (y = buf->rect.y0; y < buf->rect.y1; y += sh) { + for (x = buf->rect.x0; x < buf->rect.x1; x += sw) { + NRRectL area; #ifdef STRICT_RGBA - NRPixBlock pb; + NRPixBlock pb; #endif - NRPixBlock cb; + NRPixBlock cb; - area.x0 = x; - area.y0 = y; - area.x1 = MIN (x + sw, buf->rect.x1); - area.y1 = MIN (y + sh, buf->rect.y1); + area.x0 = x; + area.y0 = y; + area.x1 = MIN (x + sw, buf->rect.x1); + area.y1 = MIN (y + sh, buf->rect.y1); #ifdef STRICT_RGBA - nr_pixblock_setup_fast (&pb, NR_PIXBLOCK_MODE_R8G8B8A8P, area.x0, area.y0, area.x1, area.y1, TRUE); + nr_pixblock_setup_fast (&pb, NR_PIXBLOCK_MODE_R8G8B8A8P, area.x0, area.y0, area.x1, area.y1, TRUE); #endif // CAIRO FIXME: switch this to R8G8B8A8P and 4 * ... - nr_pixblock_setup_extern (&cb, NR_PIXBLOCK_MODE_R8G8B8, area.x0, area.y0, area.x1, area.y1, - buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + 3 * (x - buf->rect.x0), - buf->buf_rowstride, - FALSE, FALSE); + nr_pixblock_setup_extern (&cb, NR_PIXBLOCK_MODE_R8G8B8, area.x0, area.y0, area.x1, area.y1, + buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + 3 * (x - buf->rect.x0), + buf->buf_rowstride, + FALSE, FALSE); #ifdef STRICT_RGBA - pb.visible_area = buf->visible_rect; - - if (pb.data.px != NULL) { - cairo_t *ct = nr_create_cairo_context (&area, &pb); - - nr_arena_item_invoke_render (ct, arena->root, &area, &pb, 0); - - if (pb.empty == FALSE) { - - if (arena->arena->rendermode == RENDERMODE_OUTLINE) { - // currently we only use cairo in outline mode - - // ENDIANNESS FIX - // Inkscape and GTK use fixed byte order in their buffers: r, g, b, a. - // Cairo reads/writes buffer values as in32s and therefore depends on the hardware byte order - // (little-endian vs big-endian). - // Until we move ALL of inkscape rendering and screen display to cairo, - // we must reverse the order for big-endian architectures (e.g. PowerPC). - if (G_BYTE_ORDER == G_BIG_ENDIAN) { - unsigned char *start = NR_PIXBLOCK_PX(&pb); - unsigned char *end = start + pb.rs * (pb.area.y1 - pb.area.y0); - for (unsigned char *i = start; i < end; i += 4) { - unsigned char tmp0 = i[0]; - unsigned char tmp1 = i[1]; - i[0] = i[3]; - i[1] = i[2]; - i[2] = tmp1; - i[3] = tmp0; - } - } - } - - // this does the 32->24 squishing, using an assembler routine: - nr_blit_pixblock_pixblock (&cb, &pb); - } - - cairo_surface_t *cst = cairo_get_target(ct); - cairo_destroy (ct); - cairo_surface_finish (cst); - cairo_surface_destroy (cst); - } - - nr_pixblock_release (&pb); + pb.visible_area = buf->visible_rect; + + if (pb.data.px != NULL) { + cairo_t *ct = nr_create_cairo_context (&area, &pb); + + nr_arena_item_invoke_render (ct, arena->root, &area, &pb, 0); + + if (pb.empty == FALSE) { + + if (arena->arena->rendermode == RENDERMODE_OUTLINE) { + // currently we only use cairo in outline mode + + // ENDIANNESS FIX + // Inkscape and GTK use fixed byte order in their buffers: r, g, b, a. + // Cairo reads/writes buffer values as in32s and therefore depends on the hardware byte order + // (little-endian vs big-endian). + // Until we move ALL of inkscape rendering and screen display to cairo, + // we must reverse the order for big-endian architectures (e.g. PowerPC). + if (G_BYTE_ORDER == G_BIG_ENDIAN) { + unsigned char *start = NR_PIXBLOCK_PX(&pb); + unsigned char *end = start + pb.rs * (pb.area.y1 - pb.area.y0); + for (unsigned char *i = start; i < end; i += 4) { + unsigned char tmp0 = i[0]; + unsigned char tmp1 = i[1]; + i[0] = i[3]; + i[1] = i[2]; + i[2] = tmp1; + i[3] = tmp0; + } + } + } + + // this does the 32->24 squishing, using an assembler routine: + nr_blit_pixblock_pixblock (&cb, &pb); + } + + cairo_surface_t *cst = cairo_get_target(ct); + cairo_destroy (ct); + cairo_surface_finish (cst); + cairo_surface_destroy (cst); + } + + nr_pixblock_release (&pb); #else - cb.visible_area = buf->visible_rect; - nr_arena_item_invoke_render (NULL, arena->root, &area, &cb, 0); + cb.visible_area = buf->visible_rect; + nr_arena_item_invoke_render (NULL, arena->root, &area, &cb, 0); #endif - nr_pixblock_release (&cb); - } - } + nr_pixblock_release (&cb); + } + } } static double sp_canvas_arena_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item) { - SPCanvasArena *arena = SP_CANVAS_ARENA (item); + SPCanvasArena *arena = SP_CANVAS_ARENA (item); - nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, - NR_ARENA_ITEM_STATE_BBOX | NR_ARENA_ITEM_STATE_PICK, - NR_ARENA_ITEM_STATE_NONE); + nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, + NR_ARENA_ITEM_STATE_BBOX | NR_ARENA_ITEM_STATE_PICK, + NR_ARENA_ITEM_STATE_NONE); - NRArenaItem *picked = nr_arena_item_invoke_pick (arena->root, p, arena->arena->delta, arena->sticky); + NRArenaItem *picked = nr_arena_item_invoke_pick (arena->root, p, arena->arena->delta, arena->sticky); - arena->picked = picked; + arena->picked = picked; - if (picked) { - *actual_item = item; - return 0.0; - } + if (picked) { + *actual_item = item; + return 0.0; + } - return 1e18; + return 1e18; } static gint sp_canvas_arena_event (SPCanvasItem *item, GdkEvent *event) { - NRArenaItem *new_arena; - /* fixme: This sucks, we have to handle enter/leave notifiers */ - - SPCanvasArena *arena = SP_CANVAS_ARENA (item); - - gint ret = FALSE; - - switch (event->type) { - case GDK_ENTER_NOTIFY: - if (!arena->cursor) { - if (arena->active) { - //g_warning ("Cursor entered to arena with already active item"); - nr_object_unref ((NRObject *) arena->active); - } - arena->cursor = TRUE; - - /* TODO ... event -> arena transform? */ - arena->c = NR::Point(event->crossing.x, event->crossing.y); - - /* fixme: Not sure abut this, but seems the right thing (Lauris) */ - nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, NR_ARENA_ITEM_STATE_PICK, NR_ARENA_ITEM_STATE_NONE); - arena->active = nr_arena_item_invoke_pick (arena->root, arena->c, arena->arena->delta, arena->sticky); - if (arena->active) nr_object_ref ((NRObject *) arena->active); - ret = sp_canvas_arena_send_event (arena, event); - } - break; - case GDK_LEAVE_NOTIFY: - if (arena->cursor) { - ret = sp_canvas_arena_send_event (arena, event); - if (arena->active) nr_object_unref ((NRObject *) arena->active); - arena->active = NULL; - arena->cursor = FALSE; - } - break; - case GDK_MOTION_NOTIFY: - /* TODO ... event -> arena transform? */ - arena->c = NR::Point(event->motion.x, event->motion.y); - - /* fixme: Not sure abut this, but seems the right thing (Lauris) */ - nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, NR_ARENA_ITEM_STATE_PICK, NR_ARENA_ITEM_STATE_NONE); - new_arena = nr_arena_item_invoke_pick (arena->root, arena->c, arena->arena->delta, arena->sticky); - if (new_arena != arena->active) { - GdkEventCrossing ec; - ec.window = event->motion.window; - ec.send_event = event->motion.send_event; - ec.subwindow = event->motion.window; - ec.time = event->motion.time; - ec.x = event->motion.x; - ec.y = event->motion.y; - /* fixme: */ - if (arena->active) { - ec.type = GDK_LEAVE_NOTIFY; - ret = sp_canvas_arena_send_event (arena, (GdkEvent *) &ec); - } - if (arena->active) nr_object_unref ((NRObject *) arena->active); - arena->active = new_arena; - if (arena->active) nr_object_ref ((NRObject *) arena->active); - if (arena->active) { - ec.type = GDK_ENTER_NOTIFY; - ret = sp_canvas_arena_send_event (arena, (GdkEvent *) &ec); - } - } - ret = sp_canvas_arena_send_event (arena, event); - break; - default: - /* Just send event */ - ret = sp_canvas_arena_send_event (arena, event); - break; - } - - return ret; + NRArenaItem *new_arena; + /* fixme: This sucks, we have to handle enter/leave notifiers */ + + SPCanvasArena *arena = SP_CANVAS_ARENA (item); + + gint ret = FALSE; + + switch (event->type) { + case GDK_ENTER_NOTIFY: + if (!arena->cursor) { + if (arena->active) { + //g_warning ("Cursor entered to arena with already active item"); + nr_object_unref ((NRObject *) arena->active); + } + arena->cursor = TRUE; + + /* TODO ... event -> arena transform? */ + arena->c = NR::Point(event->crossing.x, event->crossing.y); + + /* fixme: Not sure abut this, but seems the right thing (Lauris) */ + nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, NR_ARENA_ITEM_STATE_PICK, NR_ARENA_ITEM_STATE_NONE); + arena->active = nr_arena_item_invoke_pick (arena->root, arena->c, arena->arena->delta, arena->sticky); + if (arena->active) nr_object_ref ((NRObject *) arena->active); + ret = sp_canvas_arena_send_event (arena, event); + } + break; + + case GDK_LEAVE_NOTIFY: + if (arena->cursor) { + ret = sp_canvas_arena_send_event (arena, event); + if (arena->active) nr_object_unref ((NRObject *) arena->active); + arena->active = NULL; + arena->cursor = FALSE; + } + break; + + case GDK_MOTION_NOTIFY: + /* TODO ... event -> arena transform? */ + arena->c = NR::Point(event->motion.x, event->motion.y); + + /* fixme: Not sure abut this, but seems the right thing (Lauris) */ + nr_arena_item_invoke_update (arena->root, NULL, &arena->gc, NR_ARENA_ITEM_STATE_PICK, NR_ARENA_ITEM_STATE_NONE); + new_arena = nr_arena_item_invoke_pick (arena->root, arena->c, arena->arena->delta, arena->sticky); + if (new_arena != arena->active) { + GdkEventCrossing ec; + ec.window = event->motion.window; + ec.send_event = event->motion.send_event; + ec.subwindow = event->motion.window; + ec.time = event->motion.time; + ec.x = event->motion.x; + ec.y = event->motion.y; + /* fixme: */ + if (arena->active) { + ec.type = GDK_LEAVE_NOTIFY; + ret = sp_canvas_arena_send_event (arena, (GdkEvent *) &ec); + } + if (arena->active) nr_object_unref ((NRObject *) arena->active); + arena->active = new_arena; + if (arena->active) nr_object_ref ((NRObject *) arena->active); + if (arena->active) { + ec.type = GDK_ENTER_NOTIFY; + ret = sp_canvas_arena_send_event (arena, (GdkEvent *) &ec); + } + } + ret = sp_canvas_arena_send_event (arena, event); + break; + + default: + /* Just send event */ + ret = sp_canvas_arena_send_event (arena, event); + break; + } + + return ret; } static gint sp_canvas_arena_send_event (SPCanvasArena *arena, GdkEvent *event) { - gint ret = FALSE; + gint ret = FALSE; - /* Send event to arena */ - gtk_signal_emit (GTK_OBJECT (arena), signals[ARENA_EVENT], arena->active, event, &ret); + /* Send event to arena */ + gtk_signal_emit (GTK_OBJECT (arena), signals[ARENA_EVENT], arena->active, event, &ret); - return ret; + return ret; } static void sp_canvas_arena_request_update (NRArena *arena, NRArenaItem *item, void *data) { - sp_canvas_item_request_update (SP_CANVAS_ITEM (data)); + sp_canvas_item_request_update (SP_CANVAS_ITEM (data)); } static void sp_canvas_arena_request_render (NRArena *arena, NRRectL *area, void *data) { - sp_canvas_request_redraw (SP_CANVAS_ITEM (data)->canvas, area->x0, area->y0, area->x1, area->y1); + sp_canvas_request_redraw (SP_CANVAS_ITEM (data)->canvas, area->x0, area->y0, area->x1, area->y1); } void sp_canvas_arena_set_pick_delta (SPCanvasArena *ca, gdouble delta) { - g_return_if_fail (ca != NULL); - g_return_if_fail (SP_IS_CANVAS_ARENA (ca)); + g_return_if_fail (ca != NULL); + g_return_if_fail (SP_IS_CANVAS_ARENA (ca)); - /* fixme: repick? */ - ca->delta = delta; + /* fixme: repick? */ + ca->delta = delta; } void sp_canvas_arena_set_sticky (SPCanvasArena *ca, gboolean sticky) { - g_return_if_fail (ca != NULL); - g_return_if_fail (SP_IS_CANVAS_ARENA (ca)); + g_return_if_fail (ca != NULL); + g_return_if_fail (SP_IS_CANVAS_ARENA (ca)); - /* fixme: repick? */ - ca->sticky = sticky; + /* fixme: repick? */ + ca->sticky = sticky; } void sp_canvas_arena_render_pixblock (SPCanvasArena *ca, NRPixBlock *pb) { - NRRectL area; + NRRectL area; - g_return_if_fail (ca != NULL); - g_return_if_fail (SP_IS_CANVAS_ARENA (ca)); + g_return_if_fail (ca != NULL); + g_return_if_fail (SP_IS_CANVAS_ARENA (ca)); - /* fixme: */ - pb->empty = FALSE; + /* fixme: */ + pb->empty = FALSE; - area.x0 = pb->area.x0; - area.y0 = pb->area.y0; - area.x1 = pb->area.x1; - area.y1 = pb->area.y1; + area.x0 = pb->area.x0; + area.y0 = pb->area.y0; + area.x1 = pb->area.x1; + area.y1 = pb->area.y1; - nr_arena_item_invoke_render (NULL, ca->root, &area, pb, 0); + nr_arena_item_invoke_render (NULL, ca->root, &area, pb, 0); } + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index d7e60596f..beb5c088a 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -14,9 +14,9 @@ */ /* - * TODO: LOTS LOTS LOTS. Clean up code. dirty as hell + * TODO: LOTS LOTS LOTS. Clean up code. dirty as hell * THIS FILE AND THE HEADER FILE NEED HUGE CLEANING UP. PLEASE DO NOT HESISTATE TO DO SO. -* For example: the line drawing code should not be here. There _must_ be a function somewhere else that can provide this functionality... + * For example: the line drawing code should not be here. There _must_ be a function somewhere else that can provide this functionality... */ #include "sp-canvas-util.h" @@ -36,14 +36,14 @@ #include "inkscape.h" #include "desktop.h" -#include "../document.h" +#include "document.h" #define SAFE_SETPIXEL //undefine this when it is certain that setpixel is never called with invalid params enum Dim3 { X=0, Y, Z }; #ifndef M_PI -#define M_PI 3.14159265358979323846 +# define M_PI 3.14159265358979323846 #endif static double deg_to_rad(double deg) { return deg*M_PI/180.0;} @@ -60,7 +60,8 @@ static double deg_to_rad(double deg) { return deg*M_PI/180.0;} ( rect.x1 - rect.x0 , rect.y1 - rect.y0 ) in setpixel coordinates */ static void -sp_caxonomgrid_setpixel (SPCanvasBuf *buf, gint x, gint y, guint32 rgba) { +sp_caxonomgrid_setpixel (SPCanvasBuf *buf, gint x, gint y, guint32 rgba) +{ #ifdef SAFE_SETPIXEL if ( (x >= buf->rect.x0) && (x < buf->rect.x1) && (y >= buf->rect.y0) && (y < buf->rect.y1) ) { #endif @@ -85,7 +86,8 @@ sp_caxonomgrid_setpixel (SPCanvasBuf *buf, gint x, gint y, guint32 rgba) { Coordinates are interpreted as SCREENcoordinates */ static void -sp_caxonomgrid_drawline (SPCanvasBuf *buf, gint x0, gint y0, gint x1, gint y1, guint32 rgba) { +sp_caxonomgrid_drawline (SPCanvasBuf *buf, gint x0, gint y0, gint x1, gint y1, guint32 rgba) +{ int dy = y1 - y0; int dx = x1 - x0; int stepx, stepy; @@ -162,33 +164,26 @@ namespace Inkscape { static inline void attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int start = 0) { - for (unsigned i=0, r=start; i(*arr[i]), 1, 2, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); + Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); table.attach (const_cast(*arr[i+1]), 2, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); - } - else - { - if (arr[i+1]) + Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); + } else { + if (arr[i+1]) { table.attach (const_cast(*arr[i+1]), 1, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); - else if (arr[i]) - { + Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); + } else if (arr[i]) { Gtk::Label& label = reinterpret_cast (const_cast(*arr[i])); label.set_alignment (0.0); table.attach (label, 0, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); - } - else - { + Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); + } else { Gtk::HBox *space = manage (new Gtk::HBox); space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y); table.attach (*space, 0, 1, r, r+1, - (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0); + (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0); } } ++r; @@ -198,11 +193,7 @@ attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc) : CanvasGrid(nv, in_repr, in_doc), table(1, 1) { - origin[NR::X] = origin[NR::Y] = 0.0; -// nv->gridcolor = (nv->gridcolor & 0xff) | (DEFAULTGRIDCOLOR & 0xffffff00); -// case SP_ATTR_GRIDOPACITY: -// nv->gridcolor = (nv->gridcolor & 0xffffff00) | (DEFAULTGRIDCOLOR & 0xff); color = 0xff3f3f20; empcolor = 0xFF3F3F40; empspacing = 5; @@ -265,7 +256,7 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r CanvasAxonomGrid::~CanvasAxonomGrid () { - if (snapper) delete snapper; + if (snapper) delete snapper; } @@ -433,7 +424,7 @@ CanvasAxonomGrid::updateWidgets() _wr.setUpdating (true); -// _rrb_gridtype.setValue (nv->gridtype); + //_rrb_gridtype.setValue (nv->gridtype); _rumg.setUnit (gridunit); gdouble val; @@ -466,7 +457,7 @@ CanvasAxonomGrid::Update (NR::Matrix const &affine, unsigned int flags) { ow = origin * affine; sw = NR::Point(fabs(affine[0]),fabs(affine[3])); - + for(int dim = 0; dim < 2; dim++) { gint scaling_factor = empspacing; @@ -500,11 +491,11 @@ CanvasAxonomGrid::Update (NR::Matrix const &affine, unsigned int flags) void CanvasAxonomGrid::Render (SPCanvasBuf *buf) { - // gc = gridcoordinates (the coordinates calculated from the grids origin 'grid->ow'. - // sc = screencoordinates ( for example "buf->rect.x0" is in screencoordinates ) - // bc = buffer patch coordinates + // gc = gridcoordinates (the coordinates calculated from the grids origin 'grid->ow'. + // sc = screencoordinates ( for example "buf->rect.x0" is in screencoordinates ) + // bc = buffer patch coordinates - // tl = topleft ; br = bottomright + // tl = topleft ; br = bottomright NR::Point buf_tl_gc; NR::Point buf_br_gc; buf_tl_gc[NR::X] = buf->rect.x0 - ow[NR::X]; @@ -672,4 +663,4 @@ CanvasAxonomGridSnapper::_getSnapLines(NR::Point const &p) const fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/canvas-bpath.cpp b/src/display/canvas-bpath.cpp index 909ea84ec..8fecb4e3d 100644 --- a/src/display/canvas-bpath.cpp +++ b/src/display/canvas-bpath.cpp @@ -42,15 +42,15 @@ sp_canvas_bpath_get_type (void) { static GtkType type = 0; if (!type) { - GtkTypeInfo info = { - "SPCanvasBPath", - sizeof (SPCanvasBPath), - sizeof (SPCanvasBPathClass), - (GtkClassInitFunc) sp_canvas_bpath_class_init, - (GtkObjectInitFunc) sp_canvas_bpath_init, - NULL, NULL, NULL - }; - type = gtk_type_unique (SP_TYPE_CANVAS_ITEM, &info); + GtkTypeInfo info = { + "SPCanvasBPath", + sizeof (SPCanvasBPath), + sizeof (SPCanvasBPathClass), + (GtkClassInitFunc) sp_canvas_bpath_class_init, + (GtkObjectInitFunc) sp_canvas_bpath_init, + NULL, NULL, NULL + }; + type = gtk_type_unique (SP_TYPE_CANVAS_ITEM, &info); } return type; } @@ -94,20 +94,20 @@ sp_canvas_bpath_destroy (GtkObject *object) { SPCanvasBPath *cbp = SP_CANVAS_BPATH (object); if (cbp->fill_shp) { - delete cbp->fill_shp; - cbp->fill_shp = NULL; + delete cbp->fill_shp; + cbp->fill_shp = NULL; } if (cbp->stroke_shp) { - delete cbp->stroke_shp; - cbp->stroke_shp = NULL; + delete cbp->stroke_shp; + cbp->stroke_shp = NULL; } if (cbp->curve) { - cbp->curve = sp_curve_unref (cbp->curve); + cbp->curve = sp_curve_unref (cbp->curve); } if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } static void @@ -118,18 +118,18 @@ sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); if (((SPCanvasItemClass *) parent_class)->update) - ((SPCanvasItemClass *) parent_class)->update (item, affine, flags); + ((SPCanvasItemClass *) parent_class)->update (item, affine, flags); sp_canvas_item_reset_bounds (item); if (cbp->fill_shp) { - delete cbp->fill_shp; - cbp->fill_shp = NULL; + delete cbp->fill_shp; + cbp->fill_shp = NULL; } if (cbp->stroke_shp) { - delete cbp->stroke_shp; - cbp->stroke_shp = NULL; + delete cbp->stroke_shp; + cbp->stroke_shp = NULL; } if (!cbp->curve) return; @@ -139,62 +139,62 @@ sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i dbox.x1 = dbox.y1 = -1.0; if ((cbp->fill_rgba & 0xff) || (cbp->stroke_rgba & 0xff)) { - Path* thePath=new Path; - thePath->LoadArtBPath(SP_CURVE_BPATH(cbp->curve), affine, true); - thePath->Convert(0.25); - if ((cbp->fill_rgba & 0xff) && (cbp->curve->end > 2)) { - Shape* theShape=new Shape; - thePath->Fill(theShape,0); - if ( cbp->fill_shp == NULL ) cbp->fill_shp=new Shape; - if ( cbp->fill_rule == SP_WIND_RULE_EVENODD ) { - cbp->fill_shp->ConvertToShape(theShape,fill_oddEven); - } else { - cbp->fill_shp->ConvertToShape(theShape,fill_nonZero); - } - delete theShape; - cbp->fill_shp->CalcBBox(); - if ( cbp->fill_shp->leftX < cbp->fill_shp->rightX ) { - if ( dbox.x0 >= dbox.x1 ) { - dbox.x0 = cbp->fill_shp->leftX; dbox.x1 = cbp->fill_shp->rightX; - dbox.y0 = cbp->fill_shp->topY; dbox.y1 = cbp->fill_shp->bottomY; - } else { - if ( cbp->fill_shp->leftX < dbox.x0 ) dbox.x0=cbp->fill_shp->leftX; - if ( cbp->fill_shp->rightX > dbox.x1 ) dbox.x1=cbp->fill_shp->rightX; - if ( cbp->fill_shp->topY < dbox.y0 ) dbox.y0=cbp->fill_shp->topY; - if ( cbp->fill_shp->bottomY > dbox.y1 ) dbox.y1=cbp->fill_shp->bottomY; - } - } - } - if ((cbp->stroke_rgba & 0xff) && (cbp->curve->end > 1)) { - JoinType join=join_straight; + Path* thePath=new Path; + thePath->LoadArtBPath(SP_CURVE_BPATH(cbp->curve), affine, true); + thePath->Convert(0.25); + if ((cbp->fill_rgba & 0xff) && (cbp->curve->end > 2)) { + Shape* theShape=new Shape; + thePath->Fill(theShape,0); + if ( cbp->fill_shp == NULL ) cbp->fill_shp=new Shape; + if ( cbp->fill_rule == SP_WIND_RULE_EVENODD ) { + cbp->fill_shp->ConvertToShape(theShape,fill_oddEven); + } else { + cbp->fill_shp->ConvertToShape(theShape,fill_nonZero); + } + delete theShape; + cbp->fill_shp->CalcBBox(); + if ( cbp->fill_shp->leftX < cbp->fill_shp->rightX ) { + if ( dbox.x0 >= dbox.x1 ) { + dbox.x0 = cbp->fill_shp->leftX; dbox.x1 = cbp->fill_shp->rightX; + dbox.y0 = cbp->fill_shp->topY; dbox.y1 = cbp->fill_shp->bottomY; + } else { + if ( cbp->fill_shp->leftX < dbox.x0 ) dbox.x0=cbp->fill_shp->leftX; + if ( cbp->fill_shp->rightX > dbox.x1 ) dbox.x1=cbp->fill_shp->rightX; + if ( cbp->fill_shp->topY < dbox.y0 ) dbox.y0=cbp->fill_shp->topY; + if ( cbp->fill_shp->bottomY > dbox.y1 ) dbox.y1=cbp->fill_shp->bottomY; + } + } + } + if ((cbp->stroke_rgba & 0xff) && (cbp->curve->end > 1)) { + JoinType join=join_straight; // Shape* theShape=new Shape; - ButtType butt=butt_straight; - if ( cbp->stroke_shp == NULL ) cbp->stroke_shp=new Shape; - if ( cbp->stroke_linecap == SP_STROKE_LINECAP_BUTT ) butt=butt_straight; - if ( cbp->stroke_linecap == SP_STROKE_LINECAP_ROUND ) butt=butt_round; - if ( cbp->stroke_linecap == SP_STROKE_LINECAP_SQUARE ) butt=butt_square; - if ( cbp->stroke_linejoin == SP_STROKE_LINEJOIN_MITER ) join=join_pointy; - if ( cbp->stroke_linejoin == SP_STROKE_LINEJOIN_ROUND ) join=join_round; - if ( cbp->stroke_linejoin == SP_STROKE_LINEJOIN_BEVEL ) join=join_straight; - thePath->Stroke(cbp->stroke_shp,false,0.5*cbp->stroke_width, join,butt,cbp->stroke_width*cbp->stroke_miterlimit ); - // thePath->Stroke(theShape,false,0.5*cbp->stroke_width, join,butt,cbp->stroke_width*cbp->stroke_miterlimit ); - // cbp->stroke_shp->ConvertToShape(theShape,fill_nonZero); - - cbp->stroke_shp->CalcBBox(); - if ( cbp->stroke_shp->leftX < cbp->stroke_shp->rightX ) { - if ( dbox.x0 >= dbox.x1 ) { - dbox.x0 = cbp->stroke_shp->leftX;dbox.x1 = cbp->stroke_shp->rightX; - dbox.y0 = cbp->stroke_shp->topY;dbox.y1 = cbp->stroke_shp->bottomY; - } else { - if ( cbp->stroke_shp->leftX < dbox.x0 ) dbox.x0 = cbp->stroke_shp->leftX; - if ( cbp->stroke_shp->rightX > dbox.x1 ) dbox.x1 = cbp->stroke_shp->rightX; - if ( cbp->stroke_shp->topY < dbox.y0 ) dbox.y0 = cbp->stroke_shp->topY; - if ( cbp->stroke_shp->bottomY > dbox.y1 ) dbox.y1 = cbp->stroke_shp->bottomY; - } - } + ButtType butt=butt_straight; + if ( cbp->stroke_shp == NULL ) cbp->stroke_shp=new Shape; + if ( cbp->stroke_linecap == SP_STROKE_LINECAP_BUTT ) butt=butt_straight; + if ( cbp->stroke_linecap == SP_STROKE_LINECAP_ROUND ) butt=butt_round; + if ( cbp->stroke_linecap == SP_STROKE_LINECAP_SQUARE ) butt=butt_square; + if ( cbp->stroke_linejoin == SP_STROKE_LINEJOIN_MITER ) join=join_pointy; + if ( cbp->stroke_linejoin == SP_STROKE_LINEJOIN_ROUND ) join=join_round; + if ( cbp->stroke_linejoin == SP_STROKE_LINEJOIN_BEVEL ) join=join_straight; + thePath->Stroke(cbp->stroke_shp,false,0.5*cbp->stroke_width, join,butt,cbp->stroke_width*cbp->stroke_miterlimit ); + // thePath->Stroke(theShape,false,0.5*cbp->stroke_width, join,butt,cbp->stroke_width*cbp->stroke_miterlimit ); + // cbp->stroke_shp->ConvertToShape(theShape,fill_nonZero); + + cbp->stroke_shp->CalcBBox(); + if ( cbp->stroke_shp->leftX < cbp->stroke_shp->rightX ) { + if ( dbox.x0 >= dbox.x1 ) { + dbox.x0 = cbp->stroke_shp->leftX;dbox.x1 = cbp->stroke_shp->rightX; + dbox.y0 = cbp->stroke_shp->topY;dbox.y1 = cbp->stroke_shp->bottomY; + } else { + if ( cbp->stroke_shp->leftX < dbox.x0 ) dbox.x0 = cbp->stroke_shp->leftX; + if ( cbp->stroke_shp->rightX > dbox.x1 ) dbox.x1 = cbp->stroke_shp->rightX; + if ( cbp->stroke_shp->topY < dbox.y0 ) dbox.y0 = cbp->stroke_shp->topY; + if ( cbp->stroke_shp->bottomY > dbox.y1 ) dbox.y1 = cbp->stroke_shp->bottomY; + } + } // delete theShape; - } - delete thePath; + } + delete thePath; } @@ -219,10 +219,10 @@ sp_canvas_bpath_render (SPCanvasItem *item, SPCanvasBuf *buf) area.y0=buf->rect.y0; area.y1=buf->rect.y1; if ( cbp->fill_shp ) { - nr_pixblock_render_bpath_rgba (cbp->fill_shp,cbp->fill_rgba,area,(char*)buf->buf, buf->buf_rowstride); + nr_pixblock_render_bpath_rgba (cbp->fill_shp,cbp->fill_rgba,area,(char*)buf->buf, buf->buf_rowstride); } if ( cbp->stroke_shp ) { - nr_pixblock_render_bpath_rgba (cbp->stroke_shp,cbp->stroke_rgba,area,(char*)buf->buf, buf->buf_rowstride); + nr_pixblock_render_bpath_rgba (cbp->stroke_shp,cbp->stroke_rgba,area,(char*)buf->buf, buf->buf_rowstride); } } @@ -235,15 +235,15 @@ sp_canvas_bpath_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_it SPCanvasBPath *cbp = SP_CANVAS_BPATH (item); if (cbp->fill_shp && (cbp->fill_shp->PtWinding(p) > 0 )) { - *actual_item = item; - return 0.0; + *actual_item = item; + return 0.0; } if (cbp->stroke_shp ) { - if (cbp->stroke_shp->PtWinding(p) > 0 ) { - *actual_item = item; - return 0.0; - } - return distance(cbp->stroke_shp, p); + if (cbp->stroke_shp->PtWinding(p) > 0 ) { + *actual_item = item; + return 0.0; + } + return distance(cbp->stroke_shp, p); } if (cbp->fill_shp) { return distance(cbp->fill_shp, p); @@ -272,11 +272,11 @@ sp_canvas_bpath_set_bpath (SPCanvasBPath *cbp, SPCurve *curve) g_return_if_fail (SP_IS_CANVAS_BPATH (cbp)); if (cbp->curve) { - cbp->curve = sp_curve_unref (cbp->curve); + cbp->curve = sp_curve_unref (cbp->curve); } if (curve) { - cbp->curve = sp_curve_ref (curve); + cbp->curve = sp_curve_ref (curve); } sp_canvas_item_request_update (SP_CANVAS_ITEM (cbp)); @@ -314,8 +314,8 @@ static void bpath_run_A8_OR (raster_info &dest,void *data,int st,float vst,int en,float ven) { union { - uint8_t comp[4]; - uint32_t col; + uint8_t comp[4]; + uint32_t col; } tempCol; if ( st >= en ) return; tempCol.col=*(uint32_t*)data; @@ -341,55 +341,55 @@ bpath_run_A8_OR (raster_info &dest,void *data,int st,float vst,int en,float ven) d+=3*(st-dest.startPix); if ( fabs(dv) < 0.001 ) { - if ( sv > 249.999 ) { - /* Simple copy */ - while (len > 0) { - d[0] = NR_COMPOSEN11_1111 (r, 255, d[0]); - d[1] = NR_COMPOSEN11_1111 (g, 255, d[1]); - d[2] = NR_COMPOSEN11_1111 (b, 255, d[2]); - d += 3; - len -= 1; - } - } else { - unsigned int c0_24=(int)sv; - c0_24&=0xFF; - while (len > 0) { - d[0] = NR_COMPOSEN11_1111 (r, c0_24, d[0]); - d[1] = NR_COMPOSEN11_1111 (g, c0_24, d[1]); - d[2] = NR_COMPOSEN11_1111 (b, c0_24, d[2]); - d += 3; - len -= 1; - } - } + if ( sv > 249.999 ) { + /* Simple copy */ + while (len > 0) { + d[0] = NR_COMPOSEN11_1111 (r, 255, d[0]); + d[1] = NR_COMPOSEN11_1111 (g, 255, d[1]); + d[2] = NR_COMPOSEN11_1111 (b, 255, d[2]); + d += 3; + len -= 1; + } + } else { + unsigned int c0_24=(int)sv; + c0_24&=0xFF; + while (len > 0) { + d[0] = NR_COMPOSEN11_1111 (r, c0_24, d[0]); + d[1] = NR_COMPOSEN11_1111 (g, c0_24, d[1]); + d[2] = NR_COMPOSEN11_1111 (b, c0_24, d[2]); + d += 3; + len -= 1; + } + } } else { - if ( en <= st+1 ) { - sv=0.5*(vst+ven); - unsigned int c0_24=(int)sv; - c0_24&=0xFF; - d[0] = NR_COMPOSEN11_1111 (r, c0_24, d[0]); - d[1] = NR_COMPOSEN11_1111 (g, c0_24, d[1]); - d[2] = NR_COMPOSEN11_1111 (b, c0_24, d[2]); - } else { - dv/=len; - sv+=0.5*dv; // correction trapezoidale - sv*=65536; - dv*=65536; - int c0_24 = static_cast(CLAMP(sv, 0, 16777216)); - int s0_24 = static_cast(dv); - while (len > 0) { - unsigned int ca; - /* Draw */ - ca = c0_24 >> 16; - if ( ca > 255 ) ca=255; - d[0] = NR_COMPOSEN11_1111 (r, ca, d[0]); - d[1] = NR_COMPOSEN11_1111 (g, ca, d[1]); - d[2] = NR_COMPOSEN11_1111 (b, ca, d[2]); - d += 3; - c0_24 += s0_24; - c0_24 = CLAMP (c0_24, 0, 16777216); - len -= 1; - } - } + if ( en <= st+1 ) { + sv=0.5*(vst+ven); + unsigned int c0_24=(int)sv; + c0_24&=0xFF; + d[0] = NR_COMPOSEN11_1111 (r, c0_24, d[0]); + d[1] = NR_COMPOSEN11_1111 (g, c0_24, d[1]); + d[2] = NR_COMPOSEN11_1111 (b, c0_24, d[2]); + } else { + dv/=len; + sv+=0.5*dv; // correction trapezoidale + sv*=65536; + dv*=65536; + int c0_24 = static_cast(CLAMP(sv, 0, 16777216)); + int s0_24 = static_cast(dv); + while (len > 0) { + unsigned int ca; + /* Draw */ + ca = c0_24 >> 16; + if ( ca > 255 ) ca=255; + d[0] = NR_COMPOSEN11_1111 (r, ca, d[0]); + d[1] = NR_COMPOSEN11_1111 (g, ca, d[1]); + d[2] = NR_COMPOSEN11_1111 (b, ca, d[2]); + d += 3; + c0_24 += s0_24; + c0_24 = CLAMP (c0_24, 0, 16777216); + len -= 1; + } + } } } @@ -459,27 +459,39 @@ void nr_pixblock_render_bpath_rgba (Shape* theS,uint32_t color,NRRectL &area,cha char* mdata=(char*)destBuf; uint32_t* ligStart=((uint32_t*)(mdata+(3*(il-area.x0)+stride*(it-area.y0)))); for (int y=it;yReset(); - - for (int i = 0; i < 4; i++) - theS->QuickScan(curY, curPt, ((float)(y+0.25*(i+1))), - fill_oddEven, theI[i], 0.25); - - theIL->Copy(4,theI); - // theI[0]->Affiche(); - // theIL->Affiche(); - - raster_info dest; - dest.startPix=il; - dest.endPix=ir; - dest.sth=il; - dest.stv=y; - dest.buffer=ligStart; - theIL->Raster(dest,&color,bpath_run_A8_OR); - ligStart=((uint32_t*)(((char*)ligStart)+stride)); + for (int i = 0; i < 4; i++) + theI[i]->Reset(); + + for (int i = 0; i < 4; i++) + theS->QuickScan(curY, curPt, ((float)(y+0.25*(i+1))), + fill_oddEven, theI[i], 0.25); + + theIL->Copy(4,theI); + // theI[0]->Affiche(); + // theIL->Affiche(); + + raster_info dest; + dest.startPix=il; + dest.endPix=ir; + dest.sth=il; + dest.stv=y; + dest.buffer=ligStart; + theIL->Raster(dest,&color,bpath_run_A8_OR); + ligStart=((uint32_t*)(((char*)ligStart)+stride)); } theS->EndQuickRaster(); for (int i=0;i<4;i++) delete theI[i]; delete theIL; } + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 7c391803e..b6086db27 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -176,13 +176,13 @@ CanvasGrid::~CanvasGrid() -char const * +char const * CanvasGrid::getName(GridType type) { return _(grid_name[type]); } -char const * +char const * CanvasGrid::getSVGName(GridType type) { return grid_svgname[type]; @@ -314,33 +314,26 @@ CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gc static inline void attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int start = 0) { - for (unsigned i=0, r=start; i(*arr[i]), 1, 2, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); + Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); table.attach (const_cast(*arr[i+1]), 2, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); - } - else - { - if (arr[i+1]) + Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); + } else { + if (arr[i+1]) { table.attach (const_cast(*arr[i+1]), 1, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); - else if (arr[i]) - { + Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); + } else if (arr[i]) { Gtk::Label& label = reinterpret_cast (const_cast(*arr[i])); label.set_alignment (0.0); table.attach (label, 0, 3, r, r+1, - Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); - } - else - { + Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); + } else { Gtk::HBox *space = manage (new Gtk::HBox); space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y); table.attach (*space, 0, 1, r, r+1, - (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0); + (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0); } } ++r; @@ -380,7 +373,7 @@ CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPD _("Color of the major (highlighted) grid lines"), "empcolor", "empopacity", _wr, repr, doc); _rsi.init (_("_Major grid line every:"), _("lines"), "empspacing", _wr, repr, doc); - _rcb_dotted.init ( _("_Show dots instead of lines"), + _rcb_dotted.init ( _("_Show dots instead of lines"), _("If set, displays dots at gridpoints instead of gridlines"), "dotted", _wr, false, repr, doc); @@ -484,65 +477,65 @@ static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color) /** If the passed scalar is invalid (<=0), then set the widget and the scalar to use the given old value. - @param oldVal old value to use if the new one is invalid - @param pTarget the scalar to validate - @param widget widget associated with the scalar + + @param oldVal Old value to use if the new one is invalid. + @param pTarget The scalar to validate. + @param widget Widget associated with the scalar. */ static void validateScalar(double oldVal, - double* pTarget, - Inkscape::UI::Widget::RegisteredScalarUnit& widget) + double* pTarget, + Inkscape::UI::Widget::RegisteredScalarUnit& widget) { - // Avoid nullness. - if ( pTarget == NULL ) - return; + // Avoid nullness. + if ( pTarget == NULL ) + return; - // Invalid new value? - if ( *pTarget <= 0 ) - { - // If the old value is somehow invalid as well, then default to 1. - if ( oldVal <= 0 ) - oldVal = 1; + // Invalid new value? + if ( *pTarget <= 0 ) { + // If the old value is somehow invalid as well, then default to 1. + if ( oldVal <= 0 ) + oldVal = 1; - // Reset the scalar and associated widget to the old value. - *pTarget = oldVal; - widget.setValue( *pTarget); - } //if + // Reset the scalar and associated widget to the old value. + *pTarget = oldVal; + widget.setValue( *pTarget); + } //if } //validateScalar /** If the passed int is invalid (<=0), then set the widget and the int to use the given old value. - @param oldVal old value to use if the new one is invalid - @param pTarget the int to validate - @param widget widget associated with the int + + @param oldVal Old value to use if the new one is invalid. + @param pTarget The int to validate. + @param widget Widget associated with the int. */ static void validateInt(gint oldVal, - gint* pTarget, - Inkscape::UI::Widget::RegisteredSuffixedInteger& widget) + gint* pTarget, + Inkscape::UI::Widget::RegisteredSuffixedInteger& widget) { - // Avoid nullness. - if ( pTarget == NULL ) - return; + // Avoid nullness. + if ( pTarget == NULL ) + return; - // Invalid new value? - if ( *pTarget <= 0 ) - { - // If the old value is somehow invalid as well, then default to 1. - if ( oldVal <= 0 ) - oldVal = 1; + // Invalid new value? + if ( *pTarget <= 0 ) { + // If the old value is somehow invalid as well, then default to 1. + if ( oldVal <= 0 ) + oldVal = 1; - // Reset the int and associated widget to the old value. - *pTarget = oldVal; - widget.setValue( *pTarget); - } //if + // Reset the int and associated widget to the old value. + *pTarget = oldVal; + widget.setValue( *pTarget); + } //if } //validateInt void CanvasXYGrid::readRepr() { - char buff[100]; + char buff[100]; gchar const *value; if ( (value = repr->attribute("originx")) ) { sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[NR::X], &gridunit); @@ -555,16 +548,16 @@ CanvasXYGrid::readRepr() } if ( (value = repr->attribute("spacingx")) ) { - double oldVal = spacing[NR::X]; + double oldVal = spacing[NR::X]; sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[NR::X], &gridunit); validateScalar( oldVal, &spacing[NR::X], _rsu_sx ); spacing[NR::X] = sp_units_get_pixels(spacing[NR::X], *(gridunit)); } if ( (value = repr->attribute("spacingy")) ) { - double oldVal = spacing[NR::Y]; + double oldVal = spacing[NR::Y]; sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[NR::Y], &gridunit); - validateScalar( oldVal, &spacing[NR::Y], _rsu_sy ); + validateScalar( oldVal, &spacing[NR::Y], _rsu_sy ); spacing[NR::Y] = sp_units_get_pixels(spacing[NR::Y], *(gridunit)); } @@ -585,7 +578,7 @@ CanvasXYGrid::readRepr() } if ( (value = repr->attribute("empspacing")) ) { - gint oldVal = empspacing; + gint oldVal = empspacing; empspacing = atoi(value); validateInt( oldVal, &empspacing, _rsi ); } @@ -735,7 +728,7 @@ grid_vline (SPCanvasBuf *buf, gint x, gint ys, gint ye, guint32 rgba) static void grid_dot (SPCanvasBuf *buf, gint x, gint y, guint32 rgba) { - if ( (y >= buf->rect.y0) && (y < buf->rect.y1) + if ( (y >= buf->rect.y0) && (y < buf->rect.y1) && (x >= buf->rect.x0) && (x < buf->rect.x1) ) { guint r, g, b, a; guchar *p; @@ -746,7 +739,7 @@ grid_dot (SPCanvasBuf *buf, gint x, gint y, guint32 rgba) p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x - buf->rect.x0) * 3; p[0] = NR_COMPOSEN11_1111 (r, a, p[0]); p[1] = NR_COMPOSEN11_1111 (g, a, p[1]); - p[2] = NR_COMPOSEN11_1111 (b, a, p[2]); + p[2] = NR_COMPOSEN11_1111 (b, a, p[2]); } } @@ -763,14 +756,14 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) gdouble y; for (y = syg, ylinenum = ylinestart; y < buf->rect.y1; y += sw[NR::Y], ylinenum++) { gint const y0 = (gint) Inkscape::round(y); - + if (!scaled[NR::Y] && (ylinenum % empspacing) == 0) { grid_hline (buf, y0, buf->rect.x0, buf->rect.x1 - 1, empcolor); } else { grid_hline (buf, y0, buf->rect.x0, buf->rect.x1 - 1, color); } } - + gint xlinenum; gdouble x; for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[NR::X], xlinenum++) { @@ -791,13 +784,11 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) gdouble x; for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[NR::X], xlinenum++) { gint const ix = (gint) Inkscape::round(x); - if ( (!scaled[NR::X] && (xlinenum % empspacing) == 0) - || (!scaled[NR::Y] && (ylinenum % empspacing) == 0) ) + if ( (!scaled[NR::X] && (xlinenum % empspacing) == 0) + || (!scaled[NR::Y] && (ylinenum % empspacing) == 0) ) { grid_dot (buf, ix, iy, empcolor | (guint32)0x000000FF); // put alpha to max value - } - else - { + } else { grid_dot (buf, ix, iy, color | (guint32)0x000000FF); // put alpha to max value } } @@ -865,6 +856,7 @@ CanvasXYGridSnapper::_getSnapLines(NR::Point const &p) const }; /* namespace Inkscape */ + /* Local Variables: mode:c++ @@ -874,4 +866,4 @@ CanvasXYGridSnapper::_getSnapLines(NR::Point const &p) const fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/curve.cpp b/src/display/curve.cpp index 04af56990..bcf5e92a0 100644 --- a/src/display/curve.cpp +++ b/src/display/curve.cpp @@ -124,21 +124,21 @@ SPCurve *sp_curve_new_from_foreign_bpath(NArtBpath const bpath[]) return curve; } -SPCurve *sp_curve_new_from_rect(NR::Maybe const &rect) +SPCurve *sp_curve_new_from_rect(NR::Maybe const &rect) { - g_return_val_if_fail(rect, NULL); - - SPCurve *c = sp_curve_new(); + g_return_val_if_fail(rect, NULL); - NR::Point p = rect->corner(0); + SPCurve *c = sp_curve_new(); + + NR::Point p = rect->corner(0); sp_curve_moveto(c, p); - + for (int i=3; i>=0; i--) { - sp_curve_lineto(c, rect->corner(i)); + sp_curve_lineto(c, rect->corner(i)); } sp_curve_closepath_current(c); - - return c; + + return c; } /** @@ -158,7 +158,7 @@ sp_curve_ref(SPCurve *curve) /** * Decrease refcount of curve, with possible destruction. - * + * * \todo should this be shared with other refcounting code? */ SPCurve * @@ -249,7 +249,7 @@ sp_curve_concat(GSList const *list) return new_curve; } -/** +/** * Returns a list of new curves corresponding to the subpaths in \a curve. */ GSList * @@ -576,8 +576,8 @@ sp_curve_closepath(SPCurve *curve) curve->closed = true; for (NArtBpath const *bp = curve->_bpath; bp->code != NR_END; bp++) { - /** \todo - * effic: Maintain a count of NR_MOVETO_OPEN's (e.g. instead of + /** \todo + * effic: Maintain a count of NR_MOVETO_OPEN's (e.g. instead of * the closed boolean). */ if (bp->code == NR_MOVETO_OPEN) { @@ -616,8 +616,8 @@ sp_curve_closepath_current(SPCurve *curve) curve->closed = true; for (NArtBpath const *bp = curve->_bpath; bp->code != NR_END; bp++) { - /** \todo - * effic: Maintain a count of NR_MOVETO_OPEN's (e.g. instead of + /** \todo + * effic: Maintain a count of NR_MOVETO_OPEN's (e.g. instead of * the closed boolean). */ if (bp->code == NR_MOVETO_OPEN) { @@ -738,8 +738,8 @@ is_moveto(NRPathcode const c) return c == NR_MOVETO || c == NR_MOVETO_OPEN; } -/** - * Returns \a curve but drawn in the opposite direction. +/** + * Returns \a curve but drawn in the opposite direction. * Should result in the same shape, but * with all its markers drawn facing the other direction. **/ @@ -868,8 +868,8 @@ sp_curve_append_continuous(SPCurve *c0, SPCurve const *c1, gdouble tolerance) && ( fabs( bs->y3 - be->y3 ) <= tolerance ) ) { /** \todo - * fixme: Strictly we mess in case of multisegment mixed - * open/close curves + * fixme: Strictly we mess in case of multisegment mixed + * open/close curves */ bool closed = false; for (bs = bs + 1; bs->code != NR_END; bs++) { @@ -1053,10 +1053,10 @@ static unsigned sp_bpath_length(NArtBpath const bpath[]) * \brief * * \todo - * fixme: this is bogus -- it doesn't check for nr_moveto, which will indicate - * a closing of the subpath it's nonsense to talk about a path as a whole - * being closed, although maybe someone would want that for some other reason? - * Oh, also, if the bpath just ends, then it's *open*. I hope nobody is using + * fixme: this is bogus -- it doesn't check for nr_moveto, which will indicate + * a closing of the subpath it's nonsense to talk about a path as a whole + * being closed, although maybe someone would want that for some other reason? + * Oh, also, if the bpath just ends, then it's *open*. I hope nobody is using * this code for anything. */ static bool sp_bpath_closed(NArtBpath const bpath[]) @@ -1083,7 +1083,7 @@ bezier_len(NR::Point const &c0, double const threshold) { /** \todo - * The SVG spec claims that a closed form exists, but for the moment I'll + * The SVG spec claims that a closed form exists, but for the moment I'll * use a stupid algorithm. */ double const lbound = L2( c3 - c0 ); @@ -1149,8 +1149,8 @@ sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]) return ret; } -/** - * Like sp_curve_distance_including_space(), but ensures that the +/** + * Like sp_curve_distance_including_space(), but ensures that the * result >= 1e-18: uses 1 per segment if necessary. */ static double @@ -1235,4 +1235,4 @@ sp_curve_move_endpoints(SPCurve *curve, NR::Point const &new_p0, fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 41429b408..36f51d3c6 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -33,41 +33,40 @@ GType sp_guideline_get_type() static GType guideline_type = 0; if (!guideline_type) { - static const GTypeInfo guideline_info = - { - sizeof (SPGuideLineClass), - NULL, NULL, - (GClassInitFunc) sp_guideline_class_init, - NULL, NULL, - sizeof (SPGuideLine), - 16, - (GInstanceInitFunc) sp_guideline_init, - NULL, - }; - + static GTypeInfo const guideline_info = { + sizeof (SPGuideLineClass), + NULL, NULL, + (GClassInitFunc) sp_guideline_class_init, + NULL, NULL, + sizeof (SPGuideLine), + 16, + (GInstanceInitFunc) sp_guideline_init, + NULL, + }; + guideline_type = g_type_register_static(SP_TYPE_CANVAS_ITEM, "SPGuideLine", &guideline_info, (GTypeFlags) 0); } - + return guideline_type; } static void sp_guideline_class_init(SPGuideLineClass *c) { - parent_class = (SPCanvasItemClass*) g_type_class_peek_parent(c); + parent_class = (SPCanvasItemClass*) g_type_class_peek_parent(c); - GtkObjectClass *object_class = (GtkObjectClass *) c; - object_class->destroy = sp_guideline_destroy; + GtkObjectClass *object_class = (GtkObjectClass *) c; + object_class->destroy = sp_guideline_destroy; - SPCanvasItemClass *item_class = (SPCanvasItemClass *) c; - item_class->update = sp_guideline_update; - item_class->render = sp_guideline_render; - item_class->point = sp_guideline_point; + SPCanvasItemClass *item_class = (SPCanvasItemClass *) c; + item_class->update = sp_guideline_update; + item_class->render = sp_guideline_render; + item_class->point = sp_guideline_point; } static void sp_guideline_init(SPGuideLine *gl) { gl->rgba = 0x0000ff7f; - + gl->vertical = 0; gl->sensitive = 0; } @@ -80,14 +79,14 @@ static void sp_guideline_destroy(GtkObject *object) static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf) { SPGuideLine const *gl = SP_GUIDELINE (item); - + sp_canvas_prepare_buffer(buf); - + unsigned int const r = NR_RGBA32_R (gl->rgba); unsigned int const g = NR_RGBA32_G (gl->rgba); unsigned int const b = NR_RGBA32_B (gl->rgba); unsigned int const a = NR_RGBA32_A (gl->rgba); - + int p0, p1, step; unsigned char *d; @@ -101,13 +100,13 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf) p1 = buf->rect.y1; step = buf->buf_rowstride; d = buf->buf + 3 * (gl->position - buf->rect.x0); - + } else { - if (gl->position < buf->rect.y0 || gl->position >= buf->rect.y1) { + if (gl->position < buf->rect.y0 || gl->position >= buf->rect.y1) { return; } - + p0 = buf->rect.x0; p1 = buf->rect.x1; step = 3; @@ -170,7 +169,7 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, double position, unsigned void sp_guideline_set_position(SPGuideLine *gl, double position) { - sp_canvas_item_affine_absolute(SP_CANVAS_ITEM (gl), + sp_canvas_item_affine_absolute(SP_CANVAS_ITEM (gl), NR::Matrix(NR::translate(position, position))); } @@ -186,6 +185,7 @@ void sp_guideline_set_sensitive(SPGuideLine *gl, int sensitive) gl->sensitive = sensitive; } + /* Local Variables: mode:c++ @@ -195,4 +195,4 @@ void sp_guideline_set_sensitive(SPGuideLine *gl, int sensitive) fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-arena-glyphs.cpp b/src/display/nr-arena-glyphs.cpp index 243cf6618..bba6f00c8 100644 --- a/src/display/nr-arena-glyphs.cpp +++ b/src/display/nr-arena-glyphs.cpp @@ -239,7 +239,7 @@ nr_arena_glyphs_pick(NRArenaItem *item, NR::Point p, gdouble delta, unsigned int if (!glyphs->font ) return NULL; if (!glyphs->style) return NULL; - + double const x = p[NR::X]; double const y = p[NR::Y]; /* With text we take a simple approach: pick if the point is in a characher bbox */ @@ -255,13 +255,13 @@ nr_arena_glyphs_set_path(NRArenaGlyphs *glyphs, SPCurve *curve, unsigned int lie nr_return_if_fail(NR_IS_ARENA_GLYPHS(glyphs)); nr_arena_item_request_render(NR_ARENA_ITEM(glyphs)); - + if (transform) { glyphs->g_transform = *transform; } else { nr_matrix_set_identity(&glyphs->g_transform); } - + if (font) font->Ref(); if (glyphs->font) glyphs->font->Unref(); glyphs->font=font; @@ -444,11 +444,11 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi if (item->arena->rendermode == RENDERMODE_OUTLINE) { - if (!ct) + if (!ct) return item->state; guint32 rgba = item->arena->outlinecolor; - // FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat + // FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat // by setting color channels in the "wrong" order cairo_set_source_rgba(ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba)); cairo_set_tolerance(ct, 1.25); // low quality, but good enough for outline mode @@ -475,13 +475,13 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi NRPixBlock m; nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE); - // if memory allocation failed, abort + // if memory allocation failed, abort if (m.size != NR_PIXBLOCK_SIZE_TINY && m.data.px == NULL) { nr_pixblock_release (&m); return (item->state); } - m.visible_area = pb->visible_area; + m.visible_area = pb->visible_area; /* Render children fill mask */ for (child = group->children; child != NULL; child = child->next) { @@ -521,7 +521,7 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi guint32 rgba; nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE); - // if memory allocation failed, abort + // if memory allocation failed, abort if (m.size != NR_PIXBLOCK_SIZE_TINY && m.data.px == NULL) { nr_pixblock_release (&m); return (item->state); diff --git a/src/display/nr-arena-group.cpp b/src/display/nr-arena-group.cpp index 912992a6e..fcce681a8 100644 --- a/src/display/nr-arena-group.cpp +++ b/src/display/nr-arena-group.cpp @@ -42,148 +42,148 @@ static NRArenaItemClass *parent_class; NRType nr_arena_group_get_type (void) { - static NRType type = 0; - if (!type) { - type = nr_object_register_type (NR_TYPE_ARENA_ITEM, - "NRArenaGroup", - sizeof (NRArenaGroupClass), - sizeof (NRArenaGroup), - (void (*) (NRObjectClass *)) nr_arena_group_class_init, - (void (*) (NRObject *)) nr_arena_group_init); - } - return type; + static NRType type = 0; + if (!type) { + type = nr_object_register_type (NR_TYPE_ARENA_ITEM, + "NRArenaGroup", + sizeof (NRArenaGroupClass), + sizeof (NRArenaGroup), + (void (*) (NRObjectClass *)) nr_arena_group_class_init, + (void (*) (NRObject *)) nr_arena_group_init); + } + return type; } static void nr_arena_group_class_init (NRArenaGroupClass *klass) { - NRObjectClass *object_class; - NRArenaItemClass *item_class; + NRObjectClass *object_class; + NRArenaItemClass *item_class; - object_class = (NRObjectClass *) klass; - item_class = (NRArenaItemClass *) klass; + object_class = (NRObjectClass *) klass; + item_class = (NRArenaItemClass *) klass; - parent_class = (NRArenaItemClass *) ((NRObjectClass *) klass)->parent; + parent_class = (NRArenaItemClass *) ((NRObjectClass *) klass)->parent; - object_class->cpp_ctor = NRObject::invoke_ctor; + object_class->cpp_ctor = NRObject::invoke_ctor; - item_class->children = nr_arena_group_children; - item_class->last_child = nr_arena_group_last_child; - item_class->add_child = nr_arena_group_add_child; - item_class->set_child_position = nr_arena_group_set_child_position; - item_class->remove_child = nr_arena_group_remove_child; - item_class->update = nr_arena_group_update; - item_class->render = nr_arena_group_render; - item_class->clip = nr_arena_group_clip; - item_class->pick = nr_arena_group_pick; + item_class->children = nr_arena_group_children; + item_class->last_child = nr_arena_group_last_child; + item_class->add_child = nr_arena_group_add_child; + item_class->set_child_position = nr_arena_group_set_child_position; + item_class->remove_child = nr_arena_group_remove_child; + item_class->update = nr_arena_group_update; + item_class->render = nr_arena_group_render; + item_class->clip = nr_arena_group_clip; + item_class->pick = nr_arena_group_pick; } static void nr_arena_group_init (NRArenaGroup *group) { - group->transparent = FALSE; - group->children = NULL; - group->last = NULL; - group->style = NULL; - nr_matrix_set_identity (&group->child_transform); + group->transparent = FALSE; + group->children = NULL; + group->last = NULL; + group->style = NULL; + nr_matrix_set_identity (&group->child_transform); } static NRArenaItem * nr_arena_group_children (NRArenaItem *item) { - NRArenaGroup *group = NR_ARENA_GROUP (item); + NRArenaGroup *group = NR_ARENA_GROUP (item); - return group->children; + return group->children; } static NRArenaItem * nr_arena_group_last_child (NRArenaItem *item) { - NRArenaGroup *group = NR_ARENA_GROUP (item); + NRArenaGroup *group = NR_ARENA_GROUP (item); - return group->last; + return group->last; } static void nr_arena_group_add_child (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref) { - NRArenaGroup *group = NR_ARENA_GROUP (item); + NRArenaGroup *group = NR_ARENA_GROUP (item); - if (!ref) { - group->children = nr_arena_item_attach (item, child, NULL, group->children); - } else { - ref->next = nr_arena_item_attach (item, child, ref, ref->next); - } + if (!ref) { + group->children = nr_arena_item_attach (item, child, NULL, group->children); + } else { + ref->next = nr_arena_item_attach (item, child, ref, ref->next); + } - if (ref == group->last) group->last = child; + if (ref == group->last) group->last = child; - nr_arena_item_request_update (item, NR_ARENA_ITEM_STATE_ALL, FALSE); + nr_arena_item_request_update (item, NR_ARENA_ITEM_STATE_ALL, FALSE); } static void nr_arena_group_remove_child (NRArenaItem *item, NRArenaItem *child) { - NRArenaGroup *group = NR_ARENA_GROUP (item); + NRArenaGroup *group = NR_ARENA_GROUP (item); - if (child == group->last) group->last = child->prev; + if (child == group->last) group->last = child->prev; - if (child->prev) { - nr_arena_item_detach (item, child); - } else { - group->children = nr_arena_item_detach (item, child); - } + if (child->prev) { + nr_arena_item_detach (item, child); + } else { + group->children = nr_arena_item_detach (item, child); + } - nr_arena_item_request_update (item, NR_ARENA_ITEM_STATE_ALL, FALSE); + nr_arena_item_request_update (item, NR_ARENA_ITEM_STATE_ALL, FALSE); } static void nr_arena_group_set_child_position (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref) { - NRArenaGroup *group = NR_ARENA_GROUP (item); + NRArenaGroup *group = NR_ARENA_GROUP (item); - if (child == group->last) group->last = child->prev; + if (child == group->last) group->last = child->prev; - if (child->prev) { - nr_arena_item_detach (item, child); - } else { - group->children = nr_arena_item_detach (item, child); - } + if (child->prev) { + nr_arena_item_detach (item, child); + } else { + group->children = nr_arena_item_detach (item, child); + } - if (!ref) { - group->children = nr_arena_item_attach (item, child, NULL, group->children); - } else { - ref->next = nr_arena_item_attach (item, child, ref, ref->next); - } + if (!ref) { + group->children = nr_arena_item_attach (item, child, NULL, group->children); + } else { + ref->next = nr_arena_item_attach (item, child, ref, ref->next); + } - if (ref == group->last) group->last = child; + if (ref == group->last) group->last = child; - nr_arena_item_request_render (child); + nr_arena_item_request_render (child); } static unsigned int nr_arena_group_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int state, unsigned int reset) { - unsigned int newstate; + unsigned int newstate; - NRArenaGroup *group = NR_ARENA_GROUP (item); + NRArenaGroup *group = NR_ARENA_GROUP (item); - unsigned int beststate = NR_ARENA_ITEM_STATE_ALL; + unsigned int beststate = NR_ARENA_ITEM_STATE_ALL; - for (NRArenaItem *child = group->children; child != NULL; child = child->next) { - NRGC cgc(gc); - nr_matrix_multiply (&cgc.transform, &group->child_transform, &gc->transform); - newstate = nr_arena_item_invoke_update (child, area, &cgc, state, reset); - beststate = beststate & newstate; - } + for (NRArenaItem *child = group->children; child != NULL; child = child->next) { + NRGC cgc(gc); + nr_matrix_multiply (&cgc.transform, &group->child_transform, &gc->transform); + newstate = nr_arena_item_invoke_update (child, area, &cgc, state, reset); + beststate = beststate & newstate; + } - if (beststate & NR_ARENA_ITEM_STATE_BBOX) { - nr_rect_l_set_empty (&item->bbox); - for (NRArenaItem *child = group->children; child != NULL; child = child->next) { - nr_rect_l_union (&item->bbox, &item->bbox, &child->bbox); - } - } + if (beststate & NR_ARENA_ITEM_STATE_BBOX) { + nr_rect_l_set_empty (&item->bbox); + for (NRArenaItem *child = group->children; child != NULL; child = child->next) { + nr_rect_l_union (&item->bbox, &item->bbox, &child->bbox); + } + } - return beststate; + return beststate; } void nr_arena_group_set_style (NRArenaGroup *group, SPStyle *style) @@ -207,7 +207,7 @@ void nr_arena_group_set_style (NRArenaGroup *group, SPStyle *style) delete group->filter; group->filter = NULL; } - + if (style && style->enable_background.set && style->enable_background.value == SP_CSS_BACKGROUND_NEW) { group->background_new = true; @@ -217,75 +217,76 @@ void nr_arena_group_set_style (NRArenaGroup *group, SPStyle *style) static unsigned int nr_arena_group_render (cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags) { - NRArenaGroup *group = NR_ARENA_GROUP (item); + NRArenaGroup *group = NR_ARENA_GROUP (item); - unsigned int ret = item->state; + unsigned int ret = item->state; - /* Just compose children into parent buffer */ - for (NRArenaItem *child = group->children; child != NULL; child = child->next) { - ret = nr_arena_item_invoke_render (ct, child, area, pb, flags); - if (ret & NR_ARENA_ITEM_STATE_INVALID) break; - } + /* Just compose children into parent buffer */ + for (NRArenaItem *child = group->children; child != NULL; child = child->next) { + ret = nr_arena_item_invoke_render (ct, child, area, pb, flags); + if (ret & NR_ARENA_ITEM_STATE_INVALID) break; + } - return ret; + return ret; } static unsigned int nr_arena_group_clip (NRArenaItem *item, NRRectL *area, NRPixBlock *pb) { - NRArenaGroup *group = NR_ARENA_GROUP (item); + NRArenaGroup *group = NR_ARENA_GROUP (item); - unsigned int ret = item->state; + unsigned int ret = item->state; - /* Just compose children into parent buffer */ - for (NRArenaItem *child = group->children; child != NULL; child = child->next) { - ret = nr_arena_item_invoke_clip (child, area, pb); - if (ret & NR_ARENA_ITEM_STATE_INVALID) break; - } + /* Just compose children into parent buffer */ + for (NRArenaItem *child = group->children; child != NULL; child = child->next) { + ret = nr_arena_item_invoke_clip (child, area, pb); + if (ret & NR_ARENA_ITEM_STATE_INVALID) break; + } - return ret; + return ret; } static NRArenaItem * nr_arena_group_pick (NRArenaItem *item, NR::Point p, double delta, unsigned int sticky) { - NRArenaGroup *group = NR_ARENA_GROUP (item); + NRArenaGroup *group = NR_ARENA_GROUP (item); - for (NRArenaItem *child = group->last; child != NULL; child = child->prev) { - NRArenaItem *picked = nr_arena_item_invoke_pick (child, p, delta, sticky); - if (picked) - return (group->transparent) ? picked : item; - } + for (NRArenaItem *child = group->last; child != NULL; child = child->prev) { + NRArenaItem *picked = nr_arena_item_invoke_pick (child, p, delta, sticky); + if (picked) + return (group->transparent) ? picked : item; + } - return NULL; + return NULL; } void nr_arena_group_set_transparent (NRArenaGroup *group, unsigned int transparent) { - nr_return_if_fail (group != NULL); - nr_return_if_fail (NR_IS_ARENA_GROUP (group)); + nr_return_if_fail (group != NULL); + nr_return_if_fail (NR_IS_ARENA_GROUP (group)); - group->transparent = transparent; + group->transparent = transparent; } void nr_arena_group_set_child_transform(NRArenaGroup *group, NR::Matrix const &t) { - NRMatrix nt(t); - nr_arena_group_set_child_transform(group, &nt); + NRMatrix nt(t); + nr_arena_group_set_child_transform(group, &nt); } void nr_arena_group_set_child_transform(NRArenaGroup *group, NRMatrix const *t) { - if (!t) t = &NR_MATRIX_IDENTITY; + if (!t) t = &NR_MATRIX_IDENTITY; - if (!NR_MATRIX_DF_TEST_CLOSE (t, &group->child_transform, NR_EPSILON)) { - nr_arena_item_request_render (NR_ARENA_ITEM (group)); - group->child_transform = *t; - nr_arena_item_request_update (NR_ARENA_ITEM (group), NR_ARENA_ITEM_STATE_ALL, TRUE); - } + if (!NR_MATRIX_DF_TEST_CLOSE (t, &group->child_transform, NR_EPSILON)) { + nr_arena_item_request_render (NR_ARENA_ITEM (group)); + group->child_transform = *t; + nr_arena_item_request_update (NR_ARENA_ITEM (group), NR_ARENA_ITEM_STATE_ALL, TRUE); + } } + /* Local Variables: mode:c++ diff --git a/src/display/nr-arena-group.h b/src/display/nr-arena-group.h index 9da16908d..1b699fd04 100644 --- a/src/display/nr-arena-group.h +++ b/src/display/nr-arena-group.h @@ -23,27 +23,39 @@ NRType nr_arena_group_get_type (void); struct NRArenaGroup : public NRArenaItem{ - unsigned int transparent : 1; - NRArenaItem *children; - NRArenaItem *last; - NRMatrix child_transform; - SPStyle *style; - - static NRArenaGroup *create(NRArena *arena) { - NRArenaGroup *obj=reinterpret_cast(nr_object_new(NR_TYPE_ARENA_GROUP)); - obj->init(arena); - return obj; - } + unsigned int transparent : 1; + NRArenaItem *children; + NRArenaItem *last; + NRMatrix child_transform; + SPStyle *style; + + static NRArenaGroup *create(NRArena *arena) { + NRArenaGroup *obj = reinterpret_cast(nr_object_new(NR_TYPE_ARENA_GROUP)); + obj->init(arena); + return obj; + } }; struct NRArenaGroupClass { - NRArenaItemClass parent_class; + NRArenaItemClass parent_class; }; -void nr_arena_group_set_transparent (NRArenaGroup *group, unsigned int transparent); +void nr_arena_group_set_transparent(NRArenaGroup *group, unsigned int transparent); void nr_arena_group_set_child_transform(NRArenaGroup *group, NR::Matrix const &t); void nr_arena_group_set_child_transform(NRArenaGroup *group, NRMatrix const *t); void nr_arena_group_set_style(NRArenaGroup *group, SPStyle *style); #endif + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-arena-image.cpp b/src/display/nr-arena-image.cpp index 6f3093782..debd9bd0e 100644 --- a/src/display/nr-arena-image.cpp +++ b/src/display/nr-arena-image.cpp @@ -52,123 +52,123 @@ static NRArenaItemClass *parent_class; NRType nr_arena_image_get_type (void) { - static NRType type = 0; - if (!type) { - type = nr_object_register_type (NR_TYPE_ARENA_ITEM, - "NRArenaImage", - sizeof (NRArenaImageClass), - sizeof (NRArenaImage), - (void (*) (NRObjectClass *)) nr_arena_image_class_init, - (void (*) (NRObject *)) nr_arena_image_init); - } - return type; + static NRType type = 0; + if (!type) { + type = nr_object_register_type (NR_TYPE_ARENA_ITEM, + "NRArenaImage", + sizeof (NRArenaImageClass), + sizeof (NRArenaImage), + (void (*) (NRObjectClass *)) nr_arena_image_class_init, + (void (*) (NRObject *)) nr_arena_image_init); + } + return type; } static void nr_arena_image_class_init (NRArenaImageClass *klass) { - NRObjectClass *object_class; - NRArenaItemClass *item_class; + NRObjectClass *object_class; + NRArenaItemClass *item_class; - object_class = (NRObjectClass *) klass; - item_class = (NRArenaItemClass *) klass; + object_class = (NRObjectClass *) klass; + item_class = (NRArenaItemClass *) klass; - parent_class = (NRArenaItemClass *) ((NRObjectClass *) klass)->parent; + parent_class = (NRArenaItemClass *) ((NRObjectClass *) klass)->parent; - object_class->finalize = nr_arena_image_finalize; - object_class->cpp_ctor = NRObject::invoke_ctor; + object_class->finalize = nr_arena_image_finalize; + object_class->cpp_ctor = NRObject::invoke_ctor; - item_class->update = nr_arena_image_update; - item_class->render = nr_arena_image_render; - item_class->pick = nr_arena_image_pick; + item_class->update = nr_arena_image_update; + item_class->render = nr_arena_image_render; + item_class->pick = nr_arena_image_pick; } static void nr_arena_image_init (NRArenaImage *image) { - image->px = NULL; + image->px = NULL; - image->pxw = image->pxh = image->pxrs = 0; - image->x = image->y = 0.0; - image->width = 256.0; - image->height = 256.0; + image->pxw = image->pxh = image->pxrs = 0; + image->x = image->y = 0.0; + image->width = 256.0; + image->height = 256.0; - nr_matrix_set_identity (&image->grid2px); + nr_matrix_set_identity (&image->grid2px); - image->style = 0; + image->style = 0; } static void nr_arena_image_finalize (NRObject *object) { - NRArenaImage *image = NR_ARENA_IMAGE (object); + NRArenaImage *image = NR_ARENA_IMAGE (object); - image->px = NULL; + image->px = NULL; - ((NRObjectClass *) parent_class)->finalize (object); + ((NRObjectClass *) parent_class)->finalize (object); } static unsigned int nr_arena_image_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int state, unsigned int reset) { - NRMatrix grid2px; - - NRArenaImage *image = NR_ARENA_IMAGE (item); - - /* Request render old */ - nr_arena_item_request_render (item); - - /* Copy affine */ - nr_matrix_invert (&grid2px, &gc->transform); - double hscale, vscale; // todo: replace with NR::scale - if (image->px) { - hscale = image->pxw / image->width; - vscale = image->pxh / image->height; - } else { - hscale = 1.0; - vscale = 1.0; - } - - image->grid2px[0] = grid2px.c[0] * hscale; - image->grid2px[2] = grid2px.c[2] * hscale; - image->grid2px[4] = grid2px.c[4] * hscale; - image->grid2px[1] = grid2px.c[1] * vscale; - image->grid2px[3] = grid2px.c[3] * vscale; - image->grid2px[5] = grid2px.c[5] * vscale; - - image->grid2px[4] -= image->x * hscale; - image->grid2px[5] -= image->y * vscale; - - /* Calculate bbox */ - if (image->px) { - NRRect bbox; - - bbox.x0 = image->x; - bbox.y0 = image->y; - bbox.x1 = image->x + image->width; - bbox.y1 = image->y + image->height; - - image->c00 = (NR::Point(bbox.x0, bbox.y0) * gc->transform); - image->c01 = (NR::Point(bbox.x0, bbox.y1) * gc->transform); - image->c10 = (NR::Point(bbox.x1, bbox.y0) * gc->transform); - image->c11 = (NR::Point(bbox.x1, bbox.y1) * gc->transform); - - nr_rect_d_matrix_transform (&bbox, &bbox, &gc->transform); - - item->bbox.x0 = (int) floor (bbox.x0); - item->bbox.y0 = (int) floor (bbox.y0); - item->bbox.x1 = (int) ceil (bbox.x1); - item->bbox.y1 = (int) ceil (bbox.y1); - } else { - item->bbox.x0 = (int) gc->transform[4]; - item->bbox.y0 = (int) gc->transform[5]; - item->bbox.x1 = item->bbox.x0 - 1; - item->bbox.y1 = item->bbox.y0 - 1; - } - - nr_arena_item_request_render (item); - - return NR_ARENA_ITEM_STATE_ALL; + NRMatrix grid2px; + + NRArenaImage *image = NR_ARENA_IMAGE (item); + + /* Request render old */ + nr_arena_item_request_render (item); + + /* Copy affine */ + nr_matrix_invert (&grid2px, &gc->transform); + double hscale, vscale; // todo: replace with NR::scale + if (image->px) { + hscale = image->pxw / image->width; + vscale = image->pxh / image->height; + } else { + hscale = 1.0; + vscale = 1.0; + } + + image->grid2px[0] = grid2px.c[0] * hscale; + image->grid2px[2] = grid2px.c[2] * hscale; + image->grid2px[4] = grid2px.c[4] * hscale; + image->grid2px[1] = grid2px.c[1] * vscale; + image->grid2px[3] = grid2px.c[3] * vscale; + image->grid2px[5] = grid2px.c[5] * vscale; + + image->grid2px[4] -= image->x * hscale; + image->grid2px[5] -= image->y * vscale; + + /* Calculate bbox */ + if (image->px) { + NRRect bbox; + + bbox.x0 = image->x; + bbox.y0 = image->y; + bbox.x1 = image->x + image->width; + bbox.y1 = image->y + image->height; + + image->c00 = (NR::Point(bbox.x0, bbox.y0) * gc->transform); + image->c01 = (NR::Point(bbox.x0, bbox.y1) * gc->transform); + image->c10 = (NR::Point(bbox.x1, bbox.y0) * gc->transform); + image->c11 = (NR::Point(bbox.x1, bbox.y1) * gc->transform); + + nr_rect_d_matrix_transform (&bbox, &bbox, &gc->transform); + + item->bbox.x0 = (int) floor (bbox.x0); + item->bbox.y0 = (int) floor (bbox.y0); + item->bbox.x1 = (int) ceil (bbox.x1); + item->bbox.y1 = (int) ceil (bbox.y1); + } else { + item->bbox.x0 = (int) gc->transform[4]; + item->bbox.y0 = (int) gc->transform[5]; + item->bbox.x1 = item->bbox.x0 - 1; + item->bbox.y1 = item->bbox.y0 - 1; + } + + nr_arena_item_request_render (item); + + return NR_ARENA_ITEM_STATE_ALL; } #define FBITS 12 @@ -177,156 +177,156 @@ nr_arena_image_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int static unsigned int nr_arena_image_render (cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags) { - nr_arena_image_x_sample = prefs_get_int_attribute ("options.bitmapoversample", "value", 1); - nr_arena_image_y_sample = nr_arena_image_x_sample; + nr_arena_image_x_sample = prefs_get_int_attribute ("options.bitmapoversample", "value", 1); + nr_arena_image_y_sample = nr_arena_image_x_sample; - bool outline = (item->arena->rendermode == RENDERMODE_OUTLINE); + bool outline = (item->arena->rendermode == RENDERMODE_OUTLINE); - NRArenaImage *image = NR_ARENA_IMAGE (item); + NRArenaImage *image = NR_ARENA_IMAGE (item); - NR::Matrix d2s; + NR::Matrix d2s; - d2s[0] = b2i[0]; - d2s[1] = b2i[1]; - d2s[2] = b2i[2]; - d2s[3] = b2i[3]; - d2s[4] = b2i[0] * pb->area.x0 + b2i[2] * pb->area.y0 + b2i[4]; - d2s[5] = b2i[1] * pb->area.x0 + b2i[3] * pb->area.y0 + b2i[5]; + d2s[0] = b2i[0]; + d2s[1] = b2i[1]; + d2s[2] = b2i[2]; + d2s[3] = b2i[3]; + d2s[4] = b2i[0] * pb->area.x0 + b2i[2] * pb->area.y0 + b2i[4]; + d2s[5] = b2i[1] * pb->area.x0 + b2i[3] * pb->area.y0 + b2i[5]; - if (!outline) { + if (!outline) { - if (!image->px) return item->state; + if (!image->px) return item->state; - guint32 Falpha = item->opacity; - if (Falpha < 1) return item->state; + guint32 Falpha = item->opacity; + if (Falpha < 1) return item->state; - unsigned char * dpx = NR_PIXBLOCK_PX (pb); - int const drs = pb->rs; - int const dw = pb->area.x1 - pb->area.x0; - int const dh = pb->area.y1 - pb->area.y0; + unsigned char * dpx = NR_PIXBLOCK_PX (pb); + int const drs = pb->rs; + int const dw = pb->area.x1 - pb->area.x0; + int const dh = pb->area.y1 - pb->area.y0; - unsigned char * spx = image->px; - int const srs = image->pxrs; - int const sw = image->pxw; - int const sh = image->pxh; + unsigned char * spx = image->px; + int const srs = image->pxrs; + int const sw = image->pxw; + int const sh = image->pxh; - if (pb->mode == NR_PIXBLOCK_MODE_R8G8B8) { - /* fixme: This is not implemented yet (Lauris) */ - /* nr_R8G8B8_R8G8B8_R8G8B8A8_N_TRANSFORM (dpx, dw, dh, drs, spx, sw, sh, srs, d2s, Falpha, nr_arena_image_x_sample, nr_arena_image_y_sample); */ - } else if (pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM (dpx, dw, dh, drs, spx, sw, sh, srs, d2s, Falpha, nr_arena_image_x_sample, nr_arena_image_y_sample); - } else if (pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8N) { + if (pb->mode == NR_PIXBLOCK_MODE_R8G8B8) { + /* fixme: This is not implemented yet (Lauris) */ + /* nr_R8G8B8_R8G8B8_R8G8B8A8_N_TRANSFORM (dpx, dw, dh, drs, spx, sw, sh, srs, d2s, Falpha, nr_arena_image_x_sample, nr_arena_image_y_sample); */ + } else if (pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8P) { + nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM (dpx, dw, dh, drs, spx, sw, sh, srs, d2s, Falpha, nr_arena_image_x_sample, nr_arena_image_y_sample); + } else if (pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8N) { - //FIXME: The _N_N_N_ version gives a gray border around images, see bug 906376 - // This mode is only used when exporting, screen rendering always has _P_P_P_, so I decided to simply replace it for now - // Feel free to propose a better fix + //FIXME: The _N_N_N_ version gives a gray border around images, see bug 906376 + // This mode is only used when exporting, screen rendering always has _P_P_P_, so I decided to simply replace it for now + // Feel free to propose a better fix - //nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_TRANSFORM (dpx, dw, dh, drs, spx, sw, sh, srs, d2s, Falpha, nr_arena_image_x_sample, nr_arena_image_y_sample); - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM (dpx, dw, dh, drs, spx, sw, sh, srs, d2s, Falpha, nr_arena_image_x_sample, nr_arena_image_y_sample); - } + //nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_TRANSFORM (dpx, dw, dh, drs, spx, sw, sh, srs, d2s, Falpha, nr_arena_image_x_sample, nr_arena_image_y_sample); + nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM (dpx, dw, dh, drs, spx, sw, sh, srs, d2s, Falpha, nr_arena_image_x_sample, nr_arena_image_y_sample); + } - pb->empty = FALSE; + pb->empty = FALSE; - } else { // outline; draw a rect instead + } else { // outline; draw a rect instead - if (!ct) - return item->state; + if (!ct) + return item->state; - guint32 rgba = prefs_get_int_attribute("options.wireframecolors", "images", 0xff0000ff); - // FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat - // by setting color channels in the "wrong" order - cairo_set_source_rgba(ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba)); + guint32 rgba = prefs_get_int_attribute("options.wireframecolors", "images", 0xff0000ff); + // FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat + // by setting color channels in the "wrong" order + cairo_set_source_rgba(ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba)); - cairo_set_line_width(ct, 0.5); - cairo_new_path(ct); + cairo_set_line_width(ct, 0.5); + cairo_new_path(ct); - NR::Point shift(pb->area.x0, pb->area.y0); - NR::Point c00 = image->c00 - shift; - NR::Point c01 = image->c01 - shift; - NR::Point c11 = image->c11 - shift; - NR::Point c10 = image->c10 - shift; + NR::Point shift(pb->area.x0, pb->area.y0); + NR::Point c00 = image->c00 - shift; + NR::Point c01 = image->c01 - shift; + NR::Point c11 = image->c11 - shift; + NR::Point c10 = image->c10 - shift; - cairo_move_to (ct, c00[NR::X], c00[NR::Y]); + cairo_move_to (ct, c00[NR::X], c00[NR::Y]); - // the box - cairo_line_to (ct, c10[NR::X], c10[NR::Y]); - cairo_line_to (ct, c11[NR::X], c11[NR::Y]); - cairo_line_to (ct, c01[NR::X], c01[NR::Y]); - cairo_line_to (ct, c00[NR::X], c00[NR::Y]); - // the diagonals - cairo_line_to (ct, c11[NR::X], c11[NR::Y]); - cairo_move_to (ct, c10[NR::X], c10[NR::Y]); - cairo_line_to (ct, c01[NR::X], c01[NR::Y]); + // the box + cairo_line_to (ct, c10[NR::X], c10[NR::Y]); + cairo_line_to (ct, c11[NR::X], c11[NR::Y]); + cairo_line_to (ct, c01[NR::X], c01[NR::Y]); + cairo_line_to (ct, c00[NR::X], c00[NR::Y]); + // the diagonals + cairo_line_to (ct, c11[NR::X], c11[NR::Y]); + cairo_move_to (ct, c10[NR::X], c10[NR::Y]); + cairo_line_to (ct, c01[NR::X], c01[NR::Y]); - cairo_stroke(ct); + cairo_stroke(ct); - pb->empty = FALSE; - } + pb->empty = FALSE; + } - return item->state; + return item->state; } /** Calculates the closest distance from p to the segment a1-a2*/ -double +double distance_to_segment (NR::Point p, NR::Point a1, NR::Point a2) { - // calculate sides of the triangle and their squares - double d1 = NR::L2(p - a1); - double d1_2 = d1 * d1; - double d2 = NR::L2(p - a2); - double d2_2 = d2 * d2; - double a = NR::L2(a1 - a2); - double a_2 = a * a; - - // if one of the angles at the base is > 90, return the corresponding side - if (d1_2 + a_2 <= d2_2) return d1; - if (d2_2 + a_2 <= d1_2) return d2; - - // otherwise calculate the height to the base - double peri = (a + d1 + d2)/2; - return (2*sqrt(peri * (peri - a) * (peri - d1) * (peri - d2))/a); + // calculate sides of the triangle and their squares + double d1 = NR::L2(p - a1); + double d1_2 = d1 * d1; + double d2 = NR::L2(p - a2); + double d2_2 = d2 * d2; + double a = NR::L2(a1 - a2); + double a_2 = a * a; + + // if one of the angles at the base is > 90, return the corresponding side + if (d1_2 + a_2 <= d2_2) return d1; + if (d2_2 + a_2 <= d1_2) return d2; + + // otherwise calculate the height to the base + double peri = (a + d1 + d2)/2; + return (2*sqrt(peri * (peri - a) * (peri - d1) * (peri - d2))/a); } static NRArenaItem * nr_arena_image_pick (NRArenaItem *item, NR::Point p, double delta, unsigned int sticky) { - NRArenaImage *image = NR_ARENA_IMAGE (item); + NRArenaImage *image = NR_ARENA_IMAGE (item); - if (!image->px) return NULL; + if (!image->px) return NULL; - bool outline = (item->arena->rendermode == RENDERMODE_OUTLINE); + bool outline = (item->arena->rendermode == RENDERMODE_OUTLINE); - if (outline) { + if (outline) { - // frame - if (distance_to_segment (p, image->c00, image->c10) < delta) return item; - if (distance_to_segment (p, image->c10, image->c11) < delta) return item; - if (distance_to_segment (p, image->c11, image->c01) < delta) return item; - if (distance_to_segment (p, image->c01, image->c00) < delta) return item; + // frame + if (distance_to_segment (p, image->c00, image->c10) < delta) return item; + if (distance_to_segment (p, image->c10, image->c11) < delta) return item; + if (distance_to_segment (p, image->c11, image->c01) < delta) return item; + if (distance_to_segment (p, image->c01, image->c00) < delta) return item; - // diagonals - if (distance_to_segment (p, image->c00, image->c11) < delta) return item; - if (distance_to_segment (p, image->c10, image->c01) < delta) return item; + // diagonals + if (distance_to_segment (p, image->c00, image->c11) < delta) return item; + if (distance_to_segment (p, image->c10, image->c01) < delta) return item; - return NULL; + return NULL; - } else { + } else { - unsigned char *const pixels = image->px; - int const width = image->pxw; - int const height = image->pxh; - int const rowstride = image->pxrs; - NR::Point tp = p * image->grid2px; - int const ix = (int)(tp[NR::X]); - int const iy = (int)(tp[NR::Y]); + unsigned char *const pixels = image->px; + int const width = image->pxw; + int const height = image->pxh; + int const rowstride = image->pxrs; + NR::Point tp = p * image->grid2px; + int const ix = (int)(tp[NR::X]); + int const iy = (int)(tp[NR::Y]); - if ((ix < 0) || (iy < 0) || (ix >= width) || (iy >= height)) - return NULL; + if ((ix < 0) || (iy < 0) || (ix >= width) || (iy >= height)) + return NULL; - unsigned char *pix_ptr = pixels + iy * rowstride + ix * 4; - // is the alpha not transparent? - return (pix_ptr[3] > 0) ? item : NULL; - } + unsigned char *pix_ptr = pixels + iy * rowstride + ix * 4; + // is the alpha not transparent? + return (pix_ptr[3] > 0) ? item : NULL; + } } /* Utility */ @@ -334,29 +334,29 @@ nr_arena_image_pick (NRArenaItem *item, NR::Point p, double delta, unsigned int void nr_arena_image_set_pixels (NRArenaImage *image, unsigned char const *px, unsigned int pxw, unsigned int pxh, unsigned int pxrs) { - nr_return_if_fail (image != NULL); - nr_return_if_fail (NR_IS_ARENA_IMAGE (image)); + nr_return_if_fail (image != NULL); + nr_return_if_fail (NR_IS_ARENA_IMAGE (image)); - image->px = (unsigned char *) px; - image->pxw = pxw; - image->pxh = pxh; - image->pxrs = pxrs; + image->px = (unsigned char *) px; + image->pxw = pxw; + image->pxh = pxh; + image->pxrs = pxrs; - nr_arena_item_request_update (NR_ARENA_ITEM (image), NR_ARENA_ITEM_STATE_ALL, FALSE); + nr_arena_item_request_update (NR_ARENA_ITEM (image), NR_ARENA_ITEM_STATE_ALL, FALSE); } void nr_arena_image_set_geometry (NRArenaImage *image, double x, double y, double width, double height) { - nr_return_if_fail (image != NULL); - nr_return_if_fail (NR_IS_ARENA_IMAGE (image)); + nr_return_if_fail (image != NULL); + nr_return_if_fail (NR_IS_ARENA_IMAGE (image)); - image->x = x; - image->y = y; - image->width = width; - image->height = height; + image->x = x; + image->y = y; + image->width = width; + image->height = height; - nr_arena_item_request_update (NR_ARENA_ITEM (image), NR_ARENA_ITEM_STATE_ALL, FALSE); + nr_arena_item_request_update (NR_ARENA_ITEM (image), NR_ARENA_ITEM_STATE_ALL, FALSE); } void nr_arena_image_set_style (NRArenaImage *image, SPStyle *style) @@ -387,6 +387,7 @@ void nr_arena_image_set_style (NRArenaImage *image, SPStyle *style) } } + /* Local Variables: mode:c++ diff --git a/src/display/nr-arena-image.h b/src/display/nr-arena-image.h index f9861b2ff..2d7328263 100644 --- a/src/display/nr-arena-image.h +++ b/src/display/nr-arena-image.h @@ -24,34 +24,46 @@ NRType nr_arena_image_get_type (void); struct NRArenaImage : public NRArenaItem { - unsigned char *px; - unsigned int pxw; - unsigned int pxh; - unsigned int pxrs; + unsigned char *px; + unsigned int pxw; + unsigned int pxh; + unsigned int pxrs; - double x, y; - double width, height; + double x, y; + double width, height; - NR::Point c00, c01, c11, c10; // all 4 corners of the image, for outline mode rect + NR::Point c00, c01, c11, c10; // all 4 corners of the image, for outline mode rect - /* From GRID to PIXELS */ - NR::Matrix grid2px; + /* From GRID to PIXELS */ + NR::Matrix grid2px; - SPStyle *style; + SPStyle *style; - static NRArenaImage *create(NRArena *arena) { - NRArenaImage *obj=reinterpret_cast(nr_object_new(NR_TYPE_ARENA_IMAGE)); - obj->init(arena); - return obj; - } + static NRArenaImage *create(NRArena *arena) { + NRArenaImage *obj=reinterpret_cast(nr_object_new(NR_TYPE_ARENA_IMAGE)); + obj->init(arena); + return obj; + } }; struct NRArenaImageClass { - NRArenaItemClass parent_class; + NRArenaItemClass parent_class; }; void nr_arena_image_set_pixels (NRArenaImage *image, unsigned char const *px, unsigned int pxw, unsigned int pxh, unsigned int pxrs); void nr_arena_image_set_geometry (NRArenaImage *image, double x, double y, double width, double height); void nr_arena_image_set_style (NRArenaImage *image, SPStyle *style); + #endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-arena-item.h b/src/display/nr-arena-item.h index 801657cf3..6ca1564a1 100644 --- a/src/display/nr-arena-item.h +++ b/src/display/nr-arena-item.h @@ -62,73 +62,73 @@ #include struct NRGC { - NRGC(NRGC const *p) : parent(p) {} - NRGC const *parent; - NRMatrix transform; + NRGC(NRGC const *p) : parent(p) {} + NRGC const *parent; + NRMatrix transform; }; struct NRArenaItem : public NRObject { - NRArena *arena; - Inkscape::GC::soft_ptr parent; - NRArenaItem *next; - Inkscape::GC::soft_ptr prev; - - /* Item state */ - unsigned int state : 16; - unsigned int propagate : 1; - unsigned int sensitive : 1; - unsigned int visible : 1; - /* Whether items renders opacity itself */ - unsigned int render_opacity : 1; - /* Opacity itself */ - unsigned int opacity : 8; - - /* Key for secondary rendering */ - unsigned int key; - - /* BBox in grid coordinates */ - NRRectL bbox; - /* BBox in item coordinates - this should be a bounding box as - * specified in SVG standard. Required by filters. */ - NR::Maybe item_bbox; - /* Our affine */ - NRMatrix *transform; - /* Clip item */ - NRArenaItem *clip; - /* Mask item */ - NRArenaItem *mask; - /* Filter to be applied after rendering this object, NULL if none */ - NR::Filter *filter; - /* Rendered buffer */ - unsigned char *px; - - /* Single data member */ - void *data; - - /* Current Transformation Matrix */ - NR::Matrix ctm; - - /* These hold background buffer state for filter rendering */ - NRPixBlock *background_pb; - bool background_new; - - void init(NRArena *arena) { - this->arena = arena; - } + NRArena *arena; + Inkscape::GC::soft_ptr parent; + NRArenaItem *next; + Inkscape::GC::soft_ptr prev; + + /* Item state */ + unsigned int state : 16; + unsigned int propagate : 1; + unsigned int sensitive : 1; + unsigned int visible : 1; + /* Whether items renders opacity itself */ + unsigned int render_opacity : 1; + /* Opacity itself */ + unsigned int opacity : 8; + + /* Key for secondary rendering */ + unsigned int key; + + /* BBox in grid coordinates */ + NRRectL bbox; + /* BBox in item coordinates - this should be a bounding box as + * specified in SVG standard. Required by filters. */ + NR::Maybe item_bbox; + /* Our affine */ + NRMatrix *transform; + /* Clip item */ + NRArenaItem *clip; + /* Mask item */ + NRArenaItem *mask; + /* Filter to be applied after rendering this object, NULL if none */ + NR::Filter *filter; + /* Rendered buffer */ + unsigned char *px; + + /* Single data member */ + void *data; + + /* Current Transformation Matrix */ + NR::Matrix ctm; + + /* These hold background buffer state for filter rendering */ + NRPixBlock *background_pb; + bool background_new; + + void init(NRArena *arena) { + this->arena = arena; + } }; struct NRArenaItemClass : public NRObjectClass { - NRArenaItem * (* children) (NRArenaItem *item); - NRArenaItem * (* last_child) (NRArenaItem *item); - void (* add_child) (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref); - void (* remove_child) (NRArenaItem *item, NRArenaItem *child); - void (* set_child_position) (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref); - - unsigned int (* update) (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int state, unsigned int reset); - unsigned int (* render) (cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags); - unsigned int (* clip) (NRArenaItem *item, NRRectL *area, NRPixBlock *pb); - NRArenaItem * (* pick) (NRArenaItem *item, NR::Point p, double delta, unsigned int sticky); + NRArenaItem * (* children) (NRArenaItem *item); + NRArenaItem * (* last_child) (NRArenaItem *item); + void (* add_child) (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref); + void (* remove_child) (NRArenaItem *item, NRArenaItem *child); + void (* set_child_position) (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref); + + unsigned int (* update) (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int state, unsigned int reset); + unsigned int (* render) (cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags); + unsigned int (* clip) (NRArenaItem *item, NRRectL *area, NRPixBlock *pb); + NRArenaItem * (* pick) (NRArenaItem *item, NR::Point p, double delta, unsigned int sticky); }; #define NR_ARENA_ITEM_ARENA(ai) (((NRArenaItem *) (ai))->arena) @@ -192,4 +192,16 @@ NRArenaItem *nr_arena_item_detach (NRArenaItem *parent, NRArenaItem *child); #define NR_ARENA_ITEM_SET_KEY(i,k) (((NRArenaItem *) (i))->key = (k)) #define NR_ARENA_ITEM_GET_KEY(i) (((NRArenaItem *) (i))->key) -#endif + +#endif /* !__NR_ARENA_ITEM_H__ */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-arena-shape.h b/src/display/nr-arena-shape.h index c3ff59b39..d36815a74 100644 --- a/src/display/nr-arena-shape.h +++ b/src/display/nr-arena-shape.h @@ -30,189 +30,201 @@ NRType nr_arena_shape_get_type (void); struct NRArenaShape : public NRArenaItem { - class Paint { - public: - enum Type { - NONE, - COLOR, - SERVER - }; - - Paint() : _type(NONE), _color(0), _server(NULL) {} - Paint(Paint const &p) { _assign(p); } - ~Paint() { clear(); } - - Type type() const { return _type; } - SPPaintServer *server() const { return _server; } - SPColor const &color() const { return _color; } - - Paint &operator=(Paint const &p) { - set(p); - return *this; - } - - void set(Paint const &p) { - clear(); - _assign(p); - } - void set(SPColor const &color) { - clear(); - _type = COLOR; - _color = color; - } - void set(SPPaintServer *server) { - clear(); - if (server) { - _type = SERVER; - _server = server; - sp_object_ref(_server, NULL); - } - } - void clear() { - if ( _type == SERVER ) { - sp_object_unref(_server, NULL); - _server = NULL; - } - _type = NONE; - } - - private: - Type _type; - SPColor _color; - SPPaintServer *_server; - - void _assign(Paint const &p) { - _type = p._type; - _server = p._server; - _color = p._color; - if (_server) { - sp_object_ref(_server, NULL); - } - } - }; - - enum FillRule { - EVEN_ODD, - NONZERO - }; - - enum CapType { - ROUND_CAP, - SQUARE_CAP, - BUTT_CAP - }; - - enum JoinType { - ROUND_JOIN, - BEVEL_JOIN, - MITRE_JOIN - }; - - /* Shape data */ - SPCurve *curve; - SPStyle *style; - NRRect paintbox; - /* State data */ - NR::Matrix ctm; - - SPPainter *fill_painter; - SPPainter *stroke_painter; - // the 2 cached polygons, for rasterizations uses - Shape *fill_shp; - Shape *stroke_shp; - // the stroke width of stroke_shp, to detect when it changes (on normal/outline switching) and rebuild - float cached_width; - // delayed_shp=true means the *_shp polygons are not computed yet - // they'll be computed on demand in *_render(), *_pick() or *_clip() - // the goal is to not uncross polygons that are outside the viewing region - bool delayed_shp; - // approximate bounding box, for the case when the polygons have been delayed - NRRectL approx_bbox; - // cache for transformations: cached_fill and cached_stroke are - // polygons computed for the cached_fctm and cache_sctm respectively - // when the transformation changes interactively (tracked by the - // SP_OBJECT_USER_MODIFIED_FLAG_B), we check if it's an isometry wrt - // the cached ctm. if it's an isometry, just apply it to the cached - // polygon to get the *_shp polygon. Otherwise, recompute so this - // works fine for translation and rotation, but not scaling and - // skewing - NR::Matrix cached_fctm; - NR::Matrix cached_sctm; - NRRectL cached_farea; - NRRectL cached_sarea; - bool cached_fpartialy; - bool cached_spartialy; - - Shape *cached_fill; - Shape *cached_stroke; - /* Markers */ - NRArenaItem *markers; - - NRArenaItem *last_pick; - guint repick_after; - - static NRArenaShape *create(NRArena *arena) { - NRArenaShape *obj=reinterpret_cast(nr_object_new(NR_TYPE_ARENA_SHAPE)); - obj->init(arena); - return obj; - } - - void setFill(SPPaintServer *server); - void setFill(SPColor const &color); - void setFillOpacity(double opacity); - void setFillRule(FillRule rule); - - void setStroke(SPPaintServer *server); - void setStroke(SPColor const &color); - void setStrokeOpacity(double opacity); - void setStrokeWidth(double width); - void setLineCap(CapType cap); - void setLineJoin(JoinType join); - void setMitreLimit(double limit); - - void setPaintBox(NR::Rect const &pbox); - - void _invalidateCachedFill() { - if (cached_fill) { - delete cached_fill; - cached_fill = NULL; - } - } - void _invalidateCachedStroke() { - if (cached_stroke) { - delete cached_stroke; - cached_stroke = NULL; - } - } - - struct Style { - Style() : opacity(0.0) {} - Paint paint; - double opacity; - }; - struct FillStyle : public Style { - FillStyle() : rule(EVEN_ODD) {} - FillRule rule; - } _fill; - struct StrokeStyle : public Style { - StrokeStyle() - : cap(ROUND_CAP), join(ROUND_JOIN), - width(0.0), mitre_limit(0.0) - {} - - CapType cap; - JoinType join; - double width; - double mitre_limit; - } _stroke; + class Paint { + public: + enum Type { + NONE, + COLOR, + SERVER + }; + + Paint() : _type(NONE), _color(0), _server(NULL) {} + Paint(Paint const &p) { _assign(p); } + ~Paint() { clear(); } + + Type type() const { return _type; } + SPPaintServer *server() const { return _server; } + SPColor const &color() const { return _color; } + + Paint &operator=(Paint const &p) { + set(p); + return *this; + } + + void set(Paint const &p) { + clear(); + _assign(p); + } + void set(SPColor const &color) { + clear(); + _type = COLOR; + _color = color; + } + void set(SPPaintServer *server) { + clear(); + if (server) { + _type = SERVER; + _server = server; + sp_object_ref(_server, NULL); + } + } + void clear() { + if ( _type == SERVER ) { + sp_object_unref(_server, NULL); + _server = NULL; + } + _type = NONE; + } + + private: + Type _type; + SPColor _color; + SPPaintServer *_server; + + void _assign(Paint const &p) { + _type = p._type; + _server = p._server; + _color = p._color; + if (_server) { + sp_object_ref(_server, NULL); + } + } + }; + + enum FillRule { + EVEN_ODD, + NONZERO + }; + + enum CapType { + ROUND_CAP, + SQUARE_CAP, + BUTT_CAP + }; + + enum JoinType { + ROUND_JOIN, + BEVEL_JOIN, + MITRE_JOIN + }; + + /* Shape data */ + SPCurve *curve; + SPStyle *style; + NRRect paintbox; + /* State data */ + NR::Matrix ctm; + + SPPainter *fill_painter; + SPPainter *stroke_painter; + // the 2 cached polygons, for rasterizations uses + Shape *fill_shp; + Shape *stroke_shp; + // the stroke width of stroke_shp, to detect when it changes (on normal/outline switching) and rebuild + float cached_width; + // delayed_shp=true means the *_shp polygons are not computed yet + // they'll be computed on demand in *_render(), *_pick() or *_clip() + // the goal is to not uncross polygons that are outside the viewing region + bool delayed_shp; + // approximate bounding box, for the case when the polygons have been delayed + NRRectL approx_bbox; + // cache for transformations: cached_fill and cached_stroke are + // polygons computed for the cached_fctm and cache_sctm respectively + // when the transformation changes interactively (tracked by the + // SP_OBJECT_USER_MODIFIED_FLAG_B), we check if it's an isometry wrt + // the cached ctm. if it's an isometry, just apply it to the cached + // polygon to get the *_shp polygon. Otherwise, recompute so this + // works fine for translation and rotation, but not scaling and + // skewing + NR::Matrix cached_fctm; + NR::Matrix cached_sctm; + NRRectL cached_farea; + NRRectL cached_sarea; + bool cached_fpartialy; + bool cached_spartialy; + + Shape *cached_fill; + Shape *cached_stroke; + /* Markers */ + NRArenaItem *markers; + + NRArenaItem *last_pick; + guint repick_after; + + static NRArenaShape *create(NRArena *arena) { + NRArenaShape *obj=reinterpret_cast(nr_object_new(NR_TYPE_ARENA_SHAPE)); + obj->init(arena); + return obj; + } + + void setFill(SPPaintServer *server); + void setFill(SPColor const &color); + void setFillOpacity(double opacity); + void setFillRule(FillRule rule); + + void setStroke(SPPaintServer *server); + void setStroke(SPColor const &color); + void setStrokeOpacity(double opacity); + void setStrokeWidth(double width); + void setLineCap(CapType cap); + void setLineJoin(JoinType join); + void setMitreLimit(double limit); + + void setPaintBox(NR::Rect const &pbox); + + void _invalidateCachedFill() { + if (cached_fill) { + delete cached_fill; + cached_fill = NULL; + } + } + void _invalidateCachedStroke() { + if (cached_stroke) { + delete cached_stroke; + cached_stroke = NULL; + } + } + + struct Style { + Style() : opacity(0.0) {} + Paint paint; + double opacity; + }; + struct FillStyle : public Style { + FillStyle() : rule(EVEN_ODD) {} + FillRule rule; + } _fill; + struct StrokeStyle : public Style { + StrokeStyle() + : cap(ROUND_CAP), join(ROUND_JOIN), + width(0.0), mitre_limit(0.0) + {} + + CapType cap; + JoinType join; + double width; + double mitre_limit; + } _stroke; }; struct NRArenaShapeClass { - NRArenaItemClass parent_class; + NRArenaItemClass parent_class; }; void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve, bool justTrans); void nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style); void nr_arena_shape_set_paintbox(NRArenaShape *shape, NRRect const *pbox); -#endif + +#endif /* !__NR_ARENA_SHAPE_H__ */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-arena.cpp b/src/display/nr-arena.cpp index 7c0664d16..f125cd0f8 100644 --- a/src/display/nr-arena.cpp +++ b/src/display/nr-arena.cpp @@ -25,116 +25,128 @@ static NRActiveObjectClass *parent_class; NRType nr_arena_get_type (void) { - static NRType type = 0; - if (!type) { - type = nr_object_register_type (NR_TYPE_ACTIVE_OBJECT, - "NRArena", - sizeof (NRArenaClass), - sizeof (NRArena), - (void (*) (NRObjectClass *)) nr_arena_class_init, - (void (*) (NRObject *)) nr_arena_init); - } - return type; + static NRType type = 0; + if (!type) { + type = nr_object_register_type (NR_TYPE_ACTIVE_OBJECT, + "NRArena", + sizeof (NRArenaClass), + sizeof (NRArena), + (void (*) (NRObjectClass *)) nr_arena_class_init, + (void (*) (NRObject *)) nr_arena_init); + } + return type; } static void nr_arena_class_init (NRArenaClass *klass) { - NRObjectClass *object_class = (NRObjectClass *) klass; + NRObjectClass *object_class = (NRObjectClass *) klass; - parent_class = (NRActiveObjectClass *) (((NRObjectClass *) klass)->parent); + parent_class = (NRActiveObjectClass *) (((NRObjectClass *) klass)->parent); - object_class->finalize = nr_arena_finalize; - object_class->cpp_ctor = NRObject::invoke_ctor; + object_class->finalize = nr_arena_finalize; + object_class->cpp_ctor = NRObject::invoke_ctor; } static void nr_arena_init (NRArena *arena) { - arena->delta = 0; // to be set by desktop from prefs - arena->rendermode = RENDERMODE_NORMAL; // default is normal render - arena->outlinecolor = 0xff; // black; to be set by desktop from bg color - arena->canvasarena = NULL; + arena->delta = 0; // to be set by desktop from prefs + arena->rendermode = RENDERMODE_NORMAL; // default is normal render + arena->outlinecolor = 0xff; // black; to be set by desktop from bg color + arena->canvasarena = NULL; } static void nr_arena_finalize (NRObject *object) { - ((NRObjectClass *) (parent_class))->finalize (object); + ((NRObjectClass *) (parent_class))->finalize (object); } void nr_arena_request_update (NRArena *arena, NRArenaItem *item) { - NRActiveObject *aobject = (NRActiveObject *) arena; - - nr_return_if_fail (arena != NULL); - nr_return_if_fail (NR_IS_ARENA (arena)); - nr_return_if_fail (item != NULL); - nr_return_if_fail (NR_IS_ARENA_ITEM (item)); - - if (aobject->callbacks) { - for (unsigned int i = 0; i < aobject->callbacks->length; i++) { - NRObjectListener *listener = aobject->callbacks->listeners + i; - NRArenaEventVector *avector = (NRArenaEventVector *) listener->vector; - if ((listener->size >= sizeof (NRArenaEventVector)) && avector->request_update) { - avector->request_update (arena, item, listener->data); - } - } - } + NRActiveObject *aobject = (NRActiveObject *) arena; + + nr_return_if_fail (arena != NULL); + nr_return_if_fail (NR_IS_ARENA (arena)); + nr_return_if_fail (item != NULL); + nr_return_if_fail (NR_IS_ARENA_ITEM (item)); + + if (aobject->callbacks) { + for (unsigned int i = 0; i < aobject->callbacks->length; i++) { + NRObjectListener *listener = aobject->callbacks->listeners + i; + NRArenaEventVector *avector = (NRArenaEventVector *) listener->vector; + if ((listener->size >= sizeof (NRArenaEventVector)) && avector->request_update) { + avector->request_update (arena, item, listener->data); + } + } + } } void nr_arena_request_render_rect (NRArena *arena, NRRectL *area) { - NRActiveObject *aobject = (NRActiveObject *) arena; - - nr_return_if_fail (arena != NULL); - nr_return_if_fail (NR_IS_ARENA (arena)); - nr_return_if_fail (area != NULL); - - if (aobject->callbacks && area && !nr_rect_l_test_empty (area)) { - for (unsigned int i = 0; i < aobject->callbacks->length; i++) { - NRObjectListener *listener = aobject->callbacks->listeners + i; - NRArenaEventVector *avector = (NRArenaEventVector *) listener->vector; - if ((listener->size >= sizeof (NRArenaEventVector)) && avector->request_render) { - avector->request_render (arena, area, listener->data); - } - } - } + NRActiveObject *aobject = (NRActiveObject *) arena; + + nr_return_if_fail (arena != NULL); + nr_return_if_fail (NR_IS_ARENA (arena)); + nr_return_if_fail (area != NULL); + + if (aobject->callbacks && area && !nr_rect_l_test_empty (area)) { + for (unsigned int i = 0; i < aobject->callbacks->length; i++) { + NRObjectListener *listener = aobject->callbacks->listeners + i; + NRArenaEventVector *avector = (NRArenaEventVector *) listener->vector; + if ((listener->size >= sizeof (NRArenaEventVector)) && avector->request_render) { + avector->request_render (arena, area, listener->data); + } + } + } } -void +void nr_arena_render_paintserver_fill (NRPixBlock *pb, NRRectL *area, SPPainter *painter, float opacity, NRPixBlock *mask) { - NRPixBlock cb, cb_opa; - nr_pixblock_setup_fast (&cb, NR_PIXBLOCK_MODE_R8G8B8A8N, area->x0, area->y0, area->x1, area->y1, TRUE); - nr_pixblock_setup_fast (&cb_opa, NR_PIXBLOCK_MODE_R8G8B8A8N, area->x0, area->y0, area->x1, area->y1, TRUE); - - // if memory allocation failed, abort - if ((cb.size != NR_PIXBLOCK_SIZE_TINY && cb.data.px == NULL) || (cb_opa.size != NR_PIXBLOCK_SIZE_TINY && cb_opa.data.px == NULL)) { - return; - } - - cb.visible_area = pb->visible_area; - cb_opa.visible_area = pb->visible_area; - - /* Need separate gradient buffer (lauris)*/ - // do the filling - painter->fill (painter, &cb); - cb.empty = FALSE; - - // do the fill-opacity and mask composite - if (opacity < 1.0) { - nr_blit_pixblock_pixblock_alpha (&cb_opa, &cb, (int) floor (255 * opacity)); - cb_opa.empty = FALSE; - nr_blit_pixblock_pixblock_mask (pb, &cb_opa, mask); - } else { - nr_blit_pixblock_pixblock_mask (pb, &cb, mask); - } + NRPixBlock cb, cb_opa; + nr_pixblock_setup_fast (&cb, NR_PIXBLOCK_MODE_R8G8B8A8N, area->x0, area->y0, area->x1, area->y1, TRUE); + nr_pixblock_setup_fast (&cb_opa, NR_PIXBLOCK_MODE_R8G8B8A8N, area->x0, area->y0, area->x1, area->y1, TRUE); + + // if memory allocation failed, abort + if ((cb.size != NR_PIXBLOCK_SIZE_TINY && cb.data.px == NULL) || (cb_opa.size != NR_PIXBLOCK_SIZE_TINY && cb_opa.data.px == NULL)) { + return; + } + + cb.visible_area = pb->visible_area; + cb_opa.visible_area = pb->visible_area; + + /* Need separate gradient buffer (lauris)*/ + // do the filling + painter->fill (painter, &cb); + cb.empty = FALSE; + + // do the fill-opacity and mask composite + if (opacity < 1.0) { + nr_blit_pixblock_pixblock_alpha (&cb_opa, &cb, (int) floor (255 * opacity)); + cb_opa.empty = FALSE; + nr_blit_pixblock_pixblock_mask (pb, &cb_opa, mask); + } else { + nr_blit_pixblock_pixblock_mask (pb, &cb, mask); + } + + pb->empty = FALSE; + + nr_pixblock_release (&cb); + nr_pixblock_release (&cb_opa); +} - pb->empty = FALSE; - nr_pixblock_release (&cb); - nr_pixblock_release (&cb_opa); -} +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-filter-gaussian.cpp b/src/display/nr-filter-gaussian.cpp index 5d79b1c3e..fb94a654b 100644 --- a/src/display/nr-filter-gaussian.cpp +++ b/src/display/nr-filter-gaussian.cpp @@ -38,7 +38,7 @@ // Using the backwards-pass initialization procedure from: // Boundary Conditions for Young - van Vliet Recursive Filtering // Bill Triggs, Michael Sdika -// IEEE Transactions on Signal Processing, Volume 54, Number 5 - may 2006 +// IEEE Transactions on Signal Processing, Volume 54, Number 5 - may 2006 // Number of IIR filter coefficients used. Currently only 3 is supported. // "Recursive Gaussian Derivative Filters" says this is enough though (and @@ -52,7 +52,7 @@ void copy_n(InIt beg_in, Size N, OutIt beg_out) { } // Type used for IIR filter coefficients (can be 10.21 signed fixed point, see Anisotropic Gaussian Filtering Using Fixed Point Arithmetic, Christoph H. Lampert & Oliver Wirjadi, 2006) -typedef double IIRValue; +typedef double IIRValue; // Type used for FIR filter coefficients (can be 16.16 unsigned fixed point, should have 8 or more bits in the fractional part, the integer part should be capable of storing approximately 20*255) typedef Inkscape::Util::FixedPoint FIRValue; @@ -67,15 +67,15 @@ template static inline T clip(T const& v, T const& a, T const& b) { template static inline Tt round_cast(Ts const& v) { - static Ts const rndoffset(.5); - return static_cast(v+rndoffset); + static Ts const rndoffset(.5); + return static_cast(v+rndoffset); } template static inline Tt clip_round_cast(Ts const& v, Tt const minval=std::numeric_limits::min(), Tt const maxval=std::numeric_limits::max()) { if ( v < minval ) return minval; if ( v > maxval ) return maxval; - return round_cast(v); + return round_cast(v); } namespace NR { @@ -398,8 +398,8 @@ filter2D_FIR(PT *const dst, int const dstr1, int const dstr2, // store the result in bufx dst[dst_disp + byte] = round_cast(sum); - // optimization: if there was no variation within this point's neighborhood, - // skip ahead while we keep seeing the same last_in byte: + // optimization: if there was no variation within this point's neighborhood, + // skip ahead while we keep seeing the same last_in byte: // blurring flat color would not change it anyway if (different_count <= 1) { int pos = c1 + 1; diff --git a/src/display/sodipodi-ctrl.cpp b/src/display/sodipodi-ctrl.cpp index fd655edb0..0172cc8bb 100644 --- a/src/display/sodipodi-ctrl.cpp +++ b/src/display/sodipodi-ctrl.cpp @@ -13,16 +13,16 @@ #include "sodipodi-ctrl.h" enum { - ARG_0, - ARG_SHAPE, - ARG_MODE, - ARG_ANCHOR, - ARG_SIZE, - ARG_FILLED, - ARG_FILL_COLOR, - ARG_STROKED, - ARG_STROKE_COLOR, - ARG_PIXBUF + ARG_0, + ARG_SHAPE, + ARG_MODE, + ARG_ANCHOR, + ARG_SIZE, + ARG_FILLED, + ARG_FILL_COLOR, + ARG_STROKED, + ARG_STROKE_COLOR, + ARG_PIXBUF }; @@ -42,396 +42,442 @@ static SPCanvasItemClass *parent_class; GtkType sp_ctrl_get_type (void) { - static GtkType ctrl_type = 0; - if (!ctrl_type) { - static GTypeInfo const ctrl_info = { - sizeof (SPCtrlClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_ctrl_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (SPCtrl), - 0, /* n_preallocs */ - (GInstanceInitFunc) sp_ctrl_init, - NULL - }; - ctrl_type = g_type_register_static (SP_TYPE_CANVAS_ITEM, "SPCtrl", &ctrl_info, (GTypeFlags)0); - } - return ctrl_type; + static GtkType ctrl_type = 0; + if (!ctrl_type) { + static GTypeInfo const ctrl_info = { + sizeof (SPCtrlClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) sp_ctrl_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (SPCtrl), + 0, /* n_preallocs */ + (GInstanceInitFunc) sp_ctrl_init, + NULL + }; + ctrl_type = g_type_register_static (SP_TYPE_CANVAS_ITEM, "SPCtrl", &ctrl_info, (GTypeFlags)0); + } + return ctrl_type; } static void sp_ctrl_class_init (SPCtrlClass *klass) { - GtkObjectClass *object_class; - SPCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) klass; - item_class = (SPCanvasItemClass *) klass; - - parent_class = (SPCanvasItemClass *)gtk_type_class (sp_canvas_item_get_type ()); - - gtk_object_add_arg_type ("SPCtrl::shape", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_SHAPE); - gtk_object_add_arg_type ("SPCtrl::mode", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MODE); - gtk_object_add_arg_type ("SPCtrl::anchor", GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); - gtk_object_add_arg_type ("SPCtrl::size", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_SIZE); - gtk_object_add_arg_type ("SPCtrl::pixbuf", GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_PIXBUF); - gtk_object_add_arg_type ("SPCtrl::filled", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_FILLED); - gtk_object_add_arg_type ("SPCtrl::fill_color", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("SPCtrl::stroked", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_STROKED); - gtk_object_add_arg_type ("SPCtrl::stroke_color", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_STROKE_COLOR); - - object_class->destroy = sp_ctrl_destroy; - object_class->set_arg = sp_ctrl_set_arg; - - item_class->update = sp_ctrl_update; - item_class->render = sp_ctrl_render; - item_class->point = sp_ctrl_point; + GtkObjectClass *object_class; + SPCanvasItemClass *item_class; + + object_class = (GtkObjectClass *) klass; + item_class = (SPCanvasItemClass *) klass; + + parent_class = (SPCanvasItemClass *)gtk_type_class (sp_canvas_item_get_type ()); + + gtk_object_add_arg_type ("SPCtrl::shape", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_SHAPE); + gtk_object_add_arg_type ("SPCtrl::mode", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MODE); + gtk_object_add_arg_type ("SPCtrl::anchor", GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); + gtk_object_add_arg_type ("SPCtrl::size", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_SIZE); + gtk_object_add_arg_type ("SPCtrl::pixbuf", GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_PIXBUF); + gtk_object_add_arg_type ("SPCtrl::filled", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_FILLED); + gtk_object_add_arg_type ("SPCtrl::fill_color", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_FILL_COLOR); + gtk_object_add_arg_type ("SPCtrl::stroked", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_STROKED); + gtk_object_add_arg_type ("SPCtrl::stroke_color", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_STROKE_COLOR); + + object_class->destroy = sp_ctrl_destroy; + object_class->set_arg = sp_ctrl_set_arg; + + item_class->update = sp_ctrl_update; + item_class->render = sp_ctrl_render; + item_class->point = sp_ctrl_point; } static void sp_ctrl_init (SPCtrl *ctrl) { - ctrl->shape = SP_CTRL_SHAPE_SQUARE; - ctrl->mode = SP_CTRL_MODE_COLOR; - ctrl->anchor = GTK_ANCHOR_CENTER; - ctrl->span = 3; - ctrl->defined = TRUE; - ctrl->shown = FALSE; - ctrl->build = FALSE; - ctrl->filled = 1; - ctrl->stroked = 0; - ctrl->fill_color = 0x000000ff; - ctrl->stroke_color = 0x000000ff; - ctrl->_moved = false; - - ctrl->box.x0 = ctrl->box.y0 = ctrl->box.x1 = ctrl->box.y1 = 0; - ctrl->cache = NULL; - ctrl->pixbuf = NULL; + ctrl->shape = SP_CTRL_SHAPE_SQUARE; + ctrl->mode = SP_CTRL_MODE_COLOR; + ctrl->anchor = GTK_ANCHOR_CENTER; + ctrl->span = 3; + ctrl->defined = TRUE; + ctrl->shown = FALSE; + ctrl->build = FALSE; + ctrl->filled = 1; + ctrl->stroked = 0; + ctrl->fill_color = 0x000000ff; + ctrl->stroke_color = 0x000000ff; + ctrl->_moved = false; + + ctrl->box.x0 = ctrl->box.y0 = ctrl->box.x1 = ctrl->box.y1 = 0; + ctrl->cache = NULL; + ctrl->pixbuf = NULL; } static void sp_ctrl_destroy (GtkObject *object) { - SPCtrl *ctrl; + SPCtrl *ctrl; - g_return_if_fail (object != NULL); - g_return_if_fail (SP_IS_CTRL (object)); + g_return_if_fail (object != NULL); + g_return_if_fail (SP_IS_CTRL (object)); - ctrl = SP_CTRL (object); + ctrl = SP_CTRL (object); - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); + if (GTK_OBJECT_CLASS (parent_class)->destroy) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } static void sp_ctrl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) { - SPCanvasItem *item; - SPCtrl *ctrl; - GdkPixbuf * pixbuf = NULL; - - item = SP_CANVAS_ITEM (object); - ctrl = SP_CTRL (object); - - switch (arg_id) { - case ARG_SHAPE: - ctrl->shape = (SPCtrlShapeType)(GTK_VALUE_INT (*arg)); - ctrl->build = FALSE; - sp_canvas_item_request_update (item); - break; - case ARG_MODE: - ctrl->mode = (SPCtrlModeType)(GTK_VALUE_INT (*arg)); - ctrl->build = FALSE; - sp_canvas_item_request_update (item); - break; - case ARG_ANCHOR: - ctrl->anchor = (GtkAnchorType)(GTK_VALUE_INT (*arg)); - ctrl->build = FALSE; - sp_canvas_item_request_update (item); - break; - case ARG_SIZE: - ctrl->span = (gint) ((GTK_VALUE_DOUBLE (*arg) - 1.0) / 2.0 + 0.5); - ctrl->defined = (ctrl->span > 0); - ctrl->build = FALSE; - sp_canvas_item_request_update (item); - break; - case ARG_FILLED: - ctrl->filled = GTK_VALUE_BOOL (*arg); - ctrl->build = FALSE; - sp_canvas_item_request_update (item); - break; - case ARG_FILL_COLOR: - ctrl->fill_color = GTK_VALUE_INT (*arg); - ctrl->build = FALSE; - sp_canvas_item_request_update (item); - break; - case ARG_STROKED: - ctrl->stroked = GTK_VALUE_BOOL (*arg); - ctrl->build = FALSE; - sp_canvas_item_request_update (item); - break; - case ARG_STROKE_COLOR: - ctrl->stroke_color = GTK_VALUE_INT (*arg); - ctrl->build = FALSE; - sp_canvas_item_request_update (item); - break; - case ARG_PIXBUF: - pixbuf = (GdkPixbuf*)(GTK_VALUE_POINTER (*arg)); - if (gdk_pixbuf_get_has_alpha (pixbuf)) { - ctrl->pixbuf = pixbuf; - } else { - ctrl->pixbuf = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0); - gdk_pixbuf_unref (pixbuf); - } - ctrl->build = FALSE; - break; - default: - break; - } + SPCanvasItem *item; + SPCtrl *ctrl; + GdkPixbuf * pixbuf = NULL; + + item = SP_CANVAS_ITEM (object); + ctrl = SP_CTRL (object); + + switch (arg_id) { + case ARG_SHAPE: + ctrl->shape = (SPCtrlShapeType)(GTK_VALUE_INT (*arg)); + ctrl->build = FALSE; + sp_canvas_item_request_update (item); + break; + + case ARG_MODE: + ctrl->mode = (SPCtrlModeType)(GTK_VALUE_INT (*arg)); + ctrl->build = FALSE; + sp_canvas_item_request_update (item); + break; + + case ARG_ANCHOR: + ctrl->anchor = (GtkAnchorType)(GTK_VALUE_INT (*arg)); + ctrl->build = FALSE; + sp_canvas_item_request_update (item); + break; + + case ARG_SIZE: + ctrl->span = (gint) ((GTK_VALUE_DOUBLE (*arg) - 1.0) / 2.0 + 0.5); + ctrl->defined = (ctrl->span > 0); + ctrl->build = FALSE; + sp_canvas_item_request_update (item); + break; + + case ARG_FILLED: + ctrl->filled = GTK_VALUE_BOOL (*arg); + ctrl->build = FALSE; + sp_canvas_item_request_update (item); + break; + + case ARG_FILL_COLOR: + ctrl->fill_color = GTK_VALUE_INT (*arg); + ctrl->build = FALSE; + sp_canvas_item_request_update (item); + break; + + case ARG_STROKED: + ctrl->stroked = GTK_VALUE_BOOL (*arg); + ctrl->build = FALSE; + sp_canvas_item_request_update (item); + break; + + case ARG_STROKE_COLOR: + ctrl->stroke_color = GTK_VALUE_INT (*arg); + ctrl->build = FALSE; + sp_canvas_item_request_update (item); + break; + + case ARG_PIXBUF: + pixbuf = (GdkPixbuf*)(GTK_VALUE_POINTER (*arg)); + if (gdk_pixbuf_get_has_alpha (pixbuf)) { + ctrl->pixbuf = pixbuf; + } else { + ctrl->pixbuf = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0); + gdk_pixbuf_unref (pixbuf); + } + ctrl->build = FALSE; + break; + + default: + break; + } } static void sp_ctrl_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags) { - SPCtrl *ctrl; - gint x, y; - - ctrl = SP_CTRL (item); - - if (((SPCanvasItemClass *) parent_class)->update) - (* ((SPCanvasItemClass *) parent_class)->update) (item, affine, flags); - - sp_canvas_item_reset_bounds (item); - - if (!ctrl->_moved) return; - - if (ctrl->shown) { - sp_canvas_request_redraw (item->canvas, ctrl->box.x0, ctrl->box.y0, ctrl->box.x1 + 1, ctrl->box.y1 + 1); - } - - if (!ctrl->defined) return; - - x = (gint) ((affine[4] > 0) ? (affine[4] + 0.5) : (affine[4] - 0.5)) - ctrl->span; - y = (gint) ((affine[5] > 0) ? (affine[5] + 0.5) : (affine[5] - 0.5)) - ctrl->span; - - switch (ctrl->anchor) { - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - break; - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - x += ctrl->span; - break; - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= (ctrl->span + 1); - break; - } - - switch (ctrl->anchor) { - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - break; - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - y += ctrl->span; - break; - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= (ctrl->span + 1); - break; - } - - ctrl->box.x0 = x; - ctrl->box.y0 = y; - ctrl->box.x1 = ctrl->box.x0 + 2 * ctrl->span; - ctrl->box.y1 = ctrl->box.y0 + 2 * ctrl->span; - - sp_canvas_update_bbox (item, ctrl->box.x0, ctrl->box.y0, ctrl->box.x1 + 1, ctrl->box.y1 + 1); - + SPCtrl *ctrl; + gint x, y; + + ctrl = SP_CTRL (item); + + if (((SPCanvasItemClass *) parent_class)->update) + (* ((SPCanvasItemClass *) parent_class)->update) (item, affine, flags); + + sp_canvas_item_reset_bounds (item); + + if (!ctrl->_moved) return; + + if (ctrl->shown) { + sp_canvas_request_redraw (item->canvas, ctrl->box.x0, ctrl->box.y0, ctrl->box.x1 + 1, ctrl->box.y1 + 1); + } + + if (!ctrl->defined) return; + + x = (gint) ((affine[4] > 0) ? (affine[4] + 0.5) : (affine[4] - 0.5)) - ctrl->span; + y = (gint) ((affine[5] > 0) ? (affine[5] + 0.5) : (affine[5] - 0.5)) - ctrl->span; + + switch (ctrl->anchor) { + case GTK_ANCHOR_N: + case GTK_ANCHOR_CENTER: + case GTK_ANCHOR_S: + break; + + case GTK_ANCHOR_NW: + case GTK_ANCHOR_W: + case GTK_ANCHOR_SW: + x += ctrl->span; + break; + + case GTK_ANCHOR_NE: + case GTK_ANCHOR_E: + case GTK_ANCHOR_SE: + x -= (ctrl->span + 1); + break; + } + + switch (ctrl->anchor) { + case GTK_ANCHOR_W: + case GTK_ANCHOR_CENTER: + case GTK_ANCHOR_E: + break; + + case GTK_ANCHOR_NW: + case GTK_ANCHOR_N: + case GTK_ANCHOR_NE: + y += ctrl->span; + break; + + case GTK_ANCHOR_SW: + case GTK_ANCHOR_S: + case GTK_ANCHOR_SE: + y -= (ctrl->span + 1); + break; + } + + ctrl->box.x0 = x; + ctrl->box.y0 = y; + ctrl->box.x1 = ctrl->box.x0 + 2 * ctrl->span; + ctrl->box.y1 = ctrl->box.y0 + 2 * ctrl->span; + + sp_canvas_update_bbox (item, ctrl->box.x0, ctrl->box.y0, ctrl->box.x1 + 1, ctrl->box.y1 + 1); } static double sp_ctrl_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item) { - SPCtrl *ctrl = SP_CTRL (item); + SPCtrl *ctrl = SP_CTRL (item); + + *actual_item = item; - *actual_item = item; - - double const x = p[NR::X]; - double const y = p[NR::Y]; - - if ((x >= ctrl->box.x0) && (x <= ctrl->box.x1) && (y >= ctrl->box.y0) && (y <= ctrl->box.y1)) return 0.0; + double const x = p[NR::X]; + double const y = p[NR::Y]; - return 1e18; + if ((x >= ctrl->box.x0) && (x <= ctrl->box.x1) && (y >= ctrl->box.y0) && (y <= ctrl->box.y1)) return 0.0; + + return 1e18; } static void sp_ctrl_build_cache (SPCtrl *ctrl) { - guchar * p, *q; - gint size, x, y, z, s, a, side, c; - guint8 fr, fg, fb, fa, sr, sg, sb, sa; - - if (ctrl->filled) { - fr = (ctrl->fill_color >> 24) & 0xff; - fg = (ctrl->fill_color >> 16) & 0xff; - fb = (ctrl->fill_color >> 8) & 0xff; - fa = (ctrl->fill_color) & 0xff; - } else { fr = 0x00; fg = 0x00; fb = 0x00; fa = 0x00; } - if (ctrl->stroked) { - sr = (ctrl->stroke_color >> 24) & 0xff; - sg = (ctrl->stroke_color >> 16) & 0xff; - sb = (ctrl->stroke_color >> 8) & 0xff; - sa = (ctrl->stroke_color) & 0xff; - } else { sr = fr; sg = fg; sb = fb; sa = fa; } - - - side = (ctrl->span * 2 +1); - c = ctrl->span ; - g_free (ctrl->cache); - size = (side) * (side) * 4; - ctrl->cache = (guchar*)g_malloc (size); - if (side < 2) return; - - switch (ctrl->shape) { - case SP_CTRL_SHAPE_SQUARE: - p = ctrl->cache; - for (x=0; x < side; x++) { *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; } - for (y = 2; y < side; y++) { - *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; - for (x=2; x < side; x++) { *p++ = fr; *p++ = fg; *p++ = fb; *p++ = fa; } - *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; - } - for (x=0; x < side; x++) { *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; } - ctrl->build = TRUE; - break; - case SP_CTRL_SHAPE_DIAMOND: - p = ctrl->cache; - for (y = 0; y < side; y++) { - z = abs (c - y); - for (x = 0; x < z; x++) {*p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00;} - *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; x++; - for (; x < side - z -1; x++) { *p++ = fr; *p++ = fg; *p++ = fb; *p++ = fa; } - if (z != c) {*p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; x++;} - for (; x < side; x++) {*p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00;} - } - break; - case SP_CTRL_SHAPE_CIRCLE: - p = ctrl->cache; - q = p + size -1; - s = -1; - for (y = 0; y <= c ; y++) { - a = abs (c - y); - z = (gint)(0.0 + sqrt ((c+.4)*(c+.4) - a*a)); - x = 0; - while (x < c-z) { - *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; - *q-- = 0x00; *q-- = 0x00; *q-- = 0x00; *q-- = 0x00; - x++; - } - do { - *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; - *q-- = sa; *q-- = sb; *q-- = sg; *q-- = sr; - x++; - } while (x < c-s); - while (x < MIN(c+s+1, c+z)) { - *p++ = fr; *p++ = fg; *p++ = fb; *p++ = fa; - *q-- = fa; *q-- = fb; *q-- = fg; *q-- = fr; - x++; - } - do { - *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; - *q-- = sa; *q-- = sb; *q-- = sg; *q-- = sr; - x++; - } while (x <= c+z); - while (x < side) { - *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; - *q-- = 0x00; *q-- = 0x00; *q-- = 0x00; *q-- = 0x00; - x++; - } - s = z; - } - ctrl->build = TRUE; - break; - case SP_CTRL_SHAPE_CROSS: - p = ctrl->cache; - for (y = 0; y < side; y++) { - z = abs (c - y); - for (x = 0; x < c-z; x++) {*p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00;} - *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; x++; - for (; x < c + z; x++) {*p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00;} - if (z != 0) {*p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; x++;} - for (; x < side; x++) {*p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00;} - } - ctrl->build = TRUE; - break; - case SP_CTRL_SHAPE_BITMAP: - if (ctrl->pixbuf) { - unsigned char *px; - unsigned int rs; - px = gdk_pixbuf_get_pixels (ctrl->pixbuf); - rs = gdk_pixbuf_get_rowstride (ctrl->pixbuf); - for (y = 0; y < side; y++){ - unsigned char *s, *d; - s = px + y * rs; - d = ctrl->cache + 4 * side * y; - for (x = 0; x < side; x++) { - if (s[3] < 0x80) { - d[0] = 0x00; - d[1] = 0x00; - d[2] = 0x00; - d[3] = 0x00; - } else if (s[0] < 0x80) { - d[0] = sr; - d[1] = sg; - d[2] = sb; - d[3] = sa; - } else { - d[0] = fr; - d[1] = fg; - d[2] = fb; - d[3] = fa; - } - s += 4; - d += 4; - } - } - } else { - g_print ("control has no pixmap\n"); - } - ctrl->build = TRUE; - break; - case SP_CTRL_SHAPE_IMAGE: - if (ctrl->pixbuf) { - guint r = gdk_pixbuf_get_rowstride (ctrl->pixbuf); - guchar * pix; - q = gdk_pixbuf_get_pixels (ctrl->pixbuf); - p = ctrl->cache; - for (y = 0; y < side; y++){ - pix = q + (y * r); - for (x = 0; x < side; x++) { - *p++ = *pix++; - *p++ = *pix++; - *p++ = *pix++; - *p++ = *pix++; - } - } - } else { g_print ("control has no pixmap\n"); } - ctrl->build = TRUE; - break; - default: - break; - } - + guchar * p, *q; + gint size, x, y, z, s, a, side, c; + guint8 fr, fg, fb, fa, sr, sg, sb, sa; + + if (ctrl->filled) { + fr = (ctrl->fill_color >> 24) & 0xff; + fg = (ctrl->fill_color >> 16) & 0xff; + fb = (ctrl->fill_color >> 8) & 0xff; + fa = (ctrl->fill_color) & 0xff; + } else { + fr = 0x00; fg = 0x00; fb = 0x00; fa = 0x00; + } + if (ctrl->stroked) { + sr = (ctrl->stroke_color >> 24) & 0xff; + sg = (ctrl->stroke_color >> 16) & 0xff; + sb = (ctrl->stroke_color >> 8) & 0xff; + sa = (ctrl->stroke_color) & 0xff; + } else { + sr = fr; sg = fg; sb = fb; sa = fa; + } + + + side = (ctrl->span * 2 +1); + c = ctrl->span ; + g_free (ctrl->cache); + size = (side) * (side) * 4; + ctrl->cache = (guchar*)g_malloc (size); + if (side < 2) return; + + switch (ctrl->shape) { + case SP_CTRL_SHAPE_SQUARE: + p = ctrl->cache; + for (x=0; x < side; x++) { + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; + } + for (y = 2; y < side; y++) { + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; + for (x=2; x < side; x++) { + *p++ = fr; *p++ = fg; *p++ = fb; *p++ = fa; + } + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; + } + for (x=0; x < side; x++) { + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; + } + ctrl->build = TRUE; + break; + + case SP_CTRL_SHAPE_DIAMOND: + p = ctrl->cache; + for (y = 0; y < side; y++) { + z = abs (c - y); + for (x = 0; x < z; x++) { + *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; + } + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; x++; + for (; x < side - z -1; x++) { + *p++ = fr; *p++ = fg; *p++ = fb; *p++ = fa; + } + if (z != c) { + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; x++; + } + for (; x < side; x++) { + *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; + } + } + break; + + case SP_CTRL_SHAPE_CIRCLE: + p = ctrl->cache; + q = p + size -1; + s = -1; + for (y = 0; y <= c ; y++) { + a = abs (c - y); + z = (gint)(0.0 + sqrt ((c+.4)*(c+.4) - a*a)); + x = 0; + while (x < c-z) { + *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; + *q-- = 0x00; *q-- = 0x00; *q-- = 0x00; *q-- = 0x00; + x++; + } + do { + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; + *q-- = sa; *q-- = sb; *q-- = sg; *q-- = sr; + x++; + } while (x < c-s); + while (x < MIN(c+s+1, c+z)) { + *p++ = fr; *p++ = fg; *p++ = fb; *p++ = fa; + *q-- = fa; *q-- = fb; *q-- = fg; *q-- = fr; + x++; + } + do { + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; + *q-- = sa; *q-- = sb; *q-- = sg; *q-- = sr; + x++; + } while (x <= c+z); + while (x < side) { + *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; + *q-- = 0x00; *q-- = 0x00; *q-- = 0x00; *q-- = 0x00; + x++; + } + s = z; + } + ctrl->build = TRUE; + break; + + case SP_CTRL_SHAPE_CROSS: + p = ctrl->cache; + for (y = 0; y < side; y++) { + z = abs (c - y); + for (x = 0; x < c-z; x++) { + *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; + } + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; x++; + for (; x < c + z; x++) { + *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; + } + if (z != 0) { + *p++ = sr; *p++ = sg; *p++ = sb; *p++ = sa; x++; + } + for (; x < side; x++) { + *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; + } + } + ctrl->build = TRUE; + break; + + case SP_CTRL_SHAPE_BITMAP: + if (ctrl->pixbuf) { + unsigned char *px; + unsigned int rs; + px = gdk_pixbuf_get_pixels (ctrl->pixbuf); + rs = gdk_pixbuf_get_rowstride (ctrl->pixbuf); + for (y = 0; y < side; y++){ + unsigned char *s, *d; + s = px + y * rs; + d = ctrl->cache + 4 * side * y; + for (x = 0; x < side; x++) { + if (s[3] < 0x80) { + d[0] = 0x00; + d[1] = 0x00; + d[2] = 0x00; + d[3] = 0x00; + } else if (s[0] < 0x80) { + d[0] = sr; + d[1] = sg; + d[2] = sb; + d[3] = sa; + } else { + d[0] = fr; + d[1] = fg; + d[2] = fb; + d[3] = fa; + } + s += 4; + d += 4; + } + } + } else { + g_print ("control has no pixmap\n"); + } + ctrl->build = TRUE; + break; + + case SP_CTRL_SHAPE_IMAGE: + if (ctrl->pixbuf) { + guint r = gdk_pixbuf_get_rowstride (ctrl->pixbuf); + guchar * pix; + q = gdk_pixbuf_get_pixels (ctrl->pixbuf); + p = ctrl->cache; + for (y = 0; y < side; y++){ + pix = q + (y * r); + for (x = 0; x < side; x++) { + *p++ = *pix++; + *p++ = *pix++; + *p++ = *pix++; + *p++ = *pix++; + } + } + } else { + g_print ("control has no pixmap\n"); + } + ctrl->build = TRUE; + break; + + default: + break; + } + } // composite background, foreground, alpha for xor mode @@ -442,57 +488,71 @@ sp_ctrl_build_cache (SPCtrl *ctrl) static void sp_ctrl_render (SPCanvasItem *item, SPCanvasBuf *buf) { - gint y0, y1, y, x0,x1,x; - guchar * p, * q, a; - - SPCtrl *ctrl = SP_CTRL (item); - - if (!ctrl->defined) return; - if ((!ctrl->filled) && (!ctrl->stroked)) return; - - sp_canvas_prepare_buffer (buf); - - // the control-image is rendered into ctrl->cache - if (!ctrl->build) sp_ctrl_build_cache (ctrl); - - // then we render from ctrl->cache - y0 = MAX (ctrl->box.y0, buf->rect.y0); - y1 = MIN (ctrl->box.y1, buf->rect.y1 - 1); - x0 = MAX (ctrl->box.x0, buf->rect.x0); - x1 = MIN (ctrl->box.x1, buf->rect.x1 - 1); - - bool colormode; - - for (y = y0; y <= y1; y++) { - p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x0 - buf->rect.x0) * 3; - q = ctrl->cache + ((y - ctrl->box.y0) * (ctrl->span*2+1) + (x0 - ctrl->box.x0)) * 4; - for (x = x0; x <= x1; x++) { - a = *(q + 3); - // 00000000 is the only way to get invisible; all other colors with alpha 00 are treated as mode_color with alpha ff - colormode = false; - if (a == 0x00 && !(q[0] == 0x00 && q[1] == 0x00 && q[2] == 0x00)) { - a = 0xff; - colormode = true; - } - if (ctrl->mode == SP_CTRL_MODE_COLOR || colormode) { - p[0] = COMPOSE_N (p[0], q[0], a); - p[1] = COMPOSE_N (p[1], q[1], a); - p[2] = COMPOSE_N (p[2], q[2], a); - q += 4; - p += 3; - } else if (ctrl->mode == SP_CTRL_MODE_XOR) { - p[0] = COMPOSE_X (p[0], q[0], a); - p[1] = COMPOSE_X (p[1], q[1], a); - p[2] = COMPOSE_X (p[2], q[2], a); - q += 4; - p += 3; - } - } - } - ctrl->shown = TRUE; + gint y0, y1, y, x0,x1,x; + guchar *p, *q, a; + + SPCtrl *ctrl = SP_CTRL (item); + + if (!ctrl->defined) return; + if ((!ctrl->filled) && (!ctrl->stroked)) return; + + sp_canvas_prepare_buffer (buf); + + // the control-image is rendered into ctrl->cache + if (!ctrl->build) { + sp_ctrl_build_cache (ctrl); + } + + // then we render from ctrl->cache + y0 = MAX (ctrl->box.y0, buf->rect.y0); + y1 = MIN (ctrl->box.y1, buf->rect.y1 - 1); + x0 = MAX (ctrl->box.x0, buf->rect.x0); + x1 = MIN (ctrl->box.x1, buf->rect.x1 - 1); + + bool colormode; + + for (y = y0; y <= y1; y++) { + p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x0 - buf->rect.x0) * 3; + q = ctrl->cache + ((y - ctrl->box.y0) * (ctrl->span*2+1) + (x0 - ctrl->box.x0)) * 4; + for (x = x0; x <= x1; x++) { + a = *(q + 3); + // 00000000 is the only way to get invisible; all other colors with alpha 00 are treated as mode_color with alpha ff + colormode = false; + if (a == 0x00 && !(q[0] == 0x00 && q[1] == 0x00 && q[2] == 0x00)) { + a = 0xff; + colormode = true; + } + if (ctrl->mode == SP_CTRL_MODE_COLOR || colormode) { + p[0] = COMPOSE_N (p[0], q[0], a); + p[1] = COMPOSE_N (p[1], q[1], a); + p[2] = COMPOSE_N (p[2], q[2], a); + q += 4; + p += 3; + } else if (ctrl->mode == SP_CTRL_MODE_XOR) { + p[0] = COMPOSE_X (p[0], q[0], a); + p[1] = COMPOSE_X (p[1], q[1], a); + p[2] = COMPOSE_X (p[2], q[2], a); + q += 4; + p += 3; + } + } + } + ctrl->shown = TRUE; } void SPCtrl::moveto (NR::Point const p) { - sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (this), NR::Matrix(NR::translate (p))); - _moved = true; + sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (this), NR::Matrix(NR::translate (p))); + _moved = true; } + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/sodipodi-ctrl.h b/src/display/sodipodi-ctrl.h index 2b2254d14..2a68d1943 100644 --- a/src/display/sodipodi-ctrl.h +++ b/src/display/sodipodi-ctrl.h @@ -21,39 +21,39 @@ #define SP_IS_CTRL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), SP_TYPE_CTRL)) typedef enum { - SP_CTRL_SHAPE_SQUARE, - SP_CTRL_SHAPE_DIAMOND, - SP_CTRL_SHAPE_CIRCLE, - SP_CTRL_SHAPE_CROSS, - SP_CTRL_SHAPE_BITMAP, - SP_CTRL_SHAPE_IMAGE + SP_CTRL_SHAPE_SQUARE, + SP_CTRL_SHAPE_DIAMOND, + SP_CTRL_SHAPE_CIRCLE, + SP_CTRL_SHAPE_CROSS, + SP_CTRL_SHAPE_BITMAP, + SP_CTRL_SHAPE_IMAGE } SPCtrlShapeType; typedef enum { - SP_CTRL_MODE_COLOR, - SP_CTRL_MODE_XOR + SP_CTRL_MODE_COLOR, + SP_CTRL_MODE_XOR } SPCtrlModeType; struct SPCtrl : public SPCanvasItem{ - SPCtrlShapeType shape; - SPCtrlModeType mode; - GtkAnchorType anchor; - gint span; - guint defined : 1; - guint shown : 1; - guint build : 1; - guint filled : 1; - guint stroked : 1; - guint32 fill_color; - guint32 stroke_color; - bool _moved; - - NRRectL box; /* NB! x1 & y1 are included */ - guchar *cache; - GdkPixbuf * pixbuf; - - void moveto(NR::Point const p); + SPCtrlShapeType shape; + SPCtrlModeType mode; + GtkAnchorType anchor; + gint span; + guint defined : 1; + guint shown : 1; + guint build : 1; + guint filled : 1; + guint stroked : 1; + guint32 fill_color; + guint32 stroke_color; + bool _moved; + + NRRectL box; /* NB! x1 & y1 are included */ + guchar *cache; + GdkPixbuf * pixbuf; + + void moveto(NR::Point const p); }; struct SPCtrlClass : public SPCanvasItemClass{ @@ -63,4 +63,17 @@ struct SPCtrlClass : public SPCanvasItemClass{ /* Standard Gtk function */ GtkType sp_ctrl_get_type (void); -#endif + + +#endif /* !INKSCAPE_CTRL_H */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/sodipodi-ctrlrect.cpp b/src/display/sodipodi-ctrlrect.cpp index 0e4887f59..cce921b3c 100644 --- a/src/display/sodipodi-ctrlrect.cpp +++ b/src/display/sodipodi-ctrlrect.cpp @@ -41,7 +41,7 @@ static const guint DASH_LENGTH = 4; GtkType sp_ctrlrect_get_type() { static GtkType ctrlrect_type = 0; - + if (!ctrlrect_type) { GtkTypeInfo ctrlrect_info = { "SPCtrlRect", @@ -95,7 +95,7 @@ static void sp_ctrlrect_hline(SPCanvasBuf *buf, gint y, gint xs, gint xe, guint3 guint const b = RGBA_B(rgba); guint const a = RGBA_A(rgba); gint const x0 = MAX(buf->rect.x0, xs); - gint const x1 = MIN(buf->rect.x1, xe + 1); + gint const x1 = MIN(buf->rect.x1, xe + 1); guchar *p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x0 - buf->rect.x0) * 3; for (gint x = x0; x < x1; x++) { if (!dashed || ((x / DASH_LENGTH) % 2)) { @@ -252,12 +252,12 @@ void CtrlRect::update(NR::Matrix const &affine, unsigned int flags) } NR::Rect bbox(_rect.min() * affine, _rect.max() * affine); - + _area.x0 = (int) floor(bbox.min()[NR::X] + 0.5); _area.y0 = (int) floor(bbox.min()[NR::Y] + 0.5); _area.x1 = (int) floor(bbox.max()[NR::X] + 0.5); _area.y1 = (int) floor(bbox.max()[NR::Y] + 0.5); - + _shadow_size = _shadow; if (_area.x0 != 0 || _area.x1 != 0 || _area.y0 != 0 || _area.y1 != 0) { @@ -290,7 +290,6 @@ void CtrlRect::update(NR::Matrix const &affine, unsigned int flags) x2 = _area.x1 + _shadow_size + 1; y2 = _area.y1 + _shadow_size + 1; } - } diff --git a/src/display/sp-canvas-util.cpp b/src/display/sp-canvas-util.cpp index a0c74b2c3..9b3e53f20 100644 --- a/src/display/sp-canvas-util.cpp +++ b/src/display/sp-canvas-util.cpp @@ -24,112 +24,112 @@ void sp_canvas_update_bbox (SPCanvasItem *item, int x1, int y1, int x2, int y2) { - sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); - item->x1 = x1; - item->y1 = y1; - item->x2 = x2; - item->y2 = y2; - sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); + sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); + item->x1 = x1; + item->y1 = y1; + item->x2 = x2; + item->y2 = y2; + sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); } void sp_canvas_item_reset_bounds (SPCanvasItem *item) { - item->x1 = 0.0; - item->y1 = 0.0; - item->x2 = 0.0; - item->y2 = 0.0; + item->x1 = 0.0; + item->y1 = 0.0; + item->x2 = 0.0; + item->y2 = 0.0; } void sp_canvas_prepare_buffer (SPCanvasBuf *buf) { - if (buf->is_empty) { - sp_canvas_clear_buffer(buf); - buf->is_empty = false; - } + if (buf->is_empty) { + sp_canvas_clear_buffer(buf); + buf->is_empty = false; + } } void sp_canvas_clear_buffer (SPCanvasBuf *buf) { - unsigned char r, g, b; - - r = (buf->bg_color >> 16) & 0xff; - g = (buf->bg_color >> 8) & 0xff; - b = buf->bg_color & 0xff; - - if ((r != g) || (r != b)) { - int x, y; - for (y = buf->rect.y0; y < buf->rect.y1; y++) { - unsigned char *p; - p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride; - for (x = buf->rect.x0; x < buf->rect.x1; x++) { - *p++ = r; - *p++ = g; - *p++ = b; - } - } - } else { - int y; - for (y = buf->rect.y0; y < buf->rect.y1; y++) { - memset (buf->buf + (y - buf->rect.y0) * buf->buf_rowstride, r, 3 * (buf->rect.x1 - buf->rect.x0)); // CAIRO FIXME: for cairo output we need 32bpp, so it will be 4 * ... - } - } + unsigned char r, g, b; + + r = (buf->bg_color >> 16) & 0xff; + g = (buf->bg_color >> 8) & 0xff; + b = buf->bg_color & 0xff; + + if ((r != g) || (r != b)) { + int x, y; + for (y = buf->rect.y0; y < buf->rect.y1; y++) { + unsigned char *p; + p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride; + for (x = buf->rect.x0; x < buf->rect.x1; x++) { + *p++ = r; + *p++ = g; + *p++ = b; + } + } + } else { + int y; + for (y = buf->rect.y0; y < buf->rect.y1; y++) { + memset (buf->buf + (y - buf->rect.y0) * buf->buf_rowstride, r, 3 * (buf->rect.x1 - buf->rect.x0)); // CAIRO FIXME: for cairo output we need 32bpp, so it will be 4 * ... + } + } } NR::Matrix sp_canvas_item_i2p_affine (SPCanvasItem * item) { - g_assert (item != NULL); // this may be overly zealous - it is - // plausible that this gets called - // with item == 0 - - return item->xform; + g_assert (item != NULL); /* this may be overly zealous - it is + * plausible that this gets called + * with item == 0. */ + + return item->xform; } NR::Matrix sp_canvas_item_i2i_affine (SPCanvasItem * from, SPCanvasItem * to) { - g_assert (from != NULL); - g_assert (to != NULL); + g_assert (from != NULL); + g_assert (to != NULL); - return sp_canvas_item_i2w_affine(from) / sp_canvas_item_i2w_affine(to); + return sp_canvas_item_i2w_affine(from) / sp_canvas_item_i2w_affine(to); } void sp_canvas_item_set_i2w_affine (SPCanvasItem * item, NR::Matrix const &i2w) { - g_assert (item != NULL); + g_assert (item != NULL); - sp_canvas_item_affine_absolute(item, i2w / sp_canvas_item_i2w_affine(item->parent)); + sp_canvas_item_affine_absolute(item, i2w / sp_canvas_item_i2w_affine(item->parent)); } void sp_canvas_item_move_to_z (SPCanvasItem * item, gint z) { - g_assert (item != NULL); + g_assert (item != NULL); - gint current_z = sp_canvas_item_order (item); + gint current_z = sp_canvas_item_order (item); - if (current_z == -1) // not found in its parent - return; + if (current_z == -1) // not found in its parent + return; - if (z == current_z) - return; + if (z == current_z) + return; - if (z > current_z) - sp_canvas_item_raise (item, z - current_z); + if (z > current_z) + sp_canvas_item_raise (item, z - current_z); - sp_canvas_item_lower (item, current_z - z); + sp_canvas_item_lower (item, current_z - z); } gint sp_canvas_item_compare_z (SPCanvasItem * a, SPCanvasItem * b) { - gint const o_a = sp_canvas_item_order (a); - gint const o_b = sp_canvas_item_order (b); + gint const o_a = sp_canvas_item_order (a); + gint const o_b = sp_canvas_item_order (b); - if (o_a > o_b) return -1; - if (o_a < o_b) return 1; + if (o_a > o_b) return -1; + if (o_a < o_b) return 1; - return 0; + return 0; } // These two functions are used by canvasitems that use livarot (currently ctrlline and ctrlquadr) @@ -143,17 +143,17 @@ ctrl_run_A8_OR (raster_info &dest,void *data,int st,float vst,int en,float ven) } tempCol; if ( st >= en ) return; tempCol.col=*(uint32_t*)data; - + unsigned int r, g, b, a; r = NR_RGBA32_R (tempCol.col); g = NR_RGBA32_G (tempCol.col); b = NR_RGBA32_B (tempCol.col); a = NR_RGBA32_A (tempCol.col); if (a == 0) return; - + vst*=a; ven*=a; - + if ( vst < 0 ) vst=0; if ( vst > 255 ) vst=255; if ( ven < 0 ) ven=0; @@ -162,7 +162,7 @@ ctrl_run_A8_OR (raster_info &dest,void *data,int st,float vst,int en,float ven) float dv=ven-vst; int len=en-st; uint8_t* d=(uint8_t*)dest.buffer; - + d+=3*(st-dest.startPix); if ( fabs(dv) < 0.001 ) { if ( sv > 249.999 ) { @@ -219,7 +219,7 @@ ctrl_run_A8_OR (raster_info &dest,void *data,int st,float vst,int en,float ven) void nr_pixblock_render_ctrl_rgba (Shape* theS,uint32_t color,NRRectL &area,char* destBuf,int stride) { - + theS->CalcBBox(); float l=theS->leftX,r=theS->rightX,t=theS->topY,b=theS->bottomY; int il,ir,it,ib; @@ -227,25 +227,25 @@ void nr_pixblock_render_ctrl_rgba (Shape* theS,uint32_t color,NRRectL &area,char ir=(int)ceil(r); it=(int)floor(t); ib=(int)ceil(b); - + // printf("bbox %i %i %i %i render %i %i %i %i\n",il,it,ir,ib,area.x0,area.y0,area.x1,area.y1); - + if ( il >= area.x1 || ir <= area.x0 || it >= area.y1 || ib <= area.y0 ) return; if ( il < area.x0 ) il=area.x0; if ( it < area.y0 ) it=area.y0; if ( ir > area.x1 ) ir=area.x1; if ( ib > area.y1 ) ib=area.y1; - + /* // version par FloatLigne int curPt; float curY; theS->BeginRaster(curY,curPt,1.0); - + FloatLigne* theI=new FloatLigne(); IntLigne* theIL=new IntLigne(); - + theS->Scan(curY,curPt,(float)(it),1.0); - + char* mdata=(char*)destBuf; uint32_t* ligStart=((uint32_t*)(mdata+(3*(il-area.x0)+stride*(it-area.y0)))); for (int y=it;yFlatten(); theIL->Copy(theI); - + raster_info dest; dest.startPix=il; dest.endPix=ir; @@ -270,18 +270,18 @@ void nr_pixblock_render_ctrl_rgba (Shape* theS,uint32_t color,NRRectL &area,char theS->EndRaster(); delete theI; delete theIL; */ - + // version par BitLigne directe int curPt; float curY; theS->BeginQuickRaster(curY, curPt); - + BitLigne* theI[4]; for (int i=0;i<4;i++) theI[i]=new BitLigne(il,ir); IntLigne* theIL=new IntLigne(); - + theS->QuickScan(curY,curPt,(float)(it),true,0.25); - + char* mdata=(char*)destBuf; uint32_t* ligStart=((uint32_t*)(mdata+(3*(il-area.x0)+stride*(it-area.y0)))); for (int y=it;yQuickScan(curY,curPt,((float)(y+0.75)),fill_oddEven,theI[2],0.25); theS->QuickScan(curY,curPt,((float)(y+1.0)),fill_oddEven,theI[3],0.25); theIL->Copy(4,theI); - + raster_info dest; dest.startPix=il; dest.endPix=ir; @@ -303,5 +303,17 @@ void nr_pixblock_render_ctrl_rgba (Shape* theS,uint32_t color,NRRectL &area,char } theS->EndQuickRaster(); for (int i=0;i<4;i++) delete theI[i]; - delete theIL; + delete theIL; } + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index f6a27b076..3c647aa1c 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -44,15 +44,15 @@ // Define this to visualize the regions to be redrawn //#define DEBUG_REDRAW 1; -// Tiles are a way to minimize the number of redraws, eliminating too small redraws. +// Tiles are a way to minimize the number of redraws, eliminating too small redraws. // The canvas stores a 2D array of ints, each representing a TILE_SIZExTILE_SIZE pixels tile. // If any part of it is dirtied, the entire tile is dirtied (its int is nonzero) and repainted. #define TILE_SIZE 16 enum { - RENDERMODE_NORMAL, - RENDERMODE_NOAA, - RENDERMODE_OUTLINE + RENDERMODE_NORMAL, + RENDERMODE_NOAA, + RENDERMODE_OUTLINE }; static gint const sp_canvas_update_priority = G_PRIORITY_HIGH_IDLE; @@ -299,11 +299,11 @@ sp_canvas_item_invoke_update (SPCanvasItem *item, NR::Matrix const &affine, unsi GTK_OBJECT_UNSET_FLAGS (item, SP_CANVAS_ITEM_NEED_AFFINE); } -/** - * Helper function to invoke the point method of the item. +/** + * Helper function to invoke the point method of the item. * - * The argument x, y should be in the parent's item-relative coordinate - * system. This routine applies the inverse of the item's transform, + * The argument x, y should be in the parent's item-relative coordinate + * system. This routine applies the inverse of the item's transform, * maintaining the affine invariant. */ static double @@ -318,7 +318,7 @@ sp_canvas_item_invoke_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **act /** * Makes the item's affine transformation matrix be equal to the specified * matrix. - * + * * @item: A canvas item. * @affine: An affine transformation matrix. */ @@ -340,7 +340,7 @@ sp_canvas_item_affine_absolute (SPCanvasItem *item, NR::Matrix const &affine) } /** - * Convenience function to reorder items in a group's child list. + * Convenience function to reorder items in a group's child list. * * This puts the specified link after the "before" link. */ @@ -396,7 +396,7 @@ put_item_after (GList *link, GList *before) /** * Raises the item in its parent's stack by the specified number of positions. - * + * * \param item A canvas item. * \param positions Number of steps to raise the item. * @@ -519,7 +519,7 @@ sp_canvas_item_hide (SPCanvasItem *item) /** * Grab item under cursor. - * + * * \pre !canvas->grabbed_item && item->flags & SP_CANVAS_ITEM_VISIBLE */ int @@ -552,7 +552,7 @@ sp_canvas_item_grab (SPCanvasItem *item, guint event_mask, GdkCursor *cursor, gu /** * Ungrabs the item, which must have been grabbed in the canvas, and ungrabs the * mouse. - * + * * \param item A canvas item that holds a grab. * \param etime The timestamp for ungrabbing the mouse. */ @@ -639,7 +639,7 @@ sp_canvas_item_grab_focus (SPCanvasItem *item) /** * Requests that the canvas queue an update for the specified item. - * + * * To be used only by item implementations. */ void @@ -731,7 +731,7 @@ sp_canvas_group_init (SPCanvasGroup */*group*/) } /** - * Callback that destroys all items in group and calls group's virtual + * Callback that destroys all items in group and calls group's virtual * destroy() function. */ static void @@ -875,7 +875,7 @@ group_add (SPCanvasGroup *group, SPCanvasItem *item) sp_canvas_item_request_update (item); } -/** +/** * Removes an item from a canvas group */ static void @@ -989,7 +989,7 @@ sp_canvas_class_init (SPCanvasClass *klass) widget_class->focus_out_event = sp_canvas_focus_out; } -/** +/** * Callback: object initialization for SPCanvas. */ static void @@ -1203,7 +1203,7 @@ sp_canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation) } /** - * Helper that emits an event for an item in the canvas, be it the current + * Helper that emits an event for an item in the canvas, be it the current * item, grabbed item, or focused item, as appropriate. */ static int @@ -1310,7 +1310,7 @@ emit_event (SPCanvas *canvas, GdkEvent *event) } /** - * Helper that re-picks the current item in the canvas, based on the event's + * Helper that re-picks the current item in the canvas, based on the event's * coordinates and emits enter/leave events for items as appropriate. */ static int @@ -1461,7 +1461,7 @@ sp_canvas_button (GtkWidget *widget, GdkEventButton *event) /* dispatch normally regardless of the event's window if an item has has a pointer grab in effect */ - if (!canvas->grabbed_item && + if (!canvas->grabbed_item && event->window != SP_CANVAS_WINDOW (canvas)) return retval; @@ -1610,8 +1610,8 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1, // CAIRO FIXME: after SPCanvasBuf is made 32bpp throughout, this rgb_draw below can be replaced with the below. // Why this must not be done currently: // - all canvas items (handles, nodes etc) paint themselves assuming 24bpp -// - cairo assumes bgra, but we have rgba, so r and b get swapped (until we paint all with cairo too) -// - it does not seem to be any faster; in fact since with 32bpp, buf contains less pixels, +// - cairo assumes bgra, but we have rgba, so r and b get swapped (until we paint all with cairo too) +// - it does not seem to be any faster; in fact since with 32bpp, buf contains less pixels, // we need more bufs to paint a given area and as a result it's even a bit slower cairo_surface_t* cst = cairo_image_surface_create_for_data ( @@ -1695,12 +1695,12 @@ sp_canvas_paint_rect_internal (PaintRectSetup const *setup, NRRectL this_rect) // Interrupting redraw isn't always good. // For example, when you drag one node of a big path, only the buffer containing // the mouse cursor will be redrawn again and again, and the rest of the path - // will remain stale because Inkscape never has enough idle time to redraw all - // of the screen. To work around this, such operations set a forced_redraw_limit > 0. + // will remain stale because Inkscape never has enough idle time to redraw all + // of the screen. To work around this, such operations set a forced_redraw_limit > 0. // If this limit is set, and if we have aborted redraw more times than is allowed, - // interrupting is blocked and we're forced to redraw full screen once + // interrupting is blocked and we're forced to redraw full screen once // (after which we can again interrupt forced_redraw_limit times). - if (setup->canvas->forced_redraw_limit < 0 || + if (setup->canvas->forced_redraw_limit < 0 || setup->canvas->forced_redraw_count < setup->canvas->forced_redraw_limit) { if (setup->canvas->forced_redraw_limit != -1) { @@ -1730,8 +1730,8 @@ sp_canvas_paint_rect_internal (PaintRectSetup const *setup, NRRectL this_rect) NRRectL lo = this_rect; NRRectL hi = this_rect; -/* -This test determines the redraw strategy: +/* +This test determines the redraw strategy: bw < bh (strips mode) splits across the smaller dimension of the rect and therefore (on horizontally-stretched windows) results in redrawing in horizontal strips (from cursor point, in @@ -1745,7 +1745,7 @@ faster. The default for now is the strips mode. */ - if (bw < bh || bh < 2 * TILE_SIZE) { + if (bw < bh || bh < 2 * TILE_SIZE) { int mid = (this_rect.x0 + this_rect.x1) / 2; // Make sure that mid lies on a tile boundary mid = (mid / TILE_SIZE) * TILE_SIZE; @@ -1790,7 +1790,7 @@ static bool sp_canvas_paint_rect (SPCanvas *canvas, int xx0, int yy0, int xx1, int yy1) { g_return_val_if_fail (!canvas->need_update, false); - + NRRectL rect; rect.x0 = xx0; rect.x1 = xx1; @@ -1807,11 +1807,11 @@ sp_canvas_paint_rect (SPCanvas *canvas, int xx0, int yy0, int xx1, int yy1) // paint the area to redraw yellow gdk_rgb_gc_set_foreground (canvas->pixmap_gc, 0xFFFF00); gdk_draw_rectangle (SP_CANVAS_WINDOW (canvas), - canvas->pixmap_gc, - TRUE, - rect.x0 - canvas->x0, rect.y0 - canvas->y0, - rect.x1 - rect.x0, rect.y1 - rect.y0); -#endif + canvas->pixmap_gc, + TRUE, + rect.x0 - canvas->x0, rect.y0 - canvas->y0, + rect.x1 - rect.x0, rect.y1 - rect.y0); +#endif PaintRectSetup setup; @@ -1847,7 +1847,7 @@ sp_canvas_paint_rect (SPCanvas *canvas, int xx0, int yy0, int xx1, int yy1) void sp_canvas_force_full_redraw_after_interruptions(SPCanvas *canvas, unsigned int count) { g_return_if_fail(canvas != NULL); - + canvas->forced_redraw_limit = count; canvas->forced_redraw_count = 0; } @@ -1870,7 +1870,7 @@ sp_canvas_expose (GtkWidget *widget, GdkEventExpose *event) { SPCanvas *canvas = SP_CANVAS (widget); - if (!GTK_WIDGET_DRAWABLE (widget) || + if (!GTK_WIDGET_DRAWABLE (widget) || (event->window != SP_CANVAS_WINDOW (canvas))) return FALSE; @@ -1880,7 +1880,7 @@ sp_canvas_expose (GtkWidget *widget, GdkEventExpose *event) for (int i = 0; i < n_rects; i++) { NRRectL rect; - + rect.x0 = rects[i].x + canvas->x0; rect.y0 = rects[i].y + canvas->y0; rect.x1 = rect.x0 + rects[i].width; @@ -1970,8 +1970,8 @@ paint (SPCanvas *canvas) Gdk::Region to_paint; - for (int j=canvas->tTop; jtBottom; j++) { - for (int i=canvas->tLeft; itRight; i++) { + for (int j=canvas->tTop; jtBottom; j++) { + for (int i=canvas->tLeft; itRight; i++) { int tile_index = (i - canvas->tLeft) + (j - canvas->tTop)*canvas->tileH; if ( canvas->tiles[tile_index] ) { // if this tile is dirtied (nonzero) @@ -2125,7 +2125,7 @@ sp_canvas_scroll_to (SPCanvas *canvas, double cx, double cy, unsigned int clear, } } -/** +/** * Updates canvas if necessary. */ void @@ -2350,4 +2350,4 @@ void sp_canvas_mark_rect(SPCanvas* canvas, int nl, int nt, int nr, int nb, uint8 fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : -- 2.30.2