SVG入力を現在テープ幅に自動フィットして印刷できるようにし、アプリ側が余白計算できるようにテープ幅・DPI・最小送り量を取得するAPIを追加する。 Made-with: Cursor
71 lines
2.3 KiB
Ruby
71 lines
2.3 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_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
|