I am trying to rotate a label using a function but it is not working. I only get a label without a rotation. The label should be rotated along the point (x, y) which is the middle position of the label (just=TX_JUST_CENTER). The counter-clockwise rotation angle (=theta) is given as degrees.
I would appreciate any help on this. Thanks.
void do_labely(
HDC meta_dc,
SLATE_REC *slate_rec,
const DEFAULT_STYLE *styl,
double x,
double y,
unsigned char *the_str,
short just,
short style_idx,
short size,
short stylebits,
short color,
short v_just,
BOOL clip,
double theta)
{
LOGFONT lf;
HFONT font;
UINT align;
setup_logfont(meta_dc ,&styl[ style_idx ], size, &lf, slate_rec, stylebits);
font = CreateFontIndirect( &lf );
GetObject(font, sizeof(lf), &lf);
SelectObject( meta_dc,font );
switch (color) {
case WHITE:
SetTextColor( meta_dc,RGB( 0xFF,0xFF,0xFF ) );
break;
case RED:
SetTextColor( meta_dc,RGB( 0xFF,0x00,0x00 ) );
break;
case GREEN:
SetTextColor( meta_dc,RGB( 0x00,0xFF,0x00 ) );
break;
case BLUE:
SetTextColor( meta_dc,RGB( 0x00,0x00,0xFF ) );
break;
case BLACK:
// this is the default
SetTextColor( meta_dc,RGB( 0x00,0x00,0x00 ) );
break;
}
switch (just) {
case TX_JUST_LEFT:
// this is the default
align = TA_LEFT;
break;
case TX_JUST_CENTER:
align = TA_CENTER;
break;
case TX_JUST_RIGHT:
align = TA_RIGHT;
break;
}
switch (v_just) {
case TX_JUST_TOP:
// this is the default
align += TA_TOP;
break;
case TX_JUST_BASE:
align += TA_BASELINE;
break;
case TX_JUST_BOTTOM:
align += TA_BOTTOM;
break;
}
SetTextAlign(meta_dc, align);
SetGraphicsMode(meta_dc, GM_ADVANCED);
double rad = theta * PI/180;
XFORM xform;
xform.eM11 = cos(rad);
xform.eM12 = -sin(rad);
xform.eM21 = sin(rad);
xform.eM22 = cos(rad);
//Apply rotation
ModifyWorldTransform(meta_dc, &xform, MWT_LEFTMULTIPLY);
//Draw the text
int x1 = (int)( x * slate_rec->xscale );
int y1 = (int)( y * slate_rec->yscale);
TextOut(meta_dc, x1, y1, (char *)the_str, strlen((char *)the_str));
//Reset the world transform to original
SetWorldTransform(meta_dc, &xform);
SelectObject( meta_dc,GetStockObject(SYSTEM_FONT) );
DeleteObject(font);
}