summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2021-05-16 14:17:27 +0900
committerSlávek Banko <slavek.banko@axis.cz>2021-06-07 14:48:45 +0200
commite374731ad56c7c854863e00dbdc328b2251b2db3 (patch)
tree4291da6f4af427d355f517c728cda3c2158acd14
parentc1883367c372fd293d4a17c7aae6063dd2e81da1 (diff)
downloadtdelibs-e374731ad56c7c854863e00dbdc328b2251b2db3.tar.gz
tdelibs-e374731ad56c7c854863e00dbdc328b2251b2db3.zip
Fixed handling of arcs in non conforming svg files.
This resolves issue TDE/tde#46. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it> (cherry picked from commit 35d3a3c50440b34f0fcc6ed56c630f74de41c32a)
-rw-r--r--kdecore/svgicons/ksvgiconpainter.cpp78
1 files changed, 48 insertions, 30 deletions
diff --git a/kdecore/svgicons/ksvgiconpainter.cpp b/kdecore/svgicons/ksvgiconpainter.cpp
index 0a2e2e2eb..e91b64350 100644
--- a/kdecore/svgicons/ksvgiconpainter.cpp
+++ b/kdecore/svgicons/ksvgiconpainter.cpp
@@ -1743,17 +1743,34 @@ void KSVGIconPainter::drawPath(const TQString &data, bool filled)
double curx = 0.0, cury = 0.0, contrlx = 0.0, contrly = 0.0, xc, yc;
unsigned int lastCommand = 0;
- TQString _d = value.replace(",", " ");
- _d = _d.simplifyWhiteSpace();
- const char *ptr = _d.latin1();
- const char *end = _d.latin1() + _d.length() + 1;
+ TQCString _d = value.replace(",", " ").simplifyWhiteSpace().latin1();
+ const char *ptr = _d.data();
+ const char *end = _d.data() + _d.length();
double tox, toy, x1, y1, x2, y2, rx, ry, angle;
bool largeArc, sweep;
- char command = *(ptr++);
+ char command = *ptr;
while(ptr < end)
{
+
+ if(*ptr == '+' || *ptr == '-' || *ptr == '.' || (*ptr >= '0' && *ptr <= '9'))
+ {
+ // there are still coords in this command
+ if(command == 'M')
+ {
+ command = 'L';
+ }
+ else if(command == 'm')
+ {
+ command = 'l';
+ }
+ }
+ else
+ {
+ command = *(ptr++);
+ }
+
if(*ptr == ' ')
ptr++;
@@ -2179,10 +2196,19 @@ void KSVGIconPainter::drawPath(const TQString &data, bool filled)
ptr = getCoord(ptr, rx);
ptr = getCoord(ptr, ry);
ptr = getCoord(ptr, angle);
- ptr = getCoord(ptr, tox);
- largeArc = tox == 1;
- ptr = getCoord(ptr, tox);
- sweep = tox == 1;
+ // 'largeArc' and 'sweep' are single digit flags. Some non conforming svg files do not
+ // separate those fields with separators, so we can't use getCoord() here.
+ // See TDE/tde issue #46 on TGW
+ largeArc = ((*ptr++) != '0');
+ while (*ptr == ' ')
+ {
+ ptr++;
+ }
+ sweep = ((*ptr++) != '0');
+ while (*ptr == ' ')
+ {
+ ptr++;
+ }
ptr = getCoord(ptr, tox);
ptr = getCoord(ptr, toy);
@@ -2198,10 +2224,19 @@ void KSVGIconPainter::drawPath(const TQString &data, bool filled)
ptr = getCoord(ptr, rx);
ptr = getCoord(ptr, ry);
ptr = getCoord(ptr, angle);
- ptr = getCoord(ptr, tox);
- largeArc = tox == 1;
- ptr = getCoord(ptr, tox);
- sweep = tox == 1;
+ // 'largeArc' and 'sweep' are single digit flags. Some non conforming svg files do not
+ // separate those fields with separators, so we can't use getCoord() here.
+ // See TDE/tde issue #46 on TGW
+ largeArc = ((*ptr++) != '0');
+ while (*ptr == ' ')
+ {
+ ptr++;
+ }
+ sweep = ((*ptr++) != '0');
+ while (*ptr == ' ')
+ {
+ ptr++;
+ }
ptr = getCoord(ptr, tox);
ptr = getCoord(ptr, toy);
@@ -2215,23 +2250,6 @@ void KSVGIconPainter::drawPath(const TQString &data, bool filled)
break;
}
- if(*ptr == '+' || *ptr == '-' || *ptr == '.' || (*ptr >= '0' && *ptr <= '9'))
- {
- // there are still coords in this command
- if(command == 'M')
- {
- command = 'L';
- }
- else if(command == 'm')
- {
- command = 'l';
- }
- }
- else
- {
- command = *(ptr++);
- }
-
// Detect reflection points
if(lastCommand != 'C' && lastCommand != 'c' &&
lastCommand != 'S' && lastCommand != 's' &&