forked from old/legacy-imlib2
Add support for TrueType Collections (suggested by Arne Goetje, bug 487).
The font specifier format is now "font_name[:faceidx]/size" where faceidx is an optional face index. SVN revision: 34721
This commit is contained in:
parent
48995a4b5a
commit
aa033943a6
|
@ -77,7 +77,6 @@ char **imlib_font_list_font_path(int *num_ret);
|
||||||
char **imlib_font_list_fonts(int *num_ret);
|
char **imlib_font_list_fonts(int *num_ret);
|
||||||
|
|
||||||
ImlibFont *imlib_font_load_joined(const char *name);
|
ImlibFont *imlib_font_load_joined(const char *name);
|
||||||
ImlibFont *imlib_font_load(const char *name, int size);
|
|
||||||
void imlib_font_free(ImlibFont * fn);
|
void imlib_font_free(ImlibFont * fn);
|
||||||
int imlib_font_insert_into_fallback_chain_imp(ImlibFont * fn,
|
int imlib_font_insert_into_fallback_chain_imp(ImlibFont * fn,
|
||||||
ImlibFont * fallback);
|
ImlibFont * fallback);
|
||||||
|
|
|
@ -23,6 +23,7 @@ static char **fpath = NULL;
|
||||||
static int fpath_num = 0;
|
static int fpath_num = 0;
|
||||||
static Imlib_Object_List *fonts = NULL;
|
static Imlib_Object_List *fonts = NULL;
|
||||||
|
|
||||||
|
static ImlibFont *imlib_font_load(const char *name, int faceidx, int size);
|
||||||
static int font_modify_cache_cb(Imlib_Hash * hash, const char *key,
|
static int font_modify_cache_cb(Imlib_Hash * hash, const char *key,
|
||||||
void *data, void *fdata);
|
void *data, void *fdata);
|
||||||
static int font_flush_free_glyph_cb(Imlib_Hash * hash, const char *key,
|
static int font_flush_free_glyph_cb(Imlib_Hash * hash, const char *key,
|
||||||
|
@ -34,17 +35,31 @@ static int font_flush_free_glyph_cb(Imlib_Hash * hash, const char *key,
|
||||||
ImlibFont *
|
ImlibFont *
|
||||||
imlib_font_load_joined(const char *fontname)
|
imlib_font_load_joined(const char *fontname)
|
||||||
{
|
{
|
||||||
int j, size;
|
int j, k, size, faceidx;
|
||||||
char *name = NULL, *file = NULL, *tmp = NULL;
|
char *name = NULL, *file = NULL, *tmp = NULL;
|
||||||
ImlibFont *fn;
|
ImlibFont *fn;
|
||||||
|
|
||||||
/* split font name (in format name/size) */
|
/* split font name (in format name[:faceidx]/size) */
|
||||||
for (j = strlen(fontname) - 1; (j >= 0) && (fontname[j] != '/'); j--);
|
for (j = strlen(fontname) - 1; (j >= 0) && (fontname[j] != '/'); j--);
|
||||||
/* no "/" in font after the first char */
|
/* no "/" in font after the first char */
|
||||||
if (j <= 0)
|
if (j <= 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
/* get size */
|
/* get size */
|
||||||
size = atoi(&(fontname[j + 1]));
|
size = atoi(&(fontname[j + 1]));
|
||||||
|
/* split font faceidx index (in format name[:faceidx]/size) */
|
||||||
|
faceidx = 0;
|
||||||
|
for (k = j - 1; k > 0; k--)
|
||||||
|
{
|
||||||
|
if (fontname[k] >= '0' && fontname[k] <= '9')
|
||||||
|
continue;
|
||||||
|
if (fontname[k] != ':')
|
||||||
|
break;
|
||||||
|
faceidx = atoi(&(fontname[k + 1]));
|
||||||
|
if (faceidx < 0)
|
||||||
|
faceidx = 0;
|
||||||
|
j = k;
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* split name in front off */
|
/* split name in front off */
|
||||||
name = malloc((j + 1) * sizeof(char));
|
name = malloc((j + 1) * sizeof(char));
|
||||||
memcpy(name, fontname, j);
|
memcpy(name, fontname, j);
|
||||||
|
@ -107,13 +122,13 @@ imlib_font_load_joined(const char *fontname)
|
||||||
/* didnt find a file? abort */
|
/* didnt find a file? abort */
|
||||||
if (!file)
|
if (!file)
|
||||||
return NULL;
|
return NULL;
|
||||||
fn = imlib_font_load(file, size);
|
fn = imlib_font_load(file, faceidx, size);
|
||||||
free(file);
|
free(file);
|
||||||
return fn;
|
return fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImlibFont *
|
static ImlibFont *
|
||||||
imlib_font_load(const char *name, int size)
|
imlib_font_load(const char *name, int faceidx, int size)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
ImlibFont *fn;
|
ImlibFont *fn;
|
||||||
|
@ -128,7 +143,7 @@ imlib_font_load(const char *name, int size)
|
||||||
fn = malloc(sizeof(ImlibFont));
|
fn = malloc(sizeof(ImlibFont));
|
||||||
file = (char *)name;
|
file = (char *)name;
|
||||||
|
|
||||||
error = FT_New_Face(ft_lib, file, 0, &(fn->ft.face));
|
error = FT_New_Face(ft_lib, file, faceidx, &(fn->ft.face));
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
free(fn);
|
free(fn);
|
||||||
|
|
Loading…
Reference in New Issue