HPGLWrap/HPGLWrap.py

62 lines
1.8 KiB
Python
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import os
import sys
def write_pen_values(values, char):
return "!v64" + char + "".join(["{:04d}".format(value) for value in values])
def pre_content(filename, power=50, speed=50, rate=2500):
jobName = os.path.basename(filename)[:80]
# Start
outString = "@PJL JOB NAME={}\r\n".format(jobName)
outString += "E@PJL ENTER LANGUAGE=PCL\r\n%-12345X"
# Reset
outString += "E"
# Unit
outString += "&u254D"
# Cursor
outString += "*p100X"
outString += "*p100Y"
# Set filename
outString += "!m{:d}N".format(len(jobName)) + jobName
# Set raster power+velocity. Only affects raster. Shows in display before start
outString += "!r{:d}I".format(speed * 10)
outString += "!r{:d}P".format(power * 10);
# Select first (and only) pen (commented out in original source)
# outString += "!v1D"
# outString += "!m2A" # might cause autofocus?
# Use same value for all 16 pens
# doesn't seem to affect vector settings
outString += write_pen_values([speed * 10] * 16, 'V') # Velocity, 1000=100%
outString += write_pen_values([power * 10] * 16, 'V') # Power, 1000=100%
outString += write_pen_values([rate] * 16, 'V') # PPI
outString += "%1B"
return outString
def post_content():
outString = "%1A" # Leave HPGL vector mode
outString += "E" # Reset
outString += "%-12345X@PJL EOJ \r\n" # End
return outString
def main(infile, outfile, power=50, speed=50, rate=100):
with open(infile, 'r') as f:
data = f.read()
with open(outfile, 'w') as f:
f.write(pre_content(outfile, int(power), int(speed), int(rate)))
f.write(data)
f.write(post_content())
if __name__ == '__main__':
print(sys.argv)
main(*sys.argv[1:])