kpresenter

KPrSVGPathParser.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "KPrSVGPathParser.h"
00021 
00022 
00023 ObjType KPrSVGPathParser::getType( QString &d )
00024 {
00025     m_type = true;
00026     m_pathType = 0;
00027     ObjType objType = OT_UNDEFINED;
00028     parseSVG( d, true );
00029     if ( m_pathType & UNSUPPORTED )
00030     {
00031         objType = OT_UNDEFINED;
00032     }
00033     else if ( m_pathType & SEEN_CLOSE )
00034     {
00035         objType = OT_CLOSED_LINE;
00036     }
00037     else if ( m_pathType & NO_BEZIER )
00038     {
00039         objType = OT_FREEHAND;
00040     }
00041     else if ( ( m_pathType & SEEN_QUADRIC ) && ! ( m_pathType & SEEN_CUBIC ) )
00042     {
00043         objType = OT_QUADRICBEZIERCURVE;
00044     }
00045     else if ( m_pathType & SEEN_CUBIC )
00046     {
00047         objType = OT_CUBICBEZIERCURVE;
00048     }
00049     return objType;
00050 }
00051 
00052 
00053 KoPointArray KPrSVGPathParser::getPoints( QString &d, bool convert2lines )
00054 {
00055     m_type = false;
00056     m_pointIdx = 0;
00057     m_convert2lines = convert2lines;
00058     parseSVG( d, true );
00059     return m_points;
00060 }
00061 
00062 
00063 void KPrSVGPathParser::svgMoveTo( double x1, double y1, bool /*abs*/ )
00064 {
00065     if ( m_type )
00066     {
00067         if ( m_pathType != 0 )
00068         {
00069             m_pathType |= UNSUPPORTED;
00070         }
00071         else
00072         {
00073             m_pathType |= SEEN_MOVE;
00074         }
00075     }
00076     else
00077     {
00078         m_curPoint = KoPoint( x1, y1 );
00079     }
00080 }
00081 
00082 
00083 void KPrSVGPathParser::svgLineTo( double x1, double y1, bool /*abs*/ )
00084 {
00085     if ( m_type )
00086     {
00087         if ( m_pathType & SEEN_MOVE )
00088         {
00089             if ( m_pathType & SEEN_LINE )
00090             {
00091                 m_pathType |= NO_BEZIER;
00092             }
00093             m_pathType |= SEEN_LINE;
00094         }
00095         else
00096         {
00097             m_pathType |= UNSUPPORTED;
00098         }
00099     }
00100     else
00101     {
00102         m_points.putPoints( m_pointIdx, 2, m_curPoint.x(), m_curPoint.y(), x1, y1 );
00103         m_curPoint = KoPoint( x1, y1 );
00104         m_pointIdx += 2; 
00105     }
00106 }
00107 
00108 
00109 void KPrSVGPathParser::svgCurveToCubic(  double x1, double y1, double x2, double y2, double x, double y, bool /*abs*/ )
00110 {
00111     if ( m_type )
00112     {
00113         if ( m_pathType & SEEN_MOVE )
00114         {
00115             if ( m_pathType & SEEN_LINE )
00116             {
00117                 m_pathType |= NO_BEZIER;
00118             }
00119 
00120             if ( x1 == x2 && y1 == y2 )
00121             {
00122                 m_pathType |= SEEN_QUADRIC;
00123             }
00124             else
00125             {
00126                 m_pathType |= SEEN_CUBIC;
00127             }
00128         }
00129         else
00130         {
00131             m_pathType |= UNSUPPORTED;
00132         }
00133     }
00134     else
00135     {
00136         if ( m_convert2lines )
00137         {
00138             KoPointArray bezierPoints;
00139             bezierPoints.putPoints( 0, 4, m_curPoint.x(), m_curPoint.y(), x1, y1, x2, y2, x, y );
00140 
00141             bezierPoints = bezierPoints.cubicBezier();
00142             KoPointArray::ConstIterator it;
00143             for ( it = bezierPoints.begin(); it != bezierPoints.end(); ++it ) 
00144             {
00145                 KoPoint point = (*it);
00146                 m_points.putPoints( m_pointIdx, 1, point.x(), point.y() );
00147                 ++m_pointIdx;
00148             }
00149         }
00150         else
00151         {
00152             m_points.putPoints( m_pointIdx, 4, m_curPoint.x(), m_curPoint.y(), x, y, x1, y1, x2, y2 );
00153             m_pointIdx += 4; 
00154         }
00155         m_curPoint = KoPoint( x, y );
00156     }
00157 }
00158 
00159 
00160 // TODO
00161 void KPrSVGPathParser::svgClosePath()
00162 {
00163     if ( m_type )
00164     {
00165         if ( m_pathType & SEEN_CLOSE )
00166         {
00167             m_pathType |= UNSUPPORTED;
00168         }
00169         else
00170         {
00171             m_pathType |= SEEN_CLOSE;
00172         }
00173     }
00174     else
00175     {
00176     }
00177 }
00178 
00179 
KDE Home | KDE Accessibility Home | Description of Access Keys