Changeset 1411 for trunk/buildscripts

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

Fixed #376

Location:
trunk/buildscripts/texbuilder
Files:
4 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 
  • trunk/buildscripts/texbuilder/quickstart/build.php

    r1266 r1411  
    1111$base = realpath(dirname(__FILE__).'/../../../demos/quickstart/protected/pages/'); 
    1212 
     13$pages = include('pages.php'); 
     14 
    1315//-------------- END CONFIG ------------------ 
    1416 
    15 $pages = include('pages.php'); 
    16  
    17 function escape_verbatim($matches) 
    18 { 
    19         return "\begin{verbatim}".str_replace('\$', '$', $matches[2])."\end{verbatim}\n"; 
    20 } 
    21  
    22 function escape_verb($matches) 
    23 { 
    24         $text = str_replace(array('\{', '\}'), array('{','}'), $matches[1]); 
    25         return '\verb<'.$text.'<'; 
    26 } 
    27  
    28 function include_image($matches) 
    29 { 
    30         global $current_path; 
    31  
    32         $image = dirname($current_path).'/'.trim($matches[1]); 
    33  
    34         $file = realpath($image); 
    35         $info = getimagesize($file); 
    36         switch($info[2]) 
    37         { 
    38                 case 1: 
    39                         $im = imagecreatefromgif($file); 
    40                         break; 
    41                 case 2: $im = imagecreatefromjpeg($file); break; 
    42                 case 3: $im = imagecreatefrompng($file); break; 
    43         } 
    44         global $base; 
    45  
    46         if(isset($im)) 
    47         { 
    48                 $prefix = strtolower(str_replace(realpath($base), '', $file)); 
    49                 $filename = preg_replace('/\\\|\//', '_', substr($prefix,1)); 
    50                 $filename = substr($filename, 0, strrpos($filename,'.')).'.png'; 
    51                 $newfile = dirname(__FILE__).'/'.$filename; 
    52                 imagepng($im,$newfile); 
    53                 imagedestroy($im); 
    54  
    55                 return include_figure($info, $filename); 
    56         } 
    57 } 
    58  
    59 function include_figure($info, $filename) 
    60 { 
    61         $width = sprintf('%0.2f', $info[0]/(135/2.54)); 
    62         return ' 
    63 \begin{figure}[ht] 
    64         \centering 
    65                 \includegraphics[width='.$width.'cm]{'.$filename.'} 
    66         \label{fig:'.$filename.'} 
    67 \end{figure} 
    68 '; 
    69 } 
    70  
    71 function anchor($matches) 
    72 { 
    73         $page = get_current_path(); 
    74         return '\hypertarget{'.$page.'/'.strtolower($matches[1]).'}{}'; 
    75 } 
    76  
    77 function texttt($matches) 
    78 { 
    79         return '\texttt{'.str_replace(array('#','_'),array('\#','\_'), $matches[1]).'}'; 
    80 } 
    81  
    82 function get_current_path() 
    83 { 
    84         global $current_path, $base; 
    85         $page = strtolower(substr(str_replace($base, '', $current_path),1)); 
    86         return $page; 
    87 } 
    88  
    89 function make_link($matches) 
    90 { 
    91         if(is_int(strpos($matches[1], '#'))) 
    92         { 
    93                 if(strpos($matches[1],'?') ===false) 
    94                 { 
    95                         $target = get_current_path().'/'.substr($matches[1],1); 
    96                         return '\hyperlink{'.$target.'}{'.$matches[2].'}'; 
    97                 } 
    98                 else 
    99                 { 
    100                         $page = strtolower(str_replace('?page=', '', $matches[1])); 
    101                         $page = str_replace('.','/',$page); 
    102                         $page = str_replace('#','.page/',$page); 
    103                         return '\hyperlink{'.$page.'}{'.$matches[2].'}'; 
    104                 } 
    105         } 
    106         else if(is_int(strpos($matches[1],'?'))) 
    107         { 
    108                 $page = str_replace('?page=','',$matches[1]); 
    109                 return '\hyperlink{'.$page.'}{'.$matches[2].'}'; 
    110         } 
    111         return '\href{'.$matches[1].'}{'.$matches[2].'}'; 
    112 } 
    113  
    114 function parse_html($page,$html) 
    115 { 
    116         $html = preg_replace('/<\/?com:TContent[^>]*>/', '', $html); 
    117         $html = preg_replace('/<\/?p>/m', '', $html); 
    118  
    119         //escape { and } 
    120         $html = preg_replace('/([^\s]+){([^}]*)}([^\s]+)/', '$1\\\{$2\\\}$3', $html); 
    121  
    122         //codes 
    123         $html = str_replace('$', '\$', $html); 
    124         $html = preg_replace('/<com:TTextHighlighter[^>]*>/', '`1`', $html); 
    125         $html = preg_replace('/<\/com:TTextHighlighter>/', '`2`', $html); 
    126         $html = preg_replace_callback('/(`1`)([^`]*)(`2`)/m', 'escape_verbatim', $html); 
    127         $html = preg_replace_callback('/(<div class="source">)([^<]*)(<\/div>)/', 'escape_verbatim', $html); 
    128         $html = preg_replace_callback('/(<pre>)([^<]*)(<\/pre>)/', 'escape_verbatim', $html); 
    129  
    130         //<code> 
    131         $html = preg_replace_callback('/<code>([^<]*)<\/code>/', 'escape_verb', $html); 
    132  
    133         $html = preg_replace_callback('/<img\s+src="?<%~([^"]*)%>"?[^\\/]*\/>/', 'include_image', $html); 
    134  
    135         //runbar 
    136         $html = preg_replace('/<com:RunBar\s+PagePath="([^"]*)"\s+\/>/', 
    137                         '\href{http://www.pradosoft.com/demos/quickstart/index.php?page=$1}{$1 Demo}', $html); 
    138  
    139         //DocLink 
    140         $html = preg_replace('/<com:DocLink\s+ClassPath="([^"]*)[.]([^.]*)"\s+\/>/', 
    141                         '\href{http://www.pradosoft.com/docs/manual/$1/$2.html}{$1.$2 API Reference}', $html); 
    142  
    143         //text modifiers 
    144         $html = preg_replace('/<b>([^<]*)<\/b>/', '\textbf{$1}', $html); 
    145         $html = preg_replace('/<i>([^<]*)<\/i>/', '\emph{$1}', $html); 
    146         $html = preg_replace_callback('/<tt>([^<]*)<\/tt>/', 'texttt', $html); 
    147  
    148         //links 
    149         $html = preg_replace_callback('/<a[^>]+href="([^"]*)"[^>]*>([^<]*)<\/a>/', 
    150                                                         'make_link', $html); 
    151         //anchor 
    152         $html = preg_replace_callback('/<a[^>]+name="([^"]*)"[^>]*><\/a>/', 'anchor', $html); 
    153  
    154         //description <dl> 
    155         $html = preg_replace('/<dt>([^<]*)<\/dt>/', '\item[$1]', $html); 
    156         $html = preg_replace('/<\/?dd>/', '', $html); 
    157         $html = preg_replace('/<dl>/', '\begin{description}', $html); 
    158         $html = preg_replace('/<\/dl>/', '\end{description}', $html); 
    159  
    160         //item lists 
    161         $html = preg_replace('/<ul>/', '\begin{itemize}', $html); 
    162         $html = preg_replace('/<\/ul>/', '\end{itemize}', $html); 
    163         $html = preg_replace('/<ol>/', '\begin{enumerate}', $html); 
    164         $html = preg_replace('/<\/ol>/', '\end{enumerate}', $html); 
    165         $html = preg_replace('/<li>/', '\item ', $html); 
    166         $html = preg_replace('/<\/li>/', '', $html); 
    167  
    168         //headings 
    169         $html = preg_replace('/<h1\s+id="[^"]+">([^<]+)<\/h1>/', '\section{$1}', $html); 
    170         $html = preg_replace('/<h2\s+id="[^"]+">([^<]+)<\/h2>/', '\subsection{$1}', $html); 
    171         $html = preg_replace('/<h3\s+id="[^"]+">([^<]+)<\/h3>/', '\subsubsection{$1}', $html); 
    172  
    173  
    174  
    175         $html = html_entity_decode($html); 
    176  
    177  
    178         return $html; 
    179 } 
    180  
    181 function get_chapter_label($chapter) 
    182 { 
    183         return '\hypertarget{'.str_replace(' ', '', $chapter).'}{}'; 
    184 } 
    185  
    186 function get_section_label($section) 
    187 { 
    188         $section = str_replace('.page', '', $section); 
    189         return '\hypertarget{'.str_replace('/', '.', $section).'}{}'; 
    190 } 
    191  
    192  
    193 function set_header_id($content, $count) 
    194 { 
    195         global $header_count; 
    196         $header_count = $count*100; 
    197         $content = preg_replace_callback('/<h1>/', "h1", $content); 
    198         $content = preg_replace_callback('/<h2>/', "h2", $content); 
    199         $content = preg_replace_callback('/<h3>/', "h3", $content); 
    200         return $content; 
    201 } 
    202  
    203 function h1($matches) 
    204 { 
    205         global $header_count; 
    206         return "<h1 id=\"".(++$header_count)."\">"; 
    207 } 
    208  
    209 function h2($matches) 
    210 { 
    211         global $header_count; 
    212         return "<h2 id=\"".(++$header_count)."\">"; 
    213 } 
    214  
    215 function h3($matches) 
    216 { 
    217         global $header_count; 
    218         return "<h3 id=\"".(++$header_count)."\">"; 
    219 } 
    220  
    221 $header_count = 0; 
    222  
    223 //--------------- BEGIN PROCESSING ------------------- 
    224  
    225  
    226 //--------------- Indexer ------------------- 
    227  
    228 //require_once('create_index.php'); 
    229 //$indexer = new quickstart_index($index_dir); 
     17include(dirname(__FILE__).'.../../../texbuilder/Page2Tex.php'); 
    23018 
    23119// ---------------- Create the Tex files --------- 
     
    23523echo "Compiling .page files to Latex files\n\n"; 
    23624 
     25$parser = new Page2Tex($base, dirname(__FILE__)); 
     26 
    23727foreach($pages as $chapter => $sections) 
    23828{ 
    239         $content = '\chapter{'.$chapter.'}'.get_chapter_label($chapter); 
     29        $content = '\chapter{'.$chapter.'}'.$parser->get_chapter_label($chapter); 
    24030        echo "Creating ch{$count}.txt => Chapter {$count}: {$chapter}\n"; 
    24131        echo str_repeat('-',60)."\n"; 
     
    24535                $page = $base.'/'.$section; 
    24636                $current_path = $page; 
     37                $parser->setCurrentPage($current_path); 
    24738 
    24839                //add id to <h1>, <h2>, <3> 
    249                 $tmp_content = set_header_id(file_get_contents($page),$j++); 
    250                 file_put_contents($page, $tmp_content); 
     40                $tmp_content = $parser->set_header_id(file_get_contents($page),$j++); 
     41//              file_put_contents($page, $tmp_content); 
    25142 
    252                 $content .= get_section_label($section); 
     43                $content .= $parser->get_section_label($section); 
    25344                $file_content = file_get_contents($page); 
    25445                $tex = 
    255                 $content .= parse_html($page,$file_content); 
     46                $content .= $parser->parse_html($page,$file_content); 
    25647        } 
    25748 
  • trunk/buildscripts/texbuilder/quickstart/pages.php

    r1261 r1411  
    11<?php 
    22/* 
    3  * Created on 11/05/2006 
     3 * $Id$ 
    44 */ 
    55 
     
    7575        'Controls/Repeater.page'); 
    7676 
     77$pages['Control Reference : Active Controls (AJAX)'] = array( 
     78        'ActiveControls/ActiveButton.page', 
     79        'ActiveControls/ActiveCheckBox.page', 
     80        'ActiveControls/ActiveCustomValidator.page'); 
     81 
     82$pages['Active Control Overview'] = array( 
     83                'ActiveControls/Home.page', 
     84        'ActiveControls/Introduction.page'); 
     85 
    7786$pages['Write New Controls'] = array( 
    7887        'Controls/NewControl.page'); 
     
    97106        'Advanced/Scripts3.page'); 
    98107 
    99  
    100108return $pages; 
    101109//-------------- END CONFIG ---------------- 
  • trunk/buildscripts/texbuilder/quickstart/quickstart.tex

    r1261 r1411  
    4343%----------------- TITLE -------------- 
    4444 
    45 \title{\Huge \bfseries PRADO v3.0.3 Quickstart Tutorial 
     45\title{\Huge \bfseries PRADO v3.1 Quickstart Tutorial 
    4646    \thanks{Copyright 2005-2006. All Rights Reserved.} 
    4747} 
     
    6969\addcontentsline{toc}{chapter}{License} 
    7070PRADO is free software released under the terms of the following BSD license.\\ 
    71 Copyright 2004-2006, The PRADO Group (http://www.pradosoft.com)\\ 
     71Copyright 2004-2006, The PRADO Group (http://www.pradosoft.com) 
    7272All rights reserved. 
    7373 
     
    119119\include{ch12} 
    120120\include{ch13} 
     121\include{ch14} 
     122\include{ch15} 
    121123 
    122124\end{document}