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

« back to all changes in this revision

Viewing changes to src/splivarot.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Kees Cook, Ted Gould
  • Date: 2008-02-10 14:20:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080210142016-vcnb2zqyhszu0xvb
Tags: 0.46~pre1-0ubuntu1
[ Kees Cook ]
* debian/control:
  - add libgtkspell-dev build-dep to gain GtkSpell features (LP: #183547).
  - update Standards version (no changes needed).
  - add Vcs and Homepage fields.
  - switch to new python-lxml dep.
* debian/{control,rules}: switch from dpatch to quilt for more sanity.
* debian/patches/20_fix_glib_and_gxx43_ftbfs.patch:
  - merged against upstream fixes.
  - added additional fixes for newly written code.
* debian/rules: enable parallel building.

[ Ted Gould ]
* Updating POTFILES.in to make it so things build correctly.
* debian/control:
  - add ImageMagick++ and libboost-dev to build-deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# include <config.h>
18
18
#endif
19
19
 
 
20
#include <cstring>
 
21
#include <string>
20
22
#include <vector>
21
23
#include <glib/gmem.h>
22
24
#include "xml/repr.h"
23
25
#include "svg/svg.h"
24
26
#include "sp-path.h"
25
27
#include "sp-shape.h"
 
28
#include "sp-image.h"
26
29
#include "marker.h"
27
30
#include "enums.h"
28
31
#include "sp-text.h"
 
32
#include "sp-flowtext.h"
 
33
#include "text-editing.h"
29
34
#include "sp-item-group.h"
30
35
#include "style.h"
31
36
#include "inkscape.h"
67
72
}
68
73
 
69
74
void
 
75
sp_selected_path_union_skip_undo()
 
76
{
 
77
    sp_selected_path_boolop(bool_op_union, SP_VERB_NONE, _("Union"));
 
78
}
 
79
 
 
80
void
70
81
sp_selected_path_intersect()
71
82
{
72
83
    sp_selected_path_boolop(bool_op_inters, SP_VERB_SELECTION_INTERSECT, _("Intersection"));
178
189
    for (GSList *l = il; l != NULL; l = l->next)
179
190
    {
180
191
        SPItem *item = SP_ITEM(l->data);
181
 
        if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
 
192
        if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item) && !SP_IS_FLOWTEXT(item))
182
193
        {
183
194
            desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("One of the objects is <b>not a path</b>, cannot perform boolean operation."));
184
195
            g_slist_free(il);
446
457
    sp_item_adjust_stroke(item_source, i2root.expansion());
447
458
    sp_item_adjust_pattern(item_source, i2root);
448
459
    sp_item_adjust_gradient(item_source, i2root);
 
460
    sp_item_adjust_livepatheffect(item_source, i2root);
449
461
 
450
462
    Inkscape::XML::Node *repr_source = SP_OBJECT_REPR(source);
451
463
 
474
486
    // premultiply by the inverse of parent's repr
475
487
    SPItem *parent_item = SP_ITEM(sp_desktop_document(desktop)->getObjectByRepr(parent));
476
488
    NR::Matrix local = sp_item_i2doc_affine(parent_item);
477
 
    gchar affinestr[80];
478
 
    gchar *transform = NULL;
479
 
    if (!local.test_identity() && sp_svg_transform_write(affinestr, 79, local.inverse())) {
480
 
        transform = affinestr;
481
 
    }
 
489
    gchar *transform = sp_svg_transform_write(local.inverse());
482
490
 
483
491
    // now that we have the result, add it on the canvas
484
492
    if ( bop == bool_op_cut || bop == bool_op_slice ) {
506
514
        for (int i=0;i<nbRP;i++) {
507
515
            gchar *d = resPath[i]->svg_dump_path();
508
516
 
509
 
            Inkscape::XML::Node *repr = sp_repr_new("svg:path");
 
517
            Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
 
518
            Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
510
519
            repr->setAttribute("style", style);
511
520
            if (mask)
512
521
                repr->setAttribute("mask", mask);
551
560
    } else {
552
561
        gchar *d = res->svg_dump_path();
553
562
 
554
 
        Inkscape::XML::Node *repr = sp_repr_new("svg:path");
 
563
        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
 
564
        Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
555
565
        repr->setAttribute("style", style);
556
566
 
557
567
        if ( mask )
573
583
        Inkscape::GC::release(repr);
574
584
    }
575
585
 
576
 
    sp_document_done(sp_desktop_document(desktop), verb, description);
 
586
    g_free(transform);
 
587
 
 
588
    if (verb != SP_VERB_NONE) {
 
589
        sp_document_done(sp_desktop_document(desktop), verb, description);
 
590
    }
577
591
 
578
592
    delete res;
579
593
}
769
783
 
770
784
        if (res->descr_cmd.size() > 1) { // if there's 0 or 1 node left, drop this path altogether
771
785
 
772
 
            Inkscape::XML::Node *repr = sp_repr_new("svg:path");
 
786
            Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
 
787
            Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
773
788
 
774
789
            // restore old style
775
790
            repr->setAttribute("style", style);
790
805
 
791
806
            if (SP_IS_SHAPE(item) && sp_shape_has_markers (SP_SHAPE(item))) {
792
807
 
793
 
                Inkscape::XML::Node *g_repr = sp_repr_new("svg:g");
 
808
                Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
 
809
                Inkscape::XML::Node *g_repr = xml_doc->createElement("svg:g");
794
810
 
795
811
                // add the group to the parent
796
812
                parent->appendChild(g_repr);
821
837
                            tr = marker_item->transform * marker->c2p * tr * transform;
822
838
 
823
839
                            if (SP_OBJECT_REPR(marker_item)) {
824
 
                                Inkscape::XML::Node *m_repr = SP_OBJECT_REPR(marker_item)->duplicate();
 
840
                                Inkscape::XML::Node *m_repr = SP_OBJECT_REPR(marker_item)->duplicate(xml_doc);
825
841
                                g_repr->appendChild(m_repr);
826
842
                                SPItem *marker_item = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(m_repr);
827
843
                                sp_item_write_transform(marker_item, m_repr, tr);
1091
1107
 
1092
1108
        tstr[79] = '\0';
1093
1109
 
1094
 
        repr = sp_repr_new("svg:path");
 
1110
        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
 
1111
        repr = xml_doc->createElement("svg:path");
1095
1112
        repr->setAttribute("sodipodi:type", "inkscape:offset");
1096
1113
        sp_repr_set_svg_double(repr, "inkscape:radius", ( expand > 0
1097
1114
                                                          ? o_width
1356
1373
 
1357
1374
            tstr[79] = '\0';
1358
1375
 
1359
 
            Inkscape::XML::Node *repr = sp_repr_new("svg:path");
 
1376
            Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
 
1377
            Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
1360
1378
 
1361
1379
            repr->setAttribute("style", style);
1362
1380
 
1469
1487
    Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent();
1470
1488
    // remember id
1471
1489
    char const *id = SP_OBJECT_REPR(item)->attribute("id");
 
1490
    // remember path effect
 
1491
    char const *patheffect = SP_OBJECT_REPR(item)->attribute("inkscape:path-effect");
1472
1492
 
1473
1493
    //If a group was selected, to not change the selection list
1474
1494
    if (modifySelection)
1483
1503
        orig->Simplify(threshold * size);
1484
1504
    }
1485
1505
 
1486
 
    Inkscape::XML::Node *repr = sp_repr_new("svg:path");
 
1506
    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
 
1507
    Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
1487
1508
 
1488
1509
    // restore style, mask and clip-path
1489
1510
    repr->setAttribute("style", style);
1501
1522
 
1502
1523
    // path
1503
1524
    gchar *str = orig->svg_dump_path();
1504
 
    repr->setAttribute("d", str);
 
1525
    if (patheffect)
 
1526
        repr->setAttribute("inkscape:original-d", str);
 
1527
    else 
 
1528
        repr->setAttribute("d", str);
1505
1529
    g_free(str);
1506
1530
 
1507
1531
    // restore id
1518
1542
    // reapply the transform
1519
1543
    sp_item_write_transform(newitem, repr, transform);
1520
1544
 
 
1545
    // restore path effect
 
1546
    repr->setAttribute("inkscape:path-effect", patheffect);
 
1547
 
1521
1548
    //If we are not in a selected group
1522
1549
    if (modifySelection)
1523
1550
        selection->add(repr);
1543
1570
  
1544
1571
  gchar *simplificationType;
1545
1572
  if (simplifyIndividualPaths) {
1546
 
    simplificationType = "individual paths";
 
1573
      simplificationType = _("Simplifying paths (separately):");
1547
1574
  } else {
1548
 
    simplificationType = "as a group";
 
1575
      simplificationType = _("Simplifying paths:");
1549
1576
  }
1550
1577
 
1551
1578
  bool didSomething = false;
1552
1579
 
1553
 
  NR::Rect selectionBbox = selection->bounds();
1554
 
  gdouble selectionSize  = L2(selectionBbox.dimensions());
 
1580
  NR::Maybe<NR::Rect> selectionBbox = selection->bounds();
 
1581
  if (!selectionBbox) {
 
1582
    return false;
 
1583
  }
 
1584
  gdouble selectionSize  = L2(selectionBbox->dimensions());
1555
1585
 
1556
1586
  gdouble simplifySize  = selectionSize;
1557
1587
  
1558
1588
  int pathsSimplified = 0;
1559
1589
  int totalPathCount  = g_slist_length(items);
1560
1590
  
1561
 
  desktop->disableInteraction();
 
1591
  // set "busy" cursor
 
1592
  desktop->setWaitingCursor();
1562
1593
  
1563
1594
  for (; items != NULL; items = items->next) {
1564
1595
      SPItem *item = (SPItem *) items->data;
1567
1598
          continue;
1568
1599
 
1569
1600
      if (simplifyIndividualPaths) {
1570
 
          NR::Rect itemBbox = item->invokeBbox(sp_item_i2d_affine(item));        
1571
 
          simplifySize      = L2(itemBbox.dimensions());
 
1601
          NR::Maybe<NR::Rect> itemBbox = item->getBounds(sp_item_i2d_affine(item));        
 
1602
          if (itemBbox) {
 
1603
              simplifySize      = L2(itemBbox->dimensions());
 
1604
          } else {
 
1605
              simplifySize      = 0;
 
1606
          }
1572
1607
      }
1573
1608
 
1574
 
 
1575
1609
      pathsSimplified++;
1576
1610
 
1577
1611
      if (pathsSimplified % 20 == 0) {
1578
 
        gchar *message = g_strdup_printf(_("Simplifying %s - <b>%d</b> of <b>%d</b> paths simplified..."), simplificationType, pathsSimplified, totalPathCount);
1579
 
        desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, message);
1580
 
        desktop->updateCanvasNow();
 
1612
        gchar *message = g_strdup_printf(_("%s <b>%d</b> of <b>%d</b> paths simplified..."), simplificationType, pathsSimplified, totalPathCount);
 
1613
        desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, message);
1581
1614
      }
1582
1615
 
1583
1616
      didSomething |= sp_selected_path_simplify_item(desktop, selection, item,
1584
1617
                          threshold, justCoalesce, angleLimit, breakableAngles, simplifySize, modifySelection);
1585
1618
  }
1586
1619
 
1587
 
  desktop->enableInteraction();
1588
 
  
 
1620
  desktop->clearWaitingCursor();
 
1621
 
1589
1622
  if (pathsSimplified > 20) {
1590
 
    desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, g_strdup_printf(_("Done - <b>%d</b> paths simplified."), pathsSimplified));
 
1623
    desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, g_strdup_printf(_("<b>%d</b> paths simplified."), pathsSimplified));
1591
1624
  }
1592
1625
  
1593
1626
  return didSomething;
1681
1714
Path *
1682
1715
Path_for_item(SPItem *item, bool doTransformation, bool transformFull)
1683
1716
{
1684
 
    SPCurve *curve;
1685
 
 
 
1717
    SPCurve *curve = curve_for_item(item);
 
1718
    NArtBpath *bpath = bpath_for_curve(item, curve, doTransformation, transformFull);
 
1719
    
 
1720
    if (bpath == NULL) {
 
1721
        return NULL;
 
1722
    }
 
1723
    
 
1724
    Path *dest = bpath_to_Path(bpath);
 
1725
 
 
1726
    if (doTransformation) {
 
1727
        g_free(bpath); // see comment in bpath_for_curve
 
1728
    }
 
1729
    
 
1730
    sp_curve_unref(curve);
 
1731
    
 
1732
    return dest;
 
1733
}
 
1734
 
 
1735
NArtBpath *
 
1736
bpath_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull)
 
1737
{
 
1738
    if (curve == NULL)
 
1739
        return NULL;
 
1740
 
 
1741
    NArtBpath *bpath = SP_CURVE_BPATH(curve);
 
1742
    if (bpath == NULL) {
 
1743
        return NULL;
 
1744
    }
 
1745
    
 
1746
    if (doTransformation) {
 
1747
        NArtBpath *new_bpath; // we will get a duplicate which has to be freed at some point!
 
1748
        if (transformFull) {
 
1749
            new_bpath = nr_artpath_affine(bpath, sp_item_i2doc_affine(item));
 
1750
        } else {
 
1751
            new_bpath = nr_artpath_affine(bpath, item->transform);
 
1752
        }
 
1753
        bpath = new_bpath;
 
1754
    }
 
1755
 
 
1756
    return bpath;
 
1757
}
 
1758
 
 
1759
SPCurve* curve_for_item(SPItem *item)
 
1760
{
1686
1761
    if (!item)
1687
1762
        return NULL;
1688
1763
 
1689
 
    if (SP_IS_SHAPE(item))
1690
 
    {
1691
 
        curve = sp_shape_get_curve(SP_SHAPE(item));
1692
 
    }
1693
 
    else if (SP_IS_TEXT(item))
1694
 
    {
1695
 
        curve = SP_TEXT(item)->getNormalizedBpath();
1696
 
    }
1697
 
    else
1698
 
    {
1699
 
        curve = NULL;
1700
 
    }
1701
 
 
1702
 
    if (!curve)
1703
 
        return NULL;
1704
 
    NArtBpath *bpath = SP_CURVE_BPATH(curve);
1705
 
    if (bpath == NULL)
1706
 
        return NULL;
1707
 
 
1708
 
    if ( doTransformation ) {
1709
 
        if (transformFull)
1710
 
            bpath = nr_artpath_affine(SP_CURVE_BPATH(curve), sp_item_i2doc_affine(item));
1711
 
        else
1712
 
            bpath = nr_artpath_affine(SP_CURVE_BPATH(curve), item->transform);
1713
 
        sp_curve_unref(curve);
1714
 
        curve=NULL;
1715
 
    } else {
1716
 
        bpath=SP_CURVE_BPATH(curve);
1717
 
    }
1718
 
 
 
1764
    SPCurve *curve = NULL;
 
1765
 
 
1766
    if (SP_IS_SHAPE(item)) {
 
1767
        if (SP_IS_PATH(item)) {
 
1768
            curve = sp_path_get_curve_for_edit(SP_PATH(item));
 
1769
        } else {
 
1770
            curve = sp_shape_get_curve(SP_SHAPE(item));
 
1771
        }
 
1772
    }
 
1773
    else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item))
 
1774
    {
 
1775
        curve = te_get_layout(item)->convertToCurves();
 
1776
    }
 
1777
    else if (SP_IS_IMAGE(item))
 
1778
    {
 
1779
        curve = sp_image_get_curve(SP_IMAGE(item));
 
1780
    }
 
1781
    
 
1782
    return curve; // do not forget to unref the curve at some point!
 
1783
}
 
1784
 
 
1785
Path *bpath_to_Path(NArtBpath const *bpath) {
1719
1786
    Path *dest = new Path;
1720
1787
    dest->SetBackData(false);
1721
1788
    {
1769
1836
        if (closed)
1770
1837
            dest->Close();
1771
1838
    }
1772
 
 
1773
 
    if ( doTransformation ) {
1774
 
        if ( bpath ) g_free(bpath);
1775
 
    } else {
1776
 
        sp_curve_unref(curve);
1777
 
    }
1778
1839
    return dest;
1779
1840
}
1780
1841