有没有办法使用任何Windows字体获取文本轮廓的每个顶点的位置?
我需要一个算法,我发送文本和字体,然后我得到文本中每个字符的顶点坐标。
答案 0 :(得分:0)
我不知道http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/f50d43fe-8206-40e5-98da-6c60630b5f73中的答案是否是你所需要的,但请看一看 我发布了可以解决问题的部分代码:
public struct GLYPHMETRICS
{
public uint gmBlackBoxX;
public uint gmBlackBoxY;
public Point gmptGlyphOrigin;
public short gmCellIncX;
public short gmCellIncY;
}
public struct FIXED
{
public ushort fract;
public short value;
}
public struct MAT2
{
public FIXED eM11;
public FIXED eM12;
public FIXED eM21;
public FIXED eM22;
}
[DllImport("gdi32.dll")]
static extern uint GetGlyphOutline(IntPtr hdc, uint uChar, uint uFormat,
out GLYPHMETRICS lpgm, uint cbBuffer, IntPtr lpvBuffer, ref MAT2 lpmat2);
public static bool GetGlyphShape(Font font, Char c, out GLYPHMETRICS metrics)
{
metrics = new GLYPHMETRICS();
MAT2 matrix = new MAT2();
matrix.eM11.value = 1;
matrix.eM12.value = 0;
matrix.eM21.value = 0;
matrix.eM22.value = 1;
using (Bitmap b = new Bitmap(1, 1))
{
using (Graphics g = Graphics.FromImage(b))
{
IntPtr hdc = g.GetHdc();
IntPtr prev = SelectObject(hdc, font.ToHfont());
int bufferSize = (int)GetGlyphOutline(
hdc, (uint)c, (uint)2, out metrics, 0,
IntPtr.Zero, ref matrix);
IntPtr buffer = Marshal.AllocHGlobal(bufferSize);
bool retval = false;
try
{
retval = GetGlyphOutline(hdc, (uint)c, (uint)2,
out metrics, (uint)bufferSize,
buffer, ref matrix) > 0;
g.ReleaseHdc(hdc);
}
catch { retval = false; }
finally
{
Marshal.FreeHGlobal(buffer);
}
return retval;
}
}
}
答案 1 :(得分:0)
你可以使用任何3D建模软件。例如,blender对创建文本对象和导出obj格式文件有很好的支持,可以在简单的记事本中打开。在这里,您可以检索所需角色的所有顶点。