Skip to content

Commit 40896de

Browse files
Merge pull request #3066 from yashranaway/fix/rendering-skia
fix(rendering): scale text wrap allowance with output resolution
2 parents 90fc173 + 4f18e3d commit 40896de

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎crates/rendering/src/layers/text.rs‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use glyphon::{
1010
use log::warn;
1111
use wgpu::{Device, Queue, include_wgsl, util::DeviceExt};
1212

13-
use crate::text::{PreparedText, StaggerEdge, stagger_alpha};
13+
use crate::text::{PreparedText, REFERENCE_HEIGHT, StaggerEdge, stagger_alpha};
1414

1515
#[derive(PartialEq)]
1616
struct ShapeKey {
@@ -507,7 +507,7 @@ impl TextLayer {
507507
// the editor genuinely wrapped too.
508508
let output_width = output_px[0];
509509
let wrap_width = if width < output_width * 0.98 {
510-
(width * 1.05 + 4.0).min(output_width.max(width))
510+
(width * 1.05 + 4.0 * output_px[1] / REFERENCE_HEIGHT).min(output_width.max(width))
511511
} else {
512512
width
513513
};
@@ -1015,6 +1015,26 @@ mod gpu_tests {
10151015
pixels[index..index + 4].try_into().unwrap()
10161016
}
10171017

1018+
#[test]
1019+
#[ignore = "requires a working wgpu adapter"]
1020+
fn text_wrap_width_scales_with_output_resolution() {
1021+
let (device, queue) = device().expect("A working wgpu adapter is required for this test");
1022+
let mut layer = TextLayer::new(&device, &queue);
1023+
let mut overlay = text([100.0, 100.0, 600.0, 300.0], [0.0; 4]);
1024+
overlay.background_color = None;
1025+
overlay.content = "A line of text near the wrap boundary".to_string();
1026+
1027+
layer.prepare(&device, &queue, (1920, 1080), &[overlay.clone()]);
1028+
let width_1080 = layer.buffers[0].size().0.unwrap();
1029+
1030+
overlay.bounds = [200.0, 200.0, 1200.0, 600.0];
1031+
overlay.font_size *= 2.0;
1032+
layer.prepare(&device, &queue, (3840, 2160), &[overlay]);
1033+
let width_2160 = layer.buffers[0].size().0.unwrap();
1034+
1035+
assert_eq!(width_2160, width_1080 * 2.0);
1036+
}
1037+
10181038
#[test]
10191039
#[ignore = "requires a working wgpu adapter"]
10201040
fn reused_shaping_renders_exactly_like_fresh_shaping_and_follows_edits() {

‎crates/rendering/src/text.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use cap_project::{TextAlign, TextAnimation, TextBackgroundStyle, TextSegment, XY
55
/// export resolution. `size` only positions and wraps the text — it never
66
/// affects glyph size (that coupling is baked away by the config migration
77
/// in cap_project).
8-
const REFERENCE_HEIGHT: f32 = 1080.0;
8+
pub(crate) const REFERENCE_HEIGHT: f32 = 1080.0;
99
pub const MIN_FONT_SIZE: f32 = 8.0;
1010
pub const MAX_FONT_SIZE: f32 = 480.0;
1111

0 commit comments

Comments
 (0)