using_system_fonts
authorDebian Games Team <pkg-games-devel@lists.alioth.debian.org>
Fri, 17 Oct 2014 16:00:32 +0000 (17:00 +0100)
committerGianfranco Costamagna <costamagnagianfranco@yahoo.it>
Fri, 17 Oct 2014 16:00:32 +0000 (17:00 +0100)
# HG changeset patch
# User sheepluva
# Date 1390062751 -3600
#      Sat Jan 18 17:32:31 2014 +0100
# Branch 0.9.20
# Node ID ab94889bd185654aac3a587c162ed5e4ce90445c
# Parent  f74ae7ee358599195c8e646f1f8e8652d0d38a24
Description:
backport of system fonts inclusion patches

Gbp-Pq: Name using_system_fonts.patch

CMakeLists.txt
hedgewars/CMakeLists.txt
hedgewars/config.inc.in
hedgewars/uPhysFSLayer.pas
share/hedgewars/Data/Fonts/CMakeLists.txt

index 725e1a44629044ce9b1f34f6d8ced31ebf22b83d..6919c179627bc497b095828fc8ae9b4d250fa76d 100644 (file)
@@ -38,6 +38,10 @@ if(UNIX AND NOT APPLE)
     set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path")
 endif()
 
+#system paths for finding required fonts (see share/hedgewars/Data/fonts)
+#subdirectories will NOT be searched.
+#all fonts that can't be found will be bundled with hedgewars
+set(FONTS_DIRS "" CACHE STRING "Additional paths to folders where required fonts can be found ( ; is separator)")
 
 #versioning
 set(CPACK_PACKAGE_VERSION_MAJOR 0)
index 6f31669ac14084f6b14286a0f4ea13671aebd2f8..b47e128c0cd9ee41a604740529c753cad3dd1f68 100644 (file)
@@ -23,6 +23,17 @@ endif(UNIX)
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
+# convert list into pascal array
+list(LENGTH FONTS_DIRS ndirs)
+set(FONTS_DIRS_ARRAY "array [0..${ndirs}] of PChar = (")
+foreach(fontdir ${FONTS_DIRS})
+    set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\n'${fontdir}',")
+endforeach(fontdir)
+set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\nnil);\n")
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
 
 #set the sources with the correct order of dependencies so that cmake won't be confused
 set(engine_sources
index a9d570862ef7da2e4baf441ddea5a9edf533fae3..8abeb23678f5e7976e594848a1f83615e8b42725 100644 (file)
@@ -26,3 +26,4 @@ const cNetProtoVersion = ${HEDGEWARS_PROTO_VER};
       cRevisionString = '${HEDGEWARS_REVISION}';
       cHashString = '${HEDGEWARS_HASH}';
       cDefaultPathPrefix = '${HEDGEWARS_FULL_DATADIR}/Data';
+      cFontsPaths: ${FONTS_DIRS_ARRAY}
index 6f798d21c8d0b26d1ba913eadef5bb6e9fca257b..3af648a78d060b354334835c12015efd0b0eca5d 100644 (file)
@@ -3,6 +3,8 @@ unit uPhysFSLayer;
 interface
 uses SDLh, LuaPas;
 
+{$INCLUDE "config.inc"}
+
 const PhysfsLibName = {$IFDEF PHYSFS_INTERNAL}'libhwphysfs'{$ELSE}'libphysfs'{$ENDIF};
 const PhyslayerLibName = 'libphyslayer';
 
@@ -41,12 +43,13 @@ function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName;
 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl ; external PhyslayerLibName;
 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
 
-function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName;
+function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName;
 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName;
+function PHYSFS_getLastError(): PChar; cdecl; external PhysfsLibName;
 
 procedure hedgewarsMountPackages(); cdecl; external PhyslayerLibName;
 
@@ -127,9 +130,23 @@ begin
         pfsBlockRead:= r
 end;
 
+procedure pfsMount(path: AnsiString; mountpoint: PChar);
+begin
+    if PHYSFS_mount(Str2PChar(path), mountpoint, false) then
+        AddFileLog('[PhysFS] mount ' + path + ' at ' + mountpoint + ' : ok')
+    else
+        AddFileLog('[PhysFS] mount ' + path + ' at ' + mountpoint + ' : FAILED ("' + PHYSFS_getLastError() + '")');
+end;
+
+procedure pfsMountAtRoot(path: AnsiString);
+begin
+    pfsMount(path, '/');
+end;
+
 procedure initModule;
 var i: LongInt;
     cPhysfsId: shortstring;
+    fp: PChar;
 begin
 {$IFDEF HWLIBRARY}
     //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html
@@ -141,16 +158,21 @@ begin
     i:= PHYSFS_init(Str2PChar(cPhysfsId));
     AddFileLog('[PhysFS] init: ' + inttostr(i));
 
-    i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, false);
-    AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i));
-    i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, false);
-    AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i));
+    // mount system fonts paths first
+    for i:= low(cFontsPaths) to high(cFontsPaths) do
+        begin
+            fp := cFontsPaths[i];
+            if fp <> nil then
+                pfsMount(fp, '/Fonts');
+        end;
+
+    pfsMountAtRoot(PathPrefix);
+    pfsMountAtRoot(UserPathPrefix + '/Data');
 
     hedgewarsMountPackages;
 
-    i:= PHYSFS_mount(Str2PChar(UserPathPrefix), nil, false);
     // need access to teams and frontend configs (for bindings)
-    AddFileLog('[PhysFS] mount ' + UserPathPrefix + ': ' + inttostr(i)); 
+    pfsMountAtRoot(UserPathPrefix);
 end;
 
 procedure freeModule;
index 5dd7e942bb889c4072fa61b9c38d2f31ae637c27..3f0212f47d8e8ccff021172740e2607645748273 100644 (file)
@@ -1,4 +1,26 @@
-install(FILES
+set(FONTFILES
     DejaVuSans-Bold.ttf
-    wqy-zenhei.ttc
-    DESTINATION ${SHAREPATH}Data/Fonts)
+    wqy-zenhei.ttc)
+
+if (FONTS_DIRS)
+    foreach(fontfile ${FONTFILES})
+        set(missing 1)
+        foreach(fontdir ${FONTS_DIRS})
+            if (EXISTS "${fontdir}/${fontfile}")
+                message(STATUS "Fonts: Found ${fontfile} in ${fontdir}")
+                set(missing 0)
+                break()
+            endif()
+        endforeach(fontdir)
+        if(missing)
+            set(MISSINGFONTFILES ${MISSINGFONTFILES} ${fontfile})
+            message(STATUS "Fonts: Could not find ${fontfile}, it will be installed")
+        endif()
+    endforeach(fontfile)
+else()
+    set(MISSINGFONTFILES ${FONTFILES})
+endif()
+
+if (MISSINGFONTFILES)
+    install(FILES ${MISSINGFONTFILES} DESTINATION ${SHAREPATH}Data/Fonts)
+endif()