s,rc,forat = DrawText(s, tuple , format )

Formats text in the given rectangle


s : string

The desired output string

tuple : (int, int, int, int)

The bounding rectangle in the form: (left, top, right, bottom) expressed in logical units (depending on selected coordinate system - see PyCDC::SetMapMode)

format : int

Specifies one or more bit-or'd format values, such as DT_BOTTOM, DT_CENTERDT_RIGHT, DT_VCENTER. For a complete list, see the Microsoft Win32 API documentation.



import win32ui<nl>

 import win32con<nl>

 INCH = 1440   # twips - 1440 per inch allows fine res<nl>

 def drawtext_test():<nl>

     dc = win32ui.CreateDC()<nl>

     dc.CreatePrinterDC()                # ties to default printer<nl>

     dc.StartDoc('My Python Document')<nl>



     # note: upper left is 0,0 with x increasing to the right,<nl>

     #       and y decreasing (negative) moving down<nl>



     # Centers "TEST" about an inch down on page<nl>

     dc.DrawText('TEST', (0,INCH*-1,INCH*8,INCH*-2), win32con.DT_CENTER )<nl>



     del dc<nl>

Return Value

Height of text in pixels

The return value is the height of the text, in logical units. If DT_VCENTER or DT_BOTTOM is specified, the return value is the offset from to the bottom of the drawn text. If the function fails, the return value is zero (no Python exception is thrown)