summaryrefslogtreecommitdiffstats
path: root/kbarcode
diff options
context:
space:
mode:
Diffstat (limited to 'kbarcode')
-rw-r--r--kbarcode/Makefile.am58
-rw-r--r--kbarcode/barcode.ps3563
-rw-r--r--kbarcode/barcodecombo.cpp341
-rw-r--r--kbarcode/barcodecombo.h144
-rw-r--r--kbarcode/barcodedialog.cpp218
-rw-r--r--kbarcode/barcodedialog.h79
-rw-r--r--kbarcode/barcodedialogs.cpp506
-rw-r--r--kbarcode/barcodedialogs.h180
-rw-r--r--kbarcode/barcodeitem.cpp253
-rw-r--r--kbarcode/barcodeitem.h57
-rw-r--r--kbarcode/barcodeprinterdlg.cpp125
-rw-r--r--kbarcode/barcodeprinterdlg.h55
-rw-r--r--kbarcode/barcodes.html868
-rw-r--r--kbarcode/barkode.cpp968
-rw-r--r--kbarcode/barkode.h297
-rw-r--r--kbarcode/barkodeengine.cpp55
-rw-r--r--kbarcode/barkodeengine.h103
-rw-r--r--kbarcode/batchiface.h46
-rw-r--r--kbarcode/batchprinter.cpp542
-rw-r--r--kbarcode/batchprinter.h212
-rw-r--r--kbarcode/batchwizard.cpp1263
-rw-r--r--kbarcode/batchwizard.h266
-rw-r--r--kbarcode/commands.cpp604
-rw-r--r--kbarcode/commands.h433
-rw-r--r--kbarcode/configdialog.cpp351
-rw-r--r--kbarcode/configdialog.h95
-rw-r--r--kbarcode/confwizard.cpp255
-rw-r--r--kbarcode/confwizard.h101
-rw-r--r--kbarcode/csvfile.cpp168
-rw-r--r--kbarcode/csvfile.h151
-rw-r--r--kbarcode/csvimportdlg.cpp430
-rw-r--r--kbarcode/csvimportdlg.h127
-rw-r--r--kbarcode/databasebrowser.cpp204
-rw-r--r--kbarcode/databasebrowser.h69
-rw-r--r--kbarcode/definition.cpp579
-rw-r--r--kbarcode/definition.h101
-rw-r--r--kbarcode/definitiondialog.cpp428
-rw-r--r--kbarcode/definitiondialog.h99
-rw-r--r--kbarcode/documentitem.cpp245
-rw-r--r--kbarcode/documentitem.h230
-rw-r--r--kbarcode/documentitemdlg.cpp121
-rw-r--r--kbarcode/documentitemdlg.h47
-rw-r--r--kbarcode/dsmainwindow.cpp268
-rw-r--r--kbarcode/dsmainwindow.h90
-rw-r--r--kbarcode/dsrichtext.cpp427
-rw-r--r--kbarcode/dsrichtext.h193
-rw-r--r--kbarcode/dstextedit.cpp147
-rw-r--r--kbarcode/dstextedit.h55
-rw-r--r--kbarcode/editoriface.h55
-rw-r--r--kbarcode/encodingcombo.cpp47
-rw-r--r--kbarcode/encodingcombo.h35
-rw-r--r--kbarcode/exampledata.sql10
-rw-r--r--kbarcode/gnubarcode.cpp348
-rw-r--r--kbarcode/gnubarcode.h75
-rw-r--r--kbarcode/gnubarkodeengine.cpp37
-rw-r--r--kbarcode/gnubarkodeengine.h46
-rw-r--r--kbarcode/hi16-action-barcode.pngbin0 -> 105 bytes
-rw-r--r--kbarcode/hi16-action-kbarcodeellipse.pngbin0 -> 380 bytes
-rw-r--r--kbarcode/hi16-action-kbarcodegrid.pngbin0 -> 108 bytes
-rw-r--r--kbarcode/hi16-action-kbarcodelinetool.pngbin0 -> 344 bytes
-rw-r--r--kbarcode/hi16-app-kbarcode.pngbin0 -> 460 bytes
-rw-r--r--kbarcode/hi22-action-barcode.pngbin0 -> 124 bytes
-rw-r--r--kbarcode/hi32-action-barcode.pngbin0 -> 124 bytes
-rw-r--r--kbarcode/hi32-action-kbarcoderect.pngbin0 -> 157 bytes
-rw-r--r--kbarcode/hi32-app-kbarcode.pngbin0 -> 1065 bytes
-rw-r--r--kbarcode/hi64-app-kbarcode.pngbin0 -> 2706 bytes
-rw-r--r--kbarcode/imageitem.cpp307
-rw-r--r--kbarcode/imageitem.h79
-rw-r--r--kbarcode/kactionmap.cpp188
-rw-r--r--kbarcode/kactionmap.h101
-rw-r--r--kbarcode/kbarcode-batch.desktop12
-rw-r--r--kbarcode/kbarcode-editor.desktop14
-rw-r--r--kbarcode/kbarcode-label.desktop9
-rw-r--r--kbarcode/kbarcode-single.desktop12
-rw-r--r--kbarcode/kbarcode.cpp292
-rw-r--r--kbarcode/kbarcode.desktop13
-rw-r--r--kbarcode/kbarcode.h98
-rw-r--r--kbarcode/kbarcodeiface.h46
-rw-r--r--kbarcode/kbarcodesettings.cpp106
-rw-r--r--kbarcode/kbarcodesettings.h65
-rw-r--r--kbarcode/label.cpp303
-rw-r--r--kbarcode/label.h77
-rw-r--r--kbarcode/labeldefinitions.sql1710
-rw-r--r--kbarcode/labeleditor.cpp1192
-rw-r--r--kbarcode/labeleditor.h251
-rw-r--r--kbarcode/labelutils.cpp188
-rw-r--r--kbarcode/labelutils.h61
-rw-r--r--kbarcode/lineitem.cpp67
-rw-r--r--kbarcode/lineitem.h44
-rw-r--r--kbarcode/logo.pngbin0 -> 2383 bytes
-rw-r--r--kbarcode/main.cpp121
-rw-r--r--kbarcode/measurements.cpp164
-rw-r--r--kbarcode/measurements.h134
-rw-r--r--kbarcode/mimesources.cpp129
-rw-r--r--kbarcode/mimesources.h41
-rw-r--r--kbarcode/multilineeditdlg.cpp312
-rw-r--r--kbarcode/multilineeditdlg.h85
-rw-r--r--kbarcode/mybarcode.cpp620
-rw-r--r--kbarcode/mybarcode.h304
-rw-r--r--kbarcode/mycanvasitem.cpp54
-rw-r--r--kbarcode/mycanvasitem.h52
-rw-r--r--kbarcode/mycanvasview.cpp611
-rw-r--r--kbarcode/mycanvasview.h175
-rw-r--r--kbarcode/mydatatable.cpp44
-rw-r--r--kbarcode/mydatatable.h37
-rw-r--r--kbarcode/newlabel.cpp248
-rw-r--r--kbarcode/newlabel.h79
-rw-r--r--kbarcode/pixmapbarcode.cpp492
-rw-r--r--kbarcode/pixmapbarcode.h136
-rw-r--r--kbarcode/previewdialog.cpp219
-rw-r--r--kbarcode/previewdialog.h76
-rw-r--r--kbarcode/printersettings.cpp199
-rw-r--r--kbarcode/printersettings.h95
-rw-r--r--kbarcode/printlabeldlg.cpp78
-rw-r--r--kbarcode/printlabeldlg.h69
-rw-r--r--kbarcode/propertywidget.cpp631
-rw-r--r--kbarcode/propertywidget.h210
-rw-r--r--kbarcode/purepostscript.cpp240
-rw-r--r--kbarcode/purepostscript.h90
-rw-r--r--kbarcode/rectitem.cpp159
-rw-r--r--kbarcode/rectitem.h71
-rw-r--r--kbarcode/rectsettingsdlg.cpp183
-rw-r--r--kbarcode/rectsettingsdlg.h71
-rw-r--r--kbarcode/referencecounted.cpp23
-rw-r--r--kbarcode/referencecounted.h64
-rw-r--r--kbarcode/rules.xml159
-rw-r--r--kbarcode/semantic.cache39
-rw-r--r--kbarcode/smalldialogs.cpp151
-rw-r--r--kbarcode/smalldialogs.h72
-rw-r--r--kbarcode/sqltables.cpp654
-rw-r--r--kbarcode/sqltables.h222
-rw-r--r--kbarcode/tbarcode2.cpp158
-rw-r--r--kbarcode/tbarcode2.h89
-rw-r--r--kbarcode/tcanvasitem.cpp221
-rw-r--r--kbarcode/tcanvasitem.h57
-rw-r--r--kbarcode/tec.cpp658
-rw-r--r--kbarcode/tec.h69
-rw-r--r--kbarcode/textitem.cpp252
-rw-r--r--kbarcode/textitem.h61
-rw-r--r--kbarcode/textlineedit.cpp210
-rw-r--r--kbarcode/textlineedit.h78
-rw-r--r--kbarcode/textlineitem.cpp246
-rw-r--r--kbarcode/textlineitem.h64
-rw-r--r--kbarcode/tokendialog.cpp477
-rw-r--r--kbarcode/tokendialog.h129
-rw-r--r--kbarcode/tokenprovider.cpp936
-rw-r--r--kbarcode/tokenprovider.h250
-rw-r--r--kbarcode/xmlutils.cpp489
-rw-r--r--kbarcode/xmlutils.h72
-rw-r--r--kbarcode/zplutils.cpp445
-rw-r--r--kbarcode/zplutils.h137
151 files changed, 34816 insertions, 0 deletions
diff --git a/kbarcode/Makefile.am b/kbarcode/Makefile.am
new file mode 100644
index 0000000..665c3f2
--- /dev/null
+++ b/kbarcode/Makefile.am
@@ -0,0 +1,58 @@
+## Makefile.am for kbarcode
+
+# set the include path for X, qt and KDE
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+
+# these are the headers for your project
+
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+KDE_ICON = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kdedcoptest.pot
+
+# this is the program that gets installed. it's name is used for all
+# of the other Makefile.am variables
+bin_PROGRAMS = kbarcode
+
+# the application source, library search path, and link libraries
+
+kbarcode_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+kbarcode_LDADD = $(LIB_KABC) $(LIB_KSPELL) $(LIB_KDEPRINT) \
+ $(LIB_KDEUI) -lkjs -lpcre
+
+noinst_HEADERS = barcodecombo.h barcodedialog.h barcodedialogs.h \
+ commands.h configdialog.h confwizard.h csvimportdlg.h databasebrowser.h \
+ definition.h definitiondialog.h dsmainwindow.h dsrichtext.h kbarcode.h label.h \
+ labeleditor.h labelutils.h mimesources.h multilineeditdlg.h \
+ mycanvasitem.h mycanvasview.h mydatatable.h newlabel.h previewdialog.h \
+ printersettings.h printlabeldlg.h rectsettingsdlg.h smalldialogs.h sqltables.h \
+ tokenprovider.h xmlutils.h zplutils.h measurements.h editoriface.h kbarcodeiface.h \
+ batchiface.h kbarcodesettings.h batchprinter.h barcodeitem.h documentitem.h \
+ lineitem.h rectitem.h tcanvasitem.h textitem.h imageitem.h documentitemdlg.h \
+ propertywidget.h tec.h barcodeprinterdlg.h textlineitem.h textlineedit.h tokendialog.h \
+ barkode.h gnubarcode.h barkodeengine.h pixmapbarcode.h batchwizard.h csvfile.h \
+ referencecounted.h dstextedit.h encodingcombo.h purepostscript.h tbarcode2.h \
+ kactionmap.h
+
+kbarcode_SOURCES = barcodecombo.cpp barcodedialog.cpp \
+ barcodedialogs.cpp commands.cpp configdialog.cpp confwizard.cpp csvimportdlg.cpp \
+ databasebrowser.cpp definition.cpp definitiondialog.cpp dsmainwindow.cpp dsrichtext.cpp \
+ kbarcode.cpp label.cpp labeleditor.cpp labelutils.cpp main.cpp \
+ mimesources.cpp multilineeditdlg.cpp mycanvasitem.cpp mycanvasview.cpp mydatatable.cpp \
+ newlabel.cpp previewdialog.cpp printersettings.cpp printlabeldlg.cpp \
+ rectsettingsdlg.cpp smalldialogs.cpp sqltables.cpp tokenprovider.cpp xmlutils.cpp \
+ zplutils.cpp measurements.cpp editoriface.skel kbarcodeiface.skel batchiface.skel \
+ kbarcodesettings.cpp batchprinter.cpp barcodeitem.cpp documentitem.cpp lineitem.cpp \
+ rectitem.cpp tcanvasitem.cpp textitem.cpp imageitem.cpp documentitemdlg.cpp \
+ propertywidget.cpp tec.cpp barcodeprinterdlg.cpp textlineitem.cpp textlineedit.cpp \
+ tokendialog.cpp barkode.cpp gnubarcode.cpp barkodeengine.cpp pixmapbarcode.cpp batchwizard.cpp \
+ csvfile.cpp referencecounted.cpp dstextedit.cpp encodingcombo.cpp purepostscript.cpp tbarcode2.cpp \
+ kactionmap.cpp
+
+xdg_apps_DATA = kbarcode.desktop kbarcode-batch.desktop kbarcode-editor.desktop kbarcode-label.desktop kbarcode-single.desktop
+
+datafiles_DATA = logo.png barcodes.html exampledata.sql labeldefinitions.sql barcode.ps rules.xml
+datafilesdir = $(kde_datadir)/kbarcode
diff --git a/kbarcode/barcode.ps b/kbarcode/barcode.ps
new file mode 100644
index 0000000..686a31a
--- /dev/null
+++ b/kbarcode/barcode.ps
@@ -0,0 +1,3563 @@
+%!PS-Adobe-2.0
+%%Creator: Terry Burton
+%%DocumentPaperSizes: a4
+%%EndComments
+%%EndProlog
+
+% Barcode Writer in Pure PostScript - Version 2006-09-26
+% http://www.terryburton.co.uk/barcodewriter/
+%
+% Copyright (c) 2006 Terry Burton - tez@terryburton.co.uk
+%
+% Permission is hereby granted, free of charge, to any
+% person obtaining a copy of this software and associated
+% documentation files (the "Software"), to deal in the
+% Software without restriction, including without
+% limitation the rights to use, copy, modify, merge,
+% publish, distribute, sublicense, and/or sell copies of
+% the Software, and to permit persons to whom the Software
+% is furnished to do so, subject to the following
+% conditions:
+%
+% The above copyright notice and this permission notice
+% shall be included in all copies or substantial portions
+% of the Software.
+%
+% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+% KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+% THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+% THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+% CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+% IN THE SOFTWARE.
+
+% Uncomment this next line to allow these procedure definitions to
+% remain resident within a printer's PostScript virtual machine
+% so that the barcode generation capability persists between jobs.
+
+% serverdict begin 0 exitserver
+
+% --BEGIN TEMPLATE--
+
+% --BEGIN ENCODER ean13--
+% --DESC: EAN-13
+% --EXAM: 977147396801
+/ean13 {
+
+ 0 begin
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /textfont /Helvetica def
+ /textsize 12 def
+ /textpos -4 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ /barlen barcode length def % Length of the code
+
+ % Add checksum digit to barcode if length is even
+ barlen 2 mod 0 eq {
+ /pad barlen 1 add string def % Create pad one bigger than barcode
+ /checksum 0 def
+ 0 1 barlen 1 sub {
+ /i exch def
+ /barchar barcode i get 48 sub def
+ i 2 mod 0 eq {
+ /checksum barchar checksum add def
+ } {
+ /checksum barchar 3 mul checksum add def
+ } ifelse
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ pad 0 barcode putinterval % Add barcode to the start of the pad
+ pad barlen checksum 48 add put % Put ascii for checksum at end of pad
+ /barcode pad def % barcode=pad
+ /barlen barlen 1 add def % barlen++
+ } if
+
+ % Create an array containing the character mappings
+ /encs
+ [ (3211) (2221) (2122) (1411) (1132)
+ (1231) (1114) (1312) (1213) (3112)
+ (111) (11111) (111)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ % Digits to mirror on left side
+ /mirrormaps
+ [ (000000) (001011) (001101) (001110) (010011)
+ (011001) (011100) (010101) (010110) (011010)
+ ] def
+
+ /sbs barlen 1 sub 4 mul 11 add string def
+ /txt barlen array def
+
+ % Put the start character
+ sbs 0 encs 10 get putinterval
+
+ % First digit - determine mirrormap by this and show before guard bars
+ /mirrormap mirrormaps barcode 0 get 48 sub get def
+ txt 0 [barcode 0 1 getinterval -10 textpos textfont textsize] put
+
+ % Left side - performs mirroring
+ 1 1 6 {
+ % Lookup the encoding for the each barcode character
+ /i exch def
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ mirrormap i 1 sub get 49 eq { % Reverse enc if 1 in this position in mirrormap
+ /enclen enc length def
+ /revenc enclen string def
+ 0 1 enclen 1 sub {
+ /j exch def
+ /char enc j get def
+ revenc enclen j sub 1 sub char put
+ } for
+ /enc revenc def
+ } if
+ sbs i 1 sub 4 mul 3 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 1 sub 7 mul 4 add textpos textfont textsize] put
+ } for
+
+ % Put the middle character
+ sbs 7 1 sub 4 mul 3 add encs 11 get putinterval
+
+ % Right side
+ 7 1 12 {
+ % Lookup the encoding for the each barcode character
+ /i exch def
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 1 sub 4 mul 8 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 1 sub 7 mul 8 add textpos textfont textsize] put
+ } for
+
+ % Put the end character
+ sbs barlen 1 sub 4 mul 8 add encs 12 get putinterval
+
+ % Return the arguments
+ /retval 4 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ includetext {
+ retval (bhs) [height height 12{height .075 sub}repeat height height 12{height .075 sub}repeat height height] put
+ retval (bbs) [0 0 12{.075}repeat 0 0 12{.075}repeat 0 0] put
+ retval (txt) txt put
+ } {
+ retval (bhs) [30{height}repeat] put
+ retval (bbs) [30{0}repeat] put
+ } ifelse
+ retval (opt) useropts put
+ retval (guardrightpos) 10 put
+ retval (borderbottom) 5 put
+ retval
+
+ end
+
+} bind def
+/ean13 load 0 1 dict put
+% --END ENCODER ean13--
+
+% --BEGIN ENCODER ean8--
+% --DESC: EAN-8
+% --EXAM: 01335583
+/ean8 {
+
+ 0 begin
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /textfont /Helvetica def
+ /textsize 12 def
+ /textpos -4 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (3211) (2221) (2122) (1411) (1132)
+ (1231) (1114) (1312) (1213) (3112)
+ (111) (11111) (111)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ /barlen barcode length def % Length of the code
+ /sbs barlen 4 mul 11 add string def
+ /txt barlen array def
+
+ % Put the start character
+ sbs 0 encs 10 get putinterval
+
+ % Left side
+ 0 1 3 {
+ % Lookup the encoding for the each barcode character
+ /i exch def
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 4 mul 3 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 7 mul 4 add textpos textfont textsize] put
+ } for
+
+ % Put the middle character
+ sbs 4 4 mul 3 add encs 11 get putinterval
+
+ % Right side
+ 4 1 7 {
+ % Lookup the encoding for the each barcode character
+ /i exch def
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 4 mul 8 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 7 mul 8 add textpos textfont textsize] put
+ } for
+
+ % Put the end character
+ sbs barlen 4 mul 8 add encs 12 get putinterval
+
+ % Return the arguments
+ /retval 4 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ includetext {
+ retval (bhs) [height height 8{height .075 sub}repeat height height 8{height .075 sub}repeat height height] put
+ retval (bbs) [0 0 8{.075}repeat 0 0 8{.075}repeat 0 0] put
+ retval (txt) txt put
+ } {
+ retval (bhs) [22{height}repeat] put
+ retval (bbs) [22{0}repeat] put
+ } ifelse
+ retval (opt) useropts put
+ retval (guardleftpos) 10 put
+ retval (guardrightpos) 10 put
+ retval (borderbottom) 5 put
+ retval
+
+ end
+
+} bind def
+/ean8 load 0 1 dict put
+% --END ENCODER ean8--
+
+% --BEGIN ENCODER upca--
+% --DESC: UPC-A
+% --EXAM: 78858101497
+/upca {
+
+ 0 begin
+
+ /options exch def
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /textfont /Helvetica def
+ /textsize 12 def
+ /textpos -4 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ /barlen barcode length def % Length of the code
+
+ % Add checksum digit to barcode if length is odd
+ barlen 2 mod 0 ne {
+ /pad barlen 1 add string def % Create pad one bigger than barcode
+ /checksum 0 def
+ 0 1 barlen 1 sub {
+ /i exch def
+ /barchar barcode i get 48 sub def
+ i 2 mod 0 ne {
+ /checksum checksum barchar add def
+ } {
+ /checksum checksum barchar 3 mul add def
+ } ifelse
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ pad 0 barcode putinterval % Add barcode to the start of the pad
+ pad barlen checksum 48 add put % Put ascii for checksum at end of pad
+ /barcode pad def % barcode=pad
+ /barlen barlen 1 add def % barlen++
+ } if
+
+ % Create an array containing the character mappings
+ /encs
+ [ (3211) (2221) (2122) (1411) (1132)
+ (1231) (1114) (1312) (1213) (3112)
+ (111) (11111) (111)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ /sbs barlen 4 mul 11 add string def
+ /txt barlen array def
+
+ % Put the start character
+ sbs 0 encs 10 get putinterval
+
+ % Left side
+ 0 1 5 {
+ % Lookup the encoding for the each barcode character
+ /i exch def
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 4 mul 3 add enc putinterval % Put encoded digit into sbs
+ i 0 eq { % First digit is before the guard bars
+ txt 0 [barcode 0 1 getinterval -7 textpos textfont textsize 2 sub] put
+ } {
+ txt i [barcode i 1 getinterval i 7 mul 4 add textpos textfont textsize] put
+ } ifelse
+ } for
+
+ % Put the middle character
+ sbs 6 4 mul 3 add encs 11 get putinterval
+
+ % Right side
+ 6 1 11 {
+ % Lookup the encoding for the each barcode character
+ /i exch def
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 4 mul 8 add enc putinterval % Put encoded digit into sbs
+ i 11 eq { % Last digit is after guard bars
+ txt 11 [barcode 11 1 getinterval 96 textpos textfont textsize 2 sub] put
+ } {
+ txt i [barcode i 1 getinterval i 7 mul 8 add textpos textfont textsize] put
+ } ifelse
+ } for
+
+ % Put the end character
+ sbs barlen 4 mul 8 add encs 12 get putinterval
+
+ % Return the arguments
+ /retval 4 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ includetext {
+ retval (bhs) [4{height}repeat 10{height .075 sub}repeat height height 10{height .075 sub}repeat 5{height}repeat] put
+ retval (bbs) [0 0 0 0 10{.075}repeat 0 0 10{.075}repeat 0 0 0 0 0] put
+ retval (txt) txt put
+ } {
+ retval (bhs) [31{height}repeat] put
+ retval (bbs) [31{0}repeat] put
+ } ifelse
+ retval (opt) useropts put
+ retval (borderbottom) 5 put
+ retval
+
+ end
+
+} bind def
+/upca load 0 1 dict put
+% --END ENCODER upca--
+
+% --BEGIN ENCODER upce--
+% --DESC: UPC-E
+% --EXAM: 0123456
+/upce {
+
+ 0 begin
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /textfont /Helvetica def
+ /textsize 12 def
+ /textpos -4 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ /barlen barcode length def % Length of the code
+
+ % Create an array containing the character mappings
+ /encs
+ [ (3211) (2221) (2122) (1411) (1132)
+ (1231) (1114) (1312) (1213) (3112)
+ (111) (1111111)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ /mirrormaps
+ [ (000111) (001011) (001101) (001110) (010011)
+ (011001) (011100) (010101) (010110) (011010)
+ ] def
+
+ % Add checksum digit to barcode if length is odd
+ barlen 2 mod 0 ne {
+ /pad barlen 1 add string def % Create pad one bigger than barcode
+ /checksum 0 def
+ 0 1 barlen 1 sub {
+ /i exch def
+ /barchar barcode i get 48 sub def
+ i 2 mod 0 ne {
+ /checksum barchar checksum add def
+ } {
+ /checksum barchar 3 mul checksum add def
+ } ifelse
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ pad 0 barcode putinterval % Add barcode to the start of the pad
+ pad barlen checksum 48 add put % Put ascii for checksum at end of pad
+ /barcode pad def % barcode=pad
+ /barlen barlen 1 add def % barlen++
+ } if
+ /txt barlen array def
+ txt 0 [barcode 0 1 getinterval -7 textpos textfont textsize 2 sub] put
+
+ % Determine the mirror map based on checksum
+ /mirrormap mirrormaps barcode barlen 1 sub get 48 sub get def
+
+ % Invert the mirrormap if we are using a non-zero number system
+ barcode 0 get 48 eq {
+ /invt mirrormap length string def
+ 0 1 mirrormap length 1 sub {
+ /i exch def
+ mirrormap i get 48 eq {
+ invt i 49 put
+ } {
+ invt i 48 put
+ } ifelse
+ } for
+ /mirrormap invt def
+ } if
+
+ /sbs barlen 2 sub 4 mul 10 add string def
+
+ % Put the start character
+ sbs 0 encs 10 get putinterval
+
+ 1 1 6 {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ mirrormap i 1 sub get 49 eq { % Reverse enc if 1 in this position in mirrormap
+ /enclen enc length def
+ /revenc enclen string def
+ 0 1 enclen 1 sub {
+ /j exch def
+ /char enc j get def
+ revenc enclen j sub 1 sub char put
+ } for
+ /enc revenc def
+ } if
+ sbs i 1 sub 4 mul 3 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 1 sub 7 mul 4 add textpos textfont textsize] put
+ } for
+
+ txt 7 [barcode 7 1 getinterval 6 7 mul 11 add textpos textfont textsize 2 sub] put
+
+ % Put the end character
+ sbs barlen 2 sub 4 mul 3 add encs 11 get putinterval
+
+ % Return the arguments
+ /retval 4 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ includetext {
+ retval (bhs) [height height 12{height .075 sub}repeat height height height] put
+ retval (bbs) [0 0 12{.075}repeat 0 0 0] put
+ retval (txt) txt put
+ } {
+ retval (bhs) [17{height}repeat] put
+ retval (bbs) [17{0}repeat] put
+ } ifelse
+ retval (opt) useropts put
+ retval (borderbottom) 5 put
+ retval
+
+ end
+
+} bind def
+/upce load 0 1 dict put
+% --END ENCODER upce--
+
+% --BEGIN ENCODER ean5--
+% --DESC: EAN-5 (5 digit addon)
+% --EXAM: 0123456
+/ean5 {
+
+ 0 begin
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /textfont /Helvetica def
+ /textsize 12 def
+ /textpos (unset) def
+ /height 0.7 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /height height cvr def
+ textpos (unset) eq {
+ /textpos height 72 mul 1 add def
+ } {
+ /textpos textpos cvr def
+ } ifelse
+
+ /barlen barcode length def % Length of the code
+
+ % Create an array containing the character mappings
+ /encs
+ [ (3211) (2221) (2122) (1411) (1132)
+ (1231) (1114) (1312) (1213) (3112)
+ (112) (11)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ % Determine the mirror map based on mod 10 checksum
+ /mirrormaps
+ [ (11000) (10100) (10010) (10001) (01100)
+ (00110) (00011) (01010) (01001) (00101)
+ ] def
+ /checksum 0 def
+ 0 1 4 {
+ /i exch def
+ /barchar barcode i get 48 sub def
+ i 2 mod 0 eq {
+ /checksum barchar 3 mul checksum add def
+ } {
+ /checksum barchar 9 mul checksum add def
+ } ifelse
+ } for
+ /checksum checksum 10 mod def
+ /mirrormap mirrormaps checksum get def
+
+ /sbs 31 string def
+ /txt 5 array def
+
+ 0 1 4 {
+ /i exch def
+
+ % Prefix with either a start character or separator character
+ i 0 eq {
+ sbs 0 encs 10 get putinterval
+ } {
+ sbs i 1 sub 6 mul 7 add encs 11 get putinterval
+ } ifelse
+
+ % Lookup the encoding for the barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
+ /enclen enc length def
+ /revenc enclen string def
+ 0 1 enclen 1 sub {
+ /j exch def
+ /char enc j get def
+ revenc enclen j sub 1 sub char put
+ } for
+ /enc revenc def
+ } if
+ sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textpos textfont textsize] put
+ } for
+
+ % Return the arguments
+ /retval 4 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [16{height}repeat] put
+ retval (bbs) [16{0}repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval (guardrightpos) 10 put
+ retval (guardrightypos) textpos 4 add put
+ retval (bordertop) 10 put
+ retval
+
+ end
+
+} bind def
+/ean5 load 0 1 dict put
+% --END ENCODER ean5--
+
+% --BEGIN ENCODER ean2--
+% --DESC: EAN-2 (2 digit addon)
+% --EXAM: 05
+/ean2 {
+
+ 0 begin
+
+ /options exch def % We are given an options string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /textfont /Helvetica def
+ /textsize 12 def
+ /textpos (unset) def
+ /height 0.7 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /height height cvr def
+ textpos (unset) eq {
+ /textpos height 72 mul 1 add def
+ } {
+ /textpos textpos cvr def
+ } ifelse
+
+ /barlen barcode length def % Length of the code
+
+ % Create an array containing the character mappings
+ /encs
+ [ (3211) (2221) (2122) (1411) (1132)
+ (1231) (1114) (1312) (1213) (3112)
+ (112) (11)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ % Determine the mirror map based on mod 4 checksum
+ /mirrormap [(00) (01) (10) (11)] barcode 0 2 getinterval cvi 4 mod get def
+
+ /sbs 13 string def
+ /txt 2 array def
+
+ 0 1 1 {
+ /i exch def
+
+ % Prefix with either a start character or separator character
+ i 0 eq {
+ sbs 0 encs 10 get putinterval
+ } {
+ sbs i 1 sub 6 mul 7 add encs 11 get putinterval
+ } ifelse
+
+ % Lookup the encoding for the barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
+ /enclen enc length def
+ /revenc enclen string def
+ 0 1 enclen 1 sub {
+ /j exch def
+ /char enc j get def
+ revenc enclen j sub 1 sub char put
+ } for
+ /enc revenc def
+ } if
+ sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textpos textfont textsize] put
+ } for
+
+ % Return the arguments
+ /retval 4 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [12{height}repeat] put
+ retval (bbs) [12{0}repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval (guardrightpos) 10 put
+ retval (guardrightypos) textpos 4 add put
+ retval (bordertop) 10 put
+ retval
+
+ end
+
+} bind def
+/ean2 load 0 1 dict put
+% --END ENCODER ean2--
+
+% --BEGIN ENCODER isbn--
+% --REQUIRES ean13--
+% --DESC: ISBN
+% --EXAM: 1-86074-271
+/isbn {
+
+ 0 begin
+
+ /options exch def % We are given an options string
+ /useropts options def
+ /isbntxt exch def % We are given the isbn text with dashes
+
+ /includetext false def % Enable/disable ISBN text
+ /isbnfont /Courier def
+ /isbnsize 9 def
+ /isbnpos (unset) def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /isbnfont isbnfont cvlit def
+ /isbnsize isbnsize cvr def
+ /height height cvr def
+ isbnpos (unset) eq {
+ /isbnpos height 72 mul 3 add def
+ } {
+ /isbnpos isbnpos cvr def
+ } ifelse
+
+ % Read the digits from isbntxt and calculate checksums
+ /isbn 13 string def
+ /checksum10 0 def
+ /checksum13 0 def
+ /i 0 def /n 0 def
+ { % loop
+ /isbnchar isbntxt i get 48 sub def
+ isbnchar -3 ne { % Ignore dashes
+ isbn n isbnchar 48 add put
+ /checksum10 checksum10 10 n sub isbnchar mul add def
+ n 2 mod 0 eq {
+ /checksum13 isbnchar checksum13 add def
+ } {
+ /checksum13 isbnchar 3 mul checksum13 add def
+ } ifelse
+ /n n 1 add def
+ } if
+ /i i 1 add def
+ i isbntxt length eq {exit} if
+ } loop
+
+ % Add the ISBN header to the isbntxt
+ n 9 eq n 10 eq or {
+ /checksum 11 checksum10 11 mod sub 11 mod def
+ /isbn isbn 0 9 getinterval def
+ /pad 18 string def
+ } {
+ /checksum 10 checksum13 10 mod sub 10 mod def
+ /isbn isbn 0 12 getinterval def
+ /pad 22 string def
+ } ifelse
+ pad 0 (ISBN ) putinterval
+ pad 5 isbntxt putinterval % Add isbntxt to the pad
+
+ % Add checksum digit if isbntxt length is 11 or 15
+ isbntxt length 11 eq isbntxt length 15 eq or {
+ pad isbntxt length 5 add 45 put % Put a dash
+ checksum 10 eq {
+ pad isbntxt length 6 add checksum 78 add put % Check digit for 10 is X
+ } {
+ pad isbntxt length 6 add checksum 48 add put % Put check digit
+ } ifelse
+ } if
+ /isbntxt pad def % isbntxt=pad
+
+ % Convert ISBN digits to EAN-13
+ /barcode 12 string def
+ isbn length 9 eq {
+ barcode 0 (978) putinterval
+ barcode 3 isbn putinterval
+ } {
+ barcode 0 isbn putinterval
+ } ifelse
+
+ % Get the result of encoding with ean13
+ /args barcode options ean13 def
+
+ % Add the ISBN text
+ includetext {
+ isbn length 9 eq {
+ /isbnxpos -1 def
+ } {
+ /isbnxpos -12 def
+ } ifelse
+ args (txt) known {
+ /txt args (txt) get def
+ /newtxt txt length 1 add array def
+ newtxt 0 txt putinterval
+ newtxt newtxt length 1 sub [isbntxt isbnxpos isbnpos isbnfont isbnsize] put
+ args (txt) newtxt put
+ } {
+ args (txt) [ [isbntxt isbnxpos isbnpos isbnfont isbnsize] ] put
+ } ifelse
+ } if
+
+ args (opt) useropts put
+ args
+
+ end
+
+} bind def
+/isbn load 0 1 dict put
+% --END ENCODER isbn--
+
+% --BEGIN ENCODER code128--
+% --DESC: Code 128
+% --EXAM: ^104^102Count^0990123456789^101!
+/code128 {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (212222) (222122) (222221) (121223) (121322) (131222) (122213)
+ (122312) (132212) (221213) (221312) (231212) (112232) (122132)
+ (122231) (113222) (123122) (123221) (223211) (221132) (221231)
+ (213212) (223112) (312131) (311222) (321122) (321221) (312212)
+ (322112) (322211) (212123) (212321) (232121) (111323) (131123)
+ (131321) (112313) (132113) (132311) (211313) (231113) (231311)
+ (112133) (112331) (132131) (113123) (113321) (133121) (313121)
+ (211331) (231131) (213113) (213311) (213131) (311123) (311321)
+ (331121) (312113) (312311) (332111) (314111) (221411) (431111)
+ (111224) (111422) (121124) (121421) (141122) (141221) (112214)
+ (112412) (122114) (122411) (142112) (142211) (241211) (221114)
+ (413111) (241112) (134111) (111242) (121142) (121241) (114212)
+ (124112) (124211) (411212) (421112) (421211) (212141) (214121)
+ (412121) (111143) (111341) (131141) (114113) (114311) (411113)
+ (411311) (113141) (114131) (311141) (411131) (211412) (211214)
+ (211232) (2331112)
+ ] def
+
+ % Create a string of the available characters for alphabets A and B
+ /barchars ( !"#$%&'\(\)*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~) def
+ /barlen barcode length def % Length of the code
+ /sbs barlen 6 mul string def % sbs is 6 times length of barcode
+ /txt barlen array def
+
+ /mode -1 def % A=0, B=1, C=2
+ /checksum barcode 1 3 getinterval cvi def % Initialise the checksum
+
+ /i 0 def /j 0 def
+ { % loop
+ i barlen eq {exit} if
+ barcode i 1 getinterval (^) eq {
+ % indx is given by the next three characters
+ /indx barcode i 1 add 3 getinterval cvi def
+ txt j [( ) j 11 mul textpos textfont textsize] put
+ /i i 4 add def
+ } {
+ % indx depends on the mode
+ mode 2 eq {
+ /indx barcode i 2 getinterval cvi def
+ txt j [barcode i 2 getinterval j 11 mul textpos textfont textsize] put
+ /i i 2 add def
+ } {
+ barchars barcode i 1 getinterval search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ txt j [barchars indx 1 getinterval j 11 mul textpos textfont textsize] put
+ /i i 1 add def
+ } ifelse
+ } ifelse
+ /enc encs indx get def % Get the indxth encoding
+ sbs j 6 mul enc putinterval % Put encoded digit into sbs
+
+ % Update the mode
+ indx 101 eq indx 103 eq or {/mode 0 def} if
+ indx 100 eq indx 104 eq or {/mode 1 def} if
+ indx 99 eq indx 105 eq or {/mode 2 def} if
+
+ /checksum indx j mul checksum add def % checksum+=indx*j
+ /j j 1 add def
+ } loop
+
+ % Put the checksum character
+ /checksum checksum 103 mod def
+ sbs j 6 mul encs checksum get putinterval
+
+ % Put the end character
+ sbs j 6 mul 6 add encs 106 get putinterval
+
+ % Shrink sbs and txt to fit exactly
+ /sbs sbs 0 j 6 mul 13 add getinterval def
+ /txt txt 0 j getinterval def
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/code128 load 0 1 dict put
+% --END ENCODER code128--
+
+% --BEGIN ENCODER code39--
+% --DESC: Code 39
+% --EXAM: THIS IS CODE 39
+/code39 {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includecheck false def % Enable/disable checkdigit
+ /includetext false def
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (1113313111) (3113111131) (1133111131) (3133111111) (1113311131)
+ (3113311111) (1133311111) (1113113131) (3113113111) (1133113111)
+ (3111131131) (1131131131) (3131131111) (1111331131) (3111331111)
+ (1131331111) (1111133131) (3111133111) (1131133111) (1111333111)
+ (3111111331) (1131111331) (3131111311) (1111311331) (3111311311)
+ (1131311311) (1111113331) (3111113311) (1131113311) (1111313311)
+ (3311111131) (1331111131) (3331111111) (1311311131) (3311311111)
+ (1331311111) (1311113131) (3311113111) (1331113111) (1313131111)
+ (1313111311) (1311131311) (1113131311) (1311313111)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*) def
+
+ /barlen barcode length def % Length of the code
+
+ includecheck {
+ /sbs barlen 10 mul 30 add string def
+ /txt barlen 3 add array def
+ } {
+ /sbs barlen 10 mul 20 add string def
+ /txt barlen 2 add array def
+ } ifelse
+
+ /checksum 0 def
+
+ % Put the start character
+ sbs 0 encs 43 get putinterval
+ txt 0 [(*) 0 textpos textfont textsize] put
+
+ 0 1 barlen 1 sub {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 10 mul 10 add enc putinterval % Put encoded digit into sbs
+ txt i 1 add [barcode i 1 getinterval i 1 add 16 mul textpos textfont textsize] put
+ /checksum checksum indx add def
+ } for
+
+ % Put the checksum and end characters
+ includecheck {
+ /checksum checksum 43 mod def
+ sbs barlen 10 mul 10 add encs checksum get putinterval
+ includecheckintext {
+ txt barlen 1 add [barchars checksum 1 getinterval barlen 1 add 16 mul textpos textfont textsize] put
+ } {
+ txt barlen 1 add [() barlen 1 add 16 mul textpos textfont textsize] put
+ } ifelse
+ sbs barlen 10 mul 20 add encs 43 get putinterval
+ txt barlen 2 add [(*) barlen 2 add 16 mul textpos textfont textsize] put
+ } {
+ sbs barlen 10 mul 10 add encs 43 get putinterval
+ txt barlen 1 add [(*) barlen 1 add 16 mul textpos textfont textsize] put
+ } ifelse
+
+ % Return the arguments
+ /retval 2 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/code39 load 0 1 dict put
+% --END ENCODER code39--
+
+% --BEGIN ENCODER code93--
+% --DESC: Code 93
+% --EXAM: THIS IS CODE 93
+/code93 {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includecheck false def % Enable/disable checkdigit
+ /includetext false def % Enable/disable text
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ /encs
+ [ (131112) (111213) (111312) (111411) (121113)
+ (121212) (121311) (111114) (131211) (141111)
+ (211113) (211212) (211311) (221112) (221211)
+ (231111) (112113) (112212) (112311) (122112)
+ (132111) (111123) (111222) (111321) (121122)
+ (131121) (212112) (212211) (211122) (211221)
+ (221121) (222111) (112122) (112221) (122121)
+ (123111) (121131) (311112) (311211) (321111)
+ (112131) (113121) (211131) (121221) (312111)
+ (311121) (122211) (111141) (1111411)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
+
+ /barlen barcode length def % Length of the code
+ barcode {
+ (^) search false eq {pop exit} if
+ pop pop /barlen barlen 3 sub def
+ } loop
+
+ includecheck {
+ /sbs barlen 6 mul 25 add string def
+ } {
+ /sbs barlen 6 mul 13 add string def
+ } ifelse
+ /txt barlen array def
+
+ % Put the start character
+ sbs 0 encs 47 get putinterval
+
+ /checksum1 0 def /checksum2 0 def
+
+ /i 0 def /j 0 def
+ { % loop
+ j barlen eq {exit} if
+ barcode i 1 getinterval (^) eq {
+ % indx is given by the next three characters
+ /indx barcode i 1 add 3 getinterval cvi def
+ txt j [( ) j 9 mul 9 add textpos textfont textsize] put
+ /i i 4 add def
+ } {
+ barchars barcode i 1 getinterval search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ txt j [barchars indx 1 getinterval j 9 mul 9 add textpos textfont textsize] put
+ /i i 1 add def
+ } ifelse
+ /enc encs indx get def % Get the indxth encoding
+ sbs j 6 mul 6 add enc putinterval % Put encoded digit into sbs
+ /checksum1 checksum1 barlen j sub 1 sub 20 mod 1 add indx mul add def
+ /checksum2 checksum2 barlen j sub 15 mod 1 add indx mul add def
+ /j j 1 add def
+ } loop
+
+ includecheck {
+ % Put the first checksum character
+ /checksum1 checksum1 47 mod def
+ /checksum2 checksum2 checksum1 add 47 mod def
+ sbs j 6 mul 6 add encs checksum1 get putinterval
+ sbs j 6 mul 12 add encs checksum2 get putinterval
+ % Put the end character
+ sbs j 6 mul 18 add encs 48 get putinterval
+ } {
+ % Put the end character
+ sbs j 6 mul 6 add encs 48 get putinterval
+ } ifelse
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/code93 load 0 1 dict put
+% --END ENCODER code93--
+
+% --BEGIN ENCODER interleaved2of5--
+% --DESC: Interleaved 2 of 5 (ITF)
+% --EXAM: 24012345678905
+/interleaved2of5 {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includecheck false def % Enable/disable checkdigit
+ /includetext false def % Enable/disable text
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ /barlen barcode length def % Length of the code
+
+ % Prefix 0 to barcode if length is even and including checkdigit
+ % or length is odd and not including checkdigit
+ barlen 2 mod 0 eq includecheck and % even & includecheck
+ barlen 2 mod 0 ne includecheck not and or { % odd & !includecheck
+ /pad barlen 1 add string def % Create pad one bigger than barcode
+ pad 0 48 put % Put ascii 0 at start of pad
+ pad 1 barcode putinterval % Add barcode to the end of pad
+ /barcode pad def % barcode=pad
+ /barlen barlen 1 add def % barlen++
+ } if
+
+ % Add checksum to end of barcode
+ includecheck {
+ /checksum 0 def
+ 0 1 barlen 1 sub {
+ /i exch def
+ i 2 mod 0 eq {
+ /checksum checksum barcode i get 48 sub 3 mul add def
+ } {
+ /checksum checksum barcode i get 48 sub add def
+ } ifelse
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ /pad barlen 1 add string def % Create pad one bigger than barcode
+ pad 0 barcode putinterval % Add barcode to the start of pad
+ pad barlen checksum 48 add put % Add checksum to end of pad
+ /barcode pad def % barcode=pad
+ /barlen barlen 1 add def % barlen++
+ } if
+
+ % Create an array containing the character mappings
+ /encs
+ [ (11331) (31113) (13113) (33111) (11313)
+ (31311) (13311) (11133) (31131) (13131)
+ (1111) (3111)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+ /sbs barlen 5 mul 8 add string def
+ /txt barlen array def
+
+ % Put the start character
+ sbs 0 encs 10 get putinterval
+
+ 0 2 barlen 1 sub {
+ /i exch def
+ % Lookup the encodings for two consecutive barcode characters
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enca encs indx get def % Get the indxth encoding
+
+ barcode i 1 add 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /encb encs indx get def % Get the indxth encoding
+
+ % Interleave the two character encodings
+ /intl enca length 2 mul string def
+ 0 1 enca length 1 sub {
+ /j exch def
+ /achar enca j get def
+ /bchar encb j get def
+ intl j 2 mul achar put
+ intl j 2 mul 1 add bchar put
+ } for
+
+ sbs i 5 mul 4 add intl putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 9 mul 4 add textpos textfont textsize] put
+ includecheck includecheckintext not and barlen 2 sub i eq and {
+ txt i 1 add [( ) i 1 add 9 mul 4 add textpos textfont textsize] put
+ } {
+ txt i 1 add [barcode i 1 add 1 getinterval i 1 add 9 mul 4 add textpos textfont textsize] put
+ } ifelse
+ } for
+
+ % Put the end character
+ sbs barlen 5 mul 4 add encs 11 get putinterval
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/interleaved2of5 load 0 1 dict put
+% --END ENCODER interleaved2of5--
+
+% --BEGIN ENCODER rss14--
+% --DESC: Reduced Space Symbology 14 (RSS-14)
+% --EXAM: 24012345678905
+/rss14 {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /height 1 def
+ /linkage false def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /height height cvr def
+
+ /getRSSwidths {
+ /mw exch def
+ /nm exch def
+ /val exch def
+ /j 0 def /i 0 def {
+ /v () def
+ mw 1 ne {/v i mw 4 string cvrs def} if
+ 0 v {48 sub add} forall 4 add nm eq {
+ j val eq {exit} if
+ /j j 1 add def
+ } if
+ /i i 1 add def
+ } loop
+ [4 {1} repeat v {47 sub} forall] v length 4 getinterval
+ } bind def
+
+ /binval [barcode {48 sub} forall] def
+ /binval [linkage {1} {0} ifelse binval 0 13 getinterval {} forall] def
+
+ 0 1 12 {
+ /i exch def
+ binval i 1 add 2 copy get binval i get 4537077 mod 10 mul add put
+ binval i binval i get 4537077 idiv put
+ } for
+ /right binval 13 get 4537077 mod def
+ binval 13 2 copy get 4537077 idiv put
+
+ /left 0 def
+ /i true def
+ 0 1 13 {
+ /j exch def
+ binval j get
+ dup 0 eq i and {
+ pop
+ } {
+ /i false def
+ /left left 3 -1 roll 10 13 j sub exp cvi mul add def
+ } ifelse
+ } for
+
+ /d1 left 1597 idiv def
+ /d2 left 1597 mod def
+ /d3 right 1597 idiv def
+ /d4 right 1597 mod def
+
+ /tab164 [
+ 160 0 12 4 8 1 161 1
+ 960 161 10 6 6 3 80 10
+ 2014 961 8 8 4 5 31 34
+ 2714 2015 6 10 3 6 10 70
+ 2840 2715 4 12 1 8 1 126
+ ] def
+
+ /tab154 [
+ 335 0 5 10 2 7 4 84
+ 1035 336 7 8 4 5 20 35
+ 1515 1036 9 6 6 3 48 10
+ 1596 1516 11 4 8 1 81 1
+ ] def
+
+ /i 0 def {
+ d1 tab164 i get le {
+ tab164 i 1 add 7 getinterval {} forall
+ /d1te exch def /d1to exch def
+ /d1mwe exch def /d1mwo exch def
+ /d1ele exch def /d1elo exch def
+ /d1gs exch def
+ exit
+ } if
+ /i i 8 add def
+ } loop
+
+ /i 0 def {
+ d2 tab154 i get le {
+ tab154 i 1 add 7 getinterval {} forall
+ /d2te exch def /d2to exch def
+ /d2mwe exch def /d2mwo exch def
+ /d2ele exch def /d2elo exch def
+ /d2gs exch def
+ exit
+ } if
+ /i i 8 add def
+ } loop
+
+ /i 0 def {
+ d3 tab164 i get le {
+ tab164 i 1 add 7 getinterval {} forall
+ /d3te exch def /d3to exch def
+ /d3mwe exch def /d3mwo exch def
+ /d3ele exch def /d3elo exch def
+ /d3gs exch def
+ exit
+ } if
+ /i i 8 add def
+ } loop
+
+ /i 0 def {
+ d4 tab154 i get le {
+ tab154 i 1 add 7 getinterval {} forall
+ /d4te exch def /d4to exch def
+ /d4mwe exch def /d4mwo exch def
+ /d4ele exch def /d4elo exch def
+ /d4gs exch def
+ exit
+ } if
+ /i i 8 add def
+ } loop
+
+ /d1wo d1 d1gs sub d1te idiv d1elo d1mwo getRSSwidths def
+ /d1we d1 d1gs sub d1te mod d1ele d1mwe getRSSwidths def
+ /d2wo d2 d2gs sub d2to mod d2elo d2mwo getRSSwidths def
+ /d2we d2 d2gs sub d2to idiv d2ele d2mwe getRSSwidths def
+ /d3wo d3 d3gs sub d3te idiv d3elo d3mwo getRSSwidths def
+ /d3we d3 d3gs sub d3te mod d3ele d3mwe getRSSwidths def
+ /d4wo d4 d4gs sub d4to mod d4elo d4mwo getRSSwidths def
+ /d4we d4 d4gs sub d4to idiv d4ele d4mwe getRSSwidths def
+
+ /d1w 8 array def
+ 0 1 3 {
+ /i exch def
+ d1w i 2 mul d1wo i get put
+ d1w i 2 mul 1 add d1we i get put
+ } for
+
+ /d2w 8 array def
+ 0 1 3 {
+ /i exch def
+ d2w 7 i 2 mul sub d2wo i get put
+ d2w 6 i 2 mul sub d2we i get put
+ } for
+
+ /d3w 8 array def
+ 0 1 3 {
+ /i exch def
+ d3w 7 i 2 mul sub d3wo i get put
+ d3w 6 i 2 mul sub d3we i get put
+ } for
+
+ /d4w 8 array def
+ 0 1 3 {
+ /i exch def
+ d4w i 2 mul d4wo i get put
+ d4w i 2 mul 1 add d4we i get put
+ } for
+
+ /widths [
+ d1w {} forall
+ d2w {} forall
+ d3w {} forall
+ d4w {} forall
+ ] def
+
+ /checkweights [
+ 1 3 9 27 2 6 18 54
+ 58 72 24 8 29 36 12 4
+ 74 51 17 32 37 65 48 16
+ 64 34 23 69 49 68 46 59
+ ] def
+
+ /checkwidths [
+ 3 8 2 1 1 3 5 5 1 1 3 3 7 1 1
+ 3 1 9 1 1 2 7 4 1 1 2 5 6 1 1
+ 2 3 8 1 1 1 5 7 1 1 1 3 9 1 1
+ ] def
+
+ /checksum 0 def
+ 0 1 31 {
+ /i exch def
+ /checksum checksum widths i get checkweights i get mul add def
+ } for
+ /checksum checksum 79 mod def
+ checksum 8 ge {/checksum checksum 1 add def} if
+ checksum 72 ge {/checksum checksum 1 add def} if
+ /checklt checkwidths checksum 9 idiv 5 mul 5 getinterval def
+ /checkrtrev checkwidths checksum 9 mod 5 mul 5 getinterval def
+ /checkrt 5 array def
+ 0 1 4 {
+ /i exch def
+ checkrt i checkrtrev 4 i sub get put
+ } for
+
+ /sbs [
+ 1 d1w {} forall checklt {} forall d2w {}
+ forall d4w {} forall checkrt {} forall d3w {} forall 1 1
+ ] def
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) sbs put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/rss14 load 0 1 dict put
+% --END ENCODER rss14--
+
+% --BEGIN ENCODER rsslimited--
+% --DESC: Reduced Space Symbology Limited (RSS-Limited)
+% --EXAM: 00978186074271
+/rsslimited {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /height height cvr def
+
+ /getRSSwidths {
+ /el exch def
+ /mw exch def
+ /nm exch def
+ /val exch def
+ /j 0 def /i 0 def {
+ /v () def
+ mw 1 ne {/v i mw el string cvrs def} if
+ 0 v {48 sub add} forall el add nm eq {
+ j val eq {exit} if
+ /j j 1 add def
+ } if
+ /i i 1 add def
+ } loop
+ [el {1} repeat v {47 sub} forall] v length el getinterval
+ } bind def
+
+ /binval [barcode {48 sub} forall] def
+ /binval [binval 0 13 getinterval {} forall] def
+
+ 0 1 11 {
+ /i exch def
+ binval i 1 add 2 copy get binval i get 2013571 mod 10 mul add put
+ binval i binval i get 2013571 idiv put
+ } for
+ /d2 binval 12 get 2013571 mod def
+ binval 12 2 copy get 2013571 idiv put
+
+ /d1 0 def
+ /i true def
+ 0 1 12 {
+ /j exch def
+ binval j get
+ dup 0 eq i and {
+ pop
+ } {
+ /i false def
+ /d1 d1 3 -1 roll 10 12 j sub exp cvi mul add def
+ } ifelse
+ } for
+
+ /tab267 [
+ 183063 0 17 9 6 3 6538 28
+ 820063 183064 13 13 5 4 875 728
+ 1000775 820064 9 17 3 6 28 6454
+ 1491020 1000776 15 11 5 4 2415 203
+ 1979844 1491021 11 15 4 5 203 2408
+ 1996938 1979845 19 7 8 1 17094 1
+ 2013570 1996939 7 19 1 8 1 16632
+ ] def
+
+ /i 0 def {
+ d1 tab267 i get le {
+ tab267 i 1 add 7 getinterval {} forall
+ /d1te exch def /d1to exch def
+ /d1mwe exch def /d1mwo exch def
+ /d1ele exch def /d1elo exch def
+ /d1gs exch def
+ exit
+ } if
+ /i i 8 add def
+ } loop
+
+ /i 0 def {
+ d2 tab267 i get le {
+ tab267 i 1 add 7 getinterval {} forall
+ /d2te exch def /d2to exch def
+ /d2mwe exch def /d2mwo exch def
+ /d2ele exch def /d2elo exch def
+ /d2gs exch def
+ exit
+ } if
+ /i i 8 add def
+ } loop
+
+ /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 7 getRSSwidths def
+ /d1we d1 d1gs sub d1te mod d1ele d1mwe 7 getRSSwidths def
+ /d2wo d2 d2gs sub d2te idiv d2elo d2mwo 7 getRSSwidths def
+ /d2we d2 d2gs sub d2te mod d2ele d2mwe 7 getRSSwidths def
+
+ /d1w 14 array def
+ 0 1 6 {
+ /i exch def
+ d1w i 2 mul d1wo i get put
+ d1w i 2 mul 1 add d1we i get put
+ } for
+
+ /d2w 14 array def
+ 0 1 6 {
+ /i exch def
+ d2w i 2 mul d2wo i get put
+ d2w i 2 mul 1 add d2we i get put
+ } for
+
+ /widths [
+ d1w {} forall
+ d2w {} forall
+ ] def
+
+ /checkweights [
+ 1 3 9 27 81 65 17 51 64 14 42 37 22 66
+ 20 60 2 6 18 54 73 41 34 13 39 28 84 74
+ ] def
+
+ /checkseq [
+ 0 1 43 {} for
+ 45 52 57
+ 63 1 66 {} for
+ 73 1 79 {} for
+ 82
+ 126 1 130 {} for
+ 132
+ 141 1 146 {} for
+ 210 1 217 {} for
+ 220
+ 316 1 323 {} for
+ 326 337
+ ] def
+
+ /checksum 0 def
+ 0 1 27 {
+ /i exch def
+ /checksum checksum widths i get checkweights i get mul add def
+ } for
+ /checksum checksum 89 mod def
+ /seq checkseq checksum get def
+ /swidths seq 21 idiv 8 3 6 getRSSwidths def
+ /bwidths seq 21 mod 8 3 6 getRSSwidths def
+
+ /checkwidths [0 0 0 0 0 0 0 0 0 0 0 0 1 1] def
+ 0 1 5 {
+ /i exch def
+ checkwidths i 2 mul swidths i get put
+ checkwidths i 2 mul 1 add bwidths i get put
+ } for
+
+ /sbs [
+ 1 d1w {} forall checkwidths {} forall d2w {} forall 1 1
+ ] def
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) sbs put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/rsslimited load 0 1 dict put
+% --END ENCODER rsslimited--
+
+% --BEGIN ENCODER rssexpanded--
+% --DESC: Reduced Space Symbology Expanded (RSS-Expanded)
+% --EXAM: 000000010011001010100001000000010000
+/rssexpanded {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /height height cvr def
+
+ /getRSSwidths {
+ /mw exch def
+ /nm exch def
+ /val exch def
+ /j 0 def /i 0 def {
+ /v () def
+ mw 1 ne {/v i mw 4 string cvrs def} if
+ 0 v {48 sub add} forall 4 add nm eq {
+ j val eq {exit} if
+ /j j 1 add def
+ } if
+ /i i 1 add def
+ } loop
+ [4 {1} repeat v {47 sub} forall] v length 4 getinterval
+ } bind def
+
+ /binval [barcode {48 sub} forall] def
+ /datalen binval length 12 idiv def
+
+ /tab174 [
+ 347 0 12 5 7 2 87 4
+ 1387 348 10 7 5 4 52 20
+ 2947 1388 8 9 4 5 30 52
+ 3987 2948 6 11 3 6 10 104
+ 4191 3988 4 13 1 8 1 204
+ ] def
+
+ /dxw datalen array def
+
+ 0 1 datalen 1 sub {
+
+ /x exch def
+
+ /d binval x 12 mul 12 getinterval def
+ /d 0 0 1 11 {/j exch def 2 11 j sub exp cvi d j get mul add} for def
+
+ /j 0 def {
+ d tab174 j get le {
+ tab174 j 1 add 7 getinterval {} forall
+ /dte exch def /dto exch def
+ /dmwe exch def /dmwo exch def
+ /dele exch def /delo exch def
+ /dgs exch def
+ exit
+ } if
+ /j j 8 add def
+ } loop
+
+ /dwo d dgs sub dte idiv delo dmwo getRSSwidths def
+ /dwe d dgs sub dte mod dele dmwe getRSSwidths def
+
+ /dw 8 array def
+ x 2 mod 0 eq {
+ 0 1 3 {
+ /j exch def
+ dw 7 j 2 mul sub dwo j get put
+ dw 6 j 2 mul sub dwe j get put
+ } for
+ } {
+ 0 1 3 {
+ /j exch def
+ dw j 2 mul dwo j get put
+ dw j 2 mul 1 add dwe j get put
+ } for
+ } ifelse
+
+ dxw x dw put
+
+ } for
+
+ /widths [
+ dxw {{} forall} forall
+ ] def
+
+ /checkweights [
+ 77 96 32 81 27 9 3 1
+ 20 60 180 118 143 7 21 63
+ 205 209 140 117 39 13 145 189
+ 193 157 49 147 19 57 171 91
+ 132 44 85 169 197 136 186 62
+ 185 133 188 142 4 12 36 108
+ 50 87 29 80 97 173 128 113
+ 150 28 84 41 123 158 52 156
+ 166 196 206 139 187 203 138 46
+ 76 17 51 153 37 111 122 155
+ 146 119 110 107 106 176 129 43
+ 16 48 144 10 30 90 59 177
+ 164 125 112 178 200 137 116 109
+ 70 210 208 202 184 130 179 115
+ 190 204 68 93 31 151 191 134
+ 148 22 66 198 172 94 71 2
+ 40 154 192 64 162 54 18 6
+ 120 149 25 75 14 42 126 167
+ 175 199 207 69 23 78 26 79
+ 103 98 83 38 114 131 182 124
+ 159 53 88 170 127 183 61 161
+ 55 165 73 8 24 72 5 15
+ 89 100 174 58 160 194 135 45
+ ] def
+
+ /checksum 0 def
+ 0 1 widths length 1 sub {
+ /i exch def
+ /checksum checksum widths i get checkweights i get mul add def
+ } for
+ /checksum checksum 211 mod datalen 3 sub 211 mul add def
+
+ /i 0 def {
+ checksum tab174 i get le {
+ tab174 i 1 add 7 getinterval {} forall
+ /cte exch def /cto exch def
+ /cmwe exch def /cmwo exch def
+ /cele exch def /celo exch def
+ /cgs exch def
+ exit
+ } if
+ /i i 8 add def
+ } loop
+
+ /cwo checksum cgs sub cte idiv celo cmwo getRSSwidths def
+ /cwe checksum cgs sub cte mod cele cmwe getRSSwidths def
+
+ /cw 8 array def
+ 0 1 3 {
+ /i exch def
+ cw i 2 mul cwo i get put
+ cw i 2 mul 1 add cwe i get put
+ } for
+
+ /finderwidths [
+ 1 8 4 1 1 1 1 4 8 1
+ 3 6 4 1 1 1 1 4 6 3
+ 3 4 6 1 1 1 1 6 4 3
+ 3 2 8 1 1 1 1 8 2 3
+ 2 6 5 1 1 1 1 5 6 2
+ 2 2 9 1 1 1 1 9 2 2
+ ] def
+
+ /finderseq [
+ [0 1]
+ [0 3 2]
+ [0 5 2 7]
+ [0 9 2 7 4]
+ [0 9 2 7 6 11]
+ [0 9 2 7 8 11 10]
+ [0 1 2 3 4 5 6 7]
+ [0 1 2 3 4 5 6 9 8]
+ [0 1 2 3 4 5 6 9 10 11]
+ [0 1 2 3 4 7 6 9 8 11 10]
+ ] def
+
+ /seq finderseq datalen 2 add 2 idiv 2 sub get def
+ /fxw seq length array def
+ 0 1 seq length 1 sub {
+ /x exch def
+ fxw x finderwidths seq x get 5 mul 5 getinterval put
+ } for
+
+ /sbs [
+ 1
+ cw {} forall
+ 0 1 datalen 1 sub {
+ /i exch def
+ i 2 mod 0 eq {fxw i 2 idiv get {} forall} if
+ dxw i get {} forall
+ } for
+ 1 1
+ ] def
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) sbs put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/rssexpanded load 0 1 dict put
+% --END ENCODER rssexpanded--
+
+% --BEGIN ENCODER code2of5--
+% --DESC: Code 25
+% --EXAM: 01234567
+/code2of5 {
+
+ % Thanks to Michael Landers
+
+ 0 begin % Confine variable to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includecheck false def
+ /includetext false def % Enable/disable text
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (1111313111) (3111111131) (1131111131) (3131111111)
+ (1111311131) (3111311111) (1131311111) (1111113131)
+ (3111113111) (1131113111) (313111) (311131)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ /barlen barcode length def % Length of the code
+
+ includecheck {
+ /sbs barlen 10 mul 22 add string def
+ /txt barlen 1 add array def
+ } {
+ /sbs barlen 10 mul 12 add string def
+ /txt barlen array def
+ } ifelse
+
+ % Put the start character
+ sbs 0 encs 10 get putinterval
+
+ /checksum 0 def
+
+ 0 1 barlen 1 sub {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 10 mul 6 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 14 mul 10 add textpos textfont textsize] put
+ barlen i sub 2 mod 0 eq {
+ /checksum checksum indx add def
+ } {
+ /checksum checksum indx 3 mul add def
+ } ifelse
+ } for
+
+ % Put the checksum and end characters
+ includecheck {
+ /checksum 10 checksum 10 mod sub 10 mod def
+ sbs barlen 10 mul 6 add encs checksum get putinterval
+ sbs barlen 10 mul 16 add encs 11 get putinterval
+ includecheckintext {
+ txt barlen [barchars checksum 1 getinterval barlen 14 mul 10 add textpos textfont textsize] put
+ } {
+ txt barlen [( ) barlen 14 mul 10 add textpos textfont textsize] put
+ } ifelse
+ } {
+ sbs barlen 10 mul 6 add encs 11 get putinterval
+ } ifelse
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/code2of5 load 0 1 dict put
+% --END ENCODER code2of5--
+
+% --BEGIN ENCODER code11--
+% --DESC: Code 11
+% --EXAM: 0123456789
+/code11 {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includecheck false def
+ /includetext false def
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (111131) (311131) (131131) (331111) (113131)
+ (313111) (133111) (111331) (311311) (311111)
+ (113111) (113311)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789-) def
+
+ /barlen barcode length def % Length of the code
+
+ includecheck {
+ barlen 10 ge {
+ /sbs barlen 6 mul 24 add string def
+ /txt barlen 2 add array def
+ } {
+ /sbs barlen 6 mul 18 add string def
+ /txt barlen 1 add array def
+ } ifelse
+ } {
+ /sbs barlen 6 mul 12 add string def
+ /txt barlen array def
+ } ifelse
+
+ % Put the start character
+ sbs 0 encs 10 get putinterval
+
+ /checksum1 0 def /checksum2 0 def
+
+ /xpos 8 def
+ 0 1 barlen 1 sub {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval xpos textpos textfont textsize] put
+ 0 1 5 { % xpos+=width of the character
+ /xpos exch enc exch get 48 sub xpos add def
+ } for
+ /checksum1 checksum1 barlen i sub 1 sub 10 mod 1 add indx mul add def
+ /checksum2 checksum2 barlen i sub 9 mod 1 add indx mul add def
+ } for
+
+ % Put the checksum and end characters
+ includecheck {
+ /checksum1 checksum1 11 mod def
+ barlen 10 ge {
+ /checksum2 checksum2 checksum1 add 11 mod def
+ sbs barlen 6 mul 6 add encs checksum1 get putinterval
+ sbs barlen 6 mul 12 add encs checksum2 get putinterval
+ includecheckintext {
+ txt barlen [barchars checksum1 1 getinterval xpos textpos textfont textsize] put
+ /enc encs checksum1 get def
+ 0 1 5 { % xpos+=width of the character
+ /xpos exch enc exch get 48 sub xpos add def
+ } for
+ txt barlen 1 add [barchars checksum2 1 getinterval xpos textpos textfont textsize] put
+ } {
+ txt barlen [() xpos textpos textfont textsize] put
+ txt barlen 1 add [() xpos textpos textfont textsize] put
+ } ifelse
+ sbs barlen 6 mul 18 add encs 11 get putinterval
+ } {
+ sbs barlen 6 mul 6 add encs checksum1 get putinterval
+ includecheckintext {
+ txt barlen [barchars checksum1 1 getinterval xpos textpos textfont textsize] put
+ } {
+ txt barlen [() xpos textpos textfont textsize] put
+ } ifelse
+ sbs barlen 6 mul 12 add encs 11 get putinterval
+ } ifelse
+ } {
+ sbs barlen 6 mul 6 add encs 11 get putinterval
+ } ifelse
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/code11 load 0 1 dict put
+% --END ENCODER code11--
+
+% --BEGIN ENCODER rationalizedCodabar--
+% --DESC: Rationalized Codabar
+% --EXAM: A0123456789B
+/rationalizedCodabar {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includecheck false def % Enable/disable checkdigit
+ /includetext false def % Enable/disable text
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (11111331) (11113311) (11131131) (33111111) (11311311)
+ (31111311) (13111131) (13113111) (13311111) (31131111)
+ (11133111) (11331111) (31113131) (31311131) (31313111)
+ (11313131) (11331311) (13131131) (11131331) (11133311)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789-$:/.+ABCD) def
+
+ /barlen barcode length def % Length of the code
+
+ includecheck {
+ /sbs barlen 8 mul 8 add string def
+ /txt barlen 1 add array def
+ } {
+ /sbs barlen 8 mul string def
+ /txt barlen array def
+ } ifelse
+
+ /checksum 0 def
+ /xpos 0 def
+ 0 1 barlen 2 sub {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 8 mul enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval xpos textpos textfont textsize] put
+ 0 1 7 { % xpos+=width of the character
+ /xpos exch enc exch get 48 sub xpos add def
+ } for
+ /checksum checksum indx add def
+ } for
+
+ % Find index of last character
+ barcode barlen 1 sub 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+
+ includecheck {
+ % Put the checksum character
+ /checksum checksum indx add def
+ /checksum 16 checksum 16 mod sub 16 mod def
+ sbs barlen 8 mul 8 sub encs checksum get putinterval
+ includecheckintext {
+ txt barlen 1 sub [barchars checksum 1 getinterval xpos textpos textfont textsize] put
+ } {
+ txt barlen 1 sub [( ) xpos textpos textfont textsize] put
+ } ifelse
+ 0 1 7 { % xpos+=width of the character
+ /xpos exch encs checksum get exch get 48 sub xpos add def
+ } for
+ % Put the end character
+ /enc encs indx get def % Get the indxth encoding
+ sbs barlen 8 mul enc putinterval % Put encoded digit into sbs
+ txt barlen [barcode barlen 1 sub 1 getinterval xpos textpos textfont textsize] put
+ } {
+ % Put the end character
+ /enc encs indx get def % Get the indxth encoding
+ sbs barlen 8 mul 8 sub enc putinterval % Put encoded digit into sbs
+ txt barlen 1 sub [barcode barlen 1 sub 1 getinterval xpos textpos textfont textsize] put
+ } ifelse
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/rationalizedCodabar load 0 1 dict put
+% --END ENCODER rationalizedCodabar--
+
+% --BEGIN ENCODER onecode--
+% --DESC: United States Postal Service OneCode
+% --EXAM: 0123456709498765432101234567891
+/onecode {
+
+ 0 begin
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /height 0.175 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /height height cvr def
+
+ /barlen barcode length def
+
+ /normalize {
+ /base exch def
+ /num exch def
+ num length 1 sub -1 1 {
+ /i exch def
+ num i 1 sub 2 copy get num i get base idiv add put
+ num i num i get base mod put
+ } for
+ { %loop - extend input as necessary
+ num 0 get base lt {exit} if
+ /num [0 num {} forall] def
+ num 0 num 0 get num 1 get base idiv add put
+ num 1 num 1 get base mod put
+ } loop
+ % Trim leading zeros
+ /num [/i true def num {dup 0 eq i and {pop} {/i false def} ifelse} forall] def
+ num length 0 eq {/num [0] def} if
+ num
+ } bind def
+
+ /bigadd {
+ 2 copy length exch length
+ 2 copy sub abs /offset exch def
+ lt {exch} if
+ /a exch def /b exch def
+ 0 1 b length 1 sub {
+ dup a exch offset add 2 copy get b 5 -1 roll get add put
+ } for
+ a
+ } bind def
+
+ % Conversion of data fields into binary data
+ barlen 20 eq {[0]} if
+ barlen 25 eq {[1]} if
+ barlen 29 eq {[1 0 0 0 0 1]} if
+ barlen 31 eq {[1 0 0 0 1 0 0 0 0 1]} if
+ /binval exch [barcode 20 barlen 20 sub getinterval {48 sub} forall] bigadd def
+ /binval [binval {} forall barcode 0 get 48 sub] def
+ /binval [binval {5 mul} forall] [barcode 1 get 48 sub] bigadd 10 normalize def
+ /binval [binval {} forall barcode 2 18 getinterval {48 sub} forall] def
+
+ % Conversion of binary data into byte array
+ /bytes 13 array def
+ /bintmp [binval {} forall] def
+ 12 -1 0 {
+ /i exch def
+ 0 1 bintmp length 2 sub {
+ /j exch def
+ bintmp j 1 add 2 copy get bintmp j get 256 mod 10 mul add put
+ bintmp j bintmp j get 256 idiv put
+ } for
+ bytes i bintmp bintmp length 1 sub get 256 mod put
+ bintmp bintmp length 1 sub 2 copy get 256 idiv put
+ } for
+
+ % Generation of 11-bit CRC on byte array
+ /fcs 2047 def
+ /dat bytes 0 get 5 bitshift def
+ 6 {
+ fcs dat xor 1024 and 0 ne {
+ /fcs fcs 1 bitshift 3893 xor def
+ } {
+ /fcs fcs 1 bitshift def
+ } ifelse
+ /fcs fcs 2047 and def
+ /dat dat 1 bitshift def
+ } repeat
+ 1 1 12 {
+ bytes exch get 3 bitshift /dat exch def
+ 8 {
+ fcs dat xor 1024 and 0 ne {
+ /fcs fcs 1 bitshift 3893 xor def
+ } {
+ /fcs fcs 1 bitshift def
+ } ifelse
+ /fcs fcs 2047 and def
+ /dat dat 1 bitshift def
+ } repeat
+ } for
+
+ % Conversion from binary data to codewords
+ /codewords 10 array def
+ 9 -1 0 {
+ /i exch def
+ i 9 eq {
+ /b 636 def
+ } {
+ /b 1365 def
+ } ifelse
+ 0 1 binval length 2 sub {
+ /j exch def
+ binval j 1 add 2 copy get binval j get b mod 10 mul add put
+ binval j binval j get b idiv put
+ } for
+ codewords i binval binval length 1 sub get b mod put
+ binval binval length 1 sub 2 copy get b idiv put
+ } for
+
+ % Inserting additional information into codewords
+ codewords 9 codewords 9 get 2 mul put
+ fcs 1024 and 0 ne {
+ codewords 0 codewords 0 get 659 add put
+ } if
+
+ % Conversion from codewords to characters
+ /tab513 1287 dict def
+ /lo 0 def
+ /hi 1286 def
+ 0 1 8191 {
+ { % no loop - provides common exit point
+ /i exch def
+ /onbits 0 def
+ 0 1 12 {
+ i exch 1 exch bitshift and 0 ne {
+ /onbits onbits 1 add def
+ } if
+ } for
+ onbits 5 ne {exit} if
+ /j i def
+ /rev 0 def
+ 16 {
+ /rev rev 1 bitshift j 1 and or def
+ /j j -1 bitshift def
+ } repeat
+ /rev rev -3 bitshift def
+ rev i lt {exit} if
+ rev i eq {
+ tab513 hi i put
+ /hi hi 1 sub def
+ } {
+ tab513 lo i put
+ tab513 lo 1 add rev put
+ /lo lo 2 add def
+ } ifelse
+ exit
+ } loop
+ } for
+
+ /tab213 78 dict def
+ /lo 0 def
+ /hi 77 def
+ 0 1 8191 {
+ { % no loop - provides common exit point
+ /i exch def
+ /onbits 0 def
+ 0 1 12 {
+ i exch 1 exch bitshift and 0 ne {
+ /onbits onbits 1 add def
+ } if
+ } for
+ onbits 2 ne {exit} if
+ /j i def
+ /rev 0 def
+ 16 {
+ /rev rev 1 bitshift j 1 and or def
+ /j j -1 bitshift def
+ } repeat
+ /rev rev -3 bitshift def
+ rev i lt {exit} if
+ rev i eq {
+ tab213 hi i put
+ /hi hi 1 sub def
+ } {
+ tab213 lo i put
+ tab213 lo 1 add rev put
+ /lo lo 2 add def
+ } ifelse
+ exit
+ } loop
+ } for
+
+ /chars 10 array def
+ 0 1 9 {
+ /i exch def
+ codewords i get dup 1286 le {
+ tab513 exch get
+ } {
+ tab213 exch 1287 sub get
+ } ifelse
+ chars i 3 -1 roll put
+ } for
+
+ 9 -1 0 {
+ /i exch def
+ 2 i exp cvi fcs and 0 ne {
+ chars i chars i get 8191 xor put
+ } if
+ } for
+
+ % Conversion from characters to the OneCode encoding
+ /barmap [
+ 7 2 4 3 1 10 0 0 9 12 2 8 5 5 6 11 8 9 3 1
+ 0 1 5 12 2 5 1 8 4 4 9 11 6 3 8 10 3 9 7 6
+ 5 11 1 4 8 5 2 12 9 10 0 2 7 1 6 7 3 6 4 9
+ 0 3 8 6 6 4 2 7 1 1 9 9 7 10 5 2 4 0 3 8
+ 6 2 0 4 8 11 1 0 9 8 3 12 2 6 7 7 5 1 4 10
+ 1 12 6 9 7 3 8 0 5 8 9 7 4 6 2 10 3 4 0 5
+ 8 4 5 7 7 11 1 9 6 0 9 6 0 6 4 8 2 1 3 2
+ 5 9 8 12 4 11 6 1 9 5 7 4 3 3 1 2 0 7 2 0
+ 1 3 4 1 6 10 3 5 8 7 9 4 2 11 5 6 0 8 7 12
+ 4 2 8 1 5 10 3 0 9 3 0 9 6 5 2 4 7 8 1 7
+ 5 0 4 5 2 3 0 10 6 12 9 2 3 11 1 6 8 8 7 9
+ 5 4 0 11 1 5 2 2 9 1 4 12 8 3 6 6 7 0 3 7
+ 4 7 7 5 0 12 1 11 2 9 9 0 6 8 5 3 3 10 8 2
+ ] def
+
+ /bbs 65 array def
+ /bhs 65 array def
+ 0 1 64 {
+ /i exch def
+ /dec chars barmap i 4 mul get get 2 barmap i 4 mul 1 add get exp cvi and 0 ne def
+ /asc chars barmap i 4 mul 2 add get get 2 barmap i 4 mul 3 add get exp cvi and 0 ne def
+ dec not asc not and {
+ bbs i 3 height mul 8 div put
+ bhs i 2 height mul 8 div put
+ } if
+ dec not asc and {
+ bbs i 3 height mul 8 div put
+ bhs i 5 height mul 8 div put
+ } if
+ dec asc not and {
+ bbs i 0 height mul 8 div put
+ bhs i 5 height mul 8 div put
+ } if
+ dec asc and {
+ bbs i 0 height mul 8 div put
+ bhs i 8 height mul 8 div put
+ } if
+ } for
+
+ /retval 4 dict def
+ retval (bbs) bbs put
+ retval (bhs) bhs put
+ retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/onecode load 0 1 dict put
+% --END ENCODER onecode--
+
+% --BEGIN ENCODER postnet--
+% --DESC: United States Postal Service Postnet
+% --EXAM: 012345
+/postnet {
+
+ % Thanks to Ross McFarland
+
+ 0 begin
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 0.125 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ /barlen barcode length def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (55222) (22255) (22525) (22552) (25225)
+ (25252) (25522) (52225) (52252) (52522)
+ (5) (5)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ /bhs barlen 5 mul 7 add array def
+ /txt barlen 1 add array def
+
+ % Put start character
+ /enc encs 10 get def
+ /heights enc length array def
+ 0 1 enc length 1 sub {
+ /j exch def
+ heights j enc j 1 getinterval cvi height mul 5 div put
+ } for
+ bhs 0 heights putinterval % Put encoded digit into sbs
+
+ /checksum 0 def
+ 0 1 barlen 1 sub {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ /heights enc length array def
+ 0 1 enc length 1 sub {
+ /j exch def
+ heights j enc j 1 getinterval cvi height mul 5 div put
+ } for
+ bhs i 5 mul 1 add heights putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 5 mul 1 add 3.312 mul textpos textfont textsize] put
+ /checksum checksum indx add def % checksum+=indx
+ } for
+
+ % Put the checksum character
+ /checksum 10 checksum 10 mod sub 10 mod def
+ /enc encs checksum get def
+ /heights enc length array def
+ 0 1 enc length 1 sub {
+ /j exch def
+ heights j enc j 1 getinterval cvi height mul 5 div put
+ } for
+ bhs barlen 5 mul 1 add heights putinterval
+
+ includecheckintext {
+ txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textpos textfont textsize] put
+ } {
+ txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textpos textfont textsize] put
+ } ifelse
+
+ % Put end character
+ /enc encs 11 get def
+ /heights enc length array def
+ 0 1 enc length 1 sub {
+ /j exch def
+ heights j enc j 1 getinterval cvi height mul 5 div put
+ } for
+ bhs barlen 5 mul 6 add heights putinterval
+
+ /retval 1 dict def
+ retval (bhs) bhs put
+ retval (bbs) [bhs length {0} repeat] put
+ retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/postnet load 0 1 dict put
+% --END ENCODER postnet--
+
+% --BEGIN ENCODER royalmail--
+% --DESC: Royal Mail 4 State Customer Code (RM4SCC)
+% --EXAM: LE28HS9Z
+/royalmail {
+
+ 0 begin
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 0.175 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (3300) (2211) (2301) (2310) (3201) (3210)
+ (1122) (0033) (0123) (0132) (1023) (1032)
+ (1302) (0213) (0303) (0312) (1203) (1212)
+ (1320) (0231) (0321) (0330) (1221) (1230)
+ (3102) (2013) (2103) (2112) (3003) (3012)
+ (3120) (2031) (2121) (2130) (3021) (3030)
+ (2) (3)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRS) def
+
+ /barlen barcode length def
+ /encstr barlen 4 mul 6 add string def
+ /txt barlen 1 add array def
+
+ % Put start character
+ encstr 0 encs 36 get putinterval
+
+ /checksumrow 0 def
+ /checksumcol 0 def
+ 0 1 barlen 1 sub {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ encstr i 4 mul 1 add enc putinterval
+ txt i [barcode i 1 getinterval i 4 mul 1 add 3.312 mul textpos textfont textsize] put
+ /checksumrow checksumrow indx 6 idiv add def
+ /checksumcol checksumcol indx 6 mod add def
+ } for
+
+ % Put the checksum character
+ /checksum checksumrow 6 mod 6 mul checksumcol 6 mod add def
+ /enc encs checksum get def
+ encstr barlen 4 mul 1 add enc putinterval
+ includecheckintext {
+ txt barlen [barchars checksum 1 getinterval barlen 4 mul 1 add 3.312 mul textpos textfont textsize] put
+ } {
+ txt barlen [( ) barlen 4 mul 1 add 3.312 mul textpos textfont textsize] put
+ } ifelse
+
+ % Put end character
+ encstr barlen 4 mul 5 add encs 37 get putinterval
+
+ /bbs encstr length array def
+ /bhs encstr length array def
+ 0 1 encstr length 1 sub {
+ /i exch def
+ /enc encstr i 1 getinterval def
+ enc (0) eq {
+ bbs i 3 height mul 8 div put
+ bhs i 2 height mul 8 div put
+ } if
+ enc (1) eq {
+ bbs i 0 height mul 8 div put
+ bhs i 5 height mul 8 div put
+ } if
+ enc (2) eq {
+ bbs i 3 height mul 8 div put
+ bhs i 5 height mul 8 div put
+ } if
+ enc (3) eq {
+ bbs i 0 height mul 8 div put
+ bhs i 8 height mul 8 div put
+ } if
+ } for
+
+ /retval 4 dict def
+ retval (bbs) bbs put
+ retval (bhs) bhs put
+ retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/royalmail load 0 1 dict put
+% --END ENCODER royalmail--
+
+% --BEGIN ENCODER auspost--
+% --DESC: AusPost 4 State Customer Code
+% --EXAM: 5956439111ABA 9
+/auspost {
+
+ 0 begin
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 0.175 def
+ /custinfoenc (character) def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (000) (001) (002) (010) (011) (012) (020) (021)
+ (022) (100) (101) (102) (110) (111) (112) (120)
+ (121) (122) (200) (201) (202) (210) (211) (212)
+ (220) (221) (222) (300) (301) (302) (310) (311)
+ (312) (320) (321) (322) (023) (030) (031) (032)
+ (033) (103) (113) (123) (130) (131) (132) (133)
+ (203) (213) (223) (230) (231) (232) (233) (303)
+ (313) (323) (330) (331) (332) (333) (003) (013)
+ (00) (01) (02) (10) (11) (12) (20) (21) (22) (30)
+ (13) (3)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz #) def
+
+ /barlen barcode length def
+ barcode 0 2 getinterval (11) eq {37} if
+ barcode 0 2 getinterval (59) eq {52} if
+ barcode 0 2 getinterval (62) eq {67} if
+ /encstr exch string def
+ /txt barlen 2 sub array def
+
+ % Put start character
+ encstr 0 encs 74 get putinterval
+
+ % Encode the FCC
+ 0 1 1 {
+ /i exch def
+ encs barcode i 1 getinterval cvi 64 add get
+ encstr i 2 mul 2 add 3 2 roll putinterval
+ } for
+
+ % Encode the DPID
+ 2 1 9 {
+ /i exch def
+ encs barcode i 1 getinterval cvi 64 add get
+ encstr i 2 mul 2 add 3 2 roll putinterval
+ txt i 2 sub [barcode i 1 getinterval i 2 sub 2 mul 6 add 3.312 mul textpos textfont textsize] put
+ } for
+
+ % Encode the customer information
+ custinfoenc (numeric) eq {
+ 0 1 barlen 11 sub {
+ /i exch def
+ encs barcode i 10 add 1 getinterval cvi 64 add get
+ encstr i 2 mul 22 add 3 2 roll putinterval
+ txt i 8 add [barcode i 10 add 1 getinterval i 2 mul 22 add 3.312 mul textpos textfont textsize] put
+ } for
+ /ciflen barlen 10 sub 2 mul def
+ } {
+ 0 1 barlen 11 sub {
+ /i exch def
+ barcode i 10 add 1 getinterval barchars exch search
+ pop
+ length /indx exch def
+ pop pop
+ /enc encs indx get def
+ encstr i 3 mul 22 add enc putinterval
+ txt i 8 add [barcode i 10 add 1 getinterval i 3 mul 22 add 3.312 mul textpos textfont textsize] put
+ } for
+ /ciflen barlen 10 sub 3 mul def
+ } ifelse
+
+ % Add any filler characters
+ 22 ciflen add 1 encstr length 14 sub {
+ encstr exch encs 75 get putinterval
+ } for
+
+ % Create the 64x64 Reed-Solomon table
+ /rstable 64 64 mul array def
+ rstable 0 [ 64 {0} repeat ] putinterval
+ rstable 64 [ 0 1 63 {} for ] putinterval
+ /prev 1 def
+ 64 {
+ /next prev 1 bitshift def
+ next 64 and 0 ne {
+ /next next 67 xor def
+ } if
+ 0 1 63 {
+ /j exch def
+ /nextcell {rstable 64 next mul j add} def
+ nextcell rstable 64 prev mul j add get 1 bitshift put
+ nextcell get 64 and 0 ne {
+ nextcell nextcell get 67 xor put
+ } if
+ } for
+ /prev next def
+ } repeat
+
+ % Calculate the Reed-Solomon codes for triples
+ /rscodes encstr length 16 sub 3 idiv 4 add array def
+ rscodes 0 [ 4 {0} repeat ] putinterval
+ 2 3 encstr length 16 sub {
+ /i exch def
+ rscodes rscodes length i 2 sub 3 idiv sub 1 sub
+ encstr i 1 getinterval cvi 16 mul
+ encstr i 1 add 1 getinterval cvi 4 mul add
+ encstr i 2 add 1 getinterval cvi add
+ put
+ } for
+ rscodes length 5 sub -1 0 {
+ /i exch def
+ 0 1 4 {
+ /j exch def
+ rscodes i j add rscodes i j add get
+ rstable 64 [48 17 29 30 1] j get mul rscodes i 4 add get add get
+ xor put
+ } for
+ } for
+ /checkcode (000000000000) def
+ 0 1 3 {
+ /i exch def
+ /enc rscodes 3 i sub get 4 3 string cvrs def
+ checkcode i 3 mul 3 enc length sub add enc putinterval
+ } for
+
+ % Put checkcode and end characters
+ encstr encstr length 14 sub checkcode putinterval
+ encstr encstr length 2 sub encs 74 get putinterval
+
+ /bbs encstr length array def
+ /bhs encstr length array def
+ 0 1 encstr length 1 sub {
+ /i exch def
+ /enc encstr i 1 getinterval def
+ enc (0) eq {
+ bbs i 0 height mul 8 div put
+ bhs i 8 height mul 8 div put
+ } if
+ enc (1) eq {
+ bbs i 3 height mul 8 div put
+ bhs i 5 height mul 8 div put
+ } if
+ enc (2) eq {
+ bbs i 0 height mul 8 div put
+ bhs i 5 height mul 8 div put
+ } if
+ enc (3) eq {
+ bbs i 3 height mul 8 div put
+ bhs i 2 height mul 8 div put
+ } if
+ } for
+
+ /retval 4 dict def
+ retval (bbs) bbs put
+ retval (bhs) bhs put
+ retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/auspost load 0 1 dict put
+% --END ENCODER auspost--
+
+% --BEGIN ENCODER kix--
+% --DESC: Royal Dutch TPG Post KIX 4-State Barcode
+% --EXAM: 1231FZ13XHS
+/kix {
+
+ 0 begin
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 0.175 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (0033) (0123) (0132) (1023) (1032) (1122)
+ (0213) (0303) (0312) (1203) (1212) (1302)
+ (0231) (0321) (0330) (1221) (1230) (1320)
+ (2013) (2103) (2112) (3003) (3012) (3102)
+ (2031) (2121) (2130) (3021) (3030) (3120)
+ (2211) (2301) (2310) (3201) (3210) (3300)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
+
+ /barlen barcode length def
+ /encstr barlen 4 mul string def
+ /txt barlen array def
+
+ 0 1 barlen 1 sub {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ encstr i 4 mul enc putinterval
+ txt i [barcode i 1 getinterval i 4 mul 3.312 mul textpos textfont textsize] put
+ } for
+
+ /bbs encstr length array def
+ /bhs encstr length array def
+ 0 1 encstr length 1 sub {
+ /i exch def
+ /enc encstr i 1 getinterval def
+ enc (0) eq {
+ bbs i 3 height mul 8 div put
+ bhs i 2 height mul 8 div put
+ } if
+ enc (1) eq {
+ bbs i 0 height mul 8 div put
+ bhs i 5 height mul 8 div put
+ } if
+ enc (2) eq {
+ bbs i 3 height mul 8 div put
+ bhs i 5 height mul 8 div put
+ } if
+ enc (3) eq {
+ bbs i 0 height mul 8 div put
+ bhs i 8 height mul 8 div put
+ } if
+ } for
+
+ /retval 4 dict def
+ retval (bbs) bbs put
+ retval (bhs) bhs put
+ retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/kix load 0 1 dict put
+% --END ENCODER kix--
+
+% --BEGIN ENCODER msi--
+% --DESC: MSI Modified Plessey
+% --EXAM: 0123456789
+/msi {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includecheck false def % Enable/disable checkdigit
+ /includetext false def % Enable/disable text
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (13131313) (13131331) (13133113) (13133131) (13311313)
+ (13311331) (13313113) (13313131) (31131313) (31131331)
+ (31) (131)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ /barlen barcode length def % Length of the code
+
+ includecheck {
+ /sbs barlen 8 mul 13 add string def
+ /txt barlen 1 add array def
+ } {
+ /sbs barlen 8 mul 5 add string def
+ /txt barlen array def
+ } ifelse
+
+
+ % Put start character
+ sbs 0 encs 10 get putinterval
+ /checksum 0 def
+
+ 0 1 barlen 1 sub {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 8 mul 2 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 16 mul 4 add textpos textfont textsize] put
+ barlen i sub 2 mod 0 eq {
+ /checksum indx checksum add def
+ } {
+ /checksum indx 2 mul dup 10 idiv add checksum add def
+ } ifelse
+ } for
+
+ % Put the checksum and end characters
+ includecheck {
+ /checksum 10 checksum 10 mod sub 10 mod def
+ sbs barlen 8 mul 2 add encs checksum get putinterval
+ includecheckintext {
+ txt barlen [barchars checksum 1 getinterval barlen 16 mul 4 add textpos textfont textsize] put
+ } {
+ txt barlen [( ) barlen 16 mul 4 add textpos textfont textsize] put
+ } ifelse
+ sbs barlen 8 mul 10 add encs 11 get putinterval
+ } {
+ sbs barlen 8 mul 2 add encs 11 get putinterval
+ } ifelse
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/msi load 0 1 dict put
+% --END ENCODER msi--
+
+% --BEGIN ENCODER plessey--
+% --DESC: Plessey
+% --EXAM: 01234ABCD
+/plessey {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /barcode exch def % We are given a barcode string
+
+ /includetext false def % Enable/disable text
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textpos -7 def
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /textfont textfont cvlit def
+ /textsize textsize cvr def
+ /textpos textpos cvr def
+ /height height cvr def
+
+ % Create an array containing the character mappings
+ /encs
+ [ (13131313) (31131313) (13311313) (31311313)
+ (13133113) (31133113) (13313113) (31313113)
+ (13131331) (31131331) (13311331) (31311331)
+ (13133131) (31133131) (13313131) (31313131)
+ (31311331) (331311313)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789ABCDEF) def
+
+ /barlen barcode length def % Length of the code
+ /sbs barlen 8 mul 33 add string def
+ /txt barlen 2 add array def
+ /checkbits barlen 4 mul 8 add array def
+ checkbits barlen 4 mul [ 0 0 0 0 0 0 0 0 ] putinterval
+
+ % Put start character
+ sbs 0 encs 16 get putinterval
+
+ 0 1 barlen 1 sub {
+ /i exch def
+ % Lookup the encoding for the each barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ sbs i 8 mul 8 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 16 mul 16 add textpos textfont textsize] put
+ checkbits i 4 mul [
+ indx 1 and
+ indx -1 bitshift 1 and
+ indx -2 bitshift 1 and
+ indx -3 bitshift
+ ] putinterval
+ } for
+
+ % Checksum is last 8 bits of a CRC using a salt
+ /checksalt [ 1 1 1 1 0 1 0 0 1 ] def
+ 0 1 barlen 4 mul 1 sub {
+ /i exch def
+ checkbits i get 1 eq {
+ 0 1 8 {
+ /j exch def
+ checkbits i j add checkbits i j add get checksalt j get xor put
+ } for
+ } if
+ } for
+
+ % Calculate the value of the checksum digits
+ /checkval 0 def
+ 0 1 7 {
+ /i exch def
+ /checkval checkval 2 7 i sub exp cvi checkbits barlen 4 mul i add get mul add def
+ } for
+
+ % Put the checksum characters
+ /checksum1 checkval -4 bitshift def
+ /checksum2 checkval 15 and def
+ sbs barlen 8 mul 8 add encs checksum1 get putinterval
+ sbs barlen 8 mul 16 add encs checksum2 get putinterval
+ includecheckintext {
+ txt barlen [barchars checksum1 1 getinterval barlen 16 mul 16 add textpos textfont textsize] put
+ txt barlen 1 add [barchars checksum2 1 getinterval barlen 1 add 16 mul 16 add textpos textfont textsize] put
+ } {
+ txt barlen [( ) barlen 16 mul 16 add textpos textfont textsize] put
+ txt barlen 1 add [( ) barlen 1 add 16 mul 16 add textpos textfont textsize] put
+ } ifelse
+
+ % Put end character
+ sbs barlen 8 mul 24 add encs 17 get putinterval
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ includetext {
+ retval (txt) txt put
+ } if
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/plessey load 0 1 dict put
+% --END ENCODER plessey--
+
+% --BEGIN ENCODER raw--
+% --DESC: Raw bar space succession for custom symbologies
+% --EXAM: 331132131313411122131311333213114131131221323
+/raw {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /useropts options def
+ /sbs exch def % We are given a barcode string
+
+ /height 1 def
+
+ % Parse the input options
+ options {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+ /height height cvr def
+
+ % Return the arguments
+ /retval 1 dict def
+ retval (sbs) [sbs {48 sub} forall] put
+ retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
+ retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ retval (opt) useropts put
+ retval
+
+ end
+
+} bind def
+/raw load 0 1 dict put
+% --END ENCODER raw--
+
+% --BEGIN ENCODER symbol--
+% --DESC: Miscellaneous symbols
+% --EXAM: fima
+/symbol {
+
+ 0 begin % Confine variables to local scope
+
+ /options exch def % We are given an option string
+ /barcode exch def % We are given a barcode string
+
+ barcode (fima) eq {
+ /sbs [2.25 2.25 2.25 11.25 2.25 11.25 2.25 2.25 2.25] def
+ /bhs [.625 .625 .625 .625 .625] def
+ /bbs [0 0 0 0 0] def
+ } if
+
+ barcode (fimb) eq {
+ /sbs [2.25 6.75 2.25 2.25 2.25 6.25 2.25 2.25 2.25 6.75 2.25] def
+ /bhs [.625 .625 .625 .625 .625 .625] def
+ /bbs [0 0 0 0 0 0] def
+ } if
+
+ barcode (fimc) eq {
+ /sbs [2.25 2.25 2.25 6.75 2.25 6.75 2.25 6.75 2.25 2.25 2.25] def
+ /bhs [.625 .625 .625 .625 .625 .625] def
+ /bbs [0 0 0 0 0 0] def
+ } if
+
+ barcode (fimd) eq {
+ /sbs [2.25 2.25 2.25 2.25 2.25 6.75 2.25 6.75 2.25 2.25 2.25 2.25 2.25] def
+ /bhs [.625 .625 .625 .625 .625 .625 .625] def
+ /bbs [0 0 0 0 0 0 0] def
+ } if
+
+ % Return the arguments
+ /retval 4 dict def
+ retval (sbs) sbs put
+ retval (bhs) bhs put
+ retval (bbs) bbs put
+ retval (opt) options put
+ retval
+
+ end
+
+} bind def
+/symbol load 0 1 dict put
+% --END ENCODER symbol--
+
+% --BEGIN RENDERER--
+/barcode {
+
+ 0 begin % Confine variables to local scope
+
+ /args exch def % We are given some arguments
+
+ % Default options
+ /sbs [] def
+ /bhs [] def
+ /bbs [] def
+ /txt [] def
+ /barcolor (unset) def
+ /textcolor (unset) def
+ /bordercolor (unset) def
+ /backgroundcolor (unset) def
+ /inkspread 0.15 def
+ /width 0 def
+ /barratio 1 def
+ /spaceratio 1 def
+ /showborder false def
+ /borderleft 10 def
+ /borderright 10 def
+ /bordertop 1 def
+ /borderbottom 1 def
+ /borderwidth 0.5 def
+ /guardwhitespace false def
+ /guardleftpos 0 def
+ /guardleftypos 0 def
+ /guardrightpos 0 def
+ /guardrightypos 0 def
+ /guardwidth 6 def
+ /guardheight 7 def
+
+ % Apply the renderer options
+ args {exch cvlit exch def} forall
+
+ % Parse the user options
+ opt {
+ token false eq {exit} if dup length string cvs (=) search
+ true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ } loop
+
+ /barcolor barcolor cvlit def
+ /textcolor textcolor cvlit def
+ /bordercolor bordercolor cvlit def
+ /backgroundcolor backgroundcolor cvlit def
+ /inkspread inkspread cvr def
+ /width width cvr def
+ /barratio barratio cvr def
+ /spaceratio spaceratio cvr def
+ /borderleft borderleft cvr def
+ /borderright borderright cvr def
+ /bordertop bordertop cvr def
+ /borderbottom borderbottom cvr def
+ /borderwidth borderwidth cvr def
+ /guardleftpos guardleftpos cvr def
+ /guardleftypos guardleftypos cvr def
+ /guardrightpos guardrightpos cvr def
+ /guardrightypos guardrightypos cvr def
+ /guardwidth guardwidth cvr def
+ /guardheight guardheight cvr def
+
+ % Create bar elements and put them into the bars array
+ /bars sbs length 1 add 2 idiv array def
+ /x 0.00 def /maxh 0 def
+ 0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
+ /i exch def
+ i 2 mod 0 eq { % i is even
+ /d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
+ /h bhs i 2 idiv get 72 mul def % Height from bhs
+ /c d 2 div x add def % Centre of the bar = x + d/2
+ /y bbs i 2 idiv get 72 mul def % Baseline from bbs
+ /w d inkspread sub def % bar width = digit - inkspread
+ bars i 2 idiv [h c y w] put % Add the bar entry
+ h maxh gt {/maxh h def} if
+ } {
+ /d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
+ } ifelse
+ /x x d add def % x+=d
+ } for
+
+ gsave
+
+ currentpoint translate
+
+ % Force symbol to given width
+ width 0 ne {
+ width 72 mul x div 1 scale
+ } if
+
+ % Display the border and background
+ newpath
+ borderleft neg borderbottom neg moveto
+ x borderleft add borderright add 0 rlineto
+ 0 maxh borderbottom add bordertop add rlineto
+ x borderleft add borderright add neg 0 rlineto
+ 0 maxh borderbottom add bordertop add neg rlineto
+ closepath
+ backgroundcolor (unset) ne {
+ gsave
+ (< >) dup 1 backgroundcolor putinterval cvx exec {255 div} forall setrgbcolor
+ fill
+ grestore
+ } if
+ showborder {
+ gsave
+ bordercolor (unset) ne {
+ (< >) dup 1 bordercolor putinterval cvx exec {255 div} forall setrgbcolor
+ } if
+ borderwidth setlinewidth stroke
+ grestore
+ } if
+
+ % Display the bars for elements in the bars array
+ gsave
+ barcolor (unset) ne {
+ (< >) dup 1 barcolor putinterval cvx exec {255 div} forall setrgbcolor
+ } if
+ bars {
+ {} forall
+ newpath setlinewidth moveto 0 exch rlineto stroke
+ } forall
+ grestore
+
+ % Display the text for elements in the text array
+ textcolor (unset) ne {
+ (< >) dup 1 textcolor putinterval cvx exec {255 div} forall setrgbcolor
+ } if
+ /s 0 def /f () def
+ txt {
+ {} forall
+ 2 copy s ne exch f ne or {
+ 2 copy /s exch def /f exch def
+ exch findfont exch scalefont setfont
+ } {
+ pop pop
+ } ifelse
+ moveto show
+ } forall
+
+ % Display the guard elements
+ guardwhitespace {
+ 0.75 setlinewidth
+ guardleftpos 0 ne {
+ newpath
+ guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
+ guardwidth neg guardheight -2 div rlineto
+ guardwidth guardheight -2 div rlineto
+ stroke
+ } if
+ guardrightpos 0 ne {
+ newpath
+ guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
+ guardwidth guardheight -2 div rlineto
+ guardwidth neg guardheight -2 div rlineto
+ stroke
+ } if
+ } if
+
+ grestore
+
+ end
+
+} bind def
+/barcode load 0 1 dict put
+% --END RENDERER--
+
+% --END TEMPLATE--
diff --git a/kbarcode/barcodecombo.cpp b/kbarcode/barcodecombo.cpp
new file mode 100644
index 0000000..1aadc7d
--- /dev/null
+++ b/kbarcode/barcodecombo.cpp
@@ -0,0 +1,341 @@
+/***************************************************************************
+ barcodecombo.cpp - description
+ -------------------
+ begin : Son Apr 13 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "barcodecombo.h"
+#include "barcodedialogs.h"
+#include "barkode.h"
+#include "tokendialog.h"
+
+#include <pcre.h>
+
+// Qt includes
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qregexp.h>
+#include <qstring.h>
+#if QT_VERSION >= 0x030100
+ #include <ktextedit.h>
+#else
+ #include <qtextedit.h>
+#endif
+
+// KDE includes
+#include <kiconloader.h>
+#include <knuminput.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kpushbutton.h>
+
+BarcodeValidator::BarcodeValidator( QObject* parent, const char* name )
+ : QValidator( parent, name )
+{
+ m_valid = NULL;
+ m_notValid = NULL;
+}
+
+bool BarcodeValidator::pcreValidate( QString* pattern, const QString & input ) const
+{
+ const char* error;
+ const int ovector_size = 12;
+ int erroffset;
+ pcre* compiled;
+ int ovector[ovector_size];
+ int result;
+
+ if( !pattern || input.isEmpty() )
+ return true;
+
+ if( pattern->isEmpty() )
+ return true;
+
+ compiled = pcre_compile( pattern->latin1(), 0, &error, &erroffset, NULL );
+ if( !compiled ) // ignore all errors
+ return true;
+
+ result = pcre_exec( compiled, NULL, input.latin1(), input.length(), 0, 0, ovector, ovector_size );
+
+ return (result >= 1);
+}
+
+QValidator::State BarcodeValidator::validate( QString & input, int & pos ) const
+{
+ if( (!m_valid && !m_notValid) || input.isEmpty() )
+ return Acceptable;
+
+ if( (m_valid && m_valid->isEmpty()) && (m_notValid && m_notValid->isEmpty()) )
+ return Acceptable;
+
+ if( pcreValidate( m_valid, input ) && !pcreValidate( m_notValid, input ) )
+ return Acceptable;
+ else
+ return Intermediate;
+
+ return Acceptable;
+}
+
+BarcodeCombo::BarcodeCombo(QWidget *parent, const char *name )
+ : KComboBox( false, parent, name )
+
+{
+ this->insertStringList( *Barkode::encodingTypes() );
+}
+
+BarcodeCombo::~BarcodeCombo()
+{
+}
+
+const char* BarcodeCombo::getEncodingType()
+{
+ return Barkode::typeFromName( currentText() );
+}
+
+void BarcodeCombo::setEncodingType( const QString & type )
+{
+ const QString name = Barkode::nameFromType( type );
+ for( unsigned int z = 0; z < (unsigned int)count(); z++ )
+ if( text( z ) == name )
+ {
+ setCurrentItem( z );
+ break;
+ }
+}
+
+BarcodeWidget::BarcodeWidget(QWidget *parent, const char *name )
+ : QWidget( parent, name ), m_validator( this )
+{
+ m_token = NULL;
+
+ QGridLayout* grid = new QGridLayout( this, 6, 6 );
+
+ labelStandard = new QLabel( i18n( "&Encoding Type:" ), this );
+ grid->addWidget( labelStandard, 1, 0 );
+
+ comboStandard = new BarcodeCombo( this, "comboStandard" );
+ connect( comboStandard, SIGNAL( activated(int) ), this, SLOT( encodingChanged() ) );
+ connect( comboStandard, SIGNAL( activated(int) ), this, SLOT( changed() ) );
+ grid->addMultiCellWidget( comboStandard, 1, 1, 1, 3 );
+ labelStandard->setBuddy( comboStandard );
+
+ labelData = new QLabel( i18n( "&Value:" ), this );
+ grid->addWidget( labelData, 2, 0 );
+
+ data = new KLineEdit( this, "data" );
+
+ labelData->setBuddy( data );
+ connect( data, SIGNAL( textChanged( const QString & ) ), this, SLOT( changed() ) );
+ connect( data, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotValidateValue() ) );
+ grid->addMultiCellWidget( data, 2, 2, 1, 3 );
+
+#if QT_VERSION >= 0x030100
+ multi = new KTextEdit( this );
+#else
+ multi = new QTextEdit( this );
+#endif
+ multi->setTextFormat( QTextEdit::PlainText );
+ multi->setWordWrap( QTextEdit::NoWrap );
+ multi->setEnabled( false );
+ multi->setVScrollBarMode( QScrollView::AlwaysOn );
+ multi->setHScrollBarMode( QScrollView::AlwaysOn );
+ multi->hide();
+ connect( multi, SIGNAL( textChanged() ), this, SLOT( changed() ) );
+ grid->addMultiCellWidget( multi, 3, 3, 1, 3 );
+
+ checkText = new QCheckBox( this, "checkText" );
+ checkText->setText( i18n( "&Display text" ) );
+ checkText->setChecked( true );
+ connect( checkText, SIGNAL( clicked() ), this, SLOT( changed() ) );
+ grid->addWidget( checkText, 4, 1 );
+
+ buttonAdvanced = new KPushButton( i18n("&Advanced..."), this );
+// buttonAdvanced->setEnabled( false );
+ grid->addWidget( buttonAdvanced, 4, 2 );
+
+ buttonToken = new KPushButton( i18n("&Insert Data Field..."), this );
+ buttonToken->setIconSet( QIconSet( SmallIcon("contents") ) );
+ grid->addWidget( buttonToken, 4, 3 );
+
+ spinMargin = new KIntNumInput( this, "spinMargin" );
+ spinMargin->setLabel( i18n( "&Margin:" ), KNumInput::AlignLeft | KNumInput::AlignVCenter );
+ spinMargin->setRange( 0, 10000, 1, false );
+ spinMargin->setValue( 10 );
+ connect( spinMargin, SIGNAL( valueChanged(int) ), this, SLOT( changed() ) );
+ grid->addMultiCellWidget( spinMargin, 5, 5, 0, 1 );
+
+ spinRotation = new KIntNumInput( this );
+ spinRotation->setLabel( i18n( "&Rotation:" ), KNumInput::AlignLeft | KNumInput::AlignVCenter );
+ spinRotation->setRange( 0, 360, 90, false );
+ spinRotation->setValue( 0 );
+ connect( spinRotation, SIGNAL( valueChanged(int) ), this, SLOT( changed() ) );
+ grid->addMultiCellWidget( spinRotation, 5, 5, 2, 3 );
+
+ spinScale = new KIntNumInput( spinMargin, 1000, this );
+ spinScale->setLabel( i18n("&Scale (in permille):"), KNumInput::AlignLeft | KNumInput::AlignVCenter );
+ spinScale->setRange( 100, 10000, 100, false );
+ spinScale->setValue( 1000 );
+ connect( spinScale, SIGNAL( valueChanged(int) ), this, SLOT( changed() ) );
+ grid->addMultiCellWidget( spinScale, 6, 6, 0, 1 );
+
+ spinCut = new KIntNumInput( spinRotation, 100, this );
+ spinCut->setLabel( i18n("&Crop:"), KNumInput::AlignLeft | KNumInput::AlignVCenter );
+ spinCut->setRange( 1, 100, 1, false );
+ connect( spinCut, SIGNAL( valueChanged(int) ), this, SLOT( changed() ) );
+ grid->addMultiCellWidget( spinCut, 6, 6, 2, 3 );
+
+ connect( buttonAdvanced, SIGNAL( clicked() ), this, SLOT( advanced() ) );
+ connect( buttonToken, SIGNAL( clicked() ), this, SLOT( tokens() ) );
+
+ m_enabledata = true;
+ m_multi = false;
+ encodingChanged();
+}
+
+void BarcodeWidget::getData( Barkode & barcode )
+{
+ // make sure all changes are applied to the barcode
+ // even if not all widgets have emitted their changed SIGNAL yet
+ this->changed();
+
+ barcode = m_barcode;
+}
+
+void BarcodeWidget::setData( const Barkode & b )
+{
+ comboStandard->setEncodingType( b.type() );
+ encodingChanged();
+ if( !m_multi )
+ data->setText( b.value() );
+ else
+ multi->setText( b.value() );
+
+ checkText->setChecked( b.textVisible() );
+
+ spinMargin->setValue( b.quietZone() );
+ spinRotation->setValue( b.rotation() );
+ spinCut->setValue( int(b.cut()*100) );
+ spinScale->setValue( int(b.scaling()*1000) );
+
+ m_barcode = b;
+}
+
+void BarcodeWidget::setStandardEnabled( bool b )
+{
+ labelStandard->setEnabled( b );
+ comboStandard->setEnabled( b );
+}
+
+void BarcodeWidget::setDataEnabled( bool b )
+{
+ labelData->setEnabled( b );
+ m_enabledata = b;
+ encodingChanged();
+}
+
+void BarcodeWidget::defaults()
+{
+ Barkode b; // get's automatically initialized with default values
+ setData( b );
+}
+
+void BarcodeWidget::encodingChanged()
+{
+ QString* validator;
+ QString* validatorNot;
+
+ spinCut->setEnabled( Barkode::hasFeature( comboStandard->getEncodingType(), NOCUT ) ? false : true );
+ if( !spinCut->isEnabled() )
+ spinCut->setValue( 100 ); // TODO: Don't hardcode
+
+ spinScale->setEnabled( Barkode::hasFeature( comboStandard->getEncodingType(), NOSCALE ) ? false : true );
+ if( !spinScale->isEnabled() )
+ spinScale->setValue( 1000 ); // TODO: Don't hardcode
+
+ checkText->setEnabled( Barkode::hasFeature( comboStandard->getEncodingType(), NOTEXT ) ? false : true );
+
+ if( Barkode::hasFeature( comboStandard->getEncodingType(), MULTILINE ) ) {
+ buttonToken->setEnabled( m_enabledata );
+ multi->setEnabled( m_enabledata );
+ multi->show();
+ multi->setFocus();
+ data->setEnabled( false );
+ m_multi = true;
+ } else {
+ buttonToken->setEnabled( m_enabledata );
+ data->setEnabled( m_enabledata );
+ multi->hide();
+ data->setFocus();
+ multi->setEnabled( false );
+ m_multi = false;
+ }
+
+ validator = Barkode::validatorFromType( comboStandard->getEncodingType() );
+ validatorNot = Barkode::validatorNotFromType( comboStandard->getEncodingType() );
+ if( validator || validatorNot )
+ {
+ m_validator.setRegExp( validator, validatorNot );
+ data->setValidator( &m_validator );
+ }
+ else
+ data->setValidator( NULL );
+
+ slotValidateValue();
+}
+
+void BarcodeWidget::advanced()
+{
+ AdvancedBarcodeDialog abd( comboStandard->getEncodingType(), this, "abd" );
+ abd.setData( &m_barcode );
+ if( abd.exec() == QDialog::Accepted )
+ abd.getData( &m_barcode );
+}
+
+void BarcodeWidget::tokens()
+{
+ TokenDialog tokendlg( m_token, this, "tokendlg" );
+ if( tokendlg.exec() == QDialog::Accepted )
+ {
+ if( data->isEnabled() )
+ data->insert( tokendlg.token() );
+ else
+ multi->insert( tokendlg.token() );
+ }
+}
+
+void BarcodeWidget::slotValidateValue()
+{
+ QColor c = data->hasAcceptableInput() ? this->foregroundColor() : Qt::red;
+
+ data->setPaletteForegroundColor( c );
+}
+
+void BarcodeWidget::changed()
+{
+ if( !m_multi )
+ m_barcode.setValue( data->text() );
+ else
+ m_barcode.setValue( multi->text() );
+
+ m_barcode.setType( comboStandard->getEncodingType() );
+ m_barcode.setTextVisible( checkText->isChecked() );
+
+ m_barcode.setQuietZone( spinMargin->value() );
+ m_barcode.setRotation( spinRotation->value() );
+ m_barcode.setCut( (double)spinCut->value()/100.0 );
+ m_barcode.setScaling( (double)spinScale->value()/1000.0 );
+}
+
+#include "barcodecombo.moc"
diff --git a/kbarcode/barcodecombo.h b/kbarcode/barcodecombo.h
new file mode 100644
index 0000000..48e1cde
--- /dev/null
+++ b/kbarcode/barcodecombo.h
@@ -0,0 +1,144 @@
+/***************************************************************************
+ barcodecombo.h - description
+ -------------------
+ begin : Son Apr 13 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef BARCODECOMBO_H
+#define BARCODECOMBO_H
+
+#include <qvalidator.h>
+#include <qwidget.h>
+#include <kcombobox.h>
+
+#include "barkode.h"
+
+/** A validator that takes to QRegExp's to check
+ * wether a barcode is valid or not.
+ */
+class BarcodeValidator : public QValidator {
+ public:
+ BarcodeValidator( QObject* parent = 0, const char* name = 0 );
+
+ QValidator::State validate( QString & input, int & pos ) const;
+
+ /** validate a given input string agains a pattern using
+ * Perl Compatible Regular Expressions
+ * \param pattern may be NULL
+ * \returns true if the pattern matches
+ */
+ bool pcreValidate( QString* pattern, const QString & input ) const;
+
+ inline void setRegExp( QString* valid, QString* notValid ) {
+ m_valid = valid;
+ m_notValid = notValid;
+ }
+
+ private:
+ QString* m_valid;
+ QString* m_notValid;
+};
+
+/** A combobox that lists all barcode encodign types
+ * supported by KBarcode.
+ */
+class BarcodeCombo : public KComboBox {
+ Q_OBJECT
+ public:
+ BarcodeCombo(QWidget *parent=0, const char *name=0);
+ ~BarcodeCombo();
+
+ const char* getEncodingType();
+ void setEncodingType( const QString & type );
+};
+
+class KIntNumInput;
+class KLineEdit;
+class KPushButton;
+#if QT_VERSION >= 0x030100
+ class KTextEdit;
+#else
+ class QTextEdit;
+#endif
+class QCheckBox;
+class QLabel;
+
+/** This widget is used in BarCodeDialog and BarcodeSettingsDlg and
+ * allows the user to change the data of a barcodeData struct. This powerful
+ * widget is always used when the user has to change some property of
+ * a barcode.
+ *
+ * @see BarCodeDialog, @see BarcodeSettingsDlg
+ * @author Dominik Seichter
+ */
+class BarcodeWidget : public QWidget {
+ Q_OBJECT
+ public:
+ BarcodeWidget(QWidget *parent=0, const char *name=0);
+ ~BarcodeWidget() { }
+
+ void getData( Barkode & barkode );
+ void setData( const Barkode & b );
+
+ void setStandardEnabled( bool b );
+ void setDataEnabled( bool b );
+
+ void defaults();
+
+ inline void setTokenProvider( TokenProvider* token );
+
+ private slots:
+ void encodingChanged();
+ void advanced();
+ void changed();
+ void tokens();
+ void slotValidateValue();
+
+ private:
+ TokenProvider* m_token;
+
+ BarcodeCombo* comboStandard;
+ KLineEdit* data;
+ BarcodeValidator m_validator;
+
+#if QT_VERSION >= 0x030100
+ KTextEdit* multi;
+#else
+ QTextEdit* multi;
+#endif
+
+ KIntNumInput* spinMargin;
+ KIntNumInput* spinScale;
+ KIntNumInput* spinRotation;
+ KIntNumInput* spinCut;
+ QCheckBox* checkText;
+
+ KPushButton* buttonAdvanced;
+ KPushButton* buttonToken;
+
+ QLabel* labelStandard;
+ QLabel* labelData;
+
+ bool m_enabledata;
+ bool m_multi;
+
+ Barkode m_barcode;
+};
+
+void BarcodeWidget::setTokenProvider( TokenProvider* token )
+{
+ m_token = token;
+}
+
+#endif
diff --git a/kbarcode/barcodedialog.cpp b/kbarcode/barcodedialog.cpp
new file mode 100644
index 0000000..ce6f64d
--- /dev/null
+++ b/kbarcode/barcodedialog.cpp
@@ -0,0 +1,218 @@
+/***************************************************************************
+ barcodedialog.cpp - description
+ -------------------
+ begin : Son Dez 29 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "barcodedialog.h"
+#include "barcodeitem.h"
+#include "printersettings.h"
+#include "barcodecombo.h"
+#include "mimesources.h"
+#include "tokenprovider.h"
+
+// KDE includes
+#include <kapplication.h>
+#include <kfiledialog.h>
+#include <kiconloader.h>
+#include <kimageio.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kprinter.h>
+#include <kpushbutton.h>
+
+// Qt includes
+#include <qclipboard.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpainter.h>
+#include <qpaintdevicemetrics.h>
+#include <qpicture.h>
+
+BarCodeDialog::BarCodeDialog( QWidget* parent, const char* name )
+ : QDialog( parent, name, false)
+{
+ setCaption( i18n( "Barcode Generator" ) );
+
+ BarCodeDialogLayout = new QHBoxLayout( this, 11, 6, "BarCodeDialogLayout");
+ Layout5 = new QVBoxLayout( 0, 0, 6, "Layout5");
+ Layout6 = new QVBoxLayout( 0, 0, 6, "Layout2");
+ widget = new BarcodeWidget( this, "widget" );
+
+ m_token = new TokenProvider( KApplication::desktop() );
+ widget->setTokenProvider( m_token );
+
+ buttonGenerate = new KPushButton( this, "buttonGenerate" );
+ buttonGenerate->setText( i18n( "&Generate" ) );
+ buttonGenerate->setEnabled( Barkode::haveBarcode() );
+ buttonGenerate->setIconSet( SmallIconSet("barcode") );
+
+ buttonSave = new KPushButton( this, "buttonSave" );
+ buttonSave->setText( i18n( "&Save" ) );
+ buttonSave->setEnabled( false );
+ buttonSave->setIconSet( SmallIconSet("filesave") );
+
+ buttonCopy = new KPushButton( this, "buttonCopy" );
+ buttonCopy->setText( i18n("&Copy") );
+ buttonCopy->setEnabled( false );
+ buttonCopy->setIconSet( SmallIconSet("editcopy") );
+
+ buttonPrint = new KPushButton( this );
+ buttonPrint->setText( i18n("&Print") );
+ buttonPrint->setEnabled( false );
+ buttonPrint->setIconSet( SmallIconSet("fileprint") );
+
+ buttonClose = new KPushButton( this );
+ buttonClose->setText( i18n("&Close" ) );
+ buttonClose->setIconSet( SmallIconSet("fileclose") );
+
+
+ QScrollView* sv = new QScrollView( this );
+
+ barcode = new QLabel( sv->viewport(), "barcode" );
+ sv->addChild( barcode );
+ connect( buttonGenerate, SIGNAL( clicked() ), this, SLOT( generate() ) );
+ connect( buttonSave, SIGNAL( clicked() ), this, SLOT( save() ) );
+ connect( buttonPrint, SIGNAL( clicked() ), this, SLOT( print() ) );
+ connect( buttonCopy, SIGNAL( clicked() ), this, SLOT( copy() ) );
+
+ QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding );
+
+ Layout5->addWidget( buttonGenerate );
+ Layout5->addWidget( buttonSave );
+ Layout5->addWidget( buttonPrint );
+ Layout5->addWidget( buttonCopy );
+ Layout5->addItem( spacer );
+ Layout5->addWidget( buttonClose );
+
+ Layout6->addWidget( widget );
+ Layout6->addWidget( sv );
+
+ BarCodeDialogLayout->addLayout( Layout6 );
+ BarCodeDialogLayout->addLayout( Layout5 );
+ BarCodeDialogLayout->setStretchFactor( Layout6, 2 );
+
+ connect( buttonClose, SIGNAL( clicked() ), this, SLOT( close() ) );
+
+ buttonGenerate->setDefault( true );
+
+ show();
+}
+
+BarCodeDialog::~BarCodeDialog()
+{
+ delete m_token;
+}
+
+void BarCodeDialog::generate()
+{
+ Barkode d;
+ widget->getData( d );
+ d.setTokenProvider( m_token );
+ d.update( KApplication::desktop() );
+
+ barcode->setPixmap( d.pixmap() );
+
+ buttonSave->setEnabled( !barcode->pixmap()->isNull() );
+ buttonPrint->setEnabled( !barcode->pixmap()->isNull() );
+ buttonCopy->setEnabled( !barcode->pixmap()->isNull() );
+}
+
+void BarCodeDialog::save()
+{
+ Barkode bc;
+ widget->getData( bc );
+
+ if(!bc.isValid())
+ {
+ KFileDialog fd( ":save_image", KImageIO::pattern( KImageIO::Writing ), this, "fd", true );
+ fd.setMode( KFile::File );
+ fd.setOperationMode( KFileDialog::Saving );
+ if( fd.exec() == QDialog::Accepted )
+ {
+ QString path = fd.selectedURL().path();
+ QString extension = KImageIO::type( path );
+
+ if( extension.isNull() )
+ extension = KImageIO::type( fd.currentFilter() );
+
+
+ bc.setTokenProvider( m_token );
+ bc.update( KApplication::desktop() );
+
+ if(!bc.pixmap().save( path, extension, 0 ))
+ KMessageBox::error( this, i18n("An error occurred during saving the image") );
+ }
+ }
+}
+
+void BarCodeDialog::print()
+{
+ Barkode d;
+ widget->getData( d );
+
+ if( d.isValid() )
+ return;
+
+ KPrinter* printer = PrinterSettings::getInstance()->setupPrinter( "kbarcode", this );
+ if( !printer )
+ return;
+
+ // unless we can center the barcode
+ printer->setFullPage( false );
+
+ QPaintDeviceMetrics metrics( printer );
+
+ double scalex = (double)metrics.logicalDpiX() / (double)QPaintDevice::x11AppDpiX();
+ double scaley = (double)metrics.logicalDpiY() / (double)QPaintDevice::x11AppDpiY();
+
+ QPicture picture;
+ QPainter p( printer );
+ p.scale( scalex, scaley );
+ // TODO: center barcode
+
+ TokenProvider tp( printer );
+
+ d.setTokenProvider( &tp );
+ d.update( printer );
+
+ picture = d.picture();
+ p.drawPicture( QPoint( 0, 0 ), picture );
+ p.end();
+
+ delete printer;
+}
+
+void BarCodeDialog::copy()
+{
+ if( barcode->pixmap()->isNull() )
+ return;
+
+ Barkode bc;
+ widget->getData( bc );
+
+ BarcodeItem* item = new BarcodeItem( bc );
+ DocumentItemList list;
+ list.append( item );
+ DocumentItemDrag* drag = new DocumentItemDrag();
+ drag->setDocumentItem( &list );
+
+#if QT_VERSION >= 0x030100
+ kapp->clipboard()->setData( drag, QClipboard::Clipboard );
+#else
+ kapp->clipboard()->setData( drag );
+#endif
+}
+
+#include "barcodedialog.moc"
diff --git a/kbarcode/barcodedialog.h b/kbarcode/barcodedialog.h
new file mode 100644
index 0000000..9490467
--- /dev/null
+++ b/kbarcode/barcodedialog.h
@@ -0,0 +1,79 @@
+/***************************************************************************
+ barcodedialog.h - description
+ -------------------
+ begin : Son Dez 29 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef BARCODEDIALOG_H
+#define BARCODEDIALOG_H
+
+#include <qdialog.h>
+
+class BarcodeCombo;
+class BarcodeWidget;
+class KAction;
+class KColorButton;
+class KMenuBar;
+class KToolBar;
+class KIntNumInput;
+class KLineEdit;
+class KPushButton;
+class KPopupMenu;
+class QCheckBox;
+class QLabel;
+class QPixmap;
+class QVBoxLayout;
+class QHBoxLayout;
+class QGridLayout;
+class TokenProvider;
+
+/** This class provides a dialog, where the user can create a single barcode
+ * and print it, copy it to the clipboard or save it in various image formats.
+ * This dialog can also be seen as a powerful replacement for e.g. xbarcode.
+ *
+ * All barcoding features are available for the user. This dialog allows also
+ * to just experiment a little bit with barcodes.
+ */
+class BarCodeDialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ BarCodeDialog( QWidget* parent = 0, const char* name = 0 );
+ ~BarCodeDialog();
+
+ private:
+ BarcodeWidget* widget;
+ TokenProvider* m_token;
+
+ KPushButton* buttonGenerate;
+ KPushButton* buttonPrint;
+ KPushButton* buttonSave;
+ KPushButton* buttonCopy;
+ KPushButton* buttonClose;
+ QLabel* barcode;
+
+ private slots:
+ void generate();
+ void save();
+ void print();
+ void copy();
+
+ protected:
+ QHBoxLayout* BarCodeDialogLayout;
+ QVBoxLayout* Layout6;
+ QVBoxLayout* Layout5;
+};
+
+#endif // BARCODEDIALOG_H
diff --git a/kbarcode/barcodedialogs.cpp b/kbarcode/barcodedialogs.cpp
new file mode 100644
index 0000000..28639a4
--- /dev/null
+++ b/kbarcode/barcodedialogs.cpp
@@ -0,0 +1,506 @@
+/***************************************************************************
+ barcodedialogs.cpp - description
+ -------------------
+ begin : Fre Sep 5 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "barcodedialogs.h"
+#include "barkode.h"
+#include "purepostscript.h"
+#include "tbarcode2.h"
+
+// Qt includes
+#include <qbuttongroup.h>
+#include <qcheckbox.h>
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qmap.h>
+#include <qradiobutton.h>
+#include <qtooltip.h>
+#include <qvbox.h>
+#include <qvgroupbox.h>
+
+// KDE includes
+#include <kcombobox.h>
+#include <knuminput.h>
+#include <klocale.h>
+#include <kcolorbutton.h>
+
+
+AdvancedBarcodeDialog::AdvancedBarcodeDialog( QString type, QWidget* parent, const char* name )
+ : KDialogBase( KDialogBase::Tabbed, i18n("Barcode Settings"),
+ KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, parent,name)
+{
+ list.setAutoDelete( false );
+
+ if( Barkode::hasFeature( type, PDF417BARCODE ) ) {
+ QVBox* box = addVBoxPage( i18n("PDF417") );
+ PDF417BarcodeDlg* dlg = new PDF417BarcodeDlg( box );
+ list.append( (BarcodeDlgBase*)dlg );
+ }
+
+ if( Barkode::hasFeature( type, DATAMATRIX ) ) {
+ QVBox* box = addVBoxPage( i18n("DataMatrix") );
+ DataMatrixDlg* dlg = new DataMatrixDlg( box );
+ list.append( (BarcodeDlgBase*)dlg );
+ }
+
+ if( Barkode::hasFeature( type, TBARCODEADV ) ) {
+ QVBox* box = addVBoxPage( i18n("TBarcode") );
+ TBarcodeDlg* dlg = new TBarcodeDlg( box );
+ list.append( (BarcodeDlgBase*)dlg );
+ }
+
+ if( Barkode::hasFeature( type, PUREADV ) ) {
+ QVBox* box = addVBoxPage( i18n("Barcode Writer in Pure Postscript") );
+ PurePostscriptDlg* dlg = new PurePostscriptDlg( box );
+ list.append( (BarcodeDlgBase*)dlg );
+ }
+
+ if( Barkode::hasFeature( type, COLORED ) ) {
+ QVBox* box = addVBoxPage( i18n("Colors") );
+ ColorDlg* dlg = new ColorDlg( box );
+ list.append( (BarcodeDlgBase*)dlg );
+ }
+
+ QVBox* box = addVBoxPage( i18n("Sequence") );
+ SequenceDlg* dlg = new SequenceDlg( box );
+ list.append( (BarcodeDlgBase*)dlg );
+}
+
+AdvancedBarcodeDialog::~AdvancedBarcodeDialog()
+{
+}
+
+void AdvancedBarcodeDialog::setData( Barkode* b )
+{
+ for( unsigned int i = 0; i < list.count(); i++ ) {
+ BarcodeDlgBase* bdb = list.at( i );
+ bdb->setData( b );
+ }
+}
+
+void AdvancedBarcodeDialog::getData( Barkode* b )
+{
+ for( unsigned int i = 0; i < list.count(); i++ ) {
+ BarcodeDlgBase* bdb = list.at( i );
+ bdb->getData( b );
+ }
+}
+
+TBarcodeDlg::TBarcodeDlg(QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QVBoxLayout* layout = new QVBoxLayout( this, 6, 6 );
+
+ QGroupBox* gb = new QGroupBox( i18n("TBarcode"), this );
+ gb->setColumnLayout(0, Qt::Vertical );
+ gb->layout()->setSpacing( 6 );
+ gb->layout()->setMargin( 11 );
+ gb->setEnabled( Barkode::haveTBarcode() || Barkode::haveTBarcode2() );
+ QVBoxLayout* gbLayout = new QVBoxLayout( gb->layout() );
+
+ spinModule = new KDoubleNumInput( gb );
+ spinModule->setLabel( i18n("Module width (mm):"), AlignLeft | AlignVCenter );
+ spinModule->setRange( 0.190, 1.500, 0.001, true );
+
+ spinHeight = new KIntNumInput( gb );
+ spinHeight->setLabel( i18n("Barcode Height (mm):"), AlignLeft | AlignVCenter );
+ spinHeight->setRange( 1, 1000, 10, false );
+
+ checkEscape = new QCheckBox( i18n("&Translate escape sequences"), gb );
+ checkAbove = new QCheckBox( i18n("&Text above barcode"), gb );
+ checkAutoCorrect = new QCheckBox( i18n("&Auto correction"), gb );
+
+ comboCheckSum = new KComboBox( false, gb );
+
+ QLabel* label = new QLabel( i18n("&Checksum calculation method:"), gb );
+ label->setBuddy( comboCheckSum );
+
+ QHBoxLayout * hbox = new QHBoxLayout( 0, 6, 6 );
+ hbox->addWidget( label );
+ hbox->addWidget( comboCheckSum );
+
+ gbLayout->addWidget( spinModule );
+ gbLayout->addWidget( spinHeight );
+ gbLayout->addWidget( checkEscape );
+ gbLayout->addWidget( checkAbove );
+ gbLayout->addWidget( checkAutoCorrect );
+ gbLayout->addLayout( hbox );
+
+ QToolTip::add( spinModule, i18n("<qt>Change the module with used by tbarcode. Take a look into the "
+ "tbarcode documentation for details. Normaly you do not want to change "
+ "this value.</qt>") );
+
+ layout->addWidget( gb );
+}
+
+void TBarcodeDlg::setData( Barkode* b )
+{
+ TBarcodeOptions* options = dynamic_cast<TBarcodeOptions*>( b->engine()->options() );
+
+ if( options )
+ {
+ spinModule->setValue( options->moduleWidth() );
+ spinHeight->setValue( options->height() );
+ checkEscape->setChecked( options->escape() );
+ checkAbove->setChecked( options->above() );
+ checkAutoCorrect->setChecked( options->autocorrect() );
+
+ map.insert( i18n("No Checksum"), 0 );
+ map.insert( i18n("Default Checksum Method"), 1 );
+
+ if( Barkode::hasFeature( b->type(), MODULOALLCHECK ) ||
+ Barkode::hasFeature( b->type(), MODULO10CHECK ) )
+ map.insert( i18n("Modulo 10 Checksum"), 2 );
+
+ if( Barkode::hasFeature( b->type(), MODULOALLCHECK ) ||
+ b->type() == "b13" || // EAN 13
+ b->type() == "b14" || // EAN 13
+ b->type() == "b15" || // EAN 13
+ b->type() == "b18" ) // CodaBar (2 width)
+ map.insert( i18n("Module 43 (suggested for Code39 and Logmars, 1 digit)"), 3 );
+
+ if( Barkode::hasFeature( b->type(), MODULOALLCHECK ) )
+ map.insert( i18n("Modula 47 (2 digits)"), 4 );
+
+ if( b->type() == "b21" ) // Deutsche Post Leitcode
+ map.insert( i18n("Deutsche Post Leitcode"), 5 );
+
+ if( b->type() == "b22") // Deutsche Post Identcode
+ map.insert( i18n("Deutsche Post Identcode"), 6 );
+
+ if( b->type() == "b1" ) { // Code11
+ map.insert( i18n("Code 11 (1 digit)"), 7 );
+ map.insert( i18n("Code 11 (2 digits)"), 8 );
+ }
+
+ if( Barkode::hasFeature( b->type(), POSTNETCHECK ) )
+ map.insert( i18n("USPS Postnet"), 9 );
+
+ if( b->type() == "b47" ) { // MSI
+ map.insert( i18n("MSI (1 digit)"), 10 );
+ map.insert( i18n("MSI (2 digits)"), 11 );
+ }
+
+ if( b->type() == "b46" ) // Plessey
+ map.insert( i18n("Plessey"), 12 );
+
+ if( Barkode::hasFeature( b->type(), EAN8CHECK ) )
+ map.insert( i18n("EAN 8"), 13 );
+
+ if( Barkode::hasFeature( b->type(), EAN13CHECK ) )
+ map.insert( i18n("EAN 13"), 14 );
+
+ if( Barkode::hasFeature( b->type(), UPCACHECK ) )
+ map.insert( i18n("UPC A"), 15 );
+
+ if( Barkode::hasFeature( b->type(), UPCECHECK ) )
+ map.insert( i18n("UPC E"), 16 );
+
+ if( b->type() == "b16" ) // EAN 128
+ map.insert( i18n("EAN 128"), 17 );
+
+ if( Barkode::hasFeature( b->type(), CODE128CHECK ) )
+ map.insert( i18n("Code 128"), 18 );
+
+ if( b->type() == "b70" ) // Royal Mail 4 State
+ map.insert( i18n("Royal Mail 4 State"), 19 );
+
+ comboCheckSum->insertStringList( map.keys() );
+
+ QMap<QString,int>::Iterator it;
+ for ( it = map.begin(); it != map.end(); ++it ) {
+ if( it.data() == options->checksum() ) {
+ for( int i = 0; i < comboCheckSum->count(); i++ )
+ if( comboCheckSum->text( i ) == it.key() ) {
+ comboCheckSum->setCurrentItem( i );
+ break;
+ }
+ break;
+ }
+ }
+ }
+}
+
+void TBarcodeDlg::getData( Barkode* b ) const
+{
+ TBarcodeOptions* options = dynamic_cast<TBarcodeOptions*>( b->engine()->options() );
+
+ if( options )
+ {
+ options->setModuleWidth( spinModule->value() );
+ options->setEscape( checkEscape->isChecked() );
+ options->setAbove( checkAbove->isChecked() );
+ options->setAutocorrect( checkAutoCorrect->isChecked() );
+ options->setCheckSum( map[comboCheckSum->currentText()] );
+ options->setHeight( spinHeight->value() );
+ }
+}
+
+PDF417BarcodeDlg::PDF417BarcodeDlg(QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QVBoxLayout* layout = new QVBoxLayout( this, 6, 6 );
+
+ QGroupBox* gpdf = new QGroupBox( i18n("PDF417"), this );
+ gpdf->setColumnLayout(0, Qt::Vertical );
+ gpdf->layout()->setSpacing( 6 );
+ gpdf->layout()->setMargin( 11 );
+ gpdf->setEnabled( Barkode::haveTBarcode() || Barkode::havePDFBarcode() );
+ QVBoxLayout* gpdfLayout = new QVBoxLayout( gpdf->layout() );
+
+ spinRow = new KIntNumInput( gpdf );
+ spinRow->setLabel( i18n("Rows:"), AlignLeft | AlignVCenter );
+ spinRow->setRange( 0, 90, 1, true );
+
+ spinCol = new KIntNumInput( spinRow, 0, gpdf );
+ spinCol->setLabel( i18n("Columns:"), AlignLeft | AlignVCenter );
+ spinCol->setRange( 0, 30, 1, true );
+
+ spinErr = new KIntNumInput( spinCol, 0, gpdf );
+ spinErr->setLabel( i18n("Error correction level:"), AlignLeft | AlignVCenter );
+ spinErr->setRange( 1, 8, 1, true );
+
+ gpdfLayout->addWidget( spinRow );
+ gpdfLayout->addWidget( spinCol );
+ gpdfLayout->addWidget( spinErr );
+ layout->addWidget( gpdf );
+}
+
+void PDF417BarcodeDlg::setData( Barkode* b )
+{
+ PDF417Options* options = dynamic_cast<PDF417Options*>( b->engine()->options() );
+
+ if( options )
+ {
+ spinRow->setValue( options->row() );
+ spinCol->setValue( options->col() );
+ spinErr->setValue( options->err() );
+ }
+}
+
+void PDF417BarcodeDlg::getData( Barkode* b ) const
+{
+ PDF417Options* options = dynamic_cast<PDF417Options*>( b->engine()->options() );
+
+ if( options )
+ {
+ options->setRow( spinRow->value() );
+ options->setCol( spinCol->value() );
+ options->setErr( spinErr->value() );
+ }
+}
+
+DataMatrixDlg::DataMatrixDlg(QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QHBoxLayout* datamLayout = new QHBoxLayout( this, 6, 6 );
+
+ comboDataMatrix = new KComboBox( false, this );
+
+ datamLayout->addWidget( new QLabel( i18n("Data Matrix symbol sizes (rows x cols):"), this ) );
+ datamLayout->addWidget( comboDataMatrix );
+ datamLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Minimum ) );
+
+ comboDataMatrix->insertItem( i18n("Automatic calculation" ) );
+ comboDataMatrix->insertItem( "10 x 10" );
+ comboDataMatrix->insertItem( "12 x 12" );
+ comboDataMatrix->insertItem( "14 x 14" );
+ comboDataMatrix->insertItem( "16 x 16" );
+ comboDataMatrix->insertItem( "18 x 18" );
+ comboDataMatrix->insertItem( "20 x 20" );
+ comboDataMatrix->insertItem( "22 x 22" );
+ comboDataMatrix->insertItem( "24 x 24" );
+ comboDataMatrix->insertItem( "26 x 26" );
+ comboDataMatrix->insertItem( "32 x 32" );
+ comboDataMatrix->insertItem( "36 x 36" );
+ comboDataMatrix->insertItem( "40 x 40" );
+ comboDataMatrix->insertItem( "44 x 44" );
+ comboDataMatrix->insertItem( "48 x 48" );
+ comboDataMatrix->insertItem( "52 x 52" );
+ comboDataMatrix->insertItem( "64 x 64" );
+ comboDataMatrix->insertItem( "72 x 72" );
+ comboDataMatrix->insertItem( "80 x 80" );
+ comboDataMatrix->insertItem( "88 x 88" );
+ comboDataMatrix->insertItem( "96 x 96" );
+ comboDataMatrix->insertItem( "104 x 104" );
+ comboDataMatrix->insertItem( "120 x 120" );
+ comboDataMatrix->insertItem( "132 x 132" );
+ comboDataMatrix->insertItem( "144 x 144" );
+ comboDataMatrix->insertItem( "8 x 18" );
+ comboDataMatrix->insertItem( "8 x 32" );
+ comboDataMatrix->insertItem( "12 x 26" );
+ comboDataMatrix->insertItem( "12 x 36" );
+ comboDataMatrix->insertItem( "16 x 36" );
+ comboDataMatrix->insertItem( "16 x 48" );
+}
+
+void DataMatrixDlg::setData( Barkode* b )
+{
+ comboDataMatrix->setCurrentItem( b->datamatrixSize());
+}
+
+void DataMatrixDlg::getData( Barkode* b ) const
+{
+ b->setDatamatrixSize( comboDataMatrix->currentItem() );
+}
+
+SequenceDlg::SequenceDlg( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QVBoxLayout* main = new QVBoxLayout( this, 6, 6 );
+
+ QButtonGroup* group = new QButtonGroup( i18n("Sequence"), this );
+ group->setColumnLayout(0, Qt::Vertical );
+ group->layout()->setSpacing( 6 );
+ group->layout()->setMargin( 11 );
+ QVBoxLayout* layout = new QVBoxLayout( group->layout() );
+
+ checkSequence = new QCheckBox( i18n("&Enable sequence"), group );
+
+ radioNumbers = new QRadioButton( i18n("Iterate over numbers 0-9"), group );
+ radioAlpha = new QRadioButton( i18n("Iterate over characters A-Z"), group );
+ radioAlphaNum = new QRadioButton( i18n("Iterate over A-Z, 0-9"), group );
+
+ spinStep = new KIntNumInput( group );
+ spinStep->setLabel( i18n("Step:"), AlignLeft | AlignVCenter );
+ spinStep->setRange( -100, 100, 1, false );
+
+ spinStart = new KIntNumInput( spinStep, 1, group );
+ spinStart->setLabel( i18n("Start:"), AlignLeft | AlignVCenter );
+ spinStart->setRange( -100000, 100000, 1, false );
+
+ layout->addWidget( checkSequence );
+ layout->addWidget( radioNumbers );
+ layout->addWidget( radioAlpha );
+ layout->addWidget( radioAlphaNum );
+ layout->addWidget( spinStep );
+ layout->addWidget( spinStart );
+
+ main->addWidget( group );
+
+ connect( checkSequence, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioNumbers, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioAlpha, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioAlphaNum, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+}
+
+void SequenceDlg::setData( Barkode* b )
+{
+ checkSequence->setChecked( b->sequenceEnabled() );
+ spinStep->setValue( b->sequenceStep() );
+ spinStart->setValue( b->sequenceStart() );
+
+ if( b->sequenceMode() == NUM )
+ radioNumbers->setChecked( true );
+ else if( b->sequenceMode() == ALPHA )
+ radioAlpha->setChecked( true );
+ else if( b->sequenceMode() == ALPHANUM )
+ radioAlphaNum->setChecked( true );
+
+ enableControls();
+}
+
+void SequenceDlg::getData( Barkode* b ) const
+{
+ b->setSequenceEnabled( checkSequence->isChecked() );
+
+ b->setSequenceStep( spinStep->value() );
+ b->setSequenceStart( spinStart->value() );
+
+ if( radioNumbers->isChecked() )
+ b->setSequenceMode( NUM );
+ else if( radioAlpha->isChecked() )
+ b->setSequenceMode( ALPHA );
+ else if( radioAlphaNum->isChecked() )
+ b->setSequenceMode( ALPHANUM );
+}
+
+void SequenceDlg::enableControls()
+{
+ radioNumbers->setEnabled( checkSequence->isChecked() );
+ radioAlpha->setEnabled( checkSequence->isChecked() );
+ radioAlphaNum->setEnabled( false ); //checkSequence->isChecked() );
+ spinStep->setEnabled( checkSequence->isChecked() );
+ spinStart->setEnabled( checkSequence->isChecked() && radioNumbers->isChecked() );
+}
+
+ColorDlg::ColorDlg(QWidget *parent, const char *name)
+ : QVBox( parent, name )
+{
+ QGroupBox* gb = new QGroupBox( i18n("Colors"), this );
+ gb->setColumnLayout(0, Qt::Vertical );
+ gb->layout()->setSpacing( 6 );
+ gb->layout()->setMargin( 11 );
+ gb->setEnabled( Barkode::havePurePostscriptBarcode() );
+ QGridLayout* gbLayout = new QGridLayout( gb->layout() );
+
+ buttonBarColor = new KColorButton( gb );
+ buttonBackColor = new KColorButton( gb );
+ buttonTextColor = new KColorButton( gb );
+
+ gbLayout->addWidget( new QLabel( i18n("Bar Color:"), gb ), 0, 0 );
+ gbLayout->addWidget( new QLabel( i18n("Background Color:"), gb ), 1, 0 );
+ gbLayout->addWidget( new QLabel( i18n("Text Color:"), gb ), 2, 0 );
+ gbLayout->addWidget( buttonBarColor, 0, 1 );
+ gbLayout->addWidget( buttonBackColor, 1, 1 );
+ gbLayout->addWidget( buttonTextColor, 2, 1 );
+}
+
+void ColorDlg::setData( Barkode* b )
+{
+ buttonBarColor->setColor( b->foreground() );
+ buttonBackColor->setColor( b->background() );
+ buttonTextColor->setColor( b->textColor() );
+}
+
+void ColorDlg::getData( Barkode* b ) const
+{
+ b->setForeground( buttonBarColor->color() );
+ b->setBackground( buttonBackColor->color() );
+ b->setTextColor( buttonTextColor->color() );
+}
+
+PurePostscriptDlg::PurePostscriptDlg(QWidget *parent, const char *name)
+ : QVBox( parent, name )
+{
+ QVGroupBox* gb = new QVGroupBox( i18n("Barcode Writer in Pure Postscript"), this );
+ gb->setEnabled( Barkode::havePurePostscriptBarcode() );
+
+ checkChecksum = new QCheckBox( i18n("Enable &Checksum"), gb );
+}
+
+void PurePostscriptDlg::setData( Barkode* b )
+{
+ PurePostscriptOptions* options = dynamic_cast<PurePostscriptOptions*>( b->engine()->options() );
+
+ if( options )
+ {
+ checkChecksum->setChecked( options->checksum() );
+ checkChecksum->setEnabled( Barkode::hasFeature( b->type(), MODULOALLCHECK ) );
+ }
+}
+
+void PurePostscriptDlg::getData( Barkode* b ) const
+{
+ PurePostscriptOptions* options = dynamic_cast<PurePostscriptOptions*>( b->engine()->options() );
+
+ if( options )
+ options->setChecksum( checkChecksum->isChecked() );
+}
+
+
+#include "barcodedialogs.moc"
diff --git a/kbarcode/barcodedialogs.h b/kbarcode/barcodedialogs.h
new file mode 100644
index 0000000..56e3a58
--- /dev/null
+++ b/kbarcode/barcodedialogs.h
@@ -0,0 +1,180 @@
+/***************************************************************************
+ barcodedialogs.h - description
+ -------------------
+ begin : Fre Sep 5 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef BARCODEDIALOGS_H
+#define BARCODEDIALOGS_H
+
+#include <qmap.h>
+#include <qptrlist.h>
+#include <qwidget.h>
+#include <qvbox.h>
+#include <kdialogbase.h>
+
+class Barkode;
+class KColorButton;
+class KComboBox;
+class KDoubleNumInput;
+class KIntNumInput;
+class QCheckBox;
+class QRadioButton;
+
+/** A base class for all widgets, that will be used in AdvancedBarcodeDialog
+ * to modify the settings of a barcode. The API is simple. You can only set the
+ * current barcode settings and retrieve them after the user modified them.
+ *
+ * @author Dominik Seichter
+ */
+class BarcodeDlgBase {
+ public:
+ virtual void setData( Barkode* b ) = 0;
+ virtual void getData( Barkode* b ) const = 0;
+};
+
+/**
+ * A configuration dialog for advanced barcode settings.
+ * Used in BarcodeWidget. It loads the wigets below into tabs.
+ * @see TBarcodeDlg
+ * @see PDF417BarcodeDlg
+ * @see DataMatrixDlg
+ * @seeSequenceDlg
+ *
+ * @author Dominik Seichter
+ */
+class AdvancedBarcodeDialog : public KDialogBase {
+ Q_OBJECT
+ public:
+ AdvancedBarcodeDialog( QString type, QWidget* parent = 0, const char* name = 0 );
+ ~AdvancedBarcodeDialog();
+
+ void setData( Barkode* b );
+ void getData( Barkode* b );
+
+ private:
+ QPtrList<BarcodeDlgBase> list;
+};
+
+/** A configuration widget for TBarcode settings.
+ * @author Dominik Seichter
+ */
+class TBarcodeDlg : public QWidget, public BarcodeDlgBase {
+ Q_OBJECT
+ public:
+ TBarcodeDlg(QWidget *parent=0, const char *name=0);
+
+ void setData( Barkode* b );
+ void getData( Barkode* b ) const;
+
+ private:
+ KDoubleNumInput* spinModule;
+ KIntNumInput* spinHeight;
+ QCheckBox* checkEscape;
+ QCheckBox* checkAbove;
+ QCheckBox* checkAutoCorrect;
+ KComboBox* comboCheckSum;
+
+ QMap<QString,int> map;
+};
+
+/** A configuration Dialog for PDF417 settings.
+ * @author Dominik Seichter
+ */
+class PDF417BarcodeDlg : public QWidget, public BarcodeDlgBase {
+ Q_OBJECT
+ public:
+ PDF417BarcodeDlg(QWidget *parent=0, const char *name=0);
+
+ void setData( Barkode* b );
+ void getData( Barkode* b ) const;
+
+ private:
+ KIntNumInput* spinRow;
+ KIntNumInput* spinCol;
+ KIntNumInput* spinErr;
+};
+
+/** A configuration widget for DataMatrix settings.
+ * @author Dominik Seichter
+ */
+class DataMatrixDlg : public QWidget, public BarcodeDlgBase {
+ Q_OBJECT
+ public:
+ DataMatrixDlg(QWidget *parent=0, const char *name=0);
+
+ void setData( Barkode* b );
+ void getData( Barkode* b ) const;
+
+ private:
+ KComboBox* comboDataMatrix;
+};
+
+/** A configuration widget for barcode sequences.
+ * @author Dominik Seichter
+ */
+class SequenceDlg : public QWidget, public BarcodeDlgBase {
+ Q_OBJECT
+ public:
+ SequenceDlg(QWidget *parent=0, const char *name=0);
+
+ void setData( Barkode* b );
+ void getData( Barkode* b ) const;
+
+ private slots:
+ void enableControls();
+
+ private:
+ QCheckBox* checkSequence;
+ QRadioButton* radioNumbers;
+ QRadioButton* radioAlpha;
+ QRadioButton* radioAlphaNum;
+
+ KIntNumInput* spinStep;
+ KIntNumInput* spinStart;
+};
+
+/** A configuration widget for colors in pure postscript barcodes
+ * @author Dominik Seichter
+ */
+class ColorDlg : public QVBox, public BarcodeDlgBase {
+ Q_OBJECT
+ public:
+ ColorDlg(QWidget *parent=0, const char *name=0);
+
+ void setData( Barkode* b );
+ void getData( Barkode* b ) const;
+
+ private:
+ KColorButton* buttonBarColor;
+ KColorButton* buttonBackColor;
+ KColorButton* buttonTextColor;
+};
+
+/** A configuration widget for colors in pure postscript barcodes
+ * @author Dominik Seichter
+ */
+class PurePostscriptDlg : public QVBox, public BarcodeDlgBase {
+ Q_OBJECT
+ public:
+ PurePostscriptDlg(QWidget *parent=0, const char *name=0);
+
+ void setData( Barkode* b );
+ void getData( Barkode* b ) const;
+
+ private:
+ QCheckBox* checkChecksum;
+};
+
+#endif
diff --git a/kbarcode/barcodeitem.cpp b/kbarcode/barcodeitem.cpp
new file mode 100644
index 0000000..f2fbe4c
--- /dev/null
+++ b/kbarcode/barcodeitem.cpp
@@ -0,0 +1,253 @@
+/***************************************************************************
+ barcodeitem.cpp - description
+ -------------------
+ begin : Do Sep 2 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+
+#include "barcodeitem.h"
+#include "tcanvasitem.h"
+
+#include <qdom.h>
+#include <qpainter.h>
+#include <qpaintdevicemetrics.h>
+
+BarcodeItem::BarcodeItem()
+ : Barkode(), DocumentItem()
+{
+ init();
+}
+
+BarcodeItem::BarcodeItem( const Barkode & bcode )
+ : Barkode( bcode ), DocumentItem()
+{
+ init();
+}
+
+QMap<QString,QString> BarcodeItem::legacy;
+
+void BarcodeItem::init()
+{
+ // read barcodes saved by kbarcode < 1.3.0
+ /*
+ // disable legacy code as it is really old
+ // and conflicts with tbarcode2 support
+
+ if( !legacy.count() ) {
+ legacy.insert( "0", "any" );
+ legacy.insert( "1", "ean" );
+ legacy.insert( "2", "upc" );
+ legacy.insert( "3", "isbn" );
+ legacy.insert( "4", "code39" );
+ legacy.insert( "5", "code128" );
+ legacy.insert( "6", "code128c" );
+ legacy.insert( "7", "code128b" );
+ legacy.insert( "8", "i25" );
+ legacy.insert( "9", "i28raw" );
+ legacy.insert( "10", "cbr" );
+ legacy.insert( "11", "msi" );
+ legacy.insert( "12", "pls" );
+ legacy.insert( "13", "code93" );
+ legacy.insert( "14", "msi" );
+ legacy.insert( "15", "code39 -c" );
+ legacy.insert( "16", "i25 -c" );
+ }
+ */
+ setBorder( false );
+ setRect( QRect( 0, 0, 100, 100 ) );
+
+ updateBarcode();
+}
+
+void BarcodeItem::loadXML (QDomElement* element)
+{
+ // TODO: default() should be called first and the current values should be used
+ // instead of the now hardcoded values
+ // i.e: setQuietZone( element->attribute("margin", QString::number( quietZone() ) ).toInt() );
+
+ setQuietZone( element->attribute("margin", "10" ).toInt() );
+ setRotation( element->attribute("rotation", "0" ).toInt() );
+ setScaling( element->attribute("scale", "1000" ).toDouble() / 1000 );
+ setCut( element->attribute("cut", "1.0" ).toDouble() );
+ setType( element->attribute("type", "code39" ) );
+
+ /*
+ * check for encoding types saved by kbarcode <= 1.2.0
+ */
+ if( legacy.contains( type() ) )
+ setType( legacy[type()] );
+
+ setTextVisible( element->attribute("text", "0" ).toInt() );
+ setDatabaseMode( element->attribute("caption", "Static" ) );
+
+ if( engine()->options() )
+ engine()->options()->load( element );
+
+ setDatamatrixSize( element->attribute( "datamatrix.size", "0" ).toInt() );
+
+ setSequenceEnabled( element->attribute( "sequenceenabled", "0" ).toInt() );
+ if( sequenceEnabled() )
+ {
+ setSequenceMode( (ESequence)element->attribute( "sequencemode", "0" ).toInt() );
+ setSequenceStep( element->attribute( "sequencestep", "1" ).toInt() );
+ setSequenceStart( element->attribute( "sequencestart", "0" ).toInt() );
+ }
+
+ QDomNode n = element->firstChild();
+ while( !n.isNull() ) {
+ QDomElement e = n.toElement(); // try to convert the node to an element.
+ if( !e.isNull() )
+ if( e.tagName() == "value" )
+ setValue( e.text() );
+
+ n = n.nextSibling();
+ }
+
+ DocumentItem::loadXML( element );
+
+ updateBarcode();
+}
+
+void BarcodeItem::saveXML (QDomElement* element)
+{
+ element->setAttribute( "margin", quietZone() );
+ element->setAttribute( "rotation", rotation() );
+ element->setAttribute( "cut", cut() );
+ element->setAttribute( "caption", databaseMode() );
+
+ /*
+ * This values are only needed for !cache and for sequences
+ */
+ element->setAttribute( "sequenceenabled", sequenceEnabled() );
+ if( sequenceEnabled() )
+ {
+ element->setAttribute( "sequencemode", (int)sequenceMode() );
+ element->setAttribute( "sequencestep", sequenceStep() );
+ element->setAttribute( "sequencestart", sequenceStart() );
+ }
+
+ element->setAttribute( "type", type() );
+ element->setAttribute( "text", textVisible() );
+ element->setAttribute( "scale", scaling()*1000 );
+
+ if( engine()->options() )
+ engine()->options()->save( element );
+
+ element->setAttribute( "datamatrix.size", datamatrixSize() );
+
+ QDomElement texttag = element->ownerDocument().createElement( "value" );
+ texttag.appendChild( element->ownerDocument().createTextNode( value() ) );
+
+ element->appendChild( texttag );
+
+ DocumentItem::saveXML( element );
+}
+
+void BarcodeItem::draw (QPainter* painter)
+{
+ if( DocumentItem::paintDevice() && DocumentItem::paintDevice()->isExtDev() )
+ {
+ painter->save();
+
+ /*
+ QPaintDeviceMetrics metrics( DocumentItem::paintDevice() );
+ double scalex = (double)metrics.logicalDpiX() / (double)QPaintDevice::x11AppDpiX();
+ double scaley = (double)metrics.logicalDpiY() / (double)QPaintDevice::x11AppDpiY();
+ painter->scale( 1.0 / scalex, 1.0 / scaley );
+ */
+
+ //painter->drawPixmap( rect().x(), rect().y(), m_pixmap );
+ drawBarcode( *painter, rect().x(), rect().y() );
+ painter->restore();
+ }
+ else
+ {
+ painter->save();
+ drawBarcode( *painter, rect().x(), rect().y() );
+ painter->restore();
+
+ TCanvasItem* citem = canvasItem();
+ if( citem )
+ {
+ citem->setSize( Barkode::size().width(), Barkode::size().height() );
+ }
+ // TODO: do a bitBlt when device is screen
+ //painter->drawPixmap( rect().x(), rect().y(), m_pixmap );
+ //bitBlt( painter->device(), rect().x(), rect().y(), &m_pixmap, 0, 0, rect().width(), rect().height(), Qt::CopyROP );
+ }
+ DocumentItem::drawBorder( painter );
+}
+
+void BarcodeItem::drawZpl( QTextStream* stream )
+{
+ QString encoding = ZPLUtils::encoding( type() );
+ if( encoding.isNull() )
+ {
+ qDebug( "ERROR: No ZPL barcode found");
+ return;
+ }
+
+ *stream << ZPLUtils::fieldOrigin( rect().x(), rect().y() );
+ *stream << "^B" << encoding;
+ *stream << ZPLUtils::fieldData( value() );
+}
+
+void BarcodeItem::drawIpl( QTextStream* stream, IPLUtils* utils )
+{
+ QString encoding = utils->encoding( type() );
+
+ if( encoding.isEmpty() )
+ {
+ qDebug( "ERROR: No IPL barcode found");
+ return;
+ }
+
+ int counter = utils->counter();
+ QString s = QString("B%1;").arg( counter ); // field number
+
+ s += utils->fieldOrigin( rect().x(), rect().y() );
+ s += QString("c%1;").arg( encoding ); // encoding type
+ s += QString("h%1;").arg( rect().height() ); // height of barcode
+ s += QString("w%1;").arg( 3 ); // width of barcode (per line)
+ s += QString("d0,%1;").arg( value().length() ); // max length of data
+
+ *stream << utils->field( s );
+ utils->addValue( value() );
+}
+
+void BarcodeItem::drawEPcl( QTextStream* stream )
+{
+ QString encoding = EPCLUtils::encoding( type() );
+ if( encoding.isEmpty() )
+ {
+ qDebug( "ERROR: No EPCL barcode found");
+ return;
+ }
+
+ // Coordinates cannot start at zero
+ QString s = QString("B %1").arg( rect().x()+1 );
+ s += QString(" %1 0").arg( rect().y() + rect().height() );
+ s += QString(" %1 1 4").arg( encoding );
+ s += QString(" %1 1").arg( rect().height() );
+ s += QString(" %1").arg( value() );
+
+ *stream << EPCLUtils::field( s );
+}
+
+void BarcodeItem::updateBarcode()
+{
+ Barkode::setTokenProvider( tokenProvider() );
+ Barkode::update( DocumentItem::paintDevice() );
+ setSize( Barkode::size().width(), Barkode::size().height() );
+}
+
diff --git a/kbarcode/barcodeitem.h b/kbarcode/barcodeitem.h
new file mode 100644
index 0000000..0faafc2
--- /dev/null
+++ b/kbarcode/barcodeitem.h
@@ -0,0 +1,57 @@
+/***************************************************************************
+ barcodeitem.h - description
+ -------------------
+ begin : Do Sep 2 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+
+#ifndef BARCODEITEM_H
+#define BARCODEITEM_H
+
+#include <qmap.h>
+#include <qpixmap.h>
+
+#include "barkode.h"
+#include "gnubarcode.h"
+#include "documentitem.h"
+
+/**
+ * Class BarcodeItem
+ * A barcode on the screen or printer.
+ */
+class BarcodeItem : public Barkode, public DocumentItem {
+public:
+ BarcodeItem();
+ BarcodeItem( const Barkode & bcode );
+
+ void updateBarcode();
+
+ int rtti() const { return eRtti_Barcode;}
+
+ void loadXML (QDomElement* element);
+ void saveXML (QDomElement* element);
+ void draw (QPainter* painter);
+ void drawZpl( QTextStream* stream );
+ void drawIpl( QTextStream* stream, IPLUtils* utils );
+ void drawEPcl( QTextStream* stream );
+
+private:
+ void init();
+
+private:
+ static QMap<QString,QString> legacy;
+
+ QPixmap m_pixmap;
+};
+#endif //BARCODEITEM_H
+
diff --git a/kbarcode/barcodeprinterdlg.cpp b/kbarcode/barcodeprinterdlg.cpp
new file mode 100644
index 0000000..3488a97
--- /dev/null
+++ b/kbarcode/barcodeprinterdlg.cpp
@@ -0,0 +1,125 @@
+/***************************************************************************
+ barcodeprinterdlg.cpp - description
+ -------------------
+ begin : Fri Oct 01 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "barcodeprinterdlg.h"
+#include "printersettings.h"
+
+#include <kcombobox.h>
+#include <klocale.h>
+#include <kurlrequester.h>
+
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qvbuttongroup.h>
+
+BarcodePrinterDlg::BarcodePrinterDlg(QWidget *parent, const char *name)
+ : KDialogBase( KDialogBase::Plain, i18n("Barcode Printer"),
+ KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, parent,name)
+{
+ QGridLayout* layout = new QGridLayout( plainPage(), 6, 6 );
+
+ QLabel* label = new QLabel( i18n("&Output Format:"), plainPage() );
+ comboFormat = new KComboBox( false, plainPage() );
+ label->setBuddy( comboFormat );
+
+ checkFile = new QCheckBox( i18n("&Print to File"), plainPage() );
+
+ label2 = new QLabel( i18n("&Filename:"), plainPage() );
+ requester = new KURLRequester( plainPage() );
+ label2->setBuddy( requester );
+
+ label3 = new QLabel( i18n("&Device:"), plainPage() );
+ comboDevice = new KComboBox( true, plainPage() );
+ label3->setBuddy( comboDevice );
+
+ layout->addWidget( label, 0, 0 );
+ layout->addMultiCellWidget( comboFormat, 0, 0, 1, 2 );
+ layout->addMultiCellWidget( checkFile, 1, 1, 1, 2 );
+ layout->addWidget( label2, 2, 0 );
+ layout->addWidget( requester, 2, 1 );
+ layout->addWidget( label3, 3, 0 );
+ layout->addMultiCellWidget( comboDevice, 3, 3, 1, 2 );
+
+ comboFormat->insertItem( i18n("TEC Printer (TEC)") );
+ comboFormat->insertItem( i18n("Zebra Printer (ZPL)") );
+ comboFormat->insertItem( i18n("Intermec Printer (IPL)") );
+ comboFormat->insertItem( i18n("EPCL Printer (EPCL)") );
+
+ // do not translate unix devicenames...
+ comboDevice->insertItem( "/dev/lp0" );
+ comboDevice->insertItem( "/dev/lp1" );
+ comboDevice->insertItem( "/dev/lp2" );
+ comboDevice->insertItem( "/dev/usb/lp0" );
+ comboDevice->insertItem( "/dev/usb/lp1" );
+ comboDevice->insertItem( "/dev/usb/lp2" );
+
+ connect( checkFile, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+
+// KFileDialog fd( QString::null, "*.zpl|Zebra Printer Language (*.zpl)\n*.ipl|Intermec Printer Language (*.ipl)", this, "fd", true );
+
+ enableControls();
+}
+
+
+BarcodePrinterDlg::~BarcodePrinterDlg()
+{
+}
+
+void BarcodePrinterDlg::enableControls()
+{
+ bool b = checkFile->isChecked();
+ label2->setEnabled( b );
+ requester->setEnabled( b );
+
+ label3->setEnabled( !b );
+ comboDevice->setEnabled( !b );
+}
+
+int BarcodePrinterDlg::outputFormat() const
+{
+ switch( comboFormat->currentItem() )
+ {
+ case 0:
+ return PrinterSettings::TEC;
+ case 1:
+ return PrinterSettings::ZEBRA;
+ case 2:
+ return PrinterSettings::INTERMEC;
+ case 3:
+ return PrinterSettings::EPCL;
+ default:
+ return -1;
+ }
+}
+
+bool BarcodePrinterDlg::printToFile() const
+{
+ return checkFile->isChecked();
+}
+
+const QString BarcodePrinterDlg::deviceName() const
+{
+ return comboDevice->currentText();
+}
+
+const QString BarcodePrinterDlg::fileName() const
+{
+ return requester->url();
+}
+
+#include "barcodeprinterdlg.moc"
diff --git a/kbarcode/barcodeprinterdlg.h b/kbarcode/barcodeprinterdlg.h
new file mode 100644
index 0000000..fe0e6e3
--- /dev/null
+++ b/kbarcode/barcodeprinterdlg.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+ barcodeprinterdlg.h - description
+ -------------------
+ begin : Fri Oct 01 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef BARCODEPRINTERDLG_H
+#define BARCODEPRINTERDLG_H
+
+#include <kdialogbase.h>
+
+class KComboBox;
+class KURLRequester;
+class QCheckBox;
+class QLabel;
+
+/**
+@author Dominik Seichter
+*/
+class BarcodePrinterDlg : public KDialogBase
+{
+ Q_OBJECT
+ public:
+ BarcodePrinterDlg(QWidget *parent = 0, const char *name = 0);
+ ~BarcodePrinterDlg();
+
+ int outputFormat() const;
+ bool printToFile() const;
+ const QString deviceName() const;
+ const QString fileName() const;
+
+ private slots:
+ void enableControls();
+
+ private:
+ KComboBox* comboFormat;
+ KComboBox* comboDevice;
+ KURLRequester* requester;
+
+ QCheckBox* checkFile;
+ QLabel* label2;
+ QLabel* label3;
+};
+
+#endif
diff --git a/kbarcode/barcodes.html b/kbarcode/barcodes.html
new file mode 100644
index 0000000..3e64951
--- /dev/null
+++ b/kbarcode/barcodes.html
@@ -0,0 +1,868 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>kbarcode</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body>
+<a name="top"></a>
+<p><a href="http://www.kbarcode.net" target="_blank">
+ <font face="Verdana, Arial, Helvetica, sans-serif"> <b>kbarcode </b> - The Barcode Solution for KDE </font>
+ </a></p>
+
+<p><strong>kbarcode</strong> has right now support following barcodes. Please check
+ the requirements and limitations:</p>
+
+<ul>
+ <li> <a href="#EAN">ean (EAN 8 or EAN 13)</a></li>
+ <li> <a href="#upc">upc (UPC-A or UPC-E)</a></li>
+ <li> <a href="#isbn">isbn</a></li>
+ <li> <a href="#code39">code39</a></li>
+ <li><a href="#code128"> code128</a></li>
+ <li> <a href="#code128c">code128c</a></li>
+ <li><a href="#code128b"> code128b</a></li>
+ <li> <a href="#codei25">Interleave 2 of 5</a></li>
+ <li> <a href="#code128raw">code 128 raw</a></li>
+ <li> <a href="#cbr">Codabar</a></li>
+ <li> <a href="#msi">msi</a></li>
+ <li> <a href="#pls">Plessey</a></li>
+ <li> <a href="#code93">code93</a></li>
+</ul>
+<p><strong><a name="EAN" id="EAN"></a>EAN 8</strong>:</p>
+
+
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>ean</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>numbers (0....9)</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>7 + 1 Checkum Digit = 8</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td><ul>
+ <li>when the number is 7 digits long, kbarcode will create a checksum
+ (the 8. digits)</li>
+ <li>when the number is 8 digits long, kbarcode will check the checksum
+ and deny printing if wrong</li>
+ </ul></td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td><p>fixed, but scalable<br>
+ Standard: 26.73mm x 21.64mm</p></td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td><p>possible scaling:</p>
+ <table width="80%" border="1" align="center" cellpadding="0" cellspacing="0">
+ <tr>
+ <td width="20%"><div align="center">Size</div></td>
+ <td width="20%"><div align="center">Factor</div></td>
+ <td width="20%"><p align="center">width<br>
+ <p align="center">[mm]</p></td>
+ <td width="20%"><p align="center">height</p>
+ <p align="center">[mm]</p></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC0</div></td>
+ <td><div align="center">0.818</div></td>
+ <td><div align="center">21.87</div></td>
+ <td><div align="center">17.70</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC1</div></td>
+ <td><div align="center">0.90</div></td>
+ <td><div align="center">24.06</div></td>
+ <td><div align="center">19.48</div></td>
+ </tr>
+ <tr>
+ <td><div align="center"><strong>SC2</strong></div></td>
+ <td><div align="center"><strong>1.00</strong></div></td>
+ <td><div align="center"><strong>26.73</strong></div></td>
+ <td><div align="center"><strong>21.64</strong></div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC3</div></td>
+ <td><div align="center">1.10</div></td>
+ <td><div align="center">29.40</div></td>
+ <td><div align="center">23.80</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC4</div></td>
+ <td><div align="center">1.20</div></td>
+ <td><div align="center">32.08</div></td>
+ <td><div align="center">25.97</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC5</div></td>
+ <td><div align="center">1.35</div></td>
+ <td><div align="center">36.09</div></td>
+ <td><div align="center">29.21</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC6</div></td>
+ <td><div align="center">1.50</div></td>
+ <td><div align="center">40.10</div></td>
+ <td><div align="center">32.46</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC7</div></td>
+ <td><div align="center">1.65</div></td>
+ <td><div align="center">44.10</div></td>
+ <td><div align="center">35.71</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC8</div></td>
+ <td><div align="center">1.85</div></td>
+ <td><div align="center">49.45</div></td>
+ <td><div align="center">40.03</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC9</div></td>
+ <td><div align="center">2.00</div></td>
+ <td><div align="center">53.46</div></td>
+ <td><div align="center">43.28</div></td>
+ </tr>
+ </table><p>&nbsp;</p></td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong>EAN 13</strong>:</p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>ean</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>numbers (0.....9)</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>12 + 1 checksum digitt = 13</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td><ul>
+ <li>when the number is 12 digits long, kbarcode will create a checksum
+ (the 13. digits)</li>
+ <li>when the number is 13 digits long, kbarcode will check the checksum
+ and deny printing if wrong</li>
+ </ul></td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td><p>fixed, but scalable<br>
+ Standard: 37.29 x 26.26mm</p></td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td><p>possible scaling:</p>
+ <table width="80%" border="1" align="center" cellpadding="0" cellspacing="0">
+
+ <tr>
+ <td width="20%"><div align="center">Size</div></td>
+ <td width="20%"><div align="center">Factor</div></td>
+ <td width="20%"><p align="center">width<br>
+ <p align="center">[mm]</p></td>
+ <td width="20%"><p align="center">height</p>
+ <p align="center">[mm]</p></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC0</div></td>
+ <td><div align="center">0.818</div></td>
+ <td><div align="center">30.50</div></td>
+ <td><div align="center">21.48</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC1</div></td>
+ <td><div align="center">0.90</div></td>
+ <td><div align="center">33.56</div></td>
+ <td><div align="center">23.63</div></td>
+ </tr>
+ <tr>
+ <td><div align="center"><strong>SC2</strong></div></td>
+ <td><div align="center"><strong>1.00</strong></div></td>
+ <td><div align="center">37.29</div></td>
+ <td><div align="center">26.26</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC3</div></td>
+ <td><div align="center">1.10</div></td>
+ <td><div align="center">41.02</div></td>
+ <td><div align="center">28.89</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC4</div></td>
+ <td><div align="center">1.20</div></td>
+ <td><div align="center">44.75</div></td>
+ <td><div align="center">31.51</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC5</div></td>
+ <td><div align="center">1.35</div></td>
+ <td><div align="center">50.34</div></td>
+ <td><div align="center">35.45</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC6</div></td>
+ <td><div align="center">1.50</div></td>
+ <td><div align="center">55.94</div></td>
+ <td><div align="center">39.39</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC7</div></td>
+ <td><div align="center">1.65</div></td>
+ <td><div align="center">61.35</div></td>
+ <td><div align="center">43.33</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC8</div></td>
+ <td><div align="center">1.85</div></td>
+ <td><div align="center">68.99</div></td>
+ <td><div align="center">48.58</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC9</div></td>
+ <td><div align="center">2.00</div></td>
+ <td><div align="center">74.58</div></td>
+ <td><div align="center">52.52</div></td>
+ </tr>
+ </table><p>&nbsp;</p></td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+
+<p><strong><a name="upc"></a>UPC-A</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>UPC</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>numbers (0....9)</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>11 + 1 checksum digit = 12</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td><ul>
+ <li>when the number is 11 digits long, kbarcode will create a checksum
+ (the 12. digits)</li>
+ <li>when the number is 12 digits long, kbarcode will check the checksum
+ and deny printing if wrong</li>
+ </ul></td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td><p>fixed, but scalable<br>
+ Standard: 37.29 x 26.26mm</p></td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td><p>&nbsp;</p>
+ <table width="80%" border="1" align="center" cellpadding="0" cellspacing="0">
+
+ <tr>
+ <td width="20%"><div align="center">Size</div></td>
+ <td width="20%"><div align="center">Factor</div></td>
+ <td width="20%"><p align="center">width<br>
+ <p align="center">[mm]</p></td>
+ <td width="20%"><p align="center">height</p>
+ <p align="center">[mm]</p></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC0</div></td>
+ <td><div align="center">0.818</div></td>
+ <td><div align="center">30.50</div></td>
+ <td><div align="center">21.48</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC1</div></td>
+ <td><div align="center">0.90</div></td>
+ <td><div align="center">33.56</div></td>
+ <td><div align="center">23.63</div></td>
+ </tr>
+ <tr>
+ <td><div align="center"><strong>SC2</strong></div></td>
+ <td><div align="center"><strong>1.00</strong></div></td>
+ <td><div align="center">37.29</div></td>
+ <td><div align="center">26.26</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC3</div></td>
+ <td><div align="center">1.10</div></td>
+ <td><div align="center">41.02</div></td>
+ <td><div align="center">28.89</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC4</div></td>
+ <td><div align="center">1.20</div></td>
+ <td><div align="center">44.75</div></td>
+ <td><div align="center">31.51</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC5</div></td>
+ <td><div align="center">1.35</div></td>
+ <td><div align="center">50.34</div></td>
+ <td><div align="center">35.45</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC6</div></td>
+ <td><div align="center">1.50</div></td>
+ <td><div align="center">55.94</div></td>
+ <td><div align="center">39.39</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC7</div></td>
+ <td><div align="center">1.65</div></td>
+ <td><div align="center">61.35</div></td>
+ <td><div align="center">43.33</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC8</div></td>
+ <td><div align="center">1.85</div></td>
+ <td><div align="center">68.99</div></td>
+ <td><div align="center">48.58</div></td>
+ </tr>
+ <tr>
+ <td><div align="center">SC9</div></td>
+ <td><div align="center">2.00</div></td>
+ <td><div align="center">74.58</div></td>
+ <td><div align="center">52.52</div></td>
+ </tr>
+ </table>
+ <p>&nbsp;</p></td>
+ </tr>
+</table>
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong>UPC-E</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>upc</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>numbers (0....9)</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>Systemcode 0 + 6 + 1 Checkum Digit = 8</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td><ul>
+ <li>when the number is 7 digits long, kbarcode will create a checksum
+ (the 8. digits)</li>
+ <li>when the number is 8 digits long, kbarcode will check the checksum
+ and deny printing if wrong</li>
+ </ul></td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td>
+<p>&nbsp;</p></td>
+ </tr>
+</table>
+
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+
+<p><strong><a name="isbn"></a>ISBN</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>ISBN</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td> ISBN numbers are encoded as EAN-13 symbols, with an optional add-5
+ trailer. The ISBN frontend of the library accepts real ISBN
+ numbers and deals with any hyphen and, if present, the ISBN checksum character
+ before encoding data. Valid representations for ISBN strings are for example:
+ &quot;1-56592-292-1&quot;, &quot;3-89721-122-X&quot; and &quot;3-89721-122-X
+ 06900&quot;.</p></td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+
+<p><strong><a name="code128b"></a>code 128-B</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>code 128-B</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td> This encoding can represent all of the printing ASCII characters, from
+ the space (32) to DEL (127). The checksum digit is mandatory i
+ n this encoding.</td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong><a name="code128c"></a>code 128-C</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>code 128-C</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td>
+ The &quot;C&quot; variation of Code-128 uses Code-128 symbols to represent
+ two digits at a time (Code-128 is made up of 104 symbols whose<br>
+ interpretation is controlled by the start symbol being used). Code 128-C
+ is thus the most compact way to represent any even number of digits. The
+ encoder refuses to deal with an odd number of digits because the caller
+ is expected to provide proper padding to an even number of digits. (Since
+ Code-128 includes control symbols to switch charset, it is theoretically
+ possible to represent the odd digit as a Code 128-A or 128-B symbol, but
+ this tool doesn't currently implement this option).</p></td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong><a name="code128raw"></a>code 128 raw</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>code 128 raw</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td> Code-128 output represented symbol-by-symbol in the input string.
+ To override part of the problems outlined below in specifying<br>
+ code128 symbols, this pseudo-encoding allows the used to specify a list
+ of code128 symbols separated by spaces. Each symbol is represented by
+ a number in the range 0-105. The list should include the leading character.The
+ checksum and the stop character are automatically added by the library.
+ Most likely this pseudo-encoding will be used with BARCODE_NO_ASCII and
+ some external program to supply the printed text.</p></td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong><a name="code39"></a>code 39</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>code 39</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td> The code-39 standard can encode uppercase letters, digits, the blank
+ space, plus, minus, dot, star, dollar, slash, percent. Any<br>
+ string that is only composed of such characters is accepted by the code-39
+ encoder. To avoid loosing information, the encoder refuses to encode mixed-case
+ strings (a lowercase string is nonetheless accepted as a shortcut, but is
+ encoded as uppercase).</td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong><a name="codei25"></a>interleaved 2 of 5</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>interleaved 2 of 5</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td>
+ This encoding can only represent an even number of digits (odd digits
+ are represented by bars, and even digits by the interleaving<br>
+ spaces). The name stresses the fact that two of the five items (bars or
+ spaces) allocated to each symbol are wide, while the rest are narrow.
+ The checksum digit is optional (can be disabled via BARCODE_NO_CHECKSUM).
+ Since the number of digits, including the checksum, must be even, a leading
+ zero is inserted in the string being encoded if needed (this is specifically
+ stated in the specs I have access to).</p></td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong><a name="code128"></a>code 128</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>code 128</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td> Automatic selection between alphabet A, B and C of the Code-128 standard.
+ This encoding can represent all ASCII symbols, from 0<br>
+ (NUL) to 127 (DEL), as well as four special symbols, named F1, F2, F3,
+ F4. The set of symbols available in this encoding is not easily represented
+ as input to the barcode library, so the following convention is used.
+ In the input string, which is a C-language null- terminated string, the
+ NUL char is represented by the value 128 (0x80, 0200) and the F1-F4 characters
+ are represented by the values 193-196 (0xc1-0xc4, 0301-0304). The values
+ have been chosen to ease their representation as escape sequences.</p>
+ <p>Since the shell doesn't seem to interpret escape sequences on the command
+ line, the &quot;-b&quot; option cannot be easily used to designate the
+ strings to be encoded. As a workaround you can resort to the command echo,
+ either within back-ticks or used separately to create a file that is then
+ fed to the standard-input of barcode - assuming your echo command processes
+ escape sequences. The newline character is especially though to encode
+ (but not impossible unless you use a csh variant. </p>
+ <p>These problems only apply to the command-line tool; the use of library
+ functions doesn't give any problem. In needed, you can use the &quot;code
+ 128 raw&quot; pseudo-encoding to represent code128 symbols by their numerical
+ value. This encoding is used late in the auto- selection mechanism because
+ (almost) any input string can be represented using code128.</p>
+</td>
+</tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong><a name="cbr"></a>Codabar</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>Codabar</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td>
+ Codabar can encode the ten digits and a few special symbols (minus, plus,
+ dollar, colon, bar, dot). The characters &quot;A&quot;, &quot;B&quot;,
+ &quot;C&quot; and<br>
+ &quot;D&quot; are used to represent four different start/stop characters.
+ The input string to the barcode library can include the start and stop
+ characters or not include them (in which case &quot;A&quot; is used as
+ start and &quot;B&quot; as stop). Start and stop characters in the input
+ string can be either all lowercase or all uppercase and are always printed
+ as uppercase.</p></td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong><a name="pls"></a>Plessey</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>Plessey</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td> Plessey barcodes can encode all the hexadecimal digits. Alphabetic
+ digits in the input string must either be all lowercase or all<br>
+ uppercase. The output text is always uppercase.</p></td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong><a name="msi"></a>MSI</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>MSI</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td>
+ MSI can only encode the decimal digits. While the standard specifies either
+ one or two check digits, the current implementation in<br>
+ this library only generates one check digit.</p></td>
+ </tr>
+</table>
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+
+
+<p><strong><a name="code93"></a>code 93</strong></p>
+<table width = "100%" border="1" cellspacing="0" cellpadding="0">
+ <tr>
+ <td nowrap>kbarcode Setting</td>
+ <td>code 93</td>
+ </tr>
+ <tr>
+ <td nowrap>valid character set</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>lenght</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Checksum</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Size</td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td nowrap>Remark</td>
+ <td>The code-93 standard can natively encode 48 different characters, including
+ uppercase letters, digits, the blank space, plus, minus,<br>
+ dot, star, dollar, slash, percent, as well as five special characters:
+ a start/stop delimiter and four &quot;shift characters&quot; used for
+ extended encoding. Using this &quot;extended encoding&quot; method, any
+ standard 7-bit ASCII character can be encoded, but it takes up two symbol
+ lengths in barcode if the character is not natively supported (one of
+ the 48). The encoder here fully implements the code 93 encoding standard.
+ Any characters natively supported (A-Z, 0-9, &quot;.+-/$&amp;%&quot;)
+ will be encoded as such - for any other characters (such as lower case
+ letters, brackets, parentheses, etc.), the encoder will revert to extended
+ encoding. As a note, the option to exclude the checksum will eliminate
+ the two modulo-47 checksums (called C and K) from the barcode, but this
+ probably will make it unreadable by 99% of all scanning systems. These
+ checksums are specified to be used at the firmware level, and their absence
+ will be interpreted as an invalid barcode.</p></td>
+ </tr>
+</table>
+
+
+<p>
+ <a href="#top"> TOP </a>
+</p>
+</body>
+</html>
diff --git a/kbarcode/barkode.cpp b/kbarcode/barkode.cpp
new file mode 100644
index 0000000..7ec5c84
--- /dev/null
+++ b/kbarcode/barkode.cpp
@@ -0,0 +1,968 @@
+/* Copyright (C) 2004 Dominik Seichter <domseichter@web.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "barkode.h"
+#include "barkodeengine.h"
+#include "gnubarcode.h"
+#include "pixmapbarcode.h"
+#include "purepostscript.h"
+#include "tbarcode2.h"
+#include "tokenprovider.h"
+
+#ifdef _ENABLE_NATIVE_GNU_BARCODE
+# include <barcode.h>
+#else
+#define BARCODE_DEFAULT_FLAGS 0x00000000
+
+#define BARCODE_ENCODING_MASK 0x000000ff /* 256 possibilites... */
+#define BARCODE_NO_ASCII 0x00000100 /* avoid text in output */
+#define BARCODE_NO_CHECKSUM 0x00000200 /* avoid checksum in output */
+
+#define BARCODE_OUTPUT_MASK 0x000ff000 /* 256 output types */
+#define BARCODE_OUT_EPS 0x00001000
+#define BARCODE_OUT_PS 0x00002000
+#define BARCODE_OUT_PCL 0x00004000 /* by Andrea Scopece */
+/* PCL_III 0x00008000 */
+#define BARCODE_OUT_PCL_III 0x0000C000
+#define BARCODE_OUT_NOHEADERS 0x00100000 /* no header nor footer */
+
+// include our own defines from barcode.h
+enum {
+ BARCODE_ANY = 0, /* choose best-fit */
+ BARCODE_EAN,
+ BARCODE_UPC, /* upc == 12-digit ean */
+ BARCODE_ISBN, /* isbn numbers (still EAN13) */
+ BARCODE_39, /* code 39 */
+ BARCODE_128, /* code 128 (a,b,c: autoselection) */
+ BARCODE_128C, /* code 128 (compact form for digits) */
+ BARCODE_128B, /* code 128, full printable ascii */
+ BARCODE_I25, /* interleaved 2 of 5 (only digits) */
+ BARCODE_128RAW, /* Raw code 128 (by Leonid A. Broukhis) */
+ BARCODE_CBR, /* Codabar (by Leonid A. Broukhis) */
+ BARCODE_MSI, /* MSI (by Leonid A. Broukhis) */
+ BARCODE_PLS, /* Plessey (by Leonid A. Broukhis) */
+ BARCODE_93 /* code 93 (by Nathan D. Holmes) */
+};
+#endif // _ENABLE_NATIVE_GNU_BARCODE
+
+#include <qdom.h>
+#include <qfile.h>
+#include <qpainter.h>
+#include <qpicture.h>
+#include <qpixmap.h>
+#include <qsize.h>
+
+#include <klocale.h>
+#include <kstandarddirs.h>
+
+QValueList<tBarcodeInfo> Barkode::s_info;
+QStringList* Barkode::s_encoding = NULL;
+bool Barkode::s_haveGnuBarcode = false;
+bool Barkode::s_havePdfEncode = false;
+bool Barkode::s_haveTBarcode = false;
+bool Barkode::s_haveTBarcode2 = false;
+bool Barkode::s_havePurePostscript = false;
+
+Barkode::Barkode()
+{
+ initInfo();
+ m_engine = NULL;
+ m_token = NULL;
+
+ defaults();
+}
+
+Barkode::Barkode( const Barkode & barkode )
+{
+ initInfo();
+ m_engine = NULL;
+ m_token = NULL;
+
+ *this = barkode;
+}
+
+Barkode::~Barkode()
+{
+ if( m_engine )
+ delete m_engine;
+}
+
+void Barkode::setTokenProvider( TokenProvider* token )
+{
+ m_token = token;
+}
+
+void Barkode::defaults()
+{
+ m_valid = false;
+ m_text_visible = true;
+
+ m_background = Qt::white;
+ m_foreground = Qt::black;
+ m_textcolor = Qt::black;
+
+ m_quietzone = 0;
+ m_bar_height = 80;
+ m_fontsize = 12;
+
+ m_rotation = 0;
+ m_scaling = 1.0;
+ m_cut = 1.0;
+ m_datamatrix_size = 0;
+
+ m_type = "code39";
+ m_value = "KBARCODE";
+ m_database_mode = "static";
+
+ m_index = 0;
+ m_sequence = false;
+ m_esequence = NUM;
+ m_sequence_start = 1;
+ m_sequence_step = 1;
+
+ updateEngine();
+
+ BarkodeEngineOptions* options = m_engine ? m_engine->options() : NULL;
+ if( options )
+ options->defaults();
+}
+
+void Barkode::setData( const Barkode & barkode )
+{
+ this->m_valid = barkode.m_valid;
+ this->m_text_visible = barkode.m_text_visible;
+
+ this->m_background = barkode.m_background;
+ this->m_foreground = barkode.m_foreground;
+ this->m_textcolor = barkode.m_textcolor;
+
+ this->m_quietzone = barkode.m_quietzone;
+ this->m_bar_height = barkode.m_bar_height;
+ this->m_fontsize = barkode.m_fontsize;
+ this->m_rotation = barkode.m_rotation;
+ this->m_scaling = barkode.m_scaling;
+ this->m_cut = barkode.m_cut;
+
+ this->m_type = barkode.m_type;
+ this->m_value = barkode.m_value;
+ this->m_database_mode = barkode.m_database_mode;
+
+ this->m_index = barkode.m_index;
+ this->m_sequence = barkode.m_sequence;
+ this->m_esequence = barkode.m_esequence;
+ this->m_sequence_start = barkode.m_sequence_start;
+ this->m_sequence_step = barkode.m_sequence_step;
+
+ updateEngine();
+
+ *m_engine = *(barkode.engine());
+
+ this->m_datamatrix_size = barkode.m_datamatrix_size;
+}
+
+void Barkode::operator=( const Barkode & barkode )
+{
+ setData( barkode );
+}
+
+bool Barkode::operator==( const Barkode & barkode ) const
+{
+ bool b = true;
+#warning "operator== is incomplete"
+
+ // colors
+ b = ( this->m_background == barkode.m_background && this->m_foreground == barkode.m_foreground ) && b;
+
+ // sizes
+ b = ( this->m_quietzone == barkode.m_quietzone && this->m_bar_height == barkode.m_bar_height && this->m_fontsize == barkode.m_fontsize ) && b;
+
+ // values
+ b = ( this->m_type == barkode.m_type && this->m_value == barkode.m_value ) && b;
+
+ return b;
+}
+
+const QPicture Barkode::picture()
+{
+ QPicture pic;
+ QPainter painter( &pic );
+
+ painter.fillRect( 0, 0, size().width(), size().height(), m_background );
+
+ // sub classes do the real drawing
+ drawBarcode( painter );
+
+ return pic;
+}
+
+void Barkode::drawInvalid( QPainter & painter, int x, int y )
+{
+ QRect rect( x, y, size().width(), size().height() );
+ painter.save();
+ painter.fillRect( rect, Qt::white );
+ painter.setPen( QPen( Qt::red, 2 ) );
+ painter.drawRect( rect );
+ painter.drawLine( x, y, x + size().width(), y + size().height() );
+ painter.drawLine( x, y + size().height(), x + size().width(), y );
+ painter.restore();
+}
+
+const QSize Barkode::size() const
+{
+ return m_engine ? m_engine->size() : QSize( 0, 0 );
+}
+
+const QPixmap Barkode::pixmap( double scalex, double scaley )
+{
+ QPixmap pixmap( (int)(size().width() * scalex), (int)(size().height() * scaley) );
+ if( !pixmap.isNull() )
+ {
+ QPainter painter( &pixmap );
+ painter.scale( scalex, scaley );
+ painter.fillRect( 0, 0, size().width(), size().height(), m_background );
+ drawBarcode( painter );
+ }
+
+ return pixmap;
+}
+
+const QString Barkode::parsedValue()
+{
+ QString text = m_token ? m_token->parse( m_value ) : m_value;
+
+ if( !sequenceEnabled() )
+ return text;
+
+ if( m_value.contains( '#' ) <= 0 )
+ return text;
+
+ int pos = 0, counter = 1;
+
+ pos = text.find("#", pos);
+ pos++;
+ while( text[pos] == '#' ) {
+ text.remove(pos, 1);
+ counter++;
+ }
+
+ pos = text.find("#", 0);
+ QString temp;
+
+ if( sequenceMode() == NUM ) {
+ int v = sequenceStart() + m_index*sequenceStep();
+ temp.sprintf("%0*i", counter, v );
+ } else {
+ for( int i = 0; i < counter; i++ )
+ temp.append( "A" );
+
+ unsigned int z = 0;
+ for( int p = temp.length(); p >= 0; p--, z++ ) {
+ if( sequenceMode() == ALPHA ) {
+ int v = 'A' + m_index*sequenceStep();
+ v -= z*('Z'-'A');
+
+ if( v <= 'Z' ) {
+ temp[p] = QChar(v);
+ break;
+ } else if( v > 'Z' )
+ v = 'Z';
+ temp[p] = QChar(v);
+ } else if( sequenceMode() == ALPHANUM ) {
+ qDebug("NOT IMPLEMENTED");
+/* char array[36];
+ for( unsigned int i = 'A'; i <= 'Z'; i++ )
+ array[i-'A'] = i;
+ for( unsigned int i = '0'; i <= '9'; i++ )
+ array['Z'-'A'+i-'0'] = i;
+
+ int z = m_index*barcode.sequence.step;
+ if( z < sizeof(array) )
+ temp[]
+ int v = array[ ]*/
+ }
+ }
+ }
+
+ text.replace( pos, 1, temp);
+ return text;
+}
+
+EEngine Barkode::engineForType( const QString & type )
+{
+ EEngine engine = NONE;
+
+ for( unsigned int i=0;i<s_info.count();i++)
+ if( s_info[i].xml == type )
+ {
+ engine = s_info[i].engine;
+ break;
+ }
+
+ return engine;
+}
+
+void Barkode::updateEngine()
+{
+ EEngine engine = engineForType( type() );
+
+ if( m_engine && engine != m_engine->engine() )
+ {
+ // switch to another engine
+ delete m_engine;
+ m_engine = NULL;
+ }
+
+ if( !m_engine )
+ {
+ if( engine == GNU_BARCODE )
+#ifdef _ENABLE_NATIVE_GNU_BARCODE
+ m_engine = new GnuBarcode();
+#else
+ m_engine = new PixmapBarcode();
+#endif // _ENABLE_NATIVE_GNU_BARCODE
+ else if( engine == TBARCODE )
+ m_engine = new PixmapBarcode();
+ else if( engine == TBARCODE2 )
+ m_engine = new TBarcode2();
+ else if( engine == PDF417 )
+ m_engine = new PixmapBarcode();
+ else if( engine == PURE_POSTSCRIPT )
+ m_engine = new PurePostscriptBarcode();
+ else
+ m_engine = new EmptyEngine();
+
+ m_engine->setBarkode( this );
+ }
+}
+
+void Barkode::drawBarcode( QPainter & painter, int x, int y )
+{
+ if( m_engine )
+ m_engine->drawBarcode( painter, x, y );
+}
+
+void Barkode::update( const QPaintDevice* device )
+{
+ if( m_engine )
+ m_engine->update( device );
+}
+
+////////////////////////////////////////////////////////////
+// Get attributes //
+////////////////////////////////////////////////////////////
+
+bool Barkode::isValid() const
+{
+ return m_valid;
+}
+
+const QColor & Barkode::background() const
+{
+ return m_background;
+}
+
+const QColor & Barkode::foreground() const
+{
+ return m_foreground;
+}
+
+const QColor & Barkode::textColor() const
+{
+ return m_textcolor;
+}
+
+const unsigned int Barkode::fontsize() const
+{
+ return m_fontsize;
+}
+
+const unsigned int Barkode::quietZone() const
+{
+ return m_quietzone;
+}
+
+const unsigned int Barkode::barHeight() const
+{
+ return m_bar_height;
+}
+
+const QString & Barkode::type() const
+{
+ return m_type;
+}
+
+const QString & Barkode::value() const
+{
+ return m_value;
+}
+
+const unsigned int Barkode::index() const
+{
+ return m_index;
+}
+
+const bool Barkode::sequenceEnabled() const
+{
+ return m_sequence;
+}
+
+const ESequence Barkode::sequenceMode() const
+{
+ return m_esequence;
+}
+
+const int Barkode::sequenceStart() const
+{
+ return m_sequence_start;
+}
+
+const int Barkode::sequenceStep() const
+{
+ return m_sequence_step;
+}
+
+const QString & Barkode::databaseMode() const
+{
+ return m_database_mode;
+}
+
+const bool Barkode::textVisible() const
+{
+ return m_text_visible;
+}
+
+const int Barkode::rotation() const
+{
+ return m_rotation;
+}
+
+const double Barkode::scaling() const
+{
+ return m_scaling;
+}
+
+const double Barkode::cut() const
+{
+ return m_cut;
+}
+
+const int Barkode::datamatrixSize() const
+{
+ return m_datamatrix_size;
+}
+
+////////////////////////////////////////////////////////////
+// Set attributes //
+////////////////////////////////////////////////////////////
+
+void Barkode::setBackground( const QColor & c )
+{
+ m_background = c;
+}
+
+void Barkode::setForeground( const QColor & c )
+{
+ m_foreground = c;
+}
+
+void Barkode::setTextColor( const QColor & c )
+{
+ m_textcolor = c;
+}
+
+void Barkode::setFontsize( unsigned int f )
+{
+ m_fontsize = f;
+}
+
+void Barkode::setQuietZone( const unsigned int q )
+{
+ m_quietzone = q;
+}
+
+void Barkode::setBarHeight( unsigned int h )
+{
+ m_bar_height = h;
+}
+
+void Barkode::setType( const QString & type )
+{
+ m_type = type.lower();
+ updateEngine();
+}
+
+void Barkode::setValue( const QString & value )
+{
+ m_value = value;
+}
+
+void Barkode::setIndex( const unsigned int i )
+{
+ m_index = i;
+}
+
+void Barkode::setSequenceEnabled( bool b )
+{
+ m_sequence = b;
+}
+
+void Barkode::setSequenceMode( ESequence e )
+{
+ m_esequence = e;
+}
+
+void Barkode::setSequenceStart( int s )
+{
+ m_sequence_start = s;
+}
+
+void Barkode::setSequenceStep( int s )
+{
+ m_sequence_step = s;
+}
+
+void Barkode::setDatabaseMode( const QString & mode )
+{
+ m_database_mode = mode;
+}
+
+void Barkode::setTextVisible( const bool b )
+{
+ m_text_visible = b;
+}
+
+void Barkode::setRotation( const int r )
+{
+ m_rotation = r;
+}
+
+void Barkode::setScaling( const double d )
+{
+ m_scaling = d;
+}
+
+void Barkode::setCut( const double c )
+{
+ m_cut = c;
+}
+
+void Barkode::setDatamatrixSize( int s )
+{
+ m_datamatrix_size = s;
+}
+
+////////////////////////////////////////////////////////////
+// Fill the s_info structure
+////////////////////////////////////////////////////////////
+
+bool Barkode::hasFeature( const QString & type, unsigned int feature )
+{
+ for( unsigned int i = 0; i < s_info.count(); i++ )
+ if( s_info[i].xml == type )
+ return (s_info[i].features & feature) == feature;
+
+ return false;
+}
+
+int Barkode::internalType( const QString & type )
+{
+ for( unsigned int i = 0; i < s_info.count(); i++ )
+ if( s_info[i].xml == type )
+ return s_info[i].internal;
+
+ return false;
+}
+
+const QStringList* Barkode::encodingTypes()
+{
+ if( !s_encoding )
+ {
+ s_encoding = new QStringList;
+ for( unsigned int i = 0; i < s_info.count(); i++ )
+ s_encoding->append( s_info[i].name );
+ //s_encoding->sort();
+ }
+
+ return s_encoding;
+}
+
+const char* Barkode::typeFromName( const QString & name )
+{
+ for( unsigned int i = 0; i < s_info.count(); i++ )
+ if( s_info[i].name == name )
+ return s_info[i].xml;
+
+ return NULL;
+}
+
+const char* Barkode::nameFromType( const QString & type )
+{
+ for( unsigned int i = 0; i < s_info.count(); i++ )
+ if( s_info[i].xml == type )
+ return s_info[i].name;
+
+ return NULL;
+}
+
+QString* Barkode::validatorFromType( const QString & type )
+{
+ for( unsigned int i = 0; i < s_info.count(); i++ )
+ if( s_info[i].xml == type )
+ return &(s_info[i].validator);
+
+ return NULL;
+}
+
+QString* Barkode::validatorNotFromType( const QString & type )
+{
+ for( unsigned int i = 0; i < s_info.count(); i++ )
+ if( s_info[i].xml == type )
+ return &(s_info[i].validatorNot);
+
+ return NULL;
+}
+
+tBarcodeInfo Barkode::createInfo( const char* xml, const QString & name, const EEngine engine,
+ const unsigned int features, const int internal )
+{
+ tBarcodeInfo info;
+ QString strengine;
+
+ switch( engine )
+ {
+ case GNU_BARCODE:
+ strengine = i18n(" [GNU Barcode]");
+ break;
+ case PDF417:
+ strengine = i18n(" [PDF 417]");
+ break;
+ case TBARCODE:
+ strengine = i18n(" [TBarcode]");
+ break;
+ case TBARCODE2:
+ strengine = i18n(" [TBarcode2]");
+ break;
+ case PURE_POSTSCRIPT:
+ strengine = i18n(" [Barcode Writer in Pure Postscript]");
+ break;
+ case NONE:
+ default:
+ // does not need to be translated as it should not visible anytime ever
+ strengine = " [NONE]";
+ break;
+ }
+
+ info.xml = xml;
+ info.name = name + strengine;
+ info.engine = engine;
+ info.features = features;
+ info.internal = internal;
+
+ return info;
+}
+
+void Barkode::initInfo()
+{
+ if( s_info.count() )
+ return;
+
+ PurePostscriptBarcode::init();
+
+ s_haveGnuBarcode = !KStandardDirs::findExe( "barcode" ).isNull();
+ s_havePdfEncode = !KStandardDirs::findExe( "pdf417_enc" ).isNull();
+ s_haveTBarcode = false; //!KStandardDirs::findExe( "tbarcodeclient" ).isNull();
+// TODO: do not yet enable TBarcode2 support
+ s_haveTBarcode2 = !KStandardDirs::findExe( "tbarcode" ).isNull();
+ s_havePurePostscript = !KStandardDirs::findExe( "gs" ).isNull()
+ && PurePostscriptBarcode::hasPurePostscriptBarcode();
+
+ if( s_haveGnuBarcode )
+ {
+ s_info.append( createInfo( "128raw", i18n("Raw code 128"), GNU_BARCODE, 0, BARCODE_128RAW ) );
+ s_info.append( createInfo( "cbr", i18n("Codabar"), GNU_BARCODE, 0, BARCODE_CBR ) );
+ s_info.append( createInfo( "cbr -c", i18n("Codabar (no checksum)"), GNU_BARCODE, 0, BARCODE_CBR ) );
+ s_info.append( createInfo( "code128", i18n("Code 128 (a,b,c: autoselection)"), GNU_BARCODE, 0, BARCODE_128 ) );
+ s_info.append( createInfo( "code128b", i18n("Code 128B, full printable ascii"), GNU_BARCODE, 0, BARCODE_128B ) );
+ s_info.append( createInfo( "code128c", i18n("Code 128C (compact form digits)"), GNU_BARCODE, 0, BARCODE_128C ) );
+ s_info.append( createInfo( "code39 -c", i18n("Code 39 (no checksum)"), GNU_BARCODE, 0, BARCODE_39 | BARCODE_NO_CHECKSUM ) );
+ s_info.append( createInfo( "code39", i18n("Code 39"), GNU_BARCODE, 0, BARCODE_39 ) );
+ s_info.append( createInfo( "code93", i18n("Code 93"), GNU_BARCODE, 0, BARCODE_93 ) );
+ s_info.append( createInfo( "ean", i18n("EAN (EAN 8 or EAN 13)"), GNU_BARCODE, 0, BARCODE_EAN ) );
+ s_info.append( createInfo( "i25 -c", i18n("interleaved 2 of 5 (only digits, no checksum)"), GNU_BARCODE, 0, BARCODE_I25 | BARCODE_NO_CHECKSUM ) );
+ s_info.append( createInfo( "i25", i18n("interleaved 2 of 5 (only digits)"), GNU_BARCODE, 0, BARCODE_I25 ) );
+ s_info.append( createInfo( "isbn", i18n("ISBN (still EAN13)"), GNU_BARCODE, NOCUT, BARCODE_ISBN ) );
+ s_info.append( createInfo( "msi", i18n("MSI"), GNU_BARCODE, 0, BARCODE_MSI ) );
+ s_info.append( createInfo( "pls", i18n("Plessey"), GNU_BARCODE, 0, BARCODE_PLS ) );
+ s_info.append( createInfo( "upc", i18n("UPC (12-digit EAN; UPCA and UPCB)"), GNU_BARCODE, 0, BARCODE_UPC ) );
+ }
+
+ if( s_havePdfEncode )
+ {
+ s_info.append( createInfo( "pdf417", i18n("pdf 417 2D Barcode"), PDF417, BARCODE2D | PDF417BARCODE ) );
+ }
+
+ if( s_havePurePostscript )
+ {
+ // add a leading "ps_" so that they do not conflict with GNU Barcode types
+ PurePostscriptBarcode::initInfo( &s_info );
+
+ /*
+ s_info.append( createInfo( "ps_auspost", i18n("Australian Post"), PURE_POSTSCRIPT, PUREADV | COLORED | NOCUT ) );
+ s_info.append( createInfo( "ps_code11", i18n("Code 11"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_code128", i18n("Code 128"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_code2of5", i18n("Code 2 of 5"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_code39", i18n("Code 39"), PURE_POSTSCRIPT, PUREADV | COLORED | MODULOALLCHECK ) );
+ s_info.append( createInfo( "ps_code93", i18n("Code 93"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_ean13", i18n("EAN 13"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_ean2", i18n("EAN 2"), PURE_POSTSCRIPT, PUREADV | COLORED | NOCUT ) );
+ s_info.append( createInfo( "ps_ean5", i18n("EAN 5"), PURE_POSTSCRIPT, PUREADV | COLORED | NOCUT ) );
+ s_info.append( createInfo( "ps_ean8", i18n("EAN 8"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_interleaved2of5", i18n("Interleaved 2 of 5"), PURE_POSTSCRIPT, PUREADV | COLORED | MODULOALLCHECK ) );
+ s_info.append( createInfo( "ps_isbn", i18n("ISBN"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_kix", i18n("Kix (Dutch Postal)"), PURE_POSTSCRIPT, PUREADV | COLORED | NOCUT ) );
+ s_info.append( createInfo( "ps_msi", i18n("MSI"), PURE_POSTSCRIPT, PUREADV | COLORED | MODULOALLCHECK ) );
+ s_info.append( createInfo( "ps_plessey", i18n("Plessey"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_postnet", i18n("Postnet"), PURE_POSTSCRIPT, PUREADV | COLORED | NOCUT ) );
+ s_info.append( createInfo( "ps_rationalizedCodabar", i18n("Rationalized Codabar"), PURE_POSTSCRIPT, PUREADV | COLORED | MODULOALLCHECK ) );
+ s_info.append( createInfo( "ps_royalmail", i18n("Royal Mail"), PURE_POSTSCRIPT, PUREADV | COLORED | NOCUT ) );
+ s_info.append( createInfo( "ps_symbol", i18n("Symbol"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_upca", i18n("UPCA"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ s_info.append( createInfo( "ps_upce", i18n("UPCE"), PURE_POSTSCRIPT, PUREADV | COLORED ) );
+ */
+ }
+
+ if( s_haveTBarcode )
+ {
+ s_info.append( createInfo( "b1", "Code 11", TBARCODE, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "b2", "Code 2 of 5 (Standard)", TBARCODE, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "b3", "Interleaved 2 of 5 Standard", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b4", "Code 2 of 5 IATA", TBARCODE, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "b5", "Code 2 of 5 Matrix", TBARCODE, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "b6", "Code 2 of 5 Data Logic", TBARCODE, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "b7", "Code 2 of 5 Industrial", TBARCODE, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "b8", "Code 3 of 9 (Code 39)", TBARCODE, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "b9", "Code 3 of 9 (Code 39) ASCII", TBARCODE, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "b10", "EAN8", TBARCODE, TBARCODEADV | EAN8CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "b11", "EAN8 - 2 digits add on", TBARCODE, NOCUT | TBARCODEADV | EAN8CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "b12", "EAN8 - 5 digits add on", TBARCODE, NOCUT | TBARCODEADV | EAN8CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "b13", "EAN13", TBARCODE, TBARCODEADV | EAN13CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "b14", "EAN13 - 2 digits add on", TBARCODE, NOCUT | TBARCODEADV | EAN13CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "b15", "EAN13 - 5 digits add on", TBARCODE, NOCUT | TBARCODEADV | EAN13CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "b16", "EAN128 (supports AIS)", TBARCODE, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "b17", "UPC 12 Digits", TBARCODE, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "b18", "CodaBar (2 width)", TBARCODE, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "b19", "CodaBar (18 widths)", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b20", "Code128", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b21", "Deutsche Post Leitcode", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b22", "Deutsche Post Identcode", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b25", "Code 93", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b26", "Identical to eBC_UPCA", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b33", "UCC128 (= EAN128)", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b34", "UPC A", TBARCODE, TBARCODEADV | TBARCODEADV | UPCACHECK ) );
+ s_info.append( createInfo( "b35", "UPC A - 2 digit add on", TBARCODE, TBARCODEADV | UPCACHECK ) );
+ s_info.append( createInfo( "b36", "UPC A - 5 digit add on", TBARCODE, TBARCODEADV | UPCACHECK ) );
+ s_info.append( createInfo( "b37", "UPC E", TBARCODE, TBARCODEADV | UPCECHECK ) );
+ s_info.append( createInfo( "b38", "UPC E - 2 digit add on", TBARCODE, TBARCODEADV | UPCECHECK ) );
+ s_info.append( createInfo( "b39", "UPC E - 5 digit add on", TBARCODE, TBARCODEADV | UPCECHECK ) );
+ s_info.append( createInfo( "b40", "PostNet ZIP (5d.)", TBARCODE, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "b41", "PostNet ZIP (5d.+CD)", TBARCODE, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "b42", "PostNet ZIP (8d.)", TBARCODE, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "b43", "PostNet ZIP+4 (5d.+4d.+CD)", TBARCODE, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "b44", "PostNet DPBC (5d.+4d.+2d.)", TBARCODE, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "b45", "PostNet DPBC (5d.+4d.+2d.+CD)", TBARCODE, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "b46", "Plessey Code", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b47", "MSI Code", TBARCODE, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "b50", "LOGMARS", TBARCODE, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "b55", "PDF417 - 2D bar code", TBARCODE, BARCODE2D | PDF417BARCODE ) );
+ s_info.append( createInfo( "b56", "PDF417 Truncated - 2D bar code", TBARCODE, BARCODE2D | PDF417BARCODE ) );
+ s_info.append( createInfo( "b57", "MaxiCode - 2D-bar code (Postscript only)", TBARCODE, BARCODE2D ) );
+ s_info.append( createInfo( "b58", "QR-Code", TBARCODE, BARCODE2D ) );
+ s_info.append( createInfo( "b59", "Code128 (CharSet A)", TBARCODE, TBARCODEADV | CODE128CHECK | MODULOALLCHECK ) );
+ s_info.append( createInfo( "b60", "Code128 (CharSet B)", TBARCODE, TBARCODEADV | CODE128CHECK | MODULOALLCHECK ) );
+ s_info.append( createInfo( "b61", "Code128 (CharSet C)", TBARCODE, TBARCODEADV | CODE128CHECK | MODULOALLCHECK ) );
+ s_info.append( createInfo( "b62", "Code 93 Ascii", TBARCODE, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "b63", "Australian Post Standard Customer", TBARCODE, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "b64", "Australian Post Customer 2", TBARCODE, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "b65", "Australian Post Customer 3", TBARCODE, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "b66", "Australian Post Reply Paid", TBARCODE, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "b67", "Australian Post Routing", TBARCODE, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "b68", "Australian Post Redirection", TBARCODE, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "b69", "ISBN Code (=EAN13P5)", TBARCODE, TBARCODEADV ) );
+ s_info.append( createInfo( "b70", "Royal Mail 4 State (RM4SCC)", TBARCODE, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "b71", "Data Matrix", TBARCODE, DATAMATRIX | BARCODE2D | NOSCALE ) );
+ }
+
+ if( s_haveTBarcode2 )
+ {
+ s_info.append( createInfo( "1", "Code 11", TBARCODE2, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "2", "Code 2 of 5 (Standard)", TBARCODE2, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "3", "Interleaved 2 of 5 Standard", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "4", "Code 2 of 5 IATA", TBARCODE2, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "5", "Code 2 of 5 Matrix", TBARCODE2, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "6", "Code 2 of 5 Data Logic", TBARCODE2, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "7", "Code 2 of 5 Industrial", TBARCODE2, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "8", "Code 3 of 9 (Code 39)", TBARCODE2, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "9", "Code 3 of 9 (Code 39) ASCII", TBARCODE2, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "10", "EAN8", TBARCODE2, TBARCODEADV | EAN8CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "11", "EAN8 - 2 digits add on", TBARCODE2, NOCUT | TBARCODEADV | EAN8CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "12", "EAN8 - 5 digits add on", TBARCODE2, NOCUT | TBARCODEADV | EAN8CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "13", "EAN13", TBARCODE2, TBARCODEADV | EAN13CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "14", "EAN13 - 2 digits add on", TBARCODE2, NOCUT | TBARCODEADV | EAN13CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "15", "EAN13 - 5 digits add on", TBARCODE2, NOCUT | TBARCODEADV | EAN13CHECK | MODULO10CHECK ) );
+ s_info.append( createInfo( "16", "EAN128", TBARCODE2, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "17", "UPC 12 Digits", TBARCODE2, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "18", "CodaBar (2 width)", TBARCODE2, TBARCODEADV | MODULO10CHECK ) );
+ //s_info.append( createInfo( "19", "CodaBar (18 widths)", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "20", "Code128", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "21", "Deutsche Post Leitcode", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "22", "Deutsche Post Identcode", TBARCODE2, TBARCODEADV ) );
+ //s_info.append( createInfo( "23", "Code 16K", TBARCODE2, TBARCODEADV ) );
+ //s_info.append( createInfo( "24", "Code 49", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "25", "Code 93", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "26", "UPC 25 (Identical to UPCA)", TBARCODE2, TBARCODEADV ) );
+ //s_info.append( createInfo( "27", "UPCD1", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "28", "Flattermarken", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "29", "RSS-14", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "30", "RSS Limited", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "31", "RSS Expanded", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "32", "Telepen Alpha", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "33", "UCC128 (= EAN128)", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "34", "UPC A", TBARCODE2, TBARCODEADV | TBARCODEADV | UPCACHECK ) );
+ s_info.append( createInfo( "35", "UPC A - 2 digit add on", TBARCODE2, TBARCODEADV | UPCACHECK ) );
+ s_info.append( createInfo( "36", "UPC A - 5 digit add on", TBARCODE2, TBARCODEADV | UPCACHECK ) );
+ s_info.append( createInfo( "37", "UPC E", TBARCODE2, TBARCODEADV | UPCECHECK ) );
+ s_info.append( createInfo( "38", "UPC E - 2 digit add on", TBARCODE2, TBARCODEADV | UPCECHECK ) );
+ s_info.append( createInfo( "39", "UPC E - 5 digit add on", TBARCODE2, TBARCODEADV | UPCECHECK ) );
+ s_info.append( createInfo( "40", "PostNet5", TBARCODE2, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "41", "PostNet6 (5+CD)", TBARCODE2, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "42", "PostNet9 (5+4)", TBARCODE2, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "43", "PostNet10 (5+4+CD)", TBARCODE2, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "44", "PostNet11 (5+4+2)", TBARCODE2, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "45", "PostNet12 (5+4+2+CD)", TBARCODE2, NOCUT | TBARCODEADV | POSTNETCHECK ) );
+ s_info.append( createInfo( "46", "Plessey Code", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "47", "MSI Code", TBARCODE2, TBARCODEADV | MODULO10CHECK ) );
+ s_info.append( createInfo( "48", "SSCC18", TBARCODE2, TBARCODEADV ) );
+ //s_info.append( createInfo( "49", "FIM", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "50", "LOGMARS", TBARCODE2, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "51", "Pharmacode One-Track", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "52", "Pharmacentralnumber", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "53", "Pharmacode Two-Track", TBARCODE2, TBARCODEADV ) );
+ //s_info.append( createInfo( "54", "General Parcel", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "55", "PDF417 - 2D bar code", TBARCODE2, BARCODE2D | PDF417BARCODE ) );
+ s_info.append( createInfo( "56", "PDF417 Truncated - 2D bar code", TBARCODE2, BARCODE2D | PDF417BARCODE ) );
+ s_info.append( createInfo( "57", "MaxiCode - 2D-bar code (Postscript only)", TBARCODE2, BARCODE2D ) );
+ s_info.append( createInfo( "58", "QR-Code", TBARCODE2, BARCODE2D ) );
+ s_info.append( createInfo( "59", "Code128 (CharSet A)", TBARCODE2, TBARCODEADV | CODE128CHECK | MODULOALLCHECK ) );
+ s_info.append( createInfo( "60", "Code128 (CharSet B)", TBARCODE2, TBARCODEADV | CODE128CHECK | MODULOALLCHECK ) );
+ s_info.append( createInfo( "61", "Code128 (CharSet C)", TBARCODE2, TBARCODEADV | CODE128CHECK | MODULOALLCHECK ) );
+ s_info.append( createInfo( "62", "Code 93 Ascii", TBARCODE2, TBARCODEADV | MODULOALLCHECK ) );
+ s_info.append( createInfo( "63", "Australian Post Standard Customer", TBARCODE2, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "64", "Australian Post Customer 2", TBARCODE2, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "65", "Australian Post Customer 3", TBARCODE2, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "66", "Australian Post Reply Paid", TBARCODE2, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "67", "Australian Post Routing", TBARCODE2, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "68", "Australian Post Redirection", TBARCODE2, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "69", "ISBN Code (=EAN13P5)", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "70", "Royal Mail 4 State (RM4SCC)", TBARCODE2, NOCUT | TBARCODEADV ) );
+ s_info.append( createInfo( "71", "Data Matrix", TBARCODE2, DATAMATRIX | BARCODE2D | NOSCALE ) );
+ s_info.append( createInfo( "72", "EAN-14", TBARCODE2, TBARCODEADV ) );
+ //s_info.append( createInfo( "73", "Codablock-E", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "74", "Codablock-F", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "75", "NVE-18", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "76", "Japanese Postal Code", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "77", "Korean Postal", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "78", "RSS-14 Truncated", TBARCODE2, BARCODE2D ) );
+ s_info.append( createInfo( "79", "RSS-14 Stacked", TBARCODE2, BARCODE2D ) );
+ s_info.append( createInfo( "80", "RSS-14 Stacked Omnidirektional", TBARCODE2, BARCODE2D ) );
+ s_info.append( createInfo( "81", "RSS Expanded Stacked", TBARCODE2, BARCODE2D ) );
+ s_info.append( createInfo( "82", "Planet 12 digits", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "83", "Planet 14 digits", TBARCODE2, TBARCODEADV ) );
+ s_info.append( createInfo( "84", "MicroPDF417", TBARCODE2, BARCODE2D ) );
+ }
+
+ Barkode::initValidators();
+}
+
+void Barkode::initValidators()
+{
+ QString path;
+ const char* rules = "/usr/share/libpostscriptbarcode/rules.xml";
+ if( QFile::exists( rules ) )
+ path = rules;
+ else
+ path = locate( "data", "kbarcode/rules.xml" );
+
+ QFile xml( path );
+ QDomDocument doc;
+ QDomElement root;
+ QDomNode n;
+ QString id;
+ QString* regular;
+ QString* regularNot;
+
+ if( !xml.open( IO_ReadOnly ) )
+ {
+ qDebug( "Cannot read validation rules from %s\n", path.latin1() );
+ return;
+ }
+
+ doc.setContent( &xml );
+ root = doc.documentElement();
+ n = root.firstChild();
+
+ while( !n.isNull() )
+ {
+ QDomElement e = n.toElement();
+ if( !e.isNull() && e.tagName() == "encoder" )
+ {
+ id = e.attribute( "id" );
+ id.prepend( "ps_" );
+ regular = Barkode::validatorFromType( id );
+ regularNot = Barkode::validatorNotFromType( id );
+
+ QDomNode child = e.firstChild();
+ while( !child.isNull() )
+ {
+ QDomElement e = child.toElement();
+ QString pattern = QString::null;
+
+ if( child.firstChild().isCDATASection() )
+ {
+ pattern = child.firstChild().toCDATASection().data().stripWhiteSpace();
+ }
+
+
+ if( !e.isNull() && e.tagName() == "pattern" )
+ {
+ QString sense = e.attribute( "sense", "true" );
+ if( sense == "true" )
+ *regular = pattern;
+ else
+ *regularNot = pattern;
+ }
+
+ child = child.nextSibling();
+ }
+ }
+
+ n = n.nextSibling();
+ }
+
+ xml.close();
+}
+
diff --git a/kbarcode/barkode.h b/kbarcode/barkode.h
new file mode 100644
index 0000000..4d7004b
--- /dev/null
+++ b/kbarcode/barkode.h
@@ -0,0 +1,297 @@
+/* This file is part of the KDE project
+ Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef BARKODE_H
+#define BARKODE_H
+
+
+#include <qcolor.h>
+#include <qstring.h>
+
+#include "barkodeengine.h"
+
+/**
+ * Enumeration values for sequence modes
+ */
+typedef enum { NUM, ALPHA, ALPHANUM } ESequence;
+
+/** This values are used to indicate the feature supported by a
+ * certain barcode typedef
+ */
+enum { NOCUT = 0x00001, MULTILINE = 0x00002, NOTEXT = 0x00004, NOSCALE = 0x00008,
+ /**
+ * Different advanced option modes.
+ */
+ PDF417BARCODE = 0x00100, TBARCODEADV = 0x00200, PUREADV = 0x00400, DATAMATRIX = 0x00800,
+ COLORED = 0x00010,
+
+ /**
+ * Checksum ID's
+ */
+ POSTNETCHECK = 0x01000, CODE128CHECK = 0x02000, EAN8CHECK = 0x04000, EAN13CHECK = 0x08000,
+ UPCACHECK = 0x10000, UPCECHECK = 0x20000, MODULOALLCHECK = 0x40000, MODULO10CHECK = 0x80000,
+
+ /**
+ * Short cut's
+ */
+ BARCODE2D = NOCUT | MULTILINE | NOTEXT };
+
+/** This structure holds information about a supported barcode encoding typedef
+ */
+typedef struct tBarcodeInfo
+{
+ /** the name which is stored for identification in the xml file
+ * and used as commandline parameter for external tools
+ */
+ QString xml;
+ /** the user visible name of this typedef
+ */
+ QString name;
+ /** the barcode engine to use
+ */
+ EEngine engine;
+ /** features supported by this type orred together
+ */
+ unsigned int features;
+
+ /** internal value (e.g. identifier of GNU Barcode)
+ */
+ int internal;
+
+ /** A regular expression that validates
+ * a value for this barcode.
+ */
+ QString validator;
+ QString validatorNot;
+};
+
+typedef QValueList<tBarcodeInfo> TBarcodeInfoList;
+
+class BarkodeEngine;
+class QPainter;
+class QPicture;
+class QSize;
+class QPaintDevice;
+class TokenProvider;
+
+class Barkode {
+ public:
+ Barkode();
+ Barkode( const Barkode & barkode );
+ virtual ~Barkode();
+
+ /** set a TokenProvider for data field parsing
+ */
+ void setTokenProvider( TokenProvider* token );
+
+ /** restore default values
+ */
+ void defaults();
+
+ /** call this method after you changed a property
+ * to update the internal structures
+ */
+ void update( const QPaintDevice* device );
+
+ /** get the barcode value after all sequences and datafields have
+ * been parsed
+ */
+ const QString parsedValue();
+
+ const QPixmap pixmap( double scalex = 1.0, double scaley = 1.0 );
+ const QPicture picture();
+ const QSize size() const;
+ bool isValid() const;
+
+ const QColor & background() const;
+ const QColor & foreground() const;
+ const QColor & textColor() const;
+ const unsigned int fontsize() const;
+ const unsigned int quietZone() const;
+ const unsigned int barHeight() const;
+ const QString & type() const;
+ const QString & value() const;
+ const bool sequenceEnabled() const;
+ const ESequence sequenceMode() const;
+ const int sequenceStart() const;
+ const int sequenceStep() const;
+ const QString & databaseMode() const;
+ const bool textVisible() const;
+ const int rotation() const;
+ const double scaling() const;
+ const unsigned int index() const;
+ const double cut() const;
+ const int datamatrixSize() const;
+
+ void setBackground( const QColor & c );
+ void setForeground( const QColor & c );
+ void setTextColor( const QColor & c );
+ void setFontsize ( unsigned int f );
+ void setQuietZone( unsigned int q );
+ void setBarHeight( unsigned int h );
+ void setType( const QString & type );
+ void setValue( const QString & value );
+ void setTextVisible( const bool b );
+ /** Set the index of the barcodes for barcode sequences.
+ */
+ void setIndex( unsigned int i );
+ void setSequenceEnabled( bool b );
+ void setSequenceMode( ESequence e );
+ void setSequenceStart( int s );
+ void setSequenceStep( int s );
+ void setDatabaseMode( const QString & mode );
+ void setRotation( const int r );
+ void setScaling( const double d );
+ void setCut( const double c );
+ void setDatamatrixSize( int s );
+
+ /** Sets the barcodes data structures
+ * the same as operator=
+ */
+ void setData( const Barkode & barkode );
+ void operator=( const Barkode & barkode );
+ bool operator==( const Barkode & barkode ) const;
+
+ inline BarkodeEngine* engine();
+ inline const BarkodeEngine* engine() const;
+
+ /** Test if the encodingType @p type has a certain
+ * @p feature, as defined in the codes QValueList.
+ */
+ static bool hasFeature( const QString & type, unsigned int feature );
+ /** Returns the internal value for the encoding type @p typedef
+ */
+ static int internalType( const QString & type );
+ /** Returns all supported encoding types
+ * ready for displaying them to the user
+ */
+ static const QStringList* encodingTypes();
+ /** Convert the uservisible encoding type @p name
+ * to the internal identifier
+ */
+ static const char* typeFromName( const QString & name );
+ /** Convert the internal identifier @p type
+ * to the user visible encoding name
+ */
+ static const char* nameFromType( const QString & type );
+
+ static QString* validatorFromType( const QString & type );
+ static QString* validatorNotFromType( const QString & type );
+
+ /** return the barcode generation engine for type @p typedef
+ */
+
+ static EEngine engineForType( const QString & type );
+ /** Draw an invalid barcode sign to QPainter @p painter
+ */
+ void drawInvalid( QPainter & painter, int x = 0, int y = 0 );
+
+ /** returns wether barcode functionallity
+ * is available
+ */
+ static bool haveBarcode() {
+ Barkode::initInfo();
+ return ( s_haveGnuBarcode || s_havePdfEncode || s_haveTBarcode || s_havePurePostscript );
+ }
+ static bool haveGNUBarcode() {
+ Barkode::initInfo();
+ return s_haveGnuBarcode;
+ }
+ static bool haveTBarcode() {
+ Barkode::initInfo();
+ return s_haveTBarcode;
+ }
+ static bool haveTBarcode2() {
+ Barkode::initInfo();
+ return s_haveTBarcode2;
+ }
+ static bool havePDFBarcode() {
+ Barkode::initInfo();
+ return s_havePdfEncode;
+ }
+ static bool havePurePostscriptBarcode() {
+ Barkode::initInfo();
+ return s_havePurePostscript;
+ }
+
+ static tBarcodeInfo createInfo( const char* xml, const QString & name, const EEngine engine,
+ const unsigned int features = 0, const int internal = 0 );
+
+ protected:
+ void drawBarcode( QPainter & painter, int x = 0, int y = 0 );
+
+ private:
+ static void initInfo();
+ static void initValidators();
+
+ void updateEngine();
+
+ protected:
+ BarkodeEngine* m_engine;
+ TokenProvider* m_token;
+
+ bool m_valid;
+ bool m_sequence;
+ ESequence m_esequence;
+ int m_sequence_start;
+ int m_sequence_step;
+ bool m_text_visible;
+
+ QColor m_background;
+ QColor m_foreground;
+ QColor m_textcolor;
+
+ unsigned int m_quietzone;
+ unsigned int m_bar_height;
+ unsigned int m_fontsize;
+ unsigned int m_index;
+ int m_datamatrix_size;
+ int m_rotation;
+
+ double m_scaling;
+ double m_cut; // temporarly used for the pixmap engines
+ // won't be needed for the Barkode engine
+
+ QString m_type;
+ QString m_value;
+ QString m_database_mode;
+
+ static TBarcodeInfoList s_info;
+ static QStringList* s_encoding;
+
+ static bool s_haveGnuBarcode;
+ static bool s_haveTBarcode;
+ static bool s_haveTBarcode2;
+ static bool s_havePdfEncode;
+ static bool s_havePurePostscript;
+};
+
+BarkodeEngine* Barkode::engine()
+{
+ return m_engine;
+}
+
+const BarkodeEngine* Barkode::engine() const
+{
+ return m_engine;
+}
+
+#endif // BARKODE_H
+
+
diff --git a/kbarcode/barkodeengine.cpp b/kbarcode/barkodeengine.cpp
new file mode 100644
index 0000000..f05440e
--- /dev/null
+++ b/kbarcode/barkodeengine.cpp
@@ -0,0 +1,55 @@
+/***************************************************************************
+ barkodeengine.cpp - description
+ -------------------
+ begin : Fri Nov 05 2004
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "barkodeengine.h"
+#include "barkode.h"
+
+BarkodeEngine::BarkodeEngine()
+{
+ m_valid = false;
+ barkode = NULL;
+}
+
+BarkodeEngine::~BarkodeEngine()
+{
+}
+
+BarkodeEngineOptions* BarkodeEngine::options()
+{
+ return NULL;
+}
+
+EmptyEngine::EmptyEngine()
+ : BarkodeEngine()
+{
+}
+
+void EmptyEngine::update( const QPaintDevice* )
+{
+ // Do nothing
+}
+
+const QSize EmptyEngine::size() const
+{
+ return QSize( 150, 80 );
+}
+
+void EmptyEngine::drawBarcode( QPainter & painter, int x, int y )
+{
+ barkode->drawInvalid( painter, x, y );
+}
+
diff --git a/kbarcode/barkodeengine.h b/kbarcode/barkodeengine.h
new file mode 100644
index 0000000..037667c
--- /dev/null
+++ b/kbarcode/barkodeengine.h
@@ -0,0 +1,103 @@
+/***************************************************************************
+ barkodeengine.h - description
+ -------------------
+ begin : Fri Nov 05 2004
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef BARKODEENGINE_H
+#define BARKODEENGINE_H
+
+/**
+ * The different generator backends / engines
+ */
+typedef enum { GNU_BARCODE, PDF417, TBARCODE, TBARCODE2, PIXMAP, PURE_POSTSCRIPT, NONE } EEngine;
+
+class Barkode;
+class QDomElement;
+class QPainter;
+
+/** An interface for additional special options
+ * supported by a BarkodeEngine
+ */
+class BarkodeEngineOptions {
+ public:
+ BarkodeEngineOptions() {};
+ virtual ~BarkodeEngineOptions() {};
+
+ virtual void defaults() = 0;
+
+ virtual void load( const QDomElement* tag ) = 0;
+ virtual void save( QDomElement* tag ) = 0;
+};
+
+#include <qsize.h>
+
+/**
+ * Inherit from this class if you want to create a
+ * (barkode engine) for use with KBarcode.
+ * @author Dominik Seichter
+ */
+class BarkodeEngine{
+ public:
+ BarkodeEngine();
+ virtual ~BarkodeEngine();
+
+ virtual const BarkodeEngine & operator=( const BarkodeEngine & rhs ) = 0;
+
+ virtual EEngine engine() const = 0;
+ virtual void update( const QPaintDevice* device ) = 0;
+ virtual const QSize size() const = 0;
+
+ void setBarkode( Barkode* b ) { barkode = b; }
+ virtual void drawBarcode( QPainter & painter, int x, int y ) = 0;
+
+ /** @returns a pointer to a BarkodeEngineOptions object
+ * if this BarkodeEngine has one. Otherwise null is returned.
+ * The returned object has to be casted down to the concrete object
+ * you want to use, before setting any of the options.
+ */
+ virtual BarkodeEngineOptions* options();
+
+ protected:
+ Barkode* barkode;
+ QSize m_size;
+
+ bool m_valid;
+};
+
+/** A barcode engine with implemented empty and does
+ * nothing
+ */
+class EmptyEngine : public BarkodeEngine {
+ public:
+ EmptyEngine();
+
+ virtual inline const BarkodeEngine & operator=( const BarkodeEngine & rhs );
+ virtual inline EEngine engine() const;
+ virtual void update( const QPaintDevice* device );
+ virtual const QSize size() const;
+ virtual void drawBarcode( QPainter & painter, int x, int y );
+};
+
+const BarkodeEngine & EmptyEngine::operator=( const BarkodeEngine & )
+{
+ return *this;
+}
+
+EEngine EmptyEngine::engine() const
+{
+ return NONE;
+}
+
+#endif
diff --git a/kbarcode/batchiface.h b/kbarcode/batchiface.h
new file mode 100644
index 0000000..6eb6586
--- /dev/null
+++ b/kbarcode/batchiface.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ batchiface.h - description
+ -------------------
+ begin : Sat Dec 27 23:54:28 CET 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef BATCHIFACE_H
+#define BATCHIFACE_H
+
+#include <dcopobject.h>
+#include <qstringlist.h>
+#include "batchprinter.h"
+
+class BatchIface : virtual public DCOPObject
+{
+ K_DCOP
+
+ public:
+ k_dcop:
+ virtual void setFilename( const QString & url ) = 0;
+ virtual void setImportCsvFile( const QString & filename ) = 0;
+ virtual void setImportSqlQuery( const QString & query ) = 0;
+ virtual void setNumLabels( const int n ) = 0;
+ virtual void setOutputFormat( const int e ) = 0;
+ virtual void setSerialNumber( const QString & val, int inc ) = 0;
+
+ virtual bool addItem( const QString & article, const QString & group, int count = 1, bool msg = true ) = 0;
+ virtual bool existsArticle( const QString & article ) = 0;
+ virtual void loadFromFile( const QString & url ) = 0;
+ virtual void loadFromClipboard() = 0;
+ virtual void printNow( const QString & printer, bool bUserInteraction = true ) = 0;
+};
+
+#endif /* BATCHIFACE_H */
+
diff --git a/kbarcode/batchprinter.cpp b/kbarcode/batchprinter.cpp
new file mode 100644
index 0000000..9ca66c3
--- /dev/null
+++ b/kbarcode/batchprinter.cpp
@@ -0,0 +1,542 @@
+/***************************************************************************
+ batchprinter.cpp - description
+ -------------------
+ begin : Sat Jan 10 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#include "batchprinter.h"
+
+#include "definition.h"
+#include "kbarcode.h"
+#include "label.h"
+#include "printersettings.h"
+#include "zplutils.h"
+#include "tec.h"
+
+// Qt includes
+#include <qfile.h>
+#include <qpainter.h>
+#include <qpaintdevicemetrics.h>
+#include <qprogressdialog.h>
+
+// KDE includes
+#include <kabc/addressee.h>
+#include <kabc/addresseelist.h>
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kimageio.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kprinter.h>
+
+// Other includes
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <krun.h>
+#define MAXDATASIZE 32550
+
+BatchPrinter::BatchPrinter( KPrinter* p, QWidget* _parent )
+ : printer( p ), parent( _parent )
+{
+ m_events = true;
+ m_data = NULL;
+ m_vardata = NULL;
+ m_addrdata = NULL;
+
+ m_cur_data_count = 0;
+
+ m_paintDevice = p;
+}
+
+BatchPrinter::BatchPrinter( const QString & path, QWidget* p )
+ : m_path( path ), parent( p )
+{
+ m_data = NULL;
+ m_vardata = NULL;
+ m_addrdata = NULL;
+ m_move = 0;
+ m_image_filename = E_BARCODE;
+
+ m_cur_data_count = 0;
+
+ m_paintDevice = p;
+}
+
+BatchPrinter::BatchPrinter( const QString & path, int format, QWidget* _parent )
+ : m_path( path ), m_bcp_format( format ), parent( _parent )
+{
+ m_data = NULL;
+ m_vardata = NULL;
+ m_addrdata = NULL;
+ m_move = 0;
+ m_image_filename = E_BARCODE;
+
+ m_cur_data_count = 0;
+
+ m_paintDevice = _parent;
+}
+
+BatchPrinter::~BatchPrinter()
+{
+ delete m_data;
+ delete m_vardata;
+ delete m_addrdata;
+}
+
+void BatchPrinter::start()
+{
+ painter = new QPainter( printer );
+ m_cur_data_count = 0;
+
+ QPaintDeviceMetrics pdm( painter->device() );
+
+ pageh = pdm.height(); // in pixel
+
+ curw = 0;
+ curh = 0;
+ c_h = 0;
+ c_w = 0;
+
+ QProgressDialog* progress = createProgressDialog( i18n("Printing...") );
+
+ m_measure = def->getMeasurements();
+
+ moveLabels();
+ if( m_data )
+ startPrintData( progress );
+ else if( m_vardata || m_addrdata )
+ startPrintVarData( progress );
+
+ painter->end();
+ delete progress;
+ delete painter;
+}
+
+void BatchPrinter::startPrintData( QProgressDialog* progress )
+{
+ labelprinterdata* lpdata = PrinterSettings::getInstance()->getData();
+
+ unsigned int index = 0; // counter gets increased for every label, but not for
+ // labels like article_no etc. (those who are created
+ // by events.
+
+ for( unsigned int i = 0; i < m_data->count(); i++ )
+ {
+ Label l( def, buffer, m_name, printer, m_customer,
+ (*m_data)[i].article_no, (*m_data)[i].group );
+ l.setSerial( m_serial, m_increment );
+
+ bool newgroup = false;
+ if( i == 0 )
+ newgroup = true;
+ else {
+ if( (*m_data)[i].group != (*m_data)[i-1].group )
+ newgroup = true;
+ }
+
+ if( !curw )
+ curw = m_measure.gapLeft( printer );
+
+ if( !curh )
+ curh = m_measure.gapTop( printer );
+
+ if( m_events ) {
+ if( newgroup ) {
+ proccessEvents( lpdata->groupEvent1, i18n("Group : ") + (*m_data)[i].group, &l );
+ proccessEvents( lpdata->groupEvent2, i18n("Group : ") + (*m_data)[i].group, &l );
+ proccessEvents( lpdata->groupEvent3, i18n("Group : ") + (*m_data)[i].group, &l );
+ proccessEvents( lpdata->groupEvent4, i18n("Group : ") + (*m_data)[i].group, &l );
+ }
+ proccessEvents( lpdata->articleEvent1, i18n("Article No. : ") + (*m_data)[i].article_no, &l );
+ proccessEvents( lpdata->articleEvent2, i18n("Article No. : ") + (*m_data)[i].article_no, &l );
+ proccessEvents( lpdata->articleEvent3, i18n("Article No. : ") + (*m_data)[i].article_no, &l );
+ proccessEvents( lpdata->articleEvent4, i18n("Article No. : ") + (*m_data)[i].article_no, &l );
+ }
+
+ for( int z = 0; z < (*m_data)[i].number; z++ ) {
+ changeLine();
+ checkForNewPage( &l );
+
+ painter->setClipRect((int)curw, (int)curh, (int)m_measure.width( printer ), (int)m_measure.height( printer ));
+ l.setIndex( index );
+ l.setRow( c_w );
+ l.setCol( c_h );
+ painter->save();
+ l.draw( painter, (int)curw, (int)curh );
+ painter->restore();
+
+ //painter->drawPicture( (int)curw, (int)curh, *l.picture() );
+ index++;
+ painter->setClipping( false );
+
+ drawBorders();
+
+ curw += m_measure.gapH( printer );
+ c_h++;
+
+ if( !checkProgressDialog( progress) ) {
+ printer->abort();
+ painter->end();
+ return;
+ }
+ }
+ }
+}
+
+void BatchPrinter::startPrintVarData( QProgressDialog* progress )
+{
+ Label* l;
+ while( ( l = initLabel() ) != NULL )
+ {
+ if( !curw )
+ curw = m_measure.gapLeft( printer );
+
+ if( !curh )
+ curh = m_measure.gapTop( printer );
+
+ changeLine();
+ checkForNewPage( l );
+
+ painter->setClipRect((int)curw, (int)curh, (int)m_measure.width( printer ), (int)m_measure.height( printer ));
+
+ painter->save();
+ l->draw( painter, (int)curw, (int)curh );
+ delete l;
+ painter->restore();
+
+ painter->setClipping( false );
+
+ drawBorders();
+
+ curw += m_measure.gapH( printer );
+ c_h++;
+
+ if( !checkProgressDialog( progress) )
+ {
+ printer->abort();
+ painter->end();
+ return;
+ }
+ }
+}
+
+Label* BatchPrinter::initLabel( int* number )
+{
+ Label* l = NULL;
+
+ if( (m_vardata && m_cur_data_count >= m_vardata->count() ) ||
+ (m_data && m_cur_data_count >= m_data->count() ) ||
+ (m_addrdata && m_cur_data_count >= m_addrdata->count() ) )
+ return NULL;
+
+ if( number )
+ *number = 1;
+
+ if( m_vardata )
+ {
+ l = new Label( def, buffer, m_name, m_paintDevice );
+ l->setUserVars( (*m_vardata)[m_cur_data_count] );
+ }
+ else if( m_data )
+ {
+ l = new Label( def, buffer, m_name, m_paintDevice, m_customer,
+ (*m_data)[m_cur_data_count].article_no, (*m_data)[m_cur_data_count].group );
+ if( number )
+ *number = (*m_data)[m_cur_data_count].number;
+ }
+ else if( m_addrdata )
+ {
+ l = new Label( def, buffer, m_name, m_paintDevice );
+ l->setAddressee( &((*m_addrdata)[m_cur_data_count]) );
+ }
+
+ l->setSerial( m_serial, m_increment );
+ l->setIndex( m_cur_data_count );
+ m_cur_data_count++;
+
+ return l;
+}
+
+void BatchPrinter::startImages()
+{
+ QProgressDialog* progress = createProgressDialog( i18n("Creating Images...") );
+
+ int number = 0;
+ m_cur_data_count = 0;
+
+ Measurements measure = def->getMeasurements();
+ Label* l = NULL;
+ painter = new QPainter();
+ QPixmap pixmap( (int)measure.width( parent ), (int)measure.height( parent ) );
+ while( (l = initLabel( &number ) ) != NULL )
+ {
+ for( int i = 0; i < number; i++ )
+ {
+ pixmap.fill( Qt::white );
+ painter->begin( &pixmap );
+ l->setIndex( i );
+ l->setRow( 0 );
+ l->setCol( 0 );
+ l->draw( painter, 0, 0 );
+
+ painter->end();
+
+ QString name = m_path + "/";
+ if( m_image_filename == E_ARTICLE )
+ name += m_data ? (*m_data)[m_cur_data_count].article_no : QString::number( m_cur_data_count );
+ else if( m_image_filename == E_BARCODE )
+ name += l->barcodeNo();
+ else
+ name += m_image_custom_filename;
+
+ QString filename = name + QString("_%1.").arg( i ) + KImageIO::suffix( m_image_format );
+
+ unsigned int c = 0;
+ while( QFile::exists( filename ) ) {
+ filename += "." + QString::number( c );
+ c++;
+ }
+
+ pixmap.save( filename, m_image_format );
+
+ if( !checkProgressDialog( progress ) )
+ {
+ delete l;
+ delete progress;
+ delete painter;
+ return;
+ }
+ }
+
+ delete l;
+ }
+
+ delete progress;
+ delete painter;
+
+ new KRun( m_path );
+}
+
+void BatchPrinter::startBCP()
+{
+ int number = 0;
+ QFile file( m_path );
+ if( !file.open( IO_WriteOnly ) ) // | IO_Raw ) )
+ {
+ KMessageBox::error( parent, QString( i18n("<qt>Can't open the file or device <b>%1</b></qt>.") ).arg( m_path ) );
+ return;
+ }
+
+ QProgressDialog* progress = createProgressDialog( i18n("Printing...") );
+
+ if( m_bcp_format == PrinterSettings::ZEBRA )
+ // Zebra printers are printed at 304dpi, this should
+ // be user defined, though
+ m_paintDevice = new BarcodePrinterDevice( 304.0, 304.0 );
+ else if( m_bcp_format == PrinterSettings::INTERMEC )
+ m_paintDevice = new BarcodePrinterDevice( 300.0, 300.0 );
+ else if( m_bcp_format == PrinterSettings::TEC )
+ // don't know which resolution is used for tec printers
+ // so we use a factor to convert everything to mm
+ // this is not accurate as QPaintDevice supports only integers
+ m_paintDevice = new BarcodePrinterDevice( 25.4000508001016, 25.4000508001016 );
+ else if( m_bcp_format == PrinterSettings::EPCL )
+ m_paintDevice = new BarcodePrinterDevice( 304.0, 304.0 );
+
+
+ QTextStream stream( &file );
+ Label* l;
+ while( ( l = initLabel( &number ) ) != NULL )
+ {
+ for( int i = 0; i < number; i++ )
+ {
+ switch( m_bcp_format )
+ {
+ case PrinterSettings::TEC:
+ // TODO: normally you should not care about the number or counter
+ // KBarcode will ensure that the label is printed often enough
+ if( m_data )
+ stream << tec452(m_name, (*m_data)[m_cur_data_count].number, (*m_data)[m_cur_data_count].article_no, (*m_data)[m_cur_data_count].group, m_customer);
+ else
+ /* TODO */;
+ #warning "TEC requires Old KBarcode SQL tables for printing"
+ qDebug( "TEC requires Old KBarcode SQL tables for printing" );
+ break;
+ case PrinterSettings::ZEBRA:
+ l->zpl( &stream );
+ break;
+ case PrinterSettings::INTERMEC:
+ l->ipl( &stream );
+ break;
+ case PrinterSettings::EPCL:
+ l->epcl( &stream );
+ break;
+ default:
+ break;
+ }
+
+ if( !checkProgressDialog( progress ) )
+ {
+ delete l;
+ delete progress;
+ delete m_paintDevice;
+ m_paintDevice = NULL;
+
+ file.close();
+
+ return;
+ }
+ }
+ delete l;
+ }
+
+ delete progress;
+ delete m_paintDevice;
+ m_paintDevice = NULL;
+
+ file.close();
+}
+
+void BatchPrinter::checkForNewPage( Label* label )
+{
+ if( curh + m_measure.height( printer ) > pageh || c_w == m_measure.numV() ) {
+ printer->newPage();
+ label->setPage( label->page() + 1 );
+ curh = m_measure.gapTop( printer );
+ curw = m_measure.gapLeft( printer );
+ c_w = 0;
+ }
+}
+
+void BatchPrinter::drawBorders()
+{
+ if( PrinterSettings::getInstance()->getData()->border ) {
+ painter->setPen( QPen( Qt::black, 1 ) );
+ painter->drawRect( (int)curw, (int)curh,
+ (int)m_measure.width( painter->device() ),
+ (int)m_measure.height( painter->device() ) );
+ }
+}
+
+void BatchPrinter::changeLine()
+{
+ if( c_h >= m_measure.numH() ) {
+ c_h = 0;
+ curw = m_measure.gapLeft( printer );
+ curh += m_measure.gapV( printer );
+ c_w++;
+ }
+}
+
+void BatchPrinter::proccessEvents( int lb, QString value, Label* label )
+{
+ if( lb == NEW_PAGE ) {
+ if( curh > m_measure.gapTop( printer ) || curw > m_measure.gapLeft( printer ) ) {
+ printer->newPage();
+ label->setPage( label->page() + 1 );
+ curh = m_measure.gapTop( printer );
+ curw = m_measure.gapLeft( printer );
+ c_h = 0;
+ c_w = 0;
+ }
+ }
+
+ if( lb == LINE_BREAK )
+ changeLine();
+
+ if( lb == ARTICLE_GROUP_NO )
+ printXLabel( lb, label, value );
+
+
+ if( lb == LABEL_X )
+ printXLabel( lb, label, QString::null );
+}
+
+void BatchPrinter::printXLabel( int lb, Label* label, const QString & value )
+{
+ changeLine();
+ checkForNewPage( label );
+
+ Label::getXLabel( curw, curh, m_measure.width( printer ), m_measure.height( printer ), painter, lb, value );
+
+ drawBorders();
+
+ curw += + m_measure.gapH( printer );
+ c_h++;
+}
+
+void BatchPrinter::moveLabels()
+{
+ for( unsigned int i = 0; i < m_move; i++ )
+ {
+ if( !curw )
+ curw = m_measure.gapLeft( printer );
+
+ if( !curh )
+ curh = m_measure.gapTop( printer );
+
+ changeLine();
+
+ if( curh + m_measure.height( printer ) > pageh || c_w == m_measure.numV() )
+ {
+ c_w = 0;
+ curh = m_measure.gapTop( printer );
+ curw = m_measure.gapLeft( printer );
+ }
+
+ curw += m_measure.gapH( printer );
+ c_h++;
+ }
+}
+
+QProgressDialog* BatchPrinter::createProgressDialog( const QString & caption )
+{
+ QProgressDialog* progress = new QProgressDialog( caption, i18n("&Cancel"), m_labels+1, parent );
+ progress->setProgress( 0 );
+ progress->show();
+ return progress;
+}
+
+bool BatchPrinter::checkProgressDialog( QProgressDialog* progress )
+{
+ kapp->processEvents( 0 );
+ progress->setProgress( progress->progress() + 1 );
+ if( progress->wasCancelled() ) {
+ delete progress;
+ return false;
+ }
+ return true;
+}
+
+void BatchPrinter::setData( QValueList<data>* list )
+{
+ if( m_data )
+ delete m_data;
+ m_data = list;
+}
+
+void BatchPrinter::setData( TVariableList* list )
+{
+ if( m_vardata )
+ delete m_vardata;
+ m_vardata = list;
+}
+
+void BatchPrinter::setData( KABC::AddresseeList* list )
+{
+ if( m_addrdata )
+ delete m_addrdata;
+ m_addrdata = list;
+}
+
diff --git a/kbarcode/batchprinter.h b/kbarcode/batchprinter.h
new file mode 100644
index 0000000..c189183
--- /dev/null
+++ b/kbarcode/batchprinter.h
@@ -0,0 +1,212 @@
+/***************************************************************************
+ batchprinter.h - description
+ -------------------
+ begin : Sat Jan 10 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef BATCHPRINTER_H
+#define BATCHPRINTER_H
+
+#include "measurements.h"
+
+#include <qmap.h>
+#include <qvaluelist.h>
+
+namespace KABC {
+ class AddresseeList;
+}
+
+class Definition;
+class Label;
+class KPrinter;
+class Measurements;
+class QBuffer;
+class QPainter;
+class QProgressDialog;
+class QWidget;
+class QPaintDevice;
+
+typedef QValueList< QMap<QString,QString> > TVariableList;
+/**
+ This class is responsible for batch printing of articles.
+ It is also responsible for creating images of all articles.
+ @author Dominik Seichter
+*/
+class BatchPrinter
+{
+ public:
+ typedef enum EOutputFormat { POSTSCRIPT = 0, IMAGE, BCP };
+ enum EImageFileName { E_ARTICLE, E_BARCODE, E_CUSTOM };
+
+ struct data {
+ int number;
+ QString article_no;
+ QString group;
+ };
+
+ /** Use this constructor if you want to print to
+ * a printer.
+ */
+ BatchPrinter( KPrinter* p, QWidget* _parent );
+ /** This constructor is used in image gernaration mode.
+ * @p path is the path to an existing directory where
+ * the images are saved.
+ */
+ BatchPrinter( const QString & path, QWidget* p );
+
+ /** Use this constructor to print to a barcode printer @p path
+ * with format @p format
+ */
+ BatchPrinter( const QString & path, int format, QWidget* _parent );
+
+ ~BatchPrinter();
+
+ inline void setBuffer( QBuffer* b ) { buffer = b; }
+ void setCustomer( const QString & s ) { m_customer = s; }
+
+ /** Specify the label on which is printed first on the page.
+ * The first label on the page (top/left) has the index 1,
+ * the second label is index 2 ...
+ */
+ inline void setMove( int m ) {
+ m_move = m > 0 ? --m : 0;
+ }
+
+ /** set the sql data for the batchprinter
+ * @p list will be deleted by the batchprinter
+ */
+ void setData( QValueList<data>* list );
+
+ /** set the variable data for the batchprinter
+ * @p list will be deleted by the batchprinter
+ */
+ void setData( TVariableList* list );
+
+ /** set the address data for the batchprinter
+ * @p list will be deleted by the batchprinter
+ */
+ void setData( KABC::AddresseeList* list );
+
+ inline void setImageFilename( const EImageFileName e ) { m_image_filename = e; }
+ inline void setImageCustomFilename( const QString & name ) { m_image_custom_filename = name; };
+ inline void setImageFormat( const QString & f ) { m_image_format = f; }
+ inline void setSerial( const QString & s, unsigned int inc ) { m_serial = s; m_increment = inc; }
+ inline void setName( const QString & s ) { m_name = s; }
+ inline void setDefinition( Definition* d ) { def = d; }
+ inline void setLabels( int l ) { m_labels = l; }
+ inline void setEvents( bool b ) { m_events = b; }
+
+ /** start the batch printing on a printer
+ */
+ void start();
+ /** start image generation
+ */
+ void startImages();
+ /** start printing to a barcode printer
+ */
+ void startBCP();
+ private:
+ /** create a label which gets intialized either with m_vardata or m_data
+ * @p number is set to the number of times this label should be printed.
+ */
+ Label* initLabel( int* number = NULL );
+
+ /** starts a new page on the printer, if the
+ * current label does not fit anymore on the current pageh
+ */
+ void checkForNewPage( Label* label );
+ /** draw a border around the current label using QPainter @p painter
+ */
+ void drawBorders();
+ /** start a "new line" on the printer,
+ * i.e. beginn the second row of labels
+ * on the page.
+ */
+ void changeLine();
+ void proccessEvents( int lb, QString value = QString::null, Label* label = 0 );
+ void printXLabel( int lb, Label* label, const QString & value );
+ void moveLabels();
+
+ /** print the labels using data from the m_data structure
+ */
+ void startPrintData( QProgressDialog* progress );
+ /** print the labels using data from the m_vardata or m_addrdata structure
+ */
+ void startPrintVarData( QProgressDialog* progress );
+
+ /** Create and return a progressdialog
+ */
+ QProgressDialog* createProgressDialog( const QString & caption );
+ bool checkProgressDialog( QProgressDialog* progress );
+
+ Definition* def;
+ Measurements m_measure;
+ QValueList<data>* m_data;
+ TVariableList* m_vardata;
+ KABC::AddresseeList* m_addrdata;
+
+ QString m_serial;
+ QString m_name;
+ QString m_customer;
+ /** Path for image output
+ * or device for bcp output
+ */
+ QString m_path;
+ /** defines the image format to be used
+ */
+ QString m_image_format;
+
+ unsigned int m_cur_data_count;
+
+ /** format for bcp output
+ */
+ int m_bcp_format;
+
+ /** defines the format of the filename for images
+ */
+ EImageFileName m_image_filename;
+
+ /** prefix for custom filenames if m_image_filename = E_CUSTOM
+ */
+ QString m_image_custom_filename;
+
+ /** enable/disable events
+ */
+ bool m_events;
+
+ unsigned int m_increment;
+ unsigned int m_move;
+ /** number of labels to print for the progress dialog
+ */
+ unsigned int m_labels;
+
+ /** height of the current page in pixel.
+ */
+ double pageh;
+ double curw;
+ double curh;
+ int c_h;
+ int c_w;
+
+ QPaintDevice* m_paintDevice;
+
+ QBuffer* buffer;
+ KPrinter* printer;
+ QPainter* painter;
+ /** parent for dialogs
+ */
+ QWidget* parent;
+};
+
+#endif
diff --git a/kbarcode/batchwizard.cpp b/kbarcode/batchwizard.cpp
new file mode 100644
index 0000000..defcca8
--- /dev/null
+++ b/kbarcode/batchwizard.cpp
@@ -0,0 +1,1263 @@
+/***************************************************************************
+ batchwizard.cpp - description
+ -------------------
+ begin : Sun Mar 20 2005
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "batchwizard.h"
+#include "batchwizard.moc"
+#include "barcodeprinterdlg.h"
+#include "batchprinter.h"
+#include "csvfile.h"
+#include "definition.h"
+#include "encodingcombo.h"
+#include "printersettings.h"
+#include "printlabeldlg.h"
+#include "smalldialogs.h"
+#include "sqltables.h"
+#include "tokenprovider.h"
+#include "xmlutils.h"
+
+#include <qbuffer.h>
+#include <qcheckbox.h>
+#include <qclipboard.h>
+#include <qcursor.h>
+#include <qdom.h>
+#include <qheader.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qradiobutton.h>
+#include <qsqlselectcursor.h>
+#include <qtooltip.h>
+#include <qvbuttongroup.h>
+#include <qwidgetstack.h>
+
+#include <kabc/addressee.h>
+#include <kabc/addresseelist.h>
+#include <kabc/addressbook.h>
+#include <kabc/stdaddressbook.h>
+#include <kapplication.h>
+#include <kcombobox.h>
+#include <kcompletion.h>
+#include <kfiledialog.h>
+#include <kiconloader.h>
+#include <kimageio.h>
+#include <klineedit.h>
+#include <klistbox.h>
+#include <klistview.h>
+#include <kmessagebox.h>
+#include <knuminput.h>
+#include <kpopupmenu.h>
+#include <kpushbutton.h>
+#include <kurlrequester.h>
+#include <qtable.h>
+#include <qvbox.h>
+
+#define PNG_FORMAT "PNG"
+
+class AddressListViewItem : public KListViewItem {
+public:
+ AddressListViewItem(QListView *parent, KABC::Addressee & addr )
+ : KListViewItem( parent ), m_address( addr )
+ {
+ this->setText( 0, m_address.givenName() );
+ this->setText( 1, m_address.familyName() );
+ this->setText( 2, m_address.preferredEmail() );
+ }
+
+ const KABC::Addressee & address() const {
+ return m_address;
+ }
+
+private:
+ KABC::Addressee m_address;
+
+};
+
+BatchWizard::BatchWizard( QWidget* parent, const char* name )
+ : DCOPObject("BatchPrinting"),
+ KWizard( parent, name )
+{
+ setupPage1();
+ setupPage2();
+ setupPage3();
+ setupPage4();
+ setupPage5();
+ setupPage10();
+
+ compGroup = new KCompletion();
+
+ enableControls();
+ setupSql();
+
+ show();
+}
+
+BatchWizard::~BatchWizard()
+{
+ delete compGroup;
+}
+
+void BatchWizard::setupPage1()
+{
+ page1 = new QWidget( this, "page1" );
+ QVBoxLayout* pageLayout = new QVBoxLayout( page1, 11, 6, "pageLayout");
+
+ QLabel* label = new QLabel( i18n("<qt>This wizard will guide you through the process "
+ "of printing many labels with KBarcode.<br>The first step "
+ "is to select the KBarcode label file you want to print.</qt>"), page1 );
+ pageLayout->addWidget( label );
+
+ m_url = new KURLRequester( page1 );
+ m_url->setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly );
+ m_url->setFilter( "*.kbarcode" );
+
+ label = new QLabel( i18n("&Filename:"), page1 );
+ label->setBuddy( m_url );
+
+ QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding );
+
+ pageLayout->addWidget( label );
+ pageLayout->addWidget( m_url );
+ pageLayout->addItem( spacer );
+
+ addPage( page1, i18n("File Selection") );
+
+ connect( m_url, SIGNAL( textChanged( const QString & ) ), this, SLOT( enableControls() ) );
+}
+
+void BatchWizard::setupPage2()
+{
+ page2 = new QWidget( this, "page2" );
+ QVBoxLayout* pageLayout = new QVBoxLayout( page2, 11, 6, "pageLayout");
+
+ QVButtonGroup* group = new QVButtonGroup( page2 );
+
+ radioSimple = new QRadioButton( i18n("Print &labels without data"), group );
+ radioSqlArticles = new QRadioButton( i18n("Print &articles from KBarcodes SQL database"), group );
+ radioVarImport = new QRadioButton( i18n("Import &variables and print"), group );
+ radioAddressBook = new QRadioButton( i18n("Print &contacts from your addressbook"), group );
+ radioSimple->setChecked( true );
+
+ QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding );
+ pageLayout->addWidget( group );
+ pageLayout->addItem( spacer );
+
+ connect( radioSimple, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioSqlArticles, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioVarImport, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioAddressBook, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+
+ addPage( page2, i18n("Data Source") );
+}
+
+void BatchWizard::setupPage3()
+{
+ page3 = new QWidgetStack( this, "page3" );
+
+ setupStackPage1();
+ setupStackPage2();
+ setupStackPage3();
+ setupStackPage4();
+
+ addPage( page3, i18n("Print Data") );
+}
+
+void BatchWizard::setupPage4()
+{
+ page4 = new QVBox( this, "page4" );
+ page4->setSpacing( 5 );
+
+ QHBox* hbox = new QHBox( page4 );
+ hbox->setSpacing( 5 );
+
+ buttonTableInsert = new KPushButton( i18n("Insert Row"), hbox );
+ buttonTableInsert->setIconSet( BarIconSet( "edit" ) );
+ buttonTableRemove = new KPushButton( i18n("Delete Row"), hbox );
+ buttonTableRemove->setIconSet( BarIconSet( "editdelete") );
+
+ m_varTable = new QTable( page4 );
+ m_varTable->setReadOnly( false );
+ m_varTable->setSelectionMode( QTable::SingleRow );
+
+ addPage( page4, i18n("Import Variables") );
+
+ connect( buttonTableInsert, SIGNAL( clicked() ), this, SLOT( slotTableInsert() ) );
+ connect( buttonTableRemove, SIGNAL( clicked() ), this, SLOT( slotTableRemove() ) );
+}
+
+void BatchWizard::setupPage5()
+{
+ TokenProvider serial( this );
+
+ page5 = new QVBox( this, "page5" );
+
+ new QLabel( i18n( "<qt>KBarcode has support for placing serial numbers on labels. "
+ "If you did not use the [serial] token on your label in "
+ "a text field or a barcode, you can skip this page.<br>"
+ "Serial start is a free form start value containing at least one "
+ "number. This number is increased for every printed label on the "
+ "print out.</qt>"), page5 );
+
+ QHBox* hbox = new QHBox( page5 );
+ hbox->setSpacing( 5 );
+
+ new QLabel( i18n( "Serial start:" ), hbox );
+ serialStart = new KLineEdit( serial.serial(), hbox );
+
+ serialInc = new KIntNumInput( 1, hbox );
+ serialInc->setLabel( i18n( "Serial increment:" ), KNumInput::AlignLeft | KNumInput::AlignVCenter );
+ serialInc->setRange( 1, 10000, 1, false );
+
+ addPage( page5, i18n("Serial Number") );
+}
+
+void BatchWizard::setupPage10()
+{
+ page10 = new QWidget( this, "page10" );
+ QVBoxLayout* pageLayout = new QVBoxLayout( page10, 11, 6, "pageLayout");
+
+ QVButtonGroup* group = new QVButtonGroup( page10 );
+
+ radioPrinter = new QRadioButton( i18n("&Print to a system printer or to a file"), group );
+ radioImage = new QRadioButton( i18n("&Create images"), group );
+
+ imageBox = new QVBox( group );
+ imageBox->setMargin( 10 );
+
+ radioBarcode = new QRadioButton( i18n("Print to a special &barcode printer"), group );
+
+ QHBox* directoryBox = new QHBox( imageBox );
+ directoryBox->setSpacing( 5 );
+ QLabel* label = new QLabel( i18n("Output &Directory:"), directoryBox );
+ imageDirPath = new KURLRequester( directoryBox );
+ imageDirPath->setMode( KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly );
+ label->setBuddy( directoryBox );
+
+ QHBox* formatBox = new QHBox( imageBox );
+ label = new QLabel( i18n("Output File &Format:"), formatBox );
+
+ QStringList formats = KImageIO::types( KImageIO::Writing );
+ comboFormat = new KComboBox( false, formatBox );
+ comboFormat->insertStringList( formats );
+ if( formats.contains( PNG_FORMAT ) )
+ comboFormat->setCurrentItem( formats.findIndex( PNG_FORMAT ) );
+ label->setBuddy( comboFormat );
+
+ QVButtonGroup* imageNameGroup = new QVButtonGroup( i18n("&Filename:"), imageBox );
+ radioImageFilenameArticle = new QRadioButton( i18n("Use &article number for filename"), imageNameGroup );
+ radioImageFilenameBarcode = new QRadioButton( i18n("Use &barcode number for filename"), imageNameGroup );
+ radioImageFilenameCustom = new QRadioButton( i18n("Use &custom filename:"), imageNameGroup );
+ editImageFilename = new KLineEdit( imageNameGroup );
+ radioImageFilenameBarcode->setChecked( true );
+
+ labelInfo = new QLabel( page10 );
+
+ radioPrinter->setChecked( true );
+
+ checkKeepOpen = new QCheckBox( i18n("&Keep window open after printing."), page10 );
+
+ QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding );
+ pageLayout->addWidget( group );
+ pageLayout->addItem( spacer );
+ pageLayout->addWidget( labelInfo );
+ pageLayout->addWidget( checkKeepOpen );
+
+ connect( radioPrinter, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioImage, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioBarcode, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+
+ connect( radioImageFilenameArticle, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioImageFilenameBarcode, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioImageFilenameCustom, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+
+ connect( imageDirPath, SIGNAL( textChanged( const QString & ) ), this, SLOT( enableControls() ) );
+
+ addPage( page10, i18n("Output Device") );
+}
+
+void BatchWizard::setupStackPage1()
+{
+ stack1 = new QVBox( page3, "stack1" );
+ stack1->setSpacing( 5 );
+
+ QHBox* hbox = new QHBox( stack1 );
+ hbox->setSpacing( 5 );
+
+ new QLabel( i18n( "Customer name and no.:" ), hbox );
+ customerName = new KComboBox( false, hbox );
+ customerId = new KComboBox( false, hbox );
+
+ QHBox* hButtonBox = new QHBox( stack1 );
+ hButtonBox->setSpacing( 5 );
+
+ buttonAdd = new KPushButton( i18n( "&Add..." ), hButtonBox );
+ buttonImport = new KPushButton( i18n("&Import..."), hButtonBox );
+ buttonEdit = new KPushButton( i18n( "&Edit..." ), hButtonBox );
+ buttonRemove = new KPushButton( i18n("&Remove" ), hButtonBox );
+ buttonRemoveAll = new KPushButton( i18n("R&emove All"), hButtonBox );
+
+ KPopupMenu* mnuImport = new KPopupMenu( this );
+ mnuImport->insertItem( i18n("Import from File ..."), this, SLOT( loadFromFile() ) );
+ mnuImport->insertItem( i18n("Import from Clipboard ..."), this, SLOT( loadFromClipboard() ) );
+ mnuImport->insertItem( i18n("Import barcode_basic"), this, SLOT( addAllItems() ) );
+ buttonImport->setPopup( mnuImport );
+
+ sqlList = new KListView( stack1 );
+ sqlList->addColumn( i18n("Index") );
+ sqlList->addColumn( i18n("Number of Labels") );
+ sqlList->addColumn( i18n("Article Number") );
+ sqlList->addColumn( i18n("Group") );
+ sqlList->setAllColumnsShowFocus( true );
+ connect( sqlList, SIGNAL(doubleClicked(QListViewItem*,const QPoint &,int)),
+ this, SLOT(changeItem(QListViewItem*,const QPoint &,int)));
+
+ connect( customerName, SIGNAL( activated(int) ), this, SLOT( customerNameChanged(int) ) );
+ connect( customerId, SIGNAL( activated(int) ), this, SLOT( customerIdChanged(int) ) );
+ connect( buttonAdd, SIGNAL( clicked() ), this, SLOT( addItem() ) );
+ connect( buttonEdit, SIGNAL( clicked() ), this, SLOT( editItem() ) );
+ connect( buttonRemove, SIGNAL( clicked() ), this, SLOT( removeItem() ) );
+ connect( buttonRemoveAll, SIGNAL( clicked() ), sqlList, SLOT( clear() ) );
+ connect( buttonRemoveAll, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+
+ page3->addWidget( stack1 );
+}
+
+void BatchWizard::setupStackPage2()
+{
+ stack2 = new QHBox( page3, "stack2" );
+ stack2->setSpacing( 5 );
+
+ QVButtonGroup* group = new QVButtonGroup( stack2 );
+ radioImportManual = new QRadioButton( i18n("Enter &data manually"), group );
+ radioImportSql = new QRadioButton( i18n("Import variables from a &SQL table"), group );
+ labelSqlQuery = new QLabel( i18n("Please enter a sql &query:"), group );
+ importSqlQuery = new KLineEdit( group );
+ labelSqlQuery->setBuddy( importSqlQuery );
+
+ radioImportCSV = new QRadioButton( i18n("Import from a &CSV file"), group );
+ labelCsvFile= new QLabel( i18n("Please select a csv &file:"), group );
+ importCsvFile = new KURLRequester( group );
+ labelCsvFile->setBuddy( importCsvFile );
+ labelEncoding = new QLabel( i18n("&Encoding:"), group );
+ comboEncoding = new EncodingCombo( group );
+ labelEncoding->setBuddy( comboEncoding );
+
+ radioImportManual->setChecked( true );
+
+ QVBox* box = new QVBox( stack2 );
+ box->setSpacing( 5 );
+
+ new QLabel( i18n("Available Variables:"), box );
+ m_varList = new KListBox( box );
+
+ connect( radioImportManual, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioImportSql, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioImportCSV, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( importSqlQuery, SIGNAL( textChanged( const QString & ) ), this, SLOT( enableControls() ) );
+ connect( importCsvFile, SIGNAL( textChanged( const QString & ) ), this, SLOT( enableControls() ) );
+
+ page3->addWidget( stack2 );
+}
+
+void BatchWizard::setupStackPage3()
+{
+ stack3 = new QVBox( page3, "stack3" );
+
+ numLabels = new KIntNumInput( 1, stack3 );
+ numLabels->setRange( 1, 100000, 1, true );
+ numLabels->setLabel( i18n("&Number of labels to print:"), AlignLeft | AlignVCenter );
+
+ page3->addWidget( stack3 );
+}
+
+void BatchWizard::setupStackPage4()
+{
+ stack4 = new QWidget( page3, "stack4" );
+
+ QHBoxLayout* mainLayout = new QHBoxLayout( stack4 );
+
+ QVBox* list1 = new QVBox( stack4 );
+ QVBox* list2 = new QVBox( stack4 );
+
+ QFrame* buttons = new QFrame( stack4 );
+ buttons->setMargin( 10 );
+
+ QVBoxLayout* layout = new QVBoxLayout( buttons );
+ QSpacerItem* spacer1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding );
+ QSpacerItem* spacer2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding );
+
+ buttonAddAllAddress = new KPushButton( buttons );
+ buttonAddAddress = new KPushButton( buttons );
+ buttonRemoveAddress = new KPushButton( buttons );;
+ buttonRemoveAllAddress = new KPushButton( buttons );
+
+ buttonAddAllAddress->setIconSet( BarIconSet( "2rightarrow" ) );
+ buttonAddAddress->setIconSet( BarIconSet( "1rightarrow" ) );
+ buttonRemoveAddress->setIconSet( BarIconSet( "1leftarrow" ) );
+ buttonRemoveAllAddress->setIconSet( BarIconSet( "2leftarrow" ) );
+
+ QToolTip::add( buttonAddAllAddress, i18n("Add all contacts to the list of contacts which will be printed.") );
+ QToolTip::add( buttonAddAddress, i18n("Add selected contacts to the list of contacts which will be printed.") );
+ QToolTip::add( buttonRemoveAddress, i18n("Remove selected contacts from the list of contacts which will be printed.") );
+ QToolTip::add( buttonRemoveAllAddress, i18n("Remove all contacts from the list of contacts which will be printed.") );
+
+ layout->addItem( spacer1 );
+ layout->addWidget( buttonAddAllAddress );
+ layout->addWidget( buttonAddAddress );
+ layout->addWidget( buttonRemoveAddress );
+ layout->addWidget( buttonRemoveAllAddress );
+ layout->addItem( spacer2 );
+
+ mainLayout->addWidget( list1 );
+ mainLayout->addWidget( buttons );
+ mainLayout->addWidget( list2 );
+
+ mainLayout->setStretchFactor( list1, 2 );
+ mainLayout->setStretchFactor( list2, 2 );
+
+ new QLabel( i18n("All Addresses"), list1 );
+ new QLabel( i18n("Selected Addresses"), list2 );
+
+ listAddress = new KListView( list1 );
+ listAddress->addColumn( i18n("Given Name"), 0 );
+ listAddress->addColumn( i18n("Family Name"), 1 );
+ listAddress->addColumn( i18n("Email Address"), 2 );
+ listAddress->setMultiSelection( true );
+ listAddress->setAllColumnsShowFocus( true );
+
+ listAddress->setColumnWidthMode( 0, QListView::Maximum );
+ listAddress->setColumnWidthMode( 1, QListView::Maximum );
+ listAddress->setColumnWidthMode( 2, QListView::Maximum );
+
+ listSelectedAddress = new KListView( list2 );
+ listSelectedAddress->addColumn( i18n("Given Name"), 0 );
+ listSelectedAddress->addColumn( i18n("Family Name"), 1 );
+ listSelectedAddress->addColumn( i18n("Email Address"), 2 );
+ listSelectedAddress->setMultiSelection( true );
+ listSelectedAddress->setAllColumnsShowFocus( true );
+
+ listSelectedAddress->setColumnWidthMode( 0, QListView::Maximum );
+ listSelectedAddress->setColumnWidthMode( 1, QListView::Maximum );
+ listSelectedAddress->setColumnWidthMode( 2, QListView::Maximum );
+
+ connect( buttonAddAddress, SIGNAL( clicked() ), this, SLOT( slotAddAddress() ) );
+ connect( buttonRemoveAddress, SIGNAL( clicked() ), this, SLOT( slotRemoveAddress() ) );
+ connect( buttonAddAllAddress, SIGNAL( clicked() ), this, SLOT( slotAddAllAddress() ) );
+ connect( buttonRemoveAllAddress, SIGNAL( clicked() ), this, SLOT( slotRemoveAllAddress() ) );
+
+ page3->addWidget( stack4 );
+}
+
+void BatchWizard::setupSql()
+{
+ SqlTables* tables = SqlTables::getInstance();
+ if( !tables->isConnected() )
+ return;
+
+ QSqlCursor cur( TABLE_CUSTOMER );
+ cur.select();
+ customerId->clear();
+ customerName->clear();
+ while ( cur.next() ) {
+ customerId->insertItem( cur.value("customer_no" ).toString() );
+ customerName->insertItem( cur.value("customer_name" ).toString() );
+ }
+}
+
+void BatchWizard::enableControls()
+{
+ setAppropriate( page4, radioVarImport->isChecked() );
+
+ radioSqlArticles->setEnabled( SqlTables::getInstance()->isConnected() );
+ radioImportSql->setEnabled( SqlTables::getInstance()->isConnected() );
+
+ importCsvFile->setEnabled( radioImportCSV->isChecked() );
+ labelCsvFile->setEnabled( radioImportCSV->isChecked() );
+ importSqlQuery->setEnabled( radioImportSql->isChecked() );
+ labelSqlQuery->setEnabled( radioImportSql->isChecked() );
+ labelEncoding->setEnabled( radioImportCSV->isChecked() );
+ comboEncoding->setEnabled( radioImportCSV->isChecked() );
+
+ buttonRemove->setEnabled( sqlList->childCount() );
+ buttonRemoveAll->setEnabled(sqlList->childCount() );
+ buttonEdit->setEnabled( sqlList->childCount() );
+
+ imageBox->setEnabled( radioImage->isChecked() );
+
+ if( radioImportSql->isChecked() )
+ setNextEnabled( page3, !importSqlQuery->text().isEmpty() );
+ else if( radioImportCSV->isChecked() )
+ setNextEnabled( page3, !importCsvFile->url().isEmpty() );
+ else if( radioImportManual->isChecked() )
+ setNextEnabled( page3, true );
+
+ editImageFilename->setEnabled( radioImageFilenameCustom->isChecked() );
+ radioImageFilenameArticle->setEnabled( radioSqlArticles->isChecked() );
+
+ setNextEnabled( page1, !m_url->url().isEmpty() );
+
+ if( radioAddressBook->isChecked() )
+ setNextEnabled( page3, listSelectedAddress->childCount() );
+
+ if( radioImage->isChecked() )
+ setFinishEnabled( page10, !imageDirPath->url().isEmpty() );
+ else
+ setFinishEnabled( page10, true );
+}
+
+void BatchWizard::showPage( QWidget* p )
+{
+ if( p == page3 )
+ {
+ if( radioSqlArticles->isChecked() )
+ page3->raiseWidget( stack1 );
+ else if( radioVarImport->isChecked() )
+ {
+ page3->raiseWidget( stack2 );
+ fillVarList();
+ }
+ else if( radioSimple->isChecked() )
+ page3->raiseWidget( stack3 );
+ else if( radioAddressBook->isChecked() )
+ {
+ page3->raiseWidget( stack4 );
+ fillAddressList();
+ }
+ }
+ else if( p == page4 )
+ if( !fillVarTable() )
+ return;
+
+
+ KWizard::showPage( p );
+}
+
+void BatchWizard::accept()
+{
+ printNow( QString::null );
+}
+
+void BatchWizard::printNow( const QString & printer, bool bUserInteraction )
+{
+ BatchPrinter* batch = NULL;
+ KPrinter* prn = NULL;
+ int batchType = 0;
+
+ // let's check if the label file does even exist!
+ if( !QFile::exists( m_url->url() ) )
+ {
+ KMessageBox::error( this, QString( i18n("The label file %1 was not found") ).arg( m_url->url()) );
+ return;
+ }
+
+ if( radioPrinter->isChecked() )
+ {
+ int move = 0;
+ if( bUserInteraction )
+ {
+ PrintLabelDlg pld( this, "pld" );
+ pld.setLabelsEnabled( false );
+ if( pld.exec() != QDialog::Accepted )
+ return;
+
+ move = pld.position();
+ PrinterSettings::getInstance()->getData()->border = pld.border();
+ }
+
+ prn = PrinterSettings::getInstance()->setupPrinter( m_url->url(), this, !printer.isEmpty(), printer );
+ if( !prn )
+ return;
+
+ batch = new BatchPrinter( prn, this );
+ batch->setMove( move );
+
+ batchType = BatchPrinter::POSTSCRIPT;
+ }
+ else if( radioBarcode->isChecked() )
+ {
+ BarcodePrinterDlg dlg(this);
+ if( dlg.exec() != QDialog::Accepted )
+ return;
+
+ batch = new BatchPrinter( dlg.printToFile() ? dlg.fileName() : dlg.deviceName(),
+ dlg.outputFormat(), this );
+ batchType = BatchPrinter::BCP;
+ }
+ else if( radioImage->isChecked() )
+ {
+ batch = new BatchPrinter( imageDirPath->url(), this );
+ if( radioImageFilenameArticle->isChecked() )
+ batch->setImageFilename( BatchPrinter::E_ARTICLE );
+ else if( radioImageFilenameBarcode->isChecked() )
+ batch->setImageFilename( BatchPrinter::E_BARCODE );
+ else if( radioImageFilenameCustom->isChecked() )
+ {
+ batch->setImageFilename( BatchPrinter::E_CUSTOM );
+ batch->setImageCustomFilename( editImageFilename->text() );
+ }
+
+ batchType = BatchPrinter::IMAGE;
+ }
+
+ if( !checkKeepOpen->isChecked() )
+ KWizard::accept();
+
+ KApplication::setOverrideCursor( QCursor( Qt::ArrowCursor ), true );
+ setupBatchPrinter( batch, batchType );
+ KApplication::restoreOverrideCursor();
+
+ delete prn;
+ delete batch;
+}
+
+void BatchWizard::setupBatchPrinter( BatchPrinter* batch, int m )
+{
+ Definition* def = NULL;
+ QString description;
+ bool kbarcode18;
+
+ fillByteArray();
+ QDomDocument doc( "KBarcodeLabel" );
+ if ( !doc.setContent( m_bytearray ) )
+ return;
+
+ XMLUtils util;
+ util.readXMLHeader( &doc, description, kbarcode18, &def );
+
+ QBuffer buffer( m_bytearray );
+ if( !buffer.open( IO_ReadOnly ) )
+ return;
+
+ batch->setBuffer( &buffer );
+ batch->setSerial( serialStart->text(), serialInc->value() );
+ batch->setName( m_url->url() );
+ batch->setDefinition( def );
+ batch->setImageFormat( comboFormat->currentText() );
+
+ if( radioSqlArticles->isChecked() )
+ {
+ int labels = 0;
+ batch->setCustomer( customerId->currentText() );
+
+ // sort by group
+ sqlList->setSorting( 3, true );
+ sqlList->sort();
+
+ QValueList<BatchPrinter::data>* dlist = new QValueList<BatchPrinter::data>;
+ QListViewItem* item = sqlList->firstChild();
+ while( item )
+ {
+ BatchPrinter::data m_data;
+ m_data.number = item->text( 1 ).toInt();
+ labels += m_data.number;
+ m_data.article_no = item->text( 2 );
+ m_data.group = item->text( 3 );
+
+ dlist->append( m_data );
+ item = item->nextSibling();
+ };
+
+ batch->setData( dlist );
+ batch->setLabels( labels );
+ }
+ else if( radioSimple->isChecked() )
+ {
+ batch->setLabels( numLabels->value() );
+
+ // do a dirty drick, TODO: refactor BatchPrinter in the future
+ QValueList<BatchPrinter::data>* dlist = new QValueList<BatchPrinter::data>;
+ BatchPrinter::data m_data;
+ m_data.number = numLabels->value();
+ dlist->append( m_data );
+
+ batch->setData( dlist );
+ }
+ else if( radioVarImport->isChecked() )
+ {
+ TVariableList* tVariableList = new TVariableList;
+ for( int i=0; i<m_varTable->numRows(); i++ )
+ {
+ QMap<QString, QString> map;
+ for( int z=0; z<m_varTable->numCols(); z++ )
+ map[ m_varTable->horizontalHeader()->label( z ) ] = m_varTable->text( i, z );
+ tVariableList->append( map );
+ }
+
+ batch->setData( tVariableList );
+ }
+ else if( radioAddressBook->isChecked() )
+ {
+ KABC::AddresseeList* list = new KABC::AddresseeList;
+ QListViewItem* item = listSelectedAddress->firstChild();
+ while( item )
+ {
+ list->append( static_cast<AddressListViewItem*>(item)->address() );
+ item = item->nextSibling();
+ }
+
+ batch->setData( list );
+ }
+
+ if( m == BatchPrinter::POSTSCRIPT )
+ batch->start();
+ else if( m == BatchPrinter::IMAGE )
+ batch->startImages();
+ else if( m == BatchPrinter::BCP )
+ batch->startBCP();
+
+ delete def;
+}
+
+
+void BatchWizard::addItem()
+{
+ DSSmallDialogs::AddItemsDialog aid( this, "aid" );
+ aid.setGroupCompletion( compGroup );
+ connect( &aid, SIGNAL( add( const QString &, const QString &, int) ),
+ this, SLOT( slotAddItem( const QString &, const QString &, int) ) );
+
+ aid.exec();
+}
+
+bool BatchWizard::slotAddItem( const QString & article, const QString & group, int count )
+{
+ return this->addItem( article, group, count, true );
+}
+
+bool BatchWizard::addItem( const QString & article, const QString & group, int count, bool msg )
+{
+ if( !article.isEmpty() && !existsArticle( article ) ) {
+ if( msg )
+ KMessageBox::error( this, i18n("Please enter a valid article ID") );
+ return false;
+ }
+
+ QString temp;
+ temp.sprintf("%0*i", 5, sqlList->childCount() + 1 );
+
+ KListViewItem* item = new KListViewItem( sqlList, temp, QString( "%1" ).arg( count ),
+ article, group );
+ sqlList->insertItem( item );
+
+ addGroupCompletion( group );
+ enableControls();
+
+ return true;
+}
+
+void BatchWizard::addGroupCompletion( const QString & group )
+{
+ if( !group.isEmpty() )
+ {
+ QStringList slist = compGroup->items();
+ if(!slist.contains( group ) )
+ compGroup->addItem( group );
+ }
+}
+
+bool BatchWizard::existsArticle( const QString & article )
+{
+ if( article.isEmpty() )
+ return false;
+
+ QSqlQuery query( "select uid from barcode_basic where article_no='" + article + "'" );
+ while ( query.next() )
+ return true;
+
+ return false;
+}
+
+void BatchWizard::editItem()
+{
+ QListViewItem* item = sqlList->selectedItem();
+ if( item )
+ changeItem( item, QPoint(0,0), 0 );
+}
+
+void BatchWizard::changeItem( QListViewItem* item, const QPoint &, int )
+{
+ if(!item)
+ return;
+
+ DSSmallDialogs::AddItemsDialog aid( item->text( 2 ), item->text( 3 ),
+ item->text( 1 ).toInt(), this, "aid" );
+ aid.setGroupCompletion( compGroup );
+
+ if( aid.exec() == QDialog::Accepted )
+ {
+ item->setText( 1, QString::number( aid.count() ) );
+ item->setText( 2, aid.articleNo() );
+ item->setText( 3, aid.groupName() );
+ addGroupCompletion( aid.groupName() );
+ enableControls();
+ }
+}
+
+void BatchWizard::removeItem()
+{
+ QListViewItem* item = sqlList->firstChild();
+ while( item )
+ {
+ if( item->isSelected() )
+ {
+ QListViewItem* it = item->nextSibling();
+ delete item;
+
+ while( it )
+ {
+ int a = it->text( 0 ).toInt();
+ QString temp;
+ temp.sprintf("%0*i", 5, a - 1 );
+ it->setText( 0, temp );
+ it = it->nextSibling();
+ }
+
+ break;
+ } else
+ item = item->nextSibling();
+ }
+
+ enableControls();
+}
+
+void BatchWizard::customerIdChanged( int index )
+{
+ customerName->setCurrentItem( index );
+ enableControls();
+}
+
+void BatchWizard::customerNameChanged( int index )
+{
+ customerId->setCurrentItem( index );
+ enableControls();
+}
+
+void BatchWizard::addAllItems()
+{
+ DSSmallDialogs::AddAllDialog* dlg = new DSSmallDialogs::AddAllDialog( this, "dlg" );
+ if( dlg->exec() == QDialog::Accepted )
+ {
+ QString temp;
+ QString group = dlg->groupName();
+ const QString num = QString::number( dlg->numberLabels() );
+
+ QSqlQuery query("SELECT article_no FROM " TABLE_BASIC );
+ while( query.next() )
+ {
+ temp.sprintf("%0*i", 5, sqlList->childCount() + 1 );
+ new KListViewItem( sqlList, temp, num, query.value( 0 ).toString(), group );
+ }
+
+ enableControls();
+ }
+}
+
+void BatchWizard::loadFromFile()
+{
+ QString f = KFileDialog::getOpenFileName( 0, 0, this );
+ if( !f.isEmpty() )
+ loadFromFile( f );
+}
+
+void BatchWizard::loadFromClipboard()
+{
+ QClipboard *cb = KApplication::clipboard();
+ loadData( cb->text() );
+}
+
+void BatchWizard::loadFromFile( const QString & url )
+{
+ QByteArray data;
+ QFile file( url );
+
+ if( !file.open( IO_ReadOnly ) )
+ {
+ qDebug("Unable to open file: %s", url.latin1() );
+ return;
+ }
+
+ data = file.readAll();
+
+ loadData( QString( data ) );
+}
+
+void BatchWizard::loadData( const QString & data )
+{
+ labelprinterdata* lpdata = PrinterSettings::getInstance()->getData();
+ if( lpdata->separator.isEmpty() )
+ {
+ KMessageBox::sorry( this, i18n("Separator is empty. Please set it to a value.") );
+ return;
+ }
+
+ // new config entry!!!
+ KConfig* config = kapp->config();
+ config->setGroup("FileFormat");
+ int pos[3] = { config->readNumEntry("Data0", 0 ),
+ config->readNumEntry("Data1", 1 ),
+ config->readNumEntry("Data2", 2 ) };
+
+ bool custom_article_no = lpdata->useCustomNo;
+ QBuffer buf( data.utf8() );
+ CSVFile file( buf );
+
+ QStringList list, dropped;
+ QString article, quantity, group;
+
+ while( file.isValid() && !file.isEof() )
+ {
+ list = file.readNextLine();
+ while( list.count() < 3 )
+ list.append( QString::null );
+
+ if( pos[0] == 0 )
+ quantity = list[0];
+ else if( pos[0] == 1 )
+ article = list[0];
+ else
+ group = list[0];
+
+ if( pos[1] == 0 )
+ quantity = list[1];
+ else if( pos[1] == 1 )
+ article = list[1];
+ else
+ group = list[1];
+
+ if( pos[2] == 0 )
+ quantity = list[2];
+ else if( pos[2] == 1 )
+ article = list[2];
+ else
+ group = list[2];
+
+ // data[0] == quantity
+ // data[1] == article_no
+ // data[2] == group
+
+ bool qint = false;
+ (void)quantity.toInt( &qint );
+
+ if( qint && custom_article_no ) {
+ qint = false;
+ QSqlQuery query("SELECT article_no FROM customer_text WHERE article_no_customer='" + article + "'" );
+ while( query.next() ) {
+ article = query.value( 0 ).toString();
+ qint = true;
+ break;
+ }
+ }
+
+ if( qint ) // && existsArticle( article )
+ {
+ if( !addItem( QString( article ), QString( group ), quantity.toInt(), false ) )
+ dropped.append( quantity + lpdata->separator + article + lpdata->separator + group );
+ }
+ }
+
+ if( !dropped.isEmpty() )
+#if QT_VERSION >= 0x030100
+ KMessageBox::informationList( this, i18n("<qt>The following items can not be added:" )+ "</qt>", dropped );
+#else
+ KMessageBox::questionYesNoList( this, i18n("<qt>The following items can not be added:" )+ "</qt>", dropped );
+#endif
+
+ enableControls();
+}
+
+void BatchWizard::fillByteArray()
+{
+ if( m_bytearray_filename != m_url->url() )
+ {
+ QFile f( m_url->url() );
+ if ( !f.open( IO_ReadOnly ) )
+ {
+ m_bytearray_filename = QString::null;
+ m_bytearray.resize( 0 );
+ return ;
+ }
+
+ m_bytearray = f.readAll();
+ f.close();
+ }
+}
+
+void BatchWizard::fillVarList()
+{
+ fillByteArray();
+ QDomDocument doc( "KBarcodeLabel" );
+ if ( !doc.setContent( m_bytearray ) )
+ return;
+
+ XMLUtils util;
+ DocumentItemList list;
+ list.setAutoDelete( true );
+
+ TokenProvider token( this );
+ Definition* def = NULL;
+
+ QString description;
+ bool kbarcode18;
+ util.readXMLHeader( &doc, description, kbarcode18, &def );
+ util.readDocumentItems( &list, &doc, &token, kbarcode18 );
+
+ token.setCurrentDocumentItems( list );
+
+ QStringList vars = token.listUserVars();
+ m_varList->clear();
+ m_varList->insertStringList( vars );
+ m_varTable->setNumCols( vars.count() );
+ for( unsigned int i = 0; i < vars.count(); i++ )
+ {
+ vars[i] = vars[i].right( vars[i].length() - 1 );
+ m_varTable->horizontalHeader()->setLabel( i, vars[i] );
+ }
+
+ delete def;
+}
+
+void BatchWizard::fillAddressList()
+{
+ KABC::AddressBook* ab = KABC::StdAddressBook::self();
+ listAddress->clear();
+
+ KABC::AddressBook::Iterator it;
+ listAddress->setUpdatesEnabled( false );
+ for ( it = ab->begin(); it != ab->end(); ++it )
+ new AddressListViewItem( listAddress, *it );
+ listAddress->setUpdatesEnabled( true );
+}
+
+bool BatchWizard::fillVarTable()
+{
+ // Clear the table
+ m_varTable->setNumRows( 0 );
+
+ if( radioImportSql->isChecked() )
+ {
+ int y = 0;
+ int x;
+ QSqlSelectCursor query( importSqlQuery->text(), SqlTables::getInstance()->database() );
+ query.select();
+ if( query.lastError().type() != QSqlError::None )
+ {
+ KMessageBox::error( this, i18n("<qt>Can't execute SQL query:<br>") + query.lastError().text() + "</qt>" );
+ return false;
+ }
+
+ if( m_varTable->numRows() < query.size() )
+ m_varTable->setNumRows( query.size() );
+
+ while( query.next() )
+ {
+ for( x=0;x<m_varTable->numRows();x++ )
+ m_varTable->setText( y, x, query.value( m_varTable->horizontalHeader()->label( x ) ).toString() );
+
+ y++;
+ }
+ }
+ else if( radioImportCSV->isChecked() )
+ {
+ CSVFile file( importCsvFile->url() );
+ file.setEncoding( comboEncoding->currentText() );
+
+ QStringList heading;
+ QStringList data;
+ int i = 0;
+
+ file.setCSVFile(true);
+ if( !file.isValid() )
+ {
+ KMessageBox::error( this, QString( i18n("Can't open file: %1") ).arg( importCsvFile->url() ) );
+ return false;
+ }
+
+ while( !file.isEof() )
+ {
+ if( heading.isEmpty() )
+ heading = file.readNextLine();
+ else
+ {
+ data = file.readNextLine();
+
+ // add 100 rows to get a reasonable speed
+ if( m_varTable->numRows() <= i )
+ m_varTable->setNumRows( i + 100 );
+
+ printf("datacount=%i\n", data.count() );
+ for( unsigned int z = 0; z < data.count(); z++ )
+ {
+ printf("numRows=%i\n", m_varTable->numCols() );
+ for( int x = 0; x < m_varTable->numCols(); x++ )
+ {
+ printf("horizontal header=%s\n", m_varTable->horizontalHeader()->label( x ).lower().latin1() );
+ printf("heading=%s\n", heading[z].lower().latin1() );
+ if( m_varTable->horizontalHeader()->label( x ).lower() == heading[z].lower() )
+ {
+ printf("Reading: (%s)\n", data[z].latin1());
+ m_varTable->setText( i, x, data[z] );
+ break;
+ }
+ }
+ }
+
+ if( data.count() )
+ i++;
+ }
+ }
+
+ m_varTable->setNumRows( i );
+ }
+
+ return true;
+}
+
+void BatchWizard::slotTableInsert()
+{
+ m_varTable->insertRows( m_varTable->numRows(), 1 );
+}
+
+void BatchWizard::slotTableRemove()
+{
+ QTableSelection sel = m_varTable->selection( m_varTable->currentSelection() );
+ m_varTable->removeRow( sel.topRow() );
+}
+
+void BatchWizard::setFilename( const QString & url )
+{
+ m_url->setURL( url );
+ enableControls();
+}
+
+void BatchWizard::setImportSqlQuery( const QString & query )
+{
+ radioImportCSV->setChecked( false );
+ radioImportManual->setChecked( false );
+ radioImportSql->setChecked( true );
+
+ radioVarImport->setChecked( true );
+ radioSqlArticles->setChecked( false );
+ radioSimple->setChecked( false );
+
+ importSqlQuery->setText( query );
+
+ enableControls();
+
+ showPage( page3 );
+ showPage( page4 );
+}
+
+void BatchWizard::setImportCsvFile( const QString & filename )
+{
+ radioImportCSV->setChecked( true );
+ radioImportManual->setChecked( false );
+ radioImportSql->setChecked( false );
+
+ radioVarImport->setChecked( true );
+ radioSqlArticles->setChecked( false );
+ radioSimple->setChecked( false );
+
+ importCsvFile->setURL( filename );
+
+ enableControls();
+
+ showPage( page3 );
+ showPage( page4 );
+}
+
+void BatchWizard::setNumLabels( const int n )
+{
+ numLabels->setValue( n );
+ radioSimple->setChecked( true );
+ radioSqlArticles->setChecked( false );
+ radioVarImport->setChecked( false );
+ enableControls();
+}
+
+void BatchWizard::setOutputFormat( const int e )
+{
+ radioBarcode->setChecked( false );
+ radioImage->setChecked( false );
+ radioPrinter->setChecked( false );
+
+ switch( e )
+ {
+ case BatchPrinter::BCP:
+ radioBarcode->setChecked( true );
+ break;
+ case BatchPrinter::IMAGE:
+ radioImage->setChecked( true );
+ break;
+ default:
+ case BatchPrinter::POSTSCRIPT:
+ radioPrinter->setChecked( true );
+ break;
+ }
+
+ enableControls();
+}
+
+void BatchWizard::setSerialNumber( const QString & val, int inc )
+{
+ serialInc->setValue( inc );
+ serialStart->setText( val );
+
+ // Not needed here: enableControls();
+}
+
+void BatchWizard::slotAddAddress()
+{
+ moveAddress( listAddress, listSelectedAddress );
+ enableControls();
+}
+
+void BatchWizard::slotAddAllAddress()
+{
+ moveAddress( listAddress, listSelectedAddress, true );
+ enableControls();
+}
+
+void BatchWizard::slotRemoveAddress()
+{
+ moveAddress( listSelectedAddress, listAddress );
+ enableControls();
+}
+
+void BatchWizard::slotRemoveAllAddress()
+{
+ moveAddress( listSelectedAddress, listAddress, true );
+ enableControls();
+}
+
+void BatchWizard::moveAddress( QListView* src, QListView* dst, bool bAll )
+{
+ QListViewItem* item = src->firstChild();
+ QListViewItem* cur;
+
+ while( item )
+ {
+ if( bAll || item->isSelected() )
+ {
+ cur = item;
+ item = item->nextSibling();
+
+ src->takeItem( cur );
+ dst->insertItem( cur );
+ cur->setSelected( false );
+ }
+ else
+ item = item->nextSibling();
+ }
+}
diff --git a/kbarcode/batchwizard.h b/kbarcode/batchwizard.h
new file mode 100644
index 0000000..e736a6f
--- /dev/null
+++ b/kbarcode/batchwizard.h
@@ -0,0 +1,266 @@
+/***************************************************************************
+ batchwizard.h - description
+ -------------------
+ begin : Sun Mar 20 2005
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef BATCHWIZARD_H
+#define BATCHWIZARD_H
+
+#include <kwizard.h>
+#include "batchiface.h"
+
+class BatchPrinter;
+class EncodingCombo;
+class KComboBox;
+class KCompletion;
+class KIntNumInput;
+class KLineEdit;
+class KListBox;
+class KListView;
+class KPushButton;
+class KURLRequester;
+class QCheckBox;
+class QHBox;
+class QLabel;
+class QListView;
+class QListViewItem;
+class QRadioButton;
+class QTable;
+class QVBox;
+class QWidgetStack;
+
+class BatchWizard : public KWizard, public BatchIface {
+ Q_OBJECT
+ public:
+ BatchWizard( QWidget* parent = NULL, const char* name = NULL );
+ ~BatchWizard();
+
+ /** reimplemented DCOP method from BatchIface
+ * Allow the user to add an article to print to KBarcode
+ * @p article article number to add
+ * @p group use group as group name for this article
+ * @p count number of labels to print for this article
+ * @p msgbox show a messagebox if adding the item fails
+ */
+ bool addItem( const QString & article, const QString & group, int count, bool msgbox = true );
+
+ /** reimplemented DCOP method from BatchIface
+ * tests wether the arctile is existing in KBarcodes database
+ * @p article article number to test for
+ */
+ virtual bool existsArticle( const QString & article );
+
+ /** reimplemented DCOP method from BatchIface
+ * import articles from a file. The user is asked for the filename
+ */
+ virtual void loadFromFile( const QString & url );
+
+ /** reimplemented DCOP method from BatchIface
+ * print immediately with current settings
+ * @p printer print to this printer (must be known to the system)
+ * @p bUserInteraction if false no dialog will pop up besides the printer dialog
+ */
+ virtual void printNow( const QString & printer, bool bUserInteraction = true );
+
+ /** reimplemented DCOP method from BatchIface
+ * to allow the user to set the label to be used
+ * @p url path of the label which shall get printed
+ */
+ virtual void setFilename( const QString & url );
+
+ /** reimplemented DCOP method from BatchIface
+ * Set the batchwizards mode to print from imported data
+ * and import the data from the csv file @p filname
+ * @p filename csv file to import
+ */
+ virtual void setImportCsvFile( const QString & filename );
+
+ /** reimplemented DCOP method from BatchIface
+ * Set the batchwizards mode to print from imported data
+ * and import the data from the sql query @p query
+ * @p query sql query to execute to get on user defined variables
+ */
+ virtual void setImportSqlQuery( const QString & query );
+
+ /** reimplemented DCOP method from BatchIface
+ * set the numbers of labels to print.
+ * the option to print without data import is activated too using
+ * this option
+ * @p n number of labels to print
+ */
+ virtual void setNumLabels( const int n );
+
+ /** reimplemented DCOP method from BatchIface
+ * sets wether the user wants to print to a postscript printer,
+ * a barcode printer or to image files.
+ * @p e is of datatype BatchPrinter::EOutputFormat
+ */
+ virtual void setOutputFormat( const int e );
+
+ /** reimplemented DCOP method from BatchIface
+ * allow the user to set the value and start value for
+ * the serial number that can be used on labels using the [serial] token
+ * @p val value of the serial number (e.g. TEST0002)
+ * @p inc the serial number is increased that much for every label
+ */
+ virtual void setSerialNumber( const QString & val, int inc );
+
+ public slots:
+ /** reimplemented DCOP method from BatchIface
+ * import articles from the clipboard
+ */
+ virtual void loadFromClipboard();
+
+
+ private slots:
+ void addAllItems();
+ void enableControls();
+ void customerIdChanged( int index );
+ void customerNameChanged( int index );
+ void addItem();
+ bool slotAddItem( const QString & article, const QString & group, int count );
+ void changeItem( QListViewItem* item, const QPoint &, int );
+ void editItem();
+ void removeItem();
+
+ void slotTableInsert();
+ void slotTableRemove();
+ void loadFromFile();
+
+ void slotAddAddress();
+ void slotAddAllAddress();
+ void slotRemoveAddress();
+ void slotRemoveAllAddress();
+
+ private:
+ void moveAddress( QListView* src, QListView* dst, bool bAll = false );
+
+ void fillByteArray();
+ void fillVarList();
+ bool fillVarTable();
+ void fillAddressList();
+
+ void setupPage1();
+ void setupPage2();
+ void setupPage3();
+ void setupPage4();
+ void setupPage5();
+ void setupPage10();
+
+ void setupStackPage1();
+ void setupStackPage2();
+ void setupStackPage3();
+ void setupStackPage4();
+
+ void setupSql();
+ void setupBatchPrinter( BatchPrinter* batch, int m );
+
+ void addGroupCompletion( const QString & group );
+ void loadData( const QString & data );
+
+ protected:
+ void accept();
+ void showPage( QWidget* w );
+
+ private:
+ /** m_bytearray_filename is set whenever
+ * the kbarcide label file has been read into
+ * the buffer m_bytearray. Therefore we have only
+ * to re-read the bytearray when the filename was
+ * changed by the user.
+ */
+ QString m_bytearray_filename;
+ QByteArray m_bytearray;
+
+ QWidget* page1;
+ QWidget* page2;
+ QWidgetStack* page3;
+ QVBox* page4;
+ QVBox* page5;
+ QWidget* page10;
+
+ QVBox* stack1;
+ QHBox* stack2;
+ QVBox* stack3;
+ QWidget* stack4;
+
+ QVBox* imageBox;
+
+ QLabel* labelInfo;
+ QLabel* labelSqlQuery;
+ QLabel* labelCsvFile;
+ QLabel* labelEncoding;
+
+ QRadioButton* radioSqlArticles;
+ QRadioButton* radioVarImport;
+ QRadioButton* radioSimple;
+ QRadioButton* radioAddressBook;
+
+ QRadioButton* radioPrinter;
+ QRadioButton* radioImage;
+ QRadioButton* radioBarcode;
+
+ QRadioButton* radioImportSql;
+ QRadioButton* radioImportCSV;
+ QRadioButton* radioImportManual;
+
+ QRadioButton* radioImageFilenameArticle;
+ QRadioButton* radioImageFilenameBarcode;
+ QRadioButton* radioImageFilenameCustom;
+ KLineEdit* editImageFilename;
+ KURLRequester* imageDirPath;
+
+ KLineEdit* importSqlQuery;
+ KURLRequester* importCsvFile;
+
+ KComboBox* customerName;
+ KComboBox* customerId;
+ KComboBox* comboFormat;
+ EncodingCombo* comboEncoding;
+
+ KCompletion* compGroup;
+
+ KIntNumInput* serialInc;
+ KIntNumInput* numLabels;
+
+ QTable* m_varTable;
+ KListBox* m_varList;
+
+ KListView* listAddress;
+ KListView* listSelectedAddress;
+
+ KListView* sqlList;
+ KLineEdit* serialStart;
+
+ QCheckBox* checkKeepOpen;
+
+ KPushButton* buttonAddAddress;
+ KPushButton* buttonRemoveAddress;
+ KPushButton* buttonAddAllAddress;
+ KPushButton* buttonRemoveAllAddress;
+
+ KPushButton* buttonAdd;
+ KPushButton* buttonImport;
+ KPushButton* buttonEdit;
+ KPushButton* buttonRemove;
+ KPushButton* buttonRemoveAll;
+
+ KPushButton* buttonTableInsert;
+ KPushButton* buttonTableRemove;
+
+ KURLRequester* m_url;
+};
+
+#endif // BATCHWIZARD_H
diff --git a/kbarcode/commands.cpp b/kbarcode/commands.cpp
new file mode 100644
index 0000000..a11c01b
--- /dev/null
+++ b/kbarcode/commands.cpp
@@ -0,0 +1,604 @@
+/***************************************************************************
+ commands.cpp - description
+ -------------------
+ begin : Don Dez 19 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "commands.h"
+#include "mycanvasview.h"
+
+#include "barkode.h"
+#include "tcanvasitem.h"
+#include "rectitem.h"
+#include "textitem.h"
+#include "imageitem.h"
+#include "barcodeitem.h"
+#include "lineitem.h"
+//NY26
+#include "textlineitem.h"
+//NY26
+
+
+// KDE includes
+#include <kapplication.h>
+
+QPoint getFreePos( QCanvas* c )
+{
+ MyCanvas* canvas = (MyCanvas*)c;
+
+ if( !c->width() && !c->height() )
+ return QPoint( canvas->rect().x(), canvas->rect().y() );
+
+ // TODO: fix for positions on label
+ int x = KApplication::random() % canvas->rect().width() - 20;
+ int y = KApplication::random() % canvas->rect().height() - 20;
+
+ if( x > 0 && y > 0 )
+ return QPoint( canvas->rect().x() + x, canvas->rect().y() + y );
+ else
+ return QPoint( canvas->rect().x(), canvas->rect().y() );
+}
+
+CommandUtils::CommandUtils(TCanvasItem* item)
+ : QObject()
+{
+ m_canvas_item = item;
+ m_canvas_item->addRef();
+
+ c = m_canvas_item->canvas();
+ /* NOT NEEDED:
+ if( m_canvas_item && m_canvas_item->item() )
+ connect( m_canvas_item->item(), SIGNAL( destroyed() ), this, SLOT( documentItemDeleted() ) );
+ */
+}
+
+CommandUtils::~CommandUtils()
+{
+ m_canvas_item->remRef();
+}
+
+bool CommandUtils::canvasHasItem()
+{
+ if( m_canvas_item && c )
+ {
+ QCanvasItemList list = c->allItems();
+ for( unsigned int i=0;i<list.count();i++)
+ if( m_canvas_item == list[i] )
+ return true;
+ }
+
+ return false;
+}
+
+
+void CommandUtils::documentItemDeleted()
+{
+ /** the document item got deleted, so that we can assume the TCanvasItem
+ * was deleted to (as it usually deltes the document item)
+ */
+ /* NOT NEEDED
+ m_canvas_item = NULL;
+ c = NULL;
+
+ qDebug("Document item removed from list!");
+ delete this;
+ */
+}
+
+NewItemCommand::NewItemCommand( MyCanvasView* view, const QString & name )
+ : QObject(), KCommand()
+{
+ cv = view;
+ m_name = name;
+ m_point = getFreePos( cv->canvas() );
+ m_item = NULL;
+ m_object = NULL;
+}
+
+NewItemCommand::~NewItemCommand()
+{
+ m_item->remRef();
+}
+
+void NewItemCommand::execute()
+{
+ if( !m_item )
+ {
+ create();
+
+ if( m_object )
+ {
+ m_item = new TCanvasItem( cv );
+ m_item->setItem( m_object );
+ m_item->move( m_point.x(), m_point.y() );
+ m_item->addRef();
+
+ /* NOT NEEDED:
+ connect( m_object, SIGNAL( destroyed() ), this, SLOT( documentItemDeleted() ) );
+ */
+ }
+ }
+
+ if( m_item )
+ {
+ m_item->setCanvas( cv->canvas() );
+ m_item->show();
+ m_item->update();
+ cv->setCurrent( m_item );
+ }
+}
+
+void NewItemCommand::unexecute()
+{
+ if( m_item ) {
+ m_item->setCanvas( NULL );
+ m_item->hide();
+ }
+}
+
+void NewItemCommand::documentItemDeleted()
+{
+ /** the document item got deleted, so that we can assume the TCanvasItem
+ * was deleted to (as it usually deltes the document item)
+ */
+
+ /* NOT NEEDED:
+ m_item = NULL;
+ m_object = NULL;
+
+ qDebug("NewItemCommand: Document item removed from list!");
+ delete this;
+ */
+}
+
+
+void ResizeCommand::setRect( int cx, int cy, int cw, int ch )
+{
+ // make sure that the item cannot
+ // be resized to a negative value
+ if( cw <= 0 )
+ cw = orect.width();
+
+ if( ch <= 0 )
+ ch = orect.height();
+
+ rect = QRect( cx, cy, cw, ch );
+}
+
+void ResizeCommand::execute()
+{
+ if( canvasHasItem() ) {
+ if( m_shift && rect.width() ) {
+ double r = (double)orect.height() / (double)orect.width();
+ rect.setWidth( int(rect.height() / r) );
+ }
+
+ m_canvas_item->moveMM( rect.x(), rect.y() );
+ m_canvas_item->setSizeMM( rect.width(), rect.height() );
+ m_canvas_item->update();
+
+ if( m_canvas_item->item()->rtti() == eRtti_Image )
+ {
+ ImageItem* item = static_cast<ImageItem*>(m_canvas_item->item());
+ item->updateImage();
+ }
+ }
+}
+
+void ResizeCommand::unexecute()
+{
+ if( canvasHasItem() ) {
+ m_canvas_item->moveMM( orect.x(), orect.y() );
+ m_canvas_item->setSizeMM( orect.width(), orect.height() );
+ m_canvas_item->update();
+
+ if( m_canvas_item->item()->rtti() == eRtti_Image )
+ {
+ ImageItem* item = static_cast<ImageItem*>(m_canvas_item->item());
+ item->updateImage();
+ }
+ }
+}
+
+void MoveCommand::execute()
+{
+ if( canvasHasItem() )
+ {
+ m_canvas_item->moveByMM( x, y );
+ m_canvas_item->update();
+ }
+}
+
+void MoveCommand::unexecute()
+{
+ if( canvasHasItem() )
+ {
+ m_canvas_item->moveByMM( -x, -y );
+ m_canvas_item->update();
+ }
+}
+
+ChangeZCommand::ChangeZCommand( int z, TCanvasItem* it )
+ : CommandUtils( it )
+{
+ m_z = z;
+ m_oldz = (int)m_canvas_item->z();
+}
+
+void ChangeZCommand::execute()
+{
+ if( canvasHasItem() )
+ {
+ m_canvas_item->setZ( m_z );
+ m_canvas_item->update();
+ }
+}
+
+void ChangeZCommand::unexecute()
+{
+ if( canvasHasItem() )
+ {
+ m_canvas_item->setZ( m_oldz );
+ m_canvas_item->update();
+ }
+}
+
+void LockCommand::execute()
+{
+ if( canvasHasItem() )
+ {
+ m_canvas_item->item()->setLocked( m_locked );
+ m_canvas_item->update();
+ }
+}
+
+void LockCommand::unexecute()
+{
+ if( canvasHasItem() )
+ {
+ m_canvas_item->item()->setLocked( !m_locked );
+ m_canvas_item->update();
+ }
+}
+
+PictureCommand::PictureCommand( double r, bool mh, bool mv, EImageScaling s, ImageItem* it )
+ : CommandUtils( it->canvasItem() )
+{
+ rotate = r;
+ mirrorv = mv;
+ mirrorh = mh;
+ scaling = s;
+
+ orotate = it->rotation();
+ omirrorv = it->mirrorVertical();
+ omirrorh = it->mirrorHorizontal();
+ oscaling = it->scaling();
+
+ oexpression = it->expression();
+ opixmap = it->pixmap();
+ opixserial = opixmap.serialNumber();
+
+ oldsize.setWidth( it->rect().width() );
+ oldsize.setHeight( it->rect().height() );
+
+ m_item = it;
+}
+
+void PictureCommand::setExpression( const QString & expr )
+{
+ expression = expr;
+}
+
+void PictureCommand::setPixmap( const QPixmap & pix )
+{
+ pixmap = pix;
+ pixserial = pixmap.serialNumber();
+}
+
+void PictureCommand::execute()
+{
+ if( canvasHasItem() ) {
+ m_item->setRotation( rotate );
+ m_item->setMirrorVertical( mirrorv );
+ m_item->setMirrorHorizontal( mirrorh );
+ m_item->setScaling( scaling );
+ m_item->setExpression( expression );
+ m_item->setPixmap( pixmap );
+
+ if( !pixmap.isNull() && pixserial != opixserial )
+ m_item->canvasItem()->setSize( pixmap.width(), pixmap.height() );
+ }
+}
+
+void PictureCommand::unexecute()
+{
+ if( canvasHasItem() ) {
+ m_item->setRotation( orotate );
+ m_item->setMirrorVertical( omirrorv );
+ m_item->setMirrorHorizontal( omirrorh );
+ m_item->setScaling( oscaling );
+ m_item->setExpression( oexpression );
+ m_item->setPixmap( opixmap );
+ m_item->canvasItem()->setSize( oldsize.width(), oldsize.height() );
+ }
+}
+
+TextChangeCommand::TextChangeCommand( TextItem* it, QString t )
+ : CommandUtils( it->canvasItem() )
+{
+ m_item = it;
+ text = t;
+ oldtext = m_item->text();
+}
+
+void TextChangeCommand::execute()
+{
+ if( canvasHasItem() )
+ m_item->setText( text );
+}
+
+void TextChangeCommand::unexecute()
+{
+ if( canvasHasItem() )
+ m_item->setText( oldtext );
+}
+
+TextRotationCommand::TextRotationCommand( double rot, TextItem* t )
+ : CommandUtils( t->canvasItem() ), m_item( t )
+{
+ rot1 = rot;
+ rot2 = t->rotation();
+}
+
+void TextRotationCommand::execute()
+{
+ m_item->setRotation( rot1 );
+}
+
+void TextRotationCommand::unexecute()
+{
+ m_item->setRotation( rot2 );
+}
+
+//NY24
+TextLineChangeCommand::TextLineChangeCommand( TextLineItem* it, QString t, int font , int magvert, int maghor)
+ : CommandUtils( it->canvasItem() )
+{
+ m_item = it;
+ text = t;
+ oldtext = m_item->text();
+ m_font = font;
+ m_mag_vert = magvert;
+ m_mag_hor = maghor;
+}
+
+void TextLineChangeCommand::execute()
+{
+ if( canvasHasItem() ){
+ m_item->setText( text );
+ m_item->setFont(m_font);
+ m_item->setMagVert(m_mag_vert);
+ m_item->setMagHor(m_mag_hor);
+ }
+}
+
+void TextLineChangeCommand::unexecute()
+{
+ if( canvasHasItem() )
+ m_item->setText( oldtext );
+}
+//NY24
+
+BarcodeCommand::BarcodeCommand( BarcodeItem* bcode, Barkode* d )
+ : CommandUtils( bcode->canvasItem() )
+{
+ m_item = bcode;
+ olddata = *bcode;
+ data = d;
+}
+
+void BarcodeCommand::execute()
+{
+ if( canvasHasItem() ) {
+ m_item->setData( *data );
+ m_item->updateBarcode();
+ }
+}
+
+void BarcodeCommand::unexecute()
+{
+ if( canvasHasItem() ) {
+ m_item->setData( olddata );
+ m_item->updateBarcode();
+ }
+}
+
+void NewPictureCommand::create()
+{
+ ImageItem* r = new ImageItem();
+ m_object = r;
+}
+
+NewRectCommand::NewRectCommand( MyCanvasView* v, bool circle )
+ : NewItemCommand( v, i18n("New Rectangle") )
+{
+ m_circle = circle;
+}
+
+void NewRectCommand::create()
+{
+ RectItem* r = new RectItem();
+ r->setCircle( m_circle );
+
+ m_object = r;
+}
+
+NewLineCommand::NewLineCommand( MyCanvasView* v )
+ : NewItemCommand( v, i18n("New Line") )
+{
+}
+
+void NewLineCommand::create()
+{
+ m_object = new LineItem();
+}
+
+NewTextCommand::NewTextCommand( QString t, MyCanvasView* v, TokenProvider* token )
+ : NewItemCommand( v, i18n("New Text") ),
+ m_token( token )
+{
+ text = t;
+}
+
+void NewTextCommand::create()
+{
+ TextItem* t = new TextItem();
+ t->setTokenProvider( m_token );
+ t->setText( text );
+
+ m_object = t;
+}
+
+//NY25
+NewTextLineCommand::NewTextLineCommand( QString t, MyCanvasView* v, TokenProvider* token )
+ : NewItemCommand( v, i18n("New TextLine") ),
+ m_token( token )
+{
+ text = t;
+}
+
+void NewTextLineCommand::create()
+{
+ TextLineItem* t = new TextLineItem();
+ t->setTokenProvider( m_token );
+ t->setText( text );
+
+ m_object = t;
+}
+//NY25
+
+NewBarcodeCommand::NewBarcodeCommand( MyCanvasView* v, TokenProvider* token )
+ : NewItemCommand( v, i18n("New Barcode") ),
+ m_token( token )
+{
+}
+
+void NewBarcodeCommand::create()
+{
+ m_object = new BarcodeItem();
+ m_object->setTokenProvider( m_token );
+}
+
+DeleteCommand::~DeleteCommand()
+{
+ if( m_canvas_item && canvasHasItem() && m_canvas_item->canvas() == 0 )
+ {
+ DocumentItem* item = m_canvas_item->item();
+ if( item )
+ item->disconnect( item, SIGNAL( destroyed() ), this, 0 );
+ delete m_canvas_item;
+ }
+}
+
+void DeleteCommand::execute()
+{
+ if( canvasHasItem() ) {
+ m_canvas_item->setCanvas( 0 );
+ m_canvas_item->hide();
+ }
+}
+
+void DeleteCommand::unexecute()
+{
+ // canvasHasItem won't work here
+ if( m_canvas_item ) {
+ m_canvas_item->setCanvas( c );
+ m_canvas_item->show();
+ }
+}
+
+BorderCommand::BorderCommand( bool border, const QPen & pen, DocumentItem* item )
+ : CommandUtils( item->canvasItem() )
+{
+ m_new_border = border;
+ m_new_pen = pen;
+ m_item = item;
+}
+
+void BorderCommand::execute()
+{
+ if( canvasHasItem() )
+ {
+ m_old_border = m_item->border();
+ m_old_pen = m_item->pen();
+ m_item->setBorder( m_new_border );
+ m_item->setPen( m_new_pen );
+
+ m_canvas_item->update();
+ }
+}
+
+void BorderCommand::unexecute()
+{
+ if( canvasHasItem() )
+ {
+ m_item->setBorder( m_old_border );
+ m_item->setPen( m_old_pen );
+
+ m_canvas_item->update();
+ }
+}
+
+FillCommand::FillCommand( QColor c, RectItem* r )
+ : CommandUtils( r->canvasItem() )
+{
+ fill = c;
+ m_item = r;
+}
+
+void FillCommand::execute()
+{
+ if( canvasHasItem() ) {
+ fill2 = m_item->color();
+ m_item->setColor( fill );
+ }
+}
+
+void FillCommand::unexecute()
+{
+ if( canvasHasItem() ) {
+ m_item->setColor( fill2 );
+ }
+}
+
+void ScriptCommand::execute()
+{
+ if( canvasHasItem() )
+ {
+ m_old_script = m_canvas_item->item()->visibilityScript();
+ m_canvas_item->item()->setVisibilityScript( m_script );
+ m_canvas_item->update();
+ }
+}
+
+void ScriptCommand::unexecute()
+{
+ if( canvasHasItem() )
+ {
+ m_canvas_item->item()->setVisibilityScript( m_old_script );
+ m_canvas_item->update();
+ }
+}
+
+#include "commands.moc"
diff --git a/kbarcode/commands.h b/kbarcode/commands.h
new file mode 100644
index 0000000..e9eb001
--- /dev/null
+++ b/kbarcode/commands.h
@@ -0,0 +1,433 @@
+/***************************************************************************
+ commands.h - description
+ -------------------
+ begin : Don Dez 19 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef COMMANDS_H
+#define COMMANDS_H
+
+#include "mycanvasitem.h"
+
+#include <qobject.h>
+
+#include <kcommand.h>
+#include <klocale.h>
+
+#include "barcodeitem.h"
+#include "tcanvasitem.h"
+#include "imageitem.h"
+
+struct barcodeData;
+class RectItem;
+class MyCanvasLine;
+class MyCanvasRectangle;
+class MyCanvasView;
+class CanvasBarcode;
+class PictureRectangle;
+class QCanvasItem;
+class QColor;
+class QFont;
+class QImage;
+class QPen;
+class QPixmap;
+class QPoint;
+class QString;
+class TextItem;
+//NY29
+class TextLineItem;
+//NY29
+class TokenProvider;
+
+// Stuff for undo redo
+
+class CommandUtils : public QObject {
+ Q_OBJECT
+ public:
+ CommandUtils(TCanvasItem* item);
+ ~CommandUtils();
+
+ bool canvasHasItem();
+
+ private slots:
+ void documentItemDeleted();
+
+ protected:
+ QCanvas* c;
+ TCanvasItem* m_canvas_item;
+};
+
+/**
+ * NewItemCommand is the base class for all classes
+ * that create a new item in the label editor (e.g. a
+ * barcode or a text element).
+ * You have to implement void create() which creates
+ * a QCanvasItem in item.
+ * NewItemCommand takes care about possitioning and
+ * undo/redo (because of KCommand).
+ *
+ * @author Dominik Seichter
+ */
+class NewItemCommand : public QObject, public KCommand {
+ Q_OBJECT
+ public:
+ NewItemCommand( MyCanvasView* view, const QString & name );
+ virtual ~NewItemCommand();
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return m_name;
+ };
+
+ /** @returns a pointer to the TCanvasItem created by this class
+ */
+ inline TCanvasItem* createdItem() const { return m_item; }
+
+ private slots:
+ void documentItemDeleted();
+
+ protected:
+ /** This function has to be reimplemented in all subclasses
+ * and has to create a QCanvasItem and store a pointer to it
+ * in item. Otherwise KBarcode is going to crash.
+ *
+ * Example:
+ *
+ * <pre>
+ * void create() {
+ * DrawingRect* r = new DrawingRect( 0 ); // Drawing rect is a subclass of QCanvasItem
+ * r->setCircle( m_circle ); // Do something with r
+ * item = r; // save r into item, so that NewItemCommand knows about it
+ * }
+ * </pre>
+ */
+ virtual void create() = 0;
+
+ MyCanvasView* cv;
+ TCanvasItem* m_item;
+ DocumentItem* m_object;
+ QPoint m_point;
+ QString m_name;
+};
+
+class ResizeCommand : public KCommand, CommandUtils {
+ public:
+ ResizeCommand( TCanvasItem* it, bool shift = false )
+ : CommandUtils( it )
+ {
+ orect = rect = m_canvas_item->item()->rectMM();
+ m_shift = shift;
+ }
+ ~ResizeCommand() {}
+
+ void setRect( int cx, int cy, int cw, int ch );
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Resized Item");
+ }
+
+ protected:
+ QRect orect;
+ QRect rect;
+ bool m_shift;
+};
+
+/** Move a TCanvasItem on the canvas
+ */
+class MoveCommand : public KCommand, CommandUtils {
+ public:
+ /**
+ * @param cx move in x direction cx mm
+ * @param cy move in y direction cy mm
+ */
+ MoveCommand( int cx, int cy, TCanvasItem* it )
+ : CommandUtils( it )
+ {
+ x = cx;
+ y = cy;
+ }
+ ~MoveCommand() {}
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Moved Item");
+ }
+
+ protected:
+ int x;
+ int y;
+};
+
+class ChangeZCommand : public KCommand, CommandUtils {
+ public:
+ ChangeZCommand( int z, TCanvasItem* it );
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Raised or lowered an item");
+ }
+
+ protected:
+ int m_z, m_oldz;
+};
+
+class LockCommand : public KCommand, CommandUtils {
+ public:
+ LockCommand( bool lock, TCanvasItem* it )
+ : CommandUtils( it )
+ {
+ m_locked = lock;
+ }
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Protected Item");
+ }
+
+ protected:
+ bool m_locked;
+};
+
+class PictureCommand : public KCommand, CommandUtils {
+ public:
+ PictureCommand( double r, bool mirrorh, bool mirrorv, EImageScaling s, ImageItem* it );
+ ~PictureCommand() {}
+
+ void setExpression( const QString & expr );
+ void setPixmap( const QPixmap & pix );
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Changed Settings");
+ }
+ protected:
+ double rotate, orotate;
+ bool mirrorv, omirrorv;
+ bool mirrorh, omirrorh;
+ QString expression, oexpression;
+ EImageScaling scaling, oscaling;
+ QPixmap pixmap, opixmap;
+ QSize oldsize;
+ int pixserial, opixserial;
+
+ ImageItem* m_item;
+};
+
+class TextChangeCommand : public KCommand, CommandUtils {
+ public:
+ TextChangeCommand( TextItem* it, QString t );
+ ~TextChangeCommand() { }
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Changed Text");
+ }
+ protected:
+ QString oldtext, text;
+ TextItem* m_item;
+};
+
+class TextRotationCommand : public KCommand, protected CommandUtils {
+ public:
+ TextRotationCommand( double rot, TextItem* t );
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Rotated Text");
+ }
+
+ protected:
+ double rot1, rot2;
+ TextItem* m_item;
+};
+
+
+//NY28
+class TextLineChangeCommand : public KCommand, CommandUtils {
+ public:
+ TextLineChangeCommand( TextLineItem* it, QString t, int font, int magvert, int maghor );
+ ~TextLineChangeCommand() { }
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Changed Text");
+ }
+ protected:
+ QString oldtext, text;
+ TextLineItem* m_item;
+ int m_font;
+ int m_mag_vert;
+ int m_mag_hor;
+};
+//NY28
+
+class BarcodeCommand : public KCommand, CommandUtils {
+ public:
+ BarcodeCommand( BarcodeItem* bcode, Barkode* d );
+ ~BarcodeCommand() {
+ delete data;
+ }
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Changed Barcode");
+ }
+ protected:
+ Barkode olddata;
+ Barkode* data;
+ BarcodeItem* m_item;
+};
+
+class NewPictureCommand : public NewItemCommand {
+ public:
+ NewPictureCommand( MyCanvasView* v )
+ : NewItemCommand( v, i18n("New Picture") )
+ {
+ }
+
+ protected:
+ void create();
+};
+
+class NewTextCommand : public NewItemCommand {
+ public:
+ NewTextCommand( QString t, MyCanvasView* v, TokenProvider* token );
+
+ protected:
+ void create();
+ QString text;
+ TokenProvider* m_token;
+};
+
+//NY27
+class NewTextLineCommand : public NewItemCommand {
+ public:
+ NewTextLineCommand( QString t, MyCanvasView* v, TokenProvider* token );
+
+ protected:
+ void create();
+ QString text;
+ TokenProvider* m_token;
+};
+//NY27
+
+class NewRectCommand : public NewItemCommand {
+ public:
+ NewRectCommand( MyCanvasView* v, bool circle = false );
+
+ protected:
+ void create();
+ bool m_circle;
+};
+
+class NewLineCommand : public NewItemCommand {
+ public:
+ NewLineCommand( MyCanvasView* v );
+
+ protected:
+ void create();
+};
+
+class NewBarcodeCommand : public NewItemCommand {
+ public:
+ NewBarcodeCommand( MyCanvasView* v, TokenProvider* token );
+
+ protected:
+ void create();
+
+ private:
+ TokenProvider* m_token;
+};
+
+class DeleteCommand : public KCommand, CommandUtils {
+ public:
+ DeleteCommand( TCanvasItem* it )
+ : CommandUtils( it )
+ {
+ }
+ ~DeleteCommand();
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Delete Item");
+ }
+};
+
+class BorderCommand : public KCommand, protected CommandUtils {
+ public:
+ BorderCommand( bool border, const QPen & pen, DocumentItem* item );
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Modified Border");
+ }
+
+ protected:
+ bool m_new_border;
+ bool m_old_border;
+ QPen m_new_pen;
+ QPen m_old_pen;
+
+ DocumentItem* m_item;
+};
+
+class FillCommand : public KCommand, protected CommandUtils {
+ public:
+ FillCommand( QColor c, RectItem* r );
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Modified Rectangle or Ellipse");
+ }
+
+ protected:
+ QColor fill, fill2;
+ RectItem* m_item;
+};
+
+class ScriptCommand : public KCommand, CommandUtils {
+ public:
+ ScriptCommand( const QString & script, TCanvasItem* it )
+ : CommandUtils( it )
+ {
+ m_script = script;
+ }
+ ~ScriptCommand() {}
+
+ void execute();
+ void unexecute();
+ QString name() const {
+ return i18n("Changed visibility JavaScript");
+ }
+
+ protected:
+ QString m_script;
+ QString m_old_script;
+};
+
+#endif
diff --git a/kbarcode/configdialog.cpp b/kbarcode/configdialog.cpp
new file mode 100644
index 0000000..787a560
--- /dev/null
+++ b/kbarcode/configdialog.cpp
@@ -0,0 +1,351 @@
+/***************************************************************************
+ configdialog.cpp - description
+ -------------------
+ begin : Fre Apr 26 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "configdialog.h"
+#include "printersettings.h"
+#include "sqltables.h"
+
+// Qt includes
+#include <qbuttongroup.h>
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpaintdevicemetrics.h>
+#include <qradiobutton.h>
+#include <qsqldatabase.h>
+#include <qtooltip.h>
+
+// KDE includes
+#include <kabc/addressee.h>
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kcolorbutton.h>
+#include <kiconloader.h>
+#include <kimageio.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kcombobox.h>
+#include <knuminput.h>
+#include <kmessagebox.h>
+#include <kpushbutton.h>
+
+const QString cached = I18N_NOOP("There are currently %1 cached barcodes.");
+using namespace KABC;
+
+ConfigDialog::ConfigDialog( QWidget* parent )
+ : KDialogBase( IconList, i18n("Configure KBarcode"), KDialogBase::Ok|KDialogBase::Cancel,
+ KDialogBase::Ok, parent, "", true, true )
+{
+ setupTab2(); // Printer
+ setupTab1(); // SQL
+ setupTab4(); // label editor
+ setupTab3(); // import
+ setupTab5(); // on new
+}
+
+ConfigDialog::~ConfigDialog()
+{
+}
+
+void ConfigDialog::setupTab1( )
+{
+ QFrame* box = addPage( i18n("SQL Settings"), "", BarIcon("connect_no") );
+ QVBoxLayout* layout = new QVBoxLayout( box, 6, 6 );
+ QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding );
+
+ sqlwidget = new SqlWidget( false, box, "sqlwidget" );
+
+ layout->addWidget( sqlwidget );
+ layout->addItem( spacer );
+}
+
+void ConfigDialog::setupTab2()
+{
+ labelprinterdata* lb = PrinterSettings::getInstance()->getData();
+
+ QFrame* box = addPage( i18n("Print Settings"), "", BarIcon("fileprint") );
+
+ QVBoxLayout* tabLayout = new QVBoxLayout( box, 11, 6 );
+ QHBoxLayout* Layout0 = new QHBoxLayout( 0, 6, 6 );
+ QHBoxLayout* Layout1 = new QHBoxLayout( 0, 6, 6 );
+ QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding );
+
+ printerQuality = new KComboBox( false, box );
+ printerQuality->insertItem( i18n("Medium Resolution (300dpi)") );
+ printerQuality->insertItem( i18n("High Resolution (600dpi)") );
+ printerQuality->insertItem( i18n("Very High Resolution (1200dpi)") );
+
+ switch( lb->quality ) {
+ case PrinterSettings::Middle:
+ printerQuality->setCurrentItem( 0 );
+ break;
+ case PrinterSettings::High:
+ printerQuality->setCurrentItem( 1 );
+ break;
+ case PrinterSettings::VeryHigh:
+ printerQuality->setCurrentItem( 2 );
+ break;
+ default:
+ break;
+ }
+
+ pageFormat = new KComboBox( false, box );
+ PrinterSettings::getInstance()->insertPageFormat( pageFormat );
+ pageFormat->setCurrentItem( lb->format );
+
+ Layout0->addWidget( new QLabel( i18n("Printer Resolution:"), box ) );
+ Layout0->addWidget( printerQuality );
+ Layout1->addWidget( new QLabel( i18n("Preview Page Format:"), box ) );
+ Layout1->addWidget( pageFormat );
+ tabLayout->addLayout( Layout0 );
+ tabLayout->addLayout( Layout1 );
+ tabLayout->addItem( spacer );
+}
+
+void ConfigDialog::setupTab3()
+{
+ labelprinterdata* lb = PrinterSettings::getInstance()->getData();
+
+ QFrame* box = addPage( i18n("Import"), "", BarIcon("fileimport") );
+ QGridLayout* grid = new QGridLayout( box, 2, 2 );
+
+ QLabel* label = new QLabel( box );
+ label->setText( i18n("Comment:") );
+ grid->addWidget( label, 0, 0 );
+
+ comment = new KLineEdit( lb->comment, box );
+ grid->addWidget( comment, 0, 1 );
+
+ label = new QLabel( box );
+ label->setText( i18n( "Separator:" ) );
+ grid->addWidget( label, 1, 0 );
+
+ separator = new KLineEdit( lb->separator, box );
+ grid->addWidget( separator, 1, 1 );
+
+ label = new QLabel( box );
+ label->setText( i18n("Quote Character:") );
+ grid->addWidget( label, 2, 0 );
+
+ quote = new KLineEdit( lb->quote, box );
+ grid->addWidget( quote, 2, 1 );
+
+ checkUseCustomNo = new QCheckBox( i18n("&Use customer article no. for import"), box );
+ checkUseCustomNo->setChecked( lb->useCustomNo );
+
+ grid->addMultiCellWidget( checkUseCustomNo, 3, 3, 0, 2 );
+
+ QHBoxLayout* Layout1 = new QHBoxLayout( 0, 6, 6 );
+ Layout1->addWidget( new QLabel( i18n("File Format:"), box ) );
+
+ combo1 = new KComboBox( box );
+ combo1->insertItem( i18n("Quantity") );
+ combo1->insertItem( i18n("Article Number") );
+ combo1->insertItem( i18n("Group") );
+ Layout1->addWidget( combo1 );
+
+ combo2 = new KComboBox( box );
+ combo2->insertItem( i18n("Quantity") );
+ combo2->insertItem( i18n("Article Number") );
+ combo2->insertItem( i18n("Group") );
+ Layout1->addWidget( combo2 );
+
+ combo3 = new KComboBox( box );
+ combo3->insertItem( i18n("Quantity") );
+ combo3->insertItem( i18n("Article Number") );
+ combo3->insertItem( i18n("Group") );
+ Layout1->addWidget( combo3 );
+
+ grid->addMultiCellLayout( Layout1, 4, 4, 0, 2 );
+ QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ grid->addItem( spacer, 5, 0 );
+
+ KConfig* config = kapp->config();
+ config->setGroup("FileFormat");
+ combo1->setCurrentItem( config->readNumEntry("Data0", 0 ) );
+ combo2->setCurrentItem( config->readNumEntry("Data1", 1 ) );
+ combo3->setCurrentItem( config->readNumEntry("Data2", 2 ) );
+}
+
+void ConfigDialog::setupTab4()
+{
+ QFrame* box = addPage( i18n("Label Editor"), "", BarIcon("kbarcode") );
+ QGridLayout* tabLayout = new QGridLayout( box, 11, 6 );
+
+ checkNewDlg = new QCheckBox( box );
+ checkNewDlg->setText( i18n("&Create a new label on startup") );
+
+ date = new KLineEdit( box );
+ labelDate = new QLabel( box );
+
+ connect( date, SIGNAL( textChanged( const QString & ) ), this, SLOT( updateDatePreview() ) );
+
+ spinGrid = new KIntNumInput( 0, box );
+ spinGrid->setLabel( i18n("Grid:" ), AlignLeft | AlignVCenter );
+ spinGrid->setRange(2, 100, 1, false );
+
+ colorGrid = new KColorButton( box );
+
+ tabLayout->addWidget( checkNewDlg, 0, 0 );
+ tabLayout->addMultiCellWidget( spinGrid, 1, 1, 0, 2 );
+ tabLayout->addWidget( new QLabel( i18n("Grid Color:"), box ), 2, 0 );
+ tabLayout->addWidget( colorGrid, 2, 1 );
+ tabLayout->addWidget( new QLabel( i18n("Date Format:"), box ), 3, 0 );
+ tabLayout->addWidget( date, 3, 1 );
+ tabLayout->addWidget( labelDate, 3, 2 );
+}
+
+void ConfigDialog::setupTab5()
+{
+ labelprinterdata* lb = PrinterSettings::getInstance()->getData();
+ QFrame* box = addPage( i18n("On New"), "", BarIcon("filenew") );
+
+ QVBoxLayout* tabLayout = new QVBoxLayout( box, 11, 6 );
+
+ QButtonGroup* bg = new QButtonGroup( i18n("On New Article"), box );
+ bg->setColumnLayout(0, Qt::Vertical );
+ bg->layout()->setSpacing( 6 );
+ bg->layout()->setMargin( 11 );
+ QGridLayout* bgLayout = new QGridLayout( bg->layout() );
+
+ QStringList alist, glist;
+ alist.append( i18n("No Line Break") );
+ alist.append( i18n("Line Break") );
+ alist.append( i18n("Insert Label X") );
+ alist.append( i18n("New Page") );
+ alist.append( i18n("Article No.") );
+
+ glist.append( i18n("No Line Break") );
+ glist.append( i18n("Line Break") );
+ glist.append( i18n("Insert Label X") );
+ glist.append( i18n("New Page") );
+ glist.append( i18n("Group Name") );
+
+ onNewArticle1 = new KComboBox( false, bg );
+ onNewArticle2 = new KComboBox( false, bg );
+ onNewArticle3 = new KComboBox( false, bg );
+ onNewArticle4 = new KComboBox( false, bg );
+
+ onNewArticle1->insertStringList( alist );
+ onNewArticle2->insertStringList( alist );
+ onNewArticle3->insertStringList( alist );
+ onNewArticle4->insertStringList( alist );
+
+ bgLayout->setColStretch( 1, 3 );
+
+ bgLayout->addWidget( new QLabel( "1.", bg ), 0, 0 );
+ bgLayout->addWidget( new QLabel( "2.", bg ), 1, 0 );
+ bgLayout->addWidget( new QLabel( "3.", bg ), 2, 0 );
+ bgLayout->addWidget( new QLabel( "4.", bg ), 3, 0 );
+
+ bgLayout->addWidget( onNewArticle1, 0, 1 );
+ bgLayout->addWidget( onNewArticle2, 1, 1 );
+ bgLayout->addWidget( onNewArticle3, 2, 1 );
+ bgLayout->addWidget( onNewArticle4, 3, 1 );
+
+ QButtonGroup* bg2 = new QButtonGroup( i18n("On New Group"), box );
+ bg2->setColumnLayout(0, Qt::Vertical );
+ bg2->layout()->setSpacing( 6 );
+ bg2->layout()->setMargin( 11 );
+ QGridLayout* bg2Layout = new QGridLayout( bg2->layout() );
+
+ onNewGroup1 = new KComboBox( false, bg2 );
+ onNewGroup2 = new KComboBox( false, bg2 );
+ onNewGroup3 = new KComboBox( false, bg2 );
+ onNewGroup4 = new KComboBox( false, bg2 );
+
+ onNewGroup1->insertStringList( glist );
+ onNewGroup2->insertStringList( glist );
+ onNewGroup3->insertStringList( glist );
+ onNewGroup4->insertStringList( glist );
+
+ bg2Layout->setColStretch( 1, 3 );
+
+ bg2Layout->addWidget( new QLabel( "1.", bg2 ), 0, 0 );
+ bg2Layout->addWidget( new QLabel( "2.", bg2 ), 1, 0 );
+ bg2Layout->addWidget( new QLabel( "3.", bg2 ), 2, 0 );
+ bg2Layout->addWidget( new QLabel( "4.", bg2 ), 3, 0 );
+
+ bg2Layout->addWidget( onNewGroup1, 0, 1 );
+ bg2Layout->addWidget( onNewGroup2, 1, 1 );
+ bg2Layout->addWidget( onNewGroup3, 2, 1 );
+ bg2Layout->addWidget( onNewGroup4, 3, 1 );
+
+ tabLayout->addWidget( bg );
+ tabLayout->addWidget( bg2 );
+
+ onNewArticle1->setCurrentItem( lb->articleEvent1 );
+ onNewArticle2->setCurrentItem( lb->articleEvent2 );
+ onNewArticle3->setCurrentItem( lb->articleEvent3 );
+ onNewArticle4->setCurrentItem( lb->articleEvent4 );
+
+ onNewGroup1->setCurrentItem( lb->groupEvent1 );
+ onNewGroup2->setCurrentItem( lb->groupEvent2 );
+ onNewGroup3->setCurrentItem( lb->groupEvent3 );
+ onNewGroup4->setCurrentItem( lb->groupEvent4 );
+}
+
+void ConfigDialog::accept()
+{
+ KConfig* config = kapp->config();
+ config->setGroup("FileFormat");
+ config->writeEntry("Data0", combo1->currentItem() );
+ config->writeEntry("Data1", combo2->currentItem() );
+ config->writeEntry("Data2", combo3->currentItem() );
+
+ sqlwidget->save();
+
+ labelprinterdata* lpdata = PrinterSettings::getInstance()->getData();
+ lpdata->comment = comment->text();
+ lpdata->separator = separator->text();
+ lpdata->quote = quote->text();
+ lpdata->format = pageFormat->currentItem();
+
+ lpdata->articleEvent1 = onNewArticle1->currentItem();
+ lpdata->articleEvent2 = onNewArticle2->currentItem();
+ lpdata->articleEvent3 = onNewArticle3->currentItem();
+ lpdata->articleEvent4 = onNewArticle4->currentItem();
+
+ lpdata->groupEvent1 = onNewGroup1->currentItem();
+ lpdata->groupEvent2 = onNewGroup2->currentItem();
+ lpdata->groupEvent3 = onNewGroup3->currentItem();
+ lpdata->groupEvent4 = onNewGroup4->currentItem();
+ lpdata->useCustomNo = checkUseCustomNo->isChecked();
+
+ switch( printerQuality->currentItem() ) {
+ case 0:
+ lpdata->quality = PrinterSettings::Middle;
+ break;
+ case 1:
+ lpdata->quality = PrinterSettings::High;
+ break;
+ case 2:
+ lpdata->quality = PrinterSettings::VeryHigh;
+ break;
+ default:
+ break;
+ }
+
+ QDialog::accept();
+}
+
+void ConfigDialog::updateDatePreview()
+{
+ labelDate->setText( i18n("Preview: ") + QDateTime::currentDateTime().toString( date->text() ) );
+}
+
+#include "configdialog.moc"
diff --git a/kbarcode/configdialog.h b/kbarcode/configdialog.h
new file mode 100644
index 0000000..5838f78
--- /dev/null
+++ b/kbarcode/configdialog.h
@@ -0,0 +1,95 @@
+/***************************************************************************
+ configdialog.h - description
+ -------------------
+ begin : Fre Apr 26 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef CONFIGDIALOG_H
+#define CONFIGDIALOG_H
+
+#include <kdialogbase.h>
+
+struct labelprinterdata;
+struct mysqldata;
+class KComboBox;
+class KColorButton;
+class KIntNumInput;
+class KDoubleNumInput;
+class KLineEdit;
+class KPushButton;
+class QRadioButton;
+class QCheckBox;
+class QLabel;
+class QString;
+class QWidget;
+class SqlWidget;
+/** KBarcodes configuration dialog for advanced settings.
+ */
+
+class ConfigDialog : public KDialogBase {
+ Q_OBJECT
+ public:
+ ConfigDialog( QWidget* parent );
+ ~ConfigDialog();
+
+ KLineEdit* comment;
+ KLineEdit* separator;
+ KLineEdit* quote;
+ KLineEdit* date;
+
+ KIntNumInput* spinGrid;
+
+ KComboBox* printerQuality;
+ KComboBox* pageFormat;
+
+ QLabel* labelDate;
+
+ QCheckBox* checkNewDlg;
+ QCheckBox* checkUseCustomNo;
+
+ KComboBox* combo1;
+ KComboBox* combo2;
+ KComboBox* combo3;
+
+ KComboBox* onNewArticle1;
+ KComboBox* onNewArticle2;
+ KComboBox* onNewArticle3;
+ KComboBox* onNewArticle4;
+
+ KComboBox* onNewGroup1;
+ KComboBox* onNewGroup2;
+ KComboBox* onNewGroup3;
+ KComboBox* onNewGroup4;
+
+ KColorButton* colorGrid;
+
+ private:
+ void accept();
+
+ void setupTab1();
+ void setupTab2();
+ void setupTab3();
+ void setupTab4();
+ void setupTab5();
+
+ private slots:
+ void updateDatePreview();
+
+ protected:
+ KComboBox* comboDataMatrix;
+
+ SqlWidget* sqlwidget;
+};
+
+#endif
diff --git a/kbarcode/confwizard.cpp b/kbarcode/confwizard.cpp
new file mode 100644
index 0000000..7809c6c
--- /dev/null
+++ b/kbarcode/confwizard.cpp
@@ -0,0 +1,255 @@
+/***************************************************************************
+ confwizard.cpp - description
+ -------------------
+ begin : Son Jun 16 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "confwizard.h"
+#include "sqltables.h"
+#include "printersettings.h"
+#include "dsmainwindow.h"
+
+// Qt includes
+#include <qbuttongroup.h>
+#include <qcheckbox.h>
+#include <qcursor.h>
+#include <qlayout.h>
+#include <qsqldatabase.h>
+#include <qradiobutton.h>
+#include <qprinter.h>
+#include <qtextbrowser.h>
+
+// KDE includes
+#include <kapplication.h>
+#include <kcombobox.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kpushbutton.h>
+#include <kurllabel.h>
+#include <kstandarddirs.h>
+
+
+const char* description = I18N_NOOP(
+ "KBarcode is a barcode and label printing application for KDE 3. It can "
+ "be used to print every thing from simple business cards up to complex "
+ "labels with several barcodes (e.g. article descriptions). KBarcode "
+ "comes with an easy to use WYSIWYG label designer, a setup wizard, "
+ "batch import of labels (directly from the delivery note), thousands "
+ "of predefined labels, database management tools and translations "
+ "in many languages. Even printing more than 10.000 labels in one go is "
+ "no problem for KBarcode. Additionally it is a simply xbarcode "
+ "replacement for the creation of barcodes. All major types of barcodes "
+ "like EAN, UPC, CODE39 and ISBN are supported." );
+
+ConfWizard::ConfWizard( QWidget* parent, const char* name, bool modal )
+ : KWizard( parent, name, modal )
+{
+ setCaption( i18n( "Configure KBarcode" ) );
+
+ setupPage1();
+ setupPage0();
+ setupPage2();
+ setupPage3();
+
+ setNextEnabled( page_2, false );
+ helpButton()->hide();
+
+ connect( buttonCreate, SIGNAL( clicked() ), this, SLOT( create() ) );
+ connect( buttonExample, SIGNAL( clicked() ), this, SLOT( example() ) );
+ connect( checkDatabase, SIGNAL( clicked() ), this, SLOT( useDatabase() ) );
+}
+
+ConfWizard::~ConfWizard()
+{ }
+
+void ConfWizard::accept()
+{
+ sqlwidget->save( checkDatabase->isChecked() );
+
+ KWizard::accept();
+}
+
+void ConfWizard::setupPage1()
+{
+ page = new QWidget( this, "page" );
+ pageLayout = new QVBoxLayout( page, 11, 6, "pageLayout");
+
+ Layout8 = new QHBoxLayout( 0, 0, 6, "Layout8");
+
+ Layout7 = new QVBoxLayout( 0, 0, 6, "Layout7");
+
+ logo = new QLabel( page, "logo" );
+ logo->setPixmap( locate("data", "kbarcode/logo.png") );
+ QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ pageLayout->addWidget( logo );
+ Layout7->addItem( spacer );
+ Layout8->addLayout( Layout7 );
+
+ TextLabel2_2 = new QLabel( page, "TextLabel2_2" );
+ TextLabel2_2->setText( i18n( "<qt><h1>Welcome to KBarcode</h1><br><br>") +
+ i18n( description ) + "</qt>" );
+ Layout8->addWidget( TextLabel2_2 );
+
+ pageLayout->addLayout( Layout8 );
+
+ KURLLabel1 = new KURLLabel( page, "KURLLabel1" );
+ KURLLabel1->setText( "http://www.kbarcode.net" );
+ KURLLabel1->setURL("http://www.kbarcode.net");
+ pageLayout->addWidget( KURLLabel1 );
+ addPage( page, i18n( "Welcome" ) );
+}
+
+void ConfWizard::setupPage0()
+{
+ QWidget* page_0 = new QWidget( this, "page_0" );
+ QVBoxLayout* pageLayout = new QVBoxLayout( page_0, 11, 6, "pageLayout");
+
+ QTextBrowser* b = new QTextBrowser( page_0, "b" );
+ b->setText( DSMainWindow::systemCheck() );
+
+ pageLayout->addWidget( b );
+
+ addPage( page_0, i18n("System Check") );
+}
+
+void ConfWizard::setupPage2()
+{
+ page_2 = new QWidget( this, "page_2" );
+ pageLayout_2 = new QVBoxLayout( page_2, 11, 6, "pageLayout_2");
+
+ checkDatabase = new QCheckBox( page_2 );
+ checkDatabase->setText( i18n("&Use database with KBarcode") );
+ checkDatabase->setChecked( true );
+
+ sqlwidget = new SqlWidget( true, page_2, "sqlwidget" );
+ connect( sqlwidget, SIGNAL( databaseWorking( bool ) ), this, SLOT( testSettings( bool ) ) );
+
+ QSpacerItem* spacer_5 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ pageLayout_2->addWidget( checkDatabase );
+ pageLayout_2->addWidget( sqlwidget );
+ pageLayout_2->addItem( spacer_5 );
+
+ addPage( page_2, i18n( "Database" ) );
+}
+
+void ConfWizard::setupPage3()
+{
+ page_3 = new QWidget( this, "page_3" );
+ pageLayout_3 = new QVBoxLayout( page_3, 11, 6, "pageLayout_3");
+
+ TextLabel1_2 = new QLabel( page_3, "TextLabel1_2" );
+ TextLabel1_2->setText( i18n( "KBarcode can create the required SQL tables for you.<br>KBarcode will add also some Label Definitions to the tables.<br>After that you can fill the tables with some example data." ) );
+ TextLabel1_2->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) );
+ pageLayout_3->addWidget( TextLabel1_2 );
+
+ Layout5_2 = new QVBoxLayout( 0, 0, 6, "Layout5_2");
+
+ buttonCreate = new KPushButton( page_3, "buttonCreate" );
+ buttonCreate->setText( i18n( "&Create Tables" ) );
+ Layout5_2->addWidget( buttonCreate );
+
+ buttonExample = new KPushButton( page_3, "buttonExample" );
+ buttonExample->setEnabled( FALSE );
+ buttonExample->setText( i18n( "&Add Example Data" ) );
+ Layout5_2->addWidget( buttonExample );
+ QSpacerItem* spacer_6 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ Layout5_2->addItem( spacer_6 );
+ pageLayout_3->addLayout( Layout5_2 );
+ addPage( page_3, i18n( "Create Tables" ) );
+}
+
+void ConfWizard::testSettings( bool b )
+{
+ setNextEnabled( page_2, b );
+}
+
+void ConfWizard::create()
+{
+ KApplication::setOverrideCursor( Qt::WaitCursor );
+ if(!SqlTables::getInstance()->newTables( sqlwidget->username(), sqlwidget->password(), sqlwidget->hostname(), sqlwidget->database(), sqlwidget->driver() ) )
+ {
+ KApplication::restoreOverrideCursor();
+ return;
+ }
+ else
+ KApplication::restoreOverrideCursor();
+
+ QSqlDatabase* db = QSqlDatabase::addDatabase( sqlwidget->driver() );
+ db->setDatabaseName( sqlwidget->database() );
+ db->setUserName( sqlwidget->username() );
+ db->setPassword( sqlwidget->password() );
+ db->setHostName( sqlwidget->hostname() );
+
+ if( !db->open() )
+ KMessageBox::error( this, i18n("<qt>Connection failed:<br>") + sqlwidget->database(),
+ db->lastError().databaseText() + "</qt>" );
+
+ if( db->open() ) {
+ KApplication::setOverrideCursor( Qt::WaitCursor );
+ SqlTables::getInstance()->importData(
+ locate("appdata", "labeldefinitions.sql"), db );
+ buttonExample->setEnabled( true );
+ KApplication::restoreOverrideCursor();
+ }
+
+ db->close();
+}
+
+void ConfWizard::example()
+{
+ QSqlDatabase* db = QSqlDatabase::addDatabase( sqlwidget->driver() );
+ db->setDatabaseName( sqlwidget->database() );
+ db->setUserName( sqlwidget->username() );
+ db->setPassword( sqlwidget->password() );
+ db->setHostName( sqlwidget->hostname() );
+
+ if( !db->open() )
+ KMessageBox::error( this, i18n("<qt>Connection failed:<br>") + sqlwidget->database(),
+ db->lastError().databaseText() + "</qt>" );
+
+
+ SqlTables::getInstance()->importData(
+ locate("appdata", "exampledata.sql"), db );
+ KMessageBox::information( this, i18n("Example data has been imported.") );
+
+ db->close();
+}
+
+void ConfWizard::showPage( QWidget* page )
+{
+ QWizard::showPage(page);
+
+ if( page == page_2 && !sqlwidget->driverCount() ) {
+ KMessageBox::information( this, i18n(
+ "There are no Qt SQL drivers installed. "
+ "KBarcode needs those drivers to access the different SQL databases. "
+ "This drivers are part of the Qt Source distribution and should also be part of "
+ "your distribution. Please install them first.") );
+ }
+
+ if ( page == page_3 )
+ finishButton()->setEnabled( true );
+}
+
+void ConfWizard::useDatabase()
+{
+ setFinishEnabled( page_2, !checkDatabase->isChecked() );
+ setNextEnabled( page_2, false );
+ setFinishEnabled( page_3, checkDatabase->isChecked() );
+ sqlwidget->setEnabled( checkDatabase->isChecked() );
+}
+
+
+#include "confwizard.moc"
diff --git a/kbarcode/confwizard.h b/kbarcode/confwizard.h
new file mode 100644
index 0000000..c1bfc20
--- /dev/null
+++ b/kbarcode/confwizard.h
@@ -0,0 +1,101 @@
+/***************************************************************************
+ confwizard.h - description
+ -------------------
+ begin : Son Jun 16 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef CONFWIZARD_H
+#define CONFWIZARD_H
+
+#include <kwizard.h>
+
+class QButtonGroup;
+class QCheckBox;
+class QVBoxLayout;
+class QHBoxLayout;
+class QGridLayout;
+class QRadioButton;
+class KComboBox;
+class KLineEdit;
+class KPushButton;
+class KURLLabel;
+class QLabel;
+class QWidget;
+class SqlWidget;
+/** KBarcodes configuration wizard.
+ */
+class ConfWizard : public KWizard
+{
+ Q_OBJECT
+
+ public:
+ ConfWizard( QWidget* parent = 0, const char* name = 0, bool modal = true );
+ ~ConfWizard();
+
+ void showPage( QWidget* page );
+
+ // used in dsmainwindow.cpp
+ // not a clean API, but I am lazy :-(
+ QCheckBox* checkDatabase;
+
+ private slots:
+ void testSettings( bool b );
+ void create();
+ void example();
+ void useDatabase();
+
+ protected slots:
+ void accept();
+
+ private:
+ void setupPage1();
+ void setupPage0();
+ void setupPage2();
+ void setupPage3();
+
+ SqlWidget* sqlwidget;
+
+ QWidget* page;
+ QLabel* logo;
+ QLabel* TextLabel2_2;
+ KURLLabel* KURLLabel1;
+ QWidget* page_2;
+ QLabel* TextLabel1;
+ QLabel* TextLabel2;
+ QLabel* TextLabel3;
+ QLabel* TextLabel4;
+ QLabel* TextLabel5;
+ QLabel* TextLabel6;
+ KPushButton* buttonTest;
+ QWidget* page_3;
+ QLabel* TextLabel1_2;
+ KPushButton* buttonCreate;
+ KPushButton* buttonExample;
+ QButtonGroup* groupDatabase;
+
+ protected:
+ QVBoxLayout* pageLayout;
+ QHBoxLayout* Layout8;
+ QVBoxLayout* Layout7;
+ QVBoxLayout* pageLayout_2;
+ QVBoxLayout* pageLayout_4;
+ QHBoxLayout* Layout5;
+ QVBoxLayout* Layout3;
+ QVBoxLayout* Layout4;
+ QVBoxLayout* Layout6;
+ QVBoxLayout* pageLayout_3;
+ QVBoxLayout* Layout5_2;
+};
+
+#endif // CONFWIZARD_H
diff --git a/kbarcode/csvfile.cpp b/kbarcode/csvfile.cpp
new file mode 100644
index 0000000..f8cc81f
--- /dev/null
+++ b/kbarcode/csvfile.cpp
@@ -0,0 +1,168 @@
+/***************************************************************************
+ csvfile.h - description
+ -------------------
+ begin : Mon Mar 28 2005
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "csvfile.h"
+
+#include "printersettings.h"
+
+#include <qbuffer.h>
+#include <qtextcodec.h>
+
+CSVFile::CSVFile( const QString & filename )
+{
+ m_eof = false;
+ m_csv = true;
+
+ m_quote = PrinterSettings::getInstance()->getData()->quote;
+ m_separator = PrinterSettings::getInstance()->getData()->separator;
+ m_comment = PrinterSettings::getInstance()->getData()->comment;
+
+ m_file.setName( filename );
+ m_file.open( IO_ReadOnly );
+
+ if( m_file.isOpen() )
+ m_stream.setDevice( &m_file );
+}
+
+CSVFile::CSVFile( QBuffer & buf )
+{
+ m_eof = false;
+ m_csv = true;
+
+ m_quote = PrinterSettings::getInstance()->getData()->quote;
+ m_separator = PrinterSettings::getInstance()->getData()->separator;
+ m_comment = PrinterSettings::getInstance()->getData()->comment;
+
+ buf.open( IO_ReadOnly );
+
+ if( buf.isOpen() )
+ m_stream.setDevice( &buf );
+}
+
+CSVFile::~CSVFile()
+{
+ if( m_stream.device() && m_stream.device()->isOpen() )
+ m_stream.device()->close();
+}
+
+QStringList CSVFile::readNextLine()
+{
+ QString line;
+
+ if( !m_stream.device() )
+ return QStringList();
+
+ if( !m_stream.device()->isOpen() )
+ return QStringList();
+
+ // walk through the lines until a line containing valid data
+ for( ;; )
+ {
+ line = m_stream.readLine();
+ line = line.stripWhiteSpace();
+
+ // check for eof
+ if( line.isNull() )
+ {
+ m_eof = true;
+ return QStringList();
+ }
+
+ // ignore comments and empty lines
+ if( (!m_comment.isEmpty() && line.startsWith( m_comment )) || line.isEmpty() )
+ continue;
+
+ break;
+ }
+
+ return m_csv ? readCsvLine( line ) : readFixedLine( line );
+}
+
+QStringList CSVFile::readCsvLine( const QString & l )
+{
+ QString line( l );
+ QStringList sections;
+ unsigned int start = 0;
+ unsigned int end = 0;
+ unsigned int len;
+ bool quoted = false;
+ bool quote_empty;
+
+ // if line does not end with separator, add one
+ if( !line.endsWith( m_separator ) )
+ line.append( m_separator );
+
+ // we have to handle here the case,
+ // that the separator is included
+ // in a quoted field
+ len = line.length(); // cache for better speed
+ quote_empty = m_quote.isEmpty();
+ while( end < len )
+ {
+ if( !quote_empty && line.right( len - end ).startsWith( m_quote ) )
+ quoted = !quoted;
+ else if( !quoted && line.right( len - end ).startsWith( m_separator ) )
+ {
+ sections << removeQuote( line.mid( start, end-start ) );
+
+ start = end;
+ ++start;
+ }
+ else if( line[end] == '\n' )
+ break;
+
+ ++end;
+ }
+
+ return sections;
+}
+
+QStringList CSVFile::readFixedLine( const QString & line )
+{
+ QString data( line );
+ QStringList list;
+
+ for( unsigned int i=0;i<m_width.count();i++ )
+ {
+ list << data.left( m_width[i] );
+ data = data.right( data.length() - m_width[i] );
+ }
+
+ return list;
+}
+
+QString CSVFile::removeQuote( const QString & text )
+{
+ QString line = text.stripWhiteSpace();
+
+ if( m_quote.isEmpty() )
+ return text;
+
+ if( line.startsWith( m_quote ) )
+ line = line.right( line.length() - m_quote.length() );
+
+ if( line.endsWith( m_quote ) )
+ line = line.left( line.length() - m_quote.length() );
+
+ return line;
+}
+
+void CSVFile::setEncoding( const QString & enc )
+{
+ m_stream.setCodec( QTextCodec::codecForName( enc.latin1() ) );
+}
+
diff --git a/kbarcode/csvfile.h b/kbarcode/csvfile.h
new file mode 100644
index 0000000..8049d58
--- /dev/null
+++ b/kbarcode/csvfile.h
@@ -0,0 +1,151 @@
+/***************************************************************************
+ csvfile.h - description
+ -------------------
+ begin : Mon Mar 28 2005
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef CSVFILE_H
+#define CSVFILE_H
+
+#include <qfile.h>
+#include <qstringlist.h>
+#include <qtextstream.h>
+
+class QBuffer;
+
+/** This class makes it very easy to parse a comma separated value file
+ */
+class CSVFile {
+ public:
+ CSVFile( const QString & filename );
+ CSVFile( QBuffer & buf );
+ ~CSVFile();
+
+ /** reads the next line from the CSV file and returns
+ * the line split into sections. Comments are ignored by this
+ * line.
+ */
+ QStringList readNextLine();
+
+ /** returns true when the CSVFile object is valid.
+ * returns false incase of an error
+ */
+ inline bool isValid() const;
+
+ /** returns true when the end of file was reached
+ */
+ inline bool isEof() const;
+
+ /** set the encoding to use for the data
+ */
+ void setEncoding( const QString & enc );
+
+ /** set the separator to use for the data
+ */
+ inline void setSeparator( const QString & sep );
+
+ /** set the quoting character
+ */
+ inline void setQuote( const QString & quote );
+
+ /** set the comment character
+ */
+ inline void setComment( const QString & comment );
+
+ /** set the field widths for fixed field width files
+ */
+ inline void setFieldWidth( const QValueList<int> & width );
+
+ /** sets wether this is a CSV file or
+ * a file with fixed field width.
+ * \param b if true this is a CSV file (default)
+ */
+ inline void setCSVFile( bool b );
+
+ /**
+ * \returns true if this is a CSV file
+ */
+ inline bool isCSVFile() const;
+
+ private:
+ /** removes quoting characters as defined in lpdata from the
+ * string @p text
+ */
+ QString removeQuote( const QString & text );
+
+ QStringList readCsvLine( const QString & line );
+
+ QStringList readFixedLine( const QString & line );
+
+ private:
+ /** the filehandle which is used to access the file
+ */
+ QFile m_file;
+ QTextStream m_stream;
+
+ QString m_quote;
+ QString m_separator;
+ QString m_comment;
+
+ QValueList<int> m_width;
+
+ bool m_csv;
+ bool m_eof;
+};
+
+bool CSVFile::isValid() const
+{
+ if( !m_stream.device() )
+ return false;
+
+ return m_stream.device()->isOpen();
+}
+
+bool CSVFile::isEof() const
+{
+ return m_eof;
+}
+
+void CSVFile::setCSVFile( bool b )
+{
+ m_csv = b;
+}
+
+bool CSVFile::isCSVFile() const
+{
+ return m_csv;
+}
+
+void CSVFile::setSeparator( const QString & sep )
+{
+ m_separator = sep;
+}
+
+void CSVFile::setQuote( const QString & quote )
+{
+ m_quote = quote;
+}
+
+void CSVFile::setComment( const QString & comment )
+{
+ m_comment = comment;
+}
+
+void CSVFile::setFieldWidth( const QValueList<int> & width )
+{
+ m_width = width;
+}
+
+
+#endif // CSVFILE_H
diff --git a/kbarcode/csvimportdlg.cpp b/kbarcode/csvimportdlg.cpp
new file mode 100644
index 0000000..3da1899
--- /dev/null
+++ b/kbarcode/csvimportdlg.cpp
@@ -0,0 +1,430 @@
+/***************************************************************************
+ csvimportdlg.cpp - description
+ -------------------
+ begin : Don Aug 21 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "csvimportdlg.h"
+#include "printersettings.h"
+#include "sqltables.h"
+#include "encodingcombo.h"
+
+// Qt includes
+#include <qcheckbox.h>
+#include <qcursor.h>
+#include <qfile.h>
+#include <qframe.h>
+#include <qgroupbox.h>
+#include <qhbuttongroup.h>
+#include <qheader.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlistbox.h>
+#include <qprogressdialog.h>
+#include <qsqlquery.h>
+#include <qtable.h>
+#include <qradiobutton.h>
+#include <qtextstream.h>
+#include <qvbox.h>
+
+// KDE includes
+#include <kapplication.h>
+#include <kcombobox.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <knuminput.h>
+#include <kpushbutton.h>
+#include <kurlrequester.h>
+#include "csvfile.h"
+
+// import from labelprinter.cpp
+extern QString removeQuote( QString text, QString quote );
+
+const char* NOFIELD = "<NONE>";
+
+CSVImportDlg::CSVImportDlg(QWidget *parent, const char *name )
+ : KDialogBase( KDialogBase::Tabbed, i18n("Import"),
+ KDialogBase::Ok | KDialogBase::Close, KDialogBase::Ok, parent,name,false,true)
+{
+ setButtonOKText( i18n("&Import"), i18n("Import the selected file into your tables.") );
+
+ createPage1();
+ createPage2();
+
+ connect( requester, SIGNAL( textChanged( const QString & ) ), this, SLOT( settingsChanged() ) );
+ connect( buttonSet, SIGNAL( clicked() ), this, SLOT( setCol() ) );
+ connect( comboSQL, SIGNAL( activated( int ) ), this, SLOT( updateFields() ) );
+ connect( databaseName, SIGNAL( textChanged( const QString & ) ), this, SLOT( updateFields() ) );
+ connect( comboEncoding, SIGNAL( activated( int ) ), this, SLOT( settingsChanged() ) );
+ connect( table->horizontalHeader(), SIGNAL( clicked( int ) ), this, SLOT( updateCol( int ) ) );
+ connect( radioCSVFile, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( radioFixedFile, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+ connect( buttonAdd, SIGNAL( clicked() ), this, SLOT( addWidth() ) );
+ connect( buttonRemove,SIGNAL( clicked() ), this, SLOT( removeWidth() ) );
+ connect( comment, SIGNAL( textChanged( const QString & ) ), this, SLOT( settingsChanged() ) );
+ connect( quote, SIGNAL( textChanged( const QString & ) ), this, SLOT( settingsChanged() ) );
+ connect( separator, SIGNAL( textChanged( const QString & ) ), this, SLOT( settingsChanged() ) );
+ connect( checkLoadAll, SIGNAL( clicked() ), this, SLOT( enableControls() ) );
+
+ updateFields();
+ enableControls();
+
+ show();
+}
+
+CSVImportDlg::~CSVImportDlg()
+{
+}
+
+void CSVImportDlg::createPage1()
+{
+ QFrame* box = addPage( i18n("&Import Data") );
+ QVBoxLayout* layout = new QVBoxLayout( box, 6, 6 );
+ QGridLayout* grid = new QGridLayout( 2 );
+
+ requester = new KURLRequester( box );
+ comboEncoding = new EncodingCombo( box );
+ comboSQL = new KComboBox( false, box );
+ comboSQL->insertItem( TABLE_BASIC );
+ comboSQL->insertItem( TABLE_CUSTOMER );
+ comboSQL->insertItem( TABLE_CUSTOMER_TEXT );
+ comboSQL->insertItem( TABLE_LABEL_DEF );
+ comboSQL->insertItem( i18n("Other table...") );
+
+ databaseName = new KLineEdit( box );
+ checkLoadAll = new QCheckBox( i18n("&Load complete file into preview"), box );
+ spinLoadOnly = new KIntNumInput( box );
+ spinLoadOnly->setLabel( i18n("Load only a number of datasets:"), AlignLeft | AlignVCenter );
+ spinLoadOnly->setRange( 0, 10000, 1, false );
+ checkLoadAll->setChecked( true );
+
+ table = new QTable( box );
+ table->setReadOnly( true );
+
+ frame = new QFrame( box );
+ QHBoxLayout* layout2 = new QHBoxLayout( frame, 6, 6 );
+
+ spinCol = new KIntNumInput( frame );
+ spinCol->setLabel( i18n("Column:"), AlignLeft | AlignVCenter );
+ spinCol->setRange( 0, 0, 0, false );
+
+ comboField = new KComboBox( false, frame );
+ buttonSet = new KPushButton( i18n("Set"), frame );
+
+ layout2->addWidget( spinCol );
+ layout2->addWidget( new QLabel( i18n("Database field to use for this column:"), frame ) );
+ layout2->addWidget( comboField );
+ layout2->addWidget( buttonSet );
+
+ grid->addWidget( new QLabel( i18n("File to import:"), box ), 0, 0 );
+ grid->addWidget( requester, 0, 1 );
+ grid->addWidget( new QLabel( i18n("Encoding:"), box ), 1, 0 );
+ grid->addWidget( comboEncoding, 1, 1 );
+ grid->addWidget( new QLabel( i18n("Import into table:"), box ), 2, 0 );
+ grid->addWidget( comboSQL, 2, 1 );
+ grid->addWidget( new QLabel( i18n("Table Name:"), box ), 3, 0 );
+ grid->addWidget( databaseName, 3, 1 );
+ grid->addWidget( checkLoadAll, 4, 0 );
+ grid->addWidget( spinLoadOnly, 4, 1 );
+
+ layout->addLayout( grid );
+ layout->addWidget( table );
+ layout->setStretchFactor( table, 2 );
+ layout->addWidget( frame );
+}
+
+void CSVImportDlg::createPage2()
+{
+ labelprinterdata* lb = PrinterSettings::getInstance()->getData();
+ QFrame* mainBox = addPage( i18n("&Import Settings") );
+ QVBoxLayout* layout = new QVBoxLayout( mainBox, 6, 6 );
+ QSpacerItem* spacer1 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ QSpacerItem* spacer2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
+
+ QHButtonGroup* buttonGroup = new QHButtonGroup( i18n("File Format:"), mainBox );
+ radioCSVFile = new QRadioButton( i18n("&CSV File"), buttonGroup );
+ radioFixedFile = new QRadioButton( i18n("File with &fixed field width"), buttonGroup );
+
+ QHBox* hboxFrame = new QHBox( mainBox );
+
+ groupCSV = new QGroupBox( i18n("CSV File"), hboxFrame );
+ groupFixed = new QGroupBox( i18n("Fixed Field Width File"), hboxFrame );
+
+ groupCSV->setColumnLayout(0, Qt::Vertical );
+ groupCSV->layout()->setSpacing( 6 );
+ groupCSV->layout()->setMargin( 11 );
+
+ QVBoxLayout* vbox = new QVBoxLayout( groupCSV->layout() );
+ QGridLayout* grid = new QGridLayout( 2, 2 );
+ grid->setSpacing( 6 );
+ grid->setMargin( 11 );
+
+ QLabel* label = new QLabel( groupCSV );
+ label->setText( i18n("Comment:") );
+ grid->addWidget( label, 0, 0 );
+
+ comment = new KLineEdit( lb->comment, groupCSV );
+ grid->addWidget( comment, 0, 1 );
+
+ label = new QLabel( groupCSV );
+ label->setText( i18n( "Separator:" ) );
+ grid->addWidget( label, 1, 0 );
+
+ separator = new KLineEdit( lb->separator, groupCSV );
+ grid->addWidget( separator, 1, 1 );
+
+ label = new QLabel( groupCSV );
+ label->setText( i18n("Quote Character:") );
+ grid->addWidget( label, 2, 0 );
+
+ quote = new KLineEdit( lb->quote, groupCSV );
+ grid->addWidget( quote, 2, 1 );
+
+ vbox->addLayout( grid );
+ vbox->addItem( spacer1 );
+
+ groupFixed->setColumnLayout(0, Qt::Horizontal );
+ groupFixed->layout()->setSpacing( 6 );
+ groupFixed->layout()->setMargin( 11 );
+ QHBoxLayout* groupFixedLayout = new QHBoxLayout( groupFixed->layout() );
+ groupFixedLayout->setAlignment( Qt::AlignTop );
+
+ listWidth = new KListBox( groupFixed );
+
+ buttonAdd = new KPushButton( groupFixed );
+ buttonAdd->setText( i18n( "&Add Field" ) );
+
+ buttonRemove = new KPushButton( groupFixed );
+ buttonRemove->setText( i18n( "&Remove Field" ) );
+
+ spinNumber = new KIntNumInput( groupFixed );
+ spinNumber->setMinValue( 0 );
+ spinNumber->setValue( 1 );
+ spinNumber->setFocus();
+
+ QVBoxLayout* layout2 = new QVBoxLayout( 0, 6, 6 );
+ layout2->addWidget( buttonAdd );
+ layout2->addWidget( buttonRemove );
+ layout2->addWidget( spinNumber );
+ layout2->addItem( spacer2 );
+
+ groupFixedLayout->addWidget( listWidth );
+ groupFixedLayout->addLayout( layout2 );
+
+ layout->addWidget( buttonGroup );
+ layout->addWidget( hboxFrame );
+
+ radioCSVFile->setChecked( true );
+}
+
+void CSVImportDlg::settingsChanged()
+{
+ CSVFile file( requester->url() );
+ QStringList list;
+
+ int i = 0;
+ unsigned int z;
+
+ initCsvFile( &file );
+
+ table->setNumCols( 0 );
+ table->setNumRows( 0 );
+
+ if( !file.isValid() )
+ return;
+
+ while( !file.isEof() )
+ {
+ list = file.readNextLine();
+
+ if( table->numCols() < (int)list.count() )
+ table->setNumCols( list.count() );
+
+ if( table->numRows() <= i )
+ // add 100 rows to get a reasonable speed
+ table->setNumRows( i + 100 );
+
+ for( z = 0; z < list.count(); z++ )
+ table->setText( i, z, list[z] );
+
+ if( !checkLoadAll->isChecked() && i > spinLoadOnly->value() )
+ break;
+
+ i++;
+ }
+
+ table->setNumRows( i );
+ spinCol->setRange( 1, table->numCols(), 1, false );
+
+ enableControls();
+}
+
+void CSVImportDlg::setCol()
+{
+ QString text = comboField->currentText();
+ int v = spinCol->value() - 1;
+ if( text == NOFIELD )
+ table->horizontalHeader()->setLabel( v, QString::number( v + 1 ) );
+ else {
+ for( int i = 0; i < table->horizontalHeader()->count(); i++ )
+ if( table->horizontalHeader()->label( i ) == text )
+ table->horizontalHeader()->setLabel( i, QString::number( i + 1 ) );
+
+ table->horizontalHeader()->setLabel( v, text );
+ }
+}
+
+QString CSVImportDlg::getDatabaseName()
+{
+ bool b = comboSQL->currentItem() == (comboSQL->count()-1);
+
+ databaseName->setEnabled( b );
+ return b ? databaseName->text() : comboSQL->currentText();
+}
+
+void CSVImportDlg::updateFields()
+{
+ // also enables databaseName if necessary
+ QString name = getDatabaseName();
+
+ comboField->clear();
+ comboField->insertItem( NOFIELD );
+ QSqlQuery query( SqlTables::getInstance()->driver()->showColumns( name ) );
+ while( query.next() )
+ comboField->insertItem( query.value( 0 ).toString() );
+
+ for( int i = 0; i < table->horizontalHeader()->count(); i++ )
+ table->horizontalHeader()->setLabel( i, QString::number( i + 1 ) );
+}
+
+void CSVImportDlg::enableControls()
+{
+ bool b = table->numRows() && table->numCols();
+
+ groupCSV->setEnabled( radioCSVFile->isChecked() );
+ groupFixed->setEnabled( radioFixedFile->isChecked() );
+
+ spinLoadOnly->setEnabled( !checkLoadAll->isChecked() );
+
+ enableButtonOK( b );
+ frame->setEnabled( b );
+}
+
+void CSVImportDlg::updateCol( int c )
+{
+ spinCol->setValue( ++c );
+}
+
+void CSVImportDlg::accept()
+{
+ CSVFile file( requester->url() );
+ QHeader* h = table->horizontalHeader();
+ QValueList<int> headers;
+ QStringList list;
+ QString name = getDatabaseName();
+ int i = 0;
+
+ QString q = "INSERT INTO " + name + " (";
+ for( int c = 0; c < table->horizontalHeader()->count(); c++ ) {
+ bool ok = true;
+ h->label( c ).toInt( &ok );
+ if( !ok ) {
+ q = q + table->horizontalHeader()->label( c ) + ",";
+ headers << c;
+ }
+ }
+
+ // remove last ","
+ if( q.right( 1 ) == "," )
+ q = q.left( q.length() - 1 );
+
+ q = q + ") VALUES (";
+
+ initCsvFile( &file );
+ if( !file.isValid() )
+ KMessageBox::error( this, i18n("Cannot load data from the file:") + requester->url() );
+
+
+
+ KApplication::setOverrideCursor( QCursor( Qt::WaitCursor) );
+ while( !file.isEof() )
+ {
+ list = file.readNextLine();
+
+ QString line = q;
+ for( unsigned int c = 0; c < headers.count(); c++ )
+ line.append( "'" + list[ headers[c] ] + "'" + "," );
+
+ // remove last ","
+ if( line.right( 1 ) == "," )
+ line = line.left( line.length() - 1 );
+
+ line = line + ");";
+
+ QSqlQuery query;
+ if( !query.exec( line ) )
+ qDebug( i18n("Could not import the following line:") + line );
+ //KMessageBox::error( this, i18n("Could not import the following line:") + line );
+ }
+
+ KApplication::restoreOverrideCursor();
+ KMessageBox::information( this, i18n("Data was imported successfully.") );
+ KDialogBase::accept();
+}
+
+void CSVImportDlg::addWidth()
+{
+ listWidth->insertItem( QString("%1").arg(spinNumber->value()), -1 );
+ settingsChanged();
+}
+
+void CSVImportDlg::removeWidth()
+{
+ unsigned int i = 0;
+ do {
+ if(listWidth->isSelected( i )) {
+ listWidth->removeItem( i );
+ listWidth->setSelected( i-1, true );
+ return;
+ } else
+ i++;
+ } while( i < listWidth->count() );
+ settingsChanged();
+}
+
+QValueList<int> CSVImportDlg::getFieldWidth()
+{
+ QValueList<int> list;
+
+ for( unsigned int i=0;i<listWidth->count();i++ )
+ list << listWidth->text( i ).toInt();
+
+ return list;
+}
+
+void CSVImportDlg::initCsvFile( CSVFile* file )
+{
+ QValueList<int> width = getFieldWidth();
+
+ file->setEncoding( comboEncoding->currentText() );
+ file->setCSVFile( radioCSVFile->isChecked() );
+ file->setComment( comment->text() );
+ file->setSeparator( separator->text() );
+ file->setQuote( quote->text() );
+ file->setFieldWidth( width );
+}
+
+
+#include "csvimportdlg.moc"
diff --git a/kbarcode/csvimportdlg.h b/kbarcode/csvimportdlg.h
new file mode 100644
index 0000000..b586880
--- /dev/null
+++ b/kbarcode/csvimportdlg.h
@@ -0,0 +1,127 @@
+/***************************************************************************
+ csvimportdlg.h - description
+ -------------------
+ begin : Don Aug 21 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef CSVIMPORTDLG_H
+#define CSVIMPORTDLG_H
+
+#include <qwidget.h>
+#include <kdialogbase.h>
+
+class CSVFile;
+class EncodingCombo;
+class KComboBox;
+class KIntNumInput;
+class KLineEdit;
+class KPushButton;
+class KURLRequester;
+class QCheckBox;
+class QFrame;
+class QGroupBox;
+class QTable;
+class QRadioButton;
+
+/** Import a CSV (comma separated value) file into
+ * a SQL table. CSV files can be generated by almost
+ * any spreadsheet application.
+ * This dialog is also available as a separate application
+ * KESI ( http://kesi.sf.net ).
+ * This class makes importing data in KBarcode very easy
+ * for the user.
+ *
+ * @author Dominik Seichter
+ */
+class CSVImportDlg : public KDialogBase {
+ Q_OBJECT
+ public:
+ CSVImportDlg(QWidget *parent=0, const char *name=0);
+ ~CSVImportDlg();
+
+ private slots:
+ void settingsChanged();
+ void setCol();
+ void updateFields();
+ void updateCol( int c );
+ void addWidth();
+ void removeWidth();
+
+ void enableControls();
+
+ private:
+ /**
+ * Returns the current database name which can be
+ * user specified or internal to KBarcode.
+ * It also enables the correct GUI items for
+ * a user specified or internal database.
+ *
+ * \returns the name of the current database table.
+ */
+ QString getDatabaseName();
+
+ /** Get the field with from listWidth
+ * as an integer list.
+ */
+ QValueList<int> getFieldWidth();
+
+ /** Create the first tab of the dialog
+ * to set the import data.
+ */
+ void createPage1();
+
+ /** Create the first tab of the dialog
+ * to set the import settings.
+ */
+ void createPage2();
+
+ /** Initialize a CSVFile with the settings
+ * from the GUI.
+ */
+ void initCsvFile( CSVFile* file );
+
+ private:
+ KComboBox* comboSQL;
+ KComboBox* comboField;
+ EncodingCombo* comboEncoding;
+ KIntNumInput* spinCol;
+ KPushButton* buttonSet;
+ KURLRequester* requester;
+ QFrame* frame;
+ QTable* table;
+ KLineEdit* databaseName;
+
+ QRadioButton* radioCSVFile;
+ QRadioButton* radioFixedFile;
+
+ KLineEdit* comment;
+ KLineEdit* quote;
+ KLineEdit* separator;
+
+ QGroupBox* groupCSV;
+ QGroupBox* groupFixed;
+
+ KListBox* listWidth;
+ KPushButton* buttonAdd;
+ KPushButton* buttonRemove;
+ KIntNumInput* spinNumber;
+
+ QCheckBox* checkLoadAll;
+ KIntNumInput* spinLoadOnly;
+
+ protected slots:
+ void accept();
+};
+
+#endif
diff --git a/kbarcode/databasebrowser.cpp b/kbarcode/databasebrowser.cpp
new file mode 100644
index 0000000..50af772
--- /dev/null
+++ b/kbarcode/databasebrowser.cpp
@@ -0,0 +1,204 @@
+/***************************************************************************
+ databasebrowser.cpp - description
+ -------------------
+ begin : Mit Mai 15 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "databasebrowser.h"
+#include "mydatatable.h"
+#include "definition.h"
+#include "sqltables.h"
+#include "csvimportdlg.h"
+
+// Qt includes
+#include <qclipboard.h>
+
+// KDE includes
+#include <kaction.h>
+#include <kapplication.h>
+#include <keditcl.h>
+#include <klocale.h>
+#include <kmenubar.h>
+#include <kpopupmenu.h>
+#include <kstatusbar.h>
+
+#define CUR_TABLE_ID 6666
+
+DatabaseBrowser::DatabaseBrowser( QString _database, QWidget *parent, const char *name )
+ : DSMainWindow(parent,name)
+{
+ m_direction = m_case = false;
+
+ table = new MyDataTable(this );
+ setCentralWidget( table );
+
+ statusBar()->insertItem( i18n("Current Table: <b>" ) + _database, CUR_TABLE_ID, 0, true );
+ statusBar()->setSizeGripEnabled( true );
+ statusBar()->show();
+
+ database = _database;
+
+ connect( table, SIGNAL( cursorChanged( QSql::Op ) ),
+ SqlTables::getInstance(), SIGNAL( tablesChanged() ) );
+
+ connect( this, SIGNAL( connectedSQL() ), this, SLOT( setupSql() ) );
+
+ findDlg = 0;
+
+ setupActions();
+ show();
+
+ setupSql();
+}
+
+DatabaseBrowser::~DatabaseBrowser()
+{
+ // update sql label definitions
+ // because they may have changed
+ // TODO:
+ // add selction here to only update
+ // if neccessary!
+ Definition::updateProducer();
+ DSMainWindow::saveConfig();
+
+ if( findDlg )
+ delete findDlg;
+}
+
+void DatabaseBrowser::setupActions()
+{
+ DSMainWindow::setupActions();
+ KPopupMenu* editMenu = new KPopupMenu( this );
+
+ KAction* acut = KStdAction::cut( this, SLOT( cut() ), actionCollection() );
+ KAction* acopy = KStdAction::copy( this, SLOT( copy() ), actionCollection() );
+ KAction* apaste = KStdAction::paste( this, SLOT( paste() ), actionCollection() );
+ KAction* afind = KStdAction::find( this, SLOT( find() ), actionCollection() );
+ menuBar()->insertItem( i18n("&Edit"), editMenu, -1, 1 );
+
+ acut->plug( editMenu );
+ acopy->plug( editMenu );
+ apaste->plug( editMenu );
+
+ editMenu->insertSeparator();
+ afind->plug( editMenu );
+ KStdAction::findNext( this, SLOT( findNext() ), actionCollection() )->plug( editMenu );
+ editMenu->insertSeparator();
+ KAction* aimport = new KAction( i18n("&Import CSV File..."), "",
+ 0, this, SLOT(import()), actionCollection(), "import" );
+ aimport->plug( editMenu );
+
+ acut->plug( toolBar() );
+ acopy->plug( toolBar() );
+ apaste->plug( toolBar() );
+
+ toolBar()->insertSeparator();
+ afind->plug( toolBar() );
+
+ DSMainWindow::loadConfig();
+}
+
+void DatabaseBrowser::setupSql()
+{
+ QSqlCursor* cur = new QSqlCursor( database, true );
+ cur->select();
+ unsigned int i = 0;
+ unsigned int c = 0;
+ while ( cur->next() ) {
+ for( c = 0; c < cur->count(); c++ ) {
+ table->setText( i, c, cur->value( c ).toString() );
+ table->horizontalHeader()->setLabel( c, cur->fieldName( c ) );
+ }
+ i++;
+ }
+
+ table->setNumCols( c );
+ table->setNumRows( i );
+
+ table->setSqlCursor( cur, true, true );
+ table->setSorting( true );
+ table->setConfirmDelete( true );
+ table->setAutoEdit( true );
+ table->refresh( QDataTable::RefreshAll );
+}
+
+void DatabaseBrowser::find()
+{
+ if( !findDlg )
+ findDlg = new KEdFind( this, "findDlg", false );
+
+ findDlg->setText( m_find );
+ findDlg->setDirection( m_direction );
+ findDlg->setCaseSensitive( m_case );
+ connect( findDlg, SIGNAL( search() ), this, SLOT( findNext() ) );
+
+ findDlg->exec();
+
+}
+
+void DatabaseBrowser::findNext()
+{
+ if( findDlg ) {
+ m_find = findDlg->getText();
+ m_direction = findDlg->get_direction();
+ m_case = findDlg->case_sensitive();
+ } else
+ find();
+
+ table->find( m_find, m_case, m_direction );
+}
+
+void DatabaseBrowser::cut()
+{
+ QString text = table->value( table->currentRow(), table->currentColumn() ).toString();
+ if( !text.isEmpty() ) {
+ kapp->clipboard()->setText( text );
+
+ QSqlRecord* buffer = table->sqlCursor()->primeUpdate();
+ if( buffer ) {
+ buffer->setValue( table->horizontalHeader()->label( table->currentColumn() ), "" );
+ table->sqlCursor()->update();
+ table->refresh();
+ }
+
+ }
+}
+
+void DatabaseBrowser::copy()
+{
+ QString text = table->value( table->currentRow(), table->currentColumn() ).toString();
+ if( !text.isEmpty() )
+ kapp->clipboard()->setText( text );
+}
+
+void DatabaseBrowser::paste()
+{
+ QString text = kapp->clipboard()->text();
+ if( !text.isEmpty() ) {
+ QSqlRecord* buffer = table->sqlCursor()->primeUpdate();
+ if( buffer ) {
+ buffer->setValue( table->horizontalHeader()->label( table->currentColumn() ), text );
+ table->sqlCursor()->update();
+ table->refresh();
+ }
+ }
+
+}
+
+void DatabaseBrowser::import()
+{
+ new CSVImportDlg( this );
+}
+
+#include "databasebrowser.moc"
diff --git a/kbarcode/databasebrowser.h b/kbarcode/databasebrowser.h
new file mode 100644
index 0000000..1968f88
--- /dev/null
+++ b/kbarcode/databasebrowser.h
@@ -0,0 +1,69 @@
+/***************************************************************************
+ databasebrowser.h - description
+ -------------------
+ begin : Mit Mai 15 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef DATABASEBROWSER_H
+#define DATABASEBROWSER_H
+
+#include "dsmainwindow.h"
+
+class KAction;
+class KEdFind;
+class KMenuBar;
+class KToolBar;
+class KPushButton;
+class KPopupMenu;
+class MyDataTable;
+/** A database browser widget. Allows small changes to SQL tables
+ * and is mostly used for having a quick look on the tables.
+ */
+class DatabaseBrowser : public DSMainWindow{
+ Q_OBJECT
+ public:
+ DatabaseBrowser( QString _database, QWidget *parent=0, const char *name=0);
+ ~DatabaseBrowser();
+
+ private:
+ void setupActions();
+
+ private slots:
+ void setupSql();
+
+ void cut();
+ void copy();
+ void paste();
+
+ void find();
+ void findNext();
+
+ void import();
+
+ protected:
+ QString database;
+ MyDataTable* table;
+
+ KAction* undoAct;
+ KAction* deleteAct;
+ KAction* newAct;
+
+ KEdFind* findDlg;
+
+ QString m_find;
+ bool m_direction;
+ bool m_case;
+};
+
+#endif
diff --git a/kbarcode/definition.cpp b/kbarcode/definition.cpp
new file mode 100644
index 0000000..675a36d
--- /dev/null
+++ b/kbarcode/definition.cpp
@@ -0,0 +1,579 @@
+/***************************************************************************
+ definition.cpp - description
+ -------------------
+ begin : Mit Nov 20 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "definition.h"
+#include "sqltables.h"
+
+// Qt includes
+#include <qtextstream.h>
+#include <qsqlquery.h>
+#include <qregexp.h>
+
+// KDE includes
+#include <kapplication.h>
+#include <kfiledialog.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kstandarddirs.h>
+#include <qprogressdialog.h>
+
+// a simple helper function
+// that copies a file
+bool filecopy( const char* src, const char* dest )
+{
+ FILE* s;
+ FILE* d;
+ int c;
+
+ d = fopen(dest, "w");
+ if( d == NULL )
+ return false;
+
+ s = fopen(src, "r");
+ if( s == NULL ) {
+ fclose( d );
+ remove( dest );
+ return false;
+ }
+
+ while(( c = getc( s )) != EOF )
+ putc( c, d );
+
+ fclose( s );
+ fclose( d );
+ return true;
+}
+
+class PrivateParser {
+ public:
+ PrivateParser( QString line, bool all = true );
+ ~PrivateParser();
+
+ const QString & getId() const { return m_label_def_id; }
+ const QString & getProducer() const { return m_producer; }
+ const QString & getType() const { return m_type; }
+ const Measurements & getMeasurements() const { return m_measure; };
+
+ private:
+ QString removeQuote( const QString & q );
+
+ QString m_label_def_id;
+ QString m_producer;
+ QString m_type;
+
+ Measurements m_measure;
+};
+
+PrivateParser::PrivateParser( QString line, bool all )
+{
+ line = line.stripWhiteSpace();
+ int pos = line.find("(");
+ line = line.mid( pos + 1, line.length() - pos - 1 );
+
+ m_label_def_id = line.section( ",", 0, 0 ).stripWhiteSpace();
+ m_producer = removeQuote( line.section( ",", 1, 1 ) );
+ m_type = removeQuote( line.section( ",", 2, 2 ) );
+
+ if( all ) {
+ m_measure.setGapTopMM( line.section( ",", 4, 4 ).toDouble() );
+ m_measure.setGapLeftMM( line.section( ",", 5, 5 ).toDouble() );
+ m_measure.setHeightMM( line.section( ",", 6, 6 ).toDouble() );
+ m_measure.setWidthMM( line.section( ",", 7, 7 ).toDouble() );
+ m_measure.setGapVMM( line.section( ",", 8, 8 ).toDouble() );
+ m_measure.setGapHMM( line.section( ",", 9, 9 ).toDouble() );
+ m_measure.setNumH( line.section( ",", 10, 10 ).toInt() );
+ m_measure.setNumV( line.section( ",", 11, 11 ).toInt() );
+
+ // fix broken label definitions
+ // with numh and numv = 0
+ if( !m_measure.numH() )
+ m_measure.setNumH( 1 );
+
+ if( !m_measure.numV() )
+ m_measure.setNumV( 1 );
+ }
+}
+
+PrivateParser::~PrivateParser()
+{ }
+
+QString PrivateParser::removeQuote( const QString & q )
+{
+ QString quote = q.stripWhiteSpace();
+
+ if( quote.startsWith("'") )
+ quote = quote.mid( 1, quote.length() - 1 );
+
+ if( quote.endsWith("'") )
+ quote = quote.left( quote.length() - 1 );
+
+ return quote;
+}
+
+
+/***************************************************************************/
+
+Definition::Definition( QWidget* parent )
+ : m_parent( parent )
+{
+ id = -1;
+}
+
+Definition::Definition( int label_def_id, QWidget* parent )
+ : m_parent( parent )
+{
+ init( QString("%1").arg( label_def_id ) );
+}
+
+Definition::Definition( const QString & label_def_id, QWidget* parent )
+ : m_parent( parent )
+{
+ init( label_def_id );
+}
+
+Definition::Definition( const QString & producer, const QString & type, QWidget* parent )
+ : m_parent( parent )
+{
+ if( SqlTables::isConnected() ) {
+ QSqlQuery query(
+ "select label_no from " TABLE_LABEL_DEF " WHERE manufacture='" + producer + "' AND type='" + type + "'");
+ while( query.next() )
+ init( query.value( 0 ).toString() );
+ } else {
+ if(!openFile())
+ return;
+
+ initProgress();
+
+ QString s;
+ while( file->readLine( s, 1000 ) != -1 ) {
+ if( s.isEmpty() || s.left( 1 ) == "#" )
+ continue;
+
+ increaseProgress();
+
+ PrivateParser p( s );
+ if( p.getProducer() ==producer && p.getType() == type ) {
+ init( p.getId() );
+ break;
+ }
+ }
+
+ destroyProgress();
+ }
+
+}
+
+Definition::~Definition()
+{
+}
+
+QFile* Definition::file = 0;
+QByteArray* Definition::array = 0;
+QStringList* Definition::listProducers = 0;
+QMap<QString,QStringList> Definition::mapTypes;
+QProgressDialog* Definition::m_progress = 0;
+
+void Definition::initProgress()
+{
+/*
+ if(!m_progress)
+ m_progress = new QProgressDialog( i18n("Loading Label Definitions..."), QString::null, 0, NULL, "m_progress", true );
+
+ m_progress->setTotalSteps( 1000 );
+ m_progress->show();
+*/
+// m_progress->reparent( m_parent, m_progress->pos(), true );
+}
+
+void Definition::increaseProgress()
+{
+/*
+ if( m_progress )
+ m_progress->setProgress( m_progress->progress() + 1 );
+*/
+}
+
+void Definition::destroyProgress()
+{
+/*
+ if( m_progress )
+ delete m_progress;
+ m_progress = NULL;
+*/
+}
+
+void Definition::setId( const QString & label_def_id )
+{
+ init( label_def_id );
+}
+
+void Definition::setId( int label_def_id )
+{
+ init( QString("%1").arg( label_def_id ) );
+}
+
+void Definition::init( const QString & label_def_id )
+{
+ if( SqlTables::isConnected() ) {
+ QSqlQuery* query = new QSqlQuery(
+ "select number_h, number_v, gap_left, gap_top, gap_v, gap_h, width, height, manufacture, type from " TABLE_LABEL_DEF
+ " WHERE label_no = " + label_def_id );
+
+ while( query->next() ) {
+ m_measure.setNumH( query->value( 0 ).toInt() );
+ m_measure.setNumV( query->value( 1 ).toInt() );
+ m_measure.setGapLeftMM( query->value( 2 ).toDouble() );
+ m_measure.setGapTopMM( query->value( 3 ).toDouble() );
+ m_measure.setGapVMM( query->value( 4 ).toDouble() );
+ m_measure.setGapHMM( query->value( 5 ).toDouble() );
+ m_measure.setWidthMM( query->value( 6 ).toDouble() );
+ m_measure.setHeightMM( query->value( 7 ).toDouble() );
+ producer = query->value( 8 ).toString();
+ type = query->value( 9 ).toString();
+ }
+ } else {
+ getFileMeasurements( label_def_id );
+ }
+
+ id = label_def_id.toInt();
+
+}
+
+const Measurements & Definition::getMeasurements() const
+{
+ return m_measure;
+}
+
+void Definition::getFileMeasurements( const QString & label_def_id )
+{
+ if(!openFile()) {
+ m_measure = Measurements();
+ return;
+ }
+
+ initProgress();
+
+ QTextStream stream(*array, IO_ReadOnly );
+ while( !stream.atEnd() ) {
+ QString s = stream.readLine();
+ if( s.isEmpty() || s.startsWith( "#" ) )
+ continue;
+
+ increaseProgress();
+
+ PrivateParser p( s );
+ if( p.getId() != label_def_id )
+ continue;
+
+ producer = p.getProducer();
+ type = p.getType();
+ m_measure = p.getMeasurements();
+ break;
+ }
+
+ destroyProgress();
+}
+
+bool Definition::openFile()
+{
+ if( file ) {
+ file->at( 0 );
+ return true;
+ }
+
+ QString f = locateLocal( "data", "kbarcode/labeldefinitions.sql" );
+ if( !QFile::exists( f ) ) {
+ KConfig* config = kapp->config();
+ config->setGroup( "Definitions" );
+
+ // copy file to new location
+ QString fname = config->readEntry( "defpath", locate( "data", "kbarcode/labeldefinitions.sql" ) );
+ if( !QFile::exists( fname ) || fname.isEmpty() )
+ return ( showFileError() ? openFile() : false );
+
+ if(!filecopy( (const char*)fname, (const char*)f ))
+ return ( showFileError() ? openFile() : false );
+ }
+
+ file = new QFile( f );
+ if( !file->open( IO_ReadOnly ) ) {
+ delete file;
+ file = 0;
+ return ( showFileError() ? openFile() : false );
+ }
+
+ // keeping this array around
+ // increases speed quite a lot
+ // but does also cost lot's of memory
+ array = new QByteArray();
+ *array = file->readAll();
+ file->at( 0 );
+
+ return true;
+}
+
+const QStringList Definition::getProducers()
+{
+ if( listProducers )
+ return *listProducers;
+
+ listProducers = new QStringList();
+
+ if( SqlTables::isConnected() ) {
+ QSqlQuery query("SELECT manufacture FROM " TABLE_LABEL_DEF " GROUP by manufacture;");
+ while( query.next() )
+ listProducers->append( query.value( 0 ).toString() );
+ } else {
+ if(!openFile() )
+ return *listProducers;
+
+ initProgress();
+
+ QTextStream stream(*array, IO_ReadOnly );
+ while( !stream.atEnd() ) {
+ QString s = stream.readLine();
+ if( s.isEmpty() || s.startsWith( "#" ) )
+ continue;
+
+ increaseProgress();
+
+ PrivateParser p( s, false );
+ if( !listProducers->contains( p.getProducer() ) )
+ listProducers->append( p.getProducer() );
+ }
+
+ destroyProgress();
+ }
+
+ return *listProducers;
+}
+
+const QStringList Definition::getTypes( QString producer )
+{
+ if( mapTypes.contains( producer ) ) {
+ return mapTypes[producer];
+ }
+
+ QStringList list;
+
+ if( SqlTables::isConnected() ) {
+ QSqlQuery query("SELECT type FROM " TABLE_LABEL_DEF " WHERE manufacture='" + producer + "'" );
+ while( query.next() )
+ if( !list.contains( query.value( 0 ).toString() ) )
+ list.append( query.value( 0 ).toString() );
+ } else {
+ if(!openFile())
+ return list;
+
+ initProgress();
+
+ QTextStream stream(*array, IO_ReadOnly );
+ while( !stream.atEnd() ) {
+ QString s = stream.readLine();
+ if( s.isEmpty() || s.startsWith( "#" ) )
+ continue;
+
+ increaseProgress();
+
+ PrivateParser p( s, false );
+ if( p.getProducer() == producer )
+ if( !list.contains( p.getType() ) )
+ list.append( p.getType() );
+ }
+
+ destroyProgress();
+ }
+
+ mapTypes.insert( producer, list );
+
+ return list;
+}
+
+void Definition::updateProducer()
+{
+ // TODO: check wether this function is
+ // correct! w/ SQL and without
+ if( listProducers ) {
+ delete listProducers;
+ listProducers = 0;
+
+ if( array ) {
+ delete array;
+ array = 0;
+ }
+
+ if( file ) {
+ file->close();
+ delete file;
+ file = 0;
+ }
+ mapTypes.clear();
+ }
+}
+
+int Definition::write( const Measurements & c, QString type, QString producer )
+{
+ int r = -1;
+ if( SqlTables::isConnected() )
+ r = Definition::writeSQL( c, type, producer );
+ else
+ r = Definition::writeFile( c, type, producer );
+
+ Definition::updateProducer();
+ return r;
+}
+
+int Definition::writeFile( const Measurements & c, QString type, QString producer )
+{
+ if( !openFile() )
+ return -1;
+
+ QStringList data;
+ bool datawritten = false;
+ int index = 0;
+ QString entry = ", '" +
+ producer + "', '" + type + "', 'C',"+ I2S(c.gapTopMM()) +
+ ", " + I2S(c.gapLeftMM()) + ", " +
+ I2S(c.heightMM()) + ", " + I2S(c.widthMM()) + ", " +
+ I2S(c.gapVMM()) + ", " + I2S(c.gapHMM()) + ", " +
+ I2S(c.numH()) + ", " + I2S(c.numV()) + ", NULL, NULL )";
+
+ QString s;
+ while( file->readLine( s, 1000 ) != -1 ) {
+ if( s.isEmpty() || s.left( 1 ) == "#" ) {
+ data.append( s );
+ continue;
+ }
+
+ PrivateParser p( s );
+ if( p.getId().toInt() > index )
+ index = p.getId().toInt();
+
+ if( p.getType() == type && p.getProducer() == producer ) {
+ // update an item already present in the list
+ entry = entry.prepend( "INSERT INTO " TABLE_LABEL_DEF " VALUES (" + I2S(p.getId().toInt()) );
+ data.append( entry );
+ datawritten = true;
+ } else
+ data.append( s );
+ }
+
+ if( !datawritten ) {
+ entry = entry.prepend( "INSERT INTO " TABLE_LABEL_DEF " VALUES (" + I2S(index+1) );
+ data.append( entry );
+ }
+
+ file->close();
+ if( !file->open( IO_WriteOnly ) ) {
+ file->open( IO_ReadOnly );
+ return -1;
+ }
+
+ QTextStream t( file );
+ for( unsigned int i = 0; i < data.count(); i++ )
+ t << data[i].replace( QRegExp("\\n"), "" ) << "\n";
+
+ // get the file back to the normal stage
+ file->close();
+ file->open( IO_ReadOnly );
+
+ return index + 1;
+}
+
+int Definition::writeSQL( const Measurements & c, QString type, QString producer )
+{
+ bool newitem = true;
+ QSqlQuery q( "SELECT manufacture, type FROM " TABLE_LABEL_DEF );
+ // TODO: use a more inteligent query using where=
+ while( q.next() )
+ if( q.value( 0 ) == producer &&
+ q.value( 1 ) == type )
+ newitem = false;
+
+ if( newitem ) {
+ QSqlQuery query(
+ "INSERT INTO " TABLE_LABEL_DEF " (manufacture, type, gap_top, gap_left, "
+ "width, height, gap_v, gap_h, number_h, number_v) VALUES ('" +
+ producer + "', '" + type + "', '"+ I2S( c.gapTopMM() ) +
+ "', '" + I2S( c.gapLeftMM() ) + "', '" +
+ I2S( c.widthMM() ) + "', '" + I2S( c.heightMM() ) + "', '" +
+ I2S( c.gapVMM() ) + "', '" + I2S( c.gapHMM() ) + "', '" +
+ I2S( c.numH() ) + "', '" + I2S( c.numV() ) + "')"
+ );
+
+ if(!query.isValid())
+ qDebug("Query to insert values not valid!");
+ } else {
+ QSqlQuery query( "UPDATE " TABLE_LABEL_DEF " SET "
+ "gap_top = " + I2S( c.gapTopMM() ) + " ,gap_left = " + I2S( c.gapLeftMM() ) +
+ " ,width = " + I2S( c.widthMM() ) + " ,height = " + I2S( c.heightMM() ) +
+ " ,gap_v = " + I2S( c.gapVMM() ) + " ,gap_h = " + I2S( c.gapHMM() ) +
+ " ,number_h = " + I2S( c.numH() ) + " ,number_v = " + I2S( c.numV() ) +
+ " WHERE manufacture = '" + producer + "' AND"
+ " type = '" + type + "'" );
+
+ if(!query.isValid())
+ qDebug("Query to update values not valid!\n%s\n", query.lastQuery().latin1() );
+ }
+
+ QSqlQuery qi("SELECT label_no FROM " TABLE_LABEL_DEF " WHERE manufacture='" + producer + "' AND type='" + type + "'" );
+ while( qi.next() )
+ return qi.value( 0 ).toInt();
+
+ return -1;
+}
+
+
+bool Definition::nodefmsg = true;
+bool Definition::showFileError()
+{
+ if( nodefmsg ) {
+ KMessageBox::information( 0,
+ i18n("KBarcode is unable to find its label definitions."
+ "Please make sure that the file $KDEDIR/share/apps/kbarcode/labeldefinitions.sql "
+ "does exist. This file is part of the KBarcode distribution. "
+ "You will be prompted now to select the file containing the labeldefinitions."),
+ "", "NoDefinitionsFound" );
+
+ QString f = KFileDialog::getOpenFileName( QString::null, QString::null, 0 );
+ if( !f.isEmpty() && QFile::exists( f ) ) {
+ KConfig* config = kapp->config();
+ config->setGroup( "Definitions" );
+ config->writeEntry( "defpath", f );
+ config->sync();
+ }
+ nodefmsg = false;
+ return openFile();
+ } else
+ qDebug("No label definitions found. Please install them.");
+
+ return false;
+}
+
+int Definition::getClosest( const QString & producer, const QString & type )
+{
+ QStringList t = Definition::getTypes(producer);
+ for( unsigned int z = 0; z < t.count(); z++ ) {
+ if( t[z] == type ) {
+ Definition d( producer, type );
+ return d.getId();
+ }
+ }
+
+ return -1;
+}
diff --git a/kbarcode/definition.h b/kbarcode/definition.h
new file mode 100644
index 0000000..a853a67
--- /dev/null
+++ b/kbarcode/definition.h
@@ -0,0 +1,101 @@
+/***************************************************************************
+ definition.h - description
+ -------------------
+ begin : Mit Nov 20 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+
+#ifndef DEFINITION_H
+#define DEFINITION_H
+
+#include "measurements.h"
+#include "labelutils.h"
+#include <qmap.h>
+#include <qstring.h>
+
+#ifndef I2S
+ #define I2S(x) QString::number(x)
+#endif // I2S
+
+class QWidget;
+class QFile;
+class QPaintDevice;
+class QString;
+class QStringList;
+class QSqlQuery;
+class Measurements;
+class QProgressDialog;
+/** @short A label definition;
+ *
+ * Represents a label definition. The definition is either read from
+ * a SQL database or from a text file on the harddisk.
+ * This class supports also writing new label definitions.
+ * After you selected a definition, you can retrieve its measurements.
+ *
+ * @author Dominik Seichter
+ */
+class Definition : private LabelUtils {
+ public:
+ Definition( QWidget* parent = 0 );
+ Definition( int label_def_id, QWidget* parent = 0 );
+ Definition( const QString & label_def_id, QWidget* parent = 0 );
+ Definition( const QString & producer, const QString & type, QWidget* parent = 0 );
+ ~Definition();
+
+ void setId( const QString & label_def_id );
+ void setId( int label_def_id );
+
+ const Measurements & getMeasurements() const;
+
+ static int write( const Measurements & c, QString type, QString producer );
+ static int getClosest( const QString & producer, const QString & type );
+
+ static const QStringList getProducers();
+ static const QStringList getTypes( QString producer );
+ /** reread the list of producers, because it has changed
+ * mapType is also cleared and reread when necessary.
+ */
+ static void updateProducer();
+
+ int getId() const { return id; }
+ const QString getProducer() const { return producer; }
+ const QString getType() const { return type; }
+
+ private:
+ void init( const QString & label_def_id );
+ void getFileMeasurements( const QString & label_def_id );
+ static void initProgress();
+ static void increaseProgress();
+ static void destroyProgress();
+
+ static int writeSQL( const Measurements & c, QString type, QString producer );
+ static int writeFile( const Measurements & c, QString type, QString producer );
+
+ static bool showFileError();
+ static bool openFile();
+ static QStringList* listProducers;
+ static QMap<QString,QStringList> mapTypes;
+ static QFile* file;
+ static QByteArray* array;
+ static QProgressDialog* m_progress;
+
+ QWidget* m_parent;
+ int id;
+ QString producer;
+ QString type;
+ Measurements m_measure;
+ bool locked;
+ static bool nodefmsg;
+};
+
+#endif
diff --git a/kbarcode/definitiondialog.cpp b/kbarcode/definitiondialog.cpp
new file mode 100644
index 0000000..d8f9484
--- /dev/null
+++ b/kbarcode/definitiondialog.cpp
@@ -0,0 +1,428 @@
+/***************************************************************************
+ definitiondialog.cpp - description
+ -------------------
+ begin : Don Apr 18 12:34:56 CEST 2002
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "definitiondialog.h"
+#include "printersettings.h"
+#include "labelutils.h"
+#include "definition.h"
+
+#include <kcombobox.h>
+#include <kpushbutton.h>
+#include <krestrictedline.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpainter.h>
+
+// KDE includes
+#include <klocale.h>
+
+LabelPreview::LabelPreview( QWidget* parent, const char* name )
+ : QWidget( parent, name)
+{
+ // For old DIN A4 preview
+ PrinterSettings* ps = PrinterSettings::getInstance();
+ setFixedSize( QSize( ((int)ps->pageWidth() + 20)/2, ((int)ps->pageHeight() + 20)/2 ) );
+ m_prv_enabled = true;
+}
+
+LabelPreview::~LabelPreview()
+{ }
+
+void LabelPreview::paintEvent( QPaintEvent* )
+{
+ QPainter p( this );
+ p.fillRect( 0, 0, width(), height(), QBrush( Qt::white ) );
+ p.setPen( QPen( Qt::black ) );
+ p.translate( 10, 10 );
+
+ p.fillRect( 0, 0, 210/2, 297/2, QBrush( Qt::gray ) );
+ p.drawRect( 0, 0, 210/2, 297/2 );
+
+ if(!m_prv_enabled)
+ return;
+
+// int numv = measure.num_v > 0 ? measure.num_v : 1;
+ for( int v = 0; v < measure.numV(); v++ ) {
+ for( int h = 0; h < measure.numH(); h++ ) {
+ if( !v && !h )
+ p.setPen( QPen( Qt::red ) );
+ else
+ p.setPen( QPen( Qt::black ) );
+
+ p.fillRect( int(measure.gapLeftMM() + (measure.gapHMM() * h)) / 2,
+ int(measure.gapTopMM() + (measure.gapVMM() * v)) / 2 ,
+ (int)measure.widthMM() / 2 , (int)measure.heightMM() / 2, QBrush( Qt::white ) );
+
+ p.drawRect( int(measure.gapLeftMM() + (measure.gapHMM() * h)) / 2,
+ int(measure.gapTopMM() + (measure.gapVMM() * v)) / 2,
+ (int)measure.widthMM() / 2, (int)measure.heightMM() / 2 );
+ }
+ }
+}
+
+/*****************************************/
+DefinitionDialog::DefinitionDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
+ : QDialog( parent, name, modal, fl )
+{
+ resize( 465, 345 );
+ setCaption( i18n( "Add Label Definition" ) );
+ QHBoxLayout* layout = new QHBoxLayout( this, 6, 6 );
+ DefinitionDialogLayout = new QVBoxLayout( 0, 11, 6, "DefinitionDialogLayout");
+
+ Layout17 = new QHBoxLayout( 0, 0, 6, "Layout17");
+
+ Layout13 = new QVBoxLayout( 0, 0, 6, "Layout13");
+
+ TextLabel1 = new QLabel( this, "TextLabel1" );
+ TextLabel1->setText( i18n( "Producer:" ) );
+ Layout13->addWidget( TextLabel1 );
+
+ TextLabel2 = new QLabel( this, "TextLabel2" );
+ TextLabel2->setText( i18n( "Type:" ) );
+ Layout13->addWidget( TextLabel2 );
+
+ TextLabel3 = new QLabel( this, "TextLabel3" );
+ TextLabel3->setText( QString( i18n( "Width (in %1):" ) ).arg( Measurements::system() ) );
+ Layout13->addWidget( TextLabel3 );
+
+ TextLabel4 = new QLabel( this, "TextLabel4" );
+ TextLabel4->setText( QString( i18n( "Height (in %1):" ) ).arg( Measurements::system() ) );
+ Layout13->addWidget( TextLabel4 );
+
+ TextLabel5 = new QLabel( this, "TextLabel5" );
+ TextLabel5->setText( i18n( "Horizontal Gap:" ) );
+ Layout13->addWidget( TextLabel5 );
+
+ TextLabel6 = new QLabel( this, "TextLabel6" );
+ TextLabel6->setText( i18n( "Vertical Gap:" ) );
+ Layout13->addWidget( TextLabel6 );
+
+ TextLabel7 = new QLabel( this, "TextLabel7" );
+ TextLabel7->setText( i18n( "Top Gap:" ) );
+ Layout13->addWidget( TextLabel7 );
+
+ TextLabel8 = new QLabel( this, "TextLabel8" );
+ TextLabel8->setText( i18n( "Left Gap:" ) );
+ Layout13->addWidget( TextLabel8 );
+
+ TextLabel9 = new QLabel( this, "TextLabel9" );
+ TextLabel9->setText( i18n("Number Horizontal:") );
+ Layout13->addWidget( TextLabel9 );
+
+ TextLabel10 = new QLabel( this, "TextLabel10" );
+ TextLabel10->setText( i18n("Number Vertical:") );
+ Layout13->addWidget( TextLabel10 );
+
+ Layout17->addLayout( Layout13 );
+ Layout14 = new QVBoxLayout( 0, 0, 6, "Layout14");
+
+ comboProducer = new KComboBox( FALSE, this, "comboProducer" );
+ comboProducer->setEditable( TRUE );
+ Layout14->addWidget( comboProducer );
+
+ comboType = new KComboBox( FALSE, this, "type" );
+ comboType->setEditable( TRUE );
+ Layout14->addWidget( comboType );
+
+ editWidth = new KRestrictedLine( this, "editWidth" );
+ editWidth->setText( i18n( "0" ) );
+ editWidth->setValidChars( i18n( "0123456789." ) );
+ Layout14->addWidget( editWidth );
+
+ editHeight = new KRestrictedLine( this, "editHeight" );
+ editHeight->setText( i18n( "0" ) );
+ editHeight->setValidChars( i18n( "0123456789." ) );
+ Layout14->addWidget( editHeight );
+
+ editHGap = new KRestrictedLine( this, "editHGap" );
+ editHGap->setText( i18n( "0" ) );
+ editHGap->setValidChars( i18n( "0123456789." ) );
+ Layout14->addWidget( editHGap );
+
+ editVGap = new KRestrictedLine( this, "editVGap" );
+ editVGap->setText( i18n( "0" ) );
+ editVGap->setValidChars( i18n( "0123456789." ) );
+ Layout14->addWidget( editVGap );
+
+ editTGap = new KRestrictedLine( this, "editTGap" );
+ editTGap->setText( i18n( "0" ) );
+ editTGap->setValidChars( i18n( "0123456789." ) );
+ Layout14->addWidget( editTGap );
+
+ editLGap = new KRestrictedLine( this, "editLGap" );
+ editLGap->setText( i18n( "0" ) );
+ editLGap->setValidChars( i18n( "0123456789." ) );
+ Layout14->addWidget( editLGap );
+
+ editNumH = new KRestrictedLine( this, "editNumH" );
+ editNumH->setText( i18n( "0" ) );
+ editNumH->setValidChars( "0123456789" );
+ Layout14->addWidget( editNumH );
+
+ editNumV = new KRestrictedLine( this, "editNumV" );
+ editNumV->setText( i18n( "0" ) );
+ editNumV->setValidChars( "0123456789" );
+ Layout14->addWidget( editNumV );
+
+ Layout17->addLayout( Layout14 );
+ QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ Layout17->addItem( spacer );
+ DefinitionDialogLayout->addLayout( Layout17 );
+ QSpacerItem* spacer_2 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ DefinitionDialogLayout->addItem( spacer_2 );
+
+ Layout16 = new QHBoxLayout( 0, 0, 6, "Layout16");
+ buttonInfo = new KPushButton( i18n("More &Information"), this );
+ Layout16->addWidget( buttonInfo );
+
+ QSpacerItem* spacer_3 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ Layout16->addItem( spacer_3 );
+
+ buttonAdd = new KPushButton( this, "buttonAdd" );
+ buttonAdd->setText( i18n( "&Add" ) );
+ Layout16->addWidget( buttonAdd );
+
+ buttonCancel = new KPushButton( this, "buttonCancel" );
+ buttonCancel->setText( i18n( "&Cancel" ) );
+ Layout16->addWidget( buttonCancel );
+ DefinitionDialogLayout->addLayout( Layout16 );
+
+ preview = new LabelPreview( this );
+ layout->addLayout( DefinitionDialogLayout );
+ layout->addWidget( preview );
+
+ l = new QLabel( this );
+ setExtension( l );
+ setOrientation( Vertical );
+
+ connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
+ connect( buttonAdd, SIGNAL( clicked() ), this, SLOT( add() ) );
+
+ connect( editWidth, SIGNAL( textChanged(const QString &) ), this, SLOT( updatePreview() ) );
+ connect( editHeight, SIGNAL( textChanged(const QString &) ), this, SLOT( updatePreview() ) );
+ connect( editHGap, SIGNAL( textChanged(const QString &) ), this, SLOT( updatePreview() ) );
+ connect( editVGap, SIGNAL( textChanged(const QString &) ), this, SLOT( updatePreview() ) );
+ connect( editTGap, SIGNAL( textChanged(const QString &) ), this, SLOT( updatePreview() ) );
+ connect( editLGap, SIGNAL( textChanged(const QString &) ), this, SLOT( updatePreview() ) );
+ connect( editNumH, SIGNAL( textChanged(const QString &) ), this, SLOT( updatePreview() ) );
+ connect( editNumV, SIGNAL( textChanged(const QString &) ), this, SLOT( updatePreview() ) );
+
+ comboProducer->setInsertionPolicy( QComboBox::NoInsertion );
+ comboType->setInsertionPolicy( QComboBox::NoInsertion );
+
+ comboProducer->clear();
+ QStringList list = Definition::getProducers();
+ comboProducer->insertStringList( list );
+
+ types = new QStringList[list.count()];
+ for( unsigned int i = 0; i < list.count(); i++ )
+ types[i] = Definition::getTypes( list[i] );
+
+ connect( comboProducer, SIGNAL( textChanged(const QString &) ), this, SLOT( updateType() ) );
+ connect( comboType, SIGNAL( textChanged(const QString &) ), this, SLOT( updateText() ) );
+ connect( buttonInfo, SIGNAL( clicked() ), this, SLOT( toggleExtension() ) );
+
+ drawGraphic();
+ updateType();
+
+ showExtension( false );
+}
+
+DefinitionDialog::~DefinitionDialog()
+{
+ delete [] types;
+}
+
+void DefinitionDialog::add()
+{
+ Definition::write( getCurrentMeasure(), comboType->currentText(), comboProducer->currentText() );
+
+ accept();
+}
+
+void DefinitionDialog::updateType()
+{
+ comboType->clear();
+ if( comboProducer->currentText() == comboProducer->text( comboProducer->currentItem() ) )
+ if( comboProducer->currentItem() < comboProducer->count())
+ comboType->insertStringList( types[ comboProducer->currentItem() ] );
+ comboType->insertItem( i18n( "Custom" ), 0 );
+}
+
+const Measurements DefinitionDialog::getCurrentMeasure()
+{
+ Measurements m;
+ m.setGapLeft( editLGap->text().toDouble() );
+ m.setGapTop( editTGap->text().toDouble() );
+ m.setWidth( editWidth->text().toDouble() );
+ m.setHeight( editHeight->text().toDouble() );
+ m.setGapV( editVGap->text().toDouble() );
+ m.setGapH( editHGap->text().toDouble() );
+ m.setNumH( editNumH->text().toInt() );
+ m.setNumV( editNumV->text().toInt() );
+
+ return m;
+}
+
+void DefinitionDialog::updateText()
+{
+ Definition d( comboProducer->currentText(), comboType->currentText() );
+ Measurements m = d.getMeasurements();
+
+ editTGap->setText( I2S( m.gapTop() ) );
+ editLGap->setText( I2S( m.gapLeft() ) );
+ editWidth->setText( I2S( m.width() ) );
+ editHeight->setText( I2S( m.height() ) );
+ editVGap->setText( I2S( m.gapV() ) );
+ editHGap->setText( I2S( m.gapH() ) );
+ editNumH->setText( I2S( m.numH() ) );
+ editNumV->setText( I2S( m.numV() ) );
+
+ updatePreview();
+}
+
+void DefinitionDialog::updatePreview()
+{
+ Measurements m = getCurrentMeasure();
+
+ editHeight->setPaletteForegroundColor( Qt::black );
+ editWidth->setPaletteForegroundColor( Qt::black );
+ editVGap->setPaletteForegroundColor( Qt::black );
+ editHGap->setPaletteForegroundColor( Qt::black );
+ editTGap->setPaletteForegroundColor( Qt::black );
+ editLGap->setPaletteForegroundColor( Qt::black );
+ editNumH->setPaletteForegroundColor( Qt::black );
+ editNumV->setPaletteForegroundColor( Qt::black );
+
+ // Mark errors in Red
+ if( m.heightMM() > PrinterSettings::getInstance()->pageHeight() )
+ editHeight->setPaletteForegroundColor( Qt::red );
+
+ if( m.widthMM() > PrinterSettings::getInstance()->pageWidth() )
+ editWidth->setPaletteForegroundColor( Qt::red );
+
+ if( m.gapVMM() < m.heightMM() )
+ editVGap->setPaletteForegroundColor( Qt::red );
+
+ if( m.gapHMM() < m.widthMM() )
+ editHGap->setPaletteForegroundColor( Qt::red );
+
+ if( m.gapTopMM() > PrinterSettings::getInstance()->pageHeight() - m.heightMM() )
+ editTGap->setPaletteForegroundColor( Qt::red );
+
+ if( m.gapLeftMM() > PrinterSettings::getInstance()->pageWidth() - m.widthMM() )
+ editLGap->setPaletteForegroundColor( Qt::red );
+
+ if( m.gapLeftMM() + m.numH() * m.gapHMM() > PrinterSettings::getInstance()->pageWidth() )
+ editNumH->setPaletteForegroundColor( Qt::red );
+
+ if( m.gapTopMM() + m.numV() * m.gapVMM() > PrinterSettings::getInstance()->pageHeight() )
+ editNumV->setPaletteForegroundColor( Qt::red );
+
+ preview->setRect( QRect( (int)m.gapLeftMM(), (int)m.gapTopMM(), (int)m.widthMM(), (int)m.heightMM() ) );
+ preview->setMeasurements( m );
+ preview->repaint();
+}
+
+void DefinitionDialog::drawGraphic()
+{
+ QWMatrix wm;
+ wm.rotate( 90 );
+
+ QPixmap pic( 450, 330 );
+ pic.fill( Qt::gray );
+
+ QPainter p( &pic );
+ p.setPen( Qt::black );
+
+ p.fillRect( 60, 60, 450, 330, QColor( 255, 254, 217 ) );
+ p.drawRect( 60, 60, 450, 330 );
+ p.setBrush( Qt::white );
+
+ p.setPen( Qt::DotLine );
+ p.drawRoundRect( 90, 90, 150, 90 );
+ p.drawRoundRect( 270, 90, 150, 90 );
+
+ p.drawRoundRect( 90, 210, 150, 90 );
+ p.drawRoundRect( 270, 210, 150, 90 );
+
+ // Draw width
+ p.setPen( QPen( Qt::red, 2 ) );
+ p.drawLine( 90, 150, 240, 150 );
+
+ // Draw numh
+ p.drawLine( 90, 270, 450, 270 );
+
+ // Draw Gap Top
+ p.setPen( QPen( Qt::red, 2, Qt::DotLine ) );
+ p.drawLine( 0, 60, 90, 60 );
+ p.drawLine( 0, 90, 90, 90 );
+
+ // draw Gap V
+ p.drawLine( 0, 210, 90, 210 );
+
+ // Draw height
+ p.setPen( QPen( Qt::green, 2 ) );
+ p.drawLine( 150, 90, 150, 180 );
+
+
+ // Draw numv
+ p.drawLine( 330, 90, 330, 330 );
+
+ // Draw Gap Left
+ p.setPen( QPen( Qt::green, 2, Qt::DotLine ) );
+ p.drawLine( 60, 0, 60, 90 );
+ p.drawLine( 90, 0, 90, 90 );
+
+ // draw Gap H
+ p.drawLine( 270, 0, 270, 90 );
+
+ // draw Texts:
+ p.setPen( Qt::black );
+ p.drawText( 100, 140, i18n("Width") );
+ p.drawText( 160, 120, i18n("Height") );
+ p.drawText( 100, 260, i18n("Number of horizontal Labels") );
+
+ QPixmap* pix = LabelUtils::drawString( i18n("Number of vertical Labels") );
+ p.drawPixmap( 340, 110, pix->xForm( wm ) );
+ delete pix;
+
+ p.drawText( 5, 80, i18n("Gap Top") );
+
+ pix = LabelUtils::drawString( i18n("Gap Left") );
+
+ p.drawPixmap( 60, 5, pix->xForm( wm ) );
+ delete pix;
+
+ p.drawText( 5, 150, i18n("Vertical Gap") );
+ p.drawText( 150, 50, i18n("Horizontal Gap") );
+
+ p.end();
+
+ l->setPixmap( pic );
+}
+
+void DefinitionDialog::toggleExtension()
+{
+ if( l->isVisible() ) {
+ showExtension( false );
+ } else
+ showExtension( true );
+}
+
+
+#include "definitiondialog.moc"
diff --git a/kbarcode/definitiondialog.h b/kbarcode/definitiondialog.h
new file mode 100644
index 0000000..701ce6f
--- /dev/null
+++ b/kbarcode/definitiondialog.h
@@ -0,0 +1,99 @@
+#ifndef DEFINITIONDIALOG_H
+#define DEFINITIONDIALOG_H
+
+#include <qwidget.h>
+#include <qdialog.h>
+#include "measurements.h"
+
+class QVBoxLayout;
+class QHBoxLayout;
+class QGridLayout;
+class KComboBox;
+class KPushButton;
+class KRestrictedLine;
+class QLabel;
+class QStringList;
+class QRect;
+class QPaintEvent;
+/** Displays a preview of the given label measurements.
+ * The current page size setting of the user is used.
+ * The labels are drawn using QPainter. Only one page is previewed.
+ */
+class LabelPreview : public QWidget {
+ Q_OBJECT
+ public:
+ LabelPreview( QWidget* parent = 0, const char* name = 0 );
+ ~LabelPreview();
+
+ void setRect( QRect label ) { size = label; }
+ void setMeasurements( const Measurements & m ) { measure = m; }
+
+ void setPrvEnabled( bool b ) { m_prv_enabled = b; }
+
+ protected:
+ void paintEvent( QPaintEvent* );
+ QRect size;
+ Measurements measure;
+
+ bool m_prv_enabled;
+};
+
+/** A dialog which allows the user to create his/her own
+ * label definitions easily.
+ */
+class DefinitionDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ DefinitionDialog( QWidget* parent = 0, const char* name = 0, bool modal = true, WFlags fl = 0 );
+ ~DefinitionDialog();
+private:
+ const Measurements getCurrentMeasure();
+
+private slots:
+ void add();
+ void updateType();
+ void updateText();
+ void updatePreview();
+ void toggleExtension();
+ void drawGraphic();
+
+protected:
+ QLabel* l;
+ QLabel* TextLabel1;
+ QLabel* TextLabel2;
+ QLabel* TextLabel3;
+ QLabel* TextLabel4;
+ QLabel* TextLabel5;
+ QLabel* TextLabel6;
+ QLabel* TextLabel7;
+ QLabel* TextLabel8;
+ QLabel* TextLabel9;
+ QLabel* TextLabel10;
+ KComboBox* comboProducer;
+ KComboBox* comboType;
+ KRestrictedLine* editWidth;
+ KRestrictedLine* editHeight;
+ KRestrictedLine* editHGap;
+ KRestrictedLine* editVGap;
+ KRestrictedLine* editTGap;
+ KRestrictedLine* editLGap;
+ KRestrictedLine* editNumH;
+ KRestrictedLine* editNumV;
+ KPushButton* buttonAdd;
+ KPushButton* buttonCancel;
+ KPushButton* buttonInfo;
+
+ QStringList* types;
+ LabelPreview* preview;
+
+protected:
+ QVBoxLayout* DefinitionDialogLayout;
+ QHBoxLayout* Layout17;
+ QVBoxLayout* Layout13;
+ QVBoxLayout* Layout14;
+ QHBoxLayout* Layout16;
+};
+
+#endif // DEFINITIONDIALOG_H
diff --git a/kbarcode/documentitem.cpp b/kbarcode/documentitem.cpp
new file mode 100644
index 0000000..8d85eeb
--- /dev/null
+++ b/kbarcode/documentitem.cpp
@@ -0,0 +1,245 @@
+/***************************************************************************
+ documentitem.cpp - description
+ -------------------
+ begin : Do Sep 2 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+
+#include "documentitem.h"
+#include "tcanvasitem.h"
+
+#include "labelutils.h"
+
+#include <kapplication.h>
+
+#include <qpen.h>
+#include <qpaintdevicemetrics.h>
+#include <qpainter.h>
+#include <qdom.h>
+
+DocumentItem::DocumentItem()
+ : QObject(), XMLUtils()
+{
+ init();
+}
+
+void DocumentItem::init()
+{
+ m_canvasitem = NULL;
+ m_token = NULL;
+ m_device = KApplication::desktop();
+
+ m_z = 0;
+ m_border = true;
+ m_locked = false;
+ m_pen = QPen( Qt::black, 1, Qt::SolidLine );
+ m_rect = QRect( 0, 0, 0, 0 );
+ m_visibilityScript = "true";
+}
+
+void DocumentItem::drawBorder(QPainter* painter)
+{
+ if( m_border )
+ {
+ painter->save();
+ painter->setPen( m_pen );
+ painter->drawRect( rect() );
+ painter->restore();
+ }
+}
+
+void DocumentItem::loadXML (QDomElement* element)
+{
+ LabelUtils l;
+ m_rect.setX( element->attribute( "x_mm", "0" ).toInt() );
+ m_rect.setY( element->attribute( "y_mm", "0" ).toInt() );
+ m_rect.setWidth( element->attribute( "width_mm", "-1" ).toInt() );
+ m_rect.setHeight( element->attribute( "height_mm", "-1" ).toInt() );
+
+ m_pen.setColor( readXMLColor( element, "line-color", Qt::black ) );
+ m_pen.setStyle( (Qt::PenStyle)element->attribute( "line-style", "0" ).toInt() );
+ m_pen.setWidth( element->attribute( "line-width", "1" ).toInt() );
+ m_border = (bool)element->attribute( "line-visible", "1" ).toInt();
+ m_z = element->attribute( "z", "0" ).toInt();
+ m_locked = (bool)element->attribute( "locked", "0" ).toInt();
+ m_visibilityScript = element->attribute( "visibilityScript", "true" );
+}
+
+void DocumentItem::saveXML (QDomElement* element)
+{
+ element->setAttribute( "x_mm", m_rect.x() );
+ element->setAttribute( "y_mm", m_rect.y() );
+ element->setAttribute( "width_mm", m_rect.width() );
+ element->setAttribute( "height_mm", m_rect.height() );
+
+ writeXMLColor( element, "line-color", m_pen.color() );
+ element->setAttribute( "line-style", (Qt::PenStyle)m_pen.style() );
+ element->setAttribute( "line-width", m_pen.width() );
+ element->setAttribute( "line-visible", (int)m_border );
+ element->setAttribute( "z", m_z );
+ element->setAttribute( "locked", (int)m_locked );
+ element->setAttribute( "visibilityScript", m_visibilityScript );
+}
+
+void DocumentItem::move( int x, int y )
+{
+ LabelUtils l;
+ moveMM( (int)(l.pixelToMm( x, m_device, LabelUtils::DpiX ) * 1000.0 ),
+ (int)(l.pixelToMm( y, m_device, LabelUtils::DpiY ) * 1000.0 ) );
+}
+
+void DocumentItem::moveMM( int x, int y )
+{
+// Move is not relative!
+/* m_rect.setX( m_rect.x() + x );
+ m_rect.setY( m_rect.y() + y );*/
+ m_rect = QRect( x, y, m_rect.width(), m_rect.height() );
+}
+
+void DocumentItem::setSize( int w, int h )
+{
+ LabelUtils l;
+ setSizeMM( (int)(l.pixelToMm( w, m_device, LabelUtils::DpiX ) * 1000.0 ),
+ (int)(l.pixelToMm( h, m_device, LabelUtils::DpiY ) * 1000.0 ) );
+}
+
+void DocumentItem::setSizeMM( int w, int h )
+{
+ m_rect.setWidth( w );
+ m_rect.setHeight( h );
+}
+
+void DocumentItem::setBoundingRect( const QRect & rect )
+{
+ QRect r;
+ LabelUtils l;
+ r.setX( (int)(l.pixelToMm( rect.x(), m_device, LabelUtils::DpiX ) * 1000.0 ) );
+ r.setY( (int)(l.pixelToMm( rect.y(), m_device, LabelUtils::DpiY ) * 1000.0 ) );
+ r.setWidth( (int)(l.pixelToMm( rect.width(), m_device, LabelUtils::DpiX ) * 1000.0 ) );
+ r.setHeight( (int)(l.pixelToMm( rect.height(), m_device, LabelUtils::DpiY ) * 1000.0 ) );
+
+ // avoid resizing to negative values
+ setRectMM( r.normalize() );
+}
+
+QRect DocumentItem::boundingRect() const
+{
+ QRect r;
+
+ LabelUtils l;
+ r.setX( (int)(l.mmToPixel( m_rect.x(), m_device, LabelUtils::DpiX ) / 1000.0 ) );
+ r.setY( (int)(l.mmToPixel( m_rect.y(), m_device, LabelUtils::DpiY ) / 1000.0 ) );
+ r.setWidth( (int)(l.mmToPixel( m_rect.width(), m_device, LabelUtils::DpiX ) / 1000.0 ) );
+ r.setHeight( (int)(l.mmToPixel( m_rect.height(), m_device, LabelUtils::DpiY ) / 1000.0 ) );
+
+// qDebug("bounding rect %i %i %i %i", r.x(), r.y(), r.width(), r.height() );
+
+ return r;
+}
+
+void DocumentItem::setRect( const QRect & rect)
+{
+ // avoid resizing to negative values
+ QRect r = rect.normalize();
+ setBoundingRect( QRect( r.x() - m_pen.width(), r.y() - m_pen.width(), r.width() + 2 * m_pen.width(), r.height() + 2 * m_pen.width() ) );
+}
+
+QRect DocumentItem::rect() const
+{
+ QRect bound = boundingRect();
+ QRect r( bound.x() + m_pen.width(), bound.y() + m_pen.width(), bound.width() - 2 * m_pen.width(), bound.height() - 2 * m_pen.width() );
+// qDebug("rect %i %i %i %i", r.x(), r.y(), r.width(), r.height() );
+ return r;
+}
+
+void DocumentItem::setRectMM( const QRect & rect )
+{
+ // avoid resizing to negative values
+ m_rect = rect.normalize();
+}
+
+QRect DocumentItem::rectMM() const
+{
+ return m_rect;
+}
+
+void DocumentItem::setBorder (bool b)
+{
+ m_border = b;
+}
+
+bool DocumentItem::border () const
+{
+ return m_border;
+}
+
+void DocumentItem::setPen( const QPen & pen )
+{
+ m_pen = pen;
+}
+
+QPen DocumentItem::pen() const
+{
+ return m_pen;
+}
+
+void DocumentItem::setCanvasItem( TCanvasItem* item )
+{
+ m_canvasitem = item;
+}
+
+TCanvasItem* DocumentItem::canvasItem() const
+{
+ return m_canvasitem;
+}
+
+int DocumentItem::z() const
+{
+ return m_z;
+}
+
+void DocumentItem::setZ( int z )
+{
+ m_z = z;
+}
+
+void DocumentItem::setPaintDevice( QPaintDevice* device )
+{
+ m_device = device;
+}
+
+QPaintDevice* DocumentItem::paintDevice() const
+{
+ return m_device;
+}
+
+void DocumentItem::setTokenProvider( TokenProvider* token )
+{
+ m_token = token;
+}
+
+TokenProvider* DocumentItem::tokenProvider() const
+{
+ return m_token;
+}
+
+void DocumentItem::setLocked( bool locked )
+{
+ m_locked = locked;
+}
+
+const bool DocumentItem::locked() const
+{
+ return m_locked;
+}
+
diff --git a/kbarcode/documentitem.h b/kbarcode/documentitem.h
new file mode 100644
index 0000000..ff528d3
--- /dev/null
+++ b/kbarcode/documentitem.h
@@ -0,0 +1,230 @@
+/***************************************************************************
+ documentitem.h - description
+ -------------------
+ begin : Do Sep 2 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+
+#ifndef DOCUMENTITEM_H
+#define DOCUMENTITEM_H
+
+#include <xmlutils.h>
+#include <qobject.h>
+#include <qsortedlist.h>
+#include <qstring.h>
+#include <qtextstream.h>
+
+#include <qcolor.h>
+#include <qpen.h>
+
+#include "zplutils.h"
+
+enum ERtti {
+ eRtti_Barcode,
+ eRtti_Image,
+ eRtti_Line,
+ eRtti_Rect,
+ eRtti_Text,
+ //NY33
+ eRtti_TextLine
+ //NY33
+};
+
+class QDomElement;
+class QPainter;
+class QPaintDevice;
+class QTextStream;
+class TCanvasItem;
+class TokenProvider;
+
+/**
+ * Class DocumentItem
+ * Every object which can be placed on a document has to be a subclass of this class.
+ */
+class DocumentItem : public QObject, protected XMLUtils {
+public:
+ DocumentItem ( );
+ virtual ~DocumentItem() { };
+
+ /**
+ *
+ * @param element
+ */
+ virtual void loadXML (QDomElement* element);
+
+
+ /**
+ * save this item to XML
+ */
+ virtual void saveXML (QDomElement* element);
+
+
+ /**
+ * Draws the item
+ */
+ virtual void draw (QPainter* painter) = 0;
+
+
+ /**
+ * Draw a border around the item, has to be reimplemented for round items or barcodes which do not allow borders.
+ */
+ virtual void drawBorder (QPainter* painter);
+
+ virtual int rtti () const = 0;
+
+ /**
+ * Write a ZPL string for drawing this item onto a zebra printer to a QTextStream
+ */
+ virtual void drawZpl( QTextStream* stream ) = 0;
+
+ /**
+ * Write a IPL string for drawing this item onto a zebra printer to a QTextStream
+ */
+ virtual void drawIpl( QTextStream* stream, IPLUtils* utils ) = 0;
+
+ /**
+ * Write a EPCL string for drawing this item onto a zebra printer to a QTextStream
+ */
+ virtual void drawEPcl( QTextStream* stream ) = 0;
+
+ void setCanvasItem( TCanvasItem* item );
+ TCanvasItem* canvasItem() const;
+
+ void setPaintDevice( QPaintDevice* device );
+ QPaintDevice* paintDevice() const;
+
+ void setTokenProvider( TokenProvider* token );
+ TokenProvider* tokenProvider() const;
+
+ /**
+ *
+ * @param b
+ */
+ void setBorder (bool b);
+ bool border () const;
+
+ void setPen( const QPen& pen );
+ QPen pen() const;
+
+ /** move the documentitem using pixel coordinates on the current
+ * paint device
+ */
+ void move( int x, int y );
+ /** move the documentitem using 1/1000th of a millimeter coordinates
+ */
+ void moveMM( int x, int y );
+
+ /** set the width and height of this item using pixel coordinates
+ * of the current paint device
+ */
+ void setSize( int w, int h );
+ /** set the width and height of this item using 1/1000th of a
+ * millimeter coordinates
+ */
+ void setSizeMM( int w, int h );
+
+ /** The bounding rectangle. I.e. the rectangle including
+ * the border width
+ */
+ void setBoundingRect( const QRect & rect );
+ /** The bounding rectangle. I.e. the rectangle including
+ * the border width
+ */
+ QRect boundingRect() const;
+
+ /** The drawing rectangle. I.e. the rectangle with the
+ * border width substracted
+ */
+ void setRect( const QRect & rect );
+ /** The drawing rectangle. I.e. the rectangle with the
+ * border width substracted
+ */
+ QRect rect() const;
+
+ /** the bounding rectangle including the border in 1/1000mm
+ */
+ void setRectMM( const QRect & rect );
+ /** the bounding rectangle including the border in 1/1000mm
+ */
+ QRect rectMM() const;
+
+ /** set the item to be locked in the label editor
+ * i.e protect it from being move or resized by the user
+ */
+ void setLocked( bool locked );
+ const bool locked() const;
+
+ /** set a javascript script for this item which is evaluate
+ * to determine wether this item should be printed (only in Label
+ * as items are always shown in the labeleditor.
+ * The script shall return true if the item should be visible.
+ * If script returns false the item will not be printed.
+ */
+ inline void setVisibilityScript( const QString & script );
+ inline const QString visibilityScript() const;
+
+ int z() const;
+ void setZ( int z );
+
+ /** Only the z index is compared
+ */
+ bool operator<( const DocumentItem & docitem )
+ {
+ return m_z < docitem.m_z;
+ }
+
+ /** Only the z index is compared
+ */
+ bool operator==( const DocumentItem & docitem )
+ {
+ return m_z == docitem.m_z;
+ }
+private:
+ void init();
+
+private:
+ /**
+ * Defines wether this item has a border or not
+ */
+ bool m_border;
+ QPen m_pen;
+ QRect m_rect;
+ int m_z;
+ bool m_locked;
+
+ /**
+ * Background color of this document item
+ */
+ QColor m_background;
+
+ QString m_visibilityScript;
+
+ QPaintDevice* m_device;
+ TCanvasItem* m_canvasitem;
+ TokenProvider* m_token;
+};
+
+void DocumentItem::setVisibilityScript( const QString & script )
+{
+ m_visibilityScript = script;
+}
+
+const QString DocumentItem::visibilityScript() const
+{
+ return m_visibilityScript;
+}
+
+typedef QSortedList<DocumentItem> DocumentItemList;
+
+#endif //DOCUMENTITEM_H
+
diff --git a/kbarcode/documentitemdlg.cpp b/kbarcode/documentitemdlg.cpp
new file mode 100644
index 0000000..9055de4
--- /dev/null
+++ b/kbarcode/documentitemdlg.cpp
@@ -0,0 +1,121 @@
+/***************************************************************************
+ documentitemdlg.cpp - description
+ -------------------
+ begin : Do Sep 10 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+
+#include "documentitemdlg.h"
+#include "tokenprovider.h"
+
+#include <qvbox.h>
+
+#include <kcommand.h>
+#include <klocale.h>
+
+DocumentItemDlg::DocumentItemDlg( TokenProvider* token, DocumentItem* item, KCommandHistory* history, QWidget* parent )
+ : KDialogBase( Tabbed, i18n("Properties"), KDialogBase::Ok|KDialogBase::Cancel,
+ KDialogBase::Ok, parent, 0, true, true )
+{
+ m_item = item;
+ m_history = history;
+ //m_list.setAutoDelete( false );
+
+ QVBox* boxBorder = addVBoxPage(i18n("&Position && Size"), QString::null, QPixmap() );
+ addPage( new PropertySize( boxBorder ) );
+
+ boxBorder = addVBoxPage(i18n("&Border"), QString::null, QPixmap() );
+ addPage( new PropertyBorder( boxBorder ) );
+
+ if( m_item->rtti() == eRtti_Rect )
+ {
+ boxBorder = addVBoxPage(i18n("&Fill Color"), QString::null, QPixmap() );
+ addPage( new PropertyFill( boxBorder) );
+ }
+ else if ( m_item->rtti() == eRtti_Barcode )
+ {
+ boxBorder = addVBoxPage(i18n("&Barcode"), QString::null, QPixmap() );
+ addPage( new PropertyBarcode( token, boxBorder) );
+ }
+ else if ( m_item->rtti() == eRtti_Text )
+ {
+ boxBorder = addVBoxPage(i18n("&Rotation"), QString::null, QPixmap() );
+ addPage( new PropertyRotation( boxBorder ) );
+
+ boxBorder = addVBoxPage(i18n("&Text"), QString::null, QPixmap() );
+ addPage( new PropertyText( token, boxBorder) );
+ }
+ else if( m_item->rtti() == eRtti_Image )
+ {
+ boxBorder = addVBoxPage(i18n("&Image"), QString::null, QPixmap() );
+ addPage( new PropertyImage( token, boxBorder) );
+ }
+//NY19
+ else if ( m_item->rtti() == eRtti_TextLine )
+ {
+ boxBorder = addVBoxPage(i18n("&Text"), QString::null, QPixmap() );
+ addPage( new PropertyTextLine( token, boxBorder) );
+ }
+//NY19
+
+ showPage( pageIndex( boxBorder ) );
+
+ // Add it after the call to showPage
+ // so that this page is not always shown
+ // as default page
+ if( TokenProvider::hasJavaScript() )
+ {
+ boxBorder = addVBoxPage(i18n("&Visibility"), QString::null, QPixmap() );
+ addPage( new PropertyVisible( boxBorder ) );
+ }
+
+ std::list<PropertyWidget*>::iterator it;
+ for( it=m_list.begin();it!=m_list.end();it++)
+ {
+ (*it)->initSettings( m_item );
+ }
+
+ resize( configDialogSize("DocumentItemDlg") );
+}
+
+DocumentItemDlg::~DocumentItemDlg()
+{
+ saveDialogSize("DocumentItemDlg");
+
+ std::list<PropertyWidget*>::iterator it;
+ for( it=m_list.begin();it!=m_list.end();it++)
+ {
+ delete (*it);
+ }
+}
+
+void DocumentItemDlg::addPage( PropertyWidget* widget )
+{
+ m_list.push_back( widget );
+}
+
+void DocumentItemDlg::accept()
+{
+ KMacroCommand* mc = new KMacroCommand( i18n("Property changed") );
+ std::list<PropertyWidget*>::iterator it;
+ for( it=m_list.begin();it!=m_list.end();it++)
+ {
+ (*it)->applySettings( m_item, mc );
+ }
+
+ m_history->addCommand( mc, false );
+
+ KDialogBase::accept();
+}
+
+#include "documentitemdlg.moc"
diff --git a/kbarcode/documentitemdlg.h b/kbarcode/documentitemdlg.h
new file mode 100644
index 0000000..732432e
--- /dev/null
+++ b/kbarcode/documentitemdlg.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ documentitemdlg.h - description
+ -------------------
+ begin : Do Sep 10 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+
+#ifndef DOCUMENTITEMDLG_H
+#define DOCUMENTITEMDLG_H
+
+#include <kdialogbase.h>
+#include "documentitem.h"
+#include "propertywidget.h"
+#include <list>
+
+class KCommandHistory;
+
+class DocumentItemDlg : public KDialogBase
+{
+ Q_OBJECT
+ public:
+ DocumentItemDlg( TokenProvider* token, DocumentItem* item, KCommandHistory* history, QWidget* parent );
+ ~DocumentItemDlg();
+
+ void addPage( PropertyWidget* widget );
+
+ protected slots:
+ void accept();
+
+ private:
+ DocumentItem* m_item;
+ std::list<PropertyWidget*> m_list;
+
+ KCommandHistory* m_history;
+};
+
+#endif
diff --git a/kbarcode/dsmainwindow.cpp b/kbarcode/dsmainwindow.cpp
new file mode 100644
index 0000000..0e30c4d
--- /dev/null
+++ b/kbarcode/dsmainwindow.cpp
@@ -0,0 +1,268 @@
+/***************************************************************************
+ dsmainwindow.cpp - description
+ -------------------
+ begin : Fri Jan 17 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "dsmainwindow.h"
+#include "sqltables.h"
+#include "confwizard.h"
+#include "printersettings.h"
+#include "kbarcodesettings.h"
+#include "kactionmap.h"
+#include "barkode.h"
+
+// Qt includes
+#include <qcheckbox.h>
+#include <qtextbrowser.h>
+#include <qsqldatabase.h>
+
+// KDE includes
+#include <kaction.h>
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kmenubar.h>
+#include <kmessagebox.h>
+#include <kpopupmenu.h>
+#include <kstandarddirs.h>
+#include <krun.h>
+
+bool DSMainWindow::autoconnect = true;
+bool DSMainWindow::startwizard = true;
+
+DSMainWindow::DSMainWindow(QWidget *parent, const char *name, WFlags f)
+ : KMainWindow(parent,name,f)
+{
+ connectAct = 0;
+ first = false;
+ loadConfig();
+
+ setAutoSaveSettings( QString("Window") + name, true );
+ connect( kapp, SIGNAL( aboutToQuit() ), this, SLOT( saveConfig() ) );
+
+ if( first && startwizard ) {
+ wizard();
+ startwizard = false;
+ }
+
+}
+
+DSMainWindow::~DSMainWindow()
+{
+}
+
+void DSMainWindow::setupActions()
+{
+ KAction* quitAct = KStdAction::quit(kapp, SLOT(quit()), actionCollection());
+ KAction* closeAct = KStdAction::close( this, SLOT( close() ), actionCollection(), "close" );
+ KAction* configureAct = KStdAction::preferences( KBarcodeSettings::getInstance(), SLOT(configure()), actionCollection() );
+ KAction* wizardAct = new KAction( i18n("&Start Configuration Wizard..."), BarIcon("wizard"), 0, this,
+ SLOT(wizard()), actionCollection(), "wizard" );
+ connectAct = new KAction(i18n("&Connect to Database"), BarIcon("connect_no"), 0, this, SLOT(connectMySQL()),
+ actionCollection(),"connect" );
+
+
+ KAction* newTablesAct = new KAction( i18n("&Create Tables"), "", 0, this,
+ SLOT(newTables()), actionCollection(), "tables" );
+
+ importLabelDefAct = new KAction( i18n("&Import Label Definitions"), "", 0, SqlTables::getInstance(),
+ SLOT(importLabelDef()), actionCollection(), "import" );
+
+ importExampleAct = new KAction( i18n("&Import Example Data"), "", 0, SqlTables::getInstance(),
+ SLOT(importExampleData()), actionCollection(), "import" );
+
+ KPopupMenu* file = new KPopupMenu( this );
+ KPopupMenu* settings = new KPopupMenu( this );
+ KPopupMenu* hlpMenu = helpMenu();
+ int helpid = hlpMenu->idAt( 0 );
+ hlpMenu->removeItem( helpid );
+ hlpMenu->insertItem( SmallIconSet("contents"), i18n("&Help"),
+ this, SLOT(appHelpActivated()), Key_F1, -1, 0 );
+ hlpMenu->insertSeparator(-1);
+ hlpMenu->insertItem( i18n("&Action Map..."), this, SLOT( slotFunctionMap() ), 0, -1, 0 );
+ hlpMenu->insertSeparator(-2);
+ hlpMenu->insertItem( SmallIconSet("system"), i18n("&System Check..."), this, SLOT(showCheck() ), 0, -1, 0 );
+ hlpMenu->insertItem( SmallIconSet("barcode"), i18n("&Barcode Help..."), this, SLOT( startInfo() ), 0, -1, 0 );
+ hlpMenu->insertItem( i18n("&Donate..."), this, SLOT( donations() ), 0, -1, 0 );
+
+ menuBar()->insertItem( i18n("&File"), file );
+ menuBar()->insertItem( i18n("&Settings"), settings );
+ menuBar()->insertItem( i18n("&Help"), hlpMenu );
+
+ closeAct->plug( file );
+ quitAct->plug( file );
+
+ configureAct->plug( settings );
+ wizardAct->plug( settings );
+ connectAct->plug( settings );
+ (new KActionSeparator( this ))->plug( settings );
+ newTablesAct->plug( settings );
+ importLabelDefAct->plug( settings );
+ importExampleAct->plug( settings );
+
+ SqlTables* tables = SqlTables::getInstance();
+ if( tables->getData().autoconnect && autoconnect && !first ) {
+ tables->connectMySQL();
+ autoconnect = false;
+ }
+
+ connectAct->setEnabled( !SqlTables::isConnected() );
+ importLabelDefAct->setEnabled( !connectAct->isEnabled() );
+ importExampleAct->setEnabled( !connectAct->isEnabled() );
+}
+
+void DSMainWindow::loadConfig()
+{
+ KConfig* config = kapp->config();
+
+ config->setGroup("Wizard");
+ first = config->readBoolEntry("firststart2", true );
+
+ SqlTables* tables = SqlTables::getInstance();
+ if( tables->getData().autoconnect && !first && autoconnect && connectAct ) {
+ connectAct->setEnabled( !tables->connectMySQL() );
+ importLabelDefAct->setEnabled( !connectAct->isEnabled() );
+ importExampleAct->setEnabled( !connectAct->isEnabled() );
+
+ autoconnect = false;
+ }
+
+ KBarcodeSettings::getInstance()->loadConfig();
+}
+
+void DSMainWindow::saveConfig()
+{
+ KConfig* config = kapp->config();
+
+ config->setGroup("Wizard");
+ config->writeEntry("firststart2", false );
+
+ PrinterSettings::getInstance()->saveConfig();
+ SqlTables::getInstance()->saveConfig();
+ KBarcodeSettings::getInstance()->saveConfig();
+
+ config->sync();
+}
+
+void DSMainWindow::wizard()
+{
+ ConfWizard* wiz = new ConfWizard( 0, "wiz", true );
+ if( wiz->exec() == QDialog::Accepted && wiz->checkDatabase->isChecked() )
+ SqlTables::getInstance()->connectMySQL();
+
+ delete wiz;
+}
+
+void DSMainWindow::connectMySQL()
+{
+ connectAct->setEnabled( !SqlTables::getInstance()->connectMySQL() );
+ importLabelDefAct->setEnabled( !connectAct->isEnabled() );
+ importExampleAct->setEnabled( !connectAct->isEnabled() );
+
+ if( !connectAct->isEnabled() )
+ emit connectedSQL();
+}
+
+void DSMainWindow::appHelpActivated()
+{
+ KMessageBox::information( this, i18n(
+ "<qt>The KBarcode documentation is avaible as PDF for download on our webpage.<br><br>") +
+ "<a href=\"http://www.kbarcode.net/17.0.html\">" +
+ i18n("Download Now") + "</a></qt>",
+ QString::null, QString::null, KMessageBox::AllowLink );
+}
+
+void DSMainWindow::showCheck()
+{
+ QTextBrowser* b = new QTextBrowser( 0, "b" );
+ b->setText( DSMainWindow::systemCheck() );
+ b->resize( 320, 240 );
+ b->show();
+}
+
+void DSMainWindow::startInfo()
+{
+ QString info = locate("appdata", "barcodes.html");
+ if( !info.isEmpty() )
+ kapp->invokeBrowser( info );
+}
+
+bool DSMainWindow::newTables()
+{
+ return SqlTables::getInstance()->newTables();
+}
+
+void DSMainWindow::donations()
+{
+ // orig =https://www.paypal.com/xclick/business=domseichter%40web.de&item_name=Support+KBarcode+Development&item_number=0&image_url=http%3A//www.kbarcode.net/themes/DeepBlue/images/logo.gif&no_shipping=1&return=http%3A//www.kbarcode.net&cancel_return=http%3A//www.kbarcode.net&cn=Suggestions%2C+Comments%3F&tax=0&currency_code=EUR
+ QString url = "https://www.paypal.com/xclick/business=domseichter@web.de&item_name=Support+KBarcode+Development&item_number=0&image_url=www.kbarcode.net/themes/DeepBlue/images/logo.gif&no_shipping=1&return=www.kbarcode.net&cancel_return=www.kbarcode.net&cn=Suggestions,+Comments,&tax=0&currency_code=EUR";
+
+ KMessageBox::information( this, i18n(
+ "<qt>It is possible to support the further development of KBarcode through donations. "
+ "PayPal will be used for processing the donation.<br><br>" ) +
+ "<a href=\"" + url + "\">" +
+ i18n("Donate Now") + "</a></qt>", QString::null, QString::null, KMessageBox::AllowLink );
+}
+
+QString DSMainWindow::systemCheck()
+{
+ bool gnubarcode = !Barkode::haveGNUBarcode();
+ bool pdf = !Barkode::havePDFBarcode();
+ bool tbarcode = !Barkode::haveTBarcode();
+ bool tbarcode2 = !Barkode::haveTBarcode2();
+ bool pure = !Barkode::havePurePostscriptBarcode();
+
+ QString text;
+
+ text.append( i18n("<p><h3>Barcode Support</h3></p>") );
+ text.append( "<p>GNU Barcode: ");
+ text.append( gnubarcode ? i18n("<b>No</b><br />") : i18n("<b>Found</b><br />") );
+ text.append( "PDF417 Encode: ");
+ text.append( pdf ? i18n("<b>No</b><br />") : i18n("<b>Found</b><br />") );
+ text.append( "TBarcode: ");
+ text.append( tbarcode ? i18n("<b>No</b><br />") : i18n("<b>Found</b><br />") );
+ text.append( "TBarcode2: ");
+ text.append( tbarcode2 ? i18n("<b>No</b><br />") : i18n("<b>Found</b><br />") );
+ text.append( "Pure Postscript Barcode Writer: ");
+ text.append( pure ? i18n("<b>No</b><br />") : i18n("<b>Found</b><br />") );
+
+ if( gnubarcode && tbarcode && pdf )
+ text.append( i18n("<p>To get <b>barcode support</b> you have to either install <i>GNU Barcode</i>, <i>TBarcode</i> or <i>PDF417 Enc</i>.</p>") );
+
+ text.append( i18n("<p><h3>Database Support</h3></p>") );
+
+ QStringList list = QSqlDatabase::drivers();
+
+ if( list.count() ) {
+ text.append( "<ul>" );
+ QStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ text.append( i18n("<li>Driver found: ") + *it + "</li>" );
+ ++it;
+ }
+ text.append( "</ul>" );
+ } else
+ text.append( i18n("<p><b>No database drivers found. SQL database support is disabled.</b></p>") );
+
+ return text;
+}
+
+void DSMainWindow::slotFunctionMap()
+{
+ new KActionMapDlg( actionCollection(), this );
+}
+
+#include "dsmainwindow.moc"
diff --git a/kbarcode/dsmainwindow.h b/kbarcode/dsmainwindow.h
new file mode 100644
index 0000000..c43959b
--- /dev/null
+++ b/kbarcode/dsmainwindow.h
@@ -0,0 +1,90 @@
+/***************************************************************************
+ dsmainwindow.h - description
+ -------------------
+ begin : Fre Jan 17 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef DSMAINWINDOW_H
+#define DSMAINWINDOW_H
+
+#include <qwidget.h>
+#include <kmainwindow.h>
+
+class KAction;
+class KPopupMenu;
+/** The base class of all main windows of KBarcode. It provides standard menu items
+ * for database connections, preferences, help, the first start wizard and donations.
+ * It checks also if this is the first start of KBarcode and if the configuration wizard
+ * should be started.
+ *
+ * @author Dominik Seichter
+ */
+class DSMainWindow : public KMainWindow {
+ Q_OBJECT
+ public:
+ DSMainWindow(QWidget *parent=0, const char *name=0, WFlags f = WType_TopLevel | WDestructiveClose );
+ ~DSMainWindow();
+
+ /** Is this the first start of KBarcode ?
+ * If true, the configuration wizard will
+ * be started automatically.
+ */
+ bool isFirstStart() const {
+ return first;
+ }
+
+
+ /** Do a system check and return a text
+ * informing the user about missing, programs
+ * and drivers for barcode support and database
+ * access.
+ */
+ static QString systemCheck();
+
+ public slots:
+ void wizard();
+
+ signals:
+ void connectedSQL();
+
+ private slots:
+ void connectMySQL();
+ void appHelpActivated();
+ void startInfo();
+ bool newTables();
+ void donations();
+ void showCheck();
+ void slotFunctionMap();
+
+ protected slots:
+ void loadConfig();
+ void saveConfig();
+
+ protected:
+ void setupActions();
+
+ static bool autoconnect;
+ static bool startwizard;
+
+ bool first;
+
+ KAction* connectAct;
+ KAction* importLabelDefAct;
+ KAction* importExampleAct;
+
+ KPopupMenu* file;
+ KPopupMenu* settings;
+ KPopupMenu* hlpMenu;
+};
+#endif
diff --git a/kbarcode/dsrichtext.cpp b/kbarcode/dsrichtext.cpp
new file mode 100644
index 0000000..01f7182
--- /dev/null
+++ b/kbarcode/dsrichtext.cpp
@@ -0,0 +1,427 @@
+/***************************************************************************
+ dsrichtext.cpp - description
+ -------------------
+ begin : Fre Okt 17 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "dsrichtext.h"
+
+#ifdef QT_TEXT_BUG
+
+// Qt includes
+#include <qfontmetrics.h>
+#include <qpainter.h>
+#include <qregexp.h>
+
+// for DSREPLACE
+#include "sqltables.h"
+
+/*
+EXAMPLE TEXT:
+ "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:10pt;font-family:Nimbus Sans l\">"
+ "<p>A little bit <span style=\"font-style:italic;font-weight:600\">formated</span><span style=\"color:#4400ff\"> "
+ "richtext</span> which should be printed to a <span style=\"font-weight:600\">QPrinter</span> with <span style=\"text-decoration:underline\">QSimpleRichText</span>. </p>"
+ "<p><span style=\"font-family:Times New Roman;font-size:16pt\">Printing should work in ScreenResolution as well as in HighResolution, but as you can see it will only work in ScreenResolution.</span></p>"
+ "</body></html>";
+
+Another example
+<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:10pt;font-family:Nimbus Sans l">
+<p align="center"><span style="font-size:12pt;font-weight:600;text-decoration:underline">Text test </span><span style="font-size:12pt;font-weight:600;text-decoration:underline;color:#ff0000">label</span></p>
+<p>Resolution <span style="font-weight:600">formated</span> 108dpi. This text &amp; text should now overlap with the first line. 4 &lt; 6a</p>
+<p><span style="font-family:Nimbus Sans L;font-weight:600">A</span><span style="font-family:Nimbus Sans L"> longer paragraph with some text, so that I can test wether wordwrap is working. Another &quot;line&quot; to test line spacing without a bigger font (like the one found in the next sentence) messing up the spacing.</span><span style="font-family:Courier [Adobe];font-size:16pt"> Some text &quot;in&quot; a bigger courier font.</span><span style="font-family:Nimbus Sans L"> Also this paragraph should be justified as blockquote.</span><span style="font-family:Nimbus Sans L;color:#ff0004"> I hope it works</span><span style="font-family:Nimbus Sans L"> and KBarcodes text redering will be better than the one found in Qt.</span></p>
+</body></html>
+
+*/
+
+DSRichText::DSRichText( const QString & t )
+ : text( t )
+{
+ if( text.find("<html>") == -1 )
+ text = "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:10pt;font-family:Nimbus Sans l\"><p>"
+ + t + "</p></body></html>";
+
+ //qDebug( text );
+
+ start = end = pos = 0;
+ x = y = 0;
+ sx = sy = 1.0;
+ m_base = QFont();
+
+ QString tmp = parse( text, "<body ", ">", 0 );
+ if( !tmp.isNull() ) {
+ pos += tmp.length();
+ tmp = tmp.left( tmp.length() - 1 );
+ tmp = tmp.mid( 5, tmp.length() - 5 );
+ m_base = parseStyle( parse( tmp, "style=\"", "\"", pos ), &m_color );
+ }
+
+ pos = text.find( "<p", 0 ); // initalize pos correctly
+ while( parseParagraph() ); // empty while loop
+}
+
+DSRichText::~DSRichText()
+{
+}
+
+void DSRichText::initFormat( formated_word* f, int alignment )
+{
+ f->text = QString::null;
+ f->line = false;
+ f->alignment = alignment;
+ f->font = m_base;
+ f->color = m_color;
+}
+
+void DSRichText::initLine( QValueList<formated_line>* l )
+{
+ formated_line li;
+ li.width = 0;
+ li.ascent = 0;
+ li.leading = 0;
+ li.lineSpacing = 0;
+ li.line = false;
+ l->append( li );
+}
+
+void DSRichText::updateSpacing( QValueList<formated_line>* l, QFontMetrics* fm )
+{
+ l->last().lineSpacing = (l->last().lineSpacing < fm->lineSpacing()) ? fm->lineSpacing() : l->last().lineSpacing;
+ l->last().ascent = (l->last().ascent < fm->ascent()) ? fm->ascent() : l->last().ascent;
+ l->last().leading = (l->last().leading < fm->leading()) ? fm->leading() : l->last().leading;
+}
+
+void DSRichText::fillLines()
+{
+ for( unsigned int z = 0; z < word_p.count(); z++ ) {
+ WordList words = word_p[z];
+ LineList lines;
+ initLine( &lines );
+ for( unsigned int i = 0; i < words.count(); i++ ) {
+ formated_word word = words[i];
+ lines.last().line = lines.last().line | word.line;
+
+ QFontMetrics fm( word.font );
+ updateSpacing( &lines, &fm );
+
+ int tw = fm.width( word.text );
+ // word does not fit in the current line, create a new one
+ if( lines.last().width + tw >= w )
+ initLine( &lines );
+
+ // TODO: check here for words longer than one line
+ lines.last().formats.append( word );
+ lines.last().width += tw;
+ }
+ line_p.append( lines );
+ }
+}
+
+void DSRichText::draw( QPainter* p )
+{
+ /* don't try to draw if there is no space to draw */
+ if( !w || !h )
+ return;
+
+ fillLines();
+
+ painter = p;
+ painter->save();
+ painter->setClipRect( xpos, ypos, int(w*sx), int(h*sy), QPainter::CoordPainter );
+
+ for( unsigned int z = 0; z < line_p.count(); z++ ) {
+ LineList lines = line_p[z];
+ if( lines.count() && z )
+ y += int( lines[0].lineSpacing * 0.5);
+
+ for( unsigned int i = 0; i < lines.count(); i++ ) {
+ formated_line l = lines[i];
+
+ if( l.formats.count() && l.formats[0].alignment == Qt::AlignJustify && i != lines.count() - 1 ) {
+ // last line in a paragraph is not justified (in blocksatz mode)!
+ drawJustified( &l );
+ } else {
+ for( unsigned int z = 0; z < l.formats.count(); z++ ) {
+ formated_word f = l.formats[z];
+
+ painter->setFont( f.font );
+ painter->setPen( QPen( f.color ) );
+
+ int a = f.alignment;
+ if( a == Qt::AlignRight ) {
+ a = Qt::AlignLeft;
+ if( !x )
+ x = w - l.width;
+ } else if( a == Qt::AlignHCenter ) {
+ a = Qt::AlignLeft;
+ if( !x )
+ x = ( w - l.width ) / 2;
+ }
+
+ int ya = yDeviation( &l );
+ painter->drawText( xpos + int(x*sx), ypos + int((y+ya)*sy), int(l.width*sx), int(l.lineSpacing * sy), a, f.text );
+ x += painter->fontMetrics().width( f.text );
+ }
+ }
+
+ x = 0;
+ y += l.lineSpacing;
+ }
+ }
+
+ painter->restore();
+}
+
+void DSRichText::drawJustified( formated_line* line )
+{
+ int all = 0;
+ for( unsigned int z = 0; z < line->formats.count(); z++ ) {
+ line->formats[z].text = line->formats[z].text.stripWhiteSpace();
+ QFontMetrics fm( line->formats[z].font );
+ all += fm.width( line->formats[z].text );
+ }
+
+ int x = 0;
+ int space = (w - all) / (line->formats.count() - 1);
+ for( unsigned int z = 0; z < line->formats.count(); z++ ) {
+ painter->setFont( line->formats[z].font );
+ painter->setPen( QPen( line->formats[z].color ) );
+
+ int ya = yDeviation( line );
+ int tw = painter->fontMetrics().width(line->formats[z].text);
+ painter->drawText( int(x*sx), int((y+ya)*sy), int(tw*sx), int(line->lineSpacing * sy), Qt::AlignAuto, line->formats[z].text );
+ x += tw;
+ x += space;
+ }
+
+}
+
+bool DSRichText::parseParagraph()
+{
+ int alignment = 0;
+ formated_word f;
+ QString d = parse( text, "<p", "</p>", pos );
+ //qDebug("D=" + d );
+ //qDebug("POS=%i", pos );
+
+ pos += d.length();
+ if( d.isNull() )
+ return false;
+
+ d = parseParagraphTag( d, &alignment );
+
+ WordList words;
+ QString data;
+ initFormat( &f, alignment );
+
+ if( d.isEmpty() ) {
+ // found empty paragraph
+ words.append( f );
+ word_p.append( words );
+ return true;
+ }
+
+ for( unsigned int i = 0; i < d.length(); ) {
+ if( d[i] == '<' || i == (d.length() - 1) ) {
+ if( i == (d.length() - 1) )
+ data.append( d[i] );
+
+ parseWords( data, &f, &words );
+ initFormat( &f, alignment );
+ data = QString::null;
+
+ // bail out now, otherwise there is
+ // and endless loop for e.g. <p>a</p>
+ if( i == (d.length() - 1) )
+ break;
+
+ if( d[i] == '<' ) {
+ QString span = d.mid( i, d.find( ">", i ) - i + 1 );
+ i += span.length();
+
+ if( span.startsWith( "<span " ) ) {
+ initFormat( &f, alignment );
+ f.font = parseStyle( parse( span, "style=\"", "\"", 0 ), &f.color );
+ }
+ }
+ } else {
+ data.append( d[i] );
+ i++;
+ }
+ }
+
+ word_p.append( words );
+ return true;
+}
+
+QFont DSRichText::parseStyle( const QString & s, QColor* color )
+{
+ QString style = QString( s );
+
+ style = style.left( style.length() - 1 );
+ if( style.startsWith("style=\"" ) )
+ style = style.mid( 7, style.length() - 7 );
+
+ QFont f = m_base;
+ *color = m_color;
+
+ for ( int i = 0; i < style.contains(';')+1; i++ ) {
+ QString s = style.section( ';', i, i );
+ if( s.isEmpty() )
+ continue;
+
+ if ( s.startsWith("font-size:" ) ) {
+ f.setPointSize( s.mid(10, s.length() - 12).toInt() );
+ } else if ( s.startsWith("font-family:" ) ) {
+ f.setFamily( s.right( s.length() - 12 ) );
+ } else if( s.startsWith( "color:" ) ) {
+ color->setNamedColor( s.right( s.length() - 6 ) );
+ } else if( s.startsWith("text-decoration:") ) {
+ if( s.endsWith( "underline" ) )
+ f.setUnderline( true );
+/*#if QT_VERSION >= 0x030200
+ else if( s.endsWith( "overline" ) )
+ f.setOverline( true );
+#endif */
+ else if( s.endsWith( "line-through" ) )
+ f.setStrikeOut( true );
+ } else if( s.startsWith( "font-style:") ) {
+ if( s.endsWith( "italic" ) || s.endsWith( "oblique" ) )
+ f.setItalic( true );
+ } else if( s.startsWith( "font-weight:" ) ) {
+ bool ok = false;
+ int n = s.right( s.length() - 12 ).toInt( &ok );
+ if( s.endsWith( "bold" ) )
+ f.setBold( true );
+ else if( ok )
+ f.setWeight( n / 8 ); // convert CSS values to Qt values
+ }
+ }
+
+ return f;
+}
+
+QString DSRichText::parse( const QString & t, const QString & find, const QString & find2, int start )
+{
+ int s = t.find( find, start );
+ if( s == -1 || s < start )
+ return QString::null;
+
+ int pend = t.find( find2, s + find.length() );
+ if( pend == -1 || pend < (signed int)(s + find.length()) )
+ return QString::null;
+
+ QString text = t.mid( s, pend - s + find2.length() );
+ return text;
+}
+
+void DSRichText::setX( int x )
+{
+ xpos = x;
+}
+
+void DSRichText::setY( int y )
+{
+ ypos = y;
+}
+
+void DSRichText::setWidth( int width )
+{
+ w = width;
+}
+
+void DSRichText::setHeight( int height )
+{
+ h = height;
+}
+
+int DSRichText::parseAlignment( const QString & align )
+{
+ QString a = QString( align );
+ if( a.endsWith("\"") )
+ a = a.left( a.length() - 1 );
+
+ if( a.startsWith("align=\"") )
+ a = a.mid( 7, a.length() - 7 );
+
+ if( a == "left" )
+ return Qt::AlignLeft;
+ else if( a == "center" )
+ return Qt::AlignHCenter;
+ else if( a == "right" )
+ return Qt::AlignRight;
+ else if( a == "justify" )
+ return Qt::AlignJustify;
+
+ return 0;
+}
+
+void DSRichText::parseWords( const QString & t, formated_word* w, WordList* words )
+{
+ unsigned int p = 0;
+ for( unsigned int i = 0; i < t.length(); i++ ) {
+ if( (t[i].isSpace() && p != i) || i == t.length() - 1 ) {
+ formated_word word = *w;
+
+ word.text = replaceEscapeSequences( t.mid( p, i + 1 - p ) );
+
+ p = i + 1;
+ words->append( word );
+ }
+ }
+}
+
+inline int DSRichText::yDeviation( const formated_line* line )
+{
+ // leading = 1 (almost ever)
+ // linespacing = leading + height
+ // height = ascent + descent + 1
+ if( line->lineSpacing != painter->fontMetrics().lineSpacing() ) {
+ return line->ascent + line->leading - painter->fontMetrics().ascent() - painter->fontMetrics().leading();
+ } else {
+ return 0;
+ }
+}
+
+QString DSRichText::replaceEscapeSequences( const QString & t )
+{
+ QString tmp = QString( t );
+ tmp = tmp.replace( DSREPLACE( "&lt;" ), "<" );
+ tmp = tmp.replace( DSREPLACE( "&gt;" ), ">" );
+ tmp = tmp.replace( DSREPLACE( "&amp;" ), "&" );
+ tmp = tmp.replace( DSREPLACE( "&quot;" ), "\"" );
+ return tmp;
+}
+
+QString DSRichText::parseParagraphTag( const QString &t, int* alignment )
+{
+ QString d = QString( t );
+ if( d.startsWith("<p>") ) {
+ d = d.mid( 3, d.length() - 3 );
+ } else if( d.startsWith("<p ") ) {
+ *alignment = parseAlignment( parse( d, "align=\"", "\"", 0 ) );
+ if( d.contains( ">" ) ) {
+ int x = d.find(">" ) + 1;
+ d = d.mid( x, d.length() - x );
+ }
+ }
+
+ if( d.endsWith("</p>") )
+ d = d.left( d.length() - 4 ); // strlen("</p>");
+
+ return d;
+}
+
+#endif // QT_TEXT_BUG
+
+
diff --git a/kbarcode/dsrichtext.h b/kbarcode/dsrichtext.h
new file mode 100644
index 0000000..5da22b1
--- /dev/null
+++ b/kbarcode/dsrichtext.h
@@ -0,0 +1,193 @@
+/***************************************************************************
+ dsrichtext.h - description
+ -------------------
+ begin : Fre Okt 17 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef DSRICHTEXT_H
+#define DSRICHTEXT_H
+
+#define QT_TEXT_BUG
+/*#undef QT_TEXT_BUG*/
+#ifdef QT_TEXT_BUG
+
+#include <qcolor.h>
+#include <qfont.h>
+#include <qstring.h>
+#include <qvaluelist.h>
+
+class DSRichText;
+
+/** This class represents one word,
+ * formated with a font, a color and an
+ * alignment.
+ */
+struct formated_word {
+ QString text;
+ QFont font;
+ QColor color;
+ int alignment;
+ bool line;
+};
+
+typedef QValueList<formated_word> WordList;
+
+/** This structure represents a single line.
+ * Every line contains a list of formated_words.
+ * Wordwrapping has been applied before the line
+ * was created.
+ * lineSpacing, ascent and leading come from the
+ * biggest font in the line.
+ */
+struct formated_line {
+ int width;
+ int lineSpacing;
+ int ascent;
+ int leading;
+ bool line;
+
+ WordList formats;
+};
+typedef QValueList<formated_line> LineList;
+
+class QColor;
+class QPainter;
+
+/** A richtext rendering class, which draws a piece
+ * of HTML formated richtext on any QPainter.
+ * This class works with all printer resolutions compared
+ * to the buggy QSimpleRichText
+ *
+ * rendering the richtext happens in 3 steps:
+ * <ul>
+ * <li> the HTML data is parsed into text_format structures. Each
+ * of these text_format structures may represend multiple lines, but
+ * also single words. This depends on how long a formated text is.
+ * this step happens in the constructor and in parseParagraph()</li>
+ * <li> the text_format structures are parsed into line structures.
+ * In this step the wordwrapping is calculated. Each line structure
+ * has again text_format structures. This is necessary because a line
+ * of text may of course contain different formattings. A line struct is always
+ * a single line of drawn text, not more and not less.
+ * happens in draw() and fillLines()</li>
+ * <li> the line structure is drawn line by line using QPainter.
+ * happens in draw()</li>
+ * </ul>
+ *
+ * Printing to the screen is easy and the usage does not differ from
+ * QSimpleRichText. Drawing on QPrinter is a little bit more complicated.
+ * The most important thing is that you may not use QPainter::scale().
+ * A small example on how to print on a QPrinter:
+ * <pre>
+ * QPrinter printer( QPrinter::HighResolution );
+ * QPainter painter( &printer );
+ * QPaintDeviceMetrics metrics( &printer );
+ * double scalex = (double)metrics.logicalDpiX() / (double)QPaintDevice::x11AppDpiX();
+ * double scaley = (double)metrics.logicalDpiY() / (double)QPaintDevice::x11AppDpiY();
+ *
+ * DSRichText dsr( "&lt;html&gt;&lt;p&gt;Hallo World&lt;/p&gt;&lt;/html&gt;" );
+ * dsr.setWidth( 200 ); // in screenresolution coordinates
+ * dsr.setHeight( 80 ); // in screenresolution coordinates
+ * painter.translate( 10 * scalex, 10 * scaley ); // draw at 10, 10 instead of 0, 0
+ * dsr.scale( scalex, scaley );
+ * dsr.draw( &painter );
+ * </pre>
+ *
+ *@author Dominik Seichter
+ */
+class DSRichText {
+ public:
+ /** construct a DSRichText object. @p t is formated text as produces by QTextEdit.
+ */
+ DSRichText( const QString & t );
+ ~DSRichText();
+
+ void setX( int x );
+ void setY( int y );
+
+ /** draw the formated text on the QPainter* @p p
+ */
+ void draw( QPainter* p );
+ /** set the width of the clipping rectangle
+ */
+ void setWidth( int width );
+ /** set the height of the clipping rectangle
+ */
+ void setHeight( int height );
+ /** scale everything. This is necessary to print on devices
+ * with another resolution than the screen. QPainter::scale() won't work.
+ */
+ void setScale( double x, double y ) {
+ sx = x; sy = y;
+ };
+
+ private:
+ /** parse a single pare of <p></p> elements
+ */
+ bool parseParagraph();
+ /** remove <p> and </p> from the QString @p t and return it.
+ * This function is also responsible for getting the
+ * correct alignment of the paragraph.
+ */
+ QString parseParagraphTag( const QString & t, int* alignment );
+ /** parse the align attribute of a <p> tag and return the corresponding Qt alignment value.
+ */
+ int parseAlignment( const QString & align );
+ /** parse the css style attribute of a <span> tag and return a matching QFont for these
+ * style. The font color is saved in the QColor* @p color.
+ */
+ QFont parseStyle( const QString & s, QColor* color );
+ QString parse( const QString & t, const QString & find, const QString & end, int start );
+ void parseWords( const QString & t, formated_word* w, WordList* words );
+ void initFormat( formated_word* f, int alignment );
+ void initLine( QValueList<formated_line>* l );
+ void updateSpacing( QValueList<formated_line>* l, QFontMetrics* fm );
+ /** draw the line @p line justified as blockquote
+ */
+ void drawJustified( formated_line* line );
+ /** calculate the y-deviation needed, because of different font sizes in this line
+ */
+ inline int yDeviation( const formated_line* line );
+ /** replace HTML escape sequences such as &lt; to their real character meaning (i.e. < )
+ */
+ QString replaceEscapeSequences( const QString & t );
+
+ /** fill the line structures with data
+ */
+ void fillLines();
+
+ int pos; // current position in text
+ int start; // start of a tag
+ int end; // end of a tag
+ int x; // x position
+ int y; // y position
+ int w; // width of the text element
+ int h; // height of the text element
+ int xpos; // x position at the beginning
+ int ypos; // y position at the beginning
+
+ double sx;
+ double sy;
+
+ QString text;
+ QFont m_base;
+ QColor m_color;
+ QPainter* painter;
+
+ QValueList<LineList> line_p;
+ QValueList<WordList> word_p;
+};
+
+#endif // QT_TEXT_BUG
+#endif
diff --git a/kbarcode/dstextedit.cpp b/kbarcode/dstextedit.cpp
new file mode 100644
index 0000000..e059e96
--- /dev/null
+++ b/kbarcode/dstextedit.cpp
@@ -0,0 +1,147 @@
+/***************************************************************************
+ dstextedit.cpp - description
+ -------------------
+ begin : Sam Jun 04 2005
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "dstextedit.h"
+#include "dstextedit.moc"
+#include <qregexp.h>
+
+DSTextEdit::DSTextEdit( QWidget* parent, const char* name )
+ : TextEditBase( parent, name )
+{
+ connect( this, SIGNAL( textChanged() ), this, SLOT( fixParagraphs() ) );
+}
+
+void DSTextEdit::fixParagraphs()
+{
+ struct {
+ QFont font;
+ QColor color;
+ int alignment;
+ } tFormattings;
+
+ QString t;
+ int pos = 0;
+ int count = 0;
+ int i;
+ int para, index; // needed to save the cursor position
+ int paraFrom, indexFrom, paraTo, indexTo; // needed to save the selection
+ QValueList<int> chars;
+ QRegExp reg("<p[^>]*>");
+
+ for( i = 0; i < paragraphs(); i++ )
+ chars.append( paragraphLength( i ) );
+
+ // disconnect us first as we change the text here
+ disconnect( this, SIGNAL( textChanged() ), this, SLOT( fixParagraphs() ) );
+
+ getCursorPosition( &para, &index );
+ getSelection( &paraFrom, &indexFrom, &paraTo, &indexTo );
+
+ if( !para && !index )
+ setCursorPosition( 0, index+1 );
+
+ t = this->text();
+ tFormattings.font = this->currentFont();
+ tFormattings.color = this->color();
+ tFormattings.alignment = this->alignment();
+
+ while( pos != -1 )
+ {
+ pos = reg.search( t, pos );
+ if( pos != -1 )
+ {
+ if( count && count == para )
+ {
+ for( i = 0; i < count; i++ )
+ index += chars[i];
+ ++index; // count the new <br> that is inserted later
+ }
+
+ ++count;
+
+ if( count > 1 ) //&& pos != -1 )
+ t = t.remove( pos, reg.matchedLength() );
+ else
+ pos += reg.matchedLength();
+ }
+ }
+
+ pos = t.length();
+ count = 0;
+
+ while( pos != -1 )
+ {
+ pos = t.findRev( "</p>", pos );
+ if( pos != -1 )
+ {
+ ++count;
+
+ if( count > 1 ) //&& pos != -1 )
+ t = t.replace( pos, 4, "<br />" );
+ else
+ pos -= 4;
+ }
+ }
+
+ this->setText( t );
+ this->setCursorPosition( 0, index );
+ this->setCurrentFont( tFormattings.font );
+ this->setColor( tFormattings.color );
+ this->setAlignment( tFormattings.alignment );
+ this->setSelection( paraFrom, indexFrom, paraTo, indexTo );
+
+
+ connect( this, SIGNAL( textChanged() ), this, SLOT( fixParagraphs() ) );
+}
+
+/*
+void DSTextEdit::moveCursor( CursorAction action, bool select )
+{
+ do {
+ TextEditBase::moveCursor( action, select );
+ } while( cursorIsInToken() );
+}
+
+bool DSTextEdit::cursorIsInToken()
+{
+ int para, index;
+ int firstopen, firstclose;
+ QString data;
+
+ getCursorPosition( &para, &index );
+
+ data = text( para );
+
+ qDebug("data=" + data );
+ --index;
+ firstopen = data.findRev( "[", index );
+ firstclose = data.findRev( "]", index );
+ ++index;
+
+ if( firstopen != -1 && firstopen > firstclose )
+ {
+ firstopen = data.find( "[", index );
+ firstclose = data.find( "]", index );
+ if( ( firstclose != -1 && firstopen != -1 && firstclose < firstopen ) ||
+ ( firstclose != -1 && firstopen == -1 ) )
+ return true;
+ }
+
+ return false;
+}
+
+*/
diff --git a/kbarcode/dstextedit.h b/kbarcode/dstextedit.h
new file mode 100644
index 0000000..15192a3
--- /dev/null
+++ b/kbarcode/dstextedit.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+ dstextedit.h - description
+ -------------------
+ begin : Sam Jun 04 2005
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef _DS_TEXT_EDIT_H_
+#define _DS_TEXT_EDIT_H_
+
+#include <qnamespace.h>
+
+#if QT_VERSION >= 0x030100
+ #include <ktextedit.h>
+#else
+ #include <qtextedit.h>
+#endif
+
+// Otherwise moc will complain
+#if QT_VERSION >= 0x030100
+ #define TextEditBase KTextEdit
+#else
+ #define TextEditBase QTextEdit
+#endif
+
+class DSTextEdit : public TextEditBase {
+ Q_OBJECT
+
+ public:
+ DSTextEdit( QWidget* parent, const char* name = 0 );
+
+ //virtual void moveCursor( CursorAction action, bool select );
+ private slots:
+ void fixParagraphs();
+
+ private:
+ /**
+ * returns true if the cursor is currently inside
+ * of a token of the form [value].
+ */
+ //bool cursorIsInToken();
+};
+
+#endif // _DS_TEXT_EDIT_H_
+
diff --git a/kbarcode/editoriface.h b/kbarcode/editoriface.h
new file mode 100644
index 0000000..a568879
--- /dev/null
+++ b/kbarcode/editoriface.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+ editoriface.h - description
+ -------------------
+ begin : Sat Dec 27 09:53:28 CET 2003
+ copyright : (C) 2003 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef EDITORIFACE_H
+#define EDITORIFACE_H
+
+#include <dcopobject.h>
+
+class EditorIface : virtual public DCOPObject
+{
+ K_DCOP
+
+ public:
+ k_dcop:
+
+ virtual const QString fileName() const = 0;
+ virtual bool isChanged() = 0;
+ virtual void print() = 0;
+ virtual bool newLabel() = 0;
+
+ virtual void insertBarcode() = 0;
+ virtual void insertPicture() = 0;
+ virtual void insertText() = 0;
+ virtual void insertRect() = 0;
+ virtual void insertCircle() = 0;
+ virtual void insertLine() = 0;
+
+ virtual void changeDes() = 0;
+ virtual void changeSize() = 0;
+
+ virtual void preview() = 0;
+ virtual void toggleGrid() = 0;
+
+ virtual void closeLabel() = 0;
+
+ virtual bool openUrl( const QString & url ) = 0;
+ virtual bool save( QString url ) = 0;
+
+};
+
+#endif /* EDITORIFACE_H */
diff --git a/kbarcode/encodingcombo.cpp b/kbarcode/encodingcombo.cpp
new file mode 100644
index 0000000..52f7a21
--- /dev/null
+++ b/kbarcode/encodingcombo.cpp
@@ -0,0 +1,47 @@
+/***************************************************************************
+ encodingcombo.h - description
+ -------------------
+ begin : Fri Dec 23 2005
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "encodingcombo.h"
+
+#include <kcharsets.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <qtextcodec.h>
+
+EncodingCombo::EncodingCombo( QWidget* parent )
+ : KComboBox( parent )
+{
+ QString sEncoding = QString( KGlobal::locale()->encoding() );
+ QStringList encodings (KGlobal::charsets()->availableEncodingNames());
+
+ this->insertStringList( encodings );
+
+ for (int i=0; i < encodings.count(); i++)
+ {
+ bool found = false;
+ QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(encodings[i], found);
+ if (found && ( (codecForEnc->name() == sEncoding) || (encodings[i] == sEncoding) ) )
+ {
+ this->setCurrentItem(i);
+ break;
+ }
+ }
+}
+
+EncodingCombo::~EncodingCombo()
+{
+}
diff --git a/kbarcode/encodingcombo.h b/kbarcode/encodingcombo.h
new file mode 100644
index 0000000..f6e0762
--- /dev/null
+++ b/kbarcode/encodingcombo.h
@@ -0,0 +1,35 @@
+/***************************************************************************
+ encodingcombo.h - description
+ -------------------
+ begin : Fri Dec 23 2005
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef _ENCODING_COMBO_H_
+#define _ENCODING_COMBO_H_
+
+#include <kcombobox.h>
+
+class EncodingCombo : public KComboBox {
+ Q_OBJECT
+ public:
+ EncodingCombo( QWidget* parent );
+ ~EncodingCombo();
+
+
+
+
+};
+
+#endif // _ENCODING_COMBO_H_
+
diff --git a/kbarcode/exampledata.sql b/kbarcode/exampledata.sql
new file mode 100644
index 0000000..2afcfe8
--- /dev/null
+++ b/kbarcode/exampledata.sql
@@ -0,0 +1,10 @@
+INSERT INTO barcode_basic VALUES (1,'art1001','Test1','1000001','ean','field0','field1','field2','field3','field4','field5','field6','field7','field8','field9')
+INSERT INTO barcode_basic VALUES (2,'art1002','Test1','1000002','ean','field0','field1','field2','field3','field4','field5','field6','field7','field8','field9')
+INSERT INTO barcode_basic VALUES (3,'art1003','Test1','1000003','ean','field0','field1','field2','field3','field4','field5','field6','field7','field8','field9')
+INSERT INTO barcode_basic VALUES (4,'art1004','Test1','1000004','ean','field0','field1','field2','field3','field4','field5','field6','field7','field8','field9')
+INSERT INTO barcode_basic VALUES (5,'art1005','Test1','1000005','ean','field0','field1','field2','field3','field4','field5','field6','field7','field8','field9')
+INSERT INTO barcode_basic VALUES (6,'art1006','Test1','1000006','ean','field0','field1','field2','field3','field4','field5','field6','field7','field8','field9')
+INSERT INTO customer VALUES (1,'EURO222','Europe')
+INSERT INTO customer VALUES (2,'613203','USA')
+INSERT INTO customer_text VALUES (1,'EURO222','code39','art1001','custom1001','2323232','EURO222-Line0','EURO222-Line1','EURO222-Line2','EURO222-Line3','EURO222-Line4','EURO222-Line5','EURO222-Line6','EURO222-Line7','EURO222-Line8','EURO222-Line9')
+INSERT INTO customer_text VALUES (2,'613203','code39','art1003','custom1002','11111','test-Line0','test-Line1','test-Line2','test-Line3','test-Line4','test-Line5','test-Line6','test-Line7','test-Line8','test-Line9')
diff --git a/kbarcode/gnubarcode.cpp b/kbarcode/gnubarcode.cpp
new file mode 100644
index 0000000..6f69644
--- /dev/null
+++ b/kbarcode/gnubarcode.cpp
@@ -0,0 +1,348 @@
+/***************************************************************************
+ gnubarcode.cpp - description
+ -------------------
+ begin :
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "gnubarcode.h"
+
+#ifdef _ENABLE_NATIVE_GNU_BARCODE
+
+#include <barcode.h>
+#include "barkode.h"
+#include <string.h>
+#include <ctype.h>
+
+#include <qfont.h>
+#include <qpainter.h>
+#include <qpaintdevicemetrics.h>
+
+#include <klocale.h>
+
+#define FONT_SPACE (2*m_scaley)
+#define SHRINK_AMOUNT 0.15
+#define MUL_FACTOR 10
+
+GnuBarcode::GnuBarcode()
+ : BarkodeEngine()
+{
+ m_item = NULL;
+ m_size = QSize( 0, 0 );
+
+ m_scalex = 1.0;
+ m_scaley = 1.0;
+
+ m_font_size = 10;
+}
+
+GnuBarcode::~GnuBarcode()
+{
+ if( m_item )
+ Barcode_Delete( m_item );
+}
+
+void GnuBarcode::update( const QPaintDevice* device )
+{
+ QString val = barkode->parsedValue();
+ m_valid = false;
+
+ if( m_item )
+ {
+ qDebug("Deleting");
+ Barcode_Delete( m_item );
+ m_item = NULL;
+ }
+
+ if( val.isEmpty() )
+ return;
+
+ char* value = new char[val.length()+1];
+ strncpy( value, val.latin1(), val.length()+1 );
+ value[val.length()] = '\0';
+
+ m_item = Barcode_Create( value );
+ if( !m_item )
+ {
+ Barcode_Delete( m_item );
+ m_item = NULL;
+ delete [] value;
+ return;
+ }
+
+ if( Barcode_Encode( m_item, Barkode::internalType( barkode->type() ) ) == -1 )
+ {
+ Barcode_Delete( m_item );
+ m_item = NULL;
+
+ delete [] value;
+ return;
+ }
+
+ delete [] value;
+
+ QPaintDeviceMetrics metrics( device );
+ m_scalex = (double)metrics.logicalDpiX() / (double)QPaintDevice::x11AppDpiX();
+ m_scaley = (double)metrics.logicalDpiY() / (double)QPaintDevice::x11AppDpiY();
+
+ // 72.0 is the postscript resolution generated by GNU barcode
+ m_scale_ps_x = (double)metrics.logicalDpiX() / 72.0;
+ m_scale_ps_y = (double)metrics.logicalDpiY() / 72.0;
+
+/* m_scalex *= m_scale_ps_x;
+ m_scaley *= m_scale_ps_y;*/
+
+ m_font_size = (int)(barkode->fontsize() * barkode->scaling() * m_scaley);
+ setupSize();
+ m_valid = true;
+}
+
+const QSize GnuBarcode::size() const
+{
+ if( m_size.isNull() )
+ return QSize( 100, 80 );
+ else
+ return m_size;
+}
+
+void GnuBarcode::drawBarcode( QPainter & painter, int x, int y )
+{
+ int dx = x + barkode->quietZone();
+ int dy = y + barkode->quietZone();
+
+ if( !m_item )
+ {
+ barkode->drawInvalid( painter, x, y );
+ return;
+ }
+
+ painter.save();
+ painter.scale( m_scalex, m_scaley );
+
+ // based on David J. Humphreys barcode-svg
+ // Draw the bars
+ drawBars( &painter, (int)(dx/m_scalex), (int)(dy/m_scaley) );
+
+ // Only scale for the bars, text should be scaled
+ // correctly by Qt on Qt >= 3.3.2
+ painter.restore();
+
+ // draw the text
+ if( barkode->textVisible() )
+ drawText( &painter, dx, dy );
+}
+
+void GnuBarcode::setupSize()
+{
+ m_bar_height = (int)(barkode->barHeight() * barkode->scaling() * barkode->cut());
+ m_barcode_height = m_bar_height;
+ if( barkode->textVisible() )
+ m_barcode_height += (int)(m_font_size/2 + FONT_SPACE*2);
+
+ unsigned int width = drawBars( 0 , 0, 0 );
+ unsigned int twidth = drawText( 0, 0, 0 );
+
+ //if(m_item->height == 0)
+ m_item->height = m_barcode_height + (2 * barkode->quietZone());
+
+ width = ( width > twidth ? width : twidth );
+ width += 2* barkode->quietZone();
+
+ //if(m_item->width == 0)
+ m_item->width = width;
+
+ m_size.setWidth( (int)(m_item->width * m_scalex) );
+ m_size.setHeight( (int)(m_item->height * m_scaley) );
+}
+
+int GnuBarcode::drawBars( QPainter* painter, int x, int y )
+{
+#if 0
+ int height = 0; // height of the bar to draw
+ int xpos = 0; // Where the current box is drawn
+ int current = 0;
+ unsigned int i = 0;
+
+ qDebug("Partial=%s\n", m_item->partial );
+ for( i = 0; i < strlen(m_item->partial); i++)
+ {
+ current = (int)m_item->partial[i] - ASCII_ZERO;
+ /* Guide bar */
+ if(current > 9)
+ {
+ height = m_barcode_height;
+ current = (int)m_item->partial[++i] - ASCII_ZERO;
+ i++; /* Skip the following 'a' */
+ }
+ else
+ height = m_bar_height;
+
+ current *= barkode->scaling();
+
+ if( current < 0 )
+ {
+ qDebug("current < 0: %i", current );
+ current = 0;
+ break;
+ }
+
+ if( i % 2)
+ {
+ painter.fillRect( x + xpos, y, current, height, barkode->foreground() );
+ }
+
+ xpos += current;
+ }
+#endif
+ int xpos;
+ int mode = '-'; // text below bars
+ char *ptr;
+ int i, j;
+ int x0, yr, y0;
+
+ xpos = m_item->partial[0]-'0';
+
+ for (ptr = m_item->partial+1, i=1; *ptr; ptr++, i++)
+ {
+ /* special cases: '+' and '-' */
+ if (*ptr == '+' || *ptr == '-')
+ {
+ mode = *ptr; /* don't count it */ i++; continue;
+ }
+ /* j is the width of this bar/space */
+ if (isdigit (*ptr))
+ j = *ptr-'0';
+ else
+ j = *ptr-'a'+1;
+
+ j = (int)( j * barkode->scaling() );
+ if (i%2)
+ {
+ x0 = xpos + j/2;
+ y0 = y;
+ yr = m_barcode_height;
+
+ if( barkode->textVisible() )
+ {
+ // leave space for text
+ if (mode == '-')
+ {
+ // text below bars
+ if( isdigit( *ptr ) )
+ yr = m_bar_height;
+ else
+ yr = m_barcode_height;
+ } else { /* '+' */
+ // text above bars
+ // TODO: this needs testing and a GUI
+ if( isdigit( *ptr ) )
+ yr = m_bar_height;
+ else
+ {
+ yr = m_barcode_height;
+ y0 += (m_barcode_height - m_bar_height);
+ }
+ }
+ }
+
+ if( painter )
+ {
+ painter->fillRect( x + x0, y0, j, yr, barkode->foreground() );
+ }
+ //qDebug("Bar = %i", j );
+ }
+ xpos += j;
+ }
+
+ return xpos;
+}
+
+int GnuBarcode::drawText( QPainter* painter, int x, int y )
+{
+#if 0
+ unsigned int infosz = strlen( m_item->textinfo );
+ unsigned int correction = 0; // This correction seems to be needed to align text properly
+ unsigned int j = 0;
+ unsigned int i = 0;
+ int prev_x = 0;
+ int xpos = 0;
+
+ double dub1, fsize;
+ char printer;
+ char *temp_info = new char[infosz+1];
+
+ painter.setFont( QFont( "Helvetica", 12 ) );
+ while(i < infosz)
+ {
+ for(j = 0; m_item->textinfo[i + j + 1] != ' ' &&
+ m_item->textinfo[i + j + 1] != '\0';j++); /* Empty loop, just increment j */
+ j ++;
+ strncpy(temp_info, (m_item->textinfo + i),j);
+ sscanf(temp_info, "%lf:%lf:%c", &dub1, &fsize, &printer);
+ i += j;
+
+ xpos = (int)dub1;
+ //if((xpos - prev_x) >= 10)
+ //correction += 2;
+
+ prev_x = xpos;
+ painter.drawText( x + ((xpos-correction) * m_scalex),
+ y + ((m_bar_height + (unsigned int)(barkode->fontsize()/ 2) + FONT_SPACE) * m_scaley),
+ QChar( printer ) );
+ }
+ delete [] temp_info;
+#endif
+
+ double f1, f2;
+ int y0;
+ char* ptr;
+ char c;
+
+ int mode = '-';
+ for (ptr = m_item->textinfo; ptr; ptr = strchr(ptr, ' '))
+ {
+ while (*ptr == ' ')
+ ptr++;
+ if (!*ptr)
+ break;
+ if (*ptr == '+' || *ptr == '-')
+ {
+ mode = *ptr; continue;
+ }
+
+ if (sscanf(ptr, "%lf:%lf:%c", &f1, &f2, &c) != 3)
+ {
+ fprintf(stderr, "barcode: impossible data: %s\n", ptr);
+ continue;
+ }
+
+ if( mode == '-' )
+ {
+ // text below bars
+ y0 = y + (int)(m_bar_height * m_scaley + m_font_size - FONT_SPACE);
+ }
+ else
+ y0 = (int)(y + FONT_SPACE);
+
+ if( painter )
+ {
+ painter->setFont( QFont( "Helvetica", m_font_size ) );
+ painter->drawText( x + (int)(f1 * m_scalex * barkode->scaling() ), y0, QChar( c ) );
+ }
+ }
+
+ return x;
+}
+
+#endif // _ENABLE_NATIVE_GNU_BARCODE
+
diff --git a/kbarcode/gnubarcode.h b/kbarcode/gnubarcode.h
new file mode 100644
index 0000000..afdec8e
--- /dev/null
+++ b/kbarcode/gnubarcode.h
@@ -0,0 +1,75 @@
+/***************************************************************************
+ gnubarcode.h - description
+ -------------------
+ begin :
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef GNU_BARCODE_H
+#define GNU_BARCODE_H
+
+// #define _ENABLE_NATIVE_GNU_BARCODE
+
+#ifdef _ENABLE_NATIVE_GNU_BARCODE
+
+#include "barkodeengine.h"
+
+struct Barcode_Item;
+
+class GnuBarcode : public BarkodeEngine {
+ public:
+ GnuBarcode();
+ ~GnuBarcode();
+
+ inline EEngine engine() const;
+
+ const QSize size() const;
+ void update( const QPaintDevice* device );
+ void drawBarcode( QPainter & painter, int x, int y );
+
+ private:
+ /** Draws the barcodes bars if @p painter is not 0.
+ * Otherwise only the required width is returned.
+ */
+ int drawBars( QPainter* painter, int x, int y );
+
+ /** Draws the text if @p painter is not 0.
+ * Otherwise only the required width is returned.
+ */
+ int drawText( QPainter* painter, int x, int y );
+
+ /** Fill m_size with the needed space
+ */
+ void setupSize();
+
+ private:
+ int m_bar_height;
+ int m_barcode_height;
+ int m_font_size;
+
+ double m_scalex;
+ double m_scaley;
+ double m_scale_ps_x;
+ double m_scale_ps_y;
+
+ Barcode_Item* m_item;
+ QSize m_size;
+};
+
+EEngine GnuBarcode::engine() const
+{
+ return GNU_BARCODE;
+}
+
+#endif // _ENABLE_NATIVE_GNU_BARCODE
+#endif /* GNU_BARCODE_H */
diff --git a/kbarcode/gnubarkodeengine.cpp b/kbarcode/gnubarkodeengine.cpp
new file mode 100644
index 0000000..486c453
--- /dev/null
+++ b/kbarcode/gnubarkodeengine.cpp
@@ -0,0 +1,37 @@
+/***************************************************************************
+ gnubarkodeengine.cpp - description
+ -------------------
+ begin : Fri Nov 05 2004
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#include "gnubarkodeengine.h"
+#include <barcode.h>
+
+GnuBarkodeEngine::GnuBarkodeEngine()
+ : BarkodeEngine( "libbarcode.so" )
+{
+}
+
+void GnuBarkodeEngine::init()
+{
+ if( !m_loaded )
+ {
+ (void*)Barcode_Create = dlsym(m_handle, "Barcode_Create");
+ (void*)Barcode_Delete = dlsym(m_handle, "Barcode_Delete");
+ (void*)Barcode_Encode = dlsym(m_handle, "Barcode_Encode");
+
+ m_loaded = true;
+ }
+}
+
+GnuBarkodeEngine gnuBarkodeEngine;
diff --git a/kbarcode/gnubarkodeengine.h b/kbarcode/gnubarkodeengine.h
new file mode 100644
index 0000000..323553c
--- /dev/null
+++ b/kbarcode/gnubarkodeengine.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ gnubarkodeengine.h - description
+ -------------------
+ begin : Fri Nov 05 2004
+ copyright : (C) 2002 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef GNUBARKODEENGINE_H
+#define GNUBARKODEENGINE_H
+
+#include <barkodeengine.h>
+
+struct Barcode_Item;
+
+/**
+ * Loads GNU Barcode lib dynamically when needed,
+ * so that KBarcode does not have to link against
+ * it and works even without lib gnu barcode.
+ * @author Dominik Seichter
+ */
+class GnuBarkodeEngine : public BarkodeEngine
+{
+ public:
+ GnuBarkodeEngine();
+
+ struct Barcode_Item* (*Barcode_Create)(char* text);
+ int (*Barcode_Delete)(struct Barcode_Item* bc);
+ int (*Barcode_Encode)(struct Barcode_Item *bc, int flags);
+
+
+ protected:
+ void init();
+};
+
+extern GnuBarkodeEngine gnuBarkodeEngine;
+#endif
diff --git a/kbarcode/hi16-action-barcode.png b/kbarcode/hi16-action-barcode.png
new file mode 100644
index 0000000..c238610
--- /dev/null
+++ b/kbarcode/hi16-action-barcode.png
Binary files differ
diff --git a/kbarcode/hi16-action-kbarcodeellipse.png b/kbarcode/hi16-action-kbarcodeellipse.png
new file mode 100644
index 0000000..ba683c3
--- /dev/null
+++ b/kbarcode/hi16-action-kbarcodeellipse.png
Binary files differ
diff --git a/kbarcode/hi16-action-kbarcodegrid.png b/kbarcode/hi16-action-kbarcodegrid.png
new file mode 100644
index 0000000..1bcbd32
--- /dev/null
+++ b/kbarcode/hi16-action-kbarcodegrid.png
Binary files differ
diff --git a/kbarcode/hi16-action-kbarcodelinetool.png b/kbarcode/hi16-action-kbarcodelinetool.png
new file mode 100644
index 0000000..80cd7e4
--- /dev/null
+++ b/kbarcode/hi16-action-kbarcodelinetool.png
Binary files differ
diff --git a/kbarcode/hi16-app-kbarcode.png b/kbarcode/hi16-app-kbarcode.png
new file mode 100644
index 0000000..08b115d
--- /dev/null
+++ b/kbarcode/hi16-app-kbarcode.png
Binary files differ
diff --git a/kbarcode/hi22-action-barcode.png b/kbarcode/hi22-action-barcode.png
new file mode 100644
index 0000000..68db3b4
--- /dev/null
+++ b/kbarcode/hi22-action-barcode.png
Binary files differ
diff --git a/kbarcode/hi32-action-barcode.png b/kbarcode/hi32-action-barcode.png
new file mode 100644
index 0000000..5b4b3f3
--- /dev/null
+++ b/kbarcode/hi32-action-barcode.png
Binary files differ
diff --git a/kbarcode/hi32-action-kbarcoderect.png b/kbarcode/hi32-action-kbarcoderect.png
new file mode 100644
index 0000000..9c2768f
--- /dev/null
+++ b/kbarcode/hi32-action-kbarcoderect.png
Binary files differ
diff --git a/kbarcode/hi32-app-kbarcode.png b/kbarcode/hi32-app-kbarcode.png
new file mode 100644
index 0000000..54facc9
--- /dev/null
+++ b/kbarcode/hi32-app-kbarcode.png
Binary files differ
diff --git a/kbarcode/hi64-app-kbarcode.png b/kbarcode/hi64-app-kbarcode.png
new file mode 100644
index 0000000..2f15c83
--- /dev/null
+++ b/kbarcode/hi64-app-kbarcode.png
Binary files differ
diff --git a/kbarcode/imageitem.cpp b/kbarcode/imageitem.cpp
new file mode 100644
index 0000000..139504f
--- /dev/null
+++ b/kbarcode/imageitem.cpp
@@ -0,0 +1,307 @@
+/***************************************************************************
+ imageitem.h - description
+ -------------------
+ begin : Do Sep 9 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+
+#include "imageitem.h"
+#include "tokenprovider.h"
+
+#include <qbuffer.h>
+#include <qdom.h>
+#include <qimage.h>
+#include <qpaintdevicemetrics.h>
+#include <qpainter.h>
+
+#include <klocale.h>
+#include <kmdcodec.h>
+
+ImageItem::ImageItem()
+ : DocumentItem()
+{
+ init();
+}
+
+ImageItem::~ImageItem()
+{
+}
+
+void ImageItem::init()
+{
+ m_rotation = 0.0;
+ m_mirror_h = false;
+ m_mirror_v = false;
+ m_scaling = eImage_Original;
+ setBorder( false );
+
+ setRect( QRect( 0, 0, 20, 20 ) );
+}
+
+void ImageItem::draw(QPainter* painter)
+{
+ createImage();
+
+ painter->save();
+ painter->drawPixmap( rect().x(), rect().y(), m_tmp );
+ painter->restore();
+ DocumentItem::drawBorder(painter);
+}
+
+void ImageItem::drawZpl( QTextStream* stream )
+{
+ createImage();
+
+ QBuffer buffer;
+ if( buffer.open( IO_WriteOnly ) )
+ {
+ // TODO: bmp????
+ QImageIO io( &buffer, "PNG" );
+ QImage image = m_tmp.convertToImage();
+ // create a black and white image
+ io.setImage( image.convertDepth( 1 ) );
+ io.write();
+ buffer.close();
+
+ QByteArray data = buffer.buffer();
+ *stream << ZPLUtils::fieldOrigin( rect().x(), rect().y() );
+ *stream << "~DYD,p,P," << QString::number( data.size() ) + ",0,";
+ for( unsigned int i=0;i<data.size();i++)
+ *stream << data[i];
+ }
+}
+
+void ImageItem::drawIpl( QTextStream*, IPLUtils* )
+{
+ qDebug("ImageItem is not implemented for IPL!");
+}
+
+void ImageItem::drawEPcl( QTextStream* stream )
+{
+ createImage();
+
+ // you can access m_tmp (which is a QPixmap now)
+ // m_tmp is an image which has all transformations
+ // (i.e. rotation, scaling, flipping) already apllied
+
+ QImage si = m_tmp.convertToImage();
+ int width = si.width();
+ int height = si.height();
+ int c;
+ char out;
+
+ for( int buf=0; buf < 3; buf++ ){
+ *stream << QString("GS %1 32 %1 %1 %1 %1 ")
+ .arg(buf).arg(rect().x()).arg(rect().y()).arg(width).arg(height);
+
+ for( int i=width-1; i >= 0; i-- ){
+ for( int j=0; j < height; j++ ){
+ if( buf == 0 )
+ c = qBlue(si.pixel(i,j)); // Yellow
+ else if( buf == 1 )
+ c = qGreen(si.pixel(i,j)); // Magenta
+ else if( buf == 2 )
+ c = qRed(si.pixel(i,j)); // Cyan
+
+ // printer has 5-bits per color - drop 3
+ // we also need to subtract from 255 to convert from RGB to CMY
+ out = (0xff - c) >> 3;
+ *stream << out;
+ }
+ }
+
+ *stream << "\r\n";
+ }
+}
+
+void ImageItem::loadXML(QDomElement* element)
+{
+ QByteArray out;
+ if( !element->text().isEmpty() )
+ {
+ KCodecs::base64Decode( element->text().utf8(), out );
+ m_pixmap.loadFromData( out, "PNG" );
+ }
+
+ m_expression = element->attribute( "expression", QString::null );
+ m_scaling = (EImageScaling)element->attribute( "scaling", "0" ).toInt();
+ m_mirror_h = (bool)element->attribute("mirror_horizontal", "0" ).toInt();
+ m_mirror_v = (bool)element->attribute("mirror_vertical", "0" ).toInt();
+ m_rotation = element->attribute("rotation", "0.0").toDouble();
+ DocumentItem::loadXML(element);
+
+ updateImage();
+}
+
+void ImageItem::saveXML(QDomElement* element)
+{
+ QBuffer buf;
+ if( !m_pixmap.isNull() )
+ {
+ if(!buf.open( IO_WriteOnly ))
+ return;
+
+ m_pixmap.save( &buf, "PNG" );
+ buf.close();
+
+ element->appendChild( element->ownerDocument().createCDATASection( KCodecs::base64Encode( buf.buffer(), true ) ) );
+ }
+
+ element->setAttribute( "expression", m_expression );
+ element->setAttribute( "scaling", (int)m_scaling );
+ element->setAttribute( "mirror_horizontal", m_mirror_h );
+ element->setAttribute( "mirror_vertical", m_mirror_v );
+ element->setAttribute( "rotation", m_rotation );
+
+ DocumentItem::saveXML(element);
+}
+
+void ImageItem::setExpression( const QString & ex )
+{
+ m_expression = ex;
+ updateImage();
+}
+
+void ImageItem::setPixmap( const QPixmap & pix )
+{
+ m_pixmap = pix;
+ updateImage();
+}
+
+const QPixmap & ImageItem::pixmap()
+{
+ return m_pixmap;
+}
+
+void ImageItem::setScaling( EImageScaling scaling )
+{
+ m_scaling = scaling;
+ updateImage();
+}
+
+EImageScaling ImageItem::scaling() const
+{
+ return m_scaling;
+}
+
+void ImageItem::updateImage()
+{
+ m_tmp.resize( QSize(0,0) );
+}
+
+void ImageItem::createImage()
+{
+ if( m_tmp.isNull() )
+ {
+ QImage img;
+
+ if( m_pixmap.isNull() )
+ img.load( tokenProvider() ? tokenProvider()->parse( m_expression ) : m_expression );
+ else
+ img = m_pixmap.convertToImage();
+
+ if( !img.isNull() )
+ {
+ if( m_rotation != 0.0 )
+ {
+ QWMatrix matrix;
+ matrix.rotate( m_rotation );
+ img = img.xForm( matrix );
+ }
+
+ // scale with high quality on the printer
+ // but use faster scaling for onscreen operations
+ if( m_scaling != eImage_Original )
+ {
+ if( DocumentItem::paintDevice()->isExtDev() )
+ img = img.smoothScale( rect().width(), rect().height(),
+ (m_scaling == eImage_Scaled ? QImage::ScaleMin : QImage::ScaleFree) );
+ else
+ img = img.scale( rect().width(), rect().height(),
+ (m_scaling == eImage_Scaled ? QImage::ScaleMin : QImage::ScaleFree) );
+ }
+ else
+ {
+ // we have to scale because of the bigger printer resolution
+ if( DocumentItem::paintDevice()->isExtDev() )
+ {
+ QPaintDeviceMetrics metrics( DocumentItem::paintDevice() );
+
+ img = img.smoothScale( (int)(img.width() * ((double)metrics.logicalDpiX()/QPaintDevice::x11AppDpiX())),
+ (int)(img.height() * ((double)metrics.logicalDpiY()/QPaintDevice::x11AppDpiY())),
+ QImage::ScaleMin );
+ }
+ }
+
+ if( m_mirror_h || m_mirror_v )
+ img = img.mirror( m_mirror_h, m_mirror_v );
+
+ m_tmp.convertFromImage( img );
+ }
+ else
+ {
+ // The expression does not return a valid image path
+ // or the user did not specify a image to load
+
+ // make sure that we do not get a 0 0 0 0 rectangle
+ QRect myrect( 0, 0, rect().width() ? rect().width() : 100 , rect().height() ? rect().height() : 80 );
+ m_tmp.resize( rect().width(), rect().height() );
+
+ QPainter painter( &m_tmp );
+ painter.fillRect( myrect, Qt::white );
+ painter.setPen( QPen( Qt::red, 2 ) );
+ painter.drawRect( myrect );
+ painter.drawLine( 0, 0, myrect.width(), myrect.height() );
+ painter.drawLine( 0, myrect.height(), myrect.width(), 0 );
+ painter.setPen( Qt::black );
+ painter.drawText( 0, painter.fontMetrics().lineSpacing(), i18n("Expression: ") + m_expression );
+ painter.end();
+ }
+ }
+}
+
+void ImageItem::setRotation( double rot )
+{
+ if( m_rotation <= 360.0 && m_rotation >= -360.0 )
+ {
+ m_rotation = rot;
+ updateImage();
+ }
+}
+
+double ImageItem::rotation() const
+{
+ return m_rotation;
+}
+
+void ImageItem::setMirrorHorizontal( bool b )
+{
+ m_mirror_h = b;
+ updateImage();
+}
+
+bool ImageItem::mirrorHorizontal() const
+{
+ return m_mirror_h;
+}
+
+void ImageItem::setMirrorVertical( bool b )
+{
+ m_mirror_v = b;
+ updateImage();
+}
+
+bool ImageItem::mirrorVertical() const
+{
+ return m_mirror_v;
+}
diff --git a/kbarcode/imageitem.h b/kbarcode/imageitem.h
new file mode 100644
index 0000000..d3f4194
--- /dev/null
+++ b/kbarcode/imageitem.h
@@ -0,0 +1,79 @@
+/***************************************************************************
+ imageitem.h - description
+ -------------------
+ begin : Do Sep 9 2004
+ copyright : (C) 2004 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+#ifndef IMAGEITEM_H
+#define IMAGEITEM_H
+
+#include "documentitem.h"
+
+#include <qpixmap.h>
+
+enum EImageScaling { eImage_Original = 0, eImage_Scaled, eImage_Zoomed };
+
+/**
+@author Dominik Seichter
+*/
+class ImageItem : public DocumentItem
+{
+ public:
+ ImageItem();
+ ~ImageItem();
+
+ void setExpression( const QString & ex );
+ inline QString expression() const { return m_expression; };
+
+ void setPixmap( const QPixmap & pix );
+ const QPixmap & pixmap();
+
+ void setScaling( EImageScaling scaling );
+ EImageScaling scaling() const;
+
+ void setRotation( double rot );
+ double rotation() const;
+
+ void setMirrorHorizontal( bool b );
+ bool mirrorHorizontal() const;
+
+ void setMirrorVertical( bool b );
+ bool mirrorVertical() const;
+
+ virtual int rtti() const { return eRtti_Image;}
+ virtual void draw(QPainter* painter);
+ virtual void drawZpl( QTextStream* stream );
+ virtual void drawIpl( QTextStream* stream, IPLUtils* utils );
+ virtual void drawEPcl( QTextStream* stream );
+ virtual void loadXML(QDomElement* element);
+ virtual void saveXML(QDomElement* element);
+
+ void updateImage();
+ void createImage();
+
+ private:
+ void init();
+
+ private:
+ QString m_expression;
+ QPixmap m_pixmap;
+ QPixmap m_tmp;
+
+ double m_rotation;
+ bool m_mirror_v;
+ bool m_mirror_h;
+
+ EImageScaling m_scaling;
+};
+
+#endif
diff --git a/kbarcode/kactionmap.cpp b/kbarcode/kactionmap.cpp
new file mode 100644
index 0000000..7ef48ce
--- /dev/null
+++ b/kbarcode/kactionmap.cpp
@@ -0,0 +1,188 @@
+/***************************************************************************
+ kactionmap.cpp - description
+ -------------------
+ begin : Fri Mai 19 2006
+ copyright : (C) 2006 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "kactionmap.h"
+
+#include <qimage.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qmenubar.h>
+#include <qmenudata.h>
+#include <qpixmap.h>
+#include <qpopupmenu.h>
+#include <qregexp.h>
+#include <qvbox.h>
+
+#include <kaction.h>
+#include <kapplication.h>
+#include <klistview.h>
+#if KDE_VERSION >= 0x030500
+#include <klistviewsearchline.h>
+#endif
+#include <klocale.h>
+
+class KListViewActionItem : public KListViewItem {
+public:
+ KListViewActionItem( KListView* parent, KAction* action )
+ : KListViewItem( parent ), m_action( action )
+ {
+ QPixmap pix;
+ QSize size = QIconSet::iconSize( QIconSet::Large );
+ QIconSet iconset = m_action->iconSet( KIcon::Panel, KIcon::SizeLarge );
+ QRegExp regtag( "<[^>]*>" );
+
+ pix = iconset.pixmap( QIconSet::Large, QIconSet::Normal ); // m_action->isEnabled() ? QIconSet::Normal : QIconSet::Disabled );
+ if( pix.isNull() )
+ {
+ pix.resize( size );
+ pix.fill( backgroundColor() );
+ }
+ else
+ {
+ if( pix.size() != size )
+ {
+ pix = pix.convertToImage().smoothScale( size );
+ }
+ }
+
+ setText( 0, m_action->plainText() );
+ setText( 1, m_action->shortcutText() );
+ // replace H