后脚本中的旋转图形

发布于 2024-11-15 20:10:29 字数 127 浏览 5 评论 0原文

我想知道如何旋转图形,例如在后脚本中将矩形旋转一定角度。 或者至少有什么方法可以画得很大胆!就像,有一个角度!?

我有围绕一个圆圈的句子列表,所以每个句子都在一个方向上,现在,我想将每个句子放在一个矩形中并为它们创建超链接。

I was wondering how can I rotate a graphic, say a rectangular by certain angle in post script.
Or at least is there any way to draw a very bold ! like, with an angle !?

I have list of sentence around a circle, so each or in 1 direction, and now, I would like to put each in a rectangular and make hyperlink for them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寒冷纷飞旳雪 2024-11-22 20:10:29

Postscript的力量在于它对“延迟装订”理想的无情追求。轮换的实施也不例外。它通过使用更通用的工具——仿射变换矩阵来工作。

您可以旋转文本和图形(因为文本图形),因为所有用户指定的坐标首先乘以该矩阵以生成设备坐标

要执行所有必要的技巧(缩放、旋转、剪切、平移),我们首先必须将平面 z=1 上的 2d 点扩展到 3d 点(不要问我为什么;请阅读 Bill Casselman 的数学插图< /em> 或 Adob​​e Blue Book 了解更多信息)。

[ x     [ a b 0 
  y   *   c d 0    =  [ x' y' 1 ] = [ ax+cy+e bx+dy+f 1 ]
  1 ]     e f 1 ]

由于矩阵的第 3 列始终为 [ 0 0 1 ],因此在外部表示中省略了它,并且该矩阵在后记中描述为:

[ a b c d e f ]

因此,当您使用坐标对时,例如 moveto 运算符,moveto 首先将其转换为设备坐标,x' = ax+by+e, y' = cx+dy+f,然后添加 <> 元素添加到当前路径。
改变矩阵:改变用户坐标的“含义”。

单位矩阵是这样的:

[ 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

要平移,用 x 和 y 平移偏移替换 e 和 f:

[ 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

您可以使用concat“安装”此矩阵,该矩阵采用当前变换矩阵 (CTM),将其乘以新矩阵,并将乘积用作新的 CTM。因此,translaterotatescale 只是“便捷函数”,可以这样实现:

/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

这会生成以下图像:

<图像src="https://i.sstatic.net/aeMKZ.png" alt="旋转框和文本">
(来源:googlecode.com

The power of Postscript is its ruthless pursuit of the ideal of "delayed binding". The implementation of rotations is no exception. It works by making use of a more general tool, the Affine Transformation Matrix.

You can rotate both text and graphics (because text IS graphics) because all user specified coordinates are first multiplied through this matrix to produce device coordinates.

To perform all the necessary tricks (scaling, rotation, shear, translation), we first have to extend the 2d points to 3d points on the plane z=1 (don't ask me why; read Bill Casselman's Mathematical Illustrations or the Adobe Blue Book for more).

[ x     [ a b 0 
  y   *   c d 0    =  [ x' y' 1 ] = [ ax+cy+e bx+dy+f 1 ]
  1 ]     e f 1 ]

Since the 3rd column of the matrix is always [ 0 0 1 ] it is omitted from the external representation, and the matrix is described in postscript as:

[ a b c d e f ]

So when you use a coordinate pair for, say, a moveto operator, moveto first transforms it to device coordinates, x' = ax+by+e, y' = cx+dy+f, before adding a <</move [x' y']>> element to the current path.
Change the matrix: change the "meaning" of user coordinates.

The identity matrix is this:

[ 1 0 0 1 0 0 ]  % x' = x, y' = y

To scale, replace the 1s with x and y scaling factors:

[ Sx 0 0 Sy 0 0 ]  % x' = Sx*x, y' = Sy*y

To translate, replace e and f with the x and y translation offsets:

[ 1 0 0 1 Tx Ty ]  % x' = x+Tx, y' = y+Ty

To rotate, replace a,b,c,d with sin and cos scaling and shearing factors:

[ cosW sinW -sinW cosW 0 0 ]  % x' = x*cosW-y*sinW, y' = x*sinW+y*cosW, where W is angle(degrees) from x-axis

You "install" this matrix with concat which takes the Current Tranformation Matrix (CTM), multiplies it by your new matrix, and uses the product as the new CTM. So translate, rotate, and scale are just "convenience functions" which could be implemented like this:

/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

Since the CTM is part of the graphics state, you can use the graphics state stack to manipulate your transformations in a hierarchical manner:

/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

This produces the following image:

Rotating boxes and text
(source: googlecode.com)

风月客 2024-11-22 20:10:29

我已经很长时间没有使用 PostScript 了,但我记得你可以只使用“旋转”。

                             % 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

欢呼克里斯

I haven't used PostScript for a long time, but as I remember you could just use "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

cheers Kris

梦萦几度 2024-11-22 20:10:29

Postscript 在给定的上下文中渲染图形 - 并且正是这个上下文可以在绘制之前旋转(或缩放/平移)。因此,图像上的任何元素都可以根据需要进行转换,您所要做的就是事先执行必要的上下文转换。

然而,不幸的是,虽然我可以在本文中给您一个概念,但 i 是 Postscript 的基本概念,如果不首先理解它,您将无法在其中进行任何实际工作。我建议阅读一个简短的教程,例如 http://paulbourke.net/dataformats/postscript/ .

因此,“旋转”名称是一个旋转图形上下文的函数 - 您可以在绘制所需的任何内容之前使用旋转(在这种情况下渲染文本也称为“绘图”)。

%!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 

Postscript renders graphics in a given context - and it is this context that can be rotated (or scaled/translated) before drawing. Therefore any element on the image can be transformed as one wishes, all you have to do is to perform the necessary context transforms beforehand.

However, unfortunately, while I can give you an idea of it in this writing, i is a fundamental concept of Postscript, and you won't be able to do any real work in it without understanding that first. I suggest reading a brief tutorial such as the one in http://paulbourke.net/dataformats/postscript/ .

So, the "rotate" name is a function that does rotate the graphcis context - you use rotate, before drawing anything you want (rendering text also being "drawing" in this case).

%!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 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文