|
21 | 21 |
|
22 | 22 | import numpy as np |
23 | 23 |
|
24 | | -from matplotlib import cbook, __version__, rcParams |
| 24 | +from matplotlib import _text_layout, cbook, __version__, rcParams |
25 | 25 | from matplotlib._pylab_helpers import Gcf |
26 | 26 | from matplotlib.backend_bases import ( |
27 | 27 | _Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase, |
@@ -2176,52 +2176,46 @@ def draw_text_woven(chunks): |
2176 | 2176 | -math.sin(a), math.cos(a), |
2177 | 2177 | x, y, Op.concat_matrix) |
2178 | 2178 |
|
2179 | | - # Output all the 1-byte characters in a BT/ET group, then |
2180 | | - # output all the 2-byte characters. |
2181 | | - for mode in (1, 2): |
2182 | | - newx = oldx = 0 |
2183 | | - # Output a 1-byte character chunk |
2184 | | - if mode == 1: |
2185 | | - self.file.output(Op.begin_text, |
2186 | | - self.file.fontName(prop), |
2187 | | - fontsize, |
2188 | | - Op.selectfont) |
2189 | | - |
2190 | | - for chunk_type, chunk in chunks: |
2191 | | - if mode == 1 and chunk_type == 1: |
2192 | | - self._setup_textpos(newx, 0, 0, oldx, 0, 0) |
2193 | | - self.file.output(self.encode_string(chunk, fonttype), |
2194 | | - Op.show) |
2195 | | - oldx = newx |
2196 | | - |
2197 | | - lastgind = None |
2198 | | - for c in chunk: |
2199 | | - ccode = ord(c) |
2200 | | - gind = font.get_char_index(ccode) |
2201 | | - if mode == 2 and chunk_type == 2: |
2202 | | - glyph_name = font.get_glyph_name(gind) |
2203 | | - self.file.output(Op.gsave) |
2204 | | - self.file.output(0.001 * fontsize, 0, |
2205 | | - 0, 0.001 * fontsize, |
2206 | | - newx, 0, Op.concat_matrix) |
2207 | | - name = self.file._get_xobject_symbol_name( |
2208 | | - font.fname, glyph_name) |
2209 | | - self.file.output(Name(name), Op.use_xobject) |
2210 | | - self.file.output(Op.grestore) |
2211 | | - |
2212 | | - # Move the pointer based on the character width |
2213 | | - # and kerning |
2214 | | - glyph = font.load_char(ccode, flags=LOAD_NO_HINTING) |
2215 | | - if lastgind is not None: |
2216 | | - kern = font.get_kerning( |
2217 | | - lastgind, gind, KERNING_UNFITTED) |
2218 | | - else: |
2219 | | - kern = 0 |
2220 | | - lastgind = gind |
2221 | | - newx += kern / 64 + glyph.linearHoriAdvance / 65536 |
2222 | | - |
2223 | | - if mode == 1: |
2224 | | - self.file.output(Op.end_text) |
| 2179 | + # Output all the 1-byte characters in a BT/ET group. |
| 2180 | + self.file.output(Op.begin_text, |
| 2181 | + self.file.fontName(prop), |
| 2182 | + fontsize, |
| 2183 | + Op.selectfont) |
| 2184 | + newx = oldx = 0 |
| 2185 | + for chunk_type, chunk in chunks: |
| 2186 | + if chunk_type == 1: |
| 2187 | + self._setup_textpos(newx, 0, 0, oldx, 0, 0) |
| 2188 | + self.file.output(self.encode_string(chunk, fonttype), |
| 2189 | + Op.show) |
| 2190 | + oldx = newx |
| 2191 | + # Update newx to include the advance from this chunk, |
| 2192 | + # regardless of its mode... |
| 2193 | + for char_idx, char_x in _text_layout.layout( |
| 2194 | + chunk, font, x0=newx, kern_mode=KERNING_UNFITTED): |
| 2195 | + pass |
| 2196 | + newx = char_x + ( # ... including the last character's advance |
| 2197 | + font.load_glyph(char_idx, flags=LOAD_NO_HINTING) |
| 2198 | + .linearHoriAdvance / 65536) |
| 2199 | + self.file.output(Op.end_text) |
| 2200 | + |
| 2201 | + # Then output all the 2-byte characters. |
| 2202 | + newx = 0 |
| 2203 | + for chunk_type, chunk in chunks: |
| 2204 | + for char_idx, char_x in _text_layout.layout( |
| 2205 | + chunk, font, x0=newx, kern_mode=KERNING_UNFITTED): |
| 2206 | + if chunk_type == 2: |
| 2207 | + glyph_name = font.get_glyph_name(char_idx) |
| 2208 | + self.file.output(Op.gsave) |
| 2209 | + self.file.output(0.001 * fontsize, 0, |
| 2210 | + 0, 0.001 * fontsize, |
| 2211 | + char_x, 0, Op.concat_matrix) |
| 2212 | + name = self.file._get_xobject_symbol_name( |
| 2213 | + font.fname, glyph_name) |
| 2214 | + self.file.output(Name(name), Op.use_xobject) |
| 2215 | + self.file.output(Op.grestore) |
| 2216 | + newx = char_x + ( # ... including the last character's advance |
| 2217 | + font.load_glyph(char_idx, flags=LOAD_NO_HINTING) |
| 2218 | + .linearHoriAdvance / 65536) |
2225 | 2219 |
|
2226 | 2220 | self.file.output(Op.grestore) |
2227 | 2221 |
|
|
0 commit comments