1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
procedure DrawLabel(AString: string;ACanvas:TCanvas;ARect: TRect; Alignment:TAlignment;ALayout:TTextLayout;Angle:boolean);
var
AHeight,AWidth:integer;
R:TRect;
H,W,WW,ATop,ALeft:Integer;
FontNewHeight:integer;
AText:string;
begin
ACanvas.Font:=Font;
with ACanvas do
begin
Brush.Color:=Font.Color;
FrameRect(ARect);
InflateRect(ARect,-1,-1);
AHeight:=ARect.Bottom-ARect.Top;
AWidth:=ARect.Right-ARect.Left;
AText:=AString;
WW:=TextSize(AText,Font).X;
if Angle then
begin
begin
FontNewHeight:=Ceil(Font.Height*AHeight/WW);
Font.Height:=FontNewHeight;
W:=TextSize(AString,Font).X;
H:=Round(TextSize(AString,Font).Y*1.5);
end;
if H>AWidth then
begin
FontNewHeight:=Ceil(Font.Height*AWidth/H);
Font.Height:=FontNewHeight;
W:=TextSize(AString,Font).X;
H:=TextSize(AString,Font).Y;
end;
end
else
begin
FontNewHeight:=Ceil(Font.Height*AWidth/WW);
Font.Height:=FontNewHeight;
W:=TextSize(AString,Font).X;
H:=TextSize(AString,Font).Y;
end;
if Angle then Font.Handle:=CreateRotatedFont(Font, 90); //<-- tu peux adapter ici, là ça écrira de bas en haut.
ATop:=ARect.Top;
ALeft:=ARect.Left;
if Angle then
begin
case ALayout of
tlBottom : ATop:=ARect.Bottom-W;
tlCenter : ATop:=ARect.Top+((AHeight-W) div 2);
tlTop : ATop:=ARect.Top;
end;
case Alignment of
taLeftJustify : ALeft:=ARect.Left;
taCenter : ALeft:=ARect.Left+(AWidth-H) div 2;
taRightJustify : ALeft:=ARect.Right-H;
end;
R := Bounds(ALeft,ATop,H,W);
end
else
begin
case ALayout of
tlBottom : ATop:=ARect.Bottom-H;
tlCenter : ATop:=ARect.Top+((AHeight-H) div 2);
tlTop : ATop:=ARect.Top;
end;
case Alignment of
taLeftJustify : ALeft:=ARect.Left;
taCenter : ALeft:=ARect.Left+(AWidth-W) div 2;
taRightJustify : ALeft:=ARect.Right-W;
end;
R := Bounds(ALeft,ATop,H,W);
end;
ACanvas.Brush.Color := Color;
if Angle
then TextOut(R.Left,R.Bottom,AString)
else TextOut(R.Left,R.Top,AString);
end;
end; |
Partager