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

« back to all changes in this revision

Viewing changes to src/gradient-chemistry.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:
31
31
#include "sp-tspan.h"
32
32
#include <libnr/nr-matrix-fns.h>
33
33
#include <libnr/nr-point-fns.h>
 
34
#include <libnr/nr-matrix-ops.h>
 
35
#include <libnr/nr-rotate-ops.h>
 
36
#include <2geom/transforms.h>
34
37
#include "xml/repr.h"
35
38
#include "svg/svg.h"
36
39
#include "svg/svg-color.h"
37
40
#include "svg/css-ostringstream.h"
38
 
#include "prefs-utils.h"
 
41
#include "preferences.h"
39
42
 
40
43
 
41
44
// Terminology:
75
78
    /* If gr hrefs some other gradient, remove the href */
76
79
    if (gr->ref->getObject()) {
77
80
        /* We are hrefing someone, so require flattening */
78
 
        SP_OBJECT(gr)->updateRepr(((SPObject *) gr)->repr, SP_OBJECT_WRITE_EXT | SP_OBJECT_WRITE_ALL);
 
81
        SP_OBJECT(gr)->updateRepr(SP_OBJECT_WRITE_EXT | SP_OBJECT_WRITE_ALL);
79
82
        sp_gradient_repr_set_link(SP_OBJECT_REPR(gr), NULL);
80
83
    }
81
84
 
237
240
sp_gradient_fork_vector_if_necessary (SPGradient *gr)
238
241
{
239
242
    // Some people actually prefer their gradient vectors to be shared...
240
 
    if (prefs_get_int_attribute("options.forkgradientvectors", "value", 1) == 0)
 
243
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
244
    if (!prefs->getBool("/options/forkgradientvectors/value", true))
241
245
        return gr;
242
246
 
243
247
    if (SP_OBJECT_HREFCOUNT(gr) > 1) {
281
285
 
282
286
    // calculate the bbox of the item
283
287
    sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
284
 
    NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
 
288
    Geom::OptRect bbox = item->getBounds(Geom::identity()); // we need "true" bbox without item_i2d_affine
285
289
 
286
 
    if ( !bbox || bbox->isEmpty() )
 
290
    if (!bbox)
287
291
        return gr;
288
292
 
289
 
    NR::Coord const width = bbox->dimensions()[NR::X];
290
 
    NR::Coord const height = bbox->dimensions()[NR::Y];
 
293
    Geom::Coord const width = bbox->dimensions()[Geom::X];
 
294
    Geom::Coord const height = bbox->dimensions()[Geom::Y];
291
295
 
292
 
    NR::Point const center = bbox->midpoint();
 
296
    Geom::Point const center = bbox->midpoint();
293
297
 
294
298
    if (SP_IS_RADIALGRADIENT(gr)) {
295
 
        sp_repr_set_svg_double(repr, "cx", center[NR::X]);
296
 
        sp_repr_set_svg_double(repr, "cy", center[NR::Y]);
297
 
        sp_repr_set_svg_double(repr, "fx", center[NR::X]);
298
 
        sp_repr_set_svg_double(repr, "fy", center[NR::Y]);
 
299
        sp_repr_set_svg_double(repr, "cx", center[Geom::X]);
 
300
        sp_repr_set_svg_double(repr, "cy", center[Geom::Y]);
 
301
        sp_repr_set_svg_double(repr, "fx", center[Geom::X]);
 
302
        sp_repr_set_svg_double(repr, "fy", center[Geom::Y]);
299
303
        sp_repr_set_svg_double(repr, "r", width/2);
300
304
 
301
305
        // we want it to be elliptic, not circular
302
 
        NR::Matrix squeeze = NR::Matrix (NR::translate (-center)) *
303
 
            NR::Matrix (NR::scale(1, height/width)) *
304
 
            NR::Matrix (NR::translate (center));
 
306
        Geom::Matrix squeeze = Geom::Translate (-center) *
 
307
            Geom::Scale(1, height/width) *
 
308
            Geom::Translate (center);
305
309
 
306
310
        gr->gradientTransform = squeeze;
307
311
        {
310
314
            g_free(c);
311
315
        }
312
316
    } else {
313
 
        sp_repr_set_svg_double(repr, "x1", (center - NR::Point(width/2, 0))[NR::X]);
314
 
        sp_repr_set_svg_double(repr, "y1", (center - NR::Point(width/2, 0))[NR::Y]);
315
 
        sp_repr_set_svg_double(repr, "x2", (center + NR::Point(width/2, 0))[NR::X]);
316
 
        sp_repr_set_svg_double(repr, "y2", (center + NR::Point(width/2, 0))[NR::Y]);
 
317
        sp_repr_set_svg_double(repr, "x1", (center - Geom::Point(width/2, 0))[Geom::X]);
 
318
        sp_repr_set_svg_double(repr, "y1", (center - Geom::Point(width/2, 0))[Geom::Y]);
 
319
        sp_repr_set_svg_double(repr, "x2", (center + Geom::Point(width/2, 0))[Geom::X]);
 
320
        sp_repr_set_svg_double(repr, "y2", (center + Geom::Point(width/2, 0))[Geom::Y]);
317
321
    }
318
322
 
319
323
    // set the gradientUnits
341
345
 
342
346
        // calculate the bbox of the item
343
347
        sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
344
 
        NR::Matrix bbox2user;
345
 
        NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
346
 
        if ( bbox && !bbox->isEmpty() ) {
347
 
            bbox2user = NR::Matrix(bbox->dimensions()[NR::X], 0,
348
 
                                   0, bbox->dimensions()[NR::Y],
349
 
                                   bbox->min()[NR::X], bbox->min()[NR::Y]);
 
348
        Geom::Matrix bbox2user;
 
349
        Geom::OptRect bbox = item->getBounds(Geom::identity()); // we need "true" bbox without item_i2d_affine
 
350
        if ( bbox ) {
 
351
            bbox2user = Geom::Matrix(bbox->dimensions()[Geom::X], 0,
 
352
                                   0, bbox->dimensions()[Geom::Y],
 
353
                                   bbox->min()[Geom::X], bbox->min()[Geom::Y]);
350
354
        } else {
351
355
            // would be degenerate otherwise
352
 
            bbox2user = NR::identity();
 
356
            bbox2user = Geom::identity();
353
357
        }
354
358
 
355
359
        /* skew is the additional transform, defined by the proportions of the item, that we need
366
370
         *   gradient vector in user space due to application of the non-uniform scaling
367
371
         *   transformation from bounding box space to user space.
368
372
         */
369
 
        NR::Matrix skew = bbox2user;
370
 
        double exp = skew.expansion();
 
373
        Geom::Matrix skew = bbox2user;
 
374
        double exp = skew.descrim();
371
375
        skew[0] /= exp;
372
376
        skew[1] /= exp;
373
377
        skew[2] /= exp;
385
389
 
386
390
        // Matrix to convert points to userspace coords; postmultiply by inverse of skew so
387
391
        // as to cancel it out when it's applied to the gradient during rendering
388
 
        NR::Matrix point_convert = bbox2user * skew.inverse();
 
392
        Geom::Matrix point_convert = bbox2user * skew.inverse();
389
393
 
390
394
        if (SP_IS_RADIALGRADIENT(gr)) {
391
395
            SPRadialGradient *rg = SP_RADIALGRADIENT(gr);
392
396
 
393
397
            // original points in the bbox coords
394
 
            NR::Point c_b = NR::Point(rg->cx.computed, rg->cy.computed);
395
 
            NR::Point f_b = NR::Point(rg->fx.computed, rg->fy.computed);
 
398
            Geom::Point c_b = Geom::Point(rg->cx.computed, rg->cy.computed);
 
399
            Geom::Point f_b = Geom::Point(rg->fx.computed, rg->fy.computed);
396
400
            double r_b = rg->r.computed;
397
401
 
398
402
            // converted points in userspace coords
399
 
            NR::Point c_u = c_b * point_convert;
400
 
            NR::Point f_u = f_b * point_convert;
401
 
            double r_u = r_b * point_convert.expansion();
 
403
            Geom::Point c_u = c_b * point_convert;
 
404
            Geom::Point f_u = f_b * point_convert;
 
405
            double r_u = r_b * point_convert.descrim();
402
406
 
403
 
            sp_repr_set_svg_double(repr, "cx", c_u[NR::X]);
404
 
            sp_repr_set_svg_double(repr, "cy", c_u[NR::Y]);
405
 
            sp_repr_set_svg_double(repr, "fx", f_u[NR::X]);
406
 
            sp_repr_set_svg_double(repr, "fy", f_u[NR::Y]);
 
407
            sp_repr_set_svg_double(repr, "cx", c_u[Geom::X]);
 
408
            sp_repr_set_svg_double(repr, "cy", c_u[Geom::Y]);
 
409
            sp_repr_set_svg_double(repr, "fx", f_u[Geom::X]);
 
410
            sp_repr_set_svg_double(repr, "fy", f_u[Geom::Y]);
407
411
            sp_repr_set_svg_double(repr, "r", r_u);
408
412
 
409
413
        } else {
410
414
            SPLinearGradient *lg = SP_LINEARGRADIENT(gr);
411
415
 
412
 
            NR::Point p1_b = NR::Point(lg->x1.computed, lg->y1.computed);
413
 
            NR::Point p2_b = NR::Point(lg->x2.computed, lg->y2.computed);
414
 
 
415
 
            NR::Point p1_u = p1_b * point_convert;
416
 
            NR::Point p2_u = p2_b * point_convert;
417
 
 
418
 
            sp_repr_set_svg_double(repr, "x1", p1_u[NR::X]);
419
 
            sp_repr_set_svg_double(repr, "y1", p1_u[NR::Y]);
420
 
            sp_repr_set_svg_double(repr, "x2", p2_u[NR::X]);
421
 
            sp_repr_set_svg_double(repr, "y2", p2_u[NR::Y]);
 
416
            Geom::Point p1_b = Geom::Point(lg->x1.computed, lg->y1.computed);
 
417
            Geom::Point p2_b = Geom::Point(lg->x2.computed, lg->y2.computed);
 
418
 
 
419
            Geom::Point p1_u = p1_b * point_convert;
 
420
            Geom::Point p2_u = p2_b * point_convert;
 
421
 
 
422
            sp_repr_set_svg_double(repr, "x1", p1_u[Geom::X]);
 
423
            sp_repr_set_svg_double(repr, "y1", p1_u[Geom::Y]);
 
424
            sp_repr_set_svg_double(repr, "x2", p2_u[Geom::X]);
 
425
            sp_repr_set_svg_double(repr, "y2", p2_u[Geom::Y]);
422
426
        }
423
427
 
424
428
        // set the gradientUnits
439
443
}
440
444
 
441
445
void
442
 
sp_gradient_transform_multiply(SPGradient *gradient, NR::Matrix postmul, bool set)
 
446
sp_gradient_transform_multiply(SPGradient *gradient, Geom::Matrix postmul, bool set)
443
447
{
444
448
    if (set) {
445
449
        gradient->gradientTransform = postmul;
555
559
sp_get_stop_i(SPGradient *gradient, guint stop_i)
556
560
{            
557
561
    SPStop *stop = sp_first_stop (gradient);
 
562
 
 
563
    // if this is valid but weird gradient without an offset-zero stop element,  
 
564
    // inkscape has created a handle for the start of gradient anyway,
 
565
    // so when it asks for stop N that corresponds to stop element N-1
 
566
    if (stop->offset != 0)
 
567
        stop_i --;
558
568
  
559
569
    for (guint i=0; i < stop_i; i++) {
560
570
        if (!stop) return NULL;  
809
819
p_w (in desktop coordinates). Write_repr if you want the change to become permanent.
810
820
*/
811
821
void
812
 
sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, NR::Point p_w, bool fill_or_stroke, bool write_repr, bool scale)
 
822
sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, Geom::Point p_w, bool fill_or_stroke, bool write_repr, bool scale)
813
823
{
814
824
    SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
815
825
 
818
828
 
819
829
    gradient = sp_gradient_convert_to_userspace (gradient, item, fill_or_stroke? "fill" : "stroke");
820
830
 
821
 
    NR::Matrix i2d = sp_item_i2d_affine (item);
822
 
    NR::Point p = p_w * i2d.inverse();
 
831
    Geom::Matrix i2d (sp_item_i2d_affine (item));
 
832
    Geom::Point p = p_w * i2d.inverse();
823
833
    p *= (gradient->gradientTransform).inverse();
824
834
    // now p is in gradient's original coordinates
825
835
 
830
840
        switch (point_type) {
831
841
            case POINT_LG_BEGIN:
832
842
                if (scale) {
833
 
                    lg->x2.computed += (lg->x1.computed - p[NR::X]);
834
 
                    lg->y2.computed += (lg->y1.computed - p[NR::Y]);
 
843
                    lg->x2.computed += (lg->x1.computed - p[Geom::X]);
 
844
                    lg->y2.computed += (lg->y1.computed - p[Geom::Y]);
835
845
                }
836
 
                lg->x1.computed = p[NR::X];
837
 
                lg->y1.computed = p[NR::Y];
 
846
                lg->x1.computed = p[Geom::X];
 
847
                lg->y1.computed = p[Geom::Y];
838
848
                if (write_repr) {
839
849
                    if (scale) {
840
850
                        sp_repr_set_svg_double(repr, "x2", lg->x2.computed);
848
858
                break;
849
859
            case POINT_LG_END:
850
860
                if (scale) {
851
 
                    lg->x1.computed += (lg->x2.computed - p[NR::X]);
852
 
                    lg->y1.computed += (lg->y2.computed - p[NR::Y]);
 
861
                    lg->x1.computed += (lg->x2.computed - p[Geom::X]);
 
862
                    lg->y1.computed += (lg->y2.computed - p[Geom::Y]);
853
863
                }
854
 
                lg->x2.computed = p[NR::X];
855
 
                lg->y2.computed = p[NR::Y];
 
864
                lg->x2.computed = p[Geom::X];
 
865
                lg->y2.computed = p[Geom::Y];
856
866
                if (write_repr) {
857
867
                    if (scale) {
858
868
                        sp_repr_set_svg_double(repr, "x1", lg->x1.computed);
867
877
            case POINT_LG_MID:
868
878
            {                              
869
879
                // using X-coordinates only to determine the offset, assuming p has been snapped to the vector from begin to end.
870
 
                double offset = get_offset_between_points (p, NR::Point(lg->x1.computed, lg->y1.computed), NR::Point(lg->x2.computed, lg->y2.computed));
 
880
                double offset = get_offset_between_points (p, Geom::Point(lg->x1.computed, lg->y1.computed), Geom::Point(lg->x2.computed, lg->y2.computed));
871
881
                SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (lg, false);
872
882
                sp_gradient_ensure_vector(lg);
873
883
                lg->vector.stops.at(point_i).offset = offset;
885
895
                }
886
896
        } else if (SP_IS_RADIALGRADIENT(gradient)) {
887
897
        SPRadialGradient *rg = SP_RADIALGRADIENT(gradient);
888
 
        NR::Point c (rg->cx.computed, rg->cy.computed);
889
 
        NR::Point c_w = c * gradient->gradientTransform * i2d; // now in desktop coords
890
 
        if ((point_type == POINT_RG_R1 || point_type == POINT_RG_R2) && NR::L2 (p_w - c_w) < 1e-3) {
 
898
        Geom::Point c (rg->cx.computed, rg->cy.computed);
 
899
        Geom::Point c_w = c * gradient->gradientTransform * i2d; // now in desktop coords
 
900
        if ((point_type == POINT_RG_R1 || point_type == POINT_RG_R2) && Geom::L2 (p_w - c_w) < 1e-3) {
891
901
            // prevent setting a radius too close to the center
892
902
            return;
893
903
        }
894
 
        NR::Matrix new_transform;
 
904
        Geom::Matrix new_transform;
895
905
        bool transform_set = false;
896
906
 
897
907
                switch (point_type) {
898
908
                case POINT_RG_CENTER:
899
 
                        rg->fx.computed = p[NR::X] + (rg->fx.computed - rg->cx.computed);
900
 
                        rg->fy.computed = p[NR::Y] + (rg->fy.computed - rg->cy.computed);
901
 
                        rg->cx.computed = p[NR::X];
902
 
                        rg->cy.computed = p[NR::Y];
 
909
                        rg->fx.computed = p[Geom::X] + (rg->fx.computed - rg->cx.computed);
 
910
                        rg->fy.computed = p[Geom::Y] + (rg->fy.computed - rg->cy.computed);
 
911
                        rg->cx.computed = p[Geom::X];
 
912
                        rg->cy.computed = p[Geom::Y];
903
913
                        if (write_repr) {
904
914
                                sp_repr_set_svg_double(repr, "fx", rg->fx.computed);
905
915
                                sp_repr_set_svg_double(repr, "fy", rg->fy.computed);
910
920
                        }
911
921
                        break;
912
922
                case POINT_RG_FOCUS:
913
 
                        rg->fx.computed = p[NR::X];
914
 
                        rg->fy.computed = p[NR::Y];
 
923
                        rg->fx.computed = p[Geom::X];
 
924
                        rg->fy.computed = p[Geom::Y];
915
925
                        if (write_repr) {
916
926
                                sp_repr_set_svg_double(repr, "fx", rg->fx.computed);
917
927
                                sp_repr_set_svg_double(repr, "fy", rg->fy.computed);
921
931
                        break;
922
932
                case POINT_RG_R1:
923
933
                        {
924
 
                NR::Point r1_w = (c + NR::Point(rg->r.computed, 0)) * gradient->gradientTransform * i2d;
925
 
                                double r1_angle = NR::atan2(r1_w - c_w);
926
 
                                double move_angle = NR::atan2(p_w - c_w) - r1_angle;
927
 
                                double move_stretch = NR::L2(p_w - c_w) / NR::L2(r1_w - c_w);
 
934
                Geom::Point r1_w = (c + Geom::Point(rg->r.computed, 0)) * gradient->gradientTransform * i2d;
 
935
                                double r1_angle = Geom::atan2(r1_w - c_w);
 
936
                                double move_angle = Geom::atan2(p_w - c_w) - r1_angle;
 
937
                                double move_stretch = Geom::L2(p_w - c_w) / Geom::L2(r1_w - c_w);
928
938
 
929
 
                                NR::Matrix move = NR::Matrix (NR::translate (-c_w)) *
930
 
                                                                                                 NR::Matrix (NR::rotate(-r1_angle)) *
931
 
                                                                                                 NR::Matrix (NR::scale(move_stretch, scale? move_stretch : 1)) *
932
 
                                                                                                 NR::Matrix (NR::rotate(r1_angle)) *
933
 
                                                                                                 NR::Matrix (NR::rotate(move_angle)) *
934
 
                                                                                                 NR::Matrix (NR::translate (c_w));
 
939
                                Geom::Matrix move = Geom::Matrix (Geom::Translate (-c_w)) *
 
940
                                                                                                 Geom::Matrix (Geom::Rotate(-r1_angle)) *
 
941
                                                                                                 Geom::Matrix (Geom::Scale(move_stretch, scale? move_stretch : 1)) *
 
942
                                                                                                 Geom::Matrix (Geom::Rotate(r1_angle)) *
 
943
                                                                                                 Geom::Matrix (Geom::Rotate(move_angle)) *
 
944
                                                                                                 Geom::Matrix (Geom::Translate (c_w));
935
945
 
936
946
                                new_transform = gradient->gradientTransform * i2d * move * i2d.inverse();
937
947
                                transform_set = true;
940
950
                        }
941
951
                case POINT_RG_R2:
942
952
                        {
943
 
                                NR::Point r2_w = (c + NR::Point(0, -rg->r.computed)) * gradient->gradientTransform * i2d;
944
 
                                double r2_angle = NR::atan2(r2_w - c_w);
945
 
                                double move_angle = NR::atan2(p_w - c_w) - r2_angle;
946
 
                                double move_stretch = NR::L2(p_w - c_w) / NR::L2(r2_w - c_w);
 
953
                                Geom::Point r2_w = (c + Geom::Point(0, -rg->r.computed)) * gradient->gradientTransform * i2d;
 
954
                                double r2_angle = Geom::atan2(r2_w - c_w);
 
955
                                double move_angle = Geom::atan2(p_w - c_w) - r2_angle;
 
956
                                double move_stretch = Geom::L2(p_w - c_w) / Geom::L2(r2_w - c_w);
947
957
 
948
 
                                NR::Matrix move = NR::Matrix (NR::translate (-c_w)) *
949
 
                                                                                                 NR::Matrix (NR::rotate(-r2_angle)) *
950
 
                                                                                                 NR::Matrix (NR::scale(move_stretch, scale? move_stretch : 1)) *
951
 
                                                                                                 NR::Matrix (NR::rotate(r2_angle)) *
952
 
                                                                                                 NR::Matrix (NR::rotate(move_angle)) *
953
 
                                                                                                 NR::Matrix (NR::translate (c_w));
 
958
                                Geom::Matrix move = Geom::Matrix (Geom::Translate (-c_w)) *
 
959
                                                                                                 Geom::Matrix (Geom::Rotate(-r2_angle)) *
 
960
                                                                                                 Geom::Matrix (Geom::Scale(move_stretch, scale? move_stretch : 1)) *
 
961
                                                                                                 Geom::Matrix (Geom::Rotate(r2_angle)) *
 
962
                                                                                                 Geom::Matrix (Geom::Rotate(move_angle)) *
 
963
                                                                                                 Geom::Matrix (Geom::Translate (c_w));
954
964
 
955
965
                                new_transform = gradient->gradientTransform * i2d * move * i2d.inverse();
956
966
                                transform_set = true;
959
969
            }
960
970
        case POINT_RG_MID1:
961
971
            {
962
 
                NR::Point start = NR::Point (rg->cx.computed, rg->cy.computed);
963
 
                 NR::Point end   = NR::Point (rg->cx.computed + rg->r.computed, rg->cy.computed);
 
972
                Geom::Point start = Geom::Point (rg->cx.computed, rg->cy.computed);
 
973
                 Geom::Point end   = Geom::Point (rg->cx.computed + rg->r.computed, rg->cy.computed);
964
974
                double offset = get_offset_between_points (p, start, end);
965
975
                SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (rg, false);
966
976
                sp_gradient_ensure_vector(rg);
975
985
                break;
976
986
            }
977
987
        case POINT_RG_MID2:
978
 
                NR::Point start = NR::Point (rg->cx.computed, rg->cy.computed);
979
 
                NR::Point end   = NR::Point (rg->cx.computed, rg->cy.computed - rg->r.computed);
 
988
                Geom::Point start = Geom::Point (rg->cx.computed, rg->cy.computed);
 
989
                Geom::Point end   = Geom::Point (rg->cx.computed, rg->cy.computed - rg->r.computed);
980
990
                double offset = get_offset_between_points (p, start, end);
981
991
                SPGradient *vector = sp_gradient_get_forked_vector_if_necessary(rg, false);
982
992
                sp_gradient_ensure_vector(rg);
1030
1040
in desktop coordinates.
1031
1041
*/
1032
1042
 
1033
 
NR::Point
 
1043
Geom::Point
1034
1044
sp_item_gradient_get_coords (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
1035
1045
{
1036
1046
    SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
1037
1047
 
1038
 
    NR::Point p (0, 0);
 
1048
    Geom::Point p (0, 0);
1039
1049
 
1040
1050
    if (!gradient)
1041
 
        return p;
 
1051
        return from_2geom(p);
1042
1052
 
1043
1053
    if (SP_IS_LINEARGRADIENT(gradient)) {
1044
1054
        SPLinearGradient *lg = SP_LINEARGRADIENT(gradient);
1045
1055
        switch (point_type) {
1046
1056
            case POINT_LG_BEGIN:
1047
 
                p = NR::Point (lg->x1.computed, lg->y1.computed);
 
1057
                p = Geom::Point (lg->x1.computed, lg->y1.computed);
1048
1058
                break;
1049
1059
            case POINT_LG_END:
1050
 
                p = NR::Point (lg->x2.computed, lg->y2.computed);
 
1060
                p = Geom::Point (lg->x2.computed, lg->y2.computed);
1051
1061
                break;
1052
1062
            case POINT_LG_MID:
1053
1063
                {   
1054
1064
                    gdouble offset = lg->vector.stops.at(point_i).offset;
1055
 
                    p = (1-offset) * NR::Point(lg->x1.computed, lg->y1.computed) + offset * NR::Point(lg->x2.computed, lg->y2.computed);
 
1065
                    p = (1-offset) * Geom::Point(lg->x1.computed, lg->y1.computed) + offset * Geom::Point(lg->x2.computed, lg->y2.computed);
1056
1066
                }
1057
1067
                break;
1058
1068
        }
1060
1070
        SPRadialGradient *rg = SP_RADIALGRADIENT(gradient);
1061
1071
        switch (point_type) {
1062
1072
            case POINT_RG_CENTER:
1063
 
                p = NR::Point (rg->cx.computed, rg->cy.computed);
 
1073
                p = Geom::Point (rg->cx.computed, rg->cy.computed);
1064
1074
                break;
1065
1075
            case POINT_RG_FOCUS:
1066
 
                p = NR::Point (rg->fx.computed, rg->fy.computed);
 
1076
                p = Geom::Point (rg->fx.computed, rg->fy.computed);
1067
1077
                break;
1068
1078
            case POINT_RG_R1:
1069
 
                p = NR::Point (rg->cx.computed + rg->r.computed, rg->cy.computed);
 
1079
                p = Geom::Point (rg->cx.computed + rg->r.computed, rg->cy.computed);
1070
1080
                break;
1071
1081
            case POINT_RG_R2:
1072
 
                p = NR::Point (rg->cx.computed, rg->cy.computed - rg->r.computed);
 
1082
                p = Geom::Point (rg->cx.computed, rg->cy.computed - rg->r.computed);
1073
1083
                break;
1074
1084
            case POINT_RG_MID1:
1075
1085
                {
1076
1086
                    gdouble offset = rg->vector.stops.at(point_i).offset;
1077
 
                    p = (1-offset) * NR::Point (rg->cx.computed, rg->cy.computed) + offset * NR::Point(rg->cx.computed + rg->r.computed, rg->cy.computed);
 
1087
                    p = (1-offset) * Geom::Point (rg->cx.computed, rg->cy.computed) + offset * Geom::Point(rg->cx.computed + rg->r.computed, rg->cy.computed);
1078
1088
                }        
1079
1089
                break;
1080
1090
            case POINT_RG_MID2:
1081
1091
                {
1082
1092
                    gdouble offset = rg->vector.stops.at(point_i).offset;
1083
 
                    p = (1-offset) * NR::Point (rg->cx.computed, rg->cy.computed) + offset * NR::Point(rg->cx.computed, rg->cy.computed - rg->r.computed);
 
1093
                    p = (1-offset) * Geom::Point (rg->cx.computed, rg->cy.computed) + offset * Geom::Point(rg->cx.computed, rg->cy.computed - rg->r.computed);
1084
1094
                }        
1085
1095
                break;
1086
1096
        }
1088
1098
 
1089
1099
    if (SP_GRADIENT(gradient)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
1090
1100
        sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
1091
 
        NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
 
1101
        Geom::OptRect bbox = item->getBounds(Geom::identity()); // we need "true" bbox without item_i2d_affine
1092
1102
        if (bbox) {
1093
 
            p *= NR::Matrix(bbox->dimensions()[NR::X], 0,
1094
 
                            0, bbox->dimensions()[NR::Y],
1095
 
                            bbox->min()[NR::X], bbox->min()[NR::Y]);
 
1103
            p *= Geom::Matrix(bbox->dimensions()[Geom::X], 0,
 
1104
                            0, bbox->dimensions()[Geom::Y],
 
1105
                            bbox->min()[Geom::X], bbox->min()[Geom::Y]);
1096
1106
        }
1097
1107
    }
1098
 
    p *= NR::Matrix(gradient->gradientTransform) * sp_item_i2d_affine(item);
1099
 
    return p;
 
1108
    p *= Geom::Matrix(gradient->gradientTransform) * (Geom::Matrix)sp_item_i2d_affine(item);
 
1109
    return from_2geom(p);
1100
1110
}
1101
1111
 
1102
1112