File indexing completed on 2024-12-08 06:36:05
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2006-2012 Torsten Rahn <tackat@kde.org> 0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org> 0005 // 0006 0007 0008 #include "svgxmlhandler.h" 0009 #include <QDebug> 0010 0011 SVGXmlHandler::SVGXmlHandler( QDataStream * out, const QString & path, int header ) 0012 : m_stream(out), 0013 m_header(header), 0014 m_path(path) 0015 { 0016 } 0017 0018 bool SVGXmlHandler::startElement(const QString& /*nspace*/, 0019 const QString& /*localName*/, 0020 const QString& qName, 0021 const QXmlAttributes &atts) 0022 { 0023 if (qName == QLatin1String("path") && atts.value("id") == m_path) { 0024 QString coordinates = atts.value( "d" ); 0025 0026 QStringList stringlist; 0027 coordinates.chop(2); 0028 0029 // This requires absolute paths and repeated L commands to 0030 // to be enforced in inkscape! 0031 stringlist << coordinates.mid(1).split(QLatin1Char('L')); 0032 bool firstheader = true; 0033 0034 int count = 0; 0035 qDebug() << "Starting to write path" << atts.value( "id" ); 0036 for ( const QString& str: stringlist ) { 0037 float x; 0038 float y; 0039 x = str.section(QLatin1Char(','), 0, 0).toFloat(); 0040 y = str.section(QLatin1Char(','), 1, 1).toFloat(); 0041 0042 short header; 0043 short lat; 0044 short lng; 0045 0046 if ( firstheader ) { 0047 header = m_header; 0048 firstheader = false; 0049 } 0050 else { 0051 if ( stringlist.size() > 14 ) { 0052 if ( count % 9 == 0 ) 0053 header = 5; 0054 else if ( count % 5 == 0 ) 0055 header = 3; 0056 else if ( count % 2 == 0 ) 0057 header = 2; 0058 else 0059 header = 1; 0060 } 0061 else if ( stringlist.size() > 6 ) { 0062 if ( count % 2 == 0 ) 0063 header = 3; 0064 else 0065 header = 1; 0066 } 0067 else { 0068 header = 2; 0069 } 0070 } 0071 if ( count == stringlist.size() - 1 ) 0072 header = 5; 0073 0074 lng = (int)( x * 50 - 10800 ); 0075 lat = -(int)( y * 50 - 5400 ); 0076 0077 *m_stream << header << lat << lng; 0078 count++; 0079 } 0080 } 0081 0082 return true; 0083 }