Low-Level DigitalPaint: Drawing Text

Start with the project you created in Low-Level DigitalPaint: Filling an Area.

  1. Add the following item to the popup menu "Painting Test " that you added to the main menu:
    • &Painting
    • &Text
    • with ID = IDM_PAINTTEST_TEXT
  2. Add the following function before the OnOpen function definition:
    static L_VOID OnText ( HWND hWnd, pPAINTHANDLE pPaint ) 
    { 
       HDC hDC ; 
       PAINTTEXT text ; 
       RECT rcText ; 
       LOGFONTW 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.Scale.cx = 100 ; 
       text.TransformInfo.Scale.cy = 100 ; 
       text.TransformInfo.nRotate = 45 ; 
        
       // Set the new text properties 
       L_PntSetProperty ( pPaint, 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 
       L_PntApplyText ( pPaint, hDC, &rcText ) ; 
       // Delete the font object 
       DeleteObject ( hFont ) ; 
       // Release the device context 
       ReleaseDC ( hWnd, hDC ) ; 
    } 
  3. Add the following line after the "return 0L ;" of the "case IDM_PAINTTEST_FILL:" statement:

    case IDM_PAINTTEST_TEXT:   
           OnText ( hWnd, pPaint ) ;   
           return 0L ; 

  4. Compile and run the project by selecting Build->Execute tutorial.exe from the menu.

  5. Go to the "File" menu and use the "Open" item to open an image.
  6. Go to the "Painting Test" and select the "Text" item. This will draw a text using the current text group properties.
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Digital Paint C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.