Showing with 58 additions and 12 deletions.
  1. +34 −5 renpy/text/font.py
  2. +24 −7 renpy/text/ftfont.pyx
@@ -38,6 +38,25 @@
BLACK = (0, 0, 0, 255)


def is_zerowidth(char):
if char == 0x200b: # Zero-width space.
return True

if char == 0x200c: # Zero-width non-joiner.
return True

if char == 0x200d: # Zero-width joiner.
return True

if char == 0x2060: # Word joiner.
return True

if char == 0xfeff: # Zero width non-breaking space.
return True

return False


class ImageFont(object):

# ImageFonts are expected to have the following fields defined by
@@ -69,12 +88,18 @@ def glyphs(self, s):
g.ascent = self.baseline
g.line_spacing = self.height

width = self.width.get(c, None)
if width is None:
raise Exception("Character {0!r} not found in image-based font.".format(c))
if is_zerowidth(g.character):

g.width = self.width[c]
g.advance = self.advance[c]
width = self.width.get(c, None)
if width is None:
raise Exception("Character {0!r} not found in image-based font.".format(c))

g.width = self.width[c]
g.advance = self.advance[c]

else:
g.width = 0
g.advance = 0

rv.append(g)

@@ -94,6 +119,10 @@ def draw(self, target, xo, yo, color, glyphs, underline, strikethrough, black_co
return

for g in glyphs:

if not g.width:
continue

c = unichr(g.character)

cxo, cyo = self.offsets[c]
@@ -64,6 +64,24 @@ def init():
if error:
raise FreetypeError(error)

cdef bint is_zerowidth(unsigned int char):
if char == 0x200b: # Zero-width space.
return True

if char == 0x200c: # Zero-width non-joiner.
return True

if char == 0x200d: # Zero-width joiner.
return True

if char == 0x2060: # Word joiner.
return True

if char == 0xfeff: # Zero width non-breaking space.
return True

return False

cdef unsigned long io_func(FT_Stream stream, unsigned long offset, unsigned char *buffer, unsigned long count):
"""
Seeks to offset, and then reads count bytes from the stream into buffer.
@@ -491,12 +509,7 @@ cdef class FTFont:

gl.character = c
gl.ascent = self.ascent

if c == 0x200B:
gl.width = 0
else:
gl.width = cache.width

gl.width = cache.width
gl.line_spacing = self.lineskip

if i < len_s - 1:
@@ -519,6 +532,10 @@ cdef class FTFont:
else:
gl.advance = cache.advance

if is_zerowidth(gl.character):
gl.width = 0
gl.advance = 0

rv.append(gl)

return rv
@@ -623,7 +640,7 @@ cdef class FTFont:
if glyph.split == SPLIT_INSTEAD:
continue

if glyph.character == 0x200b:
if glyph.width == 0:
continue

x = <int> (glyph.x + xo)