Skip to content

Commit

Permalink
Small update
Browse files Browse the repository at this point in the history
  • Loading branch information
KazukiPrzyborowski committed Nov 14, 2024
1 parent 64f66ec commit e7fdfd2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
7 changes: 7 additions & 0 deletions upcean/predraw/precairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ def get_save_filename(outfile):
def get_save_file(outfile):
return get_save_filename(outfile)

def new_image_surface(sizex, sizey, bgcolor):
upc_preimg = cairo.RecordingSurface(cairo.CONTENT_COLOR, (0.0, 0.0, float(sizex), float(sizey)))
upc_img = cairo.Context(upc_preimg)
upc_img.set_antialias(cairo.ANTIALIAS_NONE)
drawColorRectangle(upc_img, 0, 0, sizex, sizey, bgcolor)
return [upc_img, upc_preimg]

def save_to_file(inimage, outfile, outfileext, imgcomment="barcode"):
upc_img = inimage[0]
upc_preimg = inimage[1]
Expand Down
6 changes: 6 additions & 0 deletions upcean/predraw/prepil.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ def get_save_filename(outfile):
def get_save_file(outfile):
return get_save_filename(outfile)

def new_image_surface(sizex, sizey, bgcolor):
upc_preimg = Image.new("RGB", (sizex, sizey))
upc_img = ImageDraw.Draw(upc_preimg)
drawColorRectangle(upc_img, 0, 0, sizex, sizey, bgcolor)
return [upc_img, upc_preimg]

def save_to_file(inimage, outfile, outfileext, imgcomment="barcode"):
upc_img = inimage[0]
upc_preimg = inimage[1]
Expand Down
68 changes: 39 additions & 29 deletions upcean/predraw/preqahirah.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,66 +313,76 @@ def get_save_filename(outfile):
def get_save_file(outfile):
return get_save_filename(outfile)

def new_image_surface(sizex, sizey, bgcolor):
# Create a RecordingSurface
upc_preimg = qah.RecordingSurface(qah.Rect(0, 0, sizex, sizey))
# Create a drawing context
upc_img = qah.Context.create(upc_preimg)
# Disable antialiasing
upc_img.set_antialias(qah.ANTIALIAS_NONE)
# Draw the colored rectangle (assumes drawColorRectangle is defined)
drawColorRectangle(upc_img, 0, 0, sizex, sizey, bgcolor)
return [upc_img, upc_preimg]

def save_to_file(inimage, outfile, outfileext, imgcomment="barcode"):
upc_img = inimage[0]
upc_preimg = inimage[1]
x, y, width, height = upc_preimg.ink_extents()
uploadfile = None
if(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
if re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile)):
uploadfile = outfile
outfile = BytesIO()
if(outfileext == "SVG"):
# Create an ImageSurface with the exact dimensions of the recorded content
image_surface = cairo.SVGSurface(outfile, int(width), int(height))
image_context = cairo.Context(image_surface)
# Transfer the content from the RecordingSurface to the ImageSurface
if outfileext == "SVG":
# Create an SVGSurface with the exact dimensions of the recorded content
image_surface = qah.SVGSurface(outfile, int(width), int(height))
image_context = qah.Context.create(image_surface)
# Transfer the content from the RecordingSurface to the SVGSurface
image_context.set_source_surface(upc_preimg, -x, -y)
image_context.paint()
image_surface.flush()
image_surface.finish()
elif(outfileext == "PDF"):
# Create an ImageSurface with the exact dimensions of the recorded content
image_surface = cairo.PDFSurface(outfile, int(width), int(height))
image_context = cairo.Context(image_surface)
# Transfer the content from the RecordingSurface to the ImageSurface
elif outfileext == "PDF":
# Create a PDFSurface with the exact dimensions of the recorded content
image_surface = qah.PDFSurface(outfile, int(width), int(height))
image_context = qah.Context.create(image_surface)
# Transfer the content from the RecordingSurface to the PDFSurface
image_context.set_source_surface(upc_preimg, -x, -y)
image_context.paint()
image_surface.flush()
image_surface.finish()
elif(outfileext == "PS" or outfileext == "EPS"):
# Create an PDFSurface with the exact dimensions of the recorded content
image_surface = cairo.PSSurface(outfile, int(width), int(height))
image_context = cairo.Context(image_surface)
# Transfer the content from the RecordingSurface to the ImageSurface
elif outfileext == "PS" or outfileext == "EPS":
# Create a PSSurface with the exact dimensions of the recorded content
image_surface = qah.PSSurface(outfile, int(width), int(height))
image_context = qah.Context.create(image_surface)
# Set EPS format if needed
image_surface.set_eps(outfileext == "EPS")
# Transfer the content from the RecordingSurface to the PSSurface
image_context.set_source_surface(upc_preimg, -x, -y)
if(outfileext == "EPS"):
image_surface.set_eps(True)
else:
image_surface.set_eps(False)
image_context.paint()
image_surface.flush()
image_surface.finish()
elif(outfileext == "CAIRO" or outfileext == "CAIRO"):
# Create an ScriptSurface with the exact dimensions of the recorded content
image_surface = cairo.ScriptSurface(cairo.ScriptDevice(outfile), cairo.FORMAT_RGB24, int(width), int(height))
image_context = cairo.Context(image_surface)
# Transfer the content from the RecordingSurface to the ImageSurface
elif outfileext == "CAIRO":
# For a ScriptSurface equivalent in qahirah, saving as CAIRO
image_surface = qah.ScriptSurface(outfile, int(width), int(height))
image_context = qah.Context.create(image_surface)
# Transfer the content from the RecordingSurface to the ScriptSurface
image_context.set_source_surface(upc_preimg, -x, -y)
image_context.paint()
image_surface.flush()
image_surface.finish()
else:
# Create an ImageSurface with the exact dimensions of the recorded content
image_surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(width), int(height))
image_context = cairo.Context(image_surface)
# Default to ImageSurface and save as PNG
image_surface = qah.ImageSurface.create(format=qah.ImageSurface.FORMAT_RGB24, dimensions=(int(width), int(height)))
image_context = qah.Context.create(image_surface)
# Transfer the content from the RecordingSurface to the ImageSurface
image_context.set_source_surface(upc_preimg, -x, -y)
image_context.paint()
image_surface.flush()
# Save as PNG
image_surface.write_to_png(outfile)
image_surface.finish()
if(re.findall("^(ftp|ftps|sftp):\\/\\/", str(uploadfile))):
# Handle file upload if required
if re.findall("^(ftp|ftps|sftp):\\/\\/", str(uploadfile)):
outfile.seek(0, 0)
upload_file_to_internet_file(outfile, uploadfile)
outfile.close()
Expand Down

0 comments on commit e7fdfd2

Please sign in to comment.