ruby-libgd 0.2.1 → 0.2.2
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 +4 -4
- data/ext/gd/gd.so +0 -0
- data/ext/gd/text.c +103 -6
- data/ext/gd/text.o +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 86d2d815f83b82844f6e052eedcd00481e53bf8d270dc8db48a5c4bc18bcecbb
|
|
4
|
+
data.tar.gz: fd3bea0c6cbeb6d6bc5d0f31716b0c32d57b62f3cad20f7955cbe695360bb87c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1389a01c9e0de55a8a2aad3cda2781016c292fe6ddc44aebcb768f89e73c103f6a28466a253e92466f84990ea22e28cd76432464aa19f8a4894ad5d3d59a15bd
|
|
7
|
+
data.tar.gz: 68453f430c861714bf37ce2c2c7016cafb22543f19d5c22c964d303c6c4bf163ee4d50ac3370ee37551c1e206aec6dff03897036052c2cde94cb2b7a9cd7aad5
|
data/ext/gd/gd.so
CHANGED
|
Binary file
|
data/ext/gd/text.c
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
#include "ruby_gd.h"
|
|
2
|
-
/*
|
|
3
|
-
- [ ] imagefontheight — Get font height
|
|
4
|
-
- [ ] imagefontwidth — Get font width
|
|
5
|
-
- [ ] imageftbbox — Give the bounding box of a text using fonts via freetype2
|
|
6
|
-
- [ ] imagefttext — Write text to the image using fonts using FreeType 2
|
|
7
|
-
*/
|
|
8
2
|
|
|
9
3
|
static VALUE gd_image_text(VALUE self, VALUE text, VALUE opts) {
|
|
10
4
|
gd_image_wrapper *wrap;
|
|
@@ -39,6 +33,109 @@ static VALUE gd_image_text(VALUE self, VALUE text, VALUE opts) {
|
|
|
39
33
|
return Qnil;
|
|
40
34
|
}
|
|
41
35
|
|
|
36
|
+
static VALUE gd_image_text_bbox(VALUE self, VALUE text, VALUE opts) {
|
|
37
|
+
gd_image_wrapper *wrap;
|
|
38
|
+
TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
|
|
39
|
+
|
|
40
|
+
VALUE fontV = rb_hash_aref(opts, ID2SYM(rb_intern("font")));
|
|
41
|
+
VALUE sizeV = rb_hash_aref(opts, ID2SYM(rb_intern("size")));
|
|
42
|
+
|
|
43
|
+
if (NIL_P(fontV) || NIL_P(sizeV))
|
|
44
|
+
rb_raise(rb_eArgError, "font and size are required");
|
|
45
|
+
|
|
46
|
+
VALUE angleV = rb_hash_aref(opts, ID2SYM(rb_intern("angle")));
|
|
47
|
+
double angle = NIL_P(angleV) ? 0.0 : NUM2DBL(angleV);
|
|
48
|
+
|
|
49
|
+
const char *font = StringValueCStr(fontV);
|
|
50
|
+
const char *str = StringValueCStr(text);
|
|
51
|
+
double size = NUM2DBL(sizeV);
|
|
52
|
+
|
|
53
|
+
int brect[8];
|
|
54
|
+
|
|
55
|
+
gdFTStringExtra extra;
|
|
56
|
+
memset(&extra, 0, sizeof(extra));
|
|
57
|
+
|
|
58
|
+
char *err = gdImageStringFTEx(
|
|
59
|
+
wrap->img,
|
|
60
|
+
brect,
|
|
61
|
+
0, /* no color, we don't draw */
|
|
62
|
+
font,
|
|
63
|
+
size,
|
|
64
|
+
angle,
|
|
65
|
+
0,
|
|
66
|
+
0,
|
|
67
|
+
str,
|
|
68
|
+
&extra
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
if (err) rb_raise(rb_eRuntimeError, "%s", err);
|
|
72
|
+
|
|
73
|
+
int w = brect[2] - brect[0];
|
|
74
|
+
int h = brect[1] - brect[7];
|
|
75
|
+
|
|
76
|
+
VALUE ary = rb_ary_new2(2);
|
|
77
|
+
rb_ary_push(ary, INT2NUM(w));
|
|
78
|
+
rb_ary_push(ary, INT2NUM(h));
|
|
79
|
+
return ary;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
static VALUE gd_image_text_ft(VALUE self, VALUE text, VALUE opts) {
|
|
84
|
+
gd_image_wrapper *wrap;
|
|
85
|
+
TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
|
|
86
|
+
|
|
87
|
+
VALUE xV = rb_hash_aref(opts, ID2SYM(rb_intern("x")));
|
|
88
|
+
VALUE yV = rb_hash_aref(opts, ID2SYM(rb_intern("y")));
|
|
89
|
+
VALUE sizeV = rb_hash_aref(opts, ID2SYM(rb_intern("size")));
|
|
90
|
+
VALUE colorV = rb_hash_aref(opts, ID2SYM(rb_intern("color")));
|
|
91
|
+
VALUE fontV = rb_hash_aref(opts, ID2SYM(rb_intern("font")));
|
|
92
|
+
|
|
93
|
+
if (NIL_P(xV)||NIL_P(yV)||NIL_P(sizeV)||NIL_P(colorV)||NIL_P(fontV))
|
|
94
|
+
rb_raise(rb_eArgError, "missing required options");
|
|
95
|
+
|
|
96
|
+
int x = NUM2INT(xV);
|
|
97
|
+
int y = NUM2INT(yV);
|
|
98
|
+
double size = NUM2DBL(sizeV);
|
|
99
|
+
const char *font = StringValueCStr(fontV);
|
|
100
|
+
const char *str = StringValueCStr(text);
|
|
101
|
+
|
|
102
|
+
VALUE angleV = rb_hash_aref(opts, ID2SYM(rb_intern("angle")));
|
|
103
|
+
double angle = NIL_P(angleV) ? 0.0 : NUM2DBL(angleV);
|
|
104
|
+
|
|
105
|
+
VALUE dpiV = rb_hash_aref(opts, ID2SYM(rb_intern("dpi")));
|
|
106
|
+
int dpi = NIL_P(dpiV) ? 96 : NUM2INT(dpiV);
|
|
107
|
+
//
|
|
108
|
+
VALUE lsV = rb_hash_aref(opts, ID2SYM(rb_intern("line_spacing")));
|
|
109
|
+
double ls = NIL_P(lsV) ? 1.0 : NUM2DBL(lsV);
|
|
110
|
+
|
|
111
|
+
int fg = color_to_gd(wrap->img, colorV);
|
|
112
|
+
|
|
113
|
+
gdFTStringExtra extra;
|
|
114
|
+
memset(&extra, 0, sizeof(extra));
|
|
115
|
+
extra.flags = gdFTEX_LINESPACE | gdFTEX_RESOLUTION;
|
|
116
|
+
extra.linespacing = ls;
|
|
117
|
+
extra.hdpi = dpi;
|
|
118
|
+
extra.vdpi = dpi;
|
|
119
|
+
|
|
120
|
+
char *err = gdImageStringFTEx(
|
|
121
|
+
wrap->img,
|
|
122
|
+
NULL,
|
|
123
|
+
fg,
|
|
124
|
+
font,
|
|
125
|
+
size,
|
|
126
|
+
angle,
|
|
127
|
+
x,
|
|
128
|
+
y,
|
|
129
|
+
str,
|
|
130
|
+
&extra
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
if (err) rb_raise(rb_eRuntimeError, "%s", err);
|
|
134
|
+
return Qnil;
|
|
135
|
+
}
|
|
136
|
+
|
|
42
137
|
void gd_define_text(VALUE cGDImage) {
|
|
43
138
|
rb_define_method(cGDImage, "text", gd_image_text, 2);
|
|
139
|
+
rb_define_method(cGDImage, "text_bbox", gd_image_text_bbox, 2);
|
|
140
|
+
rb_define_method(cGDImage, "text_ft", gd_image_text_ft, 2);
|
|
44
141
|
}
|
data/ext/gd/text.o
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-libgd
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Germán Alberto Giménez Silva
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
11
|
+
date: 2026-01-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: High-performance native Ruby bindings to libgd for image generation,
|
|
14
14
|
drawing, filters, alpha blending, and transformations.
|