Mike42\Escpos\PrintBuffers\EscposPrintBuffer::writeText PHP Method

writeText() public method

public writeText ( $text )
    public function writeText($text)
    {
        if ($this->printer == null) {
            throw new LogicException("Not attached to a printer.");
        }
        if ($text == null) {
            return;
        }
        if (!mb_detect_encoding($text, self::INPUT_ENCODING, true)) {
            // Assume that the user has already put non-UTF8 into the target encoding.
            return $this->writeTextRaw($text);
        }
        $i = 0;
        $j = 0;
        $len = mb_strlen($text, self::INPUT_ENCODING);
        while ($i < $len) {
            $matching = true;
            if (($encoding = $this->identifyText(mb_substr($text, $i, 1, self::INPUT_ENCODING))) === false) {
                // Un-encodeable text
                $encoding = $this->getPrinter()->getCharacterTable();
            }
            $i++;
            $j = 1;
            do {
                $char = mb_substr($text, $i, 1, self::INPUT_ENCODING);
                $matching = !isset($this->available[$char]) || isset($this->available[$char][$encoding]);
                if ($matching) {
                    $i++;
                    $j++;
                }
            } while ($matching && $i < $len);
            $this->writeTextUsingEncoding(mb_substr($text, $i - $j, $j, self::INPUT_ENCODING), $encoding);
        }
    }