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
//! Low-level text rendering algorithms.
//!
//! This module provides the core rendering functions that power the `Text` and `Character`
//! drawables. It handles the actual unpacking and drawing of bitmap glyphs.
use ;
use crateFont;
/// Render a single character using transparent mode.
///
/// In transparent mode, only the pixels set in the glyph bitmap are drawn.
/// The background pixels remain untouched, allowing overlapping text and complex layouts.
///
/// # Arguments
///
/// * `target` - The draw target to render to
/// * `ch` - Character to render
/// * `position` - Top-left position where the character should be drawn
/// * `font` - Font definition to use
/// * `text_color` - Color for the text pixels
///
/// # Returns
///
/// Returns the width of the rendered character, or 0 if the character is not
/// supported by the font.
///
/// # Rendering Algorithm
///
/// 1. Lookup the glyph in the font's lookup table
/// 2. Extract the glyph's bitmap data from the packed binary buffer
/// 3. Iterate over each bit in the bitmap
/// 4. For each set bit, create a pixel at the appropriate coordinate
/// 5. Draw all pixels to the target using `DrawTarget::draw_iter()`
/// Render a string using transparent mode with tracking support.
///
/// Renders each character of the string in sequence, advancing the cursor
/// position by the character width plus any configured tracking.
///
/// # Arguments
///
/// * `target` - The draw target to render to
/// * `text` - String to render
/// * `position` - Starting position for the first character (top-left)
/// * `font` - Font definition to use
/// * `text_color` - Color for the text pixels
/// * `tracking` - Extra spacing to add between characters in pixels
///
/// # Returns
///
/// Returns the position where the next character would be drawn (i.e., after the last
/// character plus any trailing tracking). This is useful for continuing text on the
/// same baseline.
///
/// # Unsupported Characters
///
/// Characters not in the font's supported range are silently skipped (contribute 0 width).
///
/// # Examples
///
/// ```ignore
/// use embedded_graphics::geometry::Point;
/// use embedded_graphics_profont::renderer;
///
/// // Draw text with 2-pixel spacing between characters
/// let end_pos = renderer::draw_str(
/// &mut target,
/// "Hello",
/// Point::new(10, 10),
/// &font,
/// color,
/// 2,
/// )?;
///
/// // Continue on the same line
/// renderer::draw_str(
/// &mut target,
/// " World",
/// end_pos,
/// &font,
/// color,
/// 2,
/// )?;
/// ```