Skip to content

Commit

Permalink
<feature> improve font replace function which can support the game wi…
Browse files Browse the repository at this point in the history
…th self-defined dialogues

update version to v2.3.1
  • Loading branch information
anonymousException committed May 29, 2024
1 parent 955f540 commit eaad4ab
Show file tree
Hide file tree
Showing 32 changed files with 68 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/font_replace_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def select_font(self):
file, filetype = QFileDialog.getOpenFileName(self,
QCoreApplication.translate("FontReplaceDialog", "select the file font which supports the translated language", None),
'', # 起始路径
"Font Files (*.ttf || *.otf);;All Files (*)")
"Font Files (*.ttf || *.otf || *.ttc || *.otc || *.woff || *.woff2);;All Files (*)")
self.selectFontText.setText(file)

def replaceFont(self):
Expand Down
2 changes: 2 additions & 0 deletions src/font_style_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ translate {tl_name} python:
gui.name_text_font = font_path
style.default.font = font_path
gui.headline_text_font = FontGroup().add(font_path, 0x2E80, 0xffff).add(font_path, 0x0000, 0xffff)

font_path = "{font_path}"
#replace defined font
change_font(font_path)
Binary file modified src/qm/arabic.qm
Binary file not shown.
Binary file modified src/qm/bengali.qm
Binary file not shown.
Binary file modified src/qm/chinese.qm
Binary file not shown.
Binary file modified src/qm/french.qm
Binary file not shown.
Binary file modified src/qm/german.qm
Binary file not shown.
Binary file modified src/qm/hindi.qm
Binary file not shown.
Binary file modified src/qm/japanese.qm
Binary file not shown.
Binary file modified src/qm/korean.qm
Binary file not shown.
Binary file modified src/qm/portuguese.qm
Binary file not shown.
Binary file modified src/qm/russian.qm
Binary file not shown.
Binary file modified src/qm/spanish.qm
Binary file not shown.
Binary file modified src/qm/turkish.qm
Binary file not shown.
Binary file modified src/qm/urdu.qm
Binary file not shown.
38 changes: 36 additions & 2 deletions src/renpy_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ def replace_font_content(text, new_content):
return re.sub(pattern, replacement, text)


def ExtractDefineList(data):
define_list = set()
_read_line = data.split('\n')
for idx, line in enumerate(_read_line):
line = line.strip()
if line.endswith('"'):
line = line.strip('"')
if line.endswith("'"):
line = line.strip("'")
if line.startswith('define '):
suffix_list = ['.otf', '.ttf', '.ttc', '.otc', '.woff', '.woff2']
for suffix in suffix_list:
if line.endswith(suffix):
line = _read_line[idx].strip()
defined_var = line[7:line.find('=')].strip()
define_list.add(defined_var)
break
return define_list

def ExtractStyleList(data):
_read_line = data.split('\n')
last_i = 0
Expand Down Expand Up @@ -98,10 +117,20 @@ def ExtractStyleFontListFromFile(p):
return d


def ExtractDefinedFontListFromFile(p):
f = io.open(p, 'r+', encoding='utf-8')
_read = f.read()
f.close()
return ExtractDefineList(_read)

# ExtractDefinedFontListFromFile(f'F:\Games\RenPy\MilkyTouch-Finale.Official-pc\game\screens.rpy')


def ExtractStyleFontListFromDirectory(p):
if (p[len(p) - 1] != '/' and p[len(p) - 1] != '\\'):
p = p + '/'
ret_d = dict()
ret_set = set()
paths = os.walk(p, topdown=False)
for path, dir_lst, file_lst in paths:
for file_name in file_lst:
Expand All @@ -112,9 +141,10 @@ def ExtractStyleFontListFromDirectory(p):
continue
# print(i)
d = ExtractStyleFontListFromFile(i)
ret_set = ret_set | ExtractDefinedFontListFromFile(i)
if len(d) > 0:
ret_d.update(d)
return ret_d
return ret_d, ret_set


def ExtractFontContent(data):
Expand All @@ -138,7 +168,10 @@ def GenGuiFontsOriginal(p, tl_name, font_path):
f.close()
if (pythonBeginLine in _read):
appendMode = True
result = ExtractStyleFontListFromDirectory(p)
result, defined_set = ExtractStyleFontListFromDirectory(p)
defined_contents = ''
for defined in defined_set:
defined_contents = defined_contents + f' {defined} = gui.text_font\n'
if (appendMode):
f = io.open(guiPath, 'a+', encoding='utf-8')
for key, value in result.items():
Expand Down Expand Up @@ -181,6 +214,7 @@ def GenGuiFontsOriginal(p, tl_name, font_path):
f.close()
template = template.replace('{tl_name}', tl_name)
template = template.replace('{font_path}', 'fonts/' + font_path)
template = template.replace('#replace defined font', defined_contents)
f = io.open(guiPath, 'w', encoding='utf-8')
header = template
# print(header)
Expand Down
4 changes: 2 additions & 2 deletions src/ts/arabic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>الإصدار2.3.0</translation>
<source>Version 2.3.1</source>
<translation>الإصدار2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/bengali.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>সংস্করণ 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>সংস্করণ 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/chinese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>版本 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>版本 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
2 changes: 1 addition & 1 deletion src/ts/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<source>Version 2.3.1</source>
<translation type="unfinished"></translation>
</message>
<message>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/french.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>Version 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>Version 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/german.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1293,8 +1293,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>Version 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>Version 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="391"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/hindi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>संस्करण 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>संस्करण 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/japanese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>バージョン2.3.0</translation>
<source>Version 2.3.1</source>
<translation>バージョン2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/korean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1293,8 +1293,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>버전 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>버전 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="391"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/portuguese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>Versão 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>Versão 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/russian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>Версия 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>Версия 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/spanish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>Versión 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>Versión 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/turkish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1270,8 +1270,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>Sürüm 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>Sürüm 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="391"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/urdu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.3.0</source>
<translation>ورژن 2.3.0</translation>
<source>Version 2.3.1</source>
<translation>ورژن 2.3.1</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
2 changes: 1 addition & 1 deletion src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def retranslateUi(self, MainWindow):
self.actionpack_game_files.setText(QCoreApplication.translate("MainWindow", u"pack game files", None))
self.clearLogBtn.setText(QCoreApplication.translate("MainWindow", u"clear log", None))
self.copyrightLabel.setText(QCoreApplication.translate("MainWindow", u"\u00a92024 Last moment,All rights reserved.", None))
self.versionLabel.setText(QCoreApplication.translate("MainWindow", u"Version 2.3.0", None))
self.versionLabel.setText(QCoreApplication.translate("MainWindow", u"Version 2.3.1", None))
self.translateBtn.setText(QCoreApplication.translate("MainWindow", u"translate", None))
self.selectFilesBtn.setText(QCoreApplication.translate("MainWindow", u"...", None))
self.label_2.setText(QCoreApplication.translate("MainWindow", u"directory", None))
Expand Down
2 changes: 1 addition & 1 deletion src/ui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</size>
</property>
<property name="text">
<string>Version 2.3.0</string>
<string>Version 2.3.1</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit eaad4ab

Please sign in to comment.