forked from gotk3/gotk3
/
pangocairo.go
139 lines (121 loc) · 4.63 KB
/
pangocairo.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
/*
* 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 pangocairo
// #include <pango/pango.h>
// #include <cairo.h>
// #include <pango/pangocairo.h>
// #include "pango.go.h"
import "C"
import (
// "github.com/gotk3/gotk3/glib"
"unsafe"
"github.com/gotk3/gotk3/cairo"
)
func init() {
// tm := []glib.TypeMarshaler{
// // Enums
// {glib.Type(C.pango_alignement_get_type()), marshalAlignment},
// {glib.Type(C.pango_ellipsize_mode_get_type()), marshalEllipsizeMode},
// {glib.Type(C.pango_wrap_mode_get_type()), marshalWrapMode},
// }
// glib.RegisterGValueMarshalers(tm)
}
func cairo_context(cr *cairo.Context) *C.cairo_t {
return (*C.cairo_t)(cr.GetCContext())
}
/* Convenience
*/
//PangoContext *pango_cairo_create_context (cairo_t *cr);
func CairoCreateContext(cr *cairo.Context) *Context {
c := C.pango_cairo_create_context(cairo_context(cr))
context := new(Context)
context.pangoContext = (*C.PangoContext)(c)
return context
}
//PangoLayout *pango_cairo_create_layout (cairo_t *cr);
func CairoCreateLayout(cr *cairo.Context) *Layout {
c := C.pango_cairo_create_layout(cairo_context(cr))
layout := new(Layout)
layout.pangoLayout = (*C.PangoLayout)(c)
return layout
}
//void pango_cairo_update_layout (cairo_t *cr,
// PangoLayout *layout);
func CairoUpdateLayout(cr *cairo.Context, v *Layout) {
C.pango_cairo_update_layout(cairo_context(cr), v.native())
}
/*
* Rendering
*/
//void pango_cairo_show_glyph_string (cairo_t *cr,
// PangoFont *font,
// PangoGlyphString *glyphs);
func CairoShowGlyphString(cr *cairo.Context, font *Font, glyphs *GlyphString) {
C.pango_cairo_show_glyph_string(cairo_context(cr), font.native(), glyphs.native())
}
//void pango_cairo_show_glyph_item (cairo_t *cr,
// const char *text,
// PangoGlyphItem *glyph_item);
func CairoShowGlyphItem(cr *cairo.Context, text string, glyph_item *GlyphItem) {
cstr := C.CString(text)
defer C.free(unsafe.Pointer(cstr))
C.pango_cairo_show_glyph_item(cairo_context(cr), (*C.char)(cstr), glyph_item.native())
}
//void pango_cairo_show_layout_line (cairo_t *cr,
// PangoLayoutLine *line);
func CairoShowLayoutLine(cr *cairo.Context, line *LayoutLine) {
C.pango_cairo_show_layout_line(cairo_context(cr), line.native())
}
//void pango_cairo_show_layout (cairo_t *cr,
// PangoLayout *layout);
func CairoShowLayout(cr *cairo.Context, layout *Layout) {
C.pango_cairo_show_layout(cairo_context(cr), layout.native())
}
//void pango_cairo_show_error_underline (cairo_t *cr,
// double x,
// double y,
// double width,
// double height);
/*
* Rendering to a path
*/
//void pango_cairo_glyph_string_path (cairo_t *cr,
// PangoFont *font,
// PangoGlyphString *glyphs);
func CairoGlyphStringPath(cr *cairo.Context, font *Font, glyphs *GlyphString) {
C.pango_cairo_glyph_string_path(cairo_context(cr), font.native(), glyphs.native())
}
//void pango_cairo_layout_line_path (cairo_t *cr,
// PangoLayoutLine *line);
func CairoLayoutLinePath(cr *cairo.Context, line *LayoutLine) {
C.pango_cairo_layout_line_path(cairo_context(cr), line.native())
}
//void pango_cairo_layout_path (cairo_t *cr,
// PangoLayout *layout);
func CairoLayoutPath(cr *cairo.Context, layout *Layout) {
C.pango_cairo_layout_path(cairo_context(cr), layout.native())
}
//void pango_cairo_error_underline_path (cairo_t *cr,
// double x,
// double y,
// double width,
// double height);
func CairoErrorUnderlinePath(cr *cairo.Context, x, y, width, height float64) {
C.pango_cairo_error_underline_path(cairo_context(cr), C.double(x), C.double(y), C.double(width), C.double(height))
}