1// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gtk
3
4import (
5 "github.com/ebitengine/purego"
6
7 "github.com/bnema/puregotk/pkg/core"
8 "github.com/bnema/puregotk/v4/cairo"
9 "github.com/bnema/puregotk/v4/gobject"
10 "github.com/bnema/puregotk/v4/gobject/types"
11 "github.com/bnema/puregotk/v4/pango"
12)
13
14// Encapsulates context information that is required when
15// drawing pages for printing.
16//
17// This includes the cairo context and important parameters like page size
18// and resolution. It also lets you easily create [class@Pango.Layout] and
19// [class@Pango.Context] objects that match the font metrics of the cairo surface.
20//
21// `GtkPrintContext` objects get passed to the
22// [signal@Gtk.PrintOperation::begin-print],
23// [signal@Gtk.PrintOperation::end-print],
24// [signal@Gtk.PrintOperation::request-page-setup] and
25// [signal@Gtk.PrintOperation::draw-page] signals on the
26// [class@Gtk.PrintOperation] object.
27//
28// ## Using GtkPrintContext in a ::draw-page callback
29//
30// ```c
31// static void
32// draw_page (GtkPrintOperation *operation,
33//
34// GtkPrintContext *context,
35// int page_nr)
36//
37// {
38// cairo_t *cr;
39// PangoLayout *layout;
40// PangoFontDescription *desc;
41//
42// cr = gtk_print_context_get_cairo_context (context);
43//
44// // Draw a red rectangle, as wide as the paper (inside the margins)
45// cairo_set_source_rgb (cr, 1.0, 0, 0);
46// cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);
47//
48// cairo_fill (cr);
49//
50// // Draw some lines
51// cairo_move_to (cr, 20, 10);
52// cairo_line_to (cr, 40, 20);
53// cairo_arc (cr, 60, 60, 20, 0, M_PI);
54// cairo_line_to (cr, 80, 20);
55//
56// cairo_set_source_rgb (cr, 0, 0, 0);
57// cairo_set_line_width (cr, 5);
58// cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
59// cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
60//
61// cairo_stroke (cr);
62//
63// // Draw some text
64// layout = gtk_print_context_create_pango_layout (context);
65// pango_layout_set_text (layout, "Hello World! Printing is easy", -1);
66// desc = pango_font_description_from_string ("sans 28");
67// pango_layout_set_font_description (layout, desc);
68// pango_font_description_free (desc);
69//
70// cairo_move_to (cr, 30, 20);
71// pango_cairo_layout_path (cr, layout);
72//
73// // Font Outline
74// cairo_set_source_rgb (cr, 0.93, 1.0, 0.47);
75// cairo_set_line_width (cr, 0.5);
76// cairo_stroke_preserve (cr);
77//
78// // Font Fill
79// cairo_set_source_rgb (cr, 0, 0.0, 1.0);
80// cairo_fill (cr);
81//
82// g_object_unref (layout);
83// }
84//
85// ```
86type PrintContext struct {
87 gobject.Object
88}
89
90var xPrintContextGLibType func() types.GType
91
92func PrintContextGLibType() types.GType {
93 return xPrintContextGLibType()
94}
95
96func PrintContextNewFromInternalPtr(ptr uintptr) *PrintContext {
97 cls := &PrintContext{}
98 cls.Ptr = ptr
99 return cls
100}
101
102var xPrintContextCreatePangoContext func(uintptr) uintptr
103
104// Creates a new `PangoContext` that can be used with the
105// `GtkPrintContext`.
106func (x *PrintContext) CreatePangoContext() *pango.Context {
107 var cls *pango.Context
108
109 cret := xPrintContextCreatePangoContext(x.GoPointer())
110
111 if cret == 0 {
112 return nil
113 }
114 cls = &pango.Context{}
115 cls.Ptr = cret
116 return cls
117}
118
119var xPrintContextCreatePangoLayout func(uintptr) uintptr
120
121// Creates a new `PangoLayout` that is suitable for use
122// with the `GtkPrintContext`.
123func (x *PrintContext) CreatePangoLayout() *pango.Layout {
124 var cls *pango.Layout
125
126 cret := xPrintContextCreatePangoLayout(x.GoPointer())
127
128 if cret == 0 {
129 return nil
130 }
131 cls = &pango.Layout{}
132 cls.Ptr = cret
133 return cls
134}
135
136var xPrintContextGetCairoContext func(uintptr) *cairo.Context
137
138// Obtains the cairo context that is associated with the
139// `GtkPrintContext`.
140func (x *PrintContext) GetCairoContext() *cairo.Context {
141
142 cret := xPrintContextGetCairoContext(x.GoPointer())
143 return cret
144}
145
146var xPrintContextGetDpiX func(uintptr) float64
147
148// Obtains the horizontal resolution of the `GtkPrintContext`,
149// in dots per inch.
150func (x *PrintContext) GetDpiX() float64 {
151
152 cret := xPrintContextGetDpiX(x.GoPointer())
153 return cret
154}
155
156var xPrintContextGetDpiY func(uintptr) float64
157
158// Obtains the vertical resolution of the `GtkPrintContext`,
159// in dots per inch.
160func (x *PrintContext) GetDpiY() float64 {
161
162 cret := xPrintContextGetDpiY(x.GoPointer())
163 return cret
164}
165
166var xPrintContextGetHardMargins func(uintptr, *float64, *float64, *float64, *float64) bool
167
168// Obtains the hardware printer margins of the `GtkPrintContext`,
169// in units.
170func (x *PrintContext) GetHardMargins(TopVar *float64, BottomVar *float64, LeftVar *float64, RightVar *float64) bool {
171
172 cret := xPrintContextGetHardMargins(x.GoPointer(), TopVar, BottomVar, LeftVar, RightVar)
173 return cret
174}
175
176var xPrintContextGetHeight func(uintptr) float64
177
178// Obtains the height of the `GtkPrintContext`, in pixels.
179func (x *PrintContext) GetHeight() float64 {
180
181 cret := xPrintContextGetHeight(x.GoPointer())
182 return cret
183}
184
185var xPrintContextGetPageSetup func(uintptr) uintptr
186
187// Obtains the `GtkPageSetup` that determines the page
188// dimensions of the `GtkPrintContext`.
189func (x *PrintContext) GetPageSetup() *PageSetup {
190 var cls *PageSetup
191
192 cret := xPrintContextGetPageSetup(x.GoPointer())
193
194 if cret == 0 {
195 return nil
196 }
197 gobject.IncreaseRef(cret)
198 cls = &PageSetup{}
199 cls.Ptr = cret
200 return cls
201}
202
203var xPrintContextGetPangoFontmap func(uintptr) uintptr
204
205// Returns a `PangoFontMap` that is suitable for use
206// with the `GtkPrintContext`.
207func (x *PrintContext) GetPangoFontmap() *pango.FontMap {
208 var cls *pango.FontMap
209
210 cret := xPrintContextGetPangoFontmap(x.GoPointer())
211
212 if cret == 0 {
213 return nil
214 }
215 gobject.IncreaseRef(cret)
216 cls = &pango.FontMap{}
217 cls.Ptr = cret
218 return cls
219}
220
221var xPrintContextGetWidth func(uintptr) float64
222
223// Obtains the width of the `GtkPrintContext`, in pixels.
224func (x *PrintContext) GetWidth() float64 {
225
226 cret := xPrintContextGetWidth(x.GoPointer())
227 return cret
228}
229
230var xPrintContextSetCairoContext func(uintptr, *cairo.Context, float64, float64)
231
232// Sets a new cairo context on a print context.
233//
234// This function is intended to be used when implementing
235// an internal print preview, it is not needed for printing,
236// since GTK itself creates a suitable cairo context in that
237// case.
238func (x *PrintContext) SetCairoContext(CrVar *cairo.Context, DpiXVar float64, DpiYVar float64) {
239
240 xPrintContextSetCairoContext(x.GoPointer(), CrVar, DpiXVar, DpiYVar)
241
242}
243
244func (c *PrintContext) GoPointer() uintptr {
245 if c == nil {
246 return 0
247 }
248 return c.Ptr
249}
250
251func (c *PrintContext) SetGoPointer(ptr uintptr) {
252 c.Ptr = ptr
253}
254
255func init() {
256 core.SetPackageName("GTK", "gtk4")
257 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
258 var libs []uintptr
259 for _, libPath := range core.GetPaths("GTK") {
260 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
261 if err != nil {
262 panic(err)
263 }
264 libs = append(libs, lib)
265 }
266
267 core.PuregoSafeRegister(&xPrintContextGLibType, libs, "gtk_print_context_get_type")
268
269 core.PuregoSafeRegister(&xPrintContextCreatePangoContext, libs, "gtk_print_context_create_pango_context")
270 core.PuregoSafeRegister(&xPrintContextCreatePangoLayout, libs, "gtk_print_context_create_pango_layout")
271 core.PuregoSafeRegister(&xPrintContextGetCairoContext, libs, "gtk_print_context_get_cairo_context")
272 core.PuregoSafeRegister(&xPrintContextGetDpiX, libs, "gtk_print_context_get_dpi_x")
273 core.PuregoSafeRegister(&xPrintContextGetDpiY, libs, "gtk_print_context_get_dpi_y")
274 core.PuregoSafeRegister(&xPrintContextGetHardMargins, libs, "gtk_print_context_get_hard_margins")
275 core.PuregoSafeRegister(&xPrintContextGetHeight, libs, "gtk_print_context_get_height")
276 core.PuregoSafeRegister(&xPrintContextGetPageSetup, libs, "gtk_print_context_get_page_setup")
277 core.PuregoSafeRegister(&xPrintContextGetPangoFontmap, libs, "gtk_print_context_get_pango_fontmap")
278 core.PuregoSafeRegister(&xPrintContextGetWidth, libs, "gtk_print_context_get_width")
279 core.PuregoSafeRegister(&xPrintContextSetCairoContext, libs, "gtk_print_context_set_cairo_context")
280
281}