mirror of
https://projects.vdr-developer.org/git/vdr-plugin-skindesigner.git
synced 2023-10-19 15:58:31 +00:00
Added SVG rendering support
This commit is contained in:
parent
9454294559
commit
f17af1f713
4
Makefile
4
Makefile
@ -44,8 +44,8 @@ DEFINES += $(shell xml2-config --cflags)
|
|||||||
|
|
||||||
INCLUDES += $(shell pkg-config --cflags freetype2 fontconfig)
|
INCLUDES += $(shell pkg-config --cflags freetype2 fontconfig)
|
||||||
|
|
||||||
INCLUDES += $(shell pkg-config --cflags cairo-png)
|
INCLUDES += $(shell pkg-config --cflags librsvg-2.0 cairo-png)
|
||||||
LIBS += $(shell pkg-config --libs cairo-png)
|
LIBS += $(shell pkg-config --libs librsvg-2.0 cairo-png)
|
||||||
|
|
||||||
LIBS += $(shell xml2-config --libs)
|
LIBS += $(shell xml2-config --libs)
|
||||||
|
|
||||||
|
@ -311,18 +311,17 @@ cImage *cImageCache::GetSkinpart(string name, int width, int height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool cImageCache::LoadIcon(eImageType type, string name) {
|
bool cImageCache::LoadIcon(eImageType type, string name) {
|
||||||
bool success = false;
|
|
||||||
cString subdir("");
|
cString subdir("");
|
||||||
if (type == itMenuIcon)
|
if (type == itMenuIcon)
|
||||||
subdir = "menuicons";
|
subdir = "menuicons";
|
||||||
else if (type == itIcon)
|
else if (type == itIcon)
|
||||||
subdir = "icons";
|
subdir = "icons";
|
||||||
cString subIconPath = cString::sprintf("%s%s/", iconPath.c_str(), *subdir);
|
cString subIconPath = cString::sprintf("%s%s/", iconPath.c_str(), *subdir);
|
||||||
success = LoadImage(name, *subIconPath, "png");
|
|
||||||
if (success) {
|
if (FileExists(*subIconPath, name, "svg"))
|
||||||
return true;
|
return LoadImage(*subIconPath, name, "svg");
|
||||||
}
|
else
|
||||||
return false;
|
return LoadImage(*subIconPath, name, "png");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cImageCache::LoadLogo(const cChannel *channel) {
|
bool cImageCache::LoadLogo(const cChannel *channel) {
|
||||||
@ -331,32 +330,27 @@ bool cImageCache::LoadLogo(const cChannel *channel) {
|
|||||||
string channelID = StrToLowerCase(*(channel->GetChannelID().ToString()));
|
string channelID = StrToLowerCase(*(channel->GetChannelID().ToString()));
|
||||||
string logoLower = StrToLowerCase(channel->Name());
|
string logoLower = StrToLowerCase(channel->Name());
|
||||||
bool success = false;
|
bool success = false;
|
||||||
success = LoadImage(channelID.c_str(), logoPath.c_str(), *config.logoExtension);
|
|
||||||
if (success)
|
if (FileExists(logoPath.c_str(), channelID.c_str(), *config.logoExtension))
|
||||||
return true;
|
return LoadImage(logoPath.c_str(), channelID.c_str(), *config.logoExtension);
|
||||||
success = LoadImage(logoLower.c_str(), logoPath.c_str(), *config.logoExtension);
|
|
||||||
if (success)
|
if (FileExists(logoPath.c_str(), logoLower.c_str(), *config.logoExtension))
|
||||||
return true;
|
return LoadImage(logoPath.c_str(), logoLower.c_str(), *config.logoExtension);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cImageCache::LoadSeparatorLogo(string name) {
|
bool cImageCache::LoadSeparatorLogo(string name) {
|
||||||
cString separatorPath = cString::sprintf("%sseparatorlogos/", logoPath.c_str());
|
cString separatorPath = cString::sprintf("%sseparatorlogos/", logoPath.c_str());
|
||||||
string nameLower = StrToLowerCase(name.c_str());
|
string nameLower = StrToLowerCase(name.c_str());
|
||||||
bool success = false;
|
return LoadImage(*separatorPath, nameLower.c_str(), *config.logoExtension);
|
||||||
success = LoadImage(nameLower.c_str(), *separatorPath, *config.logoExtension);
|
|
||||||
if (success)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cImageCache::LoadSkinpart(string name) {
|
bool cImageCache::LoadSkinpart(string name) {
|
||||||
bool success = false;
|
if (FileExists(skinPartsPath.c_str(), name, "svg"))
|
||||||
success = LoadImage(name, skinPartsPath.c_str(), "png");
|
return LoadImage(skinPartsPath.c_str(), name, "svg");
|
||||||
if (success) {
|
else
|
||||||
return true;
|
return LoadImage(skinPartsPath.c_str(), name, "png");
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cImageCache::Clear(void) {
|
void cImageCache::Clear(void) {
|
||||||
|
@ -41,7 +41,6 @@ cImage *cImageLoader::CreateImage(int width, int height, bool preserveAspect) {
|
|||||||
cairo_scale(cr, sx, sy);
|
cairo_scale(cr, sx, sy);
|
||||||
|
|
||||||
importer->DrawToCairo(cr);
|
importer->DrawToCairo(cr);
|
||||||
cairo_paint(cr);
|
|
||||||
|
|
||||||
cairo_status_t status = cairo_status(cr);
|
cairo_status_t status = cairo_status(cr);
|
||||||
if (status)
|
if (status)
|
||||||
@ -51,6 +50,7 @@ cImage *cImageLoader::CreateImage(int width, int height, bool preserveAspect) {
|
|||||||
cImage *image = new cImage(cSize(width, height), (tColor*)data);
|
cImage *image = new cImage(cSize(width, height), (tColor*)data);
|
||||||
|
|
||||||
cairo_destroy(cr);
|
cairo_destroy(cr);
|
||||||
|
cairo_surface_destroy(surface);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@ -67,6 +67,8 @@ bool cImageLoader::LoadImage(const char *fullpath) {
|
|||||||
|
|
||||||
if (endswith(fullpath, ".png"))
|
if (endswith(fullpath, ".png"))
|
||||||
importer = new cImageImporterPNG;
|
importer = new cImageImporterPNG;
|
||||||
|
else if (endswith(fullpath, ".svg"))
|
||||||
|
importer = new cImageImporterSVG;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -74,7 +76,7 @@ bool cImageLoader::LoadImage(const char *fullpath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Just a different way to call LoadImage. Calls the above one.
|
// Just a different way to call LoadImage. Calls the above one.
|
||||||
bool cImageLoader::LoadImage(std::string FileName, std::string Path, std::string Extension) {
|
bool cImageLoader::LoadImage(std::string Path, std::string FileName, std::string Extension) {
|
||||||
std::stringstream sstrImgFile;
|
std::stringstream sstrImgFile;
|
||||||
sstrImgFile << Path << FileName << "." << Extension;
|
sstrImgFile << Path << FileName << "." << Extension;
|
||||||
std::string imgFile = sstrImgFile.str();
|
std::string imgFile = sstrImgFile.str();
|
||||||
@ -147,8 +149,10 @@ bool cImageImporterPNG::LoadImage(const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cImageImporterPNG::DrawToCairo(cairo_t *cr) {
|
void cImageImporterPNG::DrawToCairo(cairo_t *cr) {
|
||||||
if (surface)
|
if (surface) {
|
||||||
cairo_set_source_surface(cr, surface, 0, 0);
|
cairo_set_source_surface(cr, surface, 0, 0);
|
||||||
|
cairo_paint(cr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cImageImporterPNG::GetImageSize(int &width, int &height) {
|
void cImageImporterPNG::GetImageSize(int &width, int &height) {
|
||||||
@ -157,3 +161,51 @@ void cImageImporterPNG::GetImageSize(int &width, int &height) {
|
|||||||
height = cairo_image_surface_get_height(surface);
|
height = cairo_image_surface_get_height(surface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Image importer for SVG
|
||||||
|
//
|
||||||
|
|
||||||
|
cImageImporterSVG::cImageImporterSVG() {
|
||||||
|
handle = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cImageImporterSVG::~cImageImporterSVG() {
|
||||||
|
if (handle) {
|
||||||
|
rsvg_handle_close(handle, NULL);
|
||||||
|
g_object_unref(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cImageImporterSVG::LoadImage(const char *path) {
|
||||||
|
if (handle) {
|
||||||
|
rsvg_handle_close(handle, NULL);
|
||||||
|
g_object_unref(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
GError *error = NULL;
|
||||||
|
handle = rsvg_handle_new_from_file(path, &error);
|
||||||
|
if (!handle) {
|
||||||
|
if (config.debugImageLoading)
|
||||||
|
dsyslog("skindesigner: RSVG Error: %s", error->message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
rsvg_handle_set_dpi(handle, 90);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cImageImporterSVG::DrawToCairo(cairo_t *cr) {
|
||||||
|
if (handle)
|
||||||
|
rsvg_handle_render_cairo(handle, cr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cImageImporterSVG::GetImageSize(int &width, int &height) {
|
||||||
|
if (handle) {
|
||||||
|
RsvgDimensionData dim;
|
||||||
|
rsvg_handle_get_dimensions(handle, &dim);
|
||||||
|
width = dim.width;
|
||||||
|
height = dim.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#define X_DISPLAY_MISSING
|
#define X_DISPLAY_MISSING
|
||||||
|
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
|
#include <librsvg/rsvg.h>
|
||||||
#include <vdr/osd.h>
|
#include <vdr/osd.h>
|
||||||
#include <vdr/tools.h>
|
#include <vdr/tools.h>
|
||||||
|
|
||||||
@ -32,16 +33,17 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Image importer for SVG
|
// Image importer for SVG
|
||||||
/*
|
|
||||||
class cImageImporterSVG : public cImageImporter {
|
class cImageImporterSVG : public cImageImporter {
|
||||||
public:
|
public:
|
||||||
|
cImageImporterSVG();
|
||||||
~cImageImporterSVG();
|
~cImageImporterSVG();
|
||||||
bool LoadImage(const char *path);
|
bool LoadImage(const char *path);
|
||||||
bool RenderToCairo(cairo_t *cr);
|
void DrawToCairo(cairo_t *cr);
|
||||||
void GetImageSize(int &width, int &height);
|
void GetImageSize(int &width, int &height);
|
||||||
private:
|
private:
|
||||||
RsvgHandle *handle = NULL;
|
RsvgHandle *handle;
|
||||||
}*/
|
};
|
||||||
|
|
||||||
|
|
||||||
class cImageLoader {
|
class cImageLoader {
|
||||||
private:
|
private:
|
||||||
@ -50,7 +52,7 @@ public:
|
|||||||
cImageLoader();
|
cImageLoader();
|
||||||
virtual ~cImageLoader();
|
virtual ~cImageLoader();
|
||||||
cImage *CreateImage(int width, int height, bool preserveAspect = true);
|
cImage *CreateImage(int width, int height, bool preserveAspect = true);
|
||||||
bool LoadImage(std::string FileName, std::string Path, std::string Extension);
|
bool LoadImage(std::string Path, std::string FileName, std::string Extension);
|
||||||
bool LoadImage(const char *fullpath);
|
bool LoadImage(const char *fullpath);
|
||||||
void DeterminateChannelLogoSize(int &width, int &height);
|
void DeterminateChannelLogoSize(int &width, int &height);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user