1999-10-08 07:56:43 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2001-12-11 15:32:16 +00:00
| PHP Version 4 |
1999-10-08 07:56:43 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2001-12-11 15:32:16 +00:00
| Copyright ( c ) 1997 - 2002 The PHP Group |
1999-10-08 07:56:43 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2000-05-18 15:34:45 +00:00
| This source file is subject to version 2.02 of the PHP license , |
1999-10-08 07:56:43 +00:00
| that is bundled with this package in the file LICENSE , and is |
| available at through the world - wide - web at |
2000-05-18 15:34:45 +00:00
| http : //www.php.net/license/2_02.txt. |
1999-10-08 07:56:43 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2002-02-28 08:29:35 +00:00
| Author : Jouni Ahto < jah @ mork . net > |
1999-10-08 07:56:43 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
2000-02-25 06:43:51 +00:00
#if 0 /* Moved currently back to gd.c */
# include "php.h"
# include "php_gd.h"
# if HAVE_LIBT1
void php_free_ps_font ( int font_id )
1999-10-08 07:56:43 +00:00
{
2000-02-25 06:43:51 +00:00
T1_DeleteFont ( font_id ) ;
1999-10-08 07:56:43 +00:00
}
1999-12-17 21:50:07 +00:00
void php_free_ps_enc ( char * * enc )
1999-10-08 07:56:43 +00:00
{
T1_DeleteEncoding ( enc ) ;
}
/* {{{ proto int imagepsloadfont(string pathname)
2000-02-22 15:48:43 +00:00
Load a new font from specified file */
1999-12-17 21:50:07 +00:00
PHP_FUNCTION ( imagepsloadfont )
{
2000-02-25 06:43:51 +00:00
zval * * file ;
int f_ind , l_ind ;
1999-10-08 07:56:43 +00:00
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & file ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
WRONG_PARAM_COUNT ;
}
2000-02-25 06:43:51 +00:00
convert_to_string_ex ( file ) ;
1999-10-08 07:56:43 +00:00
2001-09-25 21:58:48 +00:00
f_ind = T1_AddFont ( Z_STRVAL_PP ( file ) ) ;
1999-10-08 07:56:43 +00:00
2000-02-25 06:43:51 +00:00
if ( f_ind < 0 ) {
switch ( f_ind ) {
1999-10-08 07:56:43 +00:00
case - 1 :
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " Couldn't find the font file " ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
break ;
case - 2 :
case - 3 :
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " Memory allocation fault in t1lib " ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
break ;
default :
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " An unknown error occurred in t1lib " ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
break ;
}
}
2000-02-25 06:43:51 +00:00
T1_LoadFont ( f_ind ) ;
/*
l_ind = zend_list_insert ( f_ind , T1_GLOBAL ( le_ps_font ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_LONG ( l_ind ) ;
2000-02-25 06:43:51 +00:00
*/
zend_list_addref ( f_ind ) ;
RETURN_LONG ( f_ind ) ;
1999-10-08 07:56:43 +00:00
}
/* }}} */
/* {{{ The function in t1lib which this function uses seem to be buggy...
proto int imagepscopyfont ( int font_index )
Make a copy of a font for purposes like extending or reenconding */
/*
1999-12-17 21:50:07 +00:00
PHP_FUNCTION ( imagepscopyfont )
{
1999-10-08 07:56:43 +00:00
pval * fnt ;
int l_ind , type ;
gd_ps_font * nf_ind , * of_ind ;
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters ( ht , 1 , & fnt ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
WRONG_PARAM_COUNT ;
}
convert_to_long ( fnt ) ;
2001-09-25 21:58:48 +00:00
of_ind = zend_list_find ( Z_LVAL_P ( fnt ) , & type ) ;
1999-10-08 07:56:43 +00:00
if ( type ! = GD_GLOBAL ( le_ps_font ) ) {
2001-09-25 21:58:48 +00:00
php_error ( E_WARNING , " %d is not a Type 1 font index " , Z_LVAL_P ( fnt ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
nf_ind = emalloc ( sizeof ( gd_ps_font ) ) ;
nf_ind - > font_id = T1_CopyFont ( of_ind - > font_id ) ;
if ( nf_ind - > font_id < 0 ) {
l_ind = nf_ind - > font_id ;
efree ( nf_ind ) ;
switch ( l_ind ) {
case - 1 :
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " FontID %d is not loaded in memory " , l_ind ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
break ;
case - 2 :
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " Tried to copy a logical font " ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
break ;
case - 3 :
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " Memory allocation fault in t1lib " ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
break ;
default :
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " An unknown error occurred in t1lib " ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
break ;
}
}
nf_ind - > extend = 1 ;
1999-12-17 19:51:39 +00:00
l_ind = zend_list_insert ( nf_ind , GD_GLOBAL ( le_ps_font ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_LONG ( l_ind ) ;
}
*/
/* }}} */
/* {{{ proto bool imagepsfreefont(int font_index)
2000-02-22 15:48:43 +00:00
Free memory used by a font */
1999-12-17 21:50:07 +00:00
PHP_FUNCTION ( imagepsfreefont )
{
2000-02-25 06:43:51 +00:00
zval * * fnt ;
1999-10-08 07:56:43 +00:00
int type ;
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & fnt ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
WRONG_PARAM_COUNT ;
}
2000-02-25 06:43:51 +00:00
convert_to_long_ex ( fnt ) ;
1999-10-08 07:56:43 +00:00
2001-09-25 21:58:48 +00:00
zend_list_find ( Z_LVAL_PP ( fnt ) , & type ) ;
1999-10-08 07:56:43 +00:00
2000-02-25 06:43:51 +00:00
if ( type ! = T1_GLOBAL ( le_ps_font ) ) {
2001-09-25 21:58:48 +00:00
php_error ( E_WARNING , " %d is not a Type 1 font index " , Z_LVAL_PP ( fnt ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2001-09-25 21:58:48 +00:00
zend_list_delete ( Z_LVAL_PP ( fnt ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_TRUE ;
}
/* }}} */
/* {{{ proto bool imagepsencodefont(int font_index, string filename)
2000-02-22 15:48:43 +00:00
To change a fonts character encoding vector */
1999-12-17 21:50:07 +00:00
PHP_FUNCTION ( imagepsencodefont )
{
2000-02-25 06:43:51 +00:00
zval * * fnt , * * enc ;
1999-10-08 07:56:43 +00:00
char * * enc_vector ;
int type ;
2000-02-25 06:43:51 +00:00
int f_ind ;
1999-10-08 07:56:43 +00:00
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & fnt , & enc ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
WRONG_PARAM_COUNT ;
}
2000-02-25 06:43:51 +00:00
convert_to_long_ex ( fnt ) ;
convert_to_string_ex ( enc ) ;
1999-10-08 07:56:43 +00:00
2001-09-25 21:58:48 +00:00
f_ind = zend_list_find ( Z_LVAL_PP ( fnt ) , & type ) ;
1999-10-08 07:56:43 +00:00
2000-02-25 06:43:51 +00:00
if ( type ! = T1_GLOBAL ( le_ps_font ) ) {
2001-09-25 21:58:48 +00:00
php_error ( E_WARNING , " %d is not a Type 1 font index " , Z_LVAL_PP ( fnt ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2001-09-25 21:58:48 +00:00
if ( ( enc_vector = T1_LoadEncoding ( Z_STRVAL_PP ( enc ) ) ) = = NULL ) {
php_error ( E_WARNING , " Couldn't load encoding vector from %s " , Z_STRVAL_PP ( enc ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2000-02-25 06:43:51 +00:00
T1_DeleteAllSizes ( f_ind ) ;
if ( T1_ReencodeFont ( f_ind , enc_vector ) ) {
1999-10-08 07:56:43 +00:00
T1_DeleteEncoding ( enc_vector ) ;
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " Couldn't reencode font " ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2000-02-25 06:43:51 +00:00
zend_list_insert ( enc_vector , T1_GLOBAL ( le_ps_enc ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_TRUE ;
}
/* }}} */
2001-09-21 21:59:27 +00:00
/* {{{ proto bool imagepsextendfont(int font_index, float extend)
2000-02-22 15:48:43 +00:00
Extend or or condense ( if extend < 1 ) a font */
1999-12-17 21:50:07 +00:00
PHP_FUNCTION ( imagepsextendfont )
{
2000-02-25 06:43:51 +00:00
zval * * fnt , * * ext ;
1999-10-08 07:56:43 +00:00
int type ;
2000-02-25 06:43:51 +00:00
int f_ind ;
1999-10-08 07:56:43 +00:00
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & fnt , & ext ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
WRONG_PARAM_COUNT ;
}
2000-02-25 06:43:51 +00:00
convert_to_long_ex ( fnt ) ;
convert_to_double_ex ( ext ) ;
1999-10-08 07:56:43 +00:00
2001-09-25 21:58:48 +00:00
f_ind = zend_list_find ( Z_LVAL_PP ( fnt ) , & type ) ;
1999-10-08 07:56:43 +00:00
2000-02-25 06:43:51 +00:00
if ( type ! = T1_GLOBAL ( le_ps_font ) ) {
2001-09-25 21:58:48 +00:00
php_error ( E_WARNING , " %d is not a Type 1 font index " , Z_LVAL_PP ( fnt ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2001-09-25 21:58:48 +00:00
if ( T1_ExtendFont ( f_ind , Z_DVAL_PP ( ext ) ) ! = 0 ) RETURN_FALSE ;
2000-02-25 06:43:51 +00:00
/*
2001-09-25 21:58:48 +00:00
f_ind - > extend = Z_DVAL_P ( ext ) ;
2000-02-25 06:43:51 +00:00
*/
1999-10-08 07:56:43 +00:00
RETURN_TRUE ;
}
/* }}} */
2001-09-21 21:59:27 +00:00
/* {{{ proto bool imagepsslantfont(int font_index, float slant)
2000-02-22 15:48:43 +00:00
Slant a font */
1999-12-17 21:50:07 +00:00
PHP_FUNCTION ( imagepsslantfont )
{
2000-02-25 06:43:51 +00:00
zval * * fnt , * * slt ;
1999-10-08 07:56:43 +00:00
int type ;
2000-02-25 06:43:51 +00:00
int f_ind ;
1999-10-08 07:56:43 +00:00
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & fnt , & slt ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
WRONG_PARAM_COUNT ;
}
2000-02-25 06:43:51 +00:00
convert_to_long_ex ( fnt ) ;
convert_to_double_ex ( slt ) ;
1999-10-08 07:56:43 +00:00
2001-09-25 21:58:48 +00:00
f_ind = zend_list_find ( Z_LVAL_PP ( fnt ) , & type ) ;
1999-10-08 07:56:43 +00:00
2000-02-25 06:43:51 +00:00
if ( type ! = T1_GLOBAL ( le_ps_font ) ) {
2001-09-25 21:58:48 +00:00
php_error ( E_WARNING , " %d is not a Type 1 font index " , Z_LVAL_PP ( fnt ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2001-09-25 21:58:48 +00:00
if ( T1_SlantFont ( f_ind , Z_DVAL_PP ( slt ) ) ! = 0 ) RETURN_FALSE ;
1999-10-08 07:56:43 +00:00
RETURN_TRUE ;
}
/* }}} */
2001-09-21 21:59:27 +00:00
/* {{{ proto array imagepstext(int image, string text, int font, int size, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias])
2000-02-22 15:48:43 +00:00
Rasterize a string over an image */
1999-12-17 21:50:07 +00:00
PHP_FUNCTION ( imagepstext )
{
2000-02-25 06:43:51 +00:00
zval * * img , * * str , * * fnt , * * sz , * * fg , * * bg , * * sp , * * px , * * py , * * aas , * * wd , * * ang ;
1999-10-08 07:56:43 +00:00
int i , j , x , y ;
int space , type ;
2000-02-25 06:43:51 +00:00
int f_ind ;
1999-10-08 07:56:43 +00:00
int h_lines , v_lines , c_ind ;
int rd , gr , bl , fg_rd , fg_gr , fg_bl , bg_rd , bg_gr , bg_bl ;
int aa [ 16 ] , aa_steps ;
int width , amount_kern , add_width ;
double angle ;
unsigned long aa_greys [ ] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 } ;
gdImagePtr bg_img ;
GLYPH * str_img ;
T1_OUTLINE * char_path , * str_path ;
T1_TMATRIX * transform = NULL ;
2000-06-05 19:47:54 +00:00
switch ( ZEND_NUM_ARGS ( ) ) {
1999-10-08 07:56:43 +00:00
case 8 :
2000-02-25 06:43:51 +00:00
if ( zend_get_parameters_ex ( 8 , & img , & str , & fnt , & sz , & fg , & bg , & px , & py ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2000-02-25 06:43:51 +00:00
convert_to_string_ex ( str ) ;
convert_to_long_ex ( fnt ) ;
convert_to_long_ex ( sz ) ;
convert_to_long_ex ( fg ) ;
convert_to_long_ex ( bg ) ;
convert_to_long_ex ( px ) ;
convert_to_long_ex ( py ) ;
2001-09-25 21:58:48 +00:00
x = Z_LVAL_PP ( px ) ;
y = Z_LVAL_PP ( py ) ;
1999-10-08 07:56:43 +00:00
space = 0 ;
aa_steps = 4 ;
width = 0 ;
angle = 0 ;
break ;
case 12 :
2000-02-25 06:43:51 +00:00
if ( zend_get_parameters_ex ( 12 , & img , & str , & fnt , & sz , & fg , & bg , & px , & py , & sp , & wd , & ang , & aas ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2000-02-25 06:43:51 +00:00
convert_to_string_ex ( str ) ;
convert_to_long_ex ( fnt ) ;
convert_to_long_ex ( sz ) ;
convert_to_long_ex ( sp ) ;
convert_to_long_ex ( fg ) ;
convert_to_long_ex ( bg ) ;
convert_to_long_ex ( px ) ;
convert_to_long_ex ( py ) ;
2001-09-25 21:58:48 +00:00
x = Z_LVAL_PP ( px ) ;
y = Z_LVAL_PP ( py ) ;
2000-02-25 06:43:51 +00:00
convert_to_long_ex ( sp ) ;
2001-09-25 21:58:48 +00:00
space = Z_LVAL_PP ( sp ) ;
2000-02-25 06:43:51 +00:00
convert_to_long_ex ( aas ) ;
2001-09-25 21:58:48 +00:00
aa_steps = Z_LVAL_PP ( aas ) ;
2000-02-25 06:43:51 +00:00
convert_to_long_ex ( wd ) ;
2001-09-25 21:58:48 +00:00
width = Z_LVAL_PP ( wd ) ;
2000-02-25 06:43:51 +00:00
convert_to_double_ex ( ang ) ;
2001-09-25 21:58:48 +00:00
angle = Z_DVAL_PP ( ang ) ;
1999-10-08 07:56:43 +00:00
break ;
default :
WRONG_PARAM_COUNT ;
}
2001-09-25 21:58:48 +00:00
bg_img = zend_list_find ( Z_LVAL_PP ( img ) , & type ) ;
1999-10-08 07:56:43 +00:00
if ( ! bg_img | | type ! = GD_GLOBAL ( le_gd ) ) {
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " Unable to find image pointer " ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2001-09-25 21:58:48 +00:00
f_ind = zend_list_find ( Z_LVAL_P ( fnt ) , & type ) ;
1999-10-08 07:56:43 +00:00
if ( ! f_ind | | type ! = GD_GLOBAL ( le_ps_font ) ) {
2001-09-25 21:58:48 +00:00
php_error ( E_WARNING , " %d is not a Type 1 font index " , Z_LVAL_P ( fnt ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
2001-09-25 21:58:48 +00:00
fg_rd = gdImageRed ( bg_img , Z_LVAL_P ( fg ) ) ;
fg_gr = gdImageGreen ( bg_img , Z_LVAL_P ( fg ) ) ;
fg_bl = gdImageBlue ( bg_img , Z_LVAL_P ( fg ) ) ;
bg_rd = gdImageRed ( bg_img , Z_LVAL_P ( bg ) ) ;
bg_gr = gdImageGreen ( bg_img , Z_LVAL_P ( bg ) ) ;
bg_bl = gdImageBlue ( bg_img , Z_LVAL_P ( bg ) ) ;
1999-10-08 07:56:43 +00:00
for ( i = 0 ; i < aa_steps ; i + + ) {
rd = bg_rd + ( double ) ( fg_rd - bg_rd ) / aa_steps * ( i + 1 ) ;
gr = bg_gr + ( double ) ( fg_gr - bg_gr ) / aa_steps * ( i + 1 ) ;
bl = bg_bl + ( double ) ( fg_bl - bg_bl ) / aa_steps * ( i + 1 ) ;
aa [ i ] = gdImageColorResolve ( bg_img , rd , gr , bl ) ;
}
T1_AASetBitsPerPixel ( 8 ) ;
switch ( aa_steps ) {
case 4 :
T1_AASetGrayValues ( 0 , 1 , 2 , 3 , 4 ) ;
T1_AASetLevel ( T1_AA_LOW ) ;
break ;
case 16 :
T1_AAHSetGrayValues ( aa_greys ) ;
T1_AASetLevel ( T1_AA_HIGH ) ;
break ;
default :
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " Invalid value %d as number of steps for antialiasing " , aa_steps ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
if ( angle ) {
transform = T1_RotateMatrix ( NULL , angle ) ;
}
if ( width ) {
# ifdef HAVE_LIBT1_OUTLINE
2001-09-25 21:58:48 +00:00
str_path = T1_GetCharOutline ( f_ind - > font_id , Z_STRVAL_P ( str ) [ 0 ] , Z_LVAL_P ( sz ) , transform ) ;
1999-10-08 07:56:43 +00:00
2001-09-25 21:58:48 +00:00
for ( i = 1 ; i < Z_STRLEN_P ( str ) ; i + + ) {
amount_kern = ( int ) T1_GetKerning ( f_ind - > font_id , Z_STRVAL_P ( str ) [ i - 1 ] , Z_STRVAL_P ( str ) [ i ] ) ;
amount_kern + = Z_STRVAL_P ( str ) [ i - 1 ] = = ' ' ? space : 0 ;
1999-10-08 07:56:43 +00:00
add_width = ( int ) ( amount_kern + width ) / f_ind - > extend ;
2001-09-25 21:58:48 +00:00
char_path = T1_GetMoveOutline ( f_ind - > font_id , add_width , 0 , 0 , Z_LVAL_P ( sz ) , transform ) ;
1999-10-08 07:56:43 +00:00
str_path = T1_ConcatOutlines ( str_path , char_path ) ;
2001-09-25 21:58:48 +00:00
char_path = T1_GetCharOutline ( f_ind - > font_id , Z_STRVAL_P ( str ) [ i ] , Z_LVAL_P ( sz ) , transform ) ;
1999-10-08 07:56:43 +00:00
str_path = T1_ConcatOutlines ( str_path , char_path ) ;
}
str_img = T1_AAFillOutline ( str_path , 0 ) ;
# else
1999-12-17 20:55:31 +00:00
php_error ( E_WARNING , " Setting space between characters in function ImagePSText is supported only with t1lib version 0.9 or above " ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
# endif
} else {
2001-09-25 21:58:48 +00:00
str_img = T1_AASetString ( f_ind - > font_id , Z_STRVAL_P ( str ) , Z_STRLEN_P ( str ) ,
space , T1_KERNING , Z_LVAL_P ( sz ) , transform ) ;
1999-10-08 07:56:43 +00:00
}
if ( T1_errno ) RETURN_FALSE ;
h_lines = str_img - > metrics . ascent - str_img - > metrics . descent ;
v_lines = str_img - > metrics . rightSideBearing - str_img - > metrics . leftSideBearing ;
for ( i = 0 ; i < v_lines ; i + + ) {
for ( j = 0 ; j < h_lines ; j + + ) {
switch ( str_img - > bits [ j * v_lines + i ] ) {
case 0 :
break ;
default :
c_ind = aa [ str_img - > bits [ j * v_lines + i ] - 1 ] ;
gdImageSetPixel ( bg_img , x + str_img - > metrics . leftSideBearing + i , y - str_img - > metrics . ascent + j , c_ind ) ;
}
}
}
if ( array_init ( return_value ) = = FAILURE ) {
RETURN_FALSE ;
}
add_next_index_long ( return_value , str_img - > metrics . leftSideBearing ) ;
add_next_index_long ( return_value , str_img - > metrics . descent ) ;
add_next_index_long ( return_value , str_img - > metrics . rightSideBearing ) ;
add_next_index_long ( return_value , str_img - > metrics . ascent ) ;
}
/* }}} */
2000-02-22 15:48:43 +00:00
/* {{{ proto array imagepsbbox(string text, int font, int size [, int space, int tightness, int angle])
Return the bounding box needed by a string if rasterized */
1999-12-17 21:50:07 +00:00
PHP_FUNCTION ( imagepsbbox )
{
1999-10-08 07:56:43 +00:00
pval * str , * fnt , * sz , * sp , * wd , * ang ;
int i , space , add_width , char_width , amount_kern , type ;
int cur_x , cur_y , dx , dy ;
int x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ;
gd_ps_font * f_ind ;
int per_char = 0 ;
double angle , sin_a , cos_a ;
BBox char_bbox , str_bbox = { 0 , 0 , 0 , 0 } ;
2000-06-05 19:47:54 +00:00
switch ( ZEND_NUM_ARGS ( ) ) {
1999-10-08 07:56:43 +00:00
case 3 :
1999-12-20 17:34:55 +00:00
if ( zend_get_parameters ( ht , 3 , & str , & fnt , & sz ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
convert_to_string ( str ) ;
convert_to_long ( fnt ) ;
convert_to_long ( sz ) ;
space = 0 ;
break ;
case 6 :
1999-12-20 17:34:55 +00:00
if ( zend_get_parameters ( ht , 6 , & str , & fnt , & sz , & sp , & wd , & ang ) = = FAILURE ) {
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
convert_to_string ( str ) ;
convert_to_long ( fnt ) ;
convert_to_long ( sz ) ;
convert_to_long ( sp ) ;
2001-09-25 21:58:48 +00:00
space = Z_LVAL_P ( sp ) ;
1999-10-08 07:56:43 +00:00
convert_to_long ( wd ) ;
2001-09-25 21:58:48 +00:00
add_width = Z_LVAL_P ( wd ) ;
1999-10-08 07:56:43 +00:00
convert_to_double ( ang ) ;
2001-09-25 21:58:48 +00:00
angle = Z_DVAL_P ( ang ) * M_PI / 180 ;
1999-10-08 07:56:43 +00:00
sin_a = sin ( angle ) ;
cos_a = cos ( angle ) ;
per_char = add_width | | angle ? 1 : 0 ;
break ;
default :
WRONG_PARAM_COUNT ;
}
2001-09-25 21:58:48 +00:00
f_ind = zend_list_find ( Z_LVAL_P ( fnt ) , & type ) ;
1999-10-08 07:56:43 +00:00
if ( type ! = GD_GLOBAL ( le_ps_font ) ) {
2001-09-25 21:58:48 +00:00
php_error ( E_WARNING , " %d is not a Type 1 font index " , Z_LVAL_P ( fnt ) ) ;
1999-10-08 07:56:43 +00:00
RETURN_FALSE ;
}
# define max(a, b) (a > b ? a : b)
# define min(a, b) (a < b ? a : b)
# define new_x(a, b) (int) ((a) * cos_a - (b) * sin_a)
# define new_y(a, b) (int) ((a) * sin_a + (b) * cos_a)
if ( per_char ) {
space + = T1_GetCharWidth ( f_ind - > font_id , ' ' ) ;
cur_x = cur_y = 0 ;
2001-09-25 21:58:48 +00:00
for ( i = 0 ; i < Z_STRLEN_P ( str ) ; i + + ) {
if ( Z_STRVAL_P ( str ) [ i ] = = ' ' ) {
1999-10-08 07:56:43 +00:00
char_bbox . llx = char_bbox . lly = char_bbox . ury = 0 ;
char_bbox . urx = char_width = space ;
} else {
2001-09-25 21:58:48 +00:00
char_bbox = T1_GetCharBBox ( f_ind - > font_id , Z_STRVAL_P ( str ) [ i ] ) ;
char_width = T1_GetCharWidth ( f_ind - > font_id , Z_STRVAL_P ( str ) [ i ] ) ;
1999-10-08 07:56:43 +00:00
}
2001-09-25 21:58:48 +00:00
amount_kern = i ? T1_GetKerning ( f_ind - > font_id , Z_STRVAL_P ( str ) [ i - 1 ] , Z_STRVAL_P ( str ) [ i ] ) : 0 ;
1999-10-08 07:56:43 +00:00
/* Transfer character bounding box to right place */
x1 = new_x ( char_bbox . llx , char_bbox . lly ) + cur_x ;
y1 = new_y ( char_bbox . llx , char_bbox . lly ) + cur_y ;
x2 = new_x ( char_bbox . llx , char_bbox . ury ) + cur_x ;
y2 = new_y ( char_bbox . llx , char_bbox . ury ) + cur_y ;
x3 = new_x ( char_bbox . urx , char_bbox . ury ) + cur_x ;
y3 = new_y ( char_bbox . urx , char_bbox . ury ) + cur_y ;
x4 = new_x ( char_bbox . urx , char_bbox . lly ) + cur_x ;
y4 = new_y ( char_bbox . urx , char_bbox . lly ) + cur_y ;
/* Find min & max values and compare them with current bounding box */
str_bbox . llx = min ( str_bbox . llx , min ( x1 , min ( x2 , min ( x3 , x4 ) ) ) ) ;
str_bbox . lly = min ( str_bbox . lly , min ( y1 , min ( y2 , min ( y3 , y4 ) ) ) ) ;
str_bbox . urx = max ( str_bbox . urx , max ( x1 , max ( x2 , max ( x3 , x4 ) ) ) ) ;
str_bbox . ury = max ( str_bbox . ury , max ( y1 , max ( y2 , max ( y3 , y4 ) ) ) ) ;
/* Move to the next base point */
dx = new_x ( char_width + add_width + amount_kern , 0 ) ;
dy = new_y ( char_width + add_width + amount_kern , 0 ) ;
cur_x + = dx ;
cur_y + = dy ;
/*
printf ( " %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \n " , x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 , char_bbox . llx , char_bbox . lly , char_bbox . urx , char_bbox . ury , char_width , amount_kern , cur_x , cur_y , dx , dy ) ;
*/
}
} else {
2001-09-25 21:58:48 +00:00
str_bbox = T1_GetStringBBox ( f_ind - > font_id , Z_STRVAL_P ( str ) , Z_STRLEN_P ( str ) , space , T1_KERNING ) ;
1999-10-08 07:56:43 +00:00
}
if ( T1_errno ) RETURN_FALSE ;
if ( array_init ( return_value ) = = FAILURE ) {
RETURN_FALSE ;
}
/*
printf ( " %d %d %d %d \n " , str_bbox . llx , str_bbox . lly , str_bbox . urx , str_bbox . ury ) ;
*/
2001-09-25 21:58:48 +00:00
add_next_index_long ( return_value , ( int ) ceil ( ( ( double ) str_bbox . llx ) * Z_LVAL_P ( sz ) / 1000 ) ) ;
add_next_index_long ( return_value , ( int ) ceil ( ( ( double ) str_bbox . lly ) * Z_LVAL_P ( sz ) / 1000 ) ) ;
add_next_index_long ( return_value , ( int ) ceil ( ( ( double ) str_bbox . urx ) * Z_LVAL_P ( sz ) / 1000 ) ) ;
add_next_index_long ( return_value , ( int ) ceil ( ( ( double ) str_bbox . ury ) * Z_LVAL_P ( sz ) / 1000 ) ) ;
1999-10-08 07:56:43 +00:00
}
/* }}} */
2000-02-25 06:43:51 +00:00
# endif /* HAVE_LIBT1 */
# endif /* 0 */
1999-10-08 07:56:43 +00:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
*/