帖子脚本中的旋转图形

| 我想知道如何在后脚本中旋转图形,例如以一定角度说一个矩形。 或至少有什么方法可以画得非常大胆!喜欢,有一个角度! 我有一个围绕一圈的句子列表,所以每个或一个方向都行,现在,我想将每个句子放在一个矩形中并为其建立超链接。     
已邀请:
        后记的力量在于对“延迟绑定”理想的无情追求。轮换的实施也不例外。它通过使用更通用的工具仿射变换矩阵来工作。 您可以同时旋转文本和图形(因为文本是IS图形),因为所有用户指定的坐标都首先通过此矩阵相乘以生成设备坐标。 要执行所有必要的技巧(缩放,旋转,剪切,平移),我们首先必须将平面z = 1上的2d点扩展到3d点(不要问我为什么;请阅读Bill Casselman的数学插图)或Adobe Blue Book了解更多信息)。
[ x     [ a b 0 
  y   *   c d 0    =  [ x\' y\' 1 ] = [ ax+cy+e bx+dy+f 1 ]
  1 ]     e f 1 ]
由于矩阵的第三列始终为[0 0 1],因此从外部表示中将其省略,并且在后记中将矩阵描述为:
[ a b c d e f ]
因此,当您将坐标对用于
moveto
运算符时,
moveto
首先将其转换为设备坐标x \'= ax + by + e,y \'= cx + dy + f,然后再向其中添加
<</move [x\' y\']>>
元素当前路径。 更改矩阵:更改用户坐标的“含义”。 身份矩阵是这样的:
[ 1 0 0 1 0 0 ]  % x\' = x, y\' = y
要缩放,请用x和y缩放因子替换1:
[ Sx 0 0 Sy 0 0 ]  % x\' = Sx*x, y\' = Sy*y
要进行翻译,请将e和f替换为x和y的翻译偏移量:
[ 1 0 0 1 Tx Ty ]  % x\' = x+Tx, y\' = y+Ty
要旋转,请用sin和cos缩放比例和剪切因子替换a,b,c,d:
[ cosW sinW -sinW cosW 0 0 ]  % x\' = x*cosW-y*sinW, y\' = x*sinW+y*cosW, where W is angle(degrees) from x-axis
您用“ 9”“安装”此矩阵,该矩阵将使用当前转换矩阵(CTM),并将其乘以新矩阵,然后将乘积用作新CTM。因此
translate
rotate
scale
只是“便利功能”,可以这样实现:
/translate { [ 1 0 0 1 7 -2 roll ] concat } def
/scale { [ 3 1 roll 0 0 3 -1 roll 0 0 ] concat } def
/rotate { [ exch dup cos exch sin dup neg 2 index 0 0 ] concat } def
由于CTM是图形状态的一部分,因此您可以使用图形状态堆栈以分层方式操作转换:
/box { % x y w h   %create a path in the shape of a box w*h with lower left corner at x,y
    4 2 roll moveto
    exch dup 3 1 roll
    0 rlineto
    0 exch rlineto
    neg 0 rlineto
    closepath
} def

/Courier 10 selectfont
100 100 100 100 box stroke   % draw an oriented box
120 120 moveto (inside) show
gsave
    150 150 translate   % make the center of the box the new 0,0 point
    45 rotate   % rotate CCW 45 degrees
    0 0 100 100 box stroke   % a rotated, shifted box
    20 20 moveto (inside) show
grestore
100 200 100 100 box stroke   % another box, just north of the first, in the original coordinte system
120 220 moveto (inside) show
这将产生以下图像: (来源:googlecode.com)     
        我已经很久没有使用PostScript了,但是我记得您可以使用\“ rotate \”。
                             % do some steps
                             % ...
                             % ...
 20 20 moveto                % go to new position
 30 /Times-Roman SetFont     % select active font
 45 rotate                   % set direction to diagonal
 (Something)show             % print text \"Something\"
 showpage                    % show it all
欢呼克里斯     
        后记在给定的上下文中渲染图形-可以在绘制之前旋转(或缩放/平移)此上下文。因此,图像上的任何元素都可以按自己的意愿进行转换,您要做的就是事先执行必要的上下文转换。 但是,不幸的是,虽然我可以在本文中给您一个概念,但我是Postscript的基本概念,如果不先了解Postscript,您将无法在其中进行任何实际的工作。我建议阅读简短的教程,例如http://paulbourke.net/dataformats/postscript/中的教程。 因此,“ rotate”名称是一个可旋转graphcis上下文的函数-在绘制所需的任何东西之前,先使用rotate(在这种情况下,渲染文本也为“ drawing \”)。
%!PS

(Helvetica) findfont 12 scalefont setfont   %select a font to use

300 300 translate    % sets the orign at 300,300 points from the bottom left of page

/start 5  def        % creates variable for keeping track of horizontal position of text

36                   % pushes number of repeats on the stack
{
    start 5 moveto   % places cursor on the starting position
    (postscript) show % renders the string in the starting position, within the current context

    /start  start 3 add def   % increases the value on the variable
   10 rotate         % rotates the context 10 degrees clockwise   (around the 300,300 new origin)
}  repeat           

showpage             % renders whole page 
    

要回复问题请先登录注册