3 pygments.formatters.img |
3 pygments.formatters.img |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Formatter for Pixmap output. |
6 Formatter for Pixmap output. |
7 |
7 |
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2015 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 |
13 |
14 from pygments.formatter import Formatter |
14 from pygments.formatter import Formatter |
15 from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \ |
15 from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \ |
16 get_choice_opt, xrange |
16 get_choice_opt, xrange |
|
17 |
|
18 import subprocess |
17 |
19 |
18 # Import this carefully |
20 # Import this carefully |
19 try: |
21 try: |
20 from PIL import Image, ImageDraw, ImageFont |
22 from PIL import Image, ImageDraw, ImageFont |
21 pil_available = True |
23 pil_available = True |
73 if not font_name: |
75 if not font_name: |
74 self.font_name = DEFAULT_FONT_NAME_NIX |
76 self.font_name = DEFAULT_FONT_NAME_NIX |
75 self._create_nix() |
77 self._create_nix() |
76 |
78 |
77 def _get_nix_font_path(self, name, style): |
79 def _get_nix_font_path(self, name, style): |
78 try: |
80 proc = subprocess.Popen(['fc-list', "%s:style=%s" % (name, style), 'file'], |
79 from commands import getstatusoutput |
81 stdout=subprocess.PIPE, stderr=None) |
80 except ImportError: |
82 stdout, _ = proc.communicate() |
81 from subprocess import getstatusoutput |
83 if proc.returncode == 0: |
82 exit, out = getstatusoutput('fc-list "%s:style=%s" file' % |
84 lines = stdout.splitlines() |
83 (name, style)) |
|
84 if not exit: |
|
85 lines = out.splitlines() |
|
86 if lines: |
85 if lines: |
87 path = lines[0].strip().strip(':') |
86 path = lines[0].decode().strip().strip(':') |
88 return path |
87 return path |
89 |
88 |
90 def _create_nix(self): |
89 def _create_nix(self): |
91 for name in STYLES['NORMAL']: |
90 for name in STYLES['NORMAL']: |
92 path = self._get_nix_font_path(self.font_name, name) |
91 path = self._get_nix_font_path(self.font_name, name) |
195 `font_name` |
194 `font_name` |
196 The font name to be used as the base font from which others, such as |
195 The font name to be used as the base font from which others, such as |
197 bold and italic fonts will be generated. This really should be a |
196 bold and italic fonts will be generated. This really should be a |
198 monospace font to look sane. |
197 monospace font to look sane. |
199 |
198 |
200 Default: "Bitstream Vera Sans Mono" |
199 Default: "Bitstream Vera Sans Mono" on Windows, Courier New on \*nix |
201 |
200 |
202 `font_size` |
201 `font_size` |
203 The font size in points to be used. |
202 The font size in points to be used. |
204 |
203 |
205 Default: 14 |
204 Default: 14 |