From 692d846d25a69023c15ba739f41c211270562dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20d=27Herbais=20de=20Thun?= Date: Mon, 4 Nov 2024 10:37:29 +0100 Subject: [PATCH] Disable justification in `raw(block: true, ...)` (#4889) Co-authored-by: Laurenz --- crates/typst-layout/src/inline/finalize.rs | 3 +-- crates/typst-layout/src/inline/line.rs | 3 +-- crates/typst-library/src/model/par.rs | 9 -------- crates/typst-library/src/text/raw.rs | 2 +- tests/ref/issue-3191-raw-indent-shrink.png | Bin 1422 -> 0 bytes tests/ref/issue-3191-raw-justify.png | Bin 0 -> 622 bytes tests/suite/text/raw.typ | 25 ++++++++------------- 7 files changed, 12 insertions(+), 30 deletions(-) delete mode 100644 tests/ref/issue-3191-raw-indent-shrink.png create mode 100644 tests/ref/issue-3191-raw-justify.png diff --git a/crates/typst-layout/src/inline/finalize.rs b/crates/typst-layout/src/inline/finalize.rs index 599ace9de..57044f0ec 100644 --- a/crates/typst-layout/src/inline/finalize.rs +++ b/crates/typst-layout/src/inline/finalize.rs @@ -27,10 +27,9 @@ pub fn finalize( }; // Stack the lines into one frame per region. - let shrink = ParElem::shrink_in(styles); lines .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::>() .map(Fragment::frames) } diff --git a/crates/typst-layout/src/inline/line.rs b/crates/typst-layout/src/inline/line.rs index 596e109ee..6dca95a9d 100644 --- a/crates/typst-layout/src/inline/line.rs +++ b/crates/typst-layout/src/inline/line.rs @@ -417,7 +417,6 @@ pub fn commit( line: &Line, width: Abs, full: Abs, - shrink: bool, locator: &mut SplitLocator<'_>, styles: StyleChain, ) -> SourceResult { @@ -469,7 +468,7 @@ pub fn commit( let shrinkability = line.shrinkability(); 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. justification_ratio = (remaining / shrinkability).max(-1.0); remaining = (remaining + shrinkability).min(Abs::zero()); diff --git a/crates/typst-library/src/model/par.rs b/crates/typst-library/src/model/par.rs index a43499d8a..8b82abdf7 100644 --- a/crates/typst-library/src/model/par.rs +++ b/crates/typst-library/src/model/par.rs @@ -126,15 +126,6 @@ pub struct ParElem { #[resolve] 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. #[external] #[required] diff --git a/crates/typst-library/src/text/raw.rs b/crates/typst-library/src/text/raw.rs index 8691afcb3..f318f06e9 100644 --- a/crates/typst-library/src/text/raw.rs +++ b/crates/typst-library/src/text/raw.rs @@ -473,7 +473,7 @@ impl ShowSet for Packed { out.set(TextElem::set_size(TextSize(Em::new(0.8).into()))); out.set(TextElem::set_font(FontList(vec![FontFamily::new("DejaVu Sans Mono")]))); if self.block(styles) { - out.set(ParElem::set_shrink(false)); + out.set(ParElem::set_justify(false)); } out } diff --git a/tests/ref/issue-3191-raw-indent-shrink.png b/tests/ref/issue-3191-raw-indent-shrink.png deleted file mode 100644 index e7ac73b739c8fbdcdfed01eade3ea73d6a5e89b2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1422 zcmV;91#$X`P)+J9B?CkIA>*Vp^>+9?9>FMw2>F?+0>FMd`>F)04=kDg_ z=jiR|=;-d{=I`X?<>&6_=jZO@($xo)Z*ge-R9ch z;NaZf>h0Ov-{0TU=*`;R>(S@S-QC^L=gQpN+}qpR?9$ZQ+S=>T(%9J8%HzY)*XZlc z(a7S#>&?*6*68cZ&+E(1>&nf|)aTUH)Xmf9)6>)I$ji&p=hD*B(9qDn-L>h%#>dX( z>cPdt%;o97!_3Ug%gf8k%F5}yz{$zU=(@k?xxKX4s8lE#FQ#e$uz+vJp- ztgNh?tJ~v}nX9X-nyT8Vsi~N#+Ks<|iNSi8r`eXL*_Ni+r>CcizI>FW*oMD$lcd<< ziIU=nkm81qqN1XKyl~-#j*g($;e?IhgN&e{pnkh;pP!$6x@&y8YKxuLik#Mno7SA1 zoZx(hceiEWdxe^snuVFwgqPIcc!F}ZV1ky^as zdXUoIZh2|2R(X%o-fei0kdTg!j@@c?jg5`nX>^Q?jNWH+-Dh&$W^!?e&~S&(++l5p zhlhcIf!kPR+f`y#FQZ#kA9Y;0_6Yinp| zXlG|7ggsdia&V8gvaYgN|)SR|LSvm4M~|&_2+Lavpvzc@J9! zpYK&YIC&`=O4I?^3dAg@R&DMzBoB#Jw6NjE*TQ$Ty_*;83DkcFoVJ?egr_| z>lcQ8>Mj`$U+eaZn*JV++%O~@>WsgyQ|hk95HM2Cv4jl>2k}?2(4=rRp{+nAqe4QP zf0?|3N1^Vx(oKbxjSdQJ#kVGu71}!8)Cu0PbAK(yM<1S8Td@=(<{jwGqC1KqkZB2v z?e_@Bp<-4^6})zd3NC$DEDRMQODFh|NyJp*mQw*v!h#5sqsj|>*ZlG3*%L%UN=k~o z$Z6Aqw?c?_cDle<@lGVJC#c{Kq^aR-4cy{cF)<)KJlsg+RPJ&y zxGftDC+4c)?v7$$eWC5cFyXXC_{NKxFNH2}8o6Y8;ooz7Uvrt}tP|`lSEhs|EMb{U cCd>Ez2B&!{LUXu&2LJ#707*qoM6N<$f_v3Lc>n+a diff --git a/tests/ref/issue-3191-raw-justify.png b/tests/ref/issue-3191-raw-justify.png new file mode 100644 index 0000000000000000000000000000000000000000..1466ccf019c7cf11fd705e04095c77dcd32f1a55 GIT binary patch literal 622 zcmV-!0+IcRP)ei;tA9FhQ%YCX(@FCK?CysJ2%stjyk0~>f>;hU=!h3&zv zwF3O9*CO9=cckp_M#o@HDi7DS-T;8R4MSsPhpqedNBwztf|CGn94I^7*2)EM9v@cxVA_qV`>8H@P$2<@N8~A^M*YytgbrR-vjmXbma-2cmivHuY9vw5aX;s3_boet=6X!$Xl` zOFV<$q8C1j&(I_0ph<*DibvoRui%>)fIgw1T?9Y~o1kch8Sw^&#RznX1$ZK&#KmKC zV*?x5z=s#k$M=AzF5Nm-0(_?SHjbM<-OyAN#)@ZfoSh9) zLiS3|d@chUxB~E!+Jre3hY6L#QZo=%9#~atu&8!mTBXRUpAb_Tf@&H3Dg?7C0ZKtq z{eo@fg@9Uz1r>oQmBv<+d%*AIBy`IFJe6s-r3>a|AB@Vc@K!EDyNqDT=ddh$K*