Last active
December 16, 2015 21:29
-
-
Save ihsanfaisal/5500036 to your computer and use it in GitHub Desktop.
populate epson escape commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Ihsan Faisal | |
*/ | |
class EscapeCommand | |
{ | |
const ESC = "\x1B"; | |
private $commands = ""; | |
public function __construct() { | |
$this->commands = ""; | |
$this->addResetCommand(); | |
} | |
public function getCommands() { | |
return $this->commands; | |
} | |
public function addResetCommand() { | |
$this->commands .= self::ESC . "@"; | |
return $this->commands; | |
} | |
public function addLineSpacing_1_6() { | |
$this->commands .= self::ESC . "2"; | |
return $this->commands; | |
} | |
public function addLineSpacing_1_8() { | |
$this->commands .= self::ESC . "0"; | |
return $this->commands; | |
} | |
public function addLineSpacing_n_216($n) { | |
$this->commands .= self::ESC . "3" . "\x$n"; | |
return $this->commands; | |
} | |
public function addPageLength33Lines() { | |
$this->commands .= self::ESC . "C" . "\x21"; | |
return $this->commands; | |
} | |
public function addMarginBottom5Lines() { | |
$this->commands .= self::ESC . "N" . "\x05"; | |
return $this->commands; | |
} | |
public function addMaster10CPI() { | |
$this->commands .= self::ESC . "!" . "\x00"; | |
return $this->commands; | |
} | |
public function addMasterCondensed() { | |
$this->commands .= self::ESC . "!" . "\x04"; | |
return $this->commands; | |
} | |
public function addModeDraft() { | |
$this->commands .= self::ESC . "x" . "\x00"; | |
return $this->commands; | |
} | |
public function addModeNLQ() { | |
$this->commands .= self::ESC . "x" . "\x01"; | |
return $this->commands; | |
} | |
public function addFormFeed() { | |
$this->commands .= "\x0C"; | |
return $this->commands; | |
} | |
public function addContent($content) { | |
$this->commands .= $content; | |
return $this->commands; | |
} | |
} | |
$commands = new EscapeCommand(); | |
$commands->addLineSpacing_1_6(); | |
$commands->addPageLength33Lines(); | |
$commands->addMarginBottom5Lines(); | |
$commands->addMaster10CPI(); | |
$commands->addMasterCondensed(); | |
$commands->addModeDraft(); | |
$commands->addContent("Sample content\r\n"); | |
$commands->addContent("Sample content\r\n"); | |
$commands->addContent("Sample content\r\n"); | |
$commands->addContent("Sample content\r\n"); | |
$commands->addContent("Sample content\r\n"); | |
$commands->addFormFeed(); | |
$commands->addResetCommand(); | |
$fp = fopen("/path/to/a/file", "w"); | |
fwrite($fp, $commands->getCommands()); | |
fclose($fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment