rastertoepson never sends ESC { A for the Oki drivers: nickname test looks for "OKIDATA"

未关闭 适合新手
#1,844 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
86/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c, python

调研方向

从 filter/rastertoepson.c 中的 StartPage() 以及 ppdc/sample.drv 中的 Oki 昵称开始。使用本地的 rastertoepson 运行提供的 repro.py,确认 Oki 输出不包含 ESC { A;完成意味着 Oki 输出以该命令开头,并且不再与 Epson 驱动程序匹配。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

The Oki 9-pin driver (drv:///sample.drv/okidata9.ppd, and okidat24.ppd) never sends ESC { A, the Oki command that selects Epson emulation, so its output is byte for byte the Epson driver's, and an Oki printer not already set to Epson emulation does not get switched.

Cause

StartPage() in filter/rastertoepson.c (master at 4fb4b58, line 145) sends it only when the PPD's nickname contains "OKIDATA":

if (ppd && ppd->nickname && strstr(ppd->nickname, "OKIDATA") != NULL)
  printf("\033{A");

but ppdc/sample.drv gives these drivers the nicknames "Oki 9-Pin Series" and "Oki 24-Pin Series", so the test never matches.

To Reproduce

With CUPS and Python 3, the script below prints a page through okidata9.ppd and epson9.ppd:

okidata9 output starts: 1b 40 1b 50 12 1b  (ESC { A would be 1b 7b 41)
okidata9 output identical to epson9: True

The same output comes from macOS's CUPS 2.3.4 filter and from filter/rastertoepson.c at master (4fb4b58), built against the system libcups.

repro.py
"""Reproduce two rastertoepson bugs with CUPS's own sample drivers.

Usage: python3 repro.py [path/to/rastertoepson]

Prints a page filled with black through the Epson 9-pin driver at
60x72dpi on Letter, and through the Oki 9-pin driver.
"""

import os
import struct
import subprocess
import sys
from pathlib import Path

serverbin = Path(subprocess.run(["cups-config", "--serverbin"], capture_output=True,
                                text=True, check=True).stdout.strip())
rastertoepson = sys.argv[1] if len(sys.argv) > 1 else str(serverbin / "filter" / "rastertoepson")

# A US Letter PDF filled with black.
content = b"0 0 612 792 re f"
objects = [
    b"<< /Type /Catalog /Pages 2 0 R >>",
    b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
    b"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R >>",
    b"<< /Length %d >>\nstream\n%s\nendstream" % (len(content), content),
]
pdf = bytearray(b"%PDF-1.4\n")
offsets = []
for number, body in enumerate(objects, 1):
    offsets.append(len(pdf))
    pdf += b"%d 0 obj\n%s\nendobj\n" % (number, body)
xref = len(pdf)
pdf += b"xref\n0 %d\n0000000000 65535 f \n" % (len(objects) + 1)
pdf += b"".join(b"%010d 00000 n \n" % o for o in offsets)
pdf += b"trailer\n<< /Size %d /Root 1 0 R >>\nstartxref\n%d\n%%%%EOF\n" % (len(objects) + 1, xref)
Path("black.pdf").write_bytes(pdf)


def run(ppd_name, resolution):
    ppd = subprocess.run([str(serverbin / "daemon" / "cups-driverd"), "cat",
                          f"drv:///sample.drv/{ppd_name}.ppd"],
                         capture_output=True, check=True).stdout
    Path(f"{ppd_name}.ppd").write_bytes(ppd)
    options = ["-o", "PageSize=Letter", "-o", f"Resolution={resolution}"]
    raster = subprocess.run(["cupsfilter", "-p", f"{ppd_name}.ppd", "-m",
                             "application/vnd.cups-raster", *options, "black.pdf"],
                            capture_output=True, check=True).stdout
    Path(f"{ppd_name}.ras").write_bytes(raster)
    out = subprocess.run([rastertoepson, "1", "user", "title", "1", "", f"{ppd_name}.ras"],
                         capture_output=True, check=True,
                         env={**os.environ, "PPD": f"{ppd_name}.ppd"}).stdout
    return raster, out


# Bug 1: the last band of a page is dropped when it holds fewer than 8 rows.
raster, out = run("epson9", "60x72dpi")
order = ">" if raster[:4] in (b"RaS2", b"RaS3") else "<"
height = struct.unpack_from(order + "I", raster, 4 + 376)[0]
images, i = [], 0
while (i := out.find(b"\x1b*", i)) >= 0:  # ESC * m nL nH data
    n = out[i + 3] | out[i + 4] << 8
    images.append(out[i + 5 : i + 5 + n])
    i += 5 + n
print(f"raster rows: {height} = {height // 8} bands of 8 + {height % 8} rows")
print(f"bit images sent: {len(images)}")
print(f"dots in the last image: {sorted(set(images[-1]))[:4]} (0xFF is all 8 pins)")
print(f"rows printed: {8 * len(images)}, rows lost: {height - 8 * len(images)}")

# Bug 2: the Oki driver never selects Epson emulation.
_, oki = run("okidata9", "120x72dpi")
_, epson = run("epson9", "120x72dpi")
print(f"\nokidata9 output starts: {oki[:6].hex(' ')}  (ESC {{ A would be 1b 7b 41)")
print(f"okidata9 output identical to epson9: {oki == epson}")

(The script also reproduces #1843, a separate bug in the same filter.)

Expected behavior

The Oki drivers' output begins with ESC { A, for instance by matching the nickname's "Oki" or by marking the Oki models in sample.drv.

System Information:

  • OS: macOS 14.6 (CUPS 2.3.4); the code is unchanged at master
主要语言
C
星标
1.8k
派生
373
平均合并
1 天 11 小时
30 天内合并 PR
9

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OpenPrinting/cups 的其他 Issue

查看 OpenPrinting/cups 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。