Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在使用路径绘制文本时从右向左生成文本_C#_String_Matrix_Path_Right To Left - Fatal编程技术网

C# 如何在使用路径绘制文本时从右向左生成文本

C# 如何在使用路径绘制文本时从右向左生成文本,c#,string,matrix,path,right-to-left,C#,String,Matrix,Path,Right To Left,我试图生成一个文本,它是RTL(从右到左的布局)。如果我用拉绳的话会很容易的。我将把字符串的所有字符保存在一个数组中,然后反向打印数组。但我用的是一个矩阵,它变换一条路径,然后画出路径。如何使用may文本绘制方法进行RTL 以下是我的代码供您参考: using (StringFormat string_format = new StringFormat()) { SizeF stringSize = e.Graphics.MeasureString(tex

我试图生成一个文本,它是RTL(从右到左的布局)。如果我用拉绳的话会很容易的。我将把字符串的所有字符保存在一个数组中,然后反向打印数组。但我用的是一个矩阵,它变换一条路径,然后画出路径。如何使用may文本绘制方法进行RTL

以下是我的代码供您参考:

using (StringFormat string_format = new StringFormat())
        {
            SizeF stringSize = e.Graphics.MeasureString(text, _fontStyle);
            rect.Location = new PointF(Shape.center.X - (rect.Width / 2), Shape.center.Y - (rect.Height / 2));
            GraphicsContainer gc = e.Graphics.BeginContainer();
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            //e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(rect));

            RectangleF r = new RectangleF(rect.Location, rect.Size);
            GraphicsPath path = new GraphicsPath();
            if (text == "" || text == " ")
                path.Dispose(); //Disposes the path to prevent OutOfMemoryExcetption
            else
            {
                path.AddString(text, _fontStyle.FontFamily, Convert.ToInt32(_fontStyle.Style), rect.Height, rect.Location, string_format);
                RectangleF text_rectf = path.GetBounds();
                PointF[] target_pts = {
                            new PointF(r.Left, r.Top),
                            new PointF(r.Right, r.Top),
                            new PointF(r.Left, r.Bottom)};
                //e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(r));
                using (Matrix m = new Matrix(text_rectf, target_pts))
                using (Matrix rotate = new Matrix(1, 0, 0, 1, Offset.X, Offset.Y)) 
                using (Matrix move = new Matrix())
                using (Matrix FlipXMatrix = new Matrix(-1, 0, 0, 1, 500, 0)) 
                using (Matrix FlipYMatrix = new Matrix(1, 0, 0, -1, 0, 500))
                using (Matrix TransformMatrix = new Matrix())
                {
                    TransformMatrix.Multiply(move);
                    rotate.RotateAt(angle, new PointF(250, 250 - Offset.Y));
                    TransformMatrix.Multiply(rotate);
                    if (flipped)
                        TransformMatrix.Multiply(FlipXMatrix);
                    TransformMatrix.Multiply(m); 
                    path.Transform(TransformMatrix);
                    //Checks if the user wants the text filled or outlined
                    if (!isOutlined)
                        e.Graphics.FillPath(Brushes.Red, path);
                    else
                        e.Graphics.DrawPath(Pens.Red, path);
                } 
            }
        e.Graphics.EndContainer(gc);
        }
另外,我使用布尔值来检查用户是否想要RTL


您可以使用string..()

inversedSample
字符串打印:

txeT elpmaS a si sihT
txeT elpmaS a si sihT