1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

Merge pull request #13 from jrk-/rsvg

Lua bindings to librsvg
This commit is contained in:
Brenden Matthews 2013-05-23 17:20:32 -07:00
commit e9474c745b
6 changed files with 229 additions and 1 deletions

View File

@ -124,6 +124,7 @@ endif(OWN_WINDOW)
option(BUILD_LUA_CAIRO "Build cairo bindings for Lua" false) option(BUILD_LUA_CAIRO "Build cairo bindings for Lua" false)
option(BUILD_LUA_IMLIB2 "Build Imlib2 bindings for Lua" false) option(BUILD_LUA_IMLIB2 "Build Imlib2 bindings for Lua" false)
option(BUILD_LUA_RSVG "Build rsvg bindings for Lua" false)
option(BUILD_AUDACIOUS "Build audacious (music player) support" false) option(BUILD_AUDACIOUS "Build audacious (music player) support" false)

View File

@ -252,6 +252,12 @@ if(BUILD_LUA_IMLIB2)
set(luaimlib2_libs ${IMLIB2_LIB} ${LUA_LIBRARIES}) set(luaimlib2_libs ${IMLIB2_LIB} ${LUA_LIBRARIES})
set(luaimlib2_includes ${IMLIB2_INCLUDE_PATH} ${LUA_INCLUDE_DIRS}) set(luaimlib2_includes ${IMLIB2_INCLUDE_PATH} ${LUA_INCLUDE_DIRS})
endif(BUILD_LUA_IMLIB2) endif(BUILD_LUA_IMLIB2)
if(BUILD_LUA_RSVG)
set(WANT_TOLUA true)
pkg_check_modules(RSVG REQUIRED librsvg-2.0)
set(luarsvg_libs ${RSVG_LIBRARIES} ${LUA_LIBRARIES})
set(luarsvg_includes ${RSVG_INCLUDE_DIRS} ${LUA_INCLUDE_DIRS})
endif(BUILD_LUA_RSVG)
if(BUILD_AUDACIOUS) if(BUILD_AUDACIOUS)
set(WANT_GLIB true) set(WANT_GLIB true)

View File

@ -108,7 +108,9 @@
#cmakedefine BUILD_LUA_IMLIB2 1 #cmakedefine BUILD_LUA_IMLIB2 1
#if defined(BUILD_LUA_CAIRO) || defined(BUILD_LUA_IMLIB2) #cmakedefine BUILD_LUA_RSVG 1
#if defined(BUILD_LUA_CAIRO) || defined(BUILD_LUA_IMLIB2) || defined(BUILD_LUA_RSVG)
#define BUILD_LUA_EXTRAS #define BUILD_LUA_EXTRAS
#endif #endif

View File

@ -52,6 +52,17 @@ if(BUILD_LUA_IMLIB2)
set(lua_libs ${lua_libs} conky-imlib2) set(lua_libs ${lua_libs} conky-imlib2)
endif(BUILD_LUA_IMLIB2) endif(BUILD_LUA_IMLIB2)
if(BUILD_LUA_RSVG)
include_directories(${luarsvg_includes} ${CMAKE_CURRENT_SOURCE_DIR})
wrap_tolua(luarsvg_src rsvg.pkg)
add_library(conky-rsvg SHARED ${luarsvg_src})
set_target_properties(conky-rsvg PROPERTIES OUTPUT_NAME "rsvg")
target_link_libraries(conky-rsvg ${luarsvg_libs} ${TOLUA_LIBS})
set(lua_libs ${lua_libs} conky-rsvg)
endif(BUILD_LUA_RSVG)
install(TARGETS install(TARGETS
${lua_libs} ${lua_libs}
LIBRARY DESTINATION lib/conky LIBRARY DESTINATION lib/conky

100
lua/librsvg-helper.h Normal file
View File

@ -0,0 +1,100 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _LIBRSVG_HELPER_H_
#define _LIBRSVG_HELPER_H_
#include <glib.h>
#include <stdlib.h>
#include <librsvg/rsvg.h>
RsvgDimensionData *
rsvgDimensionDataCreate(void)
{
return (RsvgDimensionData *)calloc(1, sizeof(RsvgDimensionData));
}
void
rsvgDimensionDataGet(RsvgDimensionData * dd,
int * width, int * height, double * em, double * ex)
{
if (dd) {
*width = dd->width;
*height = dd->height;
*em = dd->em;
*ex = dd->ex;
}
}
RsvgPositionData *
rsvgPositionDataCreate(void)
{
return (RsvgPositionData *)calloc(1, sizeof(RsvgPositionData));
}
void
rsvgPositionDataGet(RsvgPositionData * pd, int * x, int * y)
{
if (pd) {
*x = pd->x;
*y = pd->y;
}
}
RsvgHandle *
rsvg_create_handle_from_file(const char * filename)
{
GError * error = NULL;
RsvgHandle * handle = rsvg_handle_new_from_file(filename, &error);
if (error) {
g_object_unref(error);
if (handle)
g_object_unref(handle);
handle = NULL;
}
return handle;
}
int
rsvg_destroy_handle(RsvgHandle * handle)
{
int status = 0;
if (handle) {
GError * error = NULL;
status = rsvg_handle_close(handle, &error);
if (status)
g_object_unref(handle);
if (error)
g_object_unref(error);
}
return status;
}
#endif /* _LIBRSVG_HELPER_H_ */

108
lua/rsvg.pkg Normal file
View File

@ -0,0 +1,108 @@
/*
rsvg.h: SAX-based renderer for SVG files into a GdkPixbuf.
Copyright (C) 2000 Eazel, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Raph Levien <raph@artofcode.com>
rsvg-cairo.h: SAX-based renderer for SVG files using cairo
Copyright (C) 2005 Red Hat, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Carl Worth <cworth@cworth.org>
*/
$#include <glib.h>
$#include <librsvg/rsvg.h>
$#include "librsvg-helper.h"
typedef struct _RsvgHandle RsvgHandle;
typedef struct RsvgHandlePrivate RsvgHandlePrivate;
typedef struct _RsvgHandleClass RsvgHandleClass;
/**
* RsvgDimensionData:
* @width: SVG's width, in pixels
* @height: SVG's height, in pixels
* @em: em
* @ex: ex
*/
typedef struct _RsvgDimensionData {
int width;
int height;
double em;
double ex;
static tolua_outside RsvgDimensionData * rsvgDimensionDataCreate @ create();
tolua_outside void rsvgDimensionDataGet @ get(int * width, int * height,
double * em, double * ex);
} RsvgDimensionData;
/**
* RsvgPositionData:
* Position of an SVG fragment.
*/
typedef struct _RsvgPositionData {
int x;
int y;
static tolua_outside RsvgPositionData * rsvgPositionDataCreate @ create();
tolua_outside void rsvgPositionDataGet @ get(int * x, int * y);
} RsvgPositionData;
RsvgHandle *rsvg_handle_new (void);
int rsvg_handle_write (RsvgHandle * handle, const unsigned char * buf,
unsigned long count, GError ** error);
int rsvg_handle_close (RsvgHandle * handle, GError ** error);
const char *rsvg_handle_get_base_uri (RsvgHandle * handle);
void rsvg_handle_set_base_uri (RsvgHandle * handle, const char *base_uri);
void rsvg_handle_get_dimensions (RsvgHandle * handle, RsvgDimensionData * dimension_data);
int rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimension_data, const char *id);
int rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_data, const char *id);
int rsvg_handle_has_sub (RsvgHandle * handle, const char *id);
RsvgHandle *rsvg_handle_new_with_flags (RsvgHandleFlags flags);
RsvgHandle *rsvg_handle_new_from_data (const unsigned char * data, unsigned long data_len, GError ** error);
RsvgHandle *rsvg_handle_new_from_file (const char * file_name, GError ** error);
int rsvg_handle_render_cairo (RsvgHandle * handle, cairo_t * cr);
int rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id);
void g_type_init(void);
void g_object_unref(gpointer object);
RsvgHandle * rsvg_create_handle_from_file(const char *);
int rsvg_destroy_handle(RsvgHandle *);