summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-08-28 19:32:46 +0200
committerwm4 <wm4@nowhere>2015-08-28 19:32:46 +0200
commit571185341f3e58bd57a823070dde30c66491a4ee (patch)
tree45f9ccfb5ad23b185f2761e8f515f6e849324c51
parent14473afaa2ff66236dc93212f102eec867deeb37 (diff)
downloadlibass-571185341f3e58bd57a823070dde30c66491a4ee.tar.bz2
libass-571185341f3e58bd57a823070dde30c66491a4ee.tar.xz
fontselect: reimplement ass_set_fonts_dir() functionality
ass_set_fonts_dir() is supposed to enable all fonts in a specific directory. The implementation for it was dropped with the commit introducing the new fontselect code. Some users were relying on it, so we need it back. It used to be implemented using a single fontconfig call. But since this has to work even if fontconfig support is not even compiled, a new implementation is needed. This commit adds very simple and low-effort support for it. It loads all files into memory, and then lets the memory font code do the rest. A more efficient implementation would be possible, for example by implementing a new font provider, which serves get_data requests from open file handles. Anyone who wants to do this is welcome to try, and this commit is just the minimum to restore the lost feature.
-rw-r--r--libass/ass.c2
-rw-r--r--libass/ass_fontselect.c29
-rw-r--r--libass/ass_library.h2
3 files changed, 32 insertions, 1 deletions
diff --git a/libass/ass.c b/libass/ass.c
index 01dd2eb..b51cf2e 100644
--- a/libass/ass.c
+++ b/libass/ass.c
@@ -1031,7 +1031,7 @@ out:
* \param bufsize out: file size
* \return pointer to file contents. Caller is responsible for its deallocation.
*/
-static char *read_file(ASS_Library *library, char *fname, size_t *bufsize)
+char *read_file(ASS_Library *library, char *fname, size_t *bufsize)
{
int res;
long sz;
diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c
index 0514d84..6441caa 100644
--- a/libass/ass_fontselect.c
+++ b/libass/ass_fontselect.c
@@ -28,7 +28,10 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <inttypes.h>
+#include <limits.h>
#include <ft2build.h>
+#include <sys/types.h>
+#include <dirent.h>
#include FT_FREETYPE_H
#include FT_SFNT_NAMES_H
#include FT_TRUETYPE_IDS_H
@@ -156,6 +159,28 @@ static ASS_FontProviderFuncs ft_funcs = {
NULL
};
+static void load_fonts_from_dir(ASS_Library *library, const char *dir)
+{
+ DIR *d = opendir(dir);
+ if (!d)
+ return;
+ while (1) {
+ struct dirent *entry = readdir(d);
+ if (!entry)
+ break;
+ char fullname[PATH_MAX];
+ snprintf(fullname, sizeof(fullname), "%s/%s", dir, entry->d_name);
+ size_t bufsize = 0;
+ ass_msg(library, MSGL_WARN, "Loading font file '%s'", fullname);
+ void *data = read_file(library, fullname, &bufsize);
+ if (data) {
+ ass_add_font(library, entry->d_name, data, bufsize);
+ free(data);
+ }
+ }
+ closedir(d);
+}
+
/**
* \brief Create a bare font provider.
* \param selector parent selector. The provider will be attached to it.
@@ -870,6 +895,10 @@ ass_embedded_fonts_add_provider(ASS_Library *lib, ASS_FontSelector *selector,
if (priv == NULL)
return NULL;
+ if (lib->fonts_dir && lib->fonts_dir[0]) {
+ load_fonts_from_dir(lib, lib->fonts_dir);
+ }
+
for (i = 0; i < lib->num_fontdata; ++i)
process_fontdata(priv, lib, ftlib, i);
diff --git a/libass/ass_library.h b/libass/ass_library.h
index 8faf15e..8144f8e 100644
--- a/libass/ass_library.h
+++ b/libass/ass_library.h
@@ -38,4 +38,6 @@ struct ass_library {
void *msg_callback_data;
};
+char *read_file(struct ass_library *library, char *fname, size_t *bufsize);
+
#endif /* LIBASS_LIBRARY_H */