diff --git a/premake5.lua b/premake5.lua index 796601dd461..225f4bd8b08 100644 --- a/premake5.lua +++ b/premake5.lua @@ -283,6 +283,7 @@ function plugincommon() "CoreAudio.framework", "CoreAudioKit.framework", "CoreServices.framework", + "CoreText.framework", "Cocoa.framework", "CoreFoundation.framework", "OpenGL.framework", @@ -350,6 +351,7 @@ 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", } @@ -596,7 +598,7 @@ if (os.istarget("macosx")) then files { "src/au/**.cpp", - "src/au/**.mm", + "src/au/**.mm", "src/au/**.h", "libs/AUPublic/**.cpp", "libs/AUPublic/**.h", @@ -714,6 +716,8 @@ if (os.istarget("macosx")) then VSTGUI .. "vstgui_uidescription_mac.mm", "src/mac/DisplayInfoMac.mm", "src/mac/UserInteractionsMac.cpp", + "src/mac/cocoa_utils.mm", + "src/mac/RuntimeFontMac.cpp" } end @@ -724,6 +728,7 @@ if (os.istarget("windows")) then VSTGUI .. "vstgui_uidescription_win32.cpp", "src/windows/DisplayInfoWin.cpp", "src/windows/UserInteractionsWin.cpp", + "src/windows/RuntimeFontWin.cpp" } end diff --git a/resources/fonts/Lato-Black.ttf b/resources/fonts/Lato-Black.ttf new file mode 100644 index 00000000000..e2aeb6cc358 Binary files /dev/null and b/resources/fonts/Lato-Black.ttf differ diff --git a/resources/fonts/Lato-BlackItalic.ttf b/resources/fonts/Lato-BlackItalic.ttf new file mode 100644 index 00000000000..81673886692 Binary files /dev/null and b/resources/fonts/Lato-BlackItalic.ttf differ diff --git a/resources/fonts/Lato-Bold.ttf b/resources/fonts/Lato-Bold.ttf new file mode 100644 index 00000000000..ef5ae3b43e9 Binary files /dev/null and b/resources/fonts/Lato-Bold.ttf differ diff --git a/resources/fonts/Lato-BoldItalic.ttf b/resources/fonts/Lato-BoldItalic.ttf new file mode 100644 index 00000000000..664cd02c159 Binary files /dev/null and b/resources/fonts/Lato-BoldItalic.ttf differ diff --git a/resources/fonts/Lato-Hairline.ttf b/resources/fonts/Lato-Hairline.ttf new file mode 100644 index 00000000000..4c5a8fdd99a Binary files /dev/null and b/resources/fonts/Lato-Hairline.ttf differ diff --git a/resources/fonts/Lato-HairlineItalic.ttf b/resources/fonts/Lato-HairlineItalic.ttf new file mode 100644 index 00000000000..af5ac3dc779 Binary files /dev/null and b/resources/fonts/Lato-HairlineItalic.ttf differ diff --git a/resources/fonts/Lato-Heavy.ttf b/resources/fonts/Lato-Heavy.ttf new file mode 100644 index 00000000000..fc70ab7c354 Binary files /dev/null and b/resources/fonts/Lato-Heavy.ttf differ diff --git a/resources/fonts/Lato-HeavyItalic.ttf b/resources/fonts/Lato-HeavyItalic.ttf new file mode 100644 index 00000000000..823188c3790 Binary files /dev/null and b/resources/fonts/Lato-HeavyItalic.ttf differ diff --git a/resources/fonts/Lato-Italic.ttf b/resources/fonts/Lato-Italic.ttf new file mode 100644 index 00000000000..b23256ff532 Binary files /dev/null and b/resources/fonts/Lato-Italic.ttf differ diff --git a/resources/fonts/Lato-Light.ttf b/resources/fonts/Lato-Light.ttf new file mode 100644 index 00000000000..0809b8e6b55 Binary files /dev/null and b/resources/fonts/Lato-Light.ttf differ diff --git a/resources/fonts/Lato-LightItalic.ttf b/resources/fonts/Lato-LightItalic.ttf new file mode 100644 index 00000000000..2d037390dc0 Binary files /dev/null and b/resources/fonts/Lato-LightItalic.ttf differ diff --git a/resources/fonts/Lato-Medium.ttf b/resources/fonts/Lato-Medium.ttf new file mode 100644 index 00000000000..2c612da2ae5 Binary files /dev/null and b/resources/fonts/Lato-Medium.ttf differ diff --git a/resources/fonts/Lato-MediumItalic.ttf b/resources/fonts/Lato-MediumItalic.ttf new file mode 100644 index 00000000000..63ecd028c49 Binary files /dev/null and b/resources/fonts/Lato-MediumItalic.ttf differ diff --git a/resources/fonts/Lato-Regular.ttf b/resources/fonts/Lato-Regular.ttf new file mode 100644 index 00000000000..adbfc467d2d Binary files /dev/null and b/resources/fonts/Lato-Regular.ttf differ diff --git a/resources/fonts/Lato-Semibold.ttf b/resources/fonts/Lato-Semibold.ttf new file mode 100644 index 00000000000..60ac82d65b9 Binary files /dev/null and b/resources/fonts/Lato-Semibold.ttf differ diff --git a/resources/fonts/Lato-SemiboldItalic.ttf b/resources/fonts/Lato-SemiboldItalic.ttf new file mode 100644 index 00000000000..cc23390745a Binary files /dev/null and b/resources/fonts/Lato-SemiboldItalic.ttf differ diff --git a/resources/fonts/Lato-Thin.ttf b/resources/fonts/Lato-Thin.ttf new file mode 100644 index 00000000000..0f84dc1b190 Binary files /dev/null and b/resources/fonts/Lato-Thin.ttf differ diff --git a/resources/fonts/Lato-ThinItalic.ttf b/resources/fonts/Lato-ThinItalic.ttf new file mode 100644 index 00000000000..7fbca2f9748 Binary files /dev/null and b/resources/fonts/Lato-ThinItalic.ttf differ diff --git a/resources/fonts/OFL.txt b/resources/fonts/OFL.txt new file mode 100755 index 00000000000..3c5455f2af1 --- /dev/null +++ b/resources/fonts/OFL.txt @@ -0,0 +1,94 @@ +Copyright (c) 2010-2015, Ɓukasz Dziedzic (dziedzic@typoland.com), +with Reserved Font Name Lato. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/resources/fonts/README.txt b/resources/fonts/README.txt new file mode 100755 index 00000000000..272db628f61 --- /dev/null +++ b/resources/fonts/README.txt @@ -0,0 +1,72 @@ + +Lato font family (Desktop version) + +================================== + +Version 2.015; Latin+Cyrillic+Greek+IPA opensource + +Created by: tyPoland Lukasz Dziedzic +Creation year: 2015 + +Copyright (c) 2010-2015 by tyPoland Lukasz Dziedzic with Reserved Font Name "Lato". Licensed under the SIL Open Font License, Version 1.1. + +Lato is a trademark of tyPoland Lukasz Dziedzic. + +Source URL: http://www.latofonts.com/ +License URL: http://scripts.sil.org/OFL + +================ + +Lato is a sanserif typeface family designed in the Summer 2010 and extended in the Summer 2013 by Warsaw-based designer Lukasz Dziedzic ("Lato" means "Summer" in Polish). It tries to carefully balance some potentially conflicting priorities: it should seem quite "transparent" when used in body text but would display some original traits when used in larger sizes. The classical proportions, particularly visible in the uppercase, give the letterforms familiar harmony and elegance. At the same time, its sleek sanserif look makes evident the fact that Lato was designed in the 2010s, even though it does not follow any current trend. The semi-rounded details of the letters give Lato a feeling of warmth, while the strong structure provides stability and seriousness. In 2013-2014, the family was greatly extended (with the help of Adam Twardoch and Botio Nikoltchev) to cover 3000+ glyphs over nine weights with italics. It now supports 100+ Latin-based languages, 50+ Cyrillic-based languages as well as Greek and IPA phonetics. The Lato fonts are available free of charge under the SIL Open Font License from http://www.latofonts.com/ + +================ + +CONTENTS: + +This folder contains 18 font files in OpenType TT (.ttf) format. You can install these fonts on your computer and use in any desktop applications (such as Word, InDesign, Illustrator, Photoshop, Keynote or Pages). + +================ + +REVISION LOG: + +# Version 2.015 (2015-08-06) +Initial implementation of mark positioning (should work for most glyphs) +Autohinted using ttfautohint 1.3. + +# Version 2.010 (2014-09-01) +Improved some contour bugs and diacritics positioning. +Improved outline quality. +Revised OTL features so that they work in browsers (ot-sanitise). +Autohinted using ttfautohint 1.1. +Interpolated the Medium weight differently so it provides more visual difference from Regular. + +# Version 2.007 (2014-02-27) +Greatly expanded character set, revised metrics, four additional weights. + +# Version 1.104 (2011-11-08) +Merged the distribution again +Autohinted with updated ttfautohint 0.4 (which no longer causes Adobe and iOS problems) +except the Hai and Lig weights which are hinted in FLS 5.1. + +# Version 1.102 (2011-10-28) +Added OpenType Layout features +Ssplit between desktop and web versions +Desktop version: all weights autohinted with FontLab Studio +Web version autohinted with ttfautohint 0.4 except the Hai and Lig weights + +# Version 1.101 (2011-09-30) +Fixed OS/2 table Unicode and codepage entries + +# Version 1.100 (2011-09-12) +Added Polish diacritics to the character set +Weights Hai and Lig autohinted with FontLab Studio +Other weights autohinted with ttfautohint 0.3 + +# Version 1.011 (2010-12-29) +Added the soft hyphen glyph + +# Version 1.010 (2010-12-13) +Initial version released under SIL Open Font License +Western character set + +================ diff --git a/scripts/macOS/package-au.sh b/scripts/macOS/package-au.sh index 4b2ba34cd19..20affeb4f70 100755 --- a/scripts/macOS/package-au.sh +++ b/scripts/macOS/package-au.sh @@ -9,6 +9,7 @@ fi RES_SRC_LOCATION="resources" PACKAGE_SRC_LOCATION="$RES_SRC_LOCATION/osx-au" BITMAP_SRC_LOCATION="$RES_SRC_LOCATION/bitmaps" +FONT_SRC_LOCATION="$RES_SRC_LOCATION/fonts" VECTOR_BITMAP_SRC_LOCATION="assets/${SURGE_USE_VECTOR_SKIN}/exported" BUNDLE_RES_SRC_LOCATION="$RES_SRC_LOCATION/osx-resources" EXEC_LOCATION="target/au/Release/Surge.dylib" @@ -48,3 +49,6 @@ else cp $VECTOR_BITMAP_SRC_LOCATION/*png "$BUNDLE_DIR/Contents/Resources/scalable" fi + +mkdir "$BUNDLE_DIR/Contents/Resources/fonts"; +cp $FONT_SRC_LOCATION/* "$BUNDLE_DIR/Contents/Resources/fonts"; diff --git a/scripts/macOS/package-vst.sh b/scripts/macOS/package-vst.sh index 986a61a2596..4494f2d0176 100755 --- a/scripts/macOS/package-vst.sh +++ b/scripts/macOS/package-vst.sh @@ -10,6 +10,7 @@ RES_SRC_LOCATION="resources" PACKAGE_SRC_LOCATION="$RES_SRC_LOCATION/osx-vst2" BITMAP_SRC_LOCATION="$RES_SRC_LOCATION/bitmaps" VECTOR_BITMAP_SRC_LOCATION="assets/${SURGE_USE_VECTOR_SKIN}/exported" +FONT_SRC_LOCATION="$RES_SRC_LOCATION/fonts" BUNDLE_RES_SRC_LOCATION="$RES_SRC_LOCATION/osx-resources" EXEC_LOCATION="target/vst2/Release/Surge.dylib" #EXEC_LOCATION="target/vst2/Debug/Surge-Debug.dylib" @@ -48,4 +49,6 @@ else cp $VECTOR_BITMAP_SRC_LOCATION/*png "$BUNDLE_DIR/Contents/Resources/scalable" fi +mkdir "$BUNDLE_DIR/Contents/Resources/fonts"; +cp $FONT_SRC_LOCATION/* "$BUNDLE_DIR/Contents/Resources/fonts"; diff --git a/scripts/macOS/package-vst3.sh b/scripts/macOS/package-vst3.sh index e0bdebb897f..1f0572389f1 100755 --- a/scripts/macOS/package-vst3.sh +++ b/scripts/macOS/package-vst3.sh @@ -9,6 +9,7 @@ fi RES_SRC_LOCATION="resources" PACKAGE_SRC_LOCATION="$RES_SRC_LOCATION/osx-vst3" BITMAP_SRC_LOCATION="$RES_SRC_LOCATION/bitmaps" +FONT_SRC_LOCATION="$RES_SRC_LOCATION/fonts" VECTOR_BITMAP_SRC_LOCATION="assets/${SURGE_USE_VECTOR_SKIN}/exported" BUNDLE_RES_SRC_LOCATION="$RES_SRC_LOCATION/osx-resources" EXEC_LOCATION="target/vst3/Release/Surge.dylib" @@ -48,3 +49,5 @@ else cp $VECTOR_BITMAP_SRC_LOCATION/*png "$BUNDLE_DIR/Contents/Resources/scalable" fi +mkdir "$BUNDLE_DIR/Contents/Resources/fonts"; +cp $FONT_SRC_LOCATION/* "$BUNDLE_DIR/Contents/Resources/fonts"; diff --git a/src/common/gui/RuntimeFont.h b/src/common/gui/RuntimeFont.h new file mode 100644 index 00000000000..6af8855a693 --- /dev/null +++ b/src/common/gui/RuntimeFont.h @@ -0,0 +1,33 @@ +#pragma once + +#include "vstgui/vstgui.h" +#include "vstgui/lib/cfont.h" +#include "vstgui/lib/platform/iplatformfont.h" + +namespace Surge +{ +namespace GUI +{ + +/** + * initializeRuntimeFont + * + * The role of this function is to load a font from the bundle, dll, or some other + * source. Once the font file is loaded, it is used to create the VSTGUI 9 and 14 point + * fonts in global variables "surge_minifont" and "surge_patchfont" if they are NULL + * at calltime. The "surge_minifont" is used for most text rendering and the + * "surge_patchfont" is used for the patchname. + * + * The implementation is OS Specific. + */ +void initializeRuntimeFont(); + +} +} + +/* +** The two extern globals we need to initialize, which are defined/created +** in SurgeGuieditor +*/ +extern VSTGUI::CFontRef surge_minifont; +extern VSTGUI::CFontRef surge_patchfont; diff --git a/src/common/gui/SurgeGUIEditor.cpp b/src/common/gui/SurgeGUIEditor.cpp index 38e3d3c418e..dcdad438602 100644 --- a/src/common/gui/SurgeGUIEditor.cpp +++ b/src/common/gui/SurgeGUIEditor.cpp @@ -30,19 +30,28 @@ #if TARGET_AUDIOUNIT #include "aulayer.h" #endif -/* -#elif TARGET_VST3 -#include "surgeprocessor.h" -#elif TARGET_VST2 -#include "vstlayer.h" -#endif*/ - -//#include + +#if MAC || WINDOWS +#define USE_RUNTIME_LOADED_FONTS 1 +#else +#define USE_RUNTIME_LOADED_FONTS 0 +#endif + +#if USE_RUNTIME_LOADED_FONTS +#include "RuntimeFont.h" +#endif + const int yofs = 10; using namespace VSTGUI; using namespace std; + +#if USE_RUNTIME_LOADED_FONTS +CFontRef surge_minifont = NULL; +CFontRef surge_patchfont = NULL; +#else + #if MAC SharedPointer minifont = new CFontDesc("Lucida Grande", 9); SharedPointer patchfont = new CFontDesc("Lucida Grande", 14); @@ -56,6 +65,7 @@ SharedPointer patchfont = new CFontDesc("Arial", 14); CFontRef surge_minifont = minifont; CFontRef surge_patchfont = patchfont; +#endif enum special_tags @@ -143,6 +153,46 @@ SurgeGUIEditor::SurgeGUIEditor(void* effect, SurgeSynthesizer* synth) : super(ef #endif zoom_callback = [](SurgeGUIEditor* f) {}; setZoomFactor(100); + + +#if USE_RUNTIME_LOADED_FONTS + /* + ** As documented in RuntimeFonts.h, the contract of this function is to side-effect + ** onto globals surge_minifont and surge_patchfont with valid fonts from the runtime + ** distribution + */ + Surge::GUI::initializeRuntimeFont(); + + if (surge_minifont == NULL) + { + /* + ** OK the runtime load didn't work. Fall back to + ** the old defaults + ** + ** FIXME: One day we will be confident enough in + ** our dyna loader to make this a Surge::UserInteraction::promptError + ** warning also. + ** + ** For now, copy the defaults from above. (Don't factor this into + ** a function since the above defaults are initialized as dll + ** statics if we are not runtime). + */ +#if MAC + SharedPointer minifont = new CFontDesc("Lucida Grande", 9); + SharedPointer patchfont = new CFontDesc("Lucida Grande", 14); +#elif LINUX + SharedPointer minifont = new CFontDesc("sans-serif", 9); + SharedPointer patchfont = new CFontDesc("sans-serif", 14); +#else + SharedPointer minifont = new CFontDesc("Microsoft Sans Serif", 9); + SharedPointer patchfont = new CFontDesc("Arial", 14); +#endif + + surge_minifont = minifont; + surge_patchfont = patchfont; + + } +#endif } SurgeGUIEditor::~SurgeGUIEditor() diff --git a/src/common/resource.h b/src/common/resource.h index ae6f69c4e38..0a84d8b4185 100644 --- a/src/common/resource.h +++ b/src/common/resource.h @@ -60,6 +60,8 @@ #define IDC_AUTHOR 1004 #define IDC_TEDIT 1024 +#define IDR_LATO_FONT 501 + // Next default values for new objects // #ifdef APSTUDIO_INVOKED @@ -87,4 +89,5 @@ #define SCALABLE_400_OFFSET 74000 #include "scalableresource.h" // found in src/windows + #endif diff --git a/src/mac/RuntimeFontMac.cpp b/src/mac/RuntimeFontMac.cpp new file mode 100644 index 00000000000..aa2249ef93f --- /dev/null +++ b/src/mac/RuntimeFontMac.cpp @@ -0,0 +1,46 @@ +#include +#include +#include "RuntimeFont.h" + +#include "vstgui/lib/platform/mac/macglobals.h" +#include "UserInteractions.h" + + +namespace Surge +{ +namespace GUI +{ + +void initializeRuntimeFont() +{ + /* + ** Someone may have already initialized the globals. Don't do it twice + */ + if (surge_minifont != NULL || surge_patchfont != NULL) + return; + + /* + ** MacFonts use the CoreText registry so we can just find them in the bundle + ** and register them using the CoreText Font Manager API + */ + CFURLRef url = nullptr; + url = CFBundleCopyResourceURL(VSTGUI::getBundleRef(), CFSTR("Lato-Regular"), CFSTR("ttf"), CFSTR("fonts")); + if (url) + { + CTFontManagerRegisterFontsForURL(url, kCTFontManagerScopeProcess, NULL ); + CFRelease(url); + } + else + { + Surge::UserInteractions::promptError("Cannot load lato font from bundle", "Software Error"); + } + + VSTGUI::SharedPointer minifont = new VSTGUI::CFontDesc("Lato", 9); + VSTGUI::SharedPointer patchfont = new VSTGUI::CFontDesc("Lato", 14); + surge_minifont = minifont; + surge_patchfont = patchfont; + +} + +} +} diff --git a/src/windows/RuntimeFontWin.cpp b/src/windows/RuntimeFontWin.cpp new file mode 100644 index 00000000000..fe4e5deb96f --- /dev/null +++ b/src/windows/RuntimeFontWin.cpp @@ -0,0 +1,111 @@ +#include +#include +#include + +#include + +#include "RuntimeFont.h" +#include "UserInteractions.h" + +#include "resource.h" +#include "vstgui/lib/platform/win32/win32support.h" + +#include + +using namespace VSTGUI; + +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 + */ + if (surge_minifont != NULL || surge_patchfont != NULL) + return; + + /* + ** Construct my temporary file name and create it if needed. + */ + 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)) + { + void *ttfData = NULL; + size_t ttfDataSize = 0; + + HRSRC rsrc = 0; + HMODULE hResInstance = VSTGUI::GetInstance(); + rsrc = FindResourceA(hResInstance, MAKEINTRESOURCE(IDR_LATO_FONT), "BINARY"); + if (rsrc) + { + HGLOBAL mem = LoadResource(hResInstance, rsrc); + ttfData = LockResource(mem); + ttfDataSize = SizeofResource(hResInstance, rsrc); + } + + 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 + */ + VSTGUI::SharedPointer minifont = new VSTGUI::CFontDesc("Lato", 9); + VSTGUI::SharedPointer patchfont = new VSTGUI::CFontDesc("Lato", 14); + surge_minifont = minifont; + surge_patchfont = patchfont; + +} + +} +} diff --git a/src/windows/surge.rc b/src/windows/surge.rc index 09544b3f7d6..25359c42495 100644 --- a/src/windows/surge.rc +++ b/src/windows/surge.rc @@ -68,6 +68,9 @@ LANGUAGE LANG_NEUTRAL, #include "scalableui.rc" + + IDR_LATO_FONT BINARY "resources/fonts/Lato-SemiBold.ttf" + ///////////////////////////////////////////////////////////////////////////// // // Dialog