pango 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +662 -0
- data/README +33 -0
- data/Rakefile +86 -0
- data/extconf.rb +68 -0
- data/sample/attribute.rb +82 -0
- data/sample/break.rb +26 -0
- data/sample/gdk_layout.rb +27 -0
- data/sample/glyphstring.rb +61 -0
- data/sample/item.rb +35 -0
- data/sample/label.rb +23 -0
- data/sample/layout.rb +102 -0
- data/sample/pango_cairo.rb +66 -0
- data/sample/parse.rb +33 -0
- data/sample/sample.txt +10 -0
- data/sample/script.rb +21 -0
- data/src/lib/pango.rb +60 -0
- data/src/makeinits.rb +48 -0
- data/src/rbpango.c +27 -0
- data/src/rbpango.h +97 -0
- data/src/rbpangoanalysis.c +197 -0
- data/src/rbpangoattribute.c +557 -0
- data/src/rbpangoattriterator.c +137 -0
- data/src/rbpangoattrlist.c +104 -0
- data/src/rbpangocairo.c +229 -0
- data/src/rbpangocolor.c +121 -0
- data/src/rbpangocontext.c +341 -0
- data/src/rbpangocoverage.c +104 -0
- data/src/rbpangoengine.c +65 -0
- data/src/rbpangofont.c +123 -0
- data/src/rbpangofontdescription.c +300 -0
- data/src/rbpangofontface.c +71 -0
- data/src/rbpangofontfamily.c +74 -0
- data/src/rbpangofontmap.c +104 -0
- data/src/rbpangofontmetrics.c +85 -0
- data/src/rbpangofontset.c +68 -0
- data/src/rbpangofontsetsimple.c +53 -0
- data/src/rbpangoglyphinfo.c +119 -0
- data/src/rbpangoglyphitem.c +129 -0
- data/src/rbpangoglyphstring.c +162 -0
- data/src/rbpangogravity.c +43 -0
- data/src/rbpangoinits.c +71 -0
- data/src/rbpangoitem.c +110 -0
- data/src/rbpangolanguage.c +88 -0
- data/src/rbpangolayout.c +593 -0
- data/src/rbpangolayoutiter.c +202 -0
- data/src/rbpangolayoutline.c +256 -0
- data/src/rbpangologattr.c +107 -0
- data/src/rbpangomain.c +213 -0
- data/src/rbpangomatrix.c +155 -0
- data/src/rbpangorectangle.c +178 -0
- data/src/rbpangorenderer.c +204 -0
- data/src/rbpangoscript.c +80 -0
- data/src/rbpangoscriptiter.c +91 -0
- data/src/rbpangotabarray.c +128 -0
- data/src/rbpangoversion.h +24 -0
- data/test/pango-test-utils.rb +9 -0
- data/test/run-test.rb +27 -0
- data/test/test-attribute.rb +19 -0
- data/test/test-language.rb +7 -0
- data/test/test_layout.rb +20 -0
- metadata +158 -0
@@ -0,0 +1,197 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/************************************************
|
3
|
+
|
4
|
+
rbpangoanalysis.c -
|
5
|
+
|
6
|
+
$Author: mutoh $
|
7
|
+
$Date: 2005/09/17 17:09:13 $
|
8
|
+
|
9
|
+
Copyright (C) 2003-2005 Masao Mutoh
|
10
|
+
************************************************/
|
11
|
+
|
12
|
+
#include "rbpango.h"
|
13
|
+
|
14
|
+
#define _SELF(s) ((PangoAnalysis*)RVAL2BOXED(s, PANGO_TYPE_ANALYSIS))
|
15
|
+
|
16
|
+
/**********************************/
|
17
|
+
static PangoAnalysis*
|
18
|
+
ana_copy(const PangoAnalysis* val)
|
19
|
+
{
|
20
|
+
PangoAnalysis* new_val;
|
21
|
+
g_return_val_if_fail (val != NULL, NULL);
|
22
|
+
new_val = g_new(PangoAnalysis, 1);
|
23
|
+
*new_val = *val;
|
24
|
+
return new_val;
|
25
|
+
}
|
26
|
+
|
27
|
+
GType
|
28
|
+
pango_analysis_get_type(void)
|
29
|
+
{
|
30
|
+
static GType our_type = 0;
|
31
|
+
|
32
|
+
if (our_type == 0)
|
33
|
+
our_type = g_boxed_type_register_static ("PangoAnalysis",
|
34
|
+
(GBoxedCopyFunc)ana_copy,
|
35
|
+
(GBoxedFreeFunc)g_free);
|
36
|
+
return our_type;
|
37
|
+
}
|
38
|
+
/**********************************/
|
39
|
+
|
40
|
+
static VALUE
|
41
|
+
ana_initialize(self)
|
42
|
+
VALUE self;
|
43
|
+
{
|
44
|
+
PangoAnalysis ana = { NULL, NULL, NULL, 0 };
|
45
|
+
G_INITIALIZE(self, &ana);
|
46
|
+
return Qnil;
|
47
|
+
}
|
48
|
+
|
49
|
+
#if PANGO_CHECK_VERSION(1,4,0)
|
50
|
+
static VALUE
|
51
|
+
ana_set_shape_engine(self, engine)
|
52
|
+
VALUE self, engine;
|
53
|
+
{
|
54
|
+
_SELF(self)->shape_engine = PANGO_ENGINE_SHAPE(RVAL2GOBJ(engine));
|
55
|
+
return self;
|
56
|
+
}
|
57
|
+
static VALUE
|
58
|
+
ana_get_shape_engine(self)
|
59
|
+
VALUE self;
|
60
|
+
{
|
61
|
+
VALUE ret;
|
62
|
+
if (_SELF(self)->shape_engine){
|
63
|
+
const gchar* gname = G_OBJECT_TYPE_NAME(_SELF(self)->shape_engine);
|
64
|
+
gchar* name = g_strdup(gname);
|
65
|
+
name[0] = g_ascii_toupper(name[0]);
|
66
|
+
G_DEF_CLASS3(gname, name, mPango);
|
67
|
+
ret = GOBJ2RVAL(_SELF(self)->shape_engine);
|
68
|
+
} else {
|
69
|
+
ret = Qnil;
|
70
|
+
}
|
71
|
+
return ret;
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE
|
75
|
+
ana_set_lang_engine(self, engine)
|
76
|
+
VALUE self, engine;
|
77
|
+
{
|
78
|
+
_SELF(self)->lang_engine = PANGO_ENGINE_LANG(RVAL2GOBJ(engine));
|
79
|
+
return self;
|
80
|
+
}
|
81
|
+
static VALUE
|
82
|
+
ana_get_lang_engine(self)
|
83
|
+
VALUE self;
|
84
|
+
{
|
85
|
+
VALUE ret;
|
86
|
+
if (_SELF(self)->lang_engine){
|
87
|
+
const gchar* gname = G_OBJECT_TYPE_NAME(_SELF(self)->lang_engine);
|
88
|
+
gchar* name = g_strdup(gname);
|
89
|
+
name[0] = g_ascii_toupper(name[0]);
|
90
|
+
G_DEF_CLASS3(name, name, mPango);
|
91
|
+
ret = GOBJ2RVAL(_SELF(self)->lang_engine);
|
92
|
+
} else {
|
93
|
+
ret = Qnil;
|
94
|
+
}
|
95
|
+
return ret;
|
96
|
+
}
|
97
|
+
#endif
|
98
|
+
|
99
|
+
static VALUE
|
100
|
+
ana_set_font(self, font)
|
101
|
+
VALUE self, font;
|
102
|
+
{
|
103
|
+
_SELF(self)->font = PANGO_FONT(RVAL2GOBJ(font));
|
104
|
+
return self;
|
105
|
+
}
|
106
|
+
|
107
|
+
static VALUE
|
108
|
+
ana_get_font(self)
|
109
|
+
VALUE self;
|
110
|
+
{
|
111
|
+
return GOBJ2RVAL(_SELF(self)->font);
|
112
|
+
}
|
113
|
+
|
114
|
+
static VALUE
|
115
|
+
ana_set_level(self, level)
|
116
|
+
VALUE self, level;
|
117
|
+
{
|
118
|
+
_SELF(self)->level = NUM2UINT(level);
|
119
|
+
return self;
|
120
|
+
}
|
121
|
+
|
122
|
+
static VALUE
|
123
|
+
ana_get_level(self)
|
124
|
+
VALUE self;
|
125
|
+
{
|
126
|
+
return UINT2NUM(_SELF(self)->level);
|
127
|
+
}
|
128
|
+
|
129
|
+
static VALUE
|
130
|
+
ana_set_language(self, lang)
|
131
|
+
VALUE self, lang;
|
132
|
+
{
|
133
|
+
_SELF(self)->language = RVAL2BOXED(lang, PANGO_TYPE_LANGUAGE);
|
134
|
+
return self;
|
135
|
+
}
|
136
|
+
|
137
|
+
static VALUE
|
138
|
+
ana_get_language(self)
|
139
|
+
VALUE self;
|
140
|
+
{
|
141
|
+
return BOXED2RVAL(_SELF(self)->language, PANGO_TYPE_LANGUAGE);
|
142
|
+
}
|
143
|
+
|
144
|
+
static VALUE
|
145
|
+
ana_set_extra_attrs(self, attrs)
|
146
|
+
VALUE self, attrs;
|
147
|
+
{
|
148
|
+
gint i;
|
149
|
+
gint len = RARRAY_LEN(attrs);
|
150
|
+
GSList* gattrs = NULL;
|
151
|
+
|
152
|
+
for (i = 0; i < len; i++){
|
153
|
+
gattrs = g_slist_append(gattrs, RVAL2ATTR(RARRAY_PTR(attrs)[i]));
|
154
|
+
}
|
155
|
+
|
156
|
+
_SELF(self)->extra_attrs = gattrs;
|
157
|
+
return self;
|
158
|
+
}
|
159
|
+
|
160
|
+
static VALUE
|
161
|
+
ana_get_extra_attrs(self)
|
162
|
+
VALUE self;
|
163
|
+
{
|
164
|
+
VALUE ary = rb_ary_new();
|
165
|
+
GSList* list = _SELF(self)->extra_attrs;
|
166
|
+
|
167
|
+
while (list) {
|
168
|
+
rb_ary_push(ary, ATTR2RVAL(list->data));
|
169
|
+
list = list->next;
|
170
|
+
}
|
171
|
+
return ary;
|
172
|
+
}
|
173
|
+
|
174
|
+
void
|
175
|
+
Init_pango_analysis()
|
176
|
+
{
|
177
|
+
VALUE pana = G_DEF_CLASS(PANGO_TYPE_ANALYSIS, "Analysis", mPango);
|
178
|
+
|
179
|
+
rb_define_method(pana, "initialize", ana_initialize, 0);
|
180
|
+
#if PANGO_CHECK_VERSION(1,4,0)
|
181
|
+
rb_define_method(pana, "set_shape_engine", ana_set_shape_engine, 1);
|
182
|
+
rb_define_method(pana, "shape_engine", ana_get_shape_engine, 0);
|
183
|
+
rb_define_method(pana, "set_lang_engine", ana_set_lang_engine, 1);
|
184
|
+
rb_define_method(pana, "lang_engine", ana_get_lang_engine, 0);
|
185
|
+
#endif
|
186
|
+
rb_define_method(pana, "set_font", ana_set_font, 1);
|
187
|
+
rb_define_method(pana, "font", ana_get_font, 0);
|
188
|
+
rb_define_method(pana, "set_level", ana_set_level, 1);
|
189
|
+
rb_define_method(pana, "level", ana_get_level, 0);
|
190
|
+
rb_define_method(pana, "set_language", ana_set_language, 1);
|
191
|
+
rb_define_method(pana, "language", ana_get_language, 0);
|
192
|
+
|
193
|
+
rb_define_method(pana, "set_extra_attrs", ana_set_extra_attrs, 1);
|
194
|
+
rb_define_method(pana, "extra_attrs", ana_get_extra_attrs, 0);
|
195
|
+
|
196
|
+
G_DEF_SETTERS(pana);
|
197
|
+
}
|
@@ -0,0 +1,557 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/************************************************
|
3
|
+
|
4
|
+
rbpangoattribute.c -
|
5
|
+
|
6
|
+
$Author: ggc $
|
7
|
+
$Date: 2007/07/13 16:07:33 $
|
8
|
+
|
9
|
+
Copyright (C) 2002-2005 Masao Mutoh
|
10
|
+
************************************************/
|
11
|
+
|
12
|
+
#include "rbpango.h"
|
13
|
+
|
14
|
+
VALUE pattr, attrstring, pattrint, pattrfloat, pattrcolor, pattrbool;
|
15
|
+
static VALUE type_to_klass;
|
16
|
+
|
17
|
+
/***********************************************/
|
18
|
+
void
|
19
|
+
pango_add_attribute(attr_type, klass)
|
20
|
+
int attr_type;
|
21
|
+
VALUE klass;
|
22
|
+
{
|
23
|
+
rb_hash_aset(type_to_klass, INT2FIX(attr_type), klass);
|
24
|
+
}
|
25
|
+
|
26
|
+
/* This is for Attributes which has PangoAttrType. */
|
27
|
+
VALUE
|
28
|
+
pango_get_attribute_klass(attr_type)
|
29
|
+
VALUE attr_type;
|
30
|
+
{
|
31
|
+
VALUE type = Qnil;
|
32
|
+
if (TYPE(attr_type) == T_STRING){
|
33
|
+
char* strtype = RVAL2CSTR(attr_type);
|
34
|
+
if (strcmp(strtype, "Attribute") == 0){
|
35
|
+
type = pattr;
|
36
|
+
} else if (strcmp(strtype, "AttrString") == 0){
|
37
|
+
type = attrstring;
|
38
|
+
} else if (strcmp(strtype, "AttrInt") == 0){
|
39
|
+
type = pattrint;
|
40
|
+
} else if (strcmp(strtype, "AttrFloat") == 0){
|
41
|
+
type = pattrfloat;
|
42
|
+
} else if (strcmp(strtype, "AttrColor") == 0){
|
43
|
+
type = pattrcolor;
|
44
|
+
} else if (strcmp(strtype, "AttrBool") == 0){
|
45
|
+
type = pattrbool;
|
46
|
+
}
|
47
|
+
} else {
|
48
|
+
type = rb_hash_aref(type_to_klass, INT2FIX(attr_type));
|
49
|
+
}
|
50
|
+
return type;
|
51
|
+
}
|
52
|
+
|
53
|
+
VALUE
|
54
|
+
pango_make_attribute(attr)
|
55
|
+
PangoAttribute* attr;
|
56
|
+
{
|
57
|
+
if (attr == NULL) return Qnil;
|
58
|
+
return Data_Wrap_Struct(rb_hash_aref(type_to_klass, INT2FIX(attr->klass->type)), 0,
|
59
|
+
pango_attribute_destroy,
|
60
|
+
pango_attribute_copy(attr));
|
61
|
+
}
|
62
|
+
|
63
|
+
PangoAttribute*
|
64
|
+
pango_get_attribute(attr)
|
65
|
+
VALUE attr;
|
66
|
+
{
|
67
|
+
PangoAttribute *gattr;
|
68
|
+
|
69
|
+
if (NIL_P(attr)) return NULL;
|
70
|
+
|
71
|
+
if (!rb_obj_is_kind_of(attr, pattr)) {
|
72
|
+
rb_raise(rb_eTypeError, "not a Pango::Attribute...");
|
73
|
+
}
|
74
|
+
Data_Get_Struct(attr, PangoAttribute, gattr);
|
75
|
+
return gattr;
|
76
|
+
}
|
77
|
+
|
78
|
+
/***********************************************/
|
79
|
+
static VALUE
|
80
|
+
attr_s_allocate(klass)
|
81
|
+
VALUE klass;
|
82
|
+
{
|
83
|
+
/* Don't define destroy method here.
|
84
|
+
return Data_Wrap_Struct(klass, 0, pango_attribute_destroy, 0);
|
85
|
+
*/
|
86
|
+
return Data_Wrap_Struct(klass, NULL, NULL, 0);
|
87
|
+
}
|
88
|
+
|
89
|
+
#ifdef HAVE_OBJECT_ALLOCATE
|
90
|
+
#define attr_s_new rb_class_new_instance
|
91
|
+
#else
|
92
|
+
static VALUE
|
93
|
+
attr_s_new(argc, argv, klass)
|
94
|
+
int argc;
|
95
|
+
VALUE* argv;
|
96
|
+
VALUE klass;
|
97
|
+
{
|
98
|
+
VALUE obj = attr_s_allocate(klass);
|
99
|
+
rb_obj_call_init(obj, argc, argv);
|
100
|
+
return obj;
|
101
|
+
}
|
102
|
+
#endif
|
103
|
+
|
104
|
+
/***********************************************/
|
105
|
+
|
106
|
+
/* This method implemented at rbpangomain.c
|
107
|
+
gboolean pango_parse_markup (const char *markup_text,
|
108
|
+
int length,
|
109
|
+
gunichar accel_marker,
|
110
|
+
PangoAttrList **attr_list,
|
111
|
+
char **text,
|
112
|
+
gunichar *accel_char,
|
113
|
+
GError **error);
|
114
|
+
*/
|
115
|
+
|
116
|
+
static VALUE
|
117
|
+
attr_s_type_register(self, name)
|
118
|
+
VALUE self, name;
|
119
|
+
{
|
120
|
+
return INT2NUM(pango_attr_type_register(RVAL2CSTR(name)));
|
121
|
+
}
|
122
|
+
|
123
|
+
static VALUE
|
124
|
+
attr_equal(self, other)
|
125
|
+
VALUE self, other;
|
126
|
+
{
|
127
|
+
return CBOOL2RVAL(pango_attribute_equal(RVAL2ATTR(self), RVAL2ATTR(other)));
|
128
|
+
}
|
129
|
+
|
130
|
+
/*
|
131
|
+
* Structure accessors
|
132
|
+
*/
|
133
|
+
/* PangoAttribute */
|
134
|
+
static VALUE
|
135
|
+
attr_start_index(self)
|
136
|
+
VALUE self;
|
137
|
+
{
|
138
|
+
return UINT2NUM(RVAL2ATTR(self)->start_index);
|
139
|
+
}
|
140
|
+
|
141
|
+
static VALUE
|
142
|
+
attr_set_start_index(VALUE self, VALUE value)
|
143
|
+
{
|
144
|
+
RVAL2ATTR(self)->start_index = NUM2UINT(value);
|
145
|
+
return Qnil;
|
146
|
+
}
|
147
|
+
|
148
|
+
static VALUE
|
149
|
+
attr_end_index(self)
|
150
|
+
VALUE self;
|
151
|
+
{
|
152
|
+
return UINT2NUM(RVAL2ATTR(self)->end_index);
|
153
|
+
}
|
154
|
+
|
155
|
+
static VALUE
|
156
|
+
attr_set_end_index(VALUE self, VALUE value)
|
157
|
+
{
|
158
|
+
RVAL2ATTR(self)->end_index = NUM2UINT(value);
|
159
|
+
return Qnil;
|
160
|
+
}
|
161
|
+
|
162
|
+
/* PangoAttrString */
|
163
|
+
static VALUE
|
164
|
+
attr_string_value(self)
|
165
|
+
VALUE self;
|
166
|
+
{
|
167
|
+
return CSTR2RVAL(((PangoAttrString*)RVAL2ATTR(self))->value);
|
168
|
+
}
|
169
|
+
|
170
|
+
/* PangoAttrLanguage */
|
171
|
+
static VALUE
|
172
|
+
attr_language_value(self)
|
173
|
+
VALUE self;
|
174
|
+
{
|
175
|
+
return BOXED2RVAL(((PangoAttrLanguage*)RVAL2ATTR(self))->value, PANGO_TYPE_LANGUAGE);
|
176
|
+
}
|
177
|
+
|
178
|
+
/* PangoAttrColor */
|
179
|
+
static VALUE
|
180
|
+
attr_color_value(self)
|
181
|
+
VALUE self;
|
182
|
+
{
|
183
|
+
PangoColor color = ((PangoAttrColor*)RVAL2ATTR(self))->color;
|
184
|
+
return BOXED2RVAL(&color, PANGO_TYPE_COLOR);
|
185
|
+
}
|
186
|
+
|
187
|
+
/* PangoAttrInt */
|
188
|
+
static VALUE
|
189
|
+
attr_int_value(self)
|
190
|
+
VALUE self;
|
191
|
+
{
|
192
|
+
return INT2NUM(((PangoAttrInt*)RVAL2ATTR(self))->value);
|
193
|
+
}
|
194
|
+
|
195
|
+
/* PangoAttrFloat */
|
196
|
+
static VALUE
|
197
|
+
attr_float_value(self)
|
198
|
+
VALUE self;
|
199
|
+
{
|
200
|
+
return rb_float_new(((PangoAttrFloat*)RVAL2ATTR(self))->value);
|
201
|
+
}
|
202
|
+
|
203
|
+
/* PangoAttrBool(This is Ruby/Pango's original class) */
|
204
|
+
static VALUE
|
205
|
+
attr_bool_value(self)
|
206
|
+
VALUE self;
|
207
|
+
{
|
208
|
+
return CBOOL2RVAL(((PangoAttrInt*)RVAL2ATTR(self))->value);
|
209
|
+
}
|
210
|
+
|
211
|
+
/* PangoAttrFontDesc */
|
212
|
+
static VALUE
|
213
|
+
attr_fontdesc_value(self)
|
214
|
+
VALUE self;
|
215
|
+
{
|
216
|
+
return BOXED2RVAL(((PangoAttrFontDesc*)RVAL2ATTR(self))->desc, PANGO_TYPE_FONT_DESCRIPTION);
|
217
|
+
}
|
218
|
+
|
219
|
+
/* PangoAttrShape */
|
220
|
+
static VALUE
|
221
|
+
attr_shape_ink_rect(self)
|
222
|
+
VALUE self;
|
223
|
+
{
|
224
|
+
PangoRectangle rect = ((PangoAttrShape*)RVAL2ATTR(self))->ink_rect;
|
225
|
+
return BOXED2RVAL(&rect, PANGO_TYPE_RECTANGLE);
|
226
|
+
}
|
227
|
+
|
228
|
+
static VALUE
|
229
|
+
attr_shape_logical_rect(self)
|
230
|
+
VALUE self;
|
231
|
+
{
|
232
|
+
PangoRectangle rect = ((PangoAttrShape*)RVAL2ATTR(self))->logical_rect;
|
233
|
+
return BOXED2RVAL(&rect, PANGO_TYPE_RECTANGLE);
|
234
|
+
}
|
235
|
+
|
236
|
+
static VALUE
|
237
|
+
attr_shape_value(self)
|
238
|
+
VALUE self;
|
239
|
+
{
|
240
|
+
return rb_ary_new3(2, attr_shape_ink_rect(self), attr_shape_logical_rect(self));
|
241
|
+
}
|
242
|
+
|
243
|
+
/*
|
244
|
+
* Initialize methods
|
245
|
+
*/
|
246
|
+
#define MAKE_ATTRINT_INIT(klassname, funcname)\
|
247
|
+
static VALUE \
|
248
|
+
attr_ ## klassname ## _initialize(self, val)\
|
249
|
+
VALUE self, val;\
|
250
|
+
{\
|
251
|
+
DATA_PTR(self) = pango_attr_ ## funcname ## _new(NUM2INT(val));\
|
252
|
+
return Qnil;\
|
253
|
+
}
|
254
|
+
|
255
|
+
#define MAKE_ATTRENUM_INIT(klassname, funcname, type)\
|
256
|
+
static VALUE \
|
257
|
+
attr_ ## klassname ## _initialize(self, val)\
|
258
|
+
VALUE self, val;\
|
259
|
+
{\
|
260
|
+
DATA_PTR(self) = pango_attr_ ## funcname ## _new(RVAL2GENUM(val, type));\
|
261
|
+
return Qnil;\
|
262
|
+
}
|
263
|
+
|
264
|
+
static VALUE
|
265
|
+
attr_AttrLanguage_initialize(self, lang)
|
266
|
+
VALUE self, lang;
|
267
|
+
{
|
268
|
+
DATA_PTR(self) = pango_attr_language_new(
|
269
|
+
(PangoLanguage*)RVAL2BOXED(lang, PANGO_TYPE_LANGUAGE));
|
270
|
+
return Qnil;
|
271
|
+
}
|
272
|
+
|
273
|
+
static VALUE
|
274
|
+
attr_AttrFamily_initialize(self, family)
|
275
|
+
VALUE self, family;
|
276
|
+
{
|
277
|
+
DATA_PTR(self) = pango_attr_family_new(RVAL2CSTR(family));
|
278
|
+
return Qnil;
|
279
|
+
}
|
280
|
+
|
281
|
+
MAKE_ATTRENUM_INIT(AttrStyle, style, PANGO_TYPE_STYLE);
|
282
|
+
MAKE_ATTRENUM_INIT(AttrVariant, variant, PANGO_TYPE_VARIANT);
|
283
|
+
MAKE_ATTRENUM_INIT(AttrStretch, stretch, PANGO_TYPE_STRETCH);
|
284
|
+
MAKE_ATTRENUM_INIT(AttrWeight, weight, PANGO_TYPE_WEIGHT);
|
285
|
+
|
286
|
+
static VALUE
|
287
|
+
attr_AttrSize_initialize(self, size)
|
288
|
+
VALUE self, size;
|
289
|
+
{
|
290
|
+
DATA_PTR(self) = pango_attr_size_new(NUM2INT(size));
|
291
|
+
return Qnil;
|
292
|
+
}
|
293
|
+
#if PANGO_CHECK_VERSION(1,8,1)
|
294
|
+
static VALUE
|
295
|
+
attr_AttrAbsoluteSize_initialize(self, size)
|
296
|
+
VALUE self, size;
|
297
|
+
{
|
298
|
+
DATA_PTR(self) = pango_attr_size_new_absolute(NUM2INT(size));
|
299
|
+
return Qnil;
|
300
|
+
}
|
301
|
+
#endif
|
302
|
+
|
303
|
+
#if PANGO_CHECK_VERSION(1,16,0)
|
304
|
+
static VALUE
|
305
|
+
attr_AttrGravity_initialize(VALUE self, VALUE gravity)
|
306
|
+
{
|
307
|
+
DATA_PTR(self) = pango_attr_gravity_new(RVAL2GENUM(gravity, PANGO_TYPE_GRAVITY));
|
308
|
+
return Qnil;
|
309
|
+
}
|
310
|
+
|
311
|
+
static VALUE
|
312
|
+
attr_AttrGravityHint_initialize(VALUE self, VALUE gravity_hint)
|
313
|
+
{
|
314
|
+
DATA_PTR(self) = pango_attr_gravity_hint_new(RVAL2GENUM(gravity_hint, PANGO_TYPE_GRAVITY_HINT));
|
315
|
+
return Qnil;
|
316
|
+
}
|
317
|
+
#endif
|
318
|
+
|
319
|
+
static VALUE
|
320
|
+
attr_AttrFontDescription_initialize(self, fontdescription)
|
321
|
+
VALUE self, fontdescription;
|
322
|
+
{
|
323
|
+
DATA_PTR(self) = pango_attr_font_desc_new(
|
324
|
+
(PangoFontDescription*)RVAL2BOXED(fontdescription,
|
325
|
+
PANGO_TYPE_FONT_DESCRIPTION));
|
326
|
+
|
327
|
+
return Qnil;
|
328
|
+
}
|
329
|
+
|
330
|
+
static VALUE
|
331
|
+
attr_AttrForeground_initialize(self, r, g, b)
|
332
|
+
VALUE self, r, g, b;
|
333
|
+
{
|
334
|
+
DATA_PTR(self) = pango_attr_foreground_new(FIX2UINT(r), FIX2UINT(g), FIX2UINT(b));
|
335
|
+
return Qnil;
|
336
|
+
}
|
337
|
+
|
338
|
+
static VALUE
|
339
|
+
attr_AttrBackground_initialize(self, r, g, b)
|
340
|
+
VALUE self, r, g, b;
|
341
|
+
{
|
342
|
+
DATA_PTR(self) = pango_attr_background_new(FIX2UINT(r), FIX2UINT(g), FIX2UINT(b));
|
343
|
+
return Qnil;
|
344
|
+
}
|
345
|
+
|
346
|
+
static VALUE
|
347
|
+
attr_AttrStrikethrough_initialize(self, strikethrough)
|
348
|
+
VALUE self, strikethrough;
|
349
|
+
{
|
350
|
+
DATA_PTR(self) = pango_attr_strikethrough_new(RVAL2CBOOL(strikethrough));
|
351
|
+
return Qnil;
|
352
|
+
}
|
353
|
+
#if HAVE_PANGO_ATTR_STRIKETHROUGH_COLOR_NEW
|
354
|
+
static VALUE
|
355
|
+
attr_AttrStrikethroughColor_initialize(self, r, g, b)
|
356
|
+
VALUE self, r, g, b;
|
357
|
+
{
|
358
|
+
DATA_PTR(self) = pango_attr_strikethrough_color_new(FIX2UINT(r), FIX2UINT(g), FIX2UINT(b));
|
359
|
+
return Qnil;
|
360
|
+
}
|
361
|
+
#endif
|
362
|
+
|
363
|
+
MAKE_ATTRENUM_INIT(AttrUnderline, underline, PANGO_TYPE_UNDERLINE);
|
364
|
+
#if HAVE_PANGO_ATTR_UNDERLINE_COLOR_NEW
|
365
|
+
static VALUE
|
366
|
+
attr_AttrUnderlineColor_initialize(self, r, g, b)
|
367
|
+
VALUE self, r, g, b;
|
368
|
+
{
|
369
|
+
DATA_PTR(self) = pango_attr_underline_color_new(FIX2UINT(r), FIX2UINT(g), FIX2UINT(b));
|
370
|
+
return Qnil;
|
371
|
+
}
|
372
|
+
#endif
|
373
|
+
|
374
|
+
static VALUE
|
375
|
+
attr_AttrShape_initialize(argc, argv, self)
|
376
|
+
int argc;
|
377
|
+
VALUE *argv;
|
378
|
+
VALUE self;
|
379
|
+
{
|
380
|
+
VALUE ink_rect, logical_rect, data;
|
381
|
+
|
382
|
+
rb_scan_args(argc, argv, "21", &ink_rect, &logical_rect, &data);
|
383
|
+
|
384
|
+
if (NIL_P(data)){
|
385
|
+
DATA_PTR(self) = pango_attr_shape_new(
|
386
|
+
(PangoRectangle*)RVAL2BOXED(ink_rect, PANGO_TYPE_RECTANGLE),
|
387
|
+
(PangoRectangle*)RVAL2BOXED(logical_rect, PANGO_TYPE_RECTANGLE));
|
388
|
+
} else {
|
389
|
+
#if PANGO_CHECK_VERSION(1,8,0)
|
390
|
+
G_RELATIVE(self, data);
|
391
|
+
DATA_PTR(self) = pango_attr_shape_new_with_data(
|
392
|
+
(PangoRectangle*)RVAL2BOXED(ink_rect, PANGO_TYPE_RECTANGLE),
|
393
|
+
(PangoRectangle*)RVAL2BOXED(logical_rect, PANGO_TYPE_RECTANGLE),
|
394
|
+
(gpointer)data, NULL, NULL);
|
395
|
+
#else
|
396
|
+
rb_warning("not supported in Pango-1.6.x. the 3rd parameter was ignored.");
|
397
|
+
DATA_PTR(self) = pango_attr_shape_new(
|
398
|
+
(PangoRectangle*)RVAL2BOXED(ink_rect, PANGO_TYPE_RECTANGLE),
|
399
|
+
(PangoRectangle*)RVAL2BOXED(logical_rect, PANGO_TYPE_RECTANGLE));
|
400
|
+
#endif
|
401
|
+
}
|
402
|
+
|
403
|
+
return Qnil;
|
404
|
+
}
|
405
|
+
|
406
|
+
static VALUE
|
407
|
+
attr_AttrScale_initialize(self, scale)
|
408
|
+
VALUE self, scale;
|
409
|
+
{
|
410
|
+
DATA_PTR(self) = pango_attr_scale_new(NUM2DBL(scale));
|
411
|
+
return Qnil;
|
412
|
+
}
|
413
|
+
|
414
|
+
#if PANGO_CHECK_VERSION(1,4,0)
|
415
|
+
static VALUE
|
416
|
+
attr_AttrFallback_initialize(self, enable_fallback)
|
417
|
+
VALUE self, enable_fallback;
|
418
|
+
{
|
419
|
+
DATA_PTR(self) = pango_attr_fallback_new(RVAL2CBOOL(enable_fallback));
|
420
|
+
return Qnil;
|
421
|
+
}
|
422
|
+
#endif
|
423
|
+
|
424
|
+
MAKE_ATTRINT_INIT(AttrRise, rise);
|
425
|
+
|
426
|
+
#if PANGO_CHECK_VERSION(1,6,0)
|
427
|
+
MAKE_ATTRINT_INIT(AttrLetterSpacing, letter_spacing);
|
428
|
+
#endif
|
429
|
+
|
430
|
+
#define MAKE_ATTR(gtype, name, parent, num)\
|
431
|
+
tmpklass = rb_define_class_under(mPango, #name, parent);\
|
432
|
+
rb_hash_aset(type_to_klass, INT2FIX(gtype), tmpklass);\
|
433
|
+
rb_define_method(tmpklass, "initialize", attr_## name ## _initialize , num);
|
434
|
+
|
435
|
+
void
|
436
|
+
Init_pango_attribute()
|
437
|
+
{
|
438
|
+
VALUE tmpklass;
|
439
|
+
pattr = rb_define_class_under(mPango, "Attribute", rb_cData);
|
440
|
+
|
441
|
+
rb_define_singleton_method(pattr, "type_register", attr_s_type_register, 1);
|
442
|
+
rb_define_method(pattr, "==", attr_equal, 1);
|
443
|
+
rb_define_method(pattr, "start_index", attr_start_index, 0);
|
444
|
+
rb_define_method(pattr, "set_start_index", attr_set_start_index, 1);
|
445
|
+
rb_define_method(pattr, "end_index", attr_end_index, 0);
|
446
|
+
rb_define_method(pattr, "set_end_index", attr_set_end_index, 1);
|
447
|
+
|
448
|
+
G_DEF_SETTERS(pattr);
|
449
|
+
|
450
|
+
#ifndef HAVE_RB_DEFINE_ALLOC_FUNC
|
451
|
+
rb_define_singleton_method(pattr, "allocate", attr_s_allocate, 0);
|
452
|
+
#else
|
453
|
+
rb_define_alloc_func(pattr, (VALUE(*)_((VALUE)))attr_s_allocate);
|
454
|
+
#endif
|
455
|
+
#ifndef HAVE_OBJECT_ALLOCATE
|
456
|
+
rb_define_singleton_method(pattr, "new", attr_s_new, -1);
|
457
|
+
#endif
|
458
|
+
|
459
|
+
attrstring = rb_define_class_under(mPango, "AttrString", pattr);
|
460
|
+
rb_define_method(attrstring, "value", attr_string_value, 0);
|
461
|
+
|
462
|
+
pattrint = rb_define_class_under(mPango, "AttrInt", pattr);
|
463
|
+
rb_define_method(pattrint, "value", attr_int_value, 0);
|
464
|
+
|
465
|
+
pattrfloat = rb_define_class_under(mPango, "AttrFloat", pattr);
|
466
|
+
rb_define_method(pattrfloat, "value", attr_float_value, 0);
|
467
|
+
|
468
|
+
pattrcolor = rb_define_class_under(mPango, "AttrColor", pattr);
|
469
|
+
rb_define_method(pattrcolor, "value", attr_color_value, 0);
|
470
|
+
|
471
|
+
pattrbool = rb_define_class_under(mPango, "AttrBool", pattr);
|
472
|
+
rb_define_method(pattrbool, "value", attr_bool_value, 0);
|
473
|
+
|
474
|
+
rb_global_variable(&type_to_klass);
|
475
|
+
type_to_klass = rb_hash_new();
|
476
|
+
|
477
|
+
MAKE_ATTR(PANGO_ATTR_LANGUAGE, AttrLanguage, pattr, 1);
|
478
|
+
rb_define_method(tmpklass, "value", attr_language_value, 0);
|
479
|
+
|
480
|
+
MAKE_ATTR(PANGO_ATTR_FAMILY, AttrFamily, attrstring, 1);
|
481
|
+
MAKE_ATTR(PANGO_ATTR_STYLE, AttrStyle, pattrint, 1);
|
482
|
+
MAKE_ATTR(PANGO_ATTR_WEIGHT, AttrWeight, pattrint, 1);
|
483
|
+
MAKE_ATTR(PANGO_ATTR_VARIANT, AttrVariant, pattrint, 1);
|
484
|
+
MAKE_ATTR(PANGO_ATTR_STRETCH, AttrStretch, pattrint, 1);
|
485
|
+
MAKE_ATTR(PANGO_ATTR_SIZE, AttrSize, pattrint, 1);
|
486
|
+
#if PANGO_CHECK_VERSION(1,8,1)
|
487
|
+
MAKE_ATTR(PANGO_ATTR_ABSOLUTE_SIZE, AttrAbsoluteSize, pattrint, 1);
|
488
|
+
#endif
|
489
|
+
#if PANGO_CHECK_VERSION(1,16,0)
|
490
|
+
MAKE_ATTR(PANGO_ATTR_GRAVITY, AttrGravity, pattrint, 1);
|
491
|
+
MAKE_ATTR(PANGO_ATTR_GRAVITY_HINT, AttrGravityHint, pattrint, 1);
|
492
|
+
#endif
|
493
|
+
MAKE_ATTR(PANGO_ATTR_FONT_DESC, AttrFontDescription, pattr, 1);
|
494
|
+
rb_define_method(tmpklass, "value", attr_fontdesc_value, 0);
|
495
|
+
MAKE_ATTR(PANGO_ATTR_FOREGROUND, AttrForeground, pattrcolor, 3);
|
496
|
+
MAKE_ATTR(PANGO_ATTR_BACKGROUND, AttrBackground, pattrcolor, 3);
|
497
|
+
MAKE_ATTR(PANGO_ATTR_UNDERLINE, AttrUnderline, pattrint, 1);
|
498
|
+
/* PangoUnderline */
|
499
|
+
G_DEF_CLASS(PANGO_TYPE_UNDERLINE, "Underline", tmpklass);
|
500
|
+
G_DEF_CONSTANTS(tmpklass, PANGO_TYPE_UNDERLINE, "PANGO_UNDERLINE_");
|
501
|
+
#if HAVE_PANGO_ATTR_UNDERLINE_COLOR_NEW
|
502
|
+
MAKE_ATTR(PANGO_ATTR_UNDERLINE_COLOR, AttrUnderlineColor, pattrcolor, 3);
|
503
|
+
#endif
|
504
|
+
|
505
|
+
MAKE_ATTR(PANGO_ATTR_STRIKETHROUGH, AttrStrikethrough, pattrbool, 1);
|
506
|
+
#if HAVE_PANGO_ATTR_STRIKETHROUGH_COLOR_NEW
|
507
|
+
MAKE_ATTR(PANGO_ATTR_STRIKETHROUGH_COLOR, AttrStrikethroughColor, pattrcolor, 3);
|
508
|
+
#endif
|
509
|
+
MAKE_ATTR(PANGO_ATTR_RISE, AttrRise, pattrint, 1);
|
510
|
+
#if PANGO_CHECK_VERSION(1,6,0)
|
511
|
+
MAKE_ATTR(PANGO_ATTR_LETTER_SPACING, AttrLetterSpacing, pattrint, 1);
|
512
|
+
#endif
|
513
|
+
MAKE_ATTR(PANGO_ATTR_SHAPE, AttrShape, pattr, -1);
|
514
|
+
rb_define_method(tmpklass, "ink_rect", attr_shape_ink_rect, 0);
|
515
|
+
rb_define_method(tmpklass, "logical_rect", attr_shape_logical_rect, 0);
|
516
|
+
rb_define_method(tmpklass, "value", attr_shape_value, 0);
|
517
|
+
MAKE_ATTR(PANGO_ATTR_SCALE, AttrScale, pattrfloat, 1);
|
518
|
+
/* PangoScale */
|
519
|
+
rb_define_const(tmpklass, "XX_SMALL", rb_float_new(PANGO_SCALE_XX_SMALL));
|
520
|
+
rb_define_const(tmpklass, "X_SMALL", rb_float_new(PANGO_SCALE_X_SMALL));
|
521
|
+
rb_define_const(tmpklass, "SMALL", rb_float_new(PANGO_SCALE_SMALL));
|
522
|
+
rb_define_const(tmpklass, "MEDIUM", rb_float_new(PANGO_SCALE_MEDIUM));
|
523
|
+
rb_define_const(tmpklass, "LARGE", rb_float_new(PANGO_SCALE_LARGE));
|
524
|
+
rb_define_const(tmpklass, "X_LARGE", rb_float_new(PANGO_SCALE_X_LARGE));
|
525
|
+
rb_define_const(tmpklass, "XX_LARGE", rb_float_new(PANGO_SCALE_XX_LARGE));
|
526
|
+
#if PANGO_CHECK_VERSION(1,4,0)
|
527
|
+
MAKE_ATTR(PANGO_ATTR_FALLBACK, AttrFallback, pattrbool, 1);
|
528
|
+
#endif
|
529
|
+
/* PangoAttrType */
|
530
|
+
G_DEF_CLASS(PANGO_TYPE_ATTR_TYPE, "Type", pattr);
|
531
|
+
#define INT2ATTRTYPE(x) rbgobj_make_enum((x), PANGO_TYPE_ATTR_TYPE)
|
532
|
+
rb_define_const(pattr, "TYPE_INVALID", INT2ATTRTYPE(PANGO_ATTR_INVALID));
|
533
|
+
rb_define_const(pattr, "TYPE_LANGUAGE", INT2ATTRTYPE(PANGO_ATTR_LANGUAGE));
|
534
|
+
rb_define_const(pattr, "TYPE_FAMILY", INT2ATTRTYPE(PANGO_ATTR_FAMILY));
|
535
|
+
rb_define_const(pattr, "TYPE_STYLE", INT2ATTRTYPE(PANGO_ATTR_STYLE));
|
536
|
+
rb_define_const(pattr, "TYPE_WEIGHT", INT2ATTRTYPE(PANGO_ATTR_WEIGHT));
|
537
|
+
rb_define_const(pattr, "TYPE_VARIANT", INT2ATTRTYPE(PANGO_ATTR_VARIANT));
|
538
|
+
rb_define_const(pattr, "TYPE_STRETCH", INT2ATTRTYPE(PANGO_ATTR_STRETCH));
|
539
|
+
rb_define_const(pattr, "TYPE_SIZE", INT2ATTRTYPE(PANGO_ATTR_SIZE));
|
540
|
+
rb_define_const(pattr, "TYPE_FONT_DESC", INT2ATTRTYPE(PANGO_ATTR_FONT_DESC));
|
541
|
+
rb_define_const(pattr, "TYPE_FOREGROUND", INT2ATTRTYPE(PANGO_ATTR_FOREGROUND));
|
542
|
+
rb_define_const(pattr, "TYPE_BACKGROUND", INT2ATTRTYPE(PANGO_ATTR_BACKGROUND));
|
543
|
+
rb_define_const(pattr, "TYPE_UNDERLINE", INT2ATTRTYPE(PANGO_ATTR_UNDERLINE));
|
544
|
+
rb_define_const(pattr, "TYPE_STRIKETHROUGH", INT2ATTRTYPE(PANGO_ATTR_STRIKETHROUGH));
|
545
|
+
#if PANGO_CHECK_VERSION(1,8,0)
|
546
|
+
rb_define_const(pattr, "TYPE_STRIKETHROUGH_COLOR", INT2ATTRTYPE(PANGO_ATTR_STRIKETHROUGH_COLOR));
|
547
|
+
#endif
|
548
|
+
rb_define_const(pattr, "TYPE_RISE", INT2ATTRTYPE(PANGO_ATTR_RISE));
|
549
|
+
rb_define_const(pattr, "TYPE_SHAPE", INT2ATTRTYPE(PANGO_ATTR_SHAPE));
|
550
|
+
rb_define_const(pattr, "TYPE_SCALE", INT2ATTRTYPE(PANGO_ATTR_SCALE));
|
551
|
+
#if PANGO_CHECK_VERSION(1,8,0)
|
552
|
+
rb_define_const(pattr, "TYPE_FALLBACK", INT2ATTRTYPE(PANGO_ATTR_FALLBACK));
|
553
|
+
#endif
|
554
|
+
#if PANGO_CHECK_VERSION(1,6,0)
|
555
|
+
rb_define_const(pattr, "TYPE_LETTER_SPACING", INT2ATTRTYPE(PANGO_ATTR_LETTER_SPACING));
|
556
|
+
#endif
|
557
|
+
}
|