Ejecuto este código:
function calculateTextBox($font_size, $font_angle, $font_file, $text)
{
// Codigo simple par aver si estoy en desarrollo o en produccion y de
donde tengo que coger el archivo.
$mivar1 = get_web_tienda($_SESSION['tienda']);
if (!ModoProduccion()) $mivar2 =
$mivar1[0]['desarrollo'];
else $mivar2 = $mivar1[0]['produccion'];
$mifont = $mivar2.ROOT.'/'.URLFonts().'/'.$font_file;
if (!is_file($mifont)) $mifont =
$mivar2.ROOT.'/'.URLFonts().'/arial.ttf';
echo $mifont.'<br>'; // esta línea escribe este texto lo
cual indica que el archivo esta bien referenciado:
‘localhost/v1/fonts/arial.ttf’ si lo pongo en el IE me descarga el archivo
arial.ttf o sea que
esta bien
$box = imagettfbbox($font_size, $font_angle, $mifont,
$text);
$min_x = min(array($box[0], $box[2], $box[4], $box[6]));
$max_x = max(array($box[0], $box[2], $box[4], $box[6]));
$min_y = min(array($box[1], $box[3], $box[5], $box[7]));
$max_y = max(array($box[1], $box[3], $box[5], $box[7]));
return array(
'left' => ($min_x >= -1) ? -abs($min_x + 1) : abs($min_x + 2),
'top' => abs($min_y),
'width' => $max_x - $min_x,
'height' => $max_y - $min_y,
'box' => $box
);
}
Function CuentaPixels($texto)
{
echo REFERENCIA_FONTSIZE .' de tamaño<br>'; // FONT_SIZE es una
constante que vale 11
echo REFERENCIA_TIPOLETRA .' de tipo letra<br>'; // REFERENCIA_TIPOLETRA
vale ‘arial.ttf’
$retorno = calculateTextBox( REFERENCIA_FONTSIZE ,0 ,
REFERENCIA_TIPOLETRA , $texto);
return $retorno['width'];
}
function EscribeReferencia($texto)
{
$limite = REFERENCIA_WIDTH; // vale 128 que son los pixels que me caben
en la caja y el $texto es ‘MINITORRE’
$ncontador = 1;
echo $limite.' pixels de limite<br>';
echo $texto.'<br>';
echo Cuentapixels($texto).' pixels';
//while (Cuentapixels(substr($texto,1,$ncontador))<=$limite)
$ncontador++; una vez que cuentapixels devuelva bien el valor esta línea
quitara letras hasta ver lo que cabe en los pixels disponibles..
echo substr($texto,1,$ncontador-1);
}
Y esto es lo que me devuelve la pantalla:
MINITORRE
--àesto es $texto
Ref.: 128 pixels de limite ->
esto es $limite
9,20E+16
11 de tamaño
arial.ttf de tipo letra
localhost/v1/fonts/arial.ttf
Warning: imagettfbbox() [function.imagettfbbox
<http://localhost/v1/site/function.imagettfbbox> ]: Invalid font filename in
D:\xampp\htdocs\v1\include\general.php on line 305
0 pixels o sea cuentapixels me devuelve siempre 0 porque no carga el Font.
GDINFO me devuelve esto:
array(12) { ["GD Version"]=> string(27) "bundled (2.0.34 compatible)"
["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with
freetype" ["T1Lib Support"]=> bool(true) ["GIF Read Support"]=> bool(true)
["GIF Create Support"]=> bool(true) ["JPG Support"]=> bool(true) ["PNG
Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=>
bool(false) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font
Support"]=> bool(false) } Que hago mal?
Fdo Josu Udaondo Orúe