usr bin env python Making PyRTF be russian-aware PyRuRTF py This libra

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
"""
Making PyRTF be russian-aware ;-)
"""
# PyRuRTF.py
#
# This library is free software; you can redistribute
# it and/or modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation version 2.1 of the License.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# (c) 2008, Yury Yurevich (http://www,pyobject.ru)
from PyRTF import *
russianFontsAreSet = False
def setRussianFonts():
for font in StandardFonts:
if font.Name != 'Symbol':
font.SetCharacterSet(204)
class RussianDocument(Document):
def __init__(self, *args, **kwargs):
if 'default_language' not in kwargs or len(args) < 3:
# default_language is a third positional arg,
# so if it is in args, we don't want to override it
kwargs['default_language'] = Languages.Russian
global russianFontsAreSet
if not russianFontsAreSet:
setRussianFonts()
russianFontsAreSet = True
Document.__init__(self, *args, **kwargs)
class RussianRenderer(Renderer):
def _WriteDocument(self) :
settings = Settings()
assert Languages.IsValid(self._doc.DefaultLanguage)
assert ViewKind.IsValid(self._doc.ViewKind)
assert ViewZoomKind.IsValid(self._doc.ViewZoomKind)
assert ViewScale.IsValid(self._doc.ViewScale)
settings.append(self._doc.DefaultLanguage, 'deflang%s')
settings.append(self._doc.ViewKind , 'viewkind%s')
settings.append(self._doc.ViewZoomKind, 'viewzk%s')
settings.append(self._doc.ViewScale, 'viewscale%s')
self._write("{\\rtf1\\ansi\\ansicpg1251\\deff0%s\n" % settings)