skia 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/LICENSE +21 -0
- data/README.md +345 -0
- data/Rakefile +8 -0
- data/examples/avatar_generator.rb +74 -0
- data/examples/bar_chart.rb +89 -0
- data/examples/basic_drawing.rb +43 -0
- data/examples/gradient.rb +32 -0
- data/examples/pdf_output.rb +48 -0
- data/examples/picture_recording.rb +62 -0
- data/examples/progress_gauge.rb +103 -0
- data/examples/social_card.rb +121 -0
- data/examples/text_drawing.rb +40 -0
- data/lib/skia/base.rb +40 -0
- data/lib/skia/canvas.rb +177 -0
- data/lib/skia/color.rb +82 -0
- data/lib/skia/data.rb +47 -0
- data/lib/skia/document.rb +76 -0
- data/lib/skia/font.rb +74 -0
- data/lib/skia/image.rb +137 -0
- data/lib/skia/matrix.rb +163 -0
- data/lib/skia/native/callbacks.rb +6 -0
- data/lib/skia/native/functions.rb +223 -0
- data/lib/skia/native/types.rb +284 -0
- data/lib/skia/native.rb +50 -0
- data/lib/skia/paint.rb +100 -0
- data/lib/skia/path.rb +135 -0
- data/lib/skia/picture.rb +120 -0
- data/lib/skia/point.rb +94 -0
- data/lib/skia/rect.rb +179 -0
- data/lib/skia/shader.rb +107 -0
- data/lib/skia/surface.rb +151 -0
- data/lib/skia/typeface.rb +39 -0
- data/lib/skia/version.rb +5 -0
- data/lib/skia.rb +31 -0
- data/skia-ruby.gemspec +30 -0
- metadata +93 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skia
|
|
4
|
+
class Document < Base
|
|
5
|
+
def initialize(ptr, stream)
|
|
6
|
+
super(ptr, :sk_document_unref)
|
|
7
|
+
@stream = stream
|
|
8
|
+
@closed = false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.create_pdf(path)
|
|
12
|
+
stream = Native.sk_filewstream_new(path)
|
|
13
|
+
raise Error, "Failed to create file stream for: #{path}" if stream.nil? || stream.null?
|
|
14
|
+
|
|
15
|
+
ptr = Native.sk_document_create_pdf_from_stream(stream)
|
|
16
|
+
if ptr.nil? || ptr.null?
|
|
17
|
+
Native.sk_filewstream_destroy(stream)
|
|
18
|
+
raise Error, 'Failed to create PDF document'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
doc = new(ptr, stream)
|
|
22
|
+
|
|
23
|
+
if block_given?
|
|
24
|
+
begin
|
|
25
|
+
yield doc
|
|
26
|
+
ensure
|
|
27
|
+
doc.close
|
|
28
|
+
end
|
|
29
|
+
else
|
|
30
|
+
doc
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def begin_page(width, height, content_rect = nil)
|
|
35
|
+
content_ptr = content_rect&.to_struct
|
|
36
|
+
canvas_ptr = Native.sk_document_begin_page(@ptr, width.to_f, height.to_f, content_ptr)
|
|
37
|
+
raise Error, 'Failed to begin page' if canvas_ptr.nil? || canvas_ptr.null?
|
|
38
|
+
|
|
39
|
+
canvas = Canvas.new(canvas_ptr)
|
|
40
|
+
|
|
41
|
+
if block_given?
|
|
42
|
+
begin
|
|
43
|
+
yield canvas
|
|
44
|
+
ensure
|
|
45
|
+
end_page
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
canvas
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def end_page
|
|
53
|
+
Native.sk_document_end_page(@ptr)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def close
|
|
57
|
+
return if @closed
|
|
58
|
+
|
|
59
|
+
Native.sk_document_close(@ptr)
|
|
60
|
+
Native.sk_filewstream_destroy(@stream) if @stream
|
|
61
|
+
@closed = true
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def abort
|
|
65
|
+
return if @closed
|
|
66
|
+
|
|
67
|
+
Native.sk_document_abort(@ptr)
|
|
68
|
+
Native.sk_filewstream_destroy(@stream) if @stream
|
|
69
|
+
@closed = true
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def closed?
|
|
73
|
+
@closed
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
data/lib/skia/font.rb
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skia
|
|
4
|
+
class Font < Base
|
|
5
|
+
def initialize(typeface = nil, size = 12.0, scale_x = 1.0, skew_x = 0.0)
|
|
6
|
+
ptr = if typeface
|
|
7
|
+
Native.sk_font_new_with_values(typeface.ptr, size.to_f, scale_x.to_f, skew_x.to_f)
|
|
8
|
+
else
|
|
9
|
+
Native.sk_font_new
|
|
10
|
+
end
|
|
11
|
+
raise Error, 'Failed to create font' if ptr.nil? || ptr.null?
|
|
12
|
+
|
|
13
|
+
super(ptr, :sk_font_delete)
|
|
14
|
+
|
|
15
|
+
# Set size explicitly when no typeface is provided (sk_font_new uses default size)
|
|
16
|
+
self.size = size unless typeface
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def typeface
|
|
20
|
+
ptr = Native.sk_font_get_typeface(@ptr)
|
|
21
|
+
return nil if ptr.nil? || ptr.null?
|
|
22
|
+
|
|
23
|
+
Typeface.new(ptr)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def typeface=(value)
|
|
27
|
+
Native.sk_font_set_typeface(@ptr, value&.ptr)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def size
|
|
31
|
+
Native.sk_font_get_size(@ptr)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def size=(value)
|
|
35
|
+
Native.sk_font_set_size(@ptr, value.to_f)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def metrics
|
|
39
|
+
metrics_struct = Native::SKFontMetrics.new
|
|
40
|
+
Native.sk_font_get_metrics(@ptr, metrics_struct)
|
|
41
|
+
FontMetrics.new(metrics_struct)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def measure_text(text, paint = nil)
|
|
45
|
+
text_bytes = text.encode('UTF-8')
|
|
46
|
+
bounds = Native::SKRect.new
|
|
47
|
+
width = Native.sk_font_measure_text(@ptr, text_bytes, text_bytes.bytesize, :utf8, bounds, paint&.ptr)
|
|
48
|
+
[width, Rect.from_struct(bounds)]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class FontMetrics
|
|
53
|
+
attr_reader :top, :ascent, :descent, :bottom, :leading, :avg_char_width, :max_char_width, :x_min, :x_max,
|
|
54
|
+
:x_height, :cap_height, :underline_thickness, :underline_position, :strikeout_thickness, :strikeout_position
|
|
55
|
+
|
|
56
|
+
def initialize(struct)
|
|
57
|
+
@top = struct[:top]
|
|
58
|
+
@ascent = struct[:ascent]
|
|
59
|
+
@descent = struct[:descent]
|
|
60
|
+
@bottom = struct[:bottom]
|
|
61
|
+
@leading = struct[:leading]
|
|
62
|
+
@avg_char_width = struct[:avgCharWidth]
|
|
63
|
+
@max_char_width = struct[:maxCharWidth]
|
|
64
|
+
@x_min = struct[:xMin]
|
|
65
|
+
@x_max = struct[:xMax]
|
|
66
|
+
@x_height = struct[:xHeight]
|
|
67
|
+
@cap_height = struct[:capHeight]
|
|
68
|
+
@underline_thickness = struct[:underlineThickness]
|
|
69
|
+
@underline_position = struct[:underlinePosition]
|
|
70
|
+
@strikeout_thickness = struct[:strikeoutThickness]
|
|
71
|
+
@strikeout_position = struct[:strikeoutPosition]
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
data/lib/skia/image.rb
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skia
|
|
4
|
+
class Image < Base
|
|
5
|
+
def initialize(ptr)
|
|
6
|
+
super(ptr, :sk_image_unref)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.from_file(path)
|
|
10
|
+
data = Data.from_file(path)
|
|
11
|
+
ptr = Native.sk_image_new_from_encoded(data.ptr)
|
|
12
|
+
raise DecodingError, "Failed to decode image: #{path}" if ptr.nil? || ptr.null?
|
|
13
|
+
|
|
14
|
+
new(ptr)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.from_data(data)
|
|
18
|
+
data_obj = data.is_a?(Data) ? data : Data.new(data)
|
|
19
|
+
ptr = Native.sk_image_new_from_encoded(data_obj.ptr)
|
|
20
|
+
raise DecodingError, 'Failed to decode image data' if ptr.nil? || ptr.null?
|
|
21
|
+
|
|
22
|
+
new(ptr)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def width
|
|
26
|
+
Native.sk_image_get_width(@ptr)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def height
|
|
30
|
+
Native.sk_image_get_height(@ptr)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def unique_id
|
|
34
|
+
Native.sk_image_get_unique_id(@ptr)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def encode(format = :png, quality = 100)
|
|
38
|
+
# Create a pixmap to hold the image pixels
|
|
39
|
+
pixmap = Native.sk_pixmap_new
|
|
40
|
+
raise EncodingError, 'Failed to create pixmap' if pixmap.nil? || pixmap.null?
|
|
41
|
+
|
|
42
|
+
begin
|
|
43
|
+
# Peek pixels from the image into the pixmap
|
|
44
|
+
raise EncodingError, 'Failed to peek pixels from image' unless Native.sk_image_peek_pixels(@ptr, pixmap)
|
|
45
|
+
|
|
46
|
+
stream = Native.sk_dynamicmemorywstream_new
|
|
47
|
+
raise EncodingError, 'Failed to create stream' if stream.nil? || stream.null?
|
|
48
|
+
|
|
49
|
+
begin
|
|
50
|
+
success = case format
|
|
51
|
+
when :png
|
|
52
|
+
options = Native::SKPngEncoderOptions.new
|
|
53
|
+
options[:fFilterFlags] = :all
|
|
54
|
+
options[:fZLibLevel] = 6
|
|
55
|
+
options[:fComments] = nil
|
|
56
|
+
options[:fICCProfile] = nil
|
|
57
|
+
options[:fICCProfileDescription] = nil
|
|
58
|
+
Native.sk_pngencoder_encode(stream, pixmap, options)
|
|
59
|
+
when :jpeg, :jpg
|
|
60
|
+
options = Native::SKJpegEncoderOptions.new
|
|
61
|
+
options[:fQuality] = quality
|
|
62
|
+
options[:fDownsample] = :downsample_420
|
|
63
|
+
options[:fAlphaOption] = :ignore
|
|
64
|
+
options[:xmpMetadata] = nil
|
|
65
|
+
options[:fICCProfile] = nil
|
|
66
|
+
options[:fICCProfileDescription] = nil
|
|
67
|
+
Native.sk_jpegencoder_encode(stream, pixmap, options)
|
|
68
|
+
when :webp
|
|
69
|
+
options = Native::SKWebpEncoderOptions.new
|
|
70
|
+
options[:fCompression] = :lossy
|
|
71
|
+
options[:fQuality] = quality.to_f
|
|
72
|
+
options[:fICCProfile] = nil
|
|
73
|
+
options[:fICCProfileDescription] = nil
|
|
74
|
+
Native.sk_webpencoder_encode(stream, pixmap, options)
|
|
75
|
+
else
|
|
76
|
+
options = Native::SKPngEncoderOptions.new
|
|
77
|
+
options[:fFilterFlags] = :all
|
|
78
|
+
options[:fZLibLevel] = 6
|
|
79
|
+
options[:fComments] = nil
|
|
80
|
+
options[:fICCProfile] = nil
|
|
81
|
+
options[:fICCProfileDescription] = nil
|
|
82
|
+
Native.sk_pngencoder_encode(stream, pixmap, options)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
raise EncodingError, "Failed to encode image as #{format}" unless success
|
|
86
|
+
|
|
87
|
+
data_ptr = Native.sk_dynamicmemorywstream_detach_as_data(stream)
|
|
88
|
+
raise EncodingError, 'Failed to get encoded data' if data_ptr.nil? || data_ptr.null?
|
|
89
|
+
|
|
90
|
+
Data.new(data_ptr)
|
|
91
|
+
ensure
|
|
92
|
+
Native.sk_dynamicmemorywstream_destroy(stream)
|
|
93
|
+
end
|
|
94
|
+
ensure
|
|
95
|
+
Native.sk_pixmap_destructor(pixmap)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def save(path, format: nil, quality: 100)
|
|
100
|
+
format ||= detect_format_from_path(path)
|
|
101
|
+
data = encode(format, quality)
|
|
102
|
+
File.binwrite(path, data.to_s)
|
|
103
|
+
self
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def save_png(path, quality = 100)
|
|
107
|
+
save(path, format: :png, quality: quality)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def save_jpeg(path, quality = 80)
|
|
111
|
+
save(path, format: :jpeg, quality: quality)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def save_webp(path, quality = 80)
|
|
115
|
+
save(path, format: :webp, quality: quality)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
private
|
|
119
|
+
|
|
120
|
+
def detect_format_from_path(path)
|
|
121
|
+
case File.extname(path).downcase
|
|
122
|
+
when '.png'
|
|
123
|
+
:png
|
|
124
|
+
when '.jpg', '.jpeg'
|
|
125
|
+
:jpeg
|
|
126
|
+
when '.webp'
|
|
127
|
+
:webp
|
|
128
|
+
when '.gif'
|
|
129
|
+
:gif
|
|
130
|
+
when '.bmp'
|
|
131
|
+
:bmp
|
|
132
|
+
else
|
|
133
|
+
:png
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
data/lib/skia/matrix.rb
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skia
|
|
4
|
+
class Matrix
|
|
5
|
+
attr_accessor :scale_x, :skew_x, :trans_x, :skew_y, :scale_y, :trans_y, :persp0, :persp1, :persp2
|
|
6
|
+
|
|
7
|
+
def initialize(scale_x: 1.0, skew_x: 0.0, trans_x: 0.0,
|
|
8
|
+
skew_y: 0.0, scale_y: 1.0, trans_y: 0.0,
|
|
9
|
+
persp0: 0.0, persp1: 0.0, persp2: 1.0)
|
|
10
|
+
@scale_x = scale_x.to_f
|
|
11
|
+
@skew_x = skew_x.to_f
|
|
12
|
+
@trans_x = trans_x.to_f
|
|
13
|
+
@skew_y = skew_y.to_f
|
|
14
|
+
@scale_y = scale_y.to_f
|
|
15
|
+
@trans_y = trans_y.to_f
|
|
16
|
+
@persp0 = persp0.to_f
|
|
17
|
+
@persp1 = persp1.to_f
|
|
18
|
+
@persp2 = persp2.to_f
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.identity
|
|
22
|
+
new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.translate(dx, dy)
|
|
26
|
+
new(trans_x: dx.to_f, trans_y: dy.to_f)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.scale(sx, sy = sx)
|
|
30
|
+
new(scale_x: sx.to_f, scale_y: sy.to_f)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.rotate(degrees, px = 0.0, py = 0.0)
|
|
34
|
+
radians = degrees * Math::PI / 180.0
|
|
35
|
+
cos = Math.cos(radians)
|
|
36
|
+
sin = Math.sin(radians)
|
|
37
|
+
|
|
38
|
+
if px.zero? && py.zero?
|
|
39
|
+
new(scale_x: cos, skew_x: -sin, skew_y: sin, scale_y: cos)
|
|
40
|
+
else
|
|
41
|
+
new(
|
|
42
|
+
scale_x: cos,
|
|
43
|
+
skew_x: -sin,
|
|
44
|
+
trans_x: px - px * cos + py * sin,
|
|
45
|
+
skew_y: sin,
|
|
46
|
+
scale_y: cos,
|
|
47
|
+
trans_y: py - px * sin - py * cos
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.skew(sx, sy)
|
|
53
|
+
new(skew_x: sx.to_f, skew_y: sy.to_f)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def self.from_struct(struct)
|
|
57
|
+
new(
|
|
58
|
+
scale_x: struct[:scaleX],
|
|
59
|
+
skew_x: struct[:skewX],
|
|
60
|
+
trans_x: struct[:transX],
|
|
61
|
+
skew_y: struct[:skewY],
|
|
62
|
+
scale_y: struct[:scaleY],
|
|
63
|
+
trans_y: struct[:transY],
|
|
64
|
+
persp0: struct[:persp0],
|
|
65
|
+
persp1: struct[:persp1],
|
|
66
|
+
persp2: struct[:persp2]
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def to_struct
|
|
71
|
+
struct = Native::SKMatrix.new
|
|
72
|
+
struct[:scaleX] = @scale_x
|
|
73
|
+
struct[:skewX] = @skew_x
|
|
74
|
+
struct[:transX] = @trans_x
|
|
75
|
+
struct[:skewY] = @skew_y
|
|
76
|
+
struct[:scaleY] = @scale_y
|
|
77
|
+
struct[:transY] = @trans_y
|
|
78
|
+
struct[:persp0] = @persp0
|
|
79
|
+
struct[:persp1] = @persp1
|
|
80
|
+
struct[:persp2] = @persp2
|
|
81
|
+
struct
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Convert 3x3 matrix to 4x4 matrix for canvas operations
|
|
85
|
+
def to_struct44
|
|
86
|
+
struct = Native::SKMatrix44.new
|
|
87
|
+
struct[:m00] = @scale_x
|
|
88
|
+
struct[:m01] = @skew_x
|
|
89
|
+
struct[:m02] = 0.0
|
|
90
|
+
struct[:m03] = @trans_x
|
|
91
|
+
struct[:m10] = @skew_y
|
|
92
|
+
struct[:m11] = @scale_y
|
|
93
|
+
struct[:m12] = 0.0
|
|
94
|
+
struct[:m13] = @trans_y
|
|
95
|
+
struct[:m20] = 0.0
|
|
96
|
+
struct[:m21] = 0.0
|
|
97
|
+
struct[:m22] = 1.0
|
|
98
|
+
struct[:m23] = 0.0
|
|
99
|
+
struct[:m30] = @persp0
|
|
100
|
+
struct[:m31] = @persp1
|
|
101
|
+
struct[:m32] = 0.0
|
|
102
|
+
struct[:m33] = @persp2
|
|
103
|
+
struct
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Create Matrix from 4x4 struct
|
|
107
|
+
def self.from_struct44(struct)
|
|
108
|
+
new(
|
|
109
|
+
scale_x: struct[:m00],
|
|
110
|
+
skew_x: struct[:m01],
|
|
111
|
+
trans_x: struct[:m03],
|
|
112
|
+
skew_y: struct[:m10],
|
|
113
|
+
scale_y: struct[:m11],
|
|
114
|
+
trans_y: struct[:m13],
|
|
115
|
+
persp0: struct[:m30],
|
|
116
|
+
persp1: struct[:m31],
|
|
117
|
+
persp2: struct[:m33]
|
|
118
|
+
)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def *(other)
|
|
122
|
+
self.class.new(
|
|
123
|
+
scale_x: @scale_x * other.scale_x + @skew_x * other.skew_y,
|
|
124
|
+
skew_x: @scale_x * other.skew_x + @skew_x * other.scale_y,
|
|
125
|
+
trans_x: @scale_x * other.trans_x + @skew_x * other.trans_y + @trans_x,
|
|
126
|
+
skew_y: @skew_y * other.scale_x + @scale_y * other.skew_y,
|
|
127
|
+
scale_y: @skew_y * other.skew_x + @scale_y * other.scale_y,
|
|
128
|
+
trans_y: @skew_y * other.trans_x + @scale_y * other.trans_y + @trans_y,
|
|
129
|
+
persp0: @persp0 * other.scale_x + @persp1 * other.skew_y + @persp2 * other.persp0,
|
|
130
|
+
persp1: @persp0 * other.skew_x + @persp1 * other.scale_y + @persp2 * other.persp1,
|
|
131
|
+
persp2: @persp0 * other.trans_x + @persp1 * other.trans_y + @persp2 * other.persp2
|
|
132
|
+
)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def transform_point(point)
|
|
136
|
+
x = point.x * @scale_x + point.y * @skew_x + @trans_x
|
|
137
|
+
y = point.x * @skew_y + point.y * @scale_y + @trans_y
|
|
138
|
+
Point.new(x, y)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def identity?
|
|
142
|
+
@scale_x == 1.0 && @skew_x == 0.0 && @trans_x == 0.0 &&
|
|
143
|
+
@skew_y == 0.0 && @scale_y == 1.0 && @trans_y == 0.0 &&
|
|
144
|
+
@persp0 == 0.0 && @persp1 == 0.0 && @persp2 == 1.0
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def ==(other)
|
|
148
|
+
return false unless other.is_a?(Matrix)
|
|
149
|
+
|
|
150
|
+
@scale_x == other.scale_x && @skew_x == other.skew_x && @trans_x == other.trans_x &&
|
|
151
|
+
@skew_y == other.skew_y && @scale_y == other.scale_y && @trans_y == other.trans_y &&
|
|
152
|
+
@persp0 == other.persp0 && @persp1 == other.persp1 && @persp2 == other.persp2
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def to_a
|
|
156
|
+
[
|
|
157
|
+
[@scale_x, @skew_x, @trans_x],
|
|
158
|
+
[@skew_y, @scale_y, @trans_y],
|
|
159
|
+
[@persp0, @persp1, @persp2]
|
|
160
|
+
]
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skia
|
|
4
|
+
module Native
|
|
5
|
+
# Surface
|
|
6
|
+
attach_function :sk_surface_new_raster, [SKImageInfo.ptr, :size_t, :pointer], :sk_surface_t
|
|
7
|
+
attach_function :sk_surface_new_raster_direct,
|
|
8
|
+
[SKImageInfo.ptr, :pointer, :size_t, :pointer, :pointer, :pointer], :sk_surface_t
|
|
9
|
+
attach_function :sk_surface_unref, [:sk_surface_t], :void
|
|
10
|
+
attach_function :sk_surface_get_canvas, [:sk_surface_t], :sk_canvas_t
|
|
11
|
+
attach_function :sk_surface_new_image_snapshot, [:sk_surface_t], :sk_image_t
|
|
12
|
+
attach_function :sk_surface_peek_pixels, %i[sk_surface_t sk_pixmap_t], :bool
|
|
13
|
+
|
|
14
|
+
# Canvas - State
|
|
15
|
+
attach_function :sk_canvas_save, [:sk_canvas_t], :int
|
|
16
|
+
attach_function :sk_canvas_save_layer, [:sk_canvas_t, SKRect.ptr, :sk_paint_t], :int
|
|
17
|
+
attach_function :sk_canvas_restore, [:sk_canvas_t], :void
|
|
18
|
+
attach_function :sk_canvas_restore_to_count, %i[sk_canvas_t int], :void
|
|
19
|
+
attach_function :sk_canvas_get_save_count, [:sk_canvas_t], :int
|
|
20
|
+
|
|
21
|
+
# Canvas - Transform
|
|
22
|
+
attach_function :sk_canvas_translate, %i[sk_canvas_t float float], :void
|
|
23
|
+
attach_function :sk_canvas_scale, %i[sk_canvas_t float float], :void
|
|
24
|
+
attach_function :sk_canvas_rotate_degrees, %i[sk_canvas_t float], :void
|
|
25
|
+
attach_function :sk_canvas_rotate_radians, %i[sk_canvas_t float], :void
|
|
26
|
+
attach_function :sk_canvas_skew, %i[sk_canvas_t float float], :void
|
|
27
|
+
attach_function :sk_canvas_concat, [:sk_canvas_t, SKMatrix44.ptr], :void
|
|
28
|
+
attach_function :sk_canvas_set_matrix, [:sk_canvas_t, SKMatrix44.ptr], :void
|
|
29
|
+
attach_function :sk_canvas_get_matrix, [:sk_canvas_t, SKMatrix44.ptr], :void
|
|
30
|
+
attach_function :sk_canvas_reset_matrix, [:sk_canvas_t], :void
|
|
31
|
+
|
|
32
|
+
# Canvas - Clip
|
|
33
|
+
attach_function :sk_canvas_clip_rect_with_operation,
|
|
34
|
+
[:sk_canvas_t, SKRect.ptr, :sk_clipop_t, :bool], :void
|
|
35
|
+
attach_function :sk_canvas_clip_path_with_operation,
|
|
36
|
+
%i[sk_canvas_t sk_path_t sk_clipop_t bool], :void
|
|
37
|
+
attach_function :sk_canvas_clip_region, %i[sk_canvas_t pointer sk_clipop_t], :void
|
|
38
|
+
|
|
39
|
+
# Canvas - Draw
|
|
40
|
+
attach_function :sk_canvas_draw_paint, %i[sk_canvas_t sk_paint_t], :void
|
|
41
|
+
attach_function :sk_canvas_draw_rect, [:sk_canvas_t, SKRect.ptr, :sk_paint_t], :void
|
|
42
|
+
attach_function :sk_canvas_draw_rrect, %i[sk_canvas_t pointer sk_paint_t], :void
|
|
43
|
+
attach_function :sk_canvas_draw_round_rect,
|
|
44
|
+
[:sk_canvas_t, SKRect.ptr, :float, :float, :sk_paint_t], :void
|
|
45
|
+
attach_function :sk_canvas_draw_circle, %i[sk_canvas_t float float float sk_paint_t], :void
|
|
46
|
+
attach_function :sk_canvas_draw_oval, [:sk_canvas_t, SKRect.ptr, :sk_paint_t], :void
|
|
47
|
+
attach_function :sk_canvas_draw_path, %i[sk_canvas_t sk_path_t sk_paint_t], :void
|
|
48
|
+
attach_function :sk_canvas_draw_image, %i[sk_canvas_t sk_image_t float float sk_paint_t], :void
|
|
49
|
+
attach_function :sk_canvas_draw_image_rect,
|
|
50
|
+
[:sk_canvas_t, :sk_image_t, SKRect.ptr, SKRect.ptr, :sk_paint_t], :void
|
|
51
|
+
attach_function :sk_canvas_draw_line, %i[sk_canvas_t float float float float sk_paint_t], :void
|
|
52
|
+
attach_function :sk_canvas_draw_point, %i[sk_canvas_t float float sk_paint_t], :void
|
|
53
|
+
attach_function :sk_canvas_draw_points, %i[sk_canvas_t int size_t pointer sk_paint_t], :void
|
|
54
|
+
attach_function :sk_canvas_draw_simple_text,
|
|
55
|
+
%i[sk_canvas_t pointer size_t sk_text_encoding_t float float sk_font_t sk_paint_t], :void
|
|
56
|
+
attach_function :sk_canvas_clear, %i[sk_canvas_t sk_color_t], :void
|
|
57
|
+
attach_function :sk_canvas_draw_color, %i[sk_canvas_t sk_color_t sk_blend_mode_t], :void
|
|
58
|
+
|
|
59
|
+
# Paint
|
|
60
|
+
attach_function :sk_paint_new, [], :sk_paint_t
|
|
61
|
+
attach_function :sk_paint_clone, [:sk_paint_t], :sk_paint_t
|
|
62
|
+
attach_function :sk_paint_delete, [:sk_paint_t], :void
|
|
63
|
+
attach_function :sk_paint_reset, [:sk_paint_t], :void
|
|
64
|
+
attach_function :sk_paint_is_antialias, [:sk_paint_t], :bool
|
|
65
|
+
attach_function :sk_paint_set_antialias, %i[sk_paint_t bool], :void
|
|
66
|
+
attach_function :sk_paint_get_color, [:sk_paint_t], :sk_color_t
|
|
67
|
+
attach_function :sk_paint_set_color, %i[sk_paint_t sk_color_t], :void
|
|
68
|
+
attach_function :sk_paint_get_style, [:sk_paint_t], :sk_paint_style_t
|
|
69
|
+
attach_function :sk_paint_set_style, %i[sk_paint_t sk_paint_style_t], :void
|
|
70
|
+
attach_function :sk_paint_get_stroke_width, [:sk_paint_t], :float
|
|
71
|
+
attach_function :sk_paint_set_stroke_width, %i[sk_paint_t float], :void
|
|
72
|
+
attach_function :sk_paint_get_stroke_miter, [:sk_paint_t], :float
|
|
73
|
+
attach_function :sk_paint_set_stroke_miter, %i[sk_paint_t float], :void
|
|
74
|
+
attach_function :sk_paint_get_stroke_cap, [:sk_paint_t], :sk_stroke_cap_t
|
|
75
|
+
attach_function :sk_paint_set_stroke_cap, %i[sk_paint_t sk_stroke_cap_t], :void
|
|
76
|
+
attach_function :sk_paint_get_stroke_join, [:sk_paint_t], :sk_stroke_join_t
|
|
77
|
+
attach_function :sk_paint_set_stroke_join, %i[sk_paint_t sk_stroke_join_t], :void
|
|
78
|
+
attach_function :sk_paint_get_blendmode, [:sk_paint_t], :sk_blend_mode_t
|
|
79
|
+
attach_function :sk_paint_set_blendmode, %i[sk_paint_t sk_blend_mode_t], :void
|
|
80
|
+
attach_function :sk_paint_get_shader, [:sk_paint_t], :sk_shader_t
|
|
81
|
+
attach_function :sk_paint_set_shader, %i[sk_paint_t sk_shader_t], :void
|
|
82
|
+
attach_function :sk_paint_get_maskfilter, [:sk_paint_t], :sk_mask_filter_t
|
|
83
|
+
attach_function :sk_paint_set_maskfilter, %i[sk_paint_t sk_mask_filter_t], :void
|
|
84
|
+
attach_function :sk_paint_get_colorfilter, [:sk_paint_t], :sk_color_filter_t
|
|
85
|
+
attach_function :sk_paint_set_colorfilter, %i[sk_paint_t sk_color_filter_t], :void
|
|
86
|
+
attach_function :sk_paint_get_imagefilter, [:sk_paint_t], :sk_image_filter_t
|
|
87
|
+
attach_function :sk_paint_set_imagefilter, %i[sk_paint_t sk_image_filter_t], :void
|
|
88
|
+
attach_function :sk_paint_get_path_effect, [:sk_paint_t], :sk_path_effect_t
|
|
89
|
+
attach_function :sk_paint_set_path_effect, %i[sk_paint_t sk_path_effect_t], :void
|
|
90
|
+
|
|
91
|
+
# Path
|
|
92
|
+
attach_function :sk_path_new, [], :sk_path_t
|
|
93
|
+
attach_function :sk_path_clone, [:sk_path_t], :sk_path_t
|
|
94
|
+
attach_function :sk_path_delete, [:sk_path_t], :void
|
|
95
|
+
attach_function :sk_path_reset, [:sk_path_t], :void
|
|
96
|
+
attach_function :sk_path_move_to, %i[sk_path_t float float], :void
|
|
97
|
+
attach_function :sk_path_line_to, %i[sk_path_t float float], :void
|
|
98
|
+
attach_function :sk_path_quad_to, %i[sk_path_t float float float float], :void
|
|
99
|
+
attach_function :sk_path_conic_to, %i[sk_path_t float float float float float], :void
|
|
100
|
+
attach_function :sk_path_cubic_to, %i[sk_path_t float float float float float float], :void
|
|
101
|
+
attach_function :sk_path_arc_to, %i[sk_path_t float float float float float], :void
|
|
102
|
+
attach_function :sk_path_arc_to_with_oval, [:sk_path_t, SKRect.ptr, :float, :float, :bool], :void
|
|
103
|
+
attach_function :sk_path_close, [:sk_path_t], :void
|
|
104
|
+
attach_function :sk_path_add_rect, [:sk_path_t, SKRect.ptr, :sk_path_direction_t], :void
|
|
105
|
+
attach_function :sk_path_add_rrect, %i[sk_path_t pointer sk_path_direction_t], :void
|
|
106
|
+
attach_function :sk_path_add_oval, [:sk_path_t, SKRect.ptr, :sk_path_direction_t], :void
|
|
107
|
+
attach_function :sk_path_add_circle, %i[sk_path_t float float float sk_path_direction_t], :void
|
|
108
|
+
attach_function :sk_path_add_arc, [:sk_path_t, SKRect.ptr, :float, :float], :void
|
|
109
|
+
attach_function :sk_path_add_path, %i[sk_path_t sk_path_t int int], :void
|
|
110
|
+
attach_function :sk_path_add_path_offset, %i[sk_path_t sk_path_t float float int], :void
|
|
111
|
+
attach_function :sk_path_add_path_matrix, [:sk_path_t, :sk_path_t, SKMatrix.ptr, :int], :void
|
|
112
|
+
attach_function :sk_path_get_filltype, [:sk_path_t], :sk_path_filltype_t
|
|
113
|
+
attach_function :sk_path_set_filltype, %i[sk_path_t sk_path_filltype_t], :void
|
|
114
|
+
attach_function :sk_path_get_bounds, [:sk_path_t, SKRect.ptr], :void
|
|
115
|
+
attach_function :sk_path_contains, %i[sk_path_t float float], :bool
|
|
116
|
+
attach_function :sk_path_transform, [:sk_path_t, SKMatrix.ptr], :void
|
|
117
|
+
attach_function :sk_path_count_points, [:sk_path_t], :int
|
|
118
|
+
attach_function :sk_path_count_verbs, [:sk_path_t], :int
|
|
119
|
+
|
|
120
|
+
# Image
|
|
121
|
+
attach_function :sk_image_ref, [:sk_image_t], :void
|
|
122
|
+
attach_function :sk_image_unref, [:sk_image_t], :void
|
|
123
|
+
attach_function :sk_image_get_width, [:sk_image_t], :int32
|
|
124
|
+
attach_function :sk_image_get_height, [:sk_image_t], :int32
|
|
125
|
+
attach_function :sk_image_get_unique_id, [:sk_image_t], :uint32
|
|
126
|
+
attach_function :sk_image_new_from_encoded, [:sk_data_t], :sk_image_t
|
|
127
|
+
attach_function :sk_image_ref_encoded, [:sk_image_t], :sk_data_t
|
|
128
|
+
|
|
129
|
+
# Pixmap
|
|
130
|
+
attach_function :sk_pixmap_new, [], :sk_pixmap_t
|
|
131
|
+
attach_function :sk_pixmap_destructor, [:sk_pixmap_t], :void
|
|
132
|
+
attach_function :sk_pixmap_get_info, [:sk_pixmap_t, SKImageInfo.ptr], :void
|
|
133
|
+
|
|
134
|
+
# Image - Pixmap operations
|
|
135
|
+
attach_function :sk_image_peek_pixels, %i[sk_image_t sk_pixmap_t], :bool
|
|
136
|
+
|
|
137
|
+
# Encoders (take sk_pixmap_t, not sk_image_t)
|
|
138
|
+
attach_function :sk_pngencoder_encode, [:pointer, :sk_pixmap_t, SKPngEncoderOptions.ptr], :bool
|
|
139
|
+
attach_function :sk_jpegencoder_encode, [:pointer, :sk_pixmap_t, SKJpegEncoderOptions.ptr], :bool
|
|
140
|
+
attach_function :sk_webpencoder_encode, [:pointer, :sk_pixmap_t, SKWebpEncoderOptions.ptr], :bool
|
|
141
|
+
|
|
142
|
+
# Data
|
|
143
|
+
attach_function :sk_data_new_with_copy, %i[pointer size_t], :sk_data_t
|
|
144
|
+
attach_function :sk_data_new_from_file, [:string], :sk_data_t
|
|
145
|
+
attach_function :sk_data_ref, [:sk_data_t], :void
|
|
146
|
+
attach_function :sk_data_unref, [:sk_data_t], :void
|
|
147
|
+
attach_function :sk_data_get_size, [:sk_data_t], :size_t
|
|
148
|
+
attach_function :sk_data_get_data, [:sk_data_t], :pointer
|
|
149
|
+
|
|
150
|
+
# Stream
|
|
151
|
+
attach_function :sk_dynamicmemorywstream_new, [], :pointer
|
|
152
|
+
attach_function :sk_dynamicmemorywstream_destroy, [:pointer], :void
|
|
153
|
+
attach_function :sk_dynamicmemorywstream_detach_as_data, [:pointer], :sk_data_t
|
|
154
|
+
|
|
155
|
+
# Typeface
|
|
156
|
+
attach_function :sk_typeface_create_from_name, %i[string pointer], :sk_typeface_t
|
|
157
|
+
attach_function :sk_typeface_create_from_file, %i[string int], :sk_typeface_t
|
|
158
|
+
attach_function :sk_typeface_create_default, [], :sk_typeface_t
|
|
159
|
+
attach_function :sk_typeface_unref, [:sk_typeface_t], :void
|
|
160
|
+
|
|
161
|
+
# FontStyle
|
|
162
|
+
attach_function :sk_fontstyle_new, %i[int int sk_font_style_slant_t], :pointer
|
|
163
|
+
attach_function :sk_fontstyle_delete, [:pointer], :void
|
|
164
|
+
|
|
165
|
+
# Font
|
|
166
|
+
attach_function :sk_font_new, [], :sk_font_t
|
|
167
|
+
attach_function :sk_font_new_with_values, %i[sk_typeface_t float float float], :sk_font_t
|
|
168
|
+
attach_function :sk_font_delete, [:sk_font_t], :void
|
|
169
|
+
attach_function :sk_font_set_typeface, %i[sk_font_t sk_typeface_t], :void
|
|
170
|
+
attach_function :sk_font_get_typeface, [:sk_font_t], :sk_typeface_t
|
|
171
|
+
attach_function :sk_font_set_size, %i[sk_font_t float], :void
|
|
172
|
+
attach_function :sk_font_get_size, [:sk_font_t], :float
|
|
173
|
+
attach_function :sk_font_get_metrics, [:sk_font_t, SKFontMetrics.ptr], :float
|
|
174
|
+
attach_function :sk_font_measure_text,
|
|
175
|
+
[:sk_font_t, :pointer, :size_t, :sk_text_encoding_t, SKRect.ptr, :sk_paint_t], :float
|
|
176
|
+
|
|
177
|
+
# Shader
|
|
178
|
+
attach_function :sk_shader_unref, [:sk_shader_t], :void
|
|
179
|
+
attach_function :sk_shader_new_linear_gradient,
|
|
180
|
+
[:pointer, :pointer, :pointer, :int, :sk_shader_tilemode_t, SKMatrix.ptr], :sk_shader_t
|
|
181
|
+
attach_function :sk_shader_new_radial_gradient,
|
|
182
|
+
[SKPoint.ptr, :float, :pointer, :pointer, :int, :sk_shader_tilemode_t, SKMatrix.ptr], :sk_shader_t
|
|
183
|
+
attach_function :sk_shader_new_sweep_gradient,
|
|
184
|
+
[SKPoint.ptr, :pointer, :pointer, :int, :sk_shader_tilemode_t, :float, :float, SKMatrix.ptr], :sk_shader_t
|
|
185
|
+
|
|
186
|
+
# MaskFilter
|
|
187
|
+
attach_function :sk_maskfilter_new_blur, %i[int float], :sk_mask_filter_t
|
|
188
|
+
attach_function :sk_maskfilter_unref, [:sk_mask_filter_t], :void
|
|
189
|
+
|
|
190
|
+
# Color
|
|
191
|
+
attach_function :sk_colortype_get_default_8888, [], :sk_colortype_t
|
|
192
|
+
|
|
193
|
+
# Document (PDF)
|
|
194
|
+
attach_function :sk_document_unref, [:sk_document_t], :void
|
|
195
|
+
attach_function :sk_document_create_pdf_from_stream, [:pointer], :sk_document_t
|
|
196
|
+
attach_function :sk_document_begin_page, [:sk_document_t, :float, :float, SKRect.ptr], :sk_canvas_t
|
|
197
|
+
attach_function :sk_document_end_page, [:sk_document_t], :void
|
|
198
|
+
attach_function :sk_document_close, [:sk_document_t], :void
|
|
199
|
+
attach_function :sk_document_abort, [:sk_document_t], :void
|
|
200
|
+
|
|
201
|
+
# FileWStream (for PDF output)
|
|
202
|
+
attach_function :sk_filewstream_new, [:string], :pointer
|
|
203
|
+
attach_function :sk_filewstream_destroy, [:pointer], :void
|
|
204
|
+
|
|
205
|
+
# Picture Recorder
|
|
206
|
+
attach_function :sk_picture_recorder_new, [], :sk_picture_recorder_t
|
|
207
|
+
attach_function :sk_picture_recorder_delete, [:sk_picture_recorder_t], :void
|
|
208
|
+
attach_function :sk_picture_recorder_begin_recording, [:sk_picture_recorder_t, SKRect.ptr], :sk_canvas_t
|
|
209
|
+
attach_function :sk_picture_recorder_end_recording, [:sk_picture_recorder_t], :sk_picture_t
|
|
210
|
+
attach_function :sk_picture_get_recording_canvas, [:sk_picture_recorder_t], :sk_canvas_t
|
|
211
|
+
|
|
212
|
+
# Picture
|
|
213
|
+
attach_function :sk_picture_ref, [:sk_picture_t], :void
|
|
214
|
+
attach_function :sk_picture_unref, [:sk_picture_t], :void
|
|
215
|
+
attach_function :sk_picture_get_unique_id, [:sk_picture_t], :uint32
|
|
216
|
+
attach_function :sk_picture_get_cull_rect, [:sk_picture_t, SKRect.ptr], :void
|
|
217
|
+
attach_function :sk_picture_playback, %i[sk_picture_t sk_canvas_t], :void
|
|
218
|
+
attach_function :sk_picture_serialize_to_data, [:sk_picture_t], :sk_data_t
|
|
219
|
+
attach_function :sk_picture_deserialize_from_data, [:sk_data_t], :sk_picture_t
|
|
220
|
+
attach_function :sk_picture_approximate_op_count, %i[sk_picture_t bool], :int
|
|
221
|
+
attach_function :sk_picture_approximate_bytes_used, [:sk_picture_t], :size_t
|
|
222
|
+
end
|
|
223
|
+
end
|