| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: pdflib.php,v 1.5.2.1 2008/01/28 05:27:13 moodler Exp $ 2 3 /////////////////////////////////////////////////////////////////////////// 4 // // 5 // NOTICE OF COPYRIGHT // 6 // // 7 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 8 // http://moodle.org // 9 // // 10 // Copyright (C) 1999 onwards 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 /////////////////////////////////////////////////////////////////////////// 25 26 /** 27 * pdflib.php - Moodle PDF library 28 * 29 * We currently use the TCPDF library by Nicola Asuni. 30 * 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. 36 * 37 * See lib/tcpdf/fonts/README for details on how to convert fonts for use 38 * with TCPDF. 39 * 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(); 47 * 48 * @author Vy-Shane Sin Fat 49 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 50 * @package moodlecore 51 */ 52 53 54 55 /// Includes 56 require_once ('tcpdf/tcpdf.php'); 57 58 59 60 /// Constants 61 define('PDF_CUSTOM_FONT_PATH', $CFG->dataroot.'/fonts/'); 62 define('PDF_DEFAULT_FONT', 'FreeSerif'); 63 64 65 66 /** 67 * Wrapper class that extends TCPDF (lib/tcpdf/tcpdf.php). 68 * Moodle customisations are done here. 69 */ 70 class pdf extends TCPDF { 71 72 /** 73 * Constructor 74 */ 75 function pdf($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8') { 76 77 parent::TCPDF($orientation, $unit, $format, $unicode, $encoding); 78 79 if (is_dir(PDF_CUSTOM_FONT_PATH)) { 80 $fontfiles = $this->_getfontfiles(PDF_CUSTOM_FONT_PATH); 81 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); 88 } 89 } else { 90 $this->SetFont(PDF_DEFAULT_FONT); 91 } 92 } 93 94 95 /** 96 * Fake constructor to keep PHP5 happy. 97 */ 98 function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8') { 99 $this->pdf($orientation, $unit, $format, $unicode, $encoding); 100 } 101 102 103 /** 104 * Return fonts path 105 * Overriding TCPDF::_getfontpath() 106 */ 107 function _getfontpath() { 108 global $CFG; 109 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/'; 115 } 116 return $fontpath; 117 } 118 119 120 /** 121 * Get the .php files for the fonts 122 */ 123 function _getfontfiles($fontdir) { 124 $dirlist = get_directory_list($fontdir); 125 $fontfiles = array(); 126 127 foreach ($dirlist as $file) { 128 if (substr($file, -4) == '.php') { 129 array_push($fontfiles, $file); 130 } 131 } 132 return $fontfiles; 133 } 134 135 136 } // End class pdf 137 138 139 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |