-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rust11.html
352 lines (192 loc) · 23.6 KB
/
Rust11.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- iOS Safari -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!-- Chrome, Firefox OS and Opera Status Bar Color -->
<meta name="theme-color" content="#FFFFFF">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css">
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.19.0/themes/prism.min.css">
<link rel="stylesheet" type="text/css" href="css/SourceSansPro.css">
<link rel="stylesheet" type="text/css" href="css/theme.css">
<link rel="stylesheet" type="text/css" href="css/notablog.css">
<link rel="stylesheet" type="text/css" href="css/CustomSetting.css">
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🥥</text></svg>">
<style>
:root {
font-size: 20px;
}
</style>
<title>Rust 驱动 LCD - 显示中英文 | 413’s Website</title>
<meta property="og:type" content="blog">
<meta property="og:title" content="Rust 驱动 LCD - 显示中英文">
<meta property="og:image" content="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🦀</text></svg>">
<style>
.DateTagBar {
margin-top: 1.0rem;
}
</style>
</head>
<body>
<nav class="Navbar">
<a href="index.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🥥</text></svg>"></span>
<span>Home</span>
</div>
</a>
<span class="Navbar__Delim">·</span>
<a href="blog-collection.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🥅</text></svg>"></span>
<span>blog mark</span>
</div>
</a>
<span class="Navbar__Delim">·</span>
<a href="Note.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🎶</text></svg>"></span>
<span>Note</span>
</div>
</a>
<span class="Navbar__Delim">·</span>
<a href="reference.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>😷</text></svg>"></span>
<span>杂项</span>
</div>
</a>
<span class="Navbar__Delim">·</span>
<a href="About.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>😀</text></svg>"></span>
<span>About</span>
</div>
</a>
</nav>
<header class="Header">
<div class="Header__Spacer Header__Spacer--NoCover">
</div>
<div class="Header__Icon">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🦀</text></svg>"></span>
</div>
<h1 class="Header__Title">Rust 驱动 LCD - 显示中英文</h1>
<div class="DateTagBar">
<span class="DateTagBar__Item DateTagBar__Date">Posted on Mon, Sep 2, 2024</span>
<span class="DateTagBar__Item DateTagBar__Tag DateTagBar__Tag--purple">
<a href="tag/Rust.html">Rust</a>
</span>
<span class="DateTagBar__Item DateTagBar__Tag DateTagBar__Tag--red">
<a href="tag/单片机.html">单片机</a>
</span>
</div>
</header>
<div id="content-html"></div>
<article id="https://www.notion.so/dbcba38fca724a89b970305b0b39f3b3" class="PageRoot PageRoot--FullWidth"><div id="https://www.notion.so/11916030c8214641ae9d82a00ba8f20b" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">embedded-graphics 支持 BDF 和 MonoFont 字体:</mark></span></span></p></div><ul class="BulletedListWrapper"><li id="https://www.notion.so/624f15fe41a54c3d8e36499509228273" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">优先选择 BDF 字体, 特别是是中英文混合显示场景, MonoFont 由于中英文等宽, 会导致英文字体显示间距过大.</mark></span></span></li><li id="https://www.notion.so/6b405d15ebb6489d984a7464e7d5944c" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">优先选择 embedded-graphics/bdf 方案.</mark></span></span></li></ul><div id="https://www.notion.so/88871e05264c4df9b03503d0ed3b13a0" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">The draw method for text drawables returns </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">the position of the next character</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">. This can be used to combine text with different character styles on a single line of text.</mark></span></span></p></div><div id="https://www.notion.so/9cb5bd3fcd624eb881c3ba2d87c8f253" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><pre id="https://www.notion.so/150aff9596284256bb447246666383f0" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>// https://docs.rs/embedded-graphics/latest/embedded_graphics/text/index.html#examples
// Create a small and a large character style.
let small_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
let large_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
// Draw the first text at (20, 30) using the small character style.
let next = Text::new("small ", Point::new(20, 30), small_style).draw(&mut display)?;
// Draw the second text after the first text using the large character style.
let next = Text::new("large", next, large_style).draw(&mut display)?;</span></span></span></code></pre><div id="https://www.notion.so/b559651413cd4607af966f9adfe71cc0" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">字体参考:</mark></span><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/olikraus/u8g2"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://github.com/olikraus/u8g2</mark></a></span></span></p></div><h2 id="https://www.notion.so/d3b4f566a7b344eeb45fd7875ab6cc34" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--2"><a class="Anchor" href="#https://www.notion.so/d3b4f566a7b344eeb45fd7875ab6cc34"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">1 embedded-graphics/bdf </mark></span><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://blog.opsnull.com/rust-embedded/rust-lcd-cjk-font/#embedded-graphics-bdf"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">#</mark></a></span></span></h2><div id="https://www.notion.so/f47a4a0eface4b86b01f69c4b5b46a9c" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/embedded-graphics/bdf/tree/master"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://github.com/embedded-graphics/bdf/tree/master</mark></a></span></span></p></div><div id="https://www.notion.so/91306c974cc64ed49c682e2c40df7b1c" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">该库可以从 bdf 字体文件中生成 embedded-graphics 能使用的:</mark></span></span></p></div><ol class="NumberedListWrapper"><li id="https://www.notion.so/4d52d42516114ad1b1dab19de4824f10" class="NumberedList" value="1"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">BDF Font:需要配合使用</mark></span><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/embedded-graphics/bdf/blob/master/eg-bdf/src/text.rs"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">embedded-graphics/bdf/eg-bdf</mark></a></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 库中提供的 BdfFont/BdfGlyph/BdfTextStyle 类型;</mark></span></span></li><li id="https://www.notion.so/7d7b2a19c4a14eca9891c79f764be8bb" class="NumberedList" value="2"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">MonoFont:embedded-graphics 可以直接导入使用;</mark></span></span></li></ol><div id="https://www.notion.so/4999d12139ed4fe5bb697ace32e2edc3" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">先使用 otf2bdf 工具将 TTF(truetype font) 字体转换为 BDF(Bitmap Distribution Format) 类型:</mark></span></span></p></div><ul class="BulletedListWrapper"><li id="https://www.notion.so/fb24427e575f43fab63d7a8e66f4f47a" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">对于 X11 使用的 pcf 字体格式,使用 pcf2bdf 工具将它转换为 bdf 格式;</mark></span></span></li><li id="https://www.notion.so/887796512e774514bdb931b159849ce0" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">转换时 -p 参数指定生成的 BDF 字体大小;</mark></span></span></li></ul><div id="https://www.notion.so/ede362b822a6418cb512c50cfb3c6727" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">Copy</mark></span></span></p></div><pre id="https://www.notion.so/2ed5c489cad9448b93248388472c8176" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>brew <span class="token function">install</span> otf2bdf
otf2bdf <span class="token parameter variable">-p</span> <span class="token number">12</span> <span class="token parameter variable">-r</span> <span class="token number">75</span> <span class="token parameter variable">-o</span> LXGWWenKai_Regular.bdf ~/Library/Fonts/LXGWWenKai-Regular.ttf</span></span></span></code></pre><div id="https://www.notion.so/204ad25e5c2f4afd920dbf4fde7bdd8a" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">然后使用 eg-font-converter lib 来生成 BDF 或 MonoFont 字体:</mark></span></span></p></div><ul class="BulletedListWrapper"><li id="https://www.notion.so/fb12f3ec9c8a40a3b26e34a179944817" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">两者都至少包含 2 个文件: bitmap data 文件(.data) 和需要 include!() 到引用的 rs 文件;</mark></span></span></li><li id="https://www.notion.so/b78364a8f8624bfaac815fc25c9fee97" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">MonoFont 的 bitmap 文件是从 png 图片生成的, 故 MonoFont 还会生成 png 文件;</mark></span></span></li></ul><div id="https://www.notion.so/a71c4d6fa2c64c0c883e0a3a0d389ec5" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">生成 BDF 字体示例:</mark></span></span></p></div><div id="https://www.notion.so/8952ff2452054769a759b85ab0e96309" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><pre id="https://www.notion.so/4eb44ab08c28478ba8a9ac8ffb153ec1" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>// /Users/zhangjun/codes/rust/bdf/eg-font-converter/src/bin/my-bdf-font.rs
zj@a:~/codes/rust/bdf/eg-font-converter$ mkdir output
zj@a:~/codes/rust/bdf/eg-font-converter$ ls
Cargo.lock Cargo.toml output/ src/ tests/
zj@a:~/codes/rust/bdf/eg-font-converter$ cat src/bin/my-bdf-font.rs
use eg_font_converter::{FontConverter};
// 中文 unicode 字体范围: https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)
// 使用 .glyphs() 来指定要生成的字符范围
fn main() {
let font = FontConverter::new("/Users/zhangjun/docs/LXGWWenKai_Regular.bdf", "BDF_LXGWWenKai_Regular_FONT")
//.glyphs('a'..='z')
.glyphs('\u{0000}'..='\u{007F}') // ASCII
.glyphs('\u{4E00}'..='\u{9FFF}') // 常用中文字体范围
.glyphs('\u{2E80}'..='\u{2EF3}') // 常见繁体字范围
.missing_glyph_substitute('?') // 替代字符
.convert_eg_bdf()
.unwrap();
font.save("output/").unwrap(); // 结果写入 output 目录下, 存入 new(bdf_file, name) 的 小写 name.rs 文件中.
}
// 运行该程序
zj@a:~/codes/rust/bdf/eg-font-converter$ cargo run --bin my-bdf-font
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.32s
Running `/Users/zhangjun/codes/rust/bdf/target/debug/my-bdf-font`
zj@a:~/codes/rust/bdf/eg-font-converter$ ls output/
bdf_lxgwwenkai_regular_font.data bdf_lxgwwenkai_regular_font.rs
zj@a:~/codes/rust/bdf/eg-font-converter$ ls -l output/
total 4.7M
-rw-r--r-- 1 zhangjun 310K 2 17 15:34 bdf_lxgwwenkai_regular_font.data
-rw-r--r-- 1 zhangjun 4.4M 2 17 15:34 bdf_lxgwwenkai_regular_font.rs
zj@a:~/codes/rust/bdf/eg-font-converter$ head -20 output/bdf_lxgwwenkai_regular_font.rs
const BDF_LXGWWenKai_Regular_FONT: ::eg_bdf::BdfFont = {
const fn rect(
x: i32,
y: i32,
width: u32,
height: u32,
) -> ::embedded_graphics::primitives::Rectangle {
::embedded_graphics::primitives::Rectangle::new(
::embedded_graphics::geometry::Point::new(x, y),
::embedded_graphics::geometry::Size::new(width, height),
)
}
::eg_bdf::BdfFont {
data: include_bytes!("bdf_lxgwwenkai_regular_font.data"),
replacement_character: 63usize,
ascent: 12u32,
descent: 3u32,
glyphs: &[
BdfGlyph {
character: '\0',
zj@a:~/codes/rust/bdf/eg-font-converter$</span></span></span></code></pre><div id="https://www.notion.so/89e23368deca4883b07182c9dc655871" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">使用:</mark></span></span></p></div><div id="https://www.notion.so/b918bed455d9441f955b4d43d030f8f0" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><pre id="https://www.notion.so/1616bd3cfe794905aa8ab5982252bcaa" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/codes/rust/bdf/eg-font-converter$ <span class="token function">cp</span> output/bdf_lxgwwenkai_regular_font.* ~/codes/esp32/st7735-lcd-examples/esp32c3-examples/src/
<span class="token comment"># 添加本地依赖</span>
gzj@a:~/codes/esp32/st7735-lcd-examples/esp32c3-examples$ <span class="token function">grep</span> eg Cargo.toml
eg-bdf <span class="token operator">=</span> <span class="token punctuation">{</span> path <span class="token operator">=</span> <span class="token string">"../../../rust/bdf/eg-bdf/"</span> <span class="token punctuation">}</span> // clone https://github.com/embedded-graphics/bdf 的本地目录</span></span></span></code></pre><div id="https://www.notion.so/c394109839244ef5ad46a51aaca3cbfe" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">代码举例:</mark></span></span></p></div><div id="https://www.notion.so/4b0ae2e95c0045758d650327508806a1" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><pre id="https://www.notion.so/79204b465ea2422abc1a1ea3b8d77166" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>use eg_bdf::{BdfGlyph, BdfTextStyle};
include!("./bdf_lxgwwenkai_regular_font.rs");
fn main() {
let text = "Happy\u{AD}Loong\u{AD}Year!\
Happy Hacking!\
Happy Loong Year!\u{A0}新年快乐!\u{A0}-from Rust ESP32";
let bdf_style = BdfTextStyle::new(&BDF_LXGWWenKai_Regular_FONT, Rgb565::WHITE);
let textbox_style = TextBoxStyleBuilder::new()
.line_height(LineHeight::Pixels(12)) // 字体高度与生成 otf2bdf -p 12 一致
.alignment(HorizontalAlignment::Justified)
.paragraph_spacing(0)
.build();
let mut bounds = Rectangle::new(Point::new(0, 0), Size::new(128, 160));
let mut text_box = TextBox::with_textbox_style(text, bounds, bdf_style, textbox_style);
let next = text_box.draw(&mut display).unwrap();
}</span></span></span></code></pre><div id="https://www.notion.so/c9cb55382ddc46e3ba888852fbf73dc8" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><ul id="https://www.notion.so/a5e67ce1360441bfa16d84addfd7c2cc" class="ColorfulBlock ColorfulBlock--ColorGray TableOfContents"><li class="TableOfContents__Item"><a href="#https://www.notion.so/d3b4f566a7b344eeb45fd7875ab6cc34"><div style="margin-left:0px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">1 embedded-graphics/bdf </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">#</mark></span></span></div></a></li></ul></article>
<aside class="Aside">
<a href="#content-html"><div id="up">👆</div></a>
<a href="#message-board"><div id="down">👇</div></a>
</aside>
<div id="message-board"></div>
<script src="https://utteranc.es/client.js"
repo="syx-413/syx-413.github.io"
issue-term="pathname"
theme="boxy-light"
crossorigin="anonymous"
async>
</script>
<footer class="Footer">
<div>
© 413’s Website 2020~2024
</div>
<div>
·
</div>
<div>
Powered by
<a href="https://github.com/syx-413" target="_blank" rel="noopener noreferrer"> notablog</a>.
</div>
</footer>
</body>
</html>