~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/live_effects/lpe-line_segment.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define INKSCAPE_LPE_LINE_SEGMENT_CPP
 
2
 
 
3
/** \file
 
4
 * LPE <line_segment> implementation
 
5
 */
 
6
 
 
7
/*
 
8
 * Authors:
 
9
 *   Maximilian Albert
 
10
 *
 
11
 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
 
12
 *
 
13
 * Released under GNU GPL, read the file 'COPYING' for more information
 
14
 */
 
15
 
 
16
#include "live_effects/lpe-line_segment.h"
 
17
#include "lpe-tool-context.h"
 
18
 
 
19
#include <2geom/pathvector.h>
 
20
#include <2geom/geom.h>
 
21
#include <2geom/bezier-curve.h>
 
22
 
 
23
namespace Inkscape {
 
24
namespace LivePathEffect {
 
25
 
 
26
static const Util::EnumData<EndType> EndTypeData[] = {
 
27
    {END_CLOSED       , N_("Closed"), "closed"},
 
28
    {END_OPEN_INITIAL , N_("Open start"), "open_start"},
 
29
    {END_OPEN_FINAL   , N_("Open end"), "open_end"},
 
30
    {END_OPEN_BOTH    , N_("Open both"), "open_both"},
 
31
};
 
32
static const Util::EnumDataConverter<EndType> EndTypeConverter(EndTypeData, sizeof(EndTypeData)/sizeof(*EndTypeData));
 
33
 
 
34
LPELineSegment::LPELineSegment(LivePathEffectObject *lpeobject) :
 
35
    Effect(lpeobject),
 
36
    end_type(_("End type"), _("Determines on which side the line or line segment is infinite."), "end_type", EndTypeConverter, &wr, this, END_OPEN_BOTH)
 
37
{
 
38
    /* register all your parameters here, so Inkscape knows which parameters this effect has: */
 
39
    registerParameter( dynamic_cast<Parameter *>(&end_type) );
 
40
}
 
41
 
 
42
LPELineSegment::~LPELineSegment()
 
43
{
 
44
 
 
45
}
 
46
 
 
47
void
 
48
LPELineSegment::doBeforeEffect (SPLPEItem *lpeitem)
 
49
{
 
50
    lpetool_get_limiting_bbox_corners(SP_OBJECT_DOCUMENT(lpeitem), bboxA, bboxB);
 
51
}
 
52
 
 
53
std::vector<Geom::Path>
 
54
LPELineSegment::doEffect_path (std::vector<Geom::Path> const & path_in)
 
55
{
 
56
    std::vector<Geom::Path> output;
 
57
 
 
58
    A = initialPoint(path_in);
 
59
    B = finalPoint(path_in);
 
60
 
 
61
    Geom::Rect dummyRect(bboxA, bboxB);
 
62
    boost::optional<Geom::LineSegment> intersection_segment = Geom::rect_line_intersect(dummyRect, Geom::Line(A, B));
 
63
 
 
64
    if (!intersection_segment) {
 
65
        g_print ("Possible error - no intersection with limiting bounding box.\n");
 
66
        return path_in;
 
67
    }
 
68
 
 
69
    if (end_type == END_OPEN_INITIAL || end_type == END_OPEN_BOTH) {
 
70
        A = (*intersection_segment).initialPoint();
 
71
    }
 
72
 
 
73
    if (end_type == END_OPEN_FINAL || end_type == END_OPEN_BOTH) {
 
74
        B = (*intersection_segment).finalPoint();
 
75
    }
 
76
 
 
77
    Geom::Path path(A);
 
78
    path.appendNew<Geom::LineSegment>(B);
 
79
 
 
80
    output.push_back(path);
 
81
 
 
82
    return output;
 
83
}
 
84
 
 
85
} //namespace LivePathEffect
 
86
} /* namespace Inkscape */
 
87
 
 
88
/*
 
89
  Local Variables:
 
90
  mode:c++
 
91
  c-file-style:"stroustrup"
 
92
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
93
  indent-tabs-mode:nil
 
94
  fill-column:99
 
95
  End:
 
96
*/
 
97
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :