1 #include <pangomm/init.h>
2 #include "canvas/canvas.h"
3 #include "canvas/line.h"
4 #include "canvas/rectangle.h"
5 #include "canvas/polygon.h"
6 #include "canvas/arrow.h"
7 #include "canvas/text.h"
8 #include "render.h"
9 
10 using namespace std;
11 using namespace ArdourCanvas;
12 
13 CPPUNIT_TEST_SUITE_REGISTRATION (RenderTest);
14 
15 void
check(string const & name)16 RenderTest::check (string const & name)
17 {
18 	stringstream s;
19 	s << "diff -q " << name << ".png " << "../../libs/canvas/test/" << name << ".png";
20 	int r = system (s.str().c_str());
21 	CPPUNIT_ASSERT (WEXITSTATUS (r) == 0);
22 }
23 
24 void
basics()25 RenderTest::basics ()
26 {
27 	ImageCanvas canvas (Duple (256, 256));
28 
29 	/* line */
30 	Group line_group (canvas.root ());
31 	line_group.set_position (Duple (0, 0));
32 	Line line (&line_group);
33 	line.set (Duple (0, 0), Duple (32, 32));
34 	line.set_outline_width (2);
35 
36 	/* rectangle */
37 	Group rectangle_group (canvas.root ());
38 	rectangle_group.set_position (Duple (64, 0));
39 	Rectangle rectangle (&rectangle_group);
40 	rectangle.set (Rect (0, 0, 32, 32));
41 	rectangle.set_outline_width (2);
42 	rectangle.set_outline_color (0x00ff00ff);
43 	rectangle.set_fill_color (0x0000ffff);
44 
45 	/* poly line */
46 	Group poly_line_group (canvas.root ());
47 	poly_line_group.set_position (Duple (0, 64));
48 	PolyLine poly_line (&poly_line_group);
49 	Points points;
50 	points.push_back (Duple (0, 0));
51 	points.push_back (Duple (16, 48));
52 	points.push_back (Duple (32, 32));
53 	poly_line.set (points);
54 	poly_line.set_outline_color (0xff0000ff);
55 	poly_line.set_outline_width (2);
56 
57 	/* polygon */
58 	Group polygon_group (canvas.root ());
59 	polygon_group.set_position (Duple (64, 64));
60 	Polygon polygon (&polygon_group);
61 	polygon.set (points);
62 	polygon.set_outline_color (0xff00ffff);
63 	polygon.set_fill_color (0xcc00ffff);
64 	polygon.set_outline_width (2);
65 
66 	/* arrow */
67 	Group arrow_group (canvas.root ());
68 	arrow_group.set_position (Duple (128, 0));
69 	Arrow arrow (&arrow_group);
70 	arrow.set_outline_width (2);
71 	arrow.set_x (32);
72 	arrow.set_y0 (0);
73 	arrow.set_y1 (64);
74 
75 	/* text */
76 	Pango::init ();
77 	Group text_group (canvas.root ());
78 	text_group.set_position (Duple (128, 64));
79 	Text text (&text_group);
80 	text.set ("Hello world!");
81 
82 	canvas.render_to_image (Rect (0, 0, 256, 256));
83 	canvas.write_to_png ("render_basics.png");
84 
85 	check ("render_basics");
86 }
87