fixed bug in svgtemplate parsing

This commit is contained in:
louis 2015-06-15 11:27:32 +02:00
parent 41736f4428
commit bbe8c56fcb
2 changed files with 22 additions and 11 deletions

View File

@ -390,12 +390,15 @@ bool cImageCache::LoadIcon(eImageType type, string name) {
return LoadImage(*subIconSkinPath, name, "png");
//and finally check if a svg template exists
esyslog("skindesigner: checking svg template for %s", name.c_str());
cSVGTemplate svgTemplate(name, svgTemplatePath);
if (!svgTemplate.Exists())
return false;
esyslog("skindesigner: template found for %s", name.c_str());
svgTemplate.ReadTemplate();
if (!svgTemplate.ParseTemplate())
return false;
esyslog("skindesigner: template parsed for %s", name.c_str());
string tmpImageName = svgTemplate.WriteImage();
return LoadImage(tmpImageName.c_str());
}
@ -441,12 +444,15 @@ bool cImageCache::LoadSkinpart(string name) {
return LoadImage(skinPartsPathSkin.c_str(), name, "png");
//check if a svg template exists
esyslog("skindesigner: checking svg template for %s", name.c_str());
cSVGTemplate svgTemplate(name, svgTemplatePath);
if (!svgTemplate.Exists())
return false;
esyslog("skindesigner: template found for %s", name.c_str());
svgTemplate.ReadTemplate();
if (!svgTemplate.ParseTemplate())
return false;
esyslog("skindesigner: template parsed for %s", name.c_str());
string tmpImageName = svgTemplate.WriteImage();
return LoadImage(tmpImageName.c_str());
}

View File

@ -442,16 +442,21 @@ bool cSVGTemplate::ParseTemplate(void) {
i++;
continue;
}
size_t hitEnd = line.find(endToken, hit);
if (hitEnd == string::npos) {
return false;
}
string colorName = GetColorName(line, hit, hitEnd);
tColor replaceColor = 0x0;
if (!config.GetThemeColor(colorName, replaceColor)) {
return false;
}
ReplaceTokens(line, hit, hitEnd, replaceColor);
while (hit != string::npos) {
size_t hitEnd = line.find(endToken, hit);
if (hitEnd == string::npos) {
esyslog("skindesigner: error in SVG Template %s: invalid tag", imageName.c_str());
return false;
}
string colorName = GetColorName(line, hit, hitEnd);
tColor replaceColor = 0x0;
if (!config.GetThemeColor(colorName, replaceColor)) {
esyslog("skindesigner: error in SVG Template %s: invalid color %x", imageName.c_str(), replaceColor);
return false;
}
ReplaceTokens(line, hit, hitEnd, replaceColor);
hit = line.find(startTokenColor);
}
svgTemplate[i] = line;
i++;
}
@ -485,7 +490,7 @@ string cSVGTemplate::GetColorName(string line, size_t tokenStart, size_t tokenEn
}
void cSVGTemplate::ReplaceTokens(string &line, size_t tokenStart, size_t tokenEnd, tColor color) {
string rgbColor = *cString::sprintf("%x", color & 0x00FFFFFF);
string rgbColor = *cString::sprintf("%06x", color & 0x00FFFFFF);
line.replace(tokenStart, tokenEnd - tokenStart + 2, rgbColor);
size_t hitAlpha = line.find(startTokenOpac);
if (hitAlpha == string::npos) {