// 绘制虚线
{
ACvs 画布,起点X1, Y1,终点X2, Y2(单位:毫米)
M: 实线长 N:虚线长
H: 水平方向每英寸打印机的点数, V: 纵向方向每英寸打印机的光栅数
打印时可调用
H := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
V := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
}
procedure DrawVirtualLine(ACvs: TCanvas, X1, Y1, X2, Y2, M, N: Extended, H, V: Integer);
var
I, K: Integer;
ZL, YL: Extended;
procedure DrawLine(ACvs: TCanvas, X1, Y1, X2, Y2: Extended, H, V: Integer);
Const
InchTomm: Extended = 25.4;//1英寸=25.4毫米
begin
with ACvs do
begin
MoveTo(Round(X1 * H/InchTomm), Round(Y1 * V/InchTomm));
LineTo(Round(X2 * H/InchTomm), Round(Y2 * V/InchTomm));
end;
end;
begin
ZL := sqrt(Sqr(X2-X1) + Sqr(Y2-Y1));
K := Trunc(ZL/(M + N));
YL := ZL - K*(M + N);
for I := 0 to K - 1 do
begin
DrawLine(ACvs, X1 + I * ((X2 - X1) * M/ZL + (X2 - X1) * N/ZL),
Y1 + I * ((Y2 - Y1) * M/ZL + (Y2 - Y1) * N/ZL),
X1 + I * ((X2 - X1) * M/ZL + (X2 - X1) * N/ZL) + (X2 - X1) * M/ZL,
Y1 + I * ((Y2 - Y1) * M/ZL + (Y2 - Y1) * N/ZL) + (Y2 - Y1) * M/ZL
H, V);
end;
if YL < ((X2 - X1) * M/ZL) then
begin
DrawLine(ACvs, (X1 + K * ((X2 - X1) * M/ZL + (X2 - X1) * N/ZL)),
(Y1 + K * ((Y2 - Y1) * M/ZL + (Y2 - Y1) * N/ZL)),
(X1 + K * ((X2 - X1) * M/ZL + (X2 - X1) * N/ZL)) + (X2 - X1) * M/ZL,
(Y1 + K * ((Y2 - Y1) * M/ZL + (Y2 - Y1) * N/ZL)) + (Y2 - Y1) * M/ZL
H, V);
end
else
begin
DrawLine(ACvs, (X1 + K * ((X2 - X1) * M/ZL + (X2 - X1) * N/ZL)),
(Y1 + K * ((Y2 - Y1) * M/ZL + (Y2 - Y1) * N/ZL)), X2, Y2
H, V);
end;
end;
Delphi Canvas 绘制虚线
最新推荐文章于 2022-11-05 22:31:11 发布