vertical text not drawn at correct location

From: Ian (ibnospam_at_yahoo.com)
Date: 01/03/05


Date: Mon, 3 Jan 2005 00:49:51 -0500

The code below illustrates the problem I am having. A rectangle is drawn in
the center of the display. Text is suppose to be drawn at a 270 degree
angle and centered in the middle of the rectangle. Instead, the text is
always drawn to the far to the left of the rectangle. If I change text
escapement to 0 degrees then the text is correctly centered. Can someone
suggest what mistake I am making? Thanks in advance.

Ian

CMyView::OnDraw( CDC *pDC )
{
    // create font
    CFont oFont;
    LOGFONT oLF;
    memset( &oLF, 0, sizeof(oLF) );
    oLF.lfHeight = 25;
    oLF.lfOrientation = 2700; // 270 degrees
    oLF.lfEscapement = 2700;
    VERIFY( oFont.CreateFontIndirect( &oLF ) );
    CFont *pOldFont = pDC->SelectObject( &oFont );
    ASSERT( pOldFont );

    // set drawing rectangle
    CRect oCR;
    GetClientRect( &oCR );
    CRect oR(
        oCR.CenterPoint().x-30, oCR.top,
        oCR.CenterPoint().x+30, oCR.bottom
    );
    pDC->DPtoLP( &oR );

    // draw rectangle
    CBrush oBrush( RGB(0,0,0) );
    pDC->FrameRect( &oR, &oBrush );

    // draw text
    pDC->SetTextColor( RGB(0,0,0) );
    UINT uFormat = DT_SINGLELINE | DT_TOP | DT_CENTER | DT_NOCLIP;
    pDC->DrawTextEx( _T("sample text"), &oR, uFormat, NULL );

    // clean up
    pDC->SelectObject( pOldFont );
}



Relevant Pages

  • Re: Printing the whole whole printable area
    ... your rectangle are being drawn just outside of the printable area. ... need to inset the right and bottom by a pixel to get the line into the ... But at the very least, you need to understand that if you try to draw a rectangle that is the same exact width and height as what you believe to be the valid area for drawing, the right and bottom edges will not be drawn. ... For the record, the following code, when I use it with the Office Document Image Writer print driver, it prints a frame exactly the way you want: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Draw a path with a Pen which has a width of 2?
    ... For a circle or rectangle, your drawn area will be larger than the geometry ... > The border can also have different shapes such as Round, Circle, ... When I use a width of 2, the path is not drawn correctly. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: vertical text not drawn at correct location
    ... Your suggestions works in the sample code but not my ... Ian ... Text is suppose to be drawn at a 270 degree ... >> angle and centered in the middle of the rectangle. ...
    (microsoft.public.vc.mfc)
  • Re: How to Drawstring with a character drawn "partially"?
    ... Regarding drawing text character partially, I'm not too sure how to use the ... > You could draw the text without setting a layout rectangle, ... >> But I find that if a character cannot fit into the rectangle, ... >> character will not be drawn unless the size of the rectange increase, ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: DrawRectangle positioning
    ... The crux of the matter is this: ... account with regards to the size of the target rectangle. ... The entire line is drawn *outside* the rectangle. ...
    (microsoft.public.dotnet.languages.csharp)