1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// SPDX-FileCopyrightText: 2006-2012 Torsten Rahn <tackat@kde.org>
// SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
//
#include "svgxmlhandler.h"
#include <QDebug>
SVGXmlHandler::SVGXmlHandler(QDataStream *out, const QString &path, int header)
: m_stream(out)
, m_header(header)
, m_path(path)
{
}
bool SVGXmlHandler::startElement(const QString & /*nspace*/, const QString & /*localName*/, const QString &qName, const QXmlAttributes &atts)
{
if (qName == QLatin1StringView("path") && atts.value("id") == m_path) {
QString coordinates = atts.value("d");
QStringList stringlist;
coordinates.chop(2);
// This requires absolute paths and repeated L commands to
// to be enforced in inkscape!
stringlist << coordinates.mid(1).split(QLatin1Char('L'));
bool firstheader = true;
int count = 0;
qDebug() << "Starting to write path" << atts.value("id");
for (const QString &str : std::as_const(stringlist)) {
float x;
float y;
x = str.section(QLatin1Char(','), 0, 0).toFloat();
y = str.section(QLatin1Char(','), 1, 1).toFloat();
short header;
short lat;
short lng;
if (firstheader) {
header = m_header;
firstheader = false;
} else {
if (stringlist.size() > 14) {
if (count % 9 == 0)
header = 5;
else if (count % 5 == 0)
header = 3;
else if (count % 2 == 0)
header = 2;
else
header = 1;
} else if (stringlist.size() > 6) {
if (count % 2 == 0)
header = 3;
else
header = 1;
} else {
header = 2;
}
}
if (count == stringlist.size() - 1)
header = 5;
lng = (int)(x * 50 - 10800);
lat = -(int)(y * 50 - 5400);
*m_stream << header << lat << lng;
count++;
}
}
return true;
}
|