Skip to content

Commit

Permalink
Merge pull request #211 from mike42/development
Browse files Browse the repository at this point in the history
Changes for release 1.4.1
  • Loading branch information
mike42 authored Nov 3, 2016
2 parents 5e59b66 + 30103cf commit b3665b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- Excelvan ZJ-8220
- Gainscha GP-5890x (Also marketed as EC Line 5890x)
- Gainscha GP-U80300I
- Hasar HTP 250
- Okipos 80 Plus III
- P-822D
- P85A-401 (make unknown)
Expand Down
26 changes: 19 additions & 7 deletions src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,20 @@ public function writeTextRaw($text)
return;
}
// Pass only printable characters
for ($i = 0; $i < strlen($text); $i++) {
$j = 0;
$l = strlen($text);
$outp = str_repeat(self::REPLACEMENT_CHAR, $l);
for ($i = 0; $i < $l; $i++) {
$c = substr($text, $i, 1);
if (!self::asciiCheck($c, true)) {
$text[$i] = self::REPLACEMENT_CHAR;
if ($c == "\r") {
/* Skip past Windows line endings (raw usage). */
continue;
} else if (self::asciiCheck($c, true)) {
$outp[$j] = $c;
}
$j++;
}
$this -> write($text);
$this -> write(substr($outp, 0, $j));
}

/**
Expand Down Expand Up @@ -236,18 +243,23 @@ 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[$i] = $encodeMap[$char];
$rawText[$j] = $encodeMap[$char];
} elseif (self::asciiCheck($char)) {
$rawText[$i] = $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($rawText);
$this -> writeTextRaw(substr($rawText, 0, $j));
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/unit/EscposPrintBufferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,14 @@ public function testVietnamese() {
$this -> buffer -> writeText("Tiếng Việt, còn gọi tiếng Việt Nam hay Việt ngữ, là ngôn ngữ của người Việt (người Kinh) và là ngôn ngữ chính thức tại Việt Nam.\n");
$this -> checkOutput("\x1b@Ti\x1bt\x1e\xd5ng Vi\xd6t, c\xdfn g\xe4i ti\xd5ng Vi\xd6t Nam hay Vi\xd6t ng\xf7, l\xb5 ng\xabn ng\xf7 c\xf1a ng\xad\xeai Vi\xd6t (ng\xad\xeai Kinh) v\xb5 l\xb5 ng\xabn ng\xf7 ch\xddnh th\xf8c t\xb9i Vi\xd6t Nam.\x0a");
}

public function testWindowsLineEndings() {
$this -> buffer -> writeText("Hello World!\r\n");
$this -> checkOutput("\x1b@Hello World!\x0a");
}

public function testWindowsLineEndingsRaw() {
$this -> buffer -> writeTextRaw("Hello World!\r\n");
$this -> checkOutput("\x1b@Hello World!\x0a");
}
}

0 comments on commit b3665b9

Please sign in to comment.