Available in LEADTOOLS Imaging Pro, Vector, Document, and Medical Imaging toolkits. |
Painting Text
The LEADTOOLS LRasterPaint class provides the following function for painting text:
This function requires:
an optional windows device context.
the bounding rectangle in which to paint the text.
This function will paint text based on the current text properties. To determine the current text properties, call LRasterPaint::GetProperty. To set or change the current text properties, call LRasterPaint::SetProperty. For more information on the text properties, refer to the PAINTTEXT structure.
Any transformation information should be set, using the LRasterPaint::SetTransformation function before calling any text or other painting function. To get the current transformation information, call LRasterPaint::GetTransformation.
The following example sets the text properties and paints some text. It assumes the DigitalPaint class object has been initialized and the window handle is valid:
HDC hDC ;
PAINTTEXT text ;
RECT rcText ;
LOGFONT lf ;
HFONT hFont ;
/* Get device context to draw on */
hDC = GetDC ( hWnd ) ;
/* Set the required text font properties */
lf.lfHeight = 48 ;
lf.lfWidth = 0 ;
lf.lfEscapement = 0 ;
lf.lfOrientation = 0 ;
lf.lfWeight = FW_NORMAL ;
lf.lfItalic = FALSE ;
lf.lfUnderline = FALSE ;
lf.lfStrikeOut = FALSE ;
lf.lfCharSet = ANSI_CHARSET ;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS ;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS ;
lf.lfQuality = DEFAULT_QUALITY ;
lf.lfPitchAndFamily = FF_DONTCARE ;
lstrcpy(lf.lfFaceName, TEXT("Times New Roman"));
/* Create the desired text font */
hFont = CreateFontIndirect ( &lf ) ;
/* Set the desired text properties */
text.nSize = sizeof ( PAINTTEXT ) ;
text.dwMask = PTF_TEXT | PTF_FONT | PTF_TRANSFORMINFO ;
text.pszText = TEXT("LEAD") ;
text.hFont = hFont ;
text.TransformInfo.nRotate = 45 ;
/* Set the new text properties */
// Assume Paint was constructed from LRasterPaint class
Paint.SetProperty ( PAINT_GROUP_TEXT, &text ) ;
/* Set the target text drawing box coordinates with respect to the DC dimensions */
SetRect ( &rcText, 10, 10, 200, 200 ) ;
/*Use the current text properties and the current transformations properties to draw the text to the DC */
Paint.ApplyText ( hDC, &rcText ) ;
/* Release the device context */
ReleaseDC ( hWnd, hDC ) ;