Receive a textual description of the glyph and encode into a format understood by GlyphCoordinate.render().
(self, img)
| 75 | self.alt_data, alt_w, alt_h = self._encode_glyph(alt) |
| 76 | |
| 77 | def _encode_glyph(self, img): |
| 78 | """Receive a textual description of the glyph and |
| 79 | encode into a format understood by |
| 80 | GlyphCoordinate.render(). |
| 81 | |
| 82 | """ |
| 83 | img = re.sub(r"^\n", "", textwrap.dedent(img)) |
| 84 | color = "W" |
| 85 | lines = [line.rstrip() for line in img.split("\n")] |
| 86 | data = [] |
| 87 | for line in lines: |
| 88 | render_line = [] |
| 89 | line = list(line) |
| 90 | while line: |
| 91 | char = line.pop(0) |
| 92 | if char == "#": |
| 93 | color = line.pop(0) |
| 94 | continue |
| 95 | render_line.append((color, char)) |
| 96 | data.append(render_line) |
| 97 | width = max([len(rl) for rl in data]) |
| 98 | data = "".join( |
| 99 | "".join("%s%s" % (color, char) for color, char in render_line) |
| 100 | + ("W " * (width - len(render_line))) |
| 101 | for render_line in data |
| 102 | ) |
| 103 | return data, width, len(lines) |
| 104 | |
| 105 | def glyph_for_state(self, coord, state): |
| 106 | """Return the appropriate data representation |