Skip to main content

CmcFile

Struct CmcFile 

Source
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: CmcProject

The work settings.

§nodes: Vec<CanvasNode>

Every CanvasNode row, in table order (the page order is CmcFile::pages).

Implementations§

Source§

impl CmcFile

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Reads a .cmc. The file is not kept open or changed.

Source

pub fn from_bytes(data: Vec<u8>) -> Result<Self>

Parses the bytes of a .cmc (a plain SQLite file).

Source

pub fn database(&self) -> &Connection

The database (in memory; changes are saved by CmcFile::save).

Source

pub fn version_info(&self) -> Result<VersionInfo>

Which CSP generation saved the work file (see crate::version).

Source

pub fn node(&self, main_id: i64) -> Option<&CanvasNode>

The node with this MainId.

Source

pub fn root(&self) -> Result<&CanvasNode>

The root node (Project.ProjectRootCanvasNode, else the first node of type NODE_ROOT).

Source

pub fn pages(&self) -> Result<Vec<&CanvasNode>>

Pages in reading order (the linked list from the root).

Source

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.

Source

pub fn page_paths(&self, folder: &Path) -> Result<Vec<PathBuf>>

Absolute path of each page file, given the .cmc’s folder.

Source

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.

Source

pub fn findings(&self, folder: Option<&Path>) -> Vec<String>

Structural problems; with folder, also page files that are missing.

Source

pub fn reorder(&mut self, order: &[i64]) -> Result<()>

Put the pages in the given order (every page exactly once).

Source

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).

Source

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).

Source

pub fn is_modified(&self) -> bool

Something was changed since the file was read.

Source

pub fn to_bytes(&self) -> Result<Vec<u8>>

The file bytes: the original bytes when nothing changed.

Source

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

Source

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.

Source

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.

Source

pub fn page_canvas_values(&self) -> Result<Vec<(String, Value)>>

The work settings the pages keep a copy of in their Canvas row: the story info (ComicStory*: 作品名, 話数, 作者名, ノンブル) and ComicBindPosition. Pages made from another work’s template would otherwise show that work’s.

Source

pub fn save_with_pages( &mut self, output: &Path, pages: &[PathBuf], ) -> Result<()>

Save this work (a template) as output listing pages in order. Every page file must already be in the folder of output, because CSP finds pages relative to the .cmc.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.