forked from 1b-agent/opencadstudio-upstream
fix(mtext): show preview glyphs and make Enter break the line
Two defects in the in-app MTEXT editor, both surfaced once the preview text became visible: 1. Invisible preview text. After the SDF text migration, tessellate emits glyphs as SDF quads on `text_verts` and leaves the polyline `points` empty, but the editor preview draws on a 2D canvas that can't run the SDF shader — so only the selection box showed. Add a `force_text_strokes` parameter to tessellate: when set, TEXT/MTEXT run-groups also emit their glyph outline strokes as points. The preview passes true (real stroke font, aligned with glyph_boxes); every other caller passes false and keeps SDF-only text. 2. Enter did not start a new line. mtext_type inserted a literal newline, but the MTEXT layout only breaks on the `\P` code (a raw 0x0A is a break only to the caret logic). Normalise every literal newline — from Enter or a multi-line paste — to `\P`, so the line breaks and the saved value stays standard. Closes #308 Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
cf4074b0f2
commit
d37dabb0fb
6 files changed
+33
-2
No files matched your search
@@ -409,6 +409,9 @@ impl super::OpenCADStudio {
|
||||
anno,
|
||||
None,
|
||||
bg,
|
||||
// Editor preview draws on a 2D canvas with no SDF shader — force the
|
||||
// glyph outline strokes so the text is visible (#308).
|
||||
true,
|
||||
);
|
||||
// Per-character boxes share the preview wires' absolute coordinate frame.
|
||||
let boxes = crate::entities::mtext::glyph_boxes(&mt, &self.tabs[i].scene.document);
|
||||
@@ -509,6 +512,21 @@ impl super::OpenCADStudio {
|
||||
|
||||
/// Insert text (or replace the current selection) at the preview caret.
|
||||
pub(super) fn mtext_type(&mut self, s: &str) {
|
||||
// MTEXT stores a hard line break as the `\P` code. A literal newline —
|
||||
// from Enter or a multi-line paste — is not a break to the layout (only
|
||||
// the caret logic honours it), so the preview would stay on one line.
|
||||
// Normalise every literal newline to `\P` so it breaks and the saved
|
||||
// value stays standard (#308).
|
||||
let normalized;
|
||||
let s: &str = if s.contains(['\n', '\r']) {
|
||||
normalized = s
|
||||
.replace("\r\n", "\\P")
|
||||
.replace('\n', "\\P")
|
||||
.replace('\r', "\\P");
|
||||
&normalized
|
||||
} else {
|
||||
s
|
||||
};
|
||||
if let Some(ed) = self.mtext_editor.as_mut() {
|
||||
let raw0 = ed.content.text();
|
||||
let raw = raw0.clone();
|
||||
|
||||
Reference in new issue
Block a user