Skip to content

Commit

Permalink
Check for LATO built in (surge-synthesizer#682)
Browse files Browse the repository at this point in the history
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 surge-synthesizer#678 : Font causes Hang on some Windows
Closes surge-synthesizer#673 : De-Bold our Lato

Former-commit-id: 2e86d037bca7a78e53d2ff204ab65391f4ebbd9c [formerly 0a19dab]
Former-commit-id: 5ca736ed704cb2b4860644f167ff29ad53669a10
Former-commit-id: 126e499a3470bb74cf3d7a2cf6edb28cf6f3d30c
  • Loading branch information
baconpaul authored Feb 27, 2019
1 parent 838cb66 commit 0e59e25
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 67 deletions.
1 change: 1 addition & 0 deletions installer_win/surge-x86.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions installer_win/surge.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
4 changes: 4 additions & 0 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,20 @@ SurgeGUIEditor::SurgeGUIEditor(void* effect, SurgeSynthesizer* synth) : super(ef
#if MAC
SharedPointer<CFontDesc> minifont = new CFontDesc("Lucida Grande", 9);
SharedPointer<CFontDesc> patchfont = new CFontDesc("Lucida Grande", 14);
SharedPointer<CFontDesc> lfofont = new CFontDesc("Lucida Grande", 8);
#elif LINUX
SharedPointer<CFontDesc> minifont = new CFontDesc("sans-serif", 9);
SharedPointer<CFontDesc> patchfont = new CFontDesc("sans-serif", 14);
SharedPointer<CFontDesc> lfofont = new CFontDesc("sans-serif", 8);
#else
SharedPointer<CFontDesc> minifont = new CFontDesc("Microsoft Sans Serif", 9);
SharedPointer<CFontDesc> patchfont = new CFontDesc("Arial", 14);
SharedPointer<CFontDesc> lfofont = new CFontDesc("Microsoft Sans Serif", 8 );
#endif

displayFont = minifont;
patchNameFont = patchfont;
lfoTypeFont = lfofont;

}
#endif
Expand Down
75 changes: 11 additions & 64 deletions src/windows/RuntimeFontWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,84 +19,31 @@ namespace Surge
namespace GUI
{

struct RemoveFontGlobal
{
RemoveFontGlobal() {}
~RemoveFontGlobal() {
for (auto f: fonts)
{
RemoveFontResource(f.c_str());
}
}

std::list<std::string> 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
*/
if (displayFont != NULL || patchNameFont != NULL)
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<std::string> 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
*/
Expand Down
2 changes: 0 additions & 2 deletions src/windows/surge.rc
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ LANGUAGE LANG_NEUTRAL,
#include "scalableui.rc"


IDR_LATO_FONT BINARY "resources/fonts/Lato-SemiBold.ttf"

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
Expand Down

0 comments on commit 0e59e25

Please sign in to comment.