WEB开发网
开发学院WEB开发ASP.NET C#中实现文字按指定的路径排列 阅读

C#中实现文字按指定的路径排列

 2012-08-28 13:18:15 来源:WEB开发网   
核心提示:i = 0;while (i < regions.Length){Region region = regions[i];RectangleF cb = region.GetBounds(graphics);widths[start + i] = cb.Width;i += 1;}start += length;r
i = 0;
while (i < regions.Length)
{
Region region = regions[i];
RectangleF cb = region.GetBounds(graphics);
widths[start + i] = cb.Width;
i += 1;
}
start += length;
remainder -= 31;
}
return widths;
}

private double GetAngle(PointF _point1, PointF _point2)
{
double c = default(double);

c = Math.Sqrt(Math.Pow((_point2.X - _point1.X), 2) + Math.Pow((_point2.Y - _point1.Y), 2));

if (c == 0)
{
return 0;
}

if (_point1.X > _point2.X)
{
return Math.Asin((_point1.Y - _point2.Y) / c) * 180 / Math.PI - 180;
}
else
{
return Math.Asin((_point2.Y - _point1.Y) / c) * 180 / Math.PI;
}
}

private void DrawRotatedText(Graphics _gr, string _text, float _angle, PointF _PointCenter)
{
StringFormat string_format = new StringFormat();
string_format.Alignment = StringAlignment.Center;

_gr.SmoothingMode = SmoothingMode.HighQuality;
_gr.CompositingQuality = CompositingQuality.HighQuality;
_gr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
GraphicsPath graphics_path = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding);
int x = Convert.ToInt32(_PointCenter.X);
int y = Convert.ToInt32(_PointCenter.Y);

switch (TextPathPosition)
{
case TextPosition.OverPath:
graphics_path.AddString(_text, _fontTOP.FontFamily, (int)_fontTOP.Style, (float)_fontTOP.Size, new Point(x, y - (int)_fontTOP.Size), string_format);
break;
case TextPosition.CenterPath:
graphics_path.AddString(_text, _fontTOP.FontFamily, (int)_fontTOP.Style, (float)_fontTOP.Size, new Point(x, y - (int)_fontTOP.Size / 2), string_format);
break;
case TextPosition.UnderPath:
graphics_path.AddString(_text, _fontTOP.FontFamily, (int)_fontTOP.Style, (float)_fontTOP.Size, new Point(x, y), string_format);
break;
}

Matrix rotation_matrix = new Matrix();
rotation_matrix.RotateAt(_angle, new PointF(x, y));
graphics_path.Transform(rotation_matrix);

_gr.DrawPath(new Pen(_colorTOP), graphics_path);
_gr.FillPath(new SolidBrush(_fillcolorTOP), graphics_path);

graphics_path.Dispose();
}

public PointF[] GetLinePoints(PointF _p1, PointF _p2, int _stepWitdth)
{
int lCount = 0;
PointF[] _tmpPoints = new PointF[10001];
float _width = 0;
float _height = 0;
long d = 0;
long ix = 0;
long iy = 0;
int dd = 0;
int id = 0;
int lStep = _stepWitdth;

_p1.X = Convert.ToInt32(_p1.X);
_p1.Y = Convert.ToInt32(_p1.Y);
_p2.X = Convert.ToInt32(_p2.X);
_p2.Y = Convert.ToInt32(_p2.Y);
_width = _p2.X - _p1.X;
_height = _p2.Y - _p1.Y;
d = 0;

if (_width < 0)
{
_width = -_width;
ix = -1;
}
else
{
ix = 1;
}

if (_height < 0)
{
_height = -_height;
iy = -1;
}
else
{
iy = 1;
}

if (_width > _height)
{
dd = (int)(_width + _width);

上一页  1 2 3 4 5  下一页

Tags:实现 文字 指定

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接