Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for LATO built in #682

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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