Show
Ignore:
Timestamp:
09/13/2006 06:33:41 PM (2 years ago)
Author:
wei
Message:

Fixed #376

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/buildscripts/texbuilder/Page2Tex.php

    r1265 r1411  
    11<?php 
    22 
    3 class Page2Tex  
     3class Page2Tex 
    44{ 
    55        private $_current_page; 
     
    1717                $this->_dir = $dir; 
    1818        } 
    19          
     19 
    2020        function setCurrentPage($current) 
    2121        { 
     
    2525        function escape_verbatim($matches) 
    2626        { 
    27                 return "\begin{verbatim}".str_replace($this->_verb_find, $this->_verb_replace, $matches[1])."\end{verbatim}\n"; 
    28         } 
    29          
     27                return "\begin{small}\begin{verbatim}". 
     28                                str_replace($this->_verb_find, $this->_verb_replace, $matches[1]). 
     29                                "\end{verbatim}\end{small}\n"; 
     30        } 
     31 
    3032        function escape_verb($matches) 
    3133        { 
    3234                $text = str_replace($this->_verb_find, $this->_verb_replace, $matches[1]); 
    33                 return '\verb<'.$text.'<'; 
    34         } 
    35          
     35                return '\begin{small}\verb<'.$text.'< \end{small}'; 
     36        } 
     37 
    3638        function include_image($matches) 
    3739        { 
    38                  
     40 
    3941                $current_path = $this->_current_page; 
    40          
     42 
    4143                $image = dirname($current_path).'/'.trim($matches[1]); 
    42          
     44 
    4345                $file = realpath($image); 
    4446                $info = getimagesize($file); 
     
    5254                } 
    5355                $base = $this->_base; 
    54          
     56 
    5557                if(isset($im)) 
    5658                { 
     
    6567                } 
    6668        } 
    67          
     69 
    6870        function include_figure($info, $filename) 
    6971        { 
     
    7779        '; 
    7880        } 
    79          
     81 
    8082        function anchor($matches) 
    8183        { 
     
    8385                return '\hypertarget{'.$page.'/'.strtolower($matches[1]).'}{}'; 
    8486        } 
    85          
     87 
    8688        function texttt($matches) 
    8789        { 
    8890                return '\texttt{'.str_replace(array('#','_'),array('\#','\_'), $matches[1]).'}'; 
    8991        } 
    90          
     92 
    9193        function get_current_path() 
    9294        { 
     
    9698                return $page; 
    9799        } 
    98          
     100 
    99101        function make_link($matches) 
    100102        { 
     
    121123                return '\href{'.$matches[1].'}{'.$matches[2].'}'; 
    122124        } 
    123          
     125 
    124126        function parse_html($page,$html) 
    125127        { 
    126                  
    127                  
    128128                $html = preg_replace('/<\/?com:TContent[^>]*>/', '', $html); 
    129129                $html = preg_replace('/<\/?p [^>]*>/', '', $html); 
    130130                $html = preg_replace('/<\/?p>/', '', $html); 
    131          
     131 
    132132                $html = preg_replace('/(\s+|\(+|\[+)"/', '$1``', $html); 
    133                  
     133 
    134134                //escape { and } 
    135135                $html = preg_replace('/([^\s]+){([^}]*)}([^\s]+)/', '$1\\\{$2\\\}$3', $html); 
    136          
     136 
    137137                $html = preg_replace_callback('/<img\s+src="?<%~([^"]*)%>"?[^>]*\/>/', array($this, 'include_image'), $html); 
    138138 
    139139                //escape % 
    140140                $html = str_replace('%', '\%', $html); 
    141          
     141 
    142142                //codes 
    143143                $html = str_replace('$', '\$', $html); 
    144                  
     144 
    145145                $html = preg_replace_callback('/<com:TTextHighlighter[^>]*>((.|\n)*?)<\/com:TTextHighlighter>/', array($this,'escape_verbatim'), $html); 
    146146//              $html = preg_replace('/<\/com:TTextHighlighter>/', '`2`', $html); 
     
    148148                $html = preg_replace_callback('/(<div class="source">)((.|\n)*?)(<\/div>)/', array($this,'escape_verbatim'), $html); 
    149149                $html = preg_replace_callback('/(<pre>)([^<]*)(<\/pre>)/', array($this,'escape_verbatim'), $html); 
    150          
     150 
    151151                //<code> 
    152152                $html = preg_replace_callback('/<code>([^<]*)<\/code>/', array($this,'escape_verb'), $html); 
    153          
     153 
    154154                //runbar 
    155155                $html = preg_replace('/<com:RunBar\s+PagePath="([^"]*)"\s+\/>/', 
    156156                                '\href{http://www.pradosoft.com/demos/quickstart/index.php?page=$1}{$1 Demo}', $html); 
    157          
     157 
    158158                //DocLink 
    159159                $html = preg_replace('/<com:DocLink\s+ClassPath="([^"]*)[.]([^.]*)"\s+\/>/', 
    160160                                '\href{http://www.pradosoft.com/docs/manual/$1/$2.html}{$1.$2 API Reference}', $html); 
    161          
     161 
    162162                //text modifiers 
    163                 $html = preg_replace('/<b[^>]*>([^<]*)<\/b>/', '\textbf{$1}', $html); 
     163                $html = preg_replace('/<(b|strong)[^>]*>([^<]*)<\/(b|strong)>/', '\textbf{$2}', $html); 
    164164                $html = preg_replace('/<i[^>]*>([^<]*)<\/i>/', '\emph{$1}', $html); 
    165165                $html = preg_replace_callback('/<tt>([^<]*)<\/tt>/', array($this,'texttt'), $html); 
    166          
     166 
    167167                //links 
    168168                $html = preg_replace_callback('/<a[^>]+href="([^"]*)"[^>]*>([^<]*)<\/a>/', 
     
    170170                //anchor 
    171171                $html = preg_replace_callback('/<a[^>]+name="([^"]*)"[^>]*><\/a>/', array($this,'anchor'), $html); 
    172          
     172 
    173173                //description <dl> 
    174174                $html = preg_replace('/<dt>([^<]*)<\/dt>/', '\item[$1]', $html); 
     
    176176                $html = preg_replace('/<dl>/', '\begin{description}', $html); 
    177177                $html = preg_replace('/<\/dl>/', '\end{description}', $html); 
    178          
     178 
    179179                //item lists 
    180180                $html = preg_replace('/<ul[^>]*>/', '\begin{itemize}', $html); 
     
    184184                $html = preg_replace('/<li[^>]*>/', '\item ', $html); 
    185185                $html = preg_replace('/<\/li>/', '', $html); 
    186          
     186 
    187187                //headings 
    188188                $html = preg_replace('/<h1(\s+id="[^"]+")?>([^<]+)<\/h1>/', '\section{$2}', $html); 
    189189                $html = preg_replace('/<h2(\s+id="[^"]+")?>([^<]+)<\/h2>/', '\subsection{$2}', $html); 
    190190                $html = preg_replace('/<h3(\s+id="[^"]+")?>([^<]+)<\/h3>/', '\subsubsection{$2}', $html); 
    191          
     191 
    192192                //div box 
    193193                $html = preg_replace_callback('/<div class="[tipnofe]*?">((.|\n)*?)<\/div>/', 
    194                                                 array($this, 'mbox'), $html);    
    195                  
     194                                                array($this, 'mbox'), $html); 
     195 
    196196                //tabular 
    197197                $html = preg_replace_callback('/<!--\s*tabular:([^-]*)-->\s*<table[^>]*>((.|\n)*?)<\/table>/', 
    198198                                                array($this, 'tabular'), $html); 
    199          
     199 
     200                $html = preg_replace('/<!--(.*)-->/', '', $html); 
     201 
     202 
    200203                $html = html_entity_decode($html); 
    201          
     204 
    202205                return $html; 
    203206        } 
    204          
     207 
    205208        function tabular($matches) 
    206209        { 
     
    211214                        $options[trim($sub[0])] = trim($sub[1]); 
    212215                } 
    213                  
     216 
    214217                $widths = explode(' ',preg_replace('/\(|\)/', '', $options['width'])); 
    215218                $this->_tabular_widths = $widths; 
    216                  
     219 
    217220                $this->_tabular_total = count($widths); 
    218221                $this->_tabular_col = 0; 
    219                  
     222 
    220223                $begin = "\begin{table}[!hpt]\centering \n \begin{tabular}{".$options['align']."}\\hline"; 
    221224                $end = "\end{tabular} \n \end{table}\n"; 
     
    225228                $table = preg_replace_callback('/<td>((.|\n)*?)<\/td>/', array($this, 'table_column'), $table); 
    226229                $table = preg_replace('/<br \/>/', ' \\\\\\\\', $table); 
    227                  
     230 
    228231                $table = preg_replace('/&\s*\\\\\\\\/', '\\\\\\\\', $table); 
    229232                return $begin.$table.$end; 
    230233        } 
    231          
     234 
    232235        function table_column($matches) 
    233236        { 
     
    240243                        $matches[1].'\vspace{3mm}\end{minipage} & '; 
    241244        } 
    242          
     245 
    243246        function mbox($matches) 
    244247        { 
    245248                return "\n\begin{mybox}\n".$matches[1]."\n\end{mybox}\n"; 
    246249        } 
    247          
     250 
    248251        function get_chapter_label($chapter) 
    249252        { 
    250253                return '\hypertarget{'.str_replace(' ', '', $chapter).'}{}'; 
    251254        } 
    252          
     255 
    253256        function get_section_label($section) 
    254257        { 
     
    256259                return '\hypertarget{'.str_replace('/', '.', $section).'}{}'; 
    257260        } 
    258          
    259          
     261 
     262 
    260263        function set_header_id($content, $count) 
    261264        { 
     
    266269                return $content; 
    267270        } 
    268          
     271 
    269272        function h1($matches) 
    270273        { 
    271274                return "<h1 id=\"".(++self::$header_count)."\">"; 
    272275        } 
    273          
     276 
    274277        function h2($matches) 
    275278        { 
    276279                return "<h2 id=\"".(++self::$header_count)."\">"; 
    277280        } 
    278          
     281 
    279282        function h3($matches) 
    280283        { 
    281284                return "<h3 id=\"".(++self::$header_count)."\">"; 
    282285        } 
    283          
     286 
    284287} 
    285288