private function getColumnFormatLine($lineNo, $highDensity)
{
// Currently double density in both directions, very experimental
$widthPixels = $this->getWidth();
$heightPixels = $this->getHeight();
$widthBytes = $this->getWidthBytes();
$heightBytes = $this->getHeightBytes();
$lineHeight = $highDensity ? 3 : 1;
// Vertical density. 1 or 3 (for 8 and 24 pixel lines)
// Initialise to zero
$x = $y = $bit = $byte = $byteVal = 0;
$data = str_repeat("", $widthPixels * $lineHeight);
$yStart = $lineHeight * 8 * $lineNo;
if ($yStart >= $heightPixels) {
return null;
}
if (strlen($data) == 0) {
return $data;
}
do {
$yReal = $y + $yStart;
if ($yReal < $heightPixels) {
$byteVal |= (int) $this->imgData[$yReal * $widthPixels + $x] << 7 - $bit;
}
$y++;
$bit++;
if ($y >= $lineHeight * 8) {
$y = 0;
$x++;
$bit = 8;
if ($x >= $widthPixels) {
$data[$byte] = chr($byteVal);
break;
}
}
if ($bit >= 8) {
$data[$byte] = chr($byteVal);
$byteVal = 0;
$bit = 0;
$byte++;
}
} while (true);
if (strlen($data) != $widthPixels * $lineHeight) {
throw new Exception("Bug in " . __FUNCTION__ . ", wrong number of bytes.");
}
return $data;
}