1 /*
2 ** Surge Synthesizer is Free and Open Source Software
3 **
4 ** Surge is made available under the Gnu General Public License, v3.0
5 ** https://www.gnu.org/licenses/gpl-3.0.en.html
6 **
7 ** Copyright 2004-2020 by various individuals as described by the Git transaction log
8 **
9 ** All source at: https://github.com/surge-synthesizer/surge.git
10 **
11 ** Surge was a commercial product from 2004-2018, with Copyright and ownership
12 ** in that period held by Claes Johanson at Vember Audio. Claes made Surge
13 ** open source in September 2018.
14 */
15
16 #include "RuntimeFont.h"
17 #if TARGET_JUCE_UI
18 #include <JuceHeader.h>
19 #endif
20 #include <iostream>
21
22 namespace Surge
23 {
24 namespace GUI
25 {
26
initializeRuntimeFont()27 void initializeRuntimeFont()
28 {
29 /*
30 * Someone may have already initialized the globals. Don't do it twice
31 */
32 if (displayFont != NULL || patchNameFont != NULL)
33 return;
34
35 #if !TARGET_JUCE_UI
36 if (!initializeRuntimeFontForOS())
37 {
38 return;
39 }
40 #endif
41
42 displayFont = getLatoAtSize(9);
43 patchNameFont = getLatoAtSize(13);
44 lfoTypeFont = getLatoAtSize(8);
45 aboutFont = getLatoAtSize(10);
46 }
getLatoAtSize(float size,int style)47 VSTGUI::CFontRef getLatoAtSize(float size, int style)
48 {
49 #if TARGET_JUCE_UI
50 /*
51 * Optimize this later to cache the face but for now. Also I'm ignoring style and stuff.
52 */
53 auto tf = juce::Typeface::createSystemTypefaceFor(BinaryData::LatoRegular_ttf,
54 BinaryData::LatoRegular_ttfSize);
55 auto lato = juce::Font(tf).withPointHeight(size);
56 return std::make_shared<VSTGUI::CFontInternal>(lato);
57 #else
58 /*
59 * I simply cannot wait for VSTGUI to not be part of my life
60 */
61 static std::map<std::pair<float, int>, VSTGUI::SharedPointer<VSTGUI::CFontDesc>> fontCache;
62 auto key = std::make_pair(size, style);
63 if (fontCache.find(key) == fontCache.end())
64 {
65 fontCache[key] = VSTGUI::SharedPointer<VSTGUI::CFontDesc>(
66 new VSTGUI::CFontDesc("Lato", size, style), true);
67 // Just leak it to be safe since the ownership semantics are horrid
68 fontCache[key]->remember();
69 }
70 return fontCache[key];
71 #endif
72 }
73 } // namespace GUI
74 } // namespace Surge