1package cairo
2
3// #include <stdlib.h>
4// #include <cairo.h>
5// #include <cairo-gobject.h>
6import "C"
7
8import (
9	"unsafe"
10)
11
12// FontSlant is a representation of Cairo's cairo_font_slant_t
13type FontSlant int
14
15const (
16	FONT_SLANT_NORMAL  FontSlant = C.CAIRO_FONT_SLANT_NORMAL
17	FONT_SLANT_ITALIC  FontSlant = C.CAIRO_FONT_SLANT_ITALIC
18	FONT_SLANT_OBLIQUE FontSlant = C.CAIRO_FONT_SLANT_OBLIQUE
19)
20
21// FontWeight is a representation of Cairo's cairo_font_weight_t
22type FontWeight int
23
24const (
25	FONT_WEIGHT_NORMAL FontWeight = C.CAIRO_FONT_WEIGHT_NORMAL
26	FONT_WEIGHT_BOLD   FontWeight = C.CAIRO_FONT_WEIGHT_BOLD
27)
28
29func (v *Context) SelectFontFace(family string, slant FontSlant, weight FontWeight) {
30	cstr := C.CString(family)
31	defer C.free(unsafe.Pointer(cstr))
32	C.cairo_select_font_face(v.native(), (*C.char)(cstr), C.cairo_font_slant_t(slant), C.cairo_font_weight_t(weight))
33}
34
35func (v *Context) SetFontSize(size float64) {
36	C.cairo_set_font_size(v.native(), C.double(size))
37}
38
39// TODO: cairo_set_font_matrix
40
41// TODO: cairo_get_font_matrix
42
43// TODO: cairo_set_font_options
44
45// TODO: cairo_get_font_options
46
47// TODO: cairo_set_font_face
48
49// TODO: cairo_get_font_face
50
51// TODO: cairo_set_scaled_font
52
53// TODO: cairo_get_scaled_font
54
55func (v *Context) ShowText(utf8 string) {
56	cstr := C.CString(utf8)
57	defer C.free(unsafe.Pointer(cstr))
58	C.cairo_show_text(v.native(), (*C.char)(cstr))
59}
60
61// TODO: cairo_show_glyphs
62
63// TODO: cairo_show_text_glyphs
64
65type FontExtents struct {
66	Ascent      float64
67	Descent     float64
68	Height      float64
69	MaxXAdvance float64
70	MaxYAdvance float64
71}
72
73func (v *Context) FontExtents() FontExtents {
74	var extents C.cairo_font_extents_t
75	C.cairo_font_extents(v.native(), &extents)
76	return FontExtents{
77		Ascent:      float64(extents.ascent),
78		Descent:     float64(extents.descent),
79		Height:      float64(extents.height),
80		MaxXAdvance: float64(extents.max_x_advance),
81		MaxYAdvance: float64(extents.max_y_advance),
82	}
83}
84
85type TextExtents struct {
86	XBearing float64
87	YBearing float64
88	Width    float64
89	Height   float64
90	XAdvance float64
91	YAdvance float64
92}
93
94func (v *Context) TextExtents(utf8 string) TextExtents {
95	cstr := C.CString(utf8)
96	defer C.free(unsafe.Pointer(cstr))
97	var extents C.cairo_text_extents_t
98	C.cairo_text_extents(v.native(), (*C.char)(cstr), &extents)
99	return TextExtents{
100		XBearing: float64(extents.x_bearing),
101		YBearing: float64(extents.y_bearing),
102		Width:    float64(extents.width),
103		Height:   float64(extents.height),
104		XAdvance: float64(extents.x_advance),
105		YAdvance: float64(extents.y_advance),
106	}
107}
108
109// TODO: cairo_glyph_extents
110
111// TODO: cairo_toy_font_face_create
112
113// TODO: cairo_toy_font_face_get_family
114
115// TODO: cairo_toy_font_face_get_slant
116
117// TODO: cairo_toy_font_face_get_weight
118
119// TODO: cairo_glyph_allocate
120
121// TODO: cairo_glyph_free
122
123// TODO: cairo_text_cluster_allocate
124
125// TODO: cairo_text_cluster_free
126