• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
SVGPathSegList.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  2004, 2005 Rob Buis <buis@kde.org>
4  Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 
6  This file is part of the WebKit project
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include "config.h"
25 #include "wtf/Platform.h"
26 
27 #if ENABLE(SVG)
28 #include "SVGPathSegList.h"
29 
30 #include "FloatPoint.h"
31 #include "Path.h"
32 #include "PathTraversalState.h"
33 #include "SVGPathSegMoveto.h"
34 #include "SVGPathSegLineto.h"
35 #include "SVGPathSegCurvetoCubic.h"
36 
37 namespace WebCore {
38 
39 SVGPathSegList::SVGPathSegList(const QualifiedName& attributeName)
40  : SVGList<RefPtr<SVGPathSeg> >(attributeName)
41 {
42 }
43 
44 SVGPathSegList::~SVGPathSegList()
45 {
46 }
47 
48 unsigned SVGPathSegList::getPathSegAtLength(double)
49 {
50  // FIXME : to be useful this will need to support non-normalized SVGPathSegLists
51  ExceptionCode ec = 0;
52  int len = numberOfItems();
53  // FIXME: Eventually this will likely move to a "path applier"-like model, until then PathTraversalState is less useful as we could just use locals
54  PathTraversalState traversalState(PathTraversalState::TraversalSegmentAtLength);
55  for (int i = 0; i < len; ++i) {
56  SVGPathSeg* segment = getItem(i, ec).get();
57  float segmentLength = 0;
58  switch (segment->pathSegType()) {
59  case SVGPathSeg::PATHSEG_MOVETO_ABS:
60  {
61  SVGPathSegMovetoAbs* moveTo = static_cast<SVGPathSegMovetoAbs*>(segment);
62  segmentLength = traversalState.moveTo(FloatPoint(moveTo->x(), moveTo->y()));
63  break;
64  }
65  case SVGPathSeg::PATHSEG_LINETO_ABS:
66  {
67  SVGPathSegLinetoAbs* lineTo = static_cast<SVGPathSegLinetoAbs*>(segment);
68  segmentLength = traversalState.lineTo(FloatPoint(lineTo->x(), lineTo->y()));
69  break;
70  }
71  case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
72  {
73  SVGPathSegCurvetoCubicAbs* curveTo = static_cast<SVGPathSegCurvetoCubicAbs*>(segment);
74  segmentLength = traversalState.cubicBezierTo(FloatPoint(curveTo->x1(), curveTo->y1()),
75  FloatPoint(curveTo->x2(), curveTo->y2()),
76  FloatPoint(curveTo->x(), curveTo->y()));
77  break;
78  }
79  case SVGPathSeg::PATHSEG_CLOSEPATH:
80  segmentLength = traversalState.closeSubpath();
81  break;
82  default:
83  ASSERT(false); // FIXME: This only works with normalized/processed path data.
84  break;
85  }
86  traversalState.m_totalLength += segmentLength;
87  if ((traversalState.m_action == PathTraversalState::TraversalSegmentAtLength)
88  && (traversalState.m_totalLength > traversalState.m_desiredLength)) {
89  return traversalState.m_segmentIndex;
90  }
91  traversalState.m_segmentIndex++;
92  }
93 
94  return 0; // The SVG spec is unclear as to what to return when the distance is not on the path
95 }
96 
97 khtml::Path SVGPathSegList::toPathData()
98 {
99  // FIXME : This should also support non-normalized PathSegLists
100  Path pathData;
101  ExceptionCode ec = 0;
102  int len = numberOfItems();
103  for (int i = 0; i < len; ++i) {
104  SVGPathSeg* segment = getItem(i, ec).get();
105  switch (segment->pathSegType())
106  {
107  case SVGPathSeg::PATHSEG_MOVETO_ABS:
108  {
109  SVGPathSegMovetoAbs* moveTo = static_cast<SVGPathSegMovetoAbs*>(segment);
110  pathData.moveTo(FloatPoint(moveTo->x(), moveTo->y()));
111  break;
112  }
113  case SVGPathSeg::PATHSEG_LINETO_ABS:
114  {
115  SVGPathSegLinetoAbs* lineTo = static_cast<SVGPathSegLinetoAbs*>(segment);
116  pathData.addLineTo(FloatPoint(lineTo->x(), lineTo->y()));
117  break;
118  }
119  case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
120  {
121  SVGPathSegCurvetoCubicAbs* curveTo = static_cast<SVGPathSegCurvetoCubicAbs*>(segment);
122  pathData.addBezierCurveTo(FloatPoint(curveTo->x1(), curveTo->y1()),
123  FloatPoint(curveTo->x2(), curveTo->y2()),
124  FloatPoint(curveTo->x(), curveTo->y()));
125  break;
126  }
127  case SVGPathSeg::PATHSEG_CLOSEPATH:
128  pathData.closeSubpath();
129  break;
130  default:
131  ASSERT(false); // FIXME: This only works with normalized/processed path data.
132  break;
133  }
134  }
135 
136  return pathData;
137 }
138 
139 }
140 
141 #endif // ENABLE(SVG)
SVGPathSegList.h
getItem
QString getItem(const QString &caption, const QString &label, const QStringList &list, int current=0, bool editable=false, bool *ok=0, QWidget *parent=0)
SVGPathSegCurvetoCubic.h
SVGPathSegLineto.h
WebCore::Path
khtml::Path Path
Definition: PathTraversalState.h:37
FloatPoint.h
PathTraversalState.h
SVGPathSegMoveto.h
Path.h
khtml::Path
Definition: Path.h:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal