简体   繁体   English

PDFsharp - 绘制文本,围绕自定义 pivot 点旋转并移动它

[英]PDFsharp - draw text, rotate it around a custom pivot point and move it

I would like to draw a text which is rotated around x degrees.我想绘制一个围绕 x 度旋转的文本。 Due to the fact I don't rotate it around it's center point I want to provide an offset too.由于我不围绕它的中心点旋转它,我也想提供一个偏移量。

First I rotate the rectangle around the custom pivot point首先,我围绕自定义 pivot 点旋转矩形

graphics.RotateAtTransform(RotationInDegrees, pivotPoint);

and I know I can move the transform with我知道我可以移动变换

graphics.TranslateTransform(offsetX, offsetY);

but to calculate the offset I need to know the new directions, so top might be bottom now on 180 degrees.但是要计算偏移量,我需要知道新的方向,所以顶部现在可能是 180 度的底部。

I have a 2D vector representing a grid system where center is at (0|0), top left (-1|1), bottom right (1|-1) etc. So basically I could rotate first, then draw the text我有一个表示网格系统的二维向量,其中中心位于 (0|0)、左上角 (-1|1)、右下角 (1|-1) 等。所以基本上我可以先旋转,然后绘制文本

textFormatter.DrawString(watermarkContent, Font, Brush, textBox, Format);

and after drawing the textBox I translate it.并在绘制文本框后翻译它。 Then I could use this calculation to know the correct rotation然后我可以使用这个计算来知道正确的旋转

graphics.TranslateTransform(alignmentVector.X * -horizontalOffset, alignmentVector.Y * verticalOffset);

but this is not possible.但这是不可能的。 I have to apply the transformations first and draw at the end.我必须先应用转换并在最后绘制。 So how can I apply the horizontal and vertical offset to the rectangle correctly (by knowing the correct direction) after rotating?那么如何在旋转后正确地将水平和垂直偏移应用于矩形(通过知道正确的方向)?

The transformations apply to items that get drawn after setting the transformations.转换应用于设置转换后绘制的项目。 This allows to draw text at a 30° angle and other text at a 60° angle by changing the transformations later on.这允许通过稍后更改转换以 30° 角绘制文本和以 60° 角绘制其他文本。

So you have to apply the transformations before drawing the text.因此,您必须在绘制文本之前应用转换。 The transformation also applies to the "textbox" used to draw the text and there is no need to change that box.转换也适用于用于绘制文本的“文本框”,无需更改该框。

Also see this sample:另请参阅此示例:
http://www.pdfsharp.net/wiki/XForms-sample.ashx http://www.pdfsharp.net/wiki/XForms-sample.ashx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM