关于公章效果中文字旋转文字角度计算原理? ?

sncel 2005-11-25 09:40:10
我做的公章效果组件,最后一步了,怎么计算每个文字对着圆心的旋转角度

http://218.108.10.25/download/test.bmp

如能解决,发布组件源代码,谢谢.
...全文
491 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sncel 2005-11-26
  • 打赏
  • 举报
回复
请不要发表可能给我们带来伤害的言论,谢谢配合

发不了源码啊
sncel 2005-11-26
  • 打赏
  • 举报
回复
呵 呵。发 布 源 码,支 持 QuickReport 打 印 预 览 及 打 印。
sncel 2005-11-26
  • 打赏
  • 举报
回复
谢谢啊,不过你的文字位置没有我以前算的精确。
yanlls 2005-11-25
  • 打赏
  • 举报
回复
{18个字:360
9个字:180
0个字:0
}
//以下求角度 ,预定最多18个字
tempI:=100*(18-nJ+2*(nI-1));
//tempI:=100*(16-nJ+2*nI);
if tempI<2700 then
tempI:=2700-tempI
else
tempi:=6300-tempI;
//这个值就是角度
Nanc:=tempi-900;
sncel 2005-11-25
  • 打赏
  • 举报
回复
代码怎么都不加点注释啊,最关键部门不是很看的懂啊.
角度计算,用什么公式的.
wizardqi 2005-11-25
  • 打赏
  • 举报
回复
//看以下我写的代码能否满足楼主需求(可是原创呀!^_^)
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure MyTextOut(Ca:TCanvas;X,Y,Angle:Integer;Text:String);
var
lf : TLogFont;
begin
with Ca do
begin
GetObject(Font.Handle, sizeof(lf), @lf);
lf.lfEscapement := Angle*10;
Font.Handle := CreateFontIndirect(lf);
TextOut(X,Y,Text);
lf.lfEscapement := 0;
lf.lfOrientation := 0;
Font.Handle := CreateFontIndirect(lf);
end;
end;
procedure CircleText(Ca:TCanvas;X0,Y0,RX,RY,BeginAngle,EndAngle:Integer;Text:WideString);
const
aq=180/3.1415926;
qa=3.1415926/180;
procedure _CircleAlpha(Ca:TCanvas;X0,Y0,RX,RY,Angle:Integer;Alpha:WideChar);
var
x,y:Integer;
tw,th:Double;
begin
tw:=Ca.TextWidth(Alpha) / 2;
th:=Ca.TextWidth(Alpha) / 2;
x:=Round(Cos((Angle-90)*qa)*tw)+X0;
y:=Round(Sin((Angle-90)*qa)*tw)+Y0;
x:=Round(Cos(Angle*qa)*RX)+x;
y:=Round(Sin(Angle*qa)*RY)+y;
MyTextOut(Ca,x,y,270-Angle,Alpha);
end;
var
Angle,Step:Double;
n:Integer;
begin
Step:=(EndAngle-BeginAngle)/Length(Text);
Angle:=BeginAngle;
for n:=1 to Length(Text) do
begin
_CircleAlpha(Ca,X0,Y0,RX,RY,Round(Angle),Text[n]);
Angle:=Angle+Step;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Canvas.Font.Name:='宋体';
Canvas.Font.Color:=clBlue;
Canvas.Font.Size:=14;
CircleText(Canvas,200,200,150,150,150,390,'I am Wizardqi(男巫)!');
end;

end.
yanlls 2005-11-25
  • 打赏
  • 举报
回复
to 楼上
我的只有一个圆
aiirii 2005-11-25
  • 打赏
  • 举报
回复
image1.Canvas.Ellipse(50,20,170,140);
image1.Canvas.Ellipse(70,45,150,115);//加入这行
drawfive(110,80,20,image1.Canvas );
sncel 2005-11-25
  • 打赏
  • 举报
回复
好,我先试试,谢谢了.
yanlls 2005-11-25
  • 打赏
  • 举报
回复
给你一个:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure GetImage(sStr:string);
procedure GetLogFont(iAnc:integer;fCanvas:tCanvas);
procedure DrawFive(x,y,r:integer;fCanvas:tCanvas);
function GetPoint(nI:integer;nJ:integer;var NAnc:integer):Tpoint;

{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if self.Edit1.text='' then
exit
else
GetImage(edit1.Text);
end;

procedure Tform1.Getimage(sStr:String);
var
nX,nY,nZ:integer;
nPoint:Tpoint;
begin
nY:=length(widestring(sstr));
if ny>18 then ny:=18;

image1.Canvas.Pen.Width:=3;
image1.Canvas.Pen.Color:=clred;
image1.Canvas.Font.Color:=clred;
image1.Canvas.Font.Size:=10;

image1.Canvas.Ellipse(50,20,170,140);//110,80
drawfive(110,80,20,image1.Canvas );
for nx:=1 to ny do begin
npoint:=GetPoint(nx,ny,nz);
//image1.Canvas.Font.Style:=[fsBold];
getlogfont(nz,image1.Canvas);
image1.Canvas.TextOut(npoint.x,npoint.y,copy(widestring(sStr),nx,1));

end;
end;

procedure Tform1.GetLogFont(iAnc:integer;fCanvas:tCanvas);
var
FlogFont:LogFont;
begin
FillChar(FLogFont,Sizeof(TLogFont),0);//先填充一个数据结构
With FlogFont do
begin
lfHeight:=fCanvas.font.Height;
lfWidth:=0;
lfEscapement:=iAnc;
lforientation:=lfEscapement;
lfWeight:=Fw_Normal;
lfItalic:=0;
lfUnderline:=0;
lfStrikeOut:=0;
lfCharSet:=GB2312_CHARSET;
StrPCopy(lfFaceName,'宋体');
lfQuality:=PROOF_QUALITY;
lfOutPrecision:=OUT_TT_ONLY_PRECIS;
lfClipPrecision:=CLIP_DEFAULT_PRECIS;
lfPitchAndFamily:=Variable_Pitch;
end;
fCanvas.Font.Handle:=CreateFontIndirect(FLogFont);
end;
function Tform1.GetPoint(ni:integer;nj:integer;var Nanc:integer):Tpoint;
var
pPoint:Tpoint;
RAn:Extended;
tempI:integer;
begin
{18个字:360
9个字:180
0个字:0
}
tempI:=100*(16-nJ+2*nI);
if tempI<2700 then
tempI:=2700-tempI
else
tempi:=6300-tempI;

Nanc:=tempi-900;

ran:=pi*(tempi/1800);
pPoint.x:=110+round(55*cos(ran));
pPoint.Y:=80-round(55*sin(ran));
result:=pPoint;

end;
procedure Tform1.DrawFive(x,y,r:integer;fCanvas:tCanvas);
var
oldColor:Tcolor;
nX:integer;
nR:integer;
tempRgn:hrgn;
pPoint:Array[0..9] of Tpoint;
begin
for nx:=0 to 9 do begin
if (nx mod 2=0) then nR:=r else nR:=round(r*sin(pi/10)/sin(pi*126/180));
pPoint[nx].X:=x+round(nR*cos(pi*(nx/5+0.5)));
pPoint[nx].y:=y-round(nR*sin(pi*(nx/5+0.5)));
end;
oldcolor:=fcanvas.Brush.Color;
fcanvas.Brush.Color:=clred;

temprgn:=CreatePolygonRgn(ppoint[0],10,ALTERNATE);
FillRgn(fcanvas.Handle,temprgn,fcanvas.Brush.Handle);

fcanvas.Brush.Color:=oldcolor;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.Text:='测试程序有限公司';
end;

end.
wizardqi 2005-11-25
  • 打赏
  • 举报
回复
//相信我略加注释楼主必定茅塞顿开,呵呵
//我的思想是:首先求出每个字在给定中心给定角度的字中心,然后将每个字相对于字中心旋转给定角度即可;
x:=Round(Cos((Angle-90)*qa)*tw)+X0;
y:=Round(Sin((Angle-90)*qa)*tw)+Y0;//求出每个字在给定中心给定角度的字中心
x:=Round(Cos(Angle*qa)*RX)+x;
y:=Round(Sin(Angle*qa)*RY)+y;将每个字相对于字中心旋转给定角度
sncel 2005-11-25
  • 打赏
  • 举报
回复
wizardqi(男巫)

tw:=Ca.TextWidth(Alpha) / 2; //当间字符中心x,
th:=Ca.TextWidth(Alpha) / 2; //当间字符中心y,
x:=Round(Cos((Angle-90)*qa)*tw)+X0;
y:=Round(Sin((Angle-90)*qa)*tw)+Y0;
x:=Round(Cos(Angle*qa)*RX)+x;
y:=Round(Sin(Angle*qa)*RY)+y;

你能解释一下这个意思吗?

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧