Abd*_*usa 18 .net c# printing graphics
根据msdn:http: //www.microsoft.com/middleeast/msdn/arabicsupp.aspx
GDI +如何支持阿拉伯语?
GDI +支持阿拉伯文本操作,包括输出设备,屏幕和打印机的RTL读取顺序的打印文本.Graphics.DrawString方法使用指定的StringFormat对象的格式属性,使用指定的Brush和Font对象在指定的x,y位置或矩形(根据其重载)绘制指定的文本字符串.StringFormat对象包括文本布局信息,例如文本阅读顺序.
因此,您可以轻松地将图形对象的原点移动到Right-Top而不是Left-Top,以便平滑地在屏幕上的指定位置打印出阿拉伯文本,而无需显式计算位置.
虽然将(X,Y)坐标设置为(0,0)时也是如此,但如果我想增加X坐标以在纸张上的特定区域打印,则X协调将增加到纸张的右侧而不是在从右到左打印时应该保持原样; 这意味着在纸张外打印.看这个演示:
static void Main(string[] args)
{
PrintDocument p = new PrintDocument();
p.PrintPage += new PrintPageEventHandler(PrintPage);
p.Print();
}
static void PrintPage(object sender, PrintPageEventArgs e)
{
string drawString = "?????? ?????";
SolidBrush drawBrush = new SolidBrush(Color.Black);
Font drawFont = new System.Drawing.Font("Arail", 16);
RectangleF recAtZero = new RectangleF(0, 0, e.PageBounds.Width, e.PageBounds.Height);
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
e.Graphics.DrawString(drawString, drawFont, drawBrush, recAtZero, drawFormat);
RectangleF recAtGreaterThantZero = new RectangleF(300, 0, e.PageBounds.Width, e.PageBounds.Height);
e.Graphics.DrawString(drawString, drawFont, drawBrush, recAtGreaterThantZero, drawFormat);
}
Run Code Online (Sandbox Code Playgroud)
如何将图形对象的原点移动到Right-Top而不是Left-Top,当增加X坐标时,它将打印点向左推进而不是向右推进.
PS:我现在正在做的是将X协调设置为负值以强制它向左移动.

kaz*_*zem 31
使用StringFormatFlags.DirectionRightToLeft,如下所示:
StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
e.Graphics.DrawString("????",
this.Font,
new SolidBrush(Color.Red),
r1,
format);
Run Code Online (Sandbox Code Playgroud)
您可以进行非常简单的坐标变换:
public static class CoordinateConverter
{
public static RectangleF Convert(RectangleF source, RectangleF drawArea)
{
// I assume drawArea.X to be 0
return new RectangleF(
drawArea.Width - source.X - source.Width,
source.Y,
source.Width,
source.Height);
}
public static RectangleF ConvertBack(Rectangle source, RectangleF drawArea)
{
return new RectangleF(
source.X + source.Width - drawArea.Width,
source.Y,
source.Width,
source.Height);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,每次您想要绘制文本时,您都可以使用此转换器来更改坐标。当然,您也可以引用一个矩形,这样您就不会一直创建新的矩形。但原则保持不变。我希望我正确理解你的问题。