QScintilla/Exporters/ExporterTEX.py

changeset 25
5163e6f94ba5
parent 13
1af94a91f439
child 45
9a18f4dbb493
equal deleted inserted replaced
24:9233b51b54d1 25:5163e6f94ba5
65 if style == 0: 65 if style == 0:
66 buf = "a" 66 buf = "a"
67 else: 67 else:
68 while style > 0: 68 while style > 0:
69 buf += chr(ord('a') + (style % self.CHARZ)) 69 buf += chr(ord('a') + (style % self.CHARZ))
70 style /= self.CHARZ 70 style //= self.CHARZ
71 return buf 71 return buf
72 72
73 def __defineTexStyle(self, font, color, paper, file, istyle): 73 def __defineTexStyle(self, font, color, paper, file, istyle):
74 """ 74 """
75 Private method to define a new TeX style. 75 Private method to define a new TeX style.
191 styleCurrent = self.editor.styleAt(0) 191 styleCurrent = self.editor.styleAt(0)
192 f.write("\\eric%s{" % self.__texStyle(styleCurrent)) 192 f.write("\\eric%s{" % self.__texStyle(styleCurrent))
193 193
194 lineIdx = 0 194 lineIdx = 0
195 pos = 0 195 pos = 0
196 utf8 = self.editor.isUtf8()
197 utf8Ch = b""
198 utf8Len = 0
196 199
197 while pos < lengthDoc: 200 while pos < lengthDoc:
198 ch = self.editor.rawCharAt(pos) 201 ch = self.editor.byteAt(pos)
199 style = self.editor.styleAt(pos) 202 style = self.editor.styleAt(pos)
200 if style != styleCurrent: 203 if style != styleCurrent:
201 # new style 204 # new style
202 f.write("}\n\\eric%s{" % self.__texStyle(style)) 205 f.write("}\n\\eric%s{" % self.__texStyle(style))
203 styleCurrent = style 206 styleCurrent = style
204 207
205 if ch == '\t': 208 if ch == b'\t':
206 ts = tabSize - (lineIdx % tabSize) 209 ts = tabSize - (lineIdx % tabSize)
207 lineIdx += ts - 1 210 lineIdx += ts - 1
208 f.write("\\hspace*{%dem}" % ts) 211 f.write("\\hspace*{%dem}" % ts)
209 elif ch == '\\': 212 elif ch == b'\\':
210 f.write("{\\textbackslash}") 213 f.write("{\\textbackslash}")
211 elif ch in ['>', '<', '@']: 214 elif ch in [b'>', b'<', b'@']:
212 f.write("$%c$" % ch) 215 f.write("$%c$" % ch[0])
213 elif ch in ['{', '}', '^', '_', '&', '$', '#', '%', '~']: 216 elif ch in [b'{', b'}', b'^', b'_', b'&', b'$', b'#', b'%', b'~']:
214 f.write("\\%c" % ch) 217 f.write("\\%c" % ch[0])
215 elif ch in ['\r', '\n']: 218 elif ch in [b'\r', b'\n']:
216 lineIdx = -1 # because incremented below 219 lineIdx = -1 # because incremented below
217 if ch == '\r' and self.editor.rawCharAt(pos + 1) == '\n': 220 if ch == b'\r' and self.editor.byteAt(pos + 1) == b'\n':
218 pos += 1 # skip the LF 221 pos += 1 # skip the LF
219 styleCurrent = self.editor.styleAt(pos + 1) 222 styleCurrent = self.editor.styleAt(pos + 1)
220 f.write("} \\\\\n\\eric%s{" % self.__texStyle(styleCurrent)) 223 f.write("} \\\\\n\\eric%s{" % self.__texStyle(styleCurrent))
221 elif ch == ' ': 224 elif ch == b' ':
222 if self.editor.rawCharAt(pos + 1) == ' ': 225 if self.editor.byteAt(pos + 1) == b' ':
223 f.write("{\\hspace*{1em}}") 226 f.write("{\\hspace*{1em}}")
224 else: 227 else:
225 f.write(' ') 228 f.write(' ')
226 else: 229 else:
227 f.write(ch) 230 if ord(ch) > 127 and utf8:
231 utf8Ch += ch
232 if utf8Len == 0:
233 if (utf8Ch[0] & 0xF0) == 0xF0:
234 utf8Len = 4
235 elif (utf8Ch[0] & 0xE0) == 0xE0:
236 utf8Len = 3
237 elif (utf8Ch[0] & 0xC0) == 0xC0:
238 utf8Len = 2
239 elif len(utf8Ch) == utf8Len:
240 ch = utf8Ch.decode('utf8')
241 f.write(ch)
242 utf8Ch = b""
243 utf8Len = 0
244 else:
245 f.write(ch.decode())
228 lineIdx += 1 246 lineIdx += 1
229 pos += 1 247 pos += 1
230 248
231 # close last empty style macros and document too 249 # close last empty style macros and document too
232 f.write("}\n} %end tiny\n\n\\end{document}\n") 250 f.write("}\n} %end tiny\n\n\\end{document}\n")

eric ide

mercurial