summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-26 20:13:07 +0100
committersalmonik <salmonik@tuta.io>2026-10-26 20:13:07 +0100
commit76b6485a33094b40e8f833c32dc84457055062ec (patch)
tree667bffc5d38a800204656931ca3693ed3e801016
parentBones: head fallback for headcrab black/fast (diff)
downloadhl2h-76b6485a33094b40e8f833c32dc84457055062ec.tar.gz
hl2h-76b6485a33094b40e8f833c32dc84457055062ec.zip
Fonts: bundle Liberation Sans and register it with fontconfig
- ship assets/LiberationSans-Regular.ttf (+ OFL license/README) - at startup, resolve the .so path via dladdr, add assets/...ttf to the current fontconfig config with FcConfigAppFontAddFile, and fall back to the system Liberation path if the asset is missing - font creation tries Liberation Sans, then DejaVu Sans/Noto/Tahoma/Verdana/ Arial, so the overlay still renders on installs without the bundled font
Diffstat (limited to '')
-rw-r--r--assets/LiberationSans-Regular.ttfbin0 -> 410820 bytes
-rw-r--r--assets/OFL.txt94
-rw-r--r--assets/README.md9
-rw-r--r--src/menu.cpp87
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 @@
1Digitized data copyright (c) 2010 Google Corporation
2 with Reserved Font Arimo, Tinos and Cousine.
3Copyright (c) 2012 Red Hat, Inc.
4 with Reserved Font Name Liberation.
5
6This Font Software is licensed under the SIL Open Font License,
7Version 1.1.
8
9This license is copied below, and is also available with a FAQ at:
10http://scripts.sil.org/OFL
11
12SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
13
14PREAMBLE The goals of the Open Font License (OFL) are to stimulate
15worldwide development of collaborative font projects, to support the font
16creation efforts of academic and linguistic communities, and to provide
17a free and open framework in which fonts may be shared and improved in
18partnership with others.
19
20The OFL allows the licensed fonts to be used, studied, modified and
21redistributed freely as long as they are not sold by themselves.
22The fonts, including any derivative works, can be bundled, embedded,
23redistributed and/or sold with any software provided that any reserved
24names are not used by derivative works. The fonts and derivatives,
25however, cannot be released under any other type of license. The
26requirement for fonts to remain under this license does not apply to
27any document created using the fonts or their derivatives.
28
29DEFINITIONS
30"Font Software" refers to the set of files released by the Copyright
31Holder(s) under this license and clearly marked as such.
32This may include source files, build scripts and documentation.
33
34"Reserved Font Name" refers to any names specified as such after the
35copyright statement(s).
36
37"Original Version" refers to the collection of Font Software components
38as distributed by the Copyright Holder(s).
39
40"Modified Version" refers to any derivative made by adding to, deleting,
41or substituting ? in part or in whole ?
42any of the components of the Original Version, by changing formats or
43by porting the Font Software to a new environment.
44
45"Author" refers to any designer, engineer, programmer, technical writer
46or other person who contributed to the Font Software.
47
48PERMISSION & CONDITIONS
49
50Permission is hereby granted, free of charge, to any person obtaining a
51copy of the Font Software, to use, study, copy, merge, embed, modify,
52redistribute, and sell modified and unmodified copies of the Font
53Software, subject to the following conditions:
54
551) Neither the Font Software nor any of its individual components,in
56 Original or Modified Versions, may be sold by itself.
57
582) 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
653) 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
704) 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
765) 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
82TERMINATION
83This license becomes null and void if any of the above conditions are not met.
84
85DISCLAIMER
86THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
88MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
89OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
90COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
91INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
92DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
94DEALINGS 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
4Liberation Fonts project (https://github.com/liberationfonts/liberation-fonts).
5
6Licensed 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
9does 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).
225void 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 *)&register_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
220static void config_save() { 279static 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
790void install_menu() { 856void 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