mirror of
https://github.com/typst/typst
synced 2025-08-01 16:57:55 +08:00
Compare commits
5 Commits
2347d297dd
...
c1d55f053a
Author | SHA1 | Date | |
---|---|---|---|
|
c1d55f053a | ||
|
47df51c6f1 | ||
|
9eb2cafcc3 | ||
|
44c573d1a0 | ||
|
e6ac31e92c |
@ -254,7 +254,7 @@ pub struct Binding {
|
||||
/// The category of the binding.
|
||||
category: Option<Category>,
|
||||
/// The deprecation information if this item is deprecated.
|
||||
deprecation: Option<Box<Deprecation>>,
|
||||
deprecation: Option<Box<DeprecationInfo>>,
|
||||
}
|
||||
|
||||
/// The different kinds of slots.
|
||||
@ -284,8 +284,20 @@ impl Binding {
|
||||
}
|
||||
|
||||
/// Marks this binding as deprecated, with the given `message`.
|
||||
pub fn deprecated(&mut self, deprecation: Deprecation) -> &mut Self {
|
||||
self.deprecation = Some(Box::new(deprecation));
|
||||
pub fn deprecated(&mut self, message: &'static str) -> &mut Self {
|
||||
self.deprecation
|
||||
.get_or_insert_with(|| Box::new(DeprecationInfo::new()))
|
||||
.deprecated_message(message);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the version in which the binding is planned to be removed.
|
||||
///
|
||||
/// This is ignored if [`Binding::deprecated`] isn't also set.
|
||||
pub fn deprecated_until(&mut self, version: &'static str) -> &mut Self {
|
||||
self.deprecation
|
||||
.get_or_insert_with(|| Box::new(DeprecationInfo::new()))
|
||||
.deprecated_until(version);
|
||||
self
|
||||
}
|
||||
|
||||
@ -337,7 +349,7 @@ impl Binding {
|
||||
}
|
||||
|
||||
/// A deprecation message for the value, if any.
|
||||
pub fn deprecation(&self) -> Option<&Deprecation> {
|
||||
pub fn deprecation(&self) -> Option<&DeprecationInfo> {
|
||||
self.deprecation.as_deref()
|
||||
}
|
||||
|
||||
@ -358,14 +370,14 @@ pub enum Capturer {
|
||||
|
||||
/// Information about a deprecated binding.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Deprecation {
|
||||
pub struct DeprecationInfo {
|
||||
/// A deprecation message for the definition.
|
||||
message: &'static str,
|
||||
/// A version in which the deprecated binding is planned to be removed.
|
||||
until: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl Deprecation {
|
||||
impl DeprecationInfo {
|
||||
/// Creates new deprecation info with a default message to display when
|
||||
/// emitting the deprecation warning.
|
||||
pub fn new() -> Self {
|
||||
@ -373,13 +385,13 @@ impl Deprecation {
|
||||
}
|
||||
|
||||
/// Set the message to display when emitting the deprecation warning.
|
||||
pub fn with_message(mut self, message: &'static str) -> Self {
|
||||
pub fn deprecated_message(&mut self, message: &'static str) -> &mut Self {
|
||||
self.message = message;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the version in which the binding is planned to be removed.
|
||||
pub fn with_until(mut self, version: &'static str) -> Self {
|
||||
pub fn deprecated_until(&mut self, version: &'static str) -> &mut Self {
|
||||
self.until = Some(version);
|
||||
self
|
||||
}
|
||||
@ -395,7 +407,7 @@ impl Deprecation {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Deprecation {
|
||||
impl Default for DeprecationInfo {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Modifiable symbols.
|
||||
|
||||
use crate::foundations::{Deprecation, Module, Scope, Symbol, Value};
|
||||
use crate::foundations::{Module, Scope, Symbol, Value};
|
||||
|
||||
/// Hook up all `symbol` definitions.
|
||||
pub(super) fn define(global: &mut Scope) {
|
||||
@ -23,7 +23,7 @@ fn extend_scope_from_codex_module(scope: &mut Scope, module: codex::Module) {
|
||||
|
||||
let scope_binding = scope.define(name, value);
|
||||
if let Some(message) = binding.deprecation {
|
||||
scope_binding.deprecated(Deprecation::new().with_message(message));
|
||||
scope_binding.deprecated(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -476,18 +476,26 @@ impl Curve {
|
||||
|
||||
/// Computes the size of the bounding box of this curve.
|
||||
pub fn bbox_size(&self) -> Size {
|
||||
let mut min = Point::splat(Abs::inf());
|
||||
let mut max = Point::splat(-Abs::inf());
|
||||
let mut min_x = Abs::inf();
|
||||
let mut min_y = Abs::inf();
|
||||
let mut max_x = -Abs::inf();
|
||||
let mut max_y = -Abs::inf();
|
||||
|
||||
let mut cursor = Point::zero();
|
||||
for item in self.0.iter() {
|
||||
match item {
|
||||
CurveItem::Move(to) => {
|
||||
min_x = min_x.min(cursor.x);
|
||||
min_y = min_y.min(cursor.y);
|
||||
max_x = max_x.max(cursor.x);
|
||||
max_y = max_y.max(cursor.y);
|
||||
cursor = *to;
|
||||
}
|
||||
CurveItem::Line(to) => {
|
||||
min = min.min(cursor).min(*to);
|
||||
max = max.max(cursor).max(*to);
|
||||
min_x = min_x.min(cursor.x);
|
||||
min_y = min_y.min(cursor.y);
|
||||
max_x = max_x.max(cursor.x);
|
||||
max_y = max_y.max(cursor.y);
|
||||
cursor = *to;
|
||||
}
|
||||
CurveItem::Cubic(c0, c1, end) => {
|
||||
@ -499,17 +507,17 @@ impl Curve {
|
||||
);
|
||||
|
||||
let bbox = cubic.bounding_box();
|
||||
min.x = min.x.min(Abs::pt(bbox.x0)).min(Abs::pt(bbox.x1));
|
||||
min.y = min.y.min(Abs::pt(bbox.y0)).min(Abs::pt(bbox.y1));
|
||||
max.x = max.x.max(Abs::pt(bbox.x0)).max(Abs::pt(bbox.x1));
|
||||
max.y = max.y.max(Abs::pt(bbox.y0)).max(Abs::pt(bbox.y1));
|
||||
min_x = min_x.min(Abs::pt(bbox.x0)).min(Abs::pt(bbox.x1));
|
||||
min_y = min_y.min(Abs::pt(bbox.y0)).min(Abs::pt(bbox.y1));
|
||||
max_x = max_x.max(Abs::pt(bbox.x0)).max(Abs::pt(bbox.x1));
|
||||
max_y = max_y.max(Abs::pt(bbox.y0)).max(Abs::pt(bbox.y1));
|
||||
cursor = *end;
|
||||
}
|
||||
CurveItem::Close => (),
|
||||
}
|
||||
}
|
||||
|
||||
Size::new(max.x - min.x, max.y - min.y)
|
||||
Size::new(max_x - min_x, max_y - min_y)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ pub use self::shape::*;
|
||||
pub use self::stroke::*;
|
||||
pub use self::tiling::*;
|
||||
|
||||
use crate::foundations::Deprecation;
|
||||
use crate::foundations::{Element, Scope, Type};
|
||||
|
||||
/// Hook up all visualize definitions.
|
||||
@ -42,14 +41,12 @@ pub(super) fn define(global: &mut Scope) {
|
||||
global.define_elem::<CircleElem>();
|
||||
global.define_elem::<PolygonElem>();
|
||||
global.define_elem::<CurveElem>();
|
||||
global.define("path", Element::of::<PathElem>()).deprecated(
|
||||
Deprecation::new()
|
||||
.with_message("the `path` function is deprecated, use `curve` instead"),
|
||||
);
|
||||
global.define("pattern", Type::of::<Tiling>()).deprecated(
|
||||
Deprecation::new()
|
||||
.with_message("the name `pattern` is deprecated, use `tiling` instead")
|
||||
.with_until("0.15.0"),
|
||||
);
|
||||
global
|
||||
.define("path", Element::of::<PathElem>())
|
||||
.deprecated("the `path` function is deprecated, use `curve` instead");
|
||||
global
|
||||
.define("pattern", Type::of::<Tiling>())
|
||||
.deprecated("the name `pattern` is deprecated, use `tiling` instead")
|
||||
.deprecated_until("0.15.0");
|
||||
global.reset_category();
|
||||
}
|
||||
|
@ -64,22 +64,17 @@ pub fn scope(_: TokenStream, item: syn::Item) -> Result<TokenStream> {
|
||||
Punctuated::<MetaNameValue, Token![,]>::parse_separated_nonempty,
|
||||
)?;
|
||||
|
||||
let mut deprecation =
|
||||
quote! { crate::foundations::Deprecation::new() };
|
||||
|
||||
if let Some(message) = args.iter().find_map(|pair| {
|
||||
pair.path.is_ident("message").then_some(&pair.value)
|
||||
}) {
|
||||
deprecation = quote! { #deprecation.with_message(#message) }
|
||||
def = quote! { #def.deprecated(#message) }
|
||||
}
|
||||
|
||||
if let Some(version) = args.iter().find_map(|pair| {
|
||||
pair.path.is_ident("until").then_some(&pair.value)
|
||||
}) {
|
||||
deprecation = quote! { #deprecation.with_until(#version) }
|
||||
def = quote! { #def.deprecated_until(#version) }
|
||||
}
|
||||
|
||||
def = quote! { #def.deprecated(#deprecation) }
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ use serde::Deserialize;
|
||||
use serde_yaml as yaml;
|
||||
use std::sync::LazyLock;
|
||||
use typst::diag::{StrResult, bail};
|
||||
use typst::foundations::Deprecation;
|
||||
use typst::foundations::DeprecationInfo;
|
||||
use typst::foundations::{
|
||||
AutoValue, Binding, Bytes, CastInfo, Func, Module, NoneValue, ParamInfo, Repr, Scope,
|
||||
Smart, Type, Value,
|
||||
@ -382,7 +382,7 @@ fn func_page(
|
||||
parent: &str,
|
||||
func: &Func,
|
||||
path: &[&str],
|
||||
deprecation: Option<&Deprecation>,
|
||||
deprecation: Option<&DeprecationInfo>,
|
||||
) -> PageModel {
|
||||
let model = func_model(resolver, func, path, false, deprecation);
|
||||
let name = func.name().unwrap();
|
||||
@ -403,7 +403,7 @@ fn func_model(
|
||||
func: &Func,
|
||||
path: &[&str],
|
||||
nested: bool,
|
||||
deprecation: Option<&Deprecation>,
|
||||
deprecation: Option<&DeprecationInfo>,
|
||||
) -> FuncModel {
|
||||
let name = func.name().unwrap();
|
||||
let scope = func.scope().unwrap();
|
||||
@ -439,8 +439,8 @@ fn func_model(
|
||||
oneliner: oneliner(details),
|
||||
element: func.element().is_some(),
|
||||
contextual: func.contextual().unwrap_or(false),
|
||||
deprecation_message: deprecation.map(Deprecation::message),
|
||||
deprecation_until: deprecation.and_then(Deprecation::until),
|
||||
deprecation_message: deprecation.map(DeprecationInfo::message),
|
||||
deprecation_until: deprecation.and_then(DeprecationInfo::until),
|
||||
details: Html::markdown(resolver, details, nesting),
|
||||
example: example.map(|md| Html::markdown(resolver, md, None)),
|
||||
self_,
|
||||
@ -740,8 +740,8 @@ fn symbols_model(resolver: &dyn Resolver, group: &GroupData) -> SymbolsModel {
|
||||
.map(|(other, _, _)| complete(other))
|
||||
.collect(),
|
||||
deprecation_message: deprecation_message
|
||||
.or_else(|| binding.deprecation().map(Deprecation::message)),
|
||||
deprecation_until: binding.deprecation().and_then(Deprecation::until),
|
||||
.or_else(|| binding.deprecation().map(DeprecationInfo::message)),
|
||||
deprecation_until: binding.deprecation().and_then(DeprecationInfo::until),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 399 B |
Binary file not shown.
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.1 KiB |
@ -130,16 +130,6 @@
|
||||
down, up, down, up, down,
|
||||
)
|
||||
|
||||
--- curve-stroke-gradient-sharp ---
|
||||
#set page(width: auto)
|
||||
#let down = curve.line((40pt, 40pt), relative: true)
|
||||
#let up = curve.line((40pt, -40pt), relative: true)
|
||||
|
||||
#curve(
|
||||
stroke: 4pt + gradient.linear(red, blue).sharp(3),
|
||||
down, up, down, up, down,
|
||||
)
|
||||
|
||||
--- curve-fill-rule ---
|
||||
#stack(
|
||||
dir: ltr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user