remove support for default font, as it doesn't support unicode, and implement a 1px line spacing for format_png
authorTero Marttila <terom@fixme.fi>
Sat, 14 Feb 2009 17:59:13 +0200
changeset 124 4bc4de14f006
parent 123 3297596ab606
child 125 45e56cbf9086
remove support for default font, as it doesn't support unicode, and implement a 1px line spacing for format_png
config.py
log_formatter_pil.py
--- a/config.py	Fri Feb 13 01:18:28 2009 +0200
+++ b/config.py	Sat Feb 14 17:59:13 2009 +0200
@@ -73,7 +73,8 @@
 
 # TTF fonts to use for drawing images
 FORMATTER_IMAGE_FONTS =         {
-    'default':              (None,                                                                  "Ugly default font"         ),
+    # XXX: no unicode support
+    #    'default':              (None,                                                                  "Ugly default font"         ),
     'ttf-dejavu-mono':      ("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf",             "DejaVu Sans Mono"          ),
     'ttf-liberation-mono':  ("/usr/share/fonts/truetype/ttf-liberation/LiberationMono-Regular.ttf", "Liberation Mono Regular"   )
 }
@@ -91,8 +92,8 @@
 PREF_FORMATTER_DEFAULT          = IrssiFormatter
 PREF_COUNT_DEFAULT              = 200
 PREF_COUNT_MAX                  = None
-PREF_IMAGE_FONT_DEFAULT         = 'default'
-PREF_IMAGE_FONT_SIZE_DEFAULT    = 10
+PREF_IMAGE_FONT_DEFAULT         = 'ttf-dejavu-mono'
+PREF_IMAGE_FONT_SIZE_DEFAULT    = 12
 PREF_IMAGE_FONT_SIZE_MAX        = 32
 
 # search line count options
--- a/log_formatter_pil.py	Fri Feb 13 01:18:28 2009 +0200
+++ b/log_formatter_pil.py	Sat Feb 14 17:59:13 2009 +0200
@@ -14,6 +14,9 @@
     # the font we load
     font = None
 
+    # line spacing in pixels
+    LINE_SPACING = 1
+
     def _load_font (self) :
         """
             Use the configured img_ttf_path for a TrueType font, or a default one
@@ -33,6 +36,10 @@
         return self.font
 
     def format_png (self, lines, **kwargs) :
+        """
+            Build and return a PNG image of the given lines, using format_txt
+        """
+
         # load font
         font = self._load_font()
 
@@ -44,7 +51,7 @@
 
         # figure out how wide/high the image will be
         width = max(width for width, height in line_sizes)
-        height = sum(height for width, height in line_sizes)
+        height = sum(height + self.LINE_SPACING for width, height in line_sizes)
 
         # create new B/W image
         img = Image.new('L', (width, height), 0xff)
@@ -61,7 +68,7 @@
             draw.text((0, offset_y), line, font=font)
 
             # next offset
-            offset_y += height
+            offset_y += height + self.LINE_SPACING
         
         # output buffer
         buf = StringIO()