Mega Code Archive

 
Categories / Delphi / Graphic
 

Drawing text angled on canvas

Title: Drawing text angled on canvas Question: With this piece of code you can draw angled on canvas Answer: // this proc draws a text angled on specified canvas procedure TextOutAngled(const Canvas: TCanvas; const X, Y: integer; const strText: string; intAngle, intFontSize: integer ); var objLogFont: TLogFont; fntSaveFont: TFont; begin // creates a new temp TFont object fntSaveFont := TFont.Create; fntSaveFont.Assign(Canvas.Font); // get the font "properties" GetObject(fntSaveFont.Handle, SizeOf(TLogFont), @objLogFont); with objLogFont do begin lfHeight := intFontSize * 2; lfEscapement := intAngle * 10; lfQuality := PROOF_QUALITY; lfPitchAndFamily := DEFAULT_PITCH or FF_DONTCARE; end; with Canvas do begin Font.Handle := CreateFontIndirect(objLogFont); SetBkMode(Handle, TRANSPARENT); TextOut(X, Y, strText); Font.Assign(fntSaveFont); end; // destroys the "save" font fntSaveFont.Free; end; {---------------------------------------------------------------------} Sample of use: TextOutAngled(Form1.Canvas, 200, 200, 'Sample of Angled Text', 10, 36);