Exemple #1
0
def _GetMinimumRect(text, font, usableRect, drawFlags):
    """Return the minimum rectangle that the text will fit into

    Uses font, usableRect and drawFlags information to find how
    how to do it accurately
    """

    # try to create the font
    # create a Display DC (compatible to the screen)
    txtDC = win32functions.CreateDC(u"DISPLAY", None, None, None)

    hFontGUI = win32functions.CreateFontIndirect(ctypes.byref(font))

    #    # Maybe we could not get the font or we got the system font
    #    if not hFontGUI:
    #
    #        # So just get the default system font
    #        hFontGUI = win32functions.GetStockObject(win32defines.DEFAULT_GUI_FONT)
    #
    #        # if we still don't have a font!
    #        # ----- ie, we're on an antiquated OS, like NT 3.51
    #        if not hFontGUI:
    #
    #            # ----- On Asian platforms, ANSI font won't show.
    #            if win32functions.GetSystemMetrics(win32defines.SM_DBCSENABLED):
    #                # ----- was...(SYSTEM_FONT)
    #                hFontGUI = win32functions.GetStockObject(
    #                    win32defines.SYSTEM_FONT)
    #            else:
    #                # ----- was...(SYSTEM_FONT)
    #                hFontGUI = win32functions.GetStockObject(
    #                    win32defines.ANSI_VAR_FONT)

    # put our font into the Device Context
    win32functions.SelectObject(txtDC, hFontGUI)

    modifiedRect = RECT(usableRect)
    # Now write the text to our DC with our font to get the
    # rectangle that the text needs to fit in
    win32functions.DrawText(
        txtDC,  # The DC
        unicode(text),  # The Title of the control
        -1,  # -1 because sTitle is NULL terminated
        ctypes.byref(modifiedRect),  # The Rectangle to be calculated to
        #truncCtrlData.drawTextFormat |
        win32defines.DT_CALCRECT | drawFlags)

    #elif modifiedRect.right == usableRect.right and \
    #	modifiedRect.bottom == usableRect.bottom:
    #	print "Oh so you thought you were perfect!!!"

    # Delete the font we created
    win32functions.DeleteObject(hFontGUI)

    # delete the Display context that we created
    win32functions.DeleteDC(txtDC)

    return modifiedRect
Exemple #2
0
def _draw_outline(region: Region):
    """Win32-based outline drawing for region."""
    brush_struct = win32structures.LOGBRUSH()
    brush_struct.lbStyle = win32defines.BS_NULL
    brush_struct.lbHatch = win32defines.HS_DIAGCROSS

    brush = win32functions.CreateBrushIndirect(ctypes.byref(brush_struct))
    pen = win32functions.CreatePen(win32defines.PS_SOLID, 2, 0x0000FF)
    dc = win32functions.CreateDC("DISPLAY", None, None, None)

    try:
        win32functions.SelectObject(dc, brush)
        win32functions.SelectObject(dc, pen)
        win32functions.Rectangle(dc, region.left, region.top, region.right,
                                 region.bottom)
    finally:
        win32functions.DeleteObject(brush)
        win32functions.DeleteObject(pen)
        win32functions.DeleteDC(dc)