zebra-zpl 1.0.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +71 -0
  3. data/CONTRIBUTING.md +49 -0
  4. data/Gemfile +6 -0
  5. data/README.md +348 -89
  6. data/docs/example.rb +290 -0
  7. data/docs/images/barcode.png +0 -0
  8. data/docs/images/datamatrix.png +0 -0
  9. data/docs/images/earth.jpg +0 -0
  10. data/docs/images/graphics.png +0 -0
  11. data/docs/images/image.png +0 -0
  12. data/docs/images/image_inverted.png +0 -0
  13. data/docs/images/image_manipulation.png +0 -0
  14. data/docs/images/images.png +0 -0
  15. data/docs/images/justification.png +0 -0
  16. data/docs/images/qrcode.png +0 -0
  17. data/docs/images/rotation.png +0 -0
  18. data/docs/images/text.png +0 -0
  19. data/lib/zebra/print_job.rb +19 -17
  20. data/lib/zebra/zpl.rb +26 -18
  21. data/lib/zebra/zpl/barcode.rb +29 -12
  22. data/lib/zebra/zpl/barcode_type.rb +4 -1
  23. data/lib/zebra/zpl/box.rb +16 -4
  24. data/lib/zebra/zpl/comment.rb +15 -0
  25. data/lib/zebra/zpl/datamatrix.rb +76 -0
  26. data/lib/zebra/zpl/font.rb +1 -1
  27. data/lib/zebra/zpl/graphic.rb +91 -0
  28. data/lib/zebra/zpl/image.rb +97 -0
  29. data/lib/zebra/zpl/label.rb +3 -14
  30. data/lib/zebra/zpl/pdf417.rb +50 -0
  31. data/lib/zebra/zpl/qrcode.rb +6 -2
  32. data/lib/zebra/zpl/raw.rb +25 -0
  33. data/lib/zebra/zpl/text.rb +44 -20
  34. data/lib/zebra/zpl/version.rb +1 -1
  35. data/spec/fixtures/default.jpg +0 -0
  36. data/spec/spec_helper.rb +6 -2
  37. data/spec/zebra/print_job_spec.rb +13 -18
  38. data/spec/zebra/zpl/barcode_spec.rb +70 -63
  39. data/spec/zebra/zpl/box_spec.rb +27 -31
  40. data/spec/zebra/zpl/character_set_spec.rb +7 -7
  41. data/spec/zebra/zpl/comment_spec.rb +18 -0
  42. data/spec/zebra/zpl/datamatrix_spec.rb +124 -0
  43. data/spec/zebra/zpl/graphics_spec.rb +227 -0
  44. data/spec/zebra/zpl/image_spec.rb +146 -0
  45. data/spec/zebra/zpl/label_spec.rb +41 -53
  46. data/spec/zebra/zpl/pdf417_spec.rb +108 -0
  47. data/spec/zebra/zpl/qrcode_spec.rb +92 -92
  48. data/spec/zebra/zpl/text_spec.rb +60 -55
  49. data/zebra-zpl.gemspec +12 -12
  50. metadata +63 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4601d04149c76a88c86a00b57b76b004ff603183
4
- data.tar.gz: 75b6773cd9f63a0d9ca27e5b799949d076dfb150
2
+ SHA256:
3
+ metadata.gz: dc4d0325bb49923c0936ec1a9945e0abd7ff840be83a761135b841ede695fadf
4
+ data.tar.gz: 8e085aeccc1055499e96c43c3585ecbe5e024d761618014583db6ca338941d24
5
5
  SHA512:
6
- metadata.gz: 3883a043edbe74c0d9e8847f3ca3c48ef9c16605d703cc5efcd400623ab833cdb11706249412c5828d32bc2b3139dce1efd34c3e70ac503769ad0265fde5b25d
7
- data.tar.gz: eb2baa12fff0b2b6eddc69692fea622ec2d7474947965ec9a6792196a3aa23f210671436e86783e44a09b08df32c261812f78668430bb0d5e05d988ce3eccb76
6
+ metadata.gz: 982e20fa56bc1deef5c9421e83c60da9c377e0d3acb68c4d3ec5ed33c309c86ef2ca48d51a2f62b6599ec8ac79db708b32db904620e72c2c3c252d7dcb600c28
7
+ data.tar.gz: 45fa3614e53bdc7b8ea1c95f75311768b1727cb1621776af195578c9781c96d0d5b023af151ad32b2a3ac48141e76c5faaa1b9e738b55e753c3fd7fc031da28f
@@ -0,0 +1,71 @@
1
+ ### 1.1.3 (10/05/2020)
2
+
3
+ * [#70](https://github.com/bbulpett/zebra-zpl/pull/70): Update max print speed from 6 to 14 - [@eke-bb](https://github.com/eke-bb)
4
+
5
+ ### 1.1.2 (02/25/2019)
6
+
7
+ * [#63](https://github.com/bbulpett/zebra-zpl/pull/63): Un-restrict font size - [@mtking2](https://github.com/mtking2)
8
+ * [#62](https://github.com/bbulpett/zebra-zpl/pull/62): Add print service option for print jobs (`lp`/`rlpr`) - [@LagTag](https://github.com/LagTag)
9
+
10
+ ### 1.1.1 (12/19/2019)
11
+
12
+ * [#58](https://github.com/bbulpett/zebra-zpl/pull/58): Add access to source `Img2Zpl::Image` object - [@mtking2](https://github.com/mtking2)
13
+
14
+ ### 1.1.0 (11/04/2019)
15
+
16
+ * [#54](https://github.com/bbulpett/zebra-zpl/pull/54): Fix height bug with ^B commands - [@mtking2](https://github.com/mtking2)
17
+ * [#53](https://github.com/bbulpett/zebra-zpl/pull/53): Added support for symbol types, fixed other bugs with the `Graphic` class, updated specs - [@mtking2](https://github.com/mtking2)
18
+ * [#50](https://github.com/bbulpett/zebra-zpl/pull/50): Add support for image elements by incorporating the [img2zpl](https://github.com/mtking2/img2zpl) gem - [@mtking2](https://github.com/mtking2)
19
+ * [#49](https://github.com/bbulpett/zebra-zpl/pull/49): Fixed bug with `Barcode`'s `^BY` command. Added UPCA, UPCE, & EAN13 types - [@mtking2](https://github.com/mtking2)
20
+ * [#48](https://github.com/bbulpett/zebra-zpl/pull/48): Fixed bug breaking `Text` elements. Added rspecs for `Datamatrix` - [@mtking2](https://github.com/mtking2)
21
+ * [#45](https://github.com/bbulpett/zebra-zpl/pull/45): Add CHANGELOG & update README - [@mtking2](https://github.com/mtking2)
22
+ * [#44](https://github.com/bbulpett/zebra-zpl/pull/44): Update README & add more docs - [@mtking2](https://github.com/mtking2)
23
+ * [#43](https://github.com/bbulpett/zebra-zpl/pull/43): Add ZPL comment element - [@LagTag](https://github.com/LagTag)
24
+ * [#42](https://github.com/bbulpett/zebra-zpl/pull/42): Consolidate Graphic Elements to One Class. Deprecate `Box` class - [@LagTag](https://github.com/LagTag)
25
+ * [#41](https://github.com/bbulpett/zebra-zpl/pull/41): Ability to pass ZPL string to PrintJob - [@LagTag](https://github.com/LagTag)
26
+ * [#40](https://github.com/bbulpett/zebra-zpl/pull/40): Bold Text - [@LagTag](https://github.com/LagTag)
27
+ * [#39](https://github.com/bbulpett/zebra-zpl/pull/39): Fix specs + minor maintenance - [@mtking2](https://github.com/mtking2)
28
+ * [#36](https://github.com/bbulpett/zebra-zpl/pull/36): Add Datamatrix - [@rafaelmf3](https://github.com/rafaelmf3)
29
+ * [#33](https://github.com/bbulpett/zebra-zpl/pull/33): Remove the hardcoded attributes for the box element - [@LagTag](https://github.com/LagTag)
30
+ * [#32](https://github.com/bbulpett/zebra-zpl/pull/32): Added diagonal line graphic (^GD) - [@LagTag](https://github.com/LagTag)
31
+ * [#31](https://github.com/bbulpett/zebra-zpl/pull/31): Added Circle Graphic (^GC) - [@LagTag](https://github.com/LagTag)
32
+ * [#29](https://github.com/bbulpett/zebra-zpl/pull/29): Removed hard coded attributes in Text Element - [@LagTag](https://github.com/LagTag)
33
+ * [#27](https://github.com/bbulpett/zebra-zpl/pull/27): Added pdf417 support - [@LagTag](https://github.com/LagTag)
34
+ * [#25](https://github.com/bbulpett/zebra-zpl/pull/25): Don't Overwrite Element Widths - [@LagTag](https://github.com/LagTag)
35
+
36
+ ### 1.0.5 (2018/10/25)
37
+
38
+ * [#22](https://github.com/bbulpett/zebra-zpl/pull/22): update label print density range from 0-6 to 0-15 - [@steve-abrams](https://github.com/steve-abrams)
39
+ * [#21](https://github.com/bbulpett/zebra-zpl/pull/21): Support QR codes (fixed) - [@mtking2](https://github.com/mtking2)
40
+ * [#20](https://github.com/bbulpett/zebra-zpl/pull/20): Fix incorrect raw flag - [@mtking2](https://github.com/mtking2)
41
+
42
+ ### 1.0.4 (2017/10/27)
43
+
44
+ * [#15](https://github.com/bbulpett/zebra-zpl/pull/15): Raw ZPL support - [@bbulpett](https://github.com/bbulpett)
45
+
46
+ ### 1.0.3 (2017/06/12)
47
+
48
+ * [#14](https://github.com/bbulpett/zebra-zpl/pull/14): Version bump to 1.0.3 - [@bbulpett](https://github.com/bbulpett)
49
+ * [#13](https://github.com/bbulpett/zebra-zpl/pull/13): Windows Printing Support - [@mtking2](https://github.com/mtking2)
50
+
51
+ ### 1.0.2 (2017/04/27)
52
+
53
+ * [ead84a4](https://github.com/bbulpett/zebra-zpl/commit/ead84a4170f291e9a121263ac0ce577b9b5b21ba): Revert to Unix-only `lp` - [@bbulpett](https://github.com/bbulpett)
54
+
55
+ ### 1.0.1 (2017/04/26)
56
+
57
+ * [b5e3f3e](https://github.com/bbulpett/zebra-zpl/commit/b5e3f3ea41960ce953073dcf1b09c28047a17b0d): Attempt `lpr` for Windows if Unix `lp` fails - [@bbulpett](https://github.com/bbulpett)
58
+ * [3858b33](https://github.com/bbulpett/zebra-zpl/commit/3858b332491d7afe34277d43530e0da7462da2b1): Use SSL for homepage in gemspec - [@bbulpett](https://github.com/bbulpett)
59
+
60
+ ### 1.0.0 (2017/04/26)
61
+
62
+ * [#10](https://github.com/bbulpett/zebra-zpl/pull/10): Add side margins - [@bbulpett](https://github.com/bbulpett)
63
+ * [#9](https://github.com/bbulpett/zebra-zpl/pull/9): Add padding to sides for text blocks - [@bbulpett](https://github.com/bbulpett)
64
+ * [#8](https://github.com/bbulpett/zebra-zpl/pull/8): Add rotation to zpl builders - [@bbulpett](https://github.com/bbulpett)
65
+ * [#7](https://github.com/bbulpett/zebra-zpl/pull/7): Add international text support and apply label width to zpl builder methods - [@bbulpett](https://github.com/bbulpett)
66
+ * [#6](https://github.com/bbulpett/zebra-zpl/pull/6): Font modifications - [@bbulpett](https://github.com/bbulpett)
67
+ * [#5](https://github.com/bbulpett/zebra-zpl/pull/5): Restore barcode functionality - [@bbulpett](https://github.com/bbulpett)
68
+ * [#4](https://github.com/bbulpett/zebra-zpl/pull/4): Orientation module - [@bbulpett](https://github.com/bbulpett)
69
+ * [#3](https://github.com/bbulpett/zebra-zpl/pull/3): Restore zpl barcode logic - [@bbulpett](https://github.com/bbulpett)
70
+ * [#2](https://github.com/bbulpett/zebra-zpl/pull/2): ZPL barcodes tested and working - [@bbulpett](https://github.com/bbulpett)
71
+ * [#1](https://github.com/bbulpett/zebra-zpl/pull/1): Convert zpl method, class, and file namings - [@bbulpett](https://github.com/bbulpett)
@@ -0,0 +1,49 @@
1
+ ## Contributing
2
+
3
+ Check [open issues](https://github.com/bbulpett/zebra-zpl/issues) for things that need work.
4
+ Also check any [open pull requests](https://github.com/bbulpett/zebra-zpl/pulls) to make sure any changes you want to make haven't already been made by someone else.
5
+
6
+ ### Fork & clone the repository
7
+
8
+ ```
9
+ git clone git@github.com:<your-username>/zebra-zpl.git
10
+ cd zebra-zpl
11
+ git remote add upstream git@github.com:bbulpett/zebra-zpl.git
12
+ bundle install
13
+ ```
14
+
15
+ Then check out a working branch:
16
+
17
+ ```
18
+ git checkout -b <my-working-branch>
19
+ ```
20
+
21
+ ### Write tests
22
+
23
+ This project uses `rspec`. After writing your tests, you can run tests with the following command:
24
+
25
+ `bundle exec rspec`
26
+
27
+
28
+ ### Write code
29
+
30
+ Write your code to make your tests pass.
31
+
32
+ ### Update the CHANGELOG with a description and your name
33
+
34
+ Update `CHANGELOG.md` with the description of your code changes and your name on the line after `"* Your contribution here"`.
35
+
36
+ ### Commit & Push your changes
37
+
38
+ Commit and push your changes to your working branch.
39
+
40
+ ```
41
+ git commit -am 'Add some feature'
42
+ git push origin <my-working-branch>
43
+ ```
44
+
45
+ ### Open a pull request
46
+
47
+ Open a pull request against upstream master and your working branch. Give a brief description of what your PR does and explain what the code changes do.
48
+
49
+ Thank you!
data/Gemfile CHANGED
@@ -1,4 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :development, :test do
4
+ gem 'byebug'
5
+ gem 'pry'
6
+ gem 'pry-nav'
7
+ end
8
+
3
9
  # Specify your gem's dependencies in zebra-zpl.gemspec
4
10
  gemspec
data/README.md CHANGED
@@ -1,10 +1,30 @@
1
- #### This is a gem based on a terrific older gem by Cassio Marques. Although the new printers are mostly compatible with old Eltron (Epl) code, my needs require many of the new Zebra (ZPL) functions.
2
-
3
1
  # Zebra::Zpl
4
2
 
5
- ### ToDo: Update documentation with instructions for new features such as font sizing, margins, and text alignment
3
+ [![gem](https://img.shields.io/gem/v/zebra-zpl?color=orange)](https://rubygems.org/gems/zebra-zpl)
4
+ [![downloads](https://img.shields.io/gem/dt/zebra-zpl?color=brightgreen)](https://rubygems.org/gems/zebra-zpl)
5
+
6
+ Zebra::Zpl offers a Ruby DSL to design and print labels using the ZPL programming language.
7
+
8
+ ## Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Building Labels](#building-labels)
13
+ - [Printing Labels](#printing-the-labels)
14
+ - [Elements](#available-elements)
15
+ - [Text](#text)
16
+ - [Raw ZPL](#raw-zpl)
17
+ - [Barcodes](#barcodes)
18
+ - [QR Codes](#qr-codes)
19
+ - [Data Matrix](#data-matrix)
20
+ - ~[Boxes](#boxes)~ - deprecated. See [Graphics](#graphics)
21
+ - [Images](#images)
22
+ - [Options](#options)
23
+ - [Rotation](#elements-rotation)
24
+ - [Justification](#elements-justification)
25
+ - [Contributing](#contributing)
26
+ - [References](#references)
6
27
 
7
- Zebra::Zpl offers a Ruby DSL to design and print labels using the ZPL programming language.
8
28
 
9
29
  ## Installation
10
30
 
@@ -14,11 +34,11 @@ Add this line to your application's Gemfile:
14
34
 
15
35
  And then execute:
16
36
 
17
- $ bundle
37
+ bundle install
18
38
 
19
39
  Or install it yourself as:
20
40
 
21
- $ gem install zebra-zpl
41
+ gem install zebra-zpl
22
42
 
23
43
  ## Usage
24
44
 
@@ -29,81 +49,97 @@ You create new labels with an instance of the `Zebra::Zpl::Label` class. It acce
29
49
  * `copies`: The number of copies to print. This option defaults to 1.
30
50
  * `width`: The label's width, in dots.
31
51
  * `length`: The label's length, is dots.
32
- * `gap`: The gap between labels, in dots.
33
52
  * `print_speed`: The print speed to be used. You can use values between 0 and 6. This option is required.
34
- * `print_density`: The print density to be used. You can use values between 0 and 15. This option is required.
35
53
 
36
54
  With a label, you can start adding elements to it:
37
55
 
38
- label = Zebra::Zpl::Label.new :print_density => 8, :print_speed => 3
39
- text = Zebra::Zpl::Text.new :data => "Hello, printer!", :position => [100, 100], :font_size => Zebra::Zpl::FontSize::SIZE_2
40
- label << text
41
-
56
+ ```ruby
57
+ label = Zebra::Zpl::Label.new print_speed: 3
58
+ text = Zebra::Zpl::Text.new(
59
+ data: "Hello, printer!",
60
+ position: [100, 100],
61
+ font_size: Zebra::Zpl::FontSize::SIZE_2
62
+ )
63
+ label << text
64
+ ```
65
+
42
66
  You can add as many elements as you want.
43
67
 
44
68
  ### Printing the labels
45
69
 
46
- You need to have your printer visible to CUPS. Once your printer is configured and you know its name on CUPS, you can send the labels to the printer using a `Zebra::PrintJob` instance.
47
-
48
- label = Zebra::Zpl::Label.new(
49
- :width => 200,
50
- :length => 200,
51
- :print_speed => 3,
52
- :print_density => 6
53
- )
54
-
55
-
56
- barcode = Zebra::Zpl::Barcode.new(
57
- :data => "12345678",
58
- :position => [50, 50],
59
- :height => 50,
60
- :print_human_readable_code => true,
61
- :narrow_bar_width => 4,
62
- :wide_bar_width => 8,
63
- :type => Zebra::Zpl::BarcodeType::CODE_128_AUTO
64
- )
65
-
66
- label << barcode
67
-
68
- print_job = Zebra::PrintJob.new "your-printer-name-on-cups"
69
-
70
- print_job.print label
71
-
72
- This will persist the label contents to a tempfile (using Ruby's tempfile core library) and copy the file to the printer using either `lpr -P <your-printer-name-on-cups> -o raw <path-to-the-temp-file>` (if you're on Mac OSX) or `lp -d <your-printer-name-on-cups> -o raw <path-to-the-tempfile>` (if you're on Linux). All the tempfile creation/path resolution, as well as which command has to be used, are handled by the `PrintJob` class.
73
-
74
- ### Printing QR codes
75
-
76
- label = Zebra::Zpl::Label.new(
77
- :width=>350,
78
- :length=>250,
79
- :print_speed=>3,
80
- :print_density=>6
81
- )
82
-
83
- qrcode = Zebra::Zpl::Qrcode.new(
84
- :data=>"www.github.com",
85
- :position=>[50,10],
86
- :scale_factor=>3,
87
- :correction_level=>"H"
88
- )
89
-
90
- label << qrcode
91
-
92
- print_job = Zebra::PrintJob.new "your-qr-printer-name-on-cups"
93
-
94
- print_job.print label
95
-
96
- ### Available elements
97
-
98
- #### Text
70
+ You need to have your printer visible to CUPS (or shared on the network in Windows). Once your printer is configured and you know its name on CUPS (or the Windows shared printer name), you can send the labels to the printer using a `Zebra::PrintJob` instance.
71
+
72
+ ```ruby
73
+ label = Zebra::Zpl::Label.new(
74
+ width: 200,
75
+ length: 200,
76
+ print_speed: 3
77
+ )
78
+
79
+
80
+ barcode = Zebra::Zpl::Barcode.new(
81
+ data: '12345678',
82
+ position: [50, 50],
83
+ height: 50,
84
+ print_human_readable_code: true,
85
+ narrow_bar_width: 4,
86
+ wide_bar_width: 8,
87
+ type: Zebra::Zpl::BarcodeType::CODE_128_AUTO
88
+ )
89
+
90
+ label << barcode
91
+
92
+ print_job = Zebra::PrintJob.new '<your-printer-name-on-cups/windows-shared-printer-name>'
93
+
94
+ ip = '<IP/Host where the print queue lives>' # can use 'localhost', '127.0.0.1', or '0.0.0.0' for local machine
95
+
96
+ print_job.print label, ip
97
+ ```
98
+
99
+ This will persist the label contents to a tempfile (using Ruby's tempfile core library) and copy the file to the printer using either `rlpr -H <hostname/ip> -P <your-printer-name-on-windows> -o <path-to-the-temp-file>` (for Windows systems, see [section](#printing-directly-to-windows-lpd) below) or `lp -h <hostname/ip> -d <your-printer-name-on-cups> -o raw <path-to-the-tempfile>` (for Unix systems). All the tempfile creation/path resolution, as well as which command has to be used, are handled by the `PrintJob` class.
100
+
101
+ ##### Print Service
102
+
103
+ You can specify what print service command you want to be used when calling the `print` method by setting the `:print_service` option parameter. If left unspecified, it will attempt to send the print job first via `rlpr` - if the `rlpr` command fails in anyway then it will fall back to the `lp` command.
104
+
105
+ ```ruby
106
+ print_job.print label, ip, print_service: 'lp' # attempt only via the lp command
107
+
108
+ print_job.print label, ip, print_service: 'rlpr' # attempt only via the rlpr command
109
+
110
+ print_job.print label, ip # attempt via rlpr first, fallback to lp
111
+ ```
112
+
113
+ #### Printing directly to Windows LPD
114
+ This gem also supports printing directly to shared printer on Windows using LPD.
115
+ In order to print directly to a LPD on a Windows machine you need two things:
116
+ - [rlpr](http://manpages.ubuntu.com/manpages/xenial/man1/rlpr.1.html) installed on the (UNIX) system running your app that uses this gem.<sup>[1](#fn1)</sup>
117
+ - LPD Print Service and LPR Port Monitor features enabled on the Windows machine.<sup>[2](#fn2)</sup>
118
+
119
+ <p align="center">
120
+ <img align="center" src="http://i.imgur.com/3CWkEWU.png" height="300px"/>
121
+ <p/>
122
+
123
+ <hr/>
124
+
125
+ <sup><a name="fn1">1</a>. On a distro such as Ubuntu simply do: `sudo apt-get install rlpr`
126
+ If using OSX then you will have to manually build it from source and add it to your `$PATH` environment variable.<sup/>
127
+
128
+ <sup><a name="fn2">2</a>. The printer name that you pass in must correspond with the **shared printer name** on the Windows machine.</sup>
129
+
130
+ ## Available elements
131
+
132
+ ### Text
133
+
134
+ <p align="center">
135
+ <img src="docs/images/text.png" width="400">
136
+ </p>
99
137
 
100
138
  You create text elements to print using instances of the `Zebra::Zpl::Text` class. It accepts the following options:
101
139
 
102
- * `position`: An array with the coordinates to place the text, in dots.
103
- * `rotation`: The rotation for the text. More about the possible values below.
140
+ * `position`: An array with the coordinates to place the text, in dots.
141
+ * `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
104
142
  * `data`: The text to be printed.
105
- * `v_multiplier`: The vertical multiplier to use.
106
- * `h_multiplier`: The horizontal multipler to use.
107
143
  * `print_mode`: The print mode. Can be normal ("N") or reverse ("R").
108
144
  * `font_size`: The font size to use. You can use values between 1 and 5.
109
145
 
@@ -112,14 +148,38 @@ For the print modes, you can also use the constants:
112
148
  * `Zebra::Zpl::PrintMode::NORMAL`
113
149
  * `Zebra::Zpl::PrintMode::REVERSE`
114
150
 
151
+ ### Raw ZPL
152
+
153
+ The `Zebra::Zpl::Raw` class allows you to supply a raw string of ZPL to include on a label. This can be useful for small images, sections of static ZPL that never change, or if you have previously generated ZPL.
154
+
155
+ * `data`: The ZPL string to be printed.
156
+ * `position`: An array with the coordinates to place the text, in dots.
157
+ * `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
158
+
159
+ ```ruby
160
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
161
+
162
+ zpl_string = "^GFA,1300,1300,13,,::::::O01IFE,N01KFE,N0MFC,M03NF,M0OFC,L03PF,L0QF8,K01QFE,K03RF,K07RF8,J01SFC,J03F9OFE7E,J07F01MFE03F,J07E007LF803F8,J0FE003KFE001FC,I01FEI0FC00FC001FE,I03FCI04M01FF,I07FCQ01FF,I07FCQ01FF8,I0FFCQ01FFC,I0FFEQ01FFC,001FFEQ01FFE,:003FFEQ03IF,003FFEQ01IF,007FFCR0IF,007FFCR0IF8,007FF8R07FF8,00IFS03FF8,00IFS03FFC,:00FFES01FFC,01FFES01FFC,01FFES01FFE,:01FFCS01FFE,:::::01FFES01FFE,::01FFES03FFE,01IFS03FFE,01IFS03FFC,01IF8R07FFC,00IF8R0IFC,00IFCR0IFC,00IFEQ01IFC,00JFQ03IF8,007IF8P07IF8,007IFCP0JF8,007JFO03JF,003F87FCN0KF,003F81FFM03JFE,001F80FFEK01KFE,001FC07FFCJ0LFC,I0FF03FF8J0LFC,I0FF03FF8J07KF8,I07F81FF8J07KF8,I03F807F8J07KF,I03FC004K07JFE,I01FCN07JFE,J0FEN07JFC,J07FN07JF8,J03F8M07JF,J01FCM07IFE,K0FFM07IFC,K07IF8J07IF8,K03IF8J07IF,L0IF8J07FFC,L07FF8J07FF8,L01FF8J07FE,M0FF8J07F8,M01F8J07E,N07K038,,::::::::::::::^FS"
163
+
164
+ raw_zpl = Zebra::Zpl::Raw.new(
165
+ data: zpl_string,
166
+ position: [50, 50],
167
+ )
115
168
 
116
- #### Barcodes
169
+ label << raw_zpl
170
+ ```
171
+
172
+ ### Barcodes
173
+
174
+ <p align="center">
175
+ <img src="docs/images/barcode.png" width="400">
176
+ </p>
117
177
 
118
178
  You create barcode elements to print using instances of the `Zebra::Zpl::Barcode` class. It accepts the following options:
119
179
 
120
- * `position`: An array with the coordinates to place the text, in dots.
180
+ * `position`: An array with the coordinates to place the barcode, in dots.
121
181
  * `height`: The barcode's height, in dots.
122
- * `rotation`: The rotation for the text. More about the possible values below.
182
+ * `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
123
183
  * `data`: The text to be printed.
124
184
  * `type`: The type os barcode to use. More on the available types below.
125
185
  * `narrow_bar_width`: The barcode's narrow bar width, in dots.
@@ -137,21 +197,211 @@ The available barcode types are:
137
197
  * `Zebra::Zpl::BarcodeType::CODE_UPS_MAXICODE`
138
198
  * `Zebra::Zpl::BarcodeType::CODE_QR`
139
199
 
140
- #### QR Codes
200
+ ### QR Codes
201
+
202
+ <p align="center">
203
+ <img src="docs/images/qrcode.png" width="400">
204
+ </p>
141
205
 
142
206
  You can create QR Codes elements to print using instances of the `Zebra::Zpl::Qrcode` class. It accepts the following options:
143
207
 
144
208
  * `position`: An array with the coordinates to place the QR code, in dots.
145
- * `scale factor`: Crucial variable of the QR codes's size. Accepted values: 1-99.
146
- * `error correction level`: Algorithm enables reading damaged QR codes. There are four error correction levels: L - 7% of codewords can be restored, M - 15% can be restored, Q - 25% can be restored, H - 30% can be restored.
147
-
148
- #### Boxes
149
-
150
- You can draw boxes in your labels:
151
-
152
- box = Zebra::Zpl::Box.new :position => [20, 20], :end_position => [100, 100], :line_thickness => 39
153
-
154
- #### Elements Rotation
209
+ * `scale_factor`: Crucial variable of the QR codes's size. Accepted values: 1-99.
210
+ * `correction_level`: Algorithm enables reading damaged QR codes. There are four error correction levels: L - 7% of codewords can be restored, M - 15% can be restored, Q - 25% can be restored, H - 30% can be restored.
211
+
212
+ #### Printing QR codes
213
+
214
+ ```ruby
215
+ label = Zebra::Zpl::Label.new(
216
+ width: 350,
217
+ length: 250,
218
+ print_speed: 3
219
+ )
220
+
221
+ qrcode = Zebra::Zpl::Qrcode.new(
222
+ data: 'www.github.com',
223
+ position: [50,10],
224
+ scale_factor: 3,
225
+ correction_level: 'H'
226
+ )
227
+
228
+ label << qrcode
229
+
230
+ print_job = Zebra::PrintJob.new '<your-qr-printer-name-on-cups>'
231
+
232
+ print_job.print label, '<hostname>'
233
+ ```
234
+
235
+ ### Data Matrix
236
+
237
+ <p align="center">
238
+ <img src="docs/images/datamatrix.png" width="400">
239
+ </p>
240
+
241
+ You can create Data Matrix elements to print using instances of the `Zebra::Zpl::Datamatrix` class. It accepts the following options:
242
+
243
+ * `position`: An array with the coordinates to place the data matrix, in dots.
244
+ * `symbol_height`: Crucial variable of the size size of the data matrix. Accepted values: 1 - label width.
245
+ * `aspect_ratio`: 1 for square, 2 for rectangular.
246
+
247
+ ```ruby
248
+ datamatrix = Zebra::Zpl::Datamatrix.new(
249
+ data: 'www.github.com',
250
+ position: [50,50],
251
+ symbol_height: 5
252
+ )
253
+ ```
254
+
255
+ ### Boxes
256
+
257
+ **&ast;&ast;&ast; The `Zebra::Zpl::Box` class is deprecated and will be removed in future versions. Please switch to the `Zebra::Zpl::Graphic` class (see [Graphics](#graphics) below). &ast;&ast;&ast;**
258
+
259
+ ### Graphics
260
+
261
+ <p align="center">
262
+ <img src="docs/images/graphics.png" width="400">
263
+ </p>
264
+
265
+ You can create graphics elements using the `Zebra::Zpl::Graphic` class:
266
+
267
+ * `position`: An array with the coordinates to place the graphic, in dots.
268
+ * `graphic_type`: Sets the type of graphic:
269
+ * `B`: Box
270
+ * `C`: Circle
271
+ * `D`: Diagonal
272
+ * `E`: Ellipse
273
+ * `S`: Symbol, _see symbol types below._
274
+ * `graphic_width`: Width of the element in dots. (use as the diameter for circles, `C`)
275
+ * `graphic_height`: Height of the element in dots. (does not apply to circles, `C`)
276
+ * `line_thickness`: The thickness of the border in dots.
277
+ * `color`: The color if the lines. B for black, W for white.
278
+ * `orientation`: Only applies to diagonals (graphic type `D`). `R` for right-leaning. `L` for left-leaning.
279
+ * `rounding_degree`: Only applies to boxes (graphic type `B`). Determines what degree to round the corners of the box. Valid values are 0 - 8.
280
+ * `symbol_type`: Only applies to symbols (graphic type `S`). Possible values are:
281
+ * `A`: ® - Registered Trade Mark
282
+ * `B`: © - Copyright
283
+ * `C`: ™ - Trade Mark
284
+ * `D`: (UL) - Underwriters Laboratories approval
285
+ * `E`: (SA) - Canadian Standards Association approval
286
+
287
+ ```ruby
288
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
289
+
290
+ box = Zebra::Zpl::Graphic.new(
291
+ graphic_type: 'B',
292
+ position: [20,25],
293
+ graphic_width: 50,
294
+ graphic_height: 50,
295
+ line_thickness: 2,
296
+ rounding_degree: 2
297
+ )
298
+
299
+ circle = Zebra::Zpl::Graphic.new(
300
+ graphic_type: 'C',
301
+ position: [80,25],
302
+ graphic_width: 50,
303
+ line_thickness: 3
304
+ )
305
+
306
+ diagonal1 = Zebra::Zpl::Graphic.new(
307
+ graphic_type: 'D',
308
+ position: [140,25],
309
+ graphic_width: 50,
310
+ graphic_height: 50,
311
+ line_thickness: 3,
312
+ orientation: 'R'
313
+ )
314
+ diagonal2 = diagonal1.dup
315
+ diagonal2.orientation = 'L'
316
+
317
+ ellipse = Zebra::Zpl::Graphic.new(
318
+ graphic_type: 'E',
319
+ position: [200,25],
320
+ graphic_width: 25,
321
+ graphic_height: 50,
322
+ line_thickness: 3
323
+ )
324
+
325
+ symbol = Zebra::Zpl::Graphic.new(
326
+ graphic_type: 'S',
327
+ symbol_type: 'B',
328
+ position: [235,25],
329
+ graphic_width: 50,
330
+ graphic_height: 50
331
+ )
332
+
333
+ label << box
334
+ label << circle
335
+ label << diagonal1
336
+ label << diagonal2
337
+ label << ellipse
338
+ label << symbol
339
+
340
+ print_job = Zebra::PrintJob.new '<your-qr-printer-name-on-cups>'
341
+ print_job.print label, '<hostname>'
342
+ ```
343
+
344
+ ### Images
345
+
346
+ <p align="center">
347
+ <img src="docs/images/images.png" width="700">
348
+ </p>
349
+
350
+ You can also create graphics elements from an image using the `Zebra::Zpl::Image` class. Images are converted and encoded into an `^GF` (_Graphics Field_) command using the [img2zpl](https://github.com/mtking2/img2zpl) gem. Accepted parameters are:
351
+
352
+ * `path` (required): The file path or URL of an image.
353
+ * `position`: An array with the coordinates to place the image, in dots.
354
+ * `width`: The width (in pixels) that the image should be printed.
355
+ * `height`: The height (in pixels) that the image should be printed.
356
+ * `rotation`: The number of degrees the image should be rotated
357
+ * unlike the other elements with strict 90° rotations, image elements can be rotated any number of degrees since the image is rotated with imagemagick before conversion to ZPL.
358
+ * `black_threshold`: A value between 0 and 1 that sets the darkness threshold which determines how dark a pixel should be in order to become black in the resulting b/w image. Use larger value for a more saturated image and smaller value for a less saturated one. Default: `0.5`
359
+ * `invert`: set to `true` to invert which pixels are set to black and which are set to white. Default is, depending on the `black_threshold`, dark pixels become black and light pixels become white.
360
+
361
+ #### Usage
362
+ ```ruby
363
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
364
+
365
+ image = Zebra::Zpl::Image.new(
366
+ path: '/path/to/my/image.jpg',
367
+ position: [100, 50],
368
+ width: 200,
369
+ height: 180,
370
+ rotation: -90,
371
+ black_threshold: 0.35
372
+ )
373
+
374
+ label << image
375
+ ```
376
+ **Modifying Images**
377
+
378
+ <p align="center">
379
+ <img src="docs/images/image_manipulation.png" width="500">
380
+ </p>
381
+
382
+ Image elements can also be modified in many ways before being added to the label by calling ImageMagick commands (provided by the [minimagick](https://github.com/minimagick/minimagick) & [img2zpl](https://github.com/mtking2/img2zpl) gems) on the source `Img2Zpl::Image < MiniMagick::Image` object.
383
+
384
+ **Example:** Flattening an image's layers, so it is properly converted, and then trimming out unnecessary white space around the edges:
385
+
386
+ ```ruby
387
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
388
+ image = Zebra::Zpl::Image.new path: 'path/to/image.png', position: [0, 0]
389
+
390
+ img_src = image.source #=> instance of Img2Zpl::Image < MiniMagick::Image
391
+
392
+ img_src.flatten
393
+ img_src.trim
394
+
395
+ label << image
396
+ ```
397
+
398
+ ## Options
399
+
400
+ ### Elements Rotation
401
+
402
+ <p align="center">
403
+ <img src="docs/images/rotation.png" width="400">
404
+ </p>
155
405
 
156
406
  All printable elements can be rotated on the label, using the `:Rotation` option. The accepted rotation values are:
157
407
 
@@ -160,7 +410,11 @@ All printable elements can be rotated on the label, using the `:Rotation` option
160
410
  * `Zebra::Zpl::Rotation::DEGREES_180`: will rotate the element 180 degrees.
161
411
  * `Zebra::Zpl::Rotation::DEGREES_270`: will rotate the element 270 degrees.
162
412
 
163
- #### Elements Justification
413
+ ### Elements Justification
414
+
415
+ <p align="center">
416
+ <img src="docs/images/justification.png" width="400">
417
+ </p>
164
418
 
165
419
  There are four ZPL-supported `:Justification` parameters. "LEFT" (left-justified) is the default.
166
420
 
@@ -169,12 +423,17 @@ There are four ZPL-supported `:Justification` parameters. "LEFT" (left-justified
169
423
  * `Zebra::Zpl::Justification::CENTER` ~ centered
170
424
  * `Zebra::Zpl::Justification::JUSTIFIED` ~ full-width-justifed _(YMMV)_
171
425
 
426
+ ## Examples
172
427
 
428
+ See [docs/example.rb](docs/example.rb) for code samples of most elements.
173
429
 
174
430
  ## Contributing
175
431
 
176
- 1. Fork it
177
- 2. Create your feature branch (`git checkout -b my-new-feature`)
178
- 3. Commit your changes (`git commit -am 'Add some feature'`)
179
- 4. Push to the branch (`git push origin my-new-feature`)
180
- 5. Create new Pull Request
432
+ See [CONTRIBUTING.md](CONTRIBUTING.md) on how to contribute to this project.
433
+
434
+ See [CHANGELOG.md](CHANGELOG.md) for a list of changes by version as well as all the awesome people who have contributed to the project.
435
+
436
+ ## References
437
+
438
+ ###### This is a gem based on a terrific older gem by Cassio Marques. Although the new printers are mostly compatible with old Eltron (Epl) code, our needs require many of the new Zebra (ZPL) functions.
439
+ * [Zebra Technologies Corporation, _"ZPL II Programming Guide."_ 2019 PDF](https://www.zebra.com/content/dam/zebra/manuals/printers/common/programming/zpl-zbi2-pm-en.pdf)