cleanup and check the duplicated fontname of a new devfont

This commit is contained in:
Vincent Wei
2019-03-01 14:20:46 +08:00
parent 090824cb91
commit d886268eee
5 changed files with 86 additions and 28 deletions
+22 -14
View File
@@ -5469,6 +5469,7 @@ MG_EXPORT int GUIAPI SubtractRect (RECT* rc, const RECT* psrc1, const RECT* psrc
#define FONT_WEIGHT_THIN 't'
#define FONT_WEIGHT_EXTRA_LIGHT 'e'
#define FONT_WEIGHT_LIGHT 'l'
#define FONT_WEIGHT_NORMAL 'n'
#define FONT_WEIGHT_REGULAR 'r'
#define FONT_WEIGHT_MEDIUM 'm'
#define FONT_WEIGHT_DEMIBOLD 'd'
@@ -5487,6 +5488,7 @@ MG_EXPORT int GUIAPI SubtractRect (RECT* rc, const RECT* psrc1, const RECT* psrc
#define FS_WEIGHT_THIN 10
#define FS_WEIGHT_EXTRA_LIGHT 20
#define FS_WEIGHT_LIGHT 30
#define FS_WEIGHT_NORMAL 35
#define FS_WEIGHT_REGULAR 40
#define FS_WEIGHT_MEDIUM 50
#define FS_WEIGHT_DEMIBOLD 60
@@ -5727,7 +5729,7 @@ MG_EXPORT int GUIAPI SubtractRect (RECT* rc, const RECT* psrc1, const RECT* psrc
#define MAXNR_DEVFONTS 8
struct _DEVFONT;
typedef struct _DEVFONT DEVFONT;
typedef struct _DEVFONT DEVFONT;
/**
* The logical font structure.
@@ -6398,41 +6400,47 @@ struct _CHARSETOPS;
typedef struct _FONTOPS FONTOPS;
typedef struct _CHARSETOPS CHARSETOPS;
/* charops fontops devont structure is here. */
/** The device font structure. */
/**
* The device font structure.
* \note All fields are read-only.
*/
struct _DEVFONT {
/**
* The device font name.
* The family name supports aliases since 3.4.0:
*
* <fonttype>-<family[,aliase]*>-<styles>-<width>-<height>-<charsets>
* <fonttype>-<family[,aliase]*>-<styles>-<width>-<height>-<charset[,charset]*>
*
* for example:
*
* ttf-courier,monospace-rrncnn-8-16-ISO8859-1,UTF-8
* ttf-courier,monospace-rrncnn-0-0-ISO8859-1,UTF-8
*/
char name [LEN_UNIDEVFONT_NAME + 1];
/** The styles of the device font. */
DWORD style;
DWORD32 style;
/** The pointer to font operation structure. */
/*
* The following fields are internally used.
* They may changed in the future.
*/
// indicating if the data need to be unloaded before delete a devfont
BOOL need_unload;
// The pointer to font operation structure.
FONTOPS* font_ops;
/** The pointer to character set operation structure. */
// The pointer to character set operation structure.
CHARSETOPS* charset_ops;
/** The pointer to next device font. */
// The pointer to next device font.
struct _DEVFONT* next;
/** The device font used data. */
// The device font used data.
void* data;
/** The device font used relationship. */
// The device font used relationship.
void* relationship;
/** indicating if the data need to be unloaded before delete a devfont*/
BOOL need_unload;
};
/**
+40 -11
View File
@@ -406,6 +406,30 @@ void font_DelMBDevFont (DEVFONT* dev_font)
}
//////////////////////////////////////////////////////////////////////
static DEVFONT* find_devfont(const char* font_name, BOOL is_mbc_list)
{
DEVFONT* head;
DEVFONT* cur;
if (is_mbc_list) {
head = mb_dev_font_head;
}
else {
head = sb_dev_font_head;
}
cur = head;
while (cur) {
if (strcmp (cur->name, font_name) == 0) {
return cur;
}
cur = cur->next;
}
return NULL;
}
static DEVFONT* make_devfont (const char* font_name, void* data, BOOL is_filename)
{
FONTOPS_INFO* fontops_info = __mg_fontops_infos;
@@ -437,6 +461,12 @@ static DEVFONT* make_devfont (const char* font_name, void* data, BOOL is_filenam
return NULL;
}
if (find_devfont(font_name, (charset_ops->bytes_maxlen_char > 1))) {
_MG_PRINTF ("FONT>DevFont: Duplicated devfont name (%s).\n",
font_name);
return NULL;
}
devfont = calloc (1, sizeof (DEVFONT));
devfont->font_ops = fontops_info->fontops;
@@ -501,7 +531,7 @@ static void add_relating_devfonts_to_list (DEVFONT* related_devfont)
}
}
BOOL AddDevFont (const char* font_name, void* data, BOOL is_filename)
static BOOL add_dev_font (const char* font_name, void* data, BOOL is_filename)
{
DEVFONT* devfont = make_devfont (font_name, data, is_filename);
if (devfont == NULL) {
@@ -602,7 +632,7 @@ BOOL font_InitIncoreFonts (void)
#ifdef _MGFONT_RBF
for (i = 0; i < NR_RBFONTS; i++) {
if (!AddDevFont (incore_rbfonts [i]->name, incore_rbfonts [i]->data, FALSE)) {
if (!add_dev_font (incore_rbfonts [i]->name, incore_rbfonts [i]->data, FALSE)) {
_MG_PRINTF ("FONT>DevFont: can not init incore font: %s\n", incore_rbfonts [i]->name);
return FALSE;
}
@@ -611,7 +641,7 @@ BOOL font_InitIncoreFonts (void)
#ifdef _MGFONT_VBF
for (i = 0; i < NR_VBFONTS && incore_vbfonts[i]; i++) {
if (!AddDevFont (incore_vbfonts [i]->name, incore_vbfonts [i], FALSE)) {
if (!add_dev_font (incore_vbfonts [i]->name, incore_vbfonts [i], FALSE)) {
_MG_PRINTF ("FONT>DevFont: can not init incore font: %s\n", incore_vbfonts [i]->name);
return FALSE;
}
@@ -621,7 +651,7 @@ BOOL font_InitIncoreFonts (void)
#ifdef _MGFONT_UPF
for (i = 0; i < NR_UPFONTS && incore_upfonts[i]; i++) {
const char* name = ((UPFV1_FILE_HEADER*)(incore_upfonts [i]->root_dir))->font_name;
if (!AddDevFont (name, incore_upfonts [i], FALSE)) {
if (!add_dev_font (name, incore_upfonts [i], FALSE)) {
_MG_PRINTF ("FONT>DevFont: can not init incore font: %s\n", name);
return FALSE;
}
@@ -700,8 +730,7 @@ one_list:
}
*/
static inline void del_devfont_from_list(const char* font_name, BOOL is_mbc_list)
static void del_devfont_from_list(const char* font_name, BOOL is_mbc_list)
{
DEVFONT* head;
DEVFONT* cur;
@@ -829,16 +858,16 @@ static BOOL init_or_term_specifical_fonts (char* etc_section, BOOL is_unload)
/*add devfont*/
if ((memres = (MEM_RES*)LoadResource (font_file, RES_TYPE_MEM_RES, 0))) {
AddDevFont (font_name, memres->data, FALSE);
add_dev_font (font_name, memres->data, FALSE);
added_num ++;
}
else {
/* [DK] Fix Bug #4801, which introduce a absolute path check error in Windows,
* first to load from sytem res path, else load it directly(relative or absolute path).*/
if ((0 == mg_path_joint(font_path, MAX_PATH + 1, sysres_get_system_res_path(), font_file))
&& ((AddDevFont (font_name, font_path, TRUE)) == TRUE))
&& ((add_dev_font (font_name, font_path, TRUE)) == TRUE))
added_num++;
else if ((AddDevFont (font_name, font_file, TRUE)) == TRUE)
else if ((add_dev_font (font_name, font_file, TRUE)) == TRUE)
added_num++;
}
}
@@ -853,12 +882,12 @@ static BOOL init_or_term_specifical_fonts (char* etc_section, BOOL is_unload)
}
}
BOOL GUIAPI font_InitSpecificalFonts (char* etc_section)
BOOL font_InitSpecificalFonts (char* etc_section)
{
return init_or_term_specifical_fonts (etc_section, FALSE);
}
void GUIAPI font_TermSpecificalFonts (char* etc_section)
void font_TermSpecificalFonts (char* etc_section)
{
init_or_term_specifical_fonts (etc_section, TRUE);
}
+3
View File
@@ -216,6 +216,9 @@ DWORD fontConvertStyle (const char* style_part)
case FONT_WEIGHT_REGULAR:
style |= FS_WEIGHT_REGULAR;
break;
case FONT_WEIGHT_NORMAL:
style |= FS_WEIGHT_NORMAL;
break;
case FONT_WEIGHT_LIGHT:
style |= FS_WEIGHT_LIGHT;
break;
+18 -2
View File
@@ -170,10 +170,26 @@ static PLOGFONT gdiCreateLogFont (const char* type, const char* family,
// do not forward iter
}
else {
DEVFONT* df;
_DBG_PRINTF ("FONT>LogFont: try to match MBC Devfont for family (%s)\n",
name_field);
if ((devfonts[i] = font_GetMatchedMBDevFont (newlf, name_field)) == NULL)
break;
if ((df = font_GetMatchedMBDevFont (newlf, name_field))) {
int j;
// check duplicated.
for (j = 0; j <= i; j++) {
if (df == devfonts[j]) {
// duplicated
_DBG_PRINTF ("FONT>LogFont: ignore the duplicated devfont (%s)\n",
name_field);
break;
}
else if (devfonts[j] == NULL) {
devfonts[j] = df;
break;
}
}
}
iter += n;
if (*iter == ',' || *iter == ' ')
+3 -1
View File
@@ -88,8 +88,10 @@ static inline void set_devfont_scale(LOGFONT* lf, DEVFONT* df,
{
int i;
for (i = 0; i < MAXNR_DEVFONTS; i++) {
if (lf->devfonts[i] == df)
if (lf->devfonts[i] == df) {
lf->scales[i] = s;
break;
}
}
}