Example #1
0
def getfont(name, size, weight = 400, italic = 0):
    if italic:
        return win32ui.CreateFont({
            "name": name,
            "height": scale_factor * size,
            "weight": weight,
            "italic": italic,
        })
    else:
        return win32ui.CreateFont({
            "name": name,
            "height": scale_factor * size,
            "weight": weight,
        })
Example #2
0
 def print_records(self):
     
     dc = win32ui.CreateDC()
     dc.CreatePrinterDC(win32print.GetDefaultPrinter())
     dc.SetMapMode(win32con.MM_TWIPS) # 1440 per inch
     scale_factor = 20 # i.e. 20 twips to the point
     dc.StartDoc("description")
     pen = win32ui.CreatePen(0, int(scale_factor), 0L)
     dc.SelectObject(pen)
     font = win32ui.CreateFont({
         "name": "Lucida Console",
         "height": int(scale_factor * 7),
         "weight": 400,
     })
     
     dc.SelectObject(font)
     dc.TextOut(scale_factor * 72,
         -1 * scale_factor * 120,
         self.s_name.get())
     
     dc.TextOut(scale_factor * 72,
         -1 * scale_factor * 131,
         self.s_street.get() + ', ' + self.s_postcode.get() + ' ' + self.s_city.get())
     
     dc.TextOut(scale_factor * 72,
         -1 * scale_factor * 140,
         "-------------------------------------------")
     
     font = win32ui.CreateFont({
         "name": "Lucida Console",
         "height": int(scale_factor * 10),
         "weight": 400,
     })
     dc.SelectObject(font)
     
     dc.TextOut(scale_factor * 72,
         -1 * scale_factor * 155,
         self.r_name.get())
     
     dc.TextOut(scale_factor * 72,
         -1 * scale_factor * 170,
         self.r_street.get() + ',')
     
     dc.TextOut(scale_factor * 72,
         -1 * scale_factor * 185,
         self.r_postcode.get() + ' ' + self.r_city.get())
     dc.EndDoc()
     
     print type(self.r_postcode.get())
Example #3
0
    def createFont(self, fontName, fontSize, flags):
        """Create a font. returns a handle. NOTE: This wont work on LINUX!!!!
        """
        handle = self.fontId
        self.fontId += 256

        props = {"name":fontName, "height":(int)(fontSize*1.2), "charset":0, "weight":1, "pitch and family":18}
        if flags & pyui.locals.ITALIC:
            props["italic"] = 1
        if flags & pyui.locals.UNDERLINE:
            props["underline"] = 1
        if flags & pyui.locals.BOLD:
            props["weight"] = 128
            
        pf = win32ui.CreateFont( props )
        hdc = wglGetCurrentDC()
        pdc = win32ui.CreateDCFromHandle(hdc)

        
        old = pdc.SelectObject(pf)
        result = wglUseFontBitmaps(hdc , 0, 255, handle)
        if not result:
            print "ERROR!"
        pdc.SelectObject(old)

        self.fonts[handle] = (fontName, fontSize, flags)
        del pf
        del pdc

        return handle
Example #4
0
	def __init__(self,  doc, text = 'Python Rules!', font_spec = {'name':'Arial', 'height':42}):
		docview.ScrollView.__init__(self, doc)
		self.font = win32ui.CreateFont (font_spec)
		self.text = text
		self.width = self.height = 0
		# set up message handlers
		self.HookMessage (self.OnSize, win32con.WM_SIZE)
Example #5
0
def BuildFont():
    global base
    # TODO: figure out why ctypes doesn't return a c_void_p, has been
    # known since at least 2006, still presenting in Python 2.5 win32
    wgldc = wglGetCurrentDC()
    hDC = win32ui.CreateDCFromHandle(pointer_as_int(wgldc))

    base = glGenLists(32 + 96)
    # // Storage For 96 Characters, plus 32 at the start...

    # CreateFont () takes a python dictionary to specify the requested font properties.
    font_properties = {
        "name": "Courier New",
        "width": 0,
        "height": -24,
        "weight": 800
    }
    font = win32ui.CreateFont(font_properties)
    # // Selects The Font We Want
    oldfont = hDC.SelectObject(font)
    # // Builds 96 Characters Starting At Character 32
    wglUseFontBitmapsA(wgldc, 32, 96, base + 32)
    # // reset the font
    hDC.SelectObject(oldfont)
    # // Delete The Font (python will cleanup font for us...)
    return
Example #6
0
        def __init__(self,
                     name,
                     height,
                     weight=win32con.FW_NORMAL,
                     italic=False,
                     underline=False):

            self.font = win32ui.CreateFont({
                'name': name,
                'height': height,
                'weight': weight,
                'italic': italic,
                'underline': underline,
            })  #'charset': win32con.MAC_CHARSET})

            #create a compatible DC we can use to draw:

            self.desktopHwnd = win32gui.GetDesktopWindow()
            self.desktopDC = win32gui.GetWindowDC(self.desktopHwnd)
            self.mfcDC = win32ui.CreateDCFromHandle(self.desktopDC)
            self.drawDC = self.mfcDC.CreateCompatibleDC()

            #initialize it

            self.drawDC.SelectObject(self.font)
Example #7
0
def BuildFont():
    global base

    wgldc = wglGetCurrentDC()
    hDC = win32ui.CreateDCFromHandle(wgldc)

    # Storage For 96 Characters, plus 32 at the start...
    base = glGenLists(32 + 96)

    # CreateFont () takes a python dictionary to specify the requested font properties.
    font_properties = {
        "name": "Courier New",
        "width": 0,
        "height": -24,
        "weight": 800
    }
    font = win32ui.CreateFont(font_properties)
    # Selects The Font We Want
    oldfont = hDC.SelectObject(font)
    # Builds 96 Characters Starting At Character 32
    wglUseFontBitmaps(wgldc, 32, 96, base + 32)
    # reset the font
    hDC.SelectObject(oldfont)
    # Delete The Font (python will cleanup font for us...)
    return
Example #8
0
def enum_fonts(logfont, *largs):
    try:
        _gui_font = ui.CreateFont({
            'name': logfont.lfFaceName,
            'height': -17,
            'weight': 400
        })
        _gui_font2 = GUI.Font(family=logfont.lfFaceName, size=17)
        _font = gui.CreateFontIndirect(logfont)
        hdc = win_none.GetDC().GetSafeHdc()
        gui.SelectObject(hdc, _font)
        print '1.------'
        print ''.join(['[', logfont.lfFaceName,
                       ']']), gui.GetTextExtentPoint32(hdc, '12345'), logfont
        gui.SelectObject(hdc, _gui_font.GetSafeHandle())
        logfont.lfHeight = 17
        _gdip_font2 = gdip.Font.from_logfont(hdc, logfont)
        _gui_font2._win_gdip_font = _gdip_font2
        print _gui_font, (logfont.lfHeight, logfont.lfWidth,
                          logfont.lfEscapement, logfont.lfOrientation,
                          logfont.lfWeight, logfont.lfItalic,
                          logfont.lfUnderline, logfont.lfStrikeOut,
                          logfont.lfCharSet, logfont.lfOutPrecision,
                          logfont.lfClipPrecision, logfont.lfQuality,
                          logfont.lfPitchAndFamily), gui.GetTextExtentPoint32(
                              hdc, '12345'), _gui_font2.width('12345')
        _gdip_font2 = gdip.Font.from_logfont(hdc, logfont)
        print '2.------', _gdip_font2.ptr
    except:
        import traceback
        traceback.print_exc()

    return True
Example #9
0
 def SetFont(self, fType, fSize, fWeight):
     self.font = win32ui.CreateFont({
         "name": fType,
         "height": fSize,
         "weight": fWeight
     })
     self.dc.SelectObject(self.font)
Example #10
0
def createFonts():
    global fonts
    normal = {'name': 'Courier New', 'size': 12, 'weight': 400}
    bold = {'name': 'Courier New', 'size': 12, 'weight': 700}
    italic = {'name': 'Courier New', 'size': 12, 'weight': 400, 'italic': 1}
    for i in ['normal', 'bold', 'italic']:
        d = locals().get(i)
        f = win32ui.CreateFont(d)
        fonts[i] = f
Example #11
0
 def print_line(self, text, font_name, font_size, font_weight=400):
     font = win32ui.CreateFont({
         "name": font_name,
         "height": int(self.scale_factor * font_size),
         "weight": font_weight,
     })
     self.dc.SelectObject(font)
     self.dc.TextOut(self.x, self.y, str(text))
     self.move_cursor(font_size * 1.3)
Example #12
0
 def __init__(self,
              doc,
              text="Python Rules!",
              font_spec={
                  "name": "Arial",
                  "height": 42
              }):
     docview.ScrollView.__init__(self, doc)
     self.font = win32ui.CreateFont(font_spec)
     self.text = text
     self.width = self.height = 0
     # set up message handlers
     self.HookMessage(self.OnSize, win32con.WM_SIZE)
def BuildFont():
    global base
    wgldc = wglGetCurrentDC()
    hDC = win32ui.CreateDCFromHandle(wgldc)
    base = glGenLists(96);
    font_properties = { "name" : "Arial",
                        "width" : 10,
                        "height" : 40,
                        "weight" : 900
        }
    font = win32ui.CreateFont(font_properties)
    oldfont = hDC.SelectObject(font)
    wglUseFontBitmaps(wgldc, 32, 96, base)
    hDC.SelectObject(oldfont)
Example #14
0
def printing():
	global in_path, infile
	with open(in_path, 'r') as infile:
		textfile = infile.read()
	pf = win32ui.CreateDC()
	pf.CreatePrinterDC()
	pf.SetMapMode(4)
	font = win32ui.CreateFont({'name': 'Arial', 'height':16})
	pf.SelectObject(font)
	pf.StartDoc(textfile)
	pf.TextOut(40,40, textfile)
	pf.EndPage()
	pf.EndDoc()
	print(textfile)
Example #15
0
 def printfile(self):
     #with open(self.in_path, 'r') as self.infile:
         #textfile= self.infile.read()
     textfile = self.mainBody.get(1.0, END)
     dc = win32ui.CreateDC()
     dc.CreatePrinterDC()
     dc.SetMapMode(4)
     font = win32ui.CreateFont({'name':'Arial','height':16})
     dc.SelectObject(font)
     dc.StartDoc(textfile)
     dc.StartPage()
     dc.TextOut(40,40, textfile)
     dc.EndPage()
     dc.EndDoc()
Example #16
0
def Impression(lignes=[],
               imprimante=None,
               titre=_(u"Ticket"),
               nomPolice="Arial",
               taillePolice=15,
               interligne=5):
    if len(lignes) == 0:
        return

    # Vérifie que les librairies windows ont bien été chargées
    if LIB_CHARGEES == False:
        dlg = wx.MessageDialog(
            None,
            _(u"L'outil d'impression de ticket ne peut pas être chargé. Ce problème sera sûrement résolu en téléchargeant le Package redistribuable Microsoft Visual C++ 2008 (x86) de Microsoft. Rendez-vous sur http://www.microsoft.com/fr-fr/download/details.aspx?id=29."
              ), _(u"Erreur"), wx.OK | wx.ICON_ERROR)
        dlg.ShowModal()
        dlg.Destroy()
        return

    # Sélection de l'imprimante
    if imprimante != None:
        if imprimante not in GetListeImprimantes():
            imprimante = None
    if imprimante == None:
        imprimante = win32print.GetDefaultPrinter()

    # Initialisation du document
    dc = win32ui.CreateDC()
    try:
        dc.CreatePrinterDC(imprimante)
    except Exception as err:
        print("Erreur dans l'impression du ticket :", err)
        print("Test sur l'imprimante par defaut...")
        dc.CreatePrinterDC()
    dc.StartDoc(titre)
    dc.StartPage()

    # Création des lignes
    y = 0
    for ligne in lignes:
        font = win32ui.CreateFont({"name": nomPolice, "height": taillePolice})
        dc.SelectObject(font)
        dc.TextOut(0, y, ligne)
        y += taillePolice + interligne

    # Finalisation du document
    dc.EndPage()
    dc.EndDoc()
    del dc
Example #17
0
    def __init__(self):
        print("Create Printer obj")
        # self.dc = object

        self.FontSize = 100
        self.FontType = "Lucida Console"
        self.FontWeight = 400
        self.LineWeight = 2
        self.PageSize = (210, 297)

        self.Offset = Point()

        self.font = win32ui.CreateFont({
            "name": self.FontType,
            "height": self.FontSize,
            "weight": self.FontWeight,
        })

        self.printer_name = win32print.GetDefaultPrinter()
Example #18
0
    def drawDebugRaster(self):
        self.session.debug("drawDebugRaster()")
        self.flush()
        #dc=self.dc

        fontDict = dict(name="Courier New", height=8 * pt)
        font = win32ui.CreateFont(fontDict)
        self.dc.SelectObject(font)
        #print "CreateFont(%r)" % fontDict

        LEFT = 0
        BOTTOM = 0
        RIGHT = int(210 * mm)
        TOP = int(297 * mm)

        CS = int(9 * mm)  # Cross Size

        # move to upper left
        self.dc.MoveTo((LEFT, TOP))
        # line to upper right
        self.dc.LineTo((RIGHT, TOP))

        # to lower right
        self.dc.LineTo((RIGHT, BOTTOM))

        # to lower left
        self.dc.LineTo((LEFT, BOTTOM))

        # to upper left
        self.dc.LineTo((LEFT, TOP))

        for x in range(LEFT, RIGHT, int(20 * mm)):
            for y in range(BOTTOM, TOP, int(20 * mm)):

                self.dc.MoveTo((x - CS, y))
                self.dc.LineTo((x + CS, y))

                self.dc.MoveTo((x, y - CS))
                self.dc.LineTo((x, y + CS))

                self.dc.TextOut(x, y,
                                "(%d,%d)" % (round(x / mm), round(y / mm)))
def BuildFont():
    global base

    wgldc = wglGetCurrentDC()
    hDC = win32ui.CreateDCFromHandle(wgldc)
    base = glGenLists(96)
    #CreateFont()

    font_properties = {
        "name": "Broadway",
        "width": 40,
        "height": 100,
        "weight": 400
    }  #debljina fonta

    font = win32ui.CreateFont(font_properties)
    oldfont = hDC.SelectObject(font)  #odabir fonta
    wglUseFontBitmaps(wgldc, 32, 96,
                      base)  #stvaranje 96 znakova pocevsi od 32. znaka
    hDC.SelectObject(oldfont)  #reset font
Example #20
0
def BuildFont():
    global base, font
    wgldc = wglGetCurrentDC()
    hDC = win32ui.CreateDCFromHandle(wgldc)
    base = glGenLists(96)

    font_properties = {
        "name": font,
        "width": 50,  #sirina fonta
        "height": 50,  #visina fonta
        "weight": 1000  #debljina fonta
    }

    font = win32ui.CreateFont(font_properties)
    # //odabir fonta
    oldfont = hDC.SelectObject(font)
    # // Stvaranje 96 znakova pocevsi od 32. znaka
    wglUseFontBitmaps(wgldc, 32, 96, base)
    # // reset font
    hDC.SelectObject(oldfont)
Example #21
0
 def BuildFont(self,
               fontname="Times New Roman",
               width=0,
               size=24,
               weight=800):
     """Load a font as a set of OpenGL drawing lists, for quick
     drawing of each letter."""
     wgldc = wglGetCurrentDC()
     hDC = win32ui.CreateDCFromHandle(wgldc)
     properties = {
         "name": fontname,
         "width": width,
         "height": size,
         "weight": weight
     }
     self.fontlists = glGenLists(96)
     font = win32ui.CreateFont(properties)
     oldfont = hDC.SelectObject(font)  ## ?
     wglUseFontBitmaps(wgldc, 32, 96, self.fontlists)
     hDC.SelectObject(oldfont)  ## ?
Example #22
0
def write_text(text=""):
    hwin = win32gui.GetDesktopWindow()
    hdc = win32gui.GetDC(hwin)

    # 텍스트 옵션
    font = win32ui.CreateFont({"name": "Arial", "height": 64, "weight": 400})
    oldFont = win32gui.SelectObject(hdc, font.GetSafeHandle())

    #win32gui.SetTextColor(hdc, win32api.RGB(0,0,0))
    #win32gui.SetBkColor(hdc, win32api.RGB(255, 255, 255))

    rect = win32gui.GetClientRect(hwin)
    win32gui.DrawText(
        hdc, text, len(text), rect, win32con.DT_BOTTOM | win32con.DT_RIGHT
        | win32con.DT_SINGLELINE | win32con.DT_WORDBREAK
        #win32con.DT_CENTER|win32con.DT_VCENTER|win32con.DT_SINGLELINE|win32con.DT_WORDBREAK
    )

    win32gui.SelectObject(hdc, oldFont)
    win32gui.DeleteObject(font.GetSafeHandle())
    win32gui.ReleaseDC(hwin, hdc)
Example #23
0
    def BuildFont(self):

        wgldc = WGL.wglGetCurrentDC()
        hDC = win32ui.CreateDCFromHandle(wgldc)

        self.base = glGenLists(32 + 96)
        # // Storage For 96 Characters, plus 32 at the start...

        # CreateFont () takes a python dictionary to specify the requested font properties.
        font_properties = {
            "name": "Courier New",
            "width": 0,
            "height": -24,
            "weight": 800
        }
        font = win32ui.CreateFont(font_properties)
        # // Selects The Font We Want
        oldfont = hDC.SelectObject(font)
        # // Builds 96 Characters Starting At Character 32
        WGL.wglUseFontBitmaps(wgldc, 32, 96, self.base + 32)
        # // reset the font
        hDC.SelectObject(oldfont)
 def __init__(self, context):
     self.base = glGenLists(96)  # Storage For 96 Characters
     wgldc = wglGetCurrentDC()
     if wgldc > sys.maxint:
         import struct
         print 'too-large wgldc', wgldc
         wgldc = struct.unpack('>i', struct.pack('>I', wgldc))[0]
         print 'Converted wgldc to', wgldc
     dc = win32ui.CreateDCFromHandle(wgldc)
     ## pitch and family value
     f = win32ui.CreateFont({
         'italic': 0,  #use of None is required, 0 doesn't work
         'underline': 0,  #use of None is required, 0 doesn't work
         'name': 'Times New Roman',
         'weight': 700,
         'height': 20,
     })
     dc.SelectObject(f)
     '''Build 96 bitmaps as display lists starting from character 
     32.'''
     wglUseFontBitmaps(wgldc, 32, 96, self.base)
     '''f is deleted here, if it is deleted before the display-lists
Example #25
0
 def _uiFont(self):
     """Get the appropriate UI-library font for this font
     
     Note: for some reason this object is _not_ properly
     reference counted.  You will need to hold a reference
     to it until _after_ you've called wglUseFont*
     """
     specification = {
         'italic': None,
         'underline': None,
         'name': FAMILYMAPPING.get("SANS"),
     }
     if self.fontStyle:
         if self.fontStyle.family:
             name = self.fontStyle.family[0]
         else:
             name = "SANS"
         specification["name"] = FAMILYMAPPING.get(name, name)
         # size seems a little non-specific
         specification["size"] = int(self.fontStyle.size * 12)
         # need weight seperated
         weight = win32con.FW_NORMAL
         for wname, weight in WEIGHTNAMES:
             if self.fontStyle.style.find(wname) >= 0:
                 break
         specification["weight"] = weight
         if self.fontStyle.style.find('ITALIC') >= 0:
             italic = 1
         else:
             italic = None
         specification["italic"] = italic
         if self.fontStyle.style.find('UNDERLINE') >= 0:
             underline = 1
         else:
             underline = None
         specification["underline"] = underline
     if __debug__:
         log.debug("""font specification %s""", specification)
     return win32ui.CreateFont(specification, )
Example #26
0
        
dc.SetMapMode(win32con.MM_TWIPS)
#dc.SetViewportOrg((-1000,0))
        
org = dc.GetWindowOrg()
ext = dc.GetWindowExt()
print "org:",org
print "ext:",ext

def twips2mm(twips):
    return twips * 1440.0


fontDict=dict(name="Courier New",
              height=120)
font = win32ui.CreateFont(fontDict)
dc.SelectObject(font)
        
DELTA=10
LEFT=org[0]
RIGHT=ext[0]
TOP=org[1]
BOTTOM=ext[1]


LEFT=0
RIGHT=int(210*mm)
TOP=-int(297*mm)
BOTTOM=0

CS=int(9*mm) # Cross Size
Example #27
0
 def ChangeAttributes(self):
     font_spec = {'name': 'Arial', 'height': 42}
     self.font = win32ui.CreateFont(font_spec)
def getfont(name, size, weight=400):
    return win32ui.CreateFont({
        "name": name,
        "height": scale_factor * size,
        "weight": weight,
    })
Example #29
0
def print_mon_an(mon_an, note, order_id):
    Y = 10
    hDC = win32ui.CreateDC()
    font_h1 = win32ui.CreateFont({
        "name": "Courier New",
        "height": 70,
        "weight": 800,
        "charset": 0x000000A3
    })
    font_h2 = win32ui.CreateFont({
        "name": "Courier New",
        "height": 30,
        "weight": 700,
        "charset": 0x000000A3
    })
    font_normal = win32ui.CreateFont({
        "name": "Courier New",
        "height": 25,
        "weight": 600
    })
    hDC = win32ui.CreateDC()
    hDC.CreatePrinterDC("Gprinter 2120TU(Label)")
    hDC.StartDoc("XXX")
    hDC.StartPage()
    hDC.SelectObject(font_normal)
    hDC.TextOut(50, Y, "Ma: " + str(order_id))
    Y += 20
    hDC.SelectObject(font_h2)
    p = 0
    if len(mon_an.get('food').get('name_print')) > 20:
        chars = mon_an.get('food').get('name_print').split(" ")
        lines = []
        line = []
        n = 0
        for char in chars:
            n += len(char)
            if n > 40:
                hDC.TextOut(30, Y + p * 30, " ".join(line))
                p += 1
                line = []
                n = 0
            else:
                line.append(char)
        if n > 0:
            hDC.TextOut(30, Y + p * 30, " ".join(line))

    else:
        hDC.TextOut(30, Y, mon_an.get('food').get('name_print'))
    Y += 30 + p * 20

    hDC.TextOut(50, Y + 20, "Size:")
    hDC.SelectObject(font_h1)
    hDC.TextOut(150, Y, mon_an.get('size'))
    hDC.SelectObject(font_h2)
    hDC.TextOut(200, Y + 20, note)
    Y += 50
    hDC.SelectObject(font_normal)
    hDC.TextOut(0, Y, "======================")
    Y += 20
    for topping in mon_an.get('topping'):
        hDC.TextOut(30, Y, topping.get('name_print'))
        Y += 10
    hDC.SelectObject(font_normal)
    hDC.EndPage()
    hDC.EndDoc()
Example #30
0
def print_bill(order):
    Y = 0
    hDC = win32ui.CreateDC()
    font_h1 = win32ui.CreateFont({
        "name": "Courier New",
        "height": 70,
        "weight": 800,
        "charset": 0x000000A3
    })
    font_h2 = win32ui.CreateFont({
        "name": "Courier New",
        "height": 30,
        "weight": 700,
        "charset": 0x000000A3
    })
    font_normal = win32ui.CreateFont({
        "name": "Courier New",
        "height": 25,
        "weight": 600
    })
    hDC.CreatePrinterDC("XP-80")
    hDC.StartDoc("XXX")
    hDC.StartPage()
    hDC.SelectObject(font_h1)
    hDC.TextOut(60, 0, "Tra Sua HiTea")
    Y += 60
    hDC.SelectObject(font_normal)
    hDC.TextOut(0, Y, "HD:" + str(order.get("uuid", 0)))
    hDC.TextOut(
        200, Y,
        "Ngay:" + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    Y += 30
    hDC.SelectObject(font_h2)
    hDC.TextOut(0, Y, "Mon")
    hDC.TextOut(330, Y, str("Size"))
    hDC.TextOut(410, Y, str("SL"))
    hDC.TextOut(490, Y, str("Gia"))
    Y += 40
    hDC.SelectObject(font_normal)
    for item in order.get('foods', False):
        p = 0
        if len(item.get('food', False).name_print) > 20:
            chars = item.get('food', False).get('name_print', "").split(" ")
            lines = []
            line = []
            n = 0
            for char in chars:
                n += len(char)
                if n > 15:
                    hDC.TextOut(0, Y + p * 20, " ".join(line))
                    p += 1
                    line = []
                    n = 0
                else:
                    line.append(char)
            if n > 0:
                hDC.TextOut(0, Y + p * 20, " ".join(line))

        else:
            hDC.TextOut(0, Y, item.get('food', False).get('name_print', ""))

        hDC.TextOut(360, Y, item.get('size', False))
        hDC.TextOut(415, Y, str(item.get('sl', False)))
        hDC.TextOut(450, Y, item.get('price', False))
        Y += 40
        for topping in item.get('topping'):
            p = 0
            if len(topping.get('name_print')) > 20:
                chars = topping.get('name_print').split(" ")
                lines = []
                line = []
                n = 0
                for char in chars:
                    n += len(char)
                    if n > 15:
                        hDC.TextOut(20, Y + p * 20, " ".join(line))
                        p += 1
                        line = []
                        n = 0
                    else:
                        line.append(char)
                if n > 0:
                    hDC.TextOut(20, Y + p * 20, " ".join(line))

            else:
                hDC.TextOut(0, Y, topping.get('name_print'))
            hDC.TextOut(415, Y, str(item.get('sl', False)))
            hDC.TextOut(450, Y, topping.get('price', False))
            Y += 40

    hDC.TextOut(0, Y, "                      --------------")
    Y += 20
    hDC.SelectObject(font_h2)
    hDC.TextOut(0, Y, "Tong cong:")
    hDC.TextOut(450, Y, str(order.get('sum')))
    Y += 30
    hDC.TextOut(0, Y, "Tien mat:")
    hDC.TextOut(450, Y, str(order.get('khach_dua')))
    Y += 30
    hDC.TextOut(0, Y, "Thoi lai:")
    hDC.TextOut(450, Y, str(order.get('thoi')))
    Y += 30
    hDC.TextOut(0, Y, "====================================")
    Y += 30
    hDC.SelectObject(font_h2)
    hDC.TextOut(0, Y, "*******CHUC QUY KHACH VUI VE*****")

    hDC.EndPage()
    hDC.EndDoc()