fonts – 从Font中提取几何
发布时间:2020-05-28 13:44:32 所属栏目:Java 来源:互联网
导读:我希望能够在TrueType字体文件中提取每个字母的几何.每个字母都有一组坐标,假设每个字母都在自己的网格中. 如图所示,千言万语 – 我想获得与下图相似的字母顶点(由http://polymaps.org/提供) 更新 由于提示使用GDI,现在已经将其集成到.NET System.Drawing.Dra
|
我希望能够在TrueType字体文件中提取每个字母的几何.每个字母都有一组坐标,假设每个字母都在自己的网格中. 如图所示,千言万语 – 我想获得与下图相似的字母顶点(由http://polymaps.org/提供) 更新 由于提示使用GDI,现在已经将其集成到.NET System.Drawing.Drawing2D中,我获得了以下代码来创建WKT多边形.没有bezier曲线可能.即使在翻转和旋转字母后,某些路径仍然无法正确连接. // C# Visual Studio
GraphicsPath gp = new GraphicsPath();
Point origin = new Point(0,0);
StringFormat format = new StringFormat();
FontFamily ff = new FontFamily("Arial");
//enter letter here
gp.AddString("T",ff,12,origin,format); //ABCDEFGHIJKLMNOPQRSTUVWXYZ
StringBuilder sb = new StringBuilder();
sb.AppendLine("DECLARE @g geometry;");
sb.Append("SET @g = geometry::STGeomFromText('POLYGON ((");
Matrix flipmatrix = new Matrix(-1,1,0);
gp.Transform(flipmatrix);
Matrix rotationtransform = new Matrix();
RectangleF r = gp.GetBounds();
// Get center point
PointF rotationPoint = new PointF(r.Left + (r.Width / 2),r.Top + (r.Height / 2));
rotationtransform.RotateAt(180,rotationPoint);
gp.Transform(rotationtransform);
//gp.CloseAllFigures(); //make sure the polygon is closed - does not work
foreach (PointF pt in gp.PathData.Points)
{
sb.AppendFormat("{0} {1},",pt.X,pt.Y);
}
PointF firstpoint = gp.PathData.Points[0];
sb.AppendFormat("{0} {1}",firstpoint.X,firstpoint.Y); //make last point same as first
sb.Append("))',0);");
sb.AppendLine("");
sb.AppendLine("SELECT @g");
System.Diagnostics.Debug.WriteLine(sb.ToString());
解决方法对于Windows,您可以使用Gdiplus.创建一个 GraphicsPath并在其上调用AddString().然后检查PathData或PathPoints. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
