def glyphs(self, s): rv = [ ] if not s: return rv for c in s: g = textsupport.Glyph() # @UndefinedVariable g.character = ord(c) g.ascent = self.baseline g.line_spacing = self.height if not is_zerowidth(g.character): 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) # Compute kerning. for i in range(len(s) - 1): kern = self.kerns.get(s[i] + s[i+1], self.default_kern) rv[i].advance += kern return rv
def __init__(self, ts, width=0, height=0): """ `ts` The text segment that this SpaceSegment follows. """ self.glyph = glyph = textsupport.Glyph() glyph.character = 0 glyph.ascent = 0 glyph.line_spacing = height glyph.advance = width glyph.width = width if ts.hyperlink: glyph.hyperlink = ts.hyperlink self.cps = ts.cps
def textwrap(s, width=78, asian=False): """ Wraps the unicode string `s`, and returns a list of strings. `width` The number of half-width characters that fit on a line. `asian` True if we should make ambiguous width characters full-width, as is done in Asian encodings. """ import unicodedata glyphs = [ ] for c in str(s): eaw = unicodedata.east_asian_width(c) if (eaw == "F") or (eaw == "W"): gwidth = 20 elif (eaw == "A"): if asian: gwidth = 20 else: gwidth = 10 else: gwidth = 10 g = textsupport.Glyph() g.character = ord(c) g.ascent = 10 g.line_spacing = 10 g.width = gwidth g.advance = gwidth glyphs.append(g) textsupport.annotate_unicode(glyphs, False, 2) renpy.text.texwrap.linebreak_tex(glyphs, width * 10, width * 10, False) return textsupport.linebreak_list(glyphs)
def __init__(self, ts, d, renders): """ `ts` The text segment that this SpaceSegment follows. """ self.d = d rend = renders[d] w, h = rend.get_size() self.glyph = glyph = textsupport.Glyph() glyph.character = 0 glyph.ascent = 0 glyph.line_spacing = h glyph.advance = w glyph.width = w if ts.hyperlink: glyph.hyperlink = ts.hyperlink self.cps = ts.cps