add cut bitmask option and debug dump support
Replace auto-cut toggle with --cut bit flags (default 011), wire flags through C/Ruby APIs, and document the new cut/debug-dump behavior in both READMEs. Made-with: Cursor
This commit is contained in:
@@ -76,8 +76,10 @@ module Libptouch
|
||||
return nil unless threshold_option_ok?(opts_hash)
|
||||
return nil unless trim_right_option_ok?(opts_hash)
|
||||
return nil unless usb_pid_option_ok?(opts_hash)
|
||||
return nil if opts_hash[:cut_invalid]
|
||||
|
||||
opts_hash.delete(:usb_pid_invalid)
|
||||
opts_hash.delete(:cut_invalid)
|
||||
opts_hash
|
||||
end
|
||||
|
||||
@@ -94,7 +96,9 @@ module Libptouch
|
||||
media_info: false,
|
||||
status: false,
|
||||
version: false,
|
||||
help: false
|
||||
help: false,
|
||||
cut_flags: Libptouch::RASTER_FLAGS_DEFAULT,
|
||||
debug_dump: nil
|
||||
}
|
||||
end
|
||||
|
||||
@@ -138,6 +142,19 @@ module Libptouch
|
||||
false
|
||||
end
|
||||
|
||||
def apply_cut_option(opts_hash, bits)
|
||||
unless bits.is_a?(String) && bits.match?(/\A[01]{3}\z/)
|
||||
warn "--cut must be 3 bits (e.g. 010: auto/half/chain)"
|
||||
opts_hash[:cut_invalid] = true
|
||||
return
|
||||
end
|
||||
flags = 0
|
||||
flags |= Libptouch::RASTER_FLAG_AUTO_CUT if bits[0] == "1"
|
||||
flags |= Libptouch::RASTER_FLAG_HALF_CUT if bits[1] == "1"
|
||||
flags |= Libptouch::RASTER_FLAG_CHAIN_PRINT if bits[2] == "1"
|
||||
opts_hash[:cut_flags] = flags
|
||||
end
|
||||
|
||||
def build_cli_parser(opts_hash)
|
||||
OptionParser.new do |p|
|
||||
p.banner = usage_banner
|
||||
@@ -152,6 +169,12 @@ module Libptouch
|
||||
p.on("-p", "--pid PID", pid_option_description) do |v|
|
||||
apply_usb_pid_option(opts_hash, v)
|
||||
end
|
||||
p.on("--cut BITS", "3bit: [auto][half][chain]。既定 011") do |v|
|
||||
apply_cut_option(opts_hash, v)
|
||||
end
|
||||
p.on("--debug-dump PATH", "デバッグ: 印字バイト列を PATH に保存(1 印刷ごとに上書き)") do |v|
|
||||
opts_hash[:debug_dump] = v
|
||||
end
|
||||
p.on("-n", "--dry-run", "読み込みと検証のみ(USB なし)") { opts_hash[:dry_run] = true }
|
||||
p.on("--trim-right[=DOTS]", Integer,
|
||||
"右側空白を削減。DOTS省略時は左余白(失敗時 0)") do |v|
|
||||
@@ -212,6 +235,12 @@ module Libptouch
|
||||
parser.on("-p", "--pid PID", pid_option_description) do |v|
|
||||
apply_usb_pid_option(opts_hash, v)
|
||||
end
|
||||
parser.on("--cut BITS", "3bit: [auto][half][chain]。既定 011") do |v|
|
||||
apply_cut_option(opts_hash, v)
|
||||
end
|
||||
parser.on("--debug-dump PATH", "印字バイト列を PATH に保存") do |v|
|
||||
opts_hash[:debug_dump] = v
|
||||
end
|
||||
parser.on("-n", "--dry-run", "読み込みと検証のみ(USB なし)") { opts_hash[:dry_run] = true }
|
||||
parser.on("--trim-right[=DOTS]", Integer,
|
||||
"右側空白を削減。DOTS省略時は左余白(失敗時 0)") do |v|
|
||||
@@ -486,6 +515,7 @@ module Libptouch
|
||||
ctx = nil
|
||||
begin
|
||||
ctx = Libptouch::Context.new
|
||||
ctx.debug_dump_path = opts[:debug_dump] if opts[:debug_dump]
|
||||
usb_opened = false
|
||||
threshold = opts[:threshold]
|
||||
data, width, height = if kind == :svg
|
||||
@@ -508,11 +538,13 @@ module Libptouch
|
||||
data,
|
||||
width_dots: width,
|
||||
height_dots: height,
|
||||
right_padding_dots: trim_pad
|
||||
right_padding_dots: trim_pad,
|
||||
cut_flags: opts[:cut_flags]
|
||||
)
|
||||
end
|
||||
|
||||
ctx.check_raster(data, width_dots: width, height_dots: height)
|
||||
ctx.check_raster(data, width_dots: width, height_dots: height,
|
||||
cut_flags: opts[:cut_flags])
|
||||
|
||||
if opts[:dry_run]
|
||||
puts "dry-run OK: #{data.bytesize} bytes, src #{width}x#{height} dots (print lengthxwidth #{width}x#{height})"
|
||||
@@ -520,7 +552,8 @@ module Libptouch
|
||||
end
|
||||
|
||||
open_usb_for_opts(ctx, opts) if kind == :png && !usb_opened
|
||||
ctx.print_raster(data, width_dots: width, height_dots: height)
|
||||
ctx.print_raster(data, width_dots: width, height_dots: height,
|
||||
cut_flags: opts[:cut_flags])
|
||||
0
|
||||
rescue Libptouch::Error => e
|
||||
warn e.message
|
||||
|
||||
Reference in New Issue
Block a user