Missed update to private test repo version.
[dcpomatic.git] / hacks / text.cc
1 #include <cairomm/cairomm.h>
2 #include <pangomm.h>
3 #include <pangomm/init.h>
4 #include <glibmm.h>
5 #include <stdint.h>
6
7 int main ()
8 {
9 #ifdef __MINGW32__
10         putenv ("PANGOCAIRO_BACKEND=fontconfig");
11         putenv ("FONTCONFIG_PATH=.");
12 #endif
13
14         Pango::init ();
15
16         int const width = 640;
17         int const height = 480;
18         uint8_t* data = new uint8_t[width * height * 4];
19
20         Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (
21                 data,
22                 Cairo::FORMAT_ARGB32,
23                 width, height,
24                 /* Cairo ARGB32 means first byte blue, second byte green, third byte red, fourth byte alpha */
25                 Cairo::ImageSurface::format_stride_for_width (Cairo::FORMAT_ARGB32, width)
26                 );
27
28         Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (surface);
29
30         Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
31
32         context->set_source_rgb (1, 0.2, 0.3);
33         context->rectangle (0, 0, width, height);
34         context->fill ();
35
36         layout->set_alignment (Pango::ALIGN_LEFT);
37
38         context->set_line_width (1);
39         // Cairo::FontOptions fo;
40         // context->get_font_options (fo);
41         // fo.set_antialias (Cairo::ANTIALIAS_NONE);
42         // context->set_font_options (fo);
43
44         Pango::FontDescription font ("Arial");
45         layout->set_font_description (font);
46         layout->set_markup ("Hello world!");
47
48         layout->update_from_cairo_context (context);
49
50         context->set_source_rgb (1, 1, 1);
51         context->set_line_width (0);
52         context->move_to (0, 0);
53         context->scale (2, 2);
54         layout->show_in_cairo_context (context);
55
56         surface->write_to_png ("text.png");
57
58         return 0;
59 }