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 } " ;" )