Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,34 +651,45 @@ impl<R: Read + Seek> EpubDoc<R> {
/// # use epub::doc::EpubDoc;
/// # let doc = EpubDoc::new("test.epub");
/// # let mut doc = doc.unwrap();
/// assert_eq!(17, doc.get_num_pages());
/// assert_eq!(17, doc.get_num_chapters());
/// ```
pub fn get_num_pages(&self) -> usize {
pub fn get_num_chapters(&self) -> usize {
self.spine.len()
}

#[deprecated(note="please use `get_num_chapters` instead")]
pub fn get_num_pages(&self) -> usize {
self.get_num_chapters()
}

/// Returns the current chapter number, starting from 0
pub fn get_current_page(&self) -> usize {
pub fn get_current_chapter(&self) -> usize {
self.current
}

/// Changes the current page
#[deprecated(note="please use `get_current_chapter` instead")]
pub fn get_current_page(&self) -> usize {
self.get_current_chapter()
}


/// Changes the current chapter
///
/// # Examples
///
/// ```
/// # use epub::doc::EpubDoc;
/// # let doc = EpubDoc::new("test.epub");
/// # let mut doc = doc.unwrap();
/// assert_eq!(0, doc.get_current_page());
/// doc.set_current_page(2);
/// assert_eq!(0, doc.get_current_chapter());
/// doc.set_current_chapter(2);
/// assert_eq!("001.xhtml", doc.get_current_id().unwrap());
/// assert_eq!(2, doc.get_current_page());
/// assert!(!doc.set_current_page(50));
/// assert_eq!(2, doc.get_current_chapter());
/// assert!(!doc.set_current_chapter(50));
/// ```
///
/// Returns [`false`] if the page is out of bounds
pub fn set_current_page(&mut self, n: usize) -> bool {
/// Returns [`false`] if the chapter is out of bounds
pub fn set_current_chapter(&mut self, n: usize) -> bool {
if n >= self.spine.len() {
false
} else {
Expand All @@ -687,7 +698,13 @@ impl<R: Read + Seek> EpubDoc<R> {
}
}

/// This will inject this css in every html page getted with
#[deprecated(note="please use `set_current_chapter` instead")]
pub fn set_current_page(&mut self, n: usize) -> bool {
self.set_current_chapter(n)
}


/// This will inject arbitrary css into every queried html page
/// [`Self::get_current_with_epub_uris`]
///
/// # Examples
Expand All @@ -696,7 +713,7 @@ impl<R: Read + Seek> EpubDoc<R> {
/// # use epub::doc::EpubDoc;
/// # let doc = EpubDoc::new("test.epub");
/// # let mut doc = doc.unwrap();
/// # let _ = doc.set_current_page(2);
/// # let _ = doc.set_current_chapter(2);
/// let extracss = "body { background-color: black; color: white }";
/// doc.add_extra_css(extracss);
/// let current = doc.get_current_with_epub_uris().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
//! use epub::doc::EpubDoc;
//! let doc = EpubDoc::new("test.epub");
//! let mut doc = doc.unwrap();
//! assert_eq!(0, doc.get_current_page());
//! assert_eq!(0, doc.get_current_chapter());
//! assert_eq!("application/xhtml+xml", doc.get_current_mime().unwrap());
//!
//! doc.go_next();
Expand All @@ -83,13 +83,13 @@
//! doc.go_prev();
//! assert_eq!("000.xhtml", doc.get_current_id().unwrap());
//!
//! doc.set_current_page(2);
//! doc.set_current_chapter(2);
//! assert_eq!("001.xhtml", doc.get_current_id().unwrap());
//! assert_eq!(2, doc.get_current_page());
//! assert!(!doc.set_current_page(50));
//! assert_eq!(2, doc.get_current_chapter());
//! assert!(!doc.set_current_chapter(50));
//!
//! // doc.get_current() will return a Vec<u8> with the current page content
//! // doc.get_current_str() will return a String with the current page content
//! // doc.get_current() will return a Vec<u8> with the current chapter content
//! // doc.get_current_str() will return a String with the current chapter content
//! ```
//!
//! ## Getting the cover
Expand Down
2 changes: 1 addition & 1 deletion tests/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn read_doc() {
} else {
println!("Book title not found");
}
println!("Num Pages: {}\n", doc.get_num_pages());
println!("Num Pages: {}\n", doc.get_num_chapters());

{
println!("resources:\n");
Expand Down
Loading