@@ -42,7 +42,7 @@ namespace bitmap {
42
42
return text_width;
43
43
}
44
44
45
- void character (const font_t *font, rect_func rectangle, const char c, const int32_t x, const int32_t y, const uint8_t scale, unicode_sorta::codepage_t codepage) {
45
+ void character (const font_t *font, rect_func rectangle, const char c, const int32_t x, const int32_t y, const uint8_t scale, int32_t rotation, unicode_sorta::codepage_t codepage) {
46
46
if (c < 32 || c > 127 + 64 ) { // + 64 char remappings defined in unicode_sorta.hpp
47
47
return ;
48
48
}
@@ -89,7 +89,8 @@ namespace bitmap {
89
89
uint8_t accent_offset = char_index < 65 ? offset_upper : offset_lower;
90
90
91
91
// Offset our y position to account for our column canvas being 32 pixels
92
- int y_offset = y - (8 * scale);
92
+ // this gives us 8 "pixels" of headroom above the letters for diacritic marks
93
+ int font_offset = (8 * scale);
93
94
94
95
// Iterate through each horizontal column of font (and accent) data
95
96
for (uint8_t cx = 0 ; cx < font->widths [char_index]; cx++) {
@@ -98,6 +99,8 @@ namespace bitmap {
98
99
// We shift the char down 8 pixels to make room for an accent above.
99
100
uint32_t data = *d << 8 ;
100
101
102
+ int32_t o_x = cx * scale;
103
+
101
104
// For fonts that are taller than 8 pixels (up to 16) they need two bytes
102
105
if (two_bytes_per_column) {
103
106
d++;
@@ -113,7 +116,28 @@ namespace bitmap {
113
116
// Draw the 32 pixel column
114
117
for (uint8_t cy = 0 ; cy < 32 ; cy++) {
115
118
if ((1U << cy) & data) {
116
- rectangle (x + (cx * scale), y_offset + (cy * scale), scale, scale);
119
+ int32_t o_y = cy * scale;
120
+ int32_t px = 0 ;
121
+ int32_t py = 0 ;
122
+ switch (rotation) {
123
+ case 0 :
124
+ px = x + o_x;
125
+ py = y - font_offset + o_y;
126
+ break ;
127
+ case 90 :
128
+ px = x + font_offset - o_y;
129
+ py = y + o_x;
130
+ break ;
131
+ case 180 :
132
+ px = x - o_x;
133
+ py = y + font_offset - o_y;
134
+ break ;
135
+ case 270 :
136
+ px = x - font_offset + o_y;
137
+ py = y - o_x;
138
+ break ;
139
+ }
140
+ rectangle (px, py, scale, scale);
117
141
}
118
142
}
119
143
@@ -123,8 +147,9 @@ namespace bitmap {
123
147
}
124
148
}
125
149
126
- void text (const font_t *font, rect_func rectangle, const std::string_view &t, const int32_t x, const int32_t y, const int32_t wrap, const uint8_t scale, const uint8_t letter_spacing, bool fixed_width) {
127
- uint32_t co = 0 , lo = 0 ; // character and line (if wrapping) offset
150
+ void text (const font_t *font, rect_func rectangle, const std::string_view &t, const int32_t x, const int32_t y, const int32_t wrap, const uint8_t scale, const uint8_t letter_spacing, bool fixed_width, int32_t rotation) {
151
+ uint32_t char_offset = 0 ;
152
+ uint32_t line_offset = 0 ; // line (if wrapping) offset
128
153
unicode_sorta::codepage_t codepage = unicode_sorta::PAGE_195;
129
154
130
155
size_t i = 0 ;
@@ -153,37 +178,52 @@ namespace bitmap {
153
178
continue ;
154
179
}
155
180
word_width += measure_character (font, t[j], scale, codepage, fixed_width);
181
+ word_width += letter_spacing * scale;
156
182
codepage = unicode_sorta::PAGE_195;
157
183
}
158
184
159
185
// if this word would exceed the wrap limit then
160
186
// move to the next line
161
- if (co != 0 && co + word_width > (uint32_t )wrap) {
162
- co = 0 ;
163
- lo += (font->height + 1 ) * scale;
187
+ if (char_offset != 0 && char_offset + word_width > (uint32_t )wrap) {
188
+ char_offset = 0 ;
189
+ line_offset += (font->height + 1 ) * scale;
164
190
}
165
191
166
192
// draw word
167
- for (size_t j = i; j < next_break; j++) {
193
+ for (size_t j = i; j < std::min ( next_break + 1 , t. length ()) ; j++) {
168
194
if (t[j] == unicode_sorta::PAGE_194_START) {
169
195
codepage = unicode_sorta::PAGE_194;
170
196
continue ;
171
197
} else if (t[j] == unicode_sorta::PAGE_195_START) {
172
198
continue ;
173
199
}
174
- if (t[j] == ' \n ' ) {
175
- lo += (font->height + 1 ) * scale;
176
- co = 0 ;
200
+ if (t[j] == ' \n ' ) { // Linebreak
201
+ line_offset += (font->height + 1 ) * scale;
202
+ char_offset = 0 ;
203
+ } else if (t[j] == ' ' ) { // Space
204
+ char_offset += font->widths [0 ] * scale;
177
205
} else {
178
- character (font, rectangle, t[j], x + co, y + lo, scale, codepage);
179
- co += measure_character (font, t[j], scale, codepage, fixed_width);
180
- co += letter_spacing * scale;
206
+ switch (rotation) {
207
+ case 0 :
208
+ character (font, rectangle, t[j], x + char_offset, y + line_offset, scale, rotation, codepage);
209
+ break ;
210
+ case 90 :
211
+ character (font, rectangle, t[j], x - line_offset, y + char_offset, scale, rotation, codepage);
212
+ break ;
213
+ case 180 :
214
+ character (font, rectangle, t[j], x - char_offset, y - line_offset, scale, rotation, codepage);
215
+ break ;
216
+ case 270 :
217
+ character (font, rectangle, t[j], x + line_offset, y - char_offset, scale, rotation, codepage);
218
+ break ;
219
+ }
220
+ char_offset += measure_character (font, t[j], scale, codepage, fixed_width);
221
+ char_offset += letter_spacing * scale;
181
222
}
182
223
codepage = unicode_sorta::PAGE_195;
183
224
}
184
225
185
- // move character offset to end of word and add a space
186
- co += font->widths [0 ] * scale;
226
+ // move character offset
187
227
i = next_break += 1 ;
188
228
}
189
229
}
0 commit comments