Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / pdflib.php
blob40dc7df4e48cf06ebe471994d120b00d54cbf7d6
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
9 // //
10 // Copyright (C) 1999-2999 Martin Dougiamas http://moodle.com //
11 // //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
16 // //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
24 ///////////////////////////////////////////////////////////////////////////
26 /**
27 * pdflib.php - Moodle PDF library
29 * We currently use the TCPDF library by Nicola Asuni.
31 * The default location for fonts that are included with TCPDF is
32 * lib/tcpdf/fonts/. If $CFG->datadir.'/fonts/' exists, this directory
33 * will be used instead of lib/tcpdf/fonts/. If there is only one font
34 * present in $CFG->datadir.'/fonts/', the font is used as the default
35 * font.
37 * See lib/tcpdf/fonts/README for details on how to convert fonts for use
38 * with TCPDF.
40 * Example usage:
41 * $doc = new pdf;
42 * $doc->print_header = false;
43 * $doc->print_footer = false;
44 * $doc->AddPage();
45 * $doc->Write(5, 'Hello World!');
46 * $doc->Output();
48 * @author Vy-Shane Sin Fat
49 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
50 * @package moodlecore
55 /// Includes
56 require_once('tcpdf/tcpdf.php');
60 /// Constants
61 define('PDF_CUSTOM_FONT_PATH', $CFG->dataroot.'/fonts/');
62 define('PDF_DEFAULT_FONT', 'FreeSerif');
66 /**
67 * Wrapper class that extends TCPDF (lib/tcpdf/tcpdf.php).
68 * Moodle customisations are done here.
70 class pdf extends TCPDF {
72 /**
73 * Constructor
75 function pdf($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8') {
77 parent::TCPDF($orientation, $unit, $format, $unicode, $encoding);
79 if (is_dir(PDF_CUSTOM_FONT_PATH)) {
80 $fontfiles = $this->_getfontfiles(PDF_CUSTOM_FONT_PATH);
82 if (count($fontfiles) == 1) {
83 $autofontname = substr($fontfile[0], 0, -4);
84 $this->AddFont($autofontname, '', $autofontname.'.php');
85 $this->SetFont($autofontname);
86 } else if (count($fontfiles == 0)) {
87 $this->SetFont(PDF_DEFAULT_FONT);
89 } else {
90 $this->SetFont(PDF_DEFAULT_FONT);
95 /**
96 * Fake constructor to keep PHP5 happy.
98 function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8') {
99 $this->pdf($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8');
104 * Return fonts path
105 * Overriding TCPDF::_getfontpath()
107 function _getfontpath() {
108 global $CFG;
110 if (is_dir(PDF_CUSTOM_FONT_PATH)
111 && count($this->_getfontfiles(PDF_CUSTOM_FONT_PATH)) > 0) {
112 $fontpath = PDF_CUSTOM_FONT_PATH;
113 } else {
114 $fontpath = $CFG->dirroot.'/lib/tcpdf/fonts/';
116 return $fontpath;
121 * Get the .php files for the fonts
123 function _getfontfiles($fontdir) {
124 $dirlist = get_directory_list($fontdir);
125 $fontfiles = array();
127 foreach ($dirlist as $file) {
128 if (substr($file, -4) == '.php') {
129 array_push($fontfiles, $file);
132 return $fontfiles;
136 } // End class pdf