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 krilla::interchange::metadata::Metadata;
|
||||
use krilla::interchange::metadata::{Metadata, TextDirection};
|
||||
use typst_library::foundations::{Datetime, Smart};
|
||||
|
||||
use typst_library::layout::Dir;
|
||||
use typst_library::text::Lang;
|
||||
use crate::convert::GlobalContext;
|
||||
use crate::Timezone;
|
||||
|
||||
pub(crate) fn build_metadata(gc: &GlobalContext) -> Metadata {
|
||||
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()
|
||||
.creator(creator)
|
||||
.keywords(gc.document.info.keywords.iter().map(EcoString::to_string).collect())
|
||||
@ -46,6 +59,8 @@ pub(crate) fn build_metadata(gc: &GlobalContext) -> Metadata {
|
||||
if let Some(date) = date.and_then(|d| convert_date(d, tz)) {
|
||||
metadata = metadata.modification_date(date).creation_date(date);
|
||||
}
|
||||
|
||||
metadata = metadata.text_direction(dir);
|
||||
|
||||
metadata
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user