[MPlayer-cvslog] r21474 - in trunk/libass: ass.c ass.h ass_cache.c ass_font.c ass_fontconfig.c ass_fontconfig.h ass_library.c ass_library.h ass_render.c
eugeni
subversion at mplayerhq.hu
Sun Dec 3 18:59:13 CET 2006
Author: eugeni
Date: Sun Dec 3 18:59:13 2006
New Revision: 21474
Modified:
trunk/libass/ass.c
trunk/libass/ass.h
trunk/libass/ass_cache.c
trunk/libass/ass_font.c
trunk/libass/ass_fontconfig.c
trunk/libass/ass_fontconfig.h
trunk/libass/ass_library.c
trunk/libass/ass_library.h
trunk/libass/ass_render.c
Log:
Keep embedded fonts in ass_library_t and perform actual disk write
in fontconfig initialization. This is required for some fontconfig-related
improvements.
Modified: trunk/libass/ass.c
==============================================================================
--- trunk/libass/ass.c (original)
+++ trunk/libass/ass.c Sun Dec 3 18:59:13 2006
@@ -1046,86 +1046,6 @@
return 0;
}
-static char* validate_fname(char* name)
-{
- char* fname;
- char* p;
- char* q;
- unsigned code;
- int sz = strlen(name);
-
- q = fname = malloc(sz + 1);
- p = name;
- while (*p) {
- code = utf8_get_char(&p);
- if (code == 0)
- break;
- if ( (code > 0x7F) ||
- (code == '\\') ||
- (code == '/') ||
- (code == ':') ||
- (code == '*') ||
- (code == '?') ||
- (code == '<') ||
- (code == '>') ||
- (code == '|') ||
- (code == 0))
- {
- *q++ = '_';
- } else {
- *q++ = code;
- }
- if (p - name > sz)
- break;
- }
- *q = 0;
- return fname;
-}
-
-/**
- * \brief Add a memory font.
- * \param name attachment name
- * \param data binary font data
- * \param data_size data size
-*/
-void ass_add_font(ass_library_t* library, const char* name, char* data, int data_size)
-{
- char buf[1000];
- FILE* fp = 0;
- int rc;
- struct stat st;
- char* fname;
- const char* fonts_dir = library->fonts_dir;
-
- if (!fonts_dir)
- return;
- rc = stat(fonts_dir, &st);
- if (rc) {
- int res;
-#ifndef __MINGW32__
- res = mkdir(fonts_dir, 0700);
-#else
- res = mkdir(fonts_dir);
-#endif
- if (res) {
- mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_FailedToCreateDirectory, fonts_dir);
- }
- } else if (!S_ISDIR(st.st_mode)) {
- mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_NotADirectory, fonts_dir);
- }
-
- fname = validate_fname((char*)name);
-
- snprintf(buf, 1000, "%s/%s", fonts_dir, fname);
- free(fname);
-
- fp = fopen(buf, "wb");
- if (!fp) return;
-
- fwrite(data, data_size, 1, fp);
- fclose(fp);
-}
-
long long ass_step_sub(ass_track_t* track, long long now, int movement) {
int i;
Modified: trunk/libass/ass.h
==============================================================================
--- trunk/libass/ass.h (original)
+++ trunk/libass/ass.h Sun Dec 3 18:59:13 2006
@@ -182,7 +182,7 @@
* \param data binary font data
* \param data_size data size
*/
-void ass_add_font(ass_library_t* library, const char* name, char* data, int data_size);
+void ass_add_font(ass_library_t* library, char* name, char* data, int data_size);
/**
* \brief Calculates timeshift from now to the start of some other subtitle event, depending on movement parameter
Modified: trunk/libass/ass_cache.c
==============================================================================
--- trunk/libass/ass_cache.c (original)
+++ trunk/libass/ass_cache.c Sun Dec 3 18:59:13 2006
@@ -27,6 +27,7 @@
#include <assert.h>
#include "mputils.h"
+#include "ass.h"
#include "ass_fontconfig.h"
#include "ass_font.h"
#include "ass_bitmap.h"
Modified: trunk/libass/ass_font.c
==============================================================================
--- trunk/libass/ass_font.c (original)
+++ trunk/libass/ass_font.c Sun Dec 3 18:59:13 2006
@@ -26,6 +26,8 @@
#include FT_SYNTHESIS_H
#include FT_GLYPH_H
+#include "ass.h"
+#include "ass_library.h"
#include "ass_font.h"
#include "ass_bitmap.h"
#include "ass_cache.h"
Modified: trunk/libass/ass_fontconfig.c
==============================================================================
--- trunk/libass/ass_fontconfig.c (original)
+++ trunk/libass/ass_fontconfig.c Sun Dec 3 18:59:13 2006
@@ -28,6 +28,8 @@
#include <sys/stat.h>
#include "mputils.h"
+#include "ass.h"
+#include "ass_library.h"
#include "ass_fontconfig.h"
#ifdef HAVE_FONTCONFIG
@@ -184,6 +186,89 @@
return fontconfig_select_with_charset(priv, family, bold, italic, index, 0);
}
+static char* validate_fname(char* name)
+{
+ char* fname;
+ char* p;
+ char* q;
+ unsigned code;
+ int sz = strlen(name);
+
+ q = fname = malloc(sz + 1);
+ p = name;
+ while (*p) {
+ code = utf8_get_char(&p);
+ if (code == 0)
+ break;
+ if ( (code > 0x7F) ||
+ (code == '\\') ||
+ (code == '/') ||
+ (code == ':') ||
+ (code == '*') ||
+ (code == '?') ||
+ (code == '<') ||
+ (code == '>') ||
+ (code == '|') ||
+ (code == 0))
+ {
+ *q++ = '_';
+ } else {
+ *q++ = code;
+ }
+ if (p - name > sz)
+ break;
+ }
+ *q = 0;
+ return fname;
+}
+
+/**
+ * \brief Process embedded matroska font. Saves it to ~/.mplayer/fonts.
+ * \param name attachment name
+ * \param data binary font data
+ * \param data_size data size
+*/
+static void process_fontdata(fc_instance_t* priv, ass_library_t* library, int idx)
+{
+ char buf[1000];
+ FILE* fp = 0;
+ int rc;
+ struct stat st;
+ char* fname;
+ const char* name = library->fontdata[idx].name;
+ const char* data = library->fontdata[idx].data;
+ int data_size = library->fontdata[idx].size;
+ const char* fonts_dir = library->fonts_dir;
+
+ if (!fonts_dir)
+ return;
+ rc = stat(fonts_dir, &st);
+ if (rc) {
+ int res;
+#ifndef __MINGW32__
+ res = mkdir(fonts_dir, 0700);
+#else
+ res = mkdir(fonts_dir);
+#endif
+ if (res) {
+ mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_FailedToCreateDirectory, fonts_dir);
+ }
+ } else if (!S_ISDIR(st.st_mode)) {
+ mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_NotADirectory, fonts_dir);
+ }
+
+ fname = validate_fname((char*)name);
+
+ snprintf(buf, 1000, "%s/%s", fonts_dir, fname);
+ free(fname);
+
+ fp = fopen(buf, "wb");
+ if (!fp) return;
+
+ fwrite(data, data_size, 1, fp);
+ fclose(fp);
+}
+
/**
* \brief Init fontconfig.
* \param dir additional directoryu for fonts
@@ -191,11 +276,13 @@
* \param path default font path
* \return pointer to fontconfig private data
*/
-fc_instance_t* fontconfig_init(const char* dir, const char* family, const char* path)
+fc_instance_t* fontconfig_init(ass_library_t* library, const char* family, const char* path)
{
int rc;
struct stat st;
fc_instance_t* priv = calloc(1, sizeof(fc_instance_t));
+ const char* dir = library->fonts_dir;
+ int i;
rc = FcInit();
assert(rc);
@@ -206,6 +293,9 @@
return 0;
}
+ for (i = 0; i < library->num_fontdata; ++i)
+ process_fontdata(priv, library, i);
+
if (FcDirCacheValid((const FcChar8 *)dir) == FcFalse)
{
mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_UpdatingFontCache);
@@ -265,7 +355,7 @@
return priv->path_default;
}
-fc_instance_t* fontconfig_init(const char* dir, const char* family, const char* path)
+fc_instance_t* fontconfig_init(ass_library_t* library, const char* family, const char* path)
{
fc_instance_t* priv;
Modified: trunk/libass/ass_fontconfig.h
==============================================================================
--- trunk/libass/ass_fontconfig.h (original)
+++ trunk/libass/ass_fontconfig.h Sun Dec 3 18:59:13 2006
@@ -27,7 +27,7 @@
typedef struct fc_instance_s fc_instance_t;
-fc_instance_t* fontconfig_init(const char* dir, const char* family, const char* path);
+fc_instance_t* fontconfig_init(ass_library_t* library, const char* family, const char* path);
char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index);
void fontconfig_done(fc_instance_t* priv);
Modified: trunk/libass/ass_library.c
==============================================================================
--- trunk/libass/ass_library.c (original)
+++ trunk/libass/ass_library.c Sun Dec 3 18:59:13 2006
@@ -71,3 +71,19 @@
*q = strdup(*p);
priv->style_overrides[cnt] = NULL;
}
+
+static void grow_array(void **array, int nelem, size_t elsize)
+{
+ if (!(nelem & 31))
+ *array = realloc(*array, (nelem + 32) * elsize);
+}
+
+void ass_add_font(ass_library_t* priv, char* name, char* data, int size)
+{
+ grow_array((void**)&priv->fontdata, priv->num_fontdata, sizeof(*priv->fontdata));
+ priv->fontdata[priv->num_fontdata].name = name;
+ priv->fontdata[priv->num_fontdata].data = data;
+ priv->fontdata[priv->num_fontdata].size = size;
+ priv->num_fontdata ++;
+}
+
Modified: trunk/libass/ass_library.h
==============================================================================
--- trunk/libass/ass_library.h (original)
+++ trunk/libass/ass_library.h Sun Dec 3 18:59:13 2006
@@ -21,10 +21,19 @@
#ifndef __ASS_LIBRARY_H__
#define __ASS_LIBRARY_H__
+typedef struct ass_fontdata_s {
+ char* name;
+ char* data;
+ int size;
+} ass_fontdata_t;
+
struct ass_library_s {
char* fonts_dir;
int extract_fonts;
char** style_overrides;
+
+ ass_fontdata_t* fontdata;
+ int num_fontdata;
};
#endif
Modified: trunk/libass/ass_render.c
==============================================================================
--- trunk/libass/ass_render.c (original)
+++ trunk/libass/ass_render.c Sun Dec 3 18:59:13 2006
@@ -1928,7 +1928,7 @@
if (priv->fontconfig_priv)
fontconfig_done(priv->fontconfig_priv);
- priv->fontconfig_priv = fontconfig_init(priv->library->fonts_dir, default_family, default_font);
+ priv->fontconfig_priv = fontconfig_init(priv->library, default_family, default_font);
return !!priv->fontconfig_priv;
}
More information about the MPlayer-cvslog
mailing list