Skip to content

Commit f78db25

Browse files
djtuBIG-MaliceXnot-fl3
authored andcommitted
Fix multi-line rotation calculation
1 parent bf96089 commit f78db25

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/text.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ impl Font {
102102

103103
let (metrics, bitmap) = self.font.rasterize(character, size as f32);
104104

105-
// if metrics.advance_height != 0.0 {
106-
// panic!("Vertical fonts are not supported");
107-
// }
108-
109105
let (width, height) = (metrics.width as u16, metrics.height as u16);
110106

111107
let sprite = self.atlas.lock().unwrap().new_unique_id();
@@ -411,18 +407,18 @@ pub fn draw_multiline_text(
411407
}
412408

413409
/// Draw multiline text with the given line distance and custom params such as font, font size and font scale.
414-
/// If no line distance but a custom font is given, the fonts newline size will be used as line distance factor if it exists.
410+
/// If no line distance but a custom font is given, the fonts newline size will be used as line distance factor if it exists, else default to font size.
415411
pub fn draw_multiline_text_ex(
416412
text: &str,
417-
x: f32,
413+
mut x: f32,
418414
mut y: f32,
419415
line_distance_factor: Option<f32>,
420416
params: TextParams,
421417
) {
422418
let line_distance = match line_distance_factor {
423419
Some(distance) => distance,
424420
None => {
425-
let mut font_line_distance = 0.0;
421+
let mut font_line_distance = 1.0;
426422
if let Some(font) = params.font {
427423
if let Some(metrics) = font.font.horizontal_line_metrics(1.0) {
428424
font_line_distance = metrics.new_line_size;
@@ -434,7 +430,8 @@ pub fn draw_multiline_text_ex(
434430

435431
for line in text.lines() {
436432
draw_text_ex(line, x, y, params.clone());
437-
y += line_distance * params.font_size as f32 * params.font_scale;
433+
x -= (line_distance * params.font_size as f32 * params.font_scale) * params.rotation.sin();
434+
y += (line_distance * params.font_size as f32 * params.font_scale) * params.rotation.cos();
438435
}
439436
}
440437

0 commit comments

Comments
 (0)