~inkscape+alexander/inkscape/flatten

« back to all changes in this revision

Viewing changes to src/document.cpp

  • Committer: Alexander Brock
  • Date: 2015-05-31 17:41:01 UTC
  • mfrom: (13749.1.441 Inkscape)
  • Revision ID: brock.alexander@web.de-20150531174101-2roftkxg6oy1oav5
MergeĀ lp:inkscape

Show diffs side-by-side

added added

removed removed

Lines of Context:
368
368
 
369
369
    // Create SPRoot element
370
370
    const std::string typeString = NodeTraits::get_type_string(*rroot);
371
 
    SPObject* rootObj = SPFactory::instance().createObject(typeString);
 
371
    SPObject* rootObj = SPFactory::createObject(typeString);
372
372
    document->root = dynamic_cast<SPRoot*>(rootObj);
373
373
 
374
374
    if (document->root == 0) {
611
611
    return nv ? nv->getSVGUnit() : *unit_table.getUnit("px");
612
612
}
613
613
 
614
 
/// Returns document scale as defined by width/height and viewBox (real world to user-units).
 
614
/// Sets document scale (by changing viewBox)
 
615
void SPDocument::setDocumentScale( double scaleX, double scaleY ) {
 
616
 
 
617
    root->viewBox = Geom::Rect::from_xywh(
 
618
        root->viewBox.left(),
 
619
        root->viewBox.top(),
 
620
        root->width.computed  * scaleX,
 
621
        root->height.computed * scaleY );
 
622
    root->viewBox_set = true;
 
623
    root->updateRepr();
 
624
}
 
625
 
 
626
/// Sets document scale (by changing viewBox, x and y scaling equal) 
 
627
void SPDocument::setDocumentScale( double scale ) {
 
628
    setDocumentScale( scale, scale );
 
629
}
 
630
 
 
631
/// Returns document scale as defined by width/height (in pixels) and viewBox (real world to
 
632
/// user-units).
615
633
Geom::Scale SPDocument::getDocumentScale() const
616
634
{
617
635
    Geom::Scale scale;
660
678
    root->height.value = height.quantity;
661
679
    root->height.unit = (SVGLength::Unit) height.unit->svgUnit();
662
680
 
663
 
    if (root->viewBox_set && changeSize)
 
681
    // viewBox scaled by relative change in page size (maintains document scale).
 
682
    if (root->viewBox_set && changeSize) {
664
683
        root->viewBox.setMax(Geom::Point(
665
684
        root->viewBox.left() + (root->width.value /  old_width_converted ) * root->viewBox.width(),
666
685
        root->viewBox.top()  + (root->height.value / old_height_converted) * root->viewBox.height()));
 
686
    }
667
687
    root->updateRepr();
668
688
}
669
689
 
744
764
    root->updateRepr();
745
765
}
746
766
 
 
767
Geom::Rect SPDocument::getViewBox() const
 
768
{
 
769
    Geom::Rect viewBox;
 
770
    if (root->viewBox_set) {
 
771
        viewBox = root->viewBox;
 
772
    } else {
 
773
        viewBox = Geom::Rect::from_xywh( 0, 0, getWidth().value("px"), getHeight().value("px"));
 
774
    }
 
775
    return viewBox;
 
776
}
 
777
 
747
778
void SPDocument::setViewBox(const Geom::Rect &viewBox)
748
779
{
749
780
    root->viewBox_set = true;
1235
1266
    return area.intersects(box);
1236
1267
}
1237
1268
 
1238
 
static GSList *find_items_in_area(GSList *s, SPGroup *group, unsigned int dkey, Geom::Rect const &area,
 
1269
static std::vector<SPItem*> &find_items_in_area(std::vector<SPItem*> &s, SPGroup *group, unsigned int dkey, Geom::Rect const &area,
1239
1270
                                  bool (*test)(Geom::Rect const &, Geom::Rect const &), bool take_insensitive = false)
1240
1271
{
1241
1272
    g_return_val_if_fail(SP_IS_GROUP(group), s);
1248
1279
                SPItem *child = SP_ITEM(o);
1249
1280
                Geom::OptRect box = child->desktopVisualBounds();
1250
1281
                if ( box && test(area, *box) && (take_insensitive || child->isVisibleAndUnlocked(dkey))) {
1251
 
                    s = g_slist_append(s, child);
 
1282
                    s.push_back(child);
1252
1283
                }
1253
1284
            }
1254
1285
        }
1275
1306
    return inGroup;
1276
1307
}
1277
1308
 
1278
 
SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, GSList const *list,Geom::Point const &p, bool take_insensitive)
 
1309
SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, std::vector<SPItem*> const &list,Geom::Point const &p, bool take_insensitive)
1279
1310
{
1280
1311
    g_return_val_if_fail(group, NULL);
1281
1312
    SPItem *bottomMost = 0;
1289
1320
            Inkscape::DrawingItem *arenaitem = item->get_arenaitem(dkey);
1290
1321
            if (arenaitem && arenaitem->pick(p, delta, 1) != NULL
1291
1322
                && (take_insensitive || item->isVisibleAndUnlocked(dkey))) {
1292
 
                if (g_slist_find((GSList *) list, item) != NULL) {
 
1323
                if (find(list.begin(),list.end(),item)!=list.end() ) {
1293
1324
                    bottomMost = item;
1294
1325
                }
1295
1326
            }
1391
1422
 * Assumes box is normalized (and g_asserts it!)
1392
1423
 *
1393
1424
 */
1394
 
GSList *SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) const
 
1425
std::vector<SPItem*> SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) const
1395
1426
{
1396
 
    g_return_val_if_fail(this->priv != NULL, NULL);
1397
 
 
1398
 
    return find_items_in_area(NULL, SP_GROUP(this->root), dkey, box, is_within);
 
1427
    std::vector<SPItem*> x;
 
1428
    g_return_val_if_fail(this->priv != NULL, x);
 
1429
    return find_items_in_area(x, SP_GROUP(this->root), dkey, box, is_within);
1399
1430
}
1400
1431
 
1401
1432
/*
1405
1436
 *
1406
1437
 */
1407
1438
 
1408
 
GSList *SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const
 
1439
std::vector<SPItem*> SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const
1409
1440
{
1410
 
    g_return_val_if_fail(this->priv != NULL, NULL);
1411
 
 
1412
 
    return find_items_in_area(NULL, SP_GROUP(this->root), dkey, box, overlaps);
 
1441
    std::vector<SPItem*> x;
 
1442
    g_return_val_if_fail(this->priv != NULL, x);
 
1443
    return find_items_in_area(x, SP_GROUP(this->root), dkey, box, overlaps);
1413
1444
}
1414
1445
 
1415
 
GSList *SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const
 
1446
std::vector<SPItem*> SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const
1416
1447
{
1417
 
    GSList *items = NULL;
 
1448
    std::vector<SPItem*> items;
1418
1449
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1419
1450
 
1420
1451
    // When picking along the path, we don't want small objects close together
1423
1454
    gdouble saved_delta = prefs->getDouble("/options/cursortolerance/value", 1.0);
1424
1455
    prefs->setDouble("/options/cursortolerance/value", 0.25);
1425
1456
 
1426
 
    for(unsigned int i = 0; i < points.size(); i++) {
 
1457
    for(int i = points.size()-1;i>=0; i--) {
1427
1458
        SPItem *item = getItemAtPoint(key, points[i],
1428
1459
                                                 false, NULL);
1429
 
        if (item && !g_slist_find(items, item))
1430
 
            items = g_slist_prepend (items, item);
 
1460
        if (item && items.end()==find(items.begin(),items.end(), item))
 
1461
            items.push_back(item);
1431
1462
    }
1432
1463
 
1433
1464
    // and now we restore it back
1632
1663
void SPDocument::importDefs(SPDocument *source)
1633
1664
{
1634
1665
    Inkscape::XML::Node *root = source->getReprRoot();
1635
 
    Inkscape::XML::Node *defs = sp_repr_lookup_name(root, "svg:defs", 1);
1636
1666
    Inkscape::XML::Node *target_defs = this->getDefs()->getRepr();
 
1667
    std::vector<Inkscape::XML::Node const *> defsNodes = sp_repr_lookup_name_many(root, "svg:defs");
1637
1668
 
1638
1669
    prevent_id_clashes(source, this);
1639
1670
    
 
1671
    for (std::vector<Inkscape::XML::Node const *>::iterator defs = defsNodes.begin(); defs != defsNodes.end(); ++defs) {
 
1672
        importDefsNode(source, const_cast<Inkscape::XML::Node *>(*defs), target_defs);
 
1673
    }
 
1674
}
 
1675
 
 
1676
void SPDocument::importDefsNode(SPDocument *source, Inkscape::XML::Node *defs, Inkscape::XML::Node *target_defs)
 
1677
{    
1640
1678
    int stagger=0;
1641
1679
 
1642
1680
    /*  Note, "clipboard" throughout the comments means "the document that is either the clipboard