From 0e59e250bbf646f202b1c91cbc74fe850d161130 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 27 Feb 2019 18:55:14 -0500 Subject: [PATCH] Check for LATO built in (#682) Rather than try and runtime load the Lato font assume it is installed and react accordingly if it is not. No longer bundle it with the dll and instead bundle it with the installer. Closes #678 : Font causes Hang on some Windows Closes #673 : De-Bold our Lato Former-commit-id: 2e86d037bca7a78e53d2ff204ab65391f4ebbd9c [formerly 0a19dab4d3b9e3a52b52b7fa29918c8de7351f27] Former-commit-id: 5ca736ed704cb2b4860644f167ff29ad53669a10 Former-commit-id: 126e499a3470bb74cf3d7a2cf6edb28cf6f3d30c --- installer_win/surge-x86.iss | 1 + installer_win/surge.iss | 1 + premake5.lua | 1 - src/common/gui/SurgeGUIEditor.cpp | 4 ++ src/windows/RuntimeFontWin.cpp | 75 +++++-------------------------- src/windows/surge.rc | 2 - 6 files changed, 17 insertions(+), 67 deletions(-) diff --git a/installer_win/surge-x86.iss b/installer_win/surge-x86.iss index 5747910cb19..2eafbc5a18b 100644 --- a/installer_win/surge-x86.iss +++ b/installer_win/surge-x86.iss @@ -44,6 +44,7 @@ Name: VST3; Description: VST3 Plug-in (32 bit); Types: full compact custom; Flag Source: ..\target\vst2\Release\Surge32.dll; DestDir: {app}; Components: VST2; Flags: ignoreversion skipifsourcedoesntexist Source: ..\target\vst3\Release\Surge32.vst3; DestDir: {cf}\VST3; Components: VST3; Flags: ignoreversion Source: ..\resources\data\*; DestDir: {localappdata}\Surge; Components: Data; Flags: recursesubdirs; Excludes: "*.git"; +Source: ..\resources\fonts\Lato-Regular.ttf; DestDir: "{fonts}"; Components: Data; FontInstall: "Lato"; Flags: onlyifdoesntexist uninsneveruninstall [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" diff --git a/installer_win/surge.iss b/installer_win/surge.iss index 3da17f1a747..d00cef5d813 100644 --- a/installer_win/surge.iss +++ b/installer_win/surge.iss @@ -44,6 +44,7 @@ Name: VST3; Description: VST3 Plug-in (64 bit); Types: full compact custom; Flag Source: ..\target\vst2\Release\Surge.dll; DestDir: {app}; Components: VST2; Flags: ignoreversion skipifsourcedoesntexist Source: ..\target\vst3\Release\Surge.vst3; DestDir: {cf}\VST3; Components: VST3; Flags: ignoreversion Source: ..\resources\data\*; DestDir: {localappdata}\Surge; Components: Data; Flags: recursesubdirs; Excludes: "*.git"; +Source: ..\resources\fonts\Lato-Regular.ttf; DestDir: "{fonts}"; Components: Data; FontInstall: "Lato"; Flags: onlyifdoesntexist uninsneveruninstall [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" diff --git a/premake5.lua b/premake5.lua index ef74b7001b0..037f1471072 100644 --- a/premake5.lua +++ b/premake5.lua @@ -372,7 +372,6 @@ function plugincommon() "src/windows/scalableui.rc", "resources/bitmaps/*.png", "assets/original-vector/exported/*.png", - "resources/fonts/**.ttf", VSTGUI .. "vstgui_win32.cpp", VSTGUI .. "vstgui_uidescription_win32.cpp", } diff --git a/src/common/gui/SurgeGUIEditor.cpp b/src/common/gui/SurgeGUIEditor.cpp index 184af74ed63..0979b3448ff 100644 --- a/src/common/gui/SurgeGUIEditor.cpp +++ b/src/common/gui/SurgeGUIEditor.cpp @@ -185,16 +185,20 @@ SurgeGUIEditor::SurgeGUIEditor(void* effect, SurgeSynthesizer* synth) : super(ef #if MAC SharedPointer minifont = new CFontDesc("Lucida Grande", 9); SharedPointer patchfont = new CFontDesc("Lucida Grande", 14); + SharedPointer lfofont = new CFontDesc("Lucida Grande", 8); #elif LINUX SharedPointer minifont = new CFontDesc("sans-serif", 9); SharedPointer patchfont = new CFontDesc("sans-serif", 14); + SharedPointer lfofont = new CFontDesc("sans-serif", 8); #else SharedPointer minifont = new CFontDesc("Microsoft Sans Serif", 9); SharedPointer patchfont = new CFontDesc("Arial", 14); + SharedPointer lfofont = new CFontDesc("Microsoft Sans Serif", 8 ); #endif displayFont = minifont; patchNameFont = patchfont; + lfoTypeFont = lfofont; } #endif diff --git a/src/windows/RuntimeFontWin.cpp b/src/windows/RuntimeFontWin.cpp index 2fdc7347fee..fae65a58449 100644 --- a/src/windows/RuntimeFontWin.cpp +++ b/src/windows/RuntimeFontWin.cpp @@ -19,35 +19,8 @@ namespace Surge namespace GUI { -struct RemoveFontGlobal -{ - RemoveFontGlobal() {} - ~RemoveFontGlobal() { - for (auto f: fonts) - { - RemoveFontResource(f.c_str()); - } - } - - std::list fonts; -}; - -RemoveFontGlobal gRemove; // when this is destroyed at DLL unload time it should run the above constructor. - void initializeRuntimeFont() { - /* - ** The windows direct2d API seems designed to make sure you never load from - ** memory. Like seriously: check this out - ** - ** https://docs.microsoft.com/de-de/previous-versions/technical-content/dd941710(v=vs.85) - ** - ** So the best bet, albeit unpalletable, is to dump the TTF to a file and then - ** AddFontResource it. At exit time, we need to RemoveFontResource it. - ** We accomplish this with the global guard above. - ** - */ - /* ** Someone may have already initialized the globals. Don't do it twice */ @@ -55,48 +28,22 @@ void initializeRuntimeFont() return; /* - ** Construct my temporary file name and create it if needed. + ** In Feb 2019 we removed our ability to load the font from the bundle and instead + ** test if it is installed; if it is we use it; if it is not we don't. + ** We also modified the innosetup installer to install it. */ - char tmpPath[MAX_PATH]; - GetTempPathA(MAX_PATH, tmpPath); - std::string latoFileName = std::string(tmpPath) + "Surge-Delivered-Lato-SemiBold.ttf"; - - if (!std::experimental::filesystem::exists(latoFileName)) + std::list fontNames; + if (IPlatformFont::getAllPlatformFontFamilies (fontNames)) { - void *ttfData = NULL; - size_t ttfDataSize = 0; - - HRSRC rsrc = 0; - HMODULE hResInstance = VSTGUI::GetInstance(); - rsrc = FindResourceA(hResInstance, MAKEINTRESOURCE(IDR_LATO_FONT), "BINARY"); - if (rsrc) + if (std::find(fontNames.begin(), fontNames.end(), "Lato") == fontNames.end()) { - HGLOBAL mem = LoadResource(hResInstance, rsrc); - ttfData = LockResource(mem); - ttfDataSize = SizeofResource(hResInstance, rsrc); + /* + ** Lato is not installed; bail out + */ + return; } - - FILE *fontFile = fopen(latoFileName.c_str(), "wb"); - if(fontFile) - { - fwrite(ttfData,sizeof(char),ttfDataSize,fontFile); - fclose(fontFile); - } - /* - ** There is a tiny chance that the file didn't exist when we asked and - ** is non-writable because another proc is doing exactly this, so - ** if the fontFile isn't openable, just continue anyway. That's - ** probably the best choice - */ } - - /* - ** Open the font and schedule it for removal at DLL exit - */ - int nFonts = AddFontResource(latoFileName.c_str()); - ::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, NULL, NULL); - gRemove.fonts.push_back(latoFileName); - + /* ** Set up the global fonts */ diff --git a/src/windows/surge.rc b/src/windows/surge.rc index 25359c42495..a8f524ab241 100644 --- a/src/windows/surge.rc +++ b/src/windows/surge.rc @@ -69,8 +69,6 @@ LANGUAGE LANG_NEUTRAL, #include "scalableui.rc" - IDR_LATO_FONT BINARY "resources/fonts/Lato-SemiBold.ttf" - ///////////////////////////////////////////////////////////////////////////// // // Dialog