Commits

gbrandl  committed 4ab4c10

Added `line_number_start` option to image formatter (#456).

  • Participants
  • Parent commits 72c615d
  • Branches trunk

Comments (0)

Files changed (3)

 build/*
 dist/*
 Pygments.egg-info/*
+.ropeproject
 
 - 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).
 

File pygments/formatters/img.py

 
         Default: True
 
+    `line_number_start`
+        The line number of the first line.
+
+        Default: 1
+
     `line_number_step`
         The step used when printing line numbers.
 
         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)
         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,
         """
         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):
         """