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

View File

@ -442,16 +442,21 @@ bool cSVGTemplate::ParseTemplate(void) {
i++; i++;
continue; continue;
} }
size_t hitEnd = line.find(endToken, hit); while (hit != string::npos) {
if (hitEnd == string::npos) { size_t hitEnd = line.find(endToken, hit);
return false; if (hitEnd == string::npos) {
} esyslog("skindesigner: error in SVG Template %s: invalid tag", imageName.c_str());
string colorName = GetColorName(line, hit, hitEnd); return false;
tColor replaceColor = 0x0; }
if (!config.GetThemeColor(colorName, replaceColor)) { string colorName = GetColorName(line, hit, hitEnd);
return false; tColor replaceColor = 0x0;
} if (!config.GetThemeColor(colorName, replaceColor)) {
ReplaceTokens(line, hit, hitEnd, 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; svgTemplate[i] = line;
i++; 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) { 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); line.replace(tokenStart, tokenEnd - tokenStart + 2, rgbColor);
size_t hitAlpha = line.find(startTokenOpac); size_t hitAlpha = line.find(startTokenOpac);
if (hitAlpha == string::npos) { if (hitAlpha == string::npos) {