From 7d6275a2387681cbbcd76e4c17f48f2f0d3022ae Mon Sep 17 00:00:00 2001 From: Debian Games Team Date: Fri, 17 Oct 2014 17:00:32 +0100 Subject: [PATCH] using_system_fonts # 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 | 4 +++ hedgewars/CMakeLists.txt | 11 +++++++ hedgewars/config.inc.in | 1 + hedgewars/uPhysFSLayer.pas | 36 ++++++++++++++++++----- share/hedgewars/Data/Fonts/CMakeLists.txt | 28 ++++++++++++++++-- 5 files changed, 70 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 725e1a4..6919c17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/hedgewars/CMakeLists.txt b/hedgewars/CMakeLists.txt index 6f31669..b47e128 100644 --- a/hedgewars/CMakeLists.txt +++ b/hedgewars/CMakeLists.txt @@ -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 diff --git a/hedgewars/config.inc.in b/hedgewars/config.inc.in index a9d5708..8abeb23 100644 --- a/hedgewars/config.inc.in +++ b/hedgewars/config.inc.in @@ -26,3 +26,4 @@ const cNetProtoVersion = ${HEDGEWARS_PROTO_VER}; cRevisionString = '${HEDGEWARS_REVISION}'; cHashString = '${HEDGEWARS_HASH}'; cDefaultPathPrefix = '${HEDGEWARS_FULL_DATADIR}/Data'; + cFontsPaths: ${FONTS_DIRS_ARRAY} diff --git a/hedgewars/uPhysFSLayer.pas b/hedgewars/uPhysFSLayer.pas index 6f798d2..3af648a 100644 --- a/hedgewars/uPhysFSLayer.pas +++ b/hedgewars/uPhysFSLayer.pas @@ -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; diff --git a/share/hedgewars/Data/Fonts/CMakeLists.txt b/share/hedgewars/Data/Fonts/CMakeLists.txt index 5dd7e94..3f0212f 100644 --- a/share/hedgewars/Data/Fonts/CMakeLists.txt +++ b/share/hedgewars/Data/Fonts/CMakeLists.txt @@ -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() -- 2.30.2