diff --git a/CMakeLists.txt b/CMakeLists.txt index 19e2ea9..c18bf9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -455,6 +455,21 @@ if(FREETYPE_FOUND) ) target_link_libraries(GpFontHandler_FreeType2 PRIVATE Freetype::Freetype) + + + add_executable(GenerateFonts + GenerateFonts/GenerateFonts.cpp + AerofoilPortable/GpAllocator_C.cpp + WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp + ) + target_include_directories(GenerateFonts PRIVATE + Common + GpCommon + PortabilityLayer + AerofoilPortable + WindowsUnicodeToolShim + ) + target_link_libraries(GenerateFonts PortabilityLayer GpFontHandler_FreeType2) endif() diff --git a/ConvertResources.bat b/ConvertResources.bat index 0907a67..89c9392 100644 --- a/ConvertResources.bat +++ b/ConvertResources.bat @@ -8,7 +8,7 @@ x64\Release\gpr2gpa.exe "Packaged\ApplicationResources.gpr" "DefaultTimestamp.ti x64\Release\FTagData.exe "DefaultTimestamp.timestamp" "Packaged\ApplicationResources.gpf" data ozm5 0 0 locked x64\Release\MergeGPF.exe "Packaged\ApplicationResources.gpf" -x64\Release\GenerateFonts.exe +x64\Release\GenerateFonts.exe Resources Packaged x64\Release\MiniRez.exe "Empty.r" Packaged\Fonts.gpr x64\Release\gpr2gpa.exe "Packaged\Fonts.gpr" "DefaultTimestamp.timestamp" "Packaged\Fonts.gpa" -patch "Packaged\FontCacheManifest.json" diff --git a/GenerateFonts/GenerateFonts.cpp b/GenerateFonts/GenerateFonts.cpp index 53d1506..fdaa96f 100644 --- a/GenerateFonts/GenerateFonts.cpp +++ b/GenerateFonts/GenerateFonts.cpp @@ -1,3 +1,7 @@ +#include +#include +#include + #include "FontFamily.h" #include "FontManager.h" #include "FontRenderer.h" @@ -7,8 +11,6 @@ #include "GpAppInterface.h" #include "GpDriverIndex.h" #include "GpFontHandlerProperties.h" -#include "GpFileSystem_Win32.h" -#include "GpSystemServices_Win32.h" #include "CFileStream.h" #include "PLDrivers.h" @@ -17,7 +19,11 @@ #include "WindowsUnicodeToolShim.h" -extern "C" __declspec(dllimport) IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties); +extern "C" +#ifdef _MSC_VER +__declspec(dllimport) +#endif +IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties); class MemBufferStream final : public GpIOStream { @@ -168,6 +174,16 @@ bool KnownFontSpec::operator!=(const KnownFontSpec &other) const int toolMain(int argc, const char **argv) { + if (argc < 3) + { + fputs("Usage: GenerateFonts \n", stderr); + return -1; + } + std::string resourcesDir(argv[1]); + resourcesDir += '/'; + std::string outputDir(argv[2]); + outputDir += '/'; + IGpAllocator *alloc = GpAllocator_C::GetInstance(); GpFontHandlerProperties fhProperties; @@ -187,12 +203,13 @@ int toolMain(int argc, const char **argv) std::vector catalog; std::vector fontSpecs; - FILE *manifestF = fopen_utf8("Packaged/FontCacheManifest.json", "wb"); + std::string tmpPath(outputDir + "FontCacheManifest.json"); + FILE *manifestF = fopen_utf8(tmpPath.c_str(), "wb"); fprintf(manifestF, "{\n"); fprintf(manifestF, "\t\"add\" :\n"); fprintf(manifestF, "\t{\n"); - fprintf(manifestF, "\t\t\"RFCT/1000.bin\" : \"Packaged/FontCacheCatalog.bin\""); + fprintf(manifestF, "\t\t\"RFCT/1000.bin\" : \"%sFontCacheCatalog.bin\"", outputDir.c_str()); int numFontsEmitted = 0; for (int presetIndex = 0; presetIndex < PortabilityLayer::FontPresets::kCount; presetIndex++) @@ -220,8 +237,9 @@ int toolMain(int argc, const char **argv) fontSpecs.push_back(spec); - std::string resPath = std::string("Resources/") + path; - FILE *fontFile = fopen_utf8(resPath.c_str(), "rb"); + tmpPath = resourcesDir; + tmpPath += path; + FILE *fontFile = fopen_utf8(tmpPath.c_str(), "rb"); if (fontFile) { @@ -236,7 +254,7 @@ int toolMain(int argc, const char **argv) { char fontPath[1024]; - sprintf(fontPath, "Packaged/CachedFont%i.bin", numFontsEmitted); + sprintf(fontPath, "%sCachedFont%i.bin", outputDir.c_str(), numFontsEmitted); FILE *cachedFontF = fopen_utf8(fontPath, "wb"); PortabilityLayer::CFileStream cacheStream(cachedFontF); @@ -290,7 +308,9 @@ int toolMain(int argc, const char **argv) PortabilityLayer::RenderedFontCatalogHeader catHeader; - FILE *catF = fopen_utf8("Packaged/FontCacheCatalog.bin", "wb"); + tmpPath = outputDir; + tmpPath += "FontCacheCatalog.bin"; + FILE *catF = fopen_utf8(tmpPath.c_str(), "wb"); catHeader.m_version = PortabilityLayer::RenderedFontCatalogHeader::kVersion; catHeader.m_pathsOffset = static_cast(sizeof(PortabilityLayer::RenderedFontCatalogHeader) + paths.size() * sizeof(PortabilityLayer::RenderedFontCatalogPathEntry) + numFontsEmitted * sizeof(PortabilityLayer::RenderedFontCatalogRFontEntry));