Skip to content

Commit

Permalink
Merge pull request #331 from steinbergmedia/fix-custom-fonts-on-windo…
Browse files Browse the repository at this point in the history
…ws-broken

initialize fonts on Windows when the resource base path is set
  • Loading branch information
scheffle authored Aug 31, 2024
2 parents 6cb6d34 + 9e79ba5 commit 98ec968
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
29 changes: 14 additions & 15 deletions vstgui/lib/platform/win32/direct2d/d2dfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ struct CustomFonts
return false;
}

CustomFonts ()
CustomFonts (const UTF8String& resourceBasePath)
{
auto winFactory = getPlatformFactory ().asWin32Factory ();
if (!winFactory)
if (resourceBasePath.empty ())
return;
auto basePath = winFactory->getResourceBasePath ();
if (!basePath)
return;
*basePath += "Fonts\\*";
auto files = getDirectoryContents (*basePath);
auto basePath = resourceBasePath;
basePath += "Fonts\\*";
auto files = getDirectoryContents (basePath);
if (files.empty ())
return;
auto factory = getDWriteFactory ();
Expand Down Expand Up @@ -106,6 +103,7 @@ struct CustomFonts
return result;
}
#else
CustomFonts (const UTF8String& resourceBasePath) {}
IDWriteFontCollection* getFontCollection () { return nullptr; }
bool contains (const WCHAR*, DWRITE_FONT_WEIGHT, DWRITE_FONT_STRETCH, DWRITE_FONT_STYLE)
{
Expand All @@ -116,14 +114,9 @@ struct CustomFonts

//-----------------------------------------------------------------------------
static std::unique_ptr<CustomFonts> customFonts;
static std::once_flag customFontsOnceFlag;

//-----------------------------------------------------------------------------
static CustomFonts* getCustomFonts ()
{
std::call_once (customFontsOnceFlag, [] () { customFonts = std::make_unique<CustomFonts> (); });
return customFonts.get ();
}
static CustomFonts* getCustomFonts () { return customFonts.get (); }

//-----------------------------------------------------------------------------
static void gatherFonts (const FontFamilyCallback& callback, IDWriteFontCollection* collection)
Expand Down Expand Up @@ -198,8 +191,14 @@ bool D2DFont::getAllFontFamilies (const FontFamilyCallback& callback)
return true;
}

//------------------------------------------------------------------------
void D2DFont::initialize (const UTF8String& resourceBasePath)
{
D2DFontPrivate::customFonts = std::make_unique<D2DFontPrivate::CustomFonts> (resourceBasePath);
}

//-----------------------------------------------------------------------------
void D2DFont::terminate () { D2DFontPrivate::customFonts = nullptr; }
void D2DFont::terminate () { D2DFontPrivate::customFonts.reset (); }

//-----------------------------------------------------------------------------
D2DFont::D2DFont (const UTF8String& name, const CCoord& size, const int32_t& style)
Expand Down
1 change: 1 addition & 0 deletions vstgui/lib/platform/win32/direct2d/d2dfont.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class D2DFont final : public IPlatformFont, public IFontPainter

static bool getAllFontFamilies (const FontFamilyCallback& callback);

static void initialize (const UTF8String& resourceBasePath);
static void terminate ();

protected:
Expand Down
1 change: 1 addition & 0 deletions vstgui/lib/platform/win32/win32factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ HINSTANCE Win32Factory::getInstance () const noexcept
void Win32Factory::setResourceBasePath (const UTF8String& path) const noexcept
{
impl->setBasePath (path);
D2DFont::initialize (path);
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 98ec968

Please sign in to comment.