From c0aeb59489d638d43eb19ff044ea12c54c998b6a Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 10 Jul 2006 01:03:05 +0000 Subject: Update tex builder. --- .gitattributes | 1 + buildscripts/texbuilder/Page2Tex.php | 232 +++++++++++++++++++++++++++++++++ tests/test_tools/simpletest/errors.php | 8 +- 3 files changed, 237 insertions(+), 4 deletions(-) create mode 100644 buildscripts/texbuilder/Page2Tex.php diff --git a/.gitattributes b/.gitattributes index 2aa141cc..27b9374e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -587,6 +587,7 @@ buildscripts/phing/tasks/XmlLintTask.php -text buildscripts/phing/tasks/ZendCodeAnalyzerTask.php -text buildscripts/phpbuilder/build.php -text buildscripts/setup.php -text +buildscripts/texbuilder/Page2Tex.php -text buildscripts/texbuilder/build.php -text buildscripts/texbuilder/pages.php -text buildscripts/texbuilder/quickstart.tex -text diff --git a/buildscripts/texbuilder/Page2Tex.php b/buildscripts/texbuilder/Page2Tex.php new file mode 100644 index 00000000..94567816 --- /dev/null +++ b/buildscripts/texbuilder/Page2Tex.php @@ -0,0 +1,232 @@ +_base = $base; + $this->_current_page = $current; + $this->_dir = $dir; + } + + function setCurrentPage($current) + { + $this->_current_page = $current; + } + + function escape_verbatim($matches) + { + return "\begin{verbatim}".str_replace($this->_verb_find, $this->_verb_replace, $matches[2])."\end{verbatim}\n"; + } + + function escape_verb($matches) + { + $text = str_replace($this->_verb_find, $this->_verb_replace, $matches[1]); + return '\verb<'.$text.'<'; + } + + function include_image($matches) + { + + $current_path = $this->_current_page; + + $image = dirname($current_path).'/'.trim($matches[1]); + + $file = realpath($image); + $info = getimagesize($file); + switch($info[2]) + { + case 1: + $im = imagecreatefromgif($file); + break; + case 2: $im = imagecreatefromjpeg($file); break; + case 3: $im = imagecreatefrompng($file); break; + } + $base = $this->_base; + + if(isset($im)) + { + $prefix = strtolower(str_replace(realpath($base), '', $file)); + $filename = preg_replace('/\\\|\//', '_', substr($prefix,1)); + $filename = substr($filename, 0, strrpos($filename,'.')).'.png'; + $newfile = $this->_dir.'/'.$filename; + imagepng($im,$newfile); + imagedestroy($im); + + return $this->include_figure($info, $filename); + } + } + + function include_figure($info, $filename) + { + $width = sprintf('%0.2f', $info[0]/(135/2.54)); + return ' + \begin{figure}[!ht] + \centering + \includegraphics[width='.$width.'cm]{'.$filename.'} + \label{fig:'.$filename.'} + \end{figure} + '; + } + + function anchor($matches) + { + $page = $this->get_current_path(); + return '\hypertarget{'.$page.'/'.strtolower($matches[1]).'}{}'; + } + + function texttt($matches) + { + return '\texttt{'.str_replace(array('#','_'),array('\#','\_'), $matches[1]).'}'; + } + + function get_current_path() + { + $current_path = $this->_current_page; + $base = $this->_base; + $page = strtolower(substr(str_replace($base, '', $current_path),1)); + return $page; + } + + function make_link($matches) + { + if(is_int(strpos($matches[1], '#'))) + { + if(strpos($matches[1],'?') ===false) + { + $target = $this->get_current_path().'/'.substr($matches[1],1); + return '\hyperlink{'.$target.'}{'.$matches[2].'}'; + } + else + { + $page = strtolower(str_replace('?page=', '', $matches[1])); + $page = str_replace('.','/',$page); + $page = str_replace('#','.page/',$page); + return '\hyperlink{'.$page.'}{'.$matches[2].'}'; + } + } + else if(is_int(strpos($matches[1],'?'))) + { + $page = str_replace('?page=','',$matches[1]); + return '\hyperlink{'.$page.'}{'.$matches[2].'}'; + } + return '\href{'.$matches[1].'}{'.$matches[2].'}'; + } + + function parse_html($page,$html) + { + $html = preg_replace('/<\/?com:TContent[^>]*>/', '', $html); + $html = preg_replace('/<\/?p[^<]*>/m', '', $html); + + //escape { and } + $html = preg_replace('/([^\s]+){([^}]*)}([^\s]+)/', '$1\\\{$2\\\}$3', $html); + + $html = preg_replace_callback('/"?[^\\/]*\/>/', array($this, 'include_image'), $html); + + //escape % + $html = str_replace('%', '\%', $html); + + //codes + $html = str_replace('$', '\$', $html); + $html = preg_replace('/]*>/', '`1`', $html); + $html = preg_replace('/<\/com:TTextHighlighter>/', '`2`', $html); + $html = preg_replace_callback('/(`1`)([^`]*)(`2`)/m', array($this,'escape_verbatim'), $html); + $html = preg_replace_callback('/(
)([^<]*)(<\/div>)/', array($this,'escape_verbatim'), $html); + $html = preg_replace_callback('/(
)([^<]*)(<\/pre>)/', array($this,'escape_verbatim'), $html);
+	
+		//
+		$html = preg_replace_callback('/([^<]*)<\/code>/', array($this,'escape_verb'), $html);
+	
+		//runbar
+		$html = preg_replace('//',
+				'\href{http://www.pradosoft.com/demos/quickstart/index.php?page=$1}{$1 Demo}', $html);
+	
+		//DocLink
+		$html = preg_replace('//',
+	                        '\href{http://www.pradosoft.com/docs/manual/$1/$2.html}{$1.$2 API Reference}', $html);
+	
+		//text modifiers
+		$html = preg_replace('/([^<]*)<\/b>/', '\textbf{$1}', $html);
+		$html = preg_replace('/([^<]*)<\/i>/', '\emph{$1}', $html);
+		$html = preg_replace_callback('/([^<]*)<\/tt>/', array($this,'texttt'), $html);
+	
+		//links
+		$html = preg_replace_callback('/]+href="([^"]*)"[^>]*>([^<]*)<\/a>/',
+								array($this,'make_link'), $html);
+		//anchor
+		$html = preg_replace_callback('/]+name="([^"]*)"[^>]*><\/a>/', array($this,'anchor'), $html);
+	
+		//description 
+ $html = preg_replace('/
([^<]*)<\/dt>/', '\item[$1]', $html); + $html = preg_replace('/<\/?dd>/', '', $html); + $html = preg_replace('/
/', '\begin{description}', $html); + $html = preg_replace('/<\/dl>/', '\end{description}', $html); + + //item lists + $html = preg_replace('/
    /', '\begin{itemize}', $html); + $html = preg_replace('/<\/ul>/', '\end{itemize}', $html); + $html = preg_replace('/
      /', '\begin{enumerate}', $html); + $html = preg_replace('/<\/ol>/', '\end{enumerate}', $html); + $html = preg_replace('/
    1. /', '\item ', $html); + $html = preg_replace('/<\/li>/', '', $html); + + //headings + $html = preg_replace('/([^<]+)<\/h1>/', '\section{$2}', $html); + $html = preg_replace('/([^<]+)<\/h2>/', '\subsection{$2}', $html); + $html = preg_replace('/([^<]+)<\/h3>/', '\subsubsection{$2}', $html); + + + + $html = html_entity_decode($html); + + + return $html; + } + + function get_chapter_label($chapter) + { + return '\hypertarget{'.str_replace(' ', '', $chapter).'}{}'; + } + + function get_section_label($section) + { + $section = str_replace('.page', '', $section); + return '\hypertarget{'.str_replace('/', '.', $section).'}{}'; + } + + + function set_header_id($content, $count) + { + self::$header_count = $count*100; + $content = preg_replace_callback('/

      /', array($this,"h1"), $content); + $content = preg_replace_callback('/

      /', array($this,"h2"), $content); + $content = preg_replace_callback('/

      /', array($this,"h3"), $content); + return $content; + } + + function h1($matches) + { + return "

      "; + } + + function h2($matches) + { + return "

      "; + } + + function h3($matches) + { + return "

      "; + } + +} + +?> \ No newline at end of file diff --git a/tests/test_tools/simpletest/errors.php b/tests/test_tools/simpletest/errors.php index 0608de60..b32cd5fe 100644 --- a/tests/test_tools/simpletest/errors.php +++ b/tests/test_tools/simpletest/errors.php @@ -41,7 +41,7 @@ function invoke($method) { set_error_handler('simpleTestErrorHandler'); parent::invoke($method); - $queue = &SimpleErrorQueue::instance(); + $queue = SimpleErrorQueue::instance(); while (list($severity, $message, $file, $line, $globals) = $queue->extract()) { $severity = SimpleErrorQueue::getSeverityAsString($severity); $test_case = $this->getTestCase(); @@ -121,7 +121,7 @@ * @access public * @static */ - function &instance() { + static function instance() { static $queue = false; if (! $queue) { $queue = new SimpleErrorQueue(); @@ -137,7 +137,7 @@ * @access public * @static */ - function getSeverityAsString($severity) { + static function getSeverityAsString($severity) { static $map = array( E_STRICT => 'E_STRICT', E_ERROR => 'E_ERROR', @@ -174,7 +174,7 @@ $label = SimpleErrorQueue::getSeverityAsString($severity); error_log("$label: $message in $filename on line $line"); } - $queue = &SimpleErrorQueue::instance(); + $queue = SimpleErrorQueue::instance(); $queue->add($severity, $message, $filename, $line, $super_globals); set_error_handler('simpleTestErrorHandler'); } -- cgit v1.2.3