pclparaphernalia icon indicating copy to clipboard operation
pclparaphernalia copied to clipboard

option to remove more stuff from overlay output

Open bkw777 opened this issue 4 years ago • 1 comments
trafficstars

Hi, I would be happy to pay for this option, and you can email me at gmail b.kenyon.w to discuss in more detail.

I have a few things I would like to have the overlay tool (or a seperate custom tool) to do if possible.

One is easy, just strip a few more pcl codes than it currently does. I have another pcl utility called mkpcl from Jim Asman that I've been using for years and it's output works perfectly for including pcl bitmap graphics within other print jobs without disturbing the rest of the print job, nor being disturbed by it. But it only makes b&w images and the author has passed away a few years ago, and it was not open source.

I got the overlay tool here to produce almost the same output, but I still have to post-process that some more to strip out some more pcl. I assume it should be relatively simple to have the overlay tool just do that itself since that's what it already does. Even better would be a custom tool that simply doesn't generate any page/job/printer control codes in the first place, rather than generating a full print job and then having to excise all of the pcl codes except the bitmap. In my case I don't even want the cursor push/pop in the output.

If you're up for it I have a bit more of a project I'd like to commision for a custom tool to essentially script all the manual steps I have to do now into a custom tool that just does the one combination of things I want, or make the gui actions available by commandline and I can make my own script to use them, to basically take in a bitmap and spit out an unadorned pcl version of it.

Thanks much

For reference to show exactly what I mean, this is the python I'm using to post-process. The input is the output of the overlay tool, raw option.

#!/usr/bin/python
# strip_pp_ovl [email protected] 2021
# 
# Usage:
# strip_pp_ovl <foo_logo.ovl >foo_logo.pcl

# Post-process the output from PCL Paraphernalia
#
# Strip out the job/page control PCL codes from the output of PclParaphernalia
# to leave a bare PCL graphic which can be inserted into other PCL print jobs.

# sed can almost but not quite do this

# This is fragile. If the output from PP changes at all, then this has to be
# adjusted as well.
# We are stripping out selected PCL codes by simple pattern match.
# There is some basic regex to allow for variable values in some codes,
# but we are not actually parsing PCL. PCL allows stacking several pcl codes
# on a single escape char in a way that isn't practical to parse except with a
# state-machine just like a vt/ansi terminal or an actual pcl interpreter.
#
# Also we are only looking for a few specific expected codes, not all possible codes.

# The goal is to create a pcl graphic like the output of mkpcl
# but with color.
#
#  < gimp & pclparaphernalia directions here to get from foo.png to foo.ovl >
#

import re
import sys

# Each of the find & replace patterns are only applied once.
# We do NOT want to scan the bulk of the binary bitmap
# data and possibly corrupt it.

# Two lists:
# sp[] = list of search patterns
# rp[] = list of replace patterns

# Start the empty lists
sp = []
rp = []

# Use pairs of associated sp.append() & rp.append(), to add items to the lists.
# Always append to both or neither.
# If you add a sp, add a rp, if you comment out a sp, comment out it's rp.

# These lists are filled in this overly verbose way for the sake of documenting
# each individual associated pair, and being able to easily add/remove items
# without breaking the lists.

###############################################################################

# Kind of messy cheating a little on this first pair.
# This search and this replace aren't actually related.
# It's just that aside from stripping a bunch of PCL sequences,
# we also need to insert one somewhere near the beginning.
# We happen to need to strip the printer reset (ESC E)
# and we happen to also need to insert a "rotate image" sequence somewhere near the beginning,
# and the ESC E happens to always be the first thing in the file,
# and so this is a handy way to insert the rotate image code.

# Strip "printer reset"
# Insert "rotate image"
# ^[E
sp.append("\x1BE")
#rp.append("\x1B*r0F")   # mkpcl had this, but we don't seem to need it
rp.append('')

# Strip "# DPI dot resolution"
# This is not the same as the ESC*t300R which is not stripped.
# ^[&u300D   ^[&u600D
sp.append("\x1B&u[0-9]+D")
rp.append('')

# Strip "Top Margin # lines"
# ^[&l0E
sp.append("\x1B&l[0-9]+E")
rp.append('')

# Strip "Left Margin column #"
# ^[&a0L
sp.append("\x1B&a[0-9]+L")
rp.append('')

# Strip
#   "Horiz position = # Dots"
#   "Vert position = # Dots"
#
# ESC*p0X + ESC*p0Y = ESC*p0x0Y
# ^[*p0x0Y
sp.append("\x1B\*p[0-9]+x[0-9]+Y")
rp.append('')

# FIXME
# This one comes after the bitmap data, and so it's theoretically possible for this sequence of bytes to occur within the binary blob of bitmap data.
# By rights we should do something to skip over the bitmap data, but we're not.
#
# Strip "End Graphics with reset"
# Insert "End Graphics"
#
# ^[*rC
#sp.append("\x1B\*rC")
#rp.append("\x1B*rB")     // mkpcl output this, but maybe we don't need to?

###############################################################################

data = sys.stdin.read()

for s,r in zip(sp,rp):
        p = re.compile(s)
        data = p.sub(r,data,count=1)

sys.stdout.write(data)
sys.stdout.flush()

bkw777 avatar May 19 '21 17:05 bkw777

Hi,

I'm currently very very busy on m daily job, so my time is really spare... I guess stripping some more PCL commands should be easy, but (as you might have read) I have just "saved" the source code and I'm not familiar with it. If you have same Java skills, I guess you can write a small utility yourself with my Java library pclbox (it this would be an alternative for you)...

See https://github.com/michaelknigge/pclbox

bye, Michael

michaelknigge avatar May 28 '21 19:05 michaelknigge