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

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

 2012-08-28 13:18:15 来源:WEB开发网   
核心提示: 这个的难点在于排版的算法上,其他的就是对GDI+中GraphicsPath的应用,C#中实现文字按指定的路径排列,以下为核心部分的源代码:using System;using System.Collections;using System.Collections.Generic;using System.Data;u

 这个的难点在于排版的算法上,其他的就是对GDI+中GraphicsPath的应用。以下为核心部分的源代码:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace Lgms.net.Drawing
{
public enum PathAlign //文字在路径方向的对齐方向
{
Left = 0, //从第一点开始排列
Center = 1, //居中排列
Right = 2 //居右排列
}
public enum TextPosition //文字排列在路径上的位置
{
OverPath = 0, //路径之上
CenterPath = 1, //路径中间,文字中心即路径经过区域
UnderPath = 2 //路径下方
}

//基础类
public class TextOnPath
{
private PathData _pathdataTOP;
private string _textTOP;
private Font _fontTOP;
private Color _pathcolorTOP = Color.Red;
private Color _colorTOP = Color.Black;
private Color _fillcolorTOP = Color.Black;
private PathAlign _pathalignTOP = PathAlign.Center;
private int _letterspacepercentageTOP = 100;
private bool _addsvg = false;
private System.Text.StringBuilder _SVG;
private int _currentPathID;
private TextPosition _textPathPosition = TextPosition.CenterPath;
public Exception LastError = null;
public bool ShowPath = true;
public TextPosition TextPathPosition
{
get { return _textPathPosition; }
set { _textPathPosition = value; }
}
public PathData PathDataTOP
{
get { return _pathdataTOP; }
set { _pathdataTOP = value; }
}

public string TextTOP
{
get { return _textTOP; }
set { _textTOP = value; }
}


public Font FontTOP
{
get { return _fontTOP; }
set { _fontTOP = value; }
}


public Color PathColorTOP
{
get { return _pathcolorTOP; }
set { _pathcolorTOP = value; }
}
public Color ColorTOP
{
get { return _colorTOP; }
set { _colorTOP = value; }
}


public Color FillColorTOP
{
get { return _fillcolorTOP; }
set { _fillcolorTOP = value; }
}


public PathAlign PathAlignTOP
{
get { return _pathalignTOP; }
set { _pathalignTOP = value; }
}


public int LetterSpacePercentage
{
get { return _letterspacepercentageTOP; }
set { _letterspacepercentageTOP = value; }
}


public Bitmap TextOnPathBitmap(PathData _pathdata, string _text, Font _font, Color _color, Color _fillcolor, int _letterspacepercentage)
{
_pathdataTOP = _pathdata;
_textTOP = _text;
_fontTOP = new Font(_font, _fontTOP.Style);
_colorTOP = _color;
_fillcolorTOP = _fillcolor;
_letterspacepercentageTOP = _letterspacepercentage;
return TextOnPathBitmap();
}

//核心方法
public Bitmap TextOnPathBitmap()
{
int i = 0;
PointF[] _TmpPoints = null;
PointF _TmpPoint = default(PointF);
PointF[] _Points = new PointF[25001];
//= oGP.PathPoints()
int _count = 0;

1 2 3 4 5  下一页

Tags:实现 文字 指定

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