diff options
-rw-r--r-- | .hgignore | 1 | ||||
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | pygments/formatters/img.py | 19 |
3 files changed, 16 insertions, 6 deletions
@@ -5,3 +5,4 @@ syntax: glob build/* dist/* Pygments.egg-info/* +.ropeproject @@ -18,6 +18,8 @@ Version 1.2 - Updated the Logtalk lexer. +- Added `line_number_start` option to image formatter (#456). + - Fixed the HtmlFormatter's handling of noclasses=True to not output any classes (#427). diff --git a/pygments/formatters/img.py b/pygments/formatters/img.py index 91bf5179..a22a71e2 100644 --- a/pygments/formatters/img.py +++ b/pygments/formatters/img.py @@ -207,6 +207,11 @@ class ImageFormatter(Formatter): Default: True + `line_number_start` + The line number of the first line. + + Default: 1 + `line_number_step` The step used when printing line numbers. @@ -299,6 +304,7 @@ class ImageFormatter(Formatter): self.line_number_separator = get_bool_opt(options, 'line_number_separator', True) self.line_number_step = get_int_opt(options, 'line_number_step', 1) + self.line_number_start = get_int_opt(options, 'line_number_start', 1) if self.line_numbers: self.line_number_width = (self.fontw * self.line_number_chars + self.line_number_pad * 2) @@ -369,13 +375,13 @@ class ImageFormatter(Formatter): return (self._get_char_x(maxcharno) + self.image_pad, self._get_line_y(maxlineno + 0) + self.image_pad) - def _draw_linenumber(self, lineno): + def _draw_linenumber(self, posno, lineno): """ Remember a line number drawable to paint later. """ self._draw_text( - self._get_linenumber_pos(lineno), - str(lineno + 1).rjust(self.line_number_chars), + self._get_linenumber_pos(posno), + str(lineno).rjust(self.line_number_chars), font=self.fonts.get_font(self.line_number_bold, self.line_number_italic), fill=self.line_number_fg, @@ -426,9 +432,10 @@ class ImageFormatter(Formatter): """ if not self.line_numbers: return - for i in xrange(self.maxlineno): - if ((i + 1) % self.line_number_step) == 0: - self._draw_linenumber(i) + for p in xrange(self.maxlineno): + n = p + self.line_number_start + if (n % self.line_number_step) == 0: + self._draw_linenumber(p, n) def _paint_line_number_bg(self, im): """ |