Files
ptouch_label/ruby/lib/libptouch/binding.rb
knb 094f183994 ptouch-label/ptouch-print のオプション整理と trim-right 対応を反映
CLIヘルプ文言を簡潔化しつつ、右余白トリム機能と関連API・ドキュメント更新をまとめて取り込み、PNG/SVG/テンプレート経路での利用体験を揃える。

Made-with: Cursor
2026-04-16 19:09:37 +09:00

73 lines
2.5 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
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_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