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 83 84 85 86 87 88 89 90 91 92 93 94 95
| 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
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function IsTrueType(Font: TFont): Boolean;
var DC: HDC;
C : TBitmap;
Metrics: TTextMetric;
begin
C := TBitmap.create;
try
C.canvas.Font := Font;
DC := GetDC(0);
try
C.Canvas.Handle := DC;
C.Canvas.Font := Font;
GetTextMetrics(C.Canvas.Handle, Metrics );
Result := ( Metrics.tmPitchAndFamily and tmpf_TrueType ) = tmpf_TrueType;
C.Canvas.Handle := 0;
finally
ReleaseDC(0, DC);
end;
finally
C.Free;
end;
end;
function CreateRotatedFont(Font: TFont; Angle: Integer): HFont;
var
LogFont: TLogFont;
begin
If not IsTrueType(Font) then Font.Name:='Arial';
FillChar(LogFont, SizeOf(LogFont), 0);
with LogFont do begin
lfHeight := Font.Height;
lfWidth := 0;
lfEscapement := Angle * 10;
lfOrientation := 0;
if fsBold in Font.Style then lfWeight := FW_BOLD
else lfWeight := FW_NORMAL;
lfItalic := Ord(fsItalic in Font.Style);
lfUnderline := Ord(fsUnderline in Font.Style);
lfStrikeOut := Byte(fsStrikeOut in Font.Style);
lfCharSet := Byte(Font.Charset);
StrPCopy(lfFaceName, Font.Name);
lfQuality := DEFAULT_QUALITY;
lfOutPrecision := OUT_DEFAULT_PRECIS;
lfClipPrecision := CLIP_DEFAULT_PRECIS;
case Font.Pitch of
fpVariable: lfPitchAndFamily := VARIABLE_PITCH;
fpFixed: lfPitchAndFamily := FIXED_PITCH;
else lfPitchAndFamily := DEFAULT_PITCH;
end;
end;
Result := CreateFontIndirect(LogFont);
end;
procedure TexteAngle(AString: string;ACanvas:TCanvas;Font:TFont;x,y:integer;d:integer); //angle en degres
begin
ACanvas.Font:=Font;
with ACanvas do
begin
//Brush.Color:=Font.Color;
Font.Handle:=CreateRotatedFont(Font, d);
TextOut(X,Y,AString);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TexteAngle('Bonjour',Form1.Canvas,Form1.Font,100,100,45);
TexteAngle('Bonjour',Form1.Canvas,Form1.Font,100,100,180);
TexteAngle('Bonjour',Form1.Canvas,Form1.Font,100,100,-90);
end;
end. |
Partager