以编程方式扭曲Windows Phone中的文本

时间:2015-03-19 18:53:11

标签: c# wpf windows-phone-8 pathgeometry

我正在尝试使用不同的API集合(WinForms,WPF和Windows Phone 8)以编程方式使用C#绘制一个扭曲的文本字符串。

使用WinForms,我设法通过这种方式实现了GDI + System.Drawing.Drawing2D.GraphicsPath类:

System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new Drawing::Point(0, 0), Drawing::StringFormat.GenericDefault);
PointF[] origPoints = path.PathPoints;
PointF[] newPoints = new PointF[originalPath.PointCount];
/* Generate the values of newPoints items from origPoints items */
System.Drawing.Drawing2D.GraphicsPath distortion = new System.Drawing.Drawing2D.GraphicsPath(newPoints, path.PathTypes);

/* ...Create Graphics object... */

graphics.FillPath(Drawing::Brushes.Black, distortion);

使用WPF,我设法通过从System.Windows.Media.Geometry创建System.Windows.Media.FormattedText,通过PathGeometry将其转换为System.Windows.Shapes.Path,然后手动创建解冻深度来实现此目的其Figures属性的副本,并修改Point的每PolyLineSegmentPathFigure中的每个PathGeometry。它看起来像这样:

FormattedText formattedText = new Media::FormattedText(text, 
            System.Globalization.CultureInfo.GetCultureInfo("en-us"),
            Windows::FlowDirection.LeftToRight,
            typeface, fontSize, Media::Brushes.Transparent);
Geometry geom = formattedText.BuildGeometry(new Point(0, 0));

Path path = new Path();
path.Data = geom;
PathGeometry pathGeom = path.Data.GetFlattenedPathGeometry();
PathGeometry newGeom = new PathGeometry(); /* Cloned geometry. We can't modify the original - it's frozen */

newGeom.Figures = pathGeom.Figures.Clone();
/* Etc... Clone the Segments for each Figure, then the Points for every Segment */

/* ...Create DrawingContext... */

context.DrawGeometry(Media::Brushes.Black, null, newGeom);

我尝试将后一种解决方案移植到Windows Phone(Windows Phone 8),但我发现它缺少FormattedTextDrawingContextGeometry.GetFlattenedPathGeometry()和{{1 CloneFigureSegment s集合的方法(也是PointRenderTargetBitmapDrawingVisual错过的方法我对如何以及在何处呈现修改后的Geometry一无所知,但这可以被视为一个单独的问题。)

如何将WPF代码移植到Windows Phone 8?我可以使用哪些替代方法从文本字符串构建Geometry,从PathGeometry获取Geometry,以及如何Clone其内容?

或者是否有更好的方法可以在Windows Phone 8上以编程方式扭曲文本?

0 个答案:

没有答案