forked from gotk3/gotk3
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pango-layout.go
476 lines (408 loc) · 16.3 KB
/
pango-layout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/*
* Copyright (c) 2015- terrak <terrak1975@gmail.com>
*
* This file originated from: http://www.terrak.net/
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package pango
// #cgo pkg-config: pango gobject-2.0
// #include <pango/pango.h>
// #include "pango.go.h"
import "C"
import (
"unsafe"
"github.com/d2r2/gotk3/glib"
)
func init() {
tm := []glib.TypeMarshaler{
// Enums
{glib.Type(C.pango_alignment_get_type()), marshalAlignment},
{glib.Type(C.pango_ellipsize_mode_get_type()), marshalEllipsizeMode},
{glib.Type(C.pango_wrap_mode_get_type()), marshalWrapMode},
// Objects/Interfaces
// {glib.Type(C.pango_layout_get_type()), marshalLayout},
}
glib.RegisterGValueMarshalers(tm)
}
// Layout is a representation of PangoLayout.
type Layout struct {
pangoLayout *C.PangoLayout
}
// Native returns a pointer to the underlying PangoLayout.
func (v *Layout) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func (v *Layout) native() *C.PangoLayout {
if v == nil {
return nil
}
return v.pangoLayout
}
func WrapLayout(p uintptr) *Layout {
layout := new(Layout)
layout.pangoLayout = (*C.PangoLayout)(unsafe.Pointer(p))
return layout
}
// LayoutLine is a representation of PangoLayoutLine.
type LayoutLine struct {
pangoLayoutLine *C.PangoLayoutLine
}
// Native returns a pointer to the underlying PangoLayoutLine.
func (v *LayoutLine) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func (v *LayoutLine) native() *C.PangoLayoutLine {
if v == nil {
return nil
}
return v.pangoLayoutLine
}
/*
* Constants
*/
// Alignment is a representation of Pango's PangoAlignment.
type Alignment int
const (
ALIGN_LEFT Alignment = C.PANGO_ALIGN_LEFT
ALIGN_CENTER Alignment = C.PANGO_ALIGN_CENTER
ALIGN_RIGHT Alignment = C.PANGO_ALIGN_RIGHT
)
func marshalAlignment(p uintptr) (interface{}, error) {
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
return Alignment(c), nil
}
// WrapMode is a representation of Pango's PangoWrapMode.
type WrapMode int
const (
WRAP_WORD WrapMode = C.PANGO_WRAP_WORD
WRAP_CHAR WrapMode = C.PANGO_WRAP_CHAR
WRAP_WORD_CHAR WrapMode = C.PANGO_WRAP_WORD_CHAR
)
func marshalWrapMode(p uintptr) (interface{}, error) {
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
return WrapMode(c), nil
}
// EllipsizeMode is a representation of Pango's PangoEllipsizeMode.
type EllipsizeMode int
const (
ELLIPSIZE_NONE EllipsizeMode = C.PANGO_ELLIPSIZE_NONE
ELLIPSIZE_START EllipsizeMode = C.PANGO_ELLIPSIZE_START
ELLIPSIZE_MIDDLE EllipsizeMode = C.PANGO_ELLIPSIZE_MIDDLE
ELLIPSIZE_END EllipsizeMode = C.PANGO_ELLIPSIZE_END
)
func marshalEllipsizeMode(p uintptr) (interface{}, error) {
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
return EllipsizeMode(c), nil
}
/*
func marshalLayout(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := wrapObject(unsafe.Pointer(c))
return wrapLayout(obj), nil
}
func wrapLayout(obj *glib.Object) *Layout {
return &Layout{obj}
}
*/
//PangoLayout *pango_layout_new (PangoContext *context);
func LayoutNew(context *Context) *Layout {
c := C.pango_layout_new(context.native())
layout := new(Layout)
layout.pangoLayout = (*C.PangoLayout)(c)
return layout
}
//PangoLayout *pango_layout_copy (PangoLayout *src);
func (v *Layout) Copy() *Layout {
c := C.pango_layout_copy(v.native())
layout := new(Layout)
layout.pangoLayout = (*C.PangoLayout)(c)
return layout
}
//PangoContext *pango_layout_get_context (PangoLayout *layout);
func (v *Layout) GetContext() *Context {
c := C.pango_layout_get_context(v.native())
context := new(Context)
context.pangoContext = (*C.PangoContext)(c)
return context
}
//void pango_layout_set_attributes (PangoLayout *layout,
// PangoAttrList *attrs);
func (v *Layout) SetAttributes(attrs *AttrList) {
C.pango_layout_set_attributes(v.native(), attrs.native())
}
//PangoAttrList *pango_layout_get_attributes (PangoLayout *layout);
func (v *Layout) GetAttributes() *AttrList {
c := C.pango_layout_get_attributes(v.native())
attrList := new(AttrList)
attrList.pangoAttrList = (*C.PangoAttrList)(c)
return attrList
}
//void pango_layout_set_text (PangoLayout *layout,
// const char *text,
// int length);
func (v *Layout) SetText(text string, length int) {
cstr := C.CString(text)
defer C.free(unsafe.Pointer(cstr))
C.pango_layout_set_text(v.native(), cstr, (C.int)(length))
}
//const char *pango_layout_get_text (PangoLayout *layout);
func (v *Layout) GetText() string {
c := C.pango_layout_get_text(v.native())
return goString(c)
}
//gint pango_layout_get_character_count (PangoLayout *layout);
func (v *Layout) GetCharacterCount() int {
c := C.pango_layout_get_character_count(v.native())
return int(c)
}
//void pango_layout_set_markup (PangoLayout *layout,
// const char *markup,
// int length);
func (v *Layout) SetMarkup(text string, length int) {
cstr := C.CString(text)
defer C.free(unsafe.Pointer(cstr))
C.pango_layout_set_markup(v.native(), cstr, (C.int)(length))
}
//void pango_layout_set_markup_with_accel (PangoLayout *layout,
// const char *markup,
// int length,
// gunichar accel_marker,
// gunichar *accel_char);
/*
func (v *Layout)SetMarkupWithAccel (text string, length int, accel_marker, accel_char rune){
cstr := C.CString(text)
defer C.free(unsafe.Pointer(cstr))
C.pango_layout_set_markup_with_accel (v.native(), (*C.char)(cstr), (C.int)(length), (C.gunichar)(accel_marker), (C.gunichar)(accel_char) )
}
*/
//void pango_layout_set_font_description (PangoLayout *layout,
// const PangoFontDescription *desc);
func (v *Layout) SetFontDescription(desc *FontDescription) {
C.pango_layout_set_font_description(v.native(), desc.native())
}
//const PangoFontDescription *pango_layout_get_font_description (PangoLayout *layout);
func (v *Layout) GetFontDescription() *FontDescription {
c := C.pango_layout_get_font_description(v.native())
desc := new(FontDescription)
desc.pangoFontDescription = (*C.PangoFontDescription)(c)
return desc
}
//void pango_layout_set_width (PangoLayout *layout,
// int width);
func (v *Layout) SetWidth(width int) {
C.pango_layout_set_width(v.native(), C.int(width))
}
//int pango_layout_get_width (PangoLayout *layout);
func (v *Layout) GetWidth() int {
c := C.pango_layout_get_width(v.native())
return int(c)
}
//void pango_layout_set_height (PangoLayout *layout,
// int height);
func (v *Layout) SetHeight(width int) {
C.pango_layout_set_height(v.native(), C.int(width))
}
//int pango_layout_get_height (PangoLayout *layout);
func (v *Layout) GetHeight() int {
c := C.pango_layout_get_height(v.native())
return int(c)
}
//void pango_layout_set_wrap (PangoLayout *layout,
// PangoWrapMode wrap);
func (v *Layout) SetWrap(wrap WrapMode) {
C.pango_layout_set_wrap(v.native(), C.PangoWrapMode(wrap))
}
//PangoWrapMode pango_layout_get_wrap (PangoLayout *layout);
func (v *Layout) GetWrap() WrapMode {
c := C.pango_layout_get_wrap(v.native())
return WrapMode(c)
}
//gboolean pango_layout_is_wrapped (PangoLayout *layout);
func (v *Layout) IsWrapped() bool {
c := C.pango_layout_is_wrapped(v.native())
return gobool(c)
}
//void pango_layout_set_indent (PangoLayout *layout,
// int indent);
func (v *Layout) SetIndent(indent int) {
C.pango_layout_set_indent(v.native(), C.int(indent))
}
//int pango_layout_get_indent (PangoLayout *layout);
func (v *Layout) GetIndent() int {
c := C.pango_layout_get_indent(v.native())
return int(c)
}
//void pango_layout_set_spacing (PangoLayout *layout,
// int spacing);
//int pango_layout_get_spacing (PangoLayout *layout);
//void pango_layout_set_justify (PangoLayout *layout,
// gboolean justify);
//gboolean pango_layout_get_justify (PangoLayout *layout);
//void pango_layout_set_auto_dir (PangoLayout *layout,
// gboolean auto_dir);
//gboolean pango_layout_get_auto_dir (PangoLayout *layout);
//void pango_layout_set_alignment (PangoLayout *layout,
// PangoAlignment alignment);
//PangoAlignment pango_layout_get_alignment (PangoLayout *layout);
//
//void pango_layout_set_tabs (PangoLayout *layout,
// PangoTabArray *tabs);
//
//PangoTabArray* pango_layout_get_tabs (PangoLayout *layout);
//
//void pango_layout_set_single_paragraph_mode (PangoLayout *layout,
// gboolean setting);
//gboolean pango_layout_get_single_paragraph_mode (PangoLayout *layout);
//
//void pango_layout_set_ellipsize (PangoLayout *layout,
// PangoEllipsizeMode ellipsize);
//PangoEllipsizeMode pango_layout_get_ellipsize (PangoLayout *layout);
//gboolean pango_layout_is_ellipsized (PangoLayout *layout);
//
//int pango_layout_get_unknown_glyphs_count (PangoLayout *layout);
//
//void pango_layout_context_changed (PangoLayout *layout);
//guint pango_layout_get_serial (PangoLayout *layout);
//
//void pango_layout_get_log_attrs (PangoLayout *layout,
// PangoLogAttr **attrs,
// gint *n_attrs);
//
//const PangoLogAttr *pango_layout_get_log_attrs_readonly (PangoLayout *layout,
// gint *n_attrs);
//
//void pango_layout_index_to_pos (PangoLayout *layout,
// int index_,
// PangoRectangle *pos);
//void pango_layout_index_to_line_x (PangoLayout *layout,
// int index_,
// gboolean trailing,
// int *line,
// int *x_pos);
//void pango_layout_get_cursor_pos (PangoLayout *layout,
// int index_,
// PangoRectangle *strong_pos,
// PangoRectangle *weak_pos);
//void pango_layout_move_cursor_visually (PangoLayout *layout,
// gboolean strong,
// int old_index,
// int old_trailing,
// int direction,
// int *new_index,
// int *new_trailing);
//gboolean pango_layout_xy_to_index (PangoLayout *layout,
// int x,
// int y,
// int *index_,
// int *trailing);
//void pango_layout_get_extents (PangoLayout *layout,
// PangoRectangle *ink_rect,
// PangoRectangle *logical_rect);
//void pango_layout_get_pixel_extents (PangoLayout *layout,
// PangoRectangle *ink_rect,
// PangoRectangle *logical_rect);
//void pango_layout_get_size (PangoLayout *layout,
// int *width,
// int *height);
func (v *Layout) GetSize() (int, int) {
var w, h C.int
C.pango_layout_get_size(v.native(), &w, &h)
return int(w), int(h)
}
//void pango_layout_get_pixel_size (PangoLayout *layout,
// int *width,
// int *height);
//int pango_layout_get_baseline (PangoLayout *layout);
//
//int pango_layout_get_line_count (PangoLayout *layout);
//PangoLayoutLine *pango_layout_get_line (PangoLayout *layout,
// int line);
//PangoLayoutLine *pango_layout_get_line_readonly (PangoLayout *layout,
// int line);
//GSList * pango_layout_get_lines (PangoLayout *layout);
//GSList * pango_layout_get_lines_readonly (PangoLayout *layout);
//
//
//#define PANGO_TYPE_LAYOUT_LINE (pango_layout_line_get_type ())
//
//GType pango_layout_line_get_type (void) G_GNUC_CONST;
//
//PangoLayoutLine *pango_layout_line_ref (PangoLayoutLine *line);
//void pango_layout_line_unref (PangoLayoutLine *line);
//
//gboolean pango_layout_line_x_to_index (PangoLayoutLine *line,
// int x_pos,
// int *index_,
// int *trailing);
//void pango_layout_line_index_to_x (PangoLayoutLine *line,
// int index_,
// gboolean trailing,
// int *x_pos);
//void pango_layout_line_get_x_ranges (PangoLayoutLine *line,
// int start_index,
// int end_index,
// int **ranges,
// int *n_ranges);
//void pango_layout_line_get_extents (PangoLayoutLine *line,
// PangoRectangle *ink_rect,
// PangoRectangle *logical_rect);
//void pango_layout_line_get_pixel_extents (PangoLayoutLine *layout_line,
// PangoRectangle *ink_rect,
// PangoRectangle *logical_rect);
//
//typedef struct _PangoLayoutIter PangoLayoutIter;
//
//#define PANGO_TYPE_LAYOUT_ITER (pango_layout_iter_get_type ())
//
//GType pango_layout_iter_get_type (void) G_GNUC_CONST;
//
//PangoLayoutIter *pango_layout_get_iter (PangoLayout *layout);
//PangoLayoutIter *pango_layout_iter_copy (PangoLayoutIter *iter);
//void pango_layout_iter_free (PangoLayoutIter *iter);
//
//int pango_layout_iter_get_index (PangoLayoutIter *iter);
//PangoLayoutRun *pango_layout_iter_get_run (PangoLayoutIter *iter);
//PangoLayoutRun *pango_layout_iter_get_run_readonly (PangoLayoutIter *iter);
//PangoLayoutLine *pango_layout_iter_get_line (PangoLayoutIter *iter);
//PangoLayoutLine *pango_layout_iter_get_line_readonly (PangoLayoutIter *iter);
//gboolean pango_layout_iter_at_last_line (PangoLayoutIter *iter);
//PangoLayout *pango_layout_iter_get_layout (PangoLayoutIter *iter);
//
//gboolean pango_layout_iter_next_char (PangoLayoutIter *iter);
//gboolean pango_layout_iter_next_cluster (PangoLayoutIter *iter);
//gboolean pango_layout_iter_next_run (PangoLayoutIter *iter);
//gboolean pango_layout_iter_next_line (PangoLayoutIter *iter);
//
//void pango_layout_iter_get_char_extents (PangoLayoutIter *iter,
// PangoRectangle *logical_rect);
//void pango_layout_iter_get_cluster_extents (PangoLayoutIter *iter,
// PangoRectangle *ink_rect,
// PangoRectangle *logical_rect);
//void pango_layout_iter_get_run_extents (PangoLayoutIter *iter,
// PangoRectangle *ink_rect,
// PangoRectangle *logical_rect);
//void pango_layout_iter_get_line_extents (PangoLayoutIter *iter,
// PangoRectangle *ink_rect,
// PangoRectangle *logical_rect);
/* All the yranges meet, unlike the logical_rect's (i.e. the yranges
* assign between-line spacing to the nearest line)
*/
//void pango_layout_iter_get_line_yrange (PangoLayoutIter *iter,
// int *y0_,
// int *y1_);
//void pango_layout_iter_get_layout_extents (PangoLayoutIter *iter,
// PangoRectangle *ink_rect,
// PangoRectangle *logical_rect);
//int pango_layout_iter_get_baseline (PangoLayoutIter *iter);
//