Add pdf.rs viewer
This commit is contained in:
54
src/viewer/pdf.rs
Normal file
54
src/viewer/pdf.rs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
//! PDF 檢視器
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
pub struct PdfViewer {
|
||||||
|
path: Option<String>,
|
||||||
|
current_page: u32,
|
||||||
|
total_pages: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PdfViewer {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
path: None,
|
||||||
|
current_page: 1,
|
||||||
|
total_pages: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open(&mut self, path: &str) -> Result<()> {
|
||||||
|
self.path = Some(path.to_string());
|
||||||
|
self.current_page = 1;
|
||||||
|
self.total_pages = self.get_page_count()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_page_count(&self) -> Result<u32> {
|
||||||
|
Ok(10)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_page(&mut self) {
|
||||||
|
if self.current_page < self.total_pages {
|
||||||
|
self.current_page += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn prev_page(&mut self) {
|
||||||
|
if self.current_page > 1 {
|
||||||
|
self.current_page -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn go_to_page(&mut self, page: u32) {
|
||||||
|
self.current_page = page.clamp(1, self.total_pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_page(&self) -> u32 {
|
||||||
|
self.current_page
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_total(&self) -> u32 {
|
||||||
|
self.total_pages
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user