*/}}
Explorar el Código

Font loader typo and custom font path when compiling lagui.

YimingWu hace 2 años
padre
commit
c0e8f87e93
Se han modificado 2 ficheros con 21 adiciones y 6 borrados
  1. 9 2
      CMakeLists.txt
  2. 12 4
      la_tns_kernel.c

+ 9 - 2
CMakeLists.txt

@@ -2,7 +2,13 @@ cmake_minimum_required(VERSION 3.1)
 project (lagui)
 
 if (POLICY CMP0072)
-  set(OpenGL_GL_PREFERENCE GLVND)
+    set(OpenGL_GL_PREFERENCE GLVND)
+endif()
+
+SET(LAGUI_FONT_CUSTOM_PATH  $ENV{HOME}/.local/share/fonts/lagui CACHE STRING "Where to install lagui fonts")
+
+if (NOT DEFINED ${LAGUI_FONT_CUSTOM_PATH})
+    set(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui)
 endif()
 
 find_package(OpenGL REQUIRED)
@@ -16,6 +22,7 @@ file(GLOB_RECURSE SOURCE_FILES
 file(GLOB_RECURSE HEADER_FILES 
 	./*.h ./*.hpp ./resources/*.h ./resources/*.hpp)
 
+add_definitions(-DLAGUI_FONT_CUSTOM_PATH=\"${LAGUI_FONT_CUSTOM_PATH}\")
 add_definitions(-w)
 
 include_directories(
@@ -56,4 +63,4 @@ install(FILES ${HEADER_FILES} DESTINATION include/lagui)
 install(TARGETS lagui EXPORT lagui-targets DESTINATION lib/lagui)
 install(EXPORT lagui-targets DESTINATION lib/lagui)
 install(FILES lagui-config.cmake DESTINATION lib/lagui)
-install(FILES ${LAGUI_FONTS} DESTINATION $ENV{HOME}/.local/share/fonts/lagui)
+install(FILES ${LAGUI_FONTS} DESTINATION ${LAGUI_FONT_CUSTOM_PATH})

+ 12 - 4
la_tns_kernel.c

@@ -2928,6 +2928,12 @@ int tnsInvalidateFontCache(){
 }
 tnsFontSingleCharacter *tfntFetchCharTextureIDW(uint32_t ch, int UseMono);
 
+#ifndef LAGUI_FONT_CUSTOM_PATH
+#define LAGUI_FONT_CUSTOM_PATH "/usr/share/fonts/opentype/noto/"
+#endif
+
+const char* TNS_FONT_CUSTOM=LAGUI_FONT_CUSTOM_PATH;
+
 const char* TNS_FONT_LOAD_OPTIONS[9]={"","fonts/","lagui/fonts/","../","../fonts/","../lagui/fonts/","../../","../../fonts/","../../lagui/fonts/"};
 const char* TNS_FONT_LOAD_OPTIONS_FROM_HOME[2]={".local/share/fonts/lagui/",".local/share/fonts/"};
 
@@ -2940,9 +2946,10 @@ int tnsLoadSystemFontMono(char* from, char* mono){
     for(int i=0;i<f->NumFaces;i++){
         if(!FT_Get_Advance(f->ftface[i],L'我',FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP, &full_adv)) break;
     }
-    for(int i=-1;i<11;i++){
+    for(int i=-2;i<11;i++){
         char* option;
-        if(i<9){ option=(i<0)?from:TNS_FONT_LOAD_OPTIONS[i]; sprintf(buf,"%s%s%s",&MAIN.WorkingDirectory->Ptr,option,mono); }
+        if(i==-2){ sprintf(buf,"%s%s%s",TNS_FONT_CUSTOM,TNS_FONT_CUSTOM[strlen(TNS_FONT_CUSTOM)-1]=='/'?"":"/",mono); }
+        elif(i<9){ option=(i==-1)?from:TNS_FONT_LOAD_OPTIONS[i]; sprintf(buf,"%s%s%s",MAIN.WorkingDirectory->Ptr,option,mono); }
         else{ option=TNS_FONT_LOAD_OPTIONS_FROM_HOME[i-9]; sprintf(buf,"%s/%s%s",getenv("HOME"),option,mono); }
         if (FT_New_Face(f->ftlib, buf, 0, &f->ftfacemono)) continue;
         FT_Select_Charmap(f->ftfacemono, FT_ENCODING_UNICODE);
@@ -2976,9 +2983,10 @@ int tnsLoadSystemFont(char* from, char* name){
     }
 
     int GenHeight=LA_RH*MAIN.FontSize;
-    for(int i=-1;i<11;i++){
+    for(int i=-2;i<11;i++){
         char* option;
-        if(i<9){ option=(i<0)?from:TNS_FONT_LOAD_OPTIONS[i]; sprintf(buf,"%s%s%s",MAIN.WorkingDirectory->Ptr,option,name); }
+        if(i==-2){ sprintf(buf,"%s%s%s",TNS_FONT_CUSTOM,TNS_FONT_CUSTOM[strlen(TNS_FONT_CUSTOM)-1]=='/'?"":"/",name); }
+        elif(i<9){ option=(i==-1)?from:TNS_FONT_LOAD_OPTIONS[i]; sprintf(buf,"%s%s%s",MAIN.WorkingDirectory->Ptr,option,name); }
         else{ option=TNS_FONT_LOAD_OPTIONS_FROM_HOME[i-9]; sprintf(buf,"%s/%s%s",getenv("HOME"),option,name); }
         FT_Face face; FT_Long i,num_faces; FT_Open_Args args; args.flags=FT_OPEN_PATHNAME; args.pathname=buf;
         if(FT_Open_Face(f->ftlib, &args, -1, &face )) continue;