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:
knb
2026-04-20 04:22:27 +09:00
parent bfd6adda42
commit e10a430f9e
19 changed files with 255 additions and 38 deletions

View File

@@ -36,6 +36,11 @@ module Libptouch
self
end
def debug_dump_path=(path)
Binding.libptouch_set_debug_dump_path(@native, path.nil? || path.to_s.empty? ? nil : path.to_s)
self
end
def close
Binding.libptouch_close(@native) if @native && !@native.null?
self
@@ -47,11 +52,14 @@ module Libptouch
@native = nil
end
def check_raster(data, width_dots:, height_dots:, margin_mm: 0)
def check_raster(data, width_dots:, height_dots:, margin_mm: 0, cut_flags: RASTER_FLAGS_DEFAULT)
params = Binding::RasterParams.new
params[:width_dots] = width_dots
params[:height_dots] = height_dots
params[:margin_mm] = margin_mm
params[:flags] = cut_flags
params[:reserved0] = 0
params[:reserved1] = 0
buf = FFI::MemoryPointer.new(:uint8, data.bytesize)
buf.put_bytes(0, data)
raise_on_error(Binding.libptouch_check_raster(@native, buf, data.bytesize,
@@ -59,11 +67,14 @@ module Libptouch
self
end
def print_raster(data, width_dots:, height_dots:, margin_mm: 0)
def print_raster(data, width_dots:, height_dots:, margin_mm: 0, cut_flags: RASTER_FLAGS_DEFAULT)
params = Binding::RasterParams.new
params[:width_dots] = width_dots
params[:height_dots] = height_dots
params[:margin_mm] = margin_mm
params[:flags] = cut_flags
params[:reserved0] = 0
params[:reserved1] = 0
buf = FFI::MemoryPointer.new(:uint8, data.bytesize)
buf.put_bytes(0, data)
raise_on_error(Binding.libptouch_print_raster(@native, buf, data.bytesize,
@@ -115,11 +126,15 @@ module Libptouch
[bytes, out_params[:width_dots], out_params[:height_dots]]
end
def trim_right_blank_columns(data, width_dots:, height_dots:, margin_mm: 0, right_padding_dots: 0)
def trim_right_blank_columns(data, width_dots:, height_dots:, margin_mm: 0,
right_padding_dots: 0, cut_flags: RASTER_FLAGS_DEFAULT)
in_params = Binding::RasterParams.new
in_params[:width_dots] = width_dots
in_params[:height_dots] = height_dots
in_params[:margin_mm] = margin_mm
in_params[:flags] = cut_flags
in_params[:reserved0] = 0
in_params[:reserved1] = 0
in_buf = FFI::MemoryPointer.new(:uint8, data.bytesize)
in_buf.put_bytes(0, data)
out_pp = FFI::MemoryPointer.new(:pointer)