修改了一些Bug

dev-VirtualTexture
yang.yongquan 2023-01-19 12:58:06 +08:00
parent 3efb7973b0
commit e19aac0dd2
3 changed files with 62 additions and 39 deletions

View File

@ -62,14 +62,20 @@ QMap<QString, QString> SvgFileLoader::transformStyle(QString style) {
return resStyleMap;
}
QVector<QPointF> SvgFileLoader::transformPoints(QString points) {
QVector<QPointF> resPointVector;
QPointF pointBegin(0, 0);
QPolygonF SvgFileLoader::transformPoints(QString points) {
QPolygonF resPointVector;
QPointF point(0, 0);
bool isX = true;
for (auto& onePoint : points.split(' ')) {
QString x = *(onePoint.split(',').begin());
QString y = *(onePoint.split(',').rbegin());
resPointVector.push_back(QPointF(x.toDouble(), y.toDouble()));
for (auto& value : onePoint.split(',')) {
if (value.trimmed().isEmpty()) continue;
if (isX) point.setX(value.toDouble());
else {
point.setY(value.toDouble());
resPointVector.push_back(point);
}
isX = !isX;
}
}
return resPointVector;
}
@ -79,6 +85,9 @@ void SvgFileLoader::handleLabelG(QPainterPath& painterPath) {
if (attr.name().toString() == QLatin1String("style")) {
styleMap = transformStyle(attr.value().toLatin1());
}
else {
styleMap.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
}
existFatherLabelG = true;
qDebug() << styleMap;
@ -90,9 +99,12 @@ void SvgFileLoader::handleLabelPath(QPainterPath& painterPath) {
if (attr.name().toString() == QLatin1String("d")) {
QQuickSvgParser::parsePathDataFast(attr.value().toLatin1(), painterPath);
}
if (attr.name().toString() == QLatin1String("style")) {
else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1());
}
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
}
}
@ -102,20 +114,21 @@ void SvgFileLoader::handleLabelRect(QPainterPath& painterPath) {
for (auto& attr : xmlReader->attributes()) {
if (attr.name().toString() == QLatin1String("x")) {
xBegin = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("y")) {
} else if (attr.name().toString() == QLatin1String("y")) {
yBegin = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("width")) {
} else if (attr.name().toString() == QLatin1String("width")) {
width = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("height")) {
} else if (attr.name().toString() == QLatin1String("height")) {
height = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("style")) {
else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1());
}
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
}
qDebug() << labelStyle;
painterPath.addRect(xBegin, yBegin, xBegin + width, yBegin + height);
}
@ -125,17 +138,19 @@ void SvgFileLoader::handleLabelCircle(QPainterPath& painterPath) {
for (auto& attr : xmlReader->attributes()) {
if (attr.name().toString() == QLatin1String("cx")) {
cx = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("cy")) {
} else if (attr.name().toString() == QLatin1String("cy")) {
cy = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("r")) {
} else if (attr.name().toString() == QLatin1String("r")) {
r = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("style")) {
else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1());
}
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
}
qDebug() << labelStyle;
painterPath.addEllipse(cx, cy, r, r);
}
@ -145,20 +160,20 @@ void SvgFileLoader::handleLabelEllipse(QPainterPath& painterPath) {
for (auto& attr : xmlReader->attributes()) {
if (attr.name().toString() == QLatin1String("cx")) {
cx = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("cy")) {
} else if (attr.name().toString() == QLatin1String("cy")) {
cy = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("rx")) {
} else if (attr.name().toString() == QLatin1String("rx")) {
rx = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("ry")) {
} else if (attr.name().toString() == QLatin1String("ry")) {
rx = attr.value().toDouble();
}
if (attr.name().toString() == QLatin1String("style")) {
} else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1());
}
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
}
qDebug() << labelStyle;
painterPath.addEllipse(cx, cy, rx, ry);
}
@ -169,10 +184,14 @@ void SvgFileLoader::handleLabelPolyline(QPainterPath& painterPath) {
QPolygonF points = transformPoints(attr.value().toLatin1());
painterPath.addPolygon(points);
}
if (attr.name().toString() == QLatin1String("style")) {
else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1());
}
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
}
qDebug() << labelStyle;
}
void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) {
@ -182,9 +201,13 @@ void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) {
QPolygonF points = transformPoints(attr.value().toLatin1());
points.push_back(*points.begin());
painterPath.addPolygon(points);
}
if (attr.name().toString() == QLatin1String("style")) {
}
else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1());
}
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
}
qDebug() << labelStyle;
}

View File

@ -13,7 +13,7 @@ private:
bool existFatherLabelG;
QMap<QString, QString> styleMap;
std::shared_ptr<QXmlStreamReader> xmlReader;
QVector<QPointF> transformPoints(QString points);
QPolygonF transformPoints(QString points);
QMap<QString, QString> transformStyle(QString style);
void handleLabelG(QPainterPath& painterPath);
void handleLabelPath(QPainterPath& painterPath);

View File

@ -2,7 +2,6 @@
#include "Renderer/Painting/CubicBezier.h"
#include <QGuiApplication>
#include <QtWidgets/QApplication>
#include "Editor/third-party modules/util/SvgFileLoader.h"
using Renderer::CubicBezier;
@ -11,11 +10,12 @@ extern "C"
_declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
}
int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
SvgFileLoader svgLoader;
QPainterPath painterPath;
svgLoader.loadSvgFile("D:/login.svg", painterPath);
qDebug() << painterPath;
return 0;
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}