/usr/share/pyshared/schooltool/app/pdf.py is in python-schooltool 1:2.1.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2005 Shuttleworth Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
Schooltool PDF support.
"""
def isEnabled():
from schooltool.app.browser import pdfcal
return not pdfcal.disabled
# ------------------
# Font configuration
# ------------------
def registerTTFont(fontname, filename):
"""Register a TrueType font with ReportLab.
Clears up the incorrect straight-through mappings that ReportLab 1.19
unhelpfully gives us.
"""
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
import reportlab.lib.fonts
pdfmetrics.registerFont(TTFont(fontname, filename))
# For some reason pdfmetrics.registerFont for TrueType fonts explicitly
# calls addMapping with incorrect straight-through mappings, at least in
# reportlab version 1.19. We thus need to stick our dirty fingers in
# reportlab's internal data structures and undo those changes so that we
# can call addMapping with correct values.
key = fontname.lower()
del reportlab.lib.fonts._tt2ps_map[key, 0, 0]
del reportlab.lib.fonts._tt2ps_map[key, 0, 1]
del reportlab.lib.fonts._tt2ps_map[key, 1, 0]
del reportlab.lib.fonts._tt2ps_map[key, 1, 1]
del reportlab.lib.fonts._ps2tt_map[key]
# 'Arial' is predefined in ReportLab, so we use 'Arial_Normal'
font_map = {
'Arial_Normal': 'LiberationSans-Regular.ttf',
'Arial_Bold': 'LiberationSans-Bold.ttf',
'Arial_Italic': 'LiberationSans-Italic.ttf',
'Arial_Bold_Italic': 'LiberationSans-BoldItalic.ttf',
'Times_New_Roman': 'LiberationSerif-Regular.ttf',
'Times_New_Roman_Bold': 'LiberationSerif-Bold.ttf',
'Times_New_Roman_Italic': 'LiberationSerif-Italic.ttf',
'Times_New_Roman_Bold_Italic': 'LiberationSerif-BoldItalic.ttf',
'Ubuntu_Regular': 'Ubuntu-R.ttf',
'Ubuntu_Bold': 'Ubuntu-B.ttf',
'Ubuntu_Italic': 'Ubuntu-RI.ttf',
'Ubuntu_Bold_Italic': 'Ubuntu-BI.ttf',
}
def setUpFonts(directories):
"""Set up ReportGen to use Liberation and Ubuntu Fonts."""
import reportlab.rl_config
from reportlab.lib.fonts import addMapping
ttfpath = reportlab.rl_config.TTFSearchPath
for fontdir in directories:
ttfpath.append(fontdir)
reportlab.rl_config.warnOnMissingFontGlyphs = 0
for font_name, font_file in font_map.items():
registerTTFont(font_name, font_file)
addMapping('Arial_Normal', 0, 0, 'Arial_Normal')
addMapping('Arial_Normal', 0, 1, 'Arial_Italic')
addMapping('Arial_Normal', 1, 0, 'Arial_Bold')
addMapping('Arial_Normal', 1, 1, 'Arial_Bold_Italic')
addMapping('Times_New_Roman', 0, 0, 'Times_New_Roman')
addMapping('Times_New_Roman', 0, 1, 'Times_New_Roman_Italic')
addMapping('Times_New_Roman', 1, 0, 'Times_New_Roman_Bold')
addMapping('Times_New_Roman', 1, 1, 'Times_New_Roman_Bold_Italic')
addMapping('Ubuntu_Regular', 0, 0, 'Ubuntu_Regular')
addMapping('Ubuntu_Regular', 0, 1, 'Ubuntu_Italic')
addMapping('Ubuntu_Regular', 1, 0, 'Ubuntu_Bold')
addMapping('Ubuntu_Regular', 1, 1, 'Ubuntu_Bold_Italic')
from schooltool.app.browser import pdfcal
pdfcal.disabled = False
|