根据 msdn:http://www.microsoft.com/middleeast/msdn/arabicsupp.aspx (链接已过期!)
GDI + 如何支持阿拉伯文?
GDI+ 支持阿拉伯文本操作,包括在输出设备,屏幕和打印机上以 RTL 阅读顺序打印文本。 Graphics.DrawString 方法使用指定的 Brush 和 Font 对象绘制指定的文本字符串在指定的 x、y 位置或矩形(根据其重载),使用指定 StringFormat 对象的格式化特性。 StringFormat 对象包括文本布局信息,如文本读取顺序。
因此,您可以轻松地将图形对象的原点移动到右上方,而不是左上方,以在屏幕上平稳地打印出指定位置的阿拉伯文本,而无需显式地计算位置。
当将 (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);
}
如何将图形对象的原点移动到右上角而不是左上角,当增加X坐标时,它将打印点向左移而不是向右移。
PS:我现在所做的是将X坐标设置为负数以强制其向左移动。