mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 06:53:43 +00:00
Specialize font paths for preinstalled font selection instead
This commit is contained in:
@@ -283,11 +283,6 @@ bool GpSystemServices_Win32::AreFontResourcesSeekable() const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GpSystemServices_Win32::IsUsingPreinstalledFonts() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IGpClipboardContents *GpSystemServices_Win32::GetClipboardContents() const
|
||||
{
|
||||
IGpClipboardContents *cbObject = nullptr;
|
||||
|
@@ -38,7 +38,6 @@ public:
|
||||
void SetTextInputEnabled(bool isEnabled) override;
|
||||
bool IsTextInputEnabled() const override;
|
||||
bool AreFontResourcesSeekable() const override;
|
||||
bool IsUsingPreinstalledFonts() const override;
|
||||
IGpClipboardContents *GetClipboardContents() const override;
|
||||
void SetClipboardContents(IGpClipboardContents *contents) override;
|
||||
|
||||
|
@@ -104,11 +104,6 @@ bool GpSystemServices_Android::AreFontResourcesSeekable() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GpSystemServices_Android::IsUsingPreinstalledFonts() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IGpClipboardContents *GpSystemServices_Android::GetClipboardContents() const
|
||||
{
|
||||
return nullptr;
|
||||
|
@@ -19,7 +19,6 @@ public:
|
||||
void SetTextInputEnabled(bool isEnabled) override;
|
||||
bool IsTextInputEnabled() const override;
|
||||
bool AreFontResourcesSeekable() const override;
|
||||
bool IsUsingPreinstalledFonts() const override;
|
||||
IGpClipboardContents *GetClipboardContents() const override;
|
||||
void SetClipboardContents(IGpClipboardContents *contents) override;
|
||||
|
||||
|
@@ -185,11 +185,6 @@ bool GpSystemServices_Web::AreFontResourcesSeekable() const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GpSystemServices_Web::IsUsingPreinstalledFonts() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IGpClipboardContents *GpSystemServices_Web::GetClipboardContents() const
|
||||
{
|
||||
return m_clipboardContents;
|
||||
|
@@ -22,7 +22,6 @@ public:
|
||||
void SetTextInputEnabled(bool isEnabled) override;
|
||||
bool IsTextInputEnabled() const override;
|
||||
bool AreFontResourcesSeekable() const override;
|
||||
bool IsUsingPreinstalledFonts() const override;
|
||||
IGpClipboardContents *GetClipboardContents() const override;
|
||||
void SetClipboardContents(IGpClipboardContents *contents) override;
|
||||
int64_t GetTime() const override;
|
||||
|
@@ -113,11 +113,6 @@ bool GpSystemServices_X::AreFontResourcesSeekable() const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GpSystemServices_X::IsUsingPreinstalledFonts() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IGpClipboardContents *GpSystemServices_X::GetClipboardContents() const
|
||||
{
|
||||
return m_clipboardContents;
|
||||
|
@@ -22,7 +22,6 @@ public:
|
||||
void SetTextInputEnabled(bool isEnabled) override;
|
||||
bool IsTextInputEnabled() const override;
|
||||
bool AreFontResourcesSeekable() const override;
|
||||
bool IsUsingPreinstalledFonts() const override;
|
||||
IGpClipboardContents *GetClipboardContents() const override;
|
||||
void SetClipboardContents(IGpClipboardContents *contents) override;
|
||||
|
||||
|
@@ -201,8 +201,10 @@ int toolMain(int argc, const char **argv)
|
||||
int variation = fontFamily->GetVariationForFlags(flags);
|
||||
|
||||
PortabilityLayer::FontHacks hacks;
|
||||
PortabilityLayer::VirtualDirectory_t vDir;
|
||||
const char *path = nullptr;
|
||||
fontFamily->GetFontSpec(variation, hacks, path);
|
||||
int typeFaceIndex = 0;
|
||||
fontFamily->GetFontSpec(variation, hacks, vDir, path, typeFaceIndex);
|
||||
|
||||
KnownFontSpec spec(path, size, aa, hacks);
|
||||
|
||||
@@ -218,7 +220,7 @@ int toolMain(int argc, const char **argv)
|
||||
{
|
||||
PortabilityLayer::CFileStream stream(fontFile);
|
||||
|
||||
IGpFont *font = ft2Handler->LoadFont(&stream);
|
||||
IGpFont *font = ft2Handler->LoadFont(&stream, typeFaceIndex);
|
||||
if (!ft2Handler->KeepStreamOpen())
|
||||
stream.Close();
|
||||
|
||||
|
@@ -7,6 +7,6 @@ struct IGpFontHandler
|
||||
{
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
virtual IGpFont *LoadFont(GpIOStream *stream) = 0;
|
||||
virtual IGpFont *LoadFont(GpIOStream *stream, int typeFaceIndex) = 0;
|
||||
virtual bool KeepStreamOpen() const = 0;
|
||||
};
|
||||
|
@@ -36,7 +36,6 @@ public:
|
||||
virtual void SetTextInputEnabled(bool isEnabled) = 0;
|
||||
virtual bool IsTextInputEnabled() const = 0;
|
||||
virtual bool AreFontResourcesSeekable() const = 0;
|
||||
virtual bool IsUsingPreinstalledFonts() const = 0;
|
||||
virtual IGpClipboardContents *GetClipboardContents() const = 0;
|
||||
virtual void SetClipboardContents(IGpClipboardContents *contents) = 0;
|
||||
};
|
||||
|
@@ -45,7 +45,7 @@ public:
|
||||
|
||||
static GpFont_FreeType2 *Create(const FT_StreamRec_ &streamRec, GpIOStream *stream);
|
||||
|
||||
bool FTLoad(const FT_Library &library);
|
||||
bool FTLoad(const FT_Library &library, int typeFaceIndex);
|
||||
|
||||
private:
|
||||
explicit GpFont_FreeType2(const FT_StreamRec_ &streamRec, GpIOStream *stream);
|
||||
@@ -257,14 +257,14 @@ GpFont_FreeType2 *GpFont_FreeType2::Create(const FT_StreamRec_ &streamRec, GpIOS
|
||||
return new (storage) GpFont_FreeType2(streamRec, stream);
|
||||
}
|
||||
|
||||
bool GpFont_FreeType2::FTLoad(const FT_Library &library)
|
||||
bool GpFont_FreeType2::FTLoad(const FT_Library &library, int typeFaceIndex)
|
||||
{
|
||||
FT_Open_Args openArgs;
|
||||
memset(&openArgs, 0, sizeof(openArgs));
|
||||
openArgs.flags = FT_OPEN_STREAM;
|
||||
openArgs.stream = &m_ftStream;
|
||||
|
||||
FT_Error errorCode = FT_Open_Face(library, &openArgs, 0, &m_face);
|
||||
FT_Error errorCode = FT_Open_Face(library, &openArgs, typeFaceIndex, &m_face);
|
||||
if (errorCode != 0)
|
||||
return false;
|
||||
|
||||
@@ -304,7 +304,7 @@ GpFontHandler_FreeType2 *GpFontHandler_FreeType2::Create()
|
||||
return fh;
|
||||
}
|
||||
|
||||
IGpFont *GpFontHandler_FreeType2::LoadFont(GpIOStream *stream)
|
||||
IGpFont *GpFontHandler_FreeType2::LoadFont(GpIOStream *stream, int typeFaceIndex)
|
||||
{
|
||||
FT_StreamRec_ ftStream;
|
||||
memset(&ftStream, 0, sizeof(ftStream));
|
||||
@@ -321,7 +321,7 @@ IGpFont *GpFontHandler_FreeType2::LoadFont(GpIOStream *stream)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!font->FTLoad(m_library))
|
||||
if (!font->FTLoad(m_library, typeFaceIndex))
|
||||
{
|
||||
font->Destroy();
|
||||
return nullptr;
|
||||
|
@@ -16,7 +16,7 @@ namespace PortabilityLayer
|
||||
class GpFontHandler_FreeType2 final : public IGpFontHandler
|
||||
{
|
||||
public:
|
||||
IGpFont *LoadFont(GpIOStream *stream) override;
|
||||
IGpFont *LoadFont(GpIOStream *stream, int typeFaceIndex) override;
|
||||
void Shutdown() override;
|
||||
|
||||
bool KeepStreamOpen() const override;
|
||||
|
@@ -15,16 +15,20 @@
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
FontFamily::FontSpec::FontSpec()
|
||||
: m_fontPath(nullptr)
|
||||
: m_fontVDir(VirtualDirectories::kUnspecified)
|
||||
, m_fontPath(nullptr)
|
||||
, m_font(nullptr)
|
||||
, m_hacks(FontHacks_None)
|
||||
, m_typeFaceIndex(0)
|
||||
, m_isRegistered(false)
|
||||
{
|
||||
}
|
||||
|
||||
void FontFamily::AddFont(int flags, const char *path, FontHacks fontHacks)
|
||||
void FontFamily::AddFont(int flags, VirtualDirectory_t vDir, const char *path, int typeFaceIndex, FontHacks fontHacks)
|
||||
{
|
||||
m_fontSpecs[flags].m_fontVDir = vDir;
|
||||
m_fontSpecs[flags].m_fontPath = path;
|
||||
m_fontSpecs[flags].m_typeFaceIndex = typeFaceIndex;
|
||||
m_fontSpecs[flags].m_hacks = fontHacks;
|
||||
m_fontSpecs[flags].m_isRegistered = true;
|
||||
|
||||
@@ -55,7 +59,7 @@ namespace PortabilityLayer
|
||||
if (spec.m_font)
|
||||
return spec.m_font;
|
||||
|
||||
GpIOStream *sysFontStream = PLDrivers::GetFileSystem()->OpenFile(PortabilityLayer::VirtualDirectories::kFonts, spec.m_fontPath, false, GpFileCreationDispositions::kOpenExisting);
|
||||
GpIOStream *sysFontStream = PLDrivers::GetFileSystem()->OpenFile(spec.m_fontVDir, spec.m_fontPath, false, GpFileCreationDispositions::kOpenExisting);
|
||||
if (!sysFontStream)
|
||||
return nullptr;
|
||||
|
||||
@@ -93,7 +97,7 @@ namespace PortabilityLayer
|
||||
|
||||
IGpFontHandler *fontHandler = PLDrivers::GetFontHandler();
|
||||
|
||||
IGpFont *font = fontHandler->LoadFont(sysFontStream);
|
||||
IGpFont *font = fontHandler->LoadFont(sysFontStream, spec.m_typeFaceIndex);
|
||||
|
||||
if (!fontHandler->KeepStreamOpen())
|
||||
sysFontStream->Close();
|
||||
@@ -121,13 +125,16 @@ namespace PortabilityLayer
|
||||
return m_fontSpecs[variation].m_hacks;
|
||||
}
|
||||
|
||||
bool FontFamily::GetFontSpec(int variation, FontHacks &outHacks, const char *&outPath)
|
||||
bool FontFamily::GetFontSpec(int variation, FontHacks &outHacks, VirtualDirectory_t &outVDir, const char *&outPath, int &outTypeFaceIndex)
|
||||
{
|
||||
if (!m_fontSpecs[variation].m_isRegistered)
|
||||
const FontSpec &spec = m_fontSpecs[variation];
|
||||
if (!spec.m_isRegistered)
|
||||
return false;
|
||||
|
||||
outHacks = m_fontSpecs[variation].m_hacks;
|
||||
outPath = m_fontSpecs[variation].m_fontPath;
|
||||
outHacks = spec.m_hacks;
|
||||
outVDir = spec.m_fontVDir;
|
||||
outPath = spec.m_fontPath;
|
||||
outTypeFaceIndex = spec.m_typeFaceIndex;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "FontFamilyID.h"
|
||||
#include "FontHacks.h"
|
||||
#include "VirtualDirectory.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -24,9 +25,9 @@ namespace PortabilityLayer
|
||||
public:
|
||||
static const unsigned int kNumVariations = FontFamilyFlag_All + 1;
|
||||
|
||||
void AddFont(int flags, const char *path, FontHacks fontHacks);
|
||||
void AddFont(int flags, VirtualDirectory_t vDir, const char *path, int typeFaceIndex, FontHacks fontHacks);
|
||||
void SetDefaultVariation(int defaultVariation);
|
||||
bool GetFontSpec(int variation, FontHacks &outHacks, const char *&outPath);
|
||||
bool GetFontSpec(int variation, FontHacks &outHacks, VirtualDirectory_t &outVDir, const char *&outPath, int &outTypeFaceIndex);
|
||||
|
||||
int GetVariationForFlags(int flags) const;
|
||||
IGpFont *GetFontForVariation(int variation);
|
||||
@@ -47,7 +48,9 @@ namespace PortabilityLayer
|
||||
|
||||
IGpFont *m_font;
|
||||
FontHacks m_hacks;
|
||||
VirtualDirectory_t m_fontVDir;
|
||||
const char *m_fontPath;
|
||||
int m_typeFaceIndex;
|
||||
bool m_isRegistered;
|
||||
};
|
||||
|
||||
|
@@ -79,6 +79,8 @@ namespace PortabilityLayer
|
||||
PortabilityLayer::CompositeFile *m_fontArchiveFile;
|
||||
THandle<void> m_fontArchiveCatalogData;
|
||||
|
||||
bool m_hasPreinstalledFonts;
|
||||
|
||||
static FontManagerImpl ms_instance;
|
||||
static FontPreset ms_fontPresets[FontPresets::kCount];
|
||||
};
|
||||
@@ -89,19 +91,19 @@ namespace PortabilityLayer
|
||||
m_fontFamilies[static_cast<FontFamilyID_t>(i)] = FontFamily::Create(static_cast<FontFamilyID_t>(i));
|
||||
|
||||
if (m_fontFamilies[FontFamilyIDs::kSystem])
|
||||
m_fontFamilies[FontFamilyIDs::kSystem]->AddFont(FontFamilyFlag_None, "Fonts/OpenSans/OpenSans-ExtraBold.ttf", FontHacks_None);
|
||||
m_fontFamilies[FontFamilyIDs::kSystem]->AddFont(FontFamilyFlag_None, VirtualDirectories::kFonts, "Fonts/OpenSans/OpenSans-ExtraBold.ttf", 0, FontHacks_None);
|
||||
|
||||
if (m_fontFamilies[FontFamilyIDs::kApplication])
|
||||
{
|
||||
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);
|
||||
m_fontFamilies[FontFamilyIDs::kApplication]->AddFont(FontFamilyFlag_None, VirtualDirectories::kFonts, "Fonts/OpenSans/OpenSans-SemiBold.ttf", 0, FontHacks_None);
|
||||
m_fontFamilies[FontFamilyIDs::kApplication]->AddFont(FontFamilyFlag_Bold, VirtualDirectories::kFonts, "Fonts/OpenSans/OpenSans-Bold.ttf", 0, FontHacks_None);
|
||||
}
|
||||
|
||||
if (m_fontFamilies[FontFamilyIDs::kHandwriting])
|
||||
m_fontFamilies[FontFamilyIDs::kHandwriting]->AddFont(FontFamilyFlag_None, "Fonts/GochiHand/GochiHand-Regular.ttf", FontHacks_None);
|
||||
m_fontFamilies[FontFamilyIDs::kHandwriting]->AddFont(FontFamilyFlag_None, VirtualDirectories::kFonts, "Fonts/GochiHand/GochiHand-Regular.ttf", 0, FontHacks_None);
|
||||
|
||||
if (m_fontFamilies[FontFamilyIDs::kMonospace])
|
||||
m_fontFamilies[FontFamilyIDs::kMonospace]->AddFont(FontFamilyFlag_None, "Fonts/Roboto/RobotoMono-Regular.ttf", FontHacks_None);
|
||||
m_fontFamilies[FontFamilyIDs::kMonospace]->AddFont(FontFamilyFlag_None, VirtualDirectories::kFonts, "Fonts/Roboto/RobotoMono-Regular.ttf", 0, FontHacks_None);
|
||||
|
||||
memset(m_cachedRenderedFonts, 0, sizeof(m_cachedRenderedFonts));
|
||||
}
|
||||
@@ -131,8 +133,6 @@ namespace PortabilityLayer
|
||||
|
||||
void FontManagerImpl::GetFontPreset(FontPreset_t preset, FontFamilyID_t *outFamilyID, int *outSize, int *outVariationFlags, bool *outAA) const
|
||||
{
|
||||
const bool preinstalledFonts = PLDrivers::GetSystemServices()->IsUsingPreinstalledFonts();
|
||||
|
||||
if (outSize)
|
||||
*outSize = ms_fontPresets[preset].m_textSize;
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace PortabilityLayer
|
||||
bool aa = ms_fontPresets[preset].m_aa;
|
||||
FontFamilyID_t fontFamily = ms_fontPresets[preset].m_familyID;
|
||||
|
||||
if (preinstalledFonts && (fontFamily == FontFamilyIDs::kApplication || fontFamily == FontFamilyIDs::kSystem))
|
||||
if (m_hasPreinstalledFonts && (fontFamily == FontFamilyIDs::kApplication || fontFamily == FontFamilyIDs::kSystem))
|
||||
*outAA = false;
|
||||
else
|
||||
*outAA = aa;
|
||||
@@ -155,7 +155,7 @@ namespace PortabilityLayer
|
||||
switch (ms_fontPresets[preset].m_familyID)
|
||||
{
|
||||
case FontFamilyIDs::kApplication:
|
||||
if (!preinstalledFonts && ms_fontPresets[preset].m_textSize < 11 && (ms_fontPresets[preset].m_variationFlags & FontFamilyFlag_Bold) != 0)
|
||||
if (!m_hasPreinstalledFonts && 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;
|
||||
@@ -286,8 +286,14 @@ namespace PortabilityLayer
|
||||
int variation = fontFamily->GetVariationForFlags(flags);
|
||||
|
||||
FontHacks hacks = FontHacks_None;
|
||||
VirtualDirectory_t vDir = VirtualDirectories::kUnspecified;
|
||||
const char *path = nullptr;
|
||||
if (!fontFamily->GetFontSpec(variation, hacks, path))
|
||||
int typeFaceIndex = 0;
|
||||
if (!fontFamily->GetFontSpec(variation, hacks, vDir, path, typeFaceIndex))
|
||||
return nullptr;
|
||||
|
||||
// Only single TTF fonts are supported by the prerendered font system currently
|
||||
if (vDir != VirtualDirectories::kFonts || typeFaceIndex != 0)
|
||||
return nullptr;
|
||||
|
||||
size_t pathLen = strlen(path);
|
||||
@@ -372,6 +378,7 @@ namespace PortabilityLayer
|
||||
FontManagerImpl::FontManagerImpl()
|
||||
: m_fontArchive(nullptr)
|
||||
, m_fontArchiveFile(nullptr)
|
||||
, m_hasPreinstalledFonts(false)
|
||||
{
|
||||
for (int fid = 0; fid < FontFamilyIDs::kCount; fid++)
|
||||
m_fontFamilies[fid] = nullptr;
|
||||
|
@@ -13,6 +13,7 @@ namespace PortabilityLayer
|
||||
kUserData,
|
||||
kUserSaves,
|
||||
kPrefs,
|
||||
kPreinstalledFonts,
|
||||
kFonts,
|
||||
kCursors,
|
||||
kHighScores,
|
||||
|
Reference in New Issue
Block a user