Navigation Menu

Skip to content

Commit

Permalink
add a PHP interface using SWIG
Browse files Browse the repository at this point in the history
  • Loading branch information
vog committed Mar 31, 2011
1 parent 2aac003 commit 285d2a4
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -22,13 +22,16 @@ all: indep
cd python && python setup.py build_ext --inplace
cd ruby && ruby extconf.rb
$(MAKE) -C ruby
[ -e php/Makefile ] || { cd php && phpize && ./configure ; }
$(MAKE) -C php

check: all
$(MAKE) -C c check
$(MAKE) -C shell check
$(MAKE) -C postgresql check
cd python && python example.py
cd ruby && ruby example.rb
$(MAKE) -C php test PHP_TEST_SHARED_EXTENSIONS='-n -d extension=texcaller.so'

clean:
$(MAKE) -C doc-mk clean
Expand All @@ -39,6 +42,7 @@ clean:
cd python && rm -fr build dist texcaller.egg-info _texcaller.so texcaller.pyc
[ ! -e ruby/Makefile ] || $(MAKE) -C ruby clean
cd ruby && rm -fr Makefile texcaller.c
cd php && phpize --clean
rm -fr release

dist:
Expand Down
12 changes: 12 additions & 0 deletions c/texcaller.h
Expand Up @@ -38,6 +38,10 @@
* \dontinclude example.rb
* \skipline Texcaller.convert
*
* - \ref php
* \dontinclude example.php
* \skipline texcaller_convert
*
* \page download Download
*
* \section development Development version
Expand All @@ -47,6 +51,14 @@
* \verbatim
git clone https://github.com/vog/texcaller.git
\endverbatim
*
* \section release-0_6 Release 0.6
*
* <a href="http://www.profv.de/texcaller/texcaller-0.6.tar.gz">Download</a> |
* <a href="https://github.com/vog/texcaller/commits/0.6">ChangeLog</a>
*
* This release provides a PHP interface.
* The internal build system has been improved.
*
* \section release-0_5 Release 0.5
*
Expand Down
9 changes: 9 additions & 0 deletions php/config.m4
@@ -0,0 +1,9 @@
PHP_ARG_ENABLE(texcaller, for texcaller support,
[ --enable-texcaller Include texcaller support])

if test "$PHP_TEXCALLER" != no; then
PHP_REQUIRE_CXX
PHP_ADD_LIBRARY(stdc++, [], TEXCALLER_SHARED_LIBADD)
PHP_NEW_EXTENSION(texcaller, texcaller_wrap.cxx, $ext_shared)
PHP_SUBST(TEXCALLER_SHARED_LIBADD)
fi
17 changes: 17 additions & 0 deletions php/example.php
@@ -0,0 +1,17 @@
<?php

$latex = '\documentclass{article}
\begin{document}
Hello world!
\end{document}';

$pdf = '';
$info = '';
texcaller_convert($pdf, $info, $latex, 'LaTeX', 'PDF', 5);
printf("PDF size: %.1f KB\n", strlen($pdf) / 1024.0);
printf("PDF content: %s ... %s\n", substr($pdf, 0, 5), substr($pdf, -6));

$s = 'Téxt → "with" $peciäl <characters>';

echo 'Original: '.$s."\n";
echo 'Escaped: '.texcaller_escape_latex($s)."\n";
11 changes: 11 additions & 0 deletions php/tests/example.phpt
@@ -0,0 +1,11 @@
--TEST--
run example.php
--FILE--
<?php
require 'example.php';
--EXPECT--
PDF size: 5.5 KB
PDF content: %PDF- ... %%EOF

Original: Téxt → "with" $peciäl <characters>
Escaped: Téxt → {''}with{''} \$peciäl \textless{}characters\textgreater{}
4 changes: 2 additions & 2 deletions swig/Makefile
@@ -1,4 +1,4 @@
LANGUAGES := python ruby
LANGUAGES := python ruby php

WRAP_FILES := $(patsubst %,../%/texcaller_wrap.cxx,$(LANGUAGES))

Expand All @@ -7,7 +7,7 @@ WRAP_FILES := $(patsubst %,../%/texcaller_wrap.cxx,$(LANGUAGES))
all: $(WRAP_FILES)

clean:
rm -f $(WRAP_FILES) ../python/texcaller.py
rm -f $(WRAP_FILES) ../python/texcaller.py ../php/php_texcaller.h ../php/texcaller.php

../%/texcaller_wrap.cxx: texcaller.i
swig -$* -c++ -o $@ texcaller.i
34 changes: 34 additions & 0 deletions swig/texcaller.i
Expand Up @@ -80,6 +80,40 @@ Texcaller.escape_latex(s)
#endif
/*! \endcond */

/*! \defgroup php Texcaller PHP interface
*
* \par Synopsis
*
* \code
texcaller_convert(&$result, &$info, $source, $source_format, $result_format, $max_runs)
texcaller_escape_latex($s)
* \endcode
*
* \par Description
*
* These
* <a href="http://www.php.net/">PHP</a>
* functions are simple wrappers
* around the \ref c library functions,
* making
* <a href="http://www.tug.org/">TeX</a>
* typesetting
* easily accessible from PHP.
*
* \par Example
*
* \include example.php
*/

/*! \cond */
#ifdef SWIGPHP

%rename(texcaller_convert) texcaller::convert;
%rename(texcaller_escape_latex) texcaller::escape_latex;

#endif
/*! \endcond */

/*
* Declarations for all languages
*/
Expand Down

0 comments on commit 285d2a4

Please sign in to comment.