mirror of
https://github.com/typst/typst
synced 2025-07-27 22:37:54 +08:00
Compare commits
6 Commits
b0416a4cc8
...
5dcb1def0c
Author | SHA1 | Date | |
---|---|---|---|
|
5dcb1def0c | ||
|
1a66c8ebe7 | ||
|
c384f6b6c0 | ||
|
b790c6d59c | ||
|
b1c79b50d4 | ||
|
4629ede020 |
15
Cargo.lock
generated
15
Cargo.lock
generated
@ -967,7 +967,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hayro"
|
name = "hayro"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/LaurenzV/hayro?rev=d385360#d38536089c95b521b0b64080302d7a305344edbf"
|
source = "git+https://github.com/LaurenzV/hayro?rev=2b63dc8#2b63dc85b9447a815cc5b40c16338841c3780f7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"hayro-interpret",
|
"hayro-interpret",
|
||||||
@ -980,7 +980,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hayro-font"
|
name = "hayro-font"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/LaurenzV/hayro?rev=d385360#d38536089c95b521b0b64080302d7a305344edbf"
|
source = "git+https://github.com/LaurenzV/hayro?rev=2b63dc8#2b63dc85b9447a815cc5b40c16338841c3780f7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"phf",
|
"phf",
|
||||||
@ -989,7 +989,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hayro-interpret"
|
name = "hayro-interpret"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/LaurenzV/hayro?rev=d385360#d38536089c95b521b0b64080302d7a305344edbf"
|
source = "git+https://github.com/LaurenzV/hayro?rev=2b63dc8#2b63dc85b9447a815cc5b40c16338841c3780f7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.9.1",
|
"bitflags 2.9.1",
|
||||||
"hayro-font",
|
"hayro-font",
|
||||||
@ -1006,7 +1006,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hayro-syntax"
|
name = "hayro-syntax"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
source = "git+https://github.com/LaurenzV/hayro?rev=d385360#d38536089c95b521b0b64080302d7a305344edbf"
|
source = "git+https://github.com/LaurenzV/hayro?rev=2b63dc8#2b63dc85b9447a815cc5b40c16338841c3780f7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flate2",
|
"flate2",
|
||||||
"kurbo",
|
"kurbo",
|
||||||
@ -1019,7 +1019,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hayro-write"
|
name = "hayro-write"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/LaurenzV/hayro?rev=d385360#d38536089c95b521b0b64080302d7a305344edbf"
|
source = "git+https://github.com/LaurenzV/hayro?rev=2b63dc8#2b63dc85b9447a815cc5b40c16338841c3780f7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flate2",
|
"flate2",
|
||||||
"hayro-syntax",
|
"hayro-syntax",
|
||||||
@ -1430,7 +1430,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "krilla"
|
name = "krilla"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/LaurenzV/krilla?rev=f7d753c3#f7d753c39e1fb7118fb1b774243a0720771f229f"
|
source = "git+https://github.com/LaurenzV/krilla?rev=1668ac2#1668ac2e64dc85572e6c62a2399e85acd39b619d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
@ -1460,7 +1460,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "krilla-svg"
|
name = "krilla-svg"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/LaurenzV/krilla?rev=f7d753c3#f7d753c39e1fb7118fb1b774243a0720771f229f"
|
source = "git+https://github.com/LaurenzV/krilla?rev=1668ac2#1668ac2e64dc85572e6c62a2399e85acd39b619d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flate2",
|
"flate2",
|
||||||
"fontdb",
|
"fontdb",
|
||||||
@ -2926,7 +2926,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "typst-assets"
|
name = "typst-assets"
|
||||||
version = "0.13.1"
|
version = "0.13.1"
|
||||||
source = "git+https://github.com/typst/typst-assets?rev=edf0d64#edf0d648376e29738a05a933af9ea99bb81557b1"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typst-cli"
|
name = "typst-cli"
|
||||||
|
10
Cargo.toml
10
Cargo.toml
@ -32,7 +32,7 @@ typst-svg = { path = "crates/typst-svg", version = "0.13.1" }
|
|||||||
typst-syntax = { path = "crates/typst-syntax", version = "0.13.1" }
|
typst-syntax = { path = "crates/typst-syntax", version = "0.13.1" }
|
||||||
typst-timing = { path = "crates/typst-timing", version = "0.13.1" }
|
typst-timing = { path = "crates/typst-timing", version = "0.13.1" }
|
||||||
typst-utils = { path = "crates/typst-utils", version = "0.13.1" }
|
typst-utils = { path = "crates/typst-utils", version = "0.13.1" }
|
||||||
typst-assets = { git = "https://github.com/typst/typst-assets", rev = "edf0d64" }
|
typst-assets = { path = "../typst-assets" }
|
||||||
typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "bfa947f" }
|
typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "bfa947f" }
|
||||||
arrayvec = "0.7.4"
|
arrayvec = "0.7.4"
|
||||||
az = "1.2"
|
az = "1.2"
|
||||||
@ -61,8 +61,8 @@ fontdb = { version = "0.23", default-features = false }
|
|||||||
fs_extra = "1.3"
|
fs_extra = "1.3"
|
||||||
glidesort = "0.1.2"
|
glidesort = "0.1.2"
|
||||||
hayagriva = "0.8.1"
|
hayagriva = "0.8.1"
|
||||||
hayro-syntax = { git = "https://github.com/LaurenzV/hayro", rev = "d385360" }
|
hayro-syntax = { git = "https://github.com/LaurenzV/hayro", rev = "2b63dc8" }
|
||||||
hayro = { git = "https://github.com/LaurenzV/hayro", rev = "d385360" }
|
hayro = { git = "https://github.com/LaurenzV/hayro", rev = "2b63dc8" }
|
||||||
heck = "0.5"
|
heck = "0.5"
|
||||||
hypher = "0.1.4"
|
hypher = "0.1.4"
|
||||||
icu_properties = { version = "1.4", features = ["serde"] }
|
icu_properties = { version = "1.4", features = ["serde"] }
|
||||||
@ -75,8 +75,8 @@ image = { version = "0.25.5", default-features = false, features = ["png", "jpeg
|
|||||||
indexmap = { version = "2", features = ["serde"] }
|
indexmap = { version = "2", features = ["serde"] }
|
||||||
infer = { version = "0.19.0", default-features = false }
|
infer = { version = "0.19.0", default-features = false }
|
||||||
kamadak-exif = "0.6"
|
kamadak-exif = "0.6"
|
||||||
krilla = { git = "https://github.com/LaurenzV/krilla", rev = "f7d753c3", default-features = false, features = ["raster-images", "comemo", "rayon", "pdf"] }
|
krilla = { git = "https://github.com/LaurenzV/krilla", rev = "1668ac2", default-features = false, features = ["raster-images", "comemo", "rayon", "pdf"] }
|
||||||
krilla-svg = { git = "https://github.com/LaurenzV/krilla", rev = "f7d753c3" }
|
krilla-svg = { git = "https://github.com/LaurenzV/krilla", rev = "1668ac2" }
|
||||||
kurbo = "0.11"
|
kurbo = "0.11"
|
||||||
libfuzzer-sys = "0.4"
|
libfuzzer-sys = "0.4"
|
||||||
lipsum = "0.9"
|
lipsum = "0.9"
|
||||||
|
@ -174,7 +174,10 @@ typst help watch
|
|||||||
```
|
```
|
||||||
|
|
||||||
If you prefer an integrated IDE-like experience with autocompletion and instant
|
If you prefer an integrated IDE-like experience with autocompletion and instant
|
||||||
preview, you can also check out [Typst's free web app][app].
|
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
|
## Community
|
||||||
The main places where the community gathers are our [Forum][forum] and our
|
The main places where the community gathers are our [Forum][forum] and our
|
||||||
|
@ -797,7 +797,9 @@ impl Color {
|
|||||||
components
|
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)
|
/// - [`luma`]($color.luma)
|
||||||
/// - [`oklab`]($color.oklab)
|
/// - [`oklab`]($color.oklab)
|
||||||
/// - [`oklch`]($color.oklch)
|
/// - [`oklch`]($color.oklch)
|
||||||
|
@ -7,6 +7,7 @@ use hayro_syntax::page::Page;
|
|||||||
use hayro_syntax::Pdf;
|
use hayro_syntax::Pdf;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use typst_library::text::FontInfo;
|
||||||
|
|
||||||
struct DocumentRepr {
|
struct DocumentRepr {
|
||||||
pdf: Arc<Pdf>,
|
pdf: Arc<Pdf>,
|
||||||
@ -121,8 +122,9 @@ fn get_standard_fonts(world: Tracked<dyn World + '_>) -> Arc<StandardFonts> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.or_else(|| book.select_fallback(None, variant, "A"))
|
||||||
.and_then(|i| world.font(i))
|
.and_then(|i| world.font(i))
|
||||||
.map(|font| font.data().clone())
|
.map(|font| (font.data().clone(), font.index()))
|
||||||
};
|
};
|
||||||
|
|
||||||
let normal_variant = FontVariant::new(
|
let normal_variant = FontVariant::new(
|
||||||
@ -161,18 +163,17 @@ fn get_standard_fonts(world: Tracked<dyn World + '_>) -> Arc<StandardFonts> {
|
|||||||
bold_italic: get_font("times", Some("liberation serif"), bold_italic_variant),
|
bold_italic: get_font("times", Some("liberation serif"), bold_italic_variant),
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Use Foxit fonts as fallback
|
let symbol = Some(Bytes::new(typst_assets::pdf::SYMBOL));
|
||||||
let symbol = get_font("symbol", None, normal_variant);
|
let zapf_dingbats = Some(Bytes::new(typst_assets::pdf::DING_BATS));
|
||||||
let zapf_dingbats = get_font("zapf dingbats", None, normal_variant);
|
|
||||||
|
|
||||||
Arc::new(StandardFonts { helvetica, courier, times, symbol, zapf_dingbats })
|
Arc::new(StandardFonts { helvetica, courier, times, symbol, zapf_dingbats })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct VariantFont {
|
pub struct VariantFont {
|
||||||
pub normal: Option<Bytes>,
|
pub normal: Option<(Bytes, u32)>,
|
||||||
pub bold: Option<Bytes>,
|
pub bold: Option<(Bytes, u32)>,
|
||||||
pub italic: Option<Bytes>,
|
pub italic: Option<(Bytes, u32)>,
|
||||||
pub bold_italic: Option<Bytes>,
|
pub bold_italic: Option<(Bytes, u32)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StandardFonts {
|
pub struct StandardFonts {
|
||||||
|
@ -110,7 +110,7 @@ fn build_texture(image: &Image, w: u32, h: u32) -> Option<Arc<sk::Pixmap>> {
|
|||||||
fn build_pdf_texture(pdf: &PdfImage, w: u32, h: u32) -> Option<sk::Pixmap> {
|
fn build_pdf_texture(pdf: &PdfImage, w: u32, h: u32) -> Option<sk::Pixmap> {
|
||||||
let sf = pdf.standard_fonts().clone();
|
let sf = pdf.standard_fonts().clone();
|
||||||
|
|
||||||
let select_standard_font = move |font: StandardFont| -> Option<FontData> {
|
let select_standard_font = move |font: StandardFont| -> Option<(FontData, u32)> {
|
||||||
let bytes = match font {
|
let bytes = match font {
|
||||||
StandardFont::Helvetica => sf.helvetica.normal.clone(),
|
StandardFont::Helvetica => sf.helvetica.normal.clone(),
|
||||||
StandardFont::HelveticaBold => sf.helvetica.bold.clone(),
|
StandardFont::HelveticaBold => sf.helvetica.bold.clone(),
|
||||||
@ -124,14 +124,14 @@ fn build_pdf_texture(pdf: &PdfImage, w: u32, h: u32) -> Option<sk::Pixmap> {
|
|||||||
StandardFont::TimesBold => sf.times.bold.clone(),
|
StandardFont::TimesBold => sf.times.bold.clone(),
|
||||||
StandardFont::TimesItalic => sf.times.italic.clone(),
|
StandardFont::TimesItalic => sf.times.italic.clone(),
|
||||||
StandardFont::TimesBoldItalic => sf.times.bold_italic.clone(),
|
StandardFont::TimesBoldItalic => sf.times.bold_italic.clone(),
|
||||||
StandardFont::ZapfDingBats => sf.zapf_dingbats.clone(),
|
StandardFont::ZapfDingBats => sf.zapf_dingbats.clone().map(|d| (d, 0)),
|
||||||
StandardFont::Symbol => sf.symbol.clone(),
|
StandardFont::Symbol => sf.symbol.clone().map(|d| (d, 0)),
|
||||||
};
|
};
|
||||||
|
|
||||||
bytes.map(|d| {
|
bytes.map(|d| {
|
||||||
let font_data: Arc<dyn AsRef<[u8]> + Send + Sync> = Arc::new(d.clone());
|
let font_data: Arc<dyn AsRef<[u8]> + Send + Sync> = Arc::new(d.0.clone());
|
||||||
|
|
||||||
font_data
|
(font_data, d.1)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ pub fn convert_image_to_base64_url(image: &Image) -> EcoString {
|
|||||||
fn pdf_to_png(pdf: &PdfImage, w: u32, h: u32) -> Vec<u8> {
|
fn pdf_to_png(pdf: &PdfImage, w: u32, h: u32) -> Vec<u8> {
|
||||||
let sf = pdf.standard_fonts().clone();
|
let sf = pdf.standard_fonts().clone();
|
||||||
|
|
||||||
let select_standard_font = move |font: StandardFont| -> Option<FontData> {
|
let select_standard_font = move |font: StandardFont| -> Option<(FontData, u32)> {
|
||||||
let bytes = match font {
|
let bytes = match font {
|
||||||
StandardFont::Helvetica => sf.helvetica.normal.clone(),
|
StandardFont::Helvetica => sf.helvetica.normal.clone(),
|
||||||
StandardFont::HelveticaBold => sf.helvetica.bold.clone(),
|
StandardFont::HelveticaBold => sf.helvetica.bold.clone(),
|
||||||
@ -116,14 +116,14 @@ fn pdf_to_png(pdf: &PdfImage, w: u32, h: u32) -> Vec<u8> {
|
|||||||
StandardFont::TimesBold => sf.times.bold.clone(),
|
StandardFont::TimesBold => sf.times.bold.clone(),
|
||||||
StandardFont::TimesItalic => sf.times.italic.clone(),
|
StandardFont::TimesItalic => sf.times.italic.clone(),
|
||||||
StandardFont::TimesBoldItalic => sf.times.bold_italic.clone(),
|
StandardFont::TimesBoldItalic => sf.times.bold_italic.clone(),
|
||||||
StandardFont::ZapfDingBats => sf.zapf_dingbats.clone(),
|
StandardFont::ZapfDingBats => sf.zapf_dingbats.clone().map(|d| (d, 0)),
|
||||||
StandardFont::Symbol => sf.symbol.clone(),
|
StandardFont::Symbol => sf.symbol.clone().map(|d| (d, 0)),
|
||||||
};
|
};
|
||||||
|
|
||||||
bytes.map(|d| {
|
bytes.map(|d| {
|
||||||
let font_data: Arc<dyn AsRef<[u8]> + Send + Sync> = Arc::new(d.clone());
|
let font_data: Arc<dyn AsRef<[u8]> + Send + Sync> = Arc::new(d.0.clone());
|
||||||
|
|
||||||
font_data
|
(font_data, d.1)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
|||||||
items.push(CategoryItem {
|
items.push(CategoryItem {
|
||||||
name: group.name.clone(),
|
name: group.name.clone(),
|
||||||
route: subpage.route.clone(),
|
route: subpage.route.clone(),
|
||||||
oneliner: oneliner(docs).into(),
|
oneliner: oneliner(docs),
|
||||||
code: true,
|
code: true,
|
||||||
});
|
});
|
||||||
children.push(subpage);
|
children.push(subpage);
|
||||||
@ -296,7 +296,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
|||||||
items.push(CategoryItem {
|
items.push(CategoryItem {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
route: subpage.route.clone(),
|
route: subpage.route.clone(),
|
||||||
oneliner: oneliner(func.docs().unwrap_or_default()).into(),
|
oneliner: oneliner(func.docs().unwrap_or_default()),
|
||||||
code: true,
|
code: true,
|
||||||
});
|
});
|
||||||
children.push(subpage);
|
children.push(subpage);
|
||||||
@ -306,7 +306,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
|||||||
items.push(CategoryItem {
|
items.push(CategoryItem {
|
||||||
name: ty.short_name().into(),
|
name: ty.short_name().into(),
|
||||||
route: subpage.route.clone(),
|
route: subpage.route.clone(),
|
||||||
oneliner: oneliner(ty.docs()).into(),
|
oneliner: oneliner(ty.docs()),
|
||||||
code: true,
|
code: true,
|
||||||
});
|
});
|
||||||
children.push(subpage);
|
children.push(subpage);
|
||||||
@ -637,7 +637,7 @@ fn group_page(
|
|||||||
let item = CategoryItem {
|
let item = CategoryItem {
|
||||||
name: group.name.clone(),
|
name: group.name.clone(),
|
||||||
route: model.route.clone(),
|
route: model.route.clone(),
|
||||||
oneliner: oneliner(&group.details).into(),
|
oneliner: oneliner(&group.details),
|
||||||
code: false,
|
code: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -772,8 +772,24 @@ pub fn urlify(title: &str) -> EcoString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the first line of documentation.
|
/// Extract the first line of documentation.
|
||||||
fn oneliner(docs: &str) -> &str {
|
fn oneliner(docs: &str) -> EcoString {
|
||||||
docs.lines().next().unwrap_or_default()
|
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.
|
/// The order of types in the documentation.
|
||||||
|
@ -86,7 +86,7 @@ pub struct FuncModel {
|
|||||||
pub name: EcoString,
|
pub name: EcoString,
|
||||||
pub title: &'static str,
|
pub title: &'static str,
|
||||||
pub keywords: &'static [&'static str],
|
pub keywords: &'static [&'static str],
|
||||||
pub oneliner: &'static str,
|
pub oneliner: EcoString,
|
||||||
pub element: bool,
|
pub element: bool,
|
||||||
pub contextual: bool,
|
pub contextual: bool,
|
||||||
pub deprecation: Option<&'static str>,
|
pub deprecation: Option<&'static str>,
|
||||||
@ -139,7 +139,7 @@ pub struct TypeModel {
|
|||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub title: &'static str,
|
pub title: &'static str,
|
||||||
pub keywords: &'static [&'static str],
|
pub keywords: &'static [&'static str],
|
||||||
pub oneliner: &'static str,
|
pub oneliner: EcoString,
|
||||||
pub details: Html,
|
pub details: Html,
|
||||||
pub constructor: Option<FuncModel>,
|
pub constructor: Option<FuncModel>,
|
||||||
pub scope: Vec<FuncModel>,
|
pub scope: Vec<FuncModel>,
|
||||||
|
@ -127,6 +127,10 @@
|
|||||||
checks = self'.checks;
|
checks = self'.checks;
|
||||||
inputsFrom = [ typst ];
|
inputsFrom = [ typst ];
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
rust-analyzer
|
||||||
|
];
|
||||||
|
|
||||||
packages = [
|
packages = [
|
||||||
# A script for quickly running tests.
|
# A script for quickly running tests.
|
||||||
# See https://github.com/typst/typst/blob/main/tests/README.md#making-an-alias
|
# See https://github.com/typst/typst/blob/main/tests/README.md#making-an-alias
|
||||||
|
Loading…
x
Reference in New Issue
Block a user