Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. hDC = ctypes.windll.user32.GetDC(self.windowHandle)
  2. tempBMP = ctypes.windll.gdi32.CreateCompatibleBitmap(hDC, 1, 1)
  3. hBMP = ctypes.windll.gdi32.SelectObject(hDC, tempBMP)
  4. iFontSize = self.excelCellObject.Font.Size
  5. deviceCaps = ctypes.windll.gdi32.GetDeviceCaps(hDC, 90)
  6. iFontSize = int(iFontSize)
  7. iFontSize = ctypes.c_int(iFontSize)
  8. iFontSize = ctypes.windll.kernel32.MulDiv(iFontSize, deviceCaps, 72)
  9. iFontSize = iFontSize * -1
  10. iFontWeight = 700 if self.excelCellObject.Font.Bold else 400
  11.  
  12. sFontName = self.excelCellObject.Font.Name
  13. sFontItalic = self.excelCellObject.Font.Italic
  14. sFontUnderline = True if self.excelCellObject.Font.Underline else False
  15. sFontStrikeThrough = self.excelCellObject.Font.Strikethrough
  16. 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
  17. hOldFont = ctypes.windll.gdi32.SelectObject(hDC, hFont) #Load the font into the device context, storing the original font object
  18. sText = self.excelCellObject.Text
  19. log.io("nText t"+sText+"n")
  20. textLength = len(sText)
  21. class structText(ctypes.Structure):
  22. _fields_ = [("width", ctypes.c_int), ("height",ctypes.c_int)]
  23. StructText = structText()
  24. getTextExtentPoint = ctypes.windll.gdi32.GetTextExtentPoint32W
  25. getTextExtentPoint.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(structText)]
  26. getTextExtentPoint.restype = ctypes.c_int
  27. a = ctypes.windll.gdi32.GetTextExtentPoint32W(hDC, sText, textLength,ctypes.byref(StructText)) #Get the text dimensions
  28. a = ctypes.windll.gdi32.DeleteObject(hFont) #Delete the font object we created
  29. a = ctypes.windll.gdi32.DeleteObject(tempBMP)
  30. a = ctypes.windll.user32.ReleaseDC(self.windowHandle, hDC) #Release the device context
  31. textWidth = StructText.width
  32. cellWidth = self.excelCellObject.Width
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement