Skip to content

Commit

Permalink
SVG Import: fix colors
Browse files Browse the repository at this point in the history
RGB(A) are int (0-255) unless %.
  • Loading branch information
rodlie committed Nov 26, 2024
1 parent 2bf8d20 commit ac9eb4f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/svgimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,19 @@ bool toColor(const QString &colorStr, QColor &color)
str.remove(isRGB ? "rgb" : "rgba").remove(";").remove("(").remove(")");
QStringList components = str.split(",", Qt::SkipEmptyParts);
if (components.size() >= 3) {
const bool isFloat = components[0].contains("%") ||
components[1].contains("%") ||
components[2].contains("%");
qreal r = components[0].contains("%") ? components[0].remove("%").simplified().toFloat() / 100. :
components[0].simplified().toFloat();
components[0].simplified().toInt();
qreal g = components[1].contains("%") ? components[1].remove("%").simplified().toFloat() / 100. :
components[1].simplified().toFloat();
components[1].simplified().toInt();
qreal b = components[2].contains("%") ? components[2].remove("%").simplified().toFloat() / 100. :
components[2].simplified().toFloat();
components[2].simplified().toInt();
qreal a = components.size() == 4 ? components[3].contains("%") ? components[3].remove("%").simplified().toFloat() / 100. :
components[3].simplified().toFloat() : 1.0;
color.setRgbF(r, g, b, a);
components[3].simplified().toInt() : (isFloat ? 1.0 : 255);
if (isFloat) { color.setRgbF(r, g, b, a); }
else { color.setRgb(r, g, b, a); }
} else { return false; }
} else {
if (QColor::isValidColor(colorStr.simplified())) { color = QColor(colorStr.simplified()); }
Expand Down

0 comments on commit ac9eb4f

Please sign in to comment.