diff --git a/Aerofoil/GpMain_Win32.cpp b/Aerofoil/GpMain_Win32.cpp index 9df8298..3f7c04b 100644 --- a/Aerofoil/GpMain_Win32.cpp +++ b/Aerofoil/GpMain_Win32.cpp @@ -28,7 +28,7 @@ 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) PortabilityLayer::HostFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &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) { diff --git a/GpApp/About.cpp b/GpApp/About.cpp index d636836..ea52f68 100644 --- a/GpApp/About.cpp +++ b/GpApp/About.cpp @@ -27,7 +27,7 @@ #include "GpBuildVersion.h" #include "HostSystemServices.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" +#include "GpRenderedFontMetrics.h" #include "ResolveCachingColor.h" #include "ResourceManager.h" #include "ScanlineMask.h" diff --git a/GpApp/Banner.cpp b/GpApp/Banner.cpp index 81f3344..1c8eb85 100644 --- a/GpApp/Banner.cpp +++ b/GpApp/Banner.cpp @@ -15,7 +15,7 @@ #include "MainWindow.h" #include "RectUtils.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" +#include "GpRenderedFontMetrics.h" #include "ResolveCachingColor.h" #include "Room.h" #include "Utilities.h" diff --git a/GpApp/DialogUtils.cpp b/GpApp/DialogUtils.cpp index a7fd47f..335c890 100644 --- a/GpApp/DialogUtils.cpp +++ b/GpApp/DialogUtils.cpp @@ -19,7 +19,7 @@ #include "ResourceManager.h" #include "ResolveCachingColor.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" +#include "GpRenderedFontMetrics.h" #include diff --git a/GpApp/GpAppInterface.cpp b/GpApp/GpAppInterface.cpp index 45345b1..bed6391 100644 --- a/GpApp/GpAppInterface.cpp +++ b/GpApp/GpAppInterface.cpp @@ -26,7 +26,7 @@ public: void PL_HostSystemServices_SetInstance(PortabilityLayer::HostSystemServices *instance) override; void PL_HostAudioDriver_SetInstance(IGpAudioDriver *instance) override; void PL_HostLogDriver_SetInstance(IGpLogDriver *instance) override; - void PL_HostFontHandler_SetInstance(PortabilityLayer::HostFontHandler *instance) override; + void PL_HostFontHandler_SetInstance(IGpFontHandler *instance) override; void PL_HostVOSEventQueue_SetInstance(PortabilityLayer::HostVOSEventQueue *instance) override; void PL_InstallHostSuspendHook(PortabilityLayer::HostSuspendHook_t hook, void *context) override; bool PL_AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY) override; @@ -79,7 +79,7 @@ void GpAppInterfaceImpl::PL_HostInputDriver_SetInstances(IGpInputDriver *const* PortabilityLayer::HostInputDriver::SetInstances(instances, numInstances); } -void GpAppInterfaceImpl::PL_HostFontHandler_SetInstance(PortabilityLayer::HostFontHandler *instance) +void GpAppInterfaceImpl::PL_HostFontHandler_SetInstance(IGpFontHandler *instance) { PortabilityLayer::HostFontHandler::SetInstance(instance); } diff --git a/GpCommon/GpFontHandler.h b/GpCommon/GpFontHandler.h new file mode 100644 index 0000000..c7cd345 --- /dev/null +++ b/GpCommon/GpFontHandler.h @@ -0,0 +1,12 @@ +#pragma once + +class GpIOStream; +struct IGpFont; + +struct IGpFontHandler +{ + virtual void Shutdown() = 0; + + virtual IGpFont *LoadFont(GpIOStream *stream) = 0; + virtual bool KeepStreamOpen() const = 0; +}; diff --git a/GpCommon/GpFontHandlerProperties.h b/GpCommon/GpFontHandlerProperties.h index e5733da..2ca1355 100644 --- a/GpCommon/GpFontHandlerProperties.h +++ b/GpCommon/GpFontHandlerProperties.h @@ -4,5 +4,5 @@ struct GpFontHandlerProperties { - EGpFontHandlerType m_type; + EGpFontHandlerType m_type; }; diff --git a/GpCommon/GpRenderedFontMetrics.h b/GpCommon/GpRenderedFontMetrics.h new file mode 100644 index 0000000..2896473 --- /dev/null +++ b/GpCommon/GpRenderedFontMetrics.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +struct GpRenderedFontMetrics +{ + int32_t m_ascent; + int32_t m_descent; + int32_t m_linegap; +}; diff --git a/GpCommon/GpRenderedGlyphMetrics.h b/GpCommon/GpRenderedGlyphMetrics.h new file mode 100644 index 0000000..b797cc5 --- /dev/null +++ b/GpCommon/GpRenderedGlyphMetrics.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +struct GpRenderedGlyphMetrics +{ + size_t m_glyphDataPitch; + + uint32_t m_glyphWidth; + uint32_t m_glyphHeight; + + int16_t m_bearingX; + int16_t m_bearingY; + int16_t m_advanceX; +}; diff --git a/GpCommon/IGpFont.h b/GpCommon/IGpFont.h new file mode 100644 index 0000000..a1f8157 --- /dev/null +++ b/GpCommon/IGpFont.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +struct IGpFontRenderedGlyph; +struct GpRenderedFontMetrics; + +struct IGpFont +{ + virtual void Destroy() = 0; + virtual IGpFontRenderedGlyph *Render(uint32_t unicodeCodePoint, unsigned int size, bool aa) = 0; + virtual bool GetLineSpacing(unsigned int size, int32_t &outSpacing) = 0; +}; diff --git a/GpCommon/IGpFontHandler.h b/GpCommon/IGpFontHandler.h new file mode 100644 index 0000000..c7cd345 --- /dev/null +++ b/GpCommon/IGpFontHandler.h @@ -0,0 +1,12 @@ +#pragma once + +class GpIOStream; +struct IGpFont; + +struct IGpFontHandler +{ + virtual void Shutdown() = 0; + + virtual IGpFont *LoadFont(GpIOStream *stream) = 0; + virtual bool KeepStreamOpen() const = 0; +}; diff --git a/GpCommon/IGpFontRenderedGlyph.h b/GpCommon/IGpFontRenderedGlyph.h new file mode 100644 index 0000000..cec1682 --- /dev/null +++ b/GpCommon/IGpFontRenderedGlyph.h @@ -0,0 +1,10 @@ +#pragma once + +struct GpRenderedGlyphMetrics; + +struct IGpFontRenderedGlyph +{ + virtual const GpRenderedGlyphMetrics &GetMetrics() const = 0; + virtual const void *GetData() const = 0; + virtual void Destroy() = 0; +}; diff --git a/GpFontHandler_FreeType2/GpFontHandler_FreeType2.cpp b/GpFontHandler_FreeType2/GpFontHandler_FreeType2.cpp index 1abb581..73ab31e 100644 --- a/GpFontHandler_FreeType2/GpFontHandler_FreeType2.cpp +++ b/GpFontHandler_FreeType2/GpFontHandler_FreeType2.cpp @@ -3,9 +3,10 @@ #include "CoreDefs.h" #include "GpIOStream.h" -#include "HostFont.h" -#include "HostFontRenderedGlyph.h" -#include "RenderedGlyphMetrics.h" +#include "IGpFont.h" +#include "IGpFontRenderedGlyph.h" +#include "GpRenderedGlyphMetrics.h" +#include "IGpFontHandler.h" #include #include FT_FREETYPE_H @@ -16,30 +17,30 @@ #include #include -class GpFontRenderedGlyph_FreeType2 final : public PortabilityLayer::HostFontRenderedGlyph +class GpFontRenderedGlyph_FreeType2 final : public IGpFontRenderedGlyph { public: - const PortabilityLayer::RenderedGlyphMetrics &GetMetrics() const override; + const GpRenderedGlyphMetrics &GetMetrics() const override; const void *GetData() const override; void Destroy() override; - static GpFontRenderedGlyph_FreeType2 *Create(size_t dataSize, const PortabilityLayer::RenderedGlyphMetrics &metrics); + static GpFontRenderedGlyph_FreeType2 *Create(size_t dataSize, const GpRenderedGlyphMetrics &metrics); void *GetMutableData(); private: - GpFontRenderedGlyph_FreeType2(void *data, const PortabilityLayer::RenderedGlyphMetrics &metrics); + GpFontRenderedGlyph_FreeType2(void *data, const GpRenderedGlyphMetrics &metrics); ~GpFontRenderedGlyph_FreeType2(); void *m_data; - PortabilityLayer::RenderedGlyphMetrics m_metrics; + GpRenderedGlyphMetrics m_metrics; }; -class GpFont_FreeType2 final : public PortabilityLayer::HostFont +class GpFont_FreeType2 final : public IGpFont { public: void Destroy() override; - GpFontRenderedGlyph_FreeType2 *Render(uint32_t unicodeCodePoint, unsigned int size, bool aa) override; + IGpFontRenderedGlyph *Render(uint32_t unicodeCodePoint, unsigned int size, bool aa) override; bool GetLineSpacing(unsigned int size, int32_t &outSpacing) override; static GpFont_FreeType2 *Create(const FT_StreamRec_ &streamRec, GpIOStream *stream); @@ -56,7 +57,7 @@ private: unsigned int m_currentSize; }; -const PortabilityLayer::RenderedGlyphMetrics &GpFontRenderedGlyph_FreeType2::GetMetrics() const +const GpRenderedGlyphMetrics &GpFontRenderedGlyph_FreeType2::GetMetrics() const { return m_metrics; } @@ -72,7 +73,7 @@ void GpFontRenderedGlyph_FreeType2::Destroy() free(this); } -GpFontRenderedGlyph_FreeType2 *GpFontRenderedGlyph_FreeType2::Create(size_t dataSize, const PortabilityLayer::RenderedGlyphMetrics &metrics) +GpFontRenderedGlyph_FreeType2 *GpFontRenderedGlyph_FreeType2::Create(size_t dataSize, const GpRenderedGlyphMetrics &metrics) { size_t alignedPrefixSize = (sizeof(GpFontRenderedGlyph_FreeType2) + GP_SYSTEM_MEMORY_ALIGNMENT - 1); alignedPrefixSize -= alignedPrefixSize % GP_SYSTEM_MEMORY_ALIGNMENT; @@ -90,7 +91,7 @@ void *GpFontRenderedGlyph_FreeType2::GetMutableData() } -GpFontRenderedGlyph_FreeType2::GpFontRenderedGlyph_FreeType2(void *data, const PortabilityLayer::RenderedGlyphMetrics &metrics) +GpFontRenderedGlyph_FreeType2::GpFontRenderedGlyph_FreeType2(void *data, const GpRenderedGlyphMetrics &metrics) : m_metrics(metrics) , m_data(data) { @@ -106,7 +107,7 @@ void GpFont_FreeType2::Destroy() free(this); } -GpFontRenderedGlyph_FreeType2 *GpFont_FreeType2::Render(uint32_t unicodeCodePoint, unsigned int size, bool aa) +IGpFontRenderedGlyph *GpFont_FreeType2::Render(uint32_t unicodeCodePoint, unsigned int size, bool aa) { if (m_currentSize != size) { @@ -154,7 +155,7 @@ GpFontRenderedGlyph_FreeType2 *GpFont_FreeType2::Render(uint32_t unicodeCodePoin return nullptr; // This should never happen } - PortabilityLayer::RenderedGlyphMetrics metrics; + GpRenderedGlyphMetrics metrics; memset(&metrics, 0, sizeof(metrics)); metrics.m_bearingX = glyph->metrics.horiBearingX / 64; @@ -303,7 +304,7 @@ GpFontHandler_FreeType2 *GpFontHandler_FreeType2::Create() return fh; } -PortabilityLayer::HostFont *GpFontHandler_FreeType2::LoadFont(GpIOStream *stream) +IGpFont *GpFontHandler_FreeType2::LoadFont(GpIOStream *stream) { FT_StreamRec_ ftStream; memset(&ftStream, 0, sizeof(ftStream)); @@ -424,7 +425,7 @@ bool GpFontHandler_FreeType2::Init() return true; } -extern "C" __declspec(dllexport) PortabilityLayer::HostFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties) +extern "C" __declspec(dllexport) IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties) { return GpFontHandler_FreeType2::Create(); } diff --git a/GpFontHandler_FreeType2/GpFontHandler_FreeType2.h b/GpFontHandler_FreeType2/GpFontHandler_FreeType2.h index 1aed4d3..3d5c033 100644 --- a/GpFontHandler_FreeType2/GpFontHandler_FreeType2.h +++ b/GpFontHandler_FreeType2/GpFontHandler_FreeType2.h @@ -1,6 +1,6 @@ #pragma once -#include "HostFontHandler.h" +#include "IGpFontHandler.h" #include #include FT_SYSTEM_H @@ -13,10 +13,10 @@ namespace PortabilityLayer class HostFont; } -class GpFontHandler_FreeType2 final : public PortabilityLayer::HostFontHandler +class GpFontHandler_FreeType2 final : public IGpFontHandler { public: - PortabilityLayer::HostFont *LoadFont(GpIOStream *stream) override; + IGpFont *LoadFont(GpIOStream *stream) override; void Shutdown() override; bool KeepStreamOpen() const override; diff --git a/GpFontHandler_FreeType2/GpFontHandler_FreeType2.vcxproj b/GpFontHandler_FreeType2/GpFontHandler_FreeType2.vcxproj index 4c94a1b..eab02b2 100644 --- a/GpFontHandler_FreeType2/GpFontHandler_FreeType2.vcxproj +++ b/GpFontHandler_FreeType2/GpFontHandler_FreeType2.vcxproj @@ -58,7 +58,6 @@ - @@ -66,7 +65,6 @@ - @@ -74,7 +72,6 @@ - @@ -82,7 +79,6 @@ - diff --git a/GpShell/GpAppEnvironment.cpp b/GpShell/GpAppEnvironment.cpp index a8ce647..286c6b9 100644 --- a/GpShell/GpAppEnvironment.cpp +++ b/GpShell/GpAppEnvironment.cpp @@ -115,7 +115,7 @@ void GpAppEnvironment::SetInputDrivers(IGpInputDriver *const* inputDrivers, size m_numInputDrivers = numDrivers; } -void GpAppEnvironment::SetFontHandler(PortabilityLayer::HostFontHandler *fontHandler) +void GpAppEnvironment::SetFontHandler(IGpFontHandler *fontHandler) { m_fontHandler = fontHandler; } diff --git a/GpShell/GpAppEnvironment.h b/GpShell/GpAppEnvironment.h index a4f8593..841cea3 100644 --- a/GpShell/GpAppEnvironment.h +++ b/GpShell/GpAppEnvironment.h @@ -9,7 +9,6 @@ namespace PortabilityLayer { union HostSuspendCallArgument; - class HostFontHandler; class HostVOSEventQueue; } @@ -17,6 +16,7 @@ struct IGpDisplayDriver; struct IGpAudioDriver; struct IGpInputDriver; struct IGpFiber; +struct IGpFontHandler; class GpAppEnvironment { @@ -33,7 +33,7 @@ public: void SetDisplayDriver(IGpDisplayDriver *displayDriver); void SetAudioDriver(IGpAudioDriver *audioDriver); void SetInputDrivers(IGpInputDriver *const* inputDrivers, size_t numDrivers); - void SetFontHandler(PortabilityLayer::HostFontHandler *fontHandler); + void SetFontHandler(IGpFontHandler *fontHandler); void SetVOSEventQueue(GpVOSEventQueue *eventQueue); private: @@ -59,7 +59,7 @@ private: IGpDisplayDriver *m_displayDriver; IGpAudioDriver *m_audioDriver; IGpInputDriver *const* m_inputDrivers; - PortabilityLayer::HostFontHandler *m_fontHandler; + IGpFontHandler *m_fontHandler; GpVOSEventQueue *m_vosEventQueue; IGpFiber *m_applicationFiber; IGpFiber *m_vosFiber; diff --git a/GpShell/GpFontHandlerFactory.cpp b/GpShell/GpFontHandlerFactory.cpp index c34d587..3bbe801 100644 --- a/GpShell/GpFontHandlerFactory.cpp +++ b/GpShell/GpFontHandlerFactory.cpp @@ -3,7 +3,7 @@ #include -PortabilityLayer::HostFontHandler *GpFontHandlerFactory::CreateFontHandler(const GpFontHandlerProperties &properties) +IGpFontHandler *GpFontHandlerFactory::CreateFontHandler(const GpFontHandlerProperties &properties) { assert(properties.m_type < EGpFontHandlerType_Count); diff --git a/GpShell/GpFontHandlerFactory.h b/GpShell/GpFontHandlerFactory.h index eb03bea..bf35fec 100644 --- a/GpShell/GpFontHandlerFactory.h +++ b/GpShell/GpFontHandlerFactory.h @@ -2,19 +2,16 @@ #include "EGpFontHandlerType.h" -namespace PortabilityLayer -{ - class HostFontHandler; -} +struct IGpFontHandler; struct GpFontHandlerProperties; class GpFontHandlerFactory { public: - typedef PortabilityLayer::HostFontHandler *(*FactoryFunc_t)(const GpFontHandlerProperties &properties); + typedef IGpFontHandler *(*FactoryFunc_t)(const GpFontHandlerProperties &properties); - static PortabilityLayer::HostFontHandler *CreateFontHandler(const GpFontHandlerProperties &properties); + static IGpFontHandler *CreateFontHandler(const GpFontHandlerProperties &properties); static void RegisterFontHandlerFactory(EGpFontHandlerType type, FactoryFunc_t func); private: diff --git a/GpShell/GpMain.cpp b/GpShell/GpMain.cpp index 6a27450..51af6de 100644 --- a/GpShell/GpMain.cpp +++ b/GpShell/GpMain.cpp @@ -12,6 +12,7 @@ #include "GpAppEnvironment.h" #include "IGpAudioDriver.h" #include "IGpDisplayDriver.h" +#include "IGpFontHandler.h" #include "IGpInputDriver.h" #include @@ -105,7 +106,7 @@ int GpMain::Run() IGpDisplayDriver *displayDriver = GpDisplayDriverFactory::CreateDisplayDriver(ddProps); IGpAudioDriver *audioDriver = GpAudioDriverFactory::CreateAudioDriver(adProps); - PortabilityLayer::HostFontHandler *fontHandler = GpFontHandlerFactory::CreateFontHandler(fontProps); + IGpFontHandler *fontHandler = GpFontHandlerFactory::CreateFontHandler(fontProps); appEnvironment->Init(); diff --git a/PortabilityLayer/FontFamily.cpp b/PortabilityLayer/FontFamily.cpp index fd5d9c5..a30c763 100644 --- a/PortabilityLayer/FontFamily.cpp +++ b/PortabilityLayer/FontFamily.cpp @@ -1,8 +1,9 @@ #include "FontFamily.h" #include "GpIOStream.h" #include "HostFileSystem.h" +#include "IGpFontHandler.h" #include "HostFontHandler.h" -#include "HostFont.h" +#include "IGpFont.h" #include #include @@ -15,9 +16,9 @@ namespace PortabilityLayer if (!sysFontStream) return; - PortabilityLayer::HostFontHandler *fontHandler = PortabilityLayer::HostFontHandler::GetInstance(); + IGpFontHandler *fontHandler = PortabilityLayer::HostFontHandler::GetInstance(); - PortabilityLayer::HostFont *font = fontHandler->LoadFont(sysFontStream); + IGpFont *font = fontHandler->LoadFont(sysFontStream); if (!fontHandler->KeepStreamOpen()) sysFontStream->Close(); @@ -49,7 +50,7 @@ namespace PortabilityLayer return m_defaultVariation; } - PortabilityLayer::HostFont *FontFamily::GetFontForVariation(int variation) const + IGpFont *FontFamily::GetFontForVariation(int variation) const { return m_fonts[variation]; } @@ -88,7 +89,7 @@ namespace PortabilityLayer { for (unsigned int i = 0; i < kNumVariations; i++) { - if (PortabilityLayer::HostFont *font = m_fonts[i]) + if (IGpFont *font = m_fonts[i]) font->Destroy(); } } diff --git a/PortabilityLayer/FontFamily.h b/PortabilityLayer/FontFamily.h index 33c3aa4..fe5209c 100644 --- a/PortabilityLayer/FontFamily.h +++ b/PortabilityLayer/FontFamily.h @@ -4,11 +4,10 @@ #include class PLPasStr; +struct IGpFont; namespace PortabilityLayer { - class HostFont; - enum FontFamilyFlags { FontFamilyFlag_None = 0, @@ -27,15 +26,15 @@ namespace PortabilityLayer void SetDefaultVariation(int defaultVariation); int GetVariationForFlags(int variation) const; - PortabilityLayer::HostFont *GetFontForVariation(int variation) const; - PortabilityLayer::FontHacks GetHacksForVariation(int variation) const; + IGpFont *GetFontForVariation(int variation) const; + FontHacks GetHacksForVariation(int variation) const; static FontFamily *Create(); void Destroy(); private: - PortabilityLayer::FontHacks m_hacks[kNumVariations]; - PortabilityLayer::HostFont *m_fonts[kNumVariations]; + FontHacks m_hacks[kNumVariations]; + IGpFont *m_fonts[kNumVariations]; uint8_t m_defaultVariation; FontFamily(); diff --git a/PortabilityLayer/FontManager.cpp b/PortabilityLayer/FontManager.cpp index 1ee5bff..f929ecc 100644 --- a/PortabilityLayer/FontManager.cpp +++ b/PortabilityLayer/FontManager.cpp @@ -3,7 +3,7 @@ #include "FontRenderer.h" #include "HostFileSystem.h" -#include "HostFont.h" +#include "IGpFont.h" #include "HostFontHandler.h" #include "GpIOStream.h" #include "RenderedFont.h" @@ -24,7 +24,7 @@ namespace PortabilityLayer FontFamily *GetSystemFont(int textSize, int variationFlags) const override; FontFamily *GetApplicationFont(int textSize, int variationFlags) const override; - RenderedFont *GetRenderedFont(HostFont *font, int size, bool aa, FontHacks fontHacks) override; + RenderedFont *GetRenderedFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) override; RenderedFont *GetRenderedFontFromFamily(FontFamily *font, int size, bool aa, int flags) override; static FontManagerImpl *GetInstance(); @@ -35,7 +35,7 @@ namespace PortabilityLayer struct CachedRenderedFont { RenderedFont *m_rfont; - const HostFont *m_font; + const IGpFont *m_font; int m_size; uint32_t m_lastUsage; bool m_aa; @@ -80,7 +80,7 @@ namespace PortabilityLayer if (m_applicationFont) m_applicationFont->Destroy(); - HostFontHandler *hfh = HostFontHandler::GetInstance(); + IGpFontHandler *hfh = HostFontHandler::GetInstance(); if (m_systemFont) { @@ -110,7 +110,7 @@ namespace PortabilityLayer return m_applicationFont; } - RenderedFont *FontManagerImpl::GetRenderedFont(HostFont *font, int size, bool aa, FontHacks fontHacks) + RenderedFont *FontManagerImpl::GetRenderedFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) { CachedRenderedFont *newCacheSlot = &m_cachedRenderedFonts[0]; @@ -164,7 +164,7 @@ namespace PortabilityLayer { const int variation = fontFamily->GetVariationForFlags(flags); - PortabilityLayer::HostFont *hostFont = fontFamily->GetFontForVariation(variation); + IGpFont *hostFont = fontFamily->GetFontForVariation(variation); if (!hostFont) return nullptr; diff --git a/PortabilityLayer/FontManager.h b/PortabilityLayer/FontManager.h index 4d0c648..5e76714 100644 --- a/PortabilityLayer/FontManager.h +++ b/PortabilityLayer/FontManager.h @@ -2,10 +2,11 @@ #include "FontHacks.h" +struct IGpFont; + namespace PortabilityLayer { class FontFamily; - class HostFont; class RenderedFont; class FontManager @@ -17,7 +18,7 @@ namespace PortabilityLayer virtual FontFamily *GetSystemFont(int fontSize, int variationFlags) const = 0; virtual FontFamily *GetApplicationFont(int fontSize, int variationFlags) const = 0; - virtual RenderedFont *GetRenderedFont(HostFont *font, int size, bool aa, FontHacks fontHacks) = 0; + virtual RenderedFont *GetRenderedFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) = 0; virtual RenderedFont *GetRenderedFontFromFamily(FontFamily *fontFamily, int fontSize, bool aa, int flags) = 0; static FontManager *GetInstance(); diff --git a/PortabilityLayer/FontRenderer.cpp b/PortabilityLayer/FontRenderer.cpp index 6899941..f118404 100644 --- a/PortabilityLayer/FontRenderer.cpp +++ b/PortabilityLayer/FontRenderer.cpp @@ -1,14 +1,14 @@ #include "FontRenderer.h" #include "CoreDefs.h" -#include "HostFont.h" +#include "IGpFont.h" #include "HostFontHandler.h" -#include "HostFontRenderedGlyph.h" +#include "IGpFontRenderedGlyph.h" #include "MacRomanConversion.h" #include "PLPasStr.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" -#include "RenderedGlyphMetrics.h" +#include "GpRenderedFontMetrics.h" +#include "GpRenderedGlyphMetrics.h" #include #include @@ -20,15 +20,15 @@ namespace PortabilityLayer class RenderedFontImpl final : public RenderedFont { public: - bool GetGlyph(unsigned int character, const RenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const override; - const RenderedFontMetrics &GetMetrics() const override; + bool GetGlyph(unsigned int character, const GpRenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const override; + const GpRenderedFontMetrics &GetMetrics() const override; size_t MeasureString(const uint8_t *chars, size_t len) const override; bool IsAntiAliased() const override; void Destroy() override; - void SetCharData(unsigned int charID, const void *data, size_t dataOffset, const RenderedGlyphMetrics &metrics); - void SetFontMetrics(const RenderedFontMetrics &metrics); + void SetCharData(unsigned int charID, const void *data, size_t dataOffset, const GpRenderedGlyphMetrics &metrics); + void SetFontMetrics(const GpRenderedFontMetrics &metrics); static RenderedFontImpl *Create(size_t glyphDataSize, bool aa); @@ -37,9 +37,9 @@ namespace PortabilityLayer ~RenderedFontImpl(); size_t m_dataOffsets[256]; - RenderedGlyphMetrics m_glyphMetrics[256]; + GpRenderedGlyphMetrics m_glyphMetrics[256]; - RenderedFontMetrics m_fontMetrics; + GpRenderedFontMetrics m_fontMetrics; bool m_isAntiAliased; void *m_data; @@ -48,7 +48,7 @@ namespace PortabilityLayer class FontRendererImpl final : public FontRenderer { public: - RenderedFont *RenderFont(HostFont *font, int size, bool aa, FontHacks fontHacks) override; + RenderedFont *RenderFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) override; static FontRendererImpl *GetInstance(); @@ -56,7 +56,7 @@ namespace PortabilityLayer static FontRendererImpl ms_instance; }; - bool RenderedFontImpl::GetGlyph(unsigned int character, const RenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const + bool RenderedFontImpl::GetGlyph(unsigned int character, const GpRenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const { const size_t dataOffset = m_dataOffsets[character]; if (!dataOffset) @@ -68,7 +68,7 @@ namespace PortabilityLayer return true; } - const RenderedFontMetrics &RenderedFontImpl::GetMetrics() const + const GpRenderedFontMetrics &RenderedFontImpl::GetMetrics() const { return m_fontMetrics; } @@ -79,7 +79,7 @@ namespace PortabilityLayer for (size_t i = 0; i < len; i++) { - const RenderedGlyphMetrics &metrics = m_glyphMetrics[chars[i]]; + const GpRenderedGlyphMetrics &metrics = m_glyphMetrics[chars[i]]; measure += metrics.m_advanceX; } @@ -97,14 +97,14 @@ namespace PortabilityLayer free(this); } - void RenderedFontImpl::SetCharData(unsigned int charID, const void *data, size_t dataOffset, const RenderedGlyphMetrics &metrics) + void RenderedFontImpl::SetCharData(unsigned int charID, const void *data, size_t dataOffset, const GpRenderedGlyphMetrics &metrics) { m_dataOffsets[charID] = dataOffset; m_glyphMetrics[charID] = metrics; memcpy(static_cast(m_data) + dataOffset, data, metrics.m_glyphDataPitch * metrics.m_glyphHeight); } - void RenderedFontImpl::SetFontMetrics(const RenderedFontMetrics &metrics) + void RenderedFontImpl::SetFontMetrics(const GpRenderedFontMetrics &metrics) { m_fontMetrics = metrics; } @@ -141,7 +141,7 @@ namespace PortabilityLayer { } - RenderedFont *FontRendererImpl::RenderFont(HostFont *font, int size, bool aa, FontHacks fontHacks) + RenderedFont *FontRendererImpl::RenderFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) { const unsigned int numCharacters = 256; @@ -152,7 +152,7 @@ namespace PortabilityLayer if (!font->GetLineSpacing(size, lineSpacing)) return nullptr; - HostFontRenderedGlyph *glyphs[numCharacters]; + IGpFontRenderedGlyph *glyphs[numCharacters]; for (unsigned int i = 0; i < numCharacters; i++) glyphs[i] = nullptr; @@ -172,7 +172,7 @@ namespace PortabilityLayer { if (glyphs[i]) { - const RenderedGlyphMetrics &metrics = glyphs[i]->GetMetrics(); + const GpRenderedGlyphMetrics &metrics = glyphs[i]->GetMetrics(); glyphDataSize += metrics.m_glyphDataPitch * metrics.m_glyphHeight; } } @@ -187,9 +187,9 @@ namespace PortabilityLayer { if (glyphs[i]) { - HostFontRenderedGlyph *glyph = glyphs[i]; + IGpFontRenderedGlyph *glyph = glyphs[i]; - RenderedGlyphMetrics metrics = glyph->GetMetrics(); + GpRenderedGlyphMetrics metrics = glyph->GetMetrics(); const void *data = glyph->GetData(); if (fontHacks == FontHacks_Roboto && !aa) @@ -219,7 +219,7 @@ namespace PortabilityLayer } // Compute metrics - RenderedFontMetrics fontMetrics; + GpRenderedFontMetrics fontMetrics; fontMetrics.m_linegap = lineSpacing; fontMetrics.m_ascent = 0; fontMetrics.m_descent = 0; @@ -227,7 +227,7 @@ namespace PortabilityLayer bool measuredAnyGlyphs = false; for (char capChar = 'A'; capChar <= 'Z'; capChar++) { - const RenderedGlyphMetrics *glyphMetrics; + const GpRenderedGlyphMetrics *glyphMetrics; const void *glyphData; if (rfont->GetGlyph(static_cast(capChar), glyphMetrics, glyphData) && glyphMetrics != nullptr) { diff --git a/PortabilityLayer/FontRenderer.h b/PortabilityLayer/FontRenderer.h index 9718262..130226d 100644 --- a/PortabilityLayer/FontRenderer.h +++ b/PortabilityLayer/FontRenderer.h @@ -2,15 +2,16 @@ #include "FontHacks.h" +struct IGpFont; + namespace PortabilityLayer { class RenderedFont; - class HostFont; class FontRenderer { public: - virtual RenderedFont *RenderFont(HostFont *font, int size, bool aa, FontHacks fontHacks) = 0; + virtual RenderedFont *RenderFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) = 0; static FontRenderer *GetInstance(); }; diff --git a/PortabilityLayer/GpAppInterface.h b/PortabilityLayer/GpAppInterface.h index 1b0b518..e589e19 100644 --- a/PortabilityLayer/GpAppInterface.h +++ b/PortabilityLayer/GpAppInterface.h @@ -22,13 +22,13 @@ struct IGpAudioDriver; struct IGpLogDriver; struct IGpInputDriver; +struct IGpFontHandler; namespace PortabilityLayer { class HostFileSystem; class HostDisplayDriver; class HostSystemServices; - class HostFontHandler; class HostVOSEventQueue; } @@ -46,7 +46,7 @@ public: virtual void PL_HostLogDriver_SetInstance(IGpLogDriver *instance) = 0; virtual void PL_HostInputDriver_SetInstances(IGpInputDriver *const* instances, size_t numInstances) = 0; virtual void PL_HostSystemServices_SetInstance(PortabilityLayer::HostSystemServices *instance) = 0; - virtual void PL_HostFontHandler_SetInstance(PortabilityLayer::HostFontHandler *instance) = 0; + virtual void PL_HostFontHandler_SetInstance(IGpFontHandler *instance) = 0; virtual void PL_HostVOSEventQueue_SetInstance(PortabilityLayer::HostVOSEventQueue *instance) = 0; virtual void PL_InstallHostSuspendHook(PortabilityLayer::HostSuspendHook_t hook, void *context) = 0; diff --git a/PortabilityLayer/HostFont.h b/PortabilityLayer/HostFont.h deleted file mode 100644 index 596f292..0000000 --- a/PortabilityLayer/HostFont.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include - -namespace PortabilityLayer -{ - class HostFontRenderedGlyph; - struct RenderedFontMetrics; - - class HostFont - { - public: - virtual void Destroy() = 0; - virtual HostFontRenderedGlyph *Render(uint32_t unicodeCodePoint, unsigned int size, bool aa) = 0; - virtual bool GetLineSpacing(unsigned int size, int32_t &outSpacing) = 0; - }; -} diff --git a/PortabilityLayer/HostFontHandler.cpp b/PortabilityLayer/HostFontHandler.cpp index 55d74db..e0c0650 100644 --- a/PortabilityLayer/HostFontHandler.cpp +++ b/PortabilityLayer/HostFontHandler.cpp @@ -2,15 +2,15 @@ namespace PortabilityLayer { - void HostFontHandler::SetInstance(HostFontHandler *instance) + void HostFontHandler::SetInstance(IGpFontHandler *instance) { ms_instance = instance; } - HostFontHandler *HostFontHandler::GetInstance() + IGpFontHandler *HostFontHandler::GetInstance() { return ms_instance; } - HostFontHandler *HostFontHandler::ms_instance = nullptr; + IGpFontHandler *HostFontHandler::ms_instance = nullptr; } diff --git a/PortabilityLayer/HostFontHandler.h b/PortabilityLayer/HostFontHandler.h index 2e303fc..f0b3f4e 100644 --- a/PortabilityLayer/HostFontHandler.h +++ b/PortabilityLayer/HostFontHandler.h @@ -1,23 +1,17 @@ #pragma once class GpIOStream; +struct IGpFontHandler; namespace PortabilityLayer { - class HostFont; - class HostFontHandler { public: - virtual void Shutdown() = 0; - - virtual HostFont *LoadFont(GpIOStream *stream) = 0; - virtual bool KeepStreamOpen() const = 0; - - static void SetInstance(HostFontHandler *instance); - static HostFontHandler *GetInstance(); + static void SetInstance(IGpFontHandler *instance); + static IGpFontHandler *GetInstance(); private: - static HostFontHandler *ms_instance; + static IGpFontHandler *ms_instance; }; } diff --git a/PortabilityLayer/HostFontRenderedGlyph.h b/PortabilityLayer/HostFontRenderedGlyph.h deleted file mode 100644 index 8297a54..0000000 --- a/PortabilityLayer/HostFontRenderedGlyph.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -namespace PortabilityLayer -{ - struct RenderedGlyphMetrics; - - class HostFontRenderedGlyph - { - public: - virtual const RenderedGlyphMetrics &GetMetrics() const = 0; - virtual const void *GetData() const = 0; - virtual void Destroy() = 0; - }; -} diff --git a/PortabilityLayer/MenuManager.cpp b/PortabilityLayer/MenuManager.cpp index 38bfc2b..8240f4b 100644 --- a/PortabilityLayer/MenuManager.cpp +++ b/PortabilityLayer/MenuManager.cpp @@ -3,7 +3,7 @@ #include "FontFamily.h" #include "FontManager.h" #include "HostDisplayDriver.h" -#include "HostFont.h" +#include "IGpFont.h" #include "IGpDisplayDriver.h" #include "MemoryManager.h" #include "ResourceManager.h" diff --git a/PortabilityLayer/PLButtonWidget.cpp b/PortabilityLayer/PLButtonWidget.cpp index 4ef25c4..d253a43 100644 --- a/PortabilityLayer/PLButtonWidget.cpp +++ b/PortabilityLayer/PLButtonWidget.cpp @@ -7,7 +7,7 @@ #include "PLQDraw.h" #include "FontFamily.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" +#include "GpRenderedFontMetrics.h" #include "ResolveCachingColor.h" #include "SimpleGraphic.h" diff --git a/PortabilityLayer/PLEditboxWidget.cpp b/PortabilityLayer/PLEditboxWidget.cpp index 127ccc5..dcb5f81 100644 --- a/PortabilityLayer/PLEditboxWidget.cpp +++ b/PortabilityLayer/PLEditboxWidget.cpp @@ -6,7 +6,7 @@ #include "MacRomanConversion.h" #include "MemoryManager.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" +#include "GpRenderedFontMetrics.h" #include "PLKeyEncoding.h" #include "PLQDraw.h" #include "PLStandardColors.h" diff --git a/PortabilityLayer/PLLabelWidget.cpp b/PortabilityLayer/PLLabelWidget.cpp index fc4b107..9e7fc96 100644 --- a/PortabilityLayer/PLLabelWidget.cpp +++ b/PortabilityLayer/PLLabelWidget.cpp @@ -3,7 +3,7 @@ #include "FontFamily.h" #include "PLStandardColors.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" +#include "GpRenderedFontMetrics.h" #include "ResolveCachingColor.h" #include diff --git a/PortabilityLayer/PLPopupMenuWidget.cpp b/PortabilityLayer/PLPopupMenuWidget.cpp index 58b9595..48beb97 100644 --- a/PortabilityLayer/PLPopupMenuWidget.cpp +++ b/PortabilityLayer/PLPopupMenuWidget.cpp @@ -7,7 +7,7 @@ #include "PLStandardColors.h" #include "PLTimeTaggedVOSEvent.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" +#include "GpRenderedFontMetrics.h" #include "ResolveCachingColor.h" #include "FontFamily.h" #include "Vec2i.h" diff --git a/PortabilityLayer/PLQDraw.cpp b/PortabilityLayer/PLQDraw.cpp index 9ce169e..c726b9e 100644 --- a/PortabilityLayer/PLQDraw.cpp +++ b/PortabilityLayer/PLQDraw.cpp @@ -13,8 +13,8 @@ #include "PLPasStr.h" #include "PLStandardColors.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" -#include "RenderedGlyphMetrics.h" +#include "GpRenderedFontMetrics.h" +#include "GpRenderedGlyphMetrics.h" #include "Rect2i.h" #include "ResourceManager.h" #include "ResTypeID.h" @@ -240,7 +240,7 @@ static void DrawGlyph(PixMap *pixMap, const Rect &rect, const Point &penPos, con { assert(rect.IsValid()); - const PortabilityLayer::RenderedGlyphMetrics *metrics; + const GpRenderedGlyphMetrics *metrics; const void *data; if (!rfont->GetGlyph(character, metrics, data)) return; diff --git a/PortabilityLayer/RenderedFont.h b/PortabilityLayer/RenderedFont.h index 04dcd8f..3eca5c1 100644 --- a/PortabilityLayer/RenderedFont.h +++ b/PortabilityLayer/RenderedFont.h @@ -3,18 +3,16 @@ #include class PLPasStr; +struct GpRenderedFontMetrics; +struct GpRenderedGlyphMetrics; namespace PortabilityLayer { - struct RenderedFontMetrics; - - struct RenderedGlyphMetrics; - class RenderedFont { public: - virtual bool GetGlyph(unsigned int character, const RenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const = 0; - virtual const RenderedFontMetrics &GetMetrics() const = 0; + virtual bool GetGlyph(unsigned int character, const GpRenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const = 0; + virtual const GpRenderedFontMetrics &GetMetrics() const = 0; virtual size_t MeasureString(const uint8_t *chars, size_t len) const = 0; virtual bool IsAntiAliased() const = 0; @@ -28,11 +26,11 @@ namespace PortabilityLayer #include "PLPasStr.h" inline size_t PortabilityLayer::RenderedFont::MeasurePStr(const PLPasStr &pstr) const -{ +{ return this->MeasureString(pstr.UChars(), pstr.Length()); } inline size_t PortabilityLayer::RenderedFont::MeasureCharStr(const char *str, size_t len) const -{ +{ return this->MeasureString(reinterpret_cast(str), len); } diff --git a/PortabilityLayer/RenderedFontMetrics.h b/PortabilityLayer/RenderedFontMetrics.h deleted file mode 100644 index e9d84c3..0000000 --- a/PortabilityLayer/RenderedFontMetrics.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -namespace PortabilityLayer -{ - struct RenderedFontMetrics - { - int32_t m_ascent; - int32_t m_descent; - int32_t m_linegap; - }; -} diff --git a/PortabilityLayer/RenderedGlyphMetrics.h b/PortabilityLayer/RenderedGlyphMetrics.h deleted file mode 100644 index dac0a69..0000000 --- a/PortabilityLayer/RenderedGlyphMetrics.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -namespace PortabilityLayer -{ - struct RenderedGlyphMetrics - { - size_t m_glyphDataPitch; - - uint32_t m_glyphWidth; - uint32_t m_glyphHeight; - - int16_t m_bearingX; - int16_t m_bearingY; - int16_t m_advanceX; - }; -} diff --git a/PortabilityLayer/TextPlacer.cpp b/PortabilityLayer/TextPlacer.cpp index 941ce3d..516e8c1 100644 --- a/PortabilityLayer/TextPlacer.cpp +++ b/PortabilityLayer/TextPlacer.cpp @@ -1,8 +1,8 @@ #include "TextPlacer.h" #include "PLPasStr.h" -#include "RenderedFontMetrics.h" -#include "RenderedGlyphMetrics.h" +#include "GpRenderedFontMetrics.h" +#include "GpRenderedGlyphMetrics.h" #include "RenderedFont.h" #include @@ -63,7 +63,7 @@ namespace PortabilityLayer if (character == '\r') break; - const PortabilityLayer::RenderedGlyphMetrics *metrics = nullptr; + const GpRenderedGlyphMetrics *metrics = nullptr; const void *glyphData = nullptr; if (m_rfont->GetGlyph(m_chars[i], metrics, glyphData)) spanWidth += metrics->m_advanceX; @@ -72,7 +72,7 @@ namespace PortabilityLayer } else { - const PortabilityLayer::RenderedGlyphMetrics *metrics = nullptr; + const GpRenderedGlyphMetrics *metrics = nullptr; const void *glyphData = nullptr; if (!m_rfont->GetGlyph(m_chars[i], metrics, glyphData)) { @@ -116,7 +116,7 @@ namespace PortabilityLayer outCharacteristics.m_characterIndex = m_currentStartChar + m_emitOffset; outCharacteristics.m_character = character; - const PortabilityLayer::RenderedGlyphMetrics *metrics; + const GpRenderedGlyphMetrics *metrics; const void *data; if (!m_rfont->GetGlyph(character, metrics, data)) { diff --git a/PortabilityLayer/TextPlacer.h b/PortabilityLayer/TextPlacer.h index 93c8b99..49f3a77 100644 --- a/PortabilityLayer/TextPlacer.h +++ b/PortabilityLayer/TextPlacer.h @@ -2,26 +2,26 @@ #include "Vec2i.h" -class PLPasStr; +class PLPasStr; +struct GpRenderedGlyphMetrics; namespace PortabilityLayer { class RenderedFont; - struct RenderedGlyphMetrics; struct GlyphPlacementCharacteristics { bool m_haveGlyph; bool m_isParaStart; // Character is the first character in the paragraph bool m_isParaEnd; // Character is the last character in the paragraph - const RenderedGlyphMetrics *m_glyphMetrics; // Glyph metrics + const GpRenderedGlyphMetrics *m_glyphMetrics; // Glyph metrics const void *m_glyphData; // Glyph data Vec2i m_glyphStartPos; // Glyph start position Vec2i m_glyphEndPos; // Glyph end position unsigned int m_character; // Character code size_t m_characterIndex; // Index in the input string }; - + class TextPlacer { public: diff --git a/PortabilityLayer/WindowManager.cpp b/PortabilityLayer/WindowManager.cpp index c1da30d..4d26a76 100644 --- a/PortabilityLayer/WindowManager.cpp +++ b/PortabilityLayer/WindowManager.cpp @@ -17,7 +17,7 @@ #include "PLTimeTaggedVOSEvent.h" #include "Rect2i.h" #include "RenderedFont.h" -#include "RenderedFontMetrics.h" +#include "GpRenderedFontMetrics.h" #include "ResolveCachingColor.h" #include "Vec2i.h" #include "WindowDef.h"