Mike42\Escpos\Printer::selectCharacterTable PHP Метод

selectCharacterTable() публичный Метод

Switch character table (code page) manually. Used in conjunction with textRaw() to print special characters which can't be encoded automatically.
public selectCharacterTable ( integer $table )
$table integer The table to select. Available code tables are model-specific.
    public function selectCharacterTable($table = 0)
    {
        self::validateInteger($table, 0, 255, __FUNCTION__);
        $supported = $this->profile->getCodePages();
        if (!isset($supported[$table])) {
            throw new InvalidArgumentException("There is no code table {$table} allowed by this printer's capability profile.");
        }
        $this->characterTable = $table;
        if ($this->profile->getSupportsStarCommands()) {
            /* Not an ESC/POS command: STAR printers stash all the extra code pages under a different command. */
            $this->connector->write(self::ESC . self::GS . "t" . chr($table));
            return;
        }
        $this->connector->write(self::ESC . "t" . chr($table));
    }

Usage Example

Пример #1
0
 /**
  * Encode a block of text using the specified map, and write it to the printer.
  *
  * @param string $text Text to print, UTF-8 format.
  * @param integer $encodingNo Encoding number to use- assumed to exist.
  */
 private function writeTextUsingEncoding($text, $encodingNo)
 {
     $encodeMap = $this->encode[$encodingNo];
     $len = mb_strlen($text, self::INPUT_ENCODING);
     $rawText = str_repeat(self::REPLACEMENT_CHAR, $len);
     $j = 0;
     for ($i = 0; $i < $len; $i++) {
         $char = mb_substr($text, $i, 1, self::INPUT_ENCODING);
         if (isset($encodeMap[$char])) {
             $rawText[$j] = $encodeMap[$char];
         } elseif (self::asciiCheck($char)) {
             $rawText[$j] = $char;
         } elseif ($char === "\r") {
             /* Skip past Windows line endings (UTF-8 usage) */
             continue;
         }
         $j++;
     }
     if ($this->printer->getCharacterTable() != $encodingNo) {
         $this->printer->selectCharacterTable($encodingNo);
     }
     $this->writeTextRaw(substr($rawText, 0, $j));
 }
All Usage Examples Of Mike42\Escpos\Printer::selectCharacterTable