--- a/eric6/ThirdParty/Pygments/pygments/formatters/img.py Tue Apr 21 19:44:19 2020 +0200 +++ b/eric6/ThirdParty/Pygments/pygments/formatters/img.py Tue Apr 21 19:47:10 2020 +0200 @@ -5,7 +5,7 @@ Formatter for Pixmap output. - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ @@ -14,7 +14,7 @@ from pygments.formatter import Formatter from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \ - get_choice_opt, xrange + get_choice_opt import subprocess @@ -46,9 +46,9 @@ } # A sane default for modern systems -DEFAULT_FONT_NAME_NIX = 'Bitstream Vera Sans Mono' +DEFAULT_FONT_NAME_NIX = 'DejaVu Sans Mono' DEFAULT_FONT_NAME_WIN = 'Courier New' -DEFAULT_FONT_NAME_MAC = 'Courier New' +DEFAULT_FONT_NAME_MAC = 'Menlo' class PilNotAvailable(ImportError): @@ -59,7 +59,7 @@ """When there are no usable fonts specified""" -class FontManager(object): +class FontManager: """ Manages a set of fonts: normal, italic, bold, etc... """ @@ -125,8 +125,8 @@ for font_dir in (os.path.join(os.getenv("HOME"), 'Library/Fonts/'), '/Library/Fonts/', '/System/Library/Fonts/'): font_map.update( - ((os.path.splitext(f)[0].lower(), os.path.join(font_dir, f)) - for f in os.listdir(font_dir) if f.lower().endswith('ttf'))) + (os.path.splitext(f)[0].lower(), os.path.join(font_dir, f)) + for f in os.listdir(font_dir) if f.lower().endswith('ttf')) for name in STYLES['NORMAL']: path = self._get_mac_font_path(font_map, self.font_name, name) @@ -164,31 +164,43 @@ return None def _create_win(self): - try: - key = _winreg.OpenKey( - _winreg.HKEY_LOCAL_MACHINE, - r'Software\Microsoft\Windows NT\CurrentVersion\Fonts') - except EnvironmentError: + lookuperror = None + keynames = [ (_winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows NT\CurrentVersion\Fonts'), + (_winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Fonts'), + (_winreg.HKEY_LOCAL_MACHINE, r'Software\Microsoft\Windows NT\CurrentVersion\Fonts'), + (_winreg.HKEY_LOCAL_MACHINE, r'Software\Microsoft\Windows\CurrentVersion\Fonts') ] + for keyname in keynames: try: - key = _winreg.OpenKey( - _winreg.HKEY_LOCAL_MACHINE, - r'Software\Microsoft\Windows\CurrentVersion\Fonts') + key = _winreg.OpenKey(*keyname) + try: + path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True) + self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size) + for style in ('ITALIC', 'BOLD', 'BOLDITALIC'): + path = self._lookup_win(key, self.font_name, STYLES[style]) + if path: + self.fonts[style] = ImageFont.truetype(path, self.font_size) + else: + if style == 'BOLDITALIC': + self.fonts[style] = self.fonts['BOLD'] + else: + self.fonts[style] = self.fonts['NORMAL'] + return + except FontNotFound as err: + lookuperror = err + finally: + _winreg.CloseKey(key) except EnvironmentError: - raise FontNotFound('Can\'t open Windows font registry key') - try: - path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True) - self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size) - for style in ('ITALIC', 'BOLD', 'BOLDITALIC'): - path = self._lookup_win(key, self.font_name, STYLES[style]) - if path: - self.fonts[style] = ImageFont.truetype(path, self.font_size) - else: - if style == 'BOLDITALIC': - self.fonts[style] = self.fonts['BOLD'] - else: - self.fonts[style] = self.fonts['NORMAL'] - finally: - _winreg.CloseKey(key) + pass + else: + # If we get here, we checked all registry keys and had no luck + # We can be in one of two situations now: + # * All key lookups failed. In this case lookuperror is None and we + # will raise a generic error + # * At least one lookup failed with a FontNotFound error. In this + # case, we will raise that as a more specific error + if lookuperror: + raise lookuperror + raise FontNotFound('Can\'t open Windows font registry key') def get_char_size(self): """ @@ -237,7 +249,8 @@ bold and italic fonts will be generated. This really should be a monospace font to look sane. - Default: "Bitstream Vera Sans Mono" on Windows, Courier New on \\*nix + Default: "Courier New" on Windows, "Menlo" on Mac OS, and + "DejaVu Sans Mono" on \\*nix `font_size` The font size in points to be used. @@ -503,7 +516,7 @@ """ if not self.line_numbers: return - for p in xrange(self.maxlineno): + for p in range(self.maxlineno): n = p + self.line_number_start if (n % self.line_number_step) == 0: self._draw_linenumber(p, n) @@ -521,7 +534,8 @@ rectw = self.image_pad + self.line_number_width - self.line_number_pad draw.rectangle([(0, 0), (rectw, recth)], fill=self.line_number_bg) - draw.line([(rectw, 0), (rectw, recth)], fill=self.line_number_fg) + if self.line_number_separator: + draw.line([(rectw, 0), (rectw, recth)], fill=self.line_number_fg) del draw def format(self, tokensource, outfile):