Skip to content

Skew transform #2749

Closed
Closed

Description

@Enivex

Description

Typst currently has https://typst.app/docs/reference/layout/rotate/ and https://typst.app/docs/reference/layout/scale/, but no skew transform. While it can be expressed using a combination of the former, it's not trivial to get right

#let skew(angle,vscale: 1,body) = {
  let (a,b,c,d)= (1,vscale*calc.tan(angle),0,vscale)
  let E = (a + d)/2
  let F = (a - d)/2
  let G = (b + c)/2
  let H = (c - b)/2
  let Q = calc.sqrt(E*E + H*H)
  let R = calc.sqrt(F*F + G*G)
  let sx = Q + R
  let sy = Q - R
  let a1 = calc.atan2(F,G)
  let a2 = calc.atan2(E,H)
  let theta = (a2 - a1) /2
  let phi = (a2 + a1)/2
  
  set rotate(origin: bottom+center)
  set scale(origin: bottom+center)
  
  rotate(phi,scale(x: sx*100%, y: sy*100%,rotate(theta,body)))
}

(The vscale parameter is strictly speaking unnecessary)

Use Case

A couple of trivial examples are fake italic text and shadows

#let fake-italic(body) = skew(-12deg,body)

#let shadowed(body) = box(place(skew(-50deg, vscale: 0.8, text(fill:luma(200),body)))+place(body))

#fake-italic[This is fake italic text]

#shadowed[This is some fancy text with a shadow]

rendered

Activity

  1. added
    layout
    change request
    on Nov 23, 2023
  2. added
    feature request
    and removed
    change request
    on Nov 24, 2023
  3. csimide commented on Mar 20, 2024

    @csimide

    Hello, I would like to use the skew transform implementation code in this issue to add fake italics support to cuti, a package released under the MIT license. Would it be possible for me to utilize this code for that purpose?

  4. Enivex commented on Mar 20, 2024

    @Enivex
    CollaboratorAuthor

    Hello, I would like to use the skew transform implementation code in this issue to add fake italics support to cuti, a package released under the MIT license. Would it be possible for me to utilize this code for that purpose?

    Feel free

  5. added
    good contribution
    on Jul 16, 2024
  6. laurmaedje commented on Sep 2, 2024

    @laurmaedje
    Member

    Resolved by #4803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestgood contributionlayout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions