Skip to content

Commit e5baf60

Browse files
committed
docs
1 parent cd6a0bb commit e5baf60

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

README.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,45 @@ use PhpAidc\LabelPrinter\Label\Label;
6464
use PhpAidc\LabelPrinter\Label\Element;
6565
use PhpAidc\LabelPrinter\Connector\NetworkConnector;
6666

67-
$printer = new Printer(new NetworkConnector('192.168.x.x'));
68-
6967
$label = Label::create(Unit::MM(), 43, 25)
7068
->charset(Charset::UTF8())
7169
->add(Element::textBlock(168, 95, 'Hello!', 'Univers', 8)->box(338, 100, 0)->anchor(Anchor::CENTER()))
72-
->add(Element::barcode(10, 10, '123456', 'CODE93')->height(60));
70+
->add(Element::barcode(10, 10, '123456', 'CODE93')->height(60))
71+
;
7372

74-
$printer->print($label);
73+
(new Printer(new NetworkConnector('192.168.x.x')))->print($label);
7574
```
7675

77-
##### Add elements for a specific language
76+
##### Add elements only for a specific language
7877
```php
7978
use PhpAidc\LabelPrinter\Label\Label;
8079
use PhpAidc\LabelPrinter\Label\Element;
8180
use PhpAidc\LabelPrinter\Language\Tspl;
8281
use PhpAidc\LabelPrinter\Language\Fingerprint;
8382

8483
$label = Label::create()
85-
->when(Fingerprint::class, static function (Label $label) {
84+
->for(Fingerprint::class, static function (Label $label) {
8685
$label->add(Element::textLine(168, 95, 'Hello!', 'Univers', 8));
8786
})
88-
->when(Tspl::class, static function (Label $label) {
87+
->for(Tspl::class, static function (Label $label) {
8988
$label->add(Element::textLine(10, 10, 'Hello!', 'ROMAN.TTF', 8));
90-
});
89+
})
90+
;
91+
```
92+
93+
##### Add elements if some value is truthy
94+
```php
95+
use PhpAidc\LabelPrinter\Label\Label;
96+
use PhpAidc\LabelPrinter\Label\Element;
97+
98+
$text = '';
99+
100+
$label = Label::create()
101+
->when($text, static function (Label $label, $text) {
102+
// will not be added until the $text is empty
103+
$label->add(Element::textLine(168, 95, $text, 'Univers', 8));
104+
})
105+
;
91106
```
92107

93108
##### Print images
@@ -98,21 +113,21 @@ use PhpAidc\LabelPrinter\Language\Tspl;
98113
use PhpAidc\LabelPrinter\Language\Fingerprint;
99114

100115
$image = new \Imagick('gift.svg');
101-
$image->scaleImage(100, 100);
102116

103117
$label = Label::create()
104-
->when(Fingerprint::class, static function (Label $label) {
118+
->for(Fingerprint::class, static function (Label $label) {
105119
// from printer's memory — png, bmp, pcx
106120
$label->add(Element::intImage(10, 10, 'GLOBE.1'));
107121
// from filesystem
108122
$label->add(Element::extImage(10, 10, \realpath('alien.png')));
109123
})
110-
->when(Tspl::class, static function (Label $label) {
124+
->for(Tspl::class, static function (Label $label) {
111125
// from printer's memory — bmp, pcx
112126
$label->add(Element::intImage(10, 10, 'ALIEN.BMP'));
113127
})
114128
// from filesystem via Imagick — any supported types
115-
->add(Element::bitmap(50, 10, $image));
129+
->add(Element::bitmap(50, 10, $image))
130+
;
116131
```
117132

118133
##### Print text with emulation
@@ -122,7 +137,8 @@ use PhpAidc\LabelPrinter\Label\Element;
122137

123138
$label = Label::create()
124139
->add(Element::textLine(10, 10, 'Hello!', '/path/to/font/roboto.ttf', 20)->emulate())
125-
->add(Element::textBlock(100, 10, 'Hello again!', '/path/to/font/roboto.ttf', 20)->box(300, 20)->emulate());
140+
->add(Element::textBlock(100, 10, 'Hello again!', '/path/to/font/roboto.ttf', 20)->box(300, 20)->emulate())
141+
;
126142
```
127143
Text will be drawn with Imagick and printed as bitmap.
128144

0 commit comments

Comments
 (0)