diff --git a/Aerofoil.sln b/Aerofoil.sln
index 6d90b16..705163b 100644
--- a/Aerofoil.sln
+++ b/Aerofoil.sln
@@ -63,6 +63,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AerofoilSDL", "AerofoilSDL\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MergeGPF", "MergeGPF\MergeGPF.vcxproj", "{36DAF5FA-6ADB-4F20-9810-1610DE0AE653}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GenerateFonts", "GenerateFonts\GenerateFonts.vcxproj", "{3B7FD18D-7A50-4DF5-AC25-543E539BFACE}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -175,6 +177,10 @@ Global
{36DAF5FA-6ADB-4F20-9810-1610DE0AE653}.Debug|x64.Build.0 = Debug|x64
{36DAF5FA-6ADB-4F20-9810-1610DE0AE653}.Release|x64.ActiveCfg = Release|x64
{36DAF5FA-6ADB-4F20-9810-1610DE0AE653}.Release|x64.Build.0 = Release|x64
+ {3B7FD18D-7A50-4DF5-AC25-543E539BFACE}.Debug|x64.ActiveCfg = Debug|x64
+ {3B7FD18D-7A50-4DF5-AC25-543E539BFACE}.Debug|x64.Build.0 = Debug|x64
+ {3B7FD18D-7A50-4DF5-AC25-543E539BFACE}.Release|x64.ActiveCfg = Release|x64
+ {3B7FD18D-7A50-4DF5-AC25-543E539BFACE}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Aerofoil/Aerofoil.vcxproj b/Aerofoil/Aerofoil.vcxproj
index d3a386b..074ea6e 100644
--- a/Aerofoil/Aerofoil.vcxproj
+++ b/Aerofoil/Aerofoil.vcxproj
@@ -84,7 +84,6 @@
-
@@ -107,7 +106,6 @@
-
@@ -126,9 +124,6 @@
{ffc961ac-55b4-4a38-a83e-06ae98f59acc}
-
- {4b564030-8985-4975-91e1-e1b2c16ae2a1}
-
{17b96f07-ef92-47cd-95a5-8e6ee38ab564}
diff --git a/Aerofoil/Aerofoil.vcxproj.filters b/Aerofoil/Aerofoil.vcxproj.filters
index dfc844a..ded91bd 100644
--- a/Aerofoil/Aerofoil.vcxproj.filters
+++ b/Aerofoil/Aerofoil.vcxproj.filters
@@ -4,9 +4,6 @@
Source Files
-
- Source Files
-
Source Files
@@ -45,9 +42,6 @@
Header Files
-
- Header Files
-
Header Files
diff --git a/Aerofoil/GpFiber_Win32.cpp b/Aerofoil/GpFiber_Win32.cpp
deleted file mode 100644
index 213ee41..0000000
--- a/Aerofoil/GpFiber_Win32.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "GpFiber_Win32.h"
-#include
-
-GpFiber_Win32::GpFiber_Win32(LPVOID fiber)
- : m_fiber(fiber)
-{
-}
-
-void GpFiber_Win32::YieldTo(IGpFiber *toFiber)
-{
- SwitchToFiber(static_cast(toFiber)->m_fiber);
-}
-
-void GpFiber_Win32::YieldToTerminal(IGpFiber *toFiber)
-{
- YieldTo(toFiber);
-}
-
-void GpFiber_Win32::Destroy()
-{
- this->~GpFiber_Win32();
- free(this);
-}
-
-GpFiber_Win32::~GpFiber_Win32()
-{
- DeleteFiber(m_fiber);
-}
-
-IGpFiber *GpFiber_Win32::Create(LPVOID fiber)
-{
- void *storage = malloc(sizeof(GpFiber_Win32));
- if (!storage)
- return nullptr;
-
- return new (storage) GpFiber_Win32(fiber);
-}
diff --git a/Aerofoil/GpFiber_Win32.h b/Aerofoil/GpFiber_Win32.h
deleted file mode 100644
index 8007878..0000000
--- a/Aerofoil/GpFiber_Win32.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma once
-#include "GpWindows.h"
-#include "IGpFiber.h"
-
-class GpFiber_Win32 final : public IGpFiber
-{
-public:
- void YieldTo(IGpFiber *toFiber) override;
- void YieldToTerminal(IGpFiber *toFiber) override;
- void Destroy() override;
-
- static IGpFiber *Create(LPVOID fiber);
-
- LPVOID GetFiber() const;
-
-private:
- explicit GpFiber_Win32(LPVOID fiber);
- ~GpFiber_Win32();
-
- LPVOID m_fiber;
-};
-
-inline LPVOID GpFiber_Win32::GetFiber() const
-{
- return m_fiber;
-}
diff --git a/Aerofoil/GpMain_Win32.cpp b/Aerofoil/GpMain_Win32.cpp
index b40f7b4..6a5fc5c 100644
--- a/Aerofoil/GpMain_Win32.cpp
+++ b/Aerofoil/GpMain_Win32.cpp
@@ -4,7 +4,6 @@
#include "GpColorCursor_Win32.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
-#include "GpFiber_Win32.h"
#include "GpFileSystem_Win32.h"
#include "GpLogDriver_Win32.h"
#include "GpFontHandlerFactory.h"
@@ -28,7 +27,6 @@ GpWindowsGlobals g_gpWindowsGlobals;
extern "C" __declspec(dllimport) IGpAudioDriver *GpDriver_CreateAudioDriver_XAudio2(const GpAudioDriverProperties &properties);
extern "C" __declspec(dllimport) IGpDisplayDriver *GpDriver_CreateDisplayDriver_D3D11(const GpDisplayDriverProperties &properties);
extern "C" __declspec(dllimport) IGpInputDriver *GpDriver_CreateInputDriver_XInput(const GpInputDriverProperties &properties);
-extern "C" __declspec(dllimport) IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties);
static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t eventType, GpMouseButton_t button, int32_t x, int32_t y, float pixelScaleX, float pixelScaleY)
{
@@ -430,7 +428,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpWindowsGlobals.m_hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_ICON1));
g_gpWindowsGlobals.m_hIconSm = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_ICON2));
- g_gpWindowsGlobals.m_createFiberFunc = GpFiber_Win32::Create;
g_gpWindowsGlobals.m_createBWCursorFunc = GpBWCursor_Win32::Create;
g_gpWindowsGlobals.m_createColorCursorFunc = GpColorCursor_Win32::Create;
g_gpWindowsGlobals.m_translateWindowsMessageFunc = TranslateWindowsMessage;
@@ -439,7 +436,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_XAudio2;
- g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_FreeType2;
+ g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_None;
EGpInputDriverType inputDrivers[] =
{
@@ -456,7 +453,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_D3D11, GpDriver_CreateDisplayDriver_D3D11);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_XAudio2, GpDriver_CreateAudioDriver_XAudio2);
GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType_XInput, GpDriver_CreateInputDriver_XInput);
- GpFontHandlerFactory::RegisterFontHandlerFactory(EGpFontHandlerType_FreeType2, GpDriver_CreateFontHandler_FreeType2);
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Windows environment configured, starting up");
diff --git a/AerofoilPortable.props b/AerofoilPortable.props
new file mode 100644
index 0000000..08b2b3e
--- /dev/null
+++ b/AerofoilPortable.props
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/AerofoilSDL/GpMain_SDL_Win32.cpp b/AerofoilSDL/GpMain_SDL_Win32.cpp
index b4886e4..d492b13 100644
--- a/AerofoilSDL/GpMain_SDL_Win32.cpp
+++ b/AerofoilSDL/GpMain_SDL_Win32.cpp
@@ -4,7 +4,6 @@
#include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
-#include "GpFiber_Win32.h"
#include "GpFileSystem_Win32.h"
#include "GpLogDriver_Win32.h"
#include "GpFontHandlerFactory.h"
diff --git a/AerofoilWin.props b/AerofoilWin.props
new file mode 100644
index 0000000..038ae9d
--- /dev/null
+++ b/AerofoilWin.props
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+ $(SolutionDir)Aerofoil;%(AdditionalIncludeDirectories)
+
+
+
+
\ No newline at end of file
diff --git a/ApplicationResourcePatches/PICT/1302.bmp b/ApplicationResourcePatches/PICT/1302.bmp
deleted file mode 100644
index 87e1e56..0000000
Binary files a/ApplicationResourcePatches/PICT/1302.bmp and /dev/null differ
diff --git a/ApplicationResourcePatches/PICT/1303.bmp b/ApplicationResourcePatches/PICT/1303.bmp
deleted file mode 100644
index dde3d3c..0000000
Binary files a/ApplicationResourcePatches/PICT/1303.bmp and /dev/null differ
diff --git a/ApplicationResourcePatches/manifest.json b/ApplicationResourcePatches/manifest.json
index 8a1722d..b403f5a 100644
--- a/ApplicationResourcePatches/manifest.json
+++ b/ApplicationResourcePatches/manifest.json
@@ -14,8 +14,6 @@
"DITL/2008.json" : "ApplicationResourcePatches/DITL/2008.json",
"PICT/1300.bmp" : "ApplicationResourcePatches/PICT/1300.bmp",
"PICT/1301.bmp" : "ApplicationResourcePatches/PICT/1301.bmp",
- "PICT/1302.bmp" : "ApplicationResourcePatches/PICT/1302.bmp",
- "PICT/1303.bmp" : "ApplicationResourcePatches/PICT/1303.bmp",
"PICT/1971.bmp" : "ApplicationResourcePatches/PICT/1971.bmp",
"PICT/1972.bmp" : "ApplicationResourcePatches/PICT/1972.bmp",
"PICT/1973.bmp" : "ApplicationResourcePatches/PICT/1973.bmp",
diff --git a/ConvertResources.bat b/ConvertResources.bat
index 4608d53..86f8bf5 100644
--- a/ConvertResources.bat
+++ b/ConvertResources.bat
@@ -4,12 +4,23 @@ mkdir Packaged
mkdir Packaged\Houses
x64\Release\MiniRez.exe "GliderProData\Glider PRO.r" Packaged\ApplicationResources.gpr
-
x64\Release\gpr2gpa.exe "Packaged\ApplicationResources.gpr" "DefaultTimestamp.timestamp" "Packaged\ApplicationResources.gpa" "ApplicationResourcePatches\manifest.json"
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\MiniRez.exe "Empty.r" Packaged\Fonts.gpr
+x64\Release\gpr2gpa.exe "Packaged\Fonts.gpr" "DefaultTimestamp.timestamp" "Packaged\Fonts.gpa" "Packaged\FontCacheManifest.json"
+x64\Release\FTagData.exe "DefaultTimestamp.timestamp" "Packaged\Fonts.gpf" data ozm5 0 0 locked
+x64\Release\MergeGPF.exe "Packaged\Fonts.gpf"
+
+del /Q Packaged\CachedFont*.bin
+del Packaged\FontCacheCatalog.bin
+del Packaged\FontCacheManifest.json
+del Packaged\Fonts.gpr
+del Packaged\Fonts.gpa
+
x64\Release\ConvertColorCursors.exe
attrib -R Packaged\ApplicationResources.gpf
diff --git a/Empty.r b/Empty.r
new file mode 100644
index 0000000..e69de29
diff --git a/GenerateFonts/GenerateFonts.cpp b/GenerateFonts/GenerateFonts.cpp
new file mode 100644
index 0000000..7534a47
--- /dev/null
+++ b/GenerateFonts/GenerateFonts.cpp
@@ -0,0 +1,313 @@
+#include "FontFamily.h"
+#include "FontManager.h"
+#include "FontRenderer.h"
+#include "IGpFont.h"
+#include "IGpFontHandler.h"
+#include "GpAppInterface.h"
+#include "GpDriverIndex.h"
+#include "GpFontHandlerProperties.h"
+#include "GpFileSystem_Win32.h"
+#include "GpSystemServices_Win32.h"
+#include "CFileStream.h"
+
+#include "PLDrivers.h"
+#include "RenderedFont.h"
+#include "RenderedFontCatalog.h"
+
+#include "WindowsUnicodeToolShim.h"
+
+extern "C" __declspec(dllimport) IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties);
+
+class MemBufferStream final : public GpIOStream
+{
+public:
+ size_t Read(void *bytesOut, size_t size) override;
+ size_t Write(const void *bytes, size_t size) override;
+ bool IsSeekable() const override;
+ bool IsReadOnly() const override;
+ bool IsWriteOnly() const override;
+ bool SeekStart(GpUFilePos_t loc) override;
+ bool SeekCurrent(GpFilePos_t loc) override;
+ bool SeekEnd(GpUFilePos_t loc) override;
+ GpUFilePos_t Size() const override;
+ GpUFilePos_t Tell() const override;
+ void Close() override;
+ void Flush() override;
+
+ const uint8_t *GetBytes() const;
+
+private:
+ size_t m_writeOffset;
+ std::vector m_buffer;
+};
+
+size_t MemBufferStream::Read(void *bytesOut, size_t size)
+{
+ return 0;
+}
+
+size_t MemBufferStream::Write(const void *bytes, size_t size)
+{
+ const uint8_t *bytesUInt8 = static_cast(bytes);
+
+ for (size_t i = 0; i < size; i++)
+ {
+ if (m_writeOffset == m_buffer.size())
+ m_buffer.push_back(bytesUInt8[i]);
+ else
+ m_buffer[m_writeOffset] = bytesUInt8[i];
+
+ m_writeOffset++;
+ }
+
+ return size;
+}
+
+bool MemBufferStream::IsSeekable() const
+{
+ return true;
+}
+
+bool MemBufferStream::IsReadOnly() const
+{
+ return false;
+}
+
+bool MemBufferStream::IsWriteOnly() const
+{
+ return true;
+}
+
+bool MemBufferStream::SeekStart(GpUFilePos_t loc)
+{
+ m_writeOffset = static_cast(loc);
+ return true;
+}
+
+bool MemBufferStream::SeekCurrent(GpFilePos_t loc)
+{
+ m_writeOffset = static_cast(static_cast(m_writeOffset) + loc);
+ return true;
+}
+
+bool MemBufferStream::SeekEnd(GpUFilePos_t loc)
+{
+ m_writeOffset = this->Size() - loc;
+ return true;
+}
+
+GpUFilePos_t MemBufferStream::Size() const
+{
+ return m_buffer.size();
+}
+
+GpUFilePos_t MemBufferStream::Tell() const
+{
+ return m_writeOffset;
+}
+
+void MemBufferStream::Close()
+{
+}
+
+void MemBufferStream::Flush()
+{
+}
+
+
+const uint8_t *MemBufferStream::GetBytes() const
+{
+ return &m_buffer[0];
+}
+
+struct KnownFontSpec
+{
+public:
+ KnownFontSpec();
+ KnownFontSpec(const char *path, int size, bool aa, PortabilityLayer::FontHacks hacks);
+
+ bool operator==(const KnownFontSpec &other) const;
+ bool operator!=(const KnownFontSpec &other) const;
+
+private:
+ std::string m_path;
+ int m_size;
+ bool m_aa;
+ PortabilityLayer::FontHacks m_hacks;
+};
+
+
+KnownFontSpec::KnownFontSpec()
+ : m_size(0)
+ , m_aa(false)
+ , m_hacks(PortabilityLayer::FontHacks_None)
+{
+}
+
+KnownFontSpec::KnownFontSpec(const char *path, int size, bool aa, PortabilityLayer::FontHacks hacks)
+ : m_path(path)
+ , m_size(size)
+ , m_aa(aa)
+ , m_hacks(hacks)
+{
+}
+
+bool KnownFontSpec::operator==(const KnownFontSpec &other) const
+{
+ return !((*this) != other);
+}
+
+bool KnownFontSpec::operator!=(const KnownFontSpec &other) const
+{
+ return m_path != other.m_path ||
+ m_size != other.m_size ||
+ m_aa != other.m_aa ||
+ m_hacks != other.m_hacks;
+}
+
+int toolMain(int argc, const char **argv)
+{
+ GpFontHandlerProperties fhProperties;
+ fhProperties.m_type = EGpFontHandlerType_FreeType2;
+
+ IGpFontHandler *ft2Handler = GpDriver_CreateFontHandler_FreeType2(fhProperties);
+
+ PortabilityLayer::FontManager *fontManager = PortabilityLayer::FontManager::GetInstance();
+ PortabilityLayer::FontRenderer *fontRenderer = PortabilityLayer::FontRenderer::GetInstance();
+ fontManager->Init();
+
+ std::vector paths;
+ std::vector catalog;
+ std::vector fontSpecs;
+
+ FILE *manifestF = fopen_utf8("Packaged/FontCacheManifest.json", "wb");
+
+ fprintf(manifestF, "{\n");
+ fprintf(manifestF, "\t\"add\" :\n");
+ fprintf(manifestF, "\t{\n");
+ fprintf(manifestF, "\t\t\"RFCT/1000.bin\" : \"Packaged/FontCacheCatalog.bin\"");
+
+ int numFontsEmitted = 0;
+ for (int presetIndex = 0; presetIndex < PortabilityLayer::FontPresets::kCount; presetIndex++)
+ {
+ int size = 0;
+ int flags = 0;
+ bool aa = false;
+ PortabilityLayer::FontFamilyID_t fontFamilyID;
+
+ fontManager->GetFontPreset(static_cast(presetIndex), &fontFamilyID, &size, &flags, &aa);
+ PortabilityLayer::FontFamily *fontFamily = fontManager->GetFont(fontFamilyID);
+
+ int variation = fontFamily->GetVariationForFlags(flags);
+
+ PortabilityLayer::FontHacks hacks;
+ const char *path = nullptr;
+ fontFamily->GetFontSpec(variation, hacks, path);
+
+ KnownFontSpec spec(path, size, aa, hacks);
+
+ if (std::find(fontSpecs.begin(), fontSpecs.end(), spec) != fontSpecs.end())
+ continue;
+
+ fontSpecs.push_back(spec);
+
+ std::string resPath = std::string("Resources/") + path;
+ FILE *fontFile = fopen_utf8(resPath.c_str(), "rb");
+
+ if (fontFile)
+ {
+ PortabilityLayer::CFileStream stream(fontFile);
+
+ IGpFont *font = ft2Handler->LoadFont(&stream);
+ if (!ft2Handler->KeepStreamOpen())
+ stream.Close();
+
+ PortabilityLayer::RenderedFont *rfont = fontRenderer->RenderFont(font, size, aa, hacks);
+
+
+ {
+ char fontPath[1024];
+ sprintf(fontPath, "Packaged/CachedFont%i.bin", numFontsEmitted);
+
+ FILE *cachedFontF = fopen_utf8(fontPath, "wb");
+ PortabilityLayer::CFileStream cacheStream(cachedFontF);
+
+ fontRenderer->SaveCache(rfont, &cacheStream);
+ cacheStream.Close();
+
+ fprintf(manifestF, ",\n\t\t\"RFNT/%i.bin\" : \"%s\"", 1000 + numFontsEmitted, fontPath);
+ }
+
+ rfont->Destroy();
+
+ font->Destroy();
+
+ PortabilityLayer::RenderedFontCatalogRFontEntry catEntry;
+ catEntry.m_fontSize = static_cast(size);
+ catEntry.m_hacks = static_cast(hacks);
+ catEntry.m_isAA = aa ? 1 : 0;
+ catEntry.m_pathIndex = 0;
+
+ bool foundPath = false;
+ for (size_t i = 0; i < paths.size(); i++)
+ {
+ if (paths[i] == path)
+ {
+ catEntry.m_pathIndex = static_cast(i);
+ foundPath = true;
+ break;
+ }
+ }
+
+ if (!foundPath)
+ {
+ catEntry.m_pathIndex = static_cast(paths.size());
+ paths.push_back(std::string(path));
+ }
+
+ catalog.push_back(catEntry);
+
+ numFontsEmitted++;
+ }
+ }
+
+ fprintf(manifestF, "\n\t},\n");
+ fprintf(manifestF, "\t\"delete\" :\n");
+ fprintf(manifestF, "\t[\n");
+ fprintf(manifestF, "\t]\n");
+ fprintf(manifestF, "}\n");
+
+ PortabilityLayer::RenderedFontCatalogHeader catHeader;
+
+ FILE *catF = fopen_utf8("Packaged/FontCacheCatalog.bin", "wb");
+
+ catHeader.m_version = PortabilityLayer::RenderedFontCatalogHeader::kVersion;
+ catHeader.m_pathsOffset = static_cast(sizeof(PortabilityLayer::RenderedFontCatalogHeader) + paths.size() * sizeof(PortabilityLayer::RenderedFontCatalogPathEntry) + numFontsEmitted * sizeof(PortabilityLayer::RenderedFontCatalogRFontEntry));
+ catHeader.m_numPaths = static_cast(paths.size());
+ catHeader.m_numRFonts = static_cast(numFontsEmitted);
+
+ fwrite(&catHeader, sizeof(catHeader), 1, catF);
+
+ PortabilityLayer::RenderedFontCatalogPathEntry pathEntry;
+ pathEntry.m_pathOffset = 0;
+ pathEntry.m_pathSize = 0;
+ for (size_t i = 0; i < paths.size(); i++)
+ {
+ pathEntry.m_pathOffset = static_cast(pathEntry.m_pathOffset) + pathEntry.m_pathSize;
+ pathEntry.m_pathSize = static_cast(paths[i].size());
+
+ fwrite(&pathEntry, sizeof(pathEntry), 1, catF);
+ }
+
+ fwrite(&catalog[0], sizeof(PortabilityLayer::RenderedFontCatalogRFontEntry), catalog.size(), catF);
+
+ for (size_t i = 0; i < paths.size(); i++)
+ {
+ const std::string &str = paths[i];
+ fwrite(&str[0], str.size(), 1, catF);
+ }
+
+ fclose(catF);
+
+ return 0;
+}
diff --git a/GenerateFonts/GenerateFonts.vcxproj b/GenerateFonts/GenerateFonts.vcxproj
new file mode 100644
index 0000000..2a6530b
--- /dev/null
+++ b/GenerateFonts/GenerateFonts.vcxproj
@@ -0,0 +1,101 @@
+
+
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 15.0
+ {3B7FD18D-7A50-4DF5-AC25-543E539BFACE}
+ GenerateFonts
+ 10.0.17763.0
+
+
+
+ Application
+ true
+ v141
+ MultiByte
+
+
+ Application
+ false
+ v141
+ true
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Level3
+ Disabled
+ true
+ true
+
+
+ shlwapi.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ true
+ true
+
+
+ true
+ true
+ shlwapi.lib;%(AdditionalDependencies)
+
+
+
+
+ {4b564030-8985-4975-91e1-e1b2c16ae2a1}
+
+
+ {6ec62b0f-9353-40a4-a510-3788f1368b33}
+
+
+ {15009625-1120-405e-8bba-69a16cd6713d}
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/GenerateFonts/GenerateFonts.vcxproj.filters b/GenerateFonts/GenerateFonts.vcxproj.filters
new file mode 100644
index 0000000..9e43b4f
--- /dev/null
+++ b/GenerateFonts/GenerateFonts.vcxproj.filters
@@ -0,0 +1,22 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Source Files
+
+
+
\ No newline at end of file
diff --git a/GpApp/About.cpp b/GpApp/About.cpp
index f339196..41083e6 100644
--- a/GpApp/About.cpp
+++ b/GpApp/About.cpp
@@ -314,8 +314,8 @@ void DoAboutFramework (void)
PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(windowRect, PortabilityLayer::WindowStyleFlags::kAlert, true, 0, 0, PSTR(""));
PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black();
- PortabilityLayer::RenderedFont *font = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
- PortabilityLayer::RenderedFont *fontLight = GetApplicationFont(8, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *font = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
+ PortabilityLayer::RenderedFont *fontLight = GetFont(PortabilityLayer::FontPresets::kApplication8);
int16_t verticalPoint = 16 + font->GetMetrics().m_ascent;
int16_t horizontalOffset = 16;
@@ -578,7 +578,7 @@ static int16_t AboutFrameworkFilter(void *context, Dialog *dialog, const TimeTag
void DrawLicenseReader(Window *window)
{
- PortabilityLayer::RenderedFont *rfont = GetMonospaceFont(10, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *rfont = GetFont(PortabilityLayer::FontPresets::kMono10);
if (!rfont)
return;
diff --git a/GpApp/Banner.cpp b/GpApp/Banner.cpp
index 1c8eb85..70e2f7a 100644
--- a/GpApp/Banner.cpp
+++ b/GpApp/Banner.cpp
@@ -118,7 +118,7 @@ void DrawBannerMessage (Point topLeft)
PasStringCopy((*thisHouse)->banner, bannerStr);
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black();
@@ -221,7 +221,7 @@ void DisplayStarsRemaining(void)
DrawSurface *surface = starsWindow->GetDrawSurface();
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
NumToString((long)numStarsRemaining, theStr);
diff --git a/GpApp/Coordinates.cpp b/GpApp/Coordinates.cpp
index 0eac819..bfd8ca9 100644
--- a/GpApp/Coordinates.cpp
+++ b/GpApp/Coordinates.cpp
@@ -75,7 +75,7 @@ void UpdateCoordWindow (void)
PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White();
PortabilityLayer::ResolveCachingColor blueColor = StdColors::Blue();
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(9, 0, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication9);
DrawSurface *surface = coordWindow->GetDrawSurface();
diff --git a/GpApp/DialogUtils.cpp b/GpApp/DialogUtils.cpp
index afac5cb..fcd7af3 100644
--- a/GpApp/DialogUtils.cpp
+++ b/GpApp/DialogUtils.cpp
@@ -568,7 +568,7 @@ void DrawDialogUserText (Dialog *dial, short item, StringPtr text, Boolean inver
DrawSurface *surface = dial->GetWindow()->GetDrawSurface();
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(9, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication9);
PasStringCopy(text, stringCopy);
@@ -619,7 +619,7 @@ void DrawDialogUserText2 (Dialog *dial, short item, StringPtr text)
Str255 stringCopy;
DrawSurface *surface = dial->GetWindow()->GetDrawSurface();
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(9, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication9);
PasStringCopy(text, stringCopy);
const Rect iRect = dial->GetItems()[item - 1].GetWidget()->GetRect();
diff --git a/GpApp/GameOver.cpp b/GpApp/GameOver.cpp
index b6b5b81..4d8c2b0 100644
--- a/GpApp/GameOver.cpp
+++ b/GpApp/GameOver.cpp
@@ -107,7 +107,7 @@ void SetUpFinalScreen (void)
{
GetLineOfText(tempStr, count, subStr);
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
offset = ((thisMac.constrainedScreen.right - thisMac.constrainedScreen.left) -
appFont->MeasurePStr(subStr)) / 2;
diff --git a/GpApp/HighScores.cpp b/GpApp/HighScores.cpp
index f3143a5..4b9eb74 100644
--- a/GpApp/HighScores.cpp
+++ b/GpApp/HighScores.cpp
@@ -145,7 +145,7 @@ void DrawHighScores (DrawSurface *surface)
DisposeGWorld(tempMap);
DisposeGWorld(tempMask);
- PortabilityLayer::RenderedFont *appFont14 = GetApplicationFont(14, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont14 = GetFont(PortabilityLayer::FontPresets::kApplication14Bold);
PasStringCopy(PSTR("\xa5 "), tempStr);
PasStringConcat(tempStr, thisHouseName);
@@ -157,7 +157,7 @@ void DrawHighScores (DrawSurface *surface)
const Point scoreTextPoint = Point::Create(scoreLeft + ((kScoreWide - appFont14->MeasurePStr(tempStr)) / 2), dropIt - 65);
surface->DrawString(scoreTextPoint, tempStr, cyanColor, appFont14);
- PortabilityLayer::RenderedFont *appFont12 = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont12 = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
thisHousePtr = *thisHouse;
// message for score #1
@@ -264,7 +264,7 @@ void DrawHighScores (DrawSurface *surface)
}
}
- PortabilityLayer::RenderedFont *appFont9 = GetApplicationFont(9, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont9 = GetFont(PortabilityLayer::FontPresets::kApplication9Bold);
const Point textPos = Point::Create(scoreLeft + 80, dropIt - 1 + (10 * kScoreSpacing));
GetLocalizedString(8, tempStr);
diff --git a/GpApp/Input.cpp b/GpApp/Input.cpp
index cf65c9f..b5e81ce 100644
--- a/GpApp/Input.cpp
+++ b/GpApp/Input.cpp
@@ -158,7 +158,7 @@ void DrawTouchScreenMenu (DrawSurface *surface, const THandle &back
const int numItems = sizeof(itemTexts) / sizeof(itemTexts[0]);
- PortabilityLayer::RenderedFont *rfont = GetHandwritingFont(48, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *rfont = GetFont(PortabilityLayer::FontPresets::kHandwriting48);
if (!rfont)
return;
diff --git a/GpApp/Main.cpp b/GpApp/Main.cpp
index 1010b89..c30ee87 100644
--- a/GpApp/Main.cpp
+++ b/GpApp/Main.cpp
@@ -43,14 +43,6 @@
#include
-int loadScreenWindowPhase;
-int loadScreenRingStep;
-WindowPtr loadScreenWindow;
-Rect loadScreenProgressBarRect;
-int loadScreenProgress;
-DrawSurface *loadScreenRingSurface;
-
-
#define kPrefsVersion 0x0039
@@ -364,548 +356,6 @@ void WriteOutPrefs (void)
modulePrefs.Dispose();
}
-void StepLoadScreenRing()
-{
- if (loadScreenWindow)
- {
- const int loadScreenStepGranularity = 2;
- loadScreenRingStep++;
- if (loadScreenRingStep == 24 * loadScreenStepGranularity)
- loadScreenRingStep = 0;
-
- Rect ringDestRect = Rect::Create(8, 8, 24, 24);
- Rect ringSrcRect = Rect::Create(0, 0, 16, 16) + Point::Create((loadScreenRingStep / loadScreenStepGranularity) * 16, 0);
-
- if (loadScreenWindowPhase == 0)
- {
- ringDestRect = Rect::Create(0, 0, 64, 64);
-
- const int progression = (loadScreenRingStep / loadScreenStepGranularity);
- ringSrcRect = Rect::Create(0, 0, 64, 64) + Point::Create((progression % 6) * 64, (progression / 6) * 64);
- }
-
- CopyBits(*loadScreenRingSurface->m_port.GetPixMap(), *loadScreenWindow->GetDrawSurface()->m_port.GetPixMap(), &ringSrcRect, &ringDestRect, srcCopy);
- loadScreenWindow->GetDrawSurface()->m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
- }
-}
-
-
-void CreateLoadScreenWindow(int phase)
-{
- FlushResolutionChange();
-
- if (loadScreenRingSurface)
- {
- DisposeGWorld(loadScreenRingSurface);
- loadScreenRingSurface = nullptr;
- }
-
- if (loadScreenWindow)
- {
- PortabilityLayer::WindowManager::GetInstance()->DestroyWindow(loadScreenWindow);
- loadScreenWindow = nullptr;
- }
-
- if (phase == 0)
- {
- static const int kLoadScreenHeight = 64;
- static const int kLoadScreenWidth = 64;
- static const int kLoadRingResource = 1303;
-
- ForceSyncFrame();
- PLSysCalls::Sleep(1);
-
- THandle loadRingImageH = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', kLoadRingResource).StaticCast();
- BitmapImage *loadRingImage = *loadRingImageH;
-
- DrawSurface *loadRingSurface = nullptr;
- Rect loadRingRect = loadRingImage->GetRect();
- loadRingRect.right *= 2;
- loadRingRect.bottom *= 2;
- CreateOffScreenGWorld(&loadRingSurface, &loadRingRect);
- loadRingSurface->DrawPicture(loadRingImageH, loadRingRect, false);
-
- int32_t lsX = (thisMac.fullScreen.Width() - kLoadScreenWidth) / 2;
- int32_t lsY = (thisMac.fullScreen.Height() - kLoadScreenHeight) / 2;
-
-
- const Rect loadScreenRect = Rect::Create(lsY, lsX, lsY + kLoadScreenHeight, lsX + kLoadScreenWidth);
- const Rect loadScreenLocalRect = Rect::Create(0, 0, loadScreenRect.Height(), loadScreenRect.Width());
-
- PortabilityLayer::WindowDef def = PortabilityLayer::WindowDef::Create(loadScreenRect, PortabilityLayer::WindowStyleFlags::kBorderless, true, 0, 0, PSTR(""));
-
- loadScreenWindow = PortabilityLayer::WindowManager::GetInstance()->CreateWindow(def);
- PortabilityLayer::WindowManager::GetInstance()->PutWindowBehind(loadScreenWindow, PL_GetPutInFrontWindowPtr());
-
- DrawSurface *surface = loadScreenWindow->GetDrawSurface();
- PortabilityLayer::ResolveCachingColor blackColor(StdColors::Black());
-
- surface->FillRect(loadScreenLocalRect, blackColor);
-
- loadScreenProgressBarRect = Rect::Create(0, 0, 0, 0);
- loadScreenProgress = 0;
-
- Rect ringDestRect = Rect::Create(0, 0, 64, 64);
- Rect ringSrcRect = Rect::Create(0, 0, 64, 64);
- CopyBits(*loadRingSurface->m_port.GetPixMap(), *surface->m_port.GetPixMap(), &ringSrcRect, &ringDestRect, srcCopy);
-
- loadRingImageH.Dispose();
-
- loadScreenRingSurface = loadRingSurface;
- }
- else if (phase == 1)
- {
- static const int kLoadScreenHeight = 32;
- static const int kLoadRingResource = 1302;
-
- int kLoadScreenWidth = 296;
- PLPasStr loadingText = PSTR("Loading...");
-
- if (!isPrefsLoaded)
- {
- loadingText = PSTR("Getting some things ready...");
- kLoadScreenWidth = 440;
- }
-
- ForceSyncFrame();
- PLSysCalls::Sleep(1);
-
- THandle loadRingImageH = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', kLoadRingResource).StaticCast();
- BitmapImage *loadRingImage = *loadRingImageH;
-
- DrawSurface *loadRingSurface = nullptr;
- Rect loadRingRect = loadRingImage->GetRect();
- CreateOffScreenGWorld(&loadRingSurface, &loadRingRect);
- loadRingSurface->DrawPicture(loadRingImageH, loadRingRect, false);
-
- int32_t lsX = (thisMac.fullScreen.Width() - kLoadScreenWidth) / 2;
- int32_t lsY = (thisMac.fullScreen.Height() - kLoadScreenHeight) / 2;
-
-
- const Rect loadScreenRect = Rect::Create(lsY, lsX, lsY + kLoadScreenHeight, lsX + kLoadScreenWidth);
- const Rect loadScreenLocalRect = Rect::Create(0, 0, loadScreenRect.Height(), loadScreenRect.Width());
-
- PortabilityLayer::WindowDef def = PortabilityLayer::WindowDef::Create(loadScreenRect, PortabilityLayer::WindowStyleFlags::kAlert, true, 0, 0, PSTR(""));
-
- loadScreenWindow = PortabilityLayer::WindowManager::GetInstance()->CreateWindow(def);
- PortabilityLayer::WindowManager::GetInstance()->PutWindowBehind(loadScreenWindow, PL_GetPutInFrontWindowPtr());
-
- DrawSurface *surface = loadScreenWindow->GetDrawSurface();
- PortabilityLayer::ResolveCachingColor blackColor(StdColors::Black());
- PortabilityLayer::ResolveCachingColor whiteColor(StdColors::White());
-
- surface->FillRect(loadScreenLocalRect, whiteColor);
-
- PortabilityLayer::WindowManager::GetInstance()->FlickerWindowIn(loadScreenWindow, 32);
-
- PortabilityLayer::RenderedFont *font = GetApplicationFont(18, PortabilityLayer::FontFamilyFlag_None, true);
- int32_t textY = (kLoadScreenHeight + font->GetMetrics().m_ascent) / 2;
- surface->DrawString(Point::Create(4 + 16 + 8, textY), loadingText, blackColor, font);
-
- static const int32_t loadBarPadding = 16;
- static const int32_t loadBarHeight = 10;
- int32_t loadBarStartX = static_cast(font->MeasureString(loadingText.UChars(), loadingText.Length())) + 4 + 16 + 8 + loadBarPadding;
- int32_t loadBarEndX = loadScreenLocalRect.right - loadBarPadding;
-
- loadScreenProgressBarRect = Rect::Create((loadScreenLocalRect.Height() - loadBarHeight) / 2, loadBarStartX, (loadScreenLocalRect.Height() + loadBarHeight) / 2, loadBarEndX);
-
- PortabilityLayer::ResolveCachingColor partialFillColor(PortabilityLayer::RGBAColor::Create(255, 255, 204, 255));
- surface->FrameRect(loadScreenProgressBarRect, blackColor);
- surface->FillRect(loadScreenProgressBarRect.Inset(1, 1), partialFillColor);
-
- Rect ringDestRect = Rect::Create(8, 8, 24, 24);
- Rect ringSrcRect = Rect::Create(0, 0, 16, 16);
- CopyBits(*loadRingSurface->m_port.GetPixMap(), *surface->m_port.GetPixMap(), &ringSrcRect, &ringDestRect, srcCopy);
-
- loadRingImageH.Dispose();
-
- loadScreenRingSurface = loadRingSurface;
- }
-}
-
-void StepLoadScreen(int steps, bool insertDelay)
-{
- if (loadScreenWindow)
- {
- static const int kLoadScreenPhaseSwitchBreakpoint = 20;
-
- int oldProgress = loadScreenProgress;
-
- if (loadScreenProgress + steps >= kLoadScreenPhaseSwitchBreakpoint && loadScreenWindowPhase == 0)
- {
- loadScreenWindowPhase = 1;
- CreateLoadScreenWindow(loadScreenWindowPhase);
-
- // Reset old progress since the progress bar was redrawn
- oldProgress = 0;
- }
-
- const Rect loadScreenProgressBarFillRect = loadScreenProgressBarRect.Inset(1, 1);
-
- int loadScreenMax = 43;
- loadScreenProgress = loadScreenProgress + steps;
- if (loadScreenProgress > loadScreenMax)
- loadScreenProgress = loadScreenMax;
-
- PortabilityLayer::ResolveCachingColor fillColor(PortabilityLayer::RGBAColor::Create(51, 51, 51, 255));
-
- int prevStep = oldProgress * loadScreenProgressBarFillRect.Width() / loadScreenMax;
- int thisStep = loadScreenProgress * loadScreenProgressBarFillRect.Width() / loadScreenMax;
-
- loadScreenWindow->GetDrawSurface()->FillRect(Rect::Create(loadScreenProgressBarFillRect.top, loadScreenProgressBarFillRect.left + prevStep, loadScreenProgressBarFillRect.bottom, loadScreenProgressBarFillRect.left + thisStep), fillColor);
- ForceSyncFrame();
-
- if (insertDelay)
- {
- StepLoadScreenRing();
- Delay(1, nullptr);
- }
- }
- else
- SpinCursor(steps);
-}
-
-void InitLoadingWindow()
-{
- if (!thisMac.isTouchscreen && isPrefsLoaded)
- return;
-
- if (isPrefsLoaded)
- loadScreenWindowPhase = 1;
- else
- loadScreenWindowPhase = 0;
-
- CreateLoadScreenWindow(loadScreenWindowPhase);
-}
-
-enum PreloadFontCategory
-{
- FontCategory_System,
- FontCategory_Application,
- FontCategory_Handwriting,
- FontCategory_Monospace,
-};
-
-struct PreloadFontSpec
-{
- PreloadFontCategory m_category;
- int m_size;
- int m_flags;
- bool m_aa;
-};
-
-struct PreloadFontWorkSlot
-{
- IGpThreadEvent *m_completedEvent;
- PortabilityLayer::WorkerThread *m_workerThread;
- std::atomic m_singleJobCompleted;
- const PreloadFontSpec *m_spec;
- bool m_queued;
-
- PreloadFontWorkSlot();
- ~PreloadFontWorkSlot();
-};
-
-PreloadFontWorkSlot::PreloadFontWorkSlot()
- : m_completedEvent(nullptr)
- , m_workerThread(nullptr)
- , m_spec(nullptr)
- , m_queued(false)
-{
-}
-
-PreloadFontWorkSlot::~PreloadFontWorkSlot()
-{
- if (m_workerThread)
- m_workerThread->Destroy();
-}
-
-void PreloadSingleFont (const PreloadFontSpec &spec)
-{
- switch (spec.m_category)
- {
- case FontCategory_Application:
- GetApplicationFont(spec.m_size, spec.m_flags, spec.m_aa);
- break;
- case FontCategory_System:
- GetSystemFont(spec.m_size, spec.m_flags, spec.m_aa);
- break;
- case FontCategory_Handwriting:
- GetHandwritingFont(spec.m_size, spec.m_flags, spec.m_aa);
- break;
- case FontCategory_Monospace:
- GetMonospaceFont(spec.m_size, spec.m_flags, spec.m_aa);
- break;
- default:
- break;
- }
-}
-
-void PreloadFontThreadFunc(void *context)
-{
- PreloadFontWorkSlot *wSlot = static_cast(context);
-
- PreloadSingleFont(*wSlot->m_spec);
- wSlot->m_singleJobCompleted.fetch_add(1, std::memory_order_release);
- wSlot->m_completedEvent->Signal();
-}
-
-void PreloadFonts()
-{
- static PreloadFontSpec specs[] =
- {
- // First entry should be the one needed to show the load screen
- { FontCategory_Application, 18, PortabilityLayer::FontFamilyFlag_None, true },
-
- { FontCategory_System, 9, PortabilityLayer::FontFamilyFlag_Bold, true },
- { FontCategory_System, 10, PortabilityLayer::FontFamilyFlag_Bold, true },
- { FontCategory_System, 12, PortabilityLayer::FontFamilyFlag_None, true },
- { FontCategory_System, 12, PortabilityLayer::FontFamilyFlag_Bold, true },
- { FontCategory_Application, 8, PortabilityLayer::FontFamilyFlag_None, true },
- { FontCategory_Application, 9, PortabilityLayer::FontFamilyFlag_None, true },
- { FontCategory_Application, 12, PortabilityLayer::FontFamilyFlag_Bold, true },
- { FontCategory_Application, 14, PortabilityLayer::FontFamilyFlag_Bold, true },
- { FontCategory_Application, 14, PortabilityLayer::FontFamilyFlag_None, true },
- { FontCategory_Application, 40, PortabilityLayer::FontFamilyFlag_None, true },
- { FontCategory_Handwriting, 24, PortabilityLayer::FontFamilyFlag_None, true },
- { FontCategory_Handwriting, 48, PortabilityLayer::FontFamilyFlag_None, true },
- { FontCategory_Monospace, 10, PortabilityLayer::FontFamilyFlag_None, true },
- };
-
- PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
-
- const int numFontSpecs = sizeof(specs) / sizeof(specs[0]);
-
- int queuedSpecs = 0;
- int completedSpecs = 0;
-
- // We can't actually slot these because FT isn't thread-safe when accessing the same font,
- // but we can do this to unclog the render thread.
- PreloadFontWorkSlot slot;
- slot.m_workerThread = PortabilityLayer::WorkerThread::Create();
- slot.m_completedEvent = PLDrivers::GetSystemServices()->CreateThreadEvent(true, false);
-
- while (completedSpecs < numFontSpecs)
- {
- if (slot.m_queued)
- {
- if (slot.m_singleJobCompleted.load(std::memory_order_acquire) != 0)
- {
- slot.m_completedEvent->Wait();
- slot.m_queued = false;
- completedSpecs++;
-
- StepLoadScreen(1, false);
- }
- }
-
- if (!slot.m_queued)
- {
- if (queuedSpecs < numFontSpecs)
- {
- slot.m_queued = true;
- slot.m_spec = specs + queuedSpecs;
- slot.m_singleJobCompleted.store(0, std::memory_order_release);
- slot.m_workerThread->AsyncExecuteTask(PreloadFontThreadFunc, &slot);
-
- queuedSpecs++;
- }
- }
-
- StepLoadScreenRing();
- Delay(1, nullptr);
- }
-
- PortabilityLayer::FontManager::GetInstance()->PurgeCache();
-}
-
-struct PreloadAATableSpec
-{
- PortabilityLayer::RGBAColor m_color;
- bool m_isTone;
-};
-
-struct PreloadAATableWorkSlot
-{
- IGpThreadEvent *m_completedEvent;
- IGpMutex *m_mutex;
- PortabilityLayer::WorkerThread *m_workerThread;
- std::atomic m_singleJobCompleted;
- const PreloadAATableSpec *m_spec;
- bool m_queued;
-
- PreloadAATableWorkSlot();
- ~PreloadAATableWorkSlot();
-};
-
-PreloadAATableWorkSlot::PreloadAATableWorkSlot()
- : m_completedEvent(nullptr)
- , m_workerThread(nullptr)
- , m_spec(nullptr)
- , m_queued(false)
-{
-}
-
-PreloadAATableWorkSlot::~PreloadAATableWorkSlot()
-{
- if (m_workerThread)
- m_workerThread->Destroy();
-}
-
-
-void PreloadAATableThreadFunc(void *context)
-{
- PreloadAATableWorkSlot *wSlot = static_cast(context);
-
- PortabilityLayer::StandardPalette *sp = PortabilityLayer::StandardPalette::GetInstance();
-
- if (wSlot->m_spec->m_isTone)
- sp->GetCachedToneAATable(wSlot->m_spec->m_color.r, wSlot->m_mutex);
- else
- sp->GetCachedPaletteAATable(wSlot->m_spec->m_color, wSlot->m_mutex);
-
- wSlot->m_singleJobCompleted.fetch_add(1, std::memory_order_release);
- wSlot->m_completedEvent->Signal();
-}
-
-void PreloadAATables()
-{
- PortabilityLayer::StandardPalette *sp = PortabilityLayer::StandardPalette::GetInstance();
- PortabilityLayer::RGBAColor preloadColors[] =
- {
- PortabilityLayer::RGBAColor::Create(255, 255, 255, 255),
- PortabilityLayer::RGBAColor::Create(255, 51, 51, 255),
- PortabilityLayer::RGBAColor::Create(255, 0, 0, 255),
- PortabilityLayer::RGBAColor::Create(255, 255, 0, 255),
- PortabilityLayer::RGBAColor::Create(0, 255, 255, 255),
- PortabilityLayer::RGBAColor::Create(0, 0, 255, 255),
- PortabilityLayer::RGBAColor::Create(204, 102, 51, 255),
- PortabilityLayer::RGBAColor::Create(102, 102, 102, 255),
- PortabilityLayer::RGBAColor::Create(51, 51, 102, 255),
- PortabilityLayer::RGBAColor::Create(255, 255, 51, 255),
- PortabilityLayer::RGBAColor::Create(0, 0, 0, 255),
- };
-
- const size_t numPalettePreloads = sizeof(preloadColors) / sizeof(preloadColors[0]);
- const size_t maxTonePreloads = numPalettePreloads * 3;
-
- PreloadAATableSpec specs[numPalettePreloads + maxTonePreloads];
- for (size_t i = 0; i < numPalettePreloads; i++)
- {
- specs[i].m_color = preloadColors[i];
- specs[i].m_isTone = false;
- }
-
- size_t numTonePreloads = 0;
- for (size_t i = 0; i < numPalettePreloads; i++)
- {
- const uint8_t rgb[3] = { preloadColors[i].r, preloadColors[i].g, preloadColors[i].b };
-
- for (int ch = 0; ch < 3; ch++)
- {
- uint8_t tone = rgb[ch];
-
- bool toneAlreadyQueued = false;
- for (size_t j = 0; j < numTonePreloads; j++)
- {
- if (specs[numPalettePreloads + j].m_color.r == tone)
- {
- toneAlreadyQueued = true;
- break;
- }
- }
-
- if (!toneAlreadyQueued)
- {
- PreloadAATableSpec &spec = specs[numPalettePreloads + numTonePreloads];
- numTonePreloads++;
-
- spec.m_color = PortabilityLayer::RGBAColor::Create(tone, tone, tone, 255);
- spec.m_isTone = true;
- }
- }
- }
-
- PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
-
- const int numAASpecs = numPalettePreloads + numTonePreloads;
-
- unsigned int cpus = PLDrivers::GetSystemServices()->GetCPUCount();
- if (cpus < 2)
- {
- for (size_t i = 0; i < numAASpecs; i++)
- {
- PreloadAATableThreadFunc(specs + i);
- StepLoadScreen(1, false);
- }
- }
- else
- {
- cpus -= 1;
-
- int queuedSpecs = 0;
- int completedSpecs = 0;
-
- PreloadAATableWorkSlot *slots = static_cast(mm->Alloc(sizeof(PreloadAATableWorkSlot) * cpus));
-
- IGpMutex *mutex = PLDrivers::GetSystemServices()->CreateMutex();
-
- for (unsigned int i = 0; i < cpus; i++)
- {
- PreloadAATableWorkSlot *slot = new (slots + i) PreloadAATableWorkSlot();
- slot->m_workerThread = PortabilityLayer::WorkerThread::Create();
- slot->m_completedEvent = PLDrivers::GetSystemServices()->CreateThreadEvent(true, false);
- slot->m_mutex = mutex;
- }
-
- while (completedSpecs < numAASpecs)
- {
- int completedThisStep = 0;
- for (unsigned int i = 0; i < cpus; i++)
- {
- PreloadAATableWorkSlot &slot = slots[i];
-
- if (slot.m_queued)
- {
- if (slot.m_singleJobCompleted.load(std::memory_order_acquire) != 0)
- {
- slot.m_completedEvent->Wait();
- slot.m_queued = false;
- completedSpecs++;
-
- completedThisStep++;
- }
- }
-
- if (!slot.m_queued)
- {
- if (queuedSpecs < numAASpecs)
- {
- slot.m_queued = true;
- slot.m_spec = specs + queuedSpecs;
- slot.m_singleJobCompleted.store(0, std::memory_order_release);
- slot.m_workerThread->AsyncExecuteTask(PreloadAATableThreadFunc, &slot);
-
- queuedSpecs++;
- }
- }
- }
-
- if (completedThisStep > 0)
- StepLoadScreen(completedThisStep, false);
-
- StepLoadScreenRing();
- Delay(1, nullptr);
- }
-
- for (unsigned int i = 0; i < cpus; i++)
- slots[i].~PreloadAATableWorkSlot();
-
- mm->Release(slots);
- mutex->Destroy();
- }
-}
-
void ShowInitialLaunchDisclaimer()
{
const char *disclaimerLines[] =
@@ -933,8 +383,8 @@ void ShowInitialLaunchDisclaimer()
const size_t numLines = sizeof(disclaimerLines) / sizeof(disclaimerLines[0]);
- PortabilityLayer::RenderedFont *rfont = GetApplicationFont(14, PortabilityLayer::FontFamilyFlag_None, true);
- PortabilityLayer::RenderedFont *buttonFont = GetApplicationFont(18, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *rfont = GetFont(PortabilityLayer::FontPresets::kApplication14);
+ PortabilityLayer::RenderedFont *buttonFont = GetFont(PortabilityLayer::FontPresets::kApplication18);
const int kButtonSpacing = 16;
const int kButtonHeight = 32;
@@ -1098,11 +548,6 @@ int gpAppMain()
SpinCursor(2); // Tick once to let the display driver flush any resolution changes from prefs
FlushResolutionChange();
- InitLoadingWindow(); StepLoadScreen(2, true);
- PreloadAATables();
- assert(isPrefsLoaded || loadScreenWindowPhase == 0);
- PreloadFonts(); StepLoadScreen(2, true);
-
#if defined COMPILEDEMO
copyGood = true;
#elif defined COMPILENOCP
@@ -1120,25 +565,12 @@ int gpAppMain()
// if ((thisMac.numScreens > 1) && (isUseSecondScreen))
// ReflectSecondMonitorEnvirons(false, true, true);
HandleDepthSwitching();
- VariableInit(); StepLoadScreen(2, true);
- GetExtraCursors(); StepLoadScreen(2, true);
+ VariableInit();
+ GetExtraCursors();
InitMarquee();
- CreatePointers(); StepLoadScreen(2, true);
+ CreatePointers();
InitSrcRects();
- CreateOffscreens(); StepLoadScreen(2, true);
-
- if (loadScreenWindow)
- {
- PortabilityLayer::WindowManager::GetInstance()->FlickerWindowOut(loadScreenWindow, 32);
- PortabilityLayer::WindowManager::GetInstance()->DestroyWindow(loadScreenWindow);
- PLSysCalls::Sleep(15);
- }
-
- if (loadScreenRingSurface)
- {
- DisposeGWorld(loadScreenRingSurface);
- loadScreenRingSurface = nullptr;
- }
+ CreateOffscreens();
bool resolutionChanged = false;
diff --git a/GpApp/MainMenuUI.cpp b/GpApp/MainMenuUI.cpp
index 676638f..72cda53 100644
--- a/GpApp/MainMenuUI.cpp
+++ b/GpApp/MainMenuUI.cpp
@@ -64,13 +64,13 @@ struct MainMenuUIState
ControlID m_activeControl;
static const unsigned int kControlHeight = 40;
- static const unsigned int kControlFontSize = 24;
static const unsigned int kControlLeftSpacing = 20;
static const unsigned int kControlBottomSpacing = 20;
static const unsigned int kControlIntermediateSpacing = 16;
static const unsigned int kControlInteriorSpacing = 6;
static const unsigned int kControlScrollInDecay = 32;
static const unsigned int kControlScrollInDecayFalloffBits = 0;
+ static const PortabilityLayer::FontPreset_t kControlFontPreset = PortabilityLayer::FontPresets::kHandwriting24;
};
static MainMenuUIState mainMenu;
@@ -135,7 +135,7 @@ static void DrawMainMenuControl(DrawSurface *surface, MainMenuUIState::ControlID
{
case MainMenuUIState::ControlStyle_Text:
{
- PortabilityLayer::RenderedFont *rfont = GetHandwritingFont(MainMenuUIState::kControlFontSize, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *rfont = GetFont(MainMenuUIState::kControlFontPreset);
if (!rfont)
return;
@@ -219,7 +219,7 @@ void StartMainMenuUI()
{
DismissMainMenuUI();
- PortabilityLayer::RenderedFont *rfont = GetHandwritingFont(MainMenuUIState::kControlFontSize, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *rfont = GetFont(MainMenuUIState::kControlFontPreset);
if (!rfont)
return;
diff --git a/GpApp/MainWindow.cpp b/GpApp/MainWindow.cpp
index 50aa3df..effe354 100644
--- a/GpApp/MainWindow.cpp
+++ b/GpApp/MainWindow.cpp
@@ -71,7 +71,7 @@ void DrawOnSplash(DrawSurface *surface)
if ((thisMac.hasQT) && (hasMovie))
PasStringConcat(houseLoadedStr, PSTR(" (TV)"));
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(9, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication9Bold);
const Point textPoint = Point::Create(splashOriginH + 436, splashOriginV + 314);
if (thisMac.isDepth == 4)
diff --git a/GpApp/ObjectDraw2.cpp b/GpApp/ObjectDraw2.cpp
index 1dbfffb..45749b0 100644
--- a/GpApp/ObjectDraw2.cpp
+++ b/GpApp/ObjectDraw2.cpp
@@ -1057,7 +1057,7 @@ void DrawCalendar (Rect *theRect)
backSrcMap->DrawPicture(thePicture, bounds);
thePicture.Dispose();
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(9, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication9Bold);
GetTime(&timeRec);
GetIndString(monthStr, kMonthStringID, timeRec.month);
diff --git a/GpApp/Room.cpp b/GpApp/Room.cpp
index e5f5fe8..0e806d1 100644
--- a/GpApp/Room.cpp
+++ b/GpApp/Room.cpp
@@ -251,7 +251,7 @@ void ReadyBackground (short theID, short *theTiles)
workSrcMap->FillRect(workSrcRect, ltGrayColor);
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(9, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication9);
const Point textPoint = Point::Create(10, 20);
if (houseUnlocked)
diff --git a/GpApp/SavedGames.cpp b/GpApp/SavedGames.cpp
index 4ef046f..a955d74 100644
--- a/GpApp/SavedGames.cpp
+++ b/GpApp/SavedGames.cpp
@@ -44,7 +44,7 @@ static const int kScoreOffset = 320;
static void FBUI_DrawLabels(DrawSurface *surface, const Point &basePoint)
{
PortabilityLayer::ResolveCachingColor blackColor(StdColors::Black());
- PortabilityLayer::RenderedFont *rfont = GetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *rfont = GetFont(PortabilityLayer::FontPresets::kSystem12Bold);
surface->DrawString(basePoint + Point::Create(kStarsOffset, 0), PSTR("Stars Left"), blackColor, rfont);
surface->DrawString(basePoint + Point::Create(kGlidersOffset, 0), PSTR("Gliders"), blackColor, rfont);
@@ -54,7 +54,7 @@ static void FBUI_DrawLabels(DrawSurface *surface, const Point &basePoint)
static void FBUI_DrawFileDetails(DrawSurface *surface, const Point &basePoint, const Rect &constraintRect, void *fileDetails)
{
PortabilityLayer::ResolveCachingColor blackColor(StdColors::Black());
- PortabilityLayer::RenderedFont *rfont = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *rfont = GetFont(PortabilityLayer::FontPresets::kSystem12Bold);
const game2Type *gameData = static_cast(fileDetails);
diff --git a/GpApp/Scoreboard.cpp b/GpApp/Scoreboard.cpp
index 96ce361..16351b4 100644
--- a/GpApp/Scoreboard.cpp
+++ b/GpApp/Scoreboard.cpp
@@ -176,7 +176,7 @@ void RefreshRoomTitle (short mode)
const Point strShadowPoint = Point::Create(1, 10);
const Point strPoint = Point::Create(0, 9);
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
switch (mode)
{
@@ -221,7 +221,7 @@ void RefreshNumGliders (void)
long displayMortals;
DrawSurface *surface = boardGSrcMap;
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
PortabilityLayer::ResolveCachingColor theRGBColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(kGrayBackgroundColor);
PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black();
@@ -256,7 +256,7 @@ void RefreshPoints (void)
PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black();
PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White();
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
surface->FillRect(boardPSrcRect, theRGBColor);
@@ -286,7 +286,7 @@ void QuickGlidersRefresh (void)
PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black();
PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White();
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
surface->FillRect(boardGSrcRect, theRGBColor);
@@ -316,7 +316,7 @@ void QuickScoreRefresh (void)
PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black();
PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White();
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication12Bold);
surface->FillRect(boardPSrcRect, theRGBColor);
diff --git a/GpApp/SourceExport.cpp b/GpApp/SourceExport.cpp
index 2401147..0d99c5f 100644
--- a/GpApp/SourceExport.cpp
+++ b/GpApp/SourceExport.cpp
@@ -135,7 +135,7 @@ static void InitSourceExportWindow(SourceExportState *state)
PortabilityLayer::WindowManager::GetInstance()->FlickerWindowIn(state->m_window, 32);
const PLPasStr loadingText = PSTR("Exporting...");
- PortabilityLayer::RenderedFont *font = GetApplicationFont(18, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *font = GetFont(PortabilityLayer::FontPresets::kApplication18);
int32_t textY = (kLoadScreenHeight + font->GetMetrics().m_ascent) / 2;
surface->DrawString(Point::Create(4 + 16, textY), loadingText, blackColor, font);
diff --git a/GpApp/Tools.cpp b/GpApp/Tools.cpp
index d41d5ae..abe82f8 100644
--- a/GpApp/Tools.cpp
+++ b/GpApp/Tools.cpp
@@ -156,7 +156,7 @@ void DrawToolName (DrawSurface *surface)
const Point textPoint = Point::Create(toolTextRect.left + 3, toolTextRect.bottom - 6);
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(9, PortabilityLayer::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication9Bold);
ColorText(surface, textPoint, theString, 171L, appFont);
}
#endif
diff --git a/GpApp/WindowUtils.cpp b/GpApp/WindowUtils.cpp
index 2f25557..e5f4a05 100644
--- a/GpApp/WindowUtils.cpp
+++ b/GpApp/WindowUtils.cpp
@@ -146,7 +146,7 @@ void SetMessageWindowMessage (StringPtr message, const PortabilityLayer::RGBACol
{
DrawSurface *surface = mssgWindow->GetDrawSurface();
- PortabilityLayer::RenderedFont *sysFont = GetSystemFont(12, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *sysFont = GetFont(PortabilityLayer::FontPresets::kSystem12);
SetRect(&mssgWindowRect, 0, 0, 256, kMessageWindowTall);
InsetRect(&mssgWindowRect, 16, 16);
diff --git a/GpCommon/EGpFontHandlerType.h b/GpCommon/EGpFontHandlerType.h
index 7a1dc52..dff7d4a 100644
--- a/GpCommon/EGpFontHandlerType.h
+++ b/GpCommon/EGpFontHandlerType.h
@@ -2,6 +2,7 @@
enum EGpFontHandlerType
{
+ EGpFontHandlerType_None,
EGpFontHandlerType_FreeType2,
EGpFontHandlerType_Count,
diff --git a/GpCommon/GpWindows.h b/GpCommon/GpWindows.h
index 237bd7b..bc53aac 100644
--- a/GpCommon/GpWindows.h
+++ b/GpCommon/GpWindows.h
@@ -11,7 +11,6 @@
#undef LoadCursor
#undef CreateFile
-struct IGpFiber;
struct IGpBWCursor_Win32;
struct IGpCursor_Win32;
struct IGpVOSEventQueue;
@@ -29,7 +28,6 @@ struct GpWindowsGlobals
HICON m_hIconSm;
int m_nCmdShow;
- IGpFiber *(*m_createFiberFunc)(LPVOID fiber);
IGpCursor_Win32 *(*m_createColorCursorFunc)(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY);
IGpCursor_Win32 *(*m_createBWCursorFunc)(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY);
void (*m_translateWindowsMessageFunc)(const MSG *msg, IGpVOSEventQueue *eventQueue, float pixelScaleX, float pixelScaleY);
diff --git a/GpCommon/IGpFiber.h b/GpCommon/IGpFiber.h
deleted file mode 100644
index 4990eac..0000000
--- a/GpCommon/IGpFiber.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-
-#include "CoreDefs.h"
-
-struct IGpFiber
-{
- virtual void YieldTo(IGpFiber *toFiber) = 0;
- virtual void YieldToTerminal(IGpFiber *toFiber) = 0;
- virtual void Destroy() = 0;
-};
diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp
index 389ab80..0990779 100644
--- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp
+++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp
@@ -4,7 +4,6 @@
#include "GpVOSEvent.h"
#include "GpWindows.h"
#include "IGpCursor_Win32.h"
-#include "IGpFiber.h"
#include "IGpVOSEventQueue.h"
#include "IGpLogDriver.h"
@@ -624,8 +623,6 @@ bool GpDisplayDriverD3D11::InitResources(uint32_t virtualWidth, uint32_t virtual
bool GpDisplayDriverD3D11::SyncRender()
{
- fprintf(stderr, "Test\n");
-
if (m_frameTimeAccumulated >= m_frameTimeSliceSize)
{
m_frameTimeAccumulated -= m_frameTimeSliceSize;
@@ -777,165 +774,6 @@ bool GpDisplayDriverD3D11::SyncRender()
return false;
}
-GpDisplayDriverTickStatus_t GpDisplayDriverD3D11::PresentFrameAndSync()
-{
- SynchronizeCursors();
-
- FLOAT bgColor[4];
-
- for (int i = 0; i < 4; i++)
- bgColor[i] = m_bgColor[i];
-
- if (m_bgIsDark)
- {
- for (int i = 0; i < 3; i++)
- bgColor[i] *= 0.25f;
- }
-
- m_deviceContext->ClearRenderTargetView(m_virtualScreenTextureRTV, bgColor);
-
- //ID3D11RenderTargetView *const rtv = m_backBufferRTV;
- ID3D11RenderTargetView *const vsRTV = m_virtualScreenTextureRTV;
- m_deviceContext->OMSetRenderTargets(1, &vsRTV, nullptr);
-
- {
- D3D11_VIEWPORT viewport;
- viewport.TopLeftX = 0;
- viewport.TopLeftY = 0;
- viewport.Width = static_cast(m_windowWidthVirtual);
- viewport.Height = static_cast(m_windowHeightVirtual);
- viewport.MinDepth = 0.0f;
- viewport.MaxDepth = 1.0f;
-
- m_deviceContext->RSSetViewports(1, &viewport);
- }
-
- m_properties.m_renderFunc(m_properties.m_renderFuncContext);
-
- ScaleVirtualScreen();
-
- DXGI_PRESENT_PARAMETERS presentParams;
-
- ZeroMemory(&presentParams, sizeof(presentParams));
-
- UINT lastPresentCount = 0;
-
- if (FAILED(m_swapChain->GetLastPresentCount(&lastPresentCount)))
- return GpDisplayDriverTickStatuses::kNonFatalFault;
-
- if (FAILED(m_swapChain->Present1(1, 0, &presentParams)))
- return GpDisplayDriverTickStatuses::kNonFatalFault;
-
- //DebugPrintf("r: %i\n", static_cast(r));
-
- DXGI_FRAME_STATISTICS stats;
- if (FAILED(m_swapChain->GetFrameStatistics(&stats)))
- return GpDisplayDriverTickStatuses::kNonFatalFault;
-
- if (stats.SyncQPCTime.QuadPart != 0)
- {
- if (m_syncTimeBase.QuadPart == 0)
- m_syncTimeBase = stats.SyncQPCTime;
-
- LARGE_INTEGER timestamp;
- timestamp.QuadPart = stats.SyncQPCTime.QuadPart - m_syncTimeBase.QuadPart;
-
- bool compacted = false;
- if (m_presentHistory.Size() > 0)
- {
- CompactedPresentHistoryItem &lastItem = m_presentHistory[m_presentHistory.Size() - 1];
- LONGLONG timeDelta = timestamp.QuadPart - lastItem.m_timestamp.QuadPart;
-
- if (timeDelta < 0)
- timeDelta = 0; // This should never happen
-
- if (timeDelta * static_cast(m_properties.m_frameTimeLockDenominator) < m_QPFrequency.QuadPart * static_cast(m_properties.m_frameTimeLockNumerator))
- {
- lastItem.m_numFrames++;
- compacted = true;
- }
- }
-
- if (!compacted)
- {
- if (m_presentHistory.Size() == m_presentHistory.CAPACITY)
- m_presentHistory.RemoveFromStart();
-
- CompactedPresentHistoryItem *newItem = m_presentHistory.Append();
- newItem->m_timestamp = timestamp;
- newItem->m_numFrames = 1;
- }
- }
-
- if (m_presentHistory.Size() >= 2)
- {
- const size_t presentHistorySizeMinusOne = m_presentHistory.Size() - 1;
- unsigned int numFrames = 0;
- for (size_t i = 0; i < presentHistorySizeMinusOne; i++)
- numFrames += m_presentHistory[i].m_numFrames;
-
- LONGLONG timeFrame = m_presentHistory[presentHistorySizeMinusOne].m_timestamp.QuadPart - m_presentHistory[0].m_timestamp.QuadPart;
-
- unsigned int cancelledFrames = 0;
- LONGLONG cancelledTime = 0;
-
- const int overshootTolerance = 2;
-
- for (size_t i = 0; i < presentHistorySizeMinusOne; i++)
- {
- LONGLONG blockTimeframe = m_presentHistory[i + 1].m_timestamp.QuadPart - m_presentHistory[i].m_timestamp.QuadPart;
- unsigned int blockNumFrames = m_presentHistory[i].m_numFrames;
-
- if (blockTimeframe * static_cast(numFrames) >= timeFrame * static_cast(blockNumFrames) * overshootTolerance)
- {
- cancelledTime += blockTimeframe;
- cancelledFrames += blockNumFrames;
- }
- }
-
- numFrames -= cancelledFrames;
- timeFrame -= cancelledTime;
-
- // timeFrame / numFrames = Frame timestep
- // Unless Frame timestep is within the frame lock range, a.k.a.
- // timeFrame / numFrames / qpFreq >= minFrameTimeNum / minFrameTimeDenom
-
- bool isInFrameTimeLock = false;
- if (timeFrame * static_cast(m_properties.m_frameTimeLockMinDenominator) >= static_cast(numFrames) * static_cast(m_properties.m_frameTimeLockMinNumerator) * m_QPFrequency.QuadPart
- && timeFrame * static_cast(m_properties.m_frameTimeLockMaxDenominator) <= static_cast(numFrames) * static_cast(m_properties.m_frameTimeLockMaxNumerator) * m_QPFrequency.QuadPart)
- {
- isInFrameTimeLock = true;
- }
-
- LONGLONG frameTimeStep = m_frameTimeSliceSize;
- if (!isInFrameTimeLock)
- {
- const int MAX_FRAMES_PER_STEP = 4;
-
- frameTimeStep = timeFrame / numFrames;
- if (frameTimeStep > m_frameTimeSliceSize * MAX_FRAMES_PER_STEP)
- frameTimeStep = m_frameTimeSliceSize * MAX_FRAMES_PER_STEP;
- }
-
- m_frameTimeAccumulated += frameTimeStep;
- while (m_frameTimeAccumulated >= m_frameTimeSliceSize)
- {
- GpDisplayDriverTickStatus_t tickStatus = m_properties.m_tickFunc(m_properties.m_tickFuncContext, m_vosFiber);
- m_frameTimeAccumulated -= m_frameTimeSliceSize;
-
- if (tickStatus == GpDisplayDriverTickStatuses::kSynchronizing)
- {
- m_frameTimeAccumulated = 0;
- break;
- }
- else if (tickStatus != GpDisplayDriverTickStatuses::kOK)
- return tickStatus;
- }
- }
-
- return GpDisplayDriverTickStatuses::kOK;
-}
-
void GpDisplayDriverD3D11::ScaleVirtualScreen()
{
{
@@ -1294,6 +1132,11 @@ bool GpDisplayDriverD3D11::Init()
return true;
}
+void GpDisplayDriverD3D11::ForceSync()
+{
+ m_frameTimeAccumulated = 0;
+}
+
void GpDisplayDriverD3D11::ServeTicks(int tickCount)
{
HMENU menus = NULL;
@@ -1398,157 +1241,6 @@ void GpDisplayDriverD3D11::ServeTicks(int tickCount)
}
}
-void GpDisplayDriverD3D11::Run()
-{
- IGpLogDriver *logger = m_properties.m_logger;
-
- WNDCLASSEX wc;
-
- LPVOID fiber = ConvertThreadToFiberEx(this, 0);
- if (!fiber)
- {
- if (logger)
- logger->Printf(IGpLogDriver::Category_Error, "ConvertThreadToFiberEx failed");
-
- return; // ???
- }
-
- m_vosFiber = m_osGlobals->m_createFiberFunc(fiber);
-
- ZeroMemory(&wc, sizeof(wc));
-
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WinProc;
- wc.hInstance = m_osGlobals->m_hInstance;
- wc.hCursor = m_arrowCursor;
- wc.hIcon = m_osGlobals->m_hIcon;
- wc.hIconSm = m_osGlobals->m_hIconSm;
- wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
- wc.lpszClassName = "GPD3D11WindowClass";
-
- RegisterClassEx(&wc);
-
- LONG windowStyle = WS_OVERLAPPEDWINDOW;
- HMENU menus = NULL;
-
- // TODO: Fix the resolution here
- RECT wr = { 0, 0, static_cast(m_windowWidthPhysical), static_cast(m_windowHeightPhysical) };
- AdjustWindowRect(&wr, windowStyle, menus != NULL);
-
- m_osGlobals->m_hwnd = CreateWindowExW(NULL, L"GPD3D11WindowClass", GP_APPLICATION_NAME_W, WS_OVERLAPPEDWINDOW, 300, 300, wr.right - wr.left, wr.bottom - wr.top, NULL, menus, m_osGlobals->m_hInstance, NULL);
-
- ShowWindow(m_osGlobals->m_hwnd, m_osGlobals->m_nCmdShow);
-
- StartD3DForWindow(m_osGlobals->m_hwnd, m_swapChain, m_device, m_deviceContext, logger);
-
- InitResources(m_windowWidthVirtual, m_windowHeightVirtual);
-
- LARGE_INTEGER lastTimestamp;
- memset(&lastTimestamp, 0, sizeof(lastTimestamp));
-
- m_initialWidth = m_windowWidthVirtual;
- m_initialHeight = m_windowHeightVirtual;
-
- MSG msg;
- for (;;)
- {
- if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- DispatchMessage(&msg);
-
- {
- if (msg.message == WM_MOUSEMOVE)
- {
- if (!m_mouseIsInClientArea)
- {
- m_mouseIsInClientArea = true;
-
- TRACKMOUSEEVENT tme;
- ZeroMemory(&tme, sizeof(tme));
-
- tme.cbSize = sizeof(tme);
- tme.dwFlags = TME_LEAVE;
- tme.hwndTrack = m_osGlobals->m_hwnd;
- tme.dwHoverTime = HOVER_DEFAULT;
- TrackMouseEvent(&tme);
- }
- }
- else if (msg.message == WM_MOUSELEAVE)
- m_mouseIsInClientArea = false;
-
- m_osGlobals->m_translateWindowsMessageFunc(&msg, m_properties.m_eventQueue, m_pixelScaleX, m_pixelScaleY);
- }
- }
- else
- {
- if (m_isFullScreen != m_isFullScreenDesired)
- {
- if (m_isFullScreenDesired)
- BecomeFullScreen(windowStyle);
- else
- BecomeWindowed(windowStyle);
- }
-
- RECT clientRect;
- GetClientRect(m_osGlobals->m_hwnd, &clientRect);
-
- unsigned int desiredWidth = clientRect.right - clientRect.left;
- unsigned int desiredHeight = clientRect.bottom - clientRect.top;
- if (clientRect.right - clientRect.left != m_windowWidthPhysical || clientRect.bottom - clientRect.top != m_windowHeightPhysical || m_isResolutionResetDesired)
- {
- uint32_t prevWidthPhysical = m_windowWidthPhysical;
- uint32_t prevHeightPhysical = m_windowHeightPhysical;
- uint32_t prevWidthVirtual = m_windowWidthVirtual;
- uint32_t prevHeightVirtual = m_windowHeightVirtual;
- uint32_t virtualWidth = m_windowWidthVirtual;
- uint32_t virtualHeight = m_windowHeightVirtual;
- float pixelScaleX = 1.0f;
- float pixelScaleY = 1.0f;
-
- if (desiredWidth < 640)
- desiredWidth = 640;
-
- if (desiredHeight < 480)
- desiredHeight = 480;
-
- if (m_properties.m_adjustRequestedResolutionFunc(m_properties.m_adjustRequestedResolutionFuncContext, desiredWidth, desiredHeight, virtualWidth, virtualHeight, pixelScaleX, pixelScaleY))
- {
- bool resizedOK = ResizeD3DWindow(m_osGlobals->m_hwnd, m_windowWidthPhysical, m_windowHeightPhysical, desiredWidth, desiredHeight, windowStyle, menus, logger);
- resizedOK = resizedOK && DetachSwapChain();
- resizedOK = resizedOK && ResizeSwapChain(m_swapChain, m_windowWidthPhysical, m_windowHeightPhysical);
- resizedOK = resizedOK && InitBackBuffer(virtualWidth, virtualHeight);
-
- if (!resizedOK)
- break; // Critical video driver error, exit
-
- m_windowWidthVirtual = virtualWidth;
- m_windowHeightVirtual = virtualHeight;
- m_pixelScaleX = pixelScaleX;
- m_pixelScaleY = pixelScaleY;
- m_isResolutionResetDesired = false;
-
- if (GpVOSEvent *resizeEvent = m_properties.m_eventQueue->QueueEvent())
- {
- resizeEvent->m_eventType = GpVOSEventTypes::kVideoResolutionChanged;
- resizeEvent->m_event.m_resolutionChangedEvent.m_prevWidth = prevWidthVirtual;
- resizeEvent->m_event.m_resolutionChangedEvent.m_prevHeight = prevHeightVirtual;
- resizeEvent->m_event.m_resolutionChangedEvent.m_newWidth = m_windowWidthVirtual;
- resizeEvent->m_event.m_resolutionChangedEvent.m_newHeight = m_windowHeightVirtual;
- }
- }
- }
-
- GpDisplayDriverTickStatus_t tickStatus = PresentFrameAndSync();
- if (tickStatus == GpDisplayDriverTickStatuses::kFatalFault || tickStatus == GpDisplayDriverTickStatuses::kApplicationTerminated)
- break;
- }
- }
-
- // Exit
- ConvertFiberToThread();
-}
-
void GpDisplayDriverD3D11::Shutdown()
{
this->~GpDisplayDriverD3D11();
@@ -1833,7 +1525,6 @@ GpDisplayDriverD3D11::GpDisplayDriverD3D11(const GpDisplayDriverProperties &prop
, m_initialHeight(480)
, m_pixelScaleX(1.0f)
, m_pixelScaleY(1.0f)
- , m_vosFiber(nullptr)
, m_osGlobals(static_cast(properties.m_osGlobals))
, m_pendingCursor(nullptr)
, m_activeCursor(nullptr)
diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h
index 670053c..a9c583e 100644
--- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h
+++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h
@@ -16,7 +16,6 @@
struct GpWindowsGlobals;
struct IGpCursor_Win32;
struct IGpCursor;
-struct IGpFiber;
struct IDXGISwapChain1;
struct ID3D11Buffer;
@@ -37,8 +36,8 @@ class GpDisplayDriverD3D11 : public IGpDisplayDriver, public IGpPrefsHandler
{
public:
bool Init() override;
+ void ForceSync() override;
void ServeTicks(int tickCount) override;
- void Run() override;
void Shutdown() override;
void GetInitialDisplayResolution(unsigned int *width, unsigned int *height) override;
@@ -117,7 +116,6 @@ private:
bool DetachSwapChain();
bool InitBackBuffer(uint32_t virtualWidth, uint32_t virtualHeight);
bool InitResources(uint32_t virtualWidth, uint32_t virtualHeight);
- GpDisplayDriverTickStatus_t PresentFrameAndSync();
bool SyncRender();
void ScaleVirtualScreen();
@@ -192,7 +190,6 @@ private:
EGpStandardCursor_t m_pendingStandardCursor;
bool m_mouseIsInClientArea;
- IGpFiber *m_vosFiber;
GpWindowsGlobals *m_osGlobals;
HCURSOR m_arrowCursor;
diff --git a/GpShell/GpAppEnvironment.cpp b/GpShell/GpAppEnvironment.cpp
index f0d2299..14d2f18 100644
--- a/GpShell/GpAppEnvironment.cpp
+++ b/GpShell/GpAppEnvironment.cpp
@@ -1,11 +1,9 @@
#include "GpAppEnvironment.h"
-#include "GpFiberStarter.h"
#include "GpAppInterface.h"
#include "GpDisplayDriverTickStatus.h"
#include "GpFontHandlerFactory.h"
#include "HostSuspendCallArgument.h"
#include "IGpDisplayDriver.h"
-#include "IGpFiber.h"
#include "IGpInputDriver.h"
#include
diff --git a/GpShell/GpFiberStarter.h b/GpShell/GpFiberStarter.h
deleted file mode 100644
index 130443b..0000000
--- a/GpShell/GpFiberStarter.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#pragma once
-
-struct IGpFiber;
-struct IGpSystemServices;
-
-class GpFiberStarter
-{
-public:
- typedef void(*ThreadFunc_t)(void *context);
-
- static IGpFiber *StartFiber(IGpSystemServices *systemServices, ThreadFunc_t threadFunc, void *context, IGpFiber *creatingFiber);
-};
diff --git a/MakeRelease.bat b/MakeRelease.bat
index ef30418..3cb6d85 100644
--- a/MakeRelease.bat
+++ b/MakeRelease.bat
@@ -12,7 +12,6 @@ copy /Y x64\Release\GpAudioDriver_XAudio2.dll ReleasePkg\Aerofoil
copy /Y x64\Release\xaudio2_9redist.dll ReleasePkg\Aerofoil
copy /Y x64\Release\GpDisplayDriver_D3D11.dll ReleasePkg\Aerofoil
copy /Y x64\Release\GpInputDriver_XInput.dll ReleasePkg\Aerofoil
-copy /Y x64\Release\GpFontHandler_FreeType2.dll ReleasePkg\Aerofoil
copy /Y x64\Release\FreeType.dll ReleasePkg\Aerofoil
copy /Y x64\Release\GpApp.dll ReleasePkg\Aerofoil
diff --git a/PortabilityLayer.props b/PortabilityLayer.props
index 1f3de77..efe7492 100644
--- a/PortabilityLayer.props
+++ b/PortabilityLayer.props
@@ -5,7 +5,7 @@
- $(SolutionDir)\PortabilityLayer;%(AdditionalIncludeDirectories)
+ $(SolutionDir)PortabilityLayer;%(AdditionalIncludeDirectories)
diff --git a/PortabilityLayer/CFileStream.h b/PortabilityLayer/CFileStream.h
index e24196e..5bb0a6c 100644
--- a/PortabilityLayer/CFileStream.h
+++ b/PortabilityLayer/CFileStream.h
@@ -1,8 +1,5 @@
#pragma once
-#ifndef __PL_CFILESTREAM_H__
-#define __PL_CFILESTREAM_H__
-
#include
#include "CoreDefs.h"
@@ -38,5 +35,3 @@ namespace PortabilityLayer
bool m_seekable;
};
}
-
-#endif
diff --git a/PortabilityLayer/FileBrowserUI.cpp b/PortabilityLayer/FileBrowserUI.cpp
index 8565f03..8149b7d 100644
--- a/PortabilityLayer/FileBrowserUI.cpp
+++ b/PortabilityLayer/FileBrowserUI.cpp
@@ -199,7 +199,7 @@ namespace PortabilityLayer
void FileBrowserUIImpl::DrawHeaders()
{
- PortabilityLayer::RenderedFont *font = GetApplicationFont(12, PortabilityLayer::FontFamilyFlags::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *font = GetFont(FontPresets::kApplication12Bold);
ResolveCachingColor blackColor = StdColors::Black();
@@ -212,7 +212,7 @@ namespace PortabilityLayer
if (!m_entries.MMBlock())
return;
- PortabilityLayer::RenderedFont *font = GetApplicationFont(12, PortabilityLayer::FontFamilyFlags::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *font = GetFont(FontPresets::kApplication12Bold);
GpRenderedFontMetrics metrics = font->GetMetrics();
int32_t spacing = metrics.m_linegap;
@@ -634,8 +634,8 @@ namespace PortabilityLayer
PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(windowRect, PortabilityLayer::WindowStyleFlags::kAlert, true, 0, 0, PSTR(""));
PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black();
- PortabilityLayer::RenderedFont *font = GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
- PortabilityLayer::RenderedFont *fontLight = GetApplicationFont(8, PortabilityLayer::FontFamilyFlag_None, true);
+ PortabilityLayer::RenderedFont *font = GetFont(FontPresets::kApplication12Bold);
+ PortabilityLayer::RenderedFont *fontLight = GetFont(FontPresets::kApplication8);
int16_t verticalPoint = 16 + font->GetMetrics().m_ascent;
int16_t horizontalOffset = 16;
diff --git a/PortabilityLayer/FontFamily.cpp b/PortabilityLayer/FontFamily.cpp
index dba7a1b..39a5a7c 100644
--- a/PortabilityLayer/FontFamily.cpp
+++ b/PortabilityLayer/FontFamily.cpp
@@ -38,10 +38,10 @@ namespace PortabilityLayer
m_defaultVariation = defaultVariation;
}
- int FontFamily::GetVariationForFlags(int variation) const
+ int FontFamily::GetVariationForFlags(int flags) const
{
- if (m_fontSpecs[variation].m_isRegistered)
- return variation;
+ if (m_fontSpecs[flags].m_isRegistered)
+ return flags;
if (m_fontSpecs[0].m_isRegistered)
return 0;
@@ -111,9 +111,20 @@ namespace PortabilityLayer
return m_fontSpecs[variation].m_hacks;
}
- int FontFamily::GetCacheID() const
+ bool FontFamily::GetFontSpec(int variation, FontHacks &outHacks, const char *&outPath)
{
- return m_cacheID;
+ if (!m_fontSpecs[variation].m_isRegistered)
+ return false;
+
+ outHacks = m_fontSpecs[variation].m_hacks;
+ outPath = m_fontSpecs[variation].m_fontPath;
+
+ return true;
+ }
+
+ FontFamilyID_t FontFamily::GetFamilyID() const
+ {
+ return m_familyID;
}
void FontFamily::PurgeCache()
@@ -128,13 +139,13 @@ namespace PortabilityLayer
}
}
- FontFamily *FontFamily::Create(int cacheID)
+ FontFamily *FontFamily::Create(FontFamilyID_t familyID)
{
void *storage = malloc(sizeof(FontFamily));
if (!storage)
return nullptr;
- return new (storage) FontFamily(cacheID);
+ return new (storage) FontFamily(familyID);
}
void FontFamily::Destroy()
@@ -143,9 +154,9 @@ namespace PortabilityLayer
free(this);
}
- FontFamily::FontFamily(int cacheID)
+ FontFamily::FontFamily(FontFamilyID_t familyID)
: m_defaultVariation(0)
- , m_cacheID(cacheID)
+ , m_familyID(familyID)
{
}
diff --git a/PortabilityLayer/FontFamily.h b/PortabilityLayer/FontFamily.h
index 88e1283..df1f1de 100644
--- a/PortabilityLayer/FontFamily.h
+++ b/PortabilityLayer/FontFamily.h
@@ -1,6 +1,8 @@
#pragma once
+#include "FontFamilyID.h"
#include "FontHacks.h"
+
#include
class PLPasStr;
@@ -24,16 +26,17 @@ namespace PortabilityLayer
void AddFont(int flags, const char *path, FontHacks fontHacks);
void SetDefaultVariation(int defaultVariation);
+ bool GetFontSpec(int variation, FontHacks &outHacks, const char *&outPath);
- int GetVariationForFlags(int variation) const;
+ int GetVariationForFlags(int flags) const;
IGpFont *GetFontForVariation(int variation);
FontHacks GetHacksForVariation(int variation) const;
- int GetCacheID() const;
+ FontFamilyID_t GetFamilyID() const;
void PurgeCache();
- static FontFamily *Create(int cacheID);
+ static FontFamily *Create(FontFamilyID_t familyID);
void Destroy();
private:
@@ -49,9 +52,9 @@ namespace PortabilityLayer
FontSpec m_fontSpecs[kNumVariations];
uint8_t m_defaultVariation;
- int m_cacheID;
+ FontFamilyID_t m_familyID;
- explicit FontFamily(int cacheID);
+ explicit FontFamily(FontFamilyID_t familyID);
~FontFamily();
};
}
diff --git a/PortabilityLayer/FontFamilyID.h b/PortabilityLayer/FontFamilyID.h
new file mode 100644
index 0000000..4f5dd16
--- /dev/null
+++ b/PortabilityLayer/FontFamilyID.h
@@ -0,0 +1,19 @@
+#pragma once
+
+namespace PortabilityLayer
+{
+ namespace FontFamilyIDs
+ {
+ enum FontFamilyID
+ {
+ kSystem,
+ kApplication,
+ kMonospace,
+ kHandwriting,
+
+ kCount
+ };
+ }
+
+ typedef FontFamilyIDs::FontFamilyID FontFamilyID_t;
+}
diff --git a/PortabilityLayer/FontManager.cpp b/PortabilityLayer/FontManager.cpp
index 2cd1f8b..bf51a8d 100644
--- a/PortabilityLayer/FontManager.cpp
+++ b/PortabilityLayer/FontManager.cpp
@@ -2,13 +2,18 @@
#include "FontFamily.h"
#include "FontRenderer.h"
+#include "FileManager.h"
#include "GpIOStream.h"
#include "IGpFileSystem.h"
#include "IGpFont.h"
-#include "RenderedFont.h"
+#include "MemReaderStream.h"
#include "PLBigEndian.h"
#include "PLDrivers.h"
+#include "RenderedFontCatalog.h"
+#include "RenderedFont.h"
+#include "ResTypeID.h"
+#include "ResourceManager.h"
#include
#include
@@ -24,15 +29,12 @@ namespace PortabilityLayer
void Init() override;
void Shutdown() override;
- FontFamily *GetSystemFont(int textSize, int variationFlags) const override;
- FontFamily *GetApplicationFont(int textSize, int variationFlags) const override;
- FontFamily *GetHandwritingFont(int textSize, int variationFlags) const override;
- FontFamily *GetMonospaceFont(int textSize, int variationFlags) const override;
+ FontFamily *GetFont(FontFamilyID_t fontFamilyID) const override;
+ void GetFontPreset(FontPreset_t fontPreset, FontFamilyID_t *outFamilyID, int *outSize, int *outVariationFlags, bool *outAA) const override;
RenderedFont *GetRenderedFontFromFamily(FontFamily *font, int size, bool aa, int flags) override;
- RenderedFont *LoadCachedRenderedFont(int cacheID, int size, bool aa, int flags) const override;
- void SaveCachedRenderedFont(const RenderedFont *rfont, int cacheID, int size, bool aa, int flags) const override;
+ RenderedFont *LoadCachedRenderedFont(FontFamilyID_t familyID, int size, bool aa, int flags) override;
void PurgeCache() override;
@@ -40,12 +42,6 @@ namespace PortabilityLayer
private:
static const unsigned int kNumCachedRenderedFonts = 32;
- static const int kSystemFontCacheID = 1;
- static const int kApplicationFontCacheID = 2;
- static const int kHandwritingFontCacheID = 3;
- static const int kMonospaceFontCacheID = 4;
- static const int kFontCacheVersion = 2;
- static const int kFontCacheNameSize = 64;
struct CachedRenderedFont
{
@@ -56,6 +52,14 @@ namespace PortabilityLayer
bool m_aa;
};
+ struct FontPreset
+ {
+ FontFamilyID_t m_familyID;
+ int m_textSize;
+ int m_variationFlags;
+ bool m_aa;
+ };
+
FontManagerImpl();
bool FindOrReserveCacheSlot(int cacheID, int size, bool aa, CachedRenderedFont *&outCacheSlot, RenderedFont *&outRF);
@@ -64,57 +68,49 @@ namespace PortabilityLayer
void ResetUsageCounter();
static int CRFSortPredicate(const void *a, const void *b);
- static void GenerateCacheFileName(char(&str)[kFontCacheNameSize], int cacheID, int size, bool aa, int flags);
-
- FontFamily *m_systemFont;
- FontFamily *m_applicationFont;
- FontFamily *m_handwritingFont;
- FontFamily *m_monospaceFont;
+ FontFamily *m_fontFamilies[FontFamilyIDs::kCount];
uint32_t m_usageCounter;
CachedRenderedFont m_cachedRenderedFonts[kNumCachedRenderedFonts];
+ IResourceArchive *m_fontArchive;
+ PortabilityLayer::CompositeFile *m_fontArchiveFile;
+ THandle m_fontArchiveCatalogData;
+
static FontManagerImpl ms_instance;
+ static FontPreset ms_fontPresets[FontPresets::kCount];
};
void FontManagerImpl::Init()
{
- m_systemFont = FontFamily::Create(kSystemFontCacheID);
- m_applicationFont = FontFamily::Create(kApplicationFontCacheID);
- m_handwritingFont = FontFamily::Create(kHandwritingFontCacheID);
- m_monospaceFont = FontFamily::Create(kMonospaceFontCacheID);
+ for (int i = 0; i < FontFamilyIDs::kCount; i++)
+ m_fontFamilies[static_cast(i)] = FontFamily::Create(static_cast(i));
- if (m_systemFont)
- m_systemFont->AddFont(FontFamilyFlag_None, "Fonts/OpenSans/OpenSans-ExtraBold.ttf", FontHacks_None);
+ if (m_fontFamilies[FontFamilyIDs::kSystem])
+ m_fontFamilies[FontFamilyIDs::kSystem]->AddFont(FontFamilyFlag_None, "Fonts/OpenSans/OpenSans-ExtraBold.ttf", FontHacks_None);
- if (m_applicationFont)
+ if (m_fontFamilies[FontFamilyIDs::kApplication])
{
- m_applicationFont->AddFont(FontFamilyFlag_None, "Fonts/OpenSans/OpenSans-SemiBold.ttf", FontHacks_None);
- m_applicationFont->AddFont(FontFamilyFlag_Bold, "Fonts/OpenSans/OpenSans-Bold.ttf", FontHacks_None);
+ m_fontFamilies[FontFamilyIDs::kApplication]->AddFont(FontFamilyFlag_None, "Fonts/OpenSans/OpenSans-SemiBold.ttf", FontHacks_None);
+ m_fontFamilies[FontFamilyIDs::kApplication]->AddFont(FontFamilyFlag_Bold, "Fonts/OpenSans/OpenSans-Bold.ttf", FontHacks_None);
}
- if (m_handwritingFont)
- m_handwritingFont->AddFont(FontFamilyFlag_None, "Fonts/GochiHand/GochiHand-Regular.ttf", FontHacks_None);
+ if (m_fontFamilies[FontFamilyIDs::kHandwriting])
+ m_fontFamilies[FontFamilyIDs::kHandwriting]->AddFont(FontFamilyFlag_None, "Fonts/GochiHand/GochiHand-Regular.ttf", FontHacks_None);
- if (m_monospaceFont)
- m_monospaceFont->AddFont(FontFamilyFlag_None, "Fonts/Roboto/RobotoMono-Regular.ttf", FontHacks_None);
+ if (m_fontFamilies[FontFamilyIDs::kMonospace])
+ m_fontFamilies[FontFamilyIDs::kMonospace]->AddFont(FontFamilyFlag_None, "Fonts/Roboto/RobotoMono-Regular.ttf", FontHacks_None);
memset(m_cachedRenderedFonts, 0, sizeof(m_cachedRenderedFonts));
}
void FontManagerImpl::Shutdown()
{
- if (m_systemFont)
- m_systemFont->Destroy();
-
- if (m_applicationFont)
- m_applicationFont->Destroy();
-
- if (m_handwritingFont)
- m_handwritingFont->Destroy();
-
- if (m_monospaceFont)
- m_monospaceFont->Destroy();
+ for (int fid = 0; fid < FontFamilyIDs::kCount; fid++)
+ {
+ if (m_fontFamilies[fid])
+ m_fontFamilies[fid]->Destroy();
+ }
IGpFontHandler *hfh = PLDrivers::GetFontHandler();
@@ -126,27 +122,37 @@ namespace PortabilityLayer
}
}
- FontFamily *FontManagerImpl::GetSystemFont(int textSize, int variationFlags) const
+ FontFamily *FontManagerImpl::GetFont(FontFamilyID_t fontFamilyID) const
{
- return m_systemFont;
+ return m_fontFamilies[fontFamilyID];
}
- FontFamily *FontManagerImpl::GetApplicationFont(int textSize, int variationFlags) const
+ void FontManagerImpl::GetFontPreset(FontPreset_t preset, FontFamilyID_t *outFamilyID, int *outSize, int *outVariationFlags, bool *outAA) const
{
- if (textSize < 11 && (variationFlags & FontFamilyFlag_Bold) != 0)
- return m_systemFont; // Use heavier font below 11pt
+ if (outSize)
+ *outSize = ms_fontPresets[preset].m_textSize;
- return m_applicationFont;
- }
+ if (outVariationFlags)
+ *outVariationFlags = ms_fontPresets[preset].m_variationFlags;
- FontFamily *FontManagerImpl::GetHandwritingFont(int textSize, int variationFlags) const
- {
- return m_handwritingFont;
- }
+ if (outAA)
+ *outAA = ms_fontPresets[preset].m_aa;
- FontFamily *FontManagerImpl::GetMonospaceFont(int textSize, int variationFlags) const
- {
- return m_monospaceFont;
+ if (outFamilyID)
+ {
+ switch (ms_fontPresets[preset].m_familyID)
+ {
+ case FontFamilyIDs::kApplication:
+ if (ms_fontPresets[preset].m_textSize < 11 && (ms_fontPresets[preset].m_variationFlags & FontFamilyFlag_Bold) != 0)
+ *outFamilyID = FontFamilyIDs::kSystem; // Use heavier font below 11pt
+ else
+ *outFamilyID = FontFamilyIDs::kApplication;
+ break;
+ default:
+ *outFamilyID = ms_fontPresets[preset].m_familyID;
+ break;
+ }
+ }
}
bool FontManagerImpl::FindOrReserveCacheSlot(int cacheID, int size, bool aa, CachedRenderedFont *&outCacheSlot, RenderedFont *&outRF)
@@ -206,15 +212,15 @@ namespace PortabilityLayer
RenderedFont *rfont = nullptr;
CachedRenderedFont *cacheSlot = nullptr;
- int cacheID = fontFamily->GetCacheID();
+ FontFamilyID_t familyID = fontFamily->GetFamilyID();
- if (this->FindOrReserveCacheSlot(cacheID, size, aa, cacheSlot, rfont))
+ if (this->FindOrReserveCacheSlot(familyID, size, aa, cacheSlot, rfont))
return rfont;
- rfont = fm->LoadCachedRenderedFont(cacheID, size, aa, flags);
+ rfont = fm->LoadCachedRenderedFont(familyID, size, aa, flags);
if (rfont)
{
- ReplaceCachedRenderedFont(*cacheSlot, rfont, cacheID, size, aa, flags);
+ ReplaceCachedRenderedFont(*cacheSlot, rfont, familyID, size, aa, flags);
return rfont;
}
@@ -228,9 +234,7 @@ namespace PortabilityLayer
rfont = FontRenderer::GetInstance()->RenderFont(hostFont, size, aa, fontFamily->GetHacksForVariation(variation));
if (rfont)
{
- fm->SaveCachedRenderedFont(rfont, fontFamily->GetCacheID(), size, aa, flags);
-
- ReplaceCachedRenderedFont(*cacheSlot, rfont, cacheID, size, aa, flags);
+ ReplaceCachedRenderedFont(*cacheSlot, rfont, familyID, size, aa, flags);
return rfont;
}
@@ -238,60 +242,110 @@ namespace PortabilityLayer
return rfont;
}
- RenderedFont *FontManagerImpl::LoadCachedRenderedFont(int cacheID, int size, bool aa, int flags) const
+ RenderedFont *FontManagerImpl::LoadCachedRenderedFont(FontFamilyID_t familyID, int size, bool aa, int flags)
{
- char filename[kFontCacheNameSize];
- GenerateCacheFileName(filename, cacheID, size, aa, flags);
-
- GpIOStream *stream = PLDrivers::GetFileSystem()->OpenFile(PortabilityLayer::VirtualDirectories::kFontCache, filename, false, GpFileCreationDispositions::kOpenExisting);
- if (!stream)
- return nullptr;
-
- BEUInt32_t version;
- if (stream->Read(&version, sizeof(version)) != sizeof(version) || version != kFontCacheVersion)
+ if (!m_fontArchive)
{
- stream->Close();
- return nullptr;
+ m_fontArchiveFile = PortabilityLayer::FileManager::GetInstance()->OpenCompositeFile(VirtualDirectories::kApplicationData, PSTR("Fonts"));
+ if (!m_fontArchiveFile)
+ return nullptr;
+
+ m_fontArchive = PortabilityLayer::ResourceManager::GetInstance()->LoadResFile(m_fontArchiveFile);
+ if (!m_fontArchive)
+ {
+ m_fontArchiveFile->Close();
+ return nullptr;
+ }
+
+ m_fontArchiveCatalogData = m_fontArchive->LoadResource('RFCT', 1000);
+ if (!m_fontArchiveCatalogData)
+ {
+ m_fontArchive->Destroy();
+ m_fontArchiveFile->Close();
+ return nullptr;
+ }
}
- RenderedFont *rfont = PortabilityLayer::FontRenderer::GetInstance()->LoadCache(stream);
- stream->Close();
+ FontFamily *fontFamily = this->GetFont(familyID);
+ int variation = fontFamily->GetVariationForFlags(flags);
+
+ FontHacks hacks = FontHacks_None;
+ const char *path = nullptr;
+ if (!fontFamily->GetFontSpec(variation, hacks, path))
+ return nullptr;
+
+ size_t pathLen = strlen(path);
+
+ // Parse font cache header
+ const uint8_t *catalogBytes = static_cast(*m_fontArchiveCatalogData);
+
+ RenderedFontCatalogHeader catHeader;
+ memcpy(&catHeader, catalogBytes, sizeof(catHeader));
+
+ if (catHeader.m_version != RenderedFontCatalogHeader::kVersion)
+ return nullptr;
+
+ size_t numPaths = catHeader.m_numPaths;
+ size_t numFonts = catHeader.m_numRFonts;
+
+ const uint8_t *pathsBytes = catalogBytes + catHeader.m_pathsOffset;
+ const uint8_t *pathEntryBytes = catalogBytes + sizeof(RenderedFontCatalogHeader);
+ const uint8_t *fontEntryBytes = pathEntryBytes + sizeof(RenderedFontCatalogPathEntry) * numPaths;
+
+ size_t pathIndex = numPaths;
+ for (size_t i = 0; i < numPaths; i++)
+ {
+ RenderedFontCatalogPathEntry pathEntry;
+ memcpy(&pathEntry, pathEntryBytes + i * sizeof(RenderedFontCatalogPathEntry), sizeof(RenderedFontCatalogPathEntry));
+
+ if (pathEntry.m_pathSize != pathLen)
+ continue;
+
+ if (!memcmp(pathsBytes + pathEntry.m_pathOffset, path, pathLen))
+ {
+ pathIndex = i;
+ break;
+ }
+ }
+
+ if (pathIndex == numPaths)
+ return nullptr;
+
+ size_t fontIndex = numFonts;
+ for (size_t i = 0; i < numFonts; i++)
+ {
+ RenderedFontCatalogRFontEntry fontEntry;
+ memcpy(&fontEntry, fontEntryBytes + i * sizeof(RenderedFontCatalogRFontEntry), sizeof(RenderedFontCatalogRFontEntry));
+
+ if (fontEntry.m_pathIndex == pathIndex && static_cast(fontEntry.m_hacks) == hacks && fontEntry.m_fontSize == size && (fontEntry.m_isAA != 0) == aa)
+ {
+ fontIndex = i;
+ break;
+ }
+ }
+
+ if (fontIndex == numFonts)
+ return nullptr;
+
+ THandle res = m_fontArchive->LoadResource('RFNT', 1000 + static_cast(fontIndex));
+ if (!res)
+ return nullptr;
+
+ PortabilityLayer::MemReaderStream stream(*res, res.MMBlock()->m_size);
+
+ RenderedFont *rfont = PortabilityLayer::FontRenderer::GetInstance()->LoadCache(&stream);
+ res.Dispose();
return rfont;
}
- void FontManagerImpl::SaveCachedRenderedFont(const RenderedFont *rfont, int cacheID, int size, bool aa, int flags) const
- {
- char filename[kFontCacheNameSize];
- GenerateCacheFileName(filename, cacheID, size, aa, flags);
-
- GpIOStream *stream = PLDrivers::GetFileSystem()->OpenFile(PortabilityLayer::VirtualDirectories::kFontCache, filename, true, GpFileCreationDispositions::kCreateOrOverwrite);
- if (!stream)
- return;
-
- BEUInt32_t zero32(0);
- if (stream->Write(&zero32, sizeof(zero32)) != sizeof(zero32))
- {
- stream->Close();
- return;
- }
-
- if (PortabilityLayer::FontRenderer::GetInstance()->SaveCache(rfont, stream))
- {
- BEUInt32_t version(kFontCacheVersion);
- stream->SeekStart(0);
- stream->Write(&version, sizeof(version));
- }
-
- stream->Close();
- }
-
void FontManagerImpl::PurgeCache()
{
- m_systemFont->PurgeCache();
- m_applicationFont->PurgeCache();
- m_handwritingFont->PurgeCache();
- m_monospaceFont->PurgeCache();
+ for (int fid = 0; fid < FontFamilyIDs::kCount; fid++)
+ {
+ if (m_fontFamilies[fid])
+ m_fontFamilies[fid]->PurgeCache();
+ }
}
FontManagerImpl *FontManagerImpl::GetInstance()
@@ -300,8 +354,11 @@ namespace PortabilityLayer
}
FontManagerImpl::FontManagerImpl()
- : m_systemFont(nullptr)
+ : m_fontArchive(nullptr)
+ , m_fontArchiveFile(nullptr)
{
+ for (int fid = 0; fid < FontFamilyIDs::kCount; fid++)
+ m_fontFamilies[fid] = nullptr;
}
void FontManagerImpl::ResetUsageCounter()
@@ -345,10 +402,26 @@ namespace PortabilityLayer
return 0;
}
- void FontManagerImpl::GenerateCacheFileName(char(&str)[kFontCacheNameSize], int cacheID, int size, bool aa, int flags)
+ FontManagerImpl::FontPreset FontManagerImpl::ms_fontPresets[FontPresets::kCount] =
{
- sprintf(str, "rf_%i_%i_%s_%i.cache", cacheID, size, aa ? "aa" : "mc", flags);
- }
+ { FontFamilyIDs::kSystem, 12, FontFamilyFlag_None, true },
+ { FontFamilyIDs::kSystem, 12, FontFamilyFlag_Bold, true },
+
+ { FontFamilyIDs::kApplication, 8, FontFamilyFlag_None, true },
+ { FontFamilyIDs::kApplication, 9, FontFamilyFlag_None, true },
+ { FontFamilyIDs::kApplication, 9, FontFamilyFlag_Bold, true },
+ { FontFamilyIDs::kApplication, 10, FontFamilyFlag_Bold, true },
+ { FontFamilyIDs::kApplication, 12, FontFamilyFlag_Bold, true },
+ { FontFamilyIDs::kApplication, 14, FontFamilyFlag_None, true },
+ { FontFamilyIDs::kApplication, 14, FontFamilyFlag_Bold, true },
+ { FontFamilyIDs::kApplication, 18, FontFamilyFlag_None, true },
+ { FontFamilyIDs::kApplication, 40, FontFamilyFlag_None, true },
+
+ { FontFamilyIDs::kMonospace, 10, FontFamilyFlag_None, true },
+
+ { FontFamilyIDs::kHandwriting, 24, FontFamilyFlag_None, true },
+ { FontFamilyIDs::kHandwriting, 48, FontFamilyFlag_None, true },
+ };
FontManagerImpl FontManagerImpl::ms_instance;
diff --git a/PortabilityLayer/FontManager.h b/PortabilityLayer/FontManager.h
index ea60800..8c281bd 100644
--- a/PortabilityLayer/FontManager.h
+++ b/PortabilityLayer/FontManager.h
@@ -1,6 +1,7 @@
#pragma once
#include "FontHacks.h"
+#include "FontFamilyID.h"
struct IGpFont;
@@ -9,21 +10,46 @@ namespace PortabilityLayer
class FontFamily;
class RenderedFont;
+ namespace FontPresets
+ {
+ enum FontPreset
+ {
+ kSystem12,
+ kSystem12Bold,
+
+ kApplication8,
+ kApplication9,
+ kApplication9Bold,
+ kApplication10Bold,
+ kApplication12Bold,
+ kApplication14,
+ kApplication14Bold,
+ kApplication18,
+ kApplication40,
+
+ kMono10,
+
+ kHandwriting24,
+ kHandwriting48,
+
+ kCount,
+ };
+ }
+
+ typedef FontPresets::FontPreset FontPreset_t;
+
class FontManager
{
public:
virtual void Init() = 0;
virtual void Shutdown() = 0;
- virtual FontFamily *GetSystemFont(int fontSize, int variationFlags) const = 0;
- virtual FontFamily *GetApplicationFont(int fontSize, int variationFlags) const = 0;
- virtual FontFamily *GetHandwritingFont(int fontSize, int variationFlags) const = 0;
- virtual FontFamily *GetMonospaceFont(int fontSize, int variationFlags) const = 0;
+ virtual FontFamily *GetFont(FontFamilyID_t fontFamilyID) const = 0;
+ virtual void GetFontPreset(FontPreset_t fontPreset, FontFamilyID_t *outFamilyID, int *outSize, int *outVariationFlags, bool *outAA) const = 0;
virtual RenderedFont *GetRenderedFontFromFamily(FontFamily *fontFamily, int fontSize, bool aa, int flags) = 0;
- virtual RenderedFont *LoadCachedRenderedFont(int cacheID, int size, bool aa, int flags) const = 0;
- virtual void SaveCachedRenderedFont(const RenderedFont *rfont, int cacheID, int size, bool aa, int flags) const = 0;
+ virtual RenderedFont *LoadCachedRenderedFont(FontFamilyID_t familyID, int size, bool aa, int flags) = 0;
virtual void PurgeCache() = 0;
diff --git a/PortabilityLayer/FontRenderer.cpp b/PortabilityLayer/FontRenderer.cpp
index 9f971ec..5cfef15 100644
--- a/PortabilityLayer/FontRenderer.cpp
+++ b/PortabilityLayer/FontRenderer.cpp
@@ -44,19 +44,42 @@ namespace PortabilityLayer
struct CacheHeader
{
BEUInt32_t m_cacheVersion;
- BEUInt32_t m_glyphDataUncompressedSize;
- BEUInt32_t m_glyphDataCompressedSize;
- BEUInt32_t m_sizeSize;
+ BEUInt32_t m_glyphDataSize;
BEUInt32_t m_isAA;
};
- static const uint32_t kRFontCacheVersion = 2;
+ struct SerializedGlyphMetrics
+ {
+ BEUInt32_t m_glyphDataPitch;
+
+ BEUInt32_t m_glyphWidth;
+ BEUInt32_t m_glyphHeight;
+
+ BEInt16_t m_bearingX;
+ BEInt16_t m_bearingY;
+ BEInt16_t m_advanceX;
+ };
+
+ struct SerializedFontMetrics
+ {
+ BEInt32_t m_ascent;
+ BEInt32_t m_descent;
+ BEInt32_t m_linegap;
+ };
+
+ static const uint32_t kRFontCacheVersion = 3;
RenderedFontImpl(void *data, size_t dataSize, bool aa);
~RenderedFontImpl();
- bool LoadInternal(GpIOStream *stream, size_t compressedDataSize);
+ bool LoadInternal(GpIOStream *stream, size_t dataSize);
+
+ static SerializedGlyphMetrics SerializeGlyphMetrics(const GpRenderedGlyphMetrics &metrics);
+ static GpRenderedGlyphMetrics DeserializeGlyphMetrics(const SerializedGlyphMetrics &metrics);
+
+ static SerializedFontMetrics SerializeFontMetrics(const GpRenderedFontMetrics &metrics);
+ static GpRenderedFontMetrics DeserializeFontMetrics(const SerializedFontMetrics &metrics);
size_t m_dataOffsets[256];
GpRenderedGlyphMetrics m_glyphMetrics[256];
@@ -143,14 +166,11 @@ namespace PortabilityLayer
if (header.m_cacheVersion != kRFontCacheVersion)
return nullptr;
- if (header.m_sizeSize != sizeof(size_t))
- return nullptr;
-
- RenderedFontImpl *rfont = RenderedFontImpl::Create(header.m_glyphDataUncompressedSize, header.m_isAA != 0);
+ RenderedFontImpl *rfont = RenderedFontImpl::Create(header.m_glyphDataSize, header.m_isAA != 0);
if (!rfont)
return nullptr;
- if (!rfont->LoadInternal(stream, header.m_glyphDataCompressedSize))
+ if (!rfont->LoadInternal(stream, header.m_glyphDataSize))
{
rfont->Destroy();
return nullptr;
@@ -163,51 +183,35 @@ namespace PortabilityLayer
{
CacheHeader header;
header.m_cacheVersion = kRFontCacheVersion;
- header.m_glyphDataUncompressedSize = static_cast(this->m_dataSize);
- header.m_glyphDataCompressedSize = 0;
- header.m_isAA = m_isAntiAliased;
- header.m_sizeSize = sizeof(size_t);
+ header.m_glyphDataSize = static_cast(this->m_dataSize);
+ header.m_isAA = m_isAntiAliased ? 1 : 0;
GpUFilePos_t headerPos = stream->Tell();
if (stream->Write(&header, sizeof(header)) != sizeof(header))
return false;
- DeflateContext *deflateContext = DeflateContext::Create(stream, 9);
- if (!deflateContext)
+ if (!stream->WriteExact(m_data, m_dataSize))
return false;
- GpUFilePos_t dataStartPos = stream->Tell();
-
- if (!deflateContext->Append(m_data, m_dataSize) || !deflateContext->Flush())
+ for (size_t i = 0; i < sizeof(m_dataOffsets) / sizeof(m_dataOffsets[0]); i++)
{
- deflateContext->Destroy();
- return false;
+ BEUInt32_t dataOffset = BEUInt32_t(static_cast(m_dataOffsets[i]));
+ if (!stream->WriteExact(&dataOffset, sizeof(dataOffset)))
+ return false;
}
- deflateContext->Destroy();
+ for (size_t i = 0; i < sizeof(m_glyphMetrics) / sizeof(m_glyphMetrics[0]); i++)
+ {
+ SerializedGlyphMetrics serialized = SerializeGlyphMetrics(m_glyphMetrics[i]);
- GpUFilePos_t dataEndPos = stream->Tell();
+ if (!stream->WriteExact(&serialized, sizeof(serialized)))
+ return false;
+ }
- if (stream->Write(m_dataOffsets, sizeof(m_dataOffsets)) != sizeof(m_dataOffsets))
- return false;
+ SerializedFontMetrics fontMetrics = SerializeFontMetrics(m_fontMetrics);
- if (stream->Write(m_glyphMetrics, sizeof(m_glyphMetrics)) != sizeof(m_glyphMetrics))
- return false;
-
- if (stream->Write(&m_fontMetrics, sizeof(m_fontMetrics)) != sizeof(m_fontMetrics))
- return false;
-
- GpUFilePos_t endPos = stream->Tell();
-
- if (!stream->SeekStart(headerPos))
- return false;
-
- header.m_glyphDataCompressedSize = dataEndPos - dataStartPos;
- if (stream->Write(&header, sizeof(header)) != sizeof(header))
- return false;
-
- if (!stream->SeekStart(headerPos))
+ if (!stream->WriteExact(&fontMetrics, sizeof(fontMetrics)))
return false;
return true;
@@ -246,25 +250,86 @@ namespace PortabilityLayer
{
}
- bool RenderedFontImpl::LoadInternal(GpIOStream *stream, size_t compressedDataSize)
+ bool RenderedFontImpl::LoadInternal(GpIOStream *stream, size_t dataSize)
{
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
- if (!DeflateCodec::DecompressStream(stream, compressedDataSize, m_data, m_dataSize))
+ if (!stream->ReadExact(m_data, m_dataSize))
return false;
- if (stream->Read(m_dataOffsets, sizeof(m_dataOffsets)) != sizeof(m_dataOffsets))
+ for (size_t i = 0; i < sizeof(m_dataOffsets) / sizeof(m_dataOffsets[0]); i++)
+ {
+ BEUInt32_t dataOffset;
+ if (!stream->ReadExact(&dataOffset, sizeof(dataOffset)))
+ return false;
+
+ m_dataOffsets[i] = dataOffset;
+ }
+
+ for (size_t i = 0; i < sizeof(m_glyphMetrics) / sizeof(m_glyphMetrics[0]); i++)
+ {
+ SerializedGlyphMetrics glyphMetrics;
+ if (!stream->ReadExact(&glyphMetrics, sizeof(glyphMetrics)))
+ return false;
+
+ m_glyphMetrics[i] = DeserializeGlyphMetrics(glyphMetrics);
+ }
+
+ SerializedFontMetrics fontMetrics;
+ if (!stream->ReadExact(&fontMetrics, sizeof(fontMetrics)))
return false;
- if (stream->Read(m_glyphMetrics, sizeof(m_glyphMetrics)) != sizeof(m_glyphMetrics))
- return false;
-
- if (stream->Read(&m_fontMetrics, sizeof(m_fontMetrics)) != sizeof(m_fontMetrics))
- return false;
+ m_fontMetrics = DeserializeFontMetrics(fontMetrics);
return true;
}
+ RenderedFontImpl::SerializedGlyphMetrics RenderedFontImpl::SerializeGlyphMetrics(const GpRenderedGlyphMetrics &metrics)
+ {
+ SerializedGlyphMetrics result;
+ result.m_advanceX = metrics.m_advanceX;
+ result.m_bearingX = metrics.m_bearingX;
+ result.m_bearingY = metrics.m_bearingY;
+ result.m_glyphDataPitch = static_cast(metrics.m_glyphDataPitch);
+ result.m_glyphHeight = metrics.m_glyphHeight;
+ result.m_glyphWidth = metrics.m_glyphWidth;
+
+ return result;
+ }
+
+ GpRenderedGlyphMetrics RenderedFontImpl::DeserializeGlyphMetrics(const SerializedGlyphMetrics &metrics)
+ {
+ GpRenderedGlyphMetrics result;
+ result.m_advanceX = metrics.m_advanceX;
+ result.m_bearingX = metrics.m_bearingX;
+ result.m_bearingY = metrics.m_bearingY;
+ result.m_glyphDataPitch = static_cast(metrics.m_glyphDataPitch);
+ result.m_glyphHeight = metrics.m_glyphHeight;
+ result.m_glyphWidth = metrics.m_glyphWidth;
+
+ return result;
+ }
+
+ RenderedFontImpl::SerializedFontMetrics RenderedFontImpl::SerializeFontMetrics(const GpRenderedFontMetrics &metrics)
+ {
+ SerializedFontMetrics result;
+ result.m_ascent = metrics.m_ascent;
+ result.m_descent = metrics.m_descent;
+ result.m_linegap = metrics.m_linegap;
+
+ return result;
+ }
+
+ GpRenderedFontMetrics RenderedFontImpl::DeserializeFontMetrics(const SerializedFontMetrics &metrics)
+ {
+ GpRenderedFontMetrics result;
+ result.m_ascent = metrics.m_ascent;
+ result.m_descent = metrics.m_descent;
+ result.m_linegap = metrics.m_linegap;
+
+ return result;
+ }
+
RenderedFont *FontRendererImpl::RenderFont(IGpFont *font, int size, bool aa, FontHacks fontHacks)
{
diff --git a/PortabilityLayer/MenuManager.cpp b/PortabilityLayer/MenuManager.cpp
index 39d2dd2..4782f2c 100644
--- a/PortabilityLayer/MenuManager.cpp
+++ b/PortabilityLayer/MenuManager.cpp
@@ -209,8 +209,6 @@ namespace PortabilityLayer
static bool ItemIsSeparator(const Menu &menu, const MenuItem &item);
static const unsigned int kIconResID = 128;
- static const unsigned int kMenuFontSize = 12;
- static const unsigned int kTouchScreenMenuFontSize = 40;
static const unsigned int kMenuBarIconYOffset = 2;
static const unsigned int kMenuBarTextYOffset = 14;
static const unsigned int kTouchScreenMenuBarTextYOffset = 40;
@@ -235,6 +233,9 @@ namespace PortabilityLayer
static const int kMenuFontFlags = PortabilityLayer::FontFamilyFlag_Bold;
static const int kTouchScreenMenuFontFlags = PortabilityLayer::FontFamilyFlag_None;
+ static const FontPreset_t kMenuFontPreset = FontPresets::kSystem12Bold;
+ static const FontPreset_t kTouchScreenMenuFontPreset = FontPresets::kApplication40;
+
DrawSurface *m_menuBarGraf;
THandle
diff --git a/PortabilityLayer/RenderedFontCatalog.h b/PortabilityLayer/RenderedFontCatalog.h
new file mode 100644
index 0000000..0a4b869
--- /dev/null
+++ b/PortabilityLayer/RenderedFontCatalog.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "PLBigEndian.h"
+
+namespace PortabilityLayer
+{
+ struct RenderedFontCatalogHeader
+ {
+ static const int kVersion = 1;
+
+ BEUInt32_t m_version;
+ BEUInt32_t m_pathsOffset;
+ BEUInt16_t m_numPaths;
+ BEUInt16_t m_numRFonts;
+ };
+
+ struct RenderedFontCatalogPathEntry
+ {
+ BEUInt16_t m_pathOffset;
+ BEUInt16_t m_pathSize;
+ };
+
+ struct RenderedFontCatalogRFontEntry
+ {
+ uint8_t m_pathIndex;
+ uint8_t m_hacks;
+ uint8_t m_fontSize;
+ uint8_t m_isAA;
+ };
+}
diff --git a/PortabilityLayer/WindowManager.cpp b/PortabilityLayer/WindowManager.cpp
index ca5a65e..582e78a 100644
--- a/PortabilityLayer/WindowManager.cpp
+++ b/PortabilityLayer/WindowManager.cpp
@@ -474,7 +474,7 @@ namespace PortabilityLayer
if (window->GetStyleFlags() & WindowStyleFlags::kCloseBox)
RenderChromeCloseBox(surface, rect, false);
- PortabilityLayer::RenderedFont *sysFont = GetSystemFont(12, PortabilityLayer::FontFamilyFlags::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *sysFont = GetFont(FontPresets::kSystem12Bold);
int32_t ascender = sysFont->GetMetrics().m_ascent;
const PLPasStr titlePStr = window->GetTitle().ToShortStr();
@@ -593,7 +593,7 @@ namespace PortabilityLayer
if (window->GetStyleFlags() & WindowStyleFlags::kCloseBox)
RenderChromeCloseBox(surface, rect, false);
- PortabilityLayer::RenderedFont *appFont = GetApplicationFont(10, PortabilityLayer::FontFamilyFlags::FontFamilyFlag_Bold, true);
+ PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication10Bold);
int32_t ascender = appFont->GetMetrics().m_ascent;
const PLPasStr titlePStr = window->GetTitle().ToShortStr();
diff --git a/ReleasePackageInstaller/Product.wxs b/ReleasePackageInstaller/Product.wxs
index b29c992..8d7a1fb 100644
--- a/ReleasePackageInstaller/Product.wxs
+++ b/ReleasePackageInstaller/Product.wxs
@@ -34,7 +34,6 @@
-
@@ -84,6 +83,9 @@
+
+
+