forked from 1b-agent/opencadstudio-upstream
web: raster images, WBLOCK/SAVEALL/SCRIPT/CTB/LAYTRANS/INSERT, filled TTF text
A fresh web-vs-desktop audit found the remaining gaps; this closes the
top ten.
Raster images: IMAGE attach read the picked file via image::open on a
name-only path (dead on wasm), and raster references inside opened
drawings decoded the same way. Picked bytes are now registered in a
name-keyed store (the PDF-underlay pattern), decoding runs from memory,
and dropped .png/.jpg/.bmp/.tif files register by name so unresolved
references in opened drawings re-resolve and render (and export to PDF).
Command gaps fixed with the bytes-at-pick / download_bytes pattern:
- WBLOCK now downloads the extracted block instead of failing on fs.
- SAVEALL saves every dirty tab instead of printing a no-op message.
- SCRIPT picks and reads the .scr file through the browser picker.
- CENTERLTYPEFILE picks the .lin/.dnl file and populates from text.
- Custom .ctb tables picked on web now parse, register for the
session, appear in the plot dialog list, and apply (load_named
previously returned builtin-only on wasm).
- LAYTRANS 'Load standards file' parses the picked drawing on the
existing web worker.
- INSERT 'from file' in the block palette parses picked bytes and
feeds the shared import path.
Text fidelity: TTF-named styles rendered as thin stroke glyphs on web
because the font database was empty. Fetched Noto faces are now
registered into it with a family alias table (Arial, Times New Roman,
Cambria, ... -> Noto Sans/Serif), so those styles render filled, shape,
export to PDF as vector fills, and appear in the style picker.
ViewCube labels request semibold again on web.
docs/native-vs-web.md: the hatch and font rows were stale (both work on
web now), the GPU row claimed WebGPU is used where available (the
backend is pinned to OpenGL), and the parallelism row missed the parse
worker — all corrected.
(cherry picked from commit c643a10e)
Ported onto main (#1717 review): conflicts resolved toward main — the
font-file lookup, PDF searchable text, purge service, block palette and
plot-style copy stay as they are on main; the web pieces (font registry
and aliases, session plot styles, SCRIPT/SAVEALL/CENTERLTYPEFILE picks,
block-from-file on the web) are layered on top.
This commit is contained in:
1 parent
69fa7cae4f
commit
9cd898a17a
42 files changed
+1315
-155
No files matched your search
+72
-9
@@ -25,6 +25,9 @@ pub struct QueuedOpen {
|
||||
}
|
||||
|
||||
static DROPPED: Mutex<VecDeque<QueuedOpen>> = Mutex::new(VecDeque::new());
|
||||
// Dropped raster images never open as drawings: they are registered by name
|
||||
// so RasterImage entities the open drawing references can resolve them.
|
||||
static DROPPED_IMAGES: Mutex<VecDeque<(String, Vec<u8>)>> = Mutex::new(VecDeque::new());
|
||||
// `OnceLock::take` needs `&mut self`, which an immutable static cannot
|
||||
// provide — an AtomicBool swap gives the same set-once marker and can still
|
||||
// be reverted when no document exists.
|
||||
@@ -69,6 +72,32 @@ pub fn enqueue_open(name: String, bytes: Vec<u8>) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// Queue a dropped raster image for the poll to register as decodable bytes
|
||||
/// (name-keyed) — the web analogue of the drawing folder a drawing's images
|
||||
/// live beside natively. Returns `false` when the queue is full.
|
||||
pub fn enqueue_image(name: String, bytes: Vec<u8>) -> bool {
|
||||
let mut queue = DROPPED_IMAGES
|
||||
.lock()
|
||||
.unwrap_or_else(|poisoned| poisoned.into_inner());
|
||||
if queue.len() >= QUEUE_CAP {
|
||||
drop(queue);
|
||||
warn(&format!(
|
||||
"ocs: dropped-image queue full; ignoring \"{name}\""
|
||||
));
|
||||
return false;
|
||||
}
|
||||
queue.push_back((name, bytes));
|
||||
true
|
||||
}
|
||||
|
||||
/// Pop the oldest dropped image the poll has not registered yet.
|
||||
pub fn take_dropped_image() -> Option<(String, Vec<u8>)> {
|
||||
DROPPED_IMAGES
|
||||
.lock()
|
||||
.unwrap_or_else(|poisoned| poisoned.into_inner())
|
||||
.pop_front()
|
||||
}
|
||||
|
||||
/// Queue an autosave-restore file tagged with its snapshot key. Returns
|
||||
/// `false` when the queue is full and the bytes were dropped (the OPFS
|
||||
/// snapshot survives; the caller must not wait for an open that will
|
||||
@@ -162,22 +191,26 @@ pub fn install() {
|
||||
// reads that begin after the event returns, and parallel reads
|
||||
// would enqueue (and open) in completion order, not drop order.
|
||||
let mut reads: Vec<(String, js_sys::Promise)> = Vec::new();
|
||||
let mut image_reads: Vec<(String, js_sys::Promise)> = Vec::new();
|
||||
for index in 0..files.length() {
|
||||
let Some(file) = files.get(index) else {
|
||||
continue;
|
||||
};
|
||||
let name = file.name();
|
||||
// A drop has no picker filter: accept the formats the web Open
|
||||
// dialog accepts; anything else is logged, never parsed.
|
||||
if !is_drawing_name(&name) {
|
||||
// dialog accepts, plus the raster formats the IMAGE command
|
||||
// accepts; anything else is logged, never parsed.
|
||||
if is_drawing_name(&name) {
|
||||
reads.push((name, file.array_buffer()));
|
||||
} else if is_image_name(&name) {
|
||||
image_reads.push((name, file.array_buffer()));
|
||||
} else {
|
||||
warn(&format!(
|
||||
"ocs: ignored dropped file \"{name}\" (not .dwg/.dxf)"
|
||||
"ocs: ignored dropped file \"{name}\" (not .dwg/.dxf/image)"
|
||||
));
|
||||
continue;
|
||||
}
|
||||
reads.push((name, file.array_buffer()));
|
||||
}
|
||||
if reads.is_empty() {
|
||||
if reads.is_empty() && image_reads.is_empty() {
|
||||
return;
|
||||
}
|
||||
// The page is the only intended drop target; hide drawing drops
|
||||
@@ -189,8 +222,7 @@ pub fn install() {
|
||||
Ok(buffer) => {
|
||||
// A full queue warns on the console; the drop
|
||||
// handler has no command line to talk to.
|
||||
let _ =
|
||||
enqueue_open(name, js_sys::Uint8Array::new(&buffer).to_vec());
|
||||
let _ = enqueue_open(name, js_sys::Uint8Array::new(&buffer).to_vec());
|
||||
}
|
||||
Err(error) => {
|
||||
web_sys::console::error_1(&wasm_bindgen::JsValue::from_str(&format!(
|
||||
@@ -200,6 +232,19 @@ pub fn install() {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (name, read) in image_reads {
|
||||
match JsFuture::from(read).await {
|
||||
Ok(buffer) => {
|
||||
let _ = enqueue_image(name, js_sys::Uint8Array::new(&buffer).to_vec());
|
||||
}
|
||||
Err(error) => {
|
||||
web_sys::console::error_1(&wasm_bindgen::JsValue::from_str(&format!(
|
||||
"ocs: failed to read dropped image \"{name}\": {}",
|
||||
error.as_string().unwrap_or_else(|| format!("{error:?}"))
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -218,7 +263,25 @@ fn is_drawing_name(name: &str) -> bool {
|
||||
// a dot-less name is its own extension, so a file literally named
|
||||
// "DWG"/"dxf" parses and must not be filtered out here.
|
||||
matches!(
|
||||
name.rsplit('.').next().unwrap_or_default().to_ascii_lowercase().as_str(),
|
||||
name.rsplit('.')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.to_ascii_lowercase()
|
||||
.as_str(),
|
||||
"dwg" | "dxf"
|
||||
)
|
||||
}
|
||||
|
||||
/// The decodable raster set matches the IMAGE picker's filter (and the `image`
|
||||
/// crate features the app builds with) — anything else would queue bytes that
|
||||
/// can only ever fail to decode.
|
||||
fn is_image_name(name: &str) -> bool {
|
||||
matches!(
|
||||
name.rsplit('.')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.to_ascii_lowercase()
|
||||
.as_str(),
|
||||
"png" | "jpg" | "jpeg" | "bmp" | "tiff" | "tif"
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user