Painter: Another SVG fix

This commit is contained in:
Mirek Fidler 2025-09-24 09:09:01 +02:00
parent 201f96bb61
commit 14bbbe92f8
4 changed files with 9119 additions and 42 deletions

View file

@ -19,6 +19,7 @@ file
svg\rg1024_Presentation_with_girl.svg,
svg\symbol.svg,
svg\idtest.svg,
svg\wooden-easter-egg-holder.svg,
svg\yinyang.svg;
mainconfig

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 412 KiB

View file

@ -124,6 +124,7 @@ struct SvgParser {
void Items(const XmlNode& n, int depth);
void Element(const XmlNode& n, int depth, bool dosymbols = false);
void ParseGradient(const XmlNode& n, bool radial);
void ParseStyle(const XmlNode& n);
void ResolveGradient(int i);
void MapIds(const XmlNode& n);

View file

@ -238,6 +238,38 @@ void SvgParser::ParseGradient(const XmlNode& n, bool radial)
s.offset = Nvl(StrDbl(m.Attr("offset")), offset);
}
}
void SvgParser::ParseStyle(const XmlNode& n)
{
String text = n.GatherText();
try {
CParser p(text);
while(!p.IsEof()) {
if(p.Char('.') && p.IsId()) {
Vector<String> ids;
String id = p.ReadIdh();
ids.Add(id);
while(p.Char(',') && p.Char('.') && p.IsId()) {
id = p.ReadIdh();
ids.Add(id);
}
if(p.Char('{')) {
const char *b = p.GetPtr();
while(!p.IsChar('}') && !p.IsEof())
p.SkipTerm();
String style(b, p.GetPtr());
for(const String& id : ids)
classes.GetAdd(id) << style;
}
p.Char('}');
}
else
p.SkipTerm();
}
}
catch(CParser::Error) {}
}
void SvgParser::Poly(const XmlNode& n, bool line)
{
@ -356,27 +388,9 @@ void SvgParser::Element(const XmlNode& n, int depth, bool dosymbols)
else
if(m.IsTag("radialGradient"))
ParseGradient(m, true);
else if(m.IsTag("style")) {
String text = m.GatherText();
try {
CParser p(text);
while(!p.IsEof()) {
if(p.Char('.') && p.IsId()) {
String id = p.ReadIdh();
if(p.Char('{')) {
const char *b = p.GetPtr();
while(!p.IsChar('}') && !p.IsEof())
p.SkipTerm();
classes.Add(id, String(b, p.GetPtr()));
}
p.Char('}');
}
else
p.SkipTerm();
}
}
catch(CParser::Error) {}
}
if(m.IsTag("style"))
ParseStyle(m);
}
else
if(n.IsTag("linearGradient"))
@ -503,27 +517,8 @@ void SvgParser::Element(const XmlNode& n, int depth, bool dosymbols)
}
}
else
if(n.IsTag("style")) {
String text = n.GatherText();
try {
CParser p(text);
while(!p.IsEof()) {
if(p.Char('.') && p.IsId()) {
String id = p.ReadIdh();
if(p.Char('{')) {
const char *b = p.GetPtr();
while(!p.IsChar('}') && !p.IsEof())
p.SkipTerm();
classes.Add(id, String(b, p.GetPtr()));
}
p.Char('}');
}
else
p.SkipTerm();
}
}
catch(CParser::Error) {}
}
if(n.IsTag("style"))
ParseStyle(n);
}
void SvgParser::Items(const XmlNode& n, int depth)