If someone needs something similar:
type
TRotateType = (rtNone, rtCounterClockWise, rtClockWise, rtFlip);
procedure DrawRotateText(Canvas: TCanvas; const R: TRect;
const Text: String; RotateType: TRotateType);
var
TextExtent: TSize;
SavedOrientation: Integer;
begin
SavedOrientation := Canvas.Font.Orientation;
TextExtent := Canvas.TextExtent(Text);
case RotateType of
rtNone:
begin
Canvas.Font.Orientation := 0;
Canvas.TextOut((R.Right - R.Left - TextExtent.cx) div 2,
(R.Bottom - R.Left - TextExtent.cy) div 2, Text);
end;
rtCounterClockWise:
begin
Canvas.Font.Orientation := 900;
Canvas.TextOut((R.Right - R.Left - TextExtent.cy) div 2,
(R.Bottom - R.Left + TextExtent.cx) div 2, Text);
end;
rtFlip:
begin
Canvas.Font.Orientation := 1800;
Canvas.TextOut((R.Right - R.Left + TextExtent.cx) div 2,
(R.Bottom - R.Left + TextExtent.cy) div 2, Text);
end;
rtClockWise:
begin
Canvas.Font.Orientation := -900;
Canvas.TextOut((R.Right - R.Left + TextExtent.cy) div 2,
(R.Bottom - R.Left - TextExtent.cx) div 2, Text);
end;
end;
Canvas.Font.Orientation := SavedOrientation;
end;
8 comments:
Ótima dica :)
Testei no Lazarus-0.9.28.2/FPC-2.2.4-3/Ubuntu-9.10 e funcionou primeira.
O blog esta show ;)
Valeu Silvio. Faltava testar no Linux. Você fez o serviço por mim...
Show de bola! Era o que faltava para mim! Essa dica logo vai estar no meu projeto :D
TSize is now in the Types unit
in my lazarus 0.9.29.
hi luiz
good code but it works correctly only for r.left=r.top=0
all TexOut calls should look like
Canvas.TextOut(
R.Left + (R.Right - R.Left - TextExtent.cx) div 2,
R.Top + (R.Bottom - R.Top - TextExtent.cy) div 2,
Text);
regards!
Great Post, I’ll be definitely coming back to your site. Keep the nice work up.
Affordable Logo Design
Post a Comment