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
18 : * Crocodile Clips Ltd..
19 : * Portions created by the Initial Developer are Copyright (C) 2001
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "nsSVGPolyElement.h"
40 : #include "nsIDOMSVGPolygonElement.h"
41 : #include "gfxContext.h"
42 : #include "nsSVGUtils.h"
43 :
44 : typedef nsSVGPolyElement nsSVGPolygonElementBase;
45 :
46 : class nsSVGPolygonElement : public nsSVGPolygonElementBase,
47 : public nsIDOMSVGPolygonElement
48 0 : {
49 : protected:
50 : friend nsresult NS_NewSVGPolygonElement(nsIContent **aResult,
51 : already_AddRefed<nsINodeInfo> aNodeInfo);
52 : nsSVGPolygonElement(already_AddRefed<nsINodeInfo> aNodeInfo);
53 :
54 : public:
55 : // interfaces:
56 :
57 : NS_DECL_ISUPPORTS_INHERITED
58 : NS_DECL_NSIDOMSVGPOLYGONELEMENT
59 :
60 : // xxx I wish we could use virtual inheritance
61 0 : NS_FORWARD_NSIDOMNODE(nsSVGPolygonElementBase::)
62 0 : NS_FORWARD_NSIDOMELEMENT(nsSVGPolygonElementBase::)
63 0 : NS_FORWARD_NSIDOMSVGELEMENT(nsSVGPolygonElementBase::)
64 :
65 : // nsSVGPathGeometryElement methods:
66 : virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
67 : virtual void ConstructPath(gfxContext *aCtx);
68 :
69 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
70 :
71 : virtual nsXPCClassInfo* GetClassInfo();
72 : };
73 :
74 0 : NS_IMPL_NS_NEW_SVG_ELEMENT(Polygon)
75 :
76 : //----------------------------------------------------------------------
77 : // nsISupports methods
78 :
79 0 : NS_IMPL_ADDREF_INHERITED(nsSVGPolygonElement,nsSVGPolygonElementBase)
80 0 : NS_IMPL_RELEASE_INHERITED(nsSVGPolygonElement,nsSVGPolygonElementBase)
81 :
82 0 : DOMCI_NODE_DATA(SVGPolygonElement, nsSVGPolygonElement)
83 :
84 0 : NS_INTERFACE_TABLE_HEAD(nsSVGPolygonElement)
85 0 : NS_NODE_INTERFACE_TABLE5(nsSVGPolygonElement, nsIDOMNode, nsIDOMElement,
86 : nsIDOMSVGElement, nsIDOMSVGTests,
87 : nsIDOMSVGPolygonElement)
88 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGPolygonElement)
89 0 : NS_INTERFACE_MAP_END_INHERITING(nsSVGPolygonElementBase)
90 :
91 : //----------------------------------------------------------------------
92 : // Implementation
93 :
94 0 : nsSVGPolygonElement::nsSVGPolygonElement(already_AddRefed<nsINodeInfo> aNodeInfo)
95 0 : : nsSVGPolygonElementBase(aNodeInfo)
96 : {
97 :
98 0 : }
99 :
100 : //----------------------------------------------------------------------
101 : // nsIDOMNode methods
102 :
103 0 : NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGPolygonElement)
104 :
105 : //----------------------------------------------------------------------
106 : // nsSVGPathGeometryElement methods
107 :
108 : void
109 0 : nsSVGPolygonElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
110 : {
111 0 : nsSVGPolyElement::GetMarkPoints(aMarks);
112 0 : if (aMarks->Length() > 0) {
113 0 : nsSVGMark *endMark = &aMarks->ElementAt(aMarks->Length()-1);
114 0 : nsSVGMark *startMark = &aMarks->ElementAt(0);
115 0 : float angle = atan2(startMark->y - endMark->y, startMark->x - endMark->x);
116 :
117 0 : endMark->angle = nsSVGUtils::AngleBisect(angle, endMark->angle);
118 0 : startMark->angle = nsSVGUtils::AngleBisect(angle, startMark->angle);
119 : // for a polygon (as opposed to a polyline) there's an implicit extra point
120 : // co-located with the start point that nsSVGPolyElement::GetMarkPoints
121 : // doesn't return
122 0 : aMarks->AppendElement(nsSVGMark(startMark->x, startMark->y, startMark->angle));
123 : }
124 0 : }
125 :
126 : void
127 0 : nsSVGPolygonElement::ConstructPath(gfxContext *aCtx)
128 : {
129 0 : nsSVGPolygonElementBase::ConstructPath(aCtx);
130 : // the difference between a polyline and a polygon is that the
131 : // polygon is closed:
132 0 : aCtx->ClosePath();
133 0 : }
134 :
135 :
|