Skip to content
This repository was archived by the owner on Feb 19, 2024. It is now read-only.

Commit 80ce3f1

Browse files
committed
actual first commit
1 parent 1e54bf4 commit 80ce3f1

6 files changed

Lines changed: 364 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/*

Cargo.lock

Lines changed: 279 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "gm_fontsx"
3+
authors = ["Earu"]
4+
version = "0.1.0"
5+
edition = "2021"
6+
7+
[lib]
8+
crate-type = ["cdylib"]
9+
10+
[dependencies]
11+
gmod = { version = "*", default-features = false, features = ["gmcl"] }
12+
font-loader = "0.11.0"

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# gm_fontsx
2-
Check what fonts are installed and available on your system.
2+
Since apparently we're never getting a proper way to check for installed fonts on Garry's Mod, this has to exist 😒
3+
4+
### Usage
5+
```lua
6+
require("fontsx")
7+
8+
-- creates a gmod virtual font depending on whether the system font "Consolas" is available
9+
surface.CreateFont("my_virtual_font", {
10+
font = fonts.Exists("Consolas") and "Consolas" or "Roboto",
11+
size = 15,
12+
})
13+
```
14+
15+
```lua
16+
require("fontsx")
17+
18+
-- prints all system fonts currently available
19+
PrintTable(fonts.GetAll())
20+
```
321

422
### Compiling
523
- Open a terminal

rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly"

src/lib.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#![feature(c_unwind)]
2+
3+
#[macro_use]
4+
extern crate gmod;
5+
extern crate font_loader as fonts;
6+
7+
use fonts::system_fonts;
8+
9+
#[lua_function]
10+
unsafe fn get_installed_fonts(lua: gmod::lua::State) -> i32 {
11+
let sys_fonts = system_fonts::query_all();
12+
13+
lua.new_table();
14+
for (i, font) in sys_fonts.iter().enumerate() {
15+
lua.push_integer((i + 1) as isize);
16+
lua.push_string(font.as_str());
17+
lua.set_table(-3);
18+
}
19+
20+
1
21+
}
22+
23+
#[lua_function]
24+
unsafe fn font_exists(lua: gmod::lua::State) -> i32 {
25+
let sys_fonts = system_fonts::query_all();
26+
let input = lua.check_string(1);
27+
let res = sys_fonts.contains(&String::from(input.as_ref()));
28+
29+
lua.push_boolean(res);
30+
1
31+
}
32+
33+
34+
#[gmod13_open]
35+
unsafe fn gmod13_open(lua: gmod::lua::State) -> i32 {
36+
lua.new_table();
37+
38+
lua.push_function(get_installed_fonts);
39+
lua.set_field(-2, lua_string!("GetAll"));
40+
41+
lua.push_function(font_exists);
42+
lua.set_field(-2, lua_string!("Exists"));
43+
44+
lua.set_global(lua_string!("fonts"));
45+
0
46+
}
47+
48+
#[gmod13_close]
49+
unsafe fn gmod13_close(_: gmod::lua::State) -> i32 {
50+
0
51+
}

0 commit comments

Comments
 (0)