pango 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/ChangeLog +662 -0
  2. data/README +33 -0
  3. data/Rakefile +86 -0
  4. data/extconf.rb +68 -0
  5. data/sample/attribute.rb +82 -0
  6. data/sample/break.rb +26 -0
  7. data/sample/gdk_layout.rb +27 -0
  8. data/sample/glyphstring.rb +61 -0
  9. data/sample/item.rb +35 -0
  10. data/sample/label.rb +23 -0
  11. data/sample/layout.rb +102 -0
  12. data/sample/pango_cairo.rb +66 -0
  13. data/sample/parse.rb +33 -0
  14. data/sample/sample.txt +10 -0
  15. data/sample/script.rb +21 -0
  16. data/src/lib/pango.rb +60 -0
  17. data/src/makeinits.rb +48 -0
  18. data/src/rbpango.c +27 -0
  19. data/src/rbpango.h +97 -0
  20. data/src/rbpangoanalysis.c +197 -0
  21. data/src/rbpangoattribute.c +557 -0
  22. data/src/rbpangoattriterator.c +137 -0
  23. data/src/rbpangoattrlist.c +104 -0
  24. data/src/rbpangocairo.c +229 -0
  25. data/src/rbpangocolor.c +121 -0
  26. data/src/rbpangocontext.c +341 -0
  27. data/src/rbpangocoverage.c +104 -0
  28. data/src/rbpangoengine.c +65 -0
  29. data/src/rbpangofont.c +123 -0
  30. data/src/rbpangofontdescription.c +300 -0
  31. data/src/rbpangofontface.c +71 -0
  32. data/src/rbpangofontfamily.c +74 -0
  33. data/src/rbpangofontmap.c +104 -0
  34. data/src/rbpangofontmetrics.c +85 -0
  35. data/src/rbpangofontset.c +68 -0
  36. data/src/rbpangofontsetsimple.c +53 -0
  37. data/src/rbpangoglyphinfo.c +119 -0
  38. data/src/rbpangoglyphitem.c +129 -0
  39. data/src/rbpangoglyphstring.c +162 -0
  40. data/src/rbpangogravity.c +43 -0
  41. data/src/rbpangoinits.c +71 -0
  42. data/src/rbpangoitem.c +110 -0
  43. data/src/rbpangolanguage.c +88 -0
  44. data/src/rbpangolayout.c +593 -0
  45. data/src/rbpangolayoutiter.c +202 -0
  46. data/src/rbpangolayoutline.c +256 -0
  47. data/src/rbpangologattr.c +107 -0
  48. data/src/rbpangomain.c +213 -0
  49. data/src/rbpangomatrix.c +155 -0
  50. data/src/rbpangorectangle.c +178 -0
  51. data/src/rbpangorenderer.c +204 -0
  52. data/src/rbpangoscript.c +80 -0
  53. data/src/rbpangoscriptiter.c +91 -0
  54. data/src/rbpangotabarray.c +128 -0
  55. data/src/rbpangoversion.h +24 -0
  56. data/test/pango-test-utils.rb +9 -0
  57. data/test/run-test.rb +27 -0
  58. data/test/test-attribute.rb +19 -0
  59. data/test/test-language.rb +7 -0
  60. data/test/test_layout.rb +20 -0
  61. metadata +158 -0
@@ -0,0 +1,107 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbpangologattr.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 16:07:33 $
8
+
9
+ Copyright (C) 2003 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbpango.h"
13
+
14
+ #define _SELF(s) ((PangoLogAttr*)RVAL2BOXED(s, PANGO_TYPE_LOG_ATTR))
15
+
16
+ /**********************************/
17
+ static PangoLogAttr*
18
+ log_copy(const PangoLogAttr* val)
19
+ {
20
+ PangoLogAttr* new_val;
21
+ g_return_val_if_fail (val != NULL, NULL);
22
+ new_val = g_new(PangoLogAttr, 1);
23
+ *new_val = *val;
24
+ return new_val;
25
+ }
26
+
27
+ GType
28
+ pango_log_attr_get_type(void)
29
+ {
30
+ static GType our_type = 0;
31
+
32
+ if (our_type == 0)
33
+ our_type = g_boxed_type_register_static ("PangoLogAttr",
34
+ (GBoxedCopyFunc)log_copy,
35
+ (GBoxedFreeFunc)g_free);
36
+ return our_type;
37
+ }
38
+ /**********************************/
39
+
40
+ #define ATTR_BOOL(name)\
41
+ static VALUE \
42
+ log_get_ ## name (self)\
43
+ VALUE self;\
44
+ {\
45
+ return CBOOL2RVAL(_SELF(self)->name);\
46
+ }\
47
+ static VALUE \
48
+ log_set_ ## name (self, val)\
49
+ VALUE self, val;\
50
+ {\
51
+ _SELF(self)->name = RVAL2CBOOL(val);\
52
+ return self;\
53
+ }
54
+
55
+ static VALUE
56
+ log_initialize(self)
57
+ VALUE self;
58
+ {
59
+ PangoLogAttr log;
60
+ G_INITIALIZE(self, &log);
61
+ return Qnil;
62
+ }
63
+
64
+ #define DEFINE_ACCESSOR(logattr, name) \
65
+ rb_define_method(logattr, G_STRINGIFY(name?), log_get_is_ ## name, 0);\
66
+ rb_define_method(logattr, G_STRINGIFY(set_ ## name), log_set_is_ ## name, 1);
67
+
68
+ ATTR_BOOL(is_line_break);
69
+ ATTR_BOOL(is_mandatory_break);
70
+ ATTR_BOOL(is_char_break);
71
+ ATTR_BOOL(is_white);
72
+ ATTR_BOOL(is_cursor_position);
73
+ ATTR_BOOL(is_word_start);
74
+ ATTR_BOOL(is_word_end);
75
+ ATTR_BOOL(is_sentence_boundary);
76
+ ATTR_BOOL(is_sentence_start);
77
+ ATTR_BOOL(is_sentence_end);
78
+
79
+ #if PANGO_CHECK_VERSION(1,4,0)
80
+ ATTR_BOOL(backspace_deletes_character);
81
+ #endif
82
+
83
+ void
84
+ Init_pango_logattr()
85
+ {
86
+ VALUE logattr = G_DEF_CLASS(PANGO_TYPE_LOG_ATTR, "LogAttr", mPango);
87
+
88
+ rb_define_method(logattr, "initialize", log_initialize, 0);
89
+
90
+ DEFINE_ACCESSOR(logattr, line_break);
91
+ DEFINE_ACCESSOR(logattr, mandatory_break);
92
+ DEFINE_ACCESSOR(logattr, char_break);
93
+ DEFINE_ACCESSOR(logattr, white);
94
+ DEFINE_ACCESSOR(logattr, cursor_position);
95
+ DEFINE_ACCESSOR(logattr, word_start);
96
+ DEFINE_ACCESSOR(logattr, word_end);
97
+ DEFINE_ACCESSOR(logattr, sentence_boundary);
98
+ DEFINE_ACCESSOR(logattr, sentence_start);
99
+ DEFINE_ACCESSOR(logattr, sentence_end);
100
+
101
+ #if PANGO_CHECK_VERSION(1,4,0)
102
+ rb_define_method(logattr, "backspace_deletes_character?", log_get_backspace_deletes_character, 0);
103
+ rb_define_method(logattr, "set_backspace_deletes_character", log_set_backspace_deletes_character, 1);
104
+ #endif
105
+
106
+ G_DEF_SETTERS(logattr);
107
+ }
data/src/rbpangomain.c ADDED
@@ -0,0 +1,213 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbpangomain.c -
5
+
6
+ $Author: sakai $
7
+ $Date: 2007/07/08 02:53:10 $
8
+
9
+ Copyright (C) 2002-2005 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbpango.h"
13
+
14
+ /*
15
+ * Rendering
16
+ */
17
+
18
+ static VALUE
19
+ rpango_reorder_items(self, logical_items)
20
+ VALUE self, logical_items;
21
+ {
22
+ int i;
23
+ GList *glist = NULL;
24
+ GList* ret;
25
+
26
+ Check_Type(logical_items, T_ARRAY);
27
+
28
+ for (i = 0; i < RARRAY_LEN(logical_items); i++){
29
+ glist = g_list_append(glist, RVAL2BOXED(RARRAY_PTR(logical_items)[i], PANGO_TYPE_ITEM));
30
+ }
31
+
32
+ ret = pango_reorder_items(glist);
33
+ g_list_free(glist);
34
+
35
+ return GLIST2ARY2(ret, PANGO_TYPE_ITEM);
36
+ }
37
+
38
+ #if PANGO_CHECK_VERSION(1,4,0)
39
+ static VALUE
40
+ rpango_unichar_direction(self, ch)
41
+ VALUE self, ch;
42
+ {
43
+ return GENUM2RVAL(pango_unichar_direction(NUM2UINT(ch)), PANGO_TYPE_DIRECTION);
44
+ }
45
+
46
+ static VALUE
47
+ rpango_find_base_dir(self, text)
48
+ VALUE self, text;
49
+ {
50
+ StringValue(text);
51
+ return GENUM2RVAL(pango_find_base_dir(RVAL2CSTR(text), RSTRING_LEN(text)),
52
+ PANGO_TYPE_DIRECTION);
53
+ }
54
+ #endif
55
+
56
+ static VALUE
57
+ rpango_break(self, text, analysis)
58
+ VALUE self, text, analysis;
59
+ {
60
+ gint i, len;
61
+ glong attrs_len;
62
+ PangoLogAttr* attrs;
63
+ gchar* gtext;
64
+ VALUE ret;
65
+
66
+ StringValue(text);
67
+ len = RSTRING_LEN(text);
68
+ gtext = RVAL2CSTR(text);
69
+ attrs_len = g_utf8_strlen(gtext, (gssize)len) + 1l;
70
+ attrs = g_new0(PangoLogAttr, attrs_len);
71
+
72
+ pango_break((const gchar*)gtext, len,
73
+ NIL_P(analysis) ? NULL : RVAL2BOXED(analysis, PANGO_TYPE_ANALYSIS),
74
+ attrs, attrs_len);
75
+
76
+ ret = rb_ary_new();
77
+ for (i = 0; i < attrs_len; i++){
78
+ rb_ary_push(ret, BOXED2RVAL(&attrs[i], PANGO_TYPE_LOG_ATTR));
79
+ }
80
+ g_free(attrs);
81
+ return ret;
82
+ }
83
+
84
+ static VALUE
85
+ rpango_get_log_attrs(self, text, level, language)
86
+ VALUE self, text, level, language;
87
+ {
88
+ gint i, len;
89
+ glong attrs_len;
90
+ PangoLogAttr* attrs;
91
+ gchar* gtext;
92
+ VALUE ret;
93
+
94
+ StringValue(text);
95
+ len = RSTRING_LEN(text);
96
+ gtext = RVAL2CSTR(text);
97
+ attrs_len = g_utf8_strlen(gtext, (gssize)len) + 1l;
98
+ attrs = g_new0(PangoLogAttr, attrs_len);
99
+
100
+ pango_get_log_attrs((const gchar*)gtext, len, NUM2INT(level),
101
+ RVAL2BOXED(language, PANGO_TYPE_LANGUAGE),
102
+ attrs, attrs_len);
103
+
104
+ ret = rb_ary_new();
105
+ for (i = 0; i < attrs_len; i++){
106
+ rb_ary_push(ret, BOXED2RVAL(&attrs[i], PANGO_TYPE_LOG_ATTR));
107
+ }
108
+ g_free(attrs);
109
+ return ret;
110
+ }
111
+
112
+ static VALUE
113
+ rpango_find_paragraph_boundary(self, text)
114
+ VALUE self, text;
115
+ {
116
+ gint paragraph_delimiter_index, next_paragraph_start;
117
+
118
+ pango_find_paragraph_boundary(RVAL2CSTR(text), RSTRING_LEN(text),
119
+ &paragraph_delimiter_index,
120
+ &next_paragraph_start);
121
+ return rb_ary_new3(2, INT2NUM(paragraph_delimiter_index),
122
+ INT2NUM(next_paragraph_start));
123
+ }
124
+
125
+ /*
126
+ Don't need to implement this. Use pango_break instead.
127
+ void pango_default_break (const gchar *text,
128
+ int length,
129
+ PangoAnalysis *analysis,
130
+ PangoLogAttr *attrs,
131
+ int attrs_len);
132
+ */
133
+
134
+ static VALUE
135
+ rpango_shape(self, text, analysis)
136
+ VALUE self, text, analysis;
137
+ {
138
+ VALUE ret;
139
+ PangoGlyphString* glyphs = pango_glyph_string_new();
140
+ StringValue(text);
141
+ pango_shape(RVAL2CSTR(text), RSTRING_LEN(text), RVAL2BOXED(analysis, PANGO_TYPE_ANALYSIS), glyphs);
142
+ ret = BOXED2RVAL(glyphs, PANGO_TYPE_GLYPH_STRING);
143
+ pango_glyph_string_free (glyphs);
144
+ return ret;
145
+ }
146
+
147
+ /* This method is from rbpangoattribute.c */
148
+ static VALUE
149
+ rpango_parse_markup(argc, argv, self)
150
+ int argc;
151
+ VALUE *argv;
152
+ VALUE self;
153
+ {
154
+ VALUE markup_text, accel_marker;
155
+ PangoAttrList *pattr_list;
156
+ gchar* gtext;
157
+ gunichar accel_char;
158
+ GError *error = NULL;
159
+ gboolean ret;
160
+ char c;
161
+ VALUE text = Qnil;
162
+ VALUE attr_list = Qnil;
163
+
164
+ rb_scan_args(argc, argv, "11", &markup_text, &accel_marker);
165
+
166
+ if (NIL_P(markup_text)) rb_raise(rb_eRuntimeError, "1st argument can't accept nil");
167
+
168
+ ret = pango_parse_markup(RVAL2CSTR(markup_text),
169
+ RSTRING_LEN(markup_text),
170
+ NIL_P(accel_marker) ? 0 : NUM2CHR(accel_marker),
171
+ &pattr_list, &gtext, &accel_char, &error);
172
+
173
+ if (!ret) RAISE_GERROR(error);
174
+
175
+ if (pattr_list){
176
+ attr_list = BOXED2RVAL(pattr_list, PANGO_TYPE_ATTR_LIST);
177
+ pango_attr_list_unref(pattr_list);
178
+ }
179
+
180
+ c = (char)accel_char;
181
+ if (text){
182
+ text = CSTR2RVAL(gtext);
183
+ g_free(gtext);
184
+ }
185
+ return rb_ary_new3(3, attr_list, text,
186
+ accel_char ? rb_str_new(&c, 1) : Qnil);
187
+ }
188
+
189
+ static VALUE
190
+ rpango_pixels(self, pixels)
191
+ VALUE self, pixels;
192
+ {
193
+ return rb_float_new(PANGO_PIXELS(NUM2DBL(pixels)));
194
+ }
195
+
196
+ void
197
+ Init_pango_main()
198
+ {
199
+ rb_define_module_function(mPango, "reorder_items", rpango_reorder_items, 1);
200
+
201
+ #if PANGO_CHECK_VERSION(1,4,0)
202
+ rb_define_module_function(mPango, "unichar_direction", rpango_unichar_direction, 1);
203
+ rb_define_module_function(mPango, "find_base_dir", rpango_find_base_dir, 1);
204
+ #endif
205
+ rb_define_module_function(mPango, "break", rpango_break, 2);
206
+ rb_define_module_function(mPango, "get_log_attrs", rpango_get_log_attrs, 3);
207
+ rb_define_module_function(mPango, "find_paragraph_boundary", rpango_find_paragraph_boundary, 1);
208
+ rb_define_module_function(mPango, "shape", rpango_shape, 2);
209
+ rb_define_module_function(mPango, "parse_markup", rpango_parse_markup, -1);
210
+ rb_define_module_function(mPango, "pixels", rpango_pixels, 1);
211
+
212
+ rb_define_const(mPango, "SCALE", INT2FIX(PANGO_SCALE));
213
+ }
@@ -0,0 +1,155 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbpangomatrix.c -
5
+
6
+ $Author: mutoh $
7
+ $Date: 2006/12/10 15:13:10 $
8
+
9
+ Copyright (C) 2005 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbpango.h"
13
+
14
+ #if PANGO_CHECK_VERSION(1,6,0)
15
+ #define _SELF(self) ((PangoMatrix*)(RVAL2BOXED(self, PANGO_TYPE_MATRIX)))
16
+
17
+ #define ATTR_FLOAT(name)\
18
+ static VALUE \
19
+ matrix_get_ ## name (self)\
20
+ VALUE self;\
21
+ {\
22
+ return rb_float_new(_SELF(self)->name);\
23
+ }\
24
+ static VALUE \
25
+ matrix_set_ ## name (self, val)\
26
+ VALUE self, val;\
27
+ {\
28
+ _SELF(self)->name = NUM2DBL(val);\
29
+ return self;\
30
+ }
31
+
32
+ #define DEFINE_ACCESSOR(name) \
33
+ rb_define_method(matrix, G_STRINGIFY(name), matrix_get_ ## name, 0);\
34
+ rb_define_method(matrix, G_STRINGIFY(set_ ## name), matrix_set_## name, 1);
35
+
36
+ static VALUE
37
+ matrix_initialize(argc, argv, self)
38
+ int argc;
39
+ VALUE *argv;
40
+ VALUE self;
41
+ {
42
+ PangoMatrix matrix = PANGO_MATRIX_INIT;
43
+ VALUE xx, xy, yx, yy, x0, y0;
44
+
45
+ rb_scan_args(argc, argv, "06", &xx, &xy, &yx, &yy, &x0, &y0);
46
+
47
+ if (argc > 0){
48
+ matrix.xx = NUM2DBL(xx);
49
+ matrix.xy = NUM2DBL(xy);
50
+ matrix.yx = NUM2DBL(yx);
51
+ matrix.yy = NUM2DBL(yy);
52
+ matrix.x0 = NUM2DBL(x0);
53
+ matrix.y0 = NUM2DBL(y0);
54
+ }
55
+ G_INITIALIZE(self, &matrix);
56
+ return Qnil;
57
+ }
58
+
59
+ static VALUE
60
+ matrix_translate(self, tx, ty)
61
+ VALUE self, tx, ty;
62
+ {
63
+ pango_matrix_translate(_SELF(self), NUM2DBL(tx), NUM2DBL(ty));
64
+ return self;
65
+ }
66
+
67
+ static VALUE
68
+ matrix_scale(self, scale_x, scale_y)
69
+ VALUE self, scale_x, scale_y;
70
+ {
71
+ pango_matrix_scale(_SELF(self), NUM2DBL(scale_x), NUM2DBL(scale_y));
72
+ return self;
73
+ }
74
+
75
+ static VALUE
76
+ matrix_rotate(self, degrees)
77
+ VALUE self, degrees;
78
+ {
79
+ pango_matrix_rotate(_SELF(self), NUM2DBL(degrees));
80
+ return self;
81
+ }
82
+
83
+ #if PANGO_CHECK_VERSION(1,16,0)
84
+ static VALUE
85
+ matrix_get_gravity(VALUE self)
86
+ {
87
+ return GENUM2RVAL(pango_gravity_get_for_matrix(_SELF(self)), PANGO_TYPE_GRAVITY);
88
+ }
89
+ #endif
90
+
91
+ static VALUE
92
+ matrix_concat(self, new_matrix)
93
+ VALUE self, new_matrix;
94
+ {
95
+ pango_matrix_concat(_SELF(self), _SELF(new_matrix));
96
+ return self;
97
+ }
98
+
99
+ #if PANGO_CHECK_VERSION(1,12,0)
100
+ static VALUE
101
+ matrix_get_font_scale_factor(self)
102
+ VALUE self;
103
+ {
104
+ return rb_float_new(pango_matrix_get_font_scale_factor(_SELF(self)));
105
+ }
106
+ #endif
107
+
108
+ ATTR_FLOAT(xx);
109
+ ATTR_FLOAT(xy);
110
+ ATTR_FLOAT(yx);
111
+ ATTR_FLOAT(yy);
112
+ ATTR_FLOAT(x0);
113
+ ATTR_FLOAT(y0);
114
+
115
+ static VALUE
116
+ matrix_to_a(self)
117
+ VALUE self;
118
+ {
119
+ PangoMatrix* matrix = _SELF(self);
120
+ return rb_ary_new3(6, INT2NUM(matrix->xx), INT2NUM(matrix->xy), INT2NUM(matrix->yx),
121
+ INT2NUM(matrix->yy), INT2NUM(matrix->x0), INT2NUM(matrix->y0));
122
+ }
123
+
124
+ #endif
125
+
126
+ void
127
+ Init_pango_matrix()
128
+ {
129
+ #if PANGO_CHECK_VERSION(1,6,0)
130
+ VALUE matrix = G_DEF_CLASS(PANGO_TYPE_MATRIX, "Matrix", mPango);
131
+
132
+ rb_define_method(matrix, "initialize", matrix_initialize, -1);
133
+ rb_define_method(matrix, "translate!", matrix_translate, 2);
134
+ rb_define_method(matrix, "scale!", matrix_scale, 2);
135
+ rb_define_method(matrix, "rotate!", matrix_rotate, 1);
136
+ rb_define_method(matrix, "concat!", matrix_concat, 1);
137
+ #if PANGO_CHECK_VERSION(1,12,0)
138
+ rb_define_method(matrix, "font_scale_factor", matrix_get_font_scale_factor, 0);
139
+ #endif
140
+ #if PANGO_CHECK_VERSION(1,16,0)
141
+ rb_define_method(matrix, "gravity", matrix_get_gravity, 0);
142
+ #endif
143
+ rb_define_method(matrix, "to_a", matrix_to_a, 0);
144
+
145
+ DEFINE_ACCESSOR(xx);
146
+ DEFINE_ACCESSOR(xy);
147
+ DEFINE_ACCESSOR(yx);
148
+ DEFINE_ACCESSOR(yy);
149
+ DEFINE_ACCESSOR(x0);
150
+ DEFINE_ACCESSOR(y0);
151
+
152
+ G_DEF_SETTERS(matrix);
153
+
154
+ #endif
155
+ }