Question and Answer Database FAQ166C.txt How to Rotate Fonts Category :VCL Platform :All Product :C++Builder 1.x Question: How to I make it so I display text on a angle? Answer: It may sound hard but actually it is quite easy. First step is to get the LOGFONT of the TCanvas you want to display the rotated text on. to do this use the Win API call: //CODE-------------------------------------------------------- LOGFONT lf; GetObject(Canvas->Font->Handle, /*(Handle of the TCanvas->Font->Handle*/ sizeof (LOGFONT), //size of LOGFONT &lf); //pointer to the LOGFONT //END CODE---------------------------------------------------- Next adjust some of the properties of the LOGFONT: //CODE-------------------------------------------------------- lf.lfEscapement = 450; //set to 450 to make 45 degree angle lf.lfOrientation = 450; lf.lfOutPrecision = OUT_TT_ONLY_PRECIS; //END CODE---------------------------------------------------- Now create a new Font and set the Canvas.Font to the new font //CODE-------------------------------------------------------- Canvas->Font->Handle = CreateFontIndirect (&lf); Canvas->Brush->Style = bsClear; //clear the canvas brush Canvas->TextOut (20, 120, "WOW!! Angled text!"); //Out a string //END CODE---------------------------------------------------- That is all there is to it. Following is all the code ready to be put in the OnPaint event of a form. //CODE-------------------------------------------------------- LOGFONT lf; GetObject(Canvas->Font->Handle, /*(Handle of the TCanvas->Font->Handle*/ sizeof (LOGFONT), //size of LOGFONT &lf); lf.lfEscapement = 450; //set to 450 to make 45 degree angle lf.lfOrientation = 450; lf.lfOutPrecision = OUT_TT_ONLY_PRECIS; Canvas->Font->Handle = CreateFontIndirect (&lf); Canvas->Brush->Style = bsClear; //clear the canvas brush Canvas->TextOut (20, 120, "WOW!! Angled text!"); //Out a string 7/2/98 10:32:32 AM
Last Modified: 01-SEP-99