stefan-langenmaier / brother-overlay

Portage overlay for Brother printer and scanner software
GNU General Public License v3.0
34 stars 41 forks source link

HL-3140CW print jobs are misaligned on A4 paper #48

Open Mickkie opened 6 years ago

Mickkie commented 6 years ago

HL-3140CW prints misaligned pages, with the top cropped by 13mm and the left side shifted to the left by 7mm, when selecting A4 page size. The reason seems to be that cups cannot alter the page size from 'Letter' to 'A4'.

I noticed each time I modify a printer using the cups http GUI, the corresponding ppd file default settings are messed up. In particular, DefaultImageableArea and DefaultPaperDimension are reset to Letter for some reason:

grep Default /etc/cups/ppd/HL-3140CW.ppd DefaultColorSpace: Gray DefaultPageSize: A4 DefaultPageRegion: A4 DefaultImageableArea: Letter <== DefaultPaperDimension: Letter <== DefaultResolution: 300dpi

Going back into ''Administration/Set Default Options' in cups and (re)selecting A4 restores the correct setttings:

grep Default /etc/cups/ppd/HL-3140CW.ppd DefaultColorSpace: Gray DefaultPageSize: A4 DefaultPageRegion: A4 DefaultImageableArea: A4 DefaultPaperDimension: A4 DefaultResolution: 300dpi

Nevertheless, these page settings are not respected by the driver, which always submits print jobs in 'Letter' page size.

The brother-overlay ebuild for HL-3140CW installs among others two files:

/opt/brother/Printers/hl3140cw/inf/brhl3140cwfunc

where [Default] settings are specified and

/opt/brother/Printers/hl3140cw/inf/brhl3140cwrc

where printer specific [hl3140cw] settings are defined. I changed the setting to "PageSize=A4" in the second file and now pages are printed in A4 as they always used to. This does not address the underlying problem of cups not being able to set a default page size in a way that is respected by the printer, so it will require further investigation.

All default page settings in /opt/brother/Printers/hl3140cw/cupswrapper/brother_hl3140cw_printer_en.ppd are set to Letter, but I can't explain why cups does not set the correct for the OS page size the first time a printer is modified, while it apparently does so the second time.

Is it a coincidence that the file brother_lpdwrapper_hl3140cw configures an "ImagingArea" while ppd uses an "ImageableArea" and this is the same entry that settings go wrong in the ppd file above?

Can you please take a look at the respective files installed by the ebuild in case you can spot what causes this problem?

PS. I am currently running on gentoo with profile 17.0:

net-print/cups-2.2.6 net-print/cups-filters-1.18.0 net-print/brother-hl3140cw-bin-1.1.4

-- Kind regards, Mick

automorphism88 commented 6 years ago

I had the same problem with the ebuild I wrote for the MFC7460DN and found that a combination of two things fixed it:

  1. The cupswrapper file ending in -rc needs to belong to lp:lp instead of root:root
  2. All hardcoded references to the /usr/local path need to be patched to refer to the correct path in /opt. This includes the precompiled binaries.

Look at this PR to see how I fixed the problem. I'm guessing something similar should work for your printer. I've got an issue open to discuss creating an eclass to share my code with other ebuilds, but in the meantime you should be able to just use my sed scripts to fix your executables (both the shell scripts and precompiled binaries). See the src_prepare function in the PR I linked.

N8Fear commented 6 years ago

On my 3150CDW the papersize setting from cups seems to be ignored. If I run brprintconf_hl3150cdw -pt A4 it is fixed, though. Maybe try it with your version of brprintconf?

automorphism88 commented 6 years ago

Yeah, that's exactly what was happening to me - I could set the paper size via manually editing the brMFC7460DNrc file (which is what happens when you run that brprintconf command), but setting it through cups was ignored. In the normal course of things when the driver is working properly, printing through cups is supposed to call that brprintconf binary, via a shell script, and the binary will edit that rc file. That binary is run as the lp user, not root, hence the possibility of permissions issues.

So your solution is basically doing manually what the cupswrapper driver is supposed to do automatically whenever you print something through cups (and it's not just the paper size, other options you specify through cups are supposed to be passed through this way (e.g. portrait vs landscape, toner save, etc.). However, with a little experimentation, I was able to figure out what was causing that to happen and fixed the issue for my printer, so that it now works perfectly and passes through the settings from cups the way it's supposed to.

Try running grep -r /usr/local /opt/brother/Printers and see if any of the files in there have hardcoded paths that need to be fixed. That will work on both binary and text files. Also check to make sure /opt/brother/Printers/YOUR_MODEL/inf/brYOUR_MODELrc is owned by lp:lp and not root.