Merge lp:~oliver-joos/aafigure/olivers into lp:aafigure

Proposed by Oliver Joos on 2010-03-01
Status: Rejected
Rejected by: zsquareplusc on 2010-05-14
Proposed branch: lp:~oliver-joos/aafigure/olivers
Merge into: lp:aafigure
Diff against target: 96 lines (+31/-11)
2 files modified
aafigure/pil.py (+29/-6)
aafigure/svg.py (+2/-5)
To merge this branch: bzr merge lp:~oliver-joos/aafigure/olivers
Reviewer Review Type Date Requested Status
zsquareplusc 2010-03-01 Disapprove on 2010-03-27
Review via email: mp+20333@code.launchpad.net

Commit message

To post a comment you must log in.
Oliver Joos (oliver-joos) wrote :

rev111: Under Linux search fonts in /usr/share/fonts recursively
rev112: Fix for bug #529409

zsquareplusc (zsquareplusc) wrote :

please make separate patches for the SVG and font problem. The SVG patch seem to be OK. Not reporting when the font is not found is not.

review: Needs Fixing
zsquareplusc (zsquareplusc) wrote :

feature is now implemented, patch is obsolete

review: Disapprove

Unmerged revisions

113. By Oliver Joos on 2011-02-07

New icon files added, small enough to be used as button label or favicon

112. By Oliver <oliver@oliverhp> on 2010-03-01

Omit width="100%" and height="100%" to make non-standard SVG viewers happy.

111. By Oliver <oliver@oliverhp> on 2010-03-01

Under Linux search for the fonts in /usr/share/fonts recursively. Use hard-coded default font of PIL if not found.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'aafigure/pil.py'
2--- aafigure/pil.py 2009-12-13 03:02:52 +0000
3+++ aafigure/pil.py 2010-03-01 03:11:11 +0000
4@@ -8,6 +8,7 @@
5 """
6
7 import sys
8+import os
9 from error import UnsupportedFormatError
10 PIL_OK = False
11 try:
12@@ -21,6 +22,15 @@
13 except ImportError:
14 raise UnsupportedFormatError('please install PIL to get bitmaps output support')
15
16+def _find_file(name, top_dir):
17+ """Find a file by its name in a directory or its sub-directories.
18+ Return absolut path of the file or None if not found.
19+ """
20+ for (dirpath, dirnames, filenames) in os.walk(top_dir):
21+ if name in filenames:
22+ return os.path.join(dirpath, name)
23+ return None
24+
25
26 class PILOutputVisitor:
27 """Render a list of shapes as bitmap.
28@@ -36,14 +46,12 @@
29 self.fillcolor = options['fill']
30 # if front is given explicit, use it instead of textual/proportional flags
31 if 'font' in options:
32- self.font = options['font']
33+ self.font_name = options['font']
34 else:
35- # XXX find a good way to locate font files... as the following does not
36- # work on all platforms
37 if options['proportional']:
38- self.font = 'Arial.ttf'
39+ self.font_name = 'Arial.ttf'
40 else:
41- self.font = 'Courier_New.ttf'
42+ self.font_name = 'Courier_New.ttf'
43
44 def _num(self, number):
45 return number * self.scale
46@@ -56,6 +64,21 @@
47 self.width = (aa_image.width+1)*aa_image.nominal_size*aa_image.aspect_ratio
48 self.height = (aa_image.height+1)*aa_image.nominal_size
49
50+ font_size = int(self._num(self.aa_image.nominal_size*1.1))
51+ self.font = None
52+ try:
53+ self.font = ImageFont.truetype(self.font_name, font_size)
54+ except IOError:
55+ if sys.platform == 'linux2': # PIL upto 1.1.7b1 only tries abspaths for win32
56+ font_path = _find_file(self.font_name, '/usr/share/fonts')
57+ if font_path:
58+ try:
59+ self.font = ImageFont.truetype(font_path, font_size)
60+ except IOError:
61+ pass
62+ if not self.font:
63+ self.font = ImageFont.load_default()
64+
65 self.image = Image.new(
66 'RGB',
67 (int(self._num(self.width)), int(self._num(self.height))),
68@@ -151,7 +174,7 @@
69 (self._num(label.position.x), self._num(label.position.y-self.aa_image.nominal_size*1.1)),
70 label.text,
71 fill=self.foreground,
72- font=ImageFont.truetype(self.font, int(self._num(self.aa_image.nominal_size*1.1)))
73+ font=self.font
74 )
75
76 def _bezier(self, p1, c1, c2, p2, level=1):
77
78=== modified file 'aafigure/svg.py'
79--- aafigure/svg.py 2009-12-13 03:02:52 +0000
80+++ aafigure/svg.py 2010-03-01 03:11:11 +0000
81@@ -57,13 +57,10 @@
82 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
83 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
84
85-<svg width="%s" height="%s" version="1.1" xmlns="http://www.w3.org/2000/svg"
86+<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
87 xmlns:xlink="http://www.w3.org/1999/xlink">
88 <!-- automatically generated by aafigure -->
89-""" % (
90- '100%', #self._num(self.width),
91- '100%', #self._num(self.height)
92- ))
93+""")
94 else:
95 self.file_like.write("""<svg width="%s" height="%s" version="1.1" xmlns="http://www.w3.org/2000/svg">\n""" % (
96 self._num(self.width),

Subscribers

People subscribed via source and target branches

to all changes: