Add support for attach a file with metrics information to the font.
Fonts like Type 1, have one file with the glyph image and another file with metrics and kerning information, this try to search if the font have this information and load (try open the same file but with the .afm and .pfm extension). Also add a function to load the same information from memory, just in case that in some point we add a font like this.
This commit is contained in:
@@ -37,6 +37,9 @@ void BLF_exit(void);
|
||||
int BLF_load(char *name);
|
||||
int BLF_load_mem(char *name, unsigned char *mem, int mem_size);
|
||||
|
||||
/* Attach a file with metrics information from memory. */
|
||||
void BLF_metrics_attach(unsigned char *mem, int mem_size);
|
||||
|
||||
/*
|
||||
* Set/Get the current font.
|
||||
*/
|
||||
|
||||
@@ -156,6 +156,15 @@ int BLF_load(char *name)
|
||||
return(i);
|
||||
}
|
||||
|
||||
void BLF_metrics_attach(unsigned char *mem, int mem_size)
|
||||
{
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font)
|
||||
blf_font_attach_from_mem(font, mem, mem_size);
|
||||
}
|
||||
|
||||
int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
|
||||
{
|
||||
FontBLF *font;
|
||||
|
||||
@@ -173,3 +173,37 @@ int blf_dir_split(const char *str, char *file, int *size)
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Some font have additional file with metrics information,
|
||||
* in general, the extension of the file is: .afm or .pfm
|
||||
*/
|
||||
char *blf_dir_metrics_search(char *filename)
|
||||
{
|
||||
char *mfile;
|
||||
char *s;
|
||||
|
||||
mfile= BLI_strdup(filename);
|
||||
s= strrchr(mfile, '.');
|
||||
if (s) {
|
||||
if (strlen(s) < 4) {
|
||||
MEM_freeN(mfile);
|
||||
return(NULL);
|
||||
}
|
||||
s++;
|
||||
s[0]= 'a';
|
||||
s[1]= 'f';
|
||||
s[2]= 'm';
|
||||
|
||||
/* first check .afm */
|
||||
if (BLI_exist(s))
|
||||
return(s);
|
||||
|
||||
/* and now check .pfm */
|
||||
s[0]= 'p';
|
||||
|
||||
if (BLI_exist(s))
|
||||
return(s);
|
||||
}
|
||||
MEM_freeN(mfile);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
@@ -308,6 +308,7 @@ FontBLF *blf_font_new(char *name, char *filename)
|
||||
{
|
||||
FontBLF *font;
|
||||
FT_Error err;
|
||||
char *mfile;
|
||||
|
||||
font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new");
|
||||
err= FT_New_Face(global_ft_lib, filename, 0, &font->face);
|
||||
@@ -324,12 +325,28 @@ FontBLF *blf_font_new(char *name, char *filename)
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
mfile= blf_dir_metrics_search(filename);
|
||||
if (mfile) {
|
||||
err= FT_Attach_File(font->face, mfile);
|
||||
MEM_freeN(mfile);
|
||||
}
|
||||
|
||||
font->name= BLI_strdup(name);
|
||||
font->filename= BLI_strdup(filename);
|
||||
blf_font_fill(font);
|
||||
return(font);
|
||||
}
|
||||
|
||||
void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, int mem_size)
|
||||
{
|
||||
FT_Open_Args open;
|
||||
|
||||
open.flags= FT_OPEN_MEMORY;
|
||||
open.memory_base= (FT_Byte *)mem;
|
||||
open.memory_size= mem_size;
|
||||
FT_Attach_Stream(font->face, &open);
|
||||
}
|
||||
|
||||
FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size)
|
||||
{
|
||||
FontBLF *font;
|
||||
|
||||
@@ -33,6 +33,7 @@ unsigned int blf_hash(unsigned int val);
|
||||
int blf_utf8_next(unsigned char *buf, int *iindex);
|
||||
|
||||
char *blf_dir_search(const char *file);
|
||||
char *blf_dir_metrics_search(char *filename);
|
||||
int blf_dir_split(const char *str, char *file, int *size);
|
||||
|
||||
int blf_font_init(void);
|
||||
@@ -40,6 +41,8 @@ void blf_font_exit(void);
|
||||
|
||||
FontBLF *blf_font_new(char *name, char *filename);
|
||||
FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size);
|
||||
void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, int mem_size);
|
||||
|
||||
void blf_font_size(FontBLF *font, int size, int dpi);
|
||||
void blf_font_draw(FontBLF *font, char *str);
|
||||
void blf_font_boundbox(FontBLF *font, char *str, rctf *box);
|
||||
|
||||
Reference in New Issue
Block a user