修改了一些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; return resStyleMap;
} }
QVector<QPointF> SvgFileLoader::transformPoints(QString points) { QPolygonF SvgFileLoader::transformPoints(QString points) {
QVector<QPointF> resPointVector; QPolygonF resPointVector;
QPointF pointBegin(0, 0); QPointF point(0, 0);
bool isX = true;
for (auto& onePoint : points.split(' ')) { for (auto& onePoint : points.split(' ')) {
QString x = *(onePoint.split(',').begin()); for (auto& value : onePoint.split(',')) {
QString y = *(onePoint.split(',').rbegin()); if (value.trimmed().isEmpty()) continue;
resPointVector.push_back(QPointF(x.toDouble(), y.toDouble())); if (isX) point.setX(value.toDouble());
else {
point.setY(value.toDouble());
resPointVector.push_back(point);
}
isX = !isX;
}
} }
return resPointVector; return resPointVector;
} }
@ -79,6 +85,9 @@ void SvgFileLoader::handleLabelG(QPainterPath& painterPath) {
if (attr.name().toString() == QLatin1String("style")) { if (attr.name().toString() == QLatin1String("style")) {
styleMap = transformStyle(attr.value().toLatin1()); styleMap = transformStyle(attr.value().toLatin1());
} }
else {
styleMap.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
} }
existFatherLabelG = true; existFatherLabelG = true;
qDebug() << styleMap; qDebug() << styleMap;
@ -90,9 +99,12 @@ void SvgFileLoader::handleLabelPath(QPainterPath& painterPath) {
if (attr.name().toString() == QLatin1String("d")) { if (attr.name().toString() == QLatin1String("d")) {
QQuickSvgParser::parsePathDataFast(attr.value().toLatin1(), painterPath); QQuickSvgParser::parsePathDataFast(attr.value().toLatin1(), painterPath);
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); 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()) { for (auto& attr : xmlReader->attributes()) {
if (attr.name().toString() == QLatin1String("x")) { if (attr.name().toString() == QLatin1String("x")) {
xBegin = attr.value().toDouble(); xBegin = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("y")) {
if (attr.name().toString() == QLatin1String("y")) {
yBegin = attr.value().toDouble(); yBegin = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("width")) {
if (attr.name().toString() == QLatin1String("width")) {
width = attr.value().toDouble(); width = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("height")) {
if (attr.name().toString() == QLatin1String("height")) {
height = attr.value().toDouble(); height = attr.value().toDouble();
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
} }
}
qDebug() << labelStyle;
painterPath.addRect(xBegin, yBegin, xBegin + width, yBegin + height); painterPath.addRect(xBegin, yBegin, xBegin + width, yBegin + height);
} }
@ -125,17 +138,19 @@ void SvgFileLoader::handleLabelCircle(QPainterPath& painterPath) {
for (auto& attr : xmlReader->attributes()) { for (auto& attr : xmlReader->attributes()) {
if (attr.name().toString() == QLatin1String("cx")) { if (attr.name().toString() == QLatin1String("cx")) {
cx = attr.value().toDouble(); cx = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("cy")) {
if (attr.name().toString() == QLatin1String("cy")) {
cy = attr.value().toDouble(); cy = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("r")) {
if (attr.name().toString() == QLatin1String("r")) {
r = attr.value().toDouble(); r = attr.value().toDouble();
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
} }
}
qDebug() << labelStyle;
painterPath.addEllipse(cx, cy, r, r); painterPath.addEllipse(cx, cy, r, r);
} }
@ -145,20 +160,20 @@ void SvgFileLoader::handleLabelEllipse(QPainterPath& painterPath) {
for (auto& attr : xmlReader->attributes()) { for (auto& attr : xmlReader->attributes()) {
if (attr.name().toString() == QLatin1String("cx")) { if (attr.name().toString() == QLatin1String("cx")) {
cx = attr.value().toDouble(); cx = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("cy")) {
if (attr.name().toString() == QLatin1String("cy")) {
cy = attr.value().toDouble(); cy = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("rx")) {
if (attr.name().toString() == QLatin1String("rx")) {
rx = attr.value().toDouble(); rx = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("ry")) {
if (attr.name().toString() == QLatin1String("ry")) {
rx = attr.value().toDouble(); rx = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("style")) {
if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
} }
}
qDebug() << labelStyle;
painterPath.addEllipse(cx, cy, rx, ry); painterPath.addEllipse(cx, cy, rx, ry);
} }
@ -169,11 +184,15 @@ void SvgFileLoader::handleLabelPolyline(QPainterPath& painterPath) {
QPolygonF points = transformPoints(attr.value().toLatin1()); QPolygonF points = transformPoints(attr.value().toLatin1());
painterPath.addPolygon(points); painterPath.addPolygon(points);
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
} }
} }
qDebug() << labelStyle;
}
void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) { void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) {
QMap<QString, QString> labelStyle; QMap<QString, QString> labelStyle;
@ -183,8 +202,12 @@ void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) {
points.push_back(*points.begin()); points.push_back(*points.begin());
painterPath.addPolygon(points); painterPath.addPolygon(points);
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); 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; bool existFatherLabelG;
QMap<QString, QString> styleMap; QMap<QString, QString> styleMap;
std::shared_ptr<QXmlStreamReader> xmlReader; std::shared_ptr<QXmlStreamReader> xmlReader;
QVector<QPointF> transformPoints(QString points); QPolygonF transformPoints(QString points);
QMap<QString, QString> transformStyle(QString style); QMap<QString, QString> transformStyle(QString style);
void handleLabelG(QPainterPath& painterPath); void handleLabelG(QPainterPath& painterPath);
void handleLabelPath(QPainterPath& painterPath); void handleLabelPath(QPainterPath& painterPath);

View File

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