Пример #1
0
 def getCachedFont(pygame_name):
     if pygame_name in mycache:
         pass
         #print "hit!\t\t", pygame_name
     else:
         #print "\tmiss!\t" + pygame_name
         if CACHE_CHAR_LIMIT < len(self.FullCharset()) * len(mycache):
             rmkey = mycache.keys()[0]
             del mycache[rmkey]
         mycache[pygame_name] = fontclustr.cv_font(self.CharsetOf(charset_id), pygame_name, CHAR_IMG_SIZE)
     return mycache[pygame_name]
Пример #2
0
 def getCachedFont(pygame_name):
     if pygame_name in mycache:
         pass
         #print "hit!\t\t", pygame_name
     else:
         #print "\tmiss!\t" + pygame_name
         if CACHE_CHAR_LIMIT < len(self.FullCharset()) * len(mycache):
             rmkey = mycache.keys()[0]
             del mycache[rmkey]
         mycache[pygame_name] = fontclustr.cv_font(
             self.CharsetOf(charset_id), pygame_name, CHAR_IMG_SIZE)
     return mycache[pygame_name]
Пример #3
0
    def CheckFonts(self, fontlist, progress_callback, msg_callback, dialog_obj):
        c = self.db.cursor()
        c.execute("update font set present = 0")
        i = 0

        self.mkdir(fontclustr.FONT_CACHE_DIR)

        for f in fontlist:
            #prep db record
            fontobject = fontclustr.cv_font(self.FullCharset(), f, CHAR_IMG_SIZE)
            rfn = fontobject.realName()
            font_id = 0

            #we can skip this
            (_, skip) = progress_callback(i, rfn)
            if skip:
                dialog_obj.success = False
                return

            c.execute("select font_id from font where pygame_name = ?", (f,))
            row = c.fetchone()


            if None == row:
                c.execute("insert into font(name, pygame_name, present, ok) values(?,?,1,0)", (rfn, f))
                c.execute("select last_insert_rowid()")
                row = c.fetchone()
                #print "got", row
                font_id = row[0]
            else:
                font_id = row[0]
                c.execute("update font set name=?, present=1, ok=0 where font_id=?", (rfn, font_id))

            try:
                if fontobject.is_missing():
                    msg_callback("is-missing\t" + f)
                    continue

                both_names = f + " (" + fontobject.realName() + ")"

                fontobject.cache()

                if fontobject.is_null():
                    msg_callback("same-char\t" + both_names)
                    continue

                c.execute("update font set ok=1 where font_id=?", (font_id,))

            except OSError:
                raise
            except RuntimeError as inst:
                magickerr = "Magick: geometry does not contain image"
                ri = repr(inst)
                pos = ri.find(magickerr)
                if -1 != pos:
                    pth = ri[pos + len(magickerr):ri.find("@")]
                    msg_callback("blank-char\t" + both_names)
                elif -1 != ri.find("Text has zero width"):
                    msg_callback("zero-width\t" + both_names)
                else:
                    msg_callback(both_names + "\tRUNTIME ERROR: " + ri)
            except fontclustr.BlankChar:
                msg_callback("blank-char\t" + both_names)
            except Exception as inst:
                e_t = str(type(inst))
                e_r = repr(inst)

                helpful = e_t + "::" + e_r
                msg_callback(both_names + "\tERROR: " + helpful)

                #raise


            i = i + 1

        self.db.commit()
Пример #4
0
    def CheckFonts(self, fontlist, progress_callback, msg_callback,
                   dialog_obj):
        c = self.db.cursor()
        c.execute("update font set present = 0")
        i = 0

        self.mkdir(fontclustr.FONT_CACHE_DIR)

        for f in fontlist:
            #prep db record
            fontobject = fontclustr.cv_font(self.FullCharset(), f,
                                            CHAR_IMG_SIZE)
            rfn = fontobject.realName()
            font_id = 0

            #we can skip this
            (_, skip) = progress_callback(i, rfn)
            if skip:
                dialog_obj.success = False
                return

            c.execute("select font_id from font where pygame_name = ?", (f, ))
            row = c.fetchone()

            if None == row:
                c.execute(
                    "insert into font(name, pygame_name, present, ok) values(?,?,1,0)",
                    (rfn, f))
                c.execute("select last_insert_rowid()")
                row = c.fetchone()
                #print "got", row
                font_id = row[0]
            else:
                font_id = row[0]
                c.execute(
                    "update font set name=?, present=1, ok=0 where font_id=?",
                    (rfn, font_id))

            try:
                if fontobject.is_missing():
                    msg_callback("is-missing\t" + f)
                    continue

                both_names = f + " (" + fontobject.realName() + ")"

                fontobject.cache()

                if fontobject.is_null():
                    msg_callback("same-char\t" + both_names)
                    continue

                c.execute("update font set ok=1 where font_id=?", (font_id, ))

            except OSError:
                raise
            except RuntimeError as inst:
                magickerr = "Magick: geometry does not contain image"
                ri = repr(inst)
                pos = ri.find(magickerr)
                if -1 != pos:
                    pth = ri[pos + len(magickerr):ri.find("@")]
                    msg_callback("blank-char\t" + both_names)
                elif -1 != ri.find("Text has zero width"):
                    msg_callback("zero-width\t" + both_names)
                else:
                    msg_callback(both_names + "\tRUNTIME ERROR: " + ri)
            except fontclustr.BlankChar:
                msg_callback("blank-char\t" + both_names)
            except Exception as inst:
                e_t = str(type(inst))
                e_r = repr(inst)

                helpful = e_t + "::" + e_r
                msg_callback(both_names + "\tERROR: " + helpful)

                #raise

            i = i + 1

        self.db.commit()