Skip to content

Commit

Permalink
applied cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
RikaKit committed May 14, 2024
1 parent 38fa1ff commit 5045565
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
7 changes: 5 additions & 2 deletions examples/extract_stext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ fn main() {
// cargo run --example extract_stext
let mut path_to_doc = String::new();
println!("Enter a path to document: ");
io::stdin().read_line(&mut path_to_doc).expect("Failed to read line");
io::stdin()
.read_line(&mut path_to_doc)
.expect("Failed to read line");
let doc = mupdf::document::Document::open(path_to_doc.trim()).unwrap();
let page = doc.load_page(0).unwrap();
match page.stext_page_as_json_from_page(1.0) {
Ok(stext_json) => {
let stext_page: serde_json::Result<mupdf::page::StextPage> = serde_json::from_str(stext_json.as_str());
let stext_page: serde_json::Result<mupdf::page::StextPage> =
serde_json::from_str(stext_json.as_str());
match stext_page {
Ok(res) => {
for block in res.blocks {
Expand Down
22 changes: 15 additions & 7 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use mupdf_sys::*;

use crate::{
Buffer, Colorspace, context, Cookie, Device, DisplayList, Error, Link, Matrix, Pixmap, Quad,
context, Buffer, Colorspace, Cookie, Device, DisplayList, Error, Link, Matrix, Pixmap, Quad,
Rect, Separations, TextPage, TextPageOptions,
};

Expand Down Expand Up @@ -239,7 +239,11 @@ impl Page {

pub fn stext_page_as_json_from_page(&self, scale: f32) -> Result<String, Error> {
let mut buf = unsafe {
let inner = ffi_try!(mupdf_stext_page_as_json_from_page(context(), self.inner, scale));
let inner = ffi_try!(mupdf_stext_page_as_json_from_page(
context(),
self.inner,
scale
));
Buffer::from_raw(inner)
};
let mut res = String::new();
Expand Down Expand Up @@ -360,7 +364,7 @@ impl Iterator for LinkIter {
ptr::null_mut(),
ptr::null_mut(),
)
.page;
.page;
}
Some(Link {
bounds,
Expand Down Expand Up @@ -413,18 +417,22 @@ pub struct StextPage {

#[cfg(test)]
mod test {
use crate::{Document, Matrix};
use crate::page::StextPage;
use crate::{Document, Matrix};

#[test]
fn test_get_stext_page_as_json() {
let path_to_doc = std::env::current_dir().unwrap()
.join("tests").join("files").join("dummy.pdf");
let path_to_doc = std::env::current_dir()
.unwrap()
.join("tests")
.join("files")
.join("dummy.pdf");
let doc = Document::open(path_to_doc.to_str().unwrap()).unwrap();
let page = doc.load_page(0).unwrap();
match page.stext_page_as_json_from_page(1.0) {
Ok(stext_json) => {
let stext_page: serde_json::Result<StextPage> = serde_json::from_str(stext_json.as_str());
let stext_page: serde_json::Result<StextPage> =
serde_json::from_str(stext_json.as_str());
match stext_page {
Ok(res) => {
for block in res.blocks {
Expand Down

0 comments on commit 5045565

Please sign in to comment.