egui_nerdfonts
1.0.0
捆绑书呆子字体为egui。
将板条板添加为货物中的依赖性:toml:
egui_nerdfonts = " 0.1.3 "或在您的项目中键入cargo add egui_nerdfonts 。
首先,在您的egui上下文中更新字体:
let mut fonts = egui :: FontDefinitions :: default ( ) ;
egui_nerdfonts :: add_to_fonts ( & mut fonts , egui_nerdfonts :: Variant :: Regular ) ;
let egui_ctx = Context :: default ( ) ;
egui_ctx . set_fonts ( fonts ) ;选择您要在其中使用的Nerdfonts图标。
然后使用nerdfonts图标如下:
ui . label ( format ! ( "{}" , egui_nerdfonts :: regular :: NF_DEV_RUST ) ) ; cargo run --example rust_logo

受到eGUI_Phosphor的启发,代码使用相同的结构。
使用的.ttf是此的,并且使用以下python脚本生成src/variants/regular.rs , nerdfonts_regular.ttf作为第一个参数:
from itertools import chain
from fontTools . ttLib import TTFont
from fontTools . unicode import Unicode
import sys
with TTFont (
sys . argv [ 1 ], 0 , allowVID = 0 , ignoreDecompileErrors = True , fontNumber = - 1
) as ttf :
chars = chain . from_iterable (
[ y + ( Unicode [ y [ 0 ]],) for y in x . cmap . items ()] for x in ttf [ "cmap" ]. tables
)
for char in chars :
symbol_name = char [ 1 ]. upper (). replace ( '-' , '_' ). replace ( ' ' , '_' ). replace ( '#' , '_' ). replace ( '!' , '' )
code = r"u" + "{" + f" { char [ 0 ]:X } " + "}"
print ( f"pub const { symbol_name } : &str = " { code } " ;" )