def __generate_font__(self):
   gen_font1   = self.ui.rdoGenFont1.isChecked()
   temp_dir    = tempfile.mkdtemp(prefix = "sdse-")
   temp_name   = "font"
   font_type   = font_generator.FONT_TYPES.font01 if gen_font1 else font_generator.FONT_TYPES.font02
   for_game    = self.ui.chkGenForGame.isChecked()
   for_editor  = self.ui.chkGenForEditor.isChecked()
   
   font_data = self.get_font_data()
   if self.ui.rdoRightToLeft.isChecked():
     font_data.reverse()
   
   # Add the required characters to the end of the lowest-priority font
   # so they're there by default but they don't override any existing
   # settings for them, if they're already there.
   font_data[-1].chars += ''.join(REQUIRED_CHARS)
   
   font = font_generator.gen_font(font_data, font_type = font_type, img_width = 1024, draw_outlines = False)
   font.save(temp_dir, temp_name, for_game, for_editor, font_type, game = font_generator.GAMES.sdr2)
   
   basename  = os.path.join(temp_dir, temp_name)
   font_png  = basename + ".png"
   font_bmp  = basename + ".bmp"
   font_font = basename + ".font"
   
   font_dir  = os.path.join(common.editor_config.data01_dir, "jp", "font", "font.pak")
   
   if for_game:
     game_bmp  = "0000.bmp"  if gen_font1 else "0002.bmp"
     game_font = "0001.font" if gen_font1 else "0003.font"
     
     backup_files(font_dir, [game_bmp, game_font], suffix = "_FONT")
     # backup_time = time.strftime("%Y.%m.%d_%H.%M.%S_FONT")
     # backup_dir = os.path.join(common.editor_config.backup_dir, backup_time, "font.pak")
     # if not os.path.isdir(backup_dir):
       # os.makedirs(backup_dir)
     
     # Copy our existing data into the backup directory.
     # shutil.copy(game_bmp, backup_dir)
     # shutil.copy(game_font, backup_dir)
     
     # Then replace it with the one we generated.
     shutil.copy(font_bmp, os.path.join(font_dir, game_bmp))
     shutil.copy(font_font, os.path.join(font_dir, game_font))
   
   if for_editor:
     editor_png  = os.path.join(common.editor_config.gfx_dir, "font", "Font01.png"  if gen_font1 else "Font02.png")
     editor_font = os.path.join(common.editor_config.gfx_dir, "font", "Font01.font" if gen_font1 else "Font02.font")
     
     # Copy our files in.
     shutil.copy(font_png, editor_png)
     shutil.copy(font_font, editor_font)
     
     # Reparse the font for the editor.
     text_printer.load_fonts()
   
   shutil.rmtree(temp_dir)
 def update_preview(self):
   if self.importing:
     return
   
   config = self.get_data()
   config.chars = config.chars[:256]
   
   font = gen_font([config], font_type = self.font_type, img_width = 256, draw_outlines = self.ui.chkBoundingBoxes.isChecked())
   # font.save("debug/test")
   
   qt_pixmap = QtGui.QPixmap.fromImage(font.trans.copy(0, 0, 256, 256))
   self.ui.lblPreview.setPixmap(qt_pixmap)
    def update_preview(self):
        if self.importing:
            return

        config = self.get_data()
        config.chars = config.chars[:256]

        font = gen_font([config],
                        font_type=self.font_type,
                        img_width=256,
                        draw_outlines=self.ui.chkBoundingBoxes.isChecked())
        # font.save("debug/test")

        qt_pixmap = QtGui.QPixmap.fromImage(font.trans.copy(0, 0, 256, 256))
        self.ui.lblPreview.setPixmap(qt_pixmap)
Esempio n. 4
0
    def __generate_font__(self):
        gen_font1 = self.ui.rdoGenFont1.isChecked()
        temp_dir = tempfile.mkdtemp(prefix="sdse-")
        temp_name = "font"
        font_type = font_generator.FONT_TYPES.font01 if gen_font1 else font_generator.FONT_TYPES.font02
        for_game = self.ui.chkGenForGame.isChecked()
        for_editor = self.ui.chkGenForEditor.isChecked()

        font_data = self.get_font_data()
        if self.ui.rdoRightToLeft.isChecked():
            font_data.reverse()

        # Add the required characters to the end of the lowest-priority font
        # so they're there by default but they don't override any existing
        # settings for them, if they're already there.
        font_data[-1].chars += ''.join(REQUIRED_CHARS)

        font = font_generator.gen_font(font_data,
                                       font_type=font_type,
                                       img_width=1024,
                                       draw_outlines=False)
        font.save(temp_dir,
                  temp_name,
                  for_game,
                  for_editor,
                  font_type,
                  game=font_generator.GAMES.sdr2)

        basename = os.path.join(temp_dir, temp_name)
        font_png = basename + ".png"
        font_bmp = basename + ".bmp"
        font_font = basename + ".font"

        font_dir = os.path.join(common.editor_config.data01_dir, "jp", "font",
                                "font.pak")

        if for_game:
            game_bmp = "0000.bmp" if gen_font1 else "0002.bmp"
            game_font = "0001.font" if gen_font1 else "0003.font"

            backup_files(font_dir, [game_bmp, game_font], suffix="_FONT")
            # backup_time = time.strftime("%Y.%m.%d_%H.%M.%S_FONT")
            # backup_dir = os.path.join(common.editor_config.backup_dir, backup_time, "font.pak")
            # if not os.path.isdir(backup_dir):
            # os.makedirs(backup_dir)

            # Copy our existing data into the backup directory.
            # shutil.copy(game_bmp, backup_dir)
            # shutil.copy(game_font, backup_dir)

            # Then replace it with the one we generated.
            shutil.copy(font_bmp, os.path.join(font_dir, game_bmp))
            shutil.copy(font_font, os.path.join(font_dir, game_font))

        if for_editor:
            editor_png = os.path.join(
                common.editor_config.gfx_dir, "font",
                "Font01.png" if gen_font1 else "Font02.png")
            editor_font = os.path.join(
                common.editor_config.gfx_dir, "font",
                "Font01.font" if gen_font1 else "Font02.font")

            # Copy our files in.
            shutil.copy(font_png, editor_png)
            shutil.copy(font_font, editor_font)

            # Reparse the font for the editor.
            text_printer.load_fonts()

        shutil.rmtree(temp_dir)