C#中实现文字按指定的路径排列
2012-08-28 13:18:15 来源:WEB开发网_gp.FillMode = FillMode.Winding;
_gp.Flatten(null, 1);
try
{
_TmpPoint = _gp.PathPoints[0];
for (i = 0; i <= _gp.PathPoints.Length - 2; i++)
{
if (_gp.PathTypes[i + 1] == (byte)(PathPointType.Start) | (_gp.PathTypes[i] & ((byte)(PathPointType.CloseSubpath))) == (byte)(PathPointType.CloseSubpath))
{
_TmpPoints = GetLinePoints(_gp.PathPoints[i], _TmpPoint, 1);
Array.ConstrainedCopy(_TmpPoints, 0, _Points, _count, _TmpPoints.Length);
_count += 1;
_TmpPoint = _gp.PathPoints[i + 1];
}
else
{
_TmpPoints = GetLinePoints(_gp.PathPoints[i], _gp.PathPoints[i + 1], 1);
Array.ConstrainedCopy(_TmpPoints, 0, _Points, _count, _TmpPoints.Length);
_count += _TmpPoints.Length - 1;
}
}
_TmpPoints = new PointF[_count + 1];
Array.Copy(_Points, _TmpPoints, _count);
_Points = CleanPoints(_TmpPoints);
_count = _Points.Length - 1;
return DrawText(_Points, _count);
}
catch (Exception ex)
{
LastError = ex;
return null;
}
}
private PointF[] CleanPoints(PointF[] _points)
{
int i = 0;
PointF[] _tmppoints = new PointF[_points.Length + 1];
PointF _lastpoint = default(PointF);
int _count = 0;
for (i = 0; i <= _points.Length - 1; i++)
{
if (i == 0 | _points[i].X != _lastpoint.X | _points[i].Y != _lastpoint.Y)
{
_tmppoints[_count] = _points[i];
_count += 1;
}
_lastpoint = _points[i];
}
_points = new PointF[_count + 1];
Array.Copy(_tmppoints, _points, _count);
return _points;
}
//排版
private Bitmap DrawText(PointF[] _Points, int _MaxPoints)
{
GraphicsPath _gp = new GraphicsPath(_pathdataTOP.Points, _pathdataTOP.Types);
_gp.FillMode = FillMode.Winding;
_gp.Flatten();
Bitmap _bitmap = new Bitmap(
Convert.ToInt32(_gp.GetBounds().Right + _fontTOP.Size * 2),
Convert.ToInt32(_gp.GetBounds().Bottom + _fontTOP.Size * 2)
);
_gp.Dispose();
Graphics _G = Graphics.FromImage(_bitmap);
int _count = 0;
PointF _Point1 = default(PointF);
PointF _Point2 = default(PointF);
PointF _Point = default(PointF);
int _CharStep = 0;
int lStrWidth = 0;
double _Angle = default(double);
double _MaxWidthText = default(double);
int i = 0;
float[] _widths = null;
//_widths = MeasureWidths(_G)
Pen _pathpen = new Pen(_pathcolorTOP);
if (ShowPath == true)
{
foreach (PointF _Point1_loopVariable in _Points)
{
_Point1 = _Point1_loopVariable;
_G.DrawEllipse(_pathpen, _Point1.X, _Point1.Y, 1, 1);
}
}
_pathpen.Dispose();
for (i = 0; i <= _textTOP.Length - 1; i++)
{
_MaxWidthText += StringRegion(_G, i);
// _widths(i)
}
switch (_pathalignTOP)
{
case PathAlign.Left:
_Point1 = _Points[0];
_count = 0;
break;
case PathAlign.Center:
更多精彩
赞助商链接