diff options
Diffstat (limited to '')
| -rw-r--r-- | assets/LiberationSans-Regular.ttf | bin | 0 -> 410820 bytes | |||
| -rw-r--r-- | assets/OFL.txt | 94 | ||||
| -rw-r--r-- | assets/README.md | 9 | ||||
| -rw-r--r-- | src/menu.cpp | 87 |
4 files changed, 180 insertions, 10 deletions
diff --git a/assets/LiberationSans-Regular.ttf b/assets/LiberationSans-Regular.ttf new file mode 100644 index 0000000..adb8947 --- /dev/null +++ b/assets/LiberationSans-Regular.ttf | |||
| Binary files differ | |||
diff --git a/assets/OFL.txt b/assets/OFL.txt new file mode 100644 index 0000000..445c414 --- /dev/null +++ b/assets/OFL.txt | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | Digitized data copyright (c) 2010 Google Corporation | ||
| 2 | with Reserved Font Arimo, Tinos and Cousine. | ||
| 3 | Copyright (c) 2012 Red Hat, Inc. | ||
| 4 | with Reserved Font Name Liberation. | ||
| 5 | |||
| 6 | This Font Software is licensed under the SIL Open Font License, | ||
| 7 | Version 1.1. | ||
| 8 | |||
| 9 | This license is copied below, and is also available with a FAQ at: | ||
| 10 | http://scripts.sil.org/OFL | ||
| 11 | |||
| 12 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 | ||
| 13 | |||
| 14 | PREAMBLE The goals of the Open Font License (OFL) are to stimulate | ||
| 15 | worldwide development of collaborative font projects, to support the font | ||
| 16 | creation efforts of academic and linguistic communities, and to provide | ||
| 17 | a free and open framework in which fonts may be shared and improved in | ||
| 18 | partnership with others. | ||
| 19 | |||
| 20 | The OFL allows the licensed fonts to be used, studied, modified and | ||
| 21 | redistributed freely as long as they are not sold by themselves. | ||
| 22 | The fonts, including any derivative works, can be bundled, embedded, | ||
| 23 | redistributed and/or sold with any software provided that any reserved | ||
| 24 | names are not used by derivative works. The fonts and derivatives, | ||
| 25 | however, cannot be released under any other type of license. The | ||
| 26 | requirement for fonts to remain under this license does not apply to | ||
| 27 | any document created using the fonts or their derivatives. | ||
| 28 | |||
| 29 | DEFINITIONS | ||
| 30 | "Font Software" refers to the set of files released by the Copyright | ||
| 31 | Holder(s) under this license and clearly marked as such. | ||
| 32 | This may include source files, build scripts and documentation. | ||
| 33 | |||
| 34 | "Reserved Font Name" refers to any names specified as such after the | ||
| 35 | copyright statement(s). | ||
| 36 | |||
| 37 | "Original Version" refers to the collection of Font Software components | ||
| 38 | as distributed by the Copyright Holder(s). | ||
| 39 | |||
| 40 | "Modified Version" refers to any derivative made by adding to, deleting, | ||
| 41 | or substituting ? in part or in whole ? | ||
| 42 | any of the components of the Original Version, by changing formats or | ||
| 43 | by porting the Font Software to a new environment. | ||
| 44 | |||
| 45 | "Author" refers to any designer, engineer, programmer, technical writer | ||
| 46 | or other person who contributed to the Font Software. | ||
| 47 | |||
| 48 | PERMISSION & CONDITIONS | ||
| 49 | |||
| 50 | Permission is hereby granted, free of charge, to any person obtaining a | ||
| 51 | copy of the Font Software, to use, study, copy, merge, embed, modify, | ||
| 52 | redistribute, and sell modified and unmodified copies of the Font | ||
| 53 | Software, subject to the following conditions: | ||
| 54 | |||
| 55 | 1) Neither the Font Software nor any of its individual components,in | ||
| 56 | Original or Modified Versions, may be sold by itself. | ||
| 57 | |||
| 58 | 2) Original or Modified Versions of the Font Software may be bundled, | ||
| 59 | redistributed and/or sold with any software, provided that each copy | ||
| 60 | contains the above copyright notice and this license. These can be | ||
| 61 | included either as stand-alone text files, human-readable headers or | ||
| 62 | in the appropriate machine-readable metadata fields within text or | ||
| 63 | binary files as long as those fields can be easily viewed by the user. | ||
| 64 | |||
| 65 | 3) No Modified Version of the Font Software may use the Reserved Font | ||
| 66 | Name(s) unless explicit written permission is granted by the | ||
| 67 | corresponding Copyright Holder. This restriction only applies to the | ||
| 68 | primary font name as presented to the users. | ||
| 69 | |||
| 70 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font | ||
| 71 | Software shall not be used to promote, endorse or advertise any | ||
| 72 | Modified Version, except to acknowledge the contribution(s) of the | ||
| 73 | Copyright Holder(s) and the Author(s) or with their explicit written | ||
| 74 | permission. | ||
| 75 | |||
| 76 | 5) The Font Software, modified or unmodified, in part or in whole, must | ||
| 77 | be distributed entirely under this license, and must not be distributed | ||
| 78 | under any other license. The requirement for fonts to remain under | ||
| 79 | this license does not apply to any document created using the Font | ||
| 80 | Software. | ||
| 81 | |||
| 82 | TERMINATION | ||
| 83 | This license becomes null and void if any of the above conditions are not met. | ||
| 84 | |||
| 85 | DISCLAIMER | ||
| 86 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 87 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
| 88 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
| 89 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE | ||
| 90 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| 91 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
| 92 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 93 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER | ||
| 94 | DEALINGS IN THE FONT SOFTWARE. | ||
diff --git a/assets/README.md b/assets/README.md new file mode 100644 index 0000000..a4afd45 --- /dev/null +++ b/assets/README.md | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # Bundled font | ||
| 2 | |||
| 3 | `LiberationSans-Regular.ttf` is the Liberation Sans regular face from the | ||
| 4 | Liberation Fonts project (https://github.com/liberationfonts/liberation-fonts). | ||
| 5 | |||
| 6 | Licensed under the SIL Open Font License 1.1; see `OFL.txt`. | ||
| 7 | |||
| 8 | `hl2hake` registers this file with fontconfig at startup so the VGUI overlay | ||
| 9 | does not depend on the host/game install having Liberation Sans installed. | ||
diff --git a/src/menu.cpp b/src/menu.cpp index 9537e05..1ef8638 100644 --- a/src/menu.cpp +++ b/src/menu.cpp | |||
| @@ -4,7 +4,9 @@ | |||
| 4 | #include <cstdio> | 4 | #include <cstdio> |
| 5 | #include <cstdlib> | 5 | #include <cstdlib> |
| 6 | #include <cstring> | 6 | #include <cstring> |
| 7 | #include <dlfcn.h> | ||
| 7 | #include <sys/stat.h> | 8 | #include <sys/stat.h> |
| 9 | #include <unistd.h> | ||
| 8 | 10 | ||
| 9 | // --------------------------------------------------------------------------- | 11 | // --------------------------------------------------------------------------- |
| 10 | // ConMsg (tier0 console printer — prints to in-game console) | 12 | // ConMsg (tier0 console printer — prints to in-game console) |
| @@ -217,6 +219,63 @@ static std::string config_path() { | |||
| 217 | return dir + "/config"; | 219 | return dir + "/config"; |
| 218 | } | 220 | } |
| 219 | 221 | ||
| 222 | // Register the bundled Liberation Sans with fontconfig so the VGUI overlay | ||
| 223 | // does not depend on the host/game install having it. The font file lives in | ||
| 224 | // assets/ next to the .so (or the system path as a fallback). | ||
| 225 | void register_bundled_font() { | ||
| 226 | static bool done = false; | ||
| 227 | if (done) | ||
| 228 | return; | ||
| 229 | done = true; | ||
| 230 | |||
| 231 | std::string path; | ||
| 232 | Dl_info info; | ||
| 233 | if (dladdr((void *)®ister_bundled_font, &info) && info.dli_fname) { | ||
| 234 | char resolved[4096]; | ||
| 235 | const char *lib = realpath(info.dli_fname, resolved); | ||
| 236 | std::string p = lib ? resolved : info.dli_fname; | ||
| 237 | size_t slash = p.find_last_of('/'); | ||
| 238 | if (slash != std::string::npos) | ||
| 239 | p.resize(slash + 1); | ||
| 240 | else | ||
| 241 | p = "./"; | ||
| 242 | p += "assets/LiberationSans-Regular.ttf"; | ||
| 243 | if (access(p.c_str(), R_OK) == 0) | ||
| 244 | path = p; | ||
| 245 | } | ||
| 246 | if (path.empty()) { | ||
| 247 | const char *sys = "/usr/share/fonts/liberation/LiberationSans-Regular.ttf"; | ||
| 248 | if (access(sys, R_OK) == 0) | ||
| 249 | path = sys; | ||
| 250 | } | ||
| 251 | if (path.empty()) { | ||
| 252 | logf("font: bundled LiberationSans-Regular.ttf not found"); | ||
| 253 | return; | ||
| 254 | } | ||
| 255 | |||
| 256 | void *fc = dlopen("libfontconfig.so.1", RTLD_LAZY | RTLD_GLOBAL); | ||
| 257 | if (!fc) { | ||
| 258 | logf("font: libfontconfig.so.1 not available"); | ||
| 259 | return; | ||
| 260 | } | ||
| 261 | using InitFn = int (*)(); | ||
| 262 | using GetCurrentFn = void *(*)(); | ||
| 263 | using AddFileFn = int (*)(void *, const char *); | ||
| 264 | auto init = (InitFn)dlsym(fc, "FcInit"); | ||
| 265 | auto get = (GetCurrentFn)dlsym(fc, "FcConfigGetCurrent"); | ||
| 266 | auto add = (AddFileFn)dlsym(fc, "FcConfigAppFontAddFile"); | ||
| 267 | if (!init || !get || !add) { | ||
| 268 | logf("font: fontconfig symbols missing"); | ||
| 269 | return; | ||
| 270 | } | ||
| 271 | init(); | ||
| 272 | void *cfg = get(); | ||
| 273 | if (cfg && add(cfg, path.c_str())) | ||
| 274 | logf("font: registered %s", path.c_str()); | ||
| 275 | else | ||
| 276 | logf("font: failed to register %s", path.c_str()); | ||
| 277 | } | ||
| 278 | |||
| 220 | static void config_save() { | 279 | static void config_save() { |
| 221 | FILE *f = fopen(config_path().c_str(), "w"); | 280 | FILE *f = fopen(config_path().c_str(), "w"); |
| 222 | if (!f) | 281 | if (!f) |
| @@ -671,17 +730,24 @@ void outer_draw() { | |||
| 671 | if (!g_surface || (!g_menu_open && !draw_test && !esp_on)) | 730 | if (!g_surface || (!g_menu_open && !draw_test && !esp_on)) |
| 672 | return; | 731 | return; |
| 673 | if (!g_font) { | 732 | if (!g_font) { |
| 674 | g_font = surf_create_font(); | 733 | static const char *families[] = { |
| 675 | if (!g_font) { | 734 | "Liberation Sans", "DejaVu Sans", "Noto Sans", "Tahoma", |
| 676 | logf("outer_draw: CreateFont failed"); | 735 | "Verdana", "Arial", nullptr}; |
| 677 | return; | 736 | bool font_ok = false; |
| 737 | for (int fi = 0; families[fi] && !font_ok; fi++) { | ||
| 738 | g_font = surf_create_font(); | ||
| 739 | if (!g_font) | ||
| 740 | continue; | ||
| 741 | if (surf_set_font_glyph_set(g_font, families[fi], 16, 400, 0, 0, 0x400, | ||
| 742 | 0x20, 0xFF)) { | ||
| 743 | logf("outer_draw: font family %s", families[fi]); | ||
| 744 | font_ok = true; | ||
| 745 | } else { | ||
| 746 | g_font = 0; | ||
| 747 | } | ||
| 678 | } | 748 | } |
| 679 | // FONTFLAG_CUSTOM only; Liberation Sans is an installed real TTF (Verdana | 749 | if (!font_ok) { |
| 680 | // substitutes to Noto). Raw glyphs, ASCII range pinned. | 750 | logf("outer_draw: no usable font"); |
| 681 | if (!surf_set_font_glyph_set(g_font, "Liberation Sans", 16, 400, 0, 0, | ||
| 682 | 0x400, 0x20, 0xFF)) { | ||
| 683 | logf("outer_draw: SetFontGlyphSet failed"); | ||
| 684 | g_font = 0; | ||
| 685 | return; | 751 | return; |
| 686 | } | 752 | } |
| 687 | } | 753 | } |
| @@ -789,6 +855,7 @@ static ISurface *find_surface_interface() { | |||
| 789 | 855 | ||
| 790 | void install_menu() { | 856 | void install_menu() { |
| 791 | build_tree(); | 857 | build_tree(); |
| 858 | register_bundled_font(); | ||
| 792 | logf("config: %s", config_path().c_str()); | 859 | logf("config: %s", config_path().c_str()); |
| 793 | config_load(); | 860 | config_load(); |
| 794 | // resolve ISurface once (used by the DrawPrintText hook in hl2h.cpp and | 861 | // resolve ISurface once (used by the DrawPrintText hook in hl2h.cpp and |
