-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
set(PROJECT_NAME dotfontscan) | ||
project(${PROJECT_NAME} | ||
VERSION 1.0.0.0 | ||
LANGUAGES C CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_C_STANDARD 99) | ||
file(GLOB C_CXX_FILES *.h *.cpp *.c *.hpp *.cxx) | ||
add_executable(${PROJECT_NAME} ${C_CXX_FILES}) | ||
#添加线程库 | ||
find_package(Threads REQUIRED) | ||
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT}) | ||
#设定HRC文件系统目录为fs | ||
set(HRC_FS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fs/) | ||
#添加3rdparty/HCppBox | ||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../../../ HCppBox EXCLUDE_FROM_ALL) | ||
#启用HCppBox、HRC | ||
hcppbox_enable(${PROJECT_NAME}) | ||
hrc_enable(${PROJECT_NAME}) | ||
|
||
include(FindPkgConfig) | ||
#添加FreeType | ||
pkg_check_modules(FREETYPE2 IMPORTED_TARGET REQUIRED freetype2) | ||
target_link_libraries(${PROJECT_NAME} PkgConfig::FREETYPE2) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
_ _ __ _ | ||
__| | ___ | |_ / _| ___ _ __ | |_ ___ ___ __ _ _ __ | ||
/ _` |/ _ \| __| |_ / _ \| '_ \| __/ __|/ __/ _` | '_ \ | ||
| (_| | (_) | |_| _| (_) | | | | |_\__ \ (_| (_| | | | | | ||
\__,_|\___/ \__|_| \___/|_| |_|\__|___/\___\__,_|_| |_| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
#include "HCPPBox.h" | ||
#include "hbox.h" | ||
#include "hrc.h" | ||
#include <ft2build.h> | ||
#include FT_FREETYPE_H | ||
#include "stdlib.h" | ||
#include "stdio.h" | ||
#include <string> | ||
|
||
|
||
static class ft_lib | ||
{ | ||
FT_Library library; | ||
public: | ||
operator FT_Library() | ||
{ | ||
return library; | ||
} | ||
ft_lib():library(NULL) | ||
{ | ||
FT_Init_FreeType(&library); | ||
} | ||
~ft_lib() | ||
{ | ||
FT_Done_FreeType(library); | ||
} | ||
} g_ft_lib; | ||
|
||
|
||
static int cmd_help(int argc,const char *argv[]); | ||
static int cmd_font(int argc,const char *argv[]); | ||
static struct | ||
{ | ||
const char * cmd; | ||
const char * cmd_short; | ||
int (*cmd_entry)(int argc,const char *argv[]); | ||
const char * usage; | ||
const char * help; | ||
} cmd_list[]= | ||
{ | ||
{ | ||
"--help", | ||
"-h", | ||
cmd_help, | ||
"--help / -h ", | ||
"get help" | ||
}, | ||
{ | ||
"--font", | ||
"-f", | ||
cmd_help, | ||
"--font=[font_file_path] / -f [font_file_path] ", | ||
"fontfile path" | ||
} | ||
}; | ||
|
||
static int cmd_help(int argc,const char *argv[]) | ||
{ | ||
const size_t cmd_max_len=16; | ||
const size_t usage_max_len=50; | ||
{ | ||
//打印banner | ||
const char *banner=(const char *)RCGetHandle("banner"); | ||
if(banner!=NULL) | ||
{ | ||
printf("%s",banner); | ||
} | ||
} | ||
{ | ||
printf("\r\n%s [options]\r\n",argv[0]); | ||
} | ||
{ | ||
//打印标题栏 | ||
for(size_t i=0; i<cmd_max_len; i++) | ||
{ | ||
printf("%s","-"); | ||
} | ||
printf("\t"); | ||
for(size_t i=0; i<usage_max_len; i++) | ||
{ | ||
printf("%s","-"); | ||
} | ||
printf("\r\n"); | ||
} | ||
{ | ||
for(size_t i=0; i<sizeof(cmd_list)/sizeof(cmd_list[0]); i++) | ||
{ | ||
{ | ||
//打印cmd | ||
printf("%s",cmd_list[i].cmd); | ||
int cmd_pad_len=(int)cmd_max_len-strlen(cmd_list[i].cmd); | ||
if(cmd_pad_len > 0) | ||
{ | ||
for(size_t i=0; i<cmd_pad_len; i++) | ||
{ | ||
printf(" "); | ||
} | ||
} | ||
} | ||
printf("\t"); | ||
{ | ||
//打印usage | ||
printf("%s",cmd_list[i].usage); | ||
int usage_pad_len=(int)usage_max_len-strlen(cmd_list[i].usage); | ||
if(usage_pad_len > 0) | ||
{ | ||
for(size_t i=0; i<usage_pad_len; i++) | ||
{ | ||
printf(" "); | ||
} | ||
} | ||
} | ||
printf("\t"); | ||
{ | ||
printf("%s",cmd_list[i].help); | ||
} | ||
printf("\r\n"); | ||
} | ||
} | ||
//退出程序 | ||
exit(0); | ||
return 0; | ||
} | ||
|
||
#ifdef WIN32 | ||
std::string font_file_path("simsun.ttc"); | ||
#else | ||
//默认使用 文泉驿 字体,debian系统(最新版)使用sudo apt-get install fonts-wqy-zenhei安装后即可使用 | ||
std::string font_file_path("/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc"); | ||
#endif | ||
static int cmd_font(int argc,const char *argv[]) | ||
{ | ||
for(int i=0; i<argc; i++) | ||
{ | ||
{ | ||
char temp[4096]= {0}; | ||
const char *para=NULL; | ||
strcat(temp,argv[i]); | ||
for(size_t k=0; k<strlen(temp); k++) | ||
{ | ||
if(temp[k]=='=') | ||
{ | ||
temp[k]='\0'; | ||
para=&temp[k+1]; | ||
break; | ||
} | ||
} | ||
if(strcmp("--font",temp)==0) | ||
{ | ||
if(para!=NULL) | ||
{ | ||
font_file_path=para; | ||
break; | ||
} | ||
} | ||
if(strcmp("-f",argv[i])==0) | ||
{ | ||
if((i+1)<argc) | ||
{ | ||
font_file_path=argv[i+1]; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static void arg_parse(int argc,const char *argv[]) | ||
{ | ||
if(argc==1) | ||
{ | ||
cmd_help(argc,argv); | ||
} | ||
else | ||
{ | ||
for(int i=0; i<argc; i++) | ||
{ | ||
const char *cmd=argv[i]; | ||
for(size_t j=0; j<sizeof(cmd_list)/sizeof(cmd_list[0]); j++) | ||
{ | ||
if(cmd_list[j].cmd_short==NULL) | ||
{ | ||
cmd_list[j].cmd_short=""; | ||
} | ||
if(cmd_list[j].cmd==NULL) | ||
{ | ||
cmd_list[j].cmd=""; | ||
} | ||
if(strcmp(cmd,cmd_list[j].cmd_short)==0) | ||
{ | ||
if(cmd_list[j].cmd_entry!=NULL) | ||
{ | ||
cmd_list[j].cmd_entry(argc,argv); | ||
} | ||
} | ||
{ | ||
char temp[256]= {0}; | ||
strcat(temp,cmd); | ||
for(size_t k=0; k<strlen(temp); k++) | ||
{ | ||
if(temp[k]=='=') | ||
{ | ||
temp[k]='\0'; | ||
} | ||
} | ||
if(strcmp(temp,cmd_list[j].cmd)==0) | ||
{ | ||
if(cmd_list[j].cmd_entry!=NULL) | ||
{ | ||
cmd_list[j].cmd_entry(argc,argv); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
int main(int argc,const char *argv[]) | ||
{ | ||
arg_parse(argc,argv); | ||
|
||
FT_Face face=NULL; | ||
|
||
if(FT_New_Face(g_ft_lib, font_file_path.c_str(), 0, &face)) | ||
{ | ||
printf("FT_New_Face (%s) error!\r\n",font_file_path.c_str()); | ||
return -1; | ||
} | ||
|
||
FT_Done_Face(face); | ||
return 0; | ||
} | ||
|
||
|