recently I'm developing an adventure game with Ren'Py. It's a such a great tool, working with it is a joy. Thanks all developers and contributors!
I've modified some code to satisfy my own needs. First here's a path to easily reference Windows-supplied TTF/TTC fonts, like e.g. mingliu.ttc for Chinese font. It saves a lot of space since our game won't need to supply some huge Chinese fonts (assuming players are using Windows systems, and they can legally use these fonts).
Code: Select all
diff -ur renpy-6.1.1/renpy/display/text.py renpy-6.1.1c/renpy/display/text.py
--- renpy-6.1.1/renpy/display/text.py Sun Feb 25 00:40:22 2007
+++ renpy-6.1.1c/renpy/display/text.py Sun Apr 01 03:28:39 2007
@@ -22,6 +22,7 @@
import pygame
from pygame.constants import *
+import os
import re
import renpy
import sys
@@ -239,7 +240,15 @@
break
else:
# Let pygame try to find the font for us.
- rv = pygame.font.SysFont(fn, size, bold, italics)
+ fontdir = os.environ['SystemRoot'] + '\\Fonts\\'
+
+ if os.path.exists(fontdir + fn):
+ rv = pygame.font.Font(fontdir + fn, size)
+
+ rv.set_bold(bold)
+ rv.set_italic(italics)
+ else:
+ rv = pygame.font.SysFont(fn, size, bold, italics)
rv.set_underline(underline)
return rv
I've chose to allow wrapping between characters in the following ranges (refer to Mapping of Unicode characters):
# CJK Compatibility (3300–33FF)
# CJK Unified Ideographs Extension A (3400–4DBF)
# CJK Unified Ideographs (4E00–9FFF)
# CJK Compatibility Ideographs (F900–FAFF)
Better results can be achieved with full CJK phrase database/tokenizer, but it is too large for an adventure game engine to built-in, so I'm OK with current results
Code: Select all
diff -ur renpy-6.1.1/renpy/display/text.py renpy-6.1.1c/renpy/display/text.py
--- renpy-6.1.1/renpy/display/text.py Sun Feb 25 00:40:22 2007
+++ renpy-6.1.1c/renpy/display/text.py Sun Apr 01 03:44:51 2007
@@ -423,7 +432,8 @@
| \{(?P<tag>[^{}]+)\}
| (?P<untag>\{\{)
| (?P<newline>\n)
- | (?P<word>[^ \n\{]+)
+ | (?P<cjk>[\u3300-\u4dbf\u4e00-\u9fff\uf900-\ufaff])
+ | (?P<word>[^ \n\{\u3300-\u4dbf\u4e00-\u9fff\uf900-\ufaff]+)
""")
def text_tokenizer(s, style):
@@ -453,6 +463,8 @@
if m.group('space'):
yield 'space', m.group('space')
+ elif m.group('cjk'):
+ yield 'cjk', m.group('cjk')
elif m.group('word'):
yield 'word', m.group('word')
elif m.group('tag'):
@@ -1003,6 +1015,9 @@
continue
+ elif kind == "cjk":
+ triples.append(("cjk", tsl[-1], i))
+
elif kind == "word":
triples.append(("word", tsl[-1], i))
@@ -1112,7 +1127,7 @@
for type, text in tl:
if type == "newline":
rv += len(text)
- elif type == "word":
+ elif type == "word" or type == "cjk":
rv += len(text)
elif type == "space":
rv += len(text)