diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-31 08:01:28 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-31 08:01:28 +0300 |
commit | 07022bc768a8f23cf051dc6a58e85195886478d5 (patch) | |
tree | c0c97d45094fe3dde584136955ac3d6b813528ee | |
parent | 01e80caec8220c1d57d4e2ef4eb9c99538842429 (diff) |
Use the full Symbola font; don't embed resources
The fonts are too large to embed comfortably.
-rw-r--r-- | CMakeLists.txt | 8 | ||||
-rw-r--r-- | res/Symbola.ttf | bin | 0 -> 3727644 bytes | |||
-rw-r--r-- | src/app.c | 6 | ||||
-rw-r--r-- | src/history.c | 9 | ||||
-rw-r--r-- | src/ui/text.c | 26 |
5 files changed, 30 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 42e70ef8..de97bf0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -14,6 +14,8 @@ pkg_check_modules (SDL2 REQUIRED sdl2) | |||
14 | 14 | ||
15 | # Embedded resources are written to a generated source file. | 15 | # Embedded resources are written to a generated source file. |
16 | message (STATUS "Preparing embedded resources...") | 16 | message (STATUS "Preparing embedded resources...") |
17 | # Fonts are too large to comfortably embed as a C source. | ||
18 | set (EMBED_IN_EXECUTABLE OFF CACHE BOOL "Embed resources inside the executable") | ||
17 | set (EMBED_RESOURCES | 19 | set (EMBED_RESOURCES |
18 | res/SourceSansPro-Regular.ttf | 20 | res/SourceSansPro-Regular.ttf |
19 | res/FiraSans-Regular.ttf | 21 | res/FiraSans-Regular.ttf |
@@ -21,15 +23,19 @@ set (EMBED_RESOURCES | |||
21 | res/FiraSans-Italic.ttf | 23 | res/FiraSans-Italic.ttf |
22 | res/FiraMono-Regular.ttf | 24 | res/FiraMono-Regular.ttf |
23 | res/NotoEmoji-Regular.ttf | 25 | res/NotoEmoji-Regular.ttf |
24 | res/SymbolaSubset.ttf | 26 | res/Symbola.ttf |
25 | ) | 27 | ) |
26 | # if (UNIX AND NOT APPLE) | 28 | # if (UNIX AND NOT APPLE) |
27 | # list (APPEND EMBED_RESOURCES res/appicon-64.png) | 29 | # list (APPEND EMBED_RESOURCES res/appicon-64.png) |
28 | # endif () | 30 | # endif () |
29 | embed_make (${EMBED_RESOURCES}) | 31 | embed_make (${EMBED_RESOURCES}) |
30 | 32 | ||
33 | set (EMB_BIN ${CMAKE_CURRENT_BINARY_DIR}/resources.bin) | ||
34 | set_source_files_properties (${EMB_BIN} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) | ||
35 | |||
31 | # Source files. | 36 | # Source files. |
32 | set (SOURCES | 37 | set (SOURCES |
38 | ${CMAKE_CURRENT_BINARY_DIR}/resources.bin | ||
33 | ${CMAKE_CURRENT_BINARY_DIR}/embedded.c | 39 | ${CMAKE_CURRENT_BINARY_DIR}/embedded.c |
34 | ${CMAKE_CURRENT_BINARY_DIR}/embedded.h | 40 | ${CMAKE_CURRENT_BINARY_DIR}/embedded.h |
35 | src/main.c | 41 | src/main.c |
diff --git a/res/Symbola.ttf b/res/Symbola.ttf new file mode 100644 index 00000000..59e428fe --- /dev/null +++ b/res/Symbola.ttf | |||
Binary files differ | |||
@@ -32,12 +32,15 @@ | |||
32 | iDeclareType(App) | 32 | iDeclareType(App) |
33 | 33 | ||
34 | #if defined (iPlatformApple) | 34 | #if defined (iPlatformApple) |
35 | #define EMB_BIN "../../Resources/resources.bin" | ||
35 | static const char *dataDir_App_ = "~/Library/Application Support/fi.skyjake.Lagrange"; | 36 | static const char *dataDir_App_ = "~/Library/Application Support/fi.skyjake.Lagrange"; |
36 | #endif | 37 | #endif |
37 | #if defined (iPlatformMsys) | 38 | #if defined (iPlatformMsys) |
39 | #define EMB_BIN "../resources.bin" | ||
38 | static const char *dataDir_App_ = "~/AppData/Roaming/fi.skyjake.Lagrange"; | 40 | static const char *dataDir_App_ = "~/AppData/Roaming/fi.skyjake.Lagrange"; |
39 | #endif | 41 | #endif |
40 | #if defined (iPlatformLinux) | 42 | #if defined (iPlatformLinux) |
43 | #define EMB_BIN "../../share/lagrange/resources.bin" | ||
41 | static const char *dataDir_App_ = "~/.config/lagrange"; | 44 | static const char *dataDir_App_ = "~/.config/lagrange"; |
42 | #endif | 45 | #endif |
43 | static const char *prefsFileName_App_ = "prefs.cfg"; | 46 | static const char *prefsFileName_App_ = "prefs.cfg"; |
@@ -146,8 +149,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
146 | load_History(d->history, dataDir_App_); | 149 | load_History(d->history, dataDir_App_); |
147 | #if defined (iHaveLoadEmbed) | 150 | #if defined (iHaveLoadEmbed) |
148 | /* Load the resources from a file. */ { | 151 | /* Load the resources from a file. */ { |
149 | if (!load_Embed( | 152 | if (!load_Embed(concatPath_CStr(cstr_String(execPath_App()), EMB_BIN))) { |
150 | cstr_String(collect_String(concatCStr_Path(execPath_App(), "../resources.bin"))))) { | ||
151 | fprintf(stderr, "failed to load resources.bin\n"); | 153 | fprintf(stderr, "failed to load resources.bin\n"); |
152 | exit(-1); | 154 | exit(-1); |
153 | } | 155 | } |
diff --git a/src/history.c b/src/history.c index 884e8592..edffd485 100644 --- a/src/history.c +++ b/src/history.c | |||
@@ -66,12 +66,12 @@ static void writeItems_(const iArray *items, iFile *f) { | |||
66 | } | 66 | } |
67 | 67 | ||
68 | void save_History(const iHistory *d, const char *dirPath) { | 68 | void save_History(const iHistory *d, const char *dirPath) { |
69 | iFile *f = new_File(concatPath_CStr(dirPath, "recent.txt")); | 69 | iFile *f = newCStr_File(concatPath_CStr(dirPath, "recent.txt")); |
70 | if (open_File(f, writeOnly_FileMode | text_FileMode)) { | 70 | if (open_File(f, writeOnly_FileMode | text_FileMode)) { |
71 | writeItems_(&d->stack, f); | 71 | writeItems_(&d->stack, f); |
72 | } | 72 | } |
73 | iRelease(f); | 73 | iRelease(f); |
74 | f = new_File(concatPath_CStr(dirPath, "visited.txt")); | 74 | f = newCStr_File(concatPath_CStr(dirPath, "visited.txt")); |
75 | if (open_File(f, writeOnly_FileMode | text_FileMode)) { | 75 | if (open_File(f, writeOnly_FileMode | text_FileMode)) { |
76 | writeItems_(&d->visitedUrls.values, f); | 76 | writeItems_(&d->visitedUrls.values, f); |
77 | } | 77 | } |
@@ -101,12 +101,12 @@ static void loadItems_(iArray *items, iFile *f, double maxAge) { | |||
101 | } | 101 | } |
102 | 102 | ||
103 | void load_History(iHistory *d, const char *dirPath) { | 103 | void load_History(iHistory *d, const char *dirPath) { |
104 | iFile *f = new_File(concatPath_CStr(dirPath, "recent.txt")); | 104 | iFile *f = newCStr_File(concatPath_CStr(dirPath, "recent.txt")); |
105 | if (open_File(f, readOnly_FileMode | text_FileMode)) { | 105 | if (open_File(f, readOnly_FileMode | text_FileMode)) { |
106 | loadItems_(&d->stack, f, 0); | 106 | loadItems_(&d->stack, f, 0); |
107 | } | 107 | } |
108 | iRelease(f); | 108 | iRelease(f); |
109 | f = new_File(concatPath_CStr(dirPath, "visited.txt")); | 109 | f = newCStr_File(concatPath_CStr(dirPath, "visited.txt")); |
110 | if (open_File(f, readOnly_FileMode | text_FileMode)) { | 110 | if (open_File(f, readOnly_FileMode | text_FileMode)) { |
111 | loadItems_(&d->visitedUrls.values, f, maxAgeVisited_History_); | 111 | loadItems_(&d->visitedUrls.values, f, maxAgeVisited_History_); |
112 | } | 112 | } |
@@ -222,6 +222,7 @@ iTime urlVisitTime_History(const iHistory *d, const iString *url) { | |||
222 | } | 222 | } |
223 | 223 | ||
224 | void print_History(const iHistory *d) { | 224 | void print_History(const iHistory *d) { |
225 | iUnused(d); | ||
225 | #if 0 | 226 | #if 0 |
226 | iConstForEach(Array, i, &d->history) { | 227 | iConstForEach(Array, i, &d->history) { |
227 | const size_t idx = index_ArrayConstIterator(&i); | 228 | const size_t idx = index_ArrayConstIterator(&i); |
diff --git a/src/ui/text.c b/src/ui/text.c index 40008963..dee693e4 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -155,11 +155,11 @@ void init_Text(SDL_Renderer *render) { | |||
155 | { &fontFiraSansBold_Embedded, fontSize_UI * 1.333f, mediumSymbols_FontId }, | 155 | { &fontFiraSansBold_Embedded, fontSize_UI * 1.333f, mediumSymbols_FontId }, |
156 | { &fontFiraSansBold_Embedded, fontSize_UI * 1.666f, largeSymbols_FontId }, | 156 | { &fontFiraSansBold_Embedded, fontSize_UI * 1.666f, largeSymbols_FontId }, |
157 | { &fontFiraSansBold_Embedded, fontSize_UI * 2.000f, hugeSymbols_FontId }, | 157 | { &fontFiraSansBold_Embedded, fontSize_UI * 2.000f, hugeSymbols_FontId }, |
158 | { &fontSymbolaSubset_Embedded, fontSize_UI, symbols_FontId }, | 158 | { &fontSymbola_Embedded, fontSize_UI, symbols_FontId }, |
159 | { &fontSymbolaSubset_Embedded, fontSize_UI * 1.333f, mediumSymbols_FontId }, | 159 | { &fontSymbola_Embedded, fontSize_UI * 1.333f, mediumSymbols_FontId }, |
160 | { &fontSymbolaSubset_Embedded, fontSize_UI * 1.666f, largeSymbols_FontId }, | 160 | { &fontSymbola_Embedded, fontSize_UI * 1.666f, largeSymbols_FontId }, |
161 | { &fontSymbolaSubset_Embedded, fontSize_UI * 2.000f, hugeSymbols_FontId }, | 161 | { &fontSymbola_Embedded, fontSize_UI * 2.000f, hugeSymbols_FontId }, |
162 | { &fontSymbolaSubset_Embedded, fontSize_UI * 0.866f, smallSymbols_FontId }, | 162 | { &fontSymbola_Embedded, fontSize_UI * 0.866f, smallSymbols_FontId }, |
163 | { &fontNotoEmojiRegular_Embedded, fontSize_UI, symbols_FontId }, | 163 | { &fontNotoEmojiRegular_Embedded, fontSize_UI, symbols_FontId }, |
164 | { &fontNotoEmojiRegular_Embedded, fontSize_UI * 1.333f, mediumSymbols_FontId }, | 164 | { &fontNotoEmojiRegular_Embedded, fontSize_UI * 1.333f, mediumSymbols_FontId }, |
165 | { &fontNotoEmojiRegular_Embedded, fontSize_UI * 1.666f, largeSymbols_FontId }, | 165 | { &fontNotoEmojiRegular_Embedded, fontSize_UI * 1.666f, largeSymbols_FontId }, |
@@ -280,17 +280,19 @@ static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) { | |||
280 | } | 280 | } |
281 | } | 281 | } |
282 | 282 | ||
283 | iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch) { | 283 | iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch) { |
284 | if (stbtt_FindGlyphIndex(&d->font, ch) != 0) { | 284 | if (stbtt_FindGlyphIndex(&d->font, ch) != 0) { |
285 | return d; | 285 | return d; |
286 | } | 286 | } |
287 | /* Not defined in current font, try symbols. */ | 287 | /* Not defined in current font, try Noto Emoji (for selected characters). */ |
288 | iFont *symbols = font_Text_(d->symbolsFont); | 288 | if ((ch >= 0x1f300 && ch < 0x1f600) || (ch >= 0x1f680 && ch <= 0x1f6c5)) { |
289 | if (symbols != d && stbtt_FindGlyphIndex(&symbols->font, ch)) { | 289 | iFont *emoji = font_Text_(d->symbolsFont + fromSymbolsToEmojiOffset_FontId); |
290 | return symbols; | 290 | if (emoji != d && stbtt_FindGlyphIndex(&emoji->font, ch)) { |
291 | return emoji; | ||
292 | } | ||
291 | } | 293 | } |
292 | /* Perhaps it's Emoji. */ | 294 | /* Fall back to Symbola for anything else. */ |
293 | return font_Text_(d->symbolsFont + fromSymbolsToEmojiOffset_FontId); | 295 | return font_Text_(d->symbolsFont); |
294 | } | 296 | } |
295 | 297 | ||
296 | static const iGlyph *glyph_Font_(iFont *d, iChar ch) { | 298 | static const iGlyph *glyph_Font_(iFont *d, iChar ch) { |