Skip to content

Commit

Permalink
Small update
Browse files Browse the repository at this point in the history
  • Loading branch information
KazukiPrzyborowski committed Nov 20, 2024
1 parent 67d4373 commit f1a0723
Show file tree
Hide file tree
Showing 27 changed files with 194 additions and 96 deletions.
1 change: 1 addition & 0 deletions upcean/encode/barcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from upcean.encode.ean5 import *
from upcean.encode.ean2 import *
import upcean.support
tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
Expand Down
20 changes: 5 additions & 15 deletions upcean/encode/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import upcean.encode.ean2
import upcean.encode.ean5
pilsupport = upcean.support.check_for_pil()
tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
qahirahsupport = upcean.support.check_for_qahirah()
Expand All @@ -53,18 +55,6 @@
skimagesupport = upcean.support.check_for_skimage()
imagelibsupport = upcean.support.imagelibsupport
defaultdraw = upcean.support.defaultdraw
if(pilsupport or pillowsupport):
import upcean.predraw.prepil
if(cairosupport):
import upcean.predraw.precairo
if(qahirahsupport):
import upcean.predraw.preqahirah
if(svgwritesupport):
import upcean.predraw.presvgwrite
if(wandsupport):
import upcean.predraw.prewand
if(magicksupport):
import upcean.predraw.premagick


def get_binary_barcode_size(upc, resize=1, shiftxy=(0, 0), barheight=(48, 54), barwidth=(1, 1)):
Expand Down Expand Up @@ -107,9 +97,9 @@ def encode_binary_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -146,7 +136,7 @@ def encode_binary_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
txtbari = 0
txtbarmax = len(upc['text']['text'])
LineFixTxtStart = 0
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineFixTxtStart = 4
while(txtbari < txtbarmax):
texthidden = False
Expand Down
9 changes: 6 additions & 3 deletions upcean/encode/codabar.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from StringIO import StringIO
from StringIO import StringIO as BytesIO

tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
Expand Down Expand Up @@ -115,9 +116,9 @@ def encode_codabar_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -264,8 +265,10 @@ def encode_codabar_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 20) * int(resize))
LineTxtStartNorm = 20
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
while (NumTxtZero < len(upc_matches)):
texthidden = False
if hidetext or (NumTxtZero == 0 and (hidesn is None or hidesn)) or (NumTxtZero == 11 and (hidecd is None or hidecd)):
Expand Down
9 changes: 6 additions & 3 deletions upcean/encode/code11.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from StringIO import StringIO
from StringIO import StringIO as BytesIO

tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
Expand Down Expand Up @@ -111,9 +112,9 @@ def encode_code11_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -223,8 +224,10 @@ def encode_code11_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 10) * int(resize))
LineTxtStartNorm = 10
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
while (NumTxtZero < len(upc_print)):
texthidden = False
if hidetext or (NumTxtZero == 0 and (hidesn is None or hidesn)) or (NumTxtZero == 11 and (hidecd is None or hidecd)):
Expand Down
13 changes: 8 additions & 5 deletions upcean/encode/code128.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from StringIO import StringIO
from StringIO import StringIO as BytesIO

tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
Expand Down Expand Up @@ -108,9 +109,9 @@ def encode_code128_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -552,8 +553,10 @@ def encode_code128_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 16) * int(resize))
LineTxtStartNorm = 16
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
if(barcode_is_rev):
upc_print.reverse()
while (NumTxtZero < len(upc_print)):
Expand Down Expand Up @@ -707,9 +710,9 @@ def encode_code128old_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down
9 changes: 6 additions & 3 deletions upcean/encode/code32.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from StringIO import StringIO
from StringIO import StringIO as BytesIO

tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
Expand Down Expand Up @@ -108,9 +109,9 @@ def encode_code32_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -264,8 +265,10 @@ def encode_code32_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 30) * int(resize))
LineTxtStartNorm = 30
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
while (NumTxtZero < len(upc_matches)):
texthidden = False
if hidetext or (NumTxtZero == 0 and (hidesn is None or hidesn)) or (NumTxtZero == 11 and (hidecd is None or hidecd)):
Expand Down
17 changes: 11 additions & 6 deletions upcean/encode/code39.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from StringIO import StringIO
from StringIO import StringIO as BytesIO

tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
Expand Down Expand Up @@ -108,9 +109,9 @@ def encode_code39_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -286,8 +287,10 @@ def encode_code39_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 15) * int(resize))
LineTxtStartNorm = 15
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
drawColorText(upc_img, 10 * int(resize * barwidth[1]), LineTxtStart * barwidth[0], vertical_text_fix + (
barheight[0] * int(resize)), "*", barcolor[1], "ocrb", imageoutlib)
upc_array['text']['location'].append(LineTxtStartNorm)
Expand Down Expand Up @@ -428,9 +431,9 @@ def encode_code39extended_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barhei
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -608,8 +611,10 @@ def encode_code39extended_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barhei
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 15) * int(resize))
LineTxtStartNorm = 15
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
drawColorText(upc_img, 10 * int(resize * barwidth[1]), LineTxtStart * barwidth[0], vertical_text_fix + (
barheight[0] * int(resize)), "*", barcolor[1], "ocrb", imageoutlib)
upc_array['text']['location'].append(LineTxtStartNorm)
Expand Down
17 changes: 11 additions & 6 deletions upcean/encode/code93.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from StringIO import StringIO
from StringIO import StringIO as BytesIO

tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
Expand Down Expand Up @@ -107,9 +108,9 @@ def encode_code93_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -294,8 +295,10 @@ def encode_code93_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 18) * int(resize))
LineTxtStartNorm = 18
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
while (NumTxtZero < len(upc_matches)):
texthidden = False
if hidetext or (NumTxtZero == 0 and (hidesn is None or hidesn)) or (NumTxtZero == 11 and (hidecd is None or hidecd)):
Expand Down Expand Up @@ -426,9 +429,9 @@ def encode_code93extended_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barhei
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -617,8 +620,10 @@ def encode_code93extended_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barhei
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 18) * int(resize))
LineTxtStartNorm = 18
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
while (NumTxtZero < len(upc_matches)):
texthidden = False
NumTxtZeroNext = NumTxtZero + 1
Expand Down
9 changes: 6 additions & 3 deletions upcean/encode/ean13.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import upcean.encode.ean2
import upcean.encode.ean5
tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
Expand Down Expand Up @@ -127,9 +128,9 @@ def encode_ean13_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -394,8 +395,10 @@ def encode_ean13_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 2) * int(resize))
LineTxtStartNorm = 2
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
upc_print = list(re.findall("(\\d{13})", upc)[0])+[">"]
while (NumTxtZero < len(upc_print)):
texthidden = False
Expand Down
9 changes: 6 additions & 3 deletions upcean/encode/ean2.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from StringIO import StringIO
from StringIO import StringIO as BytesIO

tkintersupport = upcean.support.check_for_tkinter()
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
Expand Down Expand Up @@ -104,9 +105,9 @@ def encode_ean2_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 5
vertical_text_fix = (9 * (int(resize) * barwidth[1]))
elif((wandsupport and imageoutlib == "wand") or (magicksupport and imageoutlib == "magick") or (pgmagicksupport and imageoutlib == "pgmagick")):
vertical_text_fix = (10 * (int(resize) * barwidth[1]))
elif(svgwritesupport and imageoutlib == "svgwrite"):
elif(svgwritesupport and not cairosvgsupport and imageoutlib == "svgwrite"):
vertical_text_fix = (8 * (int(resize) * barwidth[1]))
elif(imageoutlib == "tkinter"):
elif(tkintersupport and imageoutlib == "tkinter"):
vertical_text_fix = (5 * (int(resize) * barwidth[1]))
else:
vertical_text_fix = 0
Expand Down Expand Up @@ -247,8 +248,10 @@ def encode_ean2_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 5
NumTxtZero = 0
LineTxtStart = ((shiftxy[0] + 6) * int(resize))
LineTxtStartNorm = 6
if(imageoutlib == "tkinter"):
if(tkintersupport and imageoutlib == "tkinter"):
LineTxtStart += (4 * int(resize))
elif(cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
LineTxtStart += (1 * int(resize))
upc_print = LeftDigit
while (NumTxtZero < len(upc_print)):
texthidden = False
Expand Down
Loading

0 comments on commit f1a0723

Please sign in to comment.