summaryrefslogtreecommitdiffstats
path: root/TRASH
blob: a63c51c11348020d3c2310bd978ac107efb70460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

#ifdef __LINK_AT_RUNTIME__
DEFINE_SYMBOL(long, bfd_canonicalize_reloc,
	bfd *abfd, asection *sec, arelent **loc, asymbol **syms);
DEFINE_SYMBOL(bfd_boolean, bfd_close,
	bfd *abfd);
DEFINE_SYMBOL(bfd_boolean, bfd_check_format,
	bfd *abfd, bfd_format format);
DEFINE_SYMBOL(const char *, bfd_errmsg,
	bfd_error_type error_tag);
DEFINE_SYMBOL(enum bfd_architecture, bfd_get_arch,
	bfd *abfd);
DEFINE_SYMBOL(bfd_error_type, bfd_get_error,
	void);
DEFINE_SYMBOL(unsigned long, bfd_get_mach,
	bfd *abfd);
DEFINE_SYMBOL(long, bfd_get_reloc_upper_bound,
	bfd *abfd, asection *sect);
DEFINE_SYMBOL(bfd_boolean, bfd_get_section_contents,
	bfd *abfd, asection *section, void *location, file_ptr offset, 
bfd_size_type count);
DEFINE_SYMBOL(asection *, bfd_make_section,
	bfd *, const char *name);
DEFINE_SYMBOL(asection *, bfd_make_section_anyway_with_flags,
	bfd *abfd, const char *name, flagword flags);
DEFINE_SYMBOL(bfd *, bfd_openr, const char *filename,
	const char *target);
DEFINE_SYMBOL(bfd *, bfd_openw,
	const char *filename, const char *target);
DEFINE_SYMBOL(bfd_boolean, bfd_set_file_flags,
	bfd *abfd, flagword flags);
DEFINE_SYMBOL(void, bfd_set_reloc,
	bfd *abfd, asection *sec, arelent **rel, unsigned int count);
DEFINE_SYMBOL(bfd_boolean, bfd_set_section_contents,
	bfd *abfd, asection *section, const void *data, file_ptr offset, 
bfd_size_type count);
DEFINE_SYMBOL(bfd_boolean, bfd_set_format,
	bfd *abfd, bfd_format format);
DEFINE_SYMBOL(bfd_boolean, bfd_set_section_flags,
	bfd *abfd, asection *sec, flagword flags);
DEFINE_SYMBOL(bfd_boolean, bfd_set_section_size,
	bfd *abfd, asection *sec, bfd_size_type val);
DEFINE_SYMBOL(bfd_boolean, bfd_set_start_address,
	bfd *abfd, bfd_vma vma);
DEFINE_SYMBOL(bfd_boolean, bfd_set_symtab,
	bfd *abfd, asymbol **location, unsigned int count);

#define bfd_canonicalize_reloc             
OVERRIDE_SYMBOL(bfd_canonicalize_reloc)
#define bfd_close                          OVERRIDE_SYMBOL(bfd_close)
#define bfd_check_format                   
OVERRIDE_SYMBOL(bfd_check_format)
#define bfd_errmsg                         OVERRIDE_SYMBOL(bfd_errmsg)
#define bfd_get_arch                       OVERRIDE_SYMBOL(bfd_get_arch)
#define bfd_get_error                      
OVERRIDE_SYMBOL(bfd_get_error)
#define bfd_get_mach                       OVERRIDE_SYMBOL(bfd_get_mach)
#define bfd_get_reloc_upper_bound          
OVERRIDE_SYMBOL(bfd_get_reloc_upper_bound)
#define bfd_get_section_contents           
OVERRIDE_SYMBOL(bfd_get_section_contents)
#define bfd_make_section                   
OVERRIDE_SYMBOL(bfd_make_section)
#define bfd_make_section_anyway_with_flags 
OVERRIDE_SYMBOL(bfd_make_section_anyway_with_flags)
#define bfd_openr                          OVERRIDE_SYMBOL(bfd_openr)
#define bfd_openw                          OVERRIDE_SYMBOL(bfd_openw)
#define bfd_set_file_flags                 
OVERRIDE_SYMBOL(bfd_set_file_flags)
#define bfd_set_format                     
OVERRIDE_SYMBOL(bfd_set_format)
#define bfd_set_reloc                      
OVERRIDE_SYMBOL(bfd_set_reloc)
#define bfd_set_section_contents           
OVERRIDE_SYMBOL(bfd_set_section_contents)
#define bfd_set_section_flags              
OVERRIDE_SYMBOL(bfd_set_section_flags)
#define bfd_set_section_size               
OVERRIDE_SYMBOL(bfd_set_section_size)
#define bfd_set_start_address              
OVERRIDE_SYMBOL(bfd_set_start_address)
#define bfd_set_symtab                     
OVERRIDE_SYMBOL(bfd_set_symtab)

SYMBOL_TABLE(libbfd_symbols,
	SYMBOL(bfd_openr),
	SYMBOL(bfd_set_format),
);
#endif

#include <librsvg/rsvg.h>

DEFINE_SYMBOL(void, rsvg_init, void);
DEFINE_SYMBOL(RsvgHandle *, rsvg_handle_new, void);
DEFINE_SYMBOL(GdkPixbuf *, rsvg_handle_get_pixbuf, RsvgHandle *handle);
DEFINE_SYMBOL(gboolean, rsvg_handle_close, RsvgHandle * handle, GError ** error);
DEFINE_SYMBOL(void, rsvg_handle_get_dimensions, RsvgHandle * handle, RsvgDimensionData * dimension_data);
DEFINE_SYMBOL(gboolean, rsvg_handle_write, RsvgHandle * handle, const guchar * buf, gsize count, GError ** error);
DEFINE_SYMBOL(void, rsvg_handle_set_size_callback, RsvgHandle * handle, RsvgSizeFunc size_func, gpointer user_data, GDestroyNotify user_data_destroy);

#define rsvg_init                     OVERRIDE_SYMBOL(rsvg_init)
#define rsvg_handle_new               OVERRIDE_SYMBOL(rsvg_handle_new)
#define rsvg_handle_get_pixbuf        OVERRIDE_SYMBOL(rsvg_handle_get_pixbuf)
#define rsvg_handle_close             OVERRIDE_SYMBOL(rsvg_handle_close)
#define rsvg_handle_write             OVERRIDE_SYMBOL(rsvg_handle_write)
#define rsvg_handle_set_size_callback OVERRIDE_SYMBOL(rsvg_handle_set_size_callback)
#define rsvg_handle_get_dimensions    OVERRIDE_SYMBOL(rsvg_handle_get_dimensions)

SYMBOL_TABLE(librsvg_symbols,
	SYMBOL(rsvg_init),
	SYMBOL(rsvg_handle_new),
	SYMBOL(rsvg_handle_close),
	SYMBOL(rsvg_handle_write),
	SYMBOL(rsvg_handle_get_pixbuf),
	SYMBOL(rsvg_handle_get_dimensions),
	SYMBOL(rsvg_handle_set_size_callback),
);

/*
 * Scale the SVG image to the required icon size
 */
static void rsvg_set_iconsize(int *width, int *height, gpointer data)
{
	float multiplier = *(float*)data;
	
	(*width) *= multiplier;
	(*height) *= multiplier;
}

	if(!rsvg_linked)
	{
		if(!LOAD_SYMBOLS("librsvg-2.so", librsvg_symbols))
		{
			// libr_icon_gtk requires that your application be linked to librsvg
			return NULL;
		}
	}
		RsvgHandle *rsvg = NULL;
		libr_icontype_t type;
		type = icon_handle->type;
		if(type == LIBR_SVG)
		{
			RsvgHandle *rsvg = rsvg_handle_new();
			if(rsvg != NULL)
			{
				if(rsvg_handle_write(rsvg, iconfile, iconfile_size, NULL))
				{
					if(rsvg_handle_close(rsvg, NULL))
					{
						RsvgDimensionData dim;
						float multiplier;
						int old_size;
						
						rsvg_handle_get_dimensions(rsvg, &dim);
						if(dim.width > dim.height)
							old_size = dim.width;
						else
							old_size = dim.height;
						multiplier = ((float)sizes[i])/old_size;
						rsvg_handle_set_size_callback(rsvg, rsvg_set_iconsize, (void *) &multiplier, NULL);
						icon = rsvg_handle_get_pixbuf(rsvg);
						icons = g_list_append(icons, icon);
					}
				}
			}
			free(iconfile);
		}
		else if(type == LIBR_PNG)
		{
		}
		else
		{
			/* Unhandled image type */
			continue;
		}