mirror of
https://github.com/typst/typst
synced 2025-07-29 23:37:55 +08:00
Compare commits
14 Commits
d8419c4a23
...
176d4f8345
Author | SHA1 | Date | |
---|---|---|---|
|
176d4f8345 | ||
|
b1c79b50d4 | ||
|
4629ede020 | ||
|
4aa6dcf578 | ||
|
34e2e43445 | ||
|
0148a5913d | ||
|
c8d45148f1 | ||
|
a445a3108f | ||
|
69d0d9e26d | ||
|
4fa7e5cfd9 | ||
|
7d6d46c4d8 | ||
|
07ba1c1636 | ||
|
422eb36f16 | ||
|
7f9adfac22 |
@ -173,8 +173,11 @@ typst help
|
||||
typst help watch
|
||||
```
|
||||
|
||||
If you prefer an integrated IDE-like experience with autocompletion and instant
|
||||
preview, you can also check out [Typst's free web app][app].
|
||||
If you prefer an integrated IDE-like experience with autocompletion and instant
|
||||
preview, you can also check out our [free web app][app]. Alternatively, there is
|
||||
a community-created language server called
|
||||
[Tinymist](https://myriad-dreamin.github.io/tinymist/) which is integrated into
|
||||
various editor extensions.
|
||||
|
||||
## Community
|
||||
The main places where the community gathers are our [Forum][forum] and our
|
||||
|
@ -9,6 +9,7 @@ use ttf_parser::Tag;
|
||||
use typst_library::engine::Engine;
|
||||
use typst_library::foundations::{Smart, StyleChain};
|
||||
use typst_library::layout::{Abs, Dir, Em, Frame, FrameItem, Point, Size};
|
||||
use typst_library::model::{Microtype, ParElem};
|
||||
use typst_library::text::{
|
||||
families, features, is_default_ignorable, language, variant, Font, FontFamily,
|
||||
FontVariant, Glyph, Lang, Region, ShiftSettings, TextEdgeBounds, TextElem, TextItem,
|
||||
@ -144,7 +145,11 @@ impl ShapedGlyph {
|
||||
|| self.c.is_ascii_digit()
|
||||
}
|
||||
|
||||
pub fn base_adjustability(&self, style: CjkPunctStyle) -> Adjustability {
|
||||
pub fn base_adjustability(
|
||||
&self,
|
||||
style: CjkPunctStyle,
|
||||
microtype: Microtype,
|
||||
) -> Adjustability {
|
||||
let width = self.x_advance;
|
||||
if self.is_space() {
|
||||
Adjustability {
|
||||
@ -168,7 +173,10 @@ impl ShapedGlyph {
|
||||
shrinkability: (width / 4.0, width / 4.0),
|
||||
}
|
||||
} else {
|
||||
Adjustability::default()
|
||||
Adjustability {
|
||||
stretchability: (Em::zero(), microtype.max_expand.em),
|
||||
shrinkability: (Em::zero(), microtype.max_retract.em),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1110,9 +1118,10 @@ fn track_and_space(ctx: &mut ShapingContext) {
|
||||
/// and CJK punctuation adjustments according to Chinese Layout Requirements.
|
||||
fn calculate_adjustability(ctx: &mut ShapingContext, lang: Lang, region: Option<Region>) {
|
||||
let style = cjk_punct_style(lang, region);
|
||||
let microtype = ParElem::microtype_in(ctx.styles);
|
||||
|
||||
for glyph in &mut ctx.glyphs {
|
||||
glyph.adjustability = glyph.base_adjustability(style);
|
||||
glyph.adjustability = glyph.base_adjustability(style, microtype);
|
||||
}
|
||||
|
||||
let mut glyphs = ctx.glyphs.iter_mut().peekable();
|
||||
|
@ -136,6 +136,9 @@ pub struct ParElem {
|
||||
#[default(false)]
|
||||
pub justify: bool,
|
||||
|
||||
/// Microtypographical settings that are used during justification.
|
||||
pub microtype: Microtype,
|
||||
|
||||
/// How to determine line breaks.
|
||||
///
|
||||
/// When this property is set to `{auto}`, its default value, optimized line
|
||||
@ -224,6 +227,36 @@ impl ParElem {
|
||||
type ParLine;
|
||||
}
|
||||
|
||||
/// Configuration for microtypographical settings to be used during
|
||||
/// justification.
|
||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Hash)]
|
||||
pub struct Microtype {
|
||||
/// How much a glyph is allowed to translate into its neighbor.
|
||||
pub max_retract: Length,
|
||||
/// How much a glyph is allowed to translate away from its neighbor.
|
||||
pub max_expand: Length,
|
||||
}
|
||||
|
||||
cast! {
|
||||
Microtype,
|
||||
self => Value::Dict(self.into()),
|
||||
mut dict: Dict => {
|
||||
let max_retract = dict.take("max-retract")?.cast()?;
|
||||
let max_expand = dict.take("max-expand")?.cast()?;
|
||||
dict.finish(&["max-retract", "max-expand"])?;
|
||||
Self { max_retract, max_expand }
|
||||
},
|
||||
}
|
||||
|
||||
impl From<Microtype> for Dict {
|
||||
fn from(microtype: Microtype) -> Self {
|
||||
dict! {
|
||||
"max-retract" => microtype.max_retract,
|
||||
"max-expand" => microtype.max_expand,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// How to determine line breaks in a paragraph.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
|
||||
pub enum Linebreaks {
|
||||
|
@ -797,7 +797,9 @@ impl Color {
|
||||
components
|
||||
}
|
||||
|
||||
/// Returns the constructor function for this color's space:
|
||||
/// Returns the constructor function for this color's space.
|
||||
///
|
||||
/// Returns one of:
|
||||
/// - [`luma`]($color.luma)
|
||||
/// - [`oklab`]($color.oklab)
|
||||
/// - [`oklch`]($color.oklch)
|
||||
|
@ -242,7 +242,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
||||
items.push(CategoryItem {
|
||||
name: group.name.clone(),
|
||||
route: subpage.route.clone(),
|
||||
oneliner: oneliner(docs).into(),
|
||||
oneliner: oneliner(docs),
|
||||
code: true,
|
||||
});
|
||||
children.push(subpage);
|
||||
@ -296,7 +296,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
||||
items.push(CategoryItem {
|
||||
name: name.into(),
|
||||
route: subpage.route.clone(),
|
||||
oneliner: oneliner(func.docs().unwrap_or_default()).into(),
|
||||
oneliner: oneliner(func.docs().unwrap_or_default()),
|
||||
code: true,
|
||||
});
|
||||
children.push(subpage);
|
||||
@ -306,7 +306,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
||||
items.push(CategoryItem {
|
||||
name: ty.short_name().into(),
|
||||
route: subpage.route.clone(),
|
||||
oneliner: oneliner(ty.docs()).into(),
|
||||
oneliner: oneliner(ty.docs()),
|
||||
code: true,
|
||||
});
|
||||
children.push(subpage);
|
||||
@ -637,7 +637,7 @@ fn group_page(
|
||||
let item = CategoryItem {
|
||||
name: group.name.clone(),
|
||||
route: model.route.clone(),
|
||||
oneliner: oneliner(&group.details).into(),
|
||||
oneliner: oneliner(&group.details),
|
||||
code: false,
|
||||
};
|
||||
|
||||
@ -772,8 +772,24 @@ pub fn urlify(title: &str) -> EcoString {
|
||||
}
|
||||
|
||||
/// Extract the first line of documentation.
|
||||
fn oneliner(docs: &str) -> &str {
|
||||
docs.lines().next().unwrap_or_default()
|
||||
fn oneliner(docs: &str) -> EcoString {
|
||||
let paragraph = docs.split("\n\n").next().unwrap_or_default();
|
||||
let mut depth = 0;
|
||||
let mut period = false;
|
||||
let mut end = paragraph.len();
|
||||
for (i, c) in paragraph.char_indices() {
|
||||
match c {
|
||||
'(' | '[' | '{' => depth += 1,
|
||||
')' | ']' | '}' => depth -= 1,
|
||||
'.' if depth == 0 => period = true,
|
||||
c if period && c.is_whitespace() && !docs[..i].ends_with("e.g.") => {
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
_ => period = false,
|
||||
}
|
||||
}
|
||||
EcoString::from(&docs[..end]).replace("\r\n", " ").replace("\n", " ")
|
||||
}
|
||||
|
||||
/// The order of types in the documentation.
|
||||
|
@ -86,7 +86,7 @@ pub struct FuncModel {
|
||||
pub name: EcoString,
|
||||
pub title: &'static str,
|
||||
pub keywords: &'static [&'static str],
|
||||
pub oneliner: &'static str,
|
||||
pub oneliner: EcoString,
|
||||
pub element: bool,
|
||||
pub contextual: bool,
|
||||
pub deprecation: Option<&'static str>,
|
||||
@ -139,7 +139,7 @@ pub struct TypeModel {
|
||||
pub name: &'static str,
|
||||
pub title: &'static str,
|
||||
pub keywords: &'static [&'static str],
|
||||
pub oneliner: &'static str,
|
||||
pub oneliner: EcoString,
|
||||
pub details: Html,
|
||||
pub constructor: Option<FuncModel>,
|
||||
pub scope: Vec<FuncModel>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user