summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-02-03 10:37:50 +0100
committerLaurenz <laurmaedje@gmail.com>2020-02-03 10:37:50 +0100
commit40ea35cbe7482ce04096c4d63a848c8601cc1848 (patch)
tree080a5727ba552ee4b2bf750208e5c243c1e195ef /src/layout
parent20fb4e7c379b79b84d9884d5f2c89d781c5793e2 (diff)
Upgrade to new toddle interface 🐳
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/model.rs18
-rw-r--r--src/layout/text.rs17
2 files changed, 19 insertions, 16 deletions
diff --git a/src/layout/model.rs b/src/layout/model.rs
index 1d635f5c..2eac9a8c 100644
--- a/src/layout/model.rs
+++ b/src/layout/model.rs
@@ -5,8 +5,9 @@
use std::future::Future;
use std::pin::Pin;
use smallvec::smallvec;
-use toddle::query::SharedFontLoader;
+use toddle::query::{SharedFontLoader, FontProvider};
+use crate::GlobalFontLoader;
use crate::error::Errors;
use crate::style::{LayoutStyle, PageStyle, TextStyle};
use crate::size::{Size, Size2D};
@@ -18,8 +19,8 @@ use super::*;
/// Performs the model layouting.
-pub struct ModelLayouter<'a, 'p> {
- ctx: LayoutContext<'a, 'p>,
+pub struct ModelLayouter<'a> {
+ ctx: LayoutContext<'a>,
layouter: LineLayouter,
style: LayoutStyle,
errors: Errors,
@@ -27,10 +28,10 @@ pub struct ModelLayouter<'a, 'p> {
/// The context for layouting.
#[derive(Debug, Clone)]
-pub struct LayoutContext<'a, 'p> {
+pub struct LayoutContext<'a> {
/// The font loader to retrieve fonts from when typesetting text
/// using [`layout_text`].
- pub loader: &'a SharedFontLoader<'p>,
+ pub loader: &'a GlobalFontLoader,
/// The style for pages and text.
pub style: &'a LayoutStyle,
/// The base unpadded dimensions of this container (for relative sizing).
@@ -105,7 +106,7 @@ pub enum Command<'a> {
}
/// Layout a syntax model into a list of boxes.
-pub async fn layout(model: &SyntaxModel, ctx: LayoutContext<'_, '_>) -> Layouted<MultiLayout> {
+pub async fn layout(model: &SyntaxModel, ctx: LayoutContext<'_>) -> Layouted<MultiLayout> {
let mut layouter = ModelLayouter::new(ctx);
layouter.layout_syntax_model(model).await;
layouter.finish()
@@ -116,9 +117,9 @@ pub async fn layout(model: &SyntaxModel, ctx: LayoutContext<'_, '_>) -> Layouted
/// work internally.
pub type DynFuture<'a, T> = Pin<Box<dyn Future<Output=T> + 'a>>;
-impl<'a, 'p> ModelLayouter<'a, 'p> {
+impl<'a> ModelLayouter<'a> {
/// Create a new model layouter.
- pub fn new(ctx: LayoutContext<'a, 'p>) -> ModelLayouter<'a, 'p> {
+ pub fn new(ctx: LayoutContext<'a>) -> ModelLayouter<'a> {
ModelLayouter {
layouter: LineLayouter::new(LineContext {
spaces: ctx.spaces.clone(),
@@ -182,6 +183,7 @@ impl<'a, 'p> ModelLayouter<'a, 'p> {
Some("monospace") => { list.remove(0); },
_ => list.insert(0, "monospace".to_string()),
}
+ self.style.text.fallback.flatten();
}
Node::Model(model) => {
diff --git a/src/layout/text.rs b/src/layout/text.rs
index a0f47643..6b512a07 100644
--- a/src/layout/text.rs
+++ b/src/layout/text.rs
@@ -4,17 +4,18 @@
//! When the primary layouting axis horizontally inversed, the word is spelled
//! backwards. Vertical word layout is not yet supported.
-use toddle::query::{SharedFontLoader, FontQuery, FontIndex};
+use toddle::query::{FontQuery, FontIndex};
use toddle::tables::{CharMap, Header, HorizontalMetrics};
+use crate::GlobalFontLoader;
use crate::size::{Size, Size2D};
use crate::style::TextStyle;
use super::*;
/// Performs the text layouting.
-struct TextLayouter<'a, 'p> {
- ctx: TextContext<'a, 'p>,
+struct TextLayouter<'a> {
+ ctx: TextContext<'a>,
text: &'a str,
actions: LayoutActions,
buffer: String,
@@ -24,10 +25,10 @@ struct TextLayouter<'a, 'p> {
/// The context for text layouting.
#[derive(Copy, Clone)]
-pub struct TextContext<'a, 'p> {
+pub struct TextContext<'a> {
/// The font loader to retrieve fonts from when typesetting text
/// using [`layout_text`].
- pub loader: &'a SharedFontLoader<'p>,
+ pub loader: &'a GlobalFontLoader,
/// The style for text: Font selection with classes, weights and variants,
/// font sizes, spacing and so on.
pub style: &'a TextStyle,
@@ -39,13 +40,13 @@ pub struct TextContext<'a, 'p> {
}
/// Layouts text into a box.
-pub async fn layout_text(text: &str, ctx: TextContext<'_, '_>) -> Layout {
+pub async fn layout_text(text: &str, ctx: TextContext<'_>) -> Layout {
TextLayouter::new(text, ctx).layout().await
}
-impl<'a, 'p> TextLayouter<'a, 'p> {
+impl<'a> TextLayouter<'a> {
/// Create a new text layouter.
- fn new(text: &'a str, ctx: TextContext<'a, 'p>) -> TextLayouter<'a, 'p> {
+ fn new(text: &'a str, ctx: TextContext<'a>) -> TextLayouter<'a> {
TextLayouter {
ctx,
text,