Files
ptouch_label/ruby/lib/libptouch/binding.rb
knb bfd6adda42 libptouch: P700/P900 families, optional JSON config, ESC i z and print sequencing
- Add printer_family and profile flags; load overrides from printer_families.json
- Set ESC i z page byte from profile; pass prof into ptouch_fill_esc_iz
- End print with 0x1A only (drop FF prefix); extend Ruby FFI and CLI media info
- Add reference/ptp_raster_ref.adoc; install config under share/ptouch_label

Made-with: Cursor
2026-04-19 12:20:21 +09:00

75 lines
2.6 KiB
Ruby

# frozen_string_literal: true
require "ffi"
module Libptouch
module Binding
extend FFI::Library
def self.library_files
list = []
env = ENV["LIBPTOUCH_LIB"]
list << env if env && !env.empty?
base = File.expand_path("../../..", __dir__)
%w[libptouch.so libptouch.dylib].each do |name|
path = File.join(base, "build", name)
list << path if File.file?(path)
end
list << "libptouch"
list
end
ffi_lib library_files
class RasterParams < FFI::Struct
layout :width_dots, :uint32,
:height_dots, :uint32,
:margin_mm, :uint8,
:_pad, [:uint8, 3]
end
class MediaInfo < FFI::Struct
layout :media_width_code, :uint8,
:media_kind_code, :uint8,
:_pad0, [:uint8, 6],
:print_dpi, :double,
:feed_dpi, :double,
:tape_width_mm, :double,
:printable_dots, :uint16,
:left_margin_dots, :uint16,
:right_margin_dots, :uint16,
:min_feed_dots, :uint16,
:min_feed_mm, :double,
:printer_family, :uint32
end
class PngOptions < FFI::Struct
layout :threshold, :uint8
end
class SvgOptions < FFI::Struct
layout :threshold, :uint8
end
attach_function :libptouch_create, [], :pointer
attach_function :libptouch_printer_family_label, [:uint32], :string
attach_function :libptouch_destroy, [:pointer], :void
attach_function :libptouch_strerror, [:pointer], :string
attach_function :libptouch_last_error, [:pointer], :int
attach_function :libptouch_open_usb, [:pointer], :int
attach_function :libptouch_open_usb_vid_pid, %i[pointer uint16 uint16], :int
attach_function :libptouch_close, [:pointer], :void
attach_function :libptouch_check_raster, %i[pointer pointer size_t pointer], :int
attach_function :libptouch_get_current_media_info, %i[pointer pointer], :int
attach_function :libptouch_trim_right_blank_columns,
%i[pointer pointer size_t pointer uint16 pointer pointer pointer], :int
attach_function :libptouch_print_raster, %i[pointer pointer size_t pointer], :int
attach_function :libptouch_png_file_to_raster,
%i[pointer string pointer pointer pointer pointer], :int
attach_function :libptouch_svg_file_to_raster_fit_current_tape,
%i[pointer string pointer pointer pointer pointer], :int
attach_function :libptouch_free_raster, [:pointer], :void
attach_function :libptouch_get_status, %i[pointer pointer], :int
end
end