Yes, I have made some of those implementations in PHP, the way I do it is with spaces like these:
/**
*
* @param int $x
* @param int $y
* @param string $text
* @return Fortia_JZebra
*/
public function leftText($x, $y, $text, $maxWidth = null)
{
$text = $this->_cleanText($text);
if($maxWidth)
{
$text = substr($text, 0, $maxWidth);
}
$this->_initLine($y);
//ahora reemplazamos la cadena
$this->_lines[$y] = substr(substr_replace($this->_lines[$y], $text ,$x, strlen($text)), 0, $this->_maxWidth);
return $this;
}
public function boxText($x, $y, $text, $width)
{
//colocaremos un escape.. por si no hay ancho
if(!$width)
{
$width = 80;
}
//primero dividimos el texto, en saltos de linea
//$lines = explode("\r\n", $text);//trimeamos con retorno de carro y salto de linea
$lines = preg_split("/[\r\n]+/", $text);//trimeamos con retorno de carro y salto de linea
//ahora examinamos cada linea, para que no pase del width determinado
$printedLines = 0;
foreach ($lines as $line)
{
$line = trim($line);
if($line)
{
while(strlen($line) > $width)
{
//si es mayor al ancho, cortamos por espacios
$cut = strrpos(substr($line, 0, $width), ' ');
if($cut === false)//si no hay ningun espacio, cortamos a la mala por el ancho
{
$cut = $width;
}
$cut++;//+1 por el espacio en blanco
$subline = substr($line, 0, $cut);
$this->leftText($x, $y, $subline);
$printedLines++;
$y++;
//y actualizamos la linea
$line = substr($line, $cut);
}
$this->leftText($x, $y, $line);
$printedLines++;
$y++;
}
}
return $printedLines;
}
Hope this helps...