mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Small style changes
This commit is contained in:
parent
8a88f71cb1
commit
304d9dd110
@ -583,10 +583,10 @@ impl<'a> PageExporter<'a> {
|
|||||||
let Transform { sx, ky, kx, sy, tx, ty } = transform;
|
let Transform { sx, ky, kx, sy, tx, ty } = transform;
|
||||||
self.state.transform = self.state.transform.pre_concat(transform);
|
self.state.transform = self.state.transform.pre_concat(transform);
|
||||||
self.content.transform([
|
self.content.transform([
|
||||||
sx.get() as f32,
|
sx.get() as _,
|
||||||
ky.get() as f32,
|
ky.get() as _,
|
||||||
kx.get() as f32,
|
kx.get() as _,
|
||||||
sy.get() as f32,
|
sy.get() as _,
|
||||||
tx.to_f32(),
|
tx.to_f32(),
|
||||||
ty.to_f32(),
|
ty.to_f32(),
|
||||||
]);
|
]);
|
||||||
|
@ -106,7 +106,7 @@ impl PackedNode {
|
|||||||
/// Force a size for this node.
|
/// Force a size for this node.
|
||||||
pub fn sized(self, sizing: Spec<Option<Linear>>) -> Self {
|
pub fn sized(self, sizing: Spec<Option<Linear>>) -> Self {
|
||||||
if sizing.any(Option::is_some) {
|
if sizing.any(Option::is_some) {
|
||||||
SizedNode { child: self, sizing }.pack()
|
SizedNode { sizing, child: self }.pack()
|
||||||
} else {
|
} else {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ impl PackedNode {
|
|||||||
/// Set alignments for this node.
|
/// Set alignments for this node.
|
||||||
pub fn aligned(self, aligns: Spec<Option<Align>>) -> Self {
|
pub fn aligned(self, aligns: Spec<Option<Align>>) -> Self {
|
||||||
if aligns.any(Option::is_some) {
|
if aligns.any(Option::is_some) {
|
||||||
AlignNode { child: self, aligns }.pack()
|
AlignNode { aligns, child: self }.pack()
|
||||||
} else {
|
} else {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ impl PackedNode {
|
|||||||
|| !padding.right.is_zero()
|
|| !padding.right.is_zero()
|
||||||
|| !padding.bottom.is_zero()
|
|| !padding.bottom.is_zero()
|
||||||
{
|
{
|
||||||
PadNode { child: self, padding }.pack()
|
PadNode { padding, child: self }.pack()
|
||||||
} else {
|
} else {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ impl PackedNode {
|
|||||||
/// Transform this node's contents without affecting layout.
|
/// Transform this node's contents without affecting layout.
|
||||||
pub fn transformed(self, transform: Transform, origin: Spec<Align>) -> Self {
|
pub fn transformed(self, transform: Transform, origin: Spec<Align>) -> Self {
|
||||||
if !transform.is_identity() {
|
if !transform.is_identity() {
|
||||||
TransformNode { child: self, transform, origin }.pack()
|
TransformNode { transform, origin, child: self }.pack()
|
||||||
} else {
|
} else {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,10 @@ pub fn align(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
|||||||
/// A node that aligns its child.
|
/// A node that aligns its child.
|
||||||
#[derive(Debug, Hash)]
|
#[derive(Debug, Hash)]
|
||||||
pub struct AlignNode {
|
pub struct AlignNode {
|
||||||
/// The node to be aligned.
|
|
||||||
pub child: PackedNode,
|
|
||||||
/// How to align the node horizontally and vertically.
|
/// How to align the node horizontally and vertically.
|
||||||
pub aligns: Spec<Option<Align>>,
|
pub aligns: Spec<Option<Align>>,
|
||||||
|
/// The node to be aligned.
|
||||||
|
pub child: PackedNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Layout for AlignNode {
|
impl Layout for AlignNode {
|
||||||
|
@ -68,7 +68,7 @@ pub enum FlowChild {
|
|||||||
impl Debug for FlowChild {
|
impl Debug for FlowChild {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Spacing(v) => write!(f, "Spacing({:?})", v),
|
Self::Spacing(spacing) => spacing.fmt(f),
|
||||||
Self::Node(node) => node.fmt(f),
|
Self::Node(node) => node.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -490,19 +490,19 @@ impl<'a> GridLayouter<'a> {
|
|||||||
fn layout_multi_row(
|
fn layout_multi_row(
|
||||||
&self,
|
&self,
|
||||||
ctx: &mut LayoutContext,
|
ctx: &mut LayoutContext,
|
||||||
resolved: &[Length],
|
heights: &[Length],
|
||||||
y: usize,
|
y: usize,
|
||||||
) -> Vec<Frame> {
|
) -> Vec<Frame> {
|
||||||
// Prepare frames.
|
// Prepare frames.
|
||||||
let mut outputs: Vec<_> = resolved
|
let mut outputs: Vec<_> = heights
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&h| Frame::new(Size::new(self.used.w, h), h))
|
.map(|&h| Frame::new(Size::new(self.used.w, h), h))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Prepare regions.
|
// Prepare regions.
|
||||||
let size = Size::new(self.used.w, resolved[0]);
|
let size = Size::new(self.used.w, heights[0]);
|
||||||
let mut pod = Regions::one(size, self.regions.base, Spec::splat(true));
|
let mut pod = Regions::one(size, self.regions.base, Spec::splat(true));
|
||||||
pod.backlog = resolved[1 ..]
|
pod.backlog = heights[1 ..]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&h| Size::new(self.used.w, h))
|
.map(|&h| Size::new(self.used.w, h))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
@ -73,7 +73,7 @@ impl Layout for ImageNode {
|
|||||||
ImageFit::Stretch => canvas,
|
ImageFit::Stretch => canvas,
|
||||||
};
|
};
|
||||||
|
|
||||||
// The position of the image so that it is centered in the canvas.
|
// Position the image so that it is centered in the canvas.
|
||||||
let mut frame = Frame::new(canvas, canvas.h);
|
let mut frame = Frame::new(canvas, canvas.h);
|
||||||
frame.push(
|
frame.push(
|
||||||
(canvas - size).to_point() / 2.0,
|
(canvas - size).to_point() / 2.0,
|
||||||
|
@ -23,10 +23,10 @@ pub fn pad(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
|||||||
/// A node that adds padding to its child.
|
/// A node that adds padding to its child.
|
||||||
#[derive(Debug, Hash)]
|
#[derive(Debug, Hash)]
|
||||||
pub struct PadNode {
|
pub struct PadNode {
|
||||||
/// The child node whose sides to pad.
|
|
||||||
pub child: PackedNode,
|
|
||||||
/// The amount of padding.
|
/// The amount of padding.
|
||||||
pub padding: Sides<Linear>,
|
pub padding: Sides<Linear>,
|
||||||
|
/// The child node whose sides to pad.
|
||||||
|
pub child: PackedNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Layout for PadNode {
|
impl Layout for PadNode {
|
||||||
|
@ -82,12 +82,12 @@ pub fn pagebreak(_: &mut EvalContext, _: &mut Args) -> TypResult<Value> {
|
|||||||
/// Layouts its children onto one or multiple pages.
|
/// Layouts its children onto one or multiple pages.
|
||||||
#[derive(Debug, Hash)]
|
#[derive(Debug, Hash)]
|
||||||
pub struct PageNode {
|
pub struct PageNode {
|
||||||
/// The node that produces the actual pages.
|
|
||||||
pub child: PackedNode,
|
|
||||||
/// The size of the page.
|
/// The size of the page.
|
||||||
pub size: Size,
|
pub size: Size,
|
||||||
/// The background fill.
|
/// The background fill.
|
||||||
pub fill: Option<Paint>,
|
pub fill: Option<Paint>,
|
||||||
|
/// The node that produces the actual pages.
|
||||||
|
pub child: PackedNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageNode {
|
impl PageNode {
|
||||||
|
@ -23,10 +23,10 @@ pub fn block(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
|||||||
/// A node that sizes its child.
|
/// A node that sizes its child.
|
||||||
#[derive(Debug, Hash)]
|
#[derive(Debug, Hash)]
|
||||||
pub struct SizedNode {
|
pub struct SizedNode {
|
||||||
/// The node to be sized.
|
|
||||||
pub child: PackedNode,
|
|
||||||
/// How to size the node horizontally and vertically.
|
/// How to size the node horizontally and vertically.
|
||||||
pub sizing: Spec<Option<Linear>>,
|
pub sizing: Spec<Option<Linear>>,
|
||||||
|
/// The node to be sized.
|
||||||
|
pub child: PackedNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Layout for SizedNode {
|
impl Layout for SizedNode {
|
||||||
|
@ -82,7 +82,7 @@ pub enum StackChild {
|
|||||||
impl Debug for StackChild {
|
impl Debug for StackChild {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Spacing(v) => write!(f, "Spacing({:?})", v),
|
Self::Spacing(spacing) => spacing.fmt(f),
|
||||||
Self::Node(node) => node.fmt(f),
|
Self::Node(node) => node.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
|||||||
let tracking = args.named("tracking")?.map(Em::new);
|
let tracking = args.named("tracking")?.map(Em::new);
|
||||||
let top_edge = args.named("top-edge")?;
|
let top_edge = args.named("top-edge")?;
|
||||||
let bottom_edge = args.named("bottom-edge")?;
|
let bottom_edge = args.named("bottom-edge")?;
|
||||||
let fill = args.named("fill")?.or_else(|| args.find()).map(Paint::Solid);
|
let fill = args.named("fill")?.or_else(|| args.find());
|
||||||
let kerning = args.named("kerning")?;
|
let kerning = args.named("kerning")?;
|
||||||
let smallcaps = args.named("smallcaps")?;
|
let smallcaps = args.named("smallcaps")?;
|
||||||
let alternates = args.named("alternates")?;
|
let alternates = args.named("alternates")?;
|
||||||
|
@ -40,12 +40,12 @@ fn transform_impl(args: &mut Args, transform: Transform) -> TypResult<Value> {
|
|||||||
/// A node that transforms its child without affecting layout.
|
/// A node that transforms its child without affecting layout.
|
||||||
#[derive(Debug, Hash)]
|
#[derive(Debug, Hash)]
|
||||||
pub struct TransformNode {
|
pub struct TransformNode {
|
||||||
/// The node whose contents should be transformed.
|
|
||||||
pub child: PackedNode,
|
|
||||||
/// Transformation to apply to the contents.
|
/// Transformation to apply to the contents.
|
||||||
pub transform: Transform,
|
pub transform: Transform,
|
||||||
/// The origin of the transformation.
|
/// The origin of the transformation.
|
||||||
pub origin: Spec<Align>,
|
pub origin: Spec<Align>,
|
||||||
|
/// The node whose contents should be transformed.
|
||||||
|
pub child: PackedNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Layout for TransformNode {
|
impl Layout for TransformNode {
|
||||||
|
@ -16,7 +16,7 @@ use crate::geom::{AngularUnit, LengthUnit};
|
|||||||
use crate::source::SourceId;
|
use crate::source::SourceId;
|
||||||
use crate::util::EcoString;
|
use crate::util::EcoString;
|
||||||
|
|
||||||
/// An inner of leaf node in the untyped green tree.
|
/// An inner or leaf node in the untyped green tree.
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub enum Green {
|
pub enum Green {
|
||||||
/// A reference-counted inner node.
|
/// A reference-counted inner node.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user