2021 advent calendar day 8,9

ページモードの理解

機能としてプリンターは以下の2つのモードが存在する

  • 標準モード
  • ページモード

標準モードは印字データや紙送りコマンドを受信する度に印字および紙送りを実行
ページモードは印字データや紙送りコマンドはメモリ上で処理し、ページモードの印字コマンドを受信したタイミングで印字や紙送りを実行

つまり標準モードではコマンドを送信の度に順次印字

ページモードはメモリに貯めてから印字コマンドで印字

さらにページモードは印字位置関係のコマンドがあるのでメモリ上で描画してから印字ということになる

※赤字は位置関係のコマンド

とりあえず、コマンドリファレンスを見ながら(印字領域やピッチ等は省いてます)

from escposjp import Network

# 画像加工 Start
from PIL import Image,ImageDraw

im_icon = Image.open("hatotank_a.png")
im_mask = Image.new("L", im_icon.size, 0)

draw = ImageDraw.Draw(im_mask)
draw.ellipse((0,0, 100,100), fill=255)
im_icona = im_icon.copy()
im_icona.putalpha(im_mask)
# 画像加工 End

p = Network("192.168.10.21")
p.hw("INIT")
p.JpInit()

# ページ Start
p._raw(b'\x1B\x4C')         # ESC L ページモードの選択
p._raw(b'\x1B\x57\x30\x00\x00\x00\xA0\x01\x00\x02') # ESC W xL xH yL yH dxL dxH dyL dyH ページモードにおける印字領域の設定
#<-------- 512 --------> 
#        | 0 
#      +---------+
#<-48->| <-416-> |<-48->
#      | ^       |
#      | | 512   |
#      | v       |
#      +---------+
p._raw(b'\x1B\x54\x00')     # ESC T ページモードでの印字方向および開始位置を選択
p._raw(b'\x1D\x5C\x80\x00') # GS \ ページモードにおける縦方向相対位置の指定 ↓128
p.image(img_source=im_icona,impl="graphics")
p._raw(b'\x1D\x5C\x80\xFF') # GS \ ページモードにおける縦方向相対位置の指定 ↑-128
p._raw(b'\x1B\x5C\x80\x00') # ESC \ 相対位置の指定 →128
p.JpText("[表示名]\n")
p._raw(b'\x1B\x5C\x80\x00') # ESC \ 相対位置の指定 →128
p.JpText("[投稿時間]\n")
p._raw(b'\x1B\x5C\x80\x00') # ESC \ 相対位置の指定 →128
p.JpText("[リプライとかの枠]\n")
p._raw(b'\x1B\x0C')         # ESC FF ページモードのデータ印字
p._raw(b'\x1B\x53')         # ESC S スタンダードモードの選択
# ページ End

p.cut()


OK!

しかし、色々と学習が追いつかないので2日で1ページの投稿ペースになりそう

タイトルとURLをコピーしました