-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support to infer book meta from outline (#75)
* feat: partially support to infer book meta * fix: errors * fix: keep strict default meta source * dev: shrink modules * dev: remove one todo
- Loading branch information
1 parent
1cd5d6e
commit 54802cd
Showing
8 changed files
with
1,120 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typst::layout::Position as TypstPosition; | ||
|
||
/// A serializable physical position in a document. | ||
/// | ||
/// Note that it uses [`f32`] instead of [`f64`] as same as | ||
/// [`TypstPosition`] for the coordinates to improve both performance | ||
/// of serialization and calculation. It does sacrifice the floating | ||
/// precision, but it is enough in our use cases. | ||
/// | ||
/// Also see [`TypstPosition`]. | ||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)] | ||
pub struct DocumentPosition { | ||
/// The page, starting at 1. | ||
pub page_no: usize, | ||
/// The exact x-coordinate on the page (from the left, as usual). | ||
pub x: f32, | ||
/// The exact y-coordinate on the page (from the top, as usual). | ||
pub y: f32, | ||
} | ||
|
||
impl From<TypstPosition> for DocumentPosition { | ||
fn from(position: TypstPosition) -> Self { | ||
Self { | ||
page_no: position.page.into(), | ||
x: position.point.x.to_pt() as f32, | ||
y: position.point.y.to_pt() as f32, | ||
} | ||
} | ||
} | ||
|
||
// /// Unevaluated source span. | ||
// /// The raw source span is unsafe to serialize and deserialize. | ||
// /// Because the real source location is only known during liveness of | ||
// /// the compiled document. | ||
// pub type SourceSpan = typst::syntax::Span; | ||
|
||
// /// Raw representation of a source span. | ||
// pub type RawSourceSpan = u64; | ||
|
||
// /// A char position represented in form of line and column. | ||
// /// The position is encoded in Utf-8 or Utf-16, and the encoding is | ||
// /// determined by usage. | ||
// /// | ||
// pub struct CharPosition { | ||
// /// The line number, starting at 0. | ||
// line: usize, | ||
// /// The column number, starting at 0. | ||
// column: usize, | ||
// } | ||
|
||
// /// A resolved source (text) location. | ||
// /// | ||
// /// See [`CharPosition`] for the definition of the position inside a file. | ||
// pub struct SourceLocation { | ||
// filepath: PathBuf, | ||
// pos: CharPosition, | ||
// } | ||
// /// A resolved source (text) range. | ||
// /// | ||
// /// See [`CharPosition`] for the definition of the position inside a file. | ||
// pub struct SourceRange { | ||
// filepath: PathBuf, | ||
// start: CharPosition, | ||
// end: CharPosition, | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.