~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/display/nr-arena-image.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 */
14
14
 
15
15
#include <libnr/nr-compose-transform.h>
 
16
#include <2geom/transforms.h>
16
17
#include <libnr/nr-blit.h>
17
 
#include "../prefs-utils.h"
 
18
#include "../preferences.h"
18
19
#include "nr-arena-image.h"
19
20
#include "style.h"
20
21
#include "display/nr-arena.h"
21
22
#include "display/nr-filter.h"
22
23
#include "display/nr-filter-gaussian.h"
23
 
#include <livarot/Path.h>
24
 
#include <livarot/Shape.h>
25
24
#include "sp-filter.h"
26
25
#include "sp-filter-reference.h"
27
26
#include "sp-gaussian-blur.h"
28
 
#include "sp-feblend.h"
 
27
#include "filters/blend.h"
29
28
#include "display/nr-filter-blend.h"
30
29
 
31
30
int nr_arena_image_x_sample = 1;
36
35
 *
37
36
 */
38
37
 
39
 
// defined in nr-arena-shape.cpp
40
 
void nr_pixblock_render_shape_mask_or(NRPixBlock &m, Shape *theS);
41
 
 
42
38
static void nr_arena_image_class_init (NRArenaImageClass *klass);
43
39
static void nr_arena_image_init (NRArenaImage *image);
44
40
static void nr_arena_image_finalize (NRObject *object);
45
41
 
46
42
static unsigned int nr_arena_image_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int state, unsigned int reset);
47
43
static unsigned int nr_arena_image_render (cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
48
 
static NRArenaItem *nr_arena_image_pick (NRArenaItem *item, NR::Point p, double delta, unsigned int sticky);
 
44
static NRArenaItem *nr_arena_image_pick (NRArenaItem *item, Geom::Point p, double delta, unsigned int sticky);
49
45
 
50
46
static NRArenaItemClass *parent_class;
51
47
 
93
89
    image->width = 256.0;
94
90
    image->height = 256.0;
95
91
 
96
 
    nr_matrix_set_identity (&image->grid2px);
 
92
    image->grid2px.setIdentity();
97
93
 
98
94
    image->style = 0;
99
95
}
111
107
static unsigned int
112
108
nr_arena_image_update( NRArenaItem *item, NRRectL */*area*/, NRGC *gc, unsigned int /*state*/, unsigned int /*reset*/ )
113
109
{
114
 
    NRMatrix grid2px;
 
110
    Geom::Matrix grid2px;
 
111
 
 
112
    // clear old bbox
 
113
    nr_arena_item_request_render(item);
115
114
 
116
115
    NRArenaImage *image = NR_ARENA_IMAGE (item);
117
116
 
118
 
    /* Request render old */
119
 
    nr_arena_item_request_render (item);
120
 
 
121
117
    /* Copy affine */
122
 
    nr_matrix_invert (&grid2px, &gc->transform);
123
 
    double hscale, vscale; // todo: replace with NR::scale
 
118
    grid2px = gc->transform.inverse();
 
119
    double hscale, vscale; // todo: replace with Geom::Scale
124
120
    if (image->px) {
125
121
        hscale = image->pxw / image->width;
126
122
        vscale = image->pxh / image->height;
129
125
        vscale = 1.0;
130
126
    }
131
127
 
132
 
    image->grid2px[0] = grid2px.c[0] * hscale;
133
 
    image->grid2px[2] = grid2px.c[2] * hscale;
134
 
    image->grid2px[4] = grid2px.c[4] * hscale;
135
 
    image->grid2px[1] = grid2px.c[1] * vscale;
136
 
    image->grid2px[3] = grid2px.c[3] * vscale;
137
 
    image->grid2px[5] = grid2px.c[5] * vscale;
 
128
    image->grid2px[0] = grid2px[0] * hscale;
 
129
    image->grid2px[2] = grid2px[2] * hscale;
 
130
    image->grid2px[4] = grid2px[4] * hscale;
 
131
    image->grid2px[1] = grid2px[1] * vscale;
 
132
    image->grid2px[3] = grid2px[3] * vscale;
 
133
    image->grid2px[5] = grid2px[5] * vscale;
138
134
 
139
135
    image->grid2px[4] -= image->x * hscale;
140
136
    image->grid2px[5] -= image->y * vscale;
148
144
        bbox.x1 = image->x + image->width;
149
145
        bbox.y1 = image->y + image->height;
150
146
 
151
 
        image->c00 = (NR::Point(bbox.x0, bbox.y0) * gc->transform);
152
 
        image->c01 = (NR::Point(bbox.x0, bbox.y1) * gc->transform);
153
 
        image->c10 = (NR::Point(bbox.x1, bbox.y0) * gc->transform);
154
 
        image->c11 = (NR::Point(bbox.x1, bbox.y1) * gc->transform);
 
147
        image->c00 = (Geom::Point(bbox.x0, bbox.y0) * gc->transform);
 
148
        image->c01 = (Geom::Point(bbox.x0, bbox.y1) * gc->transform);
 
149
        image->c10 = (Geom::Point(bbox.x1, bbox.y0) * gc->transform);
 
150
        image->c11 = (Geom::Point(bbox.x1, bbox.y1) * gc->transform);
155
151
 
156
 
        nr_rect_d_matrix_transform (&bbox, &bbox, &gc->transform);
 
152
        nr_rect_d_matrix_transform (&bbox, &bbox, gc->transform);
157
153
 
158
154
        item->bbox.x0 = (int) floor (bbox.x0);
159
155
        item->bbox.y0 = (int) floor (bbox.y0);
166
162
        item->bbox.y1 = item->bbox.y0 - 1;
167
163
    }
168
164
 
169
 
    nr_arena_item_request_render (item);
170
 
 
171
165
    return NR_ARENA_ITEM_STATE_ALL;
172
166
}
173
167
 
177
171
static unsigned int
178
172
nr_arena_image_render( cairo_t *ct, NRArenaItem *item, NRRectL */*area*/, NRPixBlock *pb, unsigned int /*flags*/ )
179
173
{
180
 
    nr_arena_image_x_sample = prefs_get_int_attribute ("options.bitmapoversample", "value", 1);
 
174
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
175
    nr_arena_image_x_sample = prefs->getInt("/options/bitmapoversample/value", 1);
181
176
    nr_arena_image_y_sample = nr_arena_image_x_sample;
182
177
 
183
 
    bool outline = (item->arena->rendermode == RENDERMODE_OUTLINE);
 
178
    bool outline = (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE);
184
179
 
185
180
    NRArenaImage *image = NR_ARENA_IMAGE (item);
186
181
 
187
 
    NR::Matrix d2s;
 
182
    Geom::Matrix d2s;
188
183
 
189
184
    d2s[0] = b2i[0];
190
185
    d2s[1] = b2i[1];
232
227
        if (!ct)
233
228
            return item->state;
234
229
 
235
 
        guint32 rgba = prefs_get_int_attribute("options.wireframecolors", "images", 0xff0000ff);
 
230
        guint32 rgba = prefs->getInt("/options/wireframecolors/images", 0xff0000ff);
236
231
        // FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat
237
232
        // by setting color channels in the "wrong" order
238
233
        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));
240
235
        cairo_set_line_width(ct, 0.5);
241
236
        cairo_new_path(ct);
242
237
 
243
 
        NR::Point shift(pb->area.x0, pb->area.y0);
244
 
        NR::Point c00 = image->c00 - shift;
245
 
        NR::Point c01 = image->c01 - shift;
246
 
        NR::Point c11 = image->c11 - shift;
247
 
        NR::Point c10 = image->c10 - shift;
 
238
        Geom::Point shift(pb->area.x0, pb->area.y0);
 
239
        Geom::Point c00 = image->c00 - shift;
 
240
        Geom::Point c01 = image->c01 - shift;
 
241
        Geom::Point c11 = image->c11 - shift;
 
242
        Geom::Point c10 = image->c10 - shift;
248
243
 
249
 
        cairo_move_to (ct, c00[NR::X], c00[NR::Y]);
 
244
        cairo_move_to (ct, c00[Geom::X], c00[Geom::Y]);
250
245
 
251
246
        // the box
252
 
        cairo_line_to (ct, c10[NR::X], c10[NR::Y]);
253
 
        cairo_line_to (ct, c11[NR::X], c11[NR::Y]);
254
 
        cairo_line_to (ct, c01[NR::X], c01[NR::Y]);
255
 
        cairo_line_to (ct, c00[NR::X], c00[NR::Y]);
 
247
        cairo_line_to (ct, c10[Geom::X], c10[Geom::Y]);
 
248
        cairo_line_to (ct, c11[Geom::X], c11[Geom::Y]);
 
249
        cairo_line_to (ct, c01[Geom::X], c01[Geom::Y]);
 
250
        cairo_line_to (ct, c00[Geom::X], c00[Geom::Y]);
256
251
        // the diagonals
257
 
        cairo_line_to (ct, c11[NR::X], c11[NR::Y]);
258
 
        cairo_move_to (ct, c10[NR::X], c10[NR::Y]);
259
 
        cairo_line_to (ct, c01[NR::X], c01[NR::Y]);
 
252
        cairo_line_to (ct, c11[Geom::X], c11[Geom::Y]);
 
253
        cairo_move_to (ct, c10[Geom::X], c10[Geom::Y]);
 
254
        cairo_line_to (ct, c01[Geom::X], c01[Geom::Y]);
260
255
 
261
256
        cairo_stroke(ct);
262
257
 
268
263
 
269
264
/** Calculates the closest distance from p to the segment a1-a2*/
270
265
double
271
 
distance_to_segment (NR::Point p, NR::Point a1, NR::Point a2)
 
266
distance_to_segment (Geom::Point p, Geom::Point a1, Geom::Point a2)
272
267
{
273
268
    // calculate sides of the triangle and their squares
274
 
    double d1 = NR::L2(p - a1);
 
269
    double d1 = Geom::L2(p - a1);
275
270
    double d1_2 = d1 * d1;
276
 
    double d2 = NR::L2(p - a2);
 
271
    double d2 = Geom::L2(p - a2);
277
272
    double d2_2 = d2 * d2;
278
 
    double a = NR::L2(a1 - a2);
 
273
    double a = Geom::L2(a1 - a2);
279
274
    double a_2 = a * a;
280
275
 
281
276
    // if one of the angles at the base is > 90, return the corresponding side
288
283
}
289
284
 
290
285
static NRArenaItem *
291
 
nr_arena_image_pick( NRArenaItem *item, NR::Point p, double delta, unsigned int /*sticky*/ )
 
286
nr_arena_image_pick( NRArenaItem *item, Geom::Point p, double delta, unsigned int /*sticky*/ )
292
287
{
293
288
    NRArenaImage *image = NR_ARENA_IMAGE (item);
294
289
 
295
290
    if (!image->px) return NULL;
296
291
 
297
 
    bool outline = (item->arena->rendermode == RENDERMODE_OUTLINE);
 
292
    bool outline = (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE);
298
293
 
299
294
    if (outline) {
300
295
 
316
311
        int const width = image->pxw;
317
312
        int const height = image->pxh;
318
313
        int const rowstride = image->pxrs;
319
 
        NR::Point tp = p * image->grid2px;
320
 
        int const ix = (int)(tp[NR::X]);
321
 
        int const iy = (int)(tp[NR::Y]);
 
314
        Geom::Point tp = p * image->grid2px;
 
315
        int const ix = (int)(tp[Geom::X]);
 
316
        int const iy = (int)(tp[Geom::Y]);
322
317
 
323
318
        if ((ix < 0) || (iy < 0) || (ix >= width) || (iy >= height))
324
319
            return NULL;
372
367
    if (style->filter.set && style->getFilter()) {
373
368
        if (!image->filter) {
374
369
            int primitives = sp_filter_primitive_count(SP_FILTER(style->getFilter()));
375
 
            image->filter = new NR::Filter(primitives);
 
370
            image->filter = new Inkscape::Filters::Filter(primitives);
376
371
        }
377
372
        sp_filter_build_renderer(SP_FILTER(style->getFilter()), image->filter);
378
373
    } else {
385
380
        && style->enable_background.value == SP_CSS_BACKGROUND_NEW) {
386
381
        image->background_new = true;
387
382
    }
 
383
 
 
384
    nr_arena_item_request_update(image, NR_ARENA_ITEM_STATE_ALL, FALSE);
388
385
}
389
386
 
390
387