mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
helper: Move cairo_image_surface_create_from_svg to helper.c
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
parent
93cb04e30f
commit
1d99363ce9
4 changed files with 39 additions and 32 deletions
|
@ -27,6 +27,9 @@
|
|||
|
||||
#ifndef ROFI_HELPER_H
|
||||
#define ROFI_HELPER_H
|
||||
|
||||
#include <cairo.h>
|
||||
|
||||
/**
|
||||
* @defgroup HELPERS Helpers
|
||||
*/
|
||||
|
@ -265,4 +268,14 @@ int utf8_strncmp ( const char *a, const char* b, size_t n ) __attribute__( ( non
|
|||
* @returns FALSE On failure, TRUE on success
|
||||
*/
|
||||
int helper_execute_command ( const char *wd, const char *cmd, int run_in_term );
|
||||
|
||||
/**
|
||||
* @param file The file path
|
||||
* @param height The wanted height
|
||||
* Gets a surface from an svg path
|
||||
*
|
||||
* @returns a cairo surface from an svg path
|
||||
*/
|
||||
cairo_surface_t *cairo_image_surface_create_from_svg ( const gchar* file, int height );
|
||||
|
||||
#endif // ROFI_HELPER_H
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#ifndef ROFI_XCB_H
|
||||
#define ROFI_XCB_H
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <cairo.h>
|
||||
|
||||
/**
|
||||
|
@ -200,13 +201,6 @@ cairo_surface_t * x11_helper_get_bg_surface ( void );
|
|||
*/
|
||||
cairo_surface_t *x11_helper_get_screenshot_surface ( void );
|
||||
|
||||
/**
|
||||
* Gets a surface from an svg path
|
||||
*
|
||||
* @returns a cairo surface from an svg path
|
||||
*/
|
||||
cairo_surface_t *cairo_image_surface_create_from_svg ( const gchar* file, int height );
|
||||
|
||||
/**
|
||||
* Creates an internal represenation of the available monitors.
|
||||
* Used for positioning rofi.
|
||||
|
|
|
@ -43,10 +43,10 @@
|
|||
#include <sys/stat.h>
|
||||
#include <pwd.h>
|
||||
#include <ctype.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pango-fontmap.h>
|
||||
#include <pango/pangocairo.h>
|
||||
#include <librsvg/rsvg.h>
|
||||
#include "xcb.h"
|
||||
#include "helper.h"
|
||||
#include "helper-theme.h"
|
||||
|
@ -1024,3 +1024,27 @@ char *helper_get_theme_path ( const char *file )
|
|||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
cairo_surface_t* cairo_image_surface_create_from_svg ( const gchar* file, int height )
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
RsvgHandle * handle;
|
||||
RsvgDimensionData dimensions;
|
||||
|
||||
handle = rsvg_handle_new_from_file ( file, NULL );
|
||||
rsvg_handle_get_dimensions ( handle, &dimensions );
|
||||
double scale = (double) height / dimensions.height;
|
||||
surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32,
|
||||
(double) dimensions.width * scale,
|
||||
(double) dimensions.height * scale );
|
||||
cr = cairo_create ( surface );
|
||||
cairo_scale ( cr, scale, scale );
|
||||
rsvg_handle_render_cairo ( handle, cr );
|
||||
cairo_destroy ( cr );
|
||||
|
||||
rsvg_handle_close ( handle, NULL );
|
||||
g_object_unref ( handle );
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
|
24
source/xcb.c
24
source/xcb.c
|
@ -135,30 +135,6 @@ cairo_surface_t * x11_helper_get_bg_surface ( void )
|
|||
xcb->screen->width_in_pixels, xcb->screen->height_in_pixels );
|
||||
}
|
||||
|
||||
cairo_surface_t* cairo_image_surface_create_from_svg ( const gchar* file, int height )
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
RsvgHandle * handle;
|
||||
RsvgDimensionData dimensions;
|
||||
|
||||
handle = rsvg_handle_new_from_file ( file, NULL );
|
||||
rsvg_handle_get_dimensions ( handle, &dimensions );
|
||||
double scale = (double) height / dimensions.height;
|
||||
surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32,
|
||||
(double) dimensions.width * scale,
|
||||
(double) dimensions.height * scale );
|
||||
cr = cairo_create ( surface );
|
||||
cairo_scale ( cr, scale, scale );
|
||||
rsvg_handle_render_cairo ( handle, cr );
|
||||
cairo_destroy ( cr );
|
||||
|
||||
rsvg_handle_close ( handle, NULL );
|
||||
g_object_unref ( handle );
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
// retrieve a text property from a window
|
||||
// technically we could use window_get_prop(), but this is better for character set support
|
||||
char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom )
|
||||
|
|
Loading…
Reference in a new issue