summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouis <louis.braun@gmx.de>2015-06-18 10:21:43 +0200
committerlouis <louis.braun@gmx.de>2015-06-18 10:21:43 +0200
commita0a6e21d5a7e2ff3097bd851623cf1eef3daf431 (patch)
treec66a3986061a6c73f747418f94ec78008876dd41
parentbbe8c56fcb7890f43828a41363b9930ed4a2978d (diff)
downloadvdr-plugin-skindesigner-a0a6e21d5a7e2ff3097bd851623cf1eef3daf431.tar.gz
vdr-plugin-skindesigner-a0a6e21d5a7e2ff3097bd851623cf1eef3daf431.tar.bz2
fixed memory leak when creating fonts
-rw-r--r--HISTORY5
-rw-r--r--designer.c3
-rw-r--r--libcore/fontmanager.c13
-rw-r--r--libcore/fontmanager.h43
-rw-r--r--libcore/imagecache.c6
-rw-r--r--libcore/imageloader.c1
-rw-r--r--libtemplate/template.c5
-rw-r--r--libtemplate/templateview.c1
8 files changed, 43 insertions, 34 deletions
diff --git a/HISTORY b/HISTORY
index eccf5da..1153b01 100644
--- a/HISTORY
+++ b/HISTORY
@@ -371,4 +371,7 @@ Version 0.5.2
- changed "Update from Git" to "Update"
- made viewelement scrapercontent in displayreplay detachable
-Version 0.5.3 \ No newline at end of file
+Version 0.5.3
+
+- added SVG Template parsing
+- fixed memory leak when creating fonts
diff --git a/designer.c b/designer.c
index 35ba899..9af6e7e 100644
--- a/designer.c
+++ b/designer.c
@@ -128,7 +128,7 @@ void cSkinDesigner::Reload(void) {
esyslog("skindesigner: OSD is open, close first!");
return;
}
- DeleteTemplates();
+
cStopWatch watch;
bool ok = LoadTemplates();
if (!ok) {
@@ -390,6 +390,7 @@ void cSkinDesigner::CacheTemplates(void) {
}
}
dsyslog("skindesigner: templates cached");
+ fontManager->DeleteFonts();
fontManager->CacheFonts(channelTemplate);
fontManager->CacheFonts(menuTemplate);
fontManager->CacheFonts(messageTemplate);
diff --git a/libcore/fontmanager.c b/libcore/fontmanager.c
index 1bca226..2f1e79c 100644
--- a/libcore/fontmanager.c
+++ b/libcore/fontmanager.c
@@ -132,6 +132,8 @@ cFont *cFontManager::CreateFont(string name, int size) {
}
void cFontManager::InsertFont(string name, int size) {
+ if (FontExists(name, size))
+ return;
cFont *newFont = CreateFont(name, size);
if (!newFont)
return;
@@ -145,6 +147,16 @@ void cFontManager::InsertFont(string name, int size) {
}
}
+bool cFontManager::FontExists(string name, int size) {
+ map < string, map< int, cFont* > >::iterator hit = fonts.find(name);
+ if (hit == fonts.end())
+ return false;
+ map< int, cFont* >::iterator hit2 = (hit->second).find(size);
+ if (hit2 == (hit->second).end())
+ return false;
+ return true;
+}
+
cFont *cFontManager::GetFont(string name, int size) {
map< string, map<int,cFont*> >::iterator hitName = fonts.find(name);
if (hitName == fonts.end())
@@ -192,4 +204,3 @@ bool cFontManager::FontInstalled(string fontName) {
}
return false;
}
-
diff --git a/libcore/fontmanager.h b/libcore/fontmanager.h
index 5661c2b..1dbdcde 100644
--- a/libcore/fontmanager.h
+++ b/libcore/fontmanager.h
@@ -11,27 +11,28 @@
using namespace std;
class cFontManager {
- private:
- static cMutex mutex;
- map < string, map< int, cFont* > > fonts;
- cFont *CreateFont(string name, int size);
- void InsertFont(string name, int size);
- cFont *GetFont(string name, int size);
- int GetFontHeight(const char *name, int height, int charWidth = 0);
- public:
- cFontManager();
- ~cFontManager();
- void Lock(void) { mutex.Lock(); };
- void Unlock(void) { mutex.Unlock(); };
- void CacheFonts(cTemplate *tpl);
- void DeleteFonts(void);
- int Width(string fontName, int fontSize, const char *text);
- int Height(string fontName, int fontSize);
- cFont *Font(string fontName, int fontSize);
- cFont *FontUncached(string fontName, int fontSize);
- void Debug(void);
- void ListAvailableFonts(void);
- bool FontInstalled(string fontName);
+private:
+ static cMutex mutex;
+ map < string, map< int, cFont* > > fonts;
+ cFont *CreateFont(string name, int size);
+ void InsertFont(string name, int size);
+ bool FontExists(string name, int size);
+ cFont *GetFont(string name, int size);
+ int GetFontHeight(const char *name, int height, int charWidth = 0);
+public:
+ cFontManager();
+ ~cFontManager();
+ void Lock(void) { mutex.Lock(); };
+ void Unlock(void) { mutex.Unlock(); };
+ void CacheFonts(cTemplate *tpl);
+ void DeleteFonts(void);
+ int Width(string fontName, int fontSize, const char *text);
+ int Height(string fontName, int fontSize);
+ cFont *Font(string fontName, int fontSize);
+ cFont *FontUncached(string fontName, int fontSize);
+ void Debug(void);
+ void ListAvailableFonts(void);
+ bool FontInstalled(string fontName);
};
#endif //__FONTMANAGER_H \ No newline at end of file
diff --git a/libcore/imagecache.c b/libcore/imagecache.c
index 63edb42..fe07e98 100644
--- a/libcore/imagecache.c
+++ b/libcore/imagecache.c
@@ -390,15 +390,12 @@ 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());
}
@@ -444,15 +441,12 @@ 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());
}
diff --git a/libcore/imageloader.c b/libcore/imageloader.c
index b417e01..62d284f 100644
--- a/libcore/imageloader.c
+++ b/libcore/imageloader.c
@@ -502,5 +502,6 @@ void cSVGTemplate::ReplaceTokens(string &line, size_t tokenStart, size_t tokenEn
}
tIndex alpha = (color & 0xFF000000) >> 24;
string svgAlpha = *cString::sprintf("%f", (float)(alpha / (float)255));
+ std::replace( svgAlpha.begin(), svgAlpha.end(), ',', '.');
line.replace(hitAlpha, hitAlphaEnd - hitAlpha + 2, svgAlpha);
}
diff --git a/libtemplate/template.c b/libtemplate/template.c
index c542d13..b9698c2 100644
--- a/libtemplate/template.c
+++ b/libtemplate/template.c
@@ -12,9 +12,8 @@ cTemplate::cTemplate(eViewType viewType, string pluginName, int viewID) {
}
cTemplate::~cTemplate() {
-
- if (rootView)
- delete rootView;
+ if (rootView)
+ delete rootView;
}
diff --git a/libtemplate/templateview.c b/libtemplate/templateview.c
index f64d4c6..91e28c4 100644
--- a/libtemplate/templateview.c
+++ b/libtemplate/templateview.c
@@ -14,7 +14,6 @@ cTemplateView::cTemplateView(void) {
}
cTemplateView::~cTemplateView() {
-
for (map < eViewElement, cTemplateViewElement* >::iterator it = viewElements.begin(); it != viewElements.end(); it++) {
delete it->second;
}