1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is the Mozilla SVG project.
16 : *
17 : * The Initial Developer of the Original Code is IBM Corporation.
18 : * Portions created by the Initial Developer are Copyright (C) 2006
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either of the GNU General Public License Version 2 or later (the "GPL"),
25 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 : * in which case the provisions of the GPL or the LGPL are applicable instead
27 : * of those above. If you wish to allow use of your version of this file only
28 : * under the terms of either the GPL or the LGPL, and not to allow others to
29 : * use your version of this file under the terms of the MPL, indicate your
30 : * decision by deleting the provisions above and replace them with the notice
31 : * and other provisions required by the GPL or the LGPL. If you do not delete
32 : * the provisions above, a recipient may use your version of this file under
33 : * the terms of any one of the MPL, the GPL or the LGPL.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : #include "mozilla/Util.h"
38 :
39 : #include "nsSVGPolyElement.h"
40 : #include "DOMSVGPointList.h"
41 : #include "gfxContext.h"
42 : #include "nsSVGUtils.h"
43 :
44 : using namespace mozilla;
45 :
46 : //----------------------------------------------------------------------
47 : // nsISupports methods
48 :
49 0 : NS_IMPL_ADDREF_INHERITED(nsSVGPolyElement,nsSVGPolyElementBase)
50 0 : NS_IMPL_RELEASE_INHERITED(nsSVGPolyElement,nsSVGPolyElementBase)
51 :
52 0 : NS_INTERFACE_MAP_BEGIN(nsSVGPolyElement)
53 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedPoints)
54 0 : NS_INTERFACE_MAP_END_INHERITING(nsSVGPolyElementBase)
55 :
56 : //----------------------------------------------------------------------
57 : // Implementation
58 :
59 0 : nsSVGPolyElement::nsSVGPolyElement(already_AddRefed<nsINodeInfo> aNodeInfo)
60 0 : : nsSVGPolyElementBase(aNodeInfo)
61 : {
62 :
63 0 : }
64 :
65 : //----------------------------------------------------------------------
66 : // nsIDOMSGAnimatedPoints methods:
67 :
68 : /* readonly attribute nsIDOMSVGPointList points; */
69 : NS_IMETHODIMP
70 0 : nsSVGPolyElement::GetPoints(nsIDOMSVGPointList * *aPoints)
71 : {
72 0 : void *key = mPoints.GetBaseValKey();
73 0 : *aPoints = DOMSVGPointList::GetDOMWrapper(key, this, false).get();
74 0 : return NS_OK;
75 : }
76 :
77 : /* readonly attribute nsIDOMSVGPointList animatedPoints; */
78 : NS_IMETHODIMP
79 0 : nsSVGPolyElement::GetAnimatedPoints(nsIDOMSVGPointList * *aAnimatedPoints)
80 : {
81 0 : void *key = mPoints.GetAnimValKey();
82 0 : *aAnimatedPoints = DOMSVGPointList::GetDOMWrapper(key, this, true).get();
83 0 : return NS_OK;
84 : }
85 :
86 : //----------------------------------------------------------------------
87 : // nsIContent methods
88 :
89 : NS_IMETHODIMP_(bool)
90 0 : nsSVGPolyElement::IsAttributeMapped(const nsIAtom* name) const
91 : {
92 : static const MappedAttributeEntry* const map[] = {
93 : sMarkersMap
94 : };
95 :
96 0 : return FindAttributeDependence(name, map) ||
97 0 : nsSVGPolyElementBase::IsAttributeMapped(name);
98 : }
99 :
100 : //----------------------------------------------------------------------
101 : // nsSVGPathGeometryElement methods
102 :
103 : bool
104 0 : nsSVGPolyElement::AttributeDefinesGeometry(const nsIAtom *aName)
105 : {
106 0 : if (aName == nsGkAtoms::points)
107 0 : return true;
108 :
109 0 : return false;
110 : }
111 :
112 : void
113 0 : nsSVGPolyElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
114 : {
115 0 : const SVGPointList &points = mPoints.GetAnimValue();
116 :
117 0 : if (!points.Length())
118 0 : return;
119 :
120 0 : float px = 0.0, py = 0.0, prevAngle = 0.0;
121 :
122 0 : for (PRUint32 i = 0; i < points.Length(); ++i) {
123 0 : float x = points[i].mX;
124 0 : float y = points[i].mY;
125 0 : float angle = atan2(y-py, x-px);
126 0 : if (i == 1)
127 0 : aMarks->ElementAt(aMarks->Length() - 1).angle = angle;
128 0 : else if (i > 1)
129 0 : aMarks->ElementAt(aMarks->Length() - 1).angle =
130 0 : nsSVGUtils::AngleBisect(prevAngle, angle);
131 :
132 0 : aMarks->AppendElement(nsSVGMark(x, y, 0));
133 :
134 0 : prevAngle = angle;
135 0 : px = x;
136 0 : py = y;
137 : }
138 :
139 0 : aMarks->ElementAt(aMarks->Length() - 1).angle = prevAngle;
140 : }
141 :
142 : void
143 0 : nsSVGPolyElement::ConstructPath(gfxContext *aCtx)
144 : {
145 0 : const SVGPointList &points = mPoints.GetAnimValue();
146 :
147 0 : if (!points.Length())
148 0 : return;
149 :
150 0 : aCtx->MoveTo(points[0]);
151 0 : for (PRUint32 i = 1; i < points.Length(); ++i) {
152 0 : aCtx->LineTo(points[i]);
153 : }
154 : }
155 :
|