Mike42\Escpos\EscposImage::getColumnFormatLine PHP Method

getColumnFormatLine() private method

Output image in column format. Must be called once for each line of output.
private getColumnFormatLine ( string $lineNo, string $highDensity ) : null | string
$lineNo string Line number to retrieve
$highDensity string True for high density output (24px lines), false for regular density (8px)
return null | string Column format data, or null if there is no more data (when iterating)
    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;
    }