1 #define __SP_FLOOD_CONTEXT_C__
3 /** \file
4 * Bucket fill drawing context, works by bitmap filling an area on a rendered version of the current display and then tracing the result using potrace.
5 *
6 * Author:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 * John Bintz <jcoswell@coswellproductions.org>
10 *
11 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
12 * Copyright (C) 2000-2005 authors
13 * Copyright (C) 2000-2001 Ximian, Inc.
14 *
15 * Released under GNU GPL, read the file 'COPYING' for more information
16 */
18 #include "config.h"
20 #include <gdk/gdkkeysyms.h>
21 #include <queue>
22 #include <deque>
24 #include "macros.h"
25 #include "display/sp-canvas.h"
26 #include "document.h"
27 #include "sp-namedview.h"
28 #include "sp-object.h"
29 #include "sp-rect.h"
30 #include "selection.h"
31 #include "desktop-handles.h"
32 #include "desktop.h"
33 #include "desktop-style.h"
34 #include "message-stack.h"
35 #include "message-context.h"
36 #include "pixmaps/cursor-paintbucket.xpm"
37 #include "flood-context.h"
38 #include "sp-metrics.h"
39 #include <glibmm/i18n.h>
40 #include "object-edit.h"
41 #include "xml/repr.h"
42 #include "xml/node-event-vector.h"
43 #include "prefs-utils.h"
44 #include "context-fns.h"
45 #include "rubberband.h"
47 #include "display/nr-arena-item.h"
48 #include "display/nr-arena.h"
49 #include "display/nr-arena-image.h"
50 #include "display/canvas-arena.h"
51 #include "libnr/nr-pixops.h"
52 #include "libnr/nr-matrix-translate-ops.h"
53 #include "libnr/nr-scale-ops.h"
54 #include "libnr/nr-scale-translate-ops.h"
55 #include "libnr/nr-translate-matrix-ops.h"
56 #include "libnr/nr-translate-scale-ops.h"
57 #include "libnr/nr-matrix-ops.h"
58 #include "sp-item.h"
59 #include "sp-root.h"
60 #include "sp-defs.h"
61 #include "sp-path.h"
62 #include "splivarot.h"
63 #include "livarot/Path.h"
64 #include "livarot/Shape.h"
65 #include "libnr/n-art-bpath.h"
66 #include "svg/svg.h"
67 #include "color.h"
69 #include "trace/trace.h"
70 #include "trace/potrace/inkscape-potrace.h"
72 static void sp_flood_context_class_init(SPFloodContextClass *klass);
73 static void sp_flood_context_init(SPFloodContext *flood_context);
74 static void sp_flood_context_dispose(GObject *object);
76 static void sp_flood_context_setup(SPEventContext *ec);
78 static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEvent *event);
79 static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
81 static void sp_flood_finish(SPFloodContext *rc);
83 static SPEventContextClass *parent_class;
86 GtkType sp_flood_context_get_type()
87 {
88 static GType type = 0;
89 if (!type) {
90 GTypeInfo info = {
91 sizeof(SPFloodContextClass),
92 NULL, NULL,
93 (GClassInitFunc) sp_flood_context_class_init,
94 NULL, NULL,
95 sizeof(SPFloodContext),
96 4,
97 (GInstanceInitFunc) sp_flood_context_init,
98 NULL, /* value_table */
99 };
100 type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPFloodContext", &info, (GTypeFlags) 0);
101 }
102 return type;
103 }
105 static void sp_flood_context_class_init(SPFloodContextClass *klass)
106 {
107 GObjectClass *object_class = (GObjectClass *) klass;
108 SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
110 parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass);
112 object_class->dispose = sp_flood_context_dispose;
114 event_context_class->setup = sp_flood_context_setup;
115 event_context_class->root_handler = sp_flood_context_root_handler;
116 event_context_class->item_handler = sp_flood_context_item_handler;
117 }
119 static void sp_flood_context_init(SPFloodContext *flood_context)
120 {
121 SPEventContext *event_context = SP_EVENT_CONTEXT(flood_context);
123 event_context->cursor_shape = cursor_paintbucket_xpm;
124 event_context->hot_x = 11;
125 event_context->hot_y = 30;
126 event_context->xp = 0;
127 event_context->yp = 0;
128 event_context->tolerance = 4;
129 event_context->within_tolerance = false;
130 event_context->item_to_select = NULL;
132 event_context->shape_repr = NULL;
133 event_context->shape_knot_holder = NULL;
135 flood_context->item = NULL;
137 new (&flood_context->sel_changed_connection) sigc::connection();
138 }
140 static void sp_flood_context_dispose(GObject *object)
141 {
142 SPFloodContext *rc = SP_FLOOD_CONTEXT(object);
143 SPEventContext *ec = SP_EVENT_CONTEXT(object);
145 rc->sel_changed_connection.disconnect();
146 rc->sel_changed_connection.~connection();
148 /* fixme: This is necessary because we do not grab */
149 if (rc->item) {
150 sp_flood_finish(rc);
151 }
153 if (ec->shape_repr) { // remove old listener
154 sp_repr_remove_listener_by_data(ec->shape_repr, ec);
155 Inkscape::GC::release(ec->shape_repr);
156 ec->shape_repr = 0;
157 }
159 if (rc->_message_context) {
160 delete rc->_message_context;
161 }
163 G_OBJECT_CLASS(parent_class)->dispose(object);
164 }
166 static Inkscape::XML::NodeEventVector ec_shape_repr_events = {
167 NULL, /* child_added */
168 NULL, /* child_removed */
169 ec_shape_event_attr_changed,
170 NULL, /* content_changed */
171 NULL /* order_changed */
172 };
174 /**
175 \brief Callback that processes the "changed" signal on the selection;
176 destroys old and creates new knotholder
177 */
178 void sp_flood_context_selection_changed(Inkscape::Selection *selection, gpointer data)
179 {
180 SPFloodContext *rc = SP_FLOOD_CONTEXT(data);
181 SPEventContext *ec = SP_EVENT_CONTEXT(rc);
183 if (ec->shape_repr) { // remove old listener
184 sp_repr_remove_listener_by_data(ec->shape_repr, ec);
185 Inkscape::GC::release(ec->shape_repr);
186 ec->shape_repr = 0;
187 }
189 SPItem *item = selection->singleItem();
190 if (item) {
191 Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
192 if (shape_repr) {
193 ec->shape_repr = shape_repr;
194 Inkscape::GC::anchor(shape_repr);
195 sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
196 }
197 }
198 }
200 static void sp_flood_context_setup(SPEventContext *ec)
201 {
202 SPFloodContext *rc = SP_FLOOD_CONTEXT(ec);
204 if (((SPEventContextClass *) parent_class)->setup) {
205 ((SPEventContextClass *) parent_class)->setup(ec);
206 }
208 SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
209 if (item) {
210 Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
211 if (shape_repr) {
212 ec->shape_repr = shape_repr;
213 Inkscape::GC::anchor(shape_repr);
214 sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
215 }
216 }
218 rc->sel_changed_connection.disconnect();
219 rc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(
220 sigc::bind(sigc::ptr_fun(&sp_flood_context_selection_changed), (gpointer)rc)
221 );
223 rc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
225 if (prefs_get_int_attribute("tools.paintbucket", "selcue", 0) != 0) {
226 rc->enableSelectionCue();
227 }
228 }
230 /**
231 * \brief Merge a pixel with the background color.
232 * \param orig The pixel to merge with the background.
233 * \param bg The background color.
234 * \param base The pixel to merge the original and background into.
235 */
236 inline static void
237 merge_pixel_with_background (unsigned char *orig, unsigned char *bg,
238 unsigned char *base)
239 {
240 int precalc_bg_alpha = (255 * (255 - bg[3])) / 255;
242 for (int i = 0; i < 3; i++) {
243 base[i] = precalc_bg_alpha + (bg[i] * bg[3]) / 255;
244 base[i] = (base[i] * (255 - orig[3])) / 255 + (orig[i] * orig[3]) / 255;
245 }
246 }
248 /**
249 * \brief Get the pointer to a pixel in a pixel buffer.
250 * \param px The pixel buffer.
251 * \param x The X coordinate.
252 * \param y The Y coordinate.
253 * \param width The width of the pixel buffer.
254 */
255 inline unsigned char * get_pixel(guchar *px, int x, int y, int width) {
256 return px + (x + y * width) * 4;
257 }
259 /**
260 * \brief Generate the list of trace channel selection entries.
261 */
262 GList * flood_channels_dropdown_items_list() {
263 GList *glist = NULL;
265 glist = g_list_append (glist, _("Visible Colors"));
266 glist = g_list_append (glist, _("Red"));
267 glist = g_list_append (glist, _("Green"));
268 glist = g_list_append (glist, _("Blue"));
269 glist = g_list_append (glist, _("Hue"));
270 glist = g_list_append (glist, _("Saturation"));
271 glist = g_list_append (glist, _("Lightness"));
272 glist = g_list_append (glist, _("Alpha"));
274 return glist;
275 }
277 /**
278 * \brief Generate the list of autogap selection entries.
279 */
280 GList * flood_autogap_dropdown_items_list() {
281 GList *glist = NULL;
283 glist = g_list_append (glist, _("None"));
284 glist = g_list_append (glist, _("Small"));
285 glist = g_list_append (glist, _("Medium"));
286 glist = g_list_append (glist, _("Large"));
288 return glist;
289 }
291 /**
292 * \brief Compare a pixel in a pixel buffer with another pixel to determine if a point should be included in the fill operation.
293 * \param check The pixel in the pixel buffer to check.
294 * \param orig The original selected pixel to use as the fill target color.
295 * \param merged_orig_pixel The original pixel merged with the background.
296 * \param dtc The desktop background color.
297 * \param threshold The fill threshold.
298 * \param method The fill method to use as defined in PaintBucketChannels.
299 */
300 static bool compare_pixels(unsigned char *check, unsigned char *orig, unsigned char *merged_orig_pixel, unsigned char *dtc, int threshold, PaintBucketChannels method) {
301 int diff = 0;
302 float hsl_check[3], hsl_orig[3];
304 if ((method == FLOOD_CHANNELS_H) ||
305 (method == FLOOD_CHANNELS_S) ||
306 (method == FLOOD_CHANNELS_L)) {
307 sp_color_rgb_to_hsl_floatv(hsl_check, check[0] / 255.0, check[1] / 255.0, check[2] / 255.0);
308 sp_color_rgb_to_hsl_floatv(hsl_orig, orig[0] / 255.0, orig[1] / 255.0, orig[2] / 255.0);
309 }
311 switch (method) {
312 case FLOOD_CHANNELS_ALPHA:
313 return ((int)abs(check[3] - orig[3]) <= threshold);
314 case FLOOD_CHANNELS_R:
315 return ((int)abs(check[0] - orig[0]) <= threshold);
316 case FLOOD_CHANNELS_G:
317 return ((int)abs(check[1] - orig[1]) <= threshold);
318 case FLOOD_CHANNELS_B:
319 return ((int)abs(check[2] - orig[2]) <= threshold);
320 case FLOOD_CHANNELS_RGB:
321 unsigned char merged_check[3];
323 merge_pixel_with_background(check, dtc, merged_check);
325 for (int i = 0; i < 3; i++) {
326 diff += (int)abs(merged_check[i] - merged_orig_pixel[i]);
327 }
328 return ((diff / 3) <= ((threshold * 3) / 4));
330 case FLOOD_CHANNELS_H:
331 return ((int)(fabs(hsl_check[0] - hsl_orig[0]) * 100.0) <= threshold);
332 case FLOOD_CHANNELS_S:
333 return ((int)(fabs(hsl_check[1] - hsl_orig[1]) * 100.0) <= threshold);
334 case FLOOD_CHANNELS_L:
335 return ((int)(fabs(hsl_check[2] - hsl_orig[2]) * 100.0) <= threshold);
336 }
338 return false;
339 }
341 static inline bool is_pixel_checked(unsigned char *t) { return t[0] == 1; }
342 static inline bool is_pixel_queued(unsigned char *t) { return t[1] == 1; }
343 static inline bool is_pixel_paintability_checked(unsigned char *t) { return t[2] != 0; }
344 static inline bool is_pixel_paintable(unsigned char *t) { return t[2] == 1; }
345 static inline bool is_pixel_colored(unsigned char *t) { return t[3] == 255; }
347 static inline void mark_pixel_checked(unsigned char *t) { t[0] = 1; }
348 static inline void mark_pixel_unchecked(unsigned char *t) { t[0] = 0; }
349 static inline void mark_pixel_queued(unsigned char *t) { t[1] = 1; }
350 static inline void mark_pixel_paintable(unsigned char *t) { t[2] = 1; }
351 static inline void mark_pixel_not_paintable(unsigned char *t) { t[2] = 2; }
352 static inline void mark_pixel_colored(unsigned char *t) { t[3] = 255; }
354 static inline void clear_pixel_paintability(unsigned char *t) { t[2] = 0; }
356 struct bitmap_coords_info {
357 bool is_left;
358 unsigned int x;
359 unsigned int y;
360 int y_limit;
361 unsigned int width;
362 unsigned int height;
363 unsigned int threshold;
364 unsigned int radius;
365 PaintBucketChannels method;
366 unsigned char *dtc;
367 unsigned char *merged_orig_pixel;
368 NR::Rect bbox;
369 NR::Rect screen;
370 unsigned int max_queue_size;
371 unsigned int current_step;
372 };
374 /**
375 * \brief Check if a pixel can be included in the fill.
376 * \param px The rendered pixel buffer to check.
377 * \param trace_t The pixel in the trace pixel buffer to check or mark.
378 * \param x The X coordinate.
379 * \param y The y coordinate.
380 * \param orig_color The original selected pixel to use as the fill target color.
381 * \param bci The bitmap_coords_info structure.
382 */
383 inline static bool check_if_pixel_is_paintable(guchar *px, unsigned char *trace_t, int x, int y, unsigned char *orig_color, bitmap_coords_info bci) {
384 if (is_pixel_paintability_checked(trace_t)) {
385 return is_pixel_paintable(trace_t);
386 } else {
387 unsigned char *t = get_pixel(px, x, y, bci.width);
388 if (compare_pixels(t, orig_color, bci.merged_orig_pixel, bci.dtc, bci.threshold, bci.method)) {
389 mark_pixel_paintable(trace_t);
390 return true;
391 } else {
392 mark_pixel_not_paintable(trace_t);
393 return false;
394 }
395 }
396 }
398 /**
399 * \brief Perform the bitmap-to-vector tracing and place the traced path onto the document.
400 * \param px The trace pixel buffer to trace to SVG.
401 * \param desktop The desktop on which to place the final SVG path.
402 * \param transform The transform to apply to the final SVG path.
403 * \param union_with_selection If true, merge the final SVG path with the current selection.
404 */
405 static void do_trace(GdkPixbuf *px, SPDesktop *desktop, NR::Matrix transform, bool union_with_selection) {
406 SPDocument *document = sp_desktop_document(desktop);
408 Inkscape::Trace::Potrace::PotraceTracingEngine pte;
410 pte.setTraceType(Inkscape::Trace::Potrace::TRACE_BRIGHTNESS);
411 pte.setInvert(false);
413 Glib::RefPtr<Gdk::Pixbuf> pixbuf = Glib::wrap(px, true);
415 std::vector<Inkscape::Trace::TracingEngineResult> results = pte.trace(pixbuf);
417 Inkscape::XML::Node *layer_repr = SP_GROUP(desktop->currentLayer())->repr;
418 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
420 long totalNodeCount = 0L;
422 double offset = prefs_get_double_attribute("tools.paintbucket", "offset", 0.0);
424 for (unsigned int i=0 ; i<results.size() ; i++) {
425 Inkscape::Trace::TracingEngineResult result = results[i];
426 totalNodeCount += result.getNodeCount();
428 Inkscape::XML::Node *pathRepr = xml_doc->createElement("svg:path");
429 /* Set style */
430 sp_desktop_apply_style_tool (desktop, pathRepr, "tools.paintbucket", false);
432 NArtBpath *bpath = sp_svg_read_path(result.getPathData().c_str());
433 Path *path = bpath_to_Path(bpath);
434 g_free(bpath);
436 if (offset != 0) {
438 Shape *path_shape = new Shape();
440 path->ConvertWithBackData(0.03);
441 path->Fill(path_shape, 0);
442 delete path;
444 Shape *expanded_path_shape = new Shape();
446 expanded_path_shape->ConvertToShape(path_shape, fill_nonZero);
447 path_shape->MakeOffset(expanded_path_shape, offset * desktop->current_zoom(), join_round, 4);
448 expanded_path_shape->ConvertToShape(path_shape, fill_positive);
450 Path *expanded_path = new Path();
452 expanded_path->Reset();
453 expanded_path_shape->ConvertToForme(expanded_path);
454 expanded_path->ConvertEvenLines(1.0);
455 expanded_path->Simplify(1.0);
457 delete path_shape;
458 delete expanded_path_shape;
460 gchar *str = expanded_path->svg_dump_path();
461 if (str && *str) {
462 pathRepr->setAttribute("d", str);
463 g_free(str);
464 } else {
465 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Too much inset</b>, the result is empty."));
466 Inkscape::GC::release(pathRepr);
467 g_free(str);
468 return;
469 }
471 delete expanded_path;
473 } else {
474 gchar *str = path->svg_dump_path();
475 delete path;
476 pathRepr->setAttribute("d", str);
477 g_free(str);
478 }
480 layer_repr->addChild(pathRepr, NULL);
482 SPObject *reprobj = document->getObjectByRepr(pathRepr);
483 if (reprobj) {
484 sp_item_write_transform(SP_ITEM(reprobj), pathRepr, transform, NULL);
486 // premultiply the item transform by the accumulated parent transform in the paste layer
487 NR::Matrix local = sp_item_i2doc_affine(SP_GROUP(desktop->currentLayer()));
488 if (!local.test_identity()) {
489 gchar const *t_str = pathRepr->attribute("transform");
490 NR::Matrix item_t (NR::identity());
491 if (t_str)
492 sp_svg_transform_read(t_str, &item_t);
493 item_t *= local.inverse();
494 // (we're dealing with unattached repr, so we write to its attr instead of using sp_item_set_transform)
495 gchar *affinestr=sp_svg_transform_write(item_t);
496 pathRepr->setAttribute("transform", affinestr);
497 g_free(affinestr);
498 }
500 Inkscape::Selection *selection = sp_desktop_selection(desktop);
502 pathRepr->setPosition(-1);
504 if (union_with_selection) {
505 desktop->messageStack()->flashF(Inkscape::WARNING_MESSAGE, ngettext("Area filled, path with <b>%d</b> node created and unioned with selection.","Area filled, path with <b>%d</b> nodes created and unioned with selection.",sp_nodes_in_path(SP_PATH(reprobj))), sp_nodes_in_path(SP_PATH(reprobj)));
506 selection->add(reprobj);
507 sp_selected_path_union_skip_undo();
508 } else {
509 desktop->messageStack()->flashF(Inkscape::WARNING_MESSAGE, ngettext("Area filled, path with <b>%d</b> node created.","Area filled, path with <b>%d</b> nodes created.",sp_nodes_in_path(SP_PATH(reprobj))), sp_nodes_in_path(SP_PATH(reprobj)));
510 selection->set(reprobj);
511 }
513 }
515 Inkscape::GC::release(pathRepr);
517 }
518 }
520 /**
521 * \brief The possible return states of perform_bitmap_scanline_check()
522 */
523 enum ScanlineCheckResult {
524 SCANLINE_CHECK_OK,
525 SCANLINE_CHECK_ABORTED,
526 SCANLINE_CHECK_BOUNDARY
527 };
529 /**
530 * \brief Determine if the provided coordinates are within the pixel buffer limits.
531 * \param x The X coordinate.
532 * \param y The Y coordinate.
533 * \param bci The bitmap_coords_info structure.
534 */
535 inline static bool coords_in_range(unsigned int x, unsigned int y, bitmap_coords_info bci) {
536 return (x < bci.width) &&
537 (y < bci.height);
538 }
540 #define PAINT_DIRECTION_LEFT 1
541 #define PAINT_DIRECTION_RIGHT 2
542 #define PAINT_DIRECTION_UP 4
543 #define PAINT_DIRECTION_DOWN 8
544 #define PAINT_DIRECTION_ALL 15
546 /**
547 * \brief Paint a pixel or a square (if autogap is enabled) on the trace pixel buffer
548 * \param px The rendered pixel buffer to check.
549 * \param trace_px The trace pixel buffer.
550 * \param orig_color The original selected pixel to use as the fill target color.
551 * \param bci The bitmap_coords_info structure.
552 * \param original_point_trace_t The original pixel in the trace pixel buffer to check.
553 */
554 inline static unsigned int paint_pixel(guchar *px, guchar *trace_px, unsigned char *orig_color, bitmap_coords_info bci, unsigned char *original_point_trace_t) {
555 if (bci.radius == 0) {
556 mark_pixel_colored(original_point_trace_t);
557 return PAINT_DIRECTION_ALL;
558 } else {
559 unsigned char *trace_t;
561 bool can_paint_up = true;
562 bool can_paint_down = true;
563 bool can_paint_left = true;
564 bool can_paint_right = true;
566 for (unsigned int ty = bci.y - bci.radius; ty <= bci.y + bci.radius; ty++) {
567 for (unsigned int tx = bci.x - bci.radius; tx <= bci.x + bci.radius; tx++) {
568 if (coords_in_range(tx, ty, bci)) {
569 trace_t = get_pixel(trace_px, tx, ty, bci.width);
570 if (!is_pixel_colored(trace_t)) {
571 if (check_if_pixel_is_paintable(px, trace_t, tx, ty, orig_color, bci)) {
572 mark_pixel_colored(trace_t);
573 } else {
574 if (tx < bci.x) { can_paint_left = false; }
575 if (tx > bci.x) { can_paint_right = false; }
576 if (ty < bci.y) { can_paint_up = false; }
577 if (ty > bci.y) { can_paint_down = false; }
578 }
579 }
580 }
581 }
582 }
584 unsigned int paint_directions = 0;
585 if (can_paint_left) { paint_directions += PAINT_DIRECTION_LEFT; }
586 if (can_paint_right) { paint_directions += PAINT_DIRECTION_RIGHT; }
587 if (can_paint_up) { paint_directions += PAINT_DIRECTION_UP; }
588 if (can_paint_down) { paint_directions += PAINT_DIRECTION_DOWN; }
590 return paint_directions;
591 }
592 }
594 /**
595 * \brief Push a point to be checked onto the bottom of the rendered pixel buffer check queue.
596 * \param fill_queue The fill queue to add the point to.
597 * \param max_queue_size The maximum size of the fill queue.
598 * \param trace_t The trace pixel buffer pixel.
599 * \param x The X coordinate.
600 * \param y The Y coordinate.
601 */
602 static void push_point_onto_queue(std::deque<NR::Point> *fill_queue, unsigned int max_queue_size, unsigned char *trace_t, unsigned int x, unsigned int y) {
603 if (!is_pixel_queued(trace_t)) {
604 if ((fill_queue->size() < max_queue_size)) {
605 fill_queue->push_back(NR::Point(x, y));
606 mark_pixel_queued(trace_t);
607 }
608 }
609 }
611 /**
612 * \brief Shift a point to be checked onto the top of the rendered pixel buffer check queue.
613 * \param fill_queue The fill queue to add the point to.
614 * \param max_queue_size The maximum size of the fill queue.
615 * \param trace_t The trace pixel buffer pixel.
616 * \param x The X coordinate.
617 * \param y The Y coordinate.
618 */
619 static void shift_point_onto_queue(std::deque<NR::Point> *fill_queue, unsigned int max_queue_size, unsigned char *trace_t, unsigned int x, unsigned int y) {
620 if (!is_pixel_queued(trace_t)) {
621 if ((fill_queue->size() < max_queue_size)) {
622 fill_queue->push_front(NR::Point(x, y));
623 mark_pixel_queued(trace_t);
624 }
625 }
626 }
628 /**
629 * \brief Scan a row in the rendered pixel buffer and add points to the fill queue as necessary.
630 * \param fill_queue The fill queue to add the point to.
631 * \param px The rendered pixel buffer.
632 * \param trace_px The trace pixel buffer.
633 * \param orig_color The original selected pixel to use as the fill target color.
634 * \param bci The bitmap_coords_info structure.
635 */
636 static ScanlineCheckResult perform_bitmap_scanline_check(std::deque<NR::Point> *fill_queue, guchar *px, guchar *trace_px, unsigned char *orig_color, bitmap_coords_info bci) {
637 bool aborted = false;
638 bool reached_screen_boundary = false;
639 bool ok;
641 bool keep_tracing;
642 bool initial_paint = true;
644 unsigned char *current_trace_t = get_pixel(trace_px, bci.x, bci.y, bci.width);
645 unsigned int paint_directions;
647 bool currently_painting_top = false;
648 bool currently_painting_bottom = false;
650 unsigned int pix_width = bci.width * 4;
652 unsigned int top_ty = bci.y - 1;
653 unsigned int bottom_ty = bci.y + 1;
655 bool can_paint_top = (top_ty > 0);
656 bool can_paint_bottom = (bottom_ty < bci.height);
658 NR::Point t = fill_queue->front();
660 do {
661 ok = false;
662 if (bci.is_left) {
663 keep_tracing = (bci.x != 0);
664 } else {
665 keep_tracing = (bci.x < bci.width);
666 }
668 if (keep_tracing) {
669 if (check_if_pixel_is_paintable(px, current_trace_t, bci.x, bci.y, orig_color, bci)) {
670 paint_directions = paint_pixel(px, trace_px, orig_color, bci, current_trace_t);
671 if (bci.radius == 0) {
672 mark_pixel_checked(current_trace_t);
673 if ((t[NR::X] == bci.x) && (t[NR::Y] == bci.y)) {
674 fill_queue->pop_front(); t = fill_queue->front();
675 }
676 }
678 if (can_paint_top) {
679 if (paint_directions & PAINT_DIRECTION_UP) {
680 unsigned char *trace_t = current_trace_t - pix_width;
681 if (!is_pixel_queued(trace_t)) {
682 bool ok_to_paint = check_if_pixel_is_paintable(px, trace_t, bci.x, top_ty, orig_color, bci);
684 if (initial_paint) { currently_painting_top = !ok_to_paint; }
686 if (ok_to_paint && (!currently_painting_top)) {
687 currently_painting_top = true;
688 push_point_onto_queue(fill_queue, bci.max_queue_size, trace_t, bci.x, top_ty);
689 }
690 if ((!ok_to_paint) && currently_painting_top) {
691 currently_painting_top = false;
692 }
693 }
694 }
695 }
697 if (can_paint_bottom) {
698 if (paint_directions & PAINT_DIRECTION_DOWN) {
699 unsigned char *trace_t = current_trace_t + pix_width;
700 if (!is_pixel_queued(trace_t)) {
701 bool ok_to_paint = check_if_pixel_is_paintable(px, trace_t, bci.x, bottom_ty, orig_color, bci);
703 if (initial_paint) { currently_painting_bottom = !ok_to_paint; }
705 if (ok_to_paint && (!currently_painting_bottom)) {
706 currently_painting_bottom = true;
707 push_point_onto_queue(fill_queue, bci.max_queue_size, trace_t, bci.x, bottom_ty);
708 }
709 if ((!ok_to_paint) && currently_painting_bottom) {
710 currently_painting_bottom = false;
711 }
712 }
713 }
714 }
716 if (bci.is_left) {
717 if (paint_directions & PAINT_DIRECTION_LEFT) {
718 bci.x -= 1; current_trace_t -= 4;
719 ok = true;
720 }
721 } else {
722 if (paint_directions & PAINT_DIRECTION_RIGHT) {
723 bci.x += 1; current_trace_t += 4;
724 ok = true;
725 }
726 }
728 initial_paint = false;
729 }
730 } else {
731 if (bci.bbox.min()[NR::X] > bci.screen.min()[NR::X]) {
732 aborted = true; break;
733 } else {
734 reached_screen_boundary = true;
735 }
736 }
737 } while (ok);
739 if (aborted) { return SCANLINE_CHECK_ABORTED; }
740 if (reached_screen_boundary) { return SCANLINE_CHECK_BOUNDARY; }
741 return SCANLINE_CHECK_OK;
742 }
744 /**
745 * \brief Sort the rendered pixel buffer check queue vertically.
746 */
747 static bool sort_fill_queue_vertical(NR::Point a, NR::Point b) {
748 return a[NR::Y] > b[NR::Y];
749 }
751 /**
752 * \brief Sort the rendered pixel buffer check queue horizontally.
753 */
754 static bool sort_fill_queue_horizontal(NR::Point a, NR::Point b) {
755 return a[NR::X] > b[NR::X];
756 }
758 /**
759 * \brief Perform a flood fill operation.
760 * \param event_context The event context for this tool.
761 * \param event The details of this event.
762 * \param union_with_selection If true, union the new fill with the current selection.
763 * \param is_point_fill If false, use the Rubberband "touch selection" to get the initial points for the fill.
764 * \param is_touch_fill If true, use only the initial contact point in the Rubberband "touch selection" as the fill target color.
765 */
766 static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *event, bool union_with_selection, bool is_point_fill, bool is_touch_fill) {
767 SPDesktop *desktop = event_context->desktop;
768 SPDocument *document = sp_desktop_document(desktop);
770 /* Create new arena */
771 NRArena *arena = NRArena::create();
772 unsigned dkey = sp_item_display_key_new(1);
774 sp_document_ensure_up_to_date (document);
776 SPItem *document_root = SP_ITEM(SP_DOCUMENT_ROOT(document));
777 NR::Maybe<NR::Rect> bbox = document_root->getBounds(NR::identity());
779 if (!bbox) {
780 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Area is not bounded</b>, cannot fill."));
781 return;
782 }
784 double zoom_scale = desktop->current_zoom();
786 // Render 160% of the physical display to the render pixel buffer, so that available
787 // fill areas off the screen can be included in the fill.
788 double padding = 1.6;
790 NR::Rect screen = desktop->get_display_area();
792 unsigned int width = (int)ceil(screen.extent(NR::X) * zoom_scale * padding);
793 unsigned int height = (int)ceil(screen.extent(NR::Y) * zoom_scale * padding);
795 NR::Point origin(screen.min()[NR::X],
796 sp_document_height(document) - screen.extent(NR::Y) - screen.min()[NR::Y]);
798 origin[NR::X] = origin[NR::X] + (screen.extent(NR::X) * ((1 - padding) / 2));
799 origin[NR::Y] = origin[NR::Y] + (screen.extent(NR::Y) * ((1 - padding) / 2));
801 NR::scale scale(zoom_scale, zoom_scale);
802 NR::Matrix affine = scale * NR::translate(-origin * scale);
804 /* Create ArenaItems and set transform */
805 NRArenaItem *root = sp_item_invoke_show(SP_ITEM(sp_document_root(document)), arena, dkey, SP_ITEM_SHOW_DISPLAY);
806 nr_arena_item_set_transform(NR_ARENA_ITEM(root), affine);
808 NRGC gc(NULL);
809 nr_matrix_set_identity(&gc.transform);
811 NRRectL final_bbox;
812 final_bbox.x0 = 0;
813 final_bbox.y0 = 0; //row;
814 final_bbox.x1 = width;
815 final_bbox.y1 = height; //row + num_rows;
817 nr_arena_item_invoke_update(root, &final_bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
819 guchar *px = g_new(guchar, 4 * width * height);
821 NRPixBlock B;
822 nr_pixblock_setup_extern( &B, NR_PIXBLOCK_MODE_R8G8B8A8N,
823 final_bbox.x0, final_bbox.y0, final_bbox.x1, final_bbox.y1,
824 px, 4 * width, FALSE, FALSE );
826 SPNamedView *nv = sp_desktop_namedview(desktop);
827 unsigned long bgcolor = nv->pagecolor;
829 unsigned char dtc[4];
830 dtc[0] = NR_RGBA32_R(bgcolor);
831 dtc[1] = NR_RGBA32_G(bgcolor);
832 dtc[2] = NR_RGBA32_B(bgcolor);
833 dtc[3] = NR_RGBA32_A(bgcolor);
835 for (unsigned int fy = 0; fy < height; fy++) {
836 guchar *p = NR_PIXBLOCK_PX(&B) + fy * B.rs;
837 for (unsigned int fx = 0; fx < width; fx++) {
838 for (int i = 0; i < 4; i++) {
839 *p++ = dtc[i];
840 }
841 }
842 }
844 nr_arena_item_invoke_render(NULL, root, &final_bbox, &B, NR_ARENA_ITEM_RENDER_NO_CACHE );
845 nr_pixblock_release(&B);
847 // Hide items
848 sp_item_invoke_hide(SP_ITEM(sp_document_root(document)), dkey);
850 nr_arena_item_unref(root);
851 nr_object_unref((NRObject *) arena);
853 guchar *trace_px = g_new(guchar, 4 * width * height);
854 memset(trace_px, 0x00, 4 * width * height);
856 std::deque<NR::Point> fill_queue;
857 std::queue<NR::Point> color_queue;
859 std::vector<NR::Point> fill_points;
861 bool aborted = false;
862 int y_limit = height - 1;
864 PaintBucketChannels method = (PaintBucketChannels)prefs_get_int_attribute("tools.paintbucket", "channels", 0);
865 int threshold = prefs_get_int_attribute_limited("tools.paintbucket", "threshold", 1, 0, 100);
867 switch(method) {
868 case FLOOD_CHANNELS_ALPHA:
869 case FLOOD_CHANNELS_RGB:
870 case FLOOD_CHANNELS_R:
871 case FLOOD_CHANNELS_G:
872 case FLOOD_CHANNELS_B:
873 threshold = (255 * threshold) / 100;
874 break;
875 case FLOOD_CHANNELS_H:
876 case FLOOD_CHANNELS_S:
877 case FLOOD_CHANNELS_L:
878 break;
879 }
881 bitmap_coords_info bci;
883 bci.y_limit = y_limit;
884 bci.width = width;
885 bci.height = height;
886 bci.threshold = threshold;
887 bci.method = method;
888 bci.bbox = *bbox;
889 bci.screen = screen;
890 bci.dtc = dtc;
891 bci.radius = prefs_get_int_attribute_limited("tools.paintbucket", "autogap", 0, 0, 3);
892 bci.max_queue_size = (width * height) / 4;
893 bci.current_step = 0;
895 if (is_point_fill) {
896 fill_points.push_back(NR::Point(event->button.x, event->button.y));
897 } else {
898 Inkscape::Rubberband::Rubberband *r = Inkscape::Rubberband::get();
899 fill_points = r->getPoints();
900 }
902 for (unsigned int i = 0; i < fill_points.size(); i++) {
903 NR::Point pw = NR::Point(fill_points[i][NR::X] / zoom_scale, sp_document_height(document) + (fill_points[i][NR::Y] / zoom_scale)) * affine;
905 pw[NR::X] = (int)MIN(width - 1, MAX(0, pw[NR::X]));
906 pw[NR::Y] = (int)MIN(height - 1, MAX(0, pw[NR::Y]));
908 if (is_touch_fill) {
909 if (i == 0) {
910 color_queue.push(pw);
911 } else {
912 unsigned char *trace_t = get_pixel(trace_px, (int)pw[NR::X], (int)pw[NR::Y], width);
913 push_point_onto_queue(&fill_queue, bci.max_queue_size, trace_t, (int)pw[NR::X], (int)pw[NR::Y]);
914 }
915 } else {
916 color_queue.push(pw);
917 }
918 }
920 bool reached_screen_boundary = false;
922 bool first_run = true;
924 unsigned long sort_size_threshold = 5;
926 while (!color_queue.empty() && !aborted) {
927 NR::Point color_point = color_queue.front();
928 color_queue.pop();
930 int cx = (int)color_point[NR::X];
931 int cy = (int)color_point[NR::Y];
933 unsigned char *orig_px = get_pixel(px, cx, cy, width);
934 unsigned char orig_color[4];
935 for (int i = 0; i < 4; i++) { orig_color[i] = orig_px[i]; }
937 unsigned char merged_orig[3];
939 merge_pixel_with_background(orig_color, dtc, merged_orig);
941 bci.merged_orig_pixel = merged_orig;
943 unsigned char *trace_t = get_pixel(trace_px, cx, cy, width);
944 if (!is_pixel_checked(trace_t) && !is_pixel_colored(trace_t)) {
945 if (check_if_pixel_is_paintable(px, trace_px, cx, cy, orig_color, bci)) {
946 shift_point_onto_queue(&fill_queue, bci.max_queue_size, trace_t, cx, cy);
948 if (!first_run) {
949 for (unsigned int y = 0; y < height; y++) {
950 trace_t = get_pixel(trace_px, 0, y, width);
951 for (unsigned int x = 0; x < width; x++) {
952 clear_pixel_paintability(trace_t);
953 trace_t += 4;
954 }
955 }
956 }
957 first_run = false;
958 }
959 }
961 unsigned long old_fill_queue_size = fill_queue.size();
963 while (!fill_queue.empty() && !aborted) {
964 NR::Point cp = fill_queue.front();
966 if (bci.radius == 0) {
967 unsigned long new_fill_queue_size = fill_queue.size();
969 /*
970 * To reduce the number of points in the fill queue, periodically
971 * resort all of the points in the queue so that scanline checks
972 * can complete more quickly. A point cannot be checked twice
973 * in a normal scanline checks, so forcing scanline checks to start
974 * from one corner of the rendered area as often as possible
975 * will reduce the number of points that need to be checked and queued.
976 */
977 if (new_fill_queue_size > sort_size_threshold) {
978 if (new_fill_queue_size > old_fill_queue_size) {
979 std::sort(fill_queue.begin(), fill_queue.end(), sort_fill_queue_vertical);
981 std::deque<NR::Point>::iterator start_sort = fill_queue.begin();
982 std::deque<NR::Point>::iterator end_sort = fill_queue.begin();
983 unsigned int sort_y = (unsigned int)cp[NR::Y];
984 unsigned int current_y = sort_y;
986 for (std::deque<NR::Point>::iterator i = fill_queue.begin(); i != fill_queue.end(); i++) {
987 NR::Point current = *i;
988 current_y = (unsigned int)current[NR::Y];
989 if (current_y != sort_y) {
990 if (start_sort != end_sort) {
991 std::sort(start_sort, end_sort, sort_fill_queue_horizontal);
992 }
993 sort_y = current_y;
994 start_sort = i;
995 }
996 end_sort = i;
997 }
998 if (start_sort != end_sort) {
999 std::sort(start_sort, end_sort, sort_fill_queue_horizontal);
1000 }
1002 cp = fill_queue.front();
1003 }
1004 }
1006 old_fill_queue_size = new_fill_queue_size;
1007 }
1009 fill_queue.pop_front();
1011 int x = (int)cp[NR::X];
1012 int y = (int)cp[NR::Y];
1014 unsigned char *trace_t = get_pixel(trace_px, x, y, width);
1015 if (!is_pixel_checked(trace_t)) {
1016 mark_pixel_checked(trace_t);
1018 if (y == 0) {
1019 if (bbox->min()[NR::Y] > screen.min()[NR::Y]) {
1020 aborted = true; break;
1021 } else {
1022 reached_screen_boundary = true;
1023 }
1024 }
1026 if (y == y_limit) {
1027 if (bbox->max()[NR::Y] < screen.max()[NR::Y]) {
1028 aborted = true; break;
1029 } else {
1030 reached_screen_boundary = true;
1031 }
1032 }
1034 bci.is_left = true;
1035 bci.x = x;
1036 bci.y = y;
1038 ScanlineCheckResult result = perform_bitmap_scanline_check(&fill_queue, px, trace_px, orig_color, bci);
1040 switch (result) {
1041 case SCANLINE_CHECK_ABORTED:
1042 aborted = true;
1043 break;
1044 case SCANLINE_CHECK_BOUNDARY:
1045 reached_screen_boundary = true;
1046 break;
1047 default:
1048 break;
1049 }
1051 if (bci.x < width) {
1052 trace_t += 4;
1053 if (!is_pixel_checked(trace_t) && !is_pixel_queued(trace_t)) {
1054 mark_pixel_checked(trace_t);
1055 bci.is_left = false;
1056 bci.x = x + 1;
1058 result = perform_bitmap_scanline_check(&fill_queue, px, trace_px, orig_color, bci);
1060 switch (result) {
1061 case SCANLINE_CHECK_ABORTED:
1062 aborted = true;
1063 break;
1064 case SCANLINE_CHECK_BOUNDARY:
1065 reached_screen_boundary = true;
1066 break;
1067 default:
1068 break;
1069 }
1070 }
1071 }
1072 }
1074 bci.current_step++;
1076 if (bci.current_step > bci.max_queue_size) {
1077 aborted = true;
1078 }
1079 }
1080 }
1082 g_free(px);
1084 if (aborted) {
1085 g_free(trace_px);
1086 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Area is not bounded</b>, cannot fill."));
1087 return;
1088 }
1090 if (reached_screen_boundary) {
1091 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Only the visible part of the bounded area was filled.</b> If you want to fill all of the area, undo, zoom out, and fill again."));
1092 }
1094 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(trace_px,
1095 GDK_COLORSPACE_RGB,
1096 TRUE,
1097 8, width, height, width * 4,
1098 (GdkPixbufDestroyNotify)g_free,
1099 NULL);
1101 NR::Matrix inverted_affine = NR::Matrix(affine).inverse();
1103 do_trace(pixbuf, desktop, inverted_affine, union_with_selection);
1105 g_free(trace_px);
1107 sp_document_done(document, SP_VERB_CONTEXT_PAINTBUCKET, _("Fill bounded area"));
1108 }
1110 static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
1111 {
1112 gint ret = FALSE;
1114 SPDesktop *desktop = event_context->desktop;
1116 switch (event->type) {
1117 case GDK_BUTTON_PRESS:
1118 if ((event->button.state & GDK_CONTROL_MASK) && event->button.button == 1 && !event_context->space_panning) {
1119 NR::Point const button_w(event->button.x,
1120 event->button.y);
1122 SPItem *item = sp_event_context_find_item (desktop, button_w, TRUE, TRUE);
1124 Inkscape::XML::Node *pathRepr = SP_OBJECT_REPR(item);
1125 /* Set style */
1126 sp_desktop_apply_style_tool (desktop, pathRepr, "tools.paintbucket", false);
1127 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Set style on object"));
1128 ret = TRUE;
1129 }
1130 break;
1131 default:
1132 break;
1133 }
1135 if (((SPEventContextClass *) parent_class)->item_handler) {
1136 ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
1137 }
1139 return ret;
1140 }
1142 static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEvent *event)
1143 {
1144 static bool dragging;
1146 gint ret = FALSE;
1147 SPDesktop *desktop = event_context->desktop;
1149 switch (event->type) {
1150 case GDK_BUTTON_PRESS:
1151 if (event->button.button == 1 && !event_context->space_panning) {
1152 if (!(event->button.state & GDK_CONTROL_MASK)) {
1153 NR::Point const button_w(event->button.x,
1154 event->button.y);
1156 if (Inkscape::have_viable_layer(desktop, event_context->defaultMessageContext())) {
1157 // save drag origin
1158 event_context->xp = (gint) button_w[NR::X];
1159 event_context->yp = (gint) button_w[NR::Y];
1160 event_context->within_tolerance = true;
1162 dragging = true;
1164 NR::Point const p(desktop->w2d(button_w));
1165 Inkscape::Rubberband::get()->setMode(RUBBERBAND_MODE_TOUCHPATH);
1166 Inkscape::Rubberband::get()->start(desktop, p);
1167 }
1168 }
1169 }
1170 case GDK_MOTION_NOTIFY:
1171 if ( dragging
1172 && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning)
1173 {
1174 if ( event_context->within_tolerance
1175 && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
1176 && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
1177 break; // do not drag if we're within tolerance from origin
1178 }
1180 event_context->within_tolerance = false;
1182 NR::Point const motion_pt(event->motion.x, event->motion.y);
1183 NR::Point const p(desktop->w2d(motion_pt));
1184 if (Inkscape::Rubberband::get()->is_started()) {
1185 Inkscape::Rubberband::get()->move(p);
1186 event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> areas to add to fill, hold <b>Alt</b> for touch fill"));
1187 gobble_motion_events(GDK_BUTTON1_MASK);
1188 }
1189 }
1190 break;
1192 case GDK_BUTTON_RELEASE:
1193 if (event->button.button == 1 && !event_context->space_panning) {
1194 Inkscape::Rubberband::Rubberband *r = Inkscape::Rubberband::get();
1195 if (r->is_started()) {
1196 // set "busy" cursor
1197 desktop->setWaitingCursor();
1199 if (SP_IS_EVENT_CONTEXT(event_context)) {
1200 // Since setWaitingCursor runs main loop iterations, we may have already left this tool!
1201 // So check if the tool is valid before doing anything
1202 dragging = false;
1204 bool is_point_fill = event_context->within_tolerance;
1205 bool is_touch_fill = event->button.state & GDK_MOD1_MASK;
1207 sp_flood_do_flood_fill(event_context, event, event->button.state & GDK_SHIFT_MASK, is_point_fill, is_touch_fill);
1209 desktop->clearWaitingCursor();
1210 // restore cursor when done; note that it may already be different if e.g. user
1211 // switched to another tool during interruptible tracing or drawing, in which case do nothing
1213 ret = TRUE;
1214 }
1216 r->stop();
1218 if (SP_IS_EVENT_CONTEXT(event_context)) {
1219 event_context->defaultMessageContext()->clear();
1220 }
1221 }
1222 }
1223 break;
1224 case GDK_KEY_PRESS:
1225 switch (get_group0_keyval (&event->key)) {
1226 case GDK_Up:
1227 case GDK_Down:
1228 case GDK_KP_Up:
1229 case GDK_KP_Down:
1230 // prevent the zoom field from activation
1231 if (!MOD__CTRL_ONLY)
1232 ret = TRUE;
1233 break;
1234 default:
1235 break;
1236 }
1237 break;
1238 default:
1239 break;
1240 }
1242 if (!ret) {
1243 if (((SPEventContextClass *) parent_class)->root_handler) {
1244 ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
1245 }
1246 }
1248 return ret;
1249 }
1252 static void sp_flood_finish(SPFloodContext *rc)
1253 {
1254 rc->_message_context->clear();
1256 if ( rc->item != NULL ) {
1257 SPDesktop * desktop;
1259 desktop = SP_EVENT_CONTEXT_DESKTOP(rc);
1261 SP_OBJECT(rc->item)->updateRepr();
1263 sp_canvas_end_forced_full_redraws(desktop->canvas);
1265 sp_desktop_selection(desktop)->set(rc->item);
1266 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET,
1267 _("Fill bounded area"));
1269 rc->item = NULL;
1270 }
1271 }
1273 void flood_channels_set_channels( gint channels )
1274 {
1275 prefs_set_int_attribute("tools.paintbucket", "channels", channels);
1276 }
1278 /*
1279 Local Variables:
1280 mode:c++
1281 c-file-style:"stroustrup"
1282 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1283 indent-tabs-mode:nil
1284 fill-column:99
1285 End:
1286 */
1287 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :