ThirdParty/Pygments/pygments/formatters/img.py

changeset 12
1d8dd9706f46
parent 0
de9c2efb9d02
child 684
2f29a0b6e1c7
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import sys 12 import sys
13 from commands import getstatusoutput 13 from subprocess import getstatusoutput
14 14
15 from pygments.formatter import Formatter 15 from pygments.formatter import Formatter
16 from pygments.util import get_bool_opt, get_int_opt, get_choice_opt 16 from pygments.util import get_bool_opt, get_int_opt, get_choice_opt
17 17
18 # Import this carefully 18 # Import this carefully
21 pil_available = True 21 pil_available = True
22 except ImportError: 22 except ImportError:
23 pil_available = False 23 pil_available = False
24 24
25 try: 25 try:
26 import _winreg 26 import winreg
27 except ImportError: 27 except ImportError:
28 _winreg = None 28 _winreg = None
29 29
30 __all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter', 30 __all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter',
31 'BmpImageFormatter'] 31 'BmpImageFormatter']
104 def _lookup_win(self, key, basename, styles, fail=False): 104 def _lookup_win(self, key, basename, styles, fail=False):
105 for suffix in ('', ' (TrueType)'): 105 for suffix in ('', ' (TrueType)'):
106 for style in styles: 106 for style in styles:
107 try: 107 try:
108 valname = '%s%s%s' % (basename, style and ' '+style, suffix) 108 valname = '%s%s%s' % (basename, style and ' '+style, suffix)
109 val, _ = _winreg.QueryValueEx(key, valname) 109 val, _ = winreg.QueryValueEx(key, valname)
110 return val 110 return val
111 except EnvironmentError: 111 except EnvironmentError:
112 continue 112 continue
113 else: 113 else:
114 if fail: 114 if fail:
116 (basename, styles[0])) 116 (basename, styles[0]))
117 return None 117 return None
118 118
119 def _create_win(self): 119 def _create_win(self):
120 try: 120 try:
121 key = _winreg.OpenKey( 121 key = winreg.OpenKey(
122 _winreg.HKEY_LOCAL_MACHINE, 122 winreg.HKEY_LOCAL_MACHINE,
123 r'Software\Microsoft\Windows NT\CurrentVersion\Fonts') 123 r'Software\Microsoft\Windows NT\CurrentVersion\Fonts')
124 except EnvironmentError: 124 except EnvironmentError:
125 try: 125 try:
126 key = _winreg.OpenKey( 126 key = winreg.OpenKey(
127 _winreg.HKEY_LOCAL_MACHINE, 127 winreg.HKEY_LOCAL_MACHINE,
128 r'Software\Microsoft\Windows\CurrentVersion\Fonts') 128 r'Software\Microsoft\Windows\CurrentVersion\Fonts')
129 except EnvironmentError: 129 except EnvironmentError:
130 raise FontNotFound('Can\'t open Windows font registry key') 130 raise FontNotFound('Can\'t open Windows font registry key')
131 try: 131 try:
132 path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True) 132 path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True)
139 if style == 'BOLDITALIC': 139 if style == 'BOLDITALIC':
140 self.fonts[style] = self.fonts['BOLD'] 140 self.fonts[style] = self.fonts['BOLD']
141 else: 141 else:
142 self.fonts[style] = self.fonts['NORMAL'] 142 self.fonts[style] = self.fonts['NORMAL']
143 finally: 143 finally:
144 _winreg.CloseKey(key) 144 winreg.CloseKey(key)
145 145
146 def get_char_size(self): 146 def get_char_size(self):
147 """ 147 """
148 Get the character size. 148 Get the character size.
149 """ 149 """
424 """ 424 """
425 Create drawables for the line numbers. 425 Create drawables for the line numbers.
426 """ 426 """
427 if not self.line_numbers: 427 if not self.line_numbers:
428 return 428 return
429 for i in xrange(self.maxlineno): 429 for i in range(self.maxlineno):
430 if ((i + 1) % self.line_number_step) == 0: 430 if ((i + 1) % self.line_number_step) == 0:
431 self._draw_linenumber(i) 431 self._draw_linenumber(i)
432 432
433 def _paint_line_number_bg(self, im): 433 def _paint_line_number_bg(self, im):
434 """ 434 """

eric ide

mercurial