Skip to content

Commit c7be1d5

Browse files
committed
feat: Add Font Awesome glyph support
1 parent a38637f commit c7be1d5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ The following `source` values are currently supported:
168168
- `material`: [Google Material Symbols](https://fonts.google.com/icons) (use value in "Android" tab as `id`)
169169
- `tabler`: [Tabler Icons](https://tabler.io/icons) ("Outline" style, use icon name as `id`)
170170
- `phosphor`: [Phosphor Icons](https://phosphoricons.com) (use `<weight>/<name>` as `id`, e.g. `$$phosphor:bold/lock$$`)
171+
- `fa`: [Font Awesome](https://fontawesome.com/search?ic=free) (use `<type>/<name>` as `id` where `type` is `solid`, `regular` or `brands`, e.g. `$$fa:brands/apple$$`)
171172

172173
Fetched SVGs will be [cached by default](CONFIGURATION.md#use_local_cache) to speed up future runs.
173174

keymap_drawer/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ class KeySidePars(BaseModel):
269269
"mdil": "https://raw.githubusercontent.com/Pictogrammers/MaterialDesignLight/master/svg/{}.svg",
270270
"material": "https://fonts.gstatic.com/s/i/short-term/release/materialsymbolsoutlined/{}/default/48px.svg",
271271
"phosphor": "https://unpkg.com/@phosphor-icons/core/assets/{}.svg",
272+
"fa": "https://unpkg.com/@fortawesome/fontawesome-free/svgs/{}.svg",
272273
},
273274
)
274275

keymap_drawer/draw/glyph.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ def _fetch_glyphs(self, names: Iterable[str]) -> dict[str, str]:
8383
if ":" in name: # templated source:ID format
8484
source, glyph_id = name.split(":", maxsplit=1)
8585
if templated_url := self.cfg.glyph_urls.get(source):
86-
if source == "phosphor": # special case to handle variants
87-
assert "/" in glyph_id, "phosphor glyphs should be in `$$phosphor:<type>/<id>$$` format"
88-
ph_type, ph_id = glyph_id.split("/", maxsplit=1)
89-
ph_type = ph_type.lower()
90-
glyph_id = f"{ph_type}/{ph_id}"
91-
if ph_type != "regular":
92-
glyph_id += f"-{ph_type}"
86+
if source in ("phosphor", "fa"): # special case to handle variants
87+
assert "/" in glyph_id, "phosphor/fa glyphs should be in `$$<source>:<type>/<id>$$` format"
88+
sub_type, sub_id = glyph_id.split("/", maxsplit=1)
89+
sub_type = sub_type.lower()
90+
glyph_id = f"{sub_type}/{sub_id}"
91+
if source == "phosphor" and sub_type != "regular":
92+
glyph_id += f"-{sub_type}"
9393
urls.append(templated_url.format(glyph_id))
9494
if url := self.cfg.glyph_urls.get(name): # source only
9595
urls.append(url)

0 commit comments

Comments
 (0)