mirror of
https://github.com/typst/typst
synced 2025-08-15 07:28:32 +08:00
Set main text direction
This commit is contained in:
parent
23741720ca
commit
c990ced644
@ -1,13 +1,26 @@
|
|||||||
use ecow::EcoString;
|
use ecow::EcoString;
|
||||||
use krilla::interchange::metadata::Metadata;
|
use krilla::interchange::metadata::{Metadata, TextDirection};
|
||||||
use typst_library::foundations::{Datetime, Smart};
|
use typst_library::foundations::{Datetime, Smart};
|
||||||
|
use typst_library::layout::Dir;
|
||||||
|
use typst_library::text::Lang;
|
||||||
use crate::convert::GlobalContext;
|
use crate::convert::GlobalContext;
|
||||||
use crate::Timezone;
|
use crate::Timezone;
|
||||||
|
|
||||||
pub(crate) fn build_metadata(gc: &GlobalContext) -> Metadata {
|
pub(crate) fn build_metadata(gc: &GlobalContext) -> Metadata {
|
||||||
let creator = format!("Typst {}", env!("CARGO_PKG_VERSION"));
|
let creator = format!("Typst {}", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
|
let lang = gc
|
||||||
|
.languages
|
||||||
|
.iter()
|
||||||
|
.max_by_key(|(_, &count)| count)
|
||||||
|
.map(|(&l, _)| l);
|
||||||
|
|
||||||
|
let dir = if lang.map(Lang::dir) == Some(Dir::RTL) {
|
||||||
|
TextDirection::RightToLeft
|
||||||
|
} else {
|
||||||
|
TextDirection::LeftToRight
|
||||||
|
};
|
||||||
|
|
||||||
let mut metadata = Metadata::new()
|
let mut metadata = Metadata::new()
|
||||||
.creator(creator)
|
.creator(creator)
|
||||||
.keywords(gc.document.info.keywords.iter().map(EcoString::to_string).collect())
|
.keywords(gc.document.info.keywords.iter().map(EcoString::to_string).collect())
|
||||||
@ -47,6 +60,8 @@ pub(crate) fn build_metadata(gc: &GlobalContext) -> Metadata {
|
|||||||
metadata = metadata.modification_date(date).creation_date(date);
|
metadata = metadata.modification_date(date).creation_date(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metadata = metadata.text_direction(dir);
|
||||||
|
|
||||||
metadata
|
metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user