Skip to content

Commit f773ae3

Browse files
PoroCYonGargaj
authored andcommitted
slightly fix font selection on Linux (#50)
1 parent 62b85d9 commit f773ae3

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The tool was originally conceived and implemented after the Revision 2014 demosc
1414
- F2: toggle texture preview
1515
- F5 or Ctrl-R: recompile shader
1616
- F11 or Ctrl/Cmd-f: hide shader overlay
17-
- Alt-F4: exbobolate your planet
17+
- Alt-F4 or Shift+Escape: exbobolate your planet
1818

1919
## Configuration
2020
Create a ```config.json``` with e.g. the following contents: (all fields are optional)

src/main.cpp

+38-10
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,27 @@ int main(int argc, char *argv[])
143143
editorOptions.sFontPath = "/Library/Fonts/Courier New.ttf";
144144
#else
145145
// Linux case
146-
const std::string fontPaths[2] = {
146+
// TODO: use fonts.conf(5) or X resources or something like that
147+
const char* fontPaths[] = {
148+
"/usr/share/fonts/TTF/DejaVuSansMono.ttf",
149+
"/usr/share/fonts/TTF/FreeMono.ttf",
150+
"/usr/share/fonts/TTF/LiberationMono-Regular.ttf",
151+
"/usr/share/fonts/TTF/VeraMono.ttf",
147152
"/usr/share/fonts/corefonts/cour.ttf",
148-
"/usr/share/fonts/truetype/msttcorefonts/cour.ttf"
153+
"/usr/share/fonts/truetype/msttcorefonts/cour.ttf",
154+
NULL
149155
};
150156
editorOptions.sFontPath = "";
151-
int step = 0;
152-
while( step < 2 && editorOptions.sFontPath.size() == 0 ) {
153-
const std::string & current = fontPaths[step++];
154-
155-
if (access(current.c_str(), R_OK) != -1) {
156-
editorOptions.sFontPath = current;
157+
for (int i = 0; fontPaths[i]; ++i)
158+
{
159+
if (access(fontPaths[i], R_OK) != -1)
160+
{
161+
editorOptions.sFontPath = fontPaths[i];
162+
break;
157163
}
158164
}
165+
// aiee - no font found, but don't report yet, it might still get changed
166+
// though config.json
159167
#endif
160168
editorOptions.nOpacity = 0xC0;
161169
editorOptions.bUseSpacesForTabs = true;
@@ -199,7 +207,24 @@ int main(int argc, char *argv[])
199207
if (options.get<jsonxx::Object>("font").has<jsonxx::Number>("size"))
200208
editorOptions.nFontSize = options.get<jsonxx::Object>("font").get<jsonxx::Number>("size");
201209
if (options.get<jsonxx::Object>("font").has<jsonxx::String>("file"))
202-
editorOptions.sFontPath = options.get<jsonxx::Object>("font").get<jsonxx::String>("file");
210+
{
211+
std::string fontpath = options.get<jsonxx::Object>("font").get<jsonxx::String>("file");
212+
// TODO: port this to other platforms
213+
#if !defined(_WIN32) && !defined(__APPLE__)
214+
if (access(fontpath.c_str(), R_OK) != -1)
215+
editorOptions.sFontPath = fontpath;
216+
else
217+
{
218+
printf("Couldn't open the font file '%s'.\n", fontpath.c_str());
219+
return -1;
220+
}
221+
#endif
222+
}
223+
else if (!editorOptions.sFontPath.size()) // coudn't find a default font
224+
{
225+
printf("Couldn't find any of the default fonts. Please specify one in config.json\n");
226+
return -1;
227+
}
203228
}
204229
if (options.has<jsonxx::Object>("gui"))
205230
{
@@ -230,7 +255,7 @@ int main(int argc, char *argv[])
230255
}
231256
Capture::LoadSettings( options );
232257
}
233-
if ( !Capture::Open( settings ) )
258+
if (!Capture::Open(settings))
234259
{
235260
printf("Initializing capture system failed!\n");
236261
return 0;
@@ -256,6 +281,9 @@ int main(int argc, char *argv[])
256281
printf("Last shader works fine.\n");
257282
shaderInitSuccessful = true;
258283
}
284+
else {
285+
printf("Shader error:\n%s\n", szError);
286+
}
259287
}
260288
if (!shaderInitSuccessful)
261289
{

src/platform_glfw/Renderer.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
#include <cstdio>
3+
14
#ifdef _WIN32
25
#include <windows.h>
36
#endif
@@ -411,7 +414,7 @@ namespace Renderer
411414
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
412415
{
413416
if (action == GLFW_PRESS || action == GLFW_REPEAT) {
414-
if ((key==GLFW_KEY_F4) && (mods&GLFW_MOD_ALT)) {
417+
if ((key==GLFW_KEY_F4 && (mods&GLFW_MOD_ALT)) || (key==GLFW_KEY_ESCAPE&&(mods&GLFW_MOD_SHIFT))) {
415418
run = false;
416419
}
417420
int sciKey = 0;

0 commit comments

Comments
 (0)