filters

svgimport.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, The Karbon Developers
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 #ifndef __SVGIMPORT_H__
00021 #define __SVGIMPORT_H__
00022 
00023 #include <KoFilter.h>
00024 #include <qdom.h>
00025 #include <qmap.h>
00026 #include <qptrstack.h>
00027 #include <core/vdocument.h>
00028 #include <core/vgradient.h>
00029 #include <core/vfill.h>
00030 #include <core/vstroke.h>
00031 #include <core/vfillrule.h>
00032 #include "svggraphiccontext.h"
00033 
00034 #include <vobject.h>
00035 
00036 class VGroup;
00037 class VPath;
00038 
00039 class SvgImport : public KoFilter
00040 {
00041     Q_OBJECT
00042 
00043 public:
00044     SvgImport(KoFilter *parent, const char *name, const QStringList&);
00045     virtual ~SvgImport();
00046 
00047     virtual KoFilter::ConversionStatus convert(const QCString& from, const QCString& to);
00048 
00049 protected:
00050     class GradientHelper
00051     {
00052     public:
00053         GradientHelper()
00054         {
00055             bbox = true;
00056         }
00057         VGradient   gradient;
00058         bool        bbox;
00059         QWMatrix    gradientTransform;
00060     };
00061 
00062     void parseGroup( VGroup *, const QDomElement & );
00063     void parseDefs( const QDomElement & );
00064     void parseUse( VGroup *, const QDomElement & );
00065     void parseStyle( VObject *, const QDomElement & );
00066     void parsePA( VObject *, SvgGraphicsContext *, const QString &, const QString & );
00067     void parseGradient( const QDomElement &, const QDomElement &referencedBy = QDomElement() );
00068     void parseColorStops( VGradient *, const QDomElement & );
00069     double parseUnit( const QString &, bool horiz = false, bool vert = false, KoRect bbox = KoRect() );
00070     void parseColor( VColor &, const QString & );
00071     QColor parseColor( const QString & );
00072     double toPercentage( QString );
00073     double fromPercentage( QString );
00074     void setupTransform( const QDomElement & );
00075     void addGraphicContext();
00076     QDomDocument inpdoc;
00077     QDomDocument outdoc;
00078     void convert();
00079     void createObject( VGroup *grp, const QDomElement &, VObject::VState state = VObject::normal, const QDomElement &style = QDomElement() );
00080     void createText( VGroup *, const QDomElement & );
00081     void parseFont( const QDomElement & );
00082     // find object with given id in document
00083     VObject* findObject( const QString &name );
00084     // find object with given id in given group
00085     VObject* findObject( const QString &name, VGroup * );
00086     // find gradient with given id in gradient map
00087     GradientHelper* findGradient( const QString &id, const QString &href = 0 );
00088 
00089     // Determine scaling factor from given matrix
00090     double getScalingFromMatrix( QWMatrix &matrix );
00091 
00092     QDomElement mergeStyles( const QDomElement &, const QDomElement & );
00093 
00094 private:
00095     VDocument                       m_document;
00096     QPtrStack<SvgGraphicsContext>   m_gc;
00097     QMap<QString, GradientHelper>   m_gradients;
00098     QMap<QString, QDomElement>      m_defs;
00099     KoRect                          m_outerRect;
00100 };
00101 
00102 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys