[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to prevent ly:stencil-rotate to modify dimensions
From: |
Torsten Hämmerle |
Subject: |
Re: How to prevent ly:stencil-rotate to modify dimensions |
Date: |
Sun, 11 Mar 2018 07:27:11 -0700 (MST) |
Hi Harm,
David is right - it's the bounding box being rotated. As bounding boxes can
only have heights and widths in vertical and horizontal direction (there
isn't even such a thing as an italic slant in LilyPond), the resulting new
bounding box's height and width increases.
I usually solve this problem by calculating the desired X-extent and
Y-extent and set the stencil dimensions.
In scheme, I use (ly:stencil-outline stencil point-stencil) to rotate
stencil using the dimensions of point-stencil so that the bounding box isn't
distorted .
*Example:* I've created a fake slanted markup command by combining rotate,
scale, rotate back, scale (because there is no shearing) that keeps the
original stencil extent.
Without stencil extent manipulations (using point-stencil dimensions etc.)
the resulting bounding box would be ridiculously high and totally unusable.
%%%%%%%%%%%
\version "2.19.81"
#(define-markup-command
(slanted layout props arg)
(markup?)
#:category font
#:properties ((slant-angle 12))
"Fake a slanted font"
(let* ((alpha-rad (* 0.5 (acos (tan (* (/ PI -180) slant-angle)))))
(alpha-deg (* (/ 180 PI) alpha-rad))
(stencil (if (markup? arg) (interpret-markup layout props arg)
empty-stencil))
)
(ly:stencil-outline
(ly:stencil-scale
(ly:stencil-rotate
(ly:stencil-scale
(ly:stencil-rotate (ly:stencil-outline stencil point-stencil) 45 0
0)
1 (* (tan alpha-rad)))
(* (- alpha-deg)) 0 0)
(* (sqrt 2) (cos alpha-rad)) (/ 0.5 (sqrt 0.5) (sin alpha-rad)))
stencil)))
\markup \override #'(box-padding . 0) \box \slanted "Poor man’s slanted
Text"
poor-mans-slanted.png
<http://lilypond.1069038.n5.nabble.com/file/t3887/poor-mans-slanted.png>
This is a simple case just keeping the original extents, but in the end, the
desired new bounding box (i.e. stencil extent) has to be calculated
explicitly depending on the desired output, I couldn't find an automatic
solution either.
Simple trigonometric functions are all you need - it could be worse... ;)
All the best,
Torsten
--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html
- How to prevent ly:stencil-rotate to modify dimensions, Thomas Morley, 2018/03/11
- Re: How to prevent ly:stencil-rotate to modify dimensions, Andrew Bernard, 2018/03/11
- Re: How to prevent ly:stencil-rotate to modify dimensions, David Kastrup, 2018/03/11
- Re: How to prevent ly:stencil-rotate to modify dimensions,
Torsten Hämmerle <=
- Re: How to prevent ly:stencil-rotate to modify dimensions, Thomas Morley, 2018/03/11
- Re: How to prevent ly:stencil-rotate to modify dimensions, Torsten Hämmerle, 2018/03/11
- Re: How to prevent ly:stencil-rotate to modify dimensions, David Kastrup, 2018/03/11
- Re: How to prevent ly:stencil-rotate to modify dimensions, Torsten Hämmerle, 2018/03/12
- Re: How to prevent ly:stencil-rotate to modify dimensions, David Kastrup, 2018/03/12
- Re: How to prevent ly:stencil-rotate to modify dimensions, Torsten Hämmerle, 2018/03/12