kivio

diapathparser.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003, The Kivio 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 #include "diapathparser.h"
00021 
00022 DiaPointFinder::DiaPointFinder(QValueList<float> *xlist,  QValueList<float> *ylist) :
00023     SVGPathParser(), m_xlist(xlist), m_ylist(ylist)
00024 {
00025     ;
00026 }
00027 
00028 void DiaPointFinder::svgMoveTo( double x1, double y1, bool )
00029 {
00030     m_xlist->append(x1);
00031     m_ylist->append(y1);
00032 }
00033 void DiaPointFinder::svgLineTo( double x1, double y1, bool )
00034 {
00035     m_xlist->append(x1);
00036     m_ylist->append(y1);
00037 }
00038 void DiaPointFinder::svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool )
00039 {
00040     m_xlist->append(x1);
00041     m_ylist->append(y1);
00042     m_xlist->append(x2);
00043     m_ylist->append(y2);
00044     m_xlist->append(x3);
00045     m_ylist->append(y3);
00046 }
00047 void DiaPointFinder::svgClosePath()
00048 {
00049 
00050 }
00051 DiaPathParser::DiaPathParser(QDomDocument *doc, QDomElement *shape, float xscale, float yscale, float lowestx, float lowesty) :
00052     SVGPathParser(), m_doc(doc), m_shape(shape),
00053     m_xscale(xscale), m_yscale(yscale),
00054     m_lowestx(lowestx), m_lowesty(lowesty)
00055 {
00056     lastX = 0.0;
00057     lastY = 0.0;
00058 }
00059 
00060 void DiaPathParser::svgMoveTo( double x1, double y1, bool )
00061 {
00062     lastX = x1;
00063     lastY = y1;
00064 }
00065 void DiaPathParser::svgLineTo( double x1, double y1, bool )
00066 {
00067     // Line
00068     float currentX = x1;
00069     float currentY = y1;
00070 
00071     // Create the line
00072     QDomElement kivioPointElement = m_doc->createElement("KivioPoint");
00073     kivioPointElement.setAttribute("x", QString::number(diaPointToKivio(lastX,true) * m_xscale));
00074     kivioPointElement.setAttribute("y", QString::number(diaPointToKivio(lastY, false) * m_yscale));
00075     m_shape->appendChild(kivioPointElement);
00076 
00077     kivioPointElement = m_doc->createElement("KivioPoint");
00078     kivioPointElement.setAttribute("x", QString::number(diaPointToKivio(currentX,true) * m_xscale));
00079     kivioPointElement.setAttribute("y", QString::number(diaPointToKivio(currentY, false) * m_yscale));
00080     m_shape->appendChild(kivioPointElement);
00081     lastX = currentX;
00082     lastY = currentY;
00083 }
00084 
00085 void DiaPathParser::svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool )
00086 {
00087     // Spline
00088     float lastControlX = x1;
00089     float lastControlY = y1;
00090     float currentControlX = x2;
00091     float currentControlY = y2;
00092     float currentX = x3;
00093     float currentY = y3;
00094 
00095     // Create the bezier
00096     QDomElement kivioPointElement = m_doc->createElement("KivioPoint");
00097     kivioPointElement.setAttribute("x",
00098         QString::number(diaPointToKivio(lastX,true) * m_xscale));
00099     kivioPointElement.setAttribute("y",
00100         QString::number(diaPointToKivio(lastY, false) * m_yscale));
00101     kivioPointElement.setAttribute("type", "bezier");
00102     m_shape->appendChild(kivioPointElement);
00103 
00104     kivioPointElement = m_doc->createElement("KivioPoint");
00105     kivioPointElement.setAttribute("x",
00106         QString::number(diaPointToKivio(lastControlX,true) * m_xscale));
00107     kivioPointElement.setAttribute("y",
00108         QString::number(diaPointToKivio(lastControlY, false) * m_yscale));
00109     kivioPointElement.setAttribute("type", "bezier");
00110     m_shape->appendChild(kivioPointElement);
00111 
00112     kivioPointElement = m_doc->createElement("KivioPoint");
00113     kivioPointElement.setAttribute("x",
00114             QString::number(diaPointToKivio(currentControlX,true) * m_xscale));
00115     kivioPointElement.setAttribute("y",
00116         QString::number(diaPointToKivio(currentControlY, false) * m_yscale));
00117     kivioPointElement.setAttribute("type", "bezier");
00118     m_shape->appendChild(kivioPointElement);
00119 
00120     kivioPointElement = m_doc->createElement("KivioPoint");
00121     kivioPointElement.setAttribute("x",
00122         QString::number(diaPointToKivio(currentX,true) * m_xscale));
00123     kivioPointElement.setAttribute("y",
00124         QString::number(diaPointToKivio(currentY, false) * m_yscale));
00125     kivioPointElement.setAttribute("type", "bezier");
00126     m_shape->appendChild(kivioPointElement);
00127     lastX = currentX;
00128     lastY = currentY;
00129 }
00130 void DiaPathParser::svgClosePath()
00131 {
00132 
00133 }
00134 float DiaPathParser::diaPointToKivio(float point, bool xpoint)
00135 {
00136     if(xpoint)
00137         return point - m_lowestx;
00138     else
00139         return point - m_lowesty;
00140 }
KDE Home | KDE Accessibility Home | Description of Access Keys