mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Disable justification in raw(block: true, ...)
(#4889)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
cb1aad3a0c
commit
692d846d25
@ -27,10 +27,9 @@ pub fn finalize(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Stack the lines into one frame per region.
|
// Stack the lines into one frame per region.
|
||||||
let shrink = ParElem::shrink_in(styles);
|
|
||||||
lines
|
lines
|
||||||
.iter()
|
.iter()
|
||||||
.map(|line| commit(engine, p, line, width, region.y, shrink, locator, styles))
|
.map(|line| commit(engine, p, line, width, region.y, locator, styles))
|
||||||
.collect::<SourceResult<_>>()
|
.collect::<SourceResult<_>>()
|
||||||
.map(Fragment::frames)
|
.map(Fragment::frames)
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,6 @@ pub fn commit(
|
|||||||
line: &Line,
|
line: &Line,
|
||||||
width: Abs,
|
width: Abs,
|
||||||
full: Abs,
|
full: Abs,
|
||||||
shrink: bool,
|
|
||||||
locator: &mut SplitLocator<'_>,
|
locator: &mut SplitLocator<'_>,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
) -> SourceResult<Frame> {
|
) -> SourceResult<Frame> {
|
||||||
@ -469,7 +468,7 @@ pub fn commit(
|
|||||||
|
|
||||||
let shrinkability = line.shrinkability();
|
let shrinkability = line.shrinkability();
|
||||||
let stretchability = line.stretchability();
|
let stretchability = line.stretchability();
|
||||||
if remaining < Abs::zero() && shrinkability > Abs::zero() && shrink {
|
if remaining < Abs::zero() && shrinkability > Abs::zero() {
|
||||||
// Attempt to reduce the length of the line, using shrinkability.
|
// Attempt to reduce the length of the line, using shrinkability.
|
||||||
justification_ratio = (remaining / shrinkability).max(-1.0);
|
justification_ratio = (remaining / shrinkability).max(-1.0);
|
||||||
remaining = (remaining + shrinkability).min(Abs::zero());
|
remaining = (remaining + shrinkability).min(Abs::zero());
|
||||||
|
@ -126,15 +126,6 @@ pub struct ParElem {
|
|||||||
#[resolve]
|
#[resolve]
|
||||||
pub hanging_indent: Length,
|
pub hanging_indent: Length,
|
||||||
|
|
||||||
/// Indicates whether an overflowing line should be shrunk.
|
|
||||||
///
|
|
||||||
/// This property is set to `false` on raw blocks, because shrinking a line
|
|
||||||
/// could visually break the indentation.
|
|
||||||
#[ghost]
|
|
||||||
#[internal]
|
|
||||||
#[default(true)]
|
|
||||||
pub shrink: bool,
|
|
||||||
|
|
||||||
/// The contents of the paragraph.
|
/// The contents of the paragraph.
|
||||||
#[external]
|
#[external]
|
||||||
#[required]
|
#[required]
|
||||||
|
@ -473,7 +473,7 @@ impl ShowSet for Packed<RawElem> {
|
|||||||
out.set(TextElem::set_size(TextSize(Em::new(0.8).into())));
|
out.set(TextElem::set_size(TextSize(Em::new(0.8).into())));
|
||||||
out.set(TextElem::set_font(FontList(vec![FontFamily::new("DejaVu Sans Mono")])));
|
out.set(TextElem::set_font(FontList(vec![FontFamily::new("DejaVu Sans Mono")])));
|
||||||
if self.block(styles) {
|
if self.block(styles) {
|
||||||
out.set(ParElem::set_shrink(false));
|
out.set(ParElem::set_justify(false));
|
||||||
}
|
}
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
BIN
tests/ref/issue-3191-raw-justify.png
Normal file
BIN
tests/ref/issue-3191-raw-justify.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 622 B |
@ -594,23 +594,16 @@ fn main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
--- issue-3191-raw-indent-shrink ---
|
--- issue-3191-raw-justify ---
|
||||||
// Spaces in raw blocks should not be shrunk as it would mess up the indentation
|
// Raw blocks should not be justified by default.
|
||||||
// of code.
|
```
|
||||||
#set par(justify: true)
|
a b c --------------------
|
||||||
|
```
|
||||||
#show raw.where(block: true): block.with(
|
|
||||||
fill: luma(240),
|
#show raw: set par(justify: true)
|
||||||
inset: 10pt,
|
```
|
||||||
)
|
a b c --------------------
|
||||||
|
|
||||||
#block(
|
|
||||||
width: 60%,
|
|
||||||
```py
|
|
||||||
for x in xs:
|
|
||||||
print("x=",x)
|
|
||||||
```
|
```
|
||||||
)
|
|
||||||
|
|
||||||
--- issue-3191-raw-normal-paragraphs-still-shrink ---
|
--- issue-3191-raw-normal-paragraphs-still-shrink ---
|
||||||
// In normal paragraphs, spaces should still be shrunk.
|
// In normal paragraphs, spaces should still be shrunk.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user