def wndProc(hWnd, message, wParam, lParam): global data if message == win32con.WM_PAINT: hdc, paintStruct = win32gui.BeginPaint(hWnd) dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0 fontSize = 80 # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx lf = win32gui.LOGFONT() lf.lfFaceName = "Times New Roman" lf.lfHeight = int(round(dpiScale * fontSize)) #lf.lfWeight = 150 # Use nonantialiased to remove the white edges around the text. # lf.lfQuality = win32con.NONANTIALIASED_QUALITY hf = win32gui.CreateFontIndirect(lf) win32gui.SelectObject(hdc, hf) rect = win32gui.GetClientRect(hWnd) # http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx if not loaded: win32gui.DrawText( hdc, 'Loading Neural Net...', -1, rect, win32con.DT_CENTER | win32con.DT_NOCLIP | win32con.DT_SINGLELINE | win32con.DT_VCENTER) color = win32api.RGB(0, 0, 255) color2 = win32api.RGB(255, 255, 0) brush = win32gui.CreateSolidBrush(color) fontSize = 12 lf = win32gui.LOGFONT() lf.lfFaceName = 'Times New Roman' lf.lfHeight = int(round(dpiScale * fontSize)) lf.lfQuality = win32con.NONANTIALIASED_QUALITY hf = win32gui.CreateFontIndirect(lf) win32gui.SelectObject(hdc, hf) win32gui.SetTextColor(hdc, color2) for minion in data: win32gui.DrawText( hdc, minion['class'] + ' ' + str(int(minion['score'] * 100)), -1, minion['location'], win32con.DT_BOTTOM | win32con.DT_SINGLELINE | win32con.DT_NOCLIP) win32gui.FrameRect(hdc, minion['location'], brush) win32gui.EndPaint(hWnd, paintStruct) return 0 elif message == win32con.WM_DESTROY: print('Closing the window.') win32gui.PostQuitMessage(0) return 0 else: return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
def wndProc(hWnd, message, wParam, lParam): if message == win32con.WM_PAINT: hdc, paintStruct = win32gui.BeginPaint(hWnd) dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0 fontSize = 18 lf = win32gui.LOGFONT() lf.lfFaceName = "Comic Sans" lf.lfHeight = int(round(dpiScale * fontSize)) hf = win32gui.CreateFontIndirect(lf) win32gui.SelectObject(hdc, hf) rect = win32gui.GetClientRect(hWnd) win32gui.DrawText( hdc, windowText, -1, rect, win32con.DT_LEFT | win32con.DT_BOTTOM | win32con.DT_SINGLELINE) win32gui.EndPaint(hWnd, paintStruct) return 0 elif message == win32con.WM_DESTROY: print('Being destroyed') win32gui.PostQuitMessage(0) return 0 else: return win32gui.DefWindowProc(hWnd, message, wParam, lParam) calrect = win32gui.DrawText(hdc, text, -1, rect, textformat | win32con.DT_CALCRECT) rect.top = rect.bottom - calcrect.bottom win32gui.DrawText(hDC, text, -1, rect, textformat)
def _win_update_metrics(self): dc = win_none.GetDC() dc.SelectObject(self._win_font) met = dc.GetTextMetrics() self._ascent = met['tmAscent'] self._descent = met['tmDescent'] self._internal_leading = met['tmInternalLeading'] self._leading = met['tmExternalLeading'] self._win_overhang = met['tmOverhang'] #print "Font: tmOverhang =", self._win_overhang ### logfont = gui.LOGFONT() logfont.lfHeight = win_height_sign * int(round(self._size)) logfont.lfWidth = wc.FW_BOLD if 'bold' in self._style else wc.FW_NORMAL logfont.lfEscapement = 0 logfont.lfOrientation = 0 logfont.lfWeight = 0 logfont.lfItalic = 1 if 'italic' in self._style else 0 logfont.lfUnderline = 1 if 'underline' in self._style else 0 logfont.lfStrikeOut = 1 if 'strikeout' in self._style else 0 logfont.lfCharSet = wc.DEFAULT_CHARSET logfont.lfOutPrecision = 0 logfont.lfClipPrecision = 0 logfont.lfQuality = wc.CLEARTYPE_QUALITY logfont.lfPitchAndFamily = 0 logfont.lfFaceName = self._win_family self._win_gdip_font = gdip.Font(self._win_family, self._size, self._style) #self._win_gdip_font = gdip.Font.from_logfont(dc.GetSafeHdc(), logfont) #self._win_gdip_font = gdip.Font.from_hdc(dc.GetSafeHdc()) win_none.ReleaseDC(dc)
def wndProc_edge(self, hWnd, message, wParam, lParam): if message == win32con.WM_PAINT: hdc, paintStruct = win32gui.BeginPaint(hWnd) dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0 fontSize = self.fontSize + 12 win32gui.SetTextColor(hdc, self.color_edge) # https://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx lf = win32gui.LOGFONT() lf.lfFaceName = "微軟正黑體" lf.lfHeight = int(round(dpiScale * fontSize)) lf.lfWeight = 700 # Use nonantialiased to remove the white edges around the text. lf.lfQuality = win32con.NONANTIALIASED_QUALITY hf = win32gui.CreateFontIndirect(lf) win32gui.SelectObject(hdc, hf) rect = win32gui.GetClientRect(hWnd) # https://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx win32gui.DrawTextW( hdc, self.text, -1, rect, win32con.DT_CENTER | win32con.DT_NOCLIP | win32con.DT_SINGLELINE | win32con.DT_VCENTER) win32gui.EndPaint(hWnd, paintStruct) return 0 elif message == win32con.WM_DESTROY: # print('Closing the window.') win32gui.PostQuitMessage(0) return 0 else: return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
def OnPaint(hwnd, msg, wp, lp): global dx font = win32gui.LOGFONT() font.lfFaceName = "Consolas" font.lfHeight = 48 # font.lfWidth=font.lfHeight # font.lfWeight=150 # font.lfItalic=1 # font.lfUnderline=1 hfont = win32gui.CreateFontIndirect(font) dc, ps = win32gui.BeginPaint(hwnd) win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED) l, t, r, b = win32gui.GetClientRect(hwnd) br = win32gui.CreateSolidBrush(win32api.RGB(0, 0, 255)) bitmap = win32gui.CreateBitmap(20, 5, 4, 1, None) win32gui.SelectObject(dc, bitmap) win32gui.SelectObject(dc, br) win32gui.SelectObject(dc, hfont) win32gui.SetTextColor( dc, win32api.RGB(randint(1, 255), randint(1, 255), randint(1, 255))) win32gui.DrawText(dc, 'hello', -1, (100, 100, 300, 300), 0) win32gui.FillRect(dc, (200 + dx, 200 + dx, 100 + dx, 100 + dx), br) dx = (dx + 10) % 100 win32gui.EndPaint(hwnd, ps) return 0
def _win_message(self, hWnd, message, wParam, lParam): if message == win32_contants.WM_PAINT: device_context_handle, paintStruct = win32gui.BeginPaint(hWnd) dpiScale = ctypes.windll.gdi32.GetDeviceCaps( device_context_handle, win32_contants.LOGPIXELSX) / 60.0 fontSize = 14 # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx lf = win32gui.LOGFONT() lf.lfFaceName = "Times New Roman" # lf.lfHeight = int(round(dpiScale * fontSize)) lf.lfHeight = 20 lf.lfWeight = 0 # Use nonantialiased to remove the white edges around the text. lf.lfQuality = win32con.NONANTIALIASED_QUALITY hf = win32gui.CreateFontIndirect(lf) win32gui.SetTextColor(device_context_handle, win32_color(self.font_color)) win32gui.SelectObject(device_context_handle, hf) self._draw(device_context_handle) win32gui.EndPaint(hWnd, paintStruct) return 0 elif message == win32_contants.WM_DESTROY: win32gui.PostQuitMessage(0) return 0 else: return ctypes.windll.user32.DefWindowProcW(hWnd, message, wParam, lParam)
def deploy(fontPath, ttfInstance=None): # setup fontName = ''.join(random.choice(string.digits) for i in range(0, 6)) #shortName(ttfInstance)[1] lf = win32gui.LOGFONT() number_of_font_added = windll.gdi32.AddFontResourceExA( fontPath, FR_PRIVATE, None) assert number_of_font_added == 1, 'Font not added' # TODO: what happens when a font is not added? win = mainWindow() hwnd = win.CreateWindow() hdc = windll.user32.GetDC(hwnd) # draw some crap chars_not_rendered = 0 chars_rendered = 0 for j in range(10, 100, 10): time.sleep(.1) lf.lfHeight = j #int(random.choice(string.digits)) lf.lfFaceName = fontName lf.lfWidth = j #int(random.choice(string.digits)) lf.lfEscapement = 0 lf.lfOrientation = 0 lf.lfWeight = FW_NORMAL lf.lfItalic = False lf.lfUnderline = False lf.lfStrikeOut = False lf.lfCharSet = DEFAULT_CHARSET lf.lfOutPrecision = OUT_DEFAULT_PRECIS lf.lfClipPrecision = CLIP_DEFAULT_PRECIS lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE hFont = win32gui.CreateFontIndirect(lf) oldFt = win32gui.SelectObject(hdc, hFont) # replace font #print '[*]', lf.lfFaceName, ':', lf.lfWidth, ' - ', lf.lfHeight # chars to draw char_map = [chr(i) for i in range(1, 255)] chars_rendered_current, chars_not_rendered_current = draw( hdc, char_map) chars_rendered += chars_rendered_current chars_not_rendered += chars_not_rendered_current windll.gdi32.DeleteObject(win32gui.SelectObject(hdc, oldFt)) windll.gdi32.GdiFlush() windll.gdi32.RemoveFontResourceExW(fontPath, FR_PRIVATE, None) print '[*]\t{} chars not rendered'.format(chars_not_rendered) print '[*]\t{} chars rendered'.format(chars_rendered) # bail windll.user32.ReleaseDC(hwnd, hdc) windll.user32.DestroyWindow(hwnd) print '[*] Destroy window' time.sleep(1)
def _build_font(self, font: (dict, tuple), dpi_scale: float) -> int: """Build a font from the given font options""" family, size, bold, italics = self._font_dict_to_tuple(font) font = gui.LOGFONT() if family != "default": font.lfFaceName = family font.lfHeight = int(round(dpi_scale * size)) font.lfQuality = con.NONANTIALIASED_QUALITY font.lfWeight = 900 if bold else 400 font.lfItalic = italics return gui.CreateFontIndirect(font)
def init_font(self, hdc, paintStruct): # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx lf = win32gui.LOGFONT() lf.lfFaceName = "InputMono" fontSize = 36 dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0 lf.lfHeight = int(round(dpiScale * fontSize)) # lf.lfWeight = 150 # Use nonantialiased to remove the white edges around the text. # lf.lfQuality = win32con.NONANTIALIASED_QUALITY lf.lfQuality = win32con.NONANTIALIASED_QUALITY self.font = win32gui.CreateFontIndirect(lf)
def fuzz(self): logger.info('Start fuzzing: ' + self.filepath) self.ttffont = ttLib.TTFont(self.filepath) self.fontname = font_util.shortName(self.ttffont)[1] self.logfont = win32gui.LOGFONT() self.htr = windll.gdi32.AddFontResourceExA(self.filepath, FR_PRIVATE, None) self.hwin = fuzzer_window() self.hwnd = self.hwin.CreateWindow() self.hdc = windll.user32.GetDC(self.hwnd) logger.info('Create font') self.logfont.lfHeight = 20 self.logfont.lfFaceName = self.fontname self.logfont.lfWidth = 0 self.logfont.lfEscapement = 0 self.logfont.lfOrientation = 0 self.logfont.lfWeight = FW_NORMAL self.logfont.lfItalic = False self.logfont.lfUnderline = False self.logfont.lfStrikeOut = False self.logfont.lfCharSet = DEFAULT_CHARSET self.logfont.lfOutPrecision = OUT_DEFAULT_PRECIS self.logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS self.logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE self.hfont = win32gui.CreateFontIndirect(self.logfont) self.oldfont = win32gui.SelectObject(self.hdc, self.hfont) ETO_GLYPH_INDEX = 16 text = "luffy" windll.gdi32.TextOutA(self.hdc, 5, 5, text, len(text)) windll.gdi32.DeleteObject(win32gui.SelectObject( self.hdc, self.oldfont)) windll.gdi32.GdiFlush() windll.gdi32.RemoveFontResourceExW(self.filepath, FR_PRIVATE, None) time.sleep(1) windll.user32.ReleaseDC(self.hwnd, self.hdc) windll.user32.DestroyWindow(self.hwnd) logger.info('End fuzzing: ' + self.filepath)
def debugRender(hWnd, hdc, paintStruct): dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0 fontSize = 12 # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx lf = win32gui.LOGFONT() lf.lfFaceName = "Arial" lf.lfHeight = int(round(dpiScale * fontSize)) #lf.lfWeight = 150 # Use nonantialiased to remove the white edges around the text. lf.lfQuality = win32con.NONANTIALIASED_QUALITY hf = win32gui.CreateFontIndirect(lf) win32gui.SelectObject(hdc, hf) rect = win32gui.GetClientRect(hWnd) logging.debug(rect) # http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx win32gui.DrawText( hdc, 'Text on the screen', -1, rect, win32con.DT_CENTER | win32con.DT_NOCLIP | win32con.DT_SINGLELINE | win32con.DT_VCENTER)
def selectFont(self, dc, style=None, scale=64): if style == None: style = self.style font = win32gui.LOGFONT() font.lfHeight = style.fontsize * scale if style.bold: font.lfWeight = win32con.FW_BOLD else: font.lfWeight = win32con.FW_NORMAL font.lfItalic = style.italic font.lfUnderline = style.underline font.lfStrikeOut = style.strikeout font.lfCharSet = style.encoding font.lfOutPrecision = win32con.OUT_TT_PRECIS font.lfClipPrecision = win32con.CLIP_DEFAULT_PRECIS font.lfQuality = win32con.ANTIALIASED_QUALITY font.lfPitchAndFamily = win32con.DEFAULT_PITCH | win32con.FF_DONTCARE font.lfFaceName = style.fontname[:32] font = win32gui.CreateFontIndirect(font) win32gui.SelectObject(dc, font) pass
def wndProc(hWnd, message, wParam, lParam): if message == win32con.WM_PAINT: hdc, paintStruct = win32gui.BeginPaint(hWnd) print 'windProc' dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0 fontSize = 80 lf = win32gui.LOGFONT() lf.lfFaceName = "Times New Roman" lf.lfHeight = int(round(dpiScale * fontSize)) hf = win32gui.CreateFontIndirect(lf) win32gui.SelectObject(hdc, hf) rect = win32gui.GetClientRect(hWnd) win32gui.DrawText( hdc, 'O', -1, rect, win32con.DT_CENTER | win32con.DT_NOCLIP | win32con.DT_SINGLELINE | win32con.DT_VCENTER) win32gui.EndPaint(hWnd, paintStruct) return 0 elif message == win32con.WM_DESTROY: print 'Closing the window.' win32gui.PostQuitMessage(0) return 0 else: return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
def deploy(fontPath, ttfInstance=None): # setup fontName = shortNameMine(fontPath)[ 1] #''.join( random.choice(string.digits) for i in range(0,6) ) lf = win32gui.LOGFONT() number_of_font_added = windll.gdi32.AddFontResourceExA(fontPath, 0, None) if number_of_font_added != 1: print "[WTF] Clusterfuck: invalid font" return 0, 0 win = mainWindow() hwnd = win.CreateWindow() hdc = windll.user32.GetDC(hwnd) # draw some crap chars_not_rendered = 0 chars_rendered = 0 for j in range(10, 50, 1): time.sleep(.1) lf.lfHeight = j #int(random.choice(string.digits)) lf.lfFaceName = fontName # todo: http://www.undocprint.org/winspool/getfontresourceinfo lf.lfWidth = j #int(random.choice(string.digits)) lf.lfEscapement = 0 lf.lfOrientation = 0 lf.lfWeight = FW_NORMAL lf.lfItalic = False lf.lfUnderline = False lf.lfStrikeOut = False lf.lfCharSet = DEFAULT_CHARSET lf.lfOutPrecision = OUT_DEFAULT_PRECIS lf.lfClipPrecision = CLIP_DEFAULT_PRECIS lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE hFont = win32gui.CreateFontIndirect(lf) oldFt = win32gui.SelectObject(hdc, hFont) # replace font #print '[*]', lf.lfFaceName, ':', lf.lfWidth, ' - ', lf.lfHeight # chars to draw char_map = [chr(i) for i in range(1, 255)] chars_rendered_current, chars_not_rendered_current = draw( hdc, char_map) chars_rendered += chars_rendered_current chars_not_rendered += chars_not_rendered_current windll.gdi32.DeleteObject(win32gui.SelectObject(hdc, oldFt)) windll.gdi32.GdiFlush() windll.gdi32.RemoveFontResourceExW(fontPath, 0, None) print '[*]\t{} chars not rendered'.format(chars_not_rendered) print '[*]\t{} chars rendered'.format(chars_rendered) # bail releaseResult = windll.user32.ReleaseDC(hwnd, hdc) if releaseResult == 0: print '[E] ReleaseDc failed' destroyResult = windll.user32.DestroyWindow(hwnd) if destroyResult == 0: print '[E] Destroy Window error {}'.format(GetLastError()) print '[*] Destroy window' return chars_rendered, chars_not_rendered
win32gui.SelectObject(dcDC, dcBM) win32gui.StretchBlt(dcDC, 0, 0, desktopwidth, desktopheight, dDC, 0, 0, desktopwidth, desktopheight, win32con.SRCCOPY) pcDC = win32gui.CreateCompatibleDC(pDC) pcBM = win32gui.CreateCompatibleBitmap(pDC, printerwidth, printerheight) win32gui.SelectObject(pcDC, pcBM) win32gui.StretchBlt(pcDC, 0, 0, printerwidth, printerheight, dcDC, 0, 0, desktopwidth, desktopheight, win32con.SRCCOPY) win32print.StartDoc(pDC, ('desktop.bmp', None, None, 0)) win32print.StartPage(pDC) win32gui.StretchBlt(pDC, 0, 0, int(printerwidth * .9), int(printerheight * .9), pcDC, 0, 0, printerwidth, printerheight, win32con.SRCCOPY) font = win32gui.LOGFONT() font.lfHeight = int(printerheight / 20) font.lfWidth = font.lfHeight font.lfWeight = 150 font.lfItalic = 1 font.lfUnderline = 1 hf = win32gui.CreateFontIndirect(font) win32gui.SelectObject(pDC, hf) win32gui.SetBkMode(pDC, win32con.TRANSPARENT) win32gui.SetTextColor(pDC, win32api.RGB(0, 255, 0)) win32gui.DrawText( pDC, 'Printed by Python!', -1, (0, 0, int(printerwidth * .9), int(printerheight * .9)), win32con.DT_RIGHT | win32con.DT_BOTTOM | win32con.DT_SINGLELINE) win32print.EndPage(pDC) win32print.EndDoc(pDC)
def wnd_proc(h_wnd, message, w_param, l_param): """Displays a transparent window with some graphic elements Displays a transparent window with some graphic elements :param h_wnd: an input argument :returns: nothing """ if message == win32con.WM_QUIT: # print("Closing the window overlay") win32gui.PostQuitMessage(0) return 0 if message == win32con.WM_PAINT: hdc, paint_struct = win32gui.BeginPaint(h_wnd) win32gui.SetGraphicsMode(hdc, win32con.GM_ADVANCED) win32gui.BringWindowToTop(h_wnd) for r in self.graphical_elements: if 'geometry' in r: geometry = r['geometry'] else: geometry = None if 'x' in r: x = r['x'] - self.x_min else: x = 0 if 'y' in r: y = r['y'] - self.y_min else: y = 0 if 'width' in r: width = r['width'] else: width = 100 if 'height' in r: height = r['height'] else: height = 100 if 'xyrgb_array' in r: xyrgb_array = r['xyrgb_array'] else: xyrgb_array = ((15, 15, 255, 0, 0), (15, 45, 0, 255, 0), (45, 30, 0, 0, 255)) if 'color' in r: color_r = r['color'][0] color_g = r['color'][1] color_b = r['color'][2] else: color_r = 255 color_g = 0 color_b = 0 if 'thickness' in r: thickness = r['thickness'] else: thickness = 0 if 'angle' in r: angle = r['angle'] else: angle = 0 if 'geometry' in r and r['geometry'] is Shape.triangle: vertices = () for xyrgb in xyrgb_array: vertices = vertices + ( { 'x': int(round(xyrgb[0])) - self.x_min, 'y': int(round(xyrgb[1])) - self.y_min, 'Red': xyrgb[2] * 256, 'Green': xyrgb[3] * 256, 'Blue': xyrgb[4] * 256, 'Alpha': 0 }, ) mesh = ((0, 1, 2), ) win32gui.GradientFill(hdc, vertices, mesh, win32con.GRADIENT_FILL_TRIANGLE) if 'brush_color' in r: brush_color_r = r['brush_color'][0] brush_color_g = r['brush_color'][1] brush_color_b = r['brush_color'][2] else: brush_color_r = 255 brush_color_g = 255 brush_color_b = 255 if thickness == 0: color_r = brush_color_r color_g = brush_color_g color_b = brush_color_b if 'font_size' in r: font_size = r['font_size'] else: font_size = 18 if 'font_name' in r: font_name = r['font_name'] else: font_name = "Arial" my_brush = None if 'brush' in r and width > 1 and height > 1: brush = r['brush'] brush_color = win32api.RGB(brush_color_r, brush_color_g, brush_color_b) if brush is Brush.solid: my_brush = win32gui.CreateSolidBrush(brush_color) elif brush is Brush.b_diagonal: my_brush = win32gui.CreateHatchBrush( win32con.HS_BDIAGONAL, brush_color) elif brush is Brush.cross: my_brush = win32gui.CreateHatchBrush( win32con.HS_CROSS, brush_color) elif brush is Brush.diag_cross: my_brush = win32gui.CreateHatchBrush( win32con.HS_DIAGCROSS, brush_color) elif brush is Brush.f_diagonal: my_brush = win32gui.CreateHatchBrush( win32con.HS_FDIAGONAL, brush_color) elif brush is Brush.horizontal: my_brush = win32gui.CreateHatchBrush( win32con.HS_HORIZONTAL, brush_color) elif brush is Brush.vertical: my_brush = win32gui.CreateHatchBrush( win32con.HS_VERTICAL, brush_color) old_brush = win32gui.SelectObject(hdc, my_brush) pen = win32gui.CreatePen( win32con.PS_GEOMETRIC, thickness, win32api.RGB(color_r, color_g, color_b)) old_pen = win32gui.SelectObject(hdc, pen) if 'center_of_rotation' in r: center_of_rotation_x = r['center_of_rotation'][0] center_of_rotation_y = r['center_of_rotation'][1] else: center_of_rotation_x = 0 center_of_rotation_y = 0 if angle != 0: r_angle = angle * (math.pi / 180) Py_XFORM = win32gui.GetWorldTransform(hdc) win32gui.SetWorldTransform( hdc, { 'M11': math.cos(r_angle), 'M12': math.sin(r_angle), 'M21': math.sin(r_angle) * -1, 'M22': math.cos(r_angle), 'Dx': x, 'Dy': y }) x, y = -center_of_rotation_x, -center_of_rotation_y if 'text_format' in r: text_format = eval(r['text_format']) else: text_format = win32con.DT_CENTER | win32con.DT_SINGLELINE | win32con.DT_VCENTER if 'geometry' in r: if r['geometry'] is Shape.rectangle: win32gui.Rectangle(hdc, int(round(x)), int(round(y)), int(round(x + width)), int(round(y + height))) elif r['geometry'] is Shape.ellipse: win32gui.Ellipse(hdc, int(round(x)), int(round(y)), int(round(x + width)), int(round(y + height))) elif r['geometry'] is Shape.arrow: a = thickness t = ((x - int(a * 1.4), y), (x - a * 4, y + a * 3), (x, y), (x - a * 4, y - a * 3), (x - int(a * 1.4), y), (x - a * 9, y)) win32gui.Polyline(hdc, t) elif r['geometry'] is Shape.image: hicon = r['hicon'] win32gui.DrawIconEx(hdc, x, y, hicon, 0, 0, 0, None, 0x0003) elif r['geometry'] is Shape.triangle and thickness > 0: t = () for xyrgb in xyrgb_array: t = t + ((int(round( xyrgb[0])), +int(round(xyrgb[1]))), ) t = t + ((int(round(xyrgb_array[0][0])), int(round(xyrgb_array[0][1]))), ) win32gui.Polyline(hdc, t) if angle != 0: win32gui.SetWorldTransform(hdc, Py_XFORM) win32gui.SelectObject(hdc, old_pen) if 'brush' in r and width > 1 and height > 1: win32gui.SelectObject(hdc, old_brush) if 'text' in r: text = r['text'] lf = win32gui.LOGFONT() lf.lfFaceName = font_name lf.lfHeight = font_size lf.lfWeight = win32con.FW_NORMAL lf.lfQuality = win32con.ANTIALIASED_QUALITY hf = win32gui.CreateFontIndirect(lf) old_font = win32gui.SelectObject(hdc, hf) if 'text_color' in r: text_color_r = r['text_color'][0] text_color_g = r['text_color'][1] text_color_b = r['text_color'][2] else: text_color_r = 0 text_color_g = 0 text_color_b = 0 win32gui.SetTextColor( hdc, win32api.RGB(text_color_r, text_color_g, text_color_b)) if 'text_bg_color' in r: text_bg_color_r = r['text_bg_color'][0] text_bg_color_g = r['text_bg_color'][1] text_bg_color_b = r['text_bg_color'][2] else: text_bg_color_r = brush_color_r text_bg_color_g = brush_color_g text_bg_color_b = brush_color_b win32gui.SetBkMode(hdc, win32con.TRANSPARENT) win32gui.SetBkColor( hdc, win32api.RGB(text_bg_color_r, text_bg_color_g, text_bg_color_b)) tuple_r = tuple([ int(round(x)), int(round(y)), int(round(x + width)), int(round(y + height)) ]) win32gui.DrawTextW(hdc, text, -1, tuple_r, text_format) win32gui.SelectObject(hdc, old_font) win32gui.EndPaint(h_wnd, paint_struct) return 0 else: return win32gui.DefWindowProc(h_wnd, message, w_param, l_param)
def __init__(self, printerName=None, spoolFile=None, lpi=6, fontName="Courier New", fontWeights=None, jobName="Win32PrinterDocument", **kw): TextPrinter.__init__(self, pageSize=A4, **kw) self.lpi = None self.line = "" self.leading = 0 self.maxLeading = 0 self.logfont = win32gui.LOGFONT() # 20070414 : self.weight_bold = win32con.FW_BOLD self.weight_normal = win32con.FW_NORMAL if fontWeights is not None: if len(fontWeights) != 2: raise TypeError("len(fontWeights) must be 2") for i in fontWeights: if type(i) != int: raise TypeError("%r : not an integer" % i) # bolder than normal because Courier.ttf isn't dark enough self.weight_normal = fontWeights[0] # win32con.FW_SEMIBOLD self.weight_bold = fontWeights[1] # win32con.FW_EXTRABOLD """ lfHeight lfWidth lfEscapement lfOrientation lfWeight lfItalic lfUnderline lfStrikeOut lfCharSet lfOutPrecision lfClipPrecision lfQuality lfPitchAndFamily Specifies the pitch and family of the font. The two low-order bits specify the pitch of the font and can be one of the following values: * DEFAULT_PITCH * FIXED_PITCH * VARIABLE_PITCH The four high-order bits specify the font family and can be one of the following values. Value Description FF_DECORATIVE Novelty fonts. Old English is an example. FF_DONTCARE Use default font. FF_MODERN Fonts with constant stroke width, with or without serifs. Pica, Elite, and Courier New are examples. FF_ROMAN Fonts with variable stroke width and with serifs. MS Serif is an example. FF_SCRIPT Fonts designed to look like handwriting. Script and Cursive are examples. FF_SWISS Fonts with variable stroke width and without serifs. MS Sans Serif is an example. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_8fp0.asp lfFaceName """ self.logfont.lfPitchAndFamily = win32con.FIXED_PITCH if fontName is not None: self.logfont.lfFaceName = fontName self.logfont.lfCharSet = win32con.OEM_CHARSET #self.logfont.lfCharSet=win32con.DEFAULT_CHARSET #self.logfont.lfCharSet=win32con.ANSI_CHARSET #self.logfont.lfCharSet=win32con.GB2312_CHARSET #self.logfont.lfCharSet=win32con.BALTIC_CHARSET #self.logfont.lfCharSet=win32con.HEBREW_CHARSET #self.logfont.lfCharSet=win32con.ARABIC_CHARSET #self.logfont.lfCharSet=win32con.SYMBOL_CHARSET self.logfont.lfWeight = self.weight_normal self.setCpi(self.cpi) ## self.fontDict = dict( ## name=fontName, ## #pitchAndFamily ## #orientation=50 ## ) ## try: ## self.fontDict['charset'] = charsets[encoding] ## except KeyError,e: ## self.debug("No charset defined for %s encoding",encoding) ## self.fontDict['charset'] = win32con.OEM_CHARSET #self.font = None #self.useWorldTransform=useWorldTransform self.spoolFile = spoolFile self.jobName = jobName #self.fontName=fontName if printerName is None: printerName = win32print.GetDefaultPrinter() self.printerName = printerName
def wndProc(self, hWnd, message, wParam, lParam): if message == win32con.WM_PAINT: hdc, paintStruct = win32gui.BeginPaint(hWnd) # Font configuration dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0 fontSize = 10 # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx lf = win32gui.LOGFONT() lf.lfFaceName = "Tahoma" lf.lfHeight = int(round(dpiScale * fontSize)) lf.lfWeight = 700 # bold lf.lfQuality = win32con.NONANTIALIASED_QUALITY # Use nonantialiased to remove the white edges around the text. hf = win32gui.CreateFontIndirect(lf) win32gui.SelectObject(hdc, hf) br = win32gui.CreateSolidBrush(win32api.RGB(255, 0, 0)) win32gui.SelectObject(hdc, br) # Update positions self.updatePositions() # Bars # Positions the bars if self.mounted: xc = self.axcm yc = self.aycm else: xc = self.axc yc = self.ayc r = self.aradius dr = self.awidth alpha = self.aangle #print(xc,yc) ## Text # Positions the text pleft = self.tleft ptop = self.ttop pright = self.tright pbottom = self.tbottom spc = self.tspc #print(pleft,ptop,pright,pbottom) if self.setup: sr = alpha rr = r for _ in range(2): sr, rr = self.drawRightArc(hdc, (xc, yc), rr, dr, sr, 1.0, ColorCode.ORANGE) sl = alpha rl = r for _ in range(2): sl, rl = self.drawLeftArc(hdc, (xc, yc), rl, dr, sl, 1.0, ColorCode.ORANGE) for i in range(50): pos = (pleft, ptop + i * spc, pright, pbottom) self.drawTextLabel(hdc, pos, ColorCode.ORANGE, 'ExampleText') self.drawTimerLabel(hdc, pos, ColorCode.ORANGE, float(i)) else: idx = 0 sr = alpha rr = r for idx, action in enumerate(self.rightArcToDraw): sr, rr = self.drawRightArc(hdc, (xc, yc), rr, dr, sr, action.getPercentage(), action.color) sl = alpha rl = r for idx, action in enumerate(self.leftArcToDraw): sl, rl = self.drawLeftArc(hdc, (xc, yc), rl, dr, sl, action.getPercentage(), action.color) for idx, group in enumerate(self.groupsToDraw): pos = (pleft, ptop + idx * spc, pright, pbottom) self.drawTextLabel(hdc, pos, group.color, group.labelText) self.drawTimerLabel(hdc, pos, group.color, group.countdown) k = idx + 2 for idx, action in enumerate(self.actionsToDraw): if (idx + 1) in self.emptyLines: k = k + 1 pos = (pleft, ptop + (idx + k) * spc, pright, pbottom) self.drawTextLabel(hdc, pos, action.color, action.labelText) self.drawTimerLabel(hdc, pos, action.color, action.countdown) k = k + idx + 2 for idx, equip in enumerate(self.equipmentToDraw): #if (idx+1) in emptyLines : k=k+1 pos = (pleft, ptop + (idx + k) * spc, pright, pbottom) self.drawTextLabel(hdc, pos, equip.color, equip.labelText) self.drawTimerLabel(hdc, pos, equip.color, equip.countdown) win32gui.EndPaint(hWnd, paintStruct) return 0 elif message == win32con.WM_DESTROY: win32gui.PostQuitMessage(0) return 0 else: return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
if __name__ == '__main__': if (len(sys.argv[1:]) < 1): print "Usage: ", sys.argv[0], "Target(Font File)" sys.exit() else: fileFont = sys.argv[1] try: tt = ttLib.TTFont(fileFont) except: print "Font File Corrupted" else: fontName = shortName(tt)[1] lf = win32gui.LOGFONT() htr = windll.gdi32.AddFontResourceExA(fileFont, FR_PRIVATE, None) w = mainWindow() hwnd = w.CreateWindow() hdc = windll.user32.GetDC(hwnd) for fontsize in range(0, 1000, 100): lf.lfHeight = fontsize lf.lfFaceName = fontName #lf.lfFaceName=fontPath lf.lfWidth = 0 lf.lfEscapement = 0 lf.lfOrientation = 0 lf.lfWeight = FW_NORMAL lf.lfItalic = False lf.lfUnderline = False lf.lfStrikeOut = False