如何以坐标(0,0)为中心,(x,y)为起点到(x0,y0)结束,以弧度等状态显示文字? ( 积分: 100 )

  • 主题发起人 主题发起人 fslong
  • 开始时间 开始时间
F

fslong

Unregistered / Unconfirmed
GUEST, unregistred user!
如何以坐标(0,0)为中心,(x,y)为起点到(x0,y0)结束,以弧度等状态显示文字?
正如:我画一个图形,文字随图形的弧度显示.
100分
 
如何以坐标(0,0)为中心,(x,y)为起点到(x0,y0)结束,以弧度等状态显示文字?
正如:我画一个图形,文字随图形的弧度显示.
100分
 
终于找到你这个帖子了

代码来了,新鲜出炉阿,能满足你的一定要求,可以在封装我的函数,自己把两个点转换成我的函数里面的那几个参数,圆弧的圆心,圆弧的半径这些

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
 
看Windows Graphics Programming Win32 GDI and DirectDraw.chm
PathTextOut 按路径输出文字。
 
chenybin 大哥:
如果坐标起点(x,y),终点(x0,y0),以高(0,y1)而产生的弧度呢
 
用Path算法,晚上帮你弄,昨天晚上为了你另外哪个帖子奋斗到深夜阿,嘿嘿
 
好的,多谢!!!
 
chenybin 大哥:
我可以和你联系吗?因为我还有问题向你请教呢
 
我用中文时,显示出现乱码呢
 
中文问题把参数修改成widestring就没问题了

procedure DrawArcText(ACanvas: TCanvas; AText: [blue]widestring;[/blue] ACenter, ARadius: TPoint; AAngle: Double);
,Path的用法我现在也没有研究透,这几天空了继续看

不过楼主的要求我这个基本上可以实现,当然需要自己计算函数的参数,起点终点知道了,后面两个参数就可以求了,就是ACenter圆心和ARadius半径,然后是高度,高度可以采用设置ACanvas的Font属性中的大小来控制

你自己先计算圆心半径,这个算法到处可以找到,动动脑子,另外我研究path用法,如果搞定了再帮你看,
 
辛苦你了!先给你分.我还有问题是:
如果我任意调整弧度的其中一个文字,包括向上、下、左、右移动或旋转?

QQ:403019047
E_mail:wulongdong@tom.com
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
790
import
I
后退
顶部