pub struct CmcFile {
pub project: CmcProject,
pub nodes: Vec<CanvasNode>,
/* private fields */
}Expand description
An open .cmc. Changes stay in memory until CmcFile::save.
Fields§
§project: CmcProjectThe work settings.
nodes: Vec<CanvasNode>Every CanvasNode row, in table order (the page order is CmcFile::pages).
Implementations§
Source§impl CmcFile
impl CmcFile
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Reads a .cmc. The file is not kept open or changed.
Sourcepub fn from_bytes(data: Vec<u8>) -> Result<Self>
pub fn from_bytes(data: Vec<u8>) -> Result<Self>
Parses the bytes of a .cmc (a plain SQLite file).
Sourcepub fn database(&self) -> &Connection
pub fn database(&self) -> &Connection
The database (in memory; changes are saved by CmcFile::save).
Sourcepub fn version_info(&self) -> Result<VersionInfo>
pub fn version_info(&self) -> Result<VersionInfo>
Which CSP generation saved the work file (see crate::version).
Sourcepub fn node(&self, main_id: i64) -> Option<&CanvasNode>
pub fn node(&self, main_id: i64) -> Option<&CanvasNode>
The node with this MainId.
Sourcepub fn root(&self) -> Result<&CanvasNode>
pub fn root(&self) -> Result<&CanvasNode>
The root node (Project.ProjectRootCanvasNode, else the first node of type NODE_ROOT).
Sourcepub fn pages(&self) -> Result<Vec<&CanvasNode>>
pub fn pages(&self) -> Result<Vec<&CanvasNode>>
Pages in reading order (the linked list from the root).
Sourcepub fn positions(&self) -> Result<Vec<PageSlot>>
pub fn positions(&self) -> Result<Vec<PageSlot>>
Each page’s position in the work (pages counted from 0, a spread
counts 2) and side, from the page list: what CSP writes into the
page files’ ComicPageIndex / ComicIsLeftPage when it opens them.
Works with a cover number their 表3・表4 pages differently.
Sourcepub fn page_paths(&self, folder: &Path) -> Result<Vec<PathBuf>>
pub fn page_paths(&self, folder: &Path) -> Result<Vec<PathBuf>>
Absolute path of each page file, given the .cmc’s folder.
Sourcepub fn page_thumbnail(
&self,
folder: &Path,
node: &CanvasNode,
) -> Result<Option<RgbaImage>>
pub fn page_thumbnail( &self, folder: &Path, node: &CanvasNode, ) -> Result<Option<RgbaImage>>
The thumbnail CSP shows for a page in the work’s page list: the page
file’s CanvasPreview (CanvasNode.CanvasThumbnail is unset in every
.cmc seen). None when the page has no file or no preview.
Sourcepub fn findings(&self, folder: Option<&Path>) -> Vec<String>
pub fn findings(&self, folder: Option<&Path>) -> Vec<String>
Structural problems; with folder, also page files that are missing.
Sourcepub fn reorder(&mut self, order: &[i64]) -> Result<()>
pub fn reorder(&mut self, order: &[i64]) -> Result<()>
Put the pages in the given order (every page exactly once).
Sourcepub fn add_page(
&mut self,
after: Option<i64>,
spread: bool,
) -> Result<(i64, String)>
pub fn add_page( &mut self, after: Option<i64>, spread: bool, ) -> Result<(i64, String)>
Add a page after after (None = at the end). Returns the new node’s
MainId and the page file name to create next to the .cmc (for
example a copy of another page).
Sourcepub fn remove_page(&mut self, main_id: i64) -> Result<Option<PathBuf>>
pub fn remove_page(&mut self, main_id: i64) -> Result<Option<PathBuf>>
Take a page out of the list and delete its node. The page file is left alone (the caller decides whether to delete it).
Sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Something was changed since the file was read.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>>
pub fn to_bytes(&self) -> Result<Vec<u8>>
The file bytes: the original bytes when nothing changed.
Sourcepub fn save(&self, path: impl AsRef<Path>) -> Result<()>
pub fn save(&self, path: impl AsRef<Path>) -> Result<()>
Writes CmcFile::to_bytes to a file.
path is replaced if it exists, and nothing checks whether it is
the file this was read from. Saving over the source is possible (its
bytes were read into memory), but a failed or interrupted write then
loses the original; keeping inputs intact is the caller’s job. The
cspf tool refuses an output that is one of its inputs.
Source§impl CmcFile
impl CmcFile
Sourcepub fn set_pages(&mut self, links: &[PageLink]) -> Result<()>
pub fn set_pages(&mut self, links: &[PageLink]) -> Result<()>
Replace the page list with one page per link, in order, keeping every work setting. The page files must be (or be put) in the folder of the saved .cmc.
Sourcepub fn set_project_value(&mut self, column: &str, value: Value) -> Result<bool>
pub fn set_project_value(&mut self, column: &str, value: Value) -> Result<bool>
Set one Project column; false when the work file does not have it.