static GF_Err ft_init_font_engine(GF_FontReader *dr) { const char *sOpt; FTBuilder *ftpriv = (FTBuilder *)dr->udta; sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "FontDirectory"); if (!sOpt) return GF_BAD_PARAM; /*inits freetype*/ if (FT_Init_FreeType(&ftpriv->library) ) { GF_LOG(GF_LOG_ERROR, GF_LOG_PARSER, ("[FreeType] Cannot initialize FreeType\n")); return GF_IO_ERR; } while (sOpt) { char dir[GF_MAX_PATH]; char *sep = (char *) strchr(sOpt, ','); if (sep) sep[0] = 0; strcpy(dir, sOpt); while ( (dir[strlen(dir)-1] == '\n') || (dir[strlen(dir)-1] == '\r') ) dir[strlen(dir)-1] = 0; if (dir[strlen(dir)-1] != GF_PATH_SEPARATOR) { char ext[2]; ext[0] = GF_PATH_SEPARATOR; ext[1] = 0; strcat(dir, ext); } gf_list_add(ftpriv->font_dirs, gf_strdup(dir) ); if (!sep) break; sep[0] = ','; sOpt = sep+1; } sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "RescanFonts"); if (!sOpt || !strcmp(sOpt, "yes") ) ft_rescan_fonts(dr); if (!ftpriv->font_serif) { sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "FontSerif"); ftpriv->font_serif = gf_strdup(sOpt ? sOpt : ""); } if (!ftpriv->font_sans) { sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "FontSans"); ftpriv->font_sans = gf_strdup(sOpt ? sOpt : ""); } if (!ftpriv->font_fixed) { sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "FontFixed"); ftpriv->font_fixed = gf_strdup(sOpt ? sOpt : ""); } GF_LOG(GF_LOG_DEBUG, GF_LOG_PARSER, ("[FreeType] Init OK - %d font directory (first %s)\n", gf_list_count(ftpriv->font_dirs), gf_list_get(ftpriv->font_dirs, 0) )); return GF_OK; }
static GF_Err ft_init_font_engine(GF_FontReader *dr) { const char *sOpt; FTBuilder *ftpriv = (FTBuilder *)dr->udta; sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "FontDirectory"); if (!sOpt) return GF_BAD_PARAM; /*inits freetype*/ if (FT_Init_FreeType(&ftpriv->library) ) { GF_LOG(GF_LOG_ERROR, GF_LOG_PARSER, ("[FreeType] Cannot initialize FreeType\n")); return GF_IO_ERR; } /*remove the final delimiter*/ ftpriv->font_dir = gf_strdup(sOpt); while ( (ftpriv->font_dir[strlen(ftpriv->font_dir)-1] == '\n') || (ftpriv->font_dir[strlen(ftpriv->font_dir)-1] == '\r') ) ftpriv->font_dir[strlen(ftpriv->font_dir)-1] = 0; /*store font path*/ if (ftpriv->font_dir[strlen(ftpriv->font_dir)-1] != GF_PATH_SEPARATOR) { char ext[2], *temp; ext[0] = GF_PATH_SEPARATOR; ext[1] = 0; temp = gf_malloc(sizeof(char) * (strlen(ftpriv->font_dir) + 2)); strcpy(temp, ftpriv->font_dir); strcat(temp, ext); gf_free(ftpriv->font_dir); ftpriv->font_dir = temp; } sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "RescanFonts"); if (!sOpt || !strcmp(sOpt, "yes") ) ft_rescan_fonts(dr); sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "FontSerif"); ftpriv->font_serif = gf_strdup(sOpt ? sOpt : ""); sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "FontSans"); ftpriv->font_sans = gf_strdup(sOpt ? sOpt : ""); sOpt = gf_modules_get_option((GF_BaseInterface *)dr, "FontEngine", "FontFixed"); ftpriv->font_fixed = gf_strdup(sOpt ? sOpt : ""); GF_LOG(GF_LOG_DEBUG, GF_LOG_PARSER, ("[FreeType] Init OK - font directory %s\n", ftpriv->font_dir)); return GF_OK; }