1<?php 2/** 3 * DokuWiki Plugin dw2pdf (Renderer Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr <gohr@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 14require_once DOKU_INC.'inc/parser/xhtml.php'; 15 16class renderer_plugin_dw2pdf extends Doku_Renderer_xhtml { 17 18 /** 19 * Make available as XHTML replacement renderer 20 */ 21 public function canRender($format){ 22 if($format == 'xhtml') return true; 23 return false; 24 } 25 26 // FIXME override any methods of Doku_Renderer_xhtml here 27 28 29 /** 30 * Simplified header printing with PDF bookmarks 31 */ 32 function header($text, $level, $pos) { 33 if(!$text) return; //skip empty headlines 34 35 // add PDF bookmark 36 $bmlevel = $this->getConf('maxbookmarks'); 37 if($bmlevel && $bmlevel >= $level){ 38 $this->doc .= '<bookmark content="'.$this->_xmlEntities($text).'" level="'.($level-1).'" />'; 39 } 40 41 // print header 42 $this->doc .= DOKU_LF."<h$level>"; 43 $this->doc .= $this->_xmlEntities($text); 44 $this->doc .= "</h$level>".DOKU_LF; 45 } 46 47 /** 48 * Wrap centered media in a div to center it 49 */ 50 function _media ($src, $title=NULL, $align=NULL, $width=NULL, 51 $height=NULL, $cache=NULL, $render = true) { 52 53 $out = ''; 54 if($align == 'center'){ 55 $out .= '<div align="center" style="text-align: center">'; 56 } 57 58 $out .= parent::_media ($src, $title, $align, $width, $height, $cache, $render); 59 60 if($align == 'center'){ 61 $out .= '</div>'; 62 } 63 64 return $out; 65 } 66 67 /** 68 * hover info makes no sense in PDFs, so drop acronyms 69 */ 70 function acronym($acronym) { 71 $this->doc .= $this->_xmlEntities($acronym); 72 } 73 74 75 /** 76 * reformat links if needed 77 */ 78 function _formatLink($link){ 79 // prefix interwiki links with interwiki icon 80 if($link['name'][0] != '<' && preg_match('/\binterwiki iw_(.\w+)\b/',$link['class'],$m)){ 81 if(file_exists(DOKU_INC.'lib/images/interwiki/'.$m[1].'.png')){ 82 $img = DOKU_BASE.'lib/images/interwiki/'.$m[1].'.png'; 83 }elseif(file_exists(DOKU_INC.'lib/images/interwiki/'.$m[1].'.gif')){ 84 $img = DOKU_BASE.'lib/images/interwiki/'.$m[1].'.gif'; 85 }else{ 86 $img = DOKU_BASE.'lib/images/interwiki.png'; 87 } 88 89 $link['name'] = '<img src="'.$img.'" width="16" height="16" style="vertical-align: center" />'.$link['name']; 90 } 91 return parent::_formatLink($link); 92 } 93} 94 95