aafigure fails to run examples : missing font files cause breakage

Bug #392949 reported by Todd
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
aafigure
Fix Released
Medium
Oliver Joos

Bug Description

I have reproduced this error w/ both the installed debian package, and syncing via bzr and installing from source. Apparently, this is a known issue, mentioned in the code for aafigure/pil.py. The problem is that aafigure is not using a very sound method of finding font files. By default, pil.py is configured to look for Courier_New.ttf. However, on my ubuntu jaunty install, I do not have that font. So, PIL throws when it is asked to load a non-existent font. I hacked a font into aafigure/pil.py in order to verify that referencing an extant font file solves this problem, and it does.

INSTALL METHODS:
--------------------------
1. download and install this deb: https://launchpad.net/~aafigure-team/+archive/ppa/+files/python-aafigure_0.3_all.deb
2. bzr branch https://launchpad.net/aafigure; cd aafigure; sudo python setup.py install

REPRO:
----------
1. ~/sandbox/aafigure/aafigure/examples$ aafigure fill.txt -o test.png
2. Error getting font, or somesuch:

>>> File "/usr/lib/python2.6/dist-packages/PIL/ImageFont.py", line 121, in __init__
>>> self.font = _imagingft.getfont(file, size, index, encoding)
>>> IOError: cannot open resource

STACKTRACE:
------------------
Traceback (most recent call last):
  File "/usr/local/bin/aafigure", line 7, in <module>
    aafigure.aafigure.main()
  File "/usr/local/lib/python2.6/dist-packages/aafigure/aafigure.py", line 1067, in main
    (visitor, output) = render(input, output, options_dict)
  File "/usr/local/lib/python2.6/dist-packages/aafigure/aafigure.py", line 896, in render
    visitor = process(input, visitor_class, options)
  File "/usr/local/lib/python2.6/dist-packages/aafigure/aafigure.py", line 836, in process
    visitor.visit_image(aaimg)
  File "/usr/local/lib/python2.6/dist-packages/aafigure/pil.py", line 66, in visit_image
    self.visit_shapes(aa_image.shapes)
  File "/usr/local/lib/python2.6/dist-packages/aafigure/pil.py", line 82, in visit_shapes
    getattr(self, visitor_name)(shape)
  File "/usr/local/lib/python2.6/dist-packages/aafigure/pil.py", line
 88, in visit_group
    self.visit_shapes(group.shapes)
  File "/usr/local/lib/python2.6/dist-packages/aafigure/pil.py", line 82, in visit_shapes
    getattr(self, visitor_name)(shape)
  File "/usr/local/lib/python2.6/dist-packages/aafigure/pil.py", line 141, in visit_label
    font=ImageFont.truetype(self.font, int(self.aa_image.nominal_size*1.1*self.scale))
  File "/usr/lib/python2.6/dist-packages/PIL/ImageFont.py", line 205, in truetype
    return FreeTypeFont(filename, size, index, encoding)
  File "/usr/lib/python2.6/dist-packages/PIL/ImageFont.py", line 121, in __init__
    self.font = _imagingft.getfont(file, size, index, encoding)
IOError: cannot open resource

HACK:
#/usr/local/lib/python2.6/dist-packages/aafigure/pil.py

 20 class PILOutputVisitor:
 21 """Render a list of shapes as bitmap.
 22 """
 23
HOST DETAILS:

 24 def __init__(self, options):
 25 self.options = options
 26 self.scale = options['scale']*8
 27 self.debug = options['debug']
 28 self.line_width = options['line_width']
 29 self.foreground = options['foreground']
 30 self.background = options['background']
 31 self.fillcolor = options['fill']
 32 # if front is given explicit, use it instead of textual/proportional flags
 33 if 'font' in options:
 34 self.font = options['font']
 35 else:
 36 # XXX find a good way to locate font files... as the following does not
 37 # work on all platforms
 38 if options['proportional']:
 39 self.font = 'Arial.ttf'
 40 else:
 41 #self.font = 'Courier_New.ttf' # original code, broken, as I don't have this font
 42 #self.font = 'ae_AlMohanad.ttf' # referencing extant font by name, also broken
 43 self.font = '/usr/share/fonts/truetype/ttf-arabeyes/ae_AlMohanad.ttf' # referencing extant font by fully qualified path works

SIMILAR BUGS:
 * http://trac-hacks.org/ticket/3367
 * http://trac-hacks.org/ticket/3368

Tags: font

Related branches

Revision history for this message
luca (llucax) wrote :

I think this is a known PIL issue. As a workarround you can use the new -O command line option to pass a custom font to the PIL backend.

This should work for you:

aafigure fill.txt -o test.png -O font=/usr/share/fonts/truetype/ttf-arabeyes/ae_AlMohanad.ttf

Changed in aafigure:
importance: Undecided → Medium
status: New → Confirmed
Changed in aafigure:
assignee: nobody → Oliver Joos (oliver-joos)
Changed in aafigure:
status: Confirmed → Fix Committed
milestone: none → 0.5
Changed in aafigure:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.