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

KHTML

SVGPathSegList.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
00003                   2004, 2005 Rob Buis <buis@kde.org>
00004     Copyright (C) 2007 Eric Seidel <eric@webkit.org>
00005  
00006     This file is part of the WebKit project
00007  
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "config.h"
00025 #include "wtf/Platform.h"
00026 
00027 #if ENABLE(SVG)
00028 #include "SVGPathSegList.h"
00029 
00030 #include "FloatPoint.h"
00031 #include "Path.h"
00032 #include "PathTraversalState.h"
00033 #include "SVGPathSegMoveto.h"
00034 #include "SVGPathSegLineto.h"
00035 #include "SVGPathSegCurvetoCubic.h"
00036 
00037 namespace WebCore {
00038 
00039 SVGPathSegList::SVGPathSegList(const QualifiedName& attributeName)
00040     : SVGList<RefPtr<SVGPathSeg> >(attributeName)
00041 {
00042 }
00043 
00044 SVGPathSegList::~SVGPathSegList()
00045 {
00046 }
00047 
00048 unsigned SVGPathSegList::getPathSegAtLength(double)
00049 {
00050     // FIXME : to be useful this will need to support non-normalized SVGPathSegLists
00051     ExceptionCode ec = 0;
00052     int len = numberOfItems();
00053     // FIXME: Eventually this will likely move to a "path applier"-like model, until then PathTraversalState is less useful as we could just use locals
00054     PathTraversalState traversalState(PathTraversalState::TraversalSegmentAtLength);
00055     for (int i = 0; i < len; ++i) {
00056         SVGPathSeg* segment = getItem(i, ec).get();
00057         float segmentLength = 0;
00058         switch (segment->pathSegType()) {
00059         case SVGPathSeg::PATHSEG_MOVETO_ABS:
00060         {
00061             SVGPathSegMovetoAbs* moveTo = static_cast<SVGPathSegMovetoAbs*>(segment);
00062             segmentLength = traversalState.moveTo(FloatPoint(moveTo->x(), moveTo->y()));
00063             break;
00064         }
00065         case SVGPathSeg::PATHSEG_LINETO_ABS:
00066         {
00067             SVGPathSegLinetoAbs* lineTo = static_cast<SVGPathSegLinetoAbs*>(segment);
00068             segmentLength = traversalState.lineTo(FloatPoint(lineTo->x(), lineTo->y()));
00069             break;
00070         }
00071         case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
00072         {
00073             SVGPathSegCurvetoCubicAbs* curveTo = static_cast<SVGPathSegCurvetoCubicAbs*>(segment);
00074             segmentLength = traversalState.cubicBezierTo(FloatPoint(curveTo->x1(), curveTo->y1()),
00075                                       FloatPoint(curveTo->x2(), curveTo->y2()),
00076                                       FloatPoint(curveTo->x(), curveTo->y()));
00077             break;
00078         }
00079         case SVGPathSeg::PATHSEG_CLOSEPATH:
00080             segmentLength = traversalState.closeSubpath();
00081             break;
00082         default:
00083             ASSERT(false); // FIXME: This only works with normalized/processed path data.
00084             break;
00085         }
00086         traversalState.m_totalLength += segmentLength;
00087         if ((traversalState.m_action == PathTraversalState::TraversalSegmentAtLength)
00088             && (traversalState.m_totalLength > traversalState.m_desiredLength)) {
00089             return traversalState.m_segmentIndex;
00090         }
00091         traversalState.m_segmentIndex++;
00092     }
00093     
00094     return 0; // The SVG spec is unclear as to what to return when the distance is not on the path    
00095 }
00096 
00097 khtml::Path SVGPathSegList::toPathData()
00098 {
00099     // FIXME : This should also support non-normalized PathSegLists
00100     Path pathData;
00101     ExceptionCode ec = 0;
00102     int len = numberOfItems();
00103     for (int i = 0; i < len; ++i) {
00104         SVGPathSeg* segment = getItem(i, ec).get();;
00105         switch (segment->pathSegType())
00106         {
00107             case SVGPathSeg::PATHSEG_MOVETO_ABS:
00108             {
00109                 SVGPathSegMovetoAbs* moveTo = static_cast<SVGPathSegMovetoAbs*>(segment);
00110                 pathData.moveTo(FloatPoint(moveTo->x(), moveTo->y()));
00111                 break;
00112             }
00113             case SVGPathSeg::PATHSEG_LINETO_ABS:
00114             {
00115                 SVGPathSegLinetoAbs* lineTo = static_cast<SVGPathSegLinetoAbs*>(segment);
00116                 pathData.addLineTo(FloatPoint(lineTo->x(), lineTo->y()));
00117                 break;
00118             }
00119             case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
00120             {
00121                 SVGPathSegCurvetoCubicAbs* curveTo = static_cast<SVGPathSegCurvetoCubicAbs*>(segment);
00122                 pathData.addBezierCurveTo(FloatPoint(curveTo->x1(), curveTo->y1()),
00123                                           FloatPoint(curveTo->x2(), curveTo->y2()),
00124                                           FloatPoint(curveTo->x(), curveTo->y()));
00125                 break;
00126             }
00127             case SVGPathSeg::PATHSEG_CLOSEPATH:
00128                 pathData.closeSubpath();
00129                 break;
00130             default:
00131                 ASSERT(false); // FIXME: This only works with normalized/processed path data.
00132                 break;
00133         }
00134     }
00135     
00136     return pathData;
00137 }
00138 
00139 }
00140 
00141 #endif // ENABLE(SVG)

KHTML

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal