From d3f886db33e98114e216e61d35a7488b6da9cb6b Mon Sep 17 00:00:00 2001 From: DWAA1660 Date: Sat, 5 Dec 2026 18:17:44 -0700 Subject: [PATCH] fix(notecraft): localize page menu actions and flag ink layout fallback --- crates/import/src/lib.rs | 43 +++++++++++++++++++++++++++++++++- crates/ui-egui/src/pagemenu.rs | 24 +++++++++++++++++-- docs/gaps.md | 3 ++- i18n/ar-XB.tsv | 2 ++ i18n/ar.tsv | 2 ++ i18n/de.tsv | 2 ++ i18n/en-XA.tsv | 2 ++ i18n/en.tsv | 2 ++ i18n/es.tsv | 2 ++ i18n/fa.tsv | 2 ++ i18n/fr.tsv | 2 ++ i18n/he.tsv | 2 ++ i18n/hi.tsv | 2 ++ i18n/ja.tsv | 2 ++ i18n/ko.tsv | 2 ++ i18n/nl.tsv | 2 ++ i18n/ru.tsv | 2 ++ i18n/tr.tsv | 2 ++ i18n/ur.tsv | 2 ++ i18n/zh.tsv | 2 ++ 20 files changed, 100 insertions(+), 4 deletions(-) diff --git a/crates/import/src/lib.rs b/crates/import/src/lib.rs index cec66919..9384710c 100644 --- a/crates/import/src/lib.rs +++ b/crates/import/src/lib.rs @@ -671,7 +671,11 @@ fn write_page(format: PageFormat, file_data: &FileData<'_>, p: &Page, dir: &Path let written = ink::drawing(&p.ink); let left_out = written.as_ref().map_or(0, |w| w.left_out); let missing = p.ink.unread + left_out; - for note in ink_notes(&p.ink, left_out) { + let mut notes = ink_notes(&p.ink, left_out); + if converted.boxes.is_none() && !converted.blocks.is_empty() && written.as_ref().is_some_and(|ink| ink.strokes > 0) { + notes.push("The original OneNote layout could not be kept. The imported pen strokes may not line up with the page content.".into()); + } + for note in notes { // Said on the page itself, so nobody takes it for whole. add_block(&mut converted, Block::Paragraph(vec![Span { text: note, italic: true, ..Span::default() }], Vec::new())); } @@ -1071,6 +1075,43 @@ mod tests { } } + #[test] + fn an_imported_ink_page_says_when_its_original_layout_could_not_be_kept() { + use notecraft_onenote::testing::Pen; + let mut one = OneNote::new(); + one.page_with_ink("Ink notes", &[OneNote::line("Label under the ink")], Pen::default(), &[&[(1270, 2540, 0), (5080, 2540, 0)]]); + let data = one.finish(); + let store = notecraft_onenote::read(&data).expect("read section"); + let mut section = notecraft_onenote::section(&store); + let source = section.pages.first_mut().expect("page"); + assert!(!source.places.is_empty(), "the source normally has placed content"); + let file_data = FileData::new(&store, &data, None); + let tmp = TempDir::new("ink-layout-notice"); + let settings = Settings::at(tmp.path().join("settings.toml")); + let notebook = ops::create_notebook(tmp.path(), "Imported", None, &settings).expect("notebook"); + let section = ops::create_node(¬ebook, "Ink", NodeKind::Section, None, &settings).expect("section"); + + for keeps_layout in [true, false] { + if !keeps_layout { + // Model a reader that returned the text and strokes but has no placement metadata. + source.places.clear(); + } + for format in [PageFormat::Html, PageFormat::Cmgfm] { + let title = format!("Ink {format:?} {keeps_layout}"); + let dir = ops::create_node(§ion, &title, NodeKind::Page, Some(format), &settings).expect("page"); + let mut report = Report::default(); + write_page(format, &file_data, source, &dir, &mut report).expect("write imported page"); + let saved = page::load_page(&dir).expect("imported page"); + assert!(saved.body.contains("Label under the ink"), "the page text stayed"); + assert_eq!(saved.body.contains("strokes may not line up"), !keeps_layout, "{format:?}: {}", saved.body); + let svg = fs::read_to_string(dir.join(INK_FILE)).expect("the ink stayed"); + let (drawing, lost) = notecraft_ink::svg::read(&svg).expect("read the saved ink"); + assert_eq!((drawing.strokes.len(), lost), (1, 0)); + assert!(drawing.bounds().is_some_and(|(x, y, _, _)| x > 30.0 && y > 60.0), "the ink kept its position"); + } + } + } + /// A page whose ink the reader stopped short of says on the page that some may be missing, /// beside any count of strokes it could not read. #[test] diff --git a/crates/ui-egui/src/pagemenu.rs b/crates/ui-egui/src/pagemenu.rs index 54316cc4..68c0195a 100644 --- a/crates/ui-egui/src/pagemenu.rs +++ b/crates/ui-egui/src/pagemenu.rs @@ -206,9 +206,29 @@ pub fn items_with(ui: &mut Ui, acts: &mut Vec, clipboard: bool, t: &Tokens, item(ui, Glyph::Icon(Icon::Table), "Table", Act::Insert("table"), true); item(ui, Glyph::Icon(Icon::Link), "Link", Act::Insert("link"), true); item(ui, Glyph::Icon(Icon::Equation), "Equation", Act::Insert("equation"), true); - item(ui, Glyph::Icon(Icon::Calendar), "Date and time", Act::Insert("datetime"), true); + item(ui, Glyph::Icon(Icon::Calendar), crate::tl_id!("ui.page_menu_date_and_time"), Act::Insert("datetime"), true); floating::menu_separator(ui, t); item(ui, Glyph::Icon(Icon::Picture), "Picture from a file", Act::AddPicture, true); - item(ui, Glyph::Icon(Icon::Attach), "Attach a file", Act::AddFile, true); + item(ui, Glyph::Icon(Icon::Attach), crate::tl_id!("ui.page_menu_attach_a_file"), Act::AddFile, true); picked } + +#[cfg(test)] +mod tests { + use super::*; + use egui_kittest::kittest::Queryable as _; + + #[test] + fn page_menu_localizes_date_and_attachment_actions() { + for (language, date, file) in [("de", "Datum und Uhrzeit", "Datei anh\u{e4}ngen"), ("en-XA", "$$$Date and time@@@", "$$$Attach a file@@@")] { + crate::i18n::set_current(language); + let theme = crate::theme::Theme::DEFAULT.tokens(); + let mut harness = egui_kittest::Harness::builder().with_accessibility_check(false).build_ui(move |ui| { + items_with(ui, &mut Vec::new(), false, &theme, true); + }); + harness.run(); + assert!(harness.query_by_label(date).is_some(), "{language}: missing {date}"); + assert!(harness.query_by_label(file).is_some(), "{language}: missing {file}"); + } + } +} diff --git a/docs/gaps.md b/docs/gaps.md index 581136a5..2d4bd2e0 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -117,7 +117,8 @@ narrower than 600 points, on Android, a narrow desktop window or the browser bui Handwriting and drawings are read as strokes, from facts [MS-ONE] does not give (see `docs/research/onenote-file-format/ink.md`). A page with ink keeps its boxes where OneNote had them only when OneNote's boxes hold all of the page's blocks. Otherwise the text is laid out - in order, the ink keeps its page positions, and the page gives no notice. Text wraps + in order, the ink keeps its page positions, and the page warns that the strokes may not line up + with the content. Text wraps differently, so a mark over words can sit a little off. A very full page has its pen readings thinned, then strokes from the end left out, and the page says how many. A page nested too deep or too large to read whole says that some ink may be missing. diff --git a/i18n/ar-XB.tsv b/i18n/ar-XB.tsv index c0679070..eeb6474c 100644 --- a/i18n/ar-XB.tsv +++ b/i18n/ar-XB.tsv @@ -2231,3 +2231,5 @@ @id ui.attach_page_changed [[RLI]]$$$Another page was opened before the file was added. Open the page and add the file again.@@@[[PDI]] @id ui.search_in_handwriting [[RLI]]$$$In handwriting: {words}@@@[[PDI]] @id ui.browse_new_folder [[RLI]]$$$New Folder@@@[[PDI]] +@id ui.page_menu_date_and_time [[RLI]]$$$Date and time@@@[[PDI]] +@id ui.page_menu_attach_a_file [[RLI]]$$$Attach a file@@@[[PDI]] diff --git a/i18n/ar.tsv b/i18n/ar.tsv index 0bd19c35..c2a05bde 100644 --- a/i18n/ar.tsv +++ b/i18n/ar.tsv @@ -848,3 +848,5 @@ @id ui.template_arabesque_edge_ltr_page أرابيسك (edge) @id ui.template_arabesque_edge_rtl_page أرابيسك (edge, RTL) @id ui.browse_new_folder مجلد جديد +@id ui.page_menu_date_and_time التاريخ والوقت +@id ui.page_menu_attach_a_file إرفاق ملف diff --git a/i18n/de.tsv b/i18n/de.tsv index e58cf85d..a2ee0cf3 100644 --- a/i18n/de.tsv +++ b/i18n/de.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page Arabeske (edge) @id ui.template_arabesque_edge_rtl_page Arabeske (edge, RTL) @id ui.browse_new_folder Neuer Ordner +@id ui.page_menu_date_and_time Datum und Uhrzeit +@id ui.page_menu_attach_a_file Datei anhängen diff --git a/i18n/en-XA.tsv b/i18n/en-XA.tsv index 00172fba..10d6ff4c 100644 --- a/i18n/en-XA.tsv +++ b/i18n/en-XA.tsv @@ -2231,3 +2231,5 @@ @id ui.attach_page_changed $$$Another page was opened before the file was added. Open the page and add the file again.@@@ @id ui.search_in_handwriting $$$In handwriting: {words}@@@ @id ui.browse_new_folder $$$New Folder@@@ +@id ui.page_menu_date_and_time $$$Date and time@@@ +@id ui.page_menu_attach_a_file $$$Attach a file@@@ diff --git a/i18n/en.tsv b/i18n/en.tsv index fe2b5a45..7977a6ac 100644 --- a/i18n/en.tsv +++ b/i18n/en.tsv @@ -2231,3 +2231,5 @@ @id ui.attach_page_changed Another page was opened before the file was added. Open the page and add the file again. @id ui.search_in_handwriting In handwriting: {words} @id ui.browse_new_folder New Folder +@id ui.page_menu_date_and_time Date and time +@id ui.page_menu_attach_a_file Attach a file diff --git a/i18n/es.tsv b/i18n/es.tsv index 8774ee71..0cd3843d 100644 --- a/i18n/es.tsv +++ b/i18n/es.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page Arabesco (edge) @id ui.template_arabesque_edge_rtl_page Arabesco (edge, RTL) @id ui.browse_new_folder Nueva carpeta +@id ui.page_menu_date_and_time Fecha y hora +@id ui.page_menu_attach_a_file Adjuntar un archivo diff --git a/i18n/fa.tsv b/i18n/fa.tsv index ef40bfd4..46dd289e 100644 --- a/i18n/fa.tsv +++ b/i18n/fa.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page آرابسک (edge) @id ui.template_arabesque_edge_rtl_page آرابسک (edge, RTL) @id ui.browse_new_folder پوشهٔ جدید +@id ui.page_menu_date_and_time تاریخ و زمان +@id ui.page_menu_attach_a_file پیوست کردن فایل diff --git a/i18n/fr.tsv b/i18n/fr.tsv index 0ed12d69..79520e7b 100644 --- a/i18n/fr.tsv +++ b/i18n/fr.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page Arabesque (edge) @id ui.template_arabesque_edge_rtl_page Arabesque (edge, RTL) @id ui.browse_new_folder Nouveau dossier +@id ui.page_menu_date_and_time Date et heure +@id ui.page_menu_attach_a_file Joindre un fichier diff --git a/i18n/he.tsv b/i18n/he.tsv index f355bba9..92adda7f 100644 --- a/i18n/he.tsv +++ b/i18n/he.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page ארבסקה (edge) @id ui.template_arabesque_edge_rtl_page ארבסקה (edge, RTL) @id ui.browse_new_folder תיקייה חדשה +@id ui.page_menu_date_and_time תאריך ושעה +@id ui.page_menu_attach_a_file צירוף קובץ diff --git a/i18n/hi.tsv b/i18n/hi.tsv index 066ae6ee..627a0e61 100644 --- a/i18n/hi.tsv +++ b/i18n/hi.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page अरबेस्क (edge) @id ui.template_arabesque_edge_rtl_page अरबेस्क (edge, RTL) @id ui.browse_new_folder नया फ़ोल्डर +@id ui.page_menu_date_and_time तारीख और समय +@id ui.page_menu_attach_a_file फ़ाइल संलग्न करें diff --git a/i18n/ja.tsv b/i18n/ja.tsv index b09ec914..f26cbc80 100644 --- a/i18n/ja.tsv +++ b/i18n/ja.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page アラベスク (edge) @id ui.template_arabesque_edge_rtl_page アラベスク (edge, RTL) @id ui.browse_new_folder 新しいフォルダー +@id ui.page_menu_date_and_time 日付と時刻 +@id ui.page_menu_attach_a_file ファイルを添付 diff --git a/i18n/ko.tsv b/i18n/ko.tsv index 353b1748..5636fe8d 100644 --- a/i18n/ko.tsv +++ b/i18n/ko.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page 아라베스크 (edge) @id ui.template_arabesque_edge_rtl_page 아라베스크 (edge, RTL) @id ui.browse_new_folder 새 폴더 +@id ui.page_menu_date_and_time 날짜 및 시간 +@id ui.page_menu_attach_a_file 파일 첨부 diff --git a/i18n/nl.tsv b/i18n/nl.tsv index df981a53..53309a1d 100644 --- a/i18n/nl.tsv +++ b/i18n/nl.tsv @@ -2231,3 +2231,5 @@ @id ui.attach_page_changed Er is een andere pagina geopend voordat het bestand werd toegevoegd. Open de pagina en voeg het bestand opnieuw toe. @id ui.search_in_handwriting In handschrift: {words} @id ui.browse_new_folder Nieuwe map +@id ui.page_menu_date_and_time Datum en tijd +@id ui.page_menu_attach_a_file Een bestand bijvoegen diff --git a/i18n/ru.tsv b/i18n/ru.tsv index ab46343a..cac7abba 100644 --- a/i18n/ru.tsv +++ b/i18n/ru.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page Арабеска (edge) @id ui.template_arabesque_edge_rtl_page Арабеска (edge, RTL) @id ui.browse_new_folder Новая папка +@id ui.page_menu_date_and_time Дата и время +@id ui.page_menu_attach_a_file Прикрепить файл diff --git a/i18n/tr.tsv b/i18n/tr.tsv index 707b3d33..8f2a80ac 100644 --- a/i18n/tr.tsv +++ b/i18n/tr.tsv @@ -1440,3 +1440,5 @@ @id ui.template_arabesque_edge_ltr_page Arabesk (edge) @id ui.template_arabesque_edge_rtl_page Arabesk (edge, RTL) @id ui.browse_new_folder Yeni klasör +@id ui.page_menu_date_and_time Tarih ve saat +@id ui.page_menu_attach_a_file Dosya ekle diff --git a/i18n/ur.tsv b/i18n/ur.tsv index e2790b30..fd71ff77 100644 --- a/i18n/ur.tsv +++ b/i18n/ur.tsv @@ -844,3 +844,5 @@ @id ui.template_arabesque_edge_ltr_page عربیسک (edge) @id ui.template_arabesque_edge_rtl_page عربیسک (edge, RTL) @id ui.browse_new_folder نیا فولڈر +@id ui.page_menu_date_and_time تاریخ اور وقت +@id ui.page_menu_attach_a_file فائل منسلک کریں diff --git a/i18n/zh.tsv b/i18n/zh.tsv index fa256e43..d01ff447 100644 --- a/i18n/zh.tsv +++ b/i18n/zh.tsv @@ -847,3 +847,5 @@ @id ui.template_arabesque_edge_ltr_page 阿拉伯花纹 (edge) @id ui.template_arabesque_edge_rtl_page 阿拉伯花纹 (edge, RTL) @id ui.browse_new_folder 新建文件夹 +@id ui.page_menu_date_and_time 日期和时间 +@id ui.page_menu_attach_a_file 附加文件