qt: playlist: use item title if available
[vlc.git] / contrib / src / ass / use-topendir.patch
blob2d99ca63cd91d625a9d7a012b0931d28c0f7b424
1 --- libass-0.13.4/libass/ass_fontselect.c.orig 2016-07-11 23:29:00.000000000 +0200
2 +++ libass-0.13.4/libass/ass_fontselect.c 2016-10-11 11:14:24.387661958 +0200
3 @@ -47,6 +47,9 @@
4 #include "ass_font.h"
5 #include "ass_string.h"
7 +#include <windows.h>
8 +#include <tchar.h>
10 #define ABS(x) ((x) < 0 ? -(x) : (x))
11 #define MAX_FULLNAME 100
13 @@ -161,28 +164,63 @@
14 .destroy_font = destroy_font_ft,
17 +#ifdef _WIN32
18 +static inline char *FromWide (const wchar_t *wide)
20 + size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
21 + if (len == 0)
22 + return NULL;
24 + char *out = (char *)malloc (len);
26 + if (out)
27 + WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
28 + return out;
31 +static inline wchar_t *ToWide (const char *utf8)
33 + int len = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0);
34 + if (len == 0)
35 + return NULL;
37 + wchar_t *out = (wchar_t *)malloc (len * sizeof (wchar_t));
39 + if (out)
40 + MultiByteToWideChar (CP_UTF8, 0, utf8, -1, out, len);
41 + return out;
43 +#endif
45 static void load_fonts_from_dir(ASS_Library *library, const char *dir)
47 - DIR *d = opendir(dir);
48 + wchar_t *dirw = ToWide(dir);
49 + _TDIR *d = _topendir(dirw);
50 + free(dirw);
51 if (!d)
52 return;
53 while (1) {
54 - struct dirent *entry = readdir(d);
55 + struct _tdirent *entry = _treaddir(d);
56 if (!entry)
57 break;
58 + char* d_name = FromWide(entry->d_name);
59 if (entry->d_name[0] == '.')
60 + {
61 + free(d_name);
62 continue;
63 + }
64 char fullname[4096];
65 - snprintf(fullname, sizeof(fullname), "%s/%s", dir, entry->d_name);
66 + _snprintf(fullname, sizeof(fullname), "%s/%s", dir, d_name);
67 size_t bufsize = 0;
68 ass_msg(library, MSGL_INFO, "Loading font file '%s'", fullname);
69 void *data = read_file(library, fullname, &bufsize);
70 if (data) {
71 - ass_add_font(library, entry->d_name, data, bufsize);
72 + ass_add_font(library, d_name, data, bufsize);
73 free(data);
75 + free(d_name);
77 - closedir(d);
78 + _tclosedir(d);
81 /**