Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0409a481c7 | ||
|
|
916ec5c78b |
@@ -188,28 +188,93 @@ fn complete_fallback_scene_selects_but_cannot_capture_or_finish_coordinate_gestu
|
||||
);
|
||||
assert!(input.press.is_none() && input.source.is_none());
|
||||
}
|
||||
// A gesture already captured in a Ready frame is cancelled when capability is revoked.
|
||||
scene.coordinate_input = true;
|
||||
scene.interaction = Some((context, CanvasTool::Select, true));
|
||||
// Capture from an actual Ready presentation, then revoke coordinate input
|
||||
// with the complete fallback frame of the same Saved representation.
|
||||
let Representation::Saved { diagram } = rep else {
|
||||
unreachable!()
|
||||
};
|
||||
let mut ready_project = f.project.clone();
|
||||
ready_project.diagrams.get_mut(&diagram).unwrap().layout =
|
||||
Some(DiagramLayout::Scenario(ScenarioLayout::default()));
|
||||
let ready_original = ready_project.clone();
|
||||
let ready = state.display(&ready_project, f.owner, f.call).unwrap();
|
||||
assert!(matches!(
|
||||
ready.status(),
|
||||
presentation::PresentationStatus::Ready
|
||||
));
|
||||
let mut ready_scene = ready.into_scene().unwrap();
|
||||
let line = ready_scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == f.call)
|
||||
.unwrap();
|
||||
let ready_point = Point::new(
|
||||
(line.points[0].x + line.points.last().unwrap().x) / 2.,
|
||||
line.points[0].y,
|
||||
);
|
||||
let hit = ready_scene.hit_item(ready_point).unwrap();
|
||||
assert_eq!(hit.id, f.call);
|
||||
assert_eq!(hit.role, SceneHitRole::MessageBody);
|
||||
let stamp = spacing::Stamp {
|
||||
context,
|
||||
camera_epoch: 17,
|
||||
};
|
||||
ready_scene.coordinate_input = true;
|
||||
ready_scene.interaction = Some((context, CanvasTool::Select, true));
|
||||
ready_scene.spacing_stamp = Some(stamp);
|
||||
let mut input = SequenceInput::default();
|
||||
let _ = canvas::Program::update(
|
||||
&scene,
|
||||
let begin = canvas::Program::update(
|
||||
&ready_scene,
|
||||
&mut input,
|
||||
&canvas::Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)),
|
||||
bounds,
|
||||
mouse::Cursor::Available(point),
|
||||
);
|
||||
assert!(input.press.is_some());
|
||||
scene.coordinate_input = false;
|
||||
mouse::Cursor::Available(ready_point),
|
||||
)
|
||||
.and_then(|action| action.into_inner().0)
|
||||
.unwrap();
|
||||
let Message::ScenarioCanvas(CanvasEvent::Spacing(spacing::Event::Begin {
|
||||
stamp: captured_stamp,
|
||||
token,
|
||||
target: spacing::Target::Message(target),
|
||||
..
|
||||
})) = begin
|
||||
else {
|
||||
panic!("Ready Saved message must begin a stamped spacing gesture");
|
||||
};
|
||||
assert_eq!(captured_stamp, stamp);
|
||||
assert_eq!(target, f.call);
|
||||
assert!(matches!(input.press, Some(SequencePress::Spacing {
|
||||
stamp: held_stamp, token: held_token
|
||||
}) if held_stamp == stamp && held_token == token));
|
||||
scene.interaction = Some((context, CanvasTool::Select, true));
|
||||
assert!(!scene.coordinate_input && scene.spacing_stamp.is_none());
|
||||
let release = canvas::Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left));
|
||||
let result = canvas::Program::update(
|
||||
&scene,
|
||||
&mut input,
|
||||
&canvas::Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)),
|
||||
&release,
|
||||
bounds,
|
||||
mouse::Cursor::Available(point),
|
||||
mouse::Cursor::Available(ready_point),
|
||||
)
|
||||
.and_then(|action| action.into_inner().0);
|
||||
assert!(
|
||||
matches!(result, Some(Message::ScenarioCanvas(CanvasEvent::Spacing(
|
||||
spacing::Event::Cancel { stamp: cancelled_stamp, token: cancelled_token }
|
||||
))) if cancelled_stamp == stamp && cancelled_token == token)
|
||||
);
|
||||
assert!(result.and_then(|action| action.into_inner().0).is_none());
|
||||
assert!(input.press.is_none());
|
||||
assert!(input.press.is_none() && input.source.is_none());
|
||||
assert!(
|
||||
canvas::Program::update(
|
||||
&scene,
|
||||
&mut input,
|
||||
&release,
|
||||
bounds,
|
||||
mouse::Cursor::Available(ready_point),
|
||||
)
|
||||
.and_then(|action| action.into_inner().0)
|
||||
.is_none()
|
||||
);
|
||||
assert_eq!(ready_project, ready_original);
|
||||
assert_eq!(f.project, original);
|
||||
}
|
||||
|
||||
|
||||
@@ -328,3 +328,94 @@ fn zoomed_out_message_tolerance_matches_actual_canvas_hit() {
|
||||
state.begin_spacing(doc.project(), event).unwrap();
|
||||
assert_eq!(state.spacing_token(), Some(token));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fractional_screen_packet_preserves_subpixel_motion_in_preview_and_finish() {
|
||||
let (doc, owner, diagram, _, message) = fixture();
|
||||
let original = doc.snapshot();
|
||||
assert!(doc.project().diagrams[&diagram].layout.is_none());
|
||||
let mut state = State::default();
|
||||
let document = Id::new_v4();
|
||||
state.enter_representation(document, owner, Representation::Saved { diagram });
|
||||
state.presentation.viewport = Some(Size::new(900., 600.));
|
||||
state.presentation.fit = false;
|
||||
state.presentation.zoom = Some(0.5);
|
||||
// 406 + 2^-15 puts the press just below the 512 screen-coordinate boundary.
|
||||
state.presentation.pan = Vector::new(0., f32::from_bits(0x43cb_0001));
|
||||
let camera = state.camera_boundary();
|
||||
let context = state.context(document, owner, doc.revision(), 4).unwrap();
|
||||
let baseline = resolve(doc.project(), context.representation, message).unwrap();
|
||||
let line = baseline
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == message)
|
||||
.unwrap();
|
||||
assert_eq!(line.points[0].y, 148.);
|
||||
let begin = packet(doc.project(), &state, context, 9, Target::Message(message));
|
||||
let Event::Begin {
|
||||
press_screen,
|
||||
canvas_bounds,
|
||||
scale,
|
||||
pan,
|
||||
..
|
||||
} = begin
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
assert_eq!(canvas_bounds.y, 23.);
|
||||
assert_eq!(scale, 0.5);
|
||||
assert_eq!(pan.y.to_bits(), 0x43cb_0001);
|
||||
assert_eq!(press_screen.y.to_bits(), 0x43fb_8001); // 503 + 2^-15.
|
||||
let end = press_screen + Vector::new(0., 10.);
|
||||
assert_eq!(end.y, 513.);
|
||||
assert!(canvas_bounds.contains(press_screen) && canvas_bounds.contains(end));
|
||||
// The submitted f32 displacement is 10 - 2^-15, not exactly 10.
|
||||
assert_eq!((end.y - press_screen.y).to_bits(), 0x411f_ffe0);
|
||||
assert_eq!(((end.y - press_screen.y) / scale).to_bits(), 0x419f_ffe0);
|
||||
// Independent oracle: 148 + (10 - 2^-15) / .5 = 168 - 2^-14.
|
||||
let expected_y = f32::from_bits(0x4327_fffc);
|
||||
let mut expected = original.decoded.project.clone();
|
||||
expected.diagrams.get_mut(&diagram).unwrap().layout =
|
||||
Some(oa_core::DiagramLayout::Scenario(oa_core::ScenarioLayout {
|
||||
lanes: vec![],
|
||||
messages: vec![oa_core::ScenarioMessagePosition {
|
||||
address: oa_core::OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence: message,
|
||||
},
|
||||
send_y: expected_y,
|
||||
}],
|
||||
}));
|
||||
state.begin_spacing(doc.project(), begin).unwrap();
|
||||
state.move_spacing(end);
|
||||
let preview = state.spacing.as_ref().unwrap().preview.as_ref().unwrap();
|
||||
assert_eq!(preview.project, expected);
|
||||
let line = preview
|
||||
.geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == message)
|
||||
.unwrap();
|
||||
assert_eq!(line.points[0].y.to_bits(), expected_y.to_bits());
|
||||
let Finish::Commit {
|
||||
command,
|
||||
selected,
|
||||
scale,
|
||||
pan,
|
||||
} = state.finish_spacing(end).unwrap()
|
||||
else {
|
||||
panic!("fractional motion must remain a commit")
|
||||
};
|
||||
assert_eq!(selected, message);
|
||||
assert_eq!(scale, 0.5);
|
||||
assert_eq!(pan.y.to_bits(), 0x43cb_0001);
|
||||
let committed = oa_core::execute_batch(doc.project(), &[command]).unwrap();
|
||||
assert_eq!(committed, expected);
|
||||
assert!(state.spacing_token().is_none());
|
||||
assert_eq!(doc.project(), &original.decoded.project);
|
||||
assert_eq!(doc.compiled().bundle, original.bundle);
|
||||
assert!(!doc.dirty() && !doc.can_undo() && !doc.can_redo());
|
||||
assert!(camera == state.camera_boundary());
|
||||
}
|
||||
|
||||
@@ -156,8 +156,26 @@ async fn saved_message_same_batch_pointer_events_commit_once_and_one_undo_redo_r
|
||||
let target = id(&app, "updated_report");
|
||||
let before = app.document.snapshot();
|
||||
let revision = app.document.revision();
|
||||
let start = screen(&mut mounted, &app, Point::new(400., 252.));
|
||||
let projected = screen(&mut mounted, &app, Point::new(400., 252.));
|
||||
// This fixture asks for exactly +20 world units. A fractional start near a
|
||||
// screen-coordinate exponent boundary need not retain an exact +10 delta.
|
||||
let start = Point::new(projected.x.round(), projected.y.round());
|
||||
let mut geometry = resolved(&app);
|
||||
let camera = app.behavior.scenario.presentation.camera(geometry.bounds);
|
||||
assert_eq!(camera.scale, 0.5);
|
||||
let bounds = mounted.geometry(&app).bounds("scenario-viewport");
|
||||
let world = Point::new(
|
||||
(start.x - bounds.x - camera.pan.x) / camera.scale,
|
||||
(start.y - bounds.y - camera.pan.y) / camera.scale,
|
||||
);
|
||||
geometry.scene.scale = camera.scale;
|
||||
geometry.scene.camera_pan = camera.pan;
|
||||
let hit = geometry.scene.hit_item(world).unwrap();
|
||||
assert_eq!(hit.id, target);
|
||||
assert_eq!(hit.role, crate::behavior::SceneHitRole::MessageBody);
|
||||
let end = start + Vector::new(0., 10.); // .5 display scale: +20 authored y.
|
||||
assert_eq!(end.y - start.y, 10.);
|
||||
assert!(bounds.contains(start) && bounds.contains(end));
|
||||
let messages = mounted
|
||||
.batch(
|
||||
&mut app,
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
//! It measures layout advances, not raster ink; overhang/clip/activation-border
|
||||
//! acceptance still requires the real WGPU evaluator. The old 32-grapheme/225px
|
||||
//! renderer is deliberately untouched for a later baseline comparison.
|
||||
//! Field geometry is a second unwired experiment: exact retained source spans
|
||||
//! and winning-buffer cluster boxes, with unresolved glyph coverage distinct
|
||||
//! from truncation. It does not adopt a production navigation policy.
|
||||
use iced::advanced::{
|
||||
graphics::text as graphics_text,
|
||||
text::{Alignment, LineHeight, Shaping},
|
||||
@@ -97,144 +94,9 @@ pub(super) struct Label {
|
||||
style: Style,
|
||||
measured_session: RenderSession,
|
||||
measured_zoom: f32,
|
||||
// Snapshot of the final displayed Cache entry, after alignment. These are
|
||||
// cluster advance boxes, never glyph ink or inferred character cells.
|
||||
clusters: Vec<FieldCluster>,
|
||||
source_spans: Vec<SourceSpan>,
|
||||
retained_normalized: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(super) struct FieldLayout {
|
||||
pub rectangles: Vec<Rectangle>,
|
||||
pub covered: Vec<Range<usize>>,
|
||||
pub truncated: Vec<Range<usize>>,
|
||||
pub unresolved: Vec<UnresolvedField>,
|
||||
pub partially_retained: bool,
|
||||
pub shared_cluster: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(super) enum FieldIssue {
|
||||
MissingGlyph,
|
||||
NoAdvanceGeometry,
|
||||
NonPaintingScalar,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(super) struct UnresolvedField {
|
||||
pub source: Range<usize>,
|
||||
pub reason: FieldIssue,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct SourceSpan {
|
||||
source: Range<usize>,
|
||||
normalized: Range<usize>,
|
||||
whitespace: bool,
|
||||
non_painting: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct FieldCluster {
|
||||
normalized: Range<usize>,
|
||||
rectangles: Vec<Rectangle>,
|
||||
missing: bool,
|
||||
}
|
||||
|
||||
impl Label {
|
||||
/// Geometry and coverage are separate: truncation is not missing-font
|
||||
/// coverage, and a positive .notdef advance is not represented field text.
|
||||
/// Shared ligatures use whole cluster boxes; no sub-cluster fraction is
|
||||
/// invented. Returned ranges refer only to the requested original source.
|
||||
pub fn field_layout(
|
||||
&self,
|
||||
session: &RenderSession,
|
||||
zoom: f32,
|
||||
position: Point,
|
||||
field: Range<usize>,
|
||||
) -> Result<FieldLayout, Error> {
|
||||
self.check(session, zoom)?;
|
||||
translated_bounds(position, Size::ZERO)?;
|
||||
if field.start > field.end || self.source.get(field.clone()).is_none() {
|
||||
return Err(Error::InvalidFieldRange);
|
||||
}
|
||||
let mut result = FieldLayout {
|
||||
rectangles: vec![],
|
||||
covered: vec![],
|
||||
truncated: vec![],
|
||||
unresolved: vec![],
|
||||
partially_retained: false,
|
||||
shared_cluster: false,
|
||||
};
|
||||
let mut selected = vec![false; self.clusters.len()];
|
||||
for span in &self.source_spans {
|
||||
if span.whitespace || !overlaps(&span.source, &field) {
|
||||
continue;
|
||||
}
|
||||
// Source spans for text are exact UTF-8 scalars, not intervals
|
||||
// between ends (which could assign trimmed whitespace to text).
|
||||
if span.normalized.end > self.retained_normalized {
|
||||
append_range(&mut result.truncated, span.source.clone());
|
||||
continue;
|
||||
}
|
||||
let matching: Vec<_> = self
|
||||
.clusters
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, cluster)| overlaps(&cluster.normalized, &span.normalized))
|
||||
.collect();
|
||||
result.shared_cluster |= matching.iter().any(|(_, cluster)| {
|
||||
cluster.normalized.end > self.retained_normalized
|
||||
|| self.source_spans.iter().any(|other| {
|
||||
overlaps(&other.normalized, &cluster.normalized)
|
||||
&& !overlaps(&other.source, &field)
|
||||
})
|
||||
});
|
||||
let issue = if span.non_painting {
|
||||
Some(FieldIssue::NonPaintingScalar)
|
||||
} else if matching.iter().any(|(_, cluster)| cluster.missing) {
|
||||
Some(FieldIssue::MissingGlyph)
|
||||
} else if matching.is_empty()
|
||||
|| matching
|
||||
.iter()
|
||||
.all(|(_, cluster)| cluster.rectangles.is_empty())
|
||||
{
|
||||
Some(FieldIssue::NoAdvanceGeometry)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(reason) = issue {
|
||||
result.unresolved.push(UnresolvedField {
|
||||
source: span.source.clone(),
|
||||
reason,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
append_range(&mut result.covered, span.source.clone());
|
||||
for (index, _) in matching {
|
||||
selected[index] = true;
|
||||
}
|
||||
}
|
||||
for (cluster, selected) in self.clusters.iter().zip(selected) {
|
||||
if !selected {
|
||||
continue;
|
||||
}
|
||||
for bounds in &cluster.rectangles {
|
||||
let translated = translated_bounds(
|
||||
Point::new(position.x + bounds.x, position.y + bounds.y),
|
||||
bounds.size(),
|
||||
)?;
|
||||
if !result.rectangles.contains(&translated) {
|
||||
result.rectangles.push(translated);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.partially_retained = !result.truncated.is_empty()
|
||||
&& (!result.covered.is_empty() || !result.unresolved.is_empty());
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn check(&self, session: &RenderSession, zoom: f32) -> Result<(), Error> {
|
||||
if !Arc::ptr_eq(&self.measured_session.identity, &session.identity) {
|
||||
return Err(Error::StaleRenderSession);
|
||||
@@ -332,7 +194,6 @@ pub(super) enum Error {
|
||||
StaleZoom,
|
||||
StaleRenderSession,
|
||||
FontSetChanged,
|
||||
InvalidFieldRange,
|
||||
}
|
||||
|
||||
struct Entry {
|
||||
@@ -425,8 +286,8 @@ impl Cache {
|
||||
if cuts.len().saturating_sub(1) > MAX_GRAPHEMES {
|
||||
return Err(Error::GraphemeBudget);
|
||||
}
|
||||
// Candidate buffers are temporary. The winning strings, metrics, source
|
||||
// spans and cluster boxes survive; renderer caching remains independent.
|
||||
// Candidate buffers are temporary. Only the resolved strings/metrics
|
||||
// survive, bounded by MAX_ENTRIES; renderer caching remains independent.
|
||||
let mut shapes = graphics_text::Cache::new();
|
||||
let mut measure = |content: &str| -> Result<Size, Error> {
|
||||
if content.is_empty() {
|
||||
@@ -484,24 +345,6 @@ impl Cache {
|
||||
best
|
||||
}
|
||||
};
|
||||
let clusters = if displayed.is_empty() {
|
||||
// measure("") deliberately creates no cache entry.
|
||||
vec![]
|
||||
} else {
|
||||
let (_, entry) = shapes.allocate(
|
||||
fonts.raw(),
|
||||
graphics_text::cache::Key {
|
||||
content: &displayed,
|
||||
size,
|
||||
line_height,
|
||||
font: style.font,
|
||||
bounds: Size::INFINITE,
|
||||
shaping: style.shaping,
|
||||
align_x: Alignment::Default,
|
||||
},
|
||||
);
|
||||
field_clusters(entry, zoom)?
|
||||
};
|
||||
let label = Arc::new(Label {
|
||||
source: source.into(),
|
||||
displayed,
|
||||
@@ -510,9 +353,6 @@ impl Cache {
|
||||
style,
|
||||
measured_session: session.clone(),
|
||||
measured_zoom: zoom,
|
||||
clusters,
|
||||
source_spans: normalized.spans,
|
||||
retained_normalized: retained,
|
||||
});
|
||||
if self.entries.len() == MAX_ENTRIES {
|
||||
self.entries.pop_front();
|
||||
@@ -554,14 +394,12 @@ fn translated_bounds(position: Point, size: Size) -> Result<Rectangle, Error> {
|
||||
struct Normalized {
|
||||
text: String,
|
||||
ends: Vec<(usize, usize)>,
|
||||
spans: Vec<SourceSpan>,
|
||||
}
|
||||
impl Normalized {
|
||||
fn new(source: &str) -> Self {
|
||||
let mut result = Self {
|
||||
text: String::new(),
|
||||
ends: vec![(0, 0)],
|
||||
spans: vec![],
|
||||
};
|
||||
let mut separator = false;
|
||||
for (start, c) in source.char_indices() {
|
||||
@@ -570,25 +408,11 @@ impl Normalized {
|
||||
continue;
|
||||
}
|
||||
if separator {
|
||||
let normalized_start = result.text.len();
|
||||
result.text.push(' ');
|
||||
result.spans.push(SourceSpan {
|
||||
source: result.ends.last().expect("initial boundary").1..start,
|
||||
normalized: normalized_start..result.text.len(),
|
||||
whitespace: true,
|
||||
non_painting: false,
|
||||
});
|
||||
result.ends.push((result.text.len(), start));
|
||||
separator = false;
|
||||
}
|
||||
let normalized_start = result.text.len();
|
||||
result.text.push(c);
|
||||
result.spans.push(SourceSpan {
|
||||
source: start..start + c.len_utf8(),
|
||||
normalized: normalized_start..result.text.len(),
|
||||
whitespace: false,
|
||||
non_painting: non_painting_scalar(c),
|
||||
});
|
||||
result.ends.push((result.text.len(), start + c.len_utf8()));
|
||||
}
|
||||
result
|
||||
@@ -601,86 +425,6 @@ impl Normalized {
|
||||
}
|
||||
}
|
||||
|
||||
fn overlaps(a: &Range<usize>, b: &Range<usize>) -> bool {
|
||||
a.start < a.end && b.start < b.end && a.start < b.end && b.start < a.end
|
||||
}
|
||||
|
||||
fn append_range(ranges: &mut Vec<Range<usize>>, next: Range<usize>) {
|
||||
if let Some(last) = ranges.last_mut()
|
||||
&& last.end == next.start
|
||||
{
|
||||
last.end = next.end;
|
||||
return;
|
||||
}
|
||||
ranges.push(next);
|
||||
}
|
||||
|
||||
// Conservative non-membership for controls/default-ignorables, even when a
|
||||
// shaper assigns them a neighbor's positive-width cluster. Unicode 14 ranges
|
||||
// documented in pinned harfrust 0.3.2 src/hb/unicode.rs:615–650. Include its
|
||||
// spacing-filler exceptions conservatively; this is not an ink classifier.
|
||||
fn non_painting_scalar(c: char) -> bool {
|
||||
c.is_control()
|
||||
|| matches!(c as u32,
|
||||
0x00ad | 0x034f | 0x061c | 0x115f..=0x1160 | 0x17b4..=0x17b5 |
|
||||
0x180b..=0x180f | 0x200b..=0x200f | 0x202a..=0x202e | 0x2060..=0x206f |
|
||||
0x3164 | 0xfe00..=0xfe0f | 0xfeff | 0xffa0 | 0xfff0..=0xfff8 |
|
||||
0x1bca0..=0x1bca3 | 0x1d173..=0x1d17a | 0xe0000..=0xe0fff)
|
||||
}
|
||||
|
||||
fn field_clusters(
|
||||
entry: &graphics_text::cache::Entry,
|
||||
zoom: f32,
|
||||
) -> Result<Vec<FieldCluster>, Error> {
|
||||
let mut clusters: std::collections::BTreeMap<(usize, usize), FieldCluster> = Default::default();
|
||||
for run in entry.buffer.layout_runs() {
|
||||
for glyph in run.glyphs {
|
||||
if glyph.start >= glyph.end || run.text.get(glyph.start..glyph.end).is_none() {
|
||||
return Err(Error::InvalidMeasurement);
|
||||
}
|
||||
let cluster =
|
||||
clusters
|
||||
.entry((glyph.start, glyph.end))
|
||||
.or_insert_with(|| FieldCluster {
|
||||
normalized: glyph.start..glyph.end,
|
||||
rectangles: vec![],
|
||||
missing: false,
|
||||
});
|
||||
cluster.missing |= glyph.glyph_id == 0;
|
||||
let x1 = glyph.x / zoom;
|
||||
let x2 = (glyph.x + glyph.w) / zoom;
|
||||
let y = (run.line_top + glyph.y) / zoom;
|
||||
let height = glyph.line_height_opt.unwrap_or(run.line_height) / zoom;
|
||||
if !x1.is_finite()
|
||||
|| !x2.is_finite()
|
||||
|| !y.is_finite()
|
||||
|| !height.is_finite()
|
||||
|| height < 0.
|
||||
|| !(y + height).is_finite()
|
||||
{
|
||||
return Err(Error::InvalidMeasurement);
|
||||
}
|
||||
if x1 != x2 && height > 0. {
|
||||
let bounds = Rectangle::new(
|
||||
Point::new(x1.min(x2), y),
|
||||
Size::new((x2 - x1).abs(), height),
|
||||
);
|
||||
if !bounds.width.is_finite() {
|
||||
return Err(Error::InvalidMeasurement);
|
||||
}
|
||||
if !cluster.rectangles.contains(&bounds) {
|
||||
cluster.rectangles.push(bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(clusters.into_values().collect())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "scenario_label/tests.rs"]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "scenario_label/field_tests.rs"]
|
||||
mod field_tests;
|
||||
|
||||
@@ -1,700 +0,0 @@
|
||||
//! Unwired field-layout falsifiers. Execution evidence is recorded in the harness.
|
||||
//! Paragraph is an independent
|
||||
//! shaping oracle; it never invokes the candidate normalization/extraction.
|
||||
use super::*;
|
||||
use iced::advanced::{
|
||||
graphics::text::Paragraph,
|
||||
text::{Paragraph as _, Text as ParagraphText, Wrapping},
|
||||
};
|
||||
|
||||
// The two ligature tests run alone in fresh processes. Clearing host faces is
|
||||
// deliberate: a system-installed Noto Sans with another version must not win.
|
||||
const LIGATURE_FONT: &[u8] = include_bytes!("fixtures/NotoSans-Regular.ttf");
|
||||
|
||||
fn isolated_ligature_style(shaping: Shaping) -> Style {
|
||||
let mut fonts = graphics_text::font_system().write().unwrap();
|
||||
let ids: Vec<_> = fonts.raw().db().faces().map(|face| face.id).collect();
|
||||
for id in ids {
|
||||
fonts.raw().db_mut().remove_face(id);
|
||||
}
|
||||
fonts.load_font(std::borrow::Cow::Borrowed(LIGATURE_FONT));
|
||||
assert_eq!(fonts.raw().db().len(), 1);
|
||||
Style {
|
||||
font: Font::with_name("Noto Sans"),
|
||||
shaping,
|
||||
..Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_ligature_fixture_face(oracle: &Paragraph) {
|
||||
let mut fonts = graphics_text::font_system().write().unwrap();
|
||||
let mut count = 0;
|
||||
for glyph in oracle.buffer().layout_runs().flat_map(|run| run.glyphs) {
|
||||
assert_eq!(
|
||||
fonts.raw().db().with_face_data(glyph.font_id, |bytes, index| {
|
||||
index == 0 && bytes == LIGATURE_FONT
|
||||
}),
|
||||
Some(true),
|
||||
"the actual shaped face must be the byte-pinned fixture"
|
||||
);
|
||||
count += 1;
|
||||
}
|
||||
assert!(count > 0, "font identity cannot pass on an empty paragraph");
|
||||
}
|
||||
|
||||
fn paragraph(text: &str, zoom: f32, style: Style) -> Paragraph {
|
||||
Paragraph::with_text(ParagraphText {
|
||||
content: text,
|
||||
bounds: Size::INFINITE,
|
||||
size: Pixels(style.size.0 * zoom),
|
||||
line_height: match style.line_height {
|
||||
LineHeight::Relative(value) => LineHeight::Relative(value),
|
||||
LineHeight::Absolute(value) => LineHeight::Absolute(Pixels(value.0 * zoom)),
|
||||
},
|
||||
font: style.font,
|
||||
align_x: Alignment::Default,
|
||||
align_y: iced::alignment::Vertical::Top,
|
||||
shaping: style.shaping,
|
||||
wrapping: Wrapping::default(),
|
||||
})
|
||||
}
|
||||
|
||||
fn resolve(text: &str, width: f32, zoom: f32, style: Style) -> (RenderSession, Arc<Label>) {
|
||||
let session = RenderSession::after_fonts_settled_and_renderer_reset().unwrap();
|
||||
let label = Cache::default()
|
||||
.resolve(&session, text, width, zoom, style)
|
||||
.unwrap();
|
||||
(session, label)
|
||||
}
|
||||
|
||||
// The oracle walks an independently built Paragraph, never Label's retained
|
||||
// spans, cluster snapshot, or field_layout. Test callers supply explicit ranges
|
||||
// in the already displayed string; synthetic ellipsis is deliberately excluded.
|
||||
fn paragraph_boxes(oracle: &Paragraph, ranges: &[Range<usize>], zoom: f32) -> Vec<Rectangle> {
|
||||
let mut boxes = vec![];
|
||||
for run in oracle.buffer().layout_runs() {
|
||||
for glyph in run.glyphs {
|
||||
if !ranges
|
||||
.iter()
|
||||
.any(|range| range.start < glyph.end && glyph.start < range.end)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
assert_ne!(glyph.glyph_id, 0, "oracle requires actual font coverage");
|
||||
if glyph.w == 0. {
|
||||
continue;
|
||||
}
|
||||
assert!(
|
||||
glyph.w > 0.,
|
||||
"these fixtures require positive glyph advances"
|
||||
);
|
||||
let left = glyph.x / zoom;
|
||||
let right = (glyph.x + glyph.w) / zoom;
|
||||
boxes.push(Rectangle::new(
|
||||
Point::new(left, (run.line_top + glyph.y) / zoom),
|
||||
Size::new(
|
||||
right - left,
|
||||
glyph.line_height_opt.unwrap_or(run.line_height) / zoom,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
canonical_boxes(boxes)
|
||||
}
|
||||
|
||||
fn canonical_boxes(mut boxes: Vec<Rectangle>) -> Vec<Rectangle> {
|
||||
boxes.sort_by(|a, b| {
|
||||
a.x.total_cmp(&b.x)
|
||||
.then(a.y.total_cmp(&b.y))
|
||||
.then(a.width.total_cmp(&b.width))
|
||||
.then(a.height.total_cmp(&b.height))
|
||||
});
|
||||
boxes.dedup();
|
||||
boxes
|
||||
}
|
||||
|
||||
fn assert_complete_boxes(actual: &[Rectangle], expected: Vec<Rectangle>) {
|
||||
let canonical = canonical_boxes(actual.to_vec());
|
||||
assert_eq!(
|
||||
actual.len(),
|
||||
canonical.len(),
|
||||
"duplicate returned boxes are extraneous"
|
||||
);
|
||||
assert!(
|
||||
!expected.is_empty(),
|
||||
"the geometric oracle must be nonempty"
|
||||
);
|
||||
assert_eq!(
|
||||
canonical, expected,
|
||||
"every selected rectangle and only selected rectangles"
|
||||
);
|
||||
}
|
||||
|
||||
fn resolved_fonts(oracle: &Paragraph) -> Vec<String> {
|
||||
let mut identities = vec![];
|
||||
let mut fonts = graphics_text::font_system().write().unwrap();
|
||||
for glyph in oracle.buffer().layout_runs().flat_map(|run| run.glyphs) {
|
||||
let face = fonts.raw().db().face(glyph.font_id).unwrap();
|
||||
let identity = format!(
|
||||
"{:?}: {} {:?}",
|
||||
glyph.font_id, face.post_script_name, face.families
|
||||
);
|
||||
if !identities.contains(&identity) {
|
||||
identities.push(identity);
|
||||
}
|
||||
}
|
||||
identities
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_and_ellipsis_only_have_no_field_coverage() {
|
||||
for text in ["", " \t\n", "Operation: assess"] {
|
||||
let (session, label) = resolve(text, 0., 1., Style::default());
|
||||
assert!(label.displayed.is_empty());
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 0..text.len())
|
||||
.unwrap();
|
||||
assert!(field.rectangles.is_empty());
|
||||
assert!(field.covered.is_empty());
|
||||
assert!(field.unresolved.is_empty());
|
||||
}
|
||||
let style = Style::default();
|
||||
let width = paragraph("…", 1., style).min_width();
|
||||
let text = "Operation: assess";
|
||||
let (session, label) = resolve(text, width, 1., style);
|
||||
assert_eq!(
|
||||
label.displayed, "…",
|
||||
"must exercise synthetic-only displayed content"
|
||||
);
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 0..text.len())
|
||||
.unwrap();
|
||||
assert!(field.covered.is_empty());
|
||||
assert!(field.rectangles.is_empty());
|
||||
assert!(!field.truncated.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_scalar_mapping_does_not_assign_trimmed_or_collapsed_whitespace_to_text() {
|
||||
let source = " send\t\n assess ";
|
||||
let (session, label) = resolve(source, 900., 1., Style::default());
|
||||
assert_eq!(label.displayed, "send assess");
|
||||
for range in [0..2, 6..10, 16..18] {
|
||||
let result = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, range)
|
||||
.unwrap();
|
||||
assert!(result.covered.is_empty());
|
||||
assert!(result.rectangles.is_empty());
|
||||
assert!(result.unresolved.is_empty());
|
||||
}
|
||||
let result = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 10..16)
|
||||
.unwrap();
|
||||
assert_eq!(result.covered, vec![10..16]);
|
||||
assert!(!result.rectangles.is_empty());
|
||||
assert!(result.truncated.is_empty());
|
||||
assert!(result.unresolved.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn late_operation_reports_hidden_partial_and_complete_without_ellipsis_membership() {
|
||||
let source = "1. call - Incident report - assess_pressure";
|
||||
let start = source.find("assess_pressure").unwrap();
|
||||
let style = Style {
|
||||
shaping: Shaping::Advanced,
|
||||
..Style::default()
|
||||
};
|
||||
let (session, full) = resolve(source, 900., 1., style);
|
||||
let complete = full
|
||||
.field_layout(&session, 1., Point::ORIGIN, start..source.len())
|
||||
.unwrap();
|
||||
assert_eq!(complete.covered, vec![start..source.len()]);
|
||||
assert!(!complete.partially_retained);
|
||||
let (_, hidden) = resolve(
|
||||
source,
|
||||
paragraph("1. call…", 1., style).min_width(),
|
||||
1.,
|
||||
style,
|
||||
);
|
||||
let hidden_result = hidden
|
||||
.field_layout(
|
||||
&hidden.measured_session,
|
||||
1.,
|
||||
Point::ORIGIN,
|
||||
start..source.len(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(hidden.retained_source.end <= start);
|
||||
assert!(hidden_result.covered.is_empty());
|
||||
assert_eq!(hidden_result.truncated, vec![start..source.len()]);
|
||||
assert!(!hidden_result.partially_retained);
|
||||
let desired = format!("{}assess…", &source[..start]);
|
||||
let (_, partial) = resolve(
|
||||
source,
|
||||
paragraph(&desired, 1., style).min_width(),
|
||||
1.,
|
||||
style,
|
||||
);
|
||||
assert!(
|
||||
partial.retained_source.end > start && partial.retained_source.end < source.len(),
|
||||
"actual fitting result must retain a strict operation prefix"
|
||||
);
|
||||
let result = partial
|
||||
.field_layout(
|
||||
&partial.measured_session,
|
||||
1.,
|
||||
Point::ORIGIN,
|
||||
start..source.len(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(result.covered, vec![start..partial.retained_source.end]);
|
||||
assert_eq!(
|
||||
result.truncated,
|
||||
vec![partial.retained_source.end..source.len()]
|
||||
);
|
||||
assert!(result.partially_retained);
|
||||
assert!(result.unresolved.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positive_notdef_advance_is_unresolved_not_covered_or_truncated() {
|
||||
let source = "A\u{10ffff}B";
|
||||
let style = Style {
|
||||
shaping: Shaping::Advanced,
|
||||
..Style::default()
|
||||
};
|
||||
let oracle = paragraph(source, 1., style);
|
||||
assert!(
|
||||
oracle
|
||||
.buffer()
|
||||
.layout_runs()
|
||||
.flat_map(|run| run.glyphs)
|
||||
.any(|glyph| glyph.start == 1 && glyph.end == 5 && glyph.glyph_id == 0 && glyph.w > 0.),
|
||||
"font precondition: actual positive-width .notdef for the noncharacter"
|
||||
);
|
||||
let (session, label) = resolve(source, 900., 1., style);
|
||||
let missing = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 1..5)
|
||||
.unwrap();
|
||||
assert!(missing.covered.is_empty());
|
||||
assert!(missing.rectangles.is_empty());
|
||||
assert!(missing.truncated.is_empty());
|
||||
assert_eq!(
|
||||
missing.unresolved,
|
||||
vec![UnresolvedField {
|
||||
source: 1..5,
|
||||
reason: FieldIssue::MissingGlyph
|
||||
}]
|
||||
);
|
||||
let mixed = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 0..source.len())
|
||||
.unwrap();
|
||||
assert_eq!(mixed.covered, vec![0..1, 5..6]);
|
||||
assert_eq!(mixed.unresolved, missing.unresolved);
|
||||
assert!(!mixed.rectangles.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "replaces global fonts; run only this exact test in a fresh process"]
|
||||
fn advanced_ligature_partial_field_uses_whole_shared_cluster_not_fraction() {
|
||||
let source = "ffi";
|
||||
let style = isolated_ligature_style(Shaping::Advanced);
|
||||
let oracle = paragraph(source, 1., style);
|
||||
assert_ligature_fixture_face(&oracle);
|
||||
let run = oracle.buffer().layout_runs().next().unwrap();
|
||||
let glyph = run
|
||||
.glyphs
|
||||
.iter()
|
||||
.find(|glyph| glyph.start == 0 && glyph.end == 3 && glyph.w > 0. && glyph.glyph_id != 0)
|
||||
.expect("font precondition: Advanced must produce the ffi ligature cluster");
|
||||
let expected = Rectangle::new(
|
||||
Point::new(glyph.x, run.line_top + glyph.y),
|
||||
Size::new(glyph.w, glyph.line_height_opt.unwrap_or(run.line_height)),
|
||||
);
|
||||
let (session, label) = resolve(source, 900., 1., style);
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 1..2)
|
||||
.unwrap();
|
||||
assert_eq!(field.covered, vec![1..2]);
|
||||
assert!(field.shared_cluster);
|
||||
assert!(field.rectangles.contains(&expected));
|
||||
assert_eq!(
|
||||
field.rectangles.iter().map(|rect| rect.width).sum::<f32>(),
|
||||
expected.width
|
||||
);
|
||||
assert_complete_boxes(&field.rectangles, vec![expected]);
|
||||
assert!(field.unresolved.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_default_ignorable_does_not_inherit_neighbor_coverage() {
|
||||
let source = "a\u{fe0f}";
|
||||
let style = Style {
|
||||
shaping: Shaping::Advanced,
|
||||
..Style::default()
|
||||
};
|
||||
let oracle = paragraph(source, 1., style);
|
||||
assert!(
|
||||
oracle
|
||||
.buffer()
|
||||
.layout_runs()
|
||||
.flat_map(|run| run.glyphs)
|
||||
.any(|glyph| glyph.start == 0
|
||||
&& glyph.end == source.len()
|
||||
&& glyph.w > 0.
|
||||
&& glyph.glyph_id != 0),
|
||||
"precondition: variation selector shares a real positive-width base cluster"
|
||||
);
|
||||
let (session, label) = resolve(source, 900., 1., style);
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 1..source.len())
|
||||
.unwrap();
|
||||
assert!(field.covered.is_empty());
|
||||
assert!(field.rectangles.is_empty());
|
||||
assert!(field.truncated.is_empty());
|
||||
assert!(field.shared_cluster);
|
||||
assert_eq!(
|
||||
field.unresolved,
|
||||
vec![UnresolvedField {
|
||||
source: 1..source.len(),
|
||||
reason: FieldIssue::NonPaintingScalar
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn combining_mark_field_retains_cluster_geometry_without_splitting_the_grapheme() {
|
||||
let source = "e\u{301} next";
|
||||
let style = Style {
|
||||
shaping: Shaping::Advanced,
|
||||
..Style::default()
|
||||
};
|
||||
let oracle = paragraph(source, 1., style);
|
||||
let run = oracle.buffer().layout_runs().next().unwrap();
|
||||
let cluster = run
|
||||
.glyphs
|
||||
.iter()
|
||||
.find(|glyph| glyph.start == 0 && glyph.end == 3 && glyph.w > 0. && glyph.glyph_id != 0)
|
||||
.expect("precondition: composed accent and base share the grapheme cluster");
|
||||
let (session, label) = resolve(source, 900., 1., style);
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 1..3)
|
||||
.unwrap();
|
||||
assert_eq!(field.covered, vec![1..3]);
|
||||
assert!(field.shared_cluster);
|
||||
assert!(
|
||||
field
|
||||
.rectangles
|
||||
.iter()
|
||||
.any(|rect| rect.x == cluster.x && rect.width == cluster.w)
|
||||
);
|
||||
assert!(field.unresolved.is_empty());
|
||||
assert_eq!(
|
||||
label.field_layout(&session, 1., Point::ORIGIN, 2..3),
|
||||
Err(Error::InvalidFieldRange)
|
||||
);
|
||||
let (_, short) = resolve(
|
||||
source,
|
||||
paragraph("e\u{301}…", 1., style).min_width(),
|
||||
1.,
|
||||
style,
|
||||
);
|
||||
assert_ne!(
|
||||
short.retained_source.end, 1,
|
||||
"the chosen prefix must never split the combining grapheme"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bidi_logical_field_keeps_visual_pieces_without_enclosing_unselected_glyph() {
|
||||
let source = "abc אבג xyz";
|
||||
let style = Style {
|
||||
shaping: Shaping::Advanced,
|
||||
..Style::default()
|
||||
};
|
||||
let oracle = paragraph(source, 1., style);
|
||||
let run = oracle.buffer().layout_runs().next().unwrap();
|
||||
assert!(
|
||||
!run.rtl,
|
||||
"this existing fixture specifically has an LTR paragraph base"
|
||||
);
|
||||
assert!(run.glyphs.iter().any(|glyph| glyph.level.is_rtl()));
|
||||
assert!(run.glyphs.iter().any(|glyph| !glyph.level.is_rtl()));
|
||||
let excluded = run
|
||||
.glyphs
|
||||
.iter()
|
||||
.find(|glyph| glyph.start == 8 && glyph.end == 10 && glyph.w > 0. && glyph.glyph_id != 0)
|
||||
.unwrap();
|
||||
let (session, label) = resolve(source, 900., 1., style);
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 1..8)
|
||||
.unwrap();
|
||||
assert_eq!(field.covered, vec![1..3, 4..8]);
|
||||
assert!(field.unresolved.is_empty());
|
||||
assert_complete_boxes(
|
||||
&field.rectangles,
|
||||
paragraph_boxes(&oracle, &[1..3, 4..8], 1.),
|
||||
);
|
||||
assert!(
|
||||
field
|
||||
.rectangles
|
||||
.iter()
|
||||
.any(|rect| rect.x + rect.width <= excluded.x)
|
||||
);
|
||||
assert!(
|
||||
field
|
||||
.rectangles
|
||||
.iter()
|
||||
.any(|rect| rect.x >= excluded.x + excluded.w)
|
||||
);
|
||||
assert!(
|
||||
field
|
||||
.rectangles
|
||||
.iter()
|
||||
.all(|rect| rect.x + rect.width <= excluded.x || rect.x >= excluded.x + excluded.w),
|
||||
"logical selection must not become one envelope over the intervening visual glyph"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rtl_leading_full_field_has_complete_post_alignment_rectangle_set() {
|
||||
let source = "אבג abc דהו xyz operation";
|
||||
assert_eq!(source.len(), 31);
|
||||
let style = Style {
|
||||
shaping: Shaping::Advanced,
|
||||
..Style::default()
|
||||
};
|
||||
let oracle = paragraph(source, 1., style);
|
||||
let run = oracle.buffer().layout_runs().next().unwrap();
|
||||
assert!(
|
||||
run.rtl,
|
||||
"must exercise Iced's RTL paragraph alignment branch"
|
||||
);
|
||||
assert!(run.glyphs.iter().any(|glyph| glyph.level.is_rtl()));
|
||||
assert!(run.glyphs.iter().any(|glyph| !glyph.level.is_rtl()));
|
||||
eprintln!("RTL_FIELD_FONTS={:?}", resolved_fonts(&oracle));
|
||||
let (session, label) = resolve(source, 900., 1., style);
|
||||
assert_eq!(label.displayed, source);
|
||||
let ranges = vec![2..6, 7..10, 11..17, 18..21, 22..31];
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 2..source.len())
|
||||
.unwrap();
|
||||
assert_eq!(field.covered, ranges);
|
||||
assert!(field.truncated.is_empty() && field.unresolved.is_empty());
|
||||
assert!(!field.partially_retained);
|
||||
assert_complete_boxes(&field.rectangles, paragraph_boxes(&oracle, &ranges, 1.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rtl_leading_ellipsis_field_has_complete_final_buffer_rectangle_set() {
|
||||
let source = "אבג abc דהו xyz operation";
|
||||
let style = Style {
|
||||
shaping: Shaping::Advanced,
|
||||
..Style::default()
|
||||
};
|
||||
let width = paragraph("אבג abc דהו…", 1., style).min_width();
|
||||
let (session, label) = resolve(source, width, 1., style);
|
||||
let prefix = label
|
||||
.displayed
|
||||
.strip_suffix('…')
|
||||
.expect("must use an ellipsized displayed buffer");
|
||||
assert!(prefix.len() >= 10 && prefix.len() < source.len());
|
||||
assert!(source.starts_with(prefix));
|
||||
let oracle = paragraph(&label.displayed, 1., style);
|
||||
let run = oracle.buffer().layout_runs().next().unwrap();
|
||||
assert!(
|
||||
run.rtl,
|
||||
"the ellipsized winning text must still exercise RTL alignment"
|
||||
);
|
||||
eprintln!("RTL_ELLIPSIS_FIELD_FONTS={:?}", resolved_fonts(&oracle));
|
||||
// Fixed semantic word spans from the source, clipped only by the literal
|
||||
// displayed prefix. No candidate source map or retained_source is consulted.
|
||||
let words = [2..6, 7..10, 11..17, 18..21, 22..31];
|
||||
let retained: Vec<_> = words
|
||||
.iter()
|
||||
.filter_map(|word| {
|
||||
let end = word.end.min(prefix.len());
|
||||
(word.start < end).then_some(word.start..end)
|
||||
})
|
||||
.collect();
|
||||
let hidden: Vec<_> = words
|
||||
.iter()
|
||||
.filter_map(|word| {
|
||||
let start = word.start.max(prefix.len());
|
||||
(start < word.end).then_some(start..word.end)
|
||||
})
|
||||
.collect();
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 2..source.len())
|
||||
.unwrap();
|
||||
assert_eq!(field.covered, retained);
|
||||
assert_eq!(field.truncated, hidden);
|
||||
assert!(field.partially_retained && field.unresolved.is_empty());
|
||||
assert_complete_boxes(&field.rectangles, paragraph_boxes(&oracle, &retained, 1.));
|
||||
}
|
||||
|
||||
/// Diagnostic only: warm font/Paragraph preparation precedes the timed resolver
|
||||
/// and three lookups. No latency budget or production responsiveness claim.
|
||||
#[test]
|
||||
#[ignore = "bounded high-end field lookup diagnostic; run this exact test alone with --nocapture"]
|
||||
fn field_lookup_4096_scalars_and_combining_heavy_full_coverage() {
|
||||
let style = Style {
|
||||
shaping: Shaping::Advanced,
|
||||
..Style::default()
|
||||
};
|
||||
let cases = [
|
||||
("4096_plain_scalars", "A".repeat(4096), 4096),
|
||||
(
|
||||
"4096_combining_heavy_scalars",
|
||||
"a\u{301}\u{323}\u{327}".repeat(1024),
|
||||
1024,
|
||||
),
|
||||
];
|
||||
let mut records = vec![];
|
||||
for (name, source, expected_graphemes) in cases {
|
||||
assert_eq!(source.chars().count(), 4096);
|
||||
assert_eq!(source.graphemes(true).count(), expected_graphemes);
|
||||
assert!(source.len() <= MAX_SOURCE_BYTES);
|
||||
assert!(expected_graphemes <= MAX_GRAPHEMES);
|
||||
let oracle = paragraph(&source, 1., style);
|
||||
assert_eq!(oracle.buffer().layout_runs().count(), 1);
|
||||
let expected = paragraph_boxes(&oracle, &[0..source.len()], 1.);
|
||||
let identities = resolved_fonts(&oracle);
|
||||
let session = RenderSession::after_fonts_settled_and_renderer_reset().unwrap();
|
||||
let mut cache = Cache::default();
|
||||
let start = std::time::Instant::now();
|
||||
let label = cache
|
||||
.resolve(&session, &source, 1_000_000., 1., style)
|
||||
.unwrap();
|
||||
let resolve_ns = start.elapsed().as_nanos();
|
||||
assert_eq!(label.displayed, source);
|
||||
let mut lookup_ns = vec![];
|
||||
for _ in 0..3 {
|
||||
let start = std::time::Instant::now();
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 0..source.len())
|
||||
.unwrap();
|
||||
lookup_ns.push(start.elapsed().as_nanos());
|
||||
assert_eq!(field.covered, vec![0..source.len()]);
|
||||
assert!(field.truncated.is_empty() && field.unresolved.is_empty());
|
||||
assert!(!field.partially_retained && !field.shared_cluster);
|
||||
assert_complete_boxes(&field.rectangles, expected.clone());
|
||||
}
|
||||
records.push(serde_json::json!({
|
||||
"case": name, "scalars": 4096, "graphemes": expected_graphemes,
|
||||
"source_bytes": source.len(), "expected_rectangles": expected.len(),
|
||||
"resolved_fonts": identities, "resolve_ns": resolve_ns, "lookup_ns": lookup_ns,
|
||||
"full_coverage_and_exact_geometry": "passed",
|
||||
}));
|
||||
}
|
||||
println!(
|
||||
"FIELD_LOOKUP_TIMING_JSON={}",
|
||||
serde_json::json!({
|
||||
"schema": "scenario_label_field_lookup_v1",
|
||||
"source_pin_from_runner": std::env::var("SCENARIO_LABEL_FIELDS_SOURCE_PIN").ok(),
|
||||
"debug_assertions": cfg!(debug_assertions), "os": std::env::consts::OS,
|
||||
"arch": std::env::consts::ARCH, "cases": records,
|
||||
"invariant_status": "passed",
|
||||
"scope": "warm-font source-only layout experiment; no native responsiveness threshold",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "replaces global fonts; run only this exact test in a fresh process"]
|
||||
fn auto_ascii_to_ellipsis_advanced_transition_uses_final_buffer() {
|
||||
let style = isolated_ligature_style(Shaping::Auto);
|
||||
let source = "ffi office assessment";
|
||||
assert_eq!(
|
||||
graphics_text::to_shaping(style.shaping, source),
|
||||
graphics_text::cosmic_text::Shaping::Basic
|
||||
);
|
||||
let basic = paragraph(source, 1., style);
|
||||
assert_ligature_fixture_face(&basic);
|
||||
let initial_clusters: Vec<_> = basic
|
||||
.buffer()
|
||||
.layout_runs()
|
||||
.flat_map(|run| run.glyphs)
|
||||
.filter(|glyph| glyph.start < 3)
|
||||
.map(|glyph| (glyph.start, glyph.end))
|
||||
.collect();
|
||||
assert_eq!(initial_clusters, vec![(0, 1), (1, 2), (2, 3)]);
|
||||
let (session, label) = resolve(
|
||||
source,
|
||||
paragraph("ffi office…", 1., style).min_width(),
|
||||
1.,
|
||||
style,
|
||||
);
|
||||
assert!(label.displayed.ends_with('…'));
|
||||
assert_eq!(
|
||||
graphics_text::to_shaping(style.shaping, &label.displayed),
|
||||
graphics_text::cosmic_text::Shaping::Advanced
|
||||
);
|
||||
let oracle = paragraph(&label.displayed, 1., style);
|
||||
assert_ligature_fixture_face(&oracle);
|
||||
let run = oracle.buffer().layout_runs().next().unwrap();
|
||||
let first = run
|
||||
.glyphs
|
||||
.iter()
|
||||
.find(|glyph| glyph.start == 0 && glyph.end >= 3 && glyph.w > 0. && glyph.glyph_id != 0)
|
||||
.expect("final Advanced shape must expose the ligature precondition");
|
||||
let field = label
|
||||
.field_layout(&session, 1., Point::ORIGIN, 0..3)
|
||||
.unwrap();
|
||||
assert_eq!(field.covered, vec![0..3]);
|
||||
assert!(
|
||||
field
|
||||
.rectangles
|
||||
.iter()
|
||||
.any(|rect| rect.x == first.x && rect.width == first.w)
|
||||
);
|
||||
assert_complete_boxes(&field.rectangles, paragraph_boxes(&oracle, &[0..3], 1.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn field_geometry_reuses_zoom_session_guards_and_translates_actual_cluster_boxes() {
|
||||
let source = "Z";
|
||||
for zoom in [0.5, 1.75] {
|
||||
let style = Style::default();
|
||||
let oracle = paragraph(source, zoom, style);
|
||||
let run = oracle.buffer().layout_runs().next().unwrap();
|
||||
assert_eq!(run.glyphs.len(), 1);
|
||||
let glyph = &run.glyphs[0];
|
||||
assert!(glyph.glyph_id != 0 && glyph.w > 0.);
|
||||
let (session, label) = resolve(source, 900., zoom, style);
|
||||
let position = Point::new(-300., 90.);
|
||||
let field = label.field_layout(&session, zoom, position, 0..1).unwrap();
|
||||
assert_eq!(
|
||||
field.rectangles,
|
||||
vec![Rectangle::new(
|
||||
Point::new(
|
||||
position.x + glyph.x / zoom,
|
||||
position.y + (run.line_top + glyph.y) / zoom
|
||||
),
|
||||
Size::new(
|
||||
((glyph.x + glyph.w) / zoom - glyph.x / zoom).abs(),
|
||||
glyph.line_height_opt.unwrap_or(run.line_height) / zoom
|
||||
),
|
||||
)]
|
||||
);
|
||||
assert_eq!(
|
||||
label.field_layout(&session, zoom + 0.1, position, 0..1),
|
||||
Err(Error::StaleZoom)
|
||||
);
|
||||
let fresh = RenderSession::after_fonts_settled_and_renderer_reset().unwrap();
|
||||
assert_eq!(
|
||||
label.field_layout(&fresh, zoom, position, 0..1),
|
||||
Err(Error::StaleRenderSession)
|
||||
);
|
||||
assert_eq!(
|
||||
label.field_layout(&session, zoom, Point::new(f32::NAN, 0.), 0..1),
|
||||
Err(Error::InvalidPosition)
|
||||
);
|
||||
assert_eq!(
|
||||
label.field_layout(&session, zoom, position, 0..2),
|
||||
Err(Error::InvalidFieldRange)
|
||||
);
|
||||
let empty = label.field_layout(&session, zoom, position, 0..0).unwrap();
|
||||
assert!(empty.covered.is_empty() && empty.rectangles.is_empty());
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
* -text -whitespace
|
||||
@@ -1,93 +0,0 @@
|
||||
Copyright 2012 Google Inc. All Rights Reserved.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Binary file not shown.
@@ -1,15 +0,0 @@
|
||||
# Isolated ligature font fixture
|
||||
|
||||
NotoSans-Regular.ttf and NotoSans-LICENSE are copied byte for byte from the fonts/ directory of the pinned cosmic-text 0.15.0 package. The font is unmodified and licensed under SIL Open Font License 1.1; retain the adjacent complete copyright/license file when redistributing it.
|
||||
|
||||
- Package VCS commit: c82ee1c5b5b8032e91eaff1cb34294b538727a7d (from .cargo_vcs_info.json).
|
||||
- Package checksum in this workspace Cargo.lock: 173852283a9a57a3cbe365d86e74dc428a09c50421477d5ad6fe9d9509e37737.
|
||||
- Upstream font: https://github.com/pop-os/cosmic-text/blob/c82ee1c5b5b8032e91eaff1cb34294b538727a7d/fonts/NotoSans-Regular.ttf
|
||||
- Upstream license: https://github.com/pop-os/cosmic-text/blob/c82ee1c5b5b8032e91eaff1cb34294b538727a7d/fonts/NotoSans-LICENSE
|
||||
- The pinned upstream Git LFS pointer independently reports the identical SHA-256 and 556216-byte size; the fixture contains the actual font, not the pointer.
|
||||
- Font bytes: 556216; SHA-256: 2ec33f84606cbaa0a1a944488e14f97faf2f6a25ecdd8354f5358f06da13c7d9.
|
||||
- License bytes: 4351; SHA-256: 5ec4347054089def6904da61d04f0360968f9ef36634b1fe007a5b6ec2f7aa96.
|
||||
|
||||
Static cmap/GSUB inspection found f glyph 73 and i glyph 76, with ffi [73,73,76] substituted by glyph 1654 in lookup 39 under the standard liga feature. This is a fixture-selection check, not runtime shaping evidence. Iced's bundled Fira Sans was rejected for these unchanged ffi assertions because its corresponding lookup is under discretionary dlig, which these tests do not enable.
|
||||
|
||||
Both consumers are ignored by default and must each run as the sole exact test in a fresh process. Their test-only setup removes host font faces before loading this fixture, then verifies every actual oracle glyph resolves to these exact bytes and face index zero. The fixture therefore does not depend on an installed font with the same family name. The original positive nonzero ffi-cluster preconditions remain mandatory. Nothing selects this font for the product or changes the production label algorithm.
|
||||
@@ -1,31 +0,0 @@
|
||||
# Unwired Scenario label field experiment
|
||||
|
||||
This experiment starts from `c4a2cf63f11818cf7fc766acf3a2779768a2a658`. Initial extraction is commit `c3ad6f130ba6dda271fe8417db46df29e4033ad8`; the follow-up strengthens its evaluators. Neither version wires `scenario_label` into production. No renderer, App, navigation, source language, or model behavior is adopted here.
|
||||
|
||||
The implementation lives in `crates/oa-desktop/src/behavior/scenario_label.rs`, with focused evaluators in `scenario_label/field_tests.rs`. It preserves the winning shaped buffer's cluster advance rectangles and exact scalar source mapping. Returned covered, truncated, and unresolved ranges are distinct; partial retention and shared clusters are explicit. Synthetic ellipsis never represents source text. Missing glyphs, controls/default-ignorables, and absent advance geometry cannot establish affirmative coverage. These are advance/hit rectangles, not ink bounds or proof of actual viewport visibility.
|
||||
|
||||
## Follow-up evaluator corrections
|
||||
|
||||
The original mixed bidi fixture is Latin-leading. Its glyph embedding levels are mixed, but `LayoutRun::rtl` is false, so it cannot exercise Iced's RTL paragraph alignment branch. Two added cases require a genuinely RTL-leading full and ellipsized paragraph and assert `run.rtl == true`. Their geometry oracle builds a separate Iced Paragraph using the actual displayed string and compares the **complete rectangle set**, rejecting omissions, extras and duplicate output boxes. Explicit source word spans are clipped only against the literal displayed prefix before ellipsis; no candidate retained-source map or cluster snapshot supplies the expected answer. The existing mixed-direction case now uses the same complete-set comparison in addition to its visual-gap checks.
|
||||
|
||||
The relevant pinned sources are `iced_graphics 0.14.0/src/text.rs:202–256` (measurement and RTL alignment), `src/text/cache.rs` (winning buffer), and `cosmic-text 0.15.0/src/buffer.rs`/`layout.rs` (actual layout runs and clusters). `iced_widget` is 0.14.2; the graphics package is 0.14.0. Reproduce package inputs through the base commit's Cargo.lock.
|
||||
|
||||
## Font and execution limitations
|
||||
|
||||
At source 11c605f9170eae461913410f83f333e9314714a5, the isolated harness compiled and its default-test diagnostic reported 21 passed, two failed and two ignored. The intended first listing accidentally executed tests; a later literal listing reported all 25. A separate serial normal run reproduced the same two failures before either reached field_layout: the host font did not meet the tests' exact ffi-cluster preconditions. No actual face identity was captured for those failed cases, so the failure must not be attributed to a guessed family. Parent-owned closed runner receipts are the execution authority; this note does not turn the failed diagnostic into a passing gate.
|
||||
|
||||
The correction uses an unmodified, byte-pinned Noto Sans fixture from cosmic-text 0.15.0 for exactly those two tests; see [fixture source, hashes and license](../../../crates/oa-desktop/src/behavior/scenario_label/fixtures/README.md). Standard liga contains the required ffi substitution. Each test verifies the actual Paragraph face bytes and retains its positive nonzero ffi-cluster precondition. The partial-field case compares the complete shared rectangle; the Auto case also requires three initial Basic clusters followed by the actual Advanced final-buffer rectangle set. Neither infers successful geometry merely from a shaping enum.
|
||||
|
||||
The two fixture-loading tests are ignored by default because their isolated setup replaces the global font database. Run each as the sole exact test in a fresh process: --ignored --exact <actual-listed-name> --nocapture --test-threads=1. Do not run all ignored tests together. This prevents ordinary/default parallel test execution from invalidating render sessions. Their leaf names are advanced_ligature_partial_field_uses_whole_shared_cluster_not_fraction and auto_ascii_to_ellipsis_advanced_transition_uses_final_buffer. The existing font-load invalidation test remains separately isolated.
|
||||
|
||||
Other cases retain installed system-font selection and explicit font/cluster/coverage preconditions. RTL font IDs, PostScript names and family records are diagnostic metadata, not portable content hashes. No new dependency or production font policy is introduced. A missing precondition remains an evaluator/environment finding, not a geometry pass.
|
||||
|
||||
After this correction the field module contains ten normal tests and three ignored tests (two isolated ligature cases plus the lookup diagnostic). Across the parent label module the intended inventory remains 25, now 21 normal and four ignored. The corrected source is **UNEXECUTED** at handoff. The parent module remains unwired; ordinary desktop listing does not include it without the isolated evaluator harness. Source review is not compilation or execution evidence.
|
||||
|
||||
## Optional bounded lookup diagnostic
|
||||
|
||||
Ignored leaf name: `field_lookup_4096_scalars_and_combining_heavy_full_coverage`. Run only this exact test, once an isolated compiled harness exists, with `--ignored --exact <actual-listed-name> --nocapture --test-threads=1`; obtain the qualified name from its real listing. Set `SCENARIO_LABEL_FIELDS_SOURCE_PIN` to the tested commit and separately bind the executable, source and toolchain in the runner receipt.
|
||||
|
||||
It measures one resolver call and three full-field lookups for each of two cases: 4,096 ordinary scalars/graphemes, and 4,096 scalars arranged as 1,024 combining-heavy graphemes. Both remain within the existing 64-KiB source/4,096-grapheme experiment budgets. An independent Paragraph warms the font machinery before timing, checks glyph coverage and supplies the complete expected rectangle set. Every lookup must cover the full original source, retain no unresolved/truncated ranges, and match that set exactly; its invariants are checked outside the timed interval.
|
||||
|
||||
On success it prints `FIELD_LOOKUP_TIMING_JSON=` with schema `scenario_label_field_lookup_v1`, per-case counts/font identities/resolver nanoseconds/three lookup samples, profile/OS/architecture, optional runner pin, and an explicit passed invariant status. It has no latency threshold and makes no native responsiveness claim. No optimization has been attempted before measurement. The combining case stresses clustered source mapping, while the plain case reaches the existing grapheme budget; neither claims exhaustive worst-case performance over every permitted 64-KiB input.
|
||||
Reference in New Issue
Block a user