终于找到你这个帖子了
代码来了,新鲜出炉阿,能满足你的一定要求,可以在封装我的函数,自己把两个点转换成我的函数里面的那几个参数,圆弧的圆心,圆弧的半径这些
pas文件
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
Panel1: TPanel;
PaintBox1: TPaintBox;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure DrawArcText(ACanvas: TCanvas; AText: string; ACenter, ARadius: TPoint; AAngle: Double);
var
LogFont: TLogFont;
Rads: Double;
I, X, Y: Integer;
begin
{
原理就是一个字一个字写,写玩一个换个角度再写
参数说明:
ACanvas : 不用解释了
AText : 不用说了
ACenter: 就是圆弧的中心
ARadius : 圆弧的半径大小,如果不明白就改几个值测试一些爱
AAgnle: 角度,是°为单位的,比如90°等,表示字符的起点,从原点的垂直半径距离开始算,逆时针偏移角度
不过字体是顺时针写的
}
if not Assigned(ACanvas) then Exit;
if AText = '' then Exit;
with ACanvas do begin
Rads := AAngle * Pi / 180;
SetTextAlign(ACanvas.Handle, ta_Center or ta_Baseline);
GetObject(ACanvas.Font.Handle, SizeOf(TLogFont), @LogFont);
for I := 1 to Length(AText) do begin
X := ACenter.X - Round((ARadius.X - TextHeight('Yy')) * Sin(Rads));
Y := ACenter.Y - Round((ARadius.Y - TextHeight('Yy')) * Cos(Rads));
LogFont.lfEscapement := Round(Rads * 1800 / Pi);
Font.Handle := CreateFontIndirect(LogFont);
Font.Color := clBlack; // 这里设置字体演示,可以抽到参数里面
TextOut(X, Y, AText);
Rads := Rads - (((TextWidth('w') + 2)) / ARadius.X);
end;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
I: Integer;
begin
//for I := 0 to 36000 do begin
DrawArcText(PaintBox1.Canvas, 'chenybin', Point(250, 150), Point(100, 100), 0); // I/100);
//sleep(50);
PaintBox1.Canvas.TextOut(250, 150, '原点');
PaintBox1.Canvas.TextOut(100, 100, 'X');//半径所在
//end;
end;
end.
dfm文件
object Form1: TForm1
Left = 198
Top = 151
Width = 513
Height = 356
BorderIcons = [biSystemMenu, biMinimize]
Caption = '演示旋转字体'
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
PixelsPerInch = 96
TextHeight = 12
object Panel1: TPanel
Left = 0
Top = 0
Width = 505
Height = 329
Align = alClient
BevelInner = bvRaised
Color = clWhite
TabOrder = 1
object PaintBox1: TPaintBox
Left = 2
Top = 2
Width = 501
Height = 325
Align = alClient
end
end
object BitBtn1: TBitBtn
Left = 392
Top = 20
Width = 75
Height = 25
Caption = 'BitBtn1'
TabOrder = 0
OnClick = BitBtn1Click
end
end