chore: inital commit
Split project into a Cargo workspace with two crates: - core/ (noctua_core): UI-independent document library - ui/ (noctua_ui): COSMIC application scaffold (empty) justfile for workspace (run, run-cli, check, test, build)
This commit is contained in:
commit
c85f35310e
31 changed files with 9768 additions and 0 deletions
72
core/src/document/loader.rs
Normal file
72
core/src/document/loader.rs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// src/document/loader.rs
|
||||
//
|
||||
// Document loading: format dispatch and directory scanning.
|
||||
|
||||
use crate::document::format::{detect_format, DocumentFormat};
|
||||
use crate::document::portable::PortableModel;
|
||||
use crate::document::raster::RasterModel;
|
||||
use crate::document::session::{SessionData, SessionItem};
|
||||
use crate::document::vector::VectorModel;
|
||||
use crate::document::{core::PageLayout, DocumentContent};
|
||||
use crate::error::{Error, Result};
|
||||
use std::path::Path;
|
||||
|
||||
/// Loads a document from a path and returns its content.
|
||||
pub fn load_document(path: &Path) -> Result<DocumentContent> {
|
||||
if !path.exists() {
|
||||
return Err(Error::NotFound(format!("{:?}", path)));
|
||||
}
|
||||
|
||||
match detect_format(path) {
|
||||
Some(DocumentFormat::Portable) => {
|
||||
// TODO: Replace with actual pdfium-render loading.
|
||||
Ok(DocumentContent::Portable(PortableModel {
|
||||
path: path.to_path_buf(),
|
||||
page_count: 3,
|
||||
layout: PageLayout::new(vec![(595.0, 842.0); 3], 10.0),
|
||||
}))
|
||||
}
|
||||
Some(DocumentFormat::Vector) => {
|
||||
// TODO: Replace with actual usvg parsing.
|
||||
Ok(DocumentContent::Vector(VectorModel {
|
||||
path: path.to_path_buf(),
|
||||
view_box: None,
|
||||
}))
|
||||
}
|
||||
Some(DocumentFormat::Raster) => {
|
||||
// TODO: Replace with actual image-crate loading.
|
||||
Ok(DocumentContent::Raster(RasterModel {
|
||||
path: path.to_path_buf(),
|
||||
dimensions: (1920, 1080),
|
||||
}))
|
||||
}
|
||||
None => Err(Error::Unsupported(format!(
|
||||
"extension: {}",
|
||||
path.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.unwrap_or("(none)")
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
/// Scans a directory for supported files and populates the session.
|
||||
pub fn scan_directory_into(session: &mut SessionData, dir: &Path) {
|
||||
if let Ok(entries) = std::fs::read_dir(dir) {
|
||||
let mut paths: Vec<_> = entries
|
||||
.filter_map(|e| e.ok())
|
||||
.map(|e| e.path())
|
||||
.filter(|p| p.is_file() && detect_format(p).is_some())
|
||||
.collect();
|
||||
|
||||
paths.sort();
|
||||
|
||||
session.items = paths.into_iter().map(|p| SessionItem::new(p, 0)).collect();
|
||||
}
|
||||
|
||||
session.current_index = if session.items.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(0)
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue