Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hDC = ctypes.windll.user32.GetDC(self.windowHandle)
- tempBMP = ctypes.windll.gdi32.CreateCompatibleBitmap(hDC, 1, 1)
- hBMP = ctypes.windll.gdi32.SelectObject(hDC, tempBMP)
- iFontSize = self.excelCellObject.Font.Size
- deviceCaps = ctypes.windll.gdi32.GetDeviceCaps(hDC, 90)
- iFontSize = int(iFontSize)
- iFontSize = ctypes.c_int(iFontSize)
- iFontSize = ctypes.windll.kernel32.MulDiv(iFontSize, deviceCaps, 72)
- iFontSize = iFontSize * -1
- iFontWeight = 700 if self.excelCellObject.Font.Bold else 400
- sFontName = self.excelCellObject.Font.Name
- sFontItalic = self.excelCellObject.Font.Italic
- sFontUnderline = True if self.excelCellObject.Font.Underline else False
- sFontStrikeThrough = self.excelCellObject.Font.Strikethrough
- hFont = ctypes.windll.gdi32.CreateFontW(iFontSize, 0, 0, 0, iFontWeight, sFontItalic, sFontUnderline, sFontStrikeThrough, False, False, False, False, False,sFontName) #Create a font object with the correct size, weight and style
- hOldFont = ctypes.windll.gdi32.SelectObject(hDC, hFont) #Load the font into the device context, storing the original font object
- sText = self.excelCellObject.Text
- log.io("nText t"+sText+"n")
- textLength = len(sText)
- class structText(ctypes.Structure):
- _fields_ = [("width", ctypes.c_int), ("height",ctypes.c_int)]
- StructText = structText()
- getTextExtentPoint = ctypes.windll.gdi32.GetTextExtentPoint32W
- getTextExtentPoint.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(structText)]
- getTextExtentPoint.restype = ctypes.c_int
- a = ctypes.windll.gdi32.GetTextExtentPoint32W(hDC, sText, textLength,ctypes.byref(StructText)) #Get the text dimensions
- a = ctypes.windll.gdi32.DeleteObject(hFont) #Delete the font object we created
- a = ctypes.windll.gdi32.DeleteObject(tempBMP)
- a = ctypes.windll.user32.ReleaseDC(self.windowHandle, hDC) #Release the device context
- textWidth = StructText.width
- cellWidth = self.excelCellObject.Width
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement